@standardagents/builder 0.11.8 → 0.11.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.
@@ -1,29 +1,29 @@
1
- import{d as pe,i as Xt,c as W,t as Aa,r as m,w as ve,o as Ve,a as Be,p as Pa,m as Pe,b as o,e as a,f as e,n as ot,g as et,h as Ce,u as Ye,j as oe,k as M,l as se,q as X,F as me,s as ye,v as P,x as Ie,y as ge,z as lt,A as Qe,B as V,R as Lt,C as $e,T as rt,D as Xe,E as Me,G as Oe,H as Da,I as Ue,J as ja,X as ft,K as nt,S as Yt,L as Oa,M as Ua,N as Zt,O as Ra,P as Tt,Q as Na,U as Qt,V as Ke,W as ea,Y as pt,Z as Fa,_ as ta,$ as kt,a0 as At,a1 as Ba,a2 as qa,a3 as za,a4 as Ha,a5 as Wa,a6 as aa,a7 as Pt,a8 as Ja,a9 as Ka,aa as Ga,ab as Xa,ac as Ya,ad as oa,ae as Za,af as la,ag as Qa,ah as sa,ai as wt,aj as We,ak as st,al as eo,am as to,an as na,ao as ra,ap as ao,aq as oo,ar as lo,as as so,at as no}from"./vue.js";import{f as ro}from"./vendor.js";import{W as io,a as uo,e as Dt}from"./monaco.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))i(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const r of u.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function s(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function i(l){if(l.ep)return;l.ep=!0;const u=s(l);fetch(l.href,u)}})();var ia=class{endpoint;token;constructor(t){this.endpoint=t.replace(/\/$/,""),this.token=typeof localStorage<"u"?localStorage.getItem("agentbuilder_auth_token"):null}getEndpoint(){return this.endpoint}async createThread(t){const n=await fetch(`${this.endpoint}/threads`,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`Failed to create thread: ${n.statusText}`);return n.json()}async getThread(t){const n=await fetch(`${this.endpoint}/threads/${t}`,{method:"GET",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to get thread: ${n.statusText}`);return n.json()}async getMessages(t,n={}){const s=new URLSearchParams;n.limit!==void 0&&s.set("limit",String(n.limit)),n.offset!==void 0&&s.set("offset",String(n.offset)),n.depth!==void 0&&s.set("depth",String(n.depth)),n.includeSilent!==void 0&&s.set("includeSilent",String(n.includeSilent));const i=s.toString(),l=`${this.endpoint}/threads/${t}/messages${i?`?${i}`:""}`,u=await fetch(l,{method:"GET",headers:this.getHeaders()});if(!u.ok)throw new Error(`Failed to get messages: ${u.statusText}`);return(await u.json()).messages||[]}async sendMessage(t,n){const s=await fetch(`${this.endpoint}/threads/${t}/messages`,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok)throw new Error(`Failed to send message: ${s.statusText}`);return s.json()}async stopExecution(t){const n=await fetch(`${this.endpoint}/threads/${t}/stop`,{method:"POST",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to stop execution: ${n.statusText}`);await n.json()}async deleteMessage(t,n){const s=await fetch(`${this.endpoint}/threads/${t}/messages/${n}`,{method:"DELETE",headers:this.getHeaders()});if(!s.ok)throw new Error(`Failed to delete message: ${s.statusText}`);return s.json()}async uploadFile(t,n,s){const i=encodeURIComponent(n.name),l=`${this.endpoint}/threads/${t}/fs/${i}`;if(s?.thumbnail){const r=await this.fileToBase64(n),c=await fetch(l,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify({data:r,mimeType:n.type,thumbnail:s.thumbnail,metadata:{width:s.width,height:s.height}})});if(!c.ok)throw new Error(`Failed to upload file: ${c.statusText}`);return c.json()}const u=await fetch(l,{method:"POST",headers:{...this.getHeaders(),"Content-Type":n.type},body:n});if(!u.ok)throw new Error(`Failed to upload file: ${u.statusText}`);return u.json()}fileToBase64(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>{const u=i.result.split(",")[1];n(u)},i.onerror=()=>s(new Error("Failed to read file")),i.readAsDataURL(t)})}getFileUrl(t,n){const i=(n.startsWith("/")?n.slice(1):n).split("/").map(l=>encodeURIComponent(l)).join("/");return`${this.endpoint}/threads/${t}/fs/${i}`}getThumbnailUrl(t,n){return`${this.getFileUrl(t,n)}?thumbnail=true`}async listFiles(t){const n=await fetch(`${this.endpoint}/threads/${t}/fs?find=**/*&type=file`,{method:"GET",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to list files: ${n.statusText}`);return(await n.json()).files||[]}connectMessageWebSocket(t,n={},s={}){const i=new URLSearchParams;this.token&&i.set("token",this.token),s.includeSilent!==void 0&&i.set("includeSilent",String(s.includeSilent)),s.depth!==void 0&&i.set("depth",String(s.depth));const l=this.endpoint.startsWith("https")?"wss":"ws",r=`${this.endpoint.replace(/^https?/,l)}/threads/${t}/stream?${i.toString()}`,c=new WebSocket(r);return c.onopen=()=>{n.onOpen?.()},c.onmessage=f=>{try{if(typeof f.data=="string"&&f.data==="pong")return;const g=JSON.parse(f.data);switch(g.type){case"message_data":n.onMessage?.(g);break;case"message_chunk":n.onChunk?.(g);break;case"event":n.onEvent?.(g);break;case"error":n.onError?.(g);break}}catch(g){console.error("Failed to parse WebSocket message:",g)}},c.onerror=f=>{console.error("WebSocket error:",f),n.onError?.({type:"error",error:"WebSocket connection error"})},c.onclose=f=>{console.log(`[AgentBuilderClient] Message WebSocket closed - code: ${f.code}, reason: ${f.reason||"none"}, wasClean: ${f.wasClean}`),n.onClose?.()},c}connectLogWebSocket(t,n={}){const s=new URLSearchParams;this.token&&s.set("token",this.token);const i=this.endpoint.startsWith("https")?"wss":"ws",u=`${this.endpoint.replace(/^https?/,i)}/threads/${t}?${s.toString()}`,r=new WebSocket(u);return r.onopen=()=>{n.onOpen?.()},r.onmessage=c=>{try{if(typeof c.data=="string"&&c.data==="pong")return;const f=JSON.parse(c.data);switch(f.type){case"log_data":n.onLog?.(f);break;case"custom":n.onCustom?.(f);break;case"stopped_by_user":n.onStopped?.(f);break}}catch(f){console.error("Failed to parse WebSocket message:",f)}},r.onerror=c=>{console.error("WebSocket error:",c)},r.onclose=()=>{n.onClose?.()},r}getHeaders(){const t={};return this.token&&(t.Authorization=`Bearer ${this.token}`),t}},co=class{client;threadId;callbacks;options;ws=null;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;heartbeatInterval=null;isReconnecting=!1;shouldReconnect=!0;constructor(t,n,s={},i={}){this.client=t,this.threadId=n,this.callbacks=s,this.options={depth:i.depth??0,includeSilent:i.includeSilent??!1,heartbeatInterval:i.heartbeatInterval??3e4,maxReconnectDelay:i.maxReconnectDelay??3e4}}getStatus(){return this.status}getThreadId(){return this.threadId}connect(){this.ws&&this.ws.readyState!==WebSocket.CLOSED||(this.shouldReconnect=!0,this.isReconnecting=!1,this.setStatus("connecting"),this.ws=this.client.connectMessageWebSocket(this.threadId,{onOpen:()=>{this.setStatus("connected"),this.reconnectAttempts=0,this.isReconnecting=!1,this.startHeartbeat()},onMessage:t=>{this.callbacks.onMessage?.(t)},onChunk:t=>{this.callbacks.onChunk?.(t)},onEvent:t=>{this.callbacks.onEvent?.(t)},onError:t=>{this.callbacks.onError?.(t)},onClose:()=>{this.clearTimers(),this.scheduleReconnect()}},{depth:this.options.depth,includeSilent:this.options.includeSilent}))}disconnect(){this.shouldReconnect=!1,this.clearTimers(),this.ws&&(this.ws.close(),this.ws=null),this.reconnectAttempts=0,this.isReconnecting=!1,this.setStatus("disconnected")}updateCallbacks(t){this.callbacks={...this.callbacks,...t}}updateOptions(t){this.options={...this.options,...t}}setStatus(t){this.status!==t&&(this.status=t,this.callbacks.onStatusChange?.(t))}startHeartbeat(){this.clearHeartbeat(),this.heartbeatInterval=setInterval(()=>{this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send("ping")},this.options.heartbeatInterval)}clearHeartbeat(){this.heartbeatInterval&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}clearTimers(){this.clearHeartbeat(),this.clearReconnectTimeout()}scheduleReconnect(){if(!this.shouldReconnect||this.isReconnecting){this.setStatus("disconnected");return}this.isReconnecting=!0,this.setStatus("reconnecting");const t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),this.options.maxReconnectDelay);this.reconnectAttempts++,this.reconnectTimeout=setTimeout(()=>{this.shouldReconnect&&this.connect()},t)}};function jt(t){return t.toLowerCase().startsWith("image/")}var Ot=256;function po(t){return new Promise((n,s)=>{const i=new Image,l=URL.createObjectURL(t);i.onload=()=>{URL.revokeObjectURL(l),n(i)},i.onerror=()=>{URL.revokeObjectURL(l),s(new Error("Failed to load image"))},i.src=l})}function vo(t){const{width:n,height:s}=t,i=n/s;let l,u;i>1?(l=Math.min(Ot,n),u=Math.floor(l/i)):(u=Math.min(Ot,s),l=Math.floor(u*i));const r=document.createElement("canvas");r.width=l,r.height=u;const c=r.getContext("2d");if(!c)throw new Error("Failed to get canvas context");return c.drawImage(t,0,0,l,u),r.toDataURL("image/webp",.8).split(",")[1]}async function mo(t){const n=await po(t);return{thumbnail:vo(n),width:n.width,height:n.height}}function fo(){return`pending-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function ho(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>n(i.result),i.onerror=s,i.readAsDataURL(t)})}var go=class{createPendingFile(t){return{id:fo(),name:t.name,mimeType:t.type,size:t.size,isImage:jt(t.type),localPreviewUrl:null,status:"uploading"}}queueFiles(t){return Array.from(t).map(n=>({pending:this.createPendingFile(n),file:n}))}async executeUpload(t,n,s,i,l,u={}){const{generateThumbnail:r=!0,generatePreview:c=!0}=u,f=jt(n.type);f&&c&&ho(n).then(g=>l({localPreviewUrl:g})).catch(g=>console.error("Failed to generate preview:",g));try{let g;if(f&&r)try{const p=await mo(n);g={thumbnail:p.thumbnail,width:p.width,height:p.height}}catch(p){console.warn("Failed to generate thumbnail:",p)}const d=await i.uploadFile(t,n,g);return l({id:d.id,status:"ready",path:d.path,width:d.width,height:d.height}),d}catch(g){throw l({status:"error",error:g instanceof Error?g.message:"Failed to upload file"}),g}}async executeUploads(t,n,s,i,l={}){const u=n.map(({pending:r,file:c})=>this.executeUpload(t,c,r.id,s,f=>i(r.id,f),l).catch(f=>f instanceof Error?f:new Error(String(f))));return Promise.all(u)}};function bo(t){if(t.length===0)return[];const n=[];let s=0;for(;s<t.length;){const i=t[s];if(i.role==="assistant"&&i.tool_calls){let l;try{l=JSON.parse(i.tool_calls)}catch{n.push(i),s++;continue}const u=[],r=[],c=[];let f=i.reasoning_content||null,g="completed";const d=i.id,p=i.created_at,h=i.depth;i.status==="pending"?g="pending":i.status==="failed"&&(g="failed"),i.content&&r.push(i.content);for(const k of l)u.push({id:k.id||i.id,type:"tool_call",name:k.function?.name,content:k.function?.arguments||null,status:null,tool_call_id:k.id});let _=s+1;for(;_<t.length;){const k=t[_];if(k.role==="tool"){const D=k.tool_status||"pending";if(u.push({id:k.id,type:"tool_result",name:k.name||void 0,content:k.content,status:D,tool_call_id:k.tool_call_id||void 0}),k.attachments)try{let q;typeof k.attachments=="string"?q=JSON.parse(k.attachments):Array.isArray(k.attachments)?q=k.attachments:q=[],c.push(...q)}catch{}_++}else if(k.role==="assistant"&&k.tool_calls){let D;try{D=JSON.parse(k.tool_calls)}catch{break}k.status==="pending"?g="pending":k.status==="failed"&&g!=="pending"&&(g="failed"),k.content&&r.push(k.content),!f&&k.reasoning_content&&(f=k.reasoning_content);for(const q of D)u.push({id:q.id||k.id,type:"tool_call",name:q.function?.name,content:q.function?.arguments||null,status:null,tool_call_id:q.id});_++}else break}const b=new Set(u.filter(k=>k.type==="tool_call").map(k=>k.tool_call_id)),v=u.filter(k=>k.type==="tool_result"&&k.tool_call_id&&!b.has(k.tool_call_id));for(const k of v){const D=u.indexOf(k),q=k.content?.match(/Tool not found: (\w+)/)?.[1]||"unknown_tool",B={id:`synthetic-${k.tool_call_id}`,type:"tool_call",name:q,content:null,status:k.status,tool_call_id:k.tool_call_id};u.splice(D,0,B)}for(const k of u)if(k.type==="tool_call"&&k.tool_call_id&&k.status===null){const D=u.find(q=>q.type==="tool_result"&&q.tool_call_id===k.tool_call_id);D?k.status=D.status:k.status="pending"}const y=r.length>0?r.join(""):null,x={id:d,type:"workblock",content:y,reasoning_content:f,workItems:u,status:g,created_at:p,depth:h,attachments:c.length>0?c:void 0};n.push(x),s=_}else n.push(i),s++}return n}var da=Symbol("StandardAgents"),ua=Symbol("Thread"),xo={install(t,n){if(!n?.endpoint)throw new Error("StandardAgentsPlugin requires an endpoint option");const i={client:new ia(n.endpoint),endpoint:n.endpoint};t.provide(da,i)}};function yo(){const t=Xt(da);if(!t)throw new Error("useStandardAgents must be used within a component where StandardAgentsPlugin is installed");return t}var Ut=new go;function ko(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>{const u=i.result.split(",")[1];n(u)},i.onerror=()=>s(new Error("Failed to read file")),i.readAsDataURL(t)})}function wo(t,n={}){const{preload:s=!0,live:i=!0,useWorkblocks:l=!1,depth:u=0,includeSilent:r=!1,endpoint:c}=n,f=W(()=>Aa(t)),g=yo(),d=c?new ia(c):g.client,p={preload:s,live:i,useWorkblocks:l,depth:u,includeSilent:r},h=m([]),_=m("disconnected"),b=m(s),v=m(null),y=m([]),x=m([]),k=m([]),D=W(()=>{const I=new Set(x.value.map(F=>F.path));return[...y.value.filter(F=>!F.path||!I.has(F.path)),...x.value]}),q=new Map;let B=null;const N=W(()=>l?bo(h.value):h.value);async function T(){b.value=!0,v.value=null;try{const I=await d.getMessages(f.value,{depth:u,includeSilent:r});h.value=I}catch(I){v.value=I instanceof Error?I:new Error(String(I))}finally{b.value=!1}}async function w(){try{const I=await d.listFiles(f.value);x.value=I.filter(ae=>!ae.isDirectory).map(ae=>({id:ae.path,name:ae.name,path:ae.path,mimeType:ae.mimeType,size:ae.size,isImage:ae.mimeType.startsWith("image/"),status:"committed",localPreviewUrl:null}))}catch(I){console.error("Failed to load files:",I)}}function K(I){if(I.file.isDirectory)return;const ae={id:I.path,name:I.file.name,path:I.path,mimeType:I.file.mimeType,size:I.file.size,isImage:I.file.mimeType?.startsWith("image/")||!1,status:"committed",localPreviewUrl:null},F=x.value.findIndex(G=>G.path===I.path);F>=0?x.value[F]=ae:x.value=[...x.value,ae]}function te(I){if(I.file.isDirectory)return;const ae={id:I.path,name:I.file.name,path:I.path,mimeType:I.file.mimeType,size:I.file.size,isImage:I.file.mimeType?.startsWith("image/")||!1,status:"committed",localPreviewUrl:null},F=x.value.findIndex(G=>G.path===I.path);F>=0?x.value[F]=ae:x.value=[...x.value,ae]}function le(I){x.value=x.value.filter(ae=>ae.path!==I.path)}function H(){i&&(B=new co(d,f.value,{onStatusChange:I=>{_.value=I},onMessage:I=>{if(I.type==="message_data"){const ae=h.value.findIndex(F=>F.id===I.data.id);ae>=0?h.value[ae]=I.data:h.value=[...h.value,I.data]}},onChunk:I=>{const ae=h.value.findIndex(F=>F.id===I.message_id);if(ae>=0){const F=h.value[ae];h.value[ae]={...F,content:(F.content||"")+I.chunk}}},onEvent:I=>{I.eventType==="file_created"?K(I.data):I.eventType==="file_updated"?te(I.data):I.eventType==="file_deleted"&&le(I.data);const ae=q.get(I.eventType);ae&&ae.forEach(F=>{try{F(I.data)}catch(G){console.error(`Error in event listener for "${I.eventType}":`,G)}})},onError:I=>{v.value=I instanceof Error?I:new Error(String(I))}},{depth:u,includeSilent:r}),B.connect())}async function A(I){const ae=`optimistic-${crypto.randomUUID()}`,F=k.value.map(j=>({id:j.id,type:"file",path:"",name:j.name,mimeType:j.mimeType,size:j.size,width:j.width,height:j.height,localPreviewUrl:j.previewUrl||void 0})),G={id:ae,role:I.role,content:I.content,attachments:F.length>0?JSON.stringify(F):null,created_at:Date.now()*1e3,status:"pending"};h.value=[...h.value,G];const z=[...k.value];k.value=[];try{const j=await Promise.all(z.map(async be=>({name:be.name,mimeType:be.mimeType,data:await ko(be.file),width:be.width,height:be.height}))),Q=await d.sendMessage(f.value,{...I,attachments:j.length>0?j:void 0});return h.value=h.value.filter(be=>be.id!==ae),z.forEach(be=>{be.previewUrl&&URL.revokeObjectURL(be.previewUrl)}),Q}catch(j){throw k.value=z,h.value=h.value.filter(Q=>Q.id!==ae),v.value=j instanceof Error?j:new Error(String(j)),j}}async function $(){try{await d.stopExecution(f.value)}catch(I){throw v.value=I instanceof Error?I:new Error(String(I)),I}}async function L(I){const ae=[...h.value];h.value=h.value.filter(F=>F.id!==I);try{await d.deleteMessage(f.value,I)}catch(F){throw h.value=ae,v.value=F instanceof Error?F:new Error(String(F)),F}}function J(I){const ae=Ut.queueFiles(I);y.value=[...y.value,...ae.map(F=>F.pending)];for(const{pending:F,file:G}of ae)Ut.executeUpload(f.value,G,F.id,d,z=>{y.value=y.value.map(j=>j.id===F.id?{...j,...z}:j)}).catch(()=>{})}function ee(I){y.value=y.value.filter(ae=>ae.id!==I)}function E(I){return I.path?d.getFileUrl(f.value,I.path):""}function R(I){return I.path?d.getThumbnailUrl(f.value,I.path):""}function Y(I){return I.isImage?I.localPreviewUrl?I.localPreviewUrl:I.path?R(I):null:null}function ne(I){const F=(I instanceof FileList?Array.from(I):Array.isArray(I)?I:[I]).map(G=>{const z=G.type.startsWith("image/");return{id:crypto.randomUUID(),file:G,name:G.name,mimeType:G.type,size:G.size,isImage:z,previewUrl:z?URL.createObjectURL(G):null}});k.value=[...k.value,...F]}function O(I){const ae=k.value.find(F=>F.id===I);ae?.previewUrl&&URL.revokeObjectURL(ae.previewUrl),k.value=k.value.filter(F=>F.id!==I)}function S(){k.value.forEach(I=>{I.previewUrl&&URL.revokeObjectURL(I.previewUrl)}),k.value=[]}function C(I,ae){return q.has(I)||q.set(I,new Set),q.get(I).add(ae),()=>{const F=q.get(I);F&&(F.delete(ae),F.size===0&&q.delete(I))}}function U(){B?.disconnect(),B=null,_.value="disconnected"}return ve(f,(I,ae)=>{I!==ae&&(U(),h.value=[],v.value=null,y.value=[],x.value=[],k.value.forEach(F=>{F.previewUrl&&URL.revokeObjectURL(F.previewUrl)}),k.value=[],s&&T(),w(),H())}),Ve(()=>{s&&T(),w(),H()}),Be(()=>{B?.disconnect(),q.clear(),k.value.forEach(I=>{I.previewUrl&&URL.revokeObjectURL(I.previewUrl)})}),{threadId:f,options:p,messages:h,workblocks:N,status:_,connectionStatus:_,isLoading:b,loading:b,error:v,sendMessage:A,stopExecution:$,deleteMessage:L,onEvent:C,subscribeToEvent:C,files:D,addFiles:J,removeFile:ee,getFileUrl:E,getThumbnailUrl:R,getPreviewUrl:Y,attachments:k,addAttachment:ne,removeAttachment:O,clearAttachments:S}}var _o=pe({name:"ThreadProvider",props:{threadId:{type:String,required:!0},preload:{type:Boolean,default:void 0},live:{type:Boolean,default:void 0},useWorkblocks:{type:Boolean,default:void 0},depth:{type:Number,default:void 0},includeSilent:{type:Boolean,default:void 0},endpoint:{type:String,default:void 0}},setup(t,{slots:n}){const s={};t.preload!==void 0&&(s.preload=t.preload),t.live!==void 0&&(s.live=t.live),t.useWorkblocks!==void 0&&(s.useWorkblocks=t.useWorkblocks),t.depth!==void 0&&(s.depth=t.depth),t.includeSilent!==void 0&&(s.includeSilent=t.includeSilent),t.endpoint!==void 0&&(s.endpoint=t.endpoint);const i=wo(()=>t.threadId,s);return Pa(ua,i),()=>n.default?.()}});function ca(){const t=Xt(ua);if(!t)throw new Error('useThread must be used within a <ThreadProvider>. Wrap your component with <ThreadProvider threadId="...">.');return t}const $o={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Co(t,n){return a(),o("svg",$o,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 8V4H8"}),e("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),e("path",{d:"M2 14h2m16 0h2m-7-1v2m-6-2v2"})],-1)])])}const Rt=Pe({name:"lucide-bot",render:Co}),To={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function So(t,n){return a(),o("svg",To,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"},null,-1)])])}const Nt=Pe({name:"lucide-message-square",render:So}),Vo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Mo(t,n){return a(),o("svg",Vo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 20v2m0-20v2m5 16v2m0-20v2M2 12h2m-2 5h2M2 7h2m16 5h2m-2 5h2M20 7h2M7 20v2M7 2v2"}),e("rect",{width:"16",height:"16",x:"4",y:"4",rx:"2"}),e("rect",{width:"8",height:"8",x:"8",y:"8",rx:"1"})],-1)])])}const Io=Pe({name:"lucide-cpu",render:Mo}),Eo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Lo(t,n){return a(),o("svg",Eo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e("path",{d:"M6 6h.01M6 18h.01"})],-1)])])}const Ao=Pe({name:"lucide-server",render:Lo}),Po={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Do(t,n){return a(),o("svg",Po,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z"},null,-1)])])}const jo=Pe({name:"lucide-wrench",render:Do}),Oo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Uo(t,n){return a(),o("svg",Oo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0a2.34 2.34 0 0 0 3.319 1.915a2.34 2.34 0 0 1 2.33 4.033a2.34 2.34 0 0 0 0 3.831a2.34 2.34 0 0 1-2.33 4.033a2.34 2.34 0 0 0-3.319 1.915a2.34 2.34 0 0 1-4.659 0a2.34 2.34 0 0 0-3.32-1.915a2.34 2.34 0 0 1-2.33-4.033a2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),e("circle",{cx:"12",cy:"12",r:"3"})],-1)])])}const Ro=Pe({name:"lucide-settings",render:Uo}),No={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Fo(t,n){return a(),o("svg",No,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m15 18l-6-6l6-6"},null,-1)])])}const Bo=Pe({name:"lucide-chevron-left",render:Fo}),qo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function zo(t,n){return a(),o("svg",qo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("circle",{cx:"12",cy:"12",r:"4"}),e("path",{d:"M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"})],-1)])])}const Ho=Pe({name:"lucide-sun",render:zo}),Wo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Jo(t,n){return a(),o("svg",Wo,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"},null,-1)])])}const Ko=Pe({name:"lucide-moon",render:Jo}),Go={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Xo(t,n){return a(),o("svg",Go,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"},null,-1)])])}const Yo=Pe({name:"lucide-activity",render:Xo}),Zo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Qo(t,n){return a(),o("svg",Zo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),e("path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3m-6 4.2h5.7"})],-1)])])}const el=Pe({name:"lucide-function-square",render:Qo}),tl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function al(t,n){return a(),o("svg",tl,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m16 17l5-5l-5-5m5 5H9m0 9H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"},null,-1)])])}const ol=Pe({name:"lucide-log-out",render:al}),ll={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function sl(t,n){return a(),o("svg",ll,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M16 3.128a4 4 0 0 1 0 7.744M22 21v-2a4 4 0 0 0-3-3.87"}),e("circle",{cx:"9",cy:"7",r:"4"})],-1)])])}const nl=Pe({name:"lucide-users",render:sl}),rl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function il(t,n){return a(),o("svg",rl,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"m15.5 7.5l2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4m2-2l-9.6 9.6"}),e("circle",{cx:"7.5",cy:"15.5",r:"5.5"})],-1)])])}const dl=Pe({name:"lucide-key",render:il}),ul={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function cl(t,n){return a(),o("svg",ul,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 7v14m-9-3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4a4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3a3 3 0 0 0-3-3z"},null,-1)])])}const pl=Pe({name:"lucide-book-open",render:cl}),vl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ml(t,n){return a(),o("svg",vl,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 3h6v6m-11 5L21 3m-3 10v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"},null,-1)])])}const fl=Pe({name:"lucide-external-link",render:ml}),pa="agentbuilder-accent-theme",va=["amber","lime","emerald","sky","blue","indigo","purple","fuchsia","pink","white"],_t=m("purple");let Ft=!1;function ma(t){typeof document>"u"||(t==="purple"?delete document.documentElement.dataset.accent:document.documentElement.dataset.accent=t)}function hl(t){try{localStorage.setItem(pa,t)}catch{}}function gl(){try{const t=localStorage.getItem(pa);if(t&&va.includes(t))return t}catch{}return"purple"}function fa(){if(Ft)return;Ft=!0;const t=gl();_t.value=t,ma(t)}function bl(){fa();function t(n){_t.value=n,ma(n),hl(n)}return{theme:_t,themes:va,setTheme:t}}const Ze=pe({__name:"DropShadow",props:{offsetX:{default:8},offsetY:{default:8},intensity:{default:.5},pattern:{default:"crosshatch"}},setup(t){const n=t,s=m(),i=m(),l=m(),u=m(0),r=(d,p,h,_,b,v)=>{d.beginPath(),d.moveTo(p+v,h),d.lineTo(p+_-v,h),d.quadraticCurveTo(p+_,h,p+_,h+v),d.lineTo(p+_,h+b-v),d.quadraticCurveTo(p+_,h+b,p+_-v,h+b),d.lineTo(p+v,h+b),d.quadraticCurveTo(p,h+b,p,h+b-v),d.lineTo(p,h+v),d.quadraticCurveTo(p,h,p+v,h),d.closePath()},c=async()=>{if(await Ce(),!s.value||!i.value||!l.value)return;const d=s.value.getContext("2d");if(!d)return;const p=l.value.getBoundingClientRect(),h=l.value.firstElementChild;if(h){const y=getComputedStyle(h);u.value=parseFloat(y.borderRadius)||0}const _=p.width+n.offsetX+4,b=p.height+n.offsetY+4;s.value.width=_,s.value.height=b,s.value.style.width=`${_}px`,s.value.style.height=`${b}px`,d.clearRect(0,0,s.value.width,s.value.height);const v=document.documentElement.classList.contains("dark");if(d.fillStyle=v?"#6b7280":"black",d.globalAlpha=n.intensity,d.save(),r(d,n.offsetX,n.offsetY,p.width,p.height,u.value),d.clip(),n.pattern==="crosshatch"){const y=v?4:3;d.lineWidth=1,d.strokeStyle=v?"#6b7280":"black";for(let x=-p.height;x<p.width;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY),d.lineTo(n.offsetX+x+p.height,n.offsetY+p.height),d.stroke();for(let x=0;x<p.width+p.height;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY+p.height),d.lineTo(n.offsetX+x-p.height,n.offsetY),d.stroke()}else if(n.pattern==="dots"){const x=v?3:2,k=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];for(let D=0;D<p.width;D+=x)for(let q=0;q<p.height;q+=x){const B=Math.floor(D/x)%4,N=Math.floor(q/x)%4;k[N][B]/16<n.intensity&&d.fillRect(n.offsetX+D,n.offsetY+q,1,1)}}else if(n.pattern==="diagonal"){const y=v?5:4;d.lineWidth=1,d.strokeStyle=v?"#6b7280":"black";for(let x=-p.height;x<p.width;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY),d.lineTo(n.offsetX+x+p.height,n.offsetY+p.height),d.stroke()}d.restore()};let f=null,g=null;return Ve(()=>{f=new ResizeObserver(()=>{c()}),l.value&&f.observe(l.value),c(),g=new MutationObserver(()=>{c()}),g.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})}),Be(()=>{l.value&&f&&f.unobserve(l.value),g&&g.disconnect()}),ve(()=>[n.offsetX,n.offsetY,n.intensity,n.pattern],()=>{c()}),(d,p)=>(a(),o("div",{ref_key:"container",ref:i,class:"relative",style:ot({paddingRight:`${t.offsetX}px`,paddingBottom:`${t.offsetY}px`})},[e("canvas",{ref_key:"canvas",ref:s,class:"absolute top-0 left-0 pointer-events-none"},null,512),e("div",{ref_key:"contentEl",ref:l,class:"relative"},[et(d.$slots,"default")],512)],4))}}),ha="/agents/assets/img/agent-builder-logo-light.svg",ga="/agents/assets/img/agent-builder-logo-dark.svg",xl="data:image/svg+xml,%3csvg%20width='100%25'%20height='100%25'%20viewBox='0%200%20150%20150'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20xml:space='preserve'%20xmlns:serif='http://www.serif.com/'%20style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg%20id='Artboard1'%20transform='matrix(1,0,0,1,1,1)'%3e%3crect%20x='-1'%20y='-1'%20width='150'%20height='150'%20style='fill:none;'/%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.816,92.912L108.064,59.193C103.573,53.307%20101.473,45.937%20102.197,38.566L105.475,5.046L99.553,4.466L96.312,37.643C95.895,41.808%2091.44,44.27%2087.71,42.369L30.34,13.394L27.659,18.7L84.686,47.494C87.184,48.762%2087.076,52.347%2084.504,53.452L0.387,89.671L2.741,95.139L86.189,59.211C88.76,58.106%2091.422,60.587%2090.48,63.231L62.918,141.119L68.532,143.111L96.384,64.408C97.507,61.257%20101.672,60.605%20103.7,63.249L129.107,96.498L133.834,92.876L133.816,92.912Z'%20style='fill:rgb(31,41,55);fill-opacity:0.5;fill-rule:nonzero;'/%3e%3c/g%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.925,90.214L107.648,7.346C106.036,2.257%20100.875,-0.821%2095.624,0.193L32.64,12.344C29.959,12.869%2027.605,14.408%2026.066,16.6C25.523,17.36%2025.07,18.211%2024.744,19.117L0.622,86.284C-0.917,90.594%200.459,95.375%204.081,98.164L59.568,141.137C61.469,142.604%2063.733,143.346%2066.015,143.346C68.079,143.346%2070.144,142.731%2071.937,141.517L129.832,102.111C133.707,99.468%20135.355,94.687%20133.943,90.232L133.925,90.214ZM116.92,85.922L47.127,53.923C44.374,52.673%2043.994,48.925%2046.421,47.132L94.175,11.873C97.416,9.483%20102.034,10.95%20103.284,14.771C108.173,29.548%20118.64,62.054%20124.218,79.457C125.631,83.876%20121.121,87.859%20116.902,85.94L116.92,85.922ZM79.162,15.567L42.455,42.659C40.083,44.415%2036.696,43.057%2036.189,40.16L33.781,26.342C33.038,22.05%2035.845,17.94%2040.119,17.089C49.409,15.241%2065.254,12.145%2076.681,9.917C79.995,9.265%2081.879,13.557%2079.162,15.567ZM29.126,34.238L31.716,49.069C31.915,50.21%2031.607,51.388%2030.865,52.275L16.559,69.587C15.291,71.127%2012.846,69.732%2013.516,67.849L25.704,33.93C26.32,32.21%2028.8,32.427%2029.126,34.22L29.126,34.238ZM12.882,83.386L29.543,63.231C31.517,60.84%2035.356,61.547%2036.352,64.499L56.308,123.661C57.322,126.668%2053.809,129.149%2051.31,127.193C41.223,119.297%2024.4,106.132%2014.404,98.164C9.84,94.542%209.152,87.878%2012.864,83.386L12.882,83.386ZM63.498,126.305L43.161,66.002C42.056,62.706%2045.407,59.681%2048.576,61.13L117.337,92.677C121.375,94.524%20121.864,100.083%20118.206,102.6C107.358,110.061%2088.326,123.064%2076.826,130.815C71.991,134.074%2065.381,131.829%2063.516,126.305L63.498,126.305Z'%20style='fill:rgb(31,41,55);fill-rule:nonzero;'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e",yl="data:image/svg+xml,%3csvg%20width='100%25'%20height='100%25'%20viewBox='0%200%20150%20150'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20xml:space='preserve'%20xmlns:serif='http://www.serif.com/'%20style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg%20id='Artboard1'%20transform='matrix(1,0,0,1,1,1)'%3e%3crect%20x='-1'%20y='-1'%20width='150'%20height='150'%20style='fill:none;'/%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.816,92.912L108.064,59.193C103.573,53.307%20101.473,45.937%20102.197,38.566L105.475,5.046L99.553,4.466L96.312,37.643C95.895,41.808%2091.44,44.27%2087.71,42.369L30.34,13.394L27.659,18.7L84.686,47.494C87.184,48.762%2087.076,52.347%2084.504,53.452L0.387,89.671L2.741,95.139L86.189,59.211C88.76,58.106%2091.422,60.587%2090.48,63.231L62.918,141.119L68.532,143.111L96.384,64.408C97.507,61.257%20101.672,60.605%20103.7,63.249L129.107,96.498L133.834,92.876L133.816,92.912Z'%20style='fill:rgb(249,250,251);fill-opacity:0.5;fill-rule:nonzero;'/%3e%3c/g%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.925,90.214L107.648,7.346C106.036,2.257%20100.875,-0.821%2095.624,0.193L32.64,12.344C29.959,12.869%2027.605,14.408%2026.066,16.6C25.523,17.36%2025.07,18.211%2024.744,19.117L0.622,86.284C-0.917,90.594%200.459,95.375%204.081,98.164L59.568,141.137C61.469,142.604%2063.733,143.346%2066.015,143.346C68.079,143.346%2070.144,142.731%2071.937,141.517L129.832,102.111C133.707,99.468%20135.355,94.687%20133.943,90.232L133.925,90.214ZM116.92,85.922L47.127,53.923C44.374,52.673%2043.994,48.925%2046.421,47.132L94.175,11.873C97.416,9.483%20102.034,10.95%20103.284,14.771C108.173,29.548%20118.64,62.054%20124.218,79.457C125.631,83.876%20121.121,87.859%20116.902,85.94L116.92,85.922ZM79.162,15.567L42.455,42.659C40.083,44.415%2036.696,43.057%2036.189,40.16L33.781,26.342C33.038,22.05%2035.845,17.94%2040.119,17.089C49.409,15.241%2065.254,12.145%2076.681,9.917C79.995,9.265%2081.879,13.557%2079.162,15.567ZM29.126,34.238L31.716,49.069C31.915,50.21%2031.607,51.388%2030.865,52.275L16.559,69.587C15.291,71.127%2012.846,69.732%2013.516,67.849L25.704,33.93C26.32,32.21%2028.8,32.427%2029.126,34.22L29.126,34.238ZM12.882,83.386L29.543,63.231C31.517,60.84%2035.356,61.547%2036.352,64.499L56.308,123.661C57.322,126.668%2053.809,129.149%2051.31,127.193C41.223,119.297%2024.4,106.132%2014.404,98.164C9.84,94.542%209.152,87.878%2012.864,83.386L12.882,83.386ZM63.498,126.305L43.161,66.002C42.056,62.706%2045.407,59.681%2048.576,61.13L117.337,92.677C121.375,94.524%20121.864,100.083%20118.206,102.6C107.358,110.061%2088.326,123.064%2076.826,130.815C71.991,134.074%2065.381,131.829%2063.516,126.305L63.498,126.305Z'%20style='fill:rgb(249,250,251);fill-rule:nonzero;'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e";function kl(){return window.__AGENTBUILDER_CONFIG__||{mountPoint:"/agentbuilder"}}function it(){return kl().mountPoint}function de(t){const n=it(),s=t.startsWith("/")?t:`/${t}`;return n==="/"?s:`${n}${s}`}const wl=["src"],_l=["src"],$l={class:"flex-1 flex flex-col justify-between pt-2 pb-4"},Cl={class:"flex flex-col gap-1 px-2"},Tl={key:0},Sl=["onClick","title"],Vl={key:0,class:"flex-1 whitespace-nowrap overflow-hidden text-ellipsis text-left"},Ml={key:0,class:"ml-4 space-y-0.5"},Il=["onClick"],El={class:"whitespace-nowrap overflow-hidden text-ellipsis"},Ll=["onClick","title"],Al={key:0,class:"whitespace-nowrap overflow-hidden text-ellipsis"},Pl={class:"flex flex-col gap-1 px-2"},Dl=["title"],jl={key:0,class:"flex-1 whitespace-nowrap overflow-hidden text-ellipsis"},Ol={class:"relative settings-menu-container"},Ul={key:0,class:"absolute bottom-full mb-2 left-0 z-50"},Rl={class:"bg-white dark:bg-neutral-900 border border-neutral-300 dark:border-neutral-600 rounded-lg py-2 min-w-[200px]"},Nl={class:"px-4 py-3 border-b border-neutral-200 dark:border-neutral-700"},Fl=["title"],Bl={class:"relative z-10 flex items-center justify-center w-8 h-full"},ql={class:"relative z-10 flex items-center justify-center w-8 h-full"},zl={class:"px-4 pt-3 pb-4 border-b border-neutral-200 dark:border-neutral-700"},Hl={class:"grid grid-cols-5 gap-3"},Wl=["onClick","title"],Jl={key:0,class:"w-2 h-2 rounded-full bg-white shadow-sm"},Kl={key:0,class:"text-sm overflow-hidden whitespace-nowrap max-w-0 group-hover:max-w-[60px] group-hover:ml-2 transition-all duration-200"},Gl=pe({__name:"Sidebar",props:{isCollapsed:{type:Boolean},isDark:{type:Boolean}},emits:["toggle-sidebar","toggle-theme"],setup(t,{emit:n}){function s(le){if(le.startsWith("/src/")||le.startsWith("data:"))return le;const H=it();return H==="/"?le.replace("/agents/","/"):le.replace("/agents/",`${H}/`)}const i=s(ha),l=s(ga),u=s(xl),r=s(yl),c=t,f=Ye(),g=lt(),d=W(()=>f.name);function p(le){const H=f.path;return H===le.path||H.startsWith(le.path+"/")}const h=W(()=>c.isDark?l:i),_=W(()=>c.isDark?r:u),b=[{id:"threads",label:"Threads",icon:Yo,path:"/threads"},{id:"agents",label:"Agents",icon:Rt,path:"/agents"},{id:"prompts",label:"Prompts",icon:Nt,path:"/prompts"},{id:"tools",label:"Tools",icon:jo,path:"/tools",hasSubnav:!0,subnav:[{id:"tools-functions",label:"Functions",icon:el,path:"/tools#functions"},{id:"tools-prompts",label:"Prompts",icon:Nt,path:"/tools#prompts"},{id:"tools-agents",label:"Agents",icon:Rt,path:"/tools#agents"}]},{id:"models",label:"Models",icon:Io,path:"/models"},{id:"providers",label:"Providers",icon:Ao,path:"/providers"}],v=le=>{g.push(le)},y=le=>{g.push(le),k.value=!1},x=W(()=>typeof d.value=="string"&&(d.value==="tools"||d.value.startsWith("tools-"))),k=m(!1),{theme:D,themes:q,setTheme:B}=bl(),N={amber:"bg-amber-500",lime:"bg-lime-500",emerald:"bg-emerald-500",sky:"bg-sky-500",blue:"bg-blue-500",indigo:"bg-indigo-500",purple:"bg-purple-500",fuchsia:"bg-fuchsia-500",pink:"bg-pink-500",white:"bg-neutral-400 dark:bg-neutral-500"},T=W(()=>d.value==="users"||d.value==="api-keys"),w=()=>{k.value=!k.value},K=()=>{localStorage.removeItem("auth_token"),g.push("/login")},te=le=>{const H=le.target;k.value&&!H.closest(".settings-menu-container")&&(k.value=!1)};return Ve(()=>{document.addEventListener("click",te)}),Be(()=>{document.removeEventListener("click",te)}),(le,H)=>(a(),o("aside",{class:oe(["flex flex-col transition-all duration-300 pt-2.5",t.isCollapsed?"w-16":"w-60"])},[e("div",{class:oe(`flex items-center justify-between ${t.isCollapsed?"px-2 py-4":"p-4"}`)},[t.isCollapsed?M("",!0):(a(),o("img",{key:0,src:h.value,alt:"AgentBuilder",class:"h-8 mr-2 mt-0.5"},null,8,wl)),e("button",{onClick:H[0]||(H[0]=A=>le.$emit("toggle-sidebar")),class:oe(`p-1 rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors ${t.isCollapsed?"m-auto":"border border-black/20 dark:border-white/20 opacity-50 hover:opacity-100"}`),"aria-label":"Toggle sidebar"},[t.isCollapsed?(a(),o("img",{key:1,src:_.value,alt:"AgentBuilder",class:"w-7 h-7 m-auto"},null,8,_l)):(a(),se(X(Bo),{key:0,class:"w-5 h-5"}))],2)],2),e("nav",$l,[e("div",Cl,[(a(),o(me,null,ye(b,A=>(a(),o(me,{key:A.id},[A.hasSubnav?(a(),o("div",Tl,[e("button",{onClick:$=>v(A.path),class:oe(["flex items-center gap-3 px-3 py-3 rounded text-sm font-medium transition-all w-full",x.value?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?A.label:void 0},[(a(),se(Qe(A.icon),{class:"w-5 h-5 flex-shrink-0"})),t.isCollapsed?M("",!0):(a(),o("span",Vl,V(A.label),1))],10,Sl),!t.isCollapsed&&A.subnav?(a(),o("div",Ml,[(a(!0),o(me,null,ye(A.subnav,$=>(a(),o("button",{key:$.id,onClick:L=>v($.path),class:oe(["flex items-center gap-3 px-3 py-1.5 text-sm transition-all w-full",d.value===$.id?"bg-black text-white dark:bg-white dark:text-black rounded":"hover:underline"])},[(a(),se(Qe($.icon),{class:"w-4 h-4 flex-shrink-0"})),e("span",El,V($.label),1)],10,Il))),128))])):M("",!0)])):(a(),o("button",{key:1,onClick:$=>v(A.path),class:oe(["flex items-center gap-3 px-3 py-3 rounded text-sm font-medium transition-all",p(A)?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?A.label:void 0},[(a(),se(Qe(A.icon),{class:"w-5 h-5 flex-shrink-0"})),t.isCollapsed?M("",!0):(a(),o("span",Al,V(A.label),1))],10,Ll))],64))),64))]),e("div",Pl,[e("a",{href:"https://docs.standardagentbuilder.com/",target:"_blank",rel:"noopener noreferrer",class:oe(["flex items-center gap-3 px-3 py-2 rounded text-sm transition-all","hover:bg-black/5 dark:hover:bg-white/10 text-neutral-600 dark:text-neutral-400 hover:text-black dark:hover:text-white",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?"Documentation":void 0},[P(X(pl),{class:"w-5 h-5 flex-shrink-0"}),t.isCollapsed?M("",!0):(a(),o("span",jl," Docs ")),t.isCollapsed?M("",!0):(a(),se(X(fl),{key:1,class:"w-3 h-3 flex-shrink-0 opacity-50"}))],10,Dl),e("div",{class:oe(["flex items-center gap-1 pt-2 mt-1 border-t border-black/10 dark:border-white/10",t.isCollapsed?"flex-col":"justify-between"])},[e("div",Ol,[e("button",{onClick:Ie(w,["stop"]),class:oe(["p-2 rounded transition-colors flex items-center",k.value||T.value?"bg-black/10 dark:bg-white/10 text-black dark:text-white":"hover:bg-black/5 dark:hover:bg-white/10 text-neutral-600 dark:text-neutral-400 hover:text-black dark:hover:text-white"]),title:"Settings"},[P(X(Ro),{class:"w-5 h-5 flex-shrink-0"})],2),k.value?(a(),o("div",Ul,[P(Ze,{"offset-x":6,"offset-y":6,intensity:.4},{default:ge(()=>[e("div",Rl,[e("div",Nl,[H[4]||(H[4]=e("div",{class:"text-xs font-bold text-neutral-600 dark:text-neutral-400 pb-3"}," Appearance ",-1)),e("button",{onClick:H[1]||(H[1]=Ie(A=>le.$emit("toggle-theme"),["stop"])),class:"relative flex items-center h-7 rounded-full bg-neutral-200 dark:bg-neutral-800 hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors",title:t.isDark?"Switch to light mode":"Switch to dark mode"},[e("span",{class:oe(["absolute top-0.5 h-6 w-8 rounded-full bg-white dark:bg-black shadow-sm transition-transform duration-200",t.isDark?"translate-x-[calc(100%-2px)]":"translate-x-0.5"])},null,2),e("span",Bl,[P(X(Ho),{class:oe(["w-4 h-4",t.isDark?"text-neutral-500":"text-black"])},null,8,["class"])]),e("span",ql,[P(X(Ko),{class:oe(["w-4 h-4",t.isDark?"text-white":"text-neutral-400"])},null,8,["class"])])],8,Fl)]),e("div",zl,[H[5]||(H[5]=e("div",{class:"text-xs font-bold text-neutral-600 dark:text-neutral-400 pb-3"}," Accent Color ",-1)),e("div",Hl,[(a(!0),o(me,null,ye(X(q),A=>(a(),o("button",{key:A,onClick:Ie($=>X(B)(A),["stop"]),class:oe(["w-6 h-6 rounded-full transition-all flex items-center justify-center ring-1 ring-black/10 dark:ring-white/10",[N[A],X(D)===A?"ring-2 ring-black/50 dark:ring-white/50":"hover:scale-110"]]),title:A.charAt(0).toUpperCase()+A.slice(1)},[X(D)===A?(a(),o("span",Jl)):M("",!0)],10,Wl))),128))])]),e("button",{onClick:H[2]||(H[2]=A=>y("/settings/users")),class:oe(["flex items-center gap-3 px-4 py-2 text-sm transition-all w-full text-left",d.value==="users"?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10"])},[P(X(nl),{class:"w-4 h-4 flex-shrink-0"}),H[6]||(H[6]=e("span",{class:"whitespace-nowrap"},"Users",-1))],2),e("button",{onClick:H[3]||(H[3]=A=>y("/settings/api-keys")),class:oe(["flex items-center gap-3 px-4 py-2 text-sm transition-all w-full text-left",d.value==="api-keys"?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10"])},[P(X(dl),{class:"w-4 h-4 flex-shrink-0"}),H[7]||(H[7]=e("span",{class:"whitespace-nowrap"},"API Keys",-1))],2)])]),_:1})])):M("",!0)]),e("button",{onClick:K,class:"group p-2 rounded hover:bg-red-500/10 transition-colors text-neutral-600 dark:text-neutral-400 hover:text-red-600 dark:hover:text-red-400 flex items-center",title:"Logout"},[P(X(ol),{class:"w-5 h-5 flex-shrink-0"}),t.isCollapsed?M("",!0):(a(),o("span",Kl,"Logout"))])],2)])])],2))}}),Xl={class:"warning-banner-container"},Yl={key:0,class:"warning-banner flex items-center justify-between gap-3 px-4 py-2 bg-amber-50 dark:bg-amber-900/30 border-b border-amber-200 dark:border-amber-800 text-amber-800 dark:text-amber-200 text-sm"},Zl={class:"flex items-center gap-2"},Ql=["onClick"],es=pe({__name:"WarningBanner",setup(t){const n=m([]),s=m(new Set),i=async()=>{if(localStorage.getItem("auth_token"))try{const f=await fetch(de("/api/diagnostics"));if(f.ok){const g=await f.json();n.value=g.warnings||[]}}catch{}},l=c=>{const f=`${c.type}:${c.details?.name||c.message}`;s.value.add(f)},u=c=>{const f=`${c.type}:${c.details?.name||c.message}`;return!s.value.has(f)},r=c=>{if(c.type==="duplicate_tool_name"){const f=c.details?.sources?.join(" and ")||"multiple sources";return`Duplicate tool name "${c.details?.name}" (defined as both ${f}). This may cause unexpected behavior.`}return c.message};return Ve(()=>{i()}),(c,f)=>(a(),o("div",Xl,[(a(!0),o(me,null,ye(n.value,g=>(a(),o(me,{key:`${g.type}:${g.details?.name}`},[u(g)?(a(),o("div",Yl,[e("div",Zl,[f[0]||(f[0]=e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4 flex-shrink-0",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z","clip-rule":"evenodd"})],-1)),e("span",null,V(r(g)),1)]),e("button",{onClick:d=>l(g),class:"text-amber-600 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-200 p-1",title:"Dismiss"},[...f[1]||(f[1]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1)])],8,Ql)])):M("",!0)],64))),128))]))}}),ts={key:2,class:"flex-1 overflow-auto my-3 mr-4 border border-neutral-300 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 flex flex-col"},as={class:"flex-1 overflow-auto"},os=pe({__name:"App",setup(t){fa();const n=Ye(),s=m(!1),i=m(!1),l=W(()=>n.name!=="login"),u=()=>{s.value=!s.value},r=()=>{i.value=!i.value,i.value?(document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark")):(document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light"))};return Ve(()=>{const c=localStorage.getItem("theme");(c==="dark"||!c&&window.matchMedia("(prefers-color-scheme: dark)").matches)&&(i.value=!0,document.documentElement.classList.add("dark"))}),(c,f)=>(a(),o("div",{class:oe(["app-container relative flex h-screen font-sans bg-neutral-50/80 text-black dark:bg-black dark:text-white",{"is-dark":i.value}])},[l.value?(a(),se(Gl,{key:0,"is-collapsed":s.value,"is-dark":i.value,onToggleSidebar:u,onToggleTheme:r},null,8,["is-collapsed","is-dark"])):M("",!0),l.value?(a(),o("main",ts,[P(es),e("div",as,[P(X(Lt))])])):(a(),se(X(Lt),{key:1}))],2))}}),tt=(t,n)=>{const s=t.__vccOpts||t;for(const[i,l]of n)s[i]=l;return s},ls=tt(os,[["__scopeId","data-v-2125e5d3"]]),ss={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ns(t,n){return a(),o("svg",ss,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 11v6m4-6v6m5-11v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},null,-1)])])}const rs=Pe({name:"lucide-trash-2",render:ns}),is={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ds(t,n){return a(),o("svg",is,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})],-1)])])}const us=Pe({name:"lucide-edit",render:ds}),cs={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ps(t,n){return a(),o("svg",cs,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696a10.75 10.75 0 0 1 19.876 0a1 1 0 0 1 0 .696a10.75 10.75 0 0 1-19.876 0"}),e("circle",{cx:"12",cy:"12",r:"3"})],-1)])])}const $t=Pe({name:"lucide-eye",render:ps}),vs={class:"w-full"},ms={class:"border border-black dark:border-neutral-300 rounded overflow-hidden"},fs={class:"overflow-x-auto"},hs={class:"w-full"},gs={class:"border-b border-black dark:border-neutral-300"},bs={key:0,class:"px-4 py-3 text-right font-medium text-sm"},xs={key:0},ys=["colspan"],ks={key:1},ws=["colspan"],_s=["innerHTML"],$s={key:0,class:"px-4 py-3 text-right"},Cs={class:"inline-flex gap-1"},Ts=["onClick","title"],Ge=pe({__name:"DataTable",props:{columns:{},data:{},actions:{},emptyMessage:{default:"No data available"},loading:{type:Boolean,default:!1}},setup(t){const n=u=>{switch(u){case"edit":return us;case"delete":return rs;case"view":return $t;default:return null}},s=(u,r)=>{const c=u[r.key];return r.formatter?r.formatter(c):c??"-"},i=u=>{switch(u){case"center":return"text-center";case"right":return"text-right";default:return"text-left"}},l=(u,r)=>{if(u.confirm){const c=u.confirmMessage||`Are you sure you want to ${u.label.toLowerCase()}?`;confirm(c)&&u.handler(r)}else u.handler(r)};return(u,r)=>(a(),o("div",vs,[e("div",ms,[e("div",fs,[e("table",hs,[e("thead",gs,[e("tr",null,[(a(!0),o(me,null,ye(t.columns,c=>(a(),o("th",{key:c.key,class:oe(["px-4 py-3 font-medium text-sm",i(c.align),c.width||""])},V(c.label),3))),128)),t.actions&&t.actions.length>0?(a(),o("th",bs," Actions ")):M("",!0)])]),e("tbody",null,[t.loading?(a(),o("tr",xs,[e("td",{colspan:t.columns.length+(t.actions?1:0),class:"px-4 py-8 text-center text-neutral-500"},[...r[0]||(r[0]=[e("div",{class:"inline-flex items-center gap-2"},[e("svg",{class:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),$e(" Loading... ")],-1)])],8,ys)])):t.data.length===0?(a(),o("tr",ks,[e("td",{colspan:t.columns.length+(t.actions?1:0),class:"px-4 py-8 text-center text-neutral-500"},V(t.emptyMessage),9,ws)])):(a(!0),o(me,{key:2},ye(t.data,(c,f)=>(a(),o("tr",{key:f,class:"border-t border-neutral-200 dark:border-neutral-800 hover:bg-black/5 dark:hover:bg-white/5 transition-colors"},[(a(!0),o(me,null,ye(t.columns,g=>(a(),o("td",{key:g.key,class:oe(["px-4 py-3 text-sm",i(g.align)])},[et(u.$slots,`cell-${g.key}`,{value:c[g.key],row:c,column:g},()=>[g.html?(a(),o("span",{key:0,innerHTML:s(c,g)},null,8,_s)):(a(),o(me,{key:1},[$e(V(s(c,g)),1)],64))])],2))),128)),t.actions&&t.actions.length>0?(a(),o("td",$s,[e("div",Cs,[(a(!0),o(me,null,ye(t.actions,(g,d)=>(a(),o("button",{key:d,onClick:p=>l(g,c),class:"p-1.5 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",title:g.label},[(a(),se(Qe(n(g.icon)),{class:"w-4 h-4"}))],8,Ts))),128))])])):M("",!0)]))),128))])])])])]))}}),Ss=pe({__name:"AgentsDataTable",emits:["add","edit","delete"],setup(t,{expose:n,emit:s}){const i=s,l=m([]),u=m(!1),r=[{key:"title",label:"Title",width:"w-1/5"},{key:"type",label:"Type",width:"w-1/12",formatter:d=>d==="dual_ai"?"Dual AI":"AI+Human"},{key:"side_a_agent_prompt_name",label:"Side A",width:"w-1/5",formatter:d=>d||"-"},{key:"side_b_agent_prompt_name",label:"Side B",width:"w-1/5",formatter:d=>d||"Human"},{key:"created_at",label:"Created",width:"w-1/6",formatter:d=>d?new Date(d*1e3).toLocaleDateString():"-"}],c=[{icon:"edit",label:"Edit",handler:d=>i("edit",d)},{icon:"delete",label:"Delete",handler:async d=>{await g(d)},confirm:!0,confirmMessage:"Are you sure you want to delete this agent?"}],f=async()=>{u.value=!0;try{const d=await fetch(de("/api/agents"));if(d.ok){const p=await d.json();l.value=p.agents||[]}}catch(d){console.error("Error fetching agents:",d)}finally{u.value=!1}},g=async d=>{try{const p=await fetch(de(`/api/agents/${d.id}`),{method:"DELETE"});if(p.ok)await f();else{const h=await p.json();alert(h.error||"Failed to delete agent")}}catch(p){console.error("Error deleting agent:",p),alert("Failed to delete agent")}};return Ve(()=>{f()}),n({refresh:f}),(d,p)=>(a(),o("div",null,[P(Ge,{columns:r,data:l.value,actions:c,loading:u.value,"empty-message":"No agents available. Create your first agent to get started."},null,8,["data","loading"])]))}}),Vs={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ms(t,n){return a(),o("svg",Vs,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M18 6L6 18M6 6l12 12"},null,-1)])])}const ba=Pe({name:"lucide-x",render:Ms}),Is={key:0,class:"w-full max-w-md"},Es={class:"flex items-center justify-between p-4 border-b-2 border-red-600 flex-shrink-0"},Ls={class:"text-xl font-bold text-red-600"},As={class:"p-6"},Ps={class:"text-neutral-700 dark:text-neutral-300 mb-6"},Ds={class:"flex justify-end gap-3"},xa=pe({__name:"ConfirmDialog",props:{modelValue:{type:Boolean},title:{default:"Confirm Action"},message:{default:"Are you sure you want to continue? You will lose any unsaved changes."},confirmText:{default:"Continue"},cancelText:{default:"Cancel"}},emits:["update:modelValue","confirm","cancel"],setup(t,{emit:n}){const s=t,i=n,l=()=>{i("update:modelValue",!1)},u=()=>{i("confirm"),l()},r=()=>{i("cancel"),l()},c=f=>{f.key==="Escape"&&s.modelValue&&r()};return ve(()=>s.modelValue,f=>{f?(document.addEventListener("keydown",c),document.body.style.overflow="hidden"):(document.removeEventListener("keydown",c),document.body.style.overflow="")}),(f,g)=>(a(),se(rt,{to:"body"},[P(Xe,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-200","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:ge(()=>[t.modelValue?(a(),o("div",{key:0,class:"fixed inset-0 z-[60] flex items-center justify-center p-4 bg-white/80 dark:bg-black/80 backdrop-blur-sm dark:text-white",onClick:r},[P(Xe,{"enter-active-class":"transition-all duration-200","enter-from-class":"opacity-0 scale-95","enter-to-class":"opacity-100 scale-100","leave-active-class":"transition-all duration-200","leave-from-class":"opacity-100 scale-100","leave-to-class":"opacity-0 scale-95"},{default:ge(()=>[t.modelValue?(a(),o("div",Is,[P(Ze,{"offset-x":12,"offset-y":12,intensity:.4},{default:ge(()=>[e("div",{class:"bg-white dark:bg-black border-2 border-red-600 flex flex-col",onClick:g[0]||(g[0]=Ie(()=>{},["stop"]))},[e("div",Es,[e("h2",Ls,V(t.title),1),e("button",{onClick:r,class:"p-1 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors","aria-label":"Close dialog"},[P(X(ba),{class:"w-5 h-5 text-red-600"})])]),e("div",As,[e("p",Ps,V(t.message),1),e("div",Ds,[e("button",{onClick:r,class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors"},V(t.cancelText),1),e("button",{onClick:u,class:"px-4 py-2 border-2 border-red-600 bg-red-600 text-white hover:bg-red-700 hover:border-red-700 transition-colors"},V(t.confirmText),1)])])])]),_:1})])):M("",!0)]),_:1})])):M("",!0)]),_:1})]))}}),js={class:"flex items-center justify-between p-4 border-b-2 border-black dark:border-neutral-300 flex-shrink-0"},Os={class:"text-xl font-bold"},Us={class:"overflow-y-auto flex-1"},Rs={class:"p-6"},Ns={key:0,class:"p-6 border-t-2 border-black dark:border-neutral-300 flex-shrink-0"},He=pe({__name:"Modal",props:{modelValue:{type:Boolean},title:{},width:{default:"max-w-lg"},minHeight:{default:"min-h-[24rem]"},hasChanges:{type:Boolean,default:void 0}},emits:["update:modelValue","close"],setup(t,{emit:n}){const s=t,i=n,l=m(),u=m(!1),r=m(new Map),c=()=>l.value&&(l.value.querySelector("input")||l.value.querySelector("textarea")||l.value.querySelector("select")||l.value.querySelector("[contenteditable]")||l.value.querySelector(".monaco-editor")),f=()=>{if(!l.value)return;l.value.querySelectorAll(".monaco-editor-container").forEach(q=>{const B=q.__monacoEditor;if(B&&typeof B.getValue=="function"){const N=B.getValue();r.value.set(q,N)}})},g=()=>{if(!l.value)return!1;const D=l.value.querySelectorAll(".monaco-editor-container");for(const q of D){const B=q.__monacoEditor;if(B&&typeof B.getValue=="function"){const N=B.getValue(),T=r.value.get(q);if(T===void 0||(B.getRawOptions?.()||{}).readOnly===!0)continue;if(N!==T)return!0}}return!1},d=()=>{if(s.hasChanges!==void 0)return s.hasChanges;if(!l.value)return!1;if(g())return!0;const D=l.value.querySelectorAll("form");for(const B of D){const T=B.querySelectorAll("input, textarea, select");for(const w of T){const K=w;if(K.type==="checkbox"||K.type==="radio"){const te=K;if(te.checked!==te.defaultChecked)return!0}else if(K.tagName==="SELECT"){const te=K;if(te.value!==te.defaultValue)return!0}else if(K.value!==K.defaultValue)return!0}}const q=l.value.querySelectorAll("input:not(form input), textarea:not(form textarea), select:not(form select)");for(const B of q){const N=B;if(N.type==="checkbox"||N.type==="radio"){const T=N;if(T.checked!==T.defaultChecked)return!0}else if(N.tagName==="SELECT"){const T=N;if(T.value!==T.defaultValue)return!0}else if(N.value!==N.defaultValue)return!0}return!1},p=()=>{c()&&d()?u.value=!0:h()},h=()=>{i("update:modelValue",!1),i("close")},_=()=>{u.value=!1,h()},b=()=>{u.value=!1},v=D=>{D.key==="Escape"&&s.modelValue&&(c()||h())};ve(()=>s.modelValue,async D=>{D?(document.addEventListener("keydown",v),document.body.style.overflow="hidden",await Ce(),setTimeout(()=>{f()},100)):(document.removeEventListener("keydown",v),document.body.style.overflow="",r.value.clear())});const y=m(!1),x=D=>{y.value=D.target===D.currentTarget},k=D=>{D.target===D.currentTarget&&y.value&&(c()||h()),y.value=!1};return(D,q)=>(a(),se(rt,{to:"body"},[P(Xe,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-200","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:ge(()=>[t.modelValue?(a(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-white/80 dark:bg-black/80 backdrop-blur-sm dark:text-white",onMousedown:x,onClick:k},[P(Xe,{"enter-active-class":"transition-all duration-200","enter-from-class":"opacity-0 scale-95","enter-to-class":"opacity-100 scale-100","leave-active-class":"transition-all duration-200","leave-from-class":"opacity-100 scale-100","leave-to-class":"opacity-0 scale-95"},{default:ge(()=>[t.modelValue?(a(),o("div",{key:0,class:oe(["w-full",t.width,"max-h-[85vh] flex flex-col"])},[P(Ze,{"offset-x":12,"offset-y":12,intensity:.4},{default:ge(()=>[e("div",{ref_key:"modalRef",ref:l,class:oe(["bg-white dark:bg-black border-2 border-black dark:border-neutral-300 flex flex-col max-h-[85vh]",t.minHeight])},[e("div",js,[e("h2",Os,V(t.title),1),e("button",{onClick:p,class:"p-1 hover:bg-black/5 dark:hover:bg-white/10 rounded transition-colors","aria-label":"Close modal"},[P(X(ba),{class:"w-5 h-5"})])]),e("div",Us,[e("div",Rs,[et(D.$slots,"default")])]),D.$slots.footer?(a(),o("div",Ns,[et(D.$slots,"footer")])):M("",!0)],2)]),_:3})],2)):M("",!0)]),_:3})],32)):M("",!0)]),_:3}),P(xa,{modelValue:u.value,"onUpdate:modelValue":q[0]||(q[0]=B=>u.value=B),title:"Unsaved Changes",message:"You have unsaved changes that will be lost. Are you sure you want to close?","confirm-text":"Close Anyway","cancel-text":"Keep Editing",onConfirm:_,onCancel:b},null,8,["modelValue"])]))}}),Fs={class:"space-y-1.5"},Bs={key:0,class:"block text-sm font-medium text-neutral-700 dark:text-neutral-300"},qs={key:0,class:"text-red-500"},zs=["type","value","placeholder","disabled"],Hs={key:1,class:"text-xs text-red-500 dark:text-red-400"},Ee=pe({__name:"TextInput",props:{modelValue:{},label:{},placeholder:{},type:{default:"text"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","focus","click"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(null),r=W(()=>["w-full px-3 py-2.5 bg-neutral-50 dark:bg-neutral-950 border rounded-md text-sm","focus:outline-none focus:ring-2 focus:ring-neutral-400 dark:focus:ring-neutral-500 focus:border-transparent","transition-colors placeholder:text-neutral-400 dark:placeholder:text-neutral-500",i.error?"border-red-500 dark:border-red-400":"border-neutral-300 dark:border-neutral-800",i.disabled?"opacity-50 cursor-not-allowed":""]),c=d=>{const p=d.target;l("update:modelValue",p.value)},f=d=>{l("focus",d)},g=d=>{l("click",d)};return n({inputRef:u}),(d,p)=>(a(),o("div",Fs,[t.label?(a(),o("label",Bs,[$e(V(t.label)+" ",1),t.required?(a(),o("span",qs,"*")):M("",!0)])):M("",!0),e("input",{ref_key:"inputRef",ref:u,type:t.type,value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,class:oe(r.value),onInput:c,onFocus:f,onClick:g},null,42,zs),t.error?(a(),o("p",Hs,V(t.error),1)):M("",!0)]))}}),Ws={class:"space-y-1"},Js={key:0,class:"block text-sm font-medium"},Ks={key:0,class:"text-red-500"},Gs=["value","placeholder","disabled","rows"],Xs={key:1,class:"text-xs text-red-500 dark:text-red-400"},ya=pe({__name:"TextareaInput",props:{modelValue:{},label:{},placeholder:{},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},rows:{default:4}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=W(()=>["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white","transition-colors resize-y",s.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",s.disabled?"opacity-50 cursor-not-allowed":""]),u=r=>{const c=r.target;i("update:modelValue",c.value)};return(r,c)=>(a(),o("div",Ws,[t.label?(a(),o("label",Js,[$e(V(t.label)+" ",1),t.required?(a(),o("span",Ks,"*")):M("",!0)])):M("",!0),e("textarea",{value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,rows:t.rows,class:oe(l.value),onInput:u},null,42,Gs),t.error?(a(),o("p",Xs,V(t.error),1)):M("",!0)]))}}),Ys={key:0,class:"block text-sm font-medium mb-2"},Zs={key:0,class:"text-red-500"},Qs=["disabled","aria-expanded"],en={class:"flex items-center justify-between gap-1"},tn={key:0,class:"flex items-center gap-2 text-neutral-400 flex-1 min-w-0"},an={key:1,class:"flex items-center gap-2 flex-1 min-w-0"},on=["src","alt"],ln={class:"block truncate"},sn={key:2,class:"block truncate text-neutral-400 flex-1 min-w-0"},nn={class:"bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},rn={class:"p-2 border-b border-neutral-200 dark:border-neutral-700"},dn=["placeholder"],un={class:"max-h-60 overflow-y-auto"},cn={key:0,class:"px-4 py-3 text-sm text-neutral-500 dark:text-neutral-400"},pn=["onClick","onMouseenter"],vn={class:"flex-shrink-0 w-5 h-5 mt-0.5"},mn=["src","alt"],fn={key:1,class:"w-full h-full bg-neutral-200 dark:bg-neutral-700 rounded"},hn={class:"flex-1 min-w-0"},gn={class:"text-sm font-medium text-black dark:text-white"},bn={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},xn={key:2,class:"mt-1 text-xs text-red-500 dark:text-red-400"},Se=pe({__name:"SelectInput",props:{modelValue:{},options:{},placeholder:{default:"Select an option"},searchPlaceholder:{default:"Search..."},label:{},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},error:{},required:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=m(!1),u=m(""),r=m(),c=m(),f=m(),g=m(),d=m(-1),p=W(()=>s.options.find(w=>w.value===s.modelValue)),h=W(()=>["w-full px-3 py-2 text-left rounded focus:outline-none focus:ring-2 bg-white dark:bg-black disabled:opacity-50 disabled:cursor-not-allowed font-mono text-sm overflow-hidden",s.error?"border border-red-500 dark:border-red-400 focus:ring-red-500 dark:focus:ring-red-400":"border border-black dark:border-neutral-300 focus:ring-black dark:focus:ring-white"]),_=W(()=>{if(!u.value)return s.options;const w=u.value.toLowerCase();return s.options.filter(K=>K.label.toLowerCase().includes(w)||K.value.toLowerCase().includes(w)||K.description&&K.description.toLowerCase().includes(w))});ve(_,()=>{d.value=-1});const b=()=>{s.disabled||(l.value?x():(l.value=!0,u.value="",d.value=-1,Ce(()=>{if(g.value&&(g.value.setAttribute("popover","auto"),g.value.addEventListener("toggle",T),"showPopover"in g.value))try{g.value.showPopover()}catch{}k(),setTimeout(()=>r.value?.focus(),0)})))},v=w=>{i("update:modelValue",w.value),x(),u.value="",d.value=-1},y=w=>{w.stopPropagation(),i("update:modelValue","")},x=()=>{if(g.value){if("hidePopover"in g.value)try{g.value.hidePopover()}catch{}g.value.removeEventListener("toggle",T)}l.value=!1,d.value=-1},k=()=>{if(!f.value||!g.value)return;const w=f.value.getBoundingClientRect();g.value.offsetWidth||w.width,g.value.style.position="fixed",g.value.style.top=`${w.bottom+8}px`,g.value.style.left=`${w.left}px`,g.value.style.width=`${w.width}px`,g.value.style.margin="0"},D=w=>{c.value&&!c.value.contains(w.target)&&g.value&&!g.value.contains(w.target)&&x()},q=w=>{w.key==="Escape"&&l.value&&(x(),f.value?.focus())},B=w=>{if(!l.value)return;const K=_.value;if(K.length!==0)switch(w.key){case"ArrowDown":w.preventDefault(),d.value=d.value<K.length-1?d.value+1:0,N();break;case"ArrowUp":w.preventDefault(),d.value=d.value>0?d.value-1:K.length-1,N();break;case"Enter":w.preventDefault(),d.value>=0&&d.value<K.length&&v(K[d.value]);break}},N=()=>{Ce(()=>{const w=g.value?.querySelector(".highlighted-option");w&&w.scrollIntoView({block:"nearest",behavior:"smooth"})})},T=w=>{w.target===g.value&&(l.value=w.newState==="open",l.value&&k())};return Ve(()=>{document.addEventListener("click",D),document.addEventListener("keydown",q);const w=()=>{l.value&&k()};window.addEventListener("resize",w),window.addEventListener("scroll",w,!0)}),Be(()=>{document.removeEventListener("click",D),document.removeEventListener("keydown",q),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}),(w,K)=>(a(),o("div",{ref_key:"dropdownRef",ref:c,class:"relative"},[t.label?(a(),o("label",Ys,[$e(V(t.label)+" ",1),t.required?(a(),o("span",Zs,"*")):M("",!0)])):M("",!0),e("button",{ref_key:"buttonRef",ref:f,type:"button",onClick:b,disabled:t.disabled,"aria-expanded":l.value,"aria-haspopup":!0,class:oe(h.value)},[e("div",en,[t.loading?(a(),o("span",tn,[...K[1]||(K[1]=[e("svg",{class:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1),$e(" Loading... ",-1)])])):p.value?(a(),o("span",an,[p.value.icon?(a(),o("img",{key:0,src:p.value.icon,alt:p.value.label,class:"w-5 h-5 flex-shrink-0"},null,8,on)):M("",!0),e("span",ln,V(p.value.label),1)])):(a(),o("span",sn,V(t.placeholder),1)),p.value&&!t.disabled?(a(),o("button",{key:3,type:"button",onClick:y,class:"flex-shrink-0 p-0.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors","aria-label":"Clear selection"},[...K[2]||(K[2]=[e("svg",{class:"h-4 w-4 text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1)])])):M("",!0),K[3]||(K[3]=e("svg",{class:"h-5 w-5 text-neutral-400 flex-shrink-0",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1))])],10,Qs),l.value?(a(),o("div",{key:1,ref_key:"popoverRef",ref:g,class:"dropdown-popover"},[P(Ze,{"offset-x":4,"offset-y":4,intensity:.3},{default:ge(()=>[e("div",nn,[e("div",rn,[Me(e("input",{ref_key:"searchInput",ref:r,"onUpdate:modelValue":K[0]||(K[0]=te=>u.value=te),type:"text",placeholder:t.searchPlaceholder,onKeydown:B,class:"w-full px-3 py-1.5 text-sm border border-neutral-300 dark:border-neutral-600 rounded focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white bg-white dark:bg-black text-black dark:text-white placeholder:text-neutral-400 dark:placeholder:text-neutral-500"},null,40,dn),[[Oe,u.value]])]),e("div",un,[_.value.length===0?(a(),o("div",cn," No options found ")):M("",!0),(a(!0),o(me,null,ye(_.value,(te,le)=>(a(),o("button",{key:te.value,type:"button",onClick:H=>v(te),onMouseenter:H=>d.value=le,class:oe(["w-full px-4 py-2 text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 focus:bg-neutral-100 dark:focus:bg-neutral-900 focus:outline-none flex items-start gap-3",{"bg-neutral-50 dark:bg-neutral-900":te.value===t.modelValue,"bg-neutral-100 dark:bg-neutral-800 highlighted-option":le===d.value}])},[e("div",vn,[te.icon?(a(),o("img",{key:0,src:te.icon,alt:te.label,class:"w-full h-full"},null,8,mn)):(a(),o("div",fn))]),e("div",hn,[e("div",gn,V(te.label),1),te.description?(a(),o("div",bn,V(te.description),1)):M("",!0)])],42,pn))),128))])])]),_:1})],512)):M("",!0),t.error?(a(),o("p",xn,V(t.error),1)):M("",!0)],512))}}),yn={class:"flex items-start"},kn=["for"],wn=["id","checked","disabled"],_n={class:"flex items-center h-5"},$n={class:"flex-1"},Cn={key:0,class:"text-red-500"},Tn={key:1,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-1"},Sn={key:2,class:"text-xs text-red-500 dark:text-red-400 mt-1"},Ae=pe({__name:"CheckboxInput",props:{modelValue:{type:Boolean,default:!1},label:{},helpText:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},error:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=Da(),u=W(()=>["w-5 h-5 border-2 rounded relative flex-shrink-0","transition-all duration-150",s.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",s.disabled?"opacity-50":"hover:scale-110",s.modelValue?"bg-black dark:bg-white":"bg-white dark:bg-black","before:content-[''] before:absolute before:inset-0 before:m-auto before:w-2.5 before:h-1.5 before:border-white dark:before:border-black before:border-b-2 before:border-l-2 before:rotate-[-45deg]",s.modelValue?"before:block":"before:hidden"]),r=c=>{if(!s.disabled){const f=c.target;i("update:modelValue",f.checked)}};return(c,f)=>(a(),o("div",yn,[e("label",{for:X(l),class:oe(["flex items-start space-x-3 cursor-pointer select-none",{"cursor-not-allowed":t.disabled}])},[e("input",{id:X(l),type:"checkbox",checked:t.modelValue,disabled:t.disabled,onChange:r,class:"absolute left-[-9999px]"},null,40,wn),e("div",_n,[e("span",{class:oe(u.value)},null,2)]),e("div",$n,[t.label?(a(),o("span",{key:0,class:oe(["block text-sm font-medium",{"opacity-50":t.disabled}])},[$e(V(t.label)+" ",1),t.required?(a(),o("span",Cn,"*")):M("",!0)],2)):M("",!0),t.helpText?(a(),o("p",Tn,V(t.helpText),1)):M("",!0),t.error?(a(),o("p",Sn,V(t.error),1)):M("",!0)])],10,kn)]))}}),Vn={class:"space-y-4"},Mn={class:"flex items-start gap-2"},In={class:"flex-1"},En=["onClick","disabled","title"],Ln={key:0,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},An={key:1,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Pn={key:0,class:"text-xs text-neutral-400 dark:text-neutral-500 mt-1"},Dn={key:0,class:"text-amber-500 dark:text-amber-400 ml-1"},jn={class:"flex-1"},On={class:"flex-1"},Un=["onClick","disabled"],Rn=["disabled"],ka=pe({__name:"TenvPropertyList",props:{modelValue:{},inherited:{default:()=>[]},allowCustom:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=m(new Set),u=m([]),r=W(()=>new Set(s.inherited.map(v=>v.name)));ve(()=>s.modelValue,v=>{const y=Object.keys(v).filter(k=>!r.value.has(k)),x=new Set(u.value.map(k=>k.name));for(const k of y)x.has(k)||u.value.push({id:crypto.randomUUID(),name:k,value:String(v[k]??"")})},{immediate:!0,deep:!0});const c=v=>{if(l.value.has(v)){l.value.delete(v);const y=s.inherited.find(x=>x.name===v);y&&f(v,y.value)}else l.value.add(v)},f=(v,y)=>{const x={...s.modelValue};y===void 0||y===""?delete x[v]:x[v]=y,i("update:modelValue",x)},g=v=>s.modelValue[v.name]!==void 0?String(s.modelValue[v.name]):v.value!==void 0?String(v.value):"",d=(v,y)=>{f(v.name,y||void 0)},p=()=>{u.value.push({id:crypto.randomUUID(),name:"",value:""})},h=v=>{const y=u.value.find(x=>x.id===v);if(y&&y.name){const x={...s.modelValue};delete x[y.name],i("update:modelValue",x)}u.value=u.value.filter(x=>x.id!==v)},_=(v,y,x)=>{const k=u.value.find(q=>q.id===v);if(!k)return;k.name=x;const D={...s.modelValue};y&&delete D[y],x&&k.value&&(D[x]=k.value),i("update:modelValue",D)},b=(v,y)=>{const x=u.value.find(k=>k.id===v);x&&(x.value=y,x.name&&f(x.name,y||void 0))};return(v,y)=>(a(),o("div",Vn,[(a(!0),o(me,null,ye(t.inherited,x=>(a(),o("div",{key:x.name,class:"relative"},[e("div",Mn,[e("div",In,[P(Ee,{"model-value":g(x),label:x.name,placeholder:x.description||"Enter value...",disabled:t.disabled||!l.value.has(x.name),required:x.required,"onUpdate:modelValue":k=>d(x,k)},null,8,["model-value","label","placeholder","disabled","required","onUpdate:modelValue"])]),e("button",{type:"button",onClick:k=>c(x.name),disabled:t.disabled,class:"mt-7 p-2 text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300 transition-colors disabled:opacity-50",title:l.value.has(x.name)?"Lock (use inherited value)":"Unlock to override"},[l.value.has(x.name)?(a(),o("svg",An,[...y[1]||(y[1]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"},null,-1)])])):(a(),o("svg",Ln,[...y[0]||(y[0]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"},null,-1)])]))],8,En)]),x.source?(a(),o("p",Pn,[$e(" From: "+V(x.source)+" ",1),x.required?(a(),o("span",Dn,"(required)")):M("",!0)])):M("",!0)]))),128)),(a(!0),o(me,null,ye(u.value,x=>(a(),o("div",{key:x.id,class:"flex items-start gap-2"},[e("div",jn,[P(Ee,{"model-value":x.name,label:"Name",placeholder:"Variable name",disabled:t.disabled,"onUpdate:modelValue":k=>_(x.id,x.name,k)},null,8,["model-value","disabled","onUpdate:modelValue"])]),e("div",On,[P(Ee,{"model-value":x.value,label:"Value",placeholder:"Variable value",disabled:t.disabled,"onUpdate:modelValue":k=>b(x.id,k)},null,8,["model-value","disabled","onUpdate:modelValue"])]),e("button",{type:"button",onClick:k=>h(x.id),disabled:t.disabled,class:"mt-7 p-2 text-red-400 hover:text-red-600 dark:hover:text-red-300 transition-colors disabled:opacity-50",title:"Remove"},[...y[2]||(y[2]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,Un)]))),128)),t.allowCustom?(a(),o("button",{key:0,type:"button",onClick:p,disabled:t.disabled,class:"w-full px-3 py-2 text-sm bg-neutral-50 dark:bg-neutral-900 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded transition-colors disabled:opacity-50 border border-dashed border-neutral-300 dark:border-neutral-700"},[...y[3]||(y[3]=[e("span",{class:"flex items-center justify-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),$e(" Add custom variable ")],-1)])],8,Rn)):M("",!0)]))}});async function ze(t,n={}){const s=localStorage.getItem("auth_token"),i={"Content-Type":"application/json",...n.headers};s&&(i.Authorization=`Bearer ${s}`);const l=t.startsWith("/")?t:`/${t}`,u=await fetch(de(`/api${l}`),{...n,headers:i});if(u.status===401)throw localStorage.removeItem("auth_token"),window.location.href=de("/login"),new Error("Unauthorized");return u}const Nn={key:0,class:"min-h-[400px] flex items-center justify-center"},Fn={key:1,class:"space-y-6 pr-2 pb-4"},Bn={key:0,class:"p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg"},qn={class:"text-sm text-red-800 dark:text-red-200"},zn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Hn={key:1,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Wn={key:1},Jn={key:2},Kn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Gn={key:3},Xn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Yn={class:"grid grid-cols-2 gap-6"},Zn={class:"space-y-4 p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},Qn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},er={class:"space-y-3"},tr={class:"flex items-start"},ar={key:0,class:"ml-8 mt-2 space-y-2"},or={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-1"},lr={key:1},sr={key:0,class:"mt-3 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded"},nr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},rr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},ir={class:"space-y-4 p-4 bg-neutral-100 dark:bg-neutral-800 rounded-lg"},dr={class:"font-semibold text-base mb-4 text-neutral-800 dark:text-neutral-200"},ur={key:0,class:"flex flex-col items-center justify-center py-8"},cr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},pr={class:"space-y-3"},vr={class:"flex items-start"},mr={key:0,class:"ml-8 mt-2 space-y-2"},fr={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-1"},hr={key:1},gr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},br={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},xr={key:4,class:"space-y-3"},yr={class:"flex items-center justify-between"},kr={key:0,class:"text-xs text-neutral-500"},wr={class:"flex justify-between"},_r=["disabled"],$r=pe({__name:"AgentModal",props:{modelValue:{type:Boolean},editAgent:{},mode:{},apiError:{}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=W(()=>s.mode==="edit"),u=m(!1),r=m(""),c=m(""),f=m(""),g=m(null),d=m(""),p=m("dual_ai"),h=m(!1),_=m(""),b=m(""),v=m(null),y=m(""),x=m(""),k=m(""),D=m(""),q=m(!0),B=m(!1),N=m(""),T=m(""),w=m(""),K=m(""),te=m(!1),le=m(null),H=m(""),A=m(""),$=m(""),L=m(""),J=m(""),ee=m(""),E=m(!0),R=m(!1),Y=m(""),ne=m(""),O=m(""),S=m(""),C=m(null),U=m(""),I=m(""),ae=m(""),F=m([]),G=m({}),z=m(!1),{data:j,execute:Q}=Ue(de("/api/prompts"),{immediate:!1}).json(),{data:be,execute:De}=Ue(de("/api/tools?schema=true"),{immediate:!1}).json(),ie=m(null),ce=m(!1),ue=m(null),we=m(!1),ke=m(!1),Le=W(()=>{if(!j.value)return[{value:"",label:"Select a prompt..."}];const he=j.value?.prompts||[];return[{value:"",label:"None"},...he.map(Z=>({value:Z.id,label:Z.name}))]}),Fe=he=>be.value?be.value[he]:null,Re=W(()=>!ie.value||!ie.value.tools?[{value:"",label:"None"}]:[{value:"",label:"None"},...ie.value.tools.map(he=>{const Z=typeof he=="string"?he:he.name;return{value:Z,label:Z}})]),xe=W(()=>!ue.value||!ue.value.tools?[{value:"",label:"None"}]:[{value:"",label:"None"},...ue.value.tools.map(he=>{const Z=typeof he=="string"?he:he.name;return{value:Z,label:Z}})]),fe=W(()=>{if(!N.value)return[];const he=Fe(N.value);return!he||!he.schema||!he.schema.properties?[]:Object.keys(he.schema.properties).map(Z=>({value:Z,label:Z}))}),_e=W(()=>{if(!Y.value)return[];const he=Fe(Y.value);return!he||!he.schema||!he.schema.properties?[]:Object.keys(he.schema.properties).map(Z=>({value:Z,label:Z}))}),Ne=async()=>{const he=[k.value,J.value].filter(Boolean);if(he.length===0){F.value=[];return}z.value=!0;try{const Z=[],re=new Set;for(const qe of he){const je=await ze(`/prompts/${qe}/tenvs`);if(je.ok){const gt=await je.json();for(const Je of gt.tenvs||[])re.has(Je.name)||(re.add(Je.name),Z.push({name:Je.name,value:Je.value,required:Je.required,description:Je.description,source:Je.source}))}}F.value=Z}catch(Z){console.error("Error fetching tenvs from prompts:",Z),F.value=[]}finally{z.value=!1}},ht=[{value:"dual_ai",label:"AI + AI (Subagent)"},{value:"ai_human",label:"AI + Human"}],It=W({get(){return c.value},set(he){const Z=g.value?.inputRef,re=Z?.selectionStart??he.length;let qe=he.toLowerCase().replace(/\s+/g,"_").replace(/[^a-z0-9_]/g,"");if(qe.endsWith("_agent")||(qe=qe+"_agent"),c.value=qe,Z){Z.value=qe;const je=Math.min(re,qe.length-6);Z.setSelectionRange(je,je)}}}),Et=async()=>{await Ce();const he=g.value?.inputRef;if(he&&c.value.endsWith("_agent")){const Z=c.value.length-6;he.setSelectionRange(Z,Z)}},Sa=he=>!he||he==="_agent"?(f.value="Name is required",!1):/^[a-z][a-z0-9_]*_agent$/.test(he)?(f.value="",!0):(f.value="Name must start with a letter",!1),dt=()=>{c.value="",r.value="",f.value="",d.value="",p.value="dual_ai",h.value=!1,_.value="",b.value="",v.value=null,y.value="",k.value="",D.value="",q.value=!0,B.value=!1,N.value="",T.value="",w.value="",K.value="",te.value=!1,le.value=null,H.value="",A.value="",$.value="",ie.value=null,J.value="",ee.value="",E.value=!0,R.value=!1,Y.value="",ne.value="",O.value="",S.value="",C.value=null,U.value="",I.value="",ae.value="",ue.value=null,F.value=[],G.value={}},Va=async()=>{if(s.editAgent?.id){u.value=!0,ke.value=!0;try{const he=await fetch(de(`/api/agents/${s.editAgent.id}`));if(he.ok){const Z=await he.json(),re=Z.agent||Z;c.value=re.name||"",r.value=re.name||"",d.value=re.title||"",p.value=re.type||"dual_ai",h.value=re.expose_as_tool||!1,_.value=re.tool_description||"",v.value=re.max_session_turns;const qe=re.side_a_stop_tool||"",je=re.side_a_stop_tool_response_property||"",gt=re.side_b_stop_tool||"",Je=re.side_b_stop_tool_response_property||"",Ea=re.side_a_end_conversation_tool||"",La=re.side_b_end_conversation_tool||"";x.value=re.side_a_label||"",L.value=re.side_b_label||"",k.value=re.side_a_agent_prompt||"",J.value=re.side_b_agent_prompt||"",q.value=!!re.side_a_stop_on_response,B.value=!!re.side_a_stop_tool,te.value=!!re.side_a_manual_stop_condition,le.value=re.side_a_max_steps,E.value=!!re.side_b_stop_on_response,R.value=!!re.side_b_stop_tool,C.value=re.side_b_max_steps,await Ce(),N.value=qe,w.value=je,Y.value=gt,O.value=Je,A.value=Ea,I.value=La,re.tenvs&&typeof re.tenvs=="object"&&(G.value=re.tenvs),await Ne()}}catch(he){console.error("Error loading agent data:",he)}finally{u.value=!1,ke.value=!1}}},Ma=async()=>{f.value="",y.value="",D.value="",T.value="",K.value="",H.value="",$.value="",ee.value="",ne.value="",S.value="",U.value="",ae.value="";let he=!1;Sa(c.value)||(he=!0);const Z=c.value;p.value==="dual_ai"&&v.value!==null&&v.value!==void 0&&v.value<=0&&(y.value="Max session turns must be a positive number",he=!0),k.value||(D.value="Please select an agent prompt",he=!0);const re=q.value||N.value,qe=p.value==="ai_human"&&te.value;if(!re&&!qe&&(D.value="At least one stop condition is required (or check manual stop condition for ai_human agents)",he=!0),N.value&&!w.value&&(K.value="Response property required when using stop tool",he=!0),le.value!==null&&le.value<=0&&(H.value="Max steps must be a positive number",he=!0),p.value==="dual_ai"&&!A.value&&!I.value&&($.value="At least one side must have an end conversation tool",ae.value="At least one side must have an end conversation tool",he=!0),p.value==="dual_ai"&&(J.value||(ee.value="Please select an agent prompt",he=!0),Y.value&&!O.value&&(S.value="Response property required when using stop tool",he=!0),C.value!==null&&C.value<=0&&(U.value="Max steps must be a positive number",he=!0)),he)return;const je={name:Z,title:d.value||null,type:p.value,expose_as_tool:h.value,tool_description:h.value?_.value:null,max_session_turns:p.value==="dual_ai"?v.value:null,side_a_label:x.value||null,side_a_agent_prompt:k.value,side_a_stop_on_response:q.value,side_a_stop_tool:N.value||null,side_a_stop_tool_response_property:w.value||null,side_a_manual_stop_condition:te.value,side_a_max_steps:le.value,side_a_end_conversation_tool:A.value||null};p.value==="dual_ai"&&(je.side_b_label=L.value||null,je.side_b_agent_prompt=J.value,je.side_b_stop_on_response=E.value,je.side_b_stop_tool=Y.value||null,je.side_b_stop_tool_response_property=O.value||null,je.side_b_max_steps=C.value,je.side_b_end_conversation_tool=I.value||null),Object.keys(G.value).length>0&&(je.tenvs=G.value),l.value&&s.editAgent?.id&&(je.id=s.editAgent.id),i("save",je)},Ia=()=>{dt(),i("update:modelValue",!1)};return ve(k,async he=>{if(ke.value||(N.value="",w.value=""),!he){ie.value=null;return}ce.value=!0;try{const Z=await fetch(de(`/api/prompts/${he}`));Z.ok&&(ie.value=await Z.json())}catch(Z){console.error("Error fetching Side A prompt:",Z)}finally{ce.value=!1}ke.value||await Ne()}),ve(J,async he=>{if(ke.value||(Y.value="",O.value=""),!he){ue.value=null;return}we.value=!0;try{const Z=await fetch(de(`/api/prompts/${he}`));Z.ok&&(ue.value=await Z.json())}catch(Z){console.error("Error fetching Side B prompt:",Z)}finally{we.value=!1}ke.value||await Ne()}),ve(B,he=>{he||(N.value="",w.value="")}),ve(R,he=>{he||(Y.value="",O.value="")}),ve(()=>s.modelValue,async he=>{he?(await Promise.all([Q(),De()]),l.value?(dt(),await Va()):dt()):dt()}),(he,Z)=>(a(),se(He,{"model-value":t.modelValue,"onUpdate:modelValue":Z[24]||(Z[24]=re=>he.$emit("update:modelValue",re)),title:l.value?"Edit Agent":"Create Agent",width:"max-w-6xl"},{footer:ge(()=>[e("div",wr,[e("button",{onClick:Ia,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:Ma,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:u.value},V(l.value?"Update Agent":"Create Agent"),9,_r)])]),default:ge(()=>[u.value?(a(),o("div",Nn,[...Z[25]||(Z[25]=[e("span",{class:"text-neutral-500"},"Loading agent data...",-1)])])):(a(),o("div",Fn,[t.apiError?(a(),o("div",Bn,[e("p",qn,V(t.apiError),1)])):M("",!0),e("div",null,[P(Ee,{ref_key:"nameInputRef",ref:g,modelValue:It.value,"onUpdate:modelValue":Z[0]||(Z[0]=re=>It.value=re),label:"Agent Name",error:f.value,required:"",disabled:l.value,onFocus:Et,onClick:Et},null,8,["modelValue","error","disabled"]),!f.value&&!l.value?(a(),o("p",zn," Automatically formatted to snake_case with _agent suffix (e.g., research_agent) ")):M("",!0),l.value?(a(),o("p",Hn," Agent names cannot be changed after creation (used as foreign key for threads) ")):M("",!0)]),e("div",null,[P(Ee,{modelValue:d.value,"onUpdate:modelValue":Z[1]||(Z[1]=re=>d.value=re),label:"Display Title (Optional)"},null,8,["modelValue"]),Z[26]||(Z[26]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Human-readable title shown in the UI (e.g., Research Assistant). If not set, the name will be used. ",-1))]),e("div",null,[P(Se,{modelValue:p.value,"onUpdate:modelValue":Z[2]||(Z[2]=re=>p.value=re),label:"Agent Type",options:ht},null,8,["modelValue"]),Z[27]||(Z[27]=e("p",{class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"}," Choose between two AI agents conversing, or an AI agent conversing with a human ",-1))]),p.value==="dual_ai"?(a(),o("div",Wn,[P(Ae,{modelValue:h.value,"onUpdate:modelValue":Z[3]||(Z[3]=re=>h.value=re),label:"Expose as Tool"},null,8,["modelValue"]),Z[28]||(Z[28]=e("p",{class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"}," Make this subagent available as a tool that can be called by other prompts or agents. When called, it will execute as a subagent. ",-1))])):M("",!0),h.value&&p.value==="dual_ai"?(a(),o("div",Jn,[P(ya,{modelValue:_.value,"onUpdate:modelValue":Z[4]||(Z[4]=re=>_.value=re),label:"Tool Description",placeholder:"Describe what this agent does when called as a tool",error:b.value,rows:3},null,8,["modelValue","error"]),b.value?M("",!0):(a(),o("p",Kn," This description helps other agents understand when to use this agent "))])):M("",!0),p.value==="dual_ai"?(a(),o("div",Gn,[P(Ee,{"model-value":v.value?.toString()||"","onUpdate:modelValue":Z[5]||(Z[5]=re=>v.value=re?parseInt(re):null),label:"Max Session Turns",type:"number",error:y.value,placeholder:"Unlimited"},null,8,["model-value","error"]),y.value?M("",!0):(a(),o("p",Xn," Maximum number of back-and-forth exchanges between the two agents before the conversation ends "))])):M("",!0),e("div",Yn,[e("div",Zn,[Z[35]||(Z[35]=e("h4",{class:"font-semibold text-base mb-4 text-neutral-800 dark:text-neutral-200"}," Side A (AI) ",-1)),e("div",null,[P(Ee,{modelValue:x.value,"onUpdate:modelValue":Z[6]||(Z[6]=re=>x.value=re),label:"Side Label (Optional)",placeholder:"e.g., ATC, Pilot, Customer, Support"},null,8,["modelValue"]),Z[29]||(Z[29]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Custom label for this side (shows in message bubbles and toggle) ",-1))]),e("div",null,[P(Se,{modelValue:k.value,"onUpdate:modelValue":Z[7]||(Z[7]=re=>k.value=re),label:"Agent Prompt",options:Le.value,error:D.value,required:""},null,8,["modelValue","options","error"]),D.value?M("",!0):(a(),o("p",Qn," The prompt that defines this agent's behavior "))]),e("div",er,[Z[32]||(Z[32]=e("label",{class:"block text-sm font-medium"}," Stop Conditions ",-1)),Z[33]||(Z[33]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Optional. If no stop conditions are set, the agent will continue until programmatically stopped or end conversation tool is called. ",-1)),e("div",tr,[P(Ae,{modelValue:q.value,"onUpdate:modelValue":Z[8]||(Z[8]=re=>q.value=re),label:"Stop when agent returns content"},null,8,["modelValue"])]),Z[34]||(Z[34]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-2 ml-6"}," Agent stops when it returns a response without calling tools ",-1)),e("div",null,[P(Ae,{modelValue:B.value,"onUpdate:modelValue":Z[9]||(Z[9]=re=>B.value=re),label:"Stop on specific tool call"},null,8,["modelValue"]),B.value?(a(),o("div",ar,[P(Se,{modelValue:N.value,"onUpdate:modelValue":Z[10]||(Z[10]=re=>N.value=re),label:"Stop Tool",options:Re.value,error:T.value,placeholder:"Select a tool...",disabled:ce.value||!k.value},null,8,["modelValue","options","error","disabled"]),T.value?M("",!0):(a(),o("p",or," Agent stops when this tool is called ")),N.value?(a(),o("div",lr,[P(Se,{modelValue:w.value,"onUpdate:modelValue":Z[11]||(Z[11]=re=>w.value=re),label:"Response Property",options:fe.value,error:K.value,placeholder:"Select property..."},null,8,["modelValue","options","error"]),Z[30]||(Z[30]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Property from tool arguments to return as final response ",-1))])):M("",!0)])):M("",!0)]),p.value==="ai_human"&&!q.value&&!B.value?(a(),o("div",sr,[P(Ae,{modelValue:te.value,"onUpdate:modelValue":Z[12]||(Z[12]=re=>te.value=re),label:"I have manually implemented a stop condition"},null,8,["modelValue"]),Z[31]||(Z[31]=e("p",{class:"mt-2 text-xs text-yellow-800 dark:text-yellow-200"}," ⚠️ Warning: Only check this if you have implemented a custom stop condition in your code (e.g., via hooks or custom logic). Without a stop condition, the agent may run indefinitely. ",-1))])):M("",!0)]),e("div",null,[P(Ee,{"model-value":le.value?.toString()||"","onUpdate:modelValue":Z[13]||(Z[13]=re=>le.value=re?parseInt(re):null),label:"Max Steps",type:"number",error:H.value,placeholder:"Unlimited"},null,8,["model-value","error"]),H.value?M("",!0):(a(),o("p",nr," Maximum steps this side can take before yielding (safety limit) "))]),e("div",null,[P(Se,{modelValue:A.value,"onUpdate:modelValue":Z[14]||(Z[14]=re=>A.value=re),label:"End Conversation Tool",options:Re.value,error:$.value,placeholder:"Select a tool...",disabled:ce.value||!k.value},null,8,["modelValue","options","error","disabled"]),$.value?M("",!0):(a(),o("p",rr," Tool that ends the entire conversation when called "))])]),e("div",ir,[e("h4",dr," Side B ("+V(p.value==="ai_human"?"Human":"AI")+") ",1),e("div",null,[P(Ee,{modelValue:L.value,"onUpdate:modelValue":Z[15]||(Z[15]=re=>L.value=re),label:"Side Label (Optional)",placeholder:"e.g., ATC, Pilot, Customer, Support"},null,8,["modelValue"]),Z[36]||(Z[36]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Custom label for this side (shows in message bubbles and toggle) ",-1))]),p.value==="ai_human"?(a(),o("div",ur,[...Z[37]||(Z[37]=[e("svg",{class:"w-20 h-20 mb-4 text-neutral-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})],-1),e("h5",{class:"font-medium text-lg mb-2"},"Human User",-1),e("p",{class:"text-sm text-neutral-500 dark:text-neutral-400 text-center max-w-xs"}," This side of the conversation will be handled by a human user through the interface ",-1)])])):(a(),o(me,{key:1},[e("div",null,[P(Se,{modelValue:J.value,"onUpdate:modelValue":Z[16]||(Z[16]=re=>J.value=re),label:"Agent Prompt",options:Le.value,error:ee.value,required:""},null,8,["modelValue","options","error"]),ee.value?M("",!0):(a(),o("p",cr," The prompt that defines this agent's behavior "))]),e("div",pr,[Z[39]||(Z[39]=e("label",{class:"block text-sm font-medium"}," Stop Conditions ",-1)),Z[40]||(Z[40]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Optional. If no stop conditions are set, the agent will continue until programmatically stopped or end conversation tool is called. ",-1)),e("div",vr,[P(Ae,{modelValue:E.value,"onUpdate:modelValue":Z[17]||(Z[17]=re=>E.value=re),label:"Stop when agent returns content"},null,8,["modelValue"])]),Z[41]||(Z[41]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-2 ml-6"}," Agent stops when it returns a response without calling tools ",-1)),e("div",null,[P(Ae,{modelValue:R.value,"onUpdate:modelValue":Z[18]||(Z[18]=re=>R.value=re),label:"Stop on specific tool call"},null,8,["modelValue"]),R.value?(a(),o("div",mr,[P(Se,{modelValue:Y.value,"onUpdate:modelValue":Z[19]||(Z[19]=re=>Y.value=re),label:"Stop Tool",options:xe.value,error:ne.value,placeholder:"Select a tool...",disabled:we.value||!J.value},null,8,["modelValue","options","error","disabled"]),ne.value?M("",!0):(a(),o("p",fr," Agent stops when this tool is called ")),Y.value?(a(),o("div",hr,[P(Se,{modelValue:O.value,"onUpdate:modelValue":Z[20]||(Z[20]=re=>O.value=re),label:"Response Property",options:_e.value,error:S.value,placeholder:"Select property..."},null,8,["modelValue","options","error"]),Z[38]||(Z[38]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Property from tool arguments to return as final response ",-1))])):M("",!0)])):M("",!0)])]),e("div",null,[P(Ee,{"model-value":C.value?.toString()||"","onUpdate:modelValue":Z[21]||(Z[21]=re=>C.value=re?parseInt(re):null),label:"Max Steps",type:"number",error:U.value,placeholder:"Unlimited"},null,8,["model-value","error"]),U.value?M("",!0):(a(),o("p",gr," Maximum steps this side can take before yielding (safety limit) "))]),e("div",null,[P(Se,{modelValue:I.value,"onUpdate:modelValue":Z[22]||(Z[22]=re=>I.value=re),label:"End Conversation Tool",options:xe.value,error:ae.value,placeholder:"Select a tool...",disabled:we.value||!J.value},null,8,["modelValue","options","error","disabled"]),ae.value?M("",!0):(a(),o("p",br," Tool that ends the entire conversation when called "))])],64))])]),F.value.length>0||Object.keys(G.value).length>0?(a(),o("div",xr,[e("div",yr,[Z[42]||(Z[42]=e("label",{class:"block text-sm font-medium"},"Thread Environment Variables",-1)),z.value?(a(),o("span",kr,"Loading...")):M("",!0)]),Z[43]||(Z[43]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Configure values for tools that require thread environment variables. Values from prompts are shown locked - click to unlock and override. ",-1)),P(ka,{modelValue:G.value,"onUpdate:modelValue":Z[23]||(Z[23]=re=>G.value=re),inherited:F.value,"allow-custom":!0,disabled:u.value},null,8,["modelValue","inherited","disabled"])])):M("",!0)]))]),_:1},8,["model-value","title"]))}}),Cr={},Tr={class:"p-8 w-full max-w-7xl mx-auto"};function Sr(t,n){return a(),o("div",Tr,[et(t.$slots,"default")])}const at=tt(Cr,[["render",Sr]]),Vr=pe({__name:"AgentsView",setup(t){const n=lt(),s=Ye(),i=m(!1),l=m("add"),u=m(null),r=m(null),c=m(null);ve(()=>s.query.refresh,()=>{s.query.refresh&&(r.value?.refresh(),n.replace({path:"/agents",query:{}}))});const f=()=>{l.value="add",u.value=null,c.value=null,i.value=!0},g=p=>{l.value="edit",u.value=p,c.value=null,i.value=!0},d=async p=>{c.value=null;try{const h=l.value==="edit"&&u.value?.id,{originalName:_,...b}=p,v=de(h?`/api/agents/${u.value.id}`:"/api/agents"),x=await fetch(v,{method:h?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(x.ok)r.value?.refresh(),i.value=!1,u.value=null;else{const k=await x.json();c.value=k.error||`Failed to ${h?"update":"create"} agent`}}catch(h){console.error(`Error ${l.value==="edit"?"updating":"creating"} agent:`,h),c.value=`Failed to ${l.value==="edit"?"update":"create"} agent`}};return(p,h)=>(a(),se(at,null,{default:ge(()=>[e("div",{class:"flex justify-between items-center mb-6"},[h[1]||(h[1]=e("h1",{class:"text-3xl font-bold"},"Agents",-1)),e("button",{onClick:f,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Create Agent ")]),h[2]||(h[2]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Configure and manage your AI agents. ",-1)),P(Ss,{ref_key:"dataTableRef",ref:r,onAdd:f,onEdit:g},null,512),P($r,{modelValue:i.value,"onUpdate:modelValue":h[0]||(h[0]=_=>i.value=_),mode:l.value,editAgent:u.value,apiError:c.value,onSave:d},null,8,["modelValue","mode","editAgent","apiError"])]),_:1}))}});function Mr(t){const{limit:n=50,offset:s=0,agentId:i=null,userId:l=null,search:u=null,startDate:r=null,endDate:c=null,autoFetch:f=!0}=t||{},g=W(()=>{const D=new URLSearchParams,q=typeof n=="number"?n:n.value,B=typeof s=="number"?s:s.value,N=typeof i=="string"?i:i?.value,T=typeof l=="string"?l:l?.value,w=typeof u=="string"?u:u?.value,K=typeof r=="number"?r:r?.value,te=typeof c=="number"?c:c?.value;return D.append("limit",q.toString()),D.append("offset",B.toString()),N&&D.append("agent_id",N),T&&D.append("user_id",T),w&&D.append("search",w),K&&D.append("startDate",K.toString()),te&&D.append("endDate",te.toString()),de(`/api/threads?${D.toString()}`)}),{data:d,error:p,isFetching:h,isFinished:_,execute:b,abort:v}=Ue(g,{immediate:f,refetch:!0}).get().json(),y=W(()=>d.value?.threads||[]),x=W(()=>d.value?.total||0),k=W(()=>d.value?.hasMore||!1);return{threads:y,total:x,hasMore:k,error:p,isFetching:h,isFinished:_,refetch:b,abort:v}}function St(t){const n=W(()=>!!(typeof t=="string"?t:t?.value)),s=W(()=>{const d=typeof t=="string"?t:t?.value;return de(d?`/api/threads/${d}`:"/api/threads/placeholder")}),{data:i,error:l,isFetching:u,isFinished:r,execute:c,abort:f}=Ue(s,{immediate:!1,refetch:!0}).get().json();return ve(n,d=>{d&&c()},{immediate:!0}),{thread:W(()=>i.value?{id:i.value.thread.id,agent_id:i.value.thread.agent_id,user_id:i.value.thread.user_id,tags:i.value.thread.tags||[],created_at:i.value.thread.created_at,agent:i.value.agent||{id:"",title:"Unknown",type:"unknown"},stats:i.value.stats}:null),error:l,isFetching:u,isFinished:r,refetch:c,abort:f}}function Ir(t){const{autoConnect:n=!0,onEvent:s}=t||{},i=m(null),l=m(!1),u=m(null);let r=0,c=null,f=null,g=!0;const d=3e4,p=3e4,h=()=>{c&&(clearTimeout(c),c=null),f&&(clearInterval(f),f=null)},_=()=>{f&&clearInterval(f),f=setInterval(()=>{i.value&&i.value.readyState===WebSocket.OPEN&&i.value.send("ping")},p)},b=()=>{if(!g)return;const k=Math.min(1e3*Math.pow(2,r),d);r++,console.log(`[AgentBuilderEvents] Scheduling reconnect in ${k}ms (attempt ${r})`),c=setTimeout(()=>{g&&v()},k)},v=()=>{i.value&&i.value.close();const k=window.location.protocol==="https:"?"wss:":"ws:",D=window.location.host;let q=`${k}//${D}${de("/api/events")}`;const B=localStorage.getItem("auth_token");B&&(q+=`?token=${encodeURIComponent(B)}`);try{i.value=new WebSocket(q),i.value.onopen=()=>{l.value=!0,u.value=null,r=0,_(),console.log("[AgentBuilderEvents] WebSocket connected")},i.value.onmessage=N=>{try{const T=JSON.parse(N.data);s&&s(T)}catch(T){console.error("[AgentBuilderEvents] Failed to parse WebSocket message:",T)}},i.value.onerror=N=>{u.value="WebSocket connection error",console.error("[AgentBuilderEvents] WebSocket error:",N)},i.value.onclose=()=>{l.value=!1,h(),console.log("[AgentBuilderEvents] WebSocket disconnected"),b()}}catch(N){u.value=N.message||"Failed to create WebSocket",console.error("[AgentBuilderEvents] WebSocket creation error:",N),b()}},y=()=>{g=!0,r=0,v()},x=()=>{g=!1,h(),i.value&&(i.value.close(),i.value=null),l.value=!1,r=0};return n&&y(),Be(()=>{x()}),{wsConnected:l,wsError:u,connect:y,disconnect:x}}const Er={class:"inline-flex items-center justify-center"},Te=pe({__name:"Loader",props:{size:{default:"md"}},setup(t){const n=t,s=W(()=>{switch(n.size){case"xs":return"w-3 h-3 border";case"sm":return"w-3.5 h-3.5 border";case"md":default:return"w-4 h-4 border-2"}});return(i,l)=>(a(),o("div",Er,[e("div",{class:oe([s.value,"border-black/20 dark:border-white/20 border-t-black dark:border-t-white rounded-full animate-spin"])},null,2)]))}});function Lr(t){const s=Date.now()*1e3-t,i=Math.floor(s/1e6);if(i<60)return i===1?"1 second ago":`${i} seconds ago`;const l=Math.floor(i/60);if(l<60)return l===1?"1 minute ago":`${l} minutes ago`;const u=Math.floor(l/60);if(u<24)return u===1?"1 hour ago":`${u} hours ago`;const r=Math.floor(u/24);if(r<30)return r===1?"1 day ago":`${r} days ago`;const c=Math.floor(r/30);if(c<12)return c===1?"1 month ago":`${c} months ago`;const f=Math.floor(c/12);return f===1?"1 year ago":`${f} years ago`}function Ar(t){const n=m("");let s=null;const i=()=>typeof t=="function"?t():typeof t=="number"?t:t.value,l=()=>{const u=i();n.value=Lr(u);const c=Date.now()*1e3-u,f=Math.floor(c/1e6);s!==null&&(clearInterval(s),s=null),f<60?s=setInterval(l,1e3):f<3600?s=setInterval(l,6e4):f<86400&&(s=setInterval(l,6e5))};return l(),Be(()=>{s!==null&&clearInterval(s)}),n}const mt=pe({__name:"TimeAgo",props:{timestamp:{}},setup(t){const n=t,s=Ar(()=>n.timestamp);return(i,l)=>(a(),o("span",null,V(X(s)),1))}}),Pr={class:"relative inline-flex items-center"},Dr={key:0,class:"inline-block w-2 h-2 rounded-full bg-green-500 dark:bg-green-400"},jr={key:1,class:"inline-block w-2 h-2 rounded-full bg-neutral-400 dark:bg-neutral-600"},Or={key:0},Ur={key:1},Vt=pe({__name:"StatusDot",props:{connected:{type:Boolean},error:{type:Boolean}},setup(t){const n=m(!1),s=m(null);return(i,l)=>(a(),o("div",Pr,[e("span",{class:"p-0.5 cursor-default outline-none",tabindex:"-1",onMouseenter:l[0]||(l[0]=u=>n.value=!0),onMouseleave:l[1]||(l[1]=u=>n.value=!1)},[t.connected?(a(),o("span",Dr)):(a(),o("span",jr))],32),P(Xe,{"enter-active-class":"transition-opacity duration-150","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-100","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:ge(()=>[n.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:s,class:oe(["absolute top-full left-1/2 -translate-x-1/2 mt-1 px-2 py-1 text-xs rounded shadow-lg whitespace-nowrap z-50 border",{"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800 text-green-700 dark:text-green-300":t.connected,"bg-neutral-50 dark:bg-neutral-900 border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-400":!t.connected}])},[t.connected?(a(),o("span",Or,"Live - Connected")):(a(),o("span",Ur,"Offline"))],2)):M("",!0)]),_:1})]))}});function Rr(){const t=de("/api/agents"),{data:n,error:s,isFetching:i,isFinished:l,execute:u}=Ue(t,{immediate:!0}).get().json();return{agents:W(()=>n.value?.agents||[]),error:s,isFetching:i,isFinished:l,refetch:u}}const Nr={class:"relative min-w-0"},Fr={class:"truncate min-w-0 text-left"},Br={class:"w-56 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},qr={class:"p-2 border-b-2 border-black dark:border-neutral-300"},zr={class:"relative"},Hr={class:"max-h-48 overflow-y-auto"},Wr={key:0,class:"px-3 py-4 text-sm font-mono text-center text-neutral-500"},Jr=["onClick"],Kr={class:"truncate"},Gr={key:0,class:"px-3 py-4 text-sm font-mono text-center text-neutral-500"},Xr=pe({__name:"AgentFilterDropdown",props:{modelValue:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,{agents:l,isFetching:u}=Rr(),r=m(!1),c=m(""),f=m(null),g=m(null),d=W(()=>{if(!c.value)return l.value;const N=c.value.toLowerCase();return l.value.filter(T=>T.name.toLowerCase().includes(N)||T.title.toLowerCase().includes(N))}),p=W(()=>s.modelValue&&l.value.find(N=>N.name===s.modelValue)||null),h=W(()=>p.value?p.value.title||p.value.name:"All agents"),_=W(()=>s.modelValue!==null);function b(){if(!f.value||!g.value)return;const N=f.value.getBoundingClientRect();g.value.style.position="fixed",g.value.style.top=`${N.bottom+8}px`,g.value.style.left=`${N.left}px`,g.value.style.margin="0"}function v(){r.value?y():(r.value=!0,Ce(()=>{if(g.value&&(g.value.setAttribute("popover","auto"),g.value.addEventListener("toggle",x),"showPopover"in g.value))try{g.value.showPopover()}catch{}b()}))}function y(){if(g.value){if("hidePopover"in g.value)try{g.value.hidePopover()}catch{}g.value.removeEventListener("toggle",x)}r.value=!1,c.value=""}function x(N){N.target===g.value&&(r.value=N.newState==="open",r.value&&b())}function k(N){i("update:modelValue",N?.name||null),y()}function D(N){N.stopPropagation(),i("update:modelValue",null)}const q=N=>{const T=N.target;g.value&&!g.value.contains(T)&&f.value&&!f.value.contains(T)&&y()},B=N=>{N.key==="Escape"&&r.value&&(y(),f.value?.focus())};return Ve(()=>{document.addEventListener("click",q),document.addEventListener("keydown",B),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0)}),Be(()=>{document.removeEventListener("click",q),document.removeEventListener("keydown",B),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}),(N,T)=>(a(),o("div",Nr,[e("button",{ref_key:"triggerRef",ref:f,type:"button",onClick:v,class:oe(["w-full flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded border-2 transition-colors min-w-0",[_.value?"border-accent-500 bg-accent-50 dark:bg-accent-950/50 text-accent-700 dark:text-accent-300":"border-neutral-300 dark:border-neutral-600 hover:border-accent-400 dark:hover:border-accent-500 bg-white dark:bg-black"]])},[P(X(ja),{size:12,class:"shrink-0"}),e("span",Fr,V(h.value),1),_.value?(a(),se(X(ft),{key:0,size:12,class:"shrink-0 opacity-60 hover:opacity-100",onClick:D})):(a(),se(X(nt),{key:1,size:12,class:oe(["shrink-0 opacity-60",r.value?"rotate-180":""])},null,8,["class"]))],2),r.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:g,class:"dropdown-popover z-[9999]"},[P(Ze,{"offset-x":4,"offset-y":4,intensity:.3},{default:ge(()=>[e("div",Br,[e("div",qr,[e("div",zr,[P(X(Yt),{size:12,class:"absolute left-2 top-1/2 -translate-y-1/2 opacity-60"}),Me(e("input",{"onUpdate:modelValue":T[0]||(T[0]=w=>c.value=w),type:"text",placeholder:"Search agents...",class:"w-full pl-7 pr-2 py-1.5 text-xs font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white placeholder:text-neutral-400",onClick:T[1]||(T[1]=Ie(()=>{},["stop"]))},null,512),[[Oe,c.value]])])]),e("div",Hr,[e("button",{type:"button",onClick:T[2]||(T[2]=w=>k(null)),class:oe(["w-full flex items-center gap-2 px-3 py-2 text-sm font-mono text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors",t.modelValue?"":"bg-accent-50 dark:bg-accent-950/30"])},[e("span",{class:oe(["w-2 h-2 rounded-full border-2 border-accent-500",t.modelValue?"":"bg-accent-500"])},null,2),T[3]||(T[3]=$e(" All agents ",-1))],2),X(u)?(a(),o("div",Wr," Loading... ")):(a(),o(me,{key:1},[(a(!0),o(me,null,ye(d.value,w=>(a(),o("button",{key:w.id,type:"button",onClick:K=>k(w),class:oe(["w-full flex items-center gap-2 px-3 py-2 text-sm font-mono text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors",t.modelValue===w.name?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:oe(["w-2 h-2 rounded-full border-2 border-accent-500",t.modelValue===w.name?"bg-accent-500":""])},null,2),e("span",Kr,V(w.title||w.name),1)],10,Jr))),128)),d.value.length===0&&!X(u)?(a(),o("div",Gr," No agents found ")):M("",!0)],64))])])]),_:1})],512)):M("",!0)]))}}),Yr={class:"relative min-w-0"},Zr={class:"truncate flex-1 text-left"},Qr={class:"w-52 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},ei={key:0},ti=["onClick"],ai={class:"border-t-2 border-black dark:border-neutral-300"},oi={key:1,class:"p-3 space-y-3"},li={class:"flex items-center justify-between"},si={class:"space-y-2"},ni=pe({__name:"DateFilterDropdown",props:{startDate:{},endDate:{}},emits:["update:startDate","update:endDate"],setup(t,{emit:n}){const s=t,i=n,l=m(!1),u=m(!1),r=m(null),c=m(null),f=m(""),g=m(""),d=[{label:"All time",value:"all",getRange:()=>({startDate:null,endDate:null})},{label:"Today",value:"today",getRange:()=>{const T=new Date,w=new Date(T.getFullYear(),T.getMonth(),T.getDate());return{startDate:Math.floor(w.getTime()/1e3),endDate:null}}},{label:"Last 3 days",value:"3days",getRange:()=>{const T=new Date,w=new Date(T.getFullYear(),T.getMonth(),T.getDate()-2);return{startDate:Math.floor(w.getTime()/1e3),endDate:null}}},{label:"Last 7 days",value:"7days",getRange:()=>{const T=new Date,w=new Date(T.getFullYear(),T.getMonth(),T.getDate()-6);return{startDate:Math.floor(w.getTime()/1e3),endDate:null}}},{label:"Last 30 days",value:"30days",getRange:()=>{const T=new Date,w=new Date(T.getFullYear(),T.getMonth(),T.getDate()-29);return{startDate:Math.floor(w.getTime()/1e3),endDate:null}}}],p=W(()=>{if(!s.startDate&&!s.endDate)return"all";for(const T of d){const w=T.getRange();if(w.startDate===s.startDate&&w.endDate===s.endDate)return T.value}return"custom"}),h=W(()=>{if(!s.startDate&&!s.endDate)return"All time";const T=d.find(K=>K.value===p.value);if(T&&p.value!=="custom")return T.label;const w=K=>new Date(K*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"});return s.startDate&&s.endDate?`${w(s.startDate)} - ${w(s.endDate)}`:s.startDate?`From ${w(s.startDate)}`:s.endDate?`Until ${w(s.endDate)}`:"Custom"}),_=W(()=>s.startDate!==null||s.endDate!==null);function b(){if(!r.value||!c.value)return;const T=r.value.getBoundingClientRect();c.value.style.position="fixed",c.value.style.top=`${T.bottom+8}px`,c.value.style.left=`${T.left}px`,c.value.style.margin="0"}function v(){l.value?y():(l.value=!0,Ce(()=>{if(c.value&&(c.value.setAttribute("popover","auto"),c.value.addEventListener("toggle",x),"showPopover"in c.value))try{c.value.showPopover()}catch{}b()}))}function y(){if(c.value){if("hidePopover"in c.value)try{c.value.hidePopover()}catch{}c.value.removeEventListener("toggle",x)}l.value=!1,u.value=!1}function x(T){T.target===c.value&&(l.value=T.newState==="open",l.value&&b())}function k(T){const w=T.getRange();i("update:startDate",w.startDate),i("update:endDate",w.endDate),y()}function D(){const T=f.value?Math.floor(new Date(f.value).getTime()/1e3):null,w=g.value?Math.floor(new Date(g.value+"T23:59:59").getTime()/1e3):null;i("update:startDate",T),i("update:endDate",w),y()}function q(T){T.stopPropagation(),i("update:startDate",null),i("update:endDate",null)}const B=T=>{const w=T.target;c.value&&!c.value.contains(w)&&r.value&&!r.value.contains(w)&&y()},N=T=>{T.key==="Escape"&&l.value&&(y(),r.value?.focus())};return Ve(()=>{document.addEventListener("click",B),document.addEventListener("keydown",N),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0)}),Be(()=>{document.removeEventListener("click",B),document.removeEventListener("keydown",N),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}),ve(u,T=>{T&&(s.startDate&&(f.value=new Date(s.startDate*1e3).toISOString().split("T")[0]),s.endDate?g.value=new Date(s.endDate*1e3).toISOString().split("T")[0]:g.value=new Date().toISOString().split("T")[0])}),(T,w)=>(a(),o("div",Yr,[e("button",{ref_key:"triggerRef",ref:r,type:"button",onClick:v,class:oe(["w-full flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded border-2 transition-colors min-w-0",[_.value?"border-accent-500 bg-accent-50 dark:bg-accent-950/50 text-accent-700 dark:text-accent-300":"border-neutral-300 dark:border-neutral-600 hover:border-accent-400 dark:hover:border-accent-500 bg-white dark:bg-black"]])},[P(X(Oa),{size:12,class:"shrink-0"}),e("span",Zr,V(h.value),1),_.value?(a(),se(X(ft),{key:0,size:12,class:"shrink-0 opacity-60 hover:opacity-100",onClick:q})):(a(),se(X(nt),{key:1,size:12,class:oe(["shrink-0 opacity-60",l.value?"rotate-180":""])},null,8,["class"]))],2),l.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:c,class:"dropdown-popover z-[9999]"},[P(Ze,{"offset-x":4,"offset-y":4,intensity:.3},{default:ge(()=>[e("div",Qr,[u.value?(a(),o("div",oi,[e("div",li,[w[7]||(w[7]=e("span",{class:"text-sm font-mono font-bold"},"Custom range",-1)),e("button",{type:"button",onClick:w[1]||(w[1]=Ie(K=>u.value=!1,["stop"])),class:"text-xs font-mono text-neutral-500 hover:text-black dark:hover:text-white"}," ← Back ")]),e("div",si,[e("div",null,[w[8]||(w[8]=e("label",{class:"block text-xs font-mono text-neutral-500 mb-1"},"FROM",-1)),Me(e("input",{"onUpdate:modelValue":w[2]||(w[2]=K=>f.value=K),type:"date",class:"w-full px-2 py-1.5 text-sm font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",onClick:w[3]||(w[3]=Ie(()=>{},["stop"]))},null,512),[[Oe,f.value]])]),e("div",null,[w[9]||(w[9]=e("label",{class:"block text-xs font-mono text-neutral-500 mb-1"},"TO",-1)),Me(e("input",{"onUpdate:modelValue":w[4]||(w[4]=K=>g.value=K),type:"date",class:"w-full px-2 py-1.5 text-sm font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",onClick:w[5]||(w[5]=Ie(()=>{},["stop"]))},null,512),[[Oe,g.value]])])]),e("button",{type:"button",onClick:D,class:"w-full py-2 text-sm font-mono font-bold bg-black dark:bg-white text-white dark:text-black rounded hover:opacity-90 transition-opacity"}," Apply ")])):(a(),o("div",ei,[(a(),o(me,null,ye(d,K=>e("button",{key:K.value,type:"button",onClick:te=>k(K),class:oe(["w-full px-3 py-2 text-left text-sm font-mono hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors flex items-center gap-2",p.value===K.value?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:oe(["w-2 h-2 rounded-full border-2 border-accent-500",p.value===K.value?"bg-accent-500":""])},null,2),$e(" "+V(K.label),1)],10,ti)),64)),e("div",ai,[e("button",{type:"button",onClick:w[0]||(w[0]=Ie(K=>u.value=!0,["stop"])),class:oe(["w-full px-3 py-2 text-left text-sm font-mono hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors flex items-center gap-2",p.value==="custom"?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:oe(["w-2 h-2 rounded-full border-2 border-accent-500",p.value==="custom"?"bg-accent-500":""])},null,2),w[6]||(w[6]=$e(" Custom range... ",-1))],2)])]))])]),_:1})],512)):M("",!0)]))}}),ri={class:"flex flex-col flex-1 min-h-0 overflow-visible"},ii={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},di={class:"flex items-center justify-between"},ui={class:"flex items-center gap-2"},ci={key:0,class:"text-xs font-mono text-neutral-500 dark:text-neutral-400"},pi={class:"flex items-center gap-2"},vi=["title"],mi={key:0,class:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center text-[8px] font-bold font-mono bg-accent-500 text-white rounded-full"},fi={key:0,class:"border-b-2 border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900/50"},hi={class:"p-3 space-y-2"},gi={class:"relative"},bi={class:"flex items-center gap-2 w-full"},xi={key:0,class:"flex justify-end"},yi={key:0,class:"p-4 flex justify-center"},ki={key:1,class:"p-4 text-red-600 dark:text-red-400"},wi={key:2,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},_i={key:1,class:"text-base"},$i={key:3},Ci=["id","onClick"],Ti={class:"flex items-center gap-2 mb-1"},Si={class:"flex-shrink-0 text-neutral-400 dark:text-neutral-500 text-[10px]"},Vi={class:"flex items-center gap-2"},Mi={class:"text-[10px] text-neutral-400 dark:text-neutral-500 font-mono truncate max-w-[80px]"},Ii={key:0,class:"flex flex-wrap gap-1 flex-1 min-w-0"},Ei={key:0,class:"text-[10px] text-neutral-400"},Li={key:0,class:"p-3 flex justify-center"},Ai={key:1,class:"p-3 text-center text-[10px] text-neutral-400 dark:text-neutral-500"},Pi=50,Di=pe({__name:"ThreadListPane",props:{selectedThreadId:{}},emits:["selectThread","collapse","createThread","threadsLoaded"],setup(t,{expose:n,emit:s}){const i=s,l=m(!1),u=m(""),r=m(null),c=m(null),f=m(null),g=m(null),d=m(0),p=m([]),h=m(!1),_=Na(E=>{r.value=E||null},300);ve(u,E=>{_(E)});const b=W(()=>{let E=0;return r.value&&E++,c.value&&E++,(f.value||g.value)&&E++,E});function v(){u.value="",r.value=null,c.value=null,f.value=null,g.value=null}const{threads:y,total:x,hasMore:k,isFetching:D,isFinished:q,error:B,refetch:N}=Mr({limit:Pi,offset:d,search:r,agentId:c,startDate:f,endDate:g});ve([r,c,f,g],()=>{d.value=0,p.value=[],h.value=!1}),ve(y,E=>{if(d.value===0)p.value=[...E];else{const R=new Set(p.value.map(ne=>ne.id)),Y=E.filter(ne=>!R.has(ne.id));p.value=[...p.value,...Y]}h.value=!1});const T=m([]),w=m(new Set),K=W(()=>{const E=p.value.filter(ne=>!w.value.has(ne.id)),R=new Set(E.map(ne=>ne.id));return[...T.value.filter(ne=>!R.has(ne.id)&&!w.value.has(ne.id)),...E].sort((ne,O)=>O.created_at-ne.created_at)}),te=m(null);function le(){h.value||D.value||!k.value||(h.value=!0,d.value=p.value.length)}const{arrivedState:H}=Ua(te,{offset:{bottom:100}});ve(()=>H.bottom,E=>{E&&k.value&&!D.value&&!h.value&&le()});const A=async E=>{if(E.type==="thread_created"){const R={id:E.thread.id,agent_id:E.thread.agent_name,user_id:E.thread.user_id,tags:E.thread.tags||[],created_at:E.thread.created_at,agent:{name:E.thread.agent_name,title:void 0,type:"ai_human"}};T.value.unshift(R)}else E.type==="thread_deleted"&&(w.value.add(E.threadId),T.value=T.value.filter(R=>R.id!==E.threadId))},{wsConnected:$,wsError:L}=Ir({onEvent:A});ve(()=>d.value,E=>{E===0&&(T.value=[])});const J=m(!1);ve(()=>({threads:p.value,finished:q.value}),({threads:E,finished:R})=>{R&&!J.value&&E.length>0&&(J.value=!0,i("threadsLoaded",E[0]?.id??null))},{immediate:!0}),n({refetch:N});const ee=E=>{i("selectThread",E)};return(E,R)=>(a(),o("div",ri,[e("div",ii,[e("div",di,[e("div",ui,[P(X(Zt),{size:18,class:"shrink-0"}),R[8]||(R[8]=e("h2",{class:"text-base font-bold"},"Threads",-1)),!X(D)&&X(x)>0?(a(),o("span",ci," ("+V(X(x))+") ",1)):M("",!0),P(Vt,{connected:X($),error:X(L)},null,8,["connected","error"])]),e("div",pi,[e("button",{onClick:R[0]||(R[0]=Y=>l.value=!l.value),type:"button",class:oe(["relative p-1 rounded transition-colors hover:bg-neutral-100 dark:hover:bg-neutral-900",[l.value||b.value>0?"text-accent-600 dark:text-accent-400":""]]),title:l.value?"Hide filters":"Show filters"},[P(X(Ra),{size:18}),b.value>0?(a(),o("span",mi,V(b.value),1)):M("",!0)],10,vi),e("button",{onClick:R[1]||(R[1]=Y=>i("createThread")),type:"button",class:"px-2 py-1 text-xs bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity whitespace-nowrap"}," + New "),e("button",{onClick:R[2]||(R[2]=Y=>i("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[P(X(Tt),{size:20})])])])]),P(Xe,{"enter-active-class":"transition-all duration-200 ease-out","enter-from-class":"opacity-0 -translate-y-2 max-h-0","enter-to-class":"opacity-100 translate-y-0 max-h-60","leave-active-class":"transition-all duration-150 ease-in","leave-from-class":"opacity-100 translate-y-0 max-h-60","leave-to-class":"opacity-0 -translate-y-2 max-h-0"},{default:ge(()=>[l.value?(a(),o("div",fi,[e("div",hi,[e("div",gi,[P(X(Yt),{size:14,class:"absolute left-2.5 top-1/2 -translate-y-1/2 opacity-60"}),Me(e("input",{"onUpdate:modelValue":R[3]||(R[3]=Y=>u.value=Y),type:"text",placeholder:"Search by tag or thread ID...",class:"w-full pl-8 pr-8 py-1.5 text-xs font-mono bg-white dark:bg-black border-2 border-neutral-300 dark:border-neutral-600 rounded focus:outline-none focus:border-black dark:focus:border-neutral-300 focus:ring-2 focus:ring-black/20 dark:focus:ring-white/20 placeholder:text-neutral-400"},null,512),[[Oe,u.value]]),u.value?(a(),o("button",{key:0,onClick:R[4]||(R[4]=Y=>u.value=""),type:"button",class:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 opacity-60 hover:opacity-100 transition-opacity"},[P(X(ft),{size:14})])):M("",!0)]),e("div",bi,[P(Xr,{modelValue:c.value,"onUpdate:modelValue":R[5]||(R[5]=Y=>c.value=Y),class:"flex-1 min-w-0"},null,8,["modelValue"]),P(ni,{startDate:f.value,"onUpdate:startDate":R[6]||(R[6]=Y=>f.value=Y),endDate:g.value,"onUpdate:endDate":R[7]||(R[7]=Y=>g.value=Y),class:"flex-1 min-w-0"},null,8,["startDate","endDate"])]),b.value>0?(a(),o("div",xi,[e("button",{onClick:v,type:"button",class:"text-xs font-mono text-neutral-500 hover:text-black dark:hover:text-white transition-colors"}," Clear all ")])):M("",!0)])])):M("",!0)]),_:1}),e("div",{ref_key:"scrollContainerRef",ref:te,class:"flex-1 overflow-y-auto text-xs min-h-0"},[X(D)&&p.value.length===0?(a(),o("div",yi,[P(Te)])):X(B)?(a(),o("div",ki," Error: "+V(X(B)),1)):K.value.length===0?(a(),o("div",wi,[b.value>0?(a(),o(me,{key:0},[R[9]||(R[9]=e("p",{class:"text-base mb-2"},"No matching threads",-1)),e("button",{onClick:v,type:"button",class:"text-xs text-accent-600 dark:text-accent-400 hover:underline"}," Clear filters ")],64)):(a(),o("p",_i,"No threads found"))])):(a(),o("div",$i,[(a(!0),o(me,null,ye(K.value,Y=>(a(),o("button",{key:Y.id,id:`thread-${Y.id}`,class:oe(["w-full text-left px-3 py-2.5 border-b border-neutral-200 dark:border-neutral-800 cursor-pointer transition-colors relative hover:bg-neutral-50 dark:hover:bg-neutral-800/50",{"bg-accent-50 dark:bg-accent-950/50 border-l-2 border-l-accent-500":t.selectedThreadId===Y.id}]),onClick:ne=>ee(Y.id)},[e("div",Ti,[e("span",{class:oe(["font-medium truncate flex-1 min-w-0",t.selectedThreadId===Y.id?"text-accent-700 dark:text-accent-300":""])},V(Y.agent.title||Y.agent.name),3),e("span",Si,[P(mt,{timestamp:Y.created_at*1e6},null,8,["timestamp"])])]),e("div",Vi,[e("span",Mi,V(Y.id.slice(0,8)),1),Y.tags.length>0?(a(),o("div",Ii,[(a(!0),o(me,null,ye(Y.tags.slice(0,3),ne=>(a(),o("span",{key:ne,class:oe(["inline-block px-1.5 py-0.5 rounded text-[10px] truncate max-w-[60px]",t.selectedThreadId===Y.id?"bg-accent-200 dark:bg-accent-900 text-accent-800 dark:text-accent-200":"bg-neutral-200 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400"])},V(ne),3))),128)),Y.tags.length>3?(a(),o("span",Ei," +"+V(Y.tags.length-3),1)):M("",!0)])):M("",!0)])],10,Ci))),128)),h.value||X(D)&&p.value.length>0?(a(),o("div",Li,[P(Te)])):!X(k)&&K.value.length>0?(a(),o("div",Ai," All "+V(X(x))+" threads loaded ",1)):M("",!0)]))],512)]))}});function ji(t,n={}){const s=m(null),i=m(!1),l=m(null);let u=null;try{u=ca()}catch{}const r=u?.workblocks??W(()=>[]),c=u?.messages??m([]),f=W(()=>u?.status.value==="connected"),g=m(null);u?.loading??m(!1);const d=W(()=>c.value.some(E=>E.status==="pending")),p=m(!1),h=m(0),_=m(!1);function b(E){if(!s.value?.agent)return null;const R=s.value.agent,Y=E==="assistant"?"A":"B";return Y==="A"&&R.side_a_label?R.side_a_label:Y==="B"&&R.side_b_label?R.side_b_label:null}function v(E){return{id:E.id||`att-${E.path||E.name||Math.random().toString(36).slice(2)}`,type:"file",path:E.path||"",name:E.name||E.path?.split("/").pop()||"attachment",mimeType:E.mimeType||E.mediaType||"application/octet-stream",width:E.width,height:E.height,description:E.description}}function y(E){if(E){if(Array.isArray(E))return E.length>0?E.map(v):void 0;try{const R=JSON.parse(E);return Array.isArray(R)&&R.length>0?R.map(v):void 0}catch(R){console.error("Failed to parse attachments:",R);return}}}function x(E,R){const Y=[];E.reasoning_content&&Y.push({id:`${E.id}-reasoning`,type:"reasoning",content:E.reasoning_content,created_at:E.created_at}),E.content&&Y.push({id:`${E.id}-content`,type:"content",content:E.content,created_at:E.created_at});const ne=E.workItems.filter(I=>I.type==="tool_call"),O=E.workItems.filter(I=>I.type==="tool_result"),S=new Map;for(const I of O)I.tool_call_id&&S.set(I.tool_call_id,I);for(const I of ne){const ae=I.tool_call_id||I.id,F=S.get(ae);let G="pending";if(F){const z=(F.content||"").toLowerCase(),j=z.includes("failed")||z.includes("error"),Q=z.length<500;G=F.status==="error"||j&&Q?"failed":"success"}Y.push({id:I.id,type:"tool_call",content:I.name||"",created_at:E.created_at,tool_name:I.name,tool_call_id:ae,tool_arguments:I.content||void 0,response:F?.content||null,response_status:G,response_log_id:null,log_id:null})}const C=Y.some(I=>I.type==="tool_call"&&I.response_status==="pending"),U=E.status!=="pending"&&!C;return{type:"work",id:E.id,role:"assistant",items:Y,created_at:E.created_at,updated_at:E.created_at,isComplete:U,sideLabel:b("assistant"),status:E.status}}const k=W(()=>{const E=[],Y=r.value.filter(O=>(O.depth??0)===0);let ne=[];for(let O=0;O<Y.length;O++){const S=Y[O];if(E[E.length-1]?.role,S.type==="workblock"){const U=x(S);E.push(U);const I=S;I.attachments&&I.attachments.length>0&&ne.push(...I.attachments.map(v))}else{const U=S,I=U.role;if(U.role==="tool")continue;const ae=y(U.attachments);let F;if((ne.length>0||ae)&&(F=[...ne,...ae||[]],ne=[]),U.content||I==="system"||U.status==="pending"||F?.length){const G={type:"text",id:U.id,role:I,content:U.content||"",attachments:F?.length?F:void 0,created_at:U.created_at,log_id:U.log_id||null,sideLabel:b(I),isOptimistic:U.isOptimistic,status:U.status,silent:U.silent};E.push(G)}}}return E});async function D(){if(!t.value){s.value=null;return}try{const E=await fetch(de(`/api/threads/${t.value}`));E.ok&&(s.value=await E.json())}catch(E){console.error("Error fetching thread info:",E)}}async function q(E){if(t.value){if(u?.deleteMessage){await u.deleteMessage(E);return}try{if(!(await fetch(de(`/api/threads/${t.value}/messages/${E}`),{method:"DELETE"})).ok)throw new Error("Failed to delete message")}catch(R){throw R}}}async function B(E,R){if(t.value)try{if(!(await fetch(de(`/api/threads/${t.value}/messages/${E}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:R})})).ok)throw new Error("Failed to update message")}catch(Y){throw Y}}ve(t,async E=>{E?(i.value=!0,await D(),i.value=!1):s.value=null},{immediate:!0});const N=u?.sendMessage,T=u?.stopExecution,w=u?.attachments??m([]),K=u?.addAttachment??(()=>{}),te=u?.removeAttachment??(()=>{}),le=u?.clearAttachments??(()=>{});function H(){console.warn("loadMoreMessages is deprecated - SDK handles all messages")}function A(){console.warn("connectWebSocket is deprecated - SDK handles WebSocket")}function $(){console.warn("disconnectWebSocket is deprecated - SDK handles WebSocket")}function L(){console.warn("addOptimisticMessage is deprecated - SDK handles optimistic updates")}function J(){console.warn("removeOptimisticMessage is deprecated - SDK handles optimistic updates")}async function ee(){console.warn("refetch is deprecated - SDK handles message loading")}return{messages:k,threadInfo:s,isFetching:i,isLoadingMore:_,error:l,wsConnected:f,wsError:g,isExecuting:d,hasMore:p,totalMessages:h,sendMessage:N,stopThread:T,attachments:w,addAttachment:K,removeAttachment:te,clearAttachments:le,deleteMessageById:q,updateMessageContent:B,refetch:ee,loadMoreMessages:H,connectWebSocket:A,disconnectWebSocket:$,addOptimisticMessage:L,removeOptimisticMessage:J}}const Oi={key:0,class:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800"},Ui={key:1,class:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 text-neutral-400"},Ri=["src","alt"],Ni={class:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center"},Fi={key:0,class:"text-white text-[10px]"},Bi={class:"text-xs text-neutral-600 dark:text-neutral-300 truncate max-w-[100px]"},qi=pe({__name:"FileAttachment",props:{attachment:{},threadId:{},showRemove:{type:Boolean}},emits:["remove"],setup(t,{emit:n}){const s=t,i=n,l=m(!0),u=m(!1),r=W(()=>s.attachment.mimeType.startsWith("image/")),c=W(()=>!!s.attachment.thumbnailBase64),f=W(()=>{if(!s.threadId||!s.attachment.path)return"";const b=s.attachment.path.startsWith("/")?s.attachment.path.slice(1):s.attachment.path;return de(`/api/threads/${s.threadId}/fs/${b}`)}),g=W(()=>r.value?s.attachment.thumbnailBase64?`data:image/webp;base64,${s.attachment.thumbnailBase64}`:f.value:"");function d(){l.value=!1,u.value=!1}function p(){l.value=!1,u.value=!0}function h(){i("remove",s.attachment.id)}function _(){f.value&&window.open(f.value,"_blank")}return(b,v)=>(a(),o("div",{class:oe(["relative group inline-flex items-center rounded-lg overflow-hidden border border-neutral-200 dark:border-neutral-700",{"w-[104px] h-[104px]":r.value,"px-2 py-1 bg-neutral-100 dark:bg-neutral-800":!r.value,"cursor-pointer":r.value&&f.value}]),onClick:v[0]||(v[0]=y=>r.value&&f.value?_():void 0)},[r.value?(a(),o(me,{key:0},[l.value&&!u.value&&!c.value?(a(),o("div",Oi,[...v[1]||(v[1]=[e("div",{class:"w-4 h-4 border-2 border-neutral-300 border-t-neutral-600 rounded-full animate-spin"},null,-1)])])):M("",!0),u.value&&!c.value?(a(),o("div",Ui,[P(X(Qt),{size:24})])):M("",!0),Me(e("img",{src:g.value||f.value,alt:t.attachment.name,class:"w-full h-full object-cover",onLoad:d,onError:p},null,40,Ri),[[Ke,!l.value&&!u.value||c.value]]),e("div",Ni,[f.value?(a(),o("span",Fi,"Click to view")):M("",!0)])],64)):(a(),o(me,{key:1},[P(X(ea),{size:14,class:"text-neutral-500 mr-1 flex-shrink-0"}),e("span",Bi,V(t.attachment.name),1)],64)),t.showRemove?(a(),o("button",{key:2,onClick:Ie(h,["stop"]),class:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity"},[P(X(ft),{size:10})])):M("",!0)],2))}}),zi=["onMouseenter","onMouseleave","onClick"],Hi=["onClick"],Wi={key:0,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"3",stroke:"currentColor",class:"w-3 h-3 text-white"},Ji={key:1,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2.5",stroke:"currentColor",class:"w-3 h-3 text-white"},Ki={key:0,class:"w-full text-center text-xs text-neutral-400 dark:text-neutral-500 py-1"},Gi=["contenteditable","onInput"],Xi={key:1,class:"flex gap-1 items-center min-h-[1.5rem]"},Yi={key:0,class:"opacity-50"},Zi={key:1,class:"opacity-50 italic text-neutral-500 dark:text-neutral-400"},Qi={key:0,class:"flex flex-wrap gap-2"},ed=["onClick","onMouseenter"],td={key:0,class:"space-y-1"},ad={class:"flex items-start gap-2"},od={class:"flex-1 min-w-0"},ld={key:0,class:"truncate opacity-80"},sd={key:1,class:"italic opacity-60"},nd={class:"flex items-center gap-2 pl-5 opacity-60"},rd={class:"text-[10px]"},id={class:"text-[10px]"},dd={key:1,class:"space-y-2"},ud={class:"flex items-center gap-2 pb-1 border-b border-current opacity-70"},cd={class:"text-[10px] italic"},pd={class:"text-[10px] ml-auto"},vd={key:0,class:"space-y-1"},md=["onClick","onMouseenter"],fd={class:"font-mono text-[11px] flex-shrink-0"},hd={key:2,class:"text-[10px] opacity-60 px-2 truncate flex-1 min-w-0"},gd={key:3,class:"text-[10px] text-green-600 dark:text-green-400 ml-auto flex-shrink-0"},bd={key:0,class:"pl-4 space-y-2 text-[10px]"},xd={key:0},yd={class:"w-full border-collapse"},kd={class:"py-0.5 pr-2 opacity-65 align-top"},wd={class:"py-0.5 opacity-85 break-all"},_d={key:1},$d=["onClick","onMouseenter"],Cd={class:"whitespace-pre-wrap break-all"},Td={key:1,class:"text-[10px]"},Sd=["onClick"],Vd={key:0,class:"mt-1 pl-4 whitespace-pre-wrap break-words opacity-80"},Md={key:2,class:"text-[10px] opacity-80 pl-4 pb-2 break-words"},Id=pe({__name:"AgentMessages",props:{messages:{},threadId:{},selectedMessageId:{},selectedLogId:{},hoveredLogId:{},isEditMode:{type:Boolean},selectedForDelete:{},editedMessages:{}},emits:["messageClick","messageHover","selectionChange","messageEdit"],setup(t,{expose:n,emit:s}){const i=t,l=s;function u(O){const S=i.selectedForDelete?.has(O)??!1;l("selectionChange",O,!S)}function r(O,S){const U=O.target.innerText;l("messageEdit",S,U)}function c(O){return i.editedMessages?.has(O)??!1}const f=m(new Map);function g(O,S){S?f.value.set(O,S):f.value.delete(O)}function d(O){const S=i.messages.findIndex(C=>C.log_id===O);if(S<=0)return-1;for(let C=S-1;C>=0;C--){const U=i.messages[C];if(U.role==="user")return C;if(U.role==="assistant"&&U.log_id)break}return-1}function p(O){for(let S=0;S<i.messages.length;S++){const C=i.messages[S];if(C.log_id===O||C.type==="work"&&C.items&&C.items.some(ae=>ae.log_id===O||ae.response_log_id===O))return S}return-1}function h(O,S){const U=p(O);if(U===-1)return!1;const I=f.value.get(U);if(!I)return!1;const ae=i.messages[U];let F=null;if(ae.role==="assistant"&&ae.log_id){const j=d(ae.log_id);F=j!==-1?f.value.get(j):null}const G=S.getBoundingClientRect(),z=I.getBoundingClientRect();if(z.top<G.top){const be=(F||I).getBoundingClientRect().top-G.top-10;S.scrollBy({top:be,behavior:"smooth"})}else if(z.bottom>G.bottom){const j=z.bottom-G.bottom+10;S.scrollBy({top:j,behavior:"smooth"})}else if(F){const j=F.getBoundingClientRect();if(j.top<G.top){const Q=j.top-G.top-10;S.scrollBy({top:Q,behavior:"smooth"})}}return!0}function _(O){for(const S of i.messages){if(S.type!=="work")continue;if(S.items.some(I=>I.log_id===O||I.response_log_id===O))return!0}return!1}n({scrollToLogId:h,hasWorkblockForLogId:_});function b(O){const S=i.messages[O];if(S.log_id)return S.log_id;if(S.role==="user")for(let C=O+1;C<i.messages.length;C++){const U=i.messages[C];if(U.log_id)return U.log_id;if(U.role==="user")break}return null}function v(O,S){return S?b(O)===S:!1}function y(O){const S=b(O);S&&l("messageHover",S)}function x(O){b(O)&&l("messageHover",null)}function k(O){const S=i.messages[O],C=b(O);C&&l("messageClick",S.id,C)}const D=m(new Set),q=m(new Set),B=m(new Set);function N(O){D.value.has(O)?D.value.delete(O):D.value.add(O)}function T(O){q.value.has(O)?q.value.delete(O):q.value.add(O)}function w(O){B.value.has(O)?B.value.delete(O):B.value.add(O)}function K(O){if(!O)return{};try{return JSON.parse(O)}catch{return{raw:O}}}function te(O){if(!O)return null;const S=K(O),C=Object.keys(S);if(C.length===0)return null;const U=S[C[0]];return typeof U=="string"?U:JSON.stringify(U)}function le(O){return new Date(O/1e3).toLocaleTimeString()}function H(O){const S=Math.round(O/1e6);if(S<1)return"< 1s";if(S<60)return`${S}s`;const C=Math.floor(S/60),U=S%60;return`${C}m ${U}s`}function A(O){if(O.status==="pending")return"...";if(!O.isComplete)return"Working...";let S;return O.request_sent_at&&O.response_completed_at?S=O.response_completed_at-O.request_sent_at:S=O.updated_at-O.created_at,`Worked for ${H(S)}`}function $(O){const S=O.filter(C=>C.type==="content");if(S.length===0){const C=O.filter(U=>U.type==="reasoning");return C.length>0?C[C.length-1].content:null}return S[S.length-1].content}function L(O){const C=O.trim().split(`
2
- `)[0];return C.length>60?C.substring(0,60):C}function J(O){return i.selectedMessageId===O.id?!0:i.selectedLogId?O.items.some(S=>S.log_id===i.selectedLogId||S.response_log_id===i.selectedLogId):!1}function ee(O){return!!(i.selectedLogId&&(O.log_id===i.selectedLogId||O.response_log_id===i.selectedLogId))}function E(O){return i.hoveredLogId?O.items.some(S=>S.log_id===i.hoveredLogId||S.response_log_id===i.hoveredLogId):!1}function R(O){return!!(i.hoveredLogId&&(O.log_id===i.hoveredLogId||O.response_log_id===i.hoveredLogId))}function Y(O){const S=[];for(const C of O.items)C.log_id&&S.push(C.log_id),C.response_log_id&&S.push(C.response_log_id);return S}function ne(O){return O?O.trim():""}return(O,S)=>(a(),o("div",null,[(a(!0),o(me,null,ye(t.messages,(C,U)=>(a(),o("div",{key:C.id,ref_for:!0,ref:I=>g(U,I),class:"flex items-center gap-2 pb-3",onMouseenter:I=>y(U),onMouseleave:I=>x(U),onClick:I=>t.isEditMode?u(C.id):k(U)},[t.isEditMode&&C.role!=="system"?(a(),o("button",{key:0,onClick:Ie(I=>u(C.id),["stop"]),class:oe(["flex-shrink-0 w-6 h-6 rounded-full border-2 flex items-center justify-center transition-all",{"border-red-500 bg-red-500":t.selectedForDelete?.has(C.id),"border-green-500 bg-green-500":!t.selectedForDelete?.has(C.id)&&c(C.id),"border-neutral-400 dark:border-neutral-500 bg-transparent hover:border-neutral-500 dark:hover:border-neutral-400":!t.selectedForDelete?.has(C.id)&&!c(C.id)}])},[t.selectedForDelete?.has(C.id)?(a(),o("svg",Wi,[...S[4]||(S[4]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M4.5 12.75l6 6 9-13.5"},null,-1)])])):c(C.id)?(a(),o("svg",Ji,[...S[5]||(S[5]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125"},null,-1)])])):M("",!0)],10,Hi)):M("",!0),e("div",{class:oe(["flex-1 flex items-center gap-2 min-w-0",{"justify-start":C.role==="assistant","justify-end":C.role==="user","justify-center":C.role==="system","cursor-pointer":b(U)&&!t.isEditMode}])},[C.type==="text"&&C.role==="system"&&C.content?.includes("Execution stopped")?(a(),o("div",Ki,V(C.content),1)):C.type==="text"?(a(),o("div",{key:1,class:oe(["max-w-[80%] flex flex-col gap-2",{"items-start":C.role==="assistant","items-end":C.role==="user"}])},[e("div",{class:oe(["rounded-2xl px-4 py-2 text-sm transition-all min-h-[2.5rem]",[C.silent?"bg-neutral-300 text-neutral-500 dark:bg-neutral-700 dark:text-neutral-400 opacity-70 border-2 border-dashed border-neutral-400 dark:border-neutral-500":!t.isEditMode&&C.role!=="user"&&v(U,t.selectedLogId)?"bg-accent-200 text-accent-950 dark:bg-accent-200 dark:text-accent-950 ring-2 ring-accent-400 dark:ring-accent-400":C.role==="assistant"?"bg-neutral-800 text-white dark:bg-neutral-300 dark:text-black":C.role==="user"?"bg-neutral-200 text-black dark:bg-neutral-800 dark:text-white":"bg-neutral-100 text-neutral-600 dark:bg-neutral-900 dark:text-neutral-400 text-xs",{"opacity-60":C.isOptimistic},{"ring-2 ring-accent-400 dark:ring-accent-400 !bg-accent-200 !text-accent-950 dark:!bg-accent-200 dark:!text-accent-950":!t.isEditMode&&C.role!=="user"&&b(U)&&!C.silent&&!v(U,t.selectedLogId)&&v(U,t.hoveredLogId)},{"ring-2 ring-green-500 dark:ring-green-400":t.isEditMode&&c(C.id),"border border-dashed border-neutral-400 dark:border-neutral-500":t.isEditMode&&C.role!=="system"&&!c(C.id)}]])},[C.content||t.isEditMode?(a(),o("div",{key:0,class:"whitespace-pre-wrap break-words text-sm outline-none",contenteditable:t.isEditMode&&C.role!=="system",onInput:I=>r(I,C.id),onClick:S[0]||(S[0]=I=>t.isEditMode&&I.stopPropagation())},V(ne(C.content)),41,Gi)):C.status==="pending"?(a(),o("div",Xi,[...S[6]||(S[6]=[e("span",{class:"typing-dot",style:{"animation-delay":"0ms"}},null,-1),e("span",{class:"typing-dot",style:{"animation-delay":"150ms"}},null,-1),e("span",{class:"typing-dot",style:{"animation-delay":"300ms"}},null,-1)])])):M("",!0),C.status!=="pending"?(a(),o("div",{key:2,class:oe(["text-[10px] mt-1 opacity-50 flex gap-2",{"justify-start":C.role==="assistant","justify-end":C.role!=="assistant"}])},[C.sideLabel?(a(),o("span",Yi,V(C.sideLabel),1)):M("",!0),e("span",null,V(le(C.created_at)),1),C.silent?(a(),o("span",Zi," silent ")):M("",!0)],2)):M("",!0)],2),C.attachments?.length&&t.threadId?(a(),o("div",Qi,[(a(!0),o(me,null,ye(C.attachments,I=>(a(),se(qi,{key:I.id,attachment:I,threadId:t.threadId},null,8,["attachment","threadId"]))),128))])):M("",!0)],2)):C.type==="work"?(a(),o("div",{key:2,class:oe(["w-full rounded-lg px-3 py-2 text-xs transition-all border overflow-hidden",{"cursor-pointer":!t.isEditMode,"bg-neutral-50 text-neutral-700 border-neutral-200 dark:bg-neutral-900 dark:text-neutral-300 dark:border-neutral-700":C.role==="assistant"&&!C.silent,"bg-accent-50 text-accent-700 border-accent-200 dark:bg-accent-50 dark:text-accent-700 dark:border-accent-200":C.role==="user"&&!C.silent,"bg-neutral-200 text-neutral-500 border-neutral-400 dark:bg-neutral-800 dark:text-neutral-400 dark:border-neutral-600 opacity-70 border-dashed":C.silent,"ring-2 ring-accent-500":!t.isEditMode&&J(C),"ring-2 ring-accent-400":!t.isEditMode&&!J(C)&&E(C)}]),onClick:I=>!t.isEditMode&&(N(C.id),Y(C)[0]&&l("messageClick",C.id,Y(C)[0])),onMouseenter:I=>!t.isEditMode&&Y(C)[0]&&l("messageHover",Y(C)[0]),onMouseleave:S[3]||(S[3]=I=>!t.isEditMode&&l("messageHover",null))},[D.value.has(C.id)?(a(),o("div",dd,[e("div",ud,[P(X(nt),{size:14,class:"flex-shrink-0"}),e("span",cd,V(A(C)),1),e("span",pd,V(C.items.length)+" operation"+V(C.items.length!==1?"s":""),1)]),(a(!0),o(me,null,ye(C.items,I=>(a(),o("div",{key:I.id,class:"mb-1"},[I.type==="tool_call"?(a(),o("div",vd,[e("div",{onClick:Ie(ae=>{T(I.id),I.log_id&&l("messageClick",C.id,I.log_id)},["stop"]),onMouseenter:Ie(ae=>I.log_id&&l("messageHover",I.log_id),["stop"]),onMouseleave:S[1]||(S[1]=Ie(ae=>l("messageHover",null),["stop"])),class:oe(["flex items-center gap-2 cursor-pointer hover:opacity-70 transition-opacity min-w-0",{"ring-1 ring-accent-500":ee(I),"ring-1 ring-accent-400":!ee(I)&&R(I)}])},[q.value.has(I.id)?(a(),se(X(nt),{key:1,size:12,class:"flex-shrink-0 opacity-50"})):(a(),se(X(pt),{key:0,size:12,class:"flex-shrink-0 opacity-50"})),e("span",fd,V(I.tool_name),1),te(I.tool_arguments)?(a(),o("span",hd,V(te(I.tool_arguments)),1)):M("",!0),I.response_status==="success"?(a(),o("span",gd,"✓")):I.response_status==="failed"?(a(),se(X(Fa),{key:4,size:12,class:"ml-auto text-red-600 dark:text-red-400"})):M("",!0)],42,md),q.value.has(I.id)?(a(),o("div",bd,[I.tool_arguments?(a(),o("div",xd,[S[7]||(S[7]=e("div",{class:"font-semibold mb-1 opacity-70"},"Arguments:",-1)),e("table",yd,[e("tbody",null,[(a(!0),o(me,null,ye(K(I.tool_arguments),(ae,F)=>(a(),o("tr",{key:F,class:"border-b border-current border-opacity-10"},[e("td",kd,V(F),1),e("td",wd,V(typeof ae=="object"?JSON.stringify(ae):ae),1)]))),128))])])])):M("",!0),I.response?(a(),o("div",_d,[S[8]||(S[8]=e("div",{class:"font-semibold mb-1 opacity-70"},"Response:",-1)),e("div",{class:oe(["opacity-80 cursor-pointer hover:opacity-100",{"ring-1 ring-accent-500":t.selectedLogId&&I.response_log_id===t.selectedLogId,"ring-1 ring-accent-400":t.hoveredLogId&&I.response_log_id===t.hoveredLogId&&I.response_log_id!==t.selectedLogId}]),onClick:Ie(ae=>I.response_log_id&&l("messageClick",C.id,I.response_log_id),["stop"]),onMouseenter:Ie(ae=>I.response_log_id&&l("messageHover",I.response_log_id),["stop"]),onMouseleave:S[2]||(S[2]=Ie(ae=>l("messageHover",null),["stop"]))},[e("div",Cd,V(ne(I.response)),1)],42,$d)])):M("",!0)])):M("",!0)])):I.type==="reasoning"?(a(),o("div",Td,[e("button",{onClick:Ie(ae=>w(I.id),["stop"]),class:"flex items-center gap-1 opacity-70 hover:opacity-100 transition-opacity"},[B.value.has(I.id)?(a(),se(X(nt),{key:1,size:12,class:"flex-shrink-0"})):(a(),se(X(pt),{key:0,size:12,class:"flex-shrink-0"})),S[9]||(S[9]=e("span",{class:"font-semibold"},"Reasoning",-1))],8,Sd),B.value.has(I.id)?(a(),o("div",Vd,V(ne(I.content)),1)):M("",!0)])):I.type==="content"?(a(),o("div",Md,V(ne(I.content)),1)):M("",!0)]))),128))])):(a(),o("div",td,[e("div",ad,[P(X(pt),{size:14,class:"flex-shrink-0 mt-0.5 opacity-50"}),e("div",od,[$(C.items)?(a(),o("div",ld,V(L($(C.items)))+"... ",1)):(a(),o("div",sd,V(A(C)),1))])]),e("div",nd,[e("span",rd,V(C.items.length)+" operation"+V(C.items.length!==1?"s":""),1),e("span",id,"• "+V(A(C)),1)])]))],42,ed)):M("",!0)],2)],40,zi))),128))]))}}),Ed=tt(Id,[["__scopeId","data-v-884a0fa7"]]),Ld={key:0,class:"overflow-hidden border-b border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900"},Ad={class:"max-h-[400px] overflow-y-auto"},Pd={class:"flex items-center justify-between px-4 py-2 border-b border-neutral-200 dark:border-neutral-800 sticky top-0 bg-neutral-50 dark:bg-neutral-900"},Dd={class:"p-4"},jd={key:0,class:"flex justify-center py-4"},Od={key:1,class:"text-red-600 dark:text-red-400 text-center py-4 text-sm"},Ud={key:2,class:"space-y-3 text-sm"},Rd={class:"flex items-start gap-2"},Nd={class:"font-mono text-xs break-all"},Fd={class:"flex items-start gap-2"},Bd={class:"flex-1"},qd={key:0,class:"flex items-center gap-2"},zd={class:"text-xs text-neutral-500"},Hd={key:1,class:"space-y-2"},Wd={class:"flex gap-2"},Jd=["disabled"],Kd=["disabled"],Gd={class:"flex items-start gap-2"},Xd={key:0,class:"flex items-start gap-2"},Yd={class:"font-mono text-xs"},Zd={class:"flex items-start gap-2"},Qd={class:"flex-1 flex items-center gap-2 flex-wrap"},eu={key:1,class:"text-neutral-500 dark:text-neutral-500 italic text-xs"},tu={class:"flex items-start gap-2"},au=["disabled"],ou={key:1,class:"flex justify-center py-2"},lu={key:1,class:"p-3 rounded border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800 space-y-2"},su={class:"flex items-center gap-4 text-xs"},nu={class:"font-mono font-bold ml-1"},ru={class:"font-mono font-bold ml-1"},iu={key:0,class:"text-xs"},du={class:"w-full"},uu={class:"py-1"},cu={class:"text-right py-1 font-mono"},pu={class:"text-right py-1 font-mono"},vu={class:"flex items-start gap-2"},mu={class:"flex items-center gap-2"},fu=["disabled"],hu={key:0},gu={key:1},bu={class:"pt-2 border-t border-neutral-200 dark:border-neutral-800 flex justify-end"},xu=["disabled"],yu={key:0},ku={key:1},wu=pe({__name:"MetadataSlidePane",props:{threadId:{},show:{type:Boolean}},emits:["close","threadDeleted","editThread"],setup(t,{emit:n}){const s=t,i=n,{thread:l,isFetching:u,error:r}=St(W(()=>s.threadId)),c=m(!1),f=m(!1),g=m(!1),d=m(!1),p=m(""),h=m(!1),_=m(!1),b=m(!1),v=m("a"),y=m(null),{data:x,isFetching:k}=Ue(de("/api/agents"),{refetch:!0}).json(),D=W(()=>x.value?.agents?x.value.agents.filter($=>$.type==="ai_human").map($=>({value:$.id,label:$.title,description:`Type: ${$.type}`})):[]),q=W(()=>l.value?.agent.type==="ai_human"),B=$=>new Date($*1e3).toLocaleString(),N=()=>{l.value&&(p.value=l.value.agent.id,g.value=!0)},T=()=>{g.value=!1,p.value=""},w=async()=>{if(!(!s.threadId||!p.value)){d.value=!0;try{const $=await fetch(de(`/api/threads/${s.threadId}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent_id:p.value})});if(!$.ok){const L=await $.json();throw new Error(L.error||"Failed to update agent")}window.location.reload()}catch($){console.error("Error updating agent:",$),alert(`Failed to update agent: ${$.message}`)}finally{d.value=!1}}},K=async()=>{if(s.threadId){_.value=!0,h.value=!0;try{const $=await fetch(de(`/api/threads/${s.threadId}/cost`));if(!$.ok){const L=await $.json();throw new Error(L.error||"Failed to fetch cost breakdown")}y.value=await $.json()}catch($){console.error("Error fetching cost breakdown:",$),alert(`Failed to fetch cost breakdown: ${$.message}`),h.value=!1}finally{_.value=!1}}},te=$=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:4,maximumFractionDigits:6}).format($),le=W(()=>l.value?.agent.type==="dual_ai"),H=async()=>{if(s.threadId){b.value=!0;try{const $=await fetch(de(`/api/threads/${s.threadId}/continue`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({side:v.value})});if(!$.ok){const L=await $.json();throw new Error(L.error||"Failed to continue execution")}}catch($){console.error("Error continuing execution:",$),alert(`Failed to continue execution: ${$.message}`)}finally{b.value=!1}}},A=async()=>{if(s.threadId){f.value=!0;try{const $=await fetch(de(`/api/threads/${s.threadId}`),{method:"DELETE"});if(!$.ok){const L=await $.json();throw new Error(L.error||"Failed to delete thread")}i("threadDeleted",s.threadId)}catch($){console.error("Error deleting thread:",$),alert(`Failed to delete thread: ${$.message}`)}finally{f.value=!1}}};return ve(()=>s.show,$=>{$||(g.value=!1,p.value="")}),ve(()=>s.threadId,()=>{g.value=!1,p.value="",h.value=!1,y.value=null}),($,L)=>(a(),se(Xe,{"enter-active-class":"transition-all duration-300 ease-out","enter-from-class":"max-h-0 opacity-0","enter-to-class":"max-h-[400px] opacity-100","leave-active-class":"transition-all duration-200 ease-in","leave-from-class":"max-h-[400px] opacity-100","leave-to-class":"max-h-0 opacity-0"},{default:ge(()=>[t.show&&t.threadId?(a(),o("div",Ld,[e("div",Ad,[e("div",Pd,[L[7]||(L[7]=e("span",{class:"text-sm font-medium text-neutral-600 dark:text-neutral-400"},"Thread Info",-1)),e("button",{onClick:L[0]||(L[0]=J=>i("close")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Close metadata"},[P(X(ta),{size:16})])]),e("div",Dd,[X(u)?(a(),o("div",jd,[P(Te)])):X(r)?(a(),o("div",Od," Error loading metadata: "+V(X(r)),1)):X(l)?(a(),o("div",Ud,[e("div",Rd,[L[8]||(L[8]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"ID",-1)),e("span",Nd,V(X(l).id),1)]),e("div",Fd,[L[9]||(L[9]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Agent",-1)),e("div",Bd,[g.value?(a(),o("div",Hd,[P(Se,{modelValue:p.value,"onUpdate:modelValue":L[1]||(L[1]=J=>p.value=J),options:D.value,loading:X(k),placeholder:"Select an agent"},null,8,["modelValue","options","loading"]),e("div",Wd,[e("button",{onClick:w,disabled:d.value||!p.value,class:"px-2 py-1 text-xs bg-black dark:bg-white text-white dark:text-black hover:bg-black/80 dark:hover:bg-white/80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed rounded"},V(d.value?"Saving...":"Save"),9,Jd),e("button",{onClick:T,disabled:d.value,class:"px-2 py-1 text-xs border border-black dark:border-neutral-300 hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed rounded"}," Cancel ",8,Kd)])])):(a(),o("div",qd,[e("span",null,V(X(l).agent.title),1),e("span",zd,"("+V(X(l).agent.type)+")",1),q.value?(a(),o("button",{key:0,onClick:N,type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Change agent"},[P(X(kt),{size:12})])):M("",!0)]))])]),e("div",Gd,[L[10]||(L[10]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Created",-1)),e("span",null,V(B(X(l).created_at)),1)]),X(l).user_id?(a(),o("div",Xd,[L[11]||(L[11]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"User",-1)),e("span",Yd,V(X(l).user_id),1)])):M("",!0),e("div",Zd,[L[12]||(L[12]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Tags",-1)),e("div",Qd,[X(l).tags?.length>0?(a(!0),o(me,{key:0},ye(X(l).tags,J=>(a(),o("span",{key:J,class:"inline-block px-2 py-0.5 text-xs rounded bg-black text-white dark:bg-white dark:text-black"},V(J),1))),128)):(a(),o("span",eu,"No tags")),e("button",{onClick:L[2]||(L[2]=J=>i("editThread")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Edit tags"},[P(X(kt),{size:12})])])]),e("div",tu,[L[15]||(L[15]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 shrink-0 text-left"},"Cost",-1)),!h.value&&!_.value?(a(),o("button",{key:0,onClick:K,disabled:_.value,type:"button",class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[P(X(At),{size:12}),L[13]||(L[13]=e("span",null,"View Costs",-1))],8,au)):M("",!0),_.value?(a(),o("div",ou,[P(Te)])):M("",!0),h.value?(a(),o("button",{key:2,onClick:L[3]||(L[3]=J=>h.value=!1),type:"button",class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors"},[P(X(At),{size:12}),L[14]||(L[14]=e("span",null,"Hide Costs",-1))])):M("",!0)]),h.value&&y.value?(a(),o("div",lu,[e("div",su,[e("div",null,[L[16]||(L[16]=e("span",{class:"text-neutral-500"},"Total:",-1)),e("span",nu,V(te(y.value.totalCost)),1)]),e("div",null,[L[17]||(L[17]=e("span",{class:"text-neutral-500"},"Avg/msg:",-1)),e("span",ru,V(te(y.value.avgCostPerMessage)),1)])]),y.value.modelBreakdown.length>0?(a(),o("div",iu,[e("table",du,[L[18]||(L[18]=e("thead",null,[e("tr",{class:"border-b border-neutral-300 dark:border-neutral-600"},[e("th",{class:"text-left py-1 font-medium text-neutral-500"}," Model "),e("th",{class:"text-right py-1 font-medium text-neutral-500"}," Reqs "),e("th",{class:"text-right py-1 font-medium text-neutral-500"}," Cost ")])],-1)),e("tbody",null,[(a(!0),o(me,null,ye(y.value.modelBreakdown,J=>(a(),o("tr",{key:J.modelName},[e("td",uu,V(J.modelName),1),e("td",cu,V(J.requestCount),1),e("td",pu,V(te(J.totalCost)),1)]))),128))])])])):M("",!0)])):M("",!0),e("div",vu,[L[20]||(L[20]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 shrink-0 text-left"},"Debug",-1)),e("div",mu,[le.value?Me((a(),o("select",{key:0,"onUpdate:modelValue":L[4]||(L[4]=J=>v.value=J),class:"text-xs px-1 py-0.5 border border-neutral-300 dark:border-neutral-600 rounded bg-white dark:bg-neutral-800"},[...L[19]||(L[19]=[e("option",{value:"a"},"Side A",-1),e("option",{value:"b"},"Side B",-1)])],512)),[[Ba,v.value]]):M("",!0),e("button",{onClick:H,disabled:b.value,class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[P(X(qa),{size:12}),b.value?(a(),o("span",hu,"Running...")):(a(),o("span",gu,"Continue"))],8,fu)])]),e("div",bu,[e("button",{onClick:L[5]||(L[5]=J=>c.value=!0),disabled:f.value,class:"flex items-center gap-1 px-2 py-1 text-xs text-red-600 border border-red-600 rounded hover:bg-red-50 dark:hover:bg-red-950/20 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[P(X(za),{size:12}),f.value?(a(),o("span",yu,"Deleting...")):(a(),o("span",ku,"Delete Thread"))],8,xu)])])):M("",!0)])]),P(xa,{modelValue:c.value,"onUpdate:modelValue":L[6]||(L[6]=J=>c.value=J),title:"Delete Thread?",message:"Are you sure you want to delete this thread? This will permanently delete all messages, logs, and associated data. This action cannot be undone.","confirm-text":"Delete Thread","cancel-text":"Cancel",onConfirm:A},null,8,["modelValue"])])):M("",!0)]),_:1}))}}),_u={key:0,class:"overflow-hidden border-b border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900"},$u={class:"max-h-[400px] overflow-y-auto"},Cu={class:"flex items-center justify-between px-4 py-2 border-b border-neutral-200 dark:border-neutral-800 sticky top-0 bg-neutral-50 dark:bg-neutral-900"},Tu={class:"flex items-center gap-1"},Su={class:"p-2"},Vu={key:0,class:"px-3 py-6 text-center text-neutral-500 dark:text-neutral-400 text-sm"},Mu=["onClick"],Iu={class:"text-xs truncate"},Eu={class:"text-[10px] text-neutral-400 ml-auto"},Lu=["href","onMouseenter"],Au={class:"shrink-0 text-neutral-500 dark:text-neutral-400"},Pu={class:"flex-1 min-w-0"},Du={class:"shrink-0 text-[10px] text-neutral-400 dark:text-neutral-500 ml-auto"},ju={key:0,class:"text-blue-500"},Ou={key:1,class:"text-red-500"},Uu={key:2},Ru=["href","onMouseenter"],Nu={class:"shrink-0 text-neutral-500 dark:text-neutral-400"},Fu={class:"flex-1 min-w-0"},Bu={class:"shrink-0 text-[10px] text-neutral-400 dark:text-neutral-500 ml-auto"},qu={key:0,class:"text-blue-500"},zu={key:1,class:"text-red-500"},Hu={key:2},Wu={class:"px-4 py-1.5 border-t border-neutral-200 dark:border-neutral-700 text-[10px] text-neutral-400 dark:text-neutral-500"},Ju=["src","alt"],Ku=pe({__name:"FilesSlidePane",props:{threadId:{},show:{type:Boolean}},emits:["close"],setup(t,{emit:n}){const s=t,i=n;let l=null;try{l=ca()}catch{}const u=l?.files??m([]),r=l?.addFiles??(()=>{}),c=m(null),f=m(new Set(["/attachments"])),g=m(null),d=m({x:0,y:0});function p(B){if(B===0)return"0 B";const N=1024,T=["B","KB","MB","GB"],w=Math.floor(Math.log(B)/Math.log(N));return parseFloat((B/Math.pow(N,w)).toFixed(1))+" "+T[w]}function h(B){const N=B.startsWith("/")?B.slice(1):B;return de(`/api/threads/${s.threadId}/fs/${N}`)}function _(B,N){return N?Qt:B.startsWith("audio/")?Ja:B.startsWith("video/")?Ka:B.startsWith("text/")?Ga:B.includes("javascript")||B.includes("json")||B.includes("xml")?Xa:ea}function b(B){const N=B.target;N.files?.length&&(r(N.files),N.value="")}function v(){c.value?.click()}function y(B){f.value.has(B)?f.value.delete(B):f.value.add(B),f.value=new Set(f.value)}function x(B){d.value={x:B.clientX,y:B.clientY}}function k(B){g.value=B}const D=W(()=>{const B=[],N=new Map,T=[...u.value].sort((w,K)=>w.status==="uploading"&&K.status!=="uploading"?-1:K.status==="uploading"&&w.status!=="uploading"?1:(w.path||w.name).localeCompare(K.path||K.name));for(const w of T){const K=w.path||`/${w.name}`,te=K.split("/").filter(Boolean);if(te.length===1)B.push({type:"file",name:w.name,path:K,file:w});else{const le="/"+te.slice(0,-1).join("/"),H=te[te.length-2];if(!N.has(le)){const A={type:"directory",name:H,path:le,children:[]};N.set(le,A),B.push(A)}N.get(le).children.push({type:"file",name:w.name,path:K,file:w})}}return B}),q=W(()=>u.value.length);return Ve(()=>{document.addEventListener("mousemove",x)}),Be(()=>{document.removeEventListener("mousemove",x)}),(B,N)=>(a(),se(Xe,{"enter-active-class":"transition-all duration-300 ease-out","enter-from-class":"max-h-0 opacity-0","enter-to-class":"max-h-[400px] opacity-100","leave-active-class":"transition-all duration-200 ease-in","leave-from-class":"max-h-[400px] opacity-100","leave-to-class":"max-h-0 opacity-0"},{default:ge(()=>[t.show?(a(),o("div",_u,[e("div",$u,[e("div",Cu,[N[4]||(N[4]=e("span",{class:"text-sm font-medium text-neutral-600 dark:text-neutral-400"}," Thread Files ",-1)),e("div",Tu,[e("input",{ref_key:"fileInput",ref:c,type:"file",multiple:"",class:"hidden",onChange:b},null,544),e("button",{onClick:v,type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300",title:"Upload files"},[P(X(Ha),{size:16})]),e("button",{onClick:N[0]||(N[0]=T=>i("close")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Close files"},[P(X(ta),{size:16})])])]),e("div",Su,[D.value.length===0?(a(),o("div",Vu," No files yet ")):M("",!0),(a(!0),o(me,null,ye(D.value,T=>(a(),o(me,{key:T.path},[T.type==="directory"?(a(),o(me,{key:0},[e("button",{onClick:w=>y(T.path),type:"button",class:"w-full flex items-center gap-1.5 px-2 py-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors text-left"},[P(X(pt),{size:12,class:oe(["shrink-0 text-neutral-400 transition-transform",{"rotate-90":f.value.has(T.path)}])},null,8,["class"]),(a(),se(Qe(f.value.has(T.path)?X(Wa):X(aa)),{size:14,class:"shrink-0",style:{color:"var(--accent-500)"}})),e("span",Iu,V(T.name),1),e("span",Eu,V(T.children?.length),1)],8,Mu),f.value.has(T.path)?(a(!0),o(me,{key:0},ye(T.children,w=>(a(),o("a",{key:w.path,href:w.path?h(w.path):void 0,target:"_blank",rel:"noopener noreferrer",class:oe(["flex items-center gap-2 pl-7 pr-2 py-1 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors cursor-pointer",{"pointer-events-none":w.file?.status==="uploading"}]),onMouseenter:K=>w.file?.isImage?k(w.path):null,onMouseleave:N[1]||(N[1]=K=>k(null))},[e("div",Au,[w.file?.status==="uploading"?(a(),se(X(Pt),{key:0,size:12,class:"animate-spin"})):(a(),se(Qe(_(w.file?.mimeType||"",w.file?.isImage||!1)),{key:1,size:12}))]),e("div",Pu,[e("div",{class:oe(["text-[11px] truncate",{"text-neutral-400":w.file?.status==="uploading"}])},V(w.name),3)]),e("div",Du,[w.file?.status==="uploading"?(a(),o("span",ju,"...")):w.file?.status==="error"?(a(),o("span",Ou,"err")):(a(),o("span",Uu,V(p(w.file?.size||0)),1))])],42,Lu))),128)):M("",!0)],64)):(a(),o("a",{key:1,href:T.path?h(T.path):void 0,target:"_blank",rel:"noopener noreferrer",class:oe(["flex items-center gap-2 px-2 py-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors cursor-pointer",{"pointer-events-none":T.file?.status==="uploading"}]),onMouseenter:w=>T.file?.isImage?k(T.path):null,onMouseleave:N[2]||(N[2]=w=>k(null))},[e("div",Nu,[T.file?.status==="uploading"?(a(),se(X(Pt),{key:0,size:14,class:"animate-spin"})):(a(),se(Qe(_(T.file?.mimeType||"",T.file?.isImage||!1)),{key:1,size:14}))]),e("div",Fu,[e("div",{class:oe(["text-xs truncate",{"text-neutral-400":T.file?.status==="uploading"}])},V(T.name),3)]),e("div",Bu,[T.file?.status==="uploading"?(a(),o("span",qu,"...")):T.file?.status==="error"?(a(),o("span",zu,"err")):(a(),o("span",Hu,V(p(T.file?.size||0)),1))])],42,Ru))],64))),128))]),e("div",Wu,V(q.value)+" file"+V(q.value!==1?"s":""),1)]),(a(),se(rt,{to:"body"},[g.value?(a(),o("div",{key:0,class:"fixed z-50 bg-white dark:bg-neutral-800 border border-neutral-300 dark:border-neutral-600 rounded-lg shadow-lg p-1 pointer-events-none",style:ot({left:`${d.value.x+16}px`,top:`${d.value.y-80}px`})},[e("img",{src:h(g.value),alt:g.value,class:"max-w-[200px] max-h-[150px] rounded object-contain",onError:N[3]||(N[3]=T=>T.target.style.display="none")},null,40,Ju)],4)):M("",!0)]))])):M("",!0)]),_:1}))}}),Gu=["accept"],Xu=["disabled"],Yu=pe({__name:"FileUpload",props:{isProcessing:{type:Boolean},accept:{}},emits:["filesSelected"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(null),r=W(()=>i.accept||"image/*,.pdf,.txt,.md,.json,.csv");function c(){u.value?.click()}function f(d){const p=d.target;p.files&&p.files.length>0&&(l("filesSelected",p.files),p.value="")}function g(d){const p=d.clipboardData?.items;if(!p)return;const h=[];for(let _=0;_<p.length;_++){const b=p[_];if(b.kind==="file"){const v=b.getAsFile();v&&h.push(v)}}if(h.length>0){const _=new DataTransfer;h.forEach(b=>_.items.add(b)),l("filesSelected",_.files)}}return n({handlePaste:g}),(d,p)=>(a(),o(me,null,[e("input",{ref_key:"fileInputRef",ref:u,type:"file",accept:r.value,multiple:"",class:"hidden",onChange:f},null,40,Gu),e("button",{type:"button",onClick:c,class:oe(["p-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition-colors text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300",{"opacity-50 cursor-not-allowed":t.isProcessing}]),disabled:t.isProcessing,title:"Attach files"},[P(X(Ya),{size:18})],10,Xu)],64))}}),Zu={class:"flex flex-col h-full"},Qu={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},ec={class:"flex items-center justify-between"},tc={class:"flex items-center gap-2"},ac={class:"flex items-center gap-2"},oc={class:"flex-1 flex flex-col overflow-hidden relative"},lc={key:0,class:"text-neutral-500 dark:text-neutral-400 text-center py-8"},sc={key:1,class:"flex justify-center py-2"},nc={key:2,class:"flex justify-center py-8"},rc={key:3,class:"text-red-600 dark:text-red-400 text-center py-8"},ic={key:4,class:"text-neutral-500 dark:text-neutral-400 text-center py-8"},dc={key:1,class:"p-3 bg-white dark:bg-neutral-900 border-t border-neutral-300 dark:border-neutral-700"},uc={class:"flex items-center justify-end gap-2"},cc=["disabled"],pc={key:2,class:"p-3 bg-white dark:bg-neutral-900 border-t border-neutral-300 dark:border-neutral-700"},vc={key:0,class:"mb-2 flex flex-wrap gap-2"},mc={key:0,class:"w-16 h-16 rounded-lg overflow-hidden border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800"},fc=["src","alt"],hc={key:1,class:"w-full h-full flex items-center justify-center"},gc={key:1,class:"h-16 px-3 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800 flex items-center gap-2"},bc=["title"],xc=["onClick"],yc={class:"flex items-start gap-2"},kc={class:"flex-1 flex items-start gap-2 p-2 rounded-2xl border border-neutral-300 dark:border-neutral-700 bg-white dark:bg-neutral-900"},wc=["disabled"],_c=["disabled"],$c={key:0,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",class:"w-4 h-4"},Cc={key:1,class:"w-4 h-4"},Bt=pe({__name:"MessagesPane",props:{threadId:{},selectedMessageId:{},selectedLogId:{},hoveredLogId:{}},emits:["collapse","messageClick","messageHover","threadDeleted","editThread","logsDeleted"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(!1),r=()=>{u.value=!u.value},c=m(!1),f=()=>{c.value=!c.value},g=m(!1),d=m(new Set),p=m(new Map),h=()=>{g.value=!g.value,g.value||(d.value=new Set,p.value=new Map)},_=(xe,fe)=>{const _e=new Set(d.value);fe?_e.add(xe):_e.delete(xe),d.value=_e},b=(xe,fe)=>{const _e=new Map(p.value);_e.set(xe,fe),p.value=_e},v=()=>{g.value=!1,d.value=new Set,p.value=new Map},y=W(()=>d.value.size),x=W(()=>{let xe=0;for(const[fe]of p.value)d.value.has(fe)||xe++;return xe}),k=W(()=>{const xe=y.value,fe=x.value;return xe>0&&fe>0?`Delete (${xe}), Update (${fe})`:xe>0?`Delete (${xe})`:fe>0?`Save changes (${fe})`:"Delete"}),D=W(()=>y.value>0||x.value>0),q=async()=>{if(!i.threadId||!D.value)return;const xe=[];for(const fe of d.value){const _e=B.value.find(Ne=>Ne.id===fe);_e&&"log_id"in _e&&_e.log_id&&xe.push(_e.log_id)}try{for(const[fe,_e]of p.value)d.value.has(fe)||await J(fe,_e);for(const fe of d.value)await L(fe);xe.length>0&&l("logsDeleted",xe)}catch(fe){console.error("Error applying changes:",fe)}finally{v()}},{messages:B,threadInfo:N,isFetching:T,isLoadingMore:w,error:K,wsConnected:te,wsError:le,isExecuting:H,hasMore:A,loadMoreMessages:$,deleteMessageById:L,updateMessageContent:J,stopThread:ee,sendMessage:E,attachments:R,addAttachment:Y,removeAttachment:ne}=ji(W(()=>i.threadId),{}),{thread:O}=St(W(()=>i.threadId)),S=W(()=>R.value.length>0),C=W(()=>!1),U=m(null),I=xe=>{Y(xe)},ae=m(null),F=m(null);n({scrollToLogId:xe=>F.value&&ae.value?F.value.scrollToLogId(xe,ae.value):!1,hasWorkblockForLogId:xe=>F.value?F.value.hasWorkblockForLogId(xe):!1}),typeof window<"u"&&(window.__testLoadMoreMessages=$);const j=m(""),Q=m(null),be=m("B"),De=m(!1),ie=m(!1),ce=async()=>{await Ce(),ae.value&&(ae.value.scrollTop=ae.value.scrollHeight)},ue=async xe=>{xe.target.scrollTop<100&&A.value&&!w.value&&!ie.value&&(ie.value=!0,await $(),ie.value=!1)};ve(()=>B.value.length,async()=>{!w.value&&!ie.value&&await ce()}),ve(()=>i.threadId,async xe=>{xe&&await ce()}),ve(T,async(xe,fe)=>{fe&&!xe&&await ce()});const we=W(()=>{const xe=N.value?.agent||O.value?.agent;if(!xe)return"ai A";const fe=xe.type;return be.value==="A"&&xe.side_a_label?xe.side_a_label:be.value==="B"&&xe.side_b_label?xe.side_b_label:fe==="ai_human"?be.value==="A"?"ai":"human":be.value==="A"?"ai A":"ai B"}),ke=()=>{be.value=be.value==="A"?"B":"A"},Le=async()=>{const xe=j.value.trim().length>0,fe=S.value;if(!xe&&!fe||!i.threadId||De.value||!E)return;const _e=j.value,Ne=be.value==="A"?"assistant":"user";j.value="",Q.value&&(Q.value.style.height="auto",Q.value.style.height="24px"),De.value=!0;try{await E({role:Ne,content:_e}),await ce()}catch(ht){console.error("Error sending message:",ht)}finally{De.value=!1,await Ce(),Q.value&&Q.value.focus()}},Fe=xe=>{xe.key==="Enter"&&!xe.shiftKey&&(xe.preventDefault(),Le())},Re=async()=>{if(i.threadId)try{await ee()}catch(xe){console.error("Error stopping thread:",xe)}};return(xe,fe)=>(a(),o("div",Zu,[e("div",Qu,[e("div",ec,[e("div",tc,[P(X(oa),{size:18,class:"shrink-0"}),fe[10]||(fe[10]=e("h2",{class:"text-base font-bold"},"Messages",-1)),t.threadId?(a(),se(Vt,{key:0,connected:X(te),error:X(le)},null,8,["connected","error"])):M("",!0)]),e("div",ac,[t.threadId?(a(),o("button",{key:0,onClick:f,type:"button",class:oe(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":c.value}]),title:"Toggle files"},[P(X(aa),{size:20})],2)):M("",!0),t.threadId?(a(),o("button",{key:1,onClick:r,type:"button",class:oe(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":u.value}]),title:"Toggle metadata"},[P(X(Za),{size:20})],2)):M("",!0),t.threadId&&X(B).length>0?(a(),o("button",{key:2,onClick:h,type:"button",class:oe(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":g.value}]),title:"Edit messages"},[P(X(kt),{size:20})],2)):M("",!0),e("button",{onClick:fe[0]||(fe[0]=_e=>l("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[P(X(Tt),{size:20})])])])]),e("div",oc,[P(wu,{"thread-id":t.threadId,show:u.value,onClose:fe[1]||(fe[1]=_e=>u.value=!1),onThreadDeleted:fe[2]||(fe[2]=_e=>l("threadDeleted",_e)),onEditThread:fe[3]||(fe[3]=_e=>l("editThread"))},null,8,["thread-id","show"]),t.threadId?(a(),se(Ku,{key:0,"thread-id":t.threadId,show:c.value,onClose:fe[4]||(fe[4]=_e=>c.value=!1)},null,8,["thread-id","show"])):M("",!0),e("div",{ref_key:"messagesContainer",ref:ae,class:"flex-1 overflow-y-auto overflow-x-hidden p-4 space-y-4",onScroll:ue},[t.threadId?M("",!0):(a(),o("div",lc," Select a thread to view messages ")),X(w)?(a(),o("div",sc,[P(Te,{size:"sm"}),fe[11]||(fe[11]=e("span",{class:"ml-2 text-xs text-neutral-500"},"Loading older messages...",-1))])):X(T)?(a(),o("div",nc,[P(Te)])):X(K)?(a(),o("div",rc," Error loading messages: "+V(X(K)),1)):t.threadId&&X(B).length===0?(a(),o("div",ic," No messages yet ")):(a(),se(Ed,{key:5,ref_key:"agentMessagesRef",ref:F,messages:X(B),threadId:t.threadId,selectedMessageId:t.selectedMessageId,selectedLogId:t.selectedLogId,hoveredLogId:t.hoveredLogId,isEditMode:g.value,selectedForDelete:d.value,editedMessages:p.value,onMessageClick:fe[5]||(fe[5]=(_e,Ne)=>l("messageClick",_e,Ne)),onMessageHover:fe[6]||(fe[6]=_e=>l("messageHover",_e)),onSelectionChange:_,onMessageEdit:b},null,8,["messages","threadId","selectedMessageId","selectedLogId","hoveredLogId","isEditMode","selectedForDelete","editedMessages"]))],544),t.threadId&&g.value?(a(),o("div",dc,[e("div",uc,[e("button",{onClick:v,class:"px-4 py-2 rounded-lg font-medium text-sm transition-colors bg-neutral-200 text-black hover:bg-neutral-300 dark:bg-neutral-700 dark:text-white dark:hover:bg-neutral-600"}," Cancel "),e("button",{onClick:q,disabled:!D.value,class:oe(["px-4 py-2 rounded-lg font-medium text-sm transition-colors",{"bg-red-600 text-white hover:bg-red-700":D.value&&y.value>0,"bg-black text-white hover:bg-neutral-800 dark:bg-white dark:text-black dark:hover:bg-neutral-200":D.value&&y.value===0,"bg-neutral-200 text-neutral-400 dark:bg-neutral-700 dark:text-neutral-500 cursor-not-allowed":!D.value}])},V(k.value),11,cc)])])):t.threadId?(a(),o("div",pc,[X(R).length>0?(a(),o("div",vc,[(a(!0),o(me,null,ye(X(R),_e=>(a(),o("div",{key:_e.id,class:"relative group"},[_e.isImage?(a(),o("div",mc,[_e.previewUrl?(a(),o("img",{key:0,src:_e.previewUrl,alt:_e.name,class:"w-full h-full object-cover"},null,8,fc)):(a(),o("div",hc,[...fe[12]||(fe[12]=[e("div",{class:"w-4 h-4 border-2 border-neutral-300 border-t-neutral-600 rounded-full animate-spin"},null,-1)])]))])):(a(),o("div",gc,[e("span",{class:"text-xs text-neutral-600 dark:text-neutral-300 max-w-[80px] truncate",title:_e.name},V(_e.name),9,bc)])),e("button",{onClick:Ie(Ne=>X(ne)(_e.id),["stop"]),class:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-neutral-600 dark:bg-neutral-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500"},[...fe[13]||(fe[13]=[e("span",{class:"text-[10px] font-bold leading-none"},"x",-1)])],8,xc)]))),128))])):M("",!0),e("div",yc,[e("button",{onClick:ke,class:oe(["flex-shrink-0 px-2 h-7 rounded-md flex items-center justify-center font-medium text-xs transition-colors mt-2.5",{"bg-black text-white dark:bg-white dark:text-black":be.value==="A","bg-neutral-300 text-black dark:bg-neutral-600 dark:text-white":be.value==="B"}]),title:"Toggle between sides"},V(we.value),3),e("div",kc,[P(Yu,{ref_key:"fileUploadRef",ref:U,"is-processing":!1,onFilesSelected:I},null,512),Me(e("textarea",{ref_key:"messageTextarea",ref:Q,"onUpdate:modelValue":fe[7]||(fe[7]=_e=>j.value=_e),onKeydown:Fe,onPaste:fe[8]||(fe[8]=_e=>U.value?.handlePaste(_e)),disabled:De.value,placeholder:"Type a message...",rows:"1",class:"flex-1 bg-transparent text-black dark:text-white resize-none focus:outline-none disabled:opacity-50 mt-0.5",style:{"max-height":"120px","min-height":"24px"},onInput:fe[9]||(fe[9]=_e=>{const Ne=_e.target;Ne.style.height="auto",Ne.style.height=Math.min(Ne.scrollHeight,120)+"px"})},null,40,wc),[[Oe,j.value]]),X(H)?(a(),o("button",{key:1,id:"stop-thread-button",onClick:Re,class:"flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center transition-all bg-red-600 text-white dark:bg-red-500 hover:bg-red-700 dark:hover:bg-red-600",title:"Stop execution"},[...fe[15]||(fe[15]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",class:"w-4 h-4"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M5.25 7.5A2.25 2.25 0 017.5 5.25h9a2.25 2.25 0 012.25 2.25v9a2.25 2.25 0 01-2.25 2.25h-9a2.25 2.25 0 01-2.25-2.25v-9z"})],-1)])])):(a(),o("button",{key:0,id:"send-message-button",onClick:Le,disabled:!j.value.trim()&&!S.value||De.value||C.value,class:oe(["flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center transition-all",{"bg-black text-white dark:bg-white dark:text-black":(j.value.trim()||S.value)&&!De.value&&!C.value,"bg-neutral-200 text-neutral-400 dark:bg-neutral-700 dark:text-neutral-600":!j.value.trim()&&!S.value||De.value||C.value}]),title:"Send message (Enter)"},[De.value?(a(),o("div",Cc,[P(Te)])):(a(),o("svg",$c,[...fe[14]||(fe[14]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M4.5 10.5 12 3m0 0 7.5 7.5M12 3v18"},null,-1)])]))],10,_c))])])])):M("",!0)])]))}});function Tc(t,n){const{limit:s=100,offset:i=0,order:l="desc",autoFetch:u=!0,enableWebSocket:r=!1}=n||{};W(()=>!!(typeof t=="string"?t:t?.value));const c=W(()=>{const Y=typeof t=="string"?t:t?.value;if(!Y)return de("/api/threads/placeholder/logs");const ne=new URLSearchParams,O=typeof s=="number"?s:s.value,S=typeof i=="number"?i:i.value,C=typeof l=="string"?l:l.value;return ne.append("limit",O.toString()),ne.append("offset",S.toString()),ne.append("order",C),de(`/api/threads/${Y}/logs?${ne.toString()}`)}),{data:f,error:g,isFetching:d,isFinished:p,execute:h,abort:_}=Ue(c,{immediate:!1}).get().json();ve([c,()=>u],([Y,ne])=>{Y&&!Y.includes("placeholder")&&ne&&h()},{immediate:!0});const b=W(()=>!g.value||g.value.toString().includes("aborted")||g.value.toString().includes("abort")?null:g.value),v=W(()=>f.value?.logs||[]),y=W(()=>f.value?.total||0),x=W(()=>f.value?.hasMore||!1),k=m(null),D=m(!1),q=m(null),B=m([]);let N=0,T=null,w=null,K=!0,te=null;const le=3e4,H=3e4,A=()=>{T&&(clearTimeout(T),T=null),w&&(clearInterval(w),w=null)},$=()=>{w&&clearInterval(w),w=setInterval(()=>{k.value&&k.value.readyState===WebSocket.OPEN&&k.value.send("ping")},H)},L=()=>{if(!K||!r)return;const Y=Math.min(1e3*Math.pow(2,N),le);N++,console.log(`[Logs WebSocket] Scheduling reconnect in ${Y}ms (attempt ${N})`),T=setTimeout(()=>{K&&J()},Y)},J=()=>{const Y=typeof t=="string"?t:t?.value;if(!Y||!r)return;k.value&&(te=null,k.value.close()),N===0&&(B.value=[]);const ne=window.location.protocol==="https:"?"wss:":"ws:",O=window.location.host;let S=`${ne}//${O}${de(`/api/threads/${Y}/logs`)}`;const C=localStorage.getItem("auth_token");C&&(S+=`?token=${encodeURIComponent(C)}`);try{const U=new WebSocket(S);k.value=U,te=U,U.onopen=()=>{te===U&&(D.value=!0,q.value=null,N=0,$(),console.log("[Logs WebSocket] Connected"))},U.onmessage=I=>{if(te===U&&I.data!=="pong")try{const ae=JSON.parse(I.data);if(ae.type==="log_data"){const F=B.value.findIndex(z=>z.id===ae.log_id),G=v.value.find(z=>z.id===ae.log_id);F>=0?B.value[F]={...B.value[F],...ae.data}:G?B.value.push({...G,...ae.data}):B.value.push({id:ae.log_id,...ae.data})}}catch(ae){console.error("[Logs WebSocket] Failed to parse message:",ae)}},U.onerror=I=>{te===U&&(q.value="WebSocket connection error",console.error("[Logs WebSocket] Error:",I))},U.onclose=()=>{te===U&&(D.value=!1,A(),console.log("[Logs WebSocket] Disconnected"),L())}}catch(U){q.value=U.message||"Failed to create WebSocket",console.error("[Logs WebSocket] Creation error:",U),L()}},ee=()=>{K=!1,A(),te=null,k.value&&(k.value.close(),k.value=null),D.value=!1,N=0,B.value=[]},E=()=>{K=!0,N=0,J()};return Be(()=>{ee()}),{logs:W(()=>{if(!r)return v.value;const Y=new Map;v.value.forEach(S=>Y.set(S.id,S)),B.value.forEach(S=>Y.set(S.id,S));const ne=typeof l=="string"?l:l.value;return Array.from(Y.values()).sort((S,C)=>ne==="desc"?C.created_at-S.created_at:S.created_at-C.created_at)}),total:y,hasMore:x,error:b,isFetching:d,isFinished:p,refetch:h,abort:_,wsConnected:D,wsError:q,connectWebSocket:E,disconnectWebSocket:ee}}function Sc(t,n){const s=W(()=>{const c=t.value,f=n.value;return!c||!f?null:de(`/api/threads/${c}/logs/${f}`)}),{data:i,error:l,isFetching:u,execute:r}=Ue(s,{immediate:!1}).get().json();return ve([t,n],([c,f])=>{c&&f&&r()},{immediate:!0}),{logDetails:i,error:l,isFetching:u,refetch:r}}const Vc=["disabled","title"],Mc={key:1,xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Ic={key:2,xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Ec={key:3},wa=pe({__name:"CopyButton",props:{content:{},variant:{},size:{},disabled:{type:Boolean}},setup(t){const n=t,s=m(!1),i=m(!1),l=async()=>{s.value=!0;try{await navigator.clipboard.writeText(n.content),i.value=!0,setTimeout(()=>{i.value=!1},2e3)}catch(c){console.error("Failed to copy:",c),alert(`Failed to copy: ${c instanceof Error?c.message:"Unknown error"}`)}finally{s.value=!1}},u={xs:"p-1 text-xs",sm:"px-2 py-1 text-xs"},r={solid:"bg-black text-white dark:bg-white dark:text-black",ghost:"bg-white dark:bg-neutral-950 border border-neutral-300 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-900"};return(c,f)=>(a(),o("button",{onClick:l,disabled:s.value||t.disabled,class:oe([u[t.size||"sm"],r[t.variant||"solid"],"font-medium rounded hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed transition-all"]),title:t.disabled?"No content to copy":i.value?"Copied!":"Copy to clipboard"},[s.value?(a(),se(Te,{key:0,size:"xs"})):t.variant==="ghost"&&!i.value?(a(),o("svg",Mc,[...f[0]||(f[0]=[e("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},null,-1),e("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"},null,-1)])])):t.variant==="ghost"&&i.value?(a(),o("svg",Ic,[...f[1]||(f[1]=[e("polyline",{points:"20 6 9 17 4 12"},null,-1)])])):(a(),o("span",Ec,V(i.value?"Copied!":"Copy"),1))],10,Vc))}}),bt="__shiki_highlighter__";let ut=null;async function Lc(){return typeof window<"u"&&window[bt]?window[bt]:ut||(ut=ro({themes:["min-light","github-dark-high-contrast"],langs:["json","markdown"]}).then(t=>(typeof window<"u"&&(window[bt]=t),t)),ut)}const Ac={class:"code-block"},Pc={key:0,class:"text-xs text-neutral-500 p-2"},Dc=["innerHTML"],xt=pe({__name:"CodeBlock",props:{code:{},language:{}},setup(t){const n=t,s=m(""),i=m(!0),l=async()=>{const u=n.code??"";if(!u){s.value='<pre class="shiki"><code></code></pre>',i.value=!1;return}try{const r=await Lc();if(n.language==="json"||n.language==="markdown")s.value=r.codeToHtml(u,{lang:n.language,themes:{light:"min-light",dark:"github-dark-high-contrast"}});else{const c=u.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");s.value=`<pre class="shiki shiki-text"><code>${c}</code></pre>`}}catch{const c=u.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");s.value=`<pre class="shiki"><code>${c}</code></pre>`}finally{i.value=!1}};return Ve(()=>{l()}),ve(()=>n.code,()=>{l()}),(u,r)=>(a(),o("div",Ac,[i.value?(a(),o("div",Pc,"Loading...")):(a(),o("div",{key:1,innerHTML:s.value,class:"code-content"},null,8,Dc))]))}}),jc={class:"json-viewer relative bg-white dark:bg-neutral-900"},Oc={key:0,class:"absolute top-[5px] right-[5px] z-10"},Uc=["innerHTML"],Rc=["src","alt"],Nc=pe({__name:"JsonViewer",props:{json:{},threadId:{},showCopyButton:{type:Boolean}},setup(t){const n=t,s=m(null),i=m(null),l=h=>[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp"].some(b=>h.toLowerCase().endsWith(b)),u=h=>n.threadId?de(`/api/threads/${n.threadId}/fs${h}`):null,r=W(()=>{if(!n.json)return"";if(typeof n.json=="string")try{return JSON.stringify(JSON.parse(n.json),null,2)}catch{return n.json}return JSON.stringify(n.json,null,2)}),c=h=>h.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),f=(h,_=0)=>{const b=" ".repeat(_),v=y=>`<span class="json-punct">${y}</span>`;if(h===null)return'<span class="json-null">null</span>';if(typeof h=="boolean")return`<span class="json-boolean">${h}</span>`;if(typeof h=="number")return`<span class="json-number">${h}</span>`;if(typeof h=="string"){const y=c(h);return n.threadId&&l(h)&&h.startsWith("/attachments/")?`${v('"')}<span class="json-image-path" data-path="${c(h)}">${y}</span>${v('"')}`:`${v('"')}<span class="json-string">${y}</span>${v('"')}`}if(Array.isArray(h)){if(h.length===0)return`${v("[")}${v("]")}`;const y=h.map((x,k)=>{const D=k<h.length-1?v(","):"";return`${b} ${f(x,_+1)}${D}`});return`${v("[")}
1
+ import{d as me,i as Xt,c as J,t as Aa,r as v,w as fe,o as Me,a as Be,p as Pa,m as De,b as o,e as a,f as e,n as ot,g as et,h as Te,u as Ye,j as ae,k as V,l as ne,q as X,F as ve,s as ke,v as A,x as Ee,y as be,z as lt,A as Ze,B as S,R as Lt,C as Ce,T as it,D as Xe,E as Ie,G as Oe,H as Da,I as Ue,J as ja,X as ft,K as nt,S as Yt,L as Oa,M as Ua,N as Qt,O as Ra,P as Tt,Q as Na,U as Zt,V as Ke,W as ea,Y as mt,Z as Fa,_ as ta,$ as kt,a0 as At,a1 as Ba,a2 as qa,a3 as za,a4 as Ha,a5 as Wa,a6 as aa,a7 as Pt,a8 as Ja,a9 as Ka,aa as Ga,ab as Xa,ac as Ya,ad as oa,ae as Qa,af as la,ag as Za,ah as eo,ai as sa,aj as wt,ak as We,al as st,am as to,an as ao,ao as na,ap as ra,aq as oo,ar as lo,as as so,at as no,au as ro}from"./vue.js";import{f as io}from"./vendor.js";import{W as uo,a as co,e as Dt}from"./monaco.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const l of document.querySelectorAll('link[rel="modulepreload"]'))i(l);new MutationObserver(l=>{for(const u of l)if(u.type==="childList")for(const r of u.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function s(l){const u={};return l.integrity&&(u.integrity=l.integrity),l.referrerPolicy&&(u.referrerPolicy=l.referrerPolicy),l.crossOrigin==="use-credentials"?u.credentials="include":l.crossOrigin==="anonymous"?u.credentials="omit":u.credentials="same-origin",u}function i(l){if(l.ep)return;l.ep=!0;const u=s(l);fetch(l.href,u)}})();var ia=class{endpoint;token;constructor(t){this.endpoint=t.replace(/\/$/,""),this.token=typeof localStorage<"u"?localStorage.getItem("agentbuilder_auth_token"):null}getEndpoint(){return this.endpoint}async createThread(t){const n=await fetch(`${this.endpoint}/threads`,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`Failed to create thread: ${n.statusText}`);return n.json()}async getThread(t){const n=await fetch(`${this.endpoint}/threads/${t}`,{method:"GET",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to get thread: ${n.statusText}`);return n.json()}async getMessages(t,n={}){const s=new URLSearchParams;n.limit!==void 0&&s.set("limit",String(n.limit)),n.offset!==void 0&&s.set("offset",String(n.offset)),n.depth!==void 0&&s.set("depth",String(n.depth)),n.includeSilent!==void 0&&s.set("includeSilent",String(n.includeSilent));const i=s.toString(),l=`${this.endpoint}/threads/${t}/messages${i?`?${i}`:""}`,u=await fetch(l,{method:"GET",headers:this.getHeaders()});if(!u.ok)throw new Error(`Failed to get messages: ${u.statusText}`);return(await u.json()).messages||[]}async sendMessage(t,n){const s=await fetch(`${this.endpoint}/threads/${t}/messages`,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok)throw new Error(`Failed to send message: ${s.statusText}`);return s.json()}async stopExecution(t){const n=await fetch(`${this.endpoint}/threads/${t}/stop`,{method:"POST",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to stop execution: ${n.statusText}`);await n.json()}async deleteMessage(t,n){const s=await fetch(`${this.endpoint}/threads/${t}/messages/${n}`,{method:"DELETE",headers:this.getHeaders()});if(!s.ok)throw new Error(`Failed to delete message: ${s.statusText}`);return s.json()}async uploadFile(t,n,s){const i=encodeURIComponent(n.name),l=`${this.endpoint}/threads/${t}/fs/${i}`;if(s?.thumbnail){const r=await this.fileToBase64(n),c=await fetch(l,{method:"POST",headers:{...this.getHeaders(),"Content-Type":"application/json"},body:JSON.stringify({data:r,mimeType:n.type,thumbnail:s.thumbnail,metadata:{width:s.width,height:s.height}})});if(!c.ok)throw new Error(`Failed to upload file: ${c.statusText}`);return c.json()}const u=await fetch(l,{method:"POST",headers:{...this.getHeaders(),"Content-Type":n.type},body:n});if(!u.ok)throw new Error(`Failed to upload file: ${u.statusText}`);return u.json()}fileToBase64(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>{const u=i.result.split(",")[1];n(u)},i.onerror=()=>s(new Error("Failed to read file")),i.readAsDataURL(t)})}getFileUrl(t,n){const i=(n.startsWith("/")?n.slice(1):n).split("/").map(l=>encodeURIComponent(l)).join("/");return`${this.endpoint}/threads/${t}/fs/${i}`}getThumbnailUrl(t,n){return`${this.getFileUrl(t,n)}?thumbnail=true`}async listFiles(t){const n=await fetch(`${this.endpoint}/threads/${t}/fs?find=**/*&type=file`,{method:"GET",headers:this.getHeaders()});if(!n.ok)throw new Error(`Failed to list files: ${n.statusText}`);return(await n.json()).files||[]}connectMessageWebSocket(t,n={},s={}){const i=new URLSearchParams;this.token&&i.set("token",this.token),s.includeSilent!==void 0&&i.set("includeSilent",String(s.includeSilent)),s.depth!==void 0&&i.set("depth",String(s.depth));const l=this.endpoint.startsWith("https")?"wss":"ws",r=`${this.endpoint.replace(/^https?/,l)}/threads/${t}/stream?${i.toString()}`,c=new WebSocket(r);return c.onopen=()=>{n.onOpen?.()},c.onmessage=f=>{try{if(typeof f.data=="string"&&f.data==="pong")return;const g=JSON.parse(f.data);switch(g.type){case"message_data":n.onMessage?.(g);break;case"message_chunk":n.onChunk?.(g);break;case"event":n.onEvent?.(g);break;case"error":n.onError?.(g);break}}catch(g){console.error("Failed to parse WebSocket message:",g)}},c.onerror=f=>{console.error("WebSocket error:",f),n.onError?.({type:"error",error:"WebSocket connection error"})},c.onclose=f=>{console.log(`[AgentBuilderClient] Message WebSocket closed - code: ${f.code}, reason: ${f.reason||"none"}, wasClean: ${f.wasClean}`),n.onClose?.()},c}connectLogWebSocket(t,n={}){const s=new URLSearchParams;this.token&&s.set("token",this.token);const i=this.endpoint.startsWith("https")?"wss":"ws",u=`${this.endpoint.replace(/^https?/,i)}/threads/${t}?${s.toString()}`,r=new WebSocket(u);return r.onopen=()=>{n.onOpen?.()},r.onmessage=c=>{try{if(typeof c.data=="string"&&c.data==="pong")return;const f=JSON.parse(c.data);switch(f.type){case"log_data":n.onLog?.(f);break;case"custom":n.onCustom?.(f);break;case"stopped_by_user":n.onStopped?.(f);break}}catch(f){console.error("Failed to parse WebSocket message:",f)}},r.onerror=c=>{console.error("WebSocket error:",c)},r.onclose=()=>{n.onClose?.()},r}getHeaders(){const t={};return this.token&&(t.Authorization=`Bearer ${this.token}`),t}},po=class{client;threadId;callbacks;options;ws=null;status="disconnected";reconnectAttempts=0;reconnectTimeout=null;heartbeatInterval=null;isReconnecting=!1;shouldReconnect=!0;constructor(t,n,s={},i={}){this.client=t,this.threadId=n,this.callbacks=s,this.options={depth:i.depth??0,includeSilent:i.includeSilent??!1,heartbeatInterval:i.heartbeatInterval??3e4,maxReconnectDelay:i.maxReconnectDelay??3e4}}getStatus(){return this.status}getThreadId(){return this.threadId}connect(){this.ws&&this.ws.readyState!==WebSocket.CLOSED||(this.shouldReconnect=!0,this.isReconnecting=!1,this.setStatus("connecting"),this.ws=this.client.connectMessageWebSocket(this.threadId,{onOpen:()=>{this.setStatus("connected"),this.reconnectAttempts=0,this.isReconnecting=!1,this.startHeartbeat()},onMessage:t=>{this.callbacks.onMessage?.(t)},onChunk:t=>{this.callbacks.onChunk?.(t)},onEvent:t=>{this.callbacks.onEvent?.(t)},onError:t=>{this.callbacks.onError?.(t)},onClose:()=>{this.clearTimers(),this.scheduleReconnect()}},{depth:this.options.depth,includeSilent:this.options.includeSilent}))}disconnect(){this.shouldReconnect=!1,this.clearTimers(),this.ws&&(this.ws.close(),this.ws=null),this.reconnectAttempts=0,this.isReconnecting=!1,this.setStatus("disconnected")}updateCallbacks(t){this.callbacks={...this.callbacks,...t}}updateOptions(t){this.options={...this.options,...t}}setStatus(t){this.status!==t&&(this.status=t,this.callbacks.onStatusChange?.(t))}startHeartbeat(){this.clearHeartbeat(),this.heartbeatInterval=setInterval(()=>{this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send("ping")},this.options.heartbeatInterval)}clearHeartbeat(){this.heartbeatInterval&&(clearInterval(this.heartbeatInterval),this.heartbeatInterval=null)}clearReconnectTimeout(){this.reconnectTimeout&&(clearTimeout(this.reconnectTimeout),this.reconnectTimeout=null)}clearTimers(){this.clearHeartbeat(),this.clearReconnectTimeout()}scheduleReconnect(){if(!this.shouldReconnect||this.isReconnecting){this.setStatus("disconnected");return}this.isReconnecting=!0,this.setStatus("reconnecting");const t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),this.options.maxReconnectDelay);this.reconnectAttempts++,this.reconnectTimeout=setTimeout(()=>{this.shouldReconnect&&this.connect()},t)}};function jt(t){return t.toLowerCase().startsWith("image/")}var Ot=256;function mo(t){return new Promise((n,s)=>{const i=new Image,l=URL.createObjectURL(t);i.onload=()=>{URL.revokeObjectURL(l),n(i)},i.onerror=()=>{URL.revokeObjectURL(l),s(new Error("Failed to load image"))},i.src=l})}function vo(t){const{width:n,height:s}=t,i=n/s;let l,u;i>1?(l=Math.min(Ot,n),u=Math.floor(l/i)):(u=Math.min(Ot,s),l=Math.floor(u*i));const r=document.createElement("canvas");r.width=l,r.height=u;const c=r.getContext("2d");if(!c)throw new Error("Failed to get canvas context");return c.drawImage(t,0,0,l,u),r.toDataURL("image/webp",.8).split(",")[1]}async function fo(t){const n=await mo(t);return{thumbnail:vo(n),width:n.width,height:n.height}}function ho(){return`pending-${Date.now()}-${Math.random().toString(36).substr(2,9)}`}function go(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>n(i.result),i.onerror=s,i.readAsDataURL(t)})}var bo=class{createPendingFile(t){return{id:ho(),name:t.name,mimeType:t.type,size:t.size,isImage:jt(t.type),localPreviewUrl:null,status:"uploading"}}queueFiles(t){return Array.from(t).map(n=>({pending:this.createPendingFile(n),file:n}))}async executeUpload(t,n,s,i,l,u={}){const{generateThumbnail:r=!0,generatePreview:c=!0}=u,f=jt(n.type);f&&c&&go(n).then(g=>l({localPreviewUrl:g})).catch(g=>console.error("Failed to generate preview:",g));try{let g;if(f&&r)try{const p=await fo(n);g={thumbnail:p.thumbnail,width:p.width,height:p.height}}catch(p){console.warn("Failed to generate thumbnail:",p)}const d=await i.uploadFile(t,n,g);return l({id:d.id,status:"ready",path:d.path,width:d.width,height:d.height}),d}catch(g){throw l({status:"error",error:g instanceof Error?g.message:"Failed to upload file"}),g}}async executeUploads(t,n,s,i,l={}){const u=n.map(({pending:r,file:c})=>this.executeUpload(t,c,r.id,s,f=>i(r.id,f),l).catch(f=>f instanceof Error?f:new Error(String(f))));return Promise.all(u)}};function xo(t){if(t.length===0)return[];const n=[];let s=0;for(;s<t.length;){const i=t[s];if(i.role==="assistant"&&i.tool_calls){let l;try{l=JSON.parse(i.tool_calls)}catch{n.push(i),s++;continue}const u=[],r=[],c=[];let f=i.reasoning_content||null,g="completed";const d=i.id,p=i.created_at,h=i.depth;i.status==="pending"?g="pending":i.status==="failed"&&(g="failed"),i.content&&r.push(i.content);for(const k of l)u.push({id:k.id||i.id,type:"tool_call",name:k.function?.name,content:k.function?.arguments||null,status:null,tool_call_id:k.id});let _=s+1;for(;_<t.length;){const k=t[_];if(k.role==="tool"){const D=k.tool_status||"pending";if(u.push({id:k.id,type:"tool_result",name:k.name||void 0,content:k.content,status:D,tool_call_id:k.tool_call_id||void 0}),k.attachments)try{let q;typeof k.attachments=="string"?q=JSON.parse(k.attachments):Array.isArray(k.attachments)?q=k.attachments:q=[],c.push(...q)}catch{}_++}else if(k.role==="assistant"&&k.tool_calls){let D;try{D=JSON.parse(k.tool_calls)}catch{break}k.status==="pending"?g="pending":k.status==="failed"&&g!=="pending"&&(g="failed"),k.content&&r.push(k.content),!f&&k.reasoning_content&&(f=k.reasoning_content);for(const q of D)u.push({id:q.id||k.id,type:"tool_call",name:q.function?.name,content:q.function?.arguments||null,status:null,tool_call_id:q.id});_++}else break}const b=new Set(u.filter(k=>k.type==="tool_call").map(k=>k.tool_call_id)),m=u.filter(k=>k.type==="tool_result"&&k.tool_call_id&&!b.has(k.tool_call_id));for(const k of m){const D=u.indexOf(k),q=k.content?.match(/Tool not found: (\w+)/)?.[1]||"unknown_tool",B={id:`synthetic-${k.tool_call_id}`,type:"tool_call",name:q,content:null,status:k.status,tool_call_id:k.tool_call_id};u.splice(D,0,B)}for(const k of u)if(k.type==="tool_call"&&k.tool_call_id&&k.status===null){const D=u.find(q=>q.type==="tool_result"&&q.tool_call_id===k.tool_call_id);D?k.status=D.status:k.status="pending"}const y=r.length>0?r.join(""):null,x={id:d,type:"workblock",content:y,reasoning_content:f,workItems:u,status:g,created_at:p,depth:h,attachments:c.length>0?c:void 0};n.push(x),s=_}else n.push(i),s++}return n}var da=Symbol("StandardAgents"),ua=Symbol("Thread"),yo={install(t,n){if(!n?.endpoint)throw new Error("StandardAgentsPlugin requires an endpoint option");const i={client:new ia(n.endpoint),endpoint:n.endpoint};t.provide(da,i)}};function ko(){const t=Xt(da);if(!t)throw new Error("useStandardAgents must be used within a component where StandardAgentsPlugin is installed");return t}var Ut=new bo;function wo(t){return new Promise((n,s)=>{const i=new FileReader;i.onload=()=>{const u=i.result.split(",")[1];n(u)},i.onerror=()=>s(new Error("Failed to read file")),i.readAsDataURL(t)})}function _o(t,n={}){const{preload:s=!0,live:i=!0,useWorkblocks:l=!1,depth:u=0,includeSilent:r=!1,endpoint:c}=n,f=J(()=>Aa(t)),g=ko(),d=c?new ia(c):g.client,p={preload:s,live:i,useWorkblocks:l,depth:u,includeSilent:r},h=v([]),_=v("disconnected"),b=v(s),m=v(null),y=v([]),x=v([]),k=v([]),D=J(()=>{const I=new Set(x.value.map(O=>O.path));return[...y.value.filter(O=>!O.path||!I.has(O.path)),...x.value]}),q=new Map;let B=null;const F=J(()=>l?xo(h.value):h.value);async function T(){b.value=!0,m.value=null;try{const I=await d.getMessages(f.value,{depth:u,includeSilent:r});h.value=I}catch(I){m.value=I instanceof Error?I:new Error(String(I))}finally{b.value=!1}}async function $(){try{const I=await d.listFiles(f.value);x.value=I.filter(le=>!le.isDirectory).map(le=>({id:le.path,name:le.name,path:le.path,mimeType:le.mimeType,size:le.size,isImage:le.mimeType.startsWith("image/"),status:"committed",localPreviewUrl:null}))}catch(I){console.error("Failed to load files:",I)}}function K(I){if(I.file.isDirectory)return;const le={id:I.path,name:I.file.name,path:I.path,mimeType:I.file.mimeType,size:I.file.size,isImage:I.file.mimeType?.startsWith("image/")||!1,status:"committed",localPreviewUrl:null},O=x.value.findIndex(W=>W.path===I.path);O>=0?x.value[O]=le:x.value=[...x.value,le]}function oe(I){if(I.file.isDirectory)return;const le={id:I.path,name:I.file.name,path:I.path,mimeType:I.file.mimeType,size:I.file.size,isImage:I.file.mimeType?.startsWith("image/")||!1,status:"committed",localPreviewUrl:null},O=x.value.findIndex(W=>W.path===I.path);O>=0?x.value[O]=le:x.value=[...x.value,le]}function te(I){x.value=x.value.filter(le=>le.path!==I.path)}function H(){i&&(B=new po(d,f.value,{onStatusChange:I=>{_.value=I},onMessage:I=>{if(I.type==="message_data"){const le=h.value.findIndex(O=>O.id===I.data.id);le>=0?h.value[le]=I.data:h.value=[...h.value,I.data]}},onChunk:I=>{const le=h.value.findIndex(O=>O.id===I.message_id);if(le>=0){const O=h.value[le];h.value[le]={...O,content:(O.content||"")+I.chunk}}},onEvent:I=>{I.eventType==="file_created"?K(I.data):I.eventType==="file_updated"?oe(I.data):I.eventType==="file_deleted"&&te(I.data);const le=q.get(I.eventType);le&&le.forEach(O=>{try{O(I.data)}catch(W){console.error(`Error in event listener for "${I.eventType}":`,W)}})},onError:I=>{m.value=I instanceof Error?I:new Error(String(I))}},{depth:u,includeSilent:r}),B.connect())}async function P(I){const le=`optimistic-${crypto.randomUUID()}`,O=k.value.map(z=>({id:z.id,type:"file",path:"",name:z.name,mimeType:z.mimeType,size:z.size,width:z.width,height:z.height,localPreviewUrl:z.previewUrl||void 0})),W={id:le,role:I.role,content:I.content,attachments:O.length>0?JSON.stringify(O):null,created_at:Date.now()*1e3,status:"pending"};h.value=[...h.value,W];const ce=[...k.value];k.value=[];try{const z=await Promise.all(ce.map(async Q=>({name:Q.name,mimeType:Q.mimeType,data:await wo(Q.file),width:Q.width,height:Q.height}))),N=await d.sendMessage(f.value,{...I,attachments:z.length>0?z:void 0});return h.value=h.value.filter(Q=>Q.id!==le),ce.forEach(Q=>{Q.previewUrl&&URL.revokeObjectURL(Q.previewUrl)}),N}catch(z){throw k.value=ce,h.value=h.value.filter(N=>N.id!==le),m.value=z instanceof Error?z:new Error(String(z)),z}}async function C(){try{await d.stopExecution(f.value)}catch(I){throw m.value=I instanceof Error?I:new Error(String(I)),I}}async function L(I){const le=[...h.value];h.value=h.value.filter(O=>O.id!==I);try{await d.deleteMessage(f.value,I)}catch(O){throw h.value=le,m.value=O instanceof Error?O:new Error(String(O)),O}}function G(I){const le=Ut.queueFiles(I);y.value=[...y.value,...le.map(O=>O.pending)];for(const{pending:O,file:W}of le)Ut.executeUpload(f.value,W,O.id,d,ce=>{y.value=y.value.map(z=>z.id===O.id?{...z,...ce}:z)}).catch(()=>{})}function ee(I){y.value=y.value.filter(le=>le.id!==I)}function E(I){return I.path?d.getFileUrl(f.value,I.path):""}function U(I){return I.path?d.getThumbnailUrl(f.value,I.path):""}function Z(I){return I.isImage?I.localPreviewUrl?I.localPreviewUrl:I.path?U(I):null:null}function se(I){const O=(I instanceof FileList?Array.from(I):Array.isArray(I)?I:[I]).map(W=>{const ce=W.type.startsWith("image/");return{id:crypto.randomUUID(),file:W,name:W.name,mimeType:W.type,size:W.size,isImage:ce,previewUrl:ce?URL.createObjectURL(W):null}});k.value=[...k.value,...O]}function j(I){const le=k.value.find(O=>O.id===I);le?.previewUrl&&URL.revokeObjectURL(le.previewUrl),k.value=k.value.filter(O=>O.id!==I)}function M(){k.value.forEach(I=>{I.previewUrl&&URL.revokeObjectURL(I.previewUrl)}),k.value=[]}function w(I,le){return q.has(I)||q.set(I,new Set),q.get(I).add(le),()=>{const O=q.get(I);O&&(O.delete(le),O.size===0&&q.delete(I))}}function R(){B?.disconnect(),B=null,_.value="disconnected"}return fe(f,(I,le)=>{I!==le&&(R(),h.value=[],m.value=null,y.value=[],x.value=[],k.value.forEach(O=>{O.previewUrl&&URL.revokeObjectURL(O.previewUrl)}),k.value=[],s&&T(),$(),H())}),Me(()=>{s&&T(),$(),H()}),Be(()=>{B?.disconnect(),q.clear(),k.value.forEach(I=>{I.previewUrl&&URL.revokeObjectURL(I.previewUrl)})}),{threadId:f,options:p,messages:h,workblocks:F,status:_,connectionStatus:_,isLoading:b,loading:b,error:m,sendMessage:P,stopExecution:C,deleteMessage:L,onEvent:w,subscribeToEvent:w,files:D,addFiles:G,removeFile:ee,getFileUrl:E,getThumbnailUrl:U,getPreviewUrl:Z,attachments:k,addAttachment:se,removeAttachment:j,clearAttachments:M}}var $o=me({name:"ThreadProvider",props:{threadId:{type:String,required:!0},preload:{type:Boolean,default:void 0},live:{type:Boolean,default:void 0},useWorkblocks:{type:Boolean,default:void 0},depth:{type:Number,default:void 0},includeSilent:{type:Boolean,default:void 0},endpoint:{type:String,default:void 0}},setup(t,{slots:n}){const s={};t.preload!==void 0&&(s.preload=t.preload),t.live!==void 0&&(s.live=t.live),t.useWorkblocks!==void 0&&(s.useWorkblocks=t.useWorkblocks),t.depth!==void 0&&(s.depth=t.depth),t.includeSilent!==void 0&&(s.includeSilent=t.includeSilent),t.endpoint!==void 0&&(s.endpoint=t.endpoint);const i=_o(()=>t.threadId,s);return Pa(ua,i),()=>n.default?.()}});function ca(){const t=Xt(ua);if(!t)throw new Error('useThread must be used within a <ThreadProvider>. Wrap your component with <ThreadProvider threadId="...">.');return t}const Co={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function To(t,n){return a(),o("svg",Co,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 8V4H8"}),e("rect",{width:"16",height:"12",x:"4",y:"8",rx:"2"}),e("path",{d:"M2 14h2m16 0h2m-7-1v2m-6-2v2"})],-1)])])}const Rt=De({name:"lucide-bot",render:To}),So={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Vo(t,n){return a(),o("svg",So,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"},null,-1)])])}const Nt=De({name:"lucide-message-square",render:Vo}),Mo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Io(t,n){return a(),o("svg",Mo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 20v2m0-20v2m5 16v2m0-20v2M2 12h2m-2 5h2M2 7h2m16 5h2m-2 5h2M20 7h2M7 20v2M7 2v2"}),e("rect",{width:"16",height:"16",x:"4",y:"4",rx:"2"}),e("rect",{width:"8",height:"8",x:"8",y:"8",rx:"1"})],-1)])])}const Eo=De({name:"lucide-cpu",render:Io}),Lo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ao(t,n){return a(),o("svg",Lo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e("path",{d:"M6 6h.01M6 18h.01"})],-1)])])}const Po=De({name:"lucide-server",render:Ao}),Do={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function jo(t,n){return a(),o("svg",Do,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z"},null,-1)])])}const Oo=De({name:"lucide-wrench",render:jo}),Uo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ro(t,n){return a(),o("svg",Uo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0a2.34 2.34 0 0 0 3.319 1.915a2.34 2.34 0 0 1 2.33 4.033a2.34 2.34 0 0 0 0 3.831a2.34 2.34 0 0 1-2.33 4.033a2.34 2.34 0 0 0-3.319 1.915a2.34 2.34 0 0 1-4.659 0a2.34 2.34 0 0 0-3.32-1.915a2.34 2.34 0 0 1-2.33-4.033a2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"}),e("circle",{cx:"12",cy:"12",r:"3"})],-1)])])}const No=De({name:"lucide-settings",render:Ro}),Fo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Bo(t,n){return a(),o("svg",Fo,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m15 18l-6-6l6-6"},null,-1)])])}const qo=De({name:"lucide-chevron-left",render:Bo}),zo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ho(t,n){return a(),o("svg",zo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("circle",{cx:"12",cy:"12",r:"4"}),e("path",{d:"M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"})],-1)])])}const Wo=De({name:"lucide-sun",render:Ho}),Jo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ko(t,n){return a(),o("svg",Jo,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"},null,-1)])])}const Go=De({name:"lucide-moon",render:Ko}),Xo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Yo(t,n){return a(),o("svg",Xo,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2"},null,-1)])])}const Qo=De({name:"lucide-activity",render:Yo}),Zo={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function el(t,n){return a(),o("svg",Zo,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),e("path",{d:"M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3m-6 4.2h5.7"})],-1)])])}const tl=De({name:"lucide-function-square",render:el}),al={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ol(t,n){return a(),o("svg",al,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m16 17l5-5l-5-5m5 5H9m0 9H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"},null,-1)])])}const ll=De({name:"lucide-log-out",render:ol}),sl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function nl(t,n){return a(),o("svg",sl,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2M16 3.128a4 4 0 0 1 0 7.744M22 21v-2a4 4 0 0 0-3-3.87"}),e("circle",{cx:"9",cy:"7",r:"4"})],-1)])])}const rl=De({name:"lucide-users",render:nl}),il={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function dl(t,n){return a(),o("svg",il,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"m15.5 7.5l2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4m2-2l-9.6 9.6"}),e("circle",{cx:"7.5",cy:"15.5",r:"5.5"})],-1)])])}const ul=De({name:"lucide-key",render:dl}),cl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function pl(t,n){return a(),o("svg",cl,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 7v14m-9-3a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4a4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3a3 3 0 0 0-3-3z"},null,-1)])])}const ml=De({name:"lucide-book-open",render:pl}),vl={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function fl(t,n){return a(),o("svg",vl,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 3h6v6m-11 5L21 3m-3 10v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"},null,-1)])])}const hl=De({name:"lucide-external-link",render:fl}),pa="agentbuilder-accent-theme",ma=["amber","lime","emerald","sky","blue","indigo","purple","fuchsia","pink","white"],_t=v("purple");let Ft=!1;function va(t){typeof document>"u"||(t==="purple"?delete document.documentElement.dataset.accent:document.documentElement.dataset.accent=t)}function gl(t){try{localStorage.setItem(pa,t)}catch{}}function bl(){try{const t=localStorage.getItem(pa);if(t&&ma.includes(t))return t}catch{}return"purple"}function fa(){if(Ft)return;Ft=!0;const t=bl();_t.value=t,va(t)}function xl(){fa();function t(n){_t.value=n,va(n),gl(n)}return{theme:_t,themes:ma,setTheme:t}}const Qe=me({__name:"DropShadow",props:{offsetX:{default:8},offsetY:{default:8},intensity:{default:.5},pattern:{default:"crosshatch"}},setup(t){const n=t,s=v(),i=v(),l=v(),u=v(0),r=(d,p,h,_,b,m)=>{d.beginPath(),d.moveTo(p+m,h),d.lineTo(p+_-m,h),d.quadraticCurveTo(p+_,h,p+_,h+m),d.lineTo(p+_,h+b-m),d.quadraticCurveTo(p+_,h+b,p+_-m,h+b),d.lineTo(p+m,h+b),d.quadraticCurveTo(p,h+b,p,h+b-m),d.lineTo(p,h+m),d.quadraticCurveTo(p,h,p+m,h),d.closePath()},c=async()=>{if(await Te(),!s.value||!i.value||!l.value)return;const d=s.value.getContext("2d");if(!d)return;const p=l.value.getBoundingClientRect(),h=l.value.firstElementChild;if(h){const y=getComputedStyle(h);u.value=parseFloat(y.borderRadius)||0}const _=p.width+n.offsetX+4,b=p.height+n.offsetY+4;s.value.width=_,s.value.height=b,s.value.style.width=`${_}px`,s.value.style.height=`${b}px`,d.clearRect(0,0,s.value.width,s.value.height);const m=document.documentElement.classList.contains("dark");if(d.fillStyle=m?"#6b7280":"black",d.globalAlpha=n.intensity,d.save(),r(d,n.offsetX,n.offsetY,p.width,p.height,u.value),d.clip(),n.pattern==="crosshatch"){const y=m?4:3;d.lineWidth=1,d.strokeStyle=m?"#6b7280":"black";for(let x=-p.height;x<p.width;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY),d.lineTo(n.offsetX+x+p.height,n.offsetY+p.height),d.stroke();for(let x=0;x<p.width+p.height;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY+p.height),d.lineTo(n.offsetX+x-p.height,n.offsetY),d.stroke()}else if(n.pattern==="dots"){const x=m?3:2,k=[[0,8,2,10],[12,4,14,6],[3,11,1,9],[15,7,13,5]];for(let D=0;D<p.width;D+=x)for(let q=0;q<p.height;q+=x){const B=Math.floor(D/x)%4,F=Math.floor(q/x)%4;k[F][B]/16<n.intensity&&d.fillRect(n.offsetX+D,n.offsetY+q,1,1)}}else if(n.pattern==="diagonal"){const y=m?5:4;d.lineWidth=1,d.strokeStyle=m?"#6b7280":"black";for(let x=-p.height;x<p.width;x+=y)d.beginPath(),d.moveTo(n.offsetX+x,n.offsetY),d.lineTo(n.offsetX+x+p.height,n.offsetY+p.height),d.stroke()}d.restore()};let f=null,g=null;return Me(()=>{f=new ResizeObserver(()=>{c()}),l.value&&f.observe(l.value),c(),g=new MutationObserver(()=>{c()}),g.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]})}),Be(()=>{l.value&&f&&f.unobserve(l.value),g&&g.disconnect()}),fe(()=>[n.offsetX,n.offsetY,n.intensity,n.pattern],()=>{c()}),(d,p)=>(a(),o("div",{ref_key:"container",ref:i,class:"relative",style:ot({paddingRight:`${t.offsetX}px`,paddingBottom:`${t.offsetY}px`})},[e("canvas",{ref_key:"canvas",ref:s,class:"absolute top-0 left-0 pointer-events-none"},null,512),e("div",{ref_key:"contentEl",ref:l,class:"relative"},[et(d.$slots,"default")],512)],4))}}),ha="/agents/assets/img/agent-builder-logo-light.svg",ga="/agents/assets/img/agent-builder-logo-dark.svg",yl="data:image/svg+xml,%3csvg%20width='100%25'%20height='100%25'%20viewBox='0%200%20150%20150'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20xml:space='preserve'%20xmlns:serif='http://www.serif.com/'%20style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg%20id='Artboard1'%20transform='matrix(1,0,0,1,1,1)'%3e%3crect%20x='-1'%20y='-1'%20width='150'%20height='150'%20style='fill:none;'/%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.816,92.912L108.064,59.193C103.573,53.307%20101.473,45.937%20102.197,38.566L105.475,5.046L99.553,4.466L96.312,37.643C95.895,41.808%2091.44,44.27%2087.71,42.369L30.34,13.394L27.659,18.7L84.686,47.494C87.184,48.762%2087.076,52.347%2084.504,53.452L0.387,89.671L2.741,95.139L86.189,59.211C88.76,58.106%2091.422,60.587%2090.48,63.231L62.918,141.119L68.532,143.111L96.384,64.408C97.507,61.257%20101.672,60.605%20103.7,63.249L129.107,96.498L133.834,92.876L133.816,92.912Z'%20style='fill:rgb(31,41,55);fill-opacity:0.5;fill-rule:nonzero;'/%3e%3c/g%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.925,90.214L107.648,7.346C106.036,2.257%20100.875,-0.821%2095.624,0.193L32.64,12.344C29.959,12.869%2027.605,14.408%2026.066,16.6C25.523,17.36%2025.07,18.211%2024.744,19.117L0.622,86.284C-0.917,90.594%200.459,95.375%204.081,98.164L59.568,141.137C61.469,142.604%2063.733,143.346%2066.015,143.346C68.079,143.346%2070.144,142.731%2071.937,141.517L129.832,102.111C133.707,99.468%20135.355,94.687%20133.943,90.232L133.925,90.214ZM116.92,85.922L47.127,53.923C44.374,52.673%2043.994,48.925%2046.421,47.132L94.175,11.873C97.416,9.483%20102.034,10.95%20103.284,14.771C108.173,29.548%20118.64,62.054%20124.218,79.457C125.631,83.876%20121.121,87.859%20116.902,85.94L116.92,85.922ZM79.162,15.567L42.455,42.659C40.083,44.415%2036.696,43.057%2036.189,40.16L33.781,26.342C33.038,22.05%2035.845,17.94%2040.119,17.089C49.409,15.241%2065.254,12.145%2076.681,9.917C79.995,9.265%2081.879,13.557%2079.162,15.567ZM29.126,34.238L31.716,49.069C31.915,50.21%2031.607,51.388%2030.865,52.275L16.559,69.587C15.291,71.127%2012.846,69.732%2013.516,67.849L25.704,33.93C26.32,32.21%2028.8,32.427%2029.126,34.22L29.126,34.238ZM12.882,83.386L29.543,63.231C31.517,60.84%2035.356,61.547%2036.352,64.499L56.308,123.661C57.322,126.668%2053.809,129.149%2051.31,127.193C41.223,119.297%2024.4,106.132%2014.404,98.164C9.84,94.542%209.152,87.878%2012.864,83.386L12.882,83.386ZM63.498,126.305L43.161,66.002C42.056,62.706%2045.407,59.681%2048.576,61.13L117.337,92.677C121.375,94.524%20121.864,100.083%20118.206,102.6C107.358,110.061%2088.326,123.064%2076.826,130.815C71.991,134.074%2065.381,131.829%2063.516,126.305L63.498,126.305Z'%20style='fill:rgb(31,41,55);fill-rule:nonzero;'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e",kl="data:image/svg+xml,%3csvg%20width='100%25'%20height='100%25'%20viewBox='0%200%20150%20150'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20xml:space='preserve'%20xmlns:serif='http://www.serif.com/'%20style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg%20id='Artboard1'%20transform='matrix(1,0,0,1,1,1)'%3e%3crect%20x='-1'%20y='-1'%20width='150'%20height='150'%20style='fill:none;'/%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.816,92.912L108.064,59.193C103.573,53.307%20101.473,45.937%20102.197,38.566L105.475,5.046L99.553,4.466L96.312,37.643C95.895,41.808%2091.44,44.27%2087.71,42.369L30.34,13.394L27.659,18.7L84.686,47.494C87.184,48.762%2087.076,52.347%2084.504,53.452L0.387,89.671L2.741,95.139L86.189,59.211C88.76,58.106%2091.422,60.587%2090.48,63.231L62.918,141.119L68.532,143.111L96.384,64.408C97.507,61.257%20101.672,60.605%20103.7,63.249L129.107,96.498L133.834,92.876L133.816,92.912Z'%20style='fill:rgb(249,250,251);fill-opacity:0.5;fill-rule:nonzero;'/%3e%3c/g%3e%3cg%20transform='matrix(1.034881,0,0,1.034881,4.124225,0)'%3e%3cpath%20d='M133.925,90.214L107.648,7.346C106.036,2.257%20100.875,-0.821%2095.624,0.193L32.64,12.344C29.959,12.869%2027.605,14.408%2026.066,16.6C25.523,17.36%2025.07,18.211%2024.744,19.117L0.622,86.284C-0.917,90.594%200.459,95.375%204.081,98.164L59.568,141.137C61.469,142.604%2063.733,143.346%2066.015,143.346C68.079,143.346%2070.144,142.731%2071.937,141.517L129.832,102.111C133.707,99.468%20135.355,94.687%20133.943,90.232L133.925,90.214ZM116.92,85.922L47.127,53.923C44.374,52.673%2043.994,48.925%2046.421,47.132L94.175,11.873C97.416,9.483%20102.034,10.95%20103.284,14.771C108.173,29.548%20118.64,62.054%20124.218,79.457C125.631,83.876%20121.121,87.859%20116.902,85.94L116.92,85.922ZM79.162,15.567L42.455,42.659C40.083,44.415%2036.696,43.057%2036.189,40.16L33.781,26.342C33.038,22.05%2035.845,17.94%2040.119,17.089C49.409,15.241%2065.254,12.145%2076.681,9.917C79.995,9.265%2081.879,13.557%2079.162,15.567ZM29.126,34.238L31.716,49.069C31.915,50.21%2031.607,51.388%2030.865,52.275L16.559,69.587C15.291,71.127%2012.846,69.732%2013.516,67.849L25.704,33.93C26.32,32.21%2028.8,32.427%2029.126,34.22L29.126,34.238ZM12.882,83.386L29.543,63.231C31.517,60.84%2035.356,61.547%2036.352,64.499L56.308,123.661C57.322,126.668%2053.809,129.149%2051.31,127.193C41.223,119.297%2024.4,106.132%2014.404,98.164C9.84,94.542%209.152,87.878%2012.864,83.386L12.882,83.386ZM63.498,126.305L43.161,66.002C42.056,62.706%2045.407,59.681%2048.576,61.13L117.337,92.677C121.375,94.524%20121.864,100.083%20118.206,102.6C107.358,110.061%2088.326,123.064%2076.826,130.815C71.991,134.074%2065.381,131.829%2063.516,126.305L63.498,126.305Z'%20style='fill:rgb(249,250,251);fill-rule:nonzero;'/%3e%3c/g%3e%3c/g%3e%3c/svg%3e";function wl(){return window.__AGENTBUILDER_CONFIG__||{mountPoint:"/agentbuilder"}}function dt(){return wl().mountPoint}function ue(t){const n=dt(),s=t.startsWith("/")?t:`/${t}`;return n==="/"?s:`${n}${s}`}const _l=["src"],$l=["src"],Cl={class:"flex-1 flex flex-col justify-between pt-2 pb-4"},Tl={class:"flex flex-col gap-1 px-2"},Sl={key:0},Vl=["onClick","title"],Ml={key:0,class:"flex-1 whitespace-nowrap overflow-hidden text-ellipsis text-left"},Il={key:0,class:"ml-4 space-y-0.5"},El=["onClick"],Ll={class:"whitespace-nowrap overflow-hidden text-ellipsis"},Al=["onClick","title"],Pl={key:0,class:"whitespace-nowrap overflow-hidden text-ellipsis"},Dl={class:"flex flex-col gap-1 px-2"},jl=["title"],Ol={key:0,class:"flex-1 whitespace-nowrap overflow-hidden text-ellipsis"},Ul={class:"relative settings-menu-container"},Rl={key:0,class:"absolute bottom-full mb-2 left-0 z-50"},Nl={class:"bg-white dark:bg-neutral-900 border border-neutral-300 dark:border-neutral-600 rounded-lg py-2 min-w-[200px]"},Fl={class:"px-4 py-3 border-b border-neutral-200 dark:border-neutral-700"},Bl=["title"],ql={class:"relative z-10 flex items-center justify-center w-8 h-full"},zl={class:"relative z-10 flex items-center justify-center w-8 h-full"},Hl={class:"px-4 pt-3 pb-4 border-b border-neutral-200 dark:border-neutral-700"},Wl={class:"grid grid-cols-5 gap-3"},Jl=["onClick","title"],Kl={key:0,class:"w-2 h-2 rounded-full bg-white shadow-sm"},Gl={key:0,class:"text-sm overflow-hidden whitespace-nowrap max-w-0 group-hover:max-w-[60px] group-hover:ml-2 transition-all duration-200"},Xl=me({__name:"Sidebar",props:{isCollapsed:{type:Boolean},isDark:{type:Boolean}},emits:["toggle-sidebar","toggle-theme"],setup(t,{emit:n}){function s(te){if(te.startsWith("/src/")||te.startsWith("data:"))return te;const H=dt();return H==="/"?te.replace("/agents/","/"):te.replace("/agents/",`${H}/`)}const i=s(ha),l=s(ga),u=s(yl),r=s(kl),c=t,f=Ye(),g=lt(),d=J(()=>f.name);function p(te){const H=f.path;return H===te.path||H.startsWith(te.path+"/")}const h=J(()=>c.isDark?l:i),_=J(()=>c.isDark?r:u),b=[{id:"threads",label:"Threads",icon:Qo,path:"/threads"},{id:"agents",label:"Agents",icon:Rt,path:"/agents"},{id:"prompts",label:"Prompts",icon:Nt,path:"/prompts"},{id:"tools",label:"Tools",icon:Oo,path:"/tools",hasSubnav:!0,subnav:[{id:"tools-functions",label:"Functions",icon:tl,path:"/tools#functions"},{id:"tools-prompts",label:"Prompts",icon:Nt,path:"/tools#prompts"},{id:"tools-agents",label:"Agents",icon:Rt,path:"/tools#agents"}]},{id:"models",label:"Models",icon:Eo,path:"/models"},{id:"providers",label:"Providers",icon:Po,path:"/providers"}],m=te=>{g.push(te)},y=te=>{g.push(te),k.value=!1},x=J(()=>typeof d.value=="string"&&(d.value==="tools"||d.value.startsWith("tools-"))),k=v(!1),{theme:D,themes:q,setTheme:B}=xl(),F={amber:"bg-amber-500",lime:"bg-lime-500",emerald:"bg-emerald-500",sky:"bg-sky-500",blue:"bg-blue-500",indigo:"bg-indigo-500",purple:"bg-purple-500",fuchsia:"bg-fuchsia-500",pink:"bg-pink-500",white:"bg-neutral-400 dark:bg-neutral-500"},T=J(()=>d.value==="users"||d.value==="api-keys"),$=()=>{k.value=!k.value},K=()=>{localStorage.removeItem("auth_token"),g.push("/login")},oe=te=>{const H=te.target;k.value&&!H.closest(".settings-menu-container")&&(k.value=!1)};return Me(()=>{document.addEventListener("click",oe)}),Be(()=>{document.removeEventListener("click",oe)}),(te,H)=>(a(),o("aside",{class:ae(["flex flex-col transition-all duration-300 pt-2.5",t.isCollapsed?"w-16":"w-60"])},[e("div",{class:ae(`flex items-center justify-between ${t.isCollapsed?"px-2 py-4":"p-4"}`)},[t.isCollapsed?V("",!0):(a(),o("img",{key:0,src:h.value,alt:"AgentBuilder",class:"h-8 mr-2 mt-0.5"},null,8,_l)),e("button",{onClick:H[0]||(H[0]=P=>te.$emit("toggle-sidebar")),class:ae(`p-1 rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors ${t.isCollapsed?"m-auto":"border border-black/20 dark:border-white/20 opacity-50 hover:opacity-100"}`),"aria-label":"Toggle sidebar"},[t.isCollapsed?(a(),o("img",{key:1,src:_.value,alt:"AgentBuilder",class:"w-7 h-7 m-auto"},null,8,$l)):(a(),ne(X(qo),{key:0,class:"w-5 h-5"}))],2)],2),e("nav",Cl,[e("div",Tl,[(a(),o(ve,null,ke(b,P=>(a(),o(ve,{key:P.id},[P.hasSubnav?(a(),o("div",Sl,[e("button",{onClick:C=>m(P.path),class:ae(["flex items-center gap-3 px-3 py-3 rounded text-sm font-medium transition-all w-full",x.value?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?P.label:void 0},[(a(),ne(Ze(P.icon),{class:"w-5 h-5 flex-shrink-0"})),t.isCollapsed?V("",!0):(a(),o("span",Ml,S(P.label),1))],10,Vl),!t.isCollapsed&&P.subnav?(a(),o("div",Il,[(a(!0),o(ve,null,ke(P.subnav,C=>(a(),o("button",{key:C.id,onClick:L=>m(C.path),class:ae(["flex items-center gap-3 px-3 py-1.5 text-sm transition-all w-full",d.value===C.id?"bg-black text-white dark:bg-white dark:text-black rounded":"hover:underline"])},[(a(),ne(Ze(C.icon),{class:"w-4 h-4 flex-shrink-0"})),e("span",Ll,S(C.label),1)],10,El))),128))])):V("",!0)])):(a(),o("button",{key:1,onClick:C=>m(P.path),class:ae(["flex items-center gap-3 px-3 py-3 rounded text-sm font-medium transition-all",p(P)?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?P.label:void 0},[(a(),ne(Ze(P.icon),{class:"w-5 h-5 flex-shrink-0"})),t.isCollapsed?V("",!0):(a(),o("span",Pl,S(P.label),1))],10,Al))],64))),64))]),e("div",Dl,[e("a",{href:"https://docs.standardagentbuilder.com/",target:"_blank",rel:"noopener noreferrer",class:ae(["flex items-center gap-3 px-3 py-2 rounded text-sm transition-all","hover:bg-black/5 dark:hover:bg-white/10 text-neutral-600 dark:text-neutral-400 hover:text-black dark:hover:text-white",t.isCollapsed&&"justify-center"]),title:t.isCollapsed?"Documentation":void 0},[A(X(ml),{class:"w-5 h-5 flex-shrink-0"}),t.isCollapsed?V("",!0):(a(),o("span",Ol," Docs ")),t.isCollapsed?V("",!0):(a(),ne(X(hl),{key:1,class:"w-3 h-3 flex-shrink-0 opacity-50"}))],10,jl),e("div",{class:ae(["flex items-center gap-1 pt-2 mt-1 border-t border-black/10 dark:border-white/10",t.isCollapsed?"flex-col":"justify-between"])},[e("div",Ul,[e("button",{onClick:Ee($,["stop"]),class:ae(["p-2 rounded transition-colors flex items-center",k.value||T.value?"bg-black/10 dark:bg-white/10 text-black dark:text-white":"hover:bg-black/5 dark:hover:bg-white/10 text-neutral-600 dark:text-neutral-400 hover:text-black dark:hover:text-white"]),title:"Settings"},[A(X(No),{class:"w-5 h-5 flex-shrink-0"})],2),k.value?(a(),o("div",Rl,[A(Qe,{"offset-x":6,"offset-y":6,intensity:.4},{default:be(()=>[e("div",Nl,[e("div",Fl,[H[4]||(H[4]=e("div",{class:"text-xs font-bold text-neutral-600 dark:text-neutral-400 pb-3"}," Appearance ",-1)),e("button",{onClick:H[1]||(H[1]=Ee(P=>te.$emit("toggle-theme"),["stop"])),class:"relative flex items-center h-7 rounded-full bg-neutral-200 dark:bg-neutral-800 hover:bg-neutral-300 dark:hover:bg-neutral-700 transition-colors",title:t.isDark?"Switch to light mode":"Switch to dark mode"},[e("span",{class:ae(["absolute top-0.5 h-6 w-8 rounded-full bg-white dark:bg-black shadow-sm transition-transform duration-200",t.isDark?"translate-x-[calc(100%-2px)]":"translate-x-0.5"])},null,2),e("span",ql,[A(X(Wo),{class:ae(["w-4 h-4",t.isDark?"text-neutral-500":"text-black"])},null,8,["class"])]),e("span",zl,[A(X(Go),{class:ae(["w-4 h-4",t.isDark?"text-white":"text-neutral-400"])},null,8,["class"])])],8,Bl)]),e("div",Hl,[H[5]||(H[5]=e("div",{class:"text-xs font-bold text-neutral-600 dark:text-neutral-400 pb-3"}," Accent Color ",-1)),e("div",Wl,[(a(!0),o(ve,null,ke(X(q),P=>(a(),o("button",{key:P,onClick:Ee(C=>X(B)(P),["stop"]),class:ae(["w-6 h-6 rounded-full transition-all flex items-center justify-center ring-1 ring-black/10 dark:ring-white/10",[F[P],X(D)===P?"ring-2 ring-black/50 dark:ring-white/50":"hover:scale-110"]]),title:P.charAt(0).toUpperCase()+P.slice(1)},[X(D)===P?(a(),o("span",Kl)):V("",!0)],10,Jl))),128))])]),e("button",{onClick:H[2]||(H[2]=P=>y("/settings/users")),class:ae(["flex items-center gap-3 px-4 py-2 text-sm transition-all w-full text-left",d.value==="users"?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10"])},[A(X(rl),{class:"w-4 h-4 flex-shrink-0"}),H[6]||(H[6]=e("span",{class:"whitespace-nowrap"},"Users",-1))],2),e("button",{onClick:H[3]||(H[3]=P=>y("/settings/api-keys")),class:ae(["flex items-center gap-3 px-4 py-2 text-sm transition-all w-full text-left",d.value==="api-keys"?"bg-black text-white dark:bg-white dark:text-black":"hover:bg-black/5 dark:hover:bg-white/10"])},[A(X(ul),{class:"w-4 h-4 flex-shrink-0"}),H[7]||(H[7]=e("span",{class:"whitespace-nowrap"},"API Keys",-1))],2)])]),_:1})])):V("",!0)]),e("button",{onClick:K,class:"group p-2 rounded hover:bg-red-500/10 transition-colors text-neutral-600 dark:text-neutral-400 hover:text-red-600 dark:hover:text-red-400 flex items-center",title:"Logout"},[A(X(ll),{class:"w-5 h-5 flex-shrink-0"}),t.isCollapsed?V("",!0):(a(),o("span",Gl,"Logout"))])],2)])])],2))}}),Yl={class:"warning-banner-container"},Ql={key:0,class:"warning-banner flex items-center justify-between gap-3 px-4 py-2 bg-amber-50 dark:bg-amber-900/30 border-b border-amber-200 dark:border-amber-800 text-amber-800 dark:text-amber-200 text-sm"},Zl={class:"flex items-center gap-2"},es=["onClick"],ts=me({__name:"WarningBanner",setup(t){const n=v([]),s=v(new Set),i=async()=>{if(localStorage.getItem("auth_token"))try{const f=await fetch(ue("/api/diagnostics"));if(f.ok){const g=await f.json();n.value=g.warnings||[]}}catch{}},l=c=>{const f=`${c.type}:${c.details?.name||c.message}`;s.value.add(f)},u=c=>{const f=`${c.type}:${c.details?.name||c.message}`;return!s.value.has(f)},r=c=>{if(c.type==="duplicate_tool_name"){const f=c.details?.sources?.join(" and ")||"multiple sources";return`Duplicate tool name "${c.details?.name}" (defined as both ${f}). This may cause unexpected behavior.`}return c.message};return Me(()=>{i()}),(c,f)=>(a(),o("div",Yl,[(a(!0),o(ve,null,ke(n.value,g=>(a(),o(ve,{key:`${g.type}:${g.details?.name}`},[u(g)?(a(),o("div",Ql,[e("div",Zl,[f[0]||(f[0]=e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4 flex-shrink-0",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z","clip-rule":"evenodd"})],-1)),e("span",null,S(r(g)),1)]),e("button",{onClick:d=>l(g),class:"text-amber-600 dark:text-amber-400 hover:text-amber-800 dark:hover:text-amber-200 p-1",title:"Dismiss"},[...f[1]||(f[1]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",class:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1)])],8,es)])):V("",!0)],64))),128))]))}}),as={key:2,class:"flex-1 overflow-auto my-3 mr-4 border border-neutral-300 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 flex flex-col"},os={class:"flex-1 overflow-auto"},ls=me({__name:"App",setup(t){fa();const n=Ye(),s=v(!1),i=v(!1),l=J(()=>n.name!=="login"),u=()=>{s.value=!s.value},r=()=>{i.value=!i.value,i.value?(document.documentElement.classList.add("dark"),localStorage.setItem("theme","dark")):(document.documentElement.classList.remove("dark"),localStorage.setItem("theme","light"))};return Me(()=>{const c=localStorage.getItem("theme");(c==="dark"||!c&&window.matchMedia("(prefers-color-scheme: dark)").matches)&&(i.value=!0,document.documentElement.classList.add("dark"))}),(c,f)=>(a(),o("div",{class:ae(["app-container relative flex h-screen font-sans bg-neutral-50/80 text-black dark:bg-black dark:text-white",{"is-dark":i.value}])},[l.value?(a(),ne(Xl,{key:0,"is-collapsed":s.value,"is-dark":i.value,onToggleSidebar:u,onToggleTheme:r},null,8,["is-collapsed","is-dark"])):V("",!0),l.value?(a(),o("main",as,[A(ts),e("div",os,[A(X(Lt))])])):(a(),ne(X(Lt),{key:1}))],2))}}),tt=(t,n)=>{const s=t.__vccOpts||t;for(const[i,l]of n)s[i]=l;return s},ss=tt(ls,[["__scopeId","data-v-2125e5d3"]]),ns={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function rs(t,n){return a(),o("svg",ns,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M10 11v6m4-6v6m5-11v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"},null,-1)])])}const is=De({name:"lucide-trash-2",render:rs}),ds={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function us(t,n){return a(),o("svg",ds,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e("path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z"})],-1)])])}const cs=De({name:"lucide-edit",render:us}),ps={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function ms(t,n){return a(),o("svg",ps,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("path",{d:"M2.062 12.348a1 1 0 0 1 0-.696a10.75 10.75 0 0 1 19.876 0a1 1 0 0 1 0 .696a10.75 10.75 0 0 1-19.876 0"}),e("circle",{cx:"12",cy:"12",r:"3"})],-1)])])}const $t=De({name:"lucide-eye",render:ms}),vs={class:"w-full"},fs={class:"border border-black dark:border-neutral-300 rounded overflow-hidden"},hs={class:"overflow-x-auto"},gs={class:"w-full"},bs={class:"border-b border-black dark:border-neutral-300"},xs={key:0,class:"px-4 py-3 text-right font-medium text-sm"},ys={key:0},ks=["colspan"],ws={key:1},_s=["colspan"],$s=["innerHTML"],Cs={key:0,class:"px-4 py-3 text-right"},Ts={class:"inline-flex gap-1"},Ss=["onClick","title"],Ge=me({__name:"DataTable",props:{columns:{},data:{},actions:{},emptyMessage:{default:"No data available"},loading:{type:Boolean,default:!1}},setup(t){const n=u=>{switch(u){case"edit":return cs;case"delete":return is;case"view":return $t;default:return null}},s=(u,r)=>{const c=u[r.key];return r.formatter?r.formatter(c):c??"-"},i=u=>{switch(u){case"center":return"text-center";case"right":return"text-right";default:return"text-left"}},l=(u,r)=>{if(u.confirm){const c=u.confirmMessage||`Are you sure you want to ${u.label.toLowerCase()}?`;confirm(c)&&u.handler(r)}else u.handler(r)};return(u,r)=>(a(),o("div",vs,[e("div",fs,[e("div",hs,[e("table",gs,[e("thead",bs,[e("tr",null,[(a(!0),o(ve,null,ke(t.columns,c=>(a(),o("th",{key:c.key,class:ae(["px-4 py-3 font-medium text-sm",i(c.align),c.width||""])},S(c.label),3))),128)),t.actions&&t.actions.length>0?(a(),o("th",xs," Actions ")):V("",!0)])]),e("tbody",null,[t.loading?(a(),o("tr",ys,[e("td",{colspan:t.columns.length+(t.actions?1:0),class:"px-4 py-8 text-center text-neutral-500"},[...r[0]||(r[0]=[e("div",{class:"inline-flex items-center gap-2"},[e("svg",{class:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),Ce(" Loading... ")],-1)])],8,ks)])):t.data.length===0?(a(),o("tr",ws,[e("td",{colspan:t.columns.length+(t.actions?1:0),class:"px-4 py-8 text-center text-neutral-500"},S(t.emptyMessage),9,_s)])):(a(!0),o(ve,{key:2},ke(t.data,(c,f)=>(a(),o("tr",{key:f,class:"border-t border-neutral-200 dark:border-neutral-800 hover:bg-black/5 dark:hover:bg-white/5 transition-colors"},[(a(!0),o(ve,null,ke(t.columns,g=>(a(),o("td",{key:g.key,class:ae(["px-4 py-3 text-sm",i(g.align)])},[et(u.$slots,`cell-${g.key}`,{value:c[g.key],row:c,column:g},()=>[g.html?(a(),o("span",{key:0,innerHTML:s(c,g)},null,8,$s)):(a(),o(ve,{key:1},[Ce(S(s(c,g)),1)],64))])],2))),128)),t.actions&&t.actions.length>0?(a(),o("td",Cs,[e("div",Ts,[(a(!0),o(ve,null,ke(t.actions,(g,d)=>(a(),o("button",{key:d,onClick:p=>l(g,c),class:"p-1.5 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",title:g.label},[(a(),ne(Ze(n(g.icon)),{class:"w-4 h-4"}))],8,Ss))),128))])])):V("",!0)]))),128))])])])])]))}}),Vs=me({__name:"AgentsDataTable",emits:["add","edit","delete"],setup(t,{expose:n,emit:s}){const i=s,l=v([]),u=v(!1),r=[{key:"title",label:"Title",width:"w-1/5"},{key:"type",label:"Type",width:"w-1/12",formatter:d=>d==="dual_ai"?"Dual AI":"AI+Human"},{key:"side_a_agent_prompt_name",label:"Side A",width:"w-1/5",formatter:d=>d||"-"},{key:"side_b_agent_prompt_name",label:"Side B",width:"w-1/5",formatter:d=>d||"Human"},{key:"created_at",label:"Created",width:"w-1/6",formatter:d=>d?new Date(d*1e3).toLocaleDateString():"-"}],c=[{icon:"edit",label:"Edit",handler:d=>i("edit",d)},{icon:"delete",label:"Delete",handler:async d=>{await g(d)},confirm:!0,confirmMessage:"Are you sure you want to delete this agent?"}],f=async()=>{u.value=!0;try{const d=await fetch(ue("/api/agents"));if(d.ok){const p=await d.json();l.value=p.agents||[]}}catch(d){console.error("Error fetching agents:",d)}finally{u.value=!1}},g=async d=>{try{const p=await fetch(ue(`/api/agents/${d.id}`),{method:"DELETE"});if(p.ok)await f();else{const h=await p.json();alert(h.error||"Failed to delete agent")}}catch(p){console.error("Error deleting agent:",p),alert("Failed to delete agent")}};return Me(()=>{f()}),n({refresh:f}),(d,p)=>(a(),o("div",null,[A(Ge,{columns:r,data:l.value,actions:c,loading:u.value,"empty-message":"No agents available. Create your first agent to get started."},null,8,["data","loading"])]))}}),Ms={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Is(t,n){return a(),o("svg",Ms,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M18 6L6 18M6 6l12 12"},null,-1)])])}const ba=De({name:"lucide-x",render:Is}),Es={key:0,class:"w-full max-w-md"},Ls={class:"flex items-center justify-between p-4 border-b-2 border-red-600 flex-shrink-0"},As={class:"text-xl font-bold text-red-600"},Ps={class:"p-6"},Ds={class:"text-neutral-700 dark:text-neutral-300 mb-6"},js={class:"flex justify-end gap-3"},xa=me({__name:"ConfirmDialog",props:{modelValue:{type:Boolean},title:{default:"Confirm Action"},message:{default:"Are you sure you want to continue? You will lose any unsaved changes."},confirmText:{default:"Continue"},cancelText:{default:"Cancel"}},emits:["update:modelValue","confirm","cancel"],setup(t,{emit:n}){const s=t,i=n,l=()=>{i("update:modelValue",!1)},u=()=>{i("confirm"),l()},r=()=>{i("cancel"),l()},c=f=>{f.key==="Escape"&&s.modelValue&&r()};return fe(()=>s.modelValue,f=>{f?(document.addEventListener("keydown",c),document.body.style.overflow="hidden"):(document.removeEventListener("keydown",c),document.body.style.overflow="")}),(f,g)=>(a(),ne(it,{to:"body"},[A(Xe,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-200","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:be(()=>[t.modelValue?(a(),o("div",{key:0,class:"fixed inset-0 z-[60] flex items-center justify-center p-4 bg-white/80 dark:bg-black/80 backdrop-blur-sm dark:text-white",onClick:r},[A(Xe,{"enter-active-class":"transition-all duration-200","enter-from-class":"opacity-0 scale-95","enter-to-class":"opacity-100 scale-100","leave-active-class":"transition-all duration-200","leave-from-class":"opacity-100 scale-100","leave-to-class":"opacity-0 scale-95"},{default:be(()=>[t.modelValue?(a(),o("div",Es,[A(Qe,{"offset-x":12,"offset-y":12,intensity:.4},{default:be(()=>[e("div",{class:"bg-white dark:bg-black border-2 border-red-600 flex flex-col",onClick:g[0]||(g[0]=Ee(()=>{},["stop"]))},[e("div",Ls,[e("h2",As,S(t.title),1),e("button",{onClick:r,class:"p-1 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors","aria-label":"Close dialog"},[A(X(ba),{class:"w-5 h-5 text-red-600"})])]),e("div",Ps,[e("p",Ds,S(t.message),1),e("div",js,[e("button",{onClick:r,class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors"},S(t.cancelText),1),e("button",{onClick:u,class:"px-4 py-2 border-2 border-red-600 bg-red-600 text-white hover:bg-red-700 hover:border-red-700 transition-colors"},S(t.confirmText),1)])])])]),_:1})])):V("",!0)]),_:1})])):V("",!0)]),_:1})]))}}),Os={class:"flex items-center justify-between p-4 border-b-2 border-black dark:border-neutral-300 flex-shrink-0"},Us={class:"text-xl font-bold"},Rs={class:"overflow-y-auto flex-1"},Ns={class:"p-6"},Fs={key:0,class:"p-6 border-t-2 border-black dark:border-neutral-300 flex-shrink-0"},He=me({__name:"Modal",props:{modelValue:{type:Boolean},title:{},width:{default:"max-w-lg"},minHeight:{default:"min-h-[24rem]"},hasChanges:{type:Boolean,default:void 0}},emits:["update:modelValue","close"],setup(t,{emit:n}){const s=t,i=n,l=v(),u=v(!1),r=v(new Map),c=()=>l.value&&(l.value.querySelector("input")||l.value.querySelector("textarea")||l.value.querySelector("select")||l.value.querySelector("[contenteditable]")||l.value.querySelector(".monaco-editor")),f=()=>{if(!l.value)return;l.value.querySelectorAll(".monaco-editor-container").forEach(q=>{const B=q.__monacoEditor;if(B&&typeof B.getValue=="function"){const F=B.getValue();r.value.set(q,F)}})},g=()=>{if(!l.value)return!1;const D=l.value.querySelectorAll(".monaco-editor-container");for(const q of D){const B=q.__monacoEditor;if(B&&typeof B.getValue=="function"){const F=B.getValue(),T=r.value.get(q);if(T===void 0||(B.getRawOptions?.()||{}).readOnly===!0)continue;if(F!==T)return!0}}return!1},d=()=>{if(s.hasChanges!==void 0)return s.hasChanges;if(!l.value)return!1;if(g())return!0;const D=l.value.querySelectorAll("form");for(const B of D){const T=B.querySelectorAll("input, textarea, select");for(const $ of T){const K=$;if(K.type==="checkbox"||K.type==="radio"){const oe=K;if(oe.checked!==oe.defaultChecked)return!0}else if(K.tagName==="SELECT"){const oe=K;if(oe.value!==oe.defaultValue)return!0}else if(K.value!==K.defaultValue)return!0}}const q=l.value.querySelectorAll("input:not(form input), textarea:not(form textarea), select:not(form select)");for(const B of q){const F=B;if(F.type==="checkbox"||F.type==="radio"){const T=F;if(T.checked!==T.defaultChecked)return!0}else if(F.tagName==="SELECT"){const T=F;if(T.value!==T.defaultValue)return!0}else if(F.value!==F.defaultValue)return!0}return!1},p=()=>{c()&&d()?u.value=!0:h()},h=()=>{i("update:modelValue",!1),i("close")},_=()=>{u.value=!1,h()},b=()=>{u.value=!1},m=D=>{D.key==="Escape"&&s.modelValue&&(c()||h())};fe(()=>s.modelValue,async D=>{D?(document.addEventListener("keydown",m),document.body.style.overflow="hidden",await Te(),setTimeout(()=>{f()},100)):(document.removeEventListener("keydown",m),document.body.style.overflow="",r.value.clear())});const y=v(!1),x=D=>{y.value=D.target===D.currentTarget},k=D=>{D.target===D.currentTarget&&y.value&&(c()||h()),y.value=!1};return(D,q)=>(a(),ne(it,{to:"body"},[A(Xe,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-200","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:be(()=>[t.modelValue?(a(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-white/80 dark:bg-black/80 backdrop-blur-sm dark:text-white",onMousedown:x,onClick:k},[A(Xe,{"enter-active-class":"transition-all duration-200","enter-from-class":"opacity-0 scale-95","enter-to-class":"opacity-100 scale-100","leave-active-class":"transition-all duration-200","leave-from-class":"opacity-100 scale-100","leave-to-class":"opacity-0 scale-95"},{default:be(()=>[t.modelValue?(a(),o("div",{key:0,class:ae(["w-full",t.width,"max-h-[85vh] flex flex-col"])},[A(Qe,{"offset-x":12,"offset-y":12,intensity:.4},{default:be(()=>[e("div",{ref_key:"modalRef",ref:l,class:ae(["bg-white dark:bg-black border-2 border-black dark:border-neutral-300 flex flex-col max-h-[85vh]",t.minHeight])},[e("div",Os,[e("h2",Us,S(t.title),1),e("button",{onClick:p,class:"p-1 hover:bg-black/5 dark:hover:bg-white/10 rounded transition-colors","aria-label":"Close modal"},[A(X(ba),{class:"w-5 h-5"})])]),e("div",Rs,[e("div",Ns,[et(D.$slots,"default")])]),D.$slots.footer?(a(),o("div",Fs,[et(D.$slots,"footer")])):V("",!0)],2)]),_:3})],2)):V("",!0)]),_:3})],32)):V("",!0)]),_:3}),A(xa,{modelValue:u.value,"onUpdate:modelValue":q[0]||(q[0]=B=>u.value=B),title:"Unsaved Changes",message:"You have unsaved changes that will be lost. Are you sure you want to close?","confirm-text":"Close Anyway","cancel-text":"Keep Editing",onConfirm:_,onCancel:b},null,8,["modelValue"])]))}}),Bs={class:"space-y-1.5"},qs={key:0,class:"block text-sm font-medium text-neutral-700 dark:text-neutral-300"},zs={key:0,class:"text-red-500"},Hs=["type","value","placeholder","disabled"],Ws={key:1,class:"text-xs text-red-500 dark:text-red-400"},Le=me({__name:"TextInput",props:{modelValue:{},label:{},placeholder:{},type:{default:"text"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","focus","click"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(null),r=J(()=>["w-full px-3 py-2.5 bg-neutral-50 dark:bg-neutral-950 border rounded-md text-sm","focus:outline-none focus:ring-2 focus:ring-neutral-400 dark:focus:ring-neutral-500 focus:border-transparent","transition-colors placeholder:text-neutral-400 dark:placeholder:text-neutral-500",i.error?"border-red-500 dark:border-red-400":"border-neutral-300 dark:border-neutral-800",i.disabled?"opacity-50 cursor-not-allowed":""]),c=d=>{const p=d.target;l("update:modelValue",p.value)},f=d=>{l("focus",d)},g=d=>{l("click",d)};return n({inputRef:u}),(d,p)=>(a(),o("div",Bs,[t.label?(a(),o("label",qs,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",zs,"*")):V("",!0)])):V("",!0),e("input",{ref_key:"inputRef",ref:u,type:t.type,value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,class:ae(r.value),onInput:c,onFocus:f,onClick:g},null,42,Hs),t.error?(a(),o("p",Ws,S(t.error),1)):V("",!0)]))}}),Js={class:"space-y-1"},Ks={key:0,class:"block text-sm font-medium"},Gs={key:0,class:"text-red-500"},Xs=["value","placeholder","disabled","rows"],Ys={key:1,class:"text-xs text-red-500 dark:text-red-400"},ya=me({__name:"TextareaInput",props:{modelValue:{},label:{},placeholder:{},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},rows:{default:4}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=J(()=>["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white","transition-colors resize-y",s.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",s.disabled?"opacity-50 cursor-not-allowed":""]),u=r=>{const c=r.target;i("update:modelValue",c.value)};return(r,c)=>(a(),o("div",Js,[t.label?(a(),o("label",Ks,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",Gs,"*")):V("",!0)])):V("",!0),e("textarea",{value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,rows:t.rows,class:ae(l.value),onInput:u},null,42,Xs),t.error?(a(),o("p",Ys,S(t.error),1)):V("",!0)]))}}),Qs={key:0,class:"block text-sm font-medium mb-2"},Zs={key:0,class:"text-red-500"},en=["disabled","aria-expanded"],tn={class:"flex items-center justify-between gap-1"},an={key:0,class:"flex items-center gap-2 text-neutral-400 flex-1 min-w-0"},on={key:1,class:"flex items-center gap-2 flex-1 min-w-0"},ln=["src","alt"],sn={class:"block truncate"},nn={key:2,class:"block truncate text-neutral-400 flex-1 min-w-0"},rn={class:"bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},dn={class:"p-2 border-b border-neutral-200 dark:border-neutral-700"},un=["placeholder"],cn={class:"max-h-60 overflow-y-auto"},pn={key:0,class:"px-4 py-3 text-sm text-neutral-500 dark:text-neutral-400"},mn=["onClick","onMouseenter"],vn={class:"flex-shrink-0 w-5 h-5 mt-0.5"},fn=["src","alt"],hn={key:1,class:"w-full h-full bg-neutral-200 dark:bg-neutral-700 rounded"},gn={class:"flex-1 min-w-0"},bn={class:"text-sm font-medium text-black dark:text-white"},xn={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},yn={key:2,class:"mt-1 text-xs text-red-500 dark:text-red-400"},Ve=me({__name:"SelectInput",props:{modelValue:{},options:{},placeholder:{default:"Select an option"},searchPlaceholder:{default:"Search..."},label:{},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},error:{},required:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=v(!1),u=v(""),r=v(),c=v(),f=v(),g=v(),d=v(-1),p=J(()=>s.options.find($=>$.value===s.modelValue)),h=J(()=>["w-full px-3 py-2 text-left rounded focus:outline-none focus:ring-2 bg-white dark:bg-black disabled:opacity-50 disabled:cursor-not-allowed font-mono text-sm overflow-hidden",s.error?"border border-red-500 dark:border-red-400 focus:ring-red-500 dark:focus:ring-red-400":"border border-black dark:border-neutral-300 focus:ring-black dark:focus:ring-white"]),_=J(()=>{if(!u.value)return s.options;const $=u.value.toLowerCase();return s.options.filter(K=>K.label.toLowerCase().includes($)||K.value.toLowerCase().includes($)||K.description&&K.description.toLowerCase().includes($))});fe(_,()=>{d.value=-1});const b=()=>{s.disabled||(l.value?x():(l.value=!0,u.value="",d.value=-1,Te(()=>{if(g.value&&(g.value.setAttribute("popover","auto"),g.value.addEventListener("toggle",T),"showPopover"in g.value))try{g.value.showPopover()}catch{}k(),setTimeout(()=>r.value?.focus(),0)})))},m=$=>{i("update:modelValue",$.value),x(),u.value="",d.value=-1},y=$=>{$.stopPropagation(),i("update:modelValue","")},x=()=>{if(g.value){if("hidePopover"in g.value)try{g.value.hidePopover()}catch{}g.value.removeEventListener("toggle",T)}l.value=!1,d.value=-1},k=()=>{if(!f.value||!g.value)return;const $=f.value.getBoundingClientRect();g.value.offsetWidth||$.width,g.value.style.position="fixed",g.value.style.top=`${$.bottom+8}px`,g.value.style.left=`${$.left}px`,g.value.style.width=`${$.width}px`,g.value.style.margin="0"},D=$=>{c.value&&!c.value.contains($.target)&&g.value&&!g.value.contains($.target)&&x()},q=$=>{$.key==="Escape"&&l.value&&(x(),f.value?.focus())},B=$=>{if(!l.value)return;const K=_.value;if(K.length!==0)switch($.key){case"ArrowDown":$.preventDefault(),d.value=d.value<K.length-1?d.value+1:0,F();break;case"ArrowUp":$.preventDefault(),d.value=d.value>0?d.value-1:K.length-1,F();break;case"Enter":$.preventDefault(),d.value>=0&&d.value<K.length&&m(K[d.value]);break}},F=()=>{Te(()=>{const $=g.value?.querySelector(".highlighted-option");$&&$.scrollIntoView({block:"nearest",behavior:"smooth"})})},T=$=>{$.target===g.value&&(l.value=$.newState==="open",l.value&&k())};return Me(()=>{document.addEventListener("click",D),document.addEventListener("keydown",q);const $=()=>{l.value&&k()};window.addEventListener("resize",$),window.addEventListener("scroll",$,!0)}),Be(()=>{document.removeEventListener("click",D),document.removeEventListener("keydown",q),window.removeEventListener("resize",k),window.removeEventListener("scroll",k,!0)}),($,K)=>(a(),o("div",{ref_key:"dropdownRef",ref:c,class:"relative"},[t.label?(a(),o("label",Qs,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",Zs,"*")):V("",!0)])):V("",!0),e("button",{ref_key:"buttonRef",ref:f,type:"button",onClick:b,disabled:t.disabled,"aria-expanded":l.value,"aria-haspopup":!0,class:ae(h.value)},[e("div",tn,[t.loading?(a(),o("span",an,[...K[1]||(K[1]=[e("svg",{class:"animate-spin h-4 w-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})],-1),Ce(" Loading... ",-1)])])):p.value?(a(),o("span",on,[p.value.icon?(a(),o("img",{key:0,src:p.value.icon,alt:p.value.label,class:"w-5 h-5 flex-shrink-0"},null,8,ln)):V("",!0),e("span",sn,S(p.value.label),1)])):(a(),o("span",nn,S(t.placeholder),1)),p.value&&!t.disabled?(a(),o("button",{key:3,type:"button",onClick:y,class:"flex-shrink-0 p-0.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors","aria-label":"Clear selection"},[...K[2]||(K[2]=[e("svg",{class:"h-4 w-4 text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1)])])):V("",!0),K[3]||(K[3]=e("svg",{class:"h-5 w-5 text-neutral-400 flex-shrink-0",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor"},[e("path",{"fill-rule":"evenodd",d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z","clip-rule":"evenodd"})],-1))])],10,en),l.value?(a(),o("div",{key:1,ref_key:"popoverRef",ref:g,class:"dropdown-popover"},[A(Qe,{"offset-x":4,"offset-y":4,intensity:.3},{default:be(()=>[e("div",rn,[e("div",dn,[Ie(e("input",{ref_key:"searchInput",ref:r,"onUpdate:modelValue":K[0]||(K[0]=oe=>u.value=oe),type:"text",placeholder:t.searchPlaceholder,onKeydown:B,class:"w-full px-3 py-1.5 text-sm border border-neutral-300 dark:border-neutral-600 rounded focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white bg-white dark:bg-black text-black dark:text-white placeholder:text-neutral-400 dark:placeholder:text-neutral-500"},null,40,un),[[Oe,u.value]])]),e("div",cn,[_.value.length===0?(a(),o("div",pn," No options found ")):V("",!0),(a(!0),o(ve,null,ke(_.value,(oe,te)=>(a(),o("button",{key:oe.value,type:"button",onClick:H=>m(oe),onMouseenter:H=>d.value=te,class:ae(["w-full px-4 py-2 text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 focus:bg-neutral-100 dark:focus:bg-neutral-900 focus:outline-none flex items-start gap-3",{"bg-neutral-50 dark:bg-neutral-900":oe.value===t.modelValue,"bg-neutral-100 dark:bg-neutral-800 highlighted-option":te===d.value}])},[e("div",vn,[oe.icon?(a(),o("img",{key:0,src:oe.icon,alt:oe.label,class:"w-full h-full"},null,8,fn)):(a(),o("div",hn))]),e("div",gn,[e("div",bn,S(oe.label),1),oe.description?(a(),o("div",xn,S(oe.description),1)):V("",!0)])],42,mn))),128))])])]),_:1})],512)):V("",!0),t.error?(a(),o("p",yn,S(t.error),1)):V("",!0)],512))}}),kn={class:"flex items-start"},wn=["for"],_n=["id","checked","disabled"],$n={class:"flex items-center h-5"},Cn={class:"flex-1"},Tn={key:0,class:"text-red-500"},Sn={key:1,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-1"},Vn={key:2,class:"text-xs text-red-500 dark:text-red-400 mt-1"},Pe=me({__name:"CheckboxInput",props:{modelValue:{type:Boolean,default:!1},label:{},helpText:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},error:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=Da(),u=J(()=>["w-5 h-5 border-2 rounded relative flex-shrink-0","transition-all duration-150",s.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",s.disabled?"opacity-50":"hover:scale-110",s.modelValue?"bg-black dark:bg-white":"bg-white dark:bg-black","before:content-[''] before:absolute before:inset-0 before:m-auto before:w-2.5 before:h-1.5 before:border-white dark:before:border-black before:border-b-2 before:border-l-2 before:rotate-[-45deg]",s.modelValue?"before:block":"before:hidden"]),r=c=>{if(!s.disabled){const f=c.target;i("update:modelValue",f.checked)}};return(c,f)=>(a(),o("div",kn,[e("label",{for:X(l),class:ae(["flex items-start space-x-3 cursor-pointer select-none",{"cursor-not-allowed":t.disabled}])},[e("input",{id:X(l),type:"checkbox",checked:t.modelValue,disabled:t.disabled,onChange:r,class:"absolute left-[-9999px]"},null,40,_n),e("div",$n,[e("span",{class:ae(u.value)},null,2)]),e("div",Cn,[t.label?(a(),o("span",{key:0,class:ae(["block text-sm font-medium",{"opacity-50":t.disabled}])},[Ce(S(t.label)+" ",1),t.required?(a(),o("span",Tn,"*")):V("",!0)],2)):V("",!0),t.helpText?(a(),o("p",Sn,S(t.helpText),1)):V("",!0),t.error?(a(),o("p",Vn,S(t.error),1)):V("",!0)])],10,wn)]))}}),Mn={class:"space-y-4"},In={class:"flex items-start gap-2"},En={class:"flex-1"},Ln=["onClick","disabled","title"],An={key:0,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Pn={key:1,class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Dn={key:0,class:"text-xs text-neutral-400 dark:text-neutral-500 mt-1"},jn={key:0,class:"text-amber-500 dark:text-amber-400 ml-1"},On={class:"flex-1"},Un={class:"flex-1"},Rn=["onClick","disabled"],Nn=["disabled"],ka=me({__name:"TenvPropertyList",props:{modelValue:{},inherited:{default:()=>[]},allowCustom:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=v(new Set),u=v([]),r=J(()=>new Set(s.inherited.map(m=>m.name)));fe(()=>s.modelValue,m=>{const y=Object.keys(m).filter(k=>!r.value.has(k)),x=new Set(u.value.map(k=>k.name));for(const k of y)x.has(k)||u.value.push({id:crypto.randomUUID(),name:k,value:String(m[k]??"")})},{immediate:!0,deep:!0});const c=m=>{if(l.value.has(m)){l.value.delete(m);const y=s.inherited.find(x=>x.name===m);y&&f(m,y.value)}else l.value.add(m)},f=(m,y)=>{const x={...s.modelValue};y===void 0||y===""?delete x[m]:x[m]=y,i("update:modelValue",x)},g=m=>s.modelValue[m.name]!==void 0?String(s.modelValue[m.name]):m.value!==void 0?String(m.value):"",d=(m,y)=>{f(m.name,y||void 0)},p=()=>{u.value.push({id:crypto.randomUUID(),name:"",value:""})},h=m=>{const y=u.value.find(x=>x.id===m);if(y&&y.name){const x={...s.modelValue};delete x[y.name],i("update:modelValue",x)}u.value=u.value.filter(x=>x.id!==m)},_=(m,y,x)=>{const k=u.value.find(q=>q.id===m);if(!k)return;k.name=x;const D={...s.modelValue};y&&delete D[y],x&&k.value&&(D[x]=k.value),i("update:modelValue",D)},b=(m,y)=>{const x=u.value.find(k=>k.id===m);x&&(x.value=y,x.name&&f(x.name,y||void 0))};return(m,y)=>(a(),o("div",Mn,[(a(!0),o(ve,null,ke(t.inherited,x=>(a(),o("div",{key:x.name,class:"relative"},[e("div",In,[e("div",En,[A(Le,{"model-value":g(x),label:x.name,placeholder:x.description||"Enter value...",disabled:t.disabled||!l.value.has(x.name),required:x.required,"onUpdate:modelValue":k=>d(x,k)},null,8,["model-value","label","placeholder","disabled","required","onUpdate:modelValue"])]),e("button",{type:"button",onClick:k=>c(x.name),disabled:t.disabled,class:"mt-7 p-2 text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-300 transition-colors disabled:opacity-50",title:l.value.has(x.name)?"Lock (use inherited value)":"Unlock to override"},[l.value.has(x.name)?(a(),o("svg",Pn,[...y[1]||(y[1]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"},null,-1)])])):(a(),o("svg",An,[...y[0]||(y[0]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"},null,-1)])]))],8,Ln)]),x.source?(a(),o("p",Dn,[Ce(" From: "+S(x.source)+" ",1),x.required?(a(),o("span",jn,"(required)")):V("",!0)])):V("",!0)]))),128)),(a(!0),o(ve,null,ke(u.value,x=>(a(),o("div",{key:x.id,class:"flex items-start gap-2"},[e("div",On,[A(Le,{"model-value":x.name,label:"Name",placeholder:"Variable name",disabled:t.disabled,"onUpdate:modelValue":k=>_(x.id,x.name,k)},null,8,["model-value","disabled","onUpdate:modelValue"])]),e("div",Un,[A(Le,{"model-value":x.value,label:"Value",placeholder:"Variable value",disabled:t.disabled,"onUpdate:modelValue":k=>b(x.id,k)},null,8,["model-value","disabled","onUpdate:modelValue"])]),e("button",{type:"button",onClick:k=>h(x.id),disabled:t.disabled,class:"mt-7 p-2 text-red-400 hover:text-red-600 dark:hover:text-red-300 transition-colors disabled:opacity-50",title:"Remove"},[...y[2]||(y[2]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,Rn)]))),128)),t.allowCustom?(a(),o("button",{key:0,type:"button",onClick:p,disabled:t.disabled,class:"w-full px-3 py-2 text-sm bg-neutral-50 dark:bg-neutral-900 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded transition-colors disabled:opacity-50 border border-dashed border-neutral-300 dark:border-neutral-700"},[...y[3]||(y[3]=[e("span",{class:"flex items-center justify-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),Ce(" Add custom variable ")],-1)])],8,Nn)):V("",!0)]))}});async function ze(t,n={}){const s=localStorage.getItem("auth_token"),i={"Content-Type":"application/json",...n.headers};s&&(i.Authorization=`Bearer ${s}`);const l=t.startsWith("/")?t:`/${t}`,u=await fetch(ue(`/api${l}`),{...n,headers:i});if(u.status===401)throw localStorage.removeItem("auth_token"),window.location.href=ue("/login"),new Error("Unauthorized");return u}const Fn={key:0,class:"min-h-[400px] flex items-center justify-center"},Bn={key:1,class:"space-y-6 pr-2 pb-4"},qn={key:0,class:"p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg"},zn={class:"text-sm text-red-800 dark:text-red-200"},Hn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Wn={key:1,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Jn={key:1},Kn={key:2},Gn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Xn={key:3},Yn={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Qn={class:"grid grid-cols-2 gap-6"},Zn={class:"space-y-4 p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},er={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},tr={class:"space-y-3"},ar={class:"flex items-start"},or={key:0,class:"ml-8 mt-2 space-y-2"},lr={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-1"},sr={key:1},nr={key:0,class:"mt-3 p-3 bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded"},rr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},ir={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},dr={class:"space-y-4 p-4 bg-neutral-100 dark:bg-neutral-800 rounded-lg"},ur={class:"font-semibold text-base mb-4 text-neutral-800 dark:text-neutral-200"},cr={key:0,class:"flex flex-col items-center justify-center py-8"},pr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},mr={class:"space-y-3"},vr={class:"flex items-start"},fr={key:0,class:"ml-8 mt-2 space-y-2"},hr={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-1"},gr={key:1},br={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},xr={key:0,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},yr={key:4,class:"space-y-3"},kr={class:"flex items-center justify-between"},wr={key:0,class:"text-xs text-neutral-500"},_r={class:"flex justify-between"},$r=["disabled"],Cr=me({__name:"AgentModal",props:{modelValue:{type:Boolean},editAgent:{},mode:{},apiError:{}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=J(()=>s.mode==="edit"),u=v(!1),r=v(""),c=v(""),f=v(""),g=v(null),d=v(""),p=v("dual_ai"),h=v(!1),_=v(""),b=v(""),m=v(null),y=v(""),x=v(""),k=v(""),D=v(""),q=v(!0),B=v(!1),F=v(""),T=v(""),$=v(""),K=v(""),oe=v(!1),te=v(null),H=v(""),P=v(""),C=v(""),L=v(""),G=v(""),ee=v(""),E=v(!0),U=v(!1),Z=v(""),se=v(""),j=v(""),M=v(""),w=v(null),R=v(""),I=v(""),le=v(""),O=v([]),W=v({}),ce=v(!1),{data:z,execute:N}=Ue(ue("/api/prompts"),{immediate:!1}).json(),{data:Q,execute:we}=Ue(ue("/api/tools?schema=true"),{immediate:!1}).json(),de=v(null),pe=v(!1),ie=v(null),ye=v(!1),_e=v(!1),Ae=J(()=>{if(!z.value)return[{value:"",label:"Select a prompt..."}];const ge=z.value?.prompts||[];return[{value:"",label:"None"},...ge.map(Y=>({value:Y.id,label:Y.name}))]}),Fe=ge=>Q.value?Q.value[ge]:null,Re=J(()=>!de.value||!de.value.tools?[{value:"",label:"None"}]:[{value:"",label:"None"},...de.value.tools.map(ge=>{const Y=typeof ge=="string"?ge:ge.name;return{value:Y,label:Y}})]),xe=J(()=>!ie.value||!ie.value.tools?[{value:"",label:"None"}]:[{value:"",label:"None"},...ie.value.tools.map(ge=>{const Y=typeof ge=="string"?ge:ge.name;return{value:Y,label:Y}})]),he=J(()=>{if(!F.value)return[];const ge=Fe(F.value);return!ge||!ge.schema||!ge.schema.properties?[]:Object.keys(ge.schema.properties).map(Y=>({value:Y,label:Y}))}),$e=J(()=>{if(!Z.value)return[];const ge=Fe(Z.value);return!ge||!ge.schema||!ge.schema.properties?[]:Object.keys(ge.schema.properties).map(Y=>({value:Y,label:Y}))}),Ne=async()=>{const ge=[k.value,G.value].filter(Boolean);if(ge.length===0){O.value=[];return}ce.value=!0;try{const Y=[],re=new Set;for(const qe of ge){const je=await ze(`/prompts/${qe}/tenvs`);if(je.ok){const gt=await je.json();for(const Je of gt.tenvs||[])re.has(Je.name)||(re.add(Je.name),Y.push({name:Je.name,value:Je.value,required:Je.required,description:Je.description,source:Je.source}))}}O.value=Y}catch(Y){console.error("Error fetching tenvs from prompts:",Y),O.value=[]}finally{ce.value=!1}},ht=[{value:"dual_ai",label:"AI + AI (Subagent)"},{value:"ai_human",label:"AI + Human"}],It=J({get(){return c.value},set(ge){const Y=g.value?.inputRef,re=Y?.selectionStart??ge.length;let qe=ge.toLowerCase().replace(/\s+/g,"_").replace(/[^a-z0-9_]/g,"");if(qe.endsWith("_agent")||(qe=qe+"_agent"),c.value=qe,Y){Y.value=qe;const je=Math.min(re,qe.length-6);Y.setSelectionRange(je,je)}}}),Et=async()=>{await Te();const ge=g.value?.inputRef;if(ge&&c.value.endsWith("_agent")){const Y=c.value.length-6;ge.setSelectionRange(Y,Y)}},Sa=ge=>!ge||ge==="_agent"?(f.value="Name is required",!1):/^[a-z][a-z0-9_]*_agent$/.test(ge)?(f.value="",!0):(f.value="Name must start with a letter",!1),ut=()=>{c.value="",r.value="",f.value="",d.value="",p.value="dual_ai",h.value=!1,_.value="",b.value="",m.value=null,y.value="",k.value="",D.value="",q.value=!0,B.value=!1,F.value="",T.value="",$.value="",K.value="",oe.value=!1,te.value=null,H.value="",P.value="",C.value="",de.value=null,G.value="",ee.value="",E.value=!0,U.value=!1,Z.value="",se.value="",j.value="",M.value="",w.value=null,R.value="",I.value="",le.value="",ie.value=null,O.value=[],W.value={}},Va=async()=>{if(s.editAgent?.id){u.value=!0,_e.value=!0;try{const ge=await fetch(ue(`/api/agents/${s.editAgent.id}`));if(ge.ok){const Y=await ge.json(),re=Y.agent||Y;c.value=re.name||"",r.value=re.name||"",d.value=re.title||"",p.value=re.type||"dual_ai",h.value=re.expose_as_tool||!1,_.value=re.tool_description||"",m.value=re.max_session_turns;const qe=re.side_a_stop_tool||"",je=re.side_a_stop_tool_response_property||"",gt=re.side_b_stop_tool||"",Je=re.side_b_stop_tool_response_property||"",Ea=re.side_a_end_conversation_tool||"",La=re.side_b_end_conversation_tool||"";x.value=re.side_a_label||"",L.value=re.side_b_label||"",k.value=re.side_a_agent_prompt||"",G.value=re.side_b_agent_prompt||"",q.value=!!re.side_a_stop_on_response,B.value=!!re.side_a_stop_tool,oe.value=!!re.side_a_manual_stop_condition,te.value=re.side_a_max_steps,E.value=!!re.side_b_stop_on_response,U.value=!!re.side_b_stop_tool,w.value=re.side_b_max_steps,await Te(),F.value=qe,$.value=je,Z.value=gt,j.value=Je,P.value=Ea,I.value=La,re.tenvs&&typeof re.tenvs=="object"&&(W.value=re.tenvs),await Ne()}}catch(ge){console.error("Error loading agent data:",ge)}finally{u.value=!1,_e.value=!1}}},Ma=async()=>{f.value="",y.value="",D.value="",T.value="",K.value="",H.value="",C.value="",ee.value="",se.value="",M.value="",R.value="",le.value="";let ge=!1;Sa(c.value)||(ge=!0);const Y=c.value;p.value==="dual_ai"&&m.value!==null&&m.value!==void 0&&m.value<=0&&(y.value="Max session turns must be a positive number",ge=!0),k.value||(D.value="Please select an agent prompt",ge=!0);const re=q.value||F.value,qe=p.value==="ai_human"&&oe.value;if(!re&&!qe&&(D.value="At least one stop condition is required (or check manual stop condition for ai_human agents)",ge=!0),F.value&&!$.value&&(K.value="Response property required when using stop tool",ge=!0),te.value!==null&&te.value<=0&&(H.value="Max steps must be a positive number",ge=!0),p.value==="dual_ai"&&!P.value&&!I.value&&(C.value="At least one side must have an end conversation tool",le.value="At least one side must have an end conversation tool",ge=!0),p.value==="dual_ai"&&(G.value||(ee.value="Please select an agent prompt",ge=!0),Z.value&&!j.value&&(M.value="Response property required when using stop tool",ge=!0),w.value!==null&&w.value<=0&&(R.value="Max steps must be a positive number",ge=!0)),ge)return;const je={name:Y,title:d.value||null,type:p.value,expose_as_tool:h.value,tool_description:h.value?_.value:null,max_session_turns:p.value==="dual_ai"?m.value:null,side_a_label:x.value||null,side_a_agent_prompt:k.value,side_a_stop_on_response:q.value,side_a_stop_tool:F.value||null,side_a_stop_tool_response_property:$.value||null,side_a_manual_stop_condition:oe.value,side_a_max_steps:te.value,side_a_end_conversation_tool:P.value||null};p.value==="dual_ai"&&(je.side_b_label=L.value||null,je.side_b_agent_prompt=G.value,je.side_b_stop_on_response=E.value,je.side_b_stop_tool=Z.value||null,je.side_b_stop_tool_response_property=j.value||null,je.side_b_max_steps=w.value,je.side_b_end_conversation_tool=I.value||null),Object.keys(W.value).length>0&&(je.tenvs=W.value),l.value&&s.editAgent?.id&&(je.id=s.editAgent.id),i("save",je)},Ia=()=>{ut(),i("update:modelValue",!1)};return fe(k,async ge=>{if(_e.value||(F.value="",$.value=""),!ge){de.value=null;return}pe.value=!0;try{const Y=await fetch(ue(`/api/prompts/${ge}`));Y.ok&&(de.value=await Y.json())}catch(Y){console.error("Error fetching Side A prompt:",Y)}finally{pe.value=!1}_e.value||await Ne()}),fe(G,async ge=>{if(_e.value||(Z.value="",j.value=""),!ge){ie.value=null;return}ye.value=!0;try{const Y=await fetch(ue(`/api/prompts/${ge}`));Y.ok&&(ie.value=await Y.json())}catch(Y){console.error("Error fetching Side B prompt:",Y)}finally{ye.value=!1}_e.value||await Ne()}),fe(B,ge=>{ge||(F.value="",$.value="")}),fe(U,ge=>{ge||(Z.value="",j.value="")}),fe(()=>s.modelValue,async ge=>{ge?(await Promise.all([N(),we()]),l.value?(ut(),await Va()):ut()):ut()}),(ge,Y)=>(a(),ne(He,{"model-value":t.modelValue,"onUpdate:modelValue":Y[24]||(Y[24]=re=>ge.$emit("update:modelValue",re)),title:l.value?"Edit Agent":"Create Agent",width:"max-w-6xl"},{footer:be(()=>[e("div",_r,[e("button",{onClick:Ia,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:Ma,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:u.value},S(l.value?"Update Agent":"Create Agent"),9,$r)])]),default:be(()=>[u.value?(a(),o("div",Fn,[...Y[25]||(Y[25]=[e("span",{class:"text-neutral-500"},"Loading agent data...",-1)])])):(a(),o("div",Bn,[t.apiError?(a(),o("div",qn,[e("p",zn,S(t.apiError),1)])):V("",!0),e("div",null,[A(Le,{ref_key:"nameInputRef",ref:g,modelValue:It.value,"onUpdate:modelValue":Y[0]||(Y[0]=re=>It.value=re),label:"Agent Name",error:f.value,required:"",disabled:l.value,onFocus:Et,onClick:Et},null,8,["modelValue","error","disabled"]),!f.value&&!l.value?(a(),o("p",Hn," Automatically formatted to snake_case with _agent suffix (e.g., research_agent) ")):V("",!0),l.value?(a(),o("p",Wn," Agent names cannot be changed after creation (used as foreign key for threads) ")):V("",!0)]),e("div",null,[A(Le,{modelValue:d.value,"onUpdate:modelValue":Y[1]||(Y[1]=re=>d.value=re),label:"Display Title (Optional)"},null,8,["modelValue"]),Y[26]||(Y[26]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Human-readable title shown in the UI (e.g., Research Assistant). If not set, the name will be used. ",-1))]),e("div",null,[A(Ve,{modelValue:p.value,"onUpdate:modelValue":Y[2]||(Y[2]=re=>p.value=re),label:"Agent Type",options:ht},null,8,["modelValue"]),Y[27]||(Y[27]=e("p",{class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"}," Choose between two AI agents conversing, or an AI agent conversing with a human ",-1))]),p.value==="dual_ai"?(a(),o("div",Jn,[A(Pe,{modelValue:h.value,"onUpdate:modelValue":Y[3]||(Y[3]=re=>h.value=re),label:"Expose as Tool"},null,8,["modelValue"]),Y[28]||(Y[28]=e("p",{class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"}," Make this subagent available as a tool that can be called by other prompts or agents. When called, it will execute as a subagent. ",-1))])):V("",!0),h.value&&p.value==="dual_ai"?(a(),o("div",Kn,[A(ya,{modelValue:_.value,"onUpdate:modelValue":Y[4]||(Y[4]=re=>_.value=re),label:"Tool Description",placeholder:"Describe what this agent does when called as a tool",error:b.value,rows:3},null,8,["modelValue","error"]),b.value?V("",!0):(a(),o("p",Gn," This description helps other agents understand when to use this agent "))])):V("",!0),p.value==="dual_ai"?(a(),o("div",Xn,[A(Le,{"model-value":m.value?.toString()||"","onUpdate:modelValue":Y[5]||(Y[5]=re=>m.value=re?parseInt(re):null),label:"Max Session Turns",type:"number",error:y.value,placeholder:"Unlimited"},null,8,["model-value","error"]),y.value?V("",!0):(a(),o("p",Yn," Maximum number of back-and-forth exchanges between the two agents before the conversation ends "))])):V("",!0),e("div",Qn,[e("div",Zn,[Y[35]||(Y[35]=e("h4",{class:"font-semibold text-base mb-4 text-neutral-800 dark:text-neutral-200"}," Side A (AI) ",-1)),e("div",null,[A(Le,{modelValue:x.value,"onUpdate:modelValue":Y[6]||(Y[6]=re=>x.value=re),label:"Side Label (Optional)",placeholder:"e.g., ATC, Pilot, Customer, Support"},null,8,["modelValue"]),Y[29]||(Y[29]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Custom label for this side (shows in message bubbles and toggle) ",-1))]),e("div",null,[A(Ve,{modelValue:k.value,"onUpdate:modelValue":Y[7]||(Y[7]=re=>k.value=re),label:"Agent Prompt",options:Ae.value,error:D.value,required:""},null,8,["modelValue","options","error"]),D.value?V("",!0):(a(),o("p",er," The prompt that defines this agent's behavior "))]),e("div",tr,[Y[32]||(Y[32]=e("label",{class:"block text-sm font-medium"}," Stop Conditions ",-1)),Y[33]||(Y[33]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Optional. If no stop conditions are set, the agent will continue until programmatically stopped or end conversation tool is called. ",-1)),e("div",ar,[A(Pe,{modelValue:q.value,"onUpdate:modelValue":Y[8]||(Y[8]=re=>q.value=re),label:"Stop when agent returns content"},null,8,["modelValue"])]),Y[34]||(Y[34]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-2 ml-6"}," Agent stops when it returns a response without calling tools ",-1)),e("div",null,[A(Pe,{modelValue:B.value,"onUpdate:modelValue":Y[9]||(Y[9]=re=>B.value=re),label:"Stop on specific tool call"},null,8,["modelValue"]),B.value?(a(),o("div",or,[A(Ve,{modelValue:F.value,"onUpdate:modelValue":Y[10]||(Y[10]=re=>F.value=re),label:"Stop Tool",options:Re.value,error:T.value,placeholder:"Select a tool...",disabled:pe.value||!k.value},null,8,["modelValue","options","error","disabled"]),T.value?V("",!0):(a(),o("p",lr," Agent stops when this tool is called ")),F.value?(a(),o("div",sr,[A(Ve,{modelValue:$.value,"onUpdate:modelValue":Y[11]||(Y[11]=re=>$.value=re),label:"Response Property",options:he.value,error:K.value,placeholder:"Select property..."},null,8,["modelValue","options","error"]),Y[30]||(Y[30]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Property from tool arguments to return as final response ",-1))])):V("",!0)])):V("",!0)]),p.value==="ai_human"&&!q.value&&!B.value?(a(),o("div",nr,[A(Pe,{modelValue:oe.value,"onUpdate:modelValue":Y[12]||(Y[12]=re=>oe.value=re),label:"I have manually implemented a stop condition"},null,8,["modelValue"]),Y[31]||(Y[31]=e("p",{class:"mt-2 text-xs text-yellow-800 dark:text-yellow-200"}," ⚠️ Warning: Only check this if you have implemented a custom stop condition in your code (e.g., via hooks or custom logic). Without a stop condition, the agent may run indefinitely. ",-1))])):V("",!0)]),e("div",null,[A(Le,{"model-value":te.value?.toString()||"","onUpdate:modelValue":Y[13]||(Y[13]=re=>te.value=re?parseInt(re):null),label:"Max Steps",type:"number",error:H.value,placeholder:"Unlimited"},null,8,["model-value","error"]),H.value?V("",!0):(a(),o("p",rr," Maximum steps this side can take before yielding (safety limit) "))]),e("div",null,[A(Ve,{modelValue:P.value,"onUpdate:modelValue":Y[14]||(Y[14]=re=>P.value=re),label:"End Conversation Tool",options:Re.value,error:C.value,placeholder:"Select a tool...",disabled:pe.value||!k.value},null,8,["modelValue","options","error","disabled"]),C.value?V("",!0):(a(),o("p",ir," Tool that ends the entire conversation when called "))])]),e("div",dr,[e("h4",ur," Side B ("+S(p.value==="ai_human"?"Human":"AI")+") ",1),e("div",null,[A(Le,{modelValue:L.value,"onUpdate:modelValue":Y[15]||(Y[15]=re=>L.value=re),label:"Side Label (Optional)",placeholder:"e.g., ATC, Pilot, Customer, Support"},null,8,["modelValue"]),Y[36]||(Y[36]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Custom label for this side (shows in message bubbles and toggle) ",-1))]),p.value==="ai_human"?(a(),o("div",cr,[...Y[37]||(Y[37]=[e("svg",{class:"w-20 h-20 mb-4 text-neutral-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})],-1),e("h5",{class:"font-medium text-lg mb-2"},"Human User",-1),e("p",{class:"text-sm text-neutral-500 dark:text-neutral-400 text-center max-w-xs"}," This side of the conversation will be handled by a human user through the interface ",-1)])])):(a(),o(ve,{key:1},[e("div",null,[A(Ve,{modelValue:G.value,"onUpdate:modelValue":Y[16]||(Y[16]=re=>G.value=re),label:"Agent Prompt",options:Ae.value,error:ee.value,required:""},null,8,["modelValue","options","error"]),ee.value?V("",!0):(a(),o("p",pr," The prompt that defines this agent's behavior "))]),e("div",mr,[Y[39]||(Y[39]=e("label",{class:"block text-sm font-medium"}," Stop Conditions ",-1)),Y[40]||(Y[40]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Optional. If no stop conditions are set, the agent will continue until programmatically stopped or end conversation tool is called. ",-1)),e("div",vr,[A(Pe,{modelValue:E.value,"onUpdate:modelValue":Y[17]||(Y[17]=re=>E.value=re),label:"Stop when agent returns content"},null,8,["modelValue"])]),Y[41]||(Y[41]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 -mt-2 ml-6"}," Agent stops when it returns a response without calling tools ",-1)),e("div",null,[A(Pe,{modelValue:U.value,"onUpdate:modelValue":Y[18]||(Y[18]=re=>U.value=re),label:"Stop on specific tool call"},null,8,["modelValue"]),U.value?(a(),o("div",fr,[A(Ve,{modelValue:Z.value,"onUpdate:modelValue":Y[19]||(Y[19]=re=>Z.value=re),label:"Stop Tool",options:xe.value,error:se.value,placeholder:"Select a tool...",disabled:ye.value||!G.value},null,8,["modelValue","options","error","disabled"]),se.value?V("",!0):(a(),o("p",hr," Agent stops when this tool is called ")),Z.value?(a(),o("div",gr,[A(Ve,{modelValue:j.value,"onUpdate:modelValue":Y[20]||(Y[20]=re=>j.value=re),label:"Response Property",options:$e.value,error:M.value,placeholder:"Select property..."},null,8,["modelValue","options","error"]),Y[38]||(Y[38]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Property from tool arguments to return as final response ",-1))])):V("",!0)])):V("",!0)])]),e("div",null,[A(Le,{"model-value":w.value?.toString()||"","onUpdate:modelValue":Y[21]||(Y[21]=re=>w.value=re?parseInt(re):null),label:"Max Steps",type:"number",error:R.value,placeholder:"Unlimited"},null,8,["model-value","error"]),R.value?V("",!0):(a(),o("p",br," Maximum steps this side can take before yielding (safety limit) "))]),e("div",null,[A(Ve,{modelValue:I.value,"onUpdate:modelValue":Y[22]||(Y[22]=re=>I.value=re),label:"End Conversation Tool",options:xe.value,error:le.value,placeholder:"Select a tool...",disabled:ye.value||!G.value},null,8,["modelValue","options","error","disabled"]),le.value?V("",!0):(a(),o("p",xr," Tool that ends the entire conversation when called "))])],64))])]),O.value.length>0||Object.keys(W.value).length>0?(a(),o("div",yr,[e("div",kr,[Y[42]||(Y[42]=e("label",{class:"block text-sm font-medium"},"Thread Environment Variables",-1)),ce.value?(a(),o("span",wr,"Loading...")):V("",!0)]),Y[43]||(Y[43]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Configure values for tools that require thread environment variables. Values from prompts are shown locked - click to unlock and override. ",-1)),A(ka,{modelValue:W.value,"onUpdate:modelValue":Y[23]||(Y[23]=re=>W.value=re),inherited:O.value,"allow-custom":!0,disabled:u.value},null,8,["modelValue","inherited","disabled"])])):V("",!0)]))]),_:1},8,["model-value","title"]))}}),Tr={},Sr={class:"p-8 w-full max-w-7xl mx-auto"};function Vr(t,n){return a(),o("div",Sr,[et(t.$slots,"default")])}const at=tt(Tr,[["render",Vr]]),Mr=me({__name:"AgentsView",setup(t){const n=lt(),s=Ye(),i=v(!1),l=v("add"),u=v(null),r=v(null),c=v(null);fe(()=>s.query.refresh,()=>{s.query.refresh&&(r.value?.refresh(),n.replace({path:"/agents",query:{}}))});const f=()=>{l.value="add",u.value=null,c.value=null,i.value=!0},g=p=>{l.value="edit",u.value=p,c.value=null,i.value=!0},d=async p=>{c.value=null;try{const h=l.value==="edit"&&u.value?.id,{originalName:_,...b}=p,m=ue(h?`/api/agents/${u.value.id}`:"/api/agents"),x=await fetch(m,{method:h?"PUT":"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)});if(x.ok)r.value?.refresh(),i.value=!1,u.value=null;else{const k=await x.json();c.value=k.error||`Failed to ${h?"update":"create"} agent`}}catch(h){console.error(`Error ${l.value==="edit"?"updating":"creating"} agent:`,h),c.value=`Failed to ${l.value==="edit"?"update":"create"} agent`}};return(p,h)=>(a(),ne(at,null,{default:be(()=>[e("div",{class:"flex justify-between items-center mb-6"},[h[1]||(h[1]=e("h1",{class:"text-3xl font-bold"},"Agents",-1)),e("button",{onClick:f,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Create Agent ")]),h[2]||(h[2]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Configure and manage your AI agents. ",-1)),A(Vs,{ref_key:"dataTableRef",ref:r,onAdd:f,onEdit:g},null,512),A(Cr,{modelValue:i.value,"onUpdate:modelValue":h[0]||(h[0]=_=>i.value=_),mode:l.value,editAgent:u.value,apiError:c.value,onSave:d},null,8,["modelValue","mode","editAgent","apiError"])]),_:1}))}});function Ir(t){const{limit:n=50,offset:s=0,agentId:i=null,userId:l=null,search:u=null,startDate:r=null,endDate:c=null,autoFetch:f=!0}=t||{},g=J(()=>{const D=new URLSearchParams,q=typeof n=="number"?n:n.value,B=typeof s=="number"?s:s.value,F=typeof i=="string"?i:i?.value,T=typeof l=="string"?l:l?.value,$=typeof u=="string"?u:u?.value,K=typeof r=="number"?r:r?.value,oe=typeof c=="number"?c:c?.value;return D.append("limit",q.toString()),D.append("offset",B.toString()),F&&D.append("agent_id",F),T&&D.append("user_id",T),$&&D.append("search",$),K&&D.append("startDate",K.toString()),oe&&D.append("endDate",oe.toString()),ue(`/api/threads?${D.toString()}`)}),{data:d,error:p,isFetching:h,isFinished:_,execute:b,abort:m}=Ue(g,{immediate:f,refetch:!0}).get().json(),y=J(()=>d.value?.threads||[]),x=J(()=>d.value?.total||0),k=J(()=>d.value?.hasMore||!1);return{threads:y,total:x,hasMore:k,error:p,isFetching:h,isFinished:_,refetch:b,abort:m}}function St(t){const n=J(()=>!!(typeof t=="string"?t:t?.value)),s=J(()=>{const d=typeof t=="string"?t:t?.value;return ue(d?`/api/threads/${d}`:"/api/threads/placeholder")}),{data:i,error:l,isFetching:u,isFinished:r,execute:c,abort:f}=Ue(s,{immediate:!1,refetch:!0}).get().json();return fe(n,d=>{d&&c()},{immediate:!0}),{thread:J(()=>i.value?{id:i.value.thread.id,agent_id:i.value.thread.agent_id,user_id:i.value.thread.user_id,tags:i.value.thread.tags||[],created_at:i.value.thread.created_at,agent:i.value.agent||{id:"",title:"Unknown",type:"unknown"},stats:i.value.stats}:null),error:l,isFetching:u,isFinished:r,refetch:c,abort:f}}function Er(t){const{autoConnect:n=!0,onEvent:s}=t||{},i=v(null),l=v(!1),u=v(null);let r=0,c=null,f=null,g=!0;const d=3e4,p=3e4,h=()=>{c&&(clearTimeout(c),c=null),f&&(clearInterval(f),f=null)},_=()=>{f&&clearInterval(f),f=setInterval(()=>{i.value&&i.value.readyState===WebSocket.OPEN&&i.value.send("ping")},p)},b=()=>{if(!g)return;const k=Math.min(1e3*Math.pow(2,r),d);r++,console.log(`[AgentBuilderEvents] Scheduling reconnect in ${k}ms (attempt ${r})`),c=setTimeout(()=>{g&&m()},k)},m=()=>{i.value&&i.value.close();const k=window.location.protocol==="https:"?"wss:":"ws:",D=window.location.host;let q=`${k}//${D}${ue("/api/events")}`;const B=localStorage.getItem("auth_token");B&&(q+=`?token=${encodeURIComponent(B)}`);try{i.value=new WebSocket(q),i.value.onopen=()=>{l.value=!0,u.value=null,r=0,_(),console.log("[AgentBuilderEvents] WebSocket connected")},i.value.onmessage=F=>{try{const T=JSON.parse(F.data);s&&s(T)}catch(T){console.error("[AgentBuilderEvents] Failed to parse WebSocket message:",T)}},i.value.onerror=F=>{u.value="WebSocket connection error",console.error("[AgentBuilderEvents] WebSocket error:",F)},i.value.onclose=()=>{l.value=!1,h(),console.log("[AgentBuilderEvents] WebSocket disconnected"),b()}}catch(F){u.value=F.message||"Failed to create WebSocket",console.error("[AgentBuilderEvents] WebSocket creation error:",F),b()}},y=()=>{g=!0,r=0,m()},x=()=>{g=!1,h(),i.value&&(i.value.close(),i.value=null),l.value=!1,r=0};return n&&y(),Be(()=>{x()}),{wsConnected:l,wsError:u,connect:y,disconnect:x}}const Lr={class:"inline-flex items-center justify-center"},Se=me({__name:"Loader",props:{size:{default:"md"}},setup(t){const n=t,s=J(()=>{switch(n.size){case"xs":return"w-3 h-3 border";case"sm":return"w-3.5 h-3.5 border";case"md":default:return"w-4 h-4 border-2"}});return(i,l)=>(a(),o("div",Lr,[e("div",{class:ae([s.value,"border-black/20 dark:border-white/20 border-t-black dark:border-t-white rounded-full animate-spin"])},null,2)]))}});function Ar(t){const s=Date.now()*1e3-t,i=Math.floor(s/1e6);if(i<60)return i===1?"1 second ago":`${i} seconds ago`;const l=Math.floor(i/60);if(l<60)return l===1?"1 minute ago":`${l} minutes ago`;const u=Math.floor(l/60);if(u<24)return u===1?"1 hour ago":`${u} hours ago`;const r=Math.floor(u/24);if(r<30)return r===1?"1 day ago":`${r} days ago`;const c=Math.floor(r/30);if(c<12)return c===1?"1 month ago":`${c} months ago`;const f=Math.floor(c/12);return f===1?"1 year ago":`${f} years ago`}function Pr(t){const n=v("");let s=null;const i=()=>typeof t=="function"?t():typeof t=="number"?t:t.value,l=()=>{const u=i();n.value=Ar(u);const c=Date.now()*1e3-u,f=Math.floor(c/1e6);s!==null&&(clearInterval(s),s=null),f<60?s=setInterval(l,1e3):f<3600?s=setInterval(l,6e4):f<86400&&(s=setInterval(l,6e5))};return l(),Be(()=>{s!==null&&clearInterval(s)}),n}const rt=me({__name:"TimeAgo",props:{timestamp:{}},setup(t){const n=t,s=Pr(()=>n.timestamp);return(i,l)=>(a(),o("span",null,S(X(s)),1))}}),Dr={class:"relative inline-flex items-center"},jr={key:0,class:"inline-block w-2 h-2 rounded-full bg-green-500 dark:bg-green-400"},Or={key:1,class:"inline-block w-2 h-2 rounded-full bg-neutral-400 dark:bg-neutral-600"},Ur={key:0},Rr={key:1},Vt=me({__name:"StatusDot",props:{connected:{type:Boolean},error:{type:Boolean}},setup(t){const n=v(!1),s=v(null);return(i,l)=>(a(),o("div",Dr,[e("span",{class:"p-0.5 cursor-default outline-none",tabindex:"-1",onMouseenter:l[0]||(l[0]=u=>n.value=!0),onMouseleave:l[1]||(l[1]=u=>n.value=!1)},[t.connected?(a(),o("span",jr)):(a(),o("span",Or))],32),A(Xe,{"enter-active-class":"transition-opacity duration-150","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-100","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:be(()=>[n.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:s,class:ae(["absolute top-full left-1/2 -translate-x-1/2 mt-1 px-2 py-1 text-xs rounded shadow-lg whitespace-nowrap z-50 border",{"bg-green-50 dark:bg-green-950 border-green-200 dark:border-green-800 text-green-700 dark:text-green-300":t.connected,"bg-neutral-50 dark:bg-neutral-900 border-neutral-200 dark:border-neutral-700 text-neutral-600 dark:text-neutral-400":!t.connected}])},[t.connected?(a(),o("span",Ur,"Live - Connected")):(a(),o("span",Rr,"Offline"))],2)):V("",!0)]),_:1})]))}});function Nr(){const t=ue("/api/agents"),{data:n,error:s,isFetching:i,isFinished:l,execute:u}=Ue(t,{immediate:!0}).get().json();return{agents:J(()=>n.value?.agents||[]),error:s,isFetching:i,isFinished:l,refetch:u}}const Fr={class:"relative min-w-0"},Br={class:"truncate min-w-0 text-left"},qr={class:"w-56 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},zr={class:"p-2 border-b-2 border-black dark:border-neutral-300"},Hr={class:"relative"},Wr={class:"max-h-48 overflow-y-auto"},Jr={key:0,class:"px-3 py-4 text-sm font-mono text-center text-neutral-500"},Kr=["onClick"],Gr={class:"truncate"},Xr={key:0,class:"px-3 py-4 text-sm font-mono text-center text-neutral-500"},Yr=me({__name:"AgentFilterDropdown",props:{modelValue:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,{agents:l,isFetching:u}=Nr(),r=v(!1),c=v(""),f=v(null),g=v(null),d=J(()=>{if(!c.value)return l.value;const F=c.value.toLowerCase();return l.value.filter(T=>T.name.toLowerCase().includes(F)||T.title.toLowerCase().includes(F))}),p=J(()=>s.modelValue&&l.value.find(F=>F.name===s.modelValue)||null),h=J(()=>p.value?p.value.title||p.value.name:"All agents"),_=J(()=>s.modelValue!==null);function b(){if(!f.value||!g.value)return;const F=f.value.getBoundingClientRect();g.value.style.position="fixed",g.value.style.top=`${F.bottom+8}px`,g.value.style.left=`${F.left}px`,g.value.style.margin="0"}function m(){r.value?y():(r.value=!0,Te(()=>{if(g.value&&(g.value.setAttribute("popover","auto"),g.value.addEventListener("toggle",x),"showPopover"in g.value))try{g.value.showPopover()}catch{}b()}))}function y(){if(g.value){if("hidePopover"in g.value)try{g.value.hidePopover()}catch{}g.value.removeEventListener("toggle",x)}r.value=!1,c.value=""}function x(F){F.target===g.value&&(r.value=F.newState==="open",r.value&&b())}function k(F){i("update:modelValue",F?.name||null),y()}function D(F){F.stopPropagation(),i("update:modelValue",null)}const q=F=>{const T=F.target;g.value&&!g.value.contains(T)&&f.value&&!f.value.contains(T)&&y()},B=F=>{F.key==="Escape"&&r.value&&(y(),f.value?.focus())};return Me(()=>{document.addEventListener("click",q),document.addEventListener("keydown",B),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0)}),Be(()=>{document.removeEventListener("click",q),document.removeEventListener("keydown",B),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}),(F,T)=>(a(),o("div",Fr,[e("button",{ref_key:"triggerRef",ref:f,type:"button",onClick:m,class:ae(["w-full flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded border-2 transition-colors min-w-0",[_.value?"border-accent-500 bg-accent-50 dark:bg-accent-950/50 text-accent-700 dark:text-accent-300":"border-neutral-300 dark:border-neutral-600 hover:border-accent-400 dark:hover:border-accent-500 bg-white dark:bg-black"]])},[A(X(ja),{size:12,class:"shrink-0"}),e("span",Br,S(h.value),1),_.value?(a(),ne(X(ft),{key:0,size:12,class:"shrink-0 opacity-60 hover:opacity-100",onClick:D})):(a(),ne(X(nt),{key:1,size:12,class:ae(["shrink-0 opacity-60",r.value?"rotate-180":""])},null,8,["class"]))],2),r.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:g,class:"dropdown-popover z-[9999]"},[A(Qe,{"offset-x":4,"offset-y":4,intensity:.3},{default:be(()=>[e("div",qr,[e("div",zr,[e("div",Hr,[A(X(Yt),{size:12,class:"absolute left-2 top-1/2 -translate-y-1/2 opacity-60"}),Ie(e("input",{"onUpdate:modelValue":T[0]||(T[0]=$=>c.value=$),type:"text",placeholder:"Search agents...",class:"w-full pl-7 pr-2 py-1.5 text-xs font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white placeholder:text-neutral-400",onClick:T[1]||(T[1]=Ee(()=>{},["stop"]))},null,512),[[Oe,c.value]])])]),e("div",Wr,[e("button",{type:"button",onClick:T[2]||(T[2]=$=>k(null)),class:ae(["w-full flex items-center gap-2 px-3 py-2 text-sm font-mono text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors",t.modelValue?"":"bg-accent-50 dark:bg-accent-950/30"])},[e("span",{class:ae(["w-2 h-2 rounded-full border-2 border-accent-500",t.modelValue?"":"bg-accent-500"])},null,2),T[3]||(T[3]=Ce(" All agents ",-1))],2),X(u)?(a(),o("div",Jr," Loading... ")):(a(),o(ve,{key:1},[(a(!0),o(ve,null,ke(d.value,$=>(a(),o("button",{key:$.id,type:"button",onClick:K=>k($),class:ae(["w-full flex items-center gap-2 px-3 py-2 text-sm font-mono text-left hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors",t.modelValue===$.name?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:ae(["w-2 h-2 rounded-full border-2 border-accent-500",t.modelValue===$.name?"bg-accent-500":""])},null,2),e("span",Gr,S($.title||$.name),1)],10,Kr))),128)),d.value.length===0&&!X(u)?(a(),o("div",Xr," No agents found ")):V("",!0)],64))])])]),_:1})],512)):V("",!0)]))}}),Qr={class:"relative min-w-0"},Zr={class:"truncate flex-1 text-left"},ei={class:"w-52 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},ti={key:0},ai=["onClick"],oi={class:"border-t-2 border-black dark:border-neutral-300"},li={key:1,class:"p-3 space-y-3"},si={class:"flex items-center justify-between"},ni={class:"space-y-2"},ri=me({__name:"DateFilterDropdown",props:{startDate:{},endDate:{}},emits:["update:startDate","update:endDate"],setup(t,{emit:n}){const s=t,i=n,l=v(!1),u=v(!1),r=v(null),c=v(null),f=v(""),g=v(""),d=[{label:"All time",value:"all",getRange:()=>({startDate:null,endDate:null})},{label:"Today",value:"today",getRange:()=>{const T=new Date,$=new Date(T.getFullYear(),T.getMonth(),T.getDate());return{startDate:Math.floor($.getTime()/1e3),endDate:null}}},{label:"Last 3 days",value:"3days",getRange:()=>{const T=new Date,$=new Date(T.getFullYear(),T.getMonth(),T.getDate()-2);return{startDate:Math.floor($.getTime()/1e3),endDate:null}}},{label:"Last 7 days",value:"7days",getRange:()=>{const T=new Date,$=new Date(T.getFullYear(),T.getMonth(),T.getDate()-6);return{startDate:Math.floor($.getTime()/1e3),endDate:null}}},{label:"Last 30 days",value:"30days",getRange:()=>{const T=new Date,$=new Date(T.getFullYear(),T.getMonth(),T.getDate()-29);return{startDate:Math.floor($.getTime()/1e3),endDate:null}}}],p=J(()=>{if(!s.startDate&&!s.endDate)return"all";for(const T of d){const $=T.getRange();if($.startDate===s.startDate&&$.endDate===s.endDate)return T.value}return"custom"}),h=J(()=>{if(!s.startDate&&!s.endDate)return"All time";const T=d.find(K=>K.value===p.value);if(T&&p.value!=="custom")return T.label;const $=K=>new Date(K*1e3).toLocaleDateString("en-US",{month:"short",day:"numeric"});return s.startDate&&s.endDate?`${$(s.startDate)} - ${$(s.endDate)}`:s.startDate?`From ${$(s.startDate)}`:s.endDate?`Until ${$(s.endDate)}`:"Custom"}),_=J(()=>s.startDate!==null||s.endDate!==null);function b(){if(!r.value||!c.value)return;const T=r.value.getBoundingClientRect();c.value.style.position="fixed",c.value.style.top=`${T.bottom+8}px`,c.value.style.left=`${T.left}px`,c.value.style.margin="0"}function m(){l.value?y():(l.value=!0,Te(()=>{if(c.value&&(c.value.setAttribute("popover","auto"),c.value.addEventListener("toggle",x),"showPopover"in c.value))try{c.value.showPopover()}catch{}b()}))}function y(){if(c.value){if("hidePopover"in c.value)try{c.value.hidePopover()}catch{}c.value.removeEventListener("toggle",x)}l.value=!1,u.value=!1}function x(T){T.target===c.value&&(l.value=T.newState==="open",l.value&&b())}function k(T){const $=T.getRange();i("update:startDate",$.startDate),i("update:endDate",$.endDate),y()}function D(){const T=f.value?Math.floor(new Date(f.value).getTime()/1e3):null,$=g.value?Math.floor(new Date(g.value+"T23:59:59").getTime()/1e3):null;i("update:startDate",T),i("update:endDate",$),y()}function q(T){T.stopPropagation(),i("update:startDate",null),i("update:endDate",null)}const B=T=>{const $=T.target;c.value&&!c.value.contains($)&&r.value&&!r.value.contains($)&&y()},F=T=>{T.key==="Escape"&&l.value&&(y(),r.value?.focus())};return Me(()=>{document.addEventListener("click",B),document.addEventListener("keydown",F),window.addEventListener("resize",b),window.addEventListener("scroll",b,!0)}),Be(()=>{document.removeEventListener("click",B),document.removeEventListener("keydown",F),window.removeEventListener("resize",b),window.removeEventListener("scroll",b,!0)}),fe(u,T=>{T&&(s.startDate&&(f.value=new Date(s.startDate*1e3).toISOString().split("T")[0]),s.endDate?g.value=new Date(s.endDate*1e3).toISOString().split("T")[0]:g.value=new Date().toISOString().split("T")[0])}),(T,$)=>(a(),o("div",Qr,[e("button",{ref_key:"triggerRef",ref:r,type:"button",onClick:m,class:ae(["w-full flex items-center gap-1.5 px-2 py-1 text-xs font-mono rounded border-2 transition-colors min-w-0",[_.value?"border-accent-500 bg-accent-50 dark:bg-accent-950/50 text-accent-700 dark:text-accent-300":"border-neutral-300 dark:border-neutral-600 hover:border-accent-400 dark:hover:border-accent-500 bg-white dark:bg-black"]])},[A(X(Oa),{size:12,class:"shrink-0"}),e("span",Zr,S(h.value),1),_.value?(a(),ne(X(ft),{key:0,size:12,class:"shrink-0 opacity-60 hover:opacity-100",onClick:q})):(a(),ne(X(nt),{key:1,size:12,class:ae(["shrink-0 opacity-60",l.value?"rotate-180":""])},null,8,["class"]))],2),l.value?(a(),o("div",{key:0,ref_key:"popoverRef",ref:c,class:"dropdown-popover z-[9999]"},[A(Qe,{"offset-x":4,"offset-y":4,intensity:.3},{default:be(()=>[e("div",ei,[u.value?(a(),o("div",li,[e("div",si,[$[7]||($[7]=e("span",{class:"text-sm font-mono font-bold"},"Custom range",-1)),e("button",{type:"button",onClick:$[1]||($[1]=Ee(K=>u.value=!1,["stop"])),class:"text-xs font-mono text-neutral-500 hover:text-black dark:hover:text-white"}," ← Back ")]),e("div",ni,[e("div",null,[$[8]||($[8]=e("label",{class:"block text-xs font-mono text-neutral-500 mb-1"},"FROM",-1)),Ie(e("input",{"onUpdate:modelValue":$[2]||($[2]=K=>f.value=K),type:"date",class:"w-full px-2 py-1.5 text-sm font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",onClick:$[3]||($[3]=Ee(()=>{},["stop"]))},null,512),[[Oe,f.value]])]),e("div",null,[$[9]||($[9]=e("label",{class:"block text-xs font-mono text-neutral-500 mb-1"},"TO",-1)),Ie(e("input",{"onUpdate:modelValue":$[4]||($[4]=K=>g.value=K),type:"date",class:"w-full px-2 py-1.5 text-sm font-mono bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",onClick:$[5]||($[5]=Ee(()=>{},["stop"]))},null,512),[[Oe,g.value]])])]),e("button",{type:"button",onClick:D,class:"w-full py-2 text-sm font-mono font-bold bg-black dark:bg-white text-white dark:text-black rounded hover:opacity-90 transition-opacity"}," Apply ")])):(a(),o("div",ti,[(a(),o(ve,null,ke(d,K=>e("button",{key:K.value,type:"button",onClick:oe=>k(K),class:ae(["w-full px-3 py-2 text-left text-sm font-mono hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors flex items-center gap-2",p.value===K.value?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:ae(["w-2 h-2 rounded-full border-2 border-accent-500",p.value===K.value?"bg-accent-500":""])},null,2),Ce(" "+S(K.label),1)],10,ai)),64)),e("div",oi,[e("button",{type:"button",onClick:$[0]||($[0]=Ee(K=>u.value=!0,["stop"])),class:ae(["w-full px-3 py-2 text-left text-sm font-mono hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors flex items-center gap-2",p.value==="custom"?"bg-accent-50 dark:bg-accent-950/30":""])},[e("span",{class:ae(["w-2 h-2 rounded-full border-2 border-accent-500",p.value==="custom"?"bg-accent-500":""])},null,2),$[6]||($[6]=Ce(" Custom range... ",-1))],2)])]))])]),_:1})],512)):V("",!0)]))}}),ii={class:"flex flex-col flex-1 min-h-0 overflow-visible"},di={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},ui={class:"flex items-center justify-between"},ci={class:"flex items-center gap-2"},pi={key:0,class:"text-xs font-mono text-neutral-500 dark:text-neutral-400"},mi={class:"flex items-center gap-2"},vi=["title"],fi={key:0,class:"absolute -top-1 -right-1 w-3.5 h-3.5 flex items-center justify-center text-[8px] font-bold font-mono bg-accent-500 text-white rounded-full"},hi={key:0,class:"border-b-2 border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900/50"},gi={class:"p-3 space-y-2"},bi={class:"relative"},xi={class:"flex items-center gap-2 w-full"},yi={key:0,class:"flex justify-end"},ki={key:0,class:"p-4 flex justify-center"},wi={key:1,class:"p-4 text-red-600 dark:text-red-400"},_i={key:2,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},$i={key:1,class:"text-base"},Ci={key:3},Ti=["id","onClick"],Si={class:"flex items-center gap-2 mb-1"},Vi={class:"flex-shrink-0 text-neutral-400 dark:text-neutral-500 text-[10px]"},Mi={class:"flex items-center gap-2"},Ii={class:"text-[10px] text-neutral-400 dark:text-neutral-500 font-mono truncate max-w-[80px]"},Ei={key:0,class:"flex flex-wrap gap-1 flex-1 min-w-0"},Li={key:0,class:"text-[10px] text-neutral-400"},Ai={key:0,class:"p-3 flex justify-center"},Pi={key:1,class:"p-3 text-center text-[10px] text-neutral-400 dark:text-neutral-500"},Di=50,ji=me({__name:"ThreadListPane",props:{selectedThreadId:{}},emits:["selectThread","collapse","createThread","threadsLoaded"],setup(t,{expose:n,emit:s}){const i=s,l=v(!1),u=v(""),r=v(null),c=v(null),f=v(null),g=v(null),d=v(0),p=v([]),h=v(!1),_=Na(E=>{r.value=E||null},300);fe(u,E=>{_(E)});const b=J(()=>{let E=0;return r.value&&E++,c.value&&E++,(f.value||g.value)&&E++,E});function m(){u.value="",r.value=null,c.value=null,f.value=null,g.value=null}const{threads:y,total:x,hasMore:k,isFetching:D,isFinished:q,error:B,refetch:F}=Ir({limit:Di,offset:d,search:r,agentId:c,startDate:f,endDate:g});fe([r,c,f,g],()=>{d.value=0,p.value=[],h.value=!1}),fe(y,E=>{if(d.value===0)p.value=[...E];else{const U=new Set(p.value.map(se=>se.id)),Z=E.filter(se=>!U.has(se.id));p.value=[...p.value,...Z]}h.value=!1});const T=v([]),$=v(new Set),K=J(()=>{const E=p.value.filter(se=>!$.value.has(se.id)),U=new Set(E.map(se=>se.id));return[...T.value.filter(se=>!U.has(se.id)&&!$.value.has(se.id)),...E].sort((se,j)=>j.created_at-se.created_at)}),oe=v(null);function te(){h.value||D.value||!k.value||(h.value=!0,d.value=p.value.length)}const{arrivedState:H}=Ua(oe,{offset:{bottom:100}});fe(()=>H.bottom,E=>{E&&k.value&&!D.value&&!h.value&&te()});const P=async E=>{if(E.type==="thread_created"){const U={id:E.thread.id,agent_id:E.thread.agent_name,user_id:E.thread.user_id,tags:E.thread.tags||[],created_at:E.thread.created_at,agent:{name:E.thread.agent_name,title:void 0,type:"ai_human"}};T.value.unshift(U)}else E.type==="thread_deleted"&&($.value.add(E.threadId),T.value=T.value.filter(U=>U.id!==E.threadId))},{wsConnected:C,wsError:L}=Er({onEvent:P});fe(()=>d.value,E=>{E===0&&(T.value=[])});const G=v(!1);fe(()=>({threads:p.value,finished:q.value}),({threads:E,finished:U})=>{U&&!G.value&&E.length>0&&(G.value=!0,i("threadsLoaded",E[0]?.id??null))},{immediate:!0}),n({refetch:F});const ee=E=>{i("selectThread",E)};return(E,U)=>(a(),o("div",ii,[e("div",di,[e("div",ui,[e("div",ci,[A(X(Qt),{size:18,class:"shrink-0"}),U[8]||(U[8]=e("h2",{class:"text-base font-bold"},"Threads",-1)),!X(D)&&X(x)>0?(a(),o("span",pi," ("+S(X(x))+") ",1)):V("",!0),A(Vt,{connected:X(C),error:X(L)},null,8,["connected","error"])]),e("div",mi,[e("button",{onClick:U[0]||(U[0]=Z=>l.value=!l.value),type:"button",class:ae(["relative p-1 rounded transition-colors hover:bg-neutral-100 dark:hover:bg-neutral-900",[l.value||b.value>0?"text-accent-600 dark:text-accent-400":""]]),title:l.value?"Hide filters":"Show filters"},[A(X(Ra),{size:18}),b.value>0?(a(),o("span",fi,S(b.value),1)):V("",!0)],10,vi),e("button",{onClick:U[1]||(U[1]=Z=>i("createThread")),type:"button",class:"px-2 py-1 text-xs bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity whitespace-nowrap"}," + New "),e("button",{onClick:U[2]||(U[2]=Z=>i("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[A(X(Tt),{size:20})])])])]),A(Xe,{"enter-active-class":"transition-all duration-200 ease-out","enter-from-class":"opacity-0 -translate-y-2 max-h-0","enter-to-class":"opacity-100 translate-y-0 max-h-60","leave-active-class":"transition-all duration-150 ease-in","leave-from-class":"opacity-100 translate-y-0 max-h-60","leave-to-class":"opacity-0 -translate-y-2 max-h-0"},{default:be(()=>[l.value?(a(),o("div",hi,[e("div",gi,[e("div",bi,[A(X(Yt),{size:14,class:"absolute left-2.5 top-1/2 -translate-y-1/2 opacity-60"}),Ie(e("input",{"onUpdate:modelValue":U[3]||(U[3]=Z=>u.value=Z),type:"text",placeholder:"Search by tag or thread ID...",class:"w-full pl-8 pr-8 py-1.5 text-xs font-mono bg-white dark:bg-black border-2 border-neutral-300 dark:border-neutral-600 rounded focus:outline-none focus:border-black dark:focus:border-neutral-300 focus:ring-2 focus:ring-black/20 dark:focus:ring-white/20 placeholder:text-neutral-400"},null,512),[[Oe,u.value]]),u.value?(a(),o("button",{key:0,onClick:U[4]||(U[4]=Z=>u.value=""),type:"button",class:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 opacity-60 hover:opacity-100 transition-opacity"},[A(X(ft),{size:14})])):V("",!0)]),e("div",xi,[A(Yr,{modelValue:c.value,"onUpdate:modelValue":U[5]||(U[5]=Z=>c.value=Z),class:"flex-1 min-w-0"},null,8,["modelValue"]),A(ri,{startDate:f.value,"onUpdate:startDate":U[6]||(U[6]=Z=>f.value=Z),endDate:g.value,"onUpdate:endDate":U[7]||(U[7]=Z=>g.value=Z),class:"flex-1 min-w-0"},null,8,["startDate","endDate"])]),b.value>0?(a(),o("div",yi,[e("button",{onClick:m,type:"button",class:"text-xs font-mono text-neutral-500 hover:text-black dark:hover:text-white transition-colors"}," Clear all ")])):V("",!0)])])):V("",!0)]),_:1}),e("div",{ref_key:"scrollContainerRef",ref:oe,class:"flex-1 overflow-y-auto text-xs min-h-0"},[X(D)&&p.value.length===0?(a(),o("div",ki,[A(Se)])):X(B)?(a(),o("div",wi," Error: "+S(X(B)),1)):K.value.length===0?(a(),o("div",_i,[b.value>0?(a(),o(ve,{key:0},[U[9]||(U[9]=e("p",{class:"text-base mb-2"},"No matching threads",-1)),e("button",{onClick:m,type:"button",class:"text-xs text-accent-600 dark:text-accent-400 hover:underline"}," Clear filters ")],64)):(a(),o("p",$i,"No threads found"))])):(a(),o("div",Ci,[(a(!0),o(ve,null,ke(K.value,Z=>(a(),o("button",{key:Z.id,id:`thread-${Z.id}`,class:ae(["w-full text-left px-3 py-2.5 border-b border-neutral-200 dark:border-neutral-800 cursor-pointer transition-colors relative hover:bg-neutral-50 dark:hover:bg-neutral-800/50",{"bg-accent-50 dark:bg-accent-950/50 border-l-2 border-l-accent-500":t.selectedThreadId===Z.id}]),onClick:se=>ee(Z.id)},[e("div",Si,[e("span",{class:ae(["font-medium truncate flex-1 min-w-0",t.selectedThreadId===Z.id?"text-accent-700 dark:text-accent-300":""])},S(Z.agent.title||Z.agent.name),3),e("span",Vi,[A(rt,{timestamp:Z.created_at*1e6},null,8,["timestamp"])])]),e("div",Mi,[e("span",Ii,S(Z.id.slice(0,8)),1),Z.tags.length>0?(a(),o("div",Ei,[(a(!0),o(ve,null,ke(Z.tags.slice(0,3),se=>(a(),o("span",{key:se,class:ae(["inline-block px-1.5 py-0.5 rounded text-[10px] truncate max-w-[60px]",t.selectedThreadId===Z.id?"bg-accent-200 dark:bg-accent-900 text-accent-800 dark:text-accent-200":"bg-neutral-200 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400"])},S(se),3))),128)),Z.tags.length>3?(a(),o("span",Li," +"+S(Z.tags.length-3),1)):V("",!0)])):V("",!0)])],10,Ti))),128)),h.value||X(D)&&p.value.length>0?(a(),o("div",Ai,[A(Se)])):!X(k)&&K.value.length>0?(a(),o("div",Pi," All "+S(X(x))+" threads loaded ",1)):V("",!0)]))],512)]))}});function Oi(t,n={}){const s=v(null),i=v(!1),l=v(null);let u=null;try{u=ca()}catch{}const r=u?.workblocks??J(()=>[]),c=u?.messages??v([]),f=J(()=>u?.status.value==="connected"),g=v(null);u?.loading??v(!1);const d=J(()=>c.value.some(E=>E.status==="pending")),p=v(!1),h=v(0),_=v(!1);function b(E){if(!s.value?.agent)return null;const U=s.value.agent,Z=E==="assistant"?"A":"B";return Z==="A"&&U.side_a_label?U.side_a_label:Z==="B"&&U.side_b_label?U.side_b_label:null}function m(E){return{id:E.id||`att-${E.path||E.name||Math.random().toString(36).slice(2)}`,type:"file",path:E.path||"",name:E.name||E.path?.split("/").pop()||"attachment",mimeType:E.mimeType||E.mediaType||"application/octet-stream",width:E.width,height:E.height,description:E.description}}function y(E){if(E){if(Array.isArray(E))return E.length>0?E.map(m):void 0;try{const U=JSON.parse(E);return Array.isArray(U)&&U.length>0?U.map(m):void 0}catch(U){console.error("Failed to parse attachments:",U);return}}}function x(E,U){const Z=[];E.reasoning_content&&Z.push({id:`${E.id}-reasoning`,type:"reasoning",content:E.reasoning_content,created_at:E.created_at}),E.content&&Z.push({id:`${E.id}-content`,type:"content",content:E.content,created_at:E.created_at});const se=E.workItems.filter(I=>I.type==="tool_call"),j=E.workItems.filter(I=>I.type==="tool_result"),M=new Map;for(const I of j)I.tool_call_id&&M.set(I.tool_call_id,I);for(const I of se){const le=I.tool_call_id||I.id,O=M.get(le);let W="pending";if(O){const ce=(O.content||"").toLowerCase(),z=ce.includes("failed")||ce.includes("error"),N=ce.length<500;W=O.status==="error"||z&&N?"failed":"success"}Z.push({id:I.id,type:"tool_call",content:I.name||"",created_at:E.created_at,tool_name:I.name,tool_call_id:le,tool_arguments:I.content||void 0,response:O?.content||null,response_status:W,response_log_id:null,log_id:null})}const w=Z.some(I=>I.type==="tool_call"&&I.response_status==="pending"),R=E.status!=="pending"&&!w;return{type:"work",id:E.id,role:"assistant",items:Z,created_at:E.created_at,updated_at:E.created_at,isComplete:R,sideLabel:b("assistant"),status:E.status}}const k=J(()=>{const E=[],Z=r.value.filter(j=>(j.depth??0)===0);let se=[];for(let j=0;j<Z.length;j++){const M=Z[j];if(E[E.length-1]?.role,M.type==="workblock"){const R=x(M);E.push(R);const I=M;I.attachments&&I.attachments.length>0&&se.push(...I.attachments.map(m))}else{const R=M,I=R.role;if(R.role==="tool")continue;const le=y(R.attachments);let O;if((se.length>0||le)&&(O=[...se,...le||[]],se=[]),R.content||I==="system"||R.status==="pending"||O?.length){const W={type:"text",id:R.id,role:I,content:R.content||"",attachments:O?.length?O:void 0,created_at:R.created_at,log_id:R.log_id||null,sideLabel:b(I),isOptimistic:R.isOptimistic,status:R.status,silent:R.silent};E.push(W)}}}return E});async function D(){if(!t.value){s.value=null;return}try{const E=await fetch(ue(`/api/threads/${t.value}`));E.ok&&(s.value=await E.json())}catch(E){console.error("Error fetching thread info:",E)}}async function q(E){if(t.value){if(u?.deleteMessage){await u.deleteMessage(E);return}try{if(!(await fetch(ue(`/api/threads/${t.value}/messages/${E}`),{method:"DELETE"})).ok)throw new Error("Failed to delete message")}catch(U){throw U}}}async function B(E,U){if(t.value)try{if(!(await fetch(ue(`/api/threads/${t.value}/messages/${E}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:U})})).ok)throw new Error("Failed to update message")}catch(Z){throw Z}}fe(t,async E=>{E?(i.value=!0,await D(),i.value=!1):s.value=null},{immediate:!0});const F=u?.sendMessage,T=u?.stopExecution,$=u?.attachments??v([]),K=u?.addAttachment??(()=>{}),oe=u?.removeAttachment??(()=>{}),te=u?.clearAttachments??(()=>{});function H(){console.warn("loadMoreMessages is deprecated - SDK handles all messages")}function P(){console.warn("connectWebSocket is deprecated - SDK handles WebSocket")}function C(){console.warn("disconnectWebSocket is deprecated - SDK handles WebSocket")}function L(){console.warn("addOptimisticMessage is deprecated - SDK handles optimistic updates")}function G(){console.warn("removeOptimisticMessage is deprecated - SDK handles optimistic updates")}async function ee(){console.warn("refetch is deprecated - SDK handles message loading")}return{messages:k,threadInfo:s,isFetching:i,isLoadingMore:_,error:l,wsConnected:f,wsError:g,isExecuting:d,hasMore:p,totalMessages:h,sendMessage:F,stopThread:T,attachments:$,addAttachment:K,removeAttachment:oe,clearAttachments:te,deleteMessageById:q,updateMessageContent:B,refetch:ee,loadMoreMessages:H,connectWebSocket:P,disconnectWebSocket:C,addOptimisticMessage:L,removeOptimisticMessage:G}}const Ui={key:0,class:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800"},Ri={key:1,class:"absolute inset-0 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 text-neutral-400"},Ni=["src","alt"],Fi={class:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center"},Bi={key:0,class:"text-white text-[10px]"},qi={class:"text-xs text-neutral-600 dark:text-neutral-300 truncate max-w-[100px]"},zi=me({__name:"FileAttachment",props:{attachment:{},threadId:{},showRemove:{type:Boolean}},emits:["remove"],setup(t,{emit:n}){const s=t,i=n,l=v(!0),u=v(!1),r=J(()=>s.attachment.mimeType.startsWith("image/")),c=J(()=>!!s.attachment.thumbnailBase64),f=J(()=>{if(!s.threadId||!s.attachment.path)return"";const b=s.attachment.path.startsWith("/")?s.attachment.path.slice(1):s.attachment.path;return ue(`/api/threads/${s.threadId}/fs/${b}`)}),g=J(()=>r.value?s.attachment.thumbnailBase64?`data:image/webp;base64,${s.attachment.thumbnailBase64}`:f.value:"");function d(){l.value=!1,u.value=!1}function p(){l.value=!1,u.value=!0}function h(){i("remove",s.attachment.id)}function _(){f.value&&window.open(f.value,"_blank")}return(b,m)=>(a(),o("div",{class:ae(["relative group inline-flex items-center rounded-lg overflow-hidden border border-neutral-200 dark:border-neutral-700",{"w-[104px] h-[104px]":r.value,"px-2 py-1 bg-neutral-100 dark:bg-neutral-800":!r.value,"cursor-pointer":r.value&&f.value}]),onClick:m[0]||(m[0]=y=>r.value&&f.value?_():void 0)},[r.value?(a(),o(ve,{key:0},[l.value&&!u.value&&!c.value?(a(),o("div",Ui,[...m[1]||(m[1]=[e("div",{class:"w-4 h-4 border-2 border-neutral-300 border-t-neutral-600 rounded-full animate-spin"},null,-1)])])):V("",!0),u.value&&!c.value?(a(),o("div",Ri,[A(X(Zt),{size:24})])):V("",!0),Ie(e("img",{src:g.value||f.value,alt:t.attachment.name,class:"w-full h-full object-cover",onLoad:d,onError:p},null,40,Ni),[[Ke,!l.value&&!u.value||c.value]]),e("div",Fi,[f.value?(a(),o("span",Bi,"Click to view")):V("",!0)])],64)):(a(),o(ve,{key:1},[A(X(ea),{size:14,class:"text-neutral-500 mr-1 flex-shrink-0"}),e("span",qi,S(t.attachment.name),1)],64)),t.showRemove?(a(),o("button",{key:2,onClick:Ee(h,["stop"]),class:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-red-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity"},[A(X(ft),{size:10})])):V("",!0)],2))}}),Hi=["onMouseenter","onMouseleave","onClick"],Wi=["onClick"],Ji={key:0,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"3",stroke:"currentColor",class:"w-3 h-3 text-white"},Ki={key:1,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2.5",stroke:"currentColor",class:"w-3 h-3 text-white"},Gi={key:0,class:"w-full text-center text-xs text-neutral-400 dark:text-neutral-500 py-1"},Xi=["contenteditable","onInput"],Yi={key:1,class:"flex gap-1 items-center min-h-[1.5rem]"},Qi={key:0,class:"opacity-50"},Zi={key:1,class:"opacity-50 italic text-neutral-500 dark:text-neutral-400"},ed={key:0,class:"flex flex-wrap gap-2"},td=["onClick","onMouseenter"],ad={key:0,class:"space-y-1"},od={class:"flex items-start gap-2"},ld={class:"flex-1 min-w-0"},sd={key:0,class:"truncate opacity-80"},nd={key:1,class:"italic opacity-60"},rd={class:"flex items-center gap-2 pl-5 opacity-60"},id={class:"text-[10px]"},dd={class:"text-[10px]"},ud={key:1,class:"space-y-2"},cd={class:"flex items-center gap-2 pb-1 border-b border-current opacity-70"},pd={class:"text-[10px] italic"},md={class:"text-[10px] ml-auto"},vd={key:0,class:"space-y-1"},fd=["onClick","onMouseenter"],hd={class:"font-mono text-[11px] flex-shrink-0"},gd={key:2,class:"text-[10px] opacity-60 px-2 truncate flex-1 min-w-0"},bd={key:3,class:"text-[10px] text-green-600 dark:text-green-400 ml-auto flex-shrink-0"},xd={key:0,class:"pl-4 space-y-2 text-[10px]"},yd={key:0},kd={class:"w-full border-collapse"},wd={class:"py-0.5 pr-2 opacity-65 align-top"},_d={class:"py-0.5 opacity-85 break-all"},$d={key:1},Cd=["onClick","onMouseenter"],Td={class:"whitespace-pre-wrap break-all"},Sd={key:1,class:"text-[10px]"},Vd=["onClick"],Md={key:0,class:"mt-1 pl-4 whitespace-pre-wrap break-words opacity-80"},Id={key:2,class:"text-[10px] opacity-80 pl-4 pb-2 break-words"},Ed=me({__name:"AgentMessages",props:{messages:{},threadId:{},selectedMessageId:{},selectedLogId:{},hoveredLogId:{},isEditMode:{type:Boolean},selectedForDelete:{},editedMessages:{}},emits:["messageClick","messageHover","selectionChange","messageEdit"],setup(t,{expose:n,emit:s}){const i=t,l=s;function u(j){const M=i.selectedForDelete?.has(j)??!1;l("selectionChange",j,!M)}function r(j,M){const R=j.target.innerText;l("messageEdit",M,R)}function c(j){return i.editedMessages?.has(j)??!1}const f=v(new Map);function g(j,M){M?f.value.set(j,M):f.value.delete(j)}function d(j){const M=i.messages.findIndex(w=>w.log_id===j);if(M<=0)return-1;for(let w=M-1;w>=0;w--){const R=i.messages[w];if(R.role==="user")return w;if(R.role==="assistant"&&R.log_id)break}return-1}function p(j){for(let M=0;M<i.messages.length;M++){const w=i.messages[M];if(w.log_id===j||w.type==="work"&&w.items&&w.items.some(le=>le.log_id===j||le.response_log_id===j))return M}return-1}function h(j,M){const R=p(j);if(R===-1)return!1;const I=f.value.get(R);if(!I)return!1;const le=i.messages[R];let O=null;if(le.role==="assistant"&&le.log_id){const z=d(le.log_id);O=z!==-1?f.value.get(z):null}const W=M.getBoundingClientRect(),ce=I.getBoundingClientRect();if(ce.top<W.top){const Q=(O||I).getBoundingClientRect().top-W.top-10;M.scrollBy({top:Q,behavior:"smooth"})}else if(ce.bottom>W.bottom){const z=ce.bottom-W.bottom+10;M.scrollBy({top:z,behavior:"smooth"})}else if(O){const z=O.getBoundingClientRect();if(z.top<W.top){const N=z.top-W.top-10;M.scrollBy({top:N,behavior:"smooth"})}}return!0}function _(j){for(const M of i.messages){if(M.type!=="work")continue;if(M.items.some(I=>I.log_id===j||I.response_log_id===j))return!0}return!1}n({scrollToLogId:h,hasWorkblockForLogId:_});function b(j){const M=i.messages[j];if(M.log_id)return M.log_id;if(M.role==="user")for(let w=j+1;w<i.messages.length;w++){const R=i.messages[w];if(R.log_id)return R.log_id;if(R.role==="user")break}return null}function m(j,M){return M?b(j)===M:!1}function y(j){const M=b(j);M&&l("messageHover",M)}function x(j){b(j)&&l("messageHover",null)}function k(j){const M=i.messages[j],w=b(j);w&&l("messageClick",M.id,w)}const D=v(new Set),q=v(new Set),B=v(new Set);function F(j){D.value.has(j)?D.value.delete(j):D.value.add(j)}function T(j){q.value.has(j)?q.value.delete(j):q.value.add(j)}function $(j){B.value.has(j)?B.value.delete(j):B.value.add(j)}function K(j){if(!j)return{};try{return JSON.parse(j)}catch{return{raw:j}}}function oe(j){if(!j)return null;const M=K(j),w=Object.keys(M);if(w.length===0)return null;const R=M[w[0]];return typeof R=="string"?R:JSON.stringify(R)}function te(j){return new Date(j/1e3).toLocaleTimeString()}function H(j){const M=Math.round(j/1e6);if(M<1)return"< 1s";if(M<60)return`${M}s`;const w=Math.floor(M/60),R=M%60;return`${w}m ${R}s`}function P(j){if(j.status==="pending")return"...";if(!j.isComplete)return"Working...";let M;return j.request_sent_at&&j.response_completed_at?M=j.response_completed_at-j.request_sent_at:M=j.updated_at-j.created_at,`Worked for ${H(M)}`}function C(j){const M=j.filter(w=>w.type==="content");if(M.length===0){const w=j.filter(R=>R.type==="reasoning");return w.length>0?w[w.length-1].content:null}return M[M.length-1].content}function L(j){const w=j.trim().split(`
2
+ `)[0];return w.length>60?w.substring(0,60):w}function G(j){return i.selectedMessageId===j.id?!0:i.selectedLogId?j.items.some(M=>M.log_id===i.selectedLogId||M.response_log_id===i.selectedLogId):!1}function ee(j){return!!(i.selectedLogId&&(j.log_id===i.selectedLogId||j.response_log_id===i.selectedLogId))}function E(j){return i.hoveredLogId?j.items.some(M=>M.log_id===i.hoveredLogId||M.response_log_id===i.hoveredLogId):!1}function U(j){return!!(i.hoveredLogId&&(j.log_id===i.hoveredLogId||j.response_log_id===i.hoveredLogId))}function Z(j){const M=[];for(const w of j.items)w.log_id&&M.push(w.log_id),w.response_log_id&&M.push(w.response_log_id);return M}function se(j){return j?j.trim():""}return(j,M)=>(a(),o("div",null,[(a(!0),o(ve,null,ke(t.messages,(w,R)=>(a(),o("div",{key:w.id,ref_for:!0,ref:I=>g(R,I),class:"flex items-center gap-2 pb-3",onMouseenter:I=>y(R),onMouseleave:I=>x(R),onClick:I=>t.isEditMode?u(w.id):k(R)},[t.isEditMode&&w.role!=="system"?(a(),o("button",{key:0,onClick:Ee(I=>u(w.id),["stop"]),class:ae(["flex-shrink-0 w-6 h-6 rounded-full border-2 flex items-center justify-center transition-all",{"border-red-500 bg-red-500":t.selectedForDelete?.has(w.id),"border-green-500 bg-green-500":!t.selectedForDelete?.has(w.id)&&c(w.id),"border-neutral-400 dark:border-neutral-500 bg-transparent hover:border-neutral-500 dark:hover:border-neutral-400":!t.selectedForDelete?.has(w.id)&&!c(w.id)}])},[t.selectedForDelete?.has(w.id)?(a(),o("svg",Ji,[...M[4]||(M[4]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M4.5 12.75l6 6 9-13.5"},null,-1)])])):c(w.id)?(a(),o("svg",Ki,[...M[5]||(M[5]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L6.832 19.82a4.5 4.5 0 0 1-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 0 1 1.13-1.897L16.863 4.487Zm0 0L19.5 7.125"},null,-1)])])):V("",!0)],10,Wi)):V("",!0),e("div",{class:ae(["flex-1 flex items-center gap-2 min-w-0",{"justify-start":w.role==="assistant","justify-end":w.role==="user","justify-center":w.role==="system","cursor-pointer":b(R)&&!t.isEditMode}])},[w.type==="text"&&w.role==="system"&&w.content?.includes("Execution stopped")?(a(),o("div",Gi,S(w.content),1)):w.type==="text"?(a(),o("div",{key:1,class:ae(["max-w-[80%] flex flex-col gap-2",{"items-start":w.role==="assistant","items-end":w.role==="user"}])},[e("div",{class:ae(["rounded-2xl px-4 py-2 text-sm transition-all min-h-[2.5rem]",[w.silent?"bg-neutral-300 text-neutral-500 dark:bg-neutral-700 dark:text-neutral-400 opacity-70 border-2 border-dashed border-neutral-400 dark:border-neutral-500":!t.isEditMode&&w.role!=="user"&&m(R,t.selectedLogId)?"bg-accent-200 text-accent-950 dark:bg-accent-200 dark:text-accent-950 ring-2 ring-accent-400 dark:ring-accent-400":w.role==="assistant"?"bg-neutral-800 text-white dark:bg-neutral-300 dark:text-black":w.role==="user"?"bg-neutral-200 text-black dark:bg-neutral-800 dark:text-white":"bg-neutral-100 text-neutral-600 dark:bg-neutral-900 dark:text-neutral-400 text-xs",{"opacity-60":w.isOptimistic},{"ring-2 ring-accent-400 dark:ring-accent-400 !bg-accent-200 !text-accent-950 dark:!bg-accent-200 dark:!text-accent-950":!t.isEditMode&&w.role!=="user"&&b(R)&&!w.silent&&!m(R,t.selectedLogId)&&m(R,t.hoveredLogId)},{"ring-2 ring-green-500 dark:ring-green-400":t.isEditMode&&c(w.id),"border border-dashed border-neutral-400 dark:border-neutral-500":t.isEditMode&&w.role!=="system"&&!c(w.id)}]])},[w.content||t.isEditMode?(a(),o("div",{key:0,class:"whitespace-pre-wrap break-words text-sm outline-none",contenteditable:t.isEditMode&&w.role!=="system",onInput:I=>r(I,w.id),onClick:M[0]||(M[0]=I=>t.isEditMode&&I.stopPropagation())},S(se(w.content)),41,Xi)):w.status==="pending"?(a(),o("div",Yi,[...M[6]||(M[6]=[e("span",{class:"typing-dot",style:{"animation-delay":"0ms"}},null,-1),e("span",{class:"typing-dot",style:{"animation-delay":"150ms"}},null,-1),e("span",{class:"typing-dot",style:{"animation-delay":"300ms"}},null,-1)])])):V("",!0),w.status!=="pending"?(a(),o("div",{key:2,class:ae(["text-[10px] mt-1 opacity-50 flex gap-2",{"justify-start":w.role==="assistant","justify-end":w.role!=="assistant"}])},[w.sideLabel?(a(),o("span",Qi,S(w.sideLabel),1)):V("",!0),e("span",null,S(te(w.created_at)),1),w.silent?(a(),o("span",Zi," silent ")):V("",!0)],2)):V("",!0)],2),w.attachments?.length&&t.threadId?(a(),o("div",ed,[(a(!0),o(ve,null,ke(w.attachments,I=>(a(),ne(zi,{key:I.id,attachment:I,threadId:t.threadId},null,8,["attachment","threadId"]))),128))])):V("",!0)],2)):w.type==="work"?(a(),o("div",{key:2,class:ae(["w-full rounded-lg px-3 py-2 text-xs transition-all border overflow-hidden",{"cursor-pointer":!t.isEditMode,"bg-neutral-50 text-neutral-700 border-neutral-200 dark:bg-neutral-900 dark:text-neutral-300 dark:border-neutral-700":w.role==="assistant"&&!w.silent,"bg-accent-50 text-accent-700 border-accent-200 dark:bg-accent-50 dark:text-accent-700 dark:border-accent-200":w.role==="user"&&!w.silent,"bg-neutral-200 text-neutral-500 border-neutral-400 dark:bg-neutral-800 dark:text-neutral-400 dark:border-neutral-600 opacity-70 border-dashed":w.silent,"ring-2 ring-accent-500":!t.isEditMode&&G(w),"ring-2 ring-accent-400":!t.isEditMode&&!G(w)&&E(w)}]),onClick:I=>!t.isEditMode&&(F(w.id),Z(w)[0]&&l("messageClick",w.id,Z(w)[0])),onMouseenter:I=>!t.isEditMode&&Z(w)[0]&&l("messageHover",Z(w)[0]),onMouseleave:M[3]||(M[3]=I=>!t.isEditMode&&l("messageHover",null))},[D.value.has(w.id)?(a(),o("div",ud,[e("div",cd,[A(X(nt),{size:14,class:"flex-shrink-0"}),e("span",pd,S(P(w)),1),e("span",md,S(w.items.length)+" operation"+S(w.items.length!==1?"s":""),1)]),(a(!0),o(ve,null,ke(w.items,I=>(a(),o("div",{key:I.id,class:"mb-1"},[I.type==="tool_call"?(a(),o("div",vd,[e("div",{onClick:Ee(le=>{T(I.id),I.log_id&&l("messageClick",w.id,I.log_id)},["stop"]),onMouseenter:Ee(le=>I.log_id&&l("messageHover",I.log_id),["stop"]),onMouseleave:M[1]||(M[1]=Ee(le=>l("messageHover",null),["stop"])),class:ae(["flex items-center gap-2 cursor-pointer hover:opacity-70 transition-opacity min-w-0",{"ring-1 ring-accent-500":ee(I),"ring-1 ring-accent-400":!ee(I)&&U(I)}])},[q.value.has(I.id)?(a(),ne(X(nt),{key:1,size:12,class:"flex-shrink-0 opacity-50"})):(a(),ne(X(mt),{key:0,size:12,class:"flex-shrink-0 opacity-50"})),e("span",hd,S(I.tool_name),1),oe(I.tool_arguments)?(a(),o("span",gd,S(oe(I.tool_arguments)),1)):V("",!0),I.response_status==="success"?(a(),o("span",bd,"✓")):I.response_status==="failed"?(a(),ne(X(Fa),{key:4,size:12,class:"ml-auto text-red-600 dark:text-red-400"})):V("",!0)],42,fd),q.value.has(I.id)?(a(),o("div",xd,[I.tool_arguments?(a(),o("div",yd,[M[7]||(M[7]=e("div",{class:"font-semibold mb-1 opacity-70"},"Arguments:",-1)),e("table",kd,[e("tbody",null,[(a(!0),o(ve,null,ke(K(I.tool_arguments),(le,O)=>(a(),o("tr",{key:O,class:"border-b border-current border-opacity-10"},[e("td",wd,S(O),1),e("td",_d,S(typeof le=="object"?JSON.stringify(le):le),1)]))),128))])])])):V("",!0),I.response?(a(),o("div",$d,[M[8]||(M[8]=e("div",{class:"font-semibold mb-1 opacity-70"},"Response:",-1)),e("div",{class:ae(["opacity-80 cursor-pointer hover:opacity-100",{"ring-1 ring-accent-500":t.selectedLogId&&I.response_log_id===t.selectedLogId,"ring-1 ring-accent-400":t.hoveredLogId&&I.response_log_id===t.hoveredLogId&&I.response_log_id!==t.selectedLogId}]),onClick:Ee(le=>I.response_log_id&&l("messageClick",w.id,I.response_log_id),["stop"]),onMouseenter:Ee(le=>I.response_log_id&&l("messageHover",I.response_log_id),["stop"]),onMouseleave:M[2]||(M[2]=Ee(le=>l("messageHover",null),["stop"]))},[e("div",Td,S(se(I.response)),1)],42,Cd)])):V("",!0)])):V("",!0)])):I.type==="reasoning"?(a(),o("div",Sd,[e("button",{onClick:Ee(le=>$(I.id),["stop"]),class:"flex items-center gap-1 opacity-70 hover:opacity-100 transition-opacity"},[B.value.has(I.id)?(a(),ne(X(nt),{key:1,size:12,class:"flex-shrink-0"})):(a(),ne(X(mt),{key:0,size:12,class:"flex-shrink-0"})),M[9]||(M[9]=e("span",{class:"font-semibold"},"Reasoning",-1))],8,Vd),B.value.has(I.id)?(a(),o("div",Md,S(se(I.content)),1)):V("",!0)])):I.type==="content"?(a(),o("div",Id,S(se(I.content)),1)):V("",!0)]))),128))])):(a(),o("div",ad,[e("div",od,[A(X(mt),{size:14,class:"flex-shrink-0 mt-0.5 opacity-50"}),e("div",ld,[C(w.items)?(a(),o("div",sd,S(L(C(w.items)))+"... ",1)):(a(),o("div",nd,S(P(w)),1))])]),e("div",rd,[e("span",id,S(w.items.length)+" operation"+S(w.items.length!==1?"s":""),1),e("span",dd,"• "+S(P(w)),1)])]))],42,td)):V("",!0)],2)],40,Hi))),128))]))}}),Ld=tt(Ed,[["__scopeId","data-v-884a0fa7"]]),Ad={key:0,class:"overflow-hidden border-b border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900"},Pd={class:"max-h-[400px] overflow-y-auto"},Dd={class:"flex items-center justify-between px-4 py-2 border-b border-neutral-200 dark:border-neutral-800 sticky top-0 bg-neutral-50 dark:bg-neutral-900"},jd={class:"p-4"},Od={key:0,class:"flex justify-center py-4"},Ud={key:1,class:"text-red-600 dark:text-red-400 text-center py-4 text-sm"},Rd={key:2,class:"space-y-3 text-sm"},Nd={class:"flex items-start gap-2"},Fd={class:"font-mono text-xs break-all"},Bd={class:"flex items-start gap-2"},qd={class:"flex-1"},zd={key:0,class:"flex items-center gap-2"},Hd={class:"text-xs text-neutral-500"},Wd={key:1,class:"space-y-2"},Jd={class:"flex gap-2"},Kd=["disabled"],Gd=["disabled"],Xd={class:"flex items-start gap-2"},Yd={key:0,class:"flex items-start gap-2"},Qd={class:"font-mono text-xs"},Zd={class:"flex items-start gap-2"},eu={class:"flex-1 flex items-center gap-2 flex-wrap"},tu={key:1,class:"text-neutral-500 dark:text-neutral-500 italic text-xs"},au={class:"flex items-start gap-2"},ou=["disabled"],lu={key:1,class:"flex justify-center py-2"},su={key:1,class:"p-3 rounded border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800 space-y-2"},nu={class:"flex items-center gap-4 text-xs"},ru={class:"font-mono font-bold ml-1"},iu={class:"font-mono font-bold ml-1"},du={key:0,class:"text-xs"},uu={class:"w-full"},cu={class:"py-1"},pu={class:"text-right py-1 font-mono"},mu={class:"text-right py-1 font-mono"},vu={class:"flex items-start gap-2"},fu={class:"flex items-center gap-2"},hu=["disabled"],gu={key:0},bu={key:1},xu={class:"pt-2 border-t border-neutral-200 dark:border-neutral-800 flex justify-end"},yu=["disabled"],ku={key:0},wu={key:1},_u=me({__name:"MetadataSlidePane",props:{threadId:{},show:{type:Boolean}},emits:["close","threadDeleted","editThread"],setup(t,{emit:n}){const s=t,i=n,{thread:l,isFetching:u,error:r}=St(J(()=>s.threadId)),c=v(!1),f=v(!1),g=v(!1),d=v(!1),p=v(""),h=v(!1),_=v(!1),b=v(!1),m=v("a"),y=v(null),{data:x,isFetching:k}=Ue(ue("/api/agents"),{refetch:!0}).json(),D=J(()=>x.value?.agents?x.value.agents.filter(C=>C.type==="ai_human").map(C=>({value:C.id,label:C.title,description:`Type: ${C.type}`})):[]),q=J(()=>l.value?.agent.type==="ai_human"),B=C=>new Date(C*1e3).toLocaleString(),F=()=>{l.value&&(p.value=l.value.agent.id,g.value=!0)},T=()=>{g.value=!1,p.value=""},$=async()=>{if(!(!s.threadId||!p.value)){d.value=!0;try{const C=await fetch(ue(`/api/threads/${s.threadId}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({agent_id:p.value})});if(!C.ok){const L=await C.json();throw new Error(L.error||"Failed to update agent")}window.location.reload()}catch(C){console.error("Error updating agent:",C),alert(`Failed to update agent: ${C.message}`)}finally{d.value=!1}}},K=async()=>{if(s.threadId){_.value=!0,h.value=!0;try{const C=await fetch(ue(`/api/threads/${s.threadId}/cost`));if(!C.ok){const L=await C.json();throw new Error(L.error||"Failed to fetch cost breakdown")}y.value=await C.json()}catch(C){console.error("Error fetching cost breakdown:",C),alert(`Failed to fetch cost breakdown: ${C.message}`),h.value=!1}finally{_.value=!1}}},oe=C=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:4,maximumFractionDigits:6}).format(C),te=J(()=>l.value?.agent.type==="dual_ai"),H=async()=>{if(s.threadId){b.value=!0;try{const C=await fetch(ue(`/api/threads/${s.threadId}/continue`),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({side:m.value})});if(!C.ok){const L=await C.json();throw new Error(L.error||"Failed to continue execution")}}catch(C){console.error("Error continuing execution:",C),alert(`Failed to continue execution: ${C.message}`)}finally{b.value=!1}}},P=async()=>{if(s.threadId){f.value=!0;try{const C=await fetch(ue(`/api/threads/${s.threadId}`),{method:"DELETE"});if(!C.ok){const L=await C.json();throw new Error(L.error||"Failed to delete thread")}i("threadDeleted",s.threadId)}catch(C){console.error("Error deleting thread:",C),alert(`Failed to delete thread: ${C.message}`)}finally{f.value=!1}}};return fe(()=>s.show,C=>{C||(g.value=!1,p.value="")}),fe(()=>s.threadId,()=>{g.value=!1,p.value="",h.value=!1,y.value=null}),(C,L)=>(a(),ne(Xe,{"enter-active-class":"transition-all duration-300 ease-out","enter-from-class":"max-h-0 opacity-0","enter-to-class":"max-h-[400px] opacity-100","leave-active-class":"transition-all duration-200 ease-in","leave-from-class":"max-h-[400px] opacity-100","leave-to-class":"max-h-0 opacity-0"},{default:be(()=>[t.show&&t.threadId?(a(),o("div",Ad,[e("div",Pd,[e("div",Dd,[L[7]||(L[7]=e("span",{class:"text-sm font-medium text-neutral-600 dark:text-neutral-400"},"Thread Info",-1)),e("button",{onClick:L[0]||(L[0]=G=>i("close")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Close metadata"},[A(X(ta),{size:16})])]),e("div",jd,[X(u)?(a(),o("div",Od,[A(Se)])):X(r)?(a(),o("div",Ud," Error loading metadata: "+S(X(r)),1)):X(l)?(a(),o("div",Rd,[e("div",Nd,[L[8]||(L[8]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"ID",-1)),e("span",Fd,S(X(l).id),1)]),e("div",Bd,[L[9]||(L[9]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Agent",-1)),e("div",qd,[g.value?(a(),o("div",Wd,[A(Ve,{modelValue:p.value,"onUpdate:modelValue":L[1]||(L[1]=G=>p.value=G),options:D.value,loading:X(k),placeholder:"Select an agent"},null,8,["modelValue","options","loading"]),e("div",Jd,[e("button",{onClick:$,disabled:d.value||!p.value,class:"px-2 py-1 text-xs bg-black dark:bg-white text-white dark:text-black hover:bg-black/80 dark:hover:bg-white/80 transition-colors disabled:opacity-50 disabled:cursor-not-allowed rounded"},S(d.value?"Saving...":"Save"),9,Kd),e("button",{onClick:T,disabled:d.value,class:"px-2 py-1 text-xs border border-black dark:border-neutral-300 hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed rounded"}," Cancel ",8,Gd)])])):(a(),o("div",zd,[e("span",null,S(X(l).agent.title),1),e("span",Hd,"("+S(X(l).agent.type)+")",1),q.value?(a(),o("button",{key:0,onClick:F,type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Change agent"},[A(X(kt),{size:12})])):V("",!0)]))])]),e("div",Xd,[L[10]||(L[10]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Created",-1)),e("span",null,S(B(X(l).created_at)),1)]),X(l).user_id?(a(),o("div",Yd,[L[11]||(L[11]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"User",-1)),e("span",Qd,S(X(l).user_id),1)])):V("",!0),e("div",Zd,[L[12]||(L[12]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 flex-shrink-0 text-left"},"Tags",-1)),e("div",eu,[X(l).tags?.length>0?(a(!0),o(ve,{key:0},ke(X(l).tags,G=>(a(),o("span",{key:G,class:"inline-block px-2 py-0.5 text-xs rounded bg-black text-white dark:bg-white dark:text-black"},S(G),1))),128)):(a(),o("span",tu,"No tags")),e("button",{onClick:L[2]||(L[2]=G=>i("editThread")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Edit tags"},[A(X(kt),{size:12})])])]),e("div",au,[L[15]||(L[15]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 shrink-0 text-left"},"Cost",-1)),!h.value&&!_.value?(a(),o("button",{key:0,onClick:K,disabled:_.value,type:"button",class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[A(X(At),{size:12}),L[13]||(L[13]=e("span",null,"View Costs",-1))],8,ou)):V("",!0),_.value?(a(),o("div",lu,[A(Se)])):V("",!0),h.value?(a(),o("button",{key:2,onClick:L[3]||(L[3]=G=>h.value=!1),type:"button",class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors"},[A(X(At),{size:12}),L[14]||(L[14]=e("span",null,"Hide Costs",-1))])):V("",!0)]),h.value&&y.value?(a(),o("div",su,[e("div",nu,[e("div",null,[L[16]||(L[16]=e("span",{class:"text-neutral-500"},"Total:",-1)),e("span",ru,S(oe(y.value.totalCost)),1)]),e("div",null,[L[17]||(L[17]=e("span",{class:"text-neutral-500"},"Avg/msg:",-1)),e("span",iu,S(oe(y.value.avgCostPerMessage)),1)])]),y.value.modelBreakdown.length>0?(a(),o("div",du,[e("table",uu,[L[18]||(L[18]=e("thead",null,[e("tr",{class:"border-b border-neutral-300 dark:border-neutral-600"},[e("th",{class:"text-left py-1 font-medium text-neutral-500"}," Model "),e("th",{class:"text-right py-1 font-medium text-neutral-500"}," Reqs "),e("th",{class:"text-right py-1 font-medium text-neutral-500"}," Cost ")])],-1)),e("tbody",null,[(a(!0),o(ve,null,ke(y.value.modelBreakdown,G=>(a(),o("tr",{key:G.modelName},[e("td",cu,S(G.modelName),1),e("td",pu,S(G.requestCount),1),e("td",mu,S(oe(G.totalCost)),1)]))),128))])])])):V("",!0)])):V("",!0),e("div",vu,[L[20]||(L[20]=e("span",{class:"font-medium text-neutral-600 dark:text-neutral-400 w-14 shrink-0 text-left"},"Debug",-1)),e("div",fu,[te.value?Ie((a(),o("select",{key:0,"onUpdate:modelValue":L[4]||(L[4]=G=>m.value=G),class:"text-xs px-1 py-0.5 border border-neutral-300 dark:border-neutral-600 rounded bg-white dark:bg-neutral-800"},[...L[19]||(L[19]=[e("option",{value:"a"},"Side A",-1),e("option",{value:"b"},"Side B",-1)])],512)),[[Ba,m.value]]):V("",!0),e("button",{onClick:H,disabled:b.value,class:"flex items-center gap-1 px-2 py-1 text-xs border border-black dark:border-white rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[A(X(qa),{size:12}),b.value?(a(),o("span",gu,"Running...")):(a(),o("span",bu,"Continue"))],8,hu)])]),e("div",xu,[e("button",{onClick:L[5]||(L[5]=G=>c.value=!0),disabled:f.value,class:"flex items-center gap-1 px-2 py-1 text-xs text-red-600 border border-red-600 rounded hover:bg-red-50 dark:hover:bg-red-950/20 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},[A(X(za),{size:12}),f.value?(a(),o("span",ku,"Deleting...")):(a(),o("span",wu,"Delete Thread"))],8,yu)])])):V("",!0)])]),A(xa,{modelValue:c.value,"onUpdate:modelValue":L[6]||(L[6]=G=>c.value=G),title:"Delete Thread?",message:"Are you sure you want to delete this thread? This will permanently delete all messages, logs, and associated data. This action cannot be undone.","confirm-text":"Delete Thread","cancel-text":"Cancel",onConfirm:P},null,8,["modelValue"])])):V("",!0)]),_:1}))}}),$u={key:0,class:"overflow-hidden border-b border-neutral-300 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900"},Cu={class:"max-h-[400px] overflow-y-auto"},Tu={class:"flex items-center justify-between px-4 py-2 border-b border-neutral-200 dark:border-neutral-800 sticky top-0 bg-neutral-50 dark:bg-neutral-900"},Su={class:"flex items-center gap-1"},Vu={class:"p-2"},Mu={key:0,class:"px-3 py-6 text-center text-neutral-500 dark:text-neutral-400 text-sm"},Iu=["onClick"],Eu={class:"text-xs truncate"},Lu={class:"text-[10px] text-neutral-400 ml-auto"},Au=["href","onMouseenter"],Pu={class:"shrink-0 text-neutral-500 dark:text-neutral-400"},Du={class:"flex-1 min-w-0"},ju={class:"shrink-0 text-[10px] text-neutral-400 dark:text-neutral-500 ml-auto"},Ou={key:0,class:"text-blue-500"},Uu={key:1,class:"text-red-500"},Ru={key:2},Nu=["href","onMouseenter"],Fu={class:"shrink-0 text-neutral-500 dark:text-neutral-400"},Bu={class:"flex-1 min-w-0"},qu={class:"shrink-0 text-[10px] text-neutral-400 dark:text-neutral-500 ml-auto"},zu={key:0,class:"text-blue-500"},Hu={key:1,class:"text-red-500"},Wu={key:2},Ju={class:"px-4 py-1.5 border-t border-neutral-200 dark:border-neutral-700 text-[10px] text-neutral-400 dark:text-neutral-500"},Ku=["src","alt"],Gu=me({__name:"FilesSlidePane",props:{threadId:{},show:{type:Boolean}},emits:["close"],setup(t,{emit:n}){const s=t,i=n;let l=null;try{l=ca()}catch{}const u=l?.files??v([]),r=l?.addFiles??(()=>{}),c=v(null),f=v(new Set(["/attachments"])),g=v(null),d=v({x:0,y:0});function p(B){if(B===0)return"0 B";const F=1024,T=["B","KB","MB","GB"],$=Math.floor(Math.log(B)/Math.log(F));return parseFloat((B/Math.pow(F,$)).toFixed(1))+" "+T[$]}function h(B){const F=B.startsWith("/")?B.slice(1):B;return ue(`/api/threads/${s.threadId}/fs/${F}`)}function _(B,F){return F?Zt:B.startsWith("audio/")?Ja:B.startsWith("video/")?Ka:B.startsWith("text/")?Ga:B.includes("javascript")||B.includes("json")||B.includes("xml")?Xa:ea}function b(B){const F=B.target;F.files?.length&&(r(F.files),F.value="")}function m(){c.value?.click()}function y(B){f.value.has(B)?f.value.delete(B):f.value.add(B),f.value=new Set(f.value)}function x(B){d.value={x:B.clientX,y:B.clientY}}function k(B){g.value=B}const D=J(()=>{const B=[],F=new Map,T=[...u.value].sort(($,K)=>$.status==="uploading"&&K.status!=="uploading"?-1:K.status==="uploading"&&$.status!=="uploading"?1:($.path||$.name).localeCompare(K.path||K.name));for(const $ of T){const K=$.path||`/${$.name}`,oe=K.split("/").filter(Boolean);if(oe.length===1)B.push({type:"file",name:$.name,path:K,file:$});else{const te="/"+oe.slice(0,-1).join("/"),H=oe[oe.length-2];if(!F.has(te)){const P={type:"directory",name:H,path:te,children:[]};F.set(te,P),B.push(P)}F.get(te).children.push({type:"file",name:$.name,path:K,file:$})}}return B}),q=J(()=>u.value.length);return Me(()=>{document.addEventListener("mousemove",x)}),Be(()=>{document.removeEventListener("mousemove",x)}),(B,F)=>(a(),ne(Xe,{"enter-active-class":"transition-all duration-300 ease-out","enter-from-class":"max-h-0 opacity-0","enter-to-class":"max-h-[400px] opacity-100","leave-active-class":"transition-all duration-200 ease-in","leave-from-class":"max-h-[400px] opacity-100","leave-to-class":"max-h-0 opacity-0"},{default:be(()=>[t.show?(a(),o("div",$u,[e("div",Cu,[e("div",Tu,[F[4]||(F[4]=e("span",{class:"text-sm font-medium text-neutral-600 dark:text-neutral-400"}," Thread Files ",-1)),e("div",Su,[e("input",{ref_key:"fileInput",ref:c,type:"file",multiple:"",class:"hidden",onChange:b},null,544),e("button",{onClick:m,type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300",title:"Upload files"},[A(X(Ha),{size:16})]),e("button",{onClick:F[0]||(F[0]=T=>i("close")),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors",title:"Close files"},[A(X(ta),{size:16})])])]),e("div",Vu,[D.value.length===0?(a(),o("div",Mu," No files yet ")):V("",!0),(a(!0),o(ve,null,ke(D.value,T=>(a(),o(ve,{key:T.path},[T.type==="directory"?(a(),o(ve,{key:0},[e("button",{onClick:$=>y(T.path),type:"button",class:"w-full flex items-center gap-1.5 px-2 py-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors text-left"},[A(X(mt),{size:12,class:ae(["shrink-0 text-neutral-400 transition-transform",{"rotate-90":f.value.has(T.path)}])},null,8,["class"]),(a(),ne(Ze(f.value.has(T.path)?X(Wa):X(aa)),{size:14,class:"shrink-0",style:{color:"var(--accent-500)"}})),e("span",Eu,S(T.name),1),e("span",Lu,S(T.children?.length),1)],8,Iu),f.value.has(T.path)?(a(!0),o(ve,{key:0},ke(T.children,$=>(a(),o("a",{key:$.path,href:$.path?h($.path):void 0,target:"_blank",rel:"noopener noreferrer",class:ae(["flex items-center gap-2 pl-7 pr-2 py-1 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors cursor-pointer",{"pointer-events-none":$.file?.status==="uploading"}]),onMouseenter:K=>$.file?.isImage?k($.path):null,onMouseleave:F[1]||(F[1]=K=>k(null))},[e("div",Pu,[$.file?.status==="uploading"?(a(),ne(X(Pt),{key:0,size:12,class:"animate-spin"})):(a(),ne(Ze(_($.file?.mimeType||"",$.file?.isImage||!1)),{key:1,size:12}))]),e("div",Du,[e("div",{class:ae(["text-[11px] truncate",{"text-neutral-400":$.file?.status==="uploading"}])},S($.name),3)]),e("div",ju,[$.file?.status==="uploading"?(a(),o("span",Ou,"...")):$.file?.status==="error"?(a(),o("span",Uu,"err")):(a(),o("span",Ru,S(p($.file?.size||0)),1))])],42,Au))),128)):V("",!0)],64)):(a(),o("a",{key:1,href:T.path?h(T.path):void 0,target:"_blank",rel:"noopener noreferrer",class:ae(["flex items-center gap-2 px-2 py-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors cursor-pointer",{"pointer-events-none":T.file?.status==="uploading"}]),onMouseenter:$=>T.file?.isImage?k(T.path):null,onMouseleave:F[2]||(F[2]=$=>k(null))},[e("div",Fu,[T.file?.status==="uploading"?(a(),ne(X(Pt),{key:0,size:14,class:"animate-spin"})):(a(),ne(Ze(_(T.file?.mimeType||"",T.file?.isImage||!1)),{key:1,size:14}))]),e("div",Bu,[e("div",{class:ae(["text-xs truncate",{"text-neutral-400":T.file?.status==="uploading"}])},S(T.name),3)]),e("div",qu,[T.file?.status==="uploading"?(a(),o("span",zu,"...")):T.file?.status==="error"?(a(),o("span",Hu,"err")):(a(),o("span",Wu,S(p(T.file?.size||0)),1))])],42,Nu))],64))),128))]),e("div",Ju,S(q.value)+" file"+S(q.value!==1?"s":""),1)]),(a(),ne(it,{to:"body"},[g.value?(a(),o("div",{key:0,class:"fixed z-50 bg-white dark:bg-neutral-800 border border-neutral-300 dark:border-neutral-600 rounded-lg shadow-lg p-1 pointer-events-none",style:ot({left:`${d.value.x+16}px`,top:`${d.value.y-80}px`})},[e("img",{src:h(g.value),alt:g.value,class:"max-w-[200px] max-h-[150px] rounded object-contain",onError:F[3]||(F[3]=T=>T.target.style.display="none")},null,40,Ku)],4)):V("",!0)]))])):V("",!0)]),_:1}))}}),Xu=["accept"],Yu=["disabled"],Qu=me({__name:"FileUpload",props:{isProcessing:{type:Boolean},accept:{}},emits:["filesSelected"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(null),r=J(()=>i.accept||"image/*,.pdf,.txt,.md,.json,.csv");function c(){u.value?.click()}function f(d){const p=d.target;p.files&&p.files.length>0&&(l("filesSelected",p.files),p.value="")}function g(d){const p=d.clipboardData?.items;if(!p)return;const h=[];for(let _=0;_<p.length;_++){const b=p[_];if(b.kind==="file"){const m=b.getAsFile();m&&h.push(m)}}if(h.length>0){const _=new DataTransfer;h.forEach(b=>_.items.add(b)),l("filesSelected",_.files)}}return n({handlePaste:g}),(d,p)=>(a(),o(ve,null,[e("input",{ref_key:"fileInputRef",ref:u,type:"file",accept:r.value,multiple:"",class:"hidden",onChange:f},null,40,Xu),e("button",{type:"button",onClick:c,class:ae(["p-1.5 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded-lg transition-colors text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300",{"opacity-50 cursor-not-allowed":t.isProcessing}]),disabled:t.isProcessing,title:"Attach files"},[A(X(Ya),{size:18})],10,Yu)],64))}}),Zu={class:"flex flex-col h-full"},ec={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},tc={class:"flex items-center justify-between"},ac={class:"flex items-center gap-2"},oc={class:"flex items-center gap-2"},lc={class:"flex-1 flex flex-col overflow-hidden relative"},sc={key:0,class:"text-neutral-500 dark:text-neutral-400 text-center py-8"},nc={key:1,class:"flex justify-center py-2"},rc={key:2,class:"flex justify-center py-8"},ic={key:3,class:"text-red-600 dark:text-red-400 text-center py-8"},dc={key:4,class:"text-neutral-500 dark:text-neutral-400 text-center py-8"},uc={key:1,class:"p-3 bg-white dark:bg-neutral-900 border-t border-neutral-300 dark:border-neutral-700"},cc={class:"flex items-center justify-end gap-2"},pc=["disabled"],mc={key:2,class:"p-3 bg-white dark:bg-neutral-900 border-t border-neutral-300 dark:border-neutral-700"},vc={key:0,class:"mb-2 flex flex-wrap gap-2"},fc={key:0,class:"w-16 h-16 rounded-lg overflow-hidden border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800"},hc=["src","alt"],gc={key:1,class:"w-full h-full flex items-center justify-center"},bc={key:1,class:"h-16 px-3 rounded-lg border border-neutral-200 dark:border-neutral-700 bg-neutral-100 dark:bg-neutral-800 flex items-center gap-2"},xc=["title"],yc=["onClick"],kc={class:"flex items-start gap-2"},wc={class:"flex-1 flex items-start gap-2 p-2 rounded-2xl border border-neutral-300 dark:border-neutral-700 bg-white dark:bg-neutral-900"},_c=["disabled"],$c=["disabled"],Cc={key:0,xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",class:"w-4 h-4"},Tc={key:1,class:"w-4 h-4"},Bt=me({__name:"MessagesPane",props:{threadId:{},selectedMessageId:{},selectedLogId:{},hoveredLogId:{}},emits:["collapse","messageClick","messageHover","threadDeleted","editThread","logsDeleted"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(!1),r=()=>{u.value=!u.value},c=v(!1),f=()=>{c.value=!c.value},g=v(!1),d=v(new Set),p=v(new Map),h=()=>{g.value=!g.value,g.value||(d.value=new Set,p.value=new Map)},_=(xe,he)=>{const $e=new Set(d.value);he?$e.add(xe):$e.delete(xe),d.value=$e},b=(xe,he)=>{const $e=new Map(p.value);$e.set(xe,he),p.value=$e},m=()=>{g.value=!1,d.value=new Set,p.value=new Map},y=J(()=>d.value.size),x=J(()=>{let xe=0;for(const[he]of p.value)d.value.has(he)||xe++;return xe}),k=J(()=>{const xe=y.value,he=x.value;return xe>0&&he>0?`Delete (${xe}), Update (${he})`:xe>0?`Delete (${xe})`:he>0?`Save changes (${he})`:"Delete"}),D=J(()=>y.value>0||x.value>0),q=async()=>{if(!i.threadId||!D.value)return;const xe=[];for(const he of d.value){const $e=B.value.find(Ne=>Ne.id===he);$e&&"log_id"in $e&&$e.log_id&&xe.push($e.log_id)}try{for(const[he,$e]of p.value)d.value.has(he)||await G(he,$e);for(const he of d.value)await L(he);xe.length>0&&l("logsDeleted",xe)}catch(he){console.error("Error applying changes:",he)}finally{m()}},{messages:B,threadInfo:F,isFetching:T,isLoadingMore:$,error:K,wsConnected:oe,wsError:te,isExecuting:H,hasMore:P,loadMoreMessages:C,deleteMessageById:L,updateMessageContent:G,stopThread:ee,sendMessage:E,attachments:U,addAttachment:Z,removeAttachment:se}=Oi(J(()=>i.threadId),{}),{thread:j}=St(J(()=>i.threadId)),M=J(()=>U.value.length>0),w=J(()=>!1),R=v(null),I=xe=>{Z(xe)},le=v(null),O=v(null);n({scrollToLogId:xe=>O.value&&le.value?O.value.scrollToLogId(xe,le.value):!1,hasWorkblockForLogId:xe=>O.value?O.value.hasWorkblockForLogId(xe):!1}),typeof window<"u"&&(window.__testLoadMoreMessages=C);const z=v(""),N=v(null),Q=v("B"),we=v(!1),de=v(!1),pe=async()=>{await Te(),le.value&&(le.value.scrollTop=le.value.scrollHeight)},ie=async xe=>{xe.target.scrollTop<100&&P.value&&!$.value&&!de.value&&(de.value=!0,await C(),de.value=!1)};fe(()=>B.value.length,async()=>{!$.value&&!de.value&&await pe()}),fe(()=>i.threadId,async xe=>{xe&&await pe()}),fe(T,async(xe,he)=>{he&&!xe&&await pe()});const ye=J(()=>{const xe=F.value?.agent||j.value?.agent;if(!xe)return"ai A";const he=xe.type;return Q.value==="A"&&xe.side_a_label?xe.side_a_label:Q.value==="B"&&xe.side_b_label?xe.side_b_label:he==="ai_human"?Q.value==="A"?"ai":"human":Q.value==="A"?"ai A":"ai B"}),_e=()=>{Q.value=Q.value==="A"?"B":"A"},Ae=async()=>{const xe=z.value.trim().length>0,he=M.value;if(!xe&&!he||!i.threadId||we.value||!E)return;const $e=z.value,Ne=Q.value==="A"?"assistant":"user";z.value="",N.value&&(N.value.style.height="auto",N.value.style.height="24px"),we.value=!0;try{await E({role:Ne,content:$e}),await pe()}catch(ht){console.error("Error sending message:",ht)}finally{we.value=!1,await Te(),N.value&&N.value.focus()}},Fe=xe=>{xe.key==="Enter"&&!xe.shiftKey&&(xe.preventDefault(),Ae())},Re=async()=>{if(i.threadId)try{await ee()}catch(xe){console.error("Error stopping thread:",xe)}};return(xe,he)=>(a(),o("div",Zu,[e("div",ec,[e("div",tc,[e("div",ac,[A(X(oa),{size:18,class:"shrink-0"}),he[10]||(he[10]=e("h2",{class:"text-base font-bold"},"Messages",-1)),t.threadId?(a(),ne(Vt,{key:0,connected:X(oe),error:X(te)},null,8,["connected","error"])):V("",!0)]),e("div",oc,[t.threadId?(a(),o("button",{key:0,onClick:f,type:"button",class:ae(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":c.value}]),title:"Toggle files"},[A(X(aa),{size:20})],2)):V("",!0),t.threadId?(a(),o("button",{key:1,onClick:r,type:"button",class:ae(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":u.value}]),title:"Toggle metadata"},[A(X(Qa),{size:20})],2)):V("",!0),t.threadId&&X(B).length>0?(a(),o("button",{key:2,onClick:h,type:"button",class:ae(["p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",{"bg-neutral-200 dark:bg-neutral-800":g.value}]),title:"Edit messages"},[A(X(kt),{size:20})],2)):V("",!0),e("button",{onClick:he[0]||(he[0]=$e=>l("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[A(X(Tt),{size:20})])])])]),e("div",lc,[A(_u,{"thread-id":t.threadId,show:u.value,onClose:he[1]||(he[1]=$e=>u.value=!1),onThreadDeleted:he[2]||(he[2]=$e=>l("threadDeleted",$e)),onEditThread:he[3]||(he[3]=$e=>l("editThread"))},null,8,["thread-id","show"]),t.threadId?(a(),ne(Gu,{key:0,"thread-id":t.threadId,show:c.value,onClose:he[4]||(he[4]=$e=>c.value=!1)},null,8,["thread-id","show"])):V("",!0),e("div",{ref_key:"messagesContainer",ref:le,class:"flex-1 overflow-y-auto overflow-x-hidden p-4 space-y-4",onScroll:ie},[t.threadId?V("",!0):(a(),o("div",sc," Select a thread to view messages ")),X($)?(a(),o("div",nc,[A(Se,{size:"sm"}),he[11]||(he[11]=e("span",{class:"ml-2 text-xs text-neutral-500"},"Loading older messages...",-1))])):X(T)?(a(),o("div",rc,[A(Se)])):X(K)?(a(),o("div",ic," Error loading messages: "+S(X(K)),1)):t.threadId&&X(B).length===0?(a(),o("div",dc," No messages yet ")):(a(),ne(Ld,{key:5,ref_key:"agentMessagesRef",ref:O,messages:X(B),threadId:t.threadId,selectedMessageId:t.selectedMessageId,selectedLogId:t.selectedLogId,hoveredLogId:t.hoveredLogId,isEditMode:g.value,selectedForDelete:d.value,editedMessages:p.value,onMessageClick:he[5]||(he[5]=($e,Ne)=>l("messageClick",$e,Ne)),onMessageHover:he[6]||(he[6]=$e=>l("messageHover",$e)),onSelectionChange:_,onMessageEdit:b},null,8,["messages","threadId","selectedMessageId","selectedLogId","hoveredLogId","isEditMode","selectedForDelete","editedMessages"]))],544),t.threadId&&g.value?(a(),o("div",uc,[e("div",cc,[e("button",{onClick:m,class:"px-4 py-2 rounded-lg font-medium text-sm transition-colors bg-neutral-200 text-black hover:bg-neutral-300 dark:bg-neutral-700 dark:text-white dark:hover:bg-neutral-600"}," Cancel "),e("button",{onClick:q,disabled:!D.value,class:ae(["px-4 py-2 rounded-lg font-medium text-sm transition-colors",{"bg-red-600 text-white hover:bg-red-700":D.value&&y.value>0,"bg-black text-white hover:bg-neutral-800 dark:bg-white dark:text-black dark:hover:bg-neutral-200":D.value&&y.value===0,"bg-neutral-200 text-neutral-400 dark:bg-neutral-700 dark:text-neutral-500 cursor-not-allowed":!D.value}])},S(k.value),11,pc)])])):t.threadId?(a(),o("div",mc,[X(U).length>0?(a(),o("div",vc,[(a(!0),o(ve,null,ke(X(U),$e=>(a(),o("div",{key:$e.id,class:"relative group"},[$e.isImage?(a(),o("div",fc,[$e.previewUrl?(a(),o("img",{key:0,src:$e.previewUrl,alt:$e.name,class:"w-full h-full object-cover"},null,8,hc)):(a(),o("div",gc,[...he[12]||(he[12]=[e("div",{class:"w-4 h-4 border-2 border-neutral-300 border-t-neutral-600 rounded-full animate-spin"},null,-1)])]))])):(a(),o("div",bc,[e("span",{class:"text-xs text-neutral-600 dark:text-neutral-300 max-w-[80px] truncate",title:$e.name},S($e.name),9,xc)])),e("button",{onClick:Ee(Ne=>X(se)($e.id),["stop"]),class:"absolute -top-1 -right-1 w-4 h-4 rounded-full bg-neutral-600 dark:bg-neutral-500 text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500"},[...he[13]||(he[13]=[e("span",{class:"text-[10px] font-bold leading-none"},"x",-1)])],8,yc)]))),128))])):V("",!0),e("div",kc,[e("button",{onClick:_e,class:ae(["flex-shrink-0 px-2 h-7 rounded-md flex items-center justify-center font-medium text-xs transition-colors mt-2.5",{"bg-black text-white dark:bg-white dark:text-black":Q.value==="A","bg-neutral-300 text-black dark:bg-neutral-600 dark:text-white":Q.value==="B"}]),title:"Toggle between sides"},S(ye.value),3),e("div",wc,[A(Qu,{ref_key:"fileUploadRef",ref:R,"is-processing":!1,onFilesSelected:I},null,512),Ie(e("textarea",{ref_key:"messageTextarea",ref:N,"onUpdate:modelValue":he[7]||(he[7]=$e=>z.value=$e),onKeydown:Fe,onPaste:he[8]||(he[8]=$e=>R.value?.handlePaste($e)),disabled:we.value,placeholder:"Type a message...",rows:"1",class:"flex-1 bg-transparent text-black dark:text-white resize-none focus:outline-none disabled:opacity-50 mt-0.5",style:{"max-height":"120px","min-height":"24px"},onInput:he[9]||(he[9]=$e=>{const Ne=$e.target;Ne.style.height="auto",Ne.style.height=Math.min(Ne.scrollHeight,120)+"px"})},null,40,_c),[[Oe,z.value]]),X(H)?(a(),o("button",{key:1,id:"stop-thread-button",onClick:Re,class:"flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center transition-all bg-red-600 text-white dark:bg-red-500 hover:bg-red-700 dark:hover:bg-red-600",title:"Stop execution"},[...he[15]||(he[15]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"2",stroke:"currentColor",class:"w-4 h-4"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M5.25 7.5A2.25 2.25 0 017.5 5.25h9a2.25 2.25 0 012.25 2.25v9a2.25 2.25 0 01-2.25 2.25h-9a2.25 2.25 0 01-2.25-2.25v-9z"})],-1)])])):(a(),o("button",{key:0,id:"send-message-button",onClick:Ae,disabled:!z.value.trim()&&!M.value||we.value||w.value,class:ae(["flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center transition-all",{"bg-black text-white dark:bg-white dark:text-black":(z.value.trim()||M.value)&&!we.value&&!w.value,"bg-neutral-200 text-neutral-400 dark:bg-neutral-700 dark:text-neutral-600":!z.value.trim()&&!M.value||we.value||w.value}]),title:"Send message (Enter)"},[we.value?(a(),o("div",Tc,[A(Se)])):(a(),o("svg",Cc,[...he[14]||(he[14]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M4.5 10.5 12 3m0 0 7.5 7.5M12 3v18"},null,-1)])]))],10,$c))])])])):V("",!0)])]))}});function Sc(t,n){const{limit:s=100,offset:i=0,order:l="desc",autoFetch:u=!0,enableWebSocket:r=!1}=n||{};J(()=>!!(typeof t=="string"?t:t?.value));const c=J(()=>{const se=typeof t=="string"?t:t?.value;if(!se)return ue("/api/threads/placeholder/logs");const j=new URLSearchParams,M=typeof s=="number"?s:s.value,w=typeof i=="number"?i:i.value,R=typeof l=="string"?l:l.value;return j.append("limit",M.toString()),j.append("offset",w.toString()),j.append("order",R),ue(`/api/threads/${se}/logs?${j.toString()}`)}),{data:f,error:g,isFetching:d,isFinished:p,execute:h,abort:_}=Ue(c,{immediate:!1}).get().json();fe([c,()=>u],([se,j])=>{se&&!se.includes("placeholder")&&j&&h()},{immediate:!0});const b=J(()=>!g.value||g.value.toString().includes("aborted")||g.value.toString().includes("abort")?null:g.value),m=J(()=>f.value?.logs||[]),y=J(()=>f.value?.total||0),x=J(()=>f.value?.hasMore||!1),k=v(null),D=v(!1),q=v(null),B=v([]),F=new Map;let T=0,$=null,K=null,oe=!0,te=null;const H=3e4,P=3e4,C=()=>{$&&(clearTimeout($),$=null),K&&(clearInterval(K),K=null)},L=()=>{K&&clearInterval(K),K=setInterval(()=>{k.value&&k.value.readyState===WebSocket.OPEN&&k.value.send("ping")},P)},G=()=>{if(!oe||!r)return;const se=Math.min(1e3*Math.pow(2,T),H);T++,console.log(`[Logs WebSocket] Scheduling reconnect in ${se}ms (attempt ${T})`),$=setTimeout(()=>{oe&&ee()},se)},ee=()=>{const se=typeof t=="string"?t:t?.value;if(!se||!r)return;k.value&&(te=null,k.value.close()),T===0&&(B.value=[]);const j=window.location.protocol==="https:"?"wss:":"ws:",M=window.location.host;let w=`${j}//${M}${ue(`/api/threads/${se}/logs`)}`;const R=localStorage.getItem("auth_token");R&&(w+=`?token=${encodeURIComponent(R)}`);try{const I=new WebSocket(w);k.value=I,te=I,I.onopen=()=>{te===I&&(D.value=!0,q.value=null,T=0,L(),console.log("[Logs WebSocket] Connected"))},I.onmessage=le=>{if(te===I&&le.data!=="pong")try{const O=JSON.parse(le.data);if(O.type==="log_data"){const W=B.value.findIndex(z=>z.id===O.log_id),ce=m.value.find(z=>z.id===O.log_id);if(W>=0){B.value[W]={...B.value[W],...O.data};const z=F.get(O.log_id);z&&(B.value[W].queued_tools=z,F.delete(O.log_id))}else if(ce){const z={...ce,...O.data},N=F.get(O.log_id);N&&(z.queued_tools=N,F.delete(O.log_id)),B.value.push(z)}else{const z={id:O.log_id,...O.data},N=F.get(O.log_id);N&&(z.queued_tools=N,F.delete(O.log_id)),B.value.push(z)}}else if(O.type==="log_queued_tools"){const W=B.value.findIndex(z=>z.id===O.log_id),ce=m.value.find(z=>z.id===O.log_id);W>=0?B.value[W]={...B.value[W],queued_tools:O.queued_tools}:ce?B.value.push({...ce,queued_tools:O.queued_tools}):F.set(O.log_id,O.queued_tools)}}catch(O){console.error("[Logs WebSocket] Failed to parse message:",O)}},I.onerror=le=>{te===I&&(q.value="WebSocket connection error",console.error("[Logs WebSocket] Error:",le))},I.onclose=()=>{te===I&&(D.value=!1,C(),console.log("[Logs WebSocket] Disconnected"),G())}}catch(I){q.value=I.message||"Failed to create WebSocket",console.error("[Logs WebSocket] Creation error:",I),G()}},E=()=>{oe=!1,C(),te=null,k.value&&(k.value.close(),k.value=null),D.value=!1,T=0,B.value=[],F.clear()},U=()=>{oe=!0,T=0,ee()};return Be(()=>{E()}),{logs:J(()=>{if(!r)return m.value;const se=new Map;m.value.forEach(w=>se.set(w.id,w)),B.value.forEach(w=>se.set(w.id,w));const j=typeof l=="string"?l:l.value;return Array.from(se.values()).sort((w,R)=>j==="desc"?R.created_at-w.created_at:w.created_at-R.created_at)}),total:y,hasMore:x,error:b,isFetching:d,isFinished:p,refetch:h,abort:_,wsConnected:D,wsError:q,connectWebSocket:U,disconnectWebSocket:E}}function Vc(t,n){const s=J(()=>{const c=t.value,f=n.value;return!c||!f?null:ue(`/api/threads/${c}/logs/${f}`)}),{data:i,error:l,isFetching:u,execute:r}=Ue(s,{immediate:!1}).get().json();return fe([t,n],([c,f])=>{c&&f&&r()},{immediate:!0}),{logDetails:i,error:l,isFetching:u,refetch:r}}const Mc=["disabled","title"],Ic={key:1,xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Ec={key:2,xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Lc={key:3},wa=me({__name:"CopyButton",props:{content:{},variant:{},size:{},disabled:{type:Boolean}},setup(t){const n=t,s=v(!1),i=v(!1),l=async()=>{s.value=!0;try{await navigator.clipboard.writeText(n.content),i.value=!0,setTimeout(()=>{i.value=!1},2e3)}catch(c){console.error("Failed to copy:",c),alert(`Failed to copy: ${c instanceof Error?c.message:"Unknown error"}`)}finally{s.value=!1}},u={xs:"p-1 text-xs",sm:"px-2 py-1 text-xs"},r={solid:"bg-black text-white dark:bg-white dark:text-black",ghost:"bg-white dark:bg-neutral-950 border border-neutral-300 dark:border-neutral-700 text-neutral-700 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-900"};return(c,f)=>(a(),o("button",{onClick:l,disabled:s.value||t.disabled,class:ae([u[t.size||"sm"],r[t.variant||"solid"],"font-medium rounded hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed transition-all"]),title:t.disabled?"No content to copy":i.value?"Copied!":"Copy to clipboard"},[s.value?(a(),ne(Se,{key:0,size:"xs"})):t.variant==="ghost"&&!i.value?(a(),o("svg",Ic,[...f[0]||(f[0]=[e("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"},null,-1),e("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"},null,-1)])])):t.variant==="ghost"&&i.value?(a(),o("svg",Ec,[...f[1]||(f[1]=[e("polyline",{points:"20 6 9 17 4 12"},null,-1)])])):(a(),o("span",Lc,S(i.value?"Copied!":"Copy"),1))],10,Mc))}}),bt="__shiki_highlighter__";let ct=null;async function Ac(){return typeof window<"u"&&window[bt]?window[bt]:ct||(ct=io({themes:["min-light","github-dark-high-contrast"],langs:["json","markdown"]}).then(t=>(typeof window<"u"&&(window[bt]=t),t)),ct)}const Pc={class:"code-block"},Dc={key:0,class:"text-xs text-neutral-500 p-2"},jc=["innerHTML"],xt=me({__name:"CodeBlock",props:{code:{},language:{}},setup(t){const n=t,s=v(""),i=v(!0),l=async()=>{const u=n.code??"";if(!u){s.value='<pre class="shiki"><code></code></pre>',i.value=!1;return}try{const r=await Ac();if(n.language==="json"||n.language==="markdown")s.value=r.codeToHtml(u,{lang:n.language,themes:{light:"min-light",dark:"github-dark-high-contrast"}});else{const c=u.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");s.value=`<pre class="shiki shiki-text"><code>${c}</code></pre>`}}catch{const c=u.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");s.value=`<pre class="shiki"><code>${c}</code></pre>`}finally{i.value=!1}};return Me(()=>{l()}),fe(()=>n.code,()=>{l()}),(u,r)=>(a(),o("div",Pc,[i.value?(a(),o("div",Dc,"Loading...")):(a(),o("div",{key:1,innerHTML:s.value,class:"code-content"},null,8,jc))]))}}),Oc={class:"json-viewer relative bg-white dark:bg-neutral-900"},Uc={key:0,class:"absolute top-[5px] right-[5px] z-10"},Rc=["innerHTML"],Nc=["src","alt"],Fc=me({__name:"JsonViewer",props:{json:{},threadId:{},showCopyButton:{type:Boolean}},setup(t){const n=t,s=v(null),i=v(null),l=h=>[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp"].some(b=>h.toLowerCase().endsWith(b)),u=h=>n.threadId?ue(`/api/threads/${n.threadId}/fs${h}`):null,r=J(()=>{if(!n.json)return"";if(typeof n.json=="string")try{return JSON.stringify(JSON.parse(n.json),null,2)}catch{return n.json}return JSON.stringify(n.json,null,2)}),c=h=>h.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),f=(h,_=0)=>{const b=" ".repeat(_),m=y=>`<span class="json-punct">${y}</span>`;if(h===null)return'<span class="json-null">null</span>';if(typeof h=="boolean")return`<span class="json-boolean">${h}</span>`;if(typeof h=="number")return`<span class="json-number">${h}</span>`;if(typeof h=="string"){const y=c(h);return n.threadId&&l(h)&&h.startsWith("/attachments/")?`${m('"')}<span class="json-image-path" data-path="${c(h)}">${y}</span>${m('"')}`:`${m('"')}<span class="json-string">${y}</span>${m('"')}`}if(Array.isArray(h)){if(h.length===0)return`${m("[")}${m("]")}`;const y=h.map((x,k)=>{const D=k<h.length-1?m(","):"";return`${b} ${f(x,_+1)}${D}`});return`${m("[")}
3
3
  ${y.join(`
4
4
  `)}
5
- ${b}${v("]")}`}if(typeof h=="object"){const y=Object.entries(h);if(y.length===0)return`${v("{")}${v("}")}`;const x=y.map(([k,D],q)=>{const B=q<y.length-1?v(","):"",N=`${v('"')}<span class="json-key">${c(k)}</span>${v('"')}`;return`${b} ${N}${v(":")} ${f(D,_+1)}${B}`});return`${v("{")}
5
+ ${b}${m("]")}`}if(typeof h=="object"){const y=Object.entries(h);if(y.length===0)return`${m("{")}${m("}")}`;const x=y.map(([k,D],q)=>{const B=q<y.length-1?m(","):"",F=`${m('"')}<span class="json-key">${c(k)}</span>${m('"')}`;return`${b} ${F}${m(":")} ${f(D,_+1)}${B}`});return`${m("{")}
6
6
  ${x.join(`
7
7
  `)}
8
- ${b}${v("}")}`}return String(h)},g=W(()=>{if(!n.json)return'<span class="json-null">null</span>';let h;if(typeof n.json=="string")try{h=JSON.parse(n.json)}catch{return c(n.json)}else h=n.json;return f(h)}),d=h=>{const _=h.target;if(_.classList.contains("json-image-path")){const b=_.dataset.path;if(b&&n.threadId){s.value=b;const v=_.getBoundingClientRect();i.value={x:v.left,y:v.top}}}},p=h=>{h.target.classList.contains("json-image-path")&&(s.value=null,i.value=null)};return(h,_)=>(a(),o("div",jc,[t.showCopyButton?(a(),o("div",Oc,[P(wa,{content:r.value,variant:"ghost",size:"xs"},null,8,["content"])])):M("",!0),e("pre",{class:"text-xs font-mono p-3 overflow-x-auto",onMouseover:d,onMouseout:p,innerHTML:g.value},null,40,Uc),(a(),se(rt,{to:"body"},[s.value&&i.value&&t.threadId?(a(),o("div",{key:0,class:"fixed z-50 bg-white dark:bg-neutral-800 border border-neutral-300 dark:border-neutral-600 rounded-lg shadow-lg p-1 pointer-events-none",style:ot({left:`${i.value.x}px`,top:`${i.value.y-160}px`})},[e("img",{src:u(s.value),alt:s.value,class:"max-w-[200px] max-h-[150px] rounded object-contain",onError:_[0]||(_[0]=b=>b.target.style.display="none")},null,40,Rc)],4)):M("",!0)]))]))}}),vt=tt(Nc,[["__scopeId","data-v-fc06e7bc"]]),Fc={class:"text-xs font-semibold"},Bc={key:0,class:"font-normal text-neutral-500 dark:text-neutral-400"},qc={class:"flex items-center gap-2"},zc={class:"text-neutral-500 text-xs"},ct=pe({__name:"CollapsibleSection",props:{title:{},subtitle:{},sectionId:{},expanded:{type:Boolean},scrollContainer:{}},emits:["toggle"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(null),r=m(!1),c=()=>{Ce(()=>{if(!u.value||!i.scrollContainer){r.value=!1;return}const d=i.scrollContainer.clientHeight;r.value=u.value.scrollHeight>d*2})};ve(()=>i.expanded,d=>{d?c():r.value=!1});const f=()=>{if(u.value&&i.scrollContainer){const h=u.value.offsetTop-88;i.scrollContainer.scrollTo({top:Math.max(0,h),behavior:"smooth"})}},g=()=>{if(u.value&&i.scrollContainer){const d=u.value.offsetTop+u.value.offsetHeight,p=i.scrollContainer.clientHeight,h=d-p+10;i.scrollContainer.scrollTo({top:Math.max(0,h),behavior:"smooth"})}};return n({checkHeight:c,contentRef:u}),(d,p)=>(a(),o("div",null,[e("div",{class:"sticky top-[27px] z-5 w-full px-3 py-2 bg-neutral-50 dark:bg-neutral-950 flex items-center justify-between border border-neutral-300 dark:border-neutral-700 rounded cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-950 transition-colors",onClick:p[0]||(p[0]=h=>l("toggle"))},[e("span",Fc,[$e(V(t.title)+" ",1),t.subtitle?(a(),o("span",Bc,"("+V(t.subtitle)+")",1)):M("",!0)]),e("div",qc,[r.value&&t.expanded?(a(),o(me,{key:0},[e("button",{onClick:Ie(f,["stop"]),class:"text-[10px] text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"},"↑ Top"),e("button",{onClick:Ie(g,["stop"]),class:"text-[10px] text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"},"↓ Bottom")],64)):M("",!0),e("span",zc,V(t.expanded?"▼":"▶"),1)])]),Me(e("div",{ref_key:"contentRef",ref:u,class:"border-x border-b border-neutral-300 dark:border-neutral-700 rounded-b"},[et(d.$slots,"default")],512),[[Ke,t.expanded]])]))}}),Hc={class:"flex items-center justify-between mb-3"},Wc={class:"flex items-center gap-2"},Jc={class:"flex items-center gap-1"},Kc=["disabled"],Gc=["disabled"],Xc={class:"text-lg font-bold"},Yc={class:"flex items-center gap-2"},Zc=["disabled","title"],Qc={key:1},e0={class:"@container border-b border-neutral-300 dark:border-neutral-700 pb-3"},t0={class:"hidden @[600px]:block"},a0={class:"w-full text-xs"},o0={class:"py-1 font-mono"},l0={class:"py-1 font-mono"},s0={key:1},n0={class:"py-1 font-mono"},r0={key:1},i0={class:"py-1 font-mono"},d0={key:1},u0={class:"py-1 font-mono"},c0={key:1},p0={class:"py-1 font-mono text-xs"},v0={class:"@[600px]:hidden space-y-2"},m0={class:"w-full text-xs"},f0={class:"py-1 font-mono"},h0={class:"py-1 font-mono"},g0={key:1},b0={class:"w-full text-xs"},x0={class:"py-1 font-mono"},y0={key:1},k0={class:"py-1 font-mono"},w0={key:1},_0={class:"py-1 font-mono"},$0={key:1},C0={class:"py-1 font-mono text-xs"},T0={class:"sticky -top-4 z-10 bg-white dark:bg-neutral-900 border-b border-neutral-300 dark:border-neutral-700 mb-3 pt-3 -mx-4 px-4"},S0={class:"flex gap-4"},V0={key:0,class:"text-red-600 dark:text-red-400"},M0={class:"space-y-3"},I0={class:"space-y-2"},E0={class:"flex items-center gap-1 pb-2 mb-2 border-b border-neutral-200 dark:border-neutral-700"},L0=["onClick"],A0={key:1,class:"text-xs text-red-600 dark:text-red-400 ml-2"},P0=["onClick"],D0={class:"font-mono"},j0={class:"text-neutral-500"},O0={class:"px-2 py-2 bg-white dark:bg-neutral-950 border-t border-neutral-200 dark:border-neutral-800"},U0={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mb-2"},R0={class:"relative bg-white dark:bg-neutral-900"},N0={class:"absolute top-[5px] right-[5px]"},F0={key:0,class:"mb-4"},B0={class:"text-xs font-semibold text-red-600 dark:text-red-400 mb-1"},q0={class:"space-y-2"},z0={class:"px-2 py-1 bg-red-100 dark:bg-red-900/30 text-xs font-medium text-red-800 dark:text-red-200"},H0={class:"text-xs bg-red-50 dark:bg-red-950 p-2 overflow-x-auto text-red-900 dark:text-red-100"},W0={key:1,class:"mb-4"},J0={class:"text-xs font-semibold text-red-600 dark:text-red-400 mb-1"},K0={class:"text-xs bg-red-50 dark:bg-red-950 p-2 rounded overflow-x-auto text-red-900 dark:text-red-100 border border-red-300 dark:border-red-700"},G0={key:2,class:"mb-4"},X0={class:"w-full text-xs border border-neutral-300 dark:border-neutral-700 rounded"},Y0={class:"border-b border-neutral-200 dark:border-neutral-800"},Z0={class:"py-1 px-2 font-mono"},Q0={key:1},ep={class:"border-b border-neutral-200 dark:border-neutral-800"},tp={class:"py-1 px-2 font-mono"},ap={key:1},op={key:0,class:"border-b border-neutral-200 dark:border-neutral-800"},lp={class:"py-1 px-2 font-mono"},sp={key:1},np={class:"border-b border-neutral-200 dark:border-neutral-800"},rp={class:"py-1 px-2 font-mono"},ip={key:1},dp={key:1,class:"border-b border-neutral-200 dark:border-neutral-800"},up={class:"py-1 px-2 font-mono text-accent-600 dark:text-accent-400"},cp={class:"border-b border-neutral-200 dark:border-neutral-800"},pp={class:"py-1 px-2 font-mono font-semibold"},vp={key:1},mp={class:"py-1 px-2 font-mono font-semibold"},fp={key:1},hp={key:3,class:"mb-4"},gp={class:"text-xs font-semibold mb-1"},bp={class:"border border-neutral-300 dark:border-neutral-700 rounded overflow-hidden"},xp=["onClick"],yp={class:"flex items-center gap-2"},kp={class:"font-mono"},wp={key:0,class:"px-1.5 py-0.5 text-[10px] bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded font-medium"},_p={class:"text-neutral-500"},$p={class:"text-xs mb-2"},Cp={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-neutral-200 dark:border-neutral-800"},Tp={class:"text-xs mb-2"},Sp={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-neutral-200 dark:border-neutral-800"},Vp={class:"text-xs mb-2"},Mp={class:"rounded overflow-hidden border border-neutral-200 dark:border-neutral-800 bg-white dark:bg-black"},Ip={key:0,class:"text-xs"},Ep={class:"text-xs overflow-x-auto bg-green-50 dark:bg-green-950/20 p-2 rounded border border-green-300 dark:border-green-700 whitespace-pre-wrap"},Lp={key:1,class:"text-xs"},Ap={class:"text-xs mb-2"},Pp={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-purple-200 dark:border-purple-800"},Dp={key:0,class:"text-sm mt-2"},jp={key:0,class:"text-neutral-600 dark:text-neutral-400"},Op={key:1,class:"text-neutral-600 dark:text-neutral-400"},Up=["href"],Rp={key:2,class:"ml-4 mt-1 space-y-0.5"},Np=["href"],Fp={key:0,class:"text-xs text-neutral-500"},Bp={key:1,class:"text-sm text-neutral-600 dark:text-neutral-400 mt-2"},qp={key:0},zp={class:"font-mono text-xs"},Hp={key:1},Wp={key:2,class:"text-sm mt-2"},Jp={class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800 overflow-x-auto"},Kp={key:3,class:"text-sm mt-2"},Gp={class:"font-medium text-neutral-600 dark:text-neutral-400 mb-1"},Xp={key:4,class:"mb-4"},Yp={class:"text-xs font-semibold mb-1"},Zp={class:"border border-emerald-300 dark:border-emerald-700 rounded overflow-hidden bg-emerald-50 dark:bg-emerald-950/20"},Qp={class:"p-2 flex flex-wrap gap-2"},ev=["src","alt"],tv={key:1,class:"w-[100px] h-[100px] flex items-center justify-center bg-emerald-100 dark:bg-emerald-900 rounded text-xs text-emerald-600 dark:text-emerald-400"},av={key:5,class:"mb-4"},ov={class:"border border-accent-300 dark:border-accent-700 rounded overflow-hidden bg-accent-50 dark:bg-accent-950/20"},lv={class:"text-accent-600 dark:text-accent-400"},sv={key:6,class:"mb-4"},nv={class:"border border-purple-300 dark:border-purple-700 rounded overflow-hidden bg-purple-50 dark:bg-purple-950/20"},rv={class:"flex items-center gap-2"},iv={class:"px-1.5 py-0.5 text-[10px] bg-purple-200 dark:bg-purple-800 text-purple-700 dark:text-purple-300 rounded"},dv={class:"text-purple-600 dark:text-purple-400"},uv={class:"divide-y divide-purple-200 dark:divide-purple-800 border-t border-purple-300 dark:border-purple-700"},cv={class:"flex items-center gap-2 mb-1"},pv={class:"text-xs font-semibold text-purple-700 dark:text-purple-300"},vv={key:0,class:"text-xs font-mono text-purple-600 dark:text-purple-400"},mv={key:1,class:"text-xs text-purple-500 dark:text-purple-500"},fv={key:2,class:"text-xs text-purple-500 dark:text-purple-500"},hv={key:0,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},gv={class:"text-purple-900 dark:text-purple-100 whitespace-pre-wrap"},bv={key:1,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},xv={class:"font-mono text-purple-700 dark:text-purple-300 break-all"},yv={key:2,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},kv={class:"text-purple-900 dark:text-purple-100 whitespace-pre-wrap"},wv={key:0,class:"mt-2 pt-2 border-t border-purple-200 dark:border-purple-800"},_v={class:"font-mono text-purple-700 dark:text-purple-300 text-xs break-all"},$v={key:3,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},Cv={class:"text-purple-900 dark:text-purple-100 overflow-x-auto"},Tv={key:7,class:"mb-4"},Sv={class:"rounded overflow-hidden border border-neutral-300 dark:border-neutral-700"},Vv=pe({__name:"LogDetails",props:{log:{},threadId:{},hasPrevious:{type:Boolean},hasNext:{type:Boolean}},emits:["close","previous","next"],setup(t,{emit:n}){const s=t,i=n,l=m("request"),u=m(new Set),r=m(new Set),c=m(!1),f=m(!1),g=m(!0),d=m(!0),p=m(null),h=m(null),_=m(null),b=m(null),v=m(null),y=m(new Set(["system_prompt","request_body","tools"])),x=z=>s.threadId?z.startsWith("data:")||z.startsWith("http")?z:de(`/api/threads/${s.threadId}/fs${z}`):null,k=z=>{if(!z)return"N/A";try{return JSON.stringify(JSON.parse(z),null,2)}catch{return z}},D=W(()=>{if(!s.log.tools_schema)return[];try{const z=JSON.parse(s.log.tools_schema);return Array.isArray(z)?z:[]}catch{return[]}}),q=W(()=>{if(!s.log.response_body)return[];try{const j=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.tool_calls;return Array.isArray(j)?j:[]}catch{return[]}}),B=W(()=>{if(!s.log.tool_results)return new Map;try{const z=JSON.parse(s.log.tool_results),j=new Map;return Array.isArray(z)&&z.forEach(Q=>{Q.tool_call_id&&j.set(Q.tool_call_id,{content:Q.content,status:Q.status,tool_name:Q.tool_name,timestamp:Q.timestamp})}),j}catch{return new Map}}),N=W(()=>{if(!s.log.response_body)return[];try{const j=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.reasoning_details;return Array.isArray(j)?j:[]}catch{return[]}}),T=W(()=>s.log.reasoning_content?s.log.reasoning_content.replace(/\\n/g,`
8
+ ${b}${m("}")}`}return String(h)},g=J(()=>{if(!n.json)return'<span class="json-null">null</span>';let h;if(typeof n.json=="string")try{h=JSON.parse(n.json)}catch{return c(n.json)}else h=n.json;return f(h)}),d=h=>{const _=h.target;if(_.classList.contains("json-image-path")){const b=_.dataset.path;if(b&&n.threadId){s.value=b;const m=_.getBoundingClientRect();i.value={x:m.left,y:m.top}}}},p=h=>{h.target.classList.contains("json-image-path")&&(s.value=null,i.value=null)};return(h,_)=>(a(),o("div",Oc,[t.showCopyButton?(a(),o("div",Uc,[A(wa,{content:r.value,variant:"ghost",size:"xs"},null,8,["content"])])):V("",!0),e("pre",{class:"text-xs font-mono p-3 overflow-x-auto",onMouseover:d,onMouseout:p,innerHTML:g.value},null,40,Rc),(a(),ne(it,{to:"body"},[s.value&&i.value&&t.threadId?(a(),o("div",{key:0,class:"fixed z-50 bg-white dark:bg-neutral-800 border border-neutral-300 dark:border-neutral-600 rounded-lg shadow-lg p-1 pointer-events-none",style:ot({left:`${i.value.x}px`,top:`${i.value.y-160}px`})},[e("img",{src:u(s.value),alt:s.value,class:"max-w-[200px] max-h-[150px] rounded object-contain",onError:_[0]||(_[0]=b=>b.target.style.display="none")},null,40,Nc)],4)):V("",!0)]))]))}}),vt=tt(Fc,[["__scopeId","data-v-fc06e7bc"]]),Bc={class:"text-xs font-semibold"},qc={key:0,class:"font-normal text-neutral-500 dark:text-neutral-400"},zc={class:"flex items-center gap-2"},Hc={class:"text-neutral-500 text-xs"},pt=me({__name:"CollapsibleSection",props:{title:{},subtitle:{},sectionId:{},expanded:{type:Boolean},scrollContainer:{}},emits:["toggle"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(null),r=v(!1),c=()=>{Te(()=>{if(!u.value||!i.scrollContainer){r.value=!1;return}const d=i.scrollContainer.clientHeight;r.value=u.value.scrollHeight>d*2})};fe(()=>i.expanded,d=>{d?c():r.value=!1});const f=()=>{if(u.value&&i.scrollContainer){const h=u.value.offsetTop-88;i.scrollContainer.scrollTo({top:Math.max(0,h),behavior:"smooth"})}},g=()=>{if(u.value&&i.scrollContainer){const d=u.value.offsetTop+u.value.offsetHeight,p=i.scrollContainer.clientHeight,h=d-p+10;i.scrollContainer.scrollTo({top:Math.max(0,h),behavior:"smooth"})}};return n({checkHeight:c,contentRef:u}),(d,p)=>(a(),o("div",null,[e("div",{class:"sticky top-[27px] z-5 w-full px-3 py-2 bg-neutral-50 dark:bg-neutral-950 flex items-center justify-between border border-neutral-300 dark:border-neutral-700 rounded cursor-pointer hover:bg-neutral-100 dark:hover:bg-neutral-950 transition-colors",onClick:p[0]||(p[0]=h=>l("toggle"))},[e("span",Bc,[Ce(S(t.title)+" ",1),t.subtitle?(a(),o("span",qc,"("+S(t.subtitle)+")",1)):V("",!0)]),e("div",zc,[r.value&&t.expanded?(a(),o(ve,{key:0},[e("button",{onClick:Ee(f,["stop"]),class:"text-[10px] text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"},"↑ Top"),e("button",{onClick:Ee(g,["stop"]),class:"text-[10px] text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300"},"↓ Bottom")],64)):V("",!0),e("span",Hc,S(t.expanded?"▼":"▶"),1)])]),Ie(e("div",{ref_key:"contentRef",ref:u,class:"border-x border-b border-neutral-300 dark:border-neutral-700 rounded-b"},[et(d.$slots,"default")],512),[[Ke,t.expanded]])]))}}),Wc={class:"flex items-center justify-between mb-3"},Jc={class:"flex items-center gap-2"},Kc={class:"flex items-center gap-1"},Gc=["disabled"],Xc=["disabled"],Yc={class:"text-lg font-bold"},Qc={class:"flex items-center gap-2"},Zc=["disabled","title"],e0={key:1},t0={class:"@container border-b border-neutral-300 dark:border-neutral-700 pb-3"},a0={class:"hidden @[600px]:block"},o0={class:"w-full text-xs"},l0={class:"py-1 font-mono"},s0={class:"py-1 font-mono"},n0={key:1},r0={class:"py-1 font-mono"},i0={key:1},d0={class:"py-1 font-mono"},u0={key:1},c0={class:"py-1 font-mono"},p0={key:1},m0={class:"py-1 font-mono text-xs"},v0={class:"@[600px]:hidden space-y-2"},f0={class:"w-full text-xs"},h0={class:"py-1 font-mono"},g0={class:"py-1 font-mono"},b0={key:1},x0={class:"w-full text-xs"},y0={class:"py-1 font-mono"},k0={key:1},w0={class:"py-1 font-mono"},_0={key:1},$0={class:"py-1 font-mono"},C0={key:1},T0={class:"py-1 font-mono text-xs"},S0={class:"sticky -top-4 z-10 bg-white dark:bg-neutral-900 border-b border-neutral-300 dark:border-neutral-700 mb-3 pt-3 -mx-4 px-4"},V0={class:"flex gap-4"},M0={key:0,class:"text-red-600 dark:text-red-400"},I0={class:"space-y-3"},E0={class:"space-y-2"},L0={class:"flex items-center gap-1 pb-2 mb-2 border-b border-neutral-200 dark:border-neutral-700"},A0=["onClick"],P0={key:1,class:"text-xs text-red-600 dark:text-red-400 ml-2"},D0=["onClick"],j0={class:"font-mono"},O0={class:"text-neutral-500"},U0={class:"px-2 py-2 bg-white dark:bg-neutral-950 border-t border-neutral-200 dark:border-neutral-800"},R0={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mb-2"},N0={class:"relative bg-white dark:bg-neutral-900"},F0={class:"absolute top-[5px] right-[5px]"},B0={key:0,class:"mb-4"},q0={class:"text-xs font-semibold text-red-600 dark:text-red-400 mb-1"},z0={class:"space-y-2"},H0={class:"px-2 py-1 bg-red-100 dark:bg-red-900/30 text-xs font-medium text-red-800 dark:text-red-200"},W0={class:"text-xs bg-red-50 dark:bg-red-950 p-2 overflow-x-auto text-red-900 dark:text-red-100"},J0={key:1,class:"mb-4"},K0={class:"text-xs font-semibold text-red-600 dark:text-red-400 mb-1"},G0={class:"text-xs bg-red-50 dark:bg-red-950 p-2 rounded overflow-x-auto text-red-900 dark:text-red-100 border border-red-300 dark:border-red-700"},X0={key:2,class:"mb-4"},Y0={class:"w-full text-xs border border-neutral-300 dark:border-neutral-700 rounded"},Q0={class:"border-b border-neutral-200 dark:border-neutral-800"},Z0={class:"py-1 px-2 font-mono"},ep={key:1},tp={class:"border-b border-neutral-200 dark:border-neutral-800"},ap={class:"py-1 px-2 font-mono"},op={key:1},lp={key:0,class:"border-b border-neutral-200 dark:border-neutral-800"},sp={class:"py-1 px-2 font-mono"},np={key:1},rp={class:"border-b border-neutral-200 dark:border-neutral-800"},ip={class:"py-1 px-2 font-mono"},dp={key:1},up={key:1,class:"border-b border-neutral-200 dark:border-neutral-800"},cp={class:"py-1 px-2 font-mono text-accent-600 dark:text-accent-400"},pp={class:"border-b border-neutral-200 dark:border-neutral-800"},mp={class:"py-1 px-2 font-mono font-semibold"},vp={key:1},fp={class:"py-1 px-2 font-mono font-semibold"},hp={key:1},gp={key:3,class:"mb-4"},bp={class:"text-xs font-semibold mb-1"},xp={class:"border border-neutral-300 dark:border-neutral-700 rounded overflow-hidden"},yp=["onClick"],kp={class:"flex items-center gap-2"},wp={class:"font-mono"},_p={key:0,class:"px-1.5 py-0.5 text-[10px] bg-emerald-100 dark:bg-emerald-900/40 text-emerald-700 dark:text-emerald-300 rounded font-medium border border-emerald-200 dark:border-emerald-800",title:"Programmatically called with state.queueTool()"},$p={key:1,class:"px-1.5 py-0.5 text-[10px] bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 rounded font-medium"},Cp={class:"text-neutral-500"},Tp={key:0,class:"text-xs mb-2"},Sp={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-emerald-200 dark:border-emerald-800"},Vp={class:"text-xs mb-2"},Mp={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-neutral-200 dark:border-neutral-800"},Ip={class:"text-xs mb-2"},Ep={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-neutral-200 dark:border-neutral-800"},Lp={class:"text-xs mb-2"},Ap={class:"rounded overflow-hidden border border-neutral-200 dark:border-neutral-800 bg-white dark:bg-black"},Pp={key:1,class:"text-xs"},Dp={class:"text-xs overflow-x-auto bg-green-50 dark:bg-green-950/20 p-2 rounded border border-green-300 dark:border-green-700 whitespace-pre-wrap"},jp={key:2,class:"text-xs"},Op={class:"text-xs mb-2"},Up={class:"font-mono text-xs bg-white dark:bg-black p-1 rounded border border-purple-200 dark:border-purple-800"},Rp={key:0,class:"text-sm mt-2"},Np={key:0,class:"text-neutral-600 dark:text-neutral-400"},Fp={key:1,class:"text-neutral-600 dark:text-neutral-400"},Bp=["href"],qp={key:2,class:"ml-4 mt-1 space-y-0.5"},zp=["href"],Hp={key:0,class:"text-xs text-neutral-500"},Wp={key:1,class:"text-sm text-neutral-600 dark:text-neutral-400 mt-2"},Jp={key:0},Kp={class:"font-mono text-xs"},Gp={key:1},Xp={key:2,class:"text-sm mt-2"},Yp={class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800 overflow-x-auto"},Qp={key:3,class:"text-sm mt-2"},Zp={class:"font-medium text-neutral-600 dark:text-neutral-400 mb-1"},em={key:4,class:"mb-4"},tm={class:"text-xs font-semibold mb-1"},am={class:"border border-emerald-300 dark:border-emerald-700 rounded overflow-hidden bg-emerald-50 dark:bg-emerald-950/20"},om={class:"p-2 flex flex-wrap gap-2"},lm=["src","alt"],sm={key:1,class:"w-[100px] h-[100px] flex items-center justify-center bg-emerald-100 dark:bg-emerald-900 rounded text-xs text-emerald-600 dark:text-emerald-400"},nm={key:5,class:"mb-4"},rm={class:"border border-accent-300 dark:border-accent-700 rounded overflow-hidden bg-accent-50 dark:bg-accent-950/20"},im={class:"text-accent-600 dark:text-accent-400"},dm={key:6,class:"mb-4"},um={class:"border border-purple-300 dark:border-purple-700 rounded overflow-hidden bg-purple-50 dark:bg-purple-950/20"},cm={class:"flex items-center gap-2"},pm={class:"px-1.5 py-0.5 text-[10px] bg-purple-200 dark:bg-purple-800 text-purple-700 dark:text-purple-300 rounded"},mm={class:"text-purple-600 dark:text-purple-400"},vm={class:"divide-y divide-purple-200 dark:divide-purple-800 border-t border-purple-300 dark:border-purple-700"},fm={class:"flex items-center gap-2 mb-1"},hm={class:"text-xs font-semibold text-purple-700 dark:text-purple-300"},gm={key:0,class:"text-xs font-mono text-purple-600 dark:text-purple-400"},bm={key:1,class:"text-xs text-purple-500 dark:text-purple-500"},xm={key:2,class:"text-xs text-purple-500 dark:text-purple-500"},ym={key:0,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},km={class:"text-purple-900 dark:text-purple-100 whitespace-pre-wrap"},wm={key:1,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},_m={class:"font-mono text-purple-700 dark:text-purple-300 break-all"},$m={key:2,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},Cm={class:"text-purple-900 dark:text-purple-100 whitespace-pre-wrap"},Tm={key:0,class:"mt-2 pt-2 border-t border-purple-200 dark:border-purple-800"},Sm={class:"font-mono text-purple-700 dark:text-purple-300 text-xs break-all"},Vm={key:3,class:"text-xs bg-white dark:bg-black p-2 rounded border border-purple-200 dark:border-purple-800"},Mm={class:"text-purple-900 dark:text-purple-100 overflow-x-auto"},Im={key:7,class:"mb-4"},Em={class:"rounded overflow-hidden border border-neutral-300 dark:border-neutral-700"},Lm=me({__name:"LogDetails",props:{log:{},threadId:{},hasPrevious:{type:Boolean},hasNext:{type:Boolean}},emits:["close","previous","next"],setup(t,{emit:n}){const s=t,i=n,l=v("request"),u=v(new Set),r=v(new Set),c=v(!1),f=v(!1),g=v(!0),d=v(!0),p=v(null),h=v(null),_=v(null),b=v(null),m=v(null),y=v(new Set(["system_prompt","request_body","tools"])),x=z=>s.threadId?z.startsWith("data:")||z.startsWith("http")?z:ue(`/api/threads/${s.threadId}/fs${z}`):null,k=z=>{if(!z)return"N/A";try{return JSON.stringify(JSON.parse(z),null,2)}catch{return z}},D=J(()=>{if(!s.log.tools_schema)return[];try{const z=JSON.parse(s.log.tools_schema);return Array.isArray(z)?z:[]}catch{return[]}}),q=J(()=>{if(!s.log.response_body)return[];try{const N=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.tool_calls;return Array.isArray(N)?N:[]}catch{return[]}}),B=J(()=>{if(!s.log.tool_results)return new Map;try{const z=JSON.parse(s.log.tool_results),N=new Map;return Array.isArray(z)&&z.forEach(Q=>{Q.tool_call_id&&N.set(Q.tool_call_id,{content:Q.content,status:Q.status,tool_name:Q.tool_name,timestamp:Q.timestamp})}),N}catch{return new Map}}),F=J(()=>{if(!s.log.response_body)return[];try{const N=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.reasoning_details;return Array.isArray(N)?N:[]}catch{return[]}}),T=J(()=>s.log.reasoning_content?s.log.reasoning_content.replace(/\\n/g,`
9
9
  `).replace(/\\t/g," ").replace(/\n{3,}/g,`
10
10
 
11
- `).trim():""),w=W(()=>{if(!s.log.response_body)return[];try{const j=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.images;return Array.isArray(j)?j:[]}catch{return[]}}),K=W(()=>{if(!s.log.provider_tools)return[];try{const z=JSON.parse(s.log.provider_tools);return Array.isArray(z)?z:[]}catch{return[]}}),te=W(()=>{const z=[];for(const j of q.value)z.push({id:j.id||`tool-${z.length}`,name:j.function?.name||"Unknown",isProvider:!1,function:j.function});for(const j of K.value)z.push({id:j.id,name:j.type,isProvider:!0,providerType:j.type,status:j.status,result:j.result});return z}),le=z=>{u.value.has(z)?u.value.delete(z):u.value.add(z)},H=z=>{r.value.has(z)?r.value.delete(z):r.value.add(z)},A=()=>{g.value=!g.value},$=()=>{d.value=!d.value},L=z=>{y.value.has(z)?y.value.delete(z):y.value.add(z)},J=z=>!y.value.has(z),ee=W(()=>{if(!s.log.errors)return[];try{const z=JSON.parse(s.log.errors);return Array.isArray(z)?z:[]}catch{return[]}}),E=m("standard"),R=m(null),Y=m(!1),ne=m(null),O=["openai","openrouter"],S=()=>(s.log.actual_provider||s.log.provider)?.toLowerCase(),C=()=>{const z=S();z&&O.includes(z)?E.value=z:E.value="standard"},U=z=>z.charAt(0).toUpperCase()+z.slice(1);ve(E,async z=>{if(z==="standard"){R.value=null,ne.value=null;return}if(!s.threadId||!s.log.id){ne.value="Missing thread or log ID";return}Y.value=!0,ne.value=null;try{const j=await fetch(de(`/api/threads/${s.threadId}/logs/${s.log.id}/inspect/${z}`));if(!j.ok){const Q=await j.json();throw new Error(Q.error||"Failed to inspect")}R.value=await j.json()}catch(j){ne.value=j.message||"Failed to fetch inspected request",R.value=null}finally{Y.value=!1}}),ve(()=>s.log.id,async()=>{if(R.value=null,ne.value=null,C(),E.value!=="standard"&&s.threadId&&s.log.id){Y.value=!0;try{const z=await fetch(de(`/api/threads/${s.threadId}/logs/${s.log.id}/inspect/${E.value}`));if(!z.ok){const j=await z.json();throw new Error(j.error||"Failed to fetch inspected request")}R.value=await z.json()}catch(z){ne.value=z.message||"Failed to fetch inspected request"}finally{Y.value=!1}}},{immediate:!0});const I=W(()=>{if(E.value==="standard"||!R.value)return s.log.message_history;const z=R.value.messagesPath,j=z?R.value.body?.[z]:R.value.body;return JSON.stringify(j,null,2)}),ae=W(()=>E.value==="standard"||!R.value?s.log.request_body:JSON.stringify(R.value.body,null,2)),F=W(()=>E.value==="standard"||!R.value?null:`${E.value} format`);ve(()=>s.log,()=>{Ce(()=>{h.value?.checkHeight(),_.value?.checkHeight(),b.value?.checkHeight(),v.value?.checkHeight()})});const G=async()=>{c.value=!0;try{if(!s.log.request_body||!s.log.model)throw new Error("Missing request data");const z=await fetch(de(`/api/models/${s.log.model}/curl-data`));if(!z.ok)throw new Error("Failed to fetch model data");const j=await z.json(),Q=k(s.log.request_body);let be=`curl -X POST '${j.endpoint}' \\
12
- `;be+=` -H 'Content-Type: application/json' \\
13
- `,j.sdk?.toLowerCase()==="openrouter"?(be+=` -H 'Authorization: Bearer ${j.api_key}' \\
14
- `,be+=` -H 'HTTP-Referer: https://agentkit.local' \\
15
- `,be+=` -H 'X-Title: AgentKit' \\
16
- `):j.sdk?.toLowerCase()==="openai"&&(be+=` -H 'Authorization: Bearer ${j.api_key}' \\
17
- `),be+=` -d '${Q.replace(/'/g,"'\\''")}'`,await navigator.clipboard.writeText(be),f.value=!0,setTimeout(()=>{f.value=!1},2e3)}catch(z){console.error("Failed to copy cURL command:",z),alert(`Failed to copy cURL: ${z instanceof Error?z.message:"Unknown error"}`)}finally{c.value=!1}};return(z,j)=>(a(),o("div",{ref_key:"scrollContainer",ref:p,class:"p-4 h-full overflow-y-auto"},[e("div",Hc,[e("div",Wc,[e("div",Jc,[e("button",{onClick:j[0]||(j[0]=Q=>i("previous")),disabled:!t.hasPrevious,class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent dark:disabled:hover:bg-transparent transition-all","aria-label":"Previous log",title:"Previous log"},[...j[10]||(j[10]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("polyline",{points:"15 18 9 12 15 6"})],-1)])],8,Kc),e("button",{onClick:j[1]||(j[1]=Q=>i("next")),disabled:!t.hasNext,class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent dark:disabled:hover:bg-transparent transition-all","aria-label":"Next log",title:"Next log"},[...j[11]||(j[11]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("polyline",{points:"9 18 15 12 9 6"})],-1)])],8,Gc)]),e("h3",Xc,V(t.log.prompt_name||t.log.model_name||t.log.model),1)]),e("div",Yc,[e("button",{onClick:G,disabled:c.value||!t.log.request_body,class:"px-3 py-1 text-xs font-medium bg-black text-white dark:bg-white dark:text-black rounded hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed transition-opacity",title:t.log.request_body?"Copy cURL command":"No request data available"},[c.value?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",Qc,V(f.value?"Copied!":"Copy cURL"),1))],8,Zc),e("button",{onClick:j[2]||(j[2]=Q=>i("close")),class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 transition-all","aria-label":"Close details",title:"Close"},[...j[12]||(j[12]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])])])]),e("div",e0,[e("div",t0,[e("table",a0,[j[13]||(j[13]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Status "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Provider "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Prompt "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Latency "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Tokens "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Cost "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Created ")])],-1)),e("tbody",null,[e("tr",null,[e("td",{class:oe(["py-1 font-mono",t.log.error?"text-red-600 dark:text-red-400":t.log.is_complete?"text-green-600 dark:text-green-400":"text-yellow-600 dark:text-yellow-400"])},V(t.log.error?"ERROR":t.log.is_complete?"SUCCESS":"LOADING"),3),e("td",o0,V(t.log.actual_provider||t.log.provider),1),e("td",l0,[!t.log.is_complete&&!t.log.prompt_name?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",s0,V(t.log.prompt_name||"—"),1))]),e("td",n0,[!t.log.is_complete&&!t.log.latency_ms?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",r0,V(t.log.latency_ms?`${t.log.latency_ms}ms`:"—"),1))]),e("td",i0,[!t.log.is_complete&&!t.log.total_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",d0,V(t.log.total_tokens?`${t.log.input_tokens}/${t.log.output_tokens} (${t.log.total_tokens})`:"—"),1))]),e("td",u0,[!t.log.is_complete&&!t.log.cost_total?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",c0,V(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))]),e("td",p0,[P(mt,{timestamp:t.log.created_at},null,8,["timestamp"])])])])])]),e("div",v0,[e("table",m0,[j[14]||(j[14]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Status "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Provider "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Prompt ")])],-1)),e("tbody",null,[e("tr",null,[e("td",{class:oe(["py-1 font-mono",t.log.error?"text-red-600 dark:text-red-400":t.log.is_complete?"text-green-600 dark:text-green-400":"text-yellow-600 dark:text-yellow-400"])},V(t.log.error?"ERROR":t.log.is_complete?"SUCCESS":"LOADING"),3),e("td",f0,V(t.log.actual_provider||t.log.provider),1),e("td",h0,[!t.log.is_complete&&!t.log.prompt_name?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",g0,V(t.log.prompt_name||"—"),1))])])])]),e("table",b0,[j[15]||(j[15]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Latency "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Tokens "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Cost "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Created ")])],-1)),e("tbody",null,[e("tr",null,[e("td",x0,[!t.log.is_complete&&!t.log.latency_ms?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",y0,V(t.log.latency_ms?`${t.log.latency_ms}ms`:"—"),1))]),e("td",k0,[!t.log.is_complete&&!t.log.total_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",w0,V(t.log.total_tokens?`${t.log.input_tokens}/${t.log.output_tokens} (${t.log.total_tokens})`:"—"),1))]),e("td",_0,[!t.log.is_complete&&!t.log.cost_total?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",$0,V(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))]),e("td",C0,[P(mt,{timestamp:t.log.created_at},null,8,["timestamp"])])])])])])]),e("div",T0,[e("div",S0,[e("button",{onClick:j[3]||(j[3]=Q=>l.value="request"),class:oe(["pb-2 px-1 text-sm font-medium border-b-2 transition-colors",l.value==="request"?"border-black dark:border-white text-black dark:text-white":"border-transparent text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-white"])}," Request ",2),e("button",{onClick:j[4]||(j[4]=Q=>l.value="response"),class:oe(["pb-2 px-1 text-sm font-medium border-b-2 transition-colors flex items-center gap-1",l.value==="response"?"border-black dark:border-white text-black dark:text-white":"border-transparent text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-white"])},[j[16]||(j[16]=$e(" Response ",-1)),t.log.error||ee.value.length>0?(a(),o("span",V0,"⚠")):M("",!0)],2)])]),e("div",M0,[Me(e("div",I0,[e("div",E0,[j[17]||(j[17]=e("span",{class:"text-xs text-neutral-500 dark:text-neutral-400 mr-2"},"View as:",-1)),e("button",{onClick:j[5]||(j[5]=Q=>E.value="standard"),class:oe(["px-2 py-1 text-xs rounded transition-colors",E.value==="standard"?"bg-black text-white dark:bg-white dark:text-black":"bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400 hover:bg-neutral-200 dark:hover:bg-neutral-700"])}," Standard Agents ",2),(a(),o(me,null,ye(O,Q=>e("button",{key:Q,onClick:be=>E.value=Q,class:oe(["px-2 py-1 text-xs rounded transition-colors",E.value===Q?"bg-black text-white dark:bg-white dark:text-black":"bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400 hover:bg-neutral-200 dark:hover:bg-neutral-700"])},V(U(Q)),11,L0)),64)),Y.value?(a(),se(Te,{key:0,size:"xs",class:"ml-2"})):M("",!0),ne.value?(a(),o("span",A0,V(ne.value),1)):M("",!0)]),D.value.length>0?(a(),se(ct,{key:0,ref_key:"toolsSectionRef",ref:h,title:`Available Tools (${D.value.length})`,"section-id":"tools",expanded:J("tools"),"scroll-container":p.value,onToggle:j[6]||(j[6]=Q=>L("tools"))},{default:ge(()=>[(a(!0),o(me,null,ye(D.value,(Q,be)=>(a(),o("div",{key:be,class:"border-b border-neutral-200 dark:border-neutral-800 last:border-b-0"},[e("button",{onClick:De=>le(be),class:"w-full px-2 py-1.5 text-left hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors flex items-center justify-between text-xs"},[e("span",D0,V(Q.function?.name||Q.name||"Unknown"),1),e("span",j0,V(u.value.has(be)?"▼":"▶"),1)],8,P0),Me(e("div",O0,[Q.function?.description||Q.description?(a(),o("div",U0,V(Q.function?.description||Q.description),1)):M("",!0),P(xt,{code:JSON.stringify(Q,null,2),language:"json"},null,8,["code"])],512),[[Ke,u.value.has(be)]])]))),128))]),_:1},8,["title","expanded","scroll-container"])):M("",!0),t.log.message_history?(a(),se(ct,{key:1,ref_key:"messagesSectionRef",ref:_,title:`Messages (${t.log.message_history_length||0} messages)`,subtitle:F.value,"section-id":"messages",expanded:J("messages"),"scroll-container":p.value,onToggle:j[7]||(j[7]=Q=>L("messages"))},{default:ge(()=>[P(vt,{json:I.value,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])]),_:1},8,["title","subtitle","expanded","scroll-container"])):M("",!0),t.log.system_prompt?(a(),se(ct,{key:2,ref_key:"systemPromptSectionRef",ref:b,title:"System Prompt","section-id":"system_prompt",expanded:J("system_prompt"),"scroll-container":p.value,onToggle:j[8]||(j[8]=Q=>L("system_prompt"))},{default:ge(()=>[e("div",R0,[P(xt,{code:t.log.system_prompt,language:"markdown"},null,8,["code"]),e("div",N0,[P(wa,{content:t.log.system_prompt,variant:"ghost",size:"xs"},null,8,["content"])])])]),_:1},8,["expanded","scroll-container"])):M("",!0),t.log.request_body?(a(),se(ct,{key:3,ref_key:"requestBodySectionRef",ref:v,title:"Full Request Body",subtitle:F.value,"section-id":"request_body",expanded:J("request_body"),"scroll-container":p.value,onToggle:j[9]||(j[9]=Q=>L("request_body"))},{default:ge(()=>[P(vt,{json:ae.value,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])]),_:1},8,["subtitle","expanded","scroll-container"])):M("",!0)],512),[[Ke,l.value==="request"]]),Me(e("div",null,[ee.value.length>0?(a(),o("div",F0,[e("div",B0,V(ee.value.length>1?`Errors (${ee.value.length})`:"Error"),1),e("div",q0,[(a(!0),o(me,null,ye(ee.value,(Q,be)=>(a(),o("div",{key:be,class:"border border-red-300 dark:border-red-700 rounded overflow-hidden"},[e("div",z0,V(Q.type||"error"),1),e("pre",H0,V(Q.message),1)]))),128))])])):t.log.error?(a(),o("div",W0,[e("div",J0," Error "+V(t.log.error_type?`(${t.log.error_type})`:""),1),e("pre",K0,V(t.log.error),1)])):M("",!0),t.log.is_complete||!t.log.error?(a(),o("div",G0,[j[25]||(j[25]=e("div",{class:"text-xs font-semibold mb-1"},"Response Stats",-1)),e("table",X0,[e("tbody",null,[e("tr",Y0,[j[18]||(j[18]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Finish Reason ",-1)),e("td",Z0,[!t.log.is_complete&&!t.log.finish_reason?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",Q0,V(t.log.finish_reason||"—"),1))])]),e("tr",ep,[j[19]||(j[19]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Input Tokens ",-1)),e("td",tp,[!t.log.is_complete&&!t.log.input_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",ap,V(t.log.input_tokens||"—"),1))])]),t.log.cached_tokens||!t.log.is_complete?(a(),o("tr",op,[j[20]||(j[20]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Cached Tokens ",-1)),e("td",lp,[!t.log.is_complete&&!t.log.cached_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",sp,V(t.log.cached_tokens||0),1))])])):M("",!0),e("tr",np,[j[21]||(j[21]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Output Tokens ",-1)),e("td",rp,[!t.log.is_complete&&!t.log.output_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",ip,V(t.log.output_tokens||"—"),1))])]),t.log.reasoning_tokens&&t.log.reasoning_tokens>0?(a(),o("tr",dp,[j[22]||(j[22]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Reasoning Tokens ",-1)),e("td",up,V(t.log.reasoning_tokens),1)])):M("",!0),e("tr",cp,[j[23]||(j[23]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Total Tokens ",-1)),e("td",pp,[!t.log.is_complete&&!t.log.total_tokens?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",vp,V(t.log.total_tokens||"—"),1))])]),e("tr",null,[j[24]||(j[24]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Total Cost ",-1)),e("td",mp,[!t.log.is_complete&&!t.log.cost_total?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",fp,V(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))])])])])])):M("",!0),te.value.length>0?(a(),o("div",hp,[e("div",gp," Tools Called ("+V(te.value.length)+") ",1),e("div",bp,[(a(!0),o(me,null,ye(te.value,Q=>(a(),o("div",{key:Q.id,class:"border-b border-neutral-200 dark:border-neutral-800 last:border-b-0"},[e("button",{onClick:be=>H(Q.id),class:"w-full px-2 py-1.5 text-left hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors flex items-center justify-between text-xs"},[e("div",yp,[e("span",kp,V(Q.name),1),Q.isProvider?(a(),o("span",wp," provider ")):M("",!0),Q.isProvider&&Q.status?(a(),o("span",{key:1,class:oe([Q.status==="completed"?"text-green-600 dark:text-green-400":Q.status==="failed"?"text-red-600 dark:text-red-400":"text-yellow-600 dark:text-yellow-400","text-[10px]"])},V(Q.status),3)):M("",!0)]),e("span",_p,V(r.value.has(Q.id)?"▼":"▶"),1)],8,xp),Me(e("div",{class:oe(["px-2 py-2 border-t border-neutral-200 dark:border-neutral-800",Q.isProvider?"bg-purple-50 dark:bg-purple-900/10":"bg-white dark:bg-neutral-950"])},[Q.isProvider?(a(),o(me,{key:1},[e("div",Ap,[j[31]||(j[31]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Provider Tool ID ",-1)),e("div",Pp,V(Q.id),1)]),Q.providerType==="web_search"&&Q.result?.actions?(a(),o("div",Dp,[(a(!0),o(me,null,ye(Q.result.actions,(be,De)=>(a(),o("div",{key:De,class:"mb-2"},[be.type==="search"?(a(),o("div",jp,[j[32]||(j[32]=e("span",{class:"font-medium"},"Searched:",-1)),$e(' "'+V(be.query)+'" ',1)])):M("",!0),be.type==="open"?(a(),o("div",Op,[j[33]||(j[33]=e("span",{class:"font-medium"},"Opened:",-1)),e("a",{href:be.url,target:"_blank",class:"text-blue-600 hover:underline ml-1"},V(be.url),9,Up)])):M("",!0),be.sources?.length?(a(),o("div",Rp,[(a(!0),o(me,null,ye(be.sources.slice(0,5),(ie,ce)=>(a(),o("a",{key:ce,href:ie.url,target:"_blank",class:"block text-blue-600 hover:underline text-xs truncate"},V(ie.title||ie.url),9,Np))),128)),be.sources.length>5?(a(),o("span",Fp," ... and "+V(be.sources.length-5)+" more ",1)):M("",!0)])):M("",!0)]))),128))])):M("",!0),Q.providerType==="image_generation"?(a(),o("div",Bp,[Q.result?.imagePath?(a(),o("span",qp,[j[34]||(j[34]=$e(" Stored at: ",-1)),e("span",zp,V(Q.result.imagePath),1)])):(a(),o("span",Hp," See Generated Images section below "))])):M("",!0),Q.providerType==="code_interpreter"&&Q.result?.output?(a(),o("div",Wp,[j[35]||(j[35]=e("div",{class:"font-medium text-neutral-600 dark:text-neutral-400 mb-1"},"Output:",-1)),e("pre",Jp,V(Q.result.output),1)])):M("",!0),Q.providerType==="file_search"&&Q.result?.results?.length?(a(),o("div",Kp,[e("div",Gp," Found "+V(Q.result.results.length)+" result(s) ",1)])):M("",!0)],64)):(a(),o(me,{key:0},[e("div",$p,[j[26]||(j[26]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Tool Call ID ",-1)),e("div",Cp,V(Q.id),1)]),e("div",Tp,[j[27]||(j[27]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Function Name ",-1)),e("div",Sp,V(Q.function?.name),1)]),e("div",Vp,[j[28]||(j[28]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Arguments ",-1)),e("div",Mp,[P(xt,{code:k(Q.function?.arguments||"{}"),language:"json"},null,8,["code"])])]),B.value.has(Q.id)?(a(),o("div",Ip,[j[29]||(j[29]=e("div",{class:"font-semibold text-green-600 dark:text-green-400 mb-1"}," Result ",-1)),e("pre",Ep,V(B.value.get(Q.id)?.content||"No content"),1)])):(a(),o("div",Lp,[...j[30]||(j[30]=[e("div",{class:"font-semibold text-neutral-500 dark:text-neutral-500 mb-1"}," Result ",-1),e("div",{class:"text-xs text-neutral-500 dark:text-neutral-500 italic"}," No result available ",-1)])]))],64))],2),[[Ke,r.value.has(Q.id)]])]))),128))])])):M("",!0),w.value.length>0?(a(),o("div",Xp,[e("div",Yp," Generated Images ("+V(w.value.length)+") ",1),e("div",Zp,[j[36]||(j[36]=e("div",{class:"px-2 py-1.5 bg-emerald-100 dark:bg-emerald-900/30 text-xs text-emerald-800 dark:text-emerald-200 border-b border-emerald-300 dark:border-emerald-700"}," Images returned by the model ",-1)),e("div",Qp,[(a(!0),o(me,null,ye(w.value,(Q,be)=>(a(),o("div",{key:be,class:"relative"},[Q.image_url?.url?(a(),o("img",{key:0,src:x(Q.image_url.url)||Q.image_url.url,alt:`Generated image ${be+1}`,class:"max-w-[300px] max-h-[300px] rounded border border-emerald-200 dark:border-emerald-800 object-contain"},null,8,ev)):(a(),o("div",tv," No URL "))]))),128))])])])):M("",!0),t.log.reasoning_content?(a(),o("div",av,[e("div",ov,[e("button",{onClick:A,class:"w-full px-2 py-1.5 bg-accent-100 dark:bg-accent-900/30 text-xs text-accent-800 dark:text-accent-200 flex items-center justify-between hover:bg-accent-200 dark:hover:bg-accent-900/50 transition-colors"},[j[37]||(j[37]=e("div",{class:"flex items-center gap-2"},[e("span",{class:"font-semibold"},"Reasoning Content"),e("span",{class:"text-accent-600 dark:text-accent-400 font-normal"}," Internal reasoning output (not displayed to users) ")],-1)),e("span",lv,V(g.value?"▶":"▼"),1)]),Me(e("pre",{class:"text-xs p-2 overflow-x-auto whitespace-pre-wrap max-h-96 text-accent-900 dark:text-accent-100 border-t border-accent-300 dark:border-accent-700"},V(T.value),513),[[Ke,!g.value]])])])):M("",!0),N.value.length>0?(a(),o("div",sv,[e("div",nv,[e("button",{onClick:$,class:"w-full px-2 py-1.5 bg-purple-100 dark:bg-purple-900/30 text-xs text-purple-800 dark:text-purple-200 flex items-center justify-between hover:bg-purple-200 dark:hover:bg-purple-900/50 transition-colors"},[e("div",rv,[j[38]||(j[38]=e("span",{class:"font-semibold"},"Reasoning Details",-1)),e("span",iv,V(N.value.length)+" blocks ",1),j[39]||(j[39]=e("span",{class:"text-purple-600 dark:text-purple-400 font-normal"}," Structured reasoning from OpenRouter ",-1))]),e("span",dv,V(d.value?"▶":"▼"),1)]),Me(e("div",uv,[(a(!0),o(me,null,ye(N.value,(Q,be)=>(a(),o("div",{key:be,class:"p-2"},[e("div",cv,[e("span",pv,V(Q.type||"unknown"),1),Q.id?(a(),o("span",vv," ID: "+V(Q.id),1)):M("",!0),Q.format?(a(),o("span",mv," Format: "+V(Q.format),1)):M("",!0),Q.index!==void 0?(a(),o("span",fv," Index: "+V(Q.index),1)):M("",!0)]),Q.type==="reasoning.summary"&&Q.summary?(a(),o("div",hv,[j[40]||(j[40]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Summary: ",-1)),e("div",gv,V(Q.summary),1)])):M("",!0),Q.type==="reasoning.encrypted"&&Q.data?(a(),o("div",bv,[j[41]||(j[41]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Encrypted Data: ",-1)),e("div",xv,V(Q.data),1)])):M("",!0),Q.type==="reasoning.text"&&Q.text?(a(),o("div",yv,[j[43]||(j[43]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Reasoning Text: ",-1)),e("div",kv,V(Q.text),1),Q.signature?(a(),o("div",wv,[j[42]||(j[42]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Signature: ",-1)),e("div",_v,V(Q.signature),1)])):M("",!0)])):M("",!0),["reasoning.summary","reasoning.encrypted","reasoning.text"].includes(Q.type)?M("",!0):(a(),o("div",$v,[e("pre",Cv,V(JSON.stringify(Q,null,2)),1)]))]))),128))],512),[[Ke,!d.value]])])])):M("",!0),t.log.response_body?(a(),o("div",Tv,[j[44]||(j[44]=e("div",{class:"text-xs font-semibold mb-1"},"Full Response Body",-1)),e("div",Sv,[P(vt,{json:t.log.response_body,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])])])):M("",!0)],512),[[Ke,l.value==="response"]])])],512))}}),Mv={class:"flex flex-col h-full"},Iv={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},Ev={class:"flex items-center justify-between"},Lv={class:"flex items-center gap-2"},Av={class:"flex items-center gap-2"},Pv={key:0,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},Dv={key:1,class:"flex justify-center py-12"},jv={key:2,class:"text-red-600 dark:text-red-400 text-center py-12"},Ov={key:3,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},Uv={key:4},Rv={key:0,class:"border-b border-neutral-300 dark:border-neutral-700 bg-white dark:bg-black sticky top-0 z-10"},Nv=["disabled"],Fv={key:1},Bv={key:2},qv={key:3},zv={class:"w-full text-sm"},Hv=["onClick","onMouseenter"],Wv={class:"px-3 py-2 text-xs"},Jv={class:"flex items-center gap-1"},Kv={key:0,class:"text-neutral-400 dark:text-neutral-600 mr-1"},Gv={key:3},Xv={class:"px-3 py-2"},Yv={class:"flex items-center gap-2"},Zv={key:0,class:"text-red-600 dark:text-red-400",title:"Error"},Qv={class:"font-mono text-xs"},em={class:"px-3 py-2 font-mono text-xs"},tm={key:1},am={key:1},om={key:0,class:"log-details-panel relative shrink-0 bg-neutral-100 dark:bg-neutral-950 border-t border-neutral-300 dark:border-neutral-700 overflow-hidden"},lm={class:"m-2 border h-[calc(100%-1rem)] border-neutral-300 shrink-0 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 overflow-auto"},sm={key:0,class:"flex flex-col items-center justify-center h-full gap-3 text-neutral-500 dark:text-neutral-400"},nm={key:2,class:"absolute inset-0 bg-white/50 dark:bg-black/50 flex items-center justify-center"},qt=20,rm=20,im=pe({__name:"LogsPane",props:{threadId:{},selectedLogId:{},hoveredLogId:{}},emits:["collapse","logClick","logHover","logsLoaded"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(0),r=m(qt),{logs:c,hasMore:f,isFetching:g,error:d,wsConnected:p,wsError:h,connectWebSocket:_,disconnectWebSocket:b,refetch:v}=Tc(W(()=>i.threadId),{limit:W(()=>r.value),offset:W(()=>u.value),enableWebSocket:!0,order:"desc"}),y=m([]),x=m(!0),k=m(null),D=m(null),q=m(!1),B=m(!1),N=m(new Map),T=async()=>{await Ce(),D.value&&(D.value.scrollTop=D.value.scrollHeight)},w=m(null);ve(c,async ie=>{if(u.value===0)y.value=[...ie].reverse(),x.value&&y.value.length>0&&(await T(),x.value=!1);else{const ce=[...ie].reverse(),ue=new Map;y.value.forEach(we=>ue.set(we.id,we)),ce.forEach(we=>ue.set(we.id,we)),y.value=Array.from(ue.values()).sort((we,ke)=>we.created_at-ke.created_at)}},{deep:!0,immediate:!0}),ve(g,(ie,ce)=>{if(ce&&!ie&&u.value===0&&i.threadId&&w.value!==i.threadId&&y.value.length>0){w.value=i.threadId;const ue=y.value[y.value.length-1];l("logsLoaded",ue?.id??null)}});const{logDetails:K,isFetching:te}=Sc(W(()=>i.threadId),W(()=>k.value)),le=W(()=>{if(!k.value)return null;const ce=y.value.find(ue=>ue.id===k.value);return ce?K.value?{...K.value,...ce}:ce:null}),H=W(()=>k.value?De.value.findIndex(ie=>ie.id===k.value):-1),A=W(()=>H.value>0),$=W(()=>H.value>=0&&H.value<De.value.length-1),L=()=>{if(A.value){const ie=De.value[H.value-1];E(ie)}},J=()=>{if($.value){const ie=De.value[H.value+1];E(ie)}},ee=ie=>{if(!D.value)return;const ce=N.value.get(ie);if(!ce)return;const ue=D.value,we=ce.getBoundingClientRect(),ke=ue.getBoundingClientRect(),Le=ue.querySelectorAll(".sticky");let Fe=0;Le.forEach(fe=>{Fe+=fe.getBoundingClientRect().height}),Fe+=16;const Re=we.top<ke.top+Fe,xe=we.bottom>ke.bottom;Re?ue.scrollBy({top:we.top-ke.top-Fe,behavior:"smooth"}):xe&&ue.scrollBy({top:we.bottom-ke.bottom,behavior:"smooth"})},E=ie=>{l("logClick",ie.id),k.value=ie.id},R=(ie,ce)=>{ce?N.value.set(ie,ce):N.value.delete(ie)};ve(k,async ie=>{ie&&(await Ce(),ee(ie))}),ve(()=>i.selectedLogId,ie=>{ie&&(k.value=ie)},{immediate:!0});const Y=ie=>{k.value=ie},ne=async ie=>{await Ce();const ce=N.value.get(ie);if(ce&&D.value){const ue=D.value,we=ce.getBoundingClientRect(),ke=ue.getBoundingClientRect(),Le=ue.querySelector("thead"),Fe=ue.querySelector(":scope > div > div.sticky");let Re=0;Le&&(Re+=Le.getBoundingClientRect().height),Fe&&(Re+=Fe.getBoundingClientRect().height),Re+=40;const xe=we.top<ke.top+Re,fe=we.bottom>ke.bottom;xe?ue.scrollBy({top:we.top-ke.top-Re,behavior:"smooth"}):fe&&ue.scrollBy({top:we.bottom-ke.bottom,behavior:"smooth"})}},O=ie=>{if(ie.length===0)return;const ce=new Set(ie);y.value=y.value.filter(ue=>!ce.has(ue.id))},S=m(!1),C=ie=>y.value.some(ce=>ce.id===ie),U=ie=>y.value.find(ce=>ce.id===ie)??null,I=(ie,ce=3e3)=>new Promise(ue=>{const we=Date.now(),ke=ve(y,()=>{y.value.length!==ie&&(ke(),ue(!0))},{deep:!0}),Le=setInterval(()=>{y.value.length!==ie?(clearInterval(Le),ke(),ue(!0)):Date.now()-we>ce&&(clearInterval(Le),ke(),ue(!1))},50)});n({scrollToLog:ne,selectLogById:Y,removeLogsByIds:O,loadUntilLogId:async ie=>{if(C(ie))return!0;if(!f.value)return!1;S.value=!0;const ce=100,ue=50;try{let we=0;for(;f.value&&!C(ie)&&we<ue;){we++;const ke=y.value.length;if(u.value+=r.value,r.value=ce,await v(),!await I(ke))break}return C(ie)}finally{S.value=!1}},hasLog:C,getLog:U,setLoadingForLog:ie=>{S.value=ie},waitForLogRow:async(ie,ce=2e3)=>{const ue=Date.now();for(;Date.now()-ue<ce;){if(N.value.has(ie))return!0;if(!De.value.some(ke=>ke.id===ie)){await Ce(),await new Promise(ke=>setTimeout(ke,16));continue}await Ce(),await new Promise(ke=>setTimeout(ke,16))}return!1}});const z=async()=>{if(B.value||!f.value||g.value)return;B.value=!0;const ie=D.value?.scrollHeight||0;if(u.value+=r.value,r.value=rm,await v(),await Ce(),D.value){const ce=D.value.scrollHeight;D.value.scrollTop+=ce-ie}B.value=!1};ve(()=>i.threadId,async ie=>{ie?(b(),_()):b(),u.value=0,r.value=qt,y.value=[],k.value=null,q.value=!1,x.value=!0},{immediate:!0}),ve(y,async()=>{q.value||await T()},{deep:!0});const j=()=>{if(!D.value)return;const{scrollTop:ie,scrollHeight:ce,clientHeight:ue}=D.value,we=ce-ie-ue<50;q.value=!we},Q=ie=>{const ce=[];if(ie.tools_called)try{const ue=JSON.parse(ie.tools_called);Array.isArray(ue)&&ce.push(...ue)}catch{}if(ie.provider_tools)try{const ue=JSON.parse(ie.provider_tools);Array.isArray(ue)&&ce.push(...ue.map(we=>we.type))}catch{}return ce.length>0?ce.join(", "):"—"},be=ie=>ie==null?"—":`$${ie.toFixed(6)}`,De=W(()=>{const ie=new Map,ce=new Map;y.value.forEach(ke=>{ie.set(ke.id,ke);const Le=ke.parent_log_id;Le&&(ce.has(Le)||ce.set(Le,[]),ce.get(Le).push(ke))});const ue=[],we=(ke,Le)=>{ue.push({...ke,depth:Le}),(ce.get(ke.id)||[]).forEach(Re=>{we(Re,Le+1)})};return y.value.forEach(ke=>{ke.parent_log_id||we(ke,0)}),ue});return(ie,ce)=>(a(),o("div",Mv,[e("div",Iv,[e("div",Ev,[e("div",Lv,[P(X(la),{size:18,class:"shrink-0"}),ce[4]||(ce[4]=e("h2",{class:"text-base font-bold"},"Logs",-1)),t.threadId?(a(),se(Vt,{key:0,connected:X(p),error:X(h)},null,8,["connected","error"])):M("",!0)]),e("div",Av,[e("button",{onClick:ce[0]||(ce[0]=ue=>l("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[P(X(Tt),{size:20})])])])]),e("div",{ref_key:"logsScrollContainer",ref:D,class:"logs-list-container flex-1 overflow-y-auto overflow-x-auto",onScroll:j},[t.threadId?X(g)&&u.value===0?(a(),o("div",Dv,[P(Te)])):X(d)?(a(),o("div",jv," Error loading logs: "+V(X(d)),1)):y.value.length===0?(a(),o("div",Ov," No logs yet ")):(a(),o("div",Uv,[X(f)?(a(),o("div",Rv,[e("button",{onClick:z,disabled:B.value||S.value,type:"button",class:"w-full px-3 py-2 text-xs font-medium text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"},[B.value||S.value?(a(),se(Te,{key:0,size:"xs"})):M("",!0),S.value?(a(),o("span",Fv,"Loading to find log...")):B.value?(a(),o("span",Bv,"Loading older logs...")):(a(),o("span",qv,"Load previous logs"))],8,Nv)])):M("",!0),e("table",zv,[e("thead",{class:oe(["border-b border-neutral-300 dark:border-neutral-700 sticky bg-white z-[10] dark:bg-black",{"top-0":!X(f),"top-[34px]":X(f)}])},[...ce[5]||(ce[5]=[e("tr",null,[e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Prompt"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Model"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Cost"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Tools Called"),e("th",{class:"text-right px-3 py-1.5 text-xs font-semibold"},"Called At")],-1)])],2),e("tbody",null,[(a(!0),o(me,null,ye(De.value,ue=>(a(),o("tr",{key:ue.id,ref_for:!0,ref:we=>R(ue.id,we),class:oe(["border-b border-neutral-200 dark:border-neutral-800 cursor-pointer transition-colors relative",{"last:border-b-0":le.value,"bg-red-50 dark:bg-red-950/20":ue.error,"bg-accent-100 dark:bg-accent-900 dark:text-white":k.value===ue.id,"ring-2 ring-inset ring-accent-400 dark:ring-accent-400":ue.id===i.selectedLogId||ue.id!==i.selectedLogId&&ue.id===i.hoveredLogId}]),onClick:we=>E(ue),onMouseenter:we=>l("logHover",ue.id),onMouseleave:ce[1]||(ce[1]=we=>l("logHover",null))},[e("td",Wv,[e("div",Jv,[ue.depth>0?(a(),o("span",Kv,"└─")):M("",!0),ue.retry_of_log_id?(a(),se(X(Qa),{key:1,size:14,class:"text-neutral-500 dark:text-neutral-400 flex-shrink-0"})):M("",!0),!ue.is_complete&&!ue.prompt_name?(a(),se(Te,{key:2,size:"xs"})):(a(),o("span",Gv,V(ue.prompt_name||"—"),1))])]),e("td",Xv,[e("div",Yv,[ue.error?(a(),o("span",Zv," ✕ ")):M("",!0),e("span",Qv,V(ue.model_name||ue.model),1)])]),e("td",em,[!ue.is_complete&&!ue.cost_total?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",tm,V(be(ue.cost_total)),1))]),e("td",{class:oe(["px-3 py-2 text-xs",k.value===ue.id?"text-neutral-800 dark:text-neutral-100":"text-neutral-600 dark:text-neutral-400"])},[!ue.is_complete&&Q(ue)==="—"?(a(),se(Te,{key:0,size:"xs"})):(a(),o("span",am,V(Q(ue)),1))],2),e("td",{class:oe(["px-3 py-2 text-right text-xs",k.value===ue.id?"text-neutral-800 dark:text-neutral-100":"text-neutral-500 dark:text-neutral-500"])},[P(mt,{timestamp:ue.created_at},null,8,["timestamp"])],2)],42,Hv))),128))])])])):(a(),o("div",Pv," Select a thread to view logs "))],544),P(Xe,{name:"slide-up",onAfterEnter:ce[3]||(ce[3]=()=>k.value&&ee(k.value))},{default:ge(()=>[le.value||S.value&&k.value?(a(),o("div",om,[e("div",lm,[S.value&&!le.value?(a(),o("div",sm,[P(Te),ce[6]||(ce[6]=e("span",{class:"text-sm"},"Loading log...",-1))])):le.value?(a(),se(Vv,{key:1,log:le.value,"thread-id":t.threadId,"has-previous":A.value,"has-next":$.value,onClose:ce[2]||(ce[2]=ue=>k.value=null),onPrevious:L,onNext:J},null,8,["log","thread-id","has-previous","has-next"])):M("",!0),X(te)&&le.value?(a(),o("div",nm,[P(Te)])):M("",!0)])])):M("",!0)]),_:1})]))}}),dm=tt(im,[["__scopeId","data-v-5b7c3aa9"]]),um={class:"space-y-4"},cm={key:0,class:"p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded text-sm text-red-800 dark:text-red-200"},pm={class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},vm={key:0},mm={key:1},fm={key:1,class:"space-y-4 p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},hm={key:3,class:"flex items-center gap-2"},gm=["onUpdate:modelValue","id"],bm=["for"],xm={key:0,class:"text-red-500"},ym={key:5,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-1"},km={key:2,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg text-center text-sm text-neutral-500"},wm={key:3,class:"space-y-4"},_m={key:0,class:"p-4 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-lg"},$m={class:"space-y-3"},Cm={key:0,class:"text-xs text-amber-500 dark:text-amber-400 mt-1"},Tm={key:1,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},Sm={key:4,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg text-center text-sm text-neutral-500"},Vm={key:5},Mm={key:0,class:"space-y-3 mb-4 max-h-64 overflow-y-auto p-2"},Im={class:"text-xs font-medium mb-1 opacity-70"},Em={class:"text-sm whitespace-pre-wrap"},Lm=["onClick"],Am={key:1,class:"text-center py-8 text-neutral-500 dark:text-neutral-400 text-sm"},Pm={class:"space-y-2"},Dm={class:"flex items-stretch border border-black dark:border-neutral-300 rounded overflow-hidden bg-white dark:bg-neutral-900"},jm=["disabled","title"],Om={class:"flex-1 relative"},Um=["disabled","title"],Rm={class:"text-xs text-neutral-500 dark:text-neutral-400"},Nm={class:"flex justify-between"},Fm=["disabled"],Bm=["disabled"],qm=pe({__name:"CreateThreadModal",props:{modelValue:{type:Boolean},editThread:{}},emits:["update:modelValue","thread-created","thread-updated"],setup(t,{emit:n}){const s=t,i=n,l=W(()=>!!s.editThread),u=m(""),r=m(""),c=m({}),f=m([]),g=m(""),d=m(!1),p=m(""),h=m(null),_=m({}),b=m([]),v=m(!1),{data:y,isFetching:x,execute:k}=Ue(de("/api/agents"),{immediate:!1}).json(),D=W(()=>y.value?(y.value?.agents||[]).map(C=>({value:C.id,label:C.title})):[]),q=W(()=>!u.value||!y.value?null:(y.value?.agents||[]).find(C=>C.id===u.value)),B=W(()=>q.value&&q.value.type==="ai_human"?"AI":"Side A"),N=W(()=>q.value&&q.value.type==="ai_human"?"Human":"Side B"),{data:T,isFetching:w,execute:K}=Ue(W(()=>q.value?.side_a_system_prompt?de(`/api/prompts/${q.value.side_a_system_prompt}`):""),{immediate:!1}).json(),te=W(()=>{if(!T.value)return null;const S=T.value?.required_schema;if(!S)return null;try{return typeof S=="string"?JSON.parse(S):S}catch{return null}}),le=W(()=>b.value.filter(S=>S.required&&!S.value&&!_.value[S.name])),H=W(()=>b.value.filter(S=>S.value!==void 0||!S.required)),A=W(()=>b.value.length>0),$=async S=>{if(!S){b.value=[],_.value={};return}v.value=!0;try{const C=await fetch(de(`/api/agents/${S}/tenvs`));if(C.ok){const U=await C.json();b.value=U.tenvs||[],_.value=U.merged||{}}else b.value=[],_.value={}}catch(C){console.error("Error fetching agent tenvs:",C),b.value=[],_.value={}}finally{v.value=!1}},L=W(()=>{const S=te.value;return!S||!S.properties?[]:Object.entries(S.properties).map(([C,U])=>({name:C,type:U.type||"string",description:U.description||"",required:S.required?.includes(C)||!1,enum:U.enum}))});ve(u,async S=>{S&&q.value?.side_a_system_prompt?(await K(),c.value={}):c.value={},S?await $(S):(b.value=[],_.value={})});const J=()=>{const S=h.value;S&&(S.style.height="auto",S.style.height=`${S.scrollHeight}px`)},ee=S=>{g.value.trim()&&(f.value.push({id:crypto.randomUUID(),role:S,content:g.value.trim()}),g.value="",setTimeout(()=>J(),0))},E=S=>{f.value=f.value.filter(C=>C.id!==S)},R=()=>{u.value="",r.value="",c.value={},f.value=[],g.value="",p.value="",_.value={},b.value=[]},Y=()=>{s.editThread&&(u.value=s.editThread.agent_id,r.value=s.editThread.tags?.join(", ")||"")},ne=async()=>{if(!u.value){p.value="Please select an agent";return}if(!l.value&&L.value.length>0){for(const S of L.value)if(S.required&&!c.value[S.name]){p.value=`Please provide ${S.name}`;return}}if(!l.value&&le.value.length>0){for(const S of le.value)if(!_.value[S.name]){p.value=`Please provide required environment variable: ${S.name}`;return}}d.value=!0,p.value="";try{const S=r.value.split(",").map(C=>C.trim()).filter(C=>C.length>0);if(l.value){const C=await fetch(de(`/api/threads/${s.editThread.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:S})});if(!C.ok){const U=await C.json();throw new Error(U.error||"Failed to update thread")}i("thread-updated"),R(),i("update:modelValue",!1)}else{const C={agent_id:u.value,tags:S.length>0?S:void 0};f.value.length>0&&(C.initial_messages=f.value.map(F=>({role:F.role,content:F.content}))),Object.keys(c.value).length>0&&(C.data=c.value),Object.keys(_.value).length>0&&(C.tenvs=_.value);const U=await fetch(de("/api/threads"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(C)});if(!U.ok){const F=await U.json();throw new Error(F.error||"Failed to create thread")}const ae=(await U.json()).threadId;if(!ae)throw new Error("Thread created but ID not found in response");i("thread-created",ae),R(),i("update:modelValue",!1)}}catch(S){console.error(`Error ${l.value?"updating":"creating"} thread:`,S),p.value=S.message||`Failed to ${l.value?"update":"create"} thread`}finally{d.value=!1}},O=()=>{R(),i("update:modelValue",!1)};return ve(()=>s.modelValue,async S=>{S&&(await k(),R(),l.value&&Y())}),(S,C)=>(a(),se(He,{"model-value":t.modelValue,"onUpdate:modelValue":C[8]||(C[8]=U=>S.$emit("update:modelValue",U)),title:l.value?"Edit Thread":"Create New Thread",width:"max-w-3xl"},{footer:ge(()=>[e("div",Nm,[e("button",{onClick:O,type:"button",disabled:d.value,class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50"}," Cancel ",8,Fm),e("button",{onClick:ne,type:"button",disabled:d.value||X(x),class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity disabled:opacity-50"},[l.value?(a(),o(me,{key:0},[$e(V(d.value?"Updating...":"Update Thread"),1)],64)):(a(),o(me,{key:1},[$e(V(d.value?"Creating...":"Create Thread"),1)],64))],8,Bm)])]),default:ge(()=>[e("div",um,[p.value?(a(),o("div",cm,V(p.value),1)):M("",!0),e("div",null,[P(Se,{modelValue:u.value,"onUpdate:modelValue":C[0]||(C[0]=U=>u.value=U),label:"Agent",options:D.value,disabled:X(x)||l.value,placeholder:"Select an agent...",required:""},null,8,["modelValue","options","disabled"]),e("p",pm,[l.value?(a(),o("span",vm,"Agent cannot be changed after thread creation")):(a(),o("span",mm,"Choose which agent will handle this conversation"))])]),!l.value&&L.value.length>0&&!X(w)?(a(),o("div",fm,[C[9]||(C[9]=e("h4",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300"}," Required Information ",-1)),(a(!0),o(me,null,ye(L.value,U=>(a(),o("div",{key:U.name,class:"space-y-2"},[U.enum?(a(),se(Se,{key:0,modelValue:c.value[U.name],"onUpdate:modelValue":I=>c.value[U.name]=I,label:U.name,options:[{value:"",label:"Select..."},...U.enum.map(I=>({value:I,label:I}))],required:U.required},null,8,["modelValue","onUpdate:modelValue","label","options","required"])):U.type==="string"?(a(),se(Ee,{key:1,modelValue:c.value[U.name],"onUpdate:modelValue":I=>c.value[U.name]=I,label:U.name,placeholder:U.description,required:U.required},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])):U.type==="number"||U.type==="integer"?(a(),se(Ee,{key:2,modelValue:c.value[U.name],"onUpdate:modelValue":I=>c.value[U.name]=I,modelModifiers:{number:!0},label:U.name,placeholder:U.description,type:"number",required:U.required},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])):U.type==="boolean"?(a(),o("div",hm,[Me(e("input",{"onUpdate:modelValue":I=>c.value[U.name]=I,type:"checkbox",id:`field-${U.name}`,class:"w-4 h-4"},null,8,gm),[[sa,c.value[U.name]]]),e("label",{for:`field-${U.name}`,class:"text-sm"},[$e(V(U.name)+" ",1),U.required?(a(),o("span",xm,"*")):M("",!0)],8,bm)])):(a(),se(ya,{key:4,modelValue:c.value[U.name],"onUpdate:modelValue":I=>c.value[U.name]=I,label:U.name,placeholder:U.description||`Enter ${U.name} (JSON format)`,required:U.required,rows:3},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])),U.description?(a(),o("p",ym,V(U.description),1)):M("",!0)]))),128))])):M("",!0),!l.value&&X(w)?(a(),o("div",km," Loading agent requirements... ")):M("",!0),!l.value&&A.value&&!v.value?(a(),o("div",wm,[le.value.length>0?(a(),o("div",_m,[C[10]||(C[10]=e("h4",{class:"text-sm font-medium text-amber-800 dark:text-amber-200 mb-3"}," Required Environment Variables ",-1)),C[11]||(C[11]=e("p",{class:"text-xs text-amber-600 dark:text-amber-300 mb-3"}," These values are required by the agent's tools and must be provided. ",-1)),e("div",$m,[(a(!0),o(me,null,ye(le.value,U=>(a(),o("div",{key:U.name},[P(Ee,{"model-value":_.value[U.name]||"","onUpdate:modelValue":I=>_.value[U.name]=I,label:U.name,placeholder:U.description||"Enter value...",required:""},null,8,["model-value","onUpdate:modelValue","label","placeholder"]),U.source?(a(),o("p",Cm," Required by: "+V(U.source),1)):M("",!0)]))),128))])])):M("",!0),H.value.length>0?(a(),o("div",Tm,[C[12]||(C[12]=e("h4",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3"}," Environment Configuration ",-1)),C[13]||(C[13]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 mb-3"}," Values inherited from the agent. Click the lock icon to override. ",-1)),P(ka,{modelValue:_.value,"onUpdate:modelValue":C[1]||(C[1]=U=>_.value=U),inherited:H.value,"allow-custom":!0},null,8,["modelValue","inherited"])])):M("",!0)])):M("",!0),!l.value&&v.value?(a(),o("div",Sm," Loading environment configuration... ")):M("",!0),l.value?M("",!0):(a(),o("div",Vm,[C[16]||(C[16]=e("h4",{class:"text-sm font-medium mb-3"},"Initial Conversation",-1)),f.value.length>0?(a(),o("div",Mm,[(a(!0),o(me,null,ye(f.value,U=>(a(),o("div",{key:U.id,class:oe(["flex items-start gap-2",{"justify-start":U.role==="assistant","justify-end":U.role==="user"}])},[e("div",{class:oe(["max-w-[80%] rounded-2xl px-4 py-2 break-words",{"bg-black text-white dark:bg-white dark:text-black":U.role==="assistant","bg-neutral-200 text-black dark:bg-neutral-800 dark:text-white":U.role==="user"}])},[e("div",Im,V(U.role==="assistant"?B.value:N.value),1),e("div",Em,V(U.content),1)],2),e("button",{onClick:I=>E(U.id),type:"button",class:"text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-200 text-xs mt-2"}," ✕ ",8,Lm)],2))),128))])):(a(),o("div",Am," No messages yet. Add messages to start the conversation. ")),e("div",Pm,[e("div",Dm,[e("button",{onClick:C[2]||(C[2]=U=>ee("assistant")),type:"button",disabled:!g.value.trim(),title:`Add as ${B.value}`,class:"px-3 py-2 bg-black text-white dark:bg-white dark:text-black text-sm hover:opacity-90 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap inline-flex items-center gap-1 border-r border-black dark:border-neutral-300 flex-shrink-0"},[C[14]||(C[14]=e("svg",{class:"w-[1em] h-[1em]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 10l7-7m0 0l7 7m-7-7v18"})],-1)),e("span",null,V(B.value),1)],8,jm),e("div",Om,[Me(e("textarea",{"onUpdate:modelValue":C[3]||(C[3]=U=>g.value=U),placeholder:"Type a message...",class:"w-full px-3 py-2 bg-transparent border-0 font-mono text-sm focus:outline-none resize-none overflow-hidden",rows:"1",ref_key:"textareaRef",ref:h,onInput:J,onKeydown:[C[4]||(C[4]=wt(Ie(U=>ee("user"),["meta"]),["enter"])),C[5]||(C[5]=wt(Ie(U=>ee("user"),["ctrl"]),["enter"]))]},null,544),[[Oe,g.value]])]),e("button",{onClick:C[6]||(C[6]=U=>ee("user")),type:"button",disabled:!g.value.trim(),title:`Add as ${N.value}`,class:"px-3 py-2 bg-black text-white dark:bg-white dark:text-black text-sm hover:opacity-90 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap inline-flex items-center gap-1 border-l border-black dark:border-neutral-300 flex-shrink-0"},[C[15]||(C[15]=e("svg",{class:"w-[1em] h-[1em]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 10l7-7m0 0l7 7m-7-7v18"})],-1)),e("span",null,V(N.value),1)],8,Um)]),e("p",Rm," Type a message and click "+V(B.value)+" (left) or "+V(N.value)+" (right) to add. Or press Cmd+Enter (Mac) / Ctrl+Enter (Windows) to add as "+V(N.value)+". ",1)])])),e("div",null,[P(Ee,{modelValue:r.value,"onUpdate:modelValue":C[7]||(C[7]=U=>r.value=U),label:"Tags",placeholder:"research, urgent, production"},null,8,["modelValue"]),C[17]||(C[17]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Comma-separated tags to help organize and search threads ",-1))])])]),_:1},8,["model-value","title"]))}}),zm={class:"flex h-full overflow-hidden"},Hm={key:0,class:"flex flex-col items-center p-4"},Wm={key:0,class:"flex flex-col items-center p-4"},Jm={key:0,class:"flex flex-col items-center p-4"},zt=pe({__name:"ThreadsView",setup(t){const n=Ye(),s=lt(),i=m(typeof n.params.id=="string"?n.params.id:null),l=m({threadList:!1,messages:!1,logs:!1}),u=m(!1),r=m(null),c=m(null),{thread:f}=St(W(()=>i.value)),g=m(null),d=m(null),p=m(null),h=m(null),_=m(null),b=$=>{h.value=$,_.value=$},v=$=>{if(h.value=$,!$){_.value=null;return}_.value=$;const L=y.value,J=x.value;if(!L||!J||L.hasWorkblockForLogId($))return;let ee=$;const E=10;for(let R=0;R<E&&ee;R++){const Y=J.getLog(ee);if(!Y)break;const ne=Y.parent_log_id;if(!ne)break;if(L.hasWorkblockForLogId(ne)){_.value=ne;return}ee=ne}},y=m(null),x=m(null);ve(()=>n.params.id,$=>{i.value=typeof $=="string"?$:null,g.value=null,d.value=null,p.value=null});const k=$=>{s.push(`/threads/${$}`)},D=$=>{window.location.href="/threads"},q=()=>{f.value&&(r.value=f.value,u.value=!0)},B=()=>{r.value=null,u.value=!0},N=$=>{c.value?.refetch(),s.push(`/threads/${$}`)},T=()=>{window.location.reload()},w=$=>{l.value[$]=!l.value[$]},K=async($,L)=>{if(g.value=$,!L){d.value=null,p.value=null;return}const J=x.value;if(!J){d.value=L,p.value=L;return}const ee=!J.hasLog(L);if(ee&&J.setLoadingForLog(!0),d.value=L,p.value=L,ee&&!await J.loadUntilLogId(L)){console.warn(`Could not find log ${L} after loading all available logs`),J.setLoadingForLog(!1);return}if(!await J.waitForLogRow(L)){console.warn(`Log row ${L} not rendered in time`);return}J.scrollToLog(L),J.selectLogById(L)},te=$=>{d.value=$,p.value=$,g.value=null;const L=y.value,J=x.value;if(!L||!J)return;let ee=L.scrollToLogId($);if(ee)return;let E=$;const R=10;for(let Y=0;Y<R&&E;Y++){const ne=J.getLog(E);if(!ne)break;const O=ne.parent_log_id;if(!O)break;if(ee=L.scrollToLogId(O),ee){p.value=O;return}E=O}},le=$=>{$&&(d.value=$)},H=$=>{x.value?.removeLogsByIds($)},A=$=>{$&&!i.value&&s.push(`/threads/${$}`)};return($,L)=>(a(),o("div",zm,[e("div",{class:oe([l.value.threadList?"w-[60px]":"w-[320px]","border-r border-neutral-300 dark:border-neutral-700 flex-shrink-0 transition-all duration-200 flex flex-col min-h-0"])},[l.value.threadList?(a(),o("div",Hm,[e("button",{onClick:L[0]||(L[0]=J=>w("threadList")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Threads pane"},[P(X(Zt),{size:20})])])):(a(),se(Di,{key:1,ref_key:"threadListPaneRef",ref:c,"selected-thread-id":i.value,onSelectThread:k,onCollapse:L[1]||(L[1]=J=>w("threadList")),onCreateThread:B,onThreadsLoaded:A},null,8,["selected-thread-id"]))],2),e("div",{class:oe([l.value.messages?"w-[60px]":"w-[380px]","border-r border-neutral-300 dark:border-neutral-700 flex-shrink-0 overflow-hidden transition-all duration-200 flex flex-col min-h-0"])},[l.value.messages?(a(),o("div",Wm,[e("button",{onClick:L[2]||(L[2]=J=>w("messages")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Messages pane"},[P(X(oa),{size:20})])])):i.value?(a(),se(X(_o),{key:1,"thread-id":i.value,preload:!0,live:!0,"include-silent":!0,"use-workblocks":!0},{default:ge(()=>[P(Bt,{ref_key:"messagesPaneRef",ref:y,"thread-id":i.value,"selected-message-id":g.value,"selected-log-id":p.value,"hovered-log-id":_.value,onCollapse:L[3]||(L[3]=J=>w("messages")),onMessageClick:K,onMessageHover:b,onThreadDeleted:D,onEditThread:q,onLogsDeleted:H},null,8,["thread-id","selected-message-id","selected-log-id","hovered-log-id"])]),_:1},8,["thread-id"])):l.value.messages?M("",!0):(a(),se(Bt,{key:2,ref_key:"messagesPaneRef",ref:y,"thread-id":null,"selected-message-id":g.value,"selected-log-id":p.value,"hovered-log-id":_.value,onCollapse:L[4]||(L[4]=J=>w("messages")),onMessageClick:K,onMessageHover:b,onThreadDeleted:D,onEditThread:q,onLogsDeleted:H},null,8,["selected-message-id","selected-log-id","hovered-log-id"]))],2),e("div",{class:oe([l.value.logs?"w-[60px]":"flex-1","overflow-hidden transition-all duration-200 flex flex-col min-h-0"])},[l.value.logs?(a(),o("div",Jm,[e("button",{onClick:L[5]||(L[5]=J=>w("logs")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Logs pane"},[P(X(la),{size:20})])])):(a(),se(dm,{key:1,ref_key:"logsPaneRef",ref:x,"thread-id":i.value,"selected-log-id":d.value,"hovered-log-id":h.value,onCollapse:L[6]||(L[6]=J=>w("logs")),onLogClick:te,onLogHover:v,onLogsLoaded:le},null,8,["thread-id","selected-log-id","hovered-log-id"]))],2),P(qm,{modelValue:u.value,"onUpdate:modelValue":L[7]||(L[7]=J=>u.value=J),"edit-thread":r.value,onThreadCreated:N,onThreadUpdated:T},null,8,["modelValue","edit-thread"])]))}}),Km=pe({__name:"PromptsDataTable",emits:["add","edit","delete"],setup(t,{expose:n,emit:s}){const i=s,l=m([]),u=m(!1),r=[{key:"name",label:"Name",width:"w-1/4"},{key:"tool_description",label:"Description",width:"w-2/5"},{key:"model_name",label:"Model",width:"w-1/5",formatter:(d,p)=>d||p.model_id||"-"},{key:"created_at",label:"Created",width:"w-1/6",formatter:d=>d?new Date(d*1e3).toLocaleDateString():"-"}],c=[{icon:"edit",label:"Edit",handler:d=>i("edit",d)},{icon:"delete",label:"Delete",handler:async d=>{await g(d)},confirm:!0,confirmMessage:"Are you sure you want to delete this prompt?"}],f=async()=>{u.value=!0;try{const d=await fetch(de("/api/prompts"));if(d.ok){const p=await d.json();l.value=p.prompts||[]}}catch(d){console.error("Error fetching prompts:",d)}finally{u.value=!1}},g=async d=>{try{const p=await fetch(de(`/api/prompts/${d.id}`),{method:"DELETE"});if(p.ok)await f();else{const h=await p.json();alert(h.error||"Failed to delete prompt")}}catch(p){console.error("Error deleting prompt:",p),alert("Failed to delete prompt")}};return Ve(()=>{f()}),n({refresh:f}),(d,p)=>(a(),o("div",null,[P(Ge,{columns:r,data:l.value,actions:c,loading:u.value,"empty-message":"No prompts available. Create your first prompt to get started."},null,8,["data","loading"])]))}}),Gm={class:"space-y-4"},Xm={key:0,class:"mt-1 text-sm text-red-500"},Ym={key:1,class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"},Zm={class:"px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},Qm=["value"],ef=pe({__name:"PromptBasicInfo",props:{name:{},toolDescription:{}},emits:["update:name","update:toolDescription"],setup(t,{emit:n}){const s=t,i=n,l=m(""),u=c=>{let f=c.replace(/[^a-zA-Z0-9\s_]/g,"");return f=f.trim().toLowerCase().replace(/\s+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),f?/^[a-z][a-z0-9_]*$/.test(f)?l.value="":l.value="Name must start with a letter and contain only lowercase letters, numbers, and underscores":l.value="Name is required",f},r=c=>{const f=u(c);i("update:name",f)};return ve(()=>s.name,c=>{c&&u(c)},{immediate:!0}),(c,f)=>(a(),o("div",Gm,[e("div",null,[P(Ee,{"model-value":t.name,"onUpdate:modelValue":r,label:"Prompt Name",placeholder:"Enter a unique name (will be converted to snake_case)"},null,8,["model-value"]),l.value?(a(),o("p",Xm,V(l.value),1)):t.name?(a(),o("p",Ym,[f[1]||(f[1]=$e(" Will be saved as: ",-1)),e("code",Zm,V(t.name),1)])):M("",!0)]),e("div",null,[f[2]||(f[2]=e("label",{class:"block text-sm font-medium mb-2"},"Tool Description",-1)),e("textarea",{value:t.toolDescription,onInput:f[0]||(f[0]=g=>i("update:toolDescription",g.target.value)),placeholder:"Describe what this prompt does (shown when used as a tool)",class:"w-full px-3 py-2 border border-black dark:border-white rounded bg-transparent resize-none",rows:"3"},null,40,Qm)])]))}}),tf={class:"space-y-4"},af=pe({__name:"PromptModelSelect",props:{modelValue:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=n,i=m([]),l=m(!1),u=W(()=>i.value.map(c=>({value:c.id,label:c.name,description:c.model||c.provider,icon:c.provider?`/api/providers/${c.provider}/icon?model=${encodeURIComponent(c.model||"")}`:void 0}))),r=async()=>{l.value=!0;try{const c=await fetch(de("/api/models"));if(c.ok){const f=await c.json();i.value=f.models||[]}}catch(c){console.error("Error fetching models:",c)}finally{l.value=!1}};return Ve(()=>{r()}),(c,f)=>(a(),o("div",tf,[P(Se,{"model-value":t.modelValue,"onUpdate:modelValue":f[0]||(f[0]=g=>s("update:modelValue",g)),options:u.value,label:"Model",placeholder:"Select a model for this prompt","search-placeholder":"Search models...",loading:l.value},null,8,["model-value","options","loading"])]))}}),of=["data-property-id","data-nested-property-id"],lf={class:"p-3 space-y-3"},sf={class:"flex items-start gap-2"},nf={key:0,class:"drag-handle cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400 mt-2"},rf={class:"flex-1 grid grid-cols-1 md:grid-cols-3 gap-2"},df={class:"flex items-center gap-2 mt-2"},uf=["disabled"],cf={key:0,class:"ml-6"},pf={key:0,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg space-y-2"},vf={class:"flex items-center justify-between mb-2"},mf=["disabled"],ff={key:0,class:"space-y-1"},hf=["onClick","disabled"],gf={key:1,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},bf={class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"},xf={class:"space-y-2"},yf={class:"flex items-center justify-between"},kf=["disabled"],wf={class:"space-y-2"},_f={key:2,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},$f={key:0,class:"mb-2"},Cf=["disabled"],Tf={key:1,class:"space-y-2"},Sf=pe({__name:"PropertyEditor",props:We({propertyId:{},isNested:{type:Boolean,default:!1},parentId:{},disabled:{type:Boolean,default:!1},enableDrag:{type:Boolean,default:!0}},{modelValue:{required:!0},modelModifiers:{}}),emits:We(["remove","description-keydown","add-top-level"],["update:modelValue"]),setup(t,{emit:n}){const s=t,i=n,l=st(t,"modelValue"),u=m(!1);m();const r=[{value:"string",label:"String",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z'/%3E%3C/svg%3E"},{value:"number",label:"Number",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M7 20l4-16m2 16l4-16M6 9h14M4 15h14'/%3E%3C/svg%3E"},{value:"boolean",label:"Boolean",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'/%3E%3C/svg%3E"},{value:"object",label:"Object",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10'/%3E%3C/svg%3E"},{value:"array",label:"Array",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 6h16M4 10h16M4 14h16M4 18h16'/%3E%3C/svg%3E"},{value:"enum",label:"Enum",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4'/%3E%3C/svg%3E"},{value:"anyOf",label:"Any Of (Multiple Types)",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z'/%3E%3C/svg%3E"}],c=W(()=>["object","array","enum","anyOf"].includes(l.value.type));ve(()=>l.value.type,async(b,v)=>{if(["object","array","enum","anyOf"].includes(b)&&(u.value=!0,b==="anyOf"&&!l.value.anyOf&&(l.value.anyOf=[]),b==="object"&&!l.value.properties&&(l.value.properties=[{id:crypto.randomUUID(),name:"property1",type:"string",description:""}]),b==="array"&&!l.value.items&&(l.value.items={id:crypto.randomUUID(),name:"",type:"string",description:""}),b==="enum"&&!l.value.enum&&(l.value.enum=["value1"])),v!==void 0){await Ce();const y=s.isNested?`[data-nested-property-id="${s.propertyId}"] input[placeholder="Description"]`:`[data-property-id="${s.propertyId}"] input[placeholder="Description"]`,x=document.querySelector(y);x&&x.focus()}});const f=b=>{b.shiftKey&&l.value.type==="object"&&l.value.properties?h():i("add-top-level")},g=()=>{l.value.items||(l.value.items={id:crypto.randomUUID(),name:"",type:"string",description:""})},d=()=>{l.value.enum||(l.value.enum=[]),l.value.enum.push(`value${l.value.enum.length+1}`)},p=b=>{l.value.enum&&l.value.enum.splice(b,1)},h=async()=>{const b={id:crypto.randomUUID(),name:l.value.type==="anyOf"?"":`property${(l.value.properties?.length||l.value.anyOf?.length||0)+1}`,type:"string",description:""};l.value.type==="anyOf"?(l.value.anyOf||(l.value.anyOf=[]),l.value.anyOf.push(b)):(l.value.properties||(l.value.properties=[]),l.value.properties.push(b)),await Ce();const v=document.querySelector(`[data-nested-property-id="${b.id}"] input[placeholder="Property name"]`);v&&(v.focus(),v.select())},_=b=>{l.value.type==="anyOf"&&l.value.anyOf?l.value.anyOf=l.value.anyOf.filter(v=>v.id!==b):l.value.properties&&(l.value.properties=l.value.properties.filter(v=>v.id!==b))};return(b,v)=>{const y=eo("PropertyEditor",!0);return a(),o("div",{"data-property-id":t.isNested?void 0:t.propertyId,"data-nested-property-id":t.isNested?t.propertyId:void 0,class:oe(["border rounded-lg",t.isNested?"border-neutral-100 dark:border-neutral-900":"border-neutral-200 dark:border-neutral-800"])},[e("div",lf,[e("div",sf,[t.enableDrag?(a(),o("div",nf,[...v[10]||(v[10]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})],-1)])])):M("",!0),e("div",rf,[P(Ee,{modelValue:l.value.name,"onUpdate:modelValue":v[0]||(v[0]=x=>l.value.name=x),placeholder:"Property name",disabled:t.disabled},null,8,["modelValue","disabled"]),P(Se,{modelValue:l.value.type,"onUpdate:modelValue":v[1]||(v[1]=x=>l.value.type=x),options:r,disabled:t.disabled},null,8,["modelValue","disabled"]),P(Ee,{modelValue:l.value.description,"onUpdate:modelValue":v[2]||(v[2]=x=>l.value.description=x),placeholder:"Description",disabled:t.disabled,onKeydown:v[3]||(v[3]=wt(Ie(x=>f(x),["prevent"]),["enter"]))},null,8,["modelValue","disabled"])]),e("div",df,[c.value?(a(),o("button",{key:0,onClick:v[4]||(v[4]=x=>u.value=!u.value),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors"},[(a(),o("svg",{class:oe(["w-4 h-4 transition-transform",u.value?"rotate-90":""]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[...v[11]||(v[11]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 5l7 7-7 7"},null,-1)])],2))])):M("",!0),e("button",{onClick:v[5]||(v[5]=x=>b.$emit("remove")),type:"button",disabled:t.disabled,class:"p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors disabled:opacity-50"},[...v[12]||(v[12]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,uf)])]),u.value&&c.value?(a(),o("div",cf,[l.value.type==="enum"?(a(),o("div",pf,[e("div",vf,[v[13]||(v[13]=e("h4",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400"}," Enum Values ",-1)),e("button",{onClick:d,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Add Value ",8,mf)]),l.value.enum?(a(),o("div",ff,[(a(!0),o(me,null,ye(l.value.enum,(x,k)=>(a(),o("div",{key:k,class:"flex items-center gap-2"},[P(Ee,{modelValue:l.value.enum[k],"onUpdate:modelValue":D=>l.value.enum[k]=D,placeholder:"Enum value",disabled:t.disabled,class:"flex-1"},null,8,["modelValue","onUpdate:modelValue","disabled"]),e("button",{onClick:D=>p(k),type:"button",disabled:t.disabled,class:"p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors disabled:opacity-50"},[...v[14]||(v[14]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,hf)]))),128))])):M("",!0)])):M("",!0),l.value.type==="object"||l.value.type==="anyOf"?(a(),o("div",gf,[e("h4",bf,V(l.value.type==="anyOf"?"Type Options":"Nested Properties"),1),e("div",xf,[e("div",yf,[e("button",{onClick:h,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Add "+V(l.value.type==="anyOf"?"Type Option":"Property"),9,kf)]),e("div",wf,[(a(!0),o(me,null,ye(l.value.type==="anyOf"?l.value.anyOf:l.value.properties,(x,k)=>(a(),se(y,{key:x.id,modelValue:(l.value.type==="anyOf"?l.value.anyOf:l.value.properties)[k],"onUpdate:modelValue":D=>(l.value.type==="anyOf"?l.value.anyOf:l.value.properties)[k]=D,"property-id":x.id,"is-nested":!0,"parent-id":t.propertyId,disabled:t.disabled,"enable-drag":!1,onRemove:D=>_(x.id),onAddTopLevel:v[6]||(v[6]=D=>i("add-top-level"))},null,8,["modelValue","onUpdate:modelValue","property-id","parent-id","disabled","onRemove"]))),128))])])])):M("",!0),l.value.type==="array"?(a(),o("div",_f,[v[15]||(v[15]=e("h4",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Array Item Type ",-1)),l.value.items?M("",!0):(a(),o("div",$f,[e("button",{onClick:g,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Define Item Type ",8,Cf)])),l.value.items?(a(),o("div",Tf,[P(y,{modelValue:l.value.items,"onUpdate:modelValue":v[7]||(v[7]=x=>l.value.items=x),"property-id":l.value.items.id,"is-nested":!0,"parent-id":t.propertyId,disabled:t.disabled,"enable-drag":!1,onRemove:v[8]||(v[8]=x=>l.value.items=null),onAddTopLevel:v[9]||(v[9]=x=>i("add-top-level"))},null,8,["modelValue","property-id","parent-id","disabled"])])):M("",!0)])):M("",!0)])):M("",!0)])],10,of)}}}),Vf={class:"space-y-2"},Mf=["disabled"],If=pe({__name:"PropertyList",props:We({disabled:{type:Boolean,default:!1},parentId:{},isNested:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["add-property","description-keydown"],["update:modelValue"]),setup(t,{expose:n,emit:s}){const i=t,l=s,u=st(t,"modelValue"),r=m();let c=!1;Ve(async()=>{}),Be(()=>{});const f=async()=>{if(c)return;c=!0;const d={id:crypto.randomUUID(),name:`property${u.value.length+1}`,type:"string",description:"",required:!1};u.value=[...u.value,d],await Ce();const p=i.parentId?`[data-nested-property-id="${d.id}"]`:`[data-property-id="${d.id}"]`,h=document.querySelector(`${p} input[placeholder="Property name"]`);h&&(h.focus(),h.select()),l("add-property"),c=!1},g=d=>{u.value=u.value.filter(p=>p.id!==d)};return n({addProperty:f}),(d,p)=>(a(),o("div",Vf,[e("div",{ref_key:"dragAreaRef",ref:r,class:"space-y-2"},[(a(!0),o(me,null,ye(u.value,h=>(a(),se(Sf,{key:h.id,modelValue:u.value[u.value.indexOf(h)],"onUpdate:modelValue":_=>u.value[u.value.indexOf(h)]=_,"property-id":h.id,"is-nested":t.isNested,"parent-id":t.parentId,disabled:t.disabled,"enable-drag":!t.isNested,onRemove:_=>g(h.id),onAddTopLevel:p[0]||(p[0]=_=>d.$emit("add-property"))},null,8,["modelValue","onUpdate:modelValue","property-id","is-nested","parent-id","disabled","enable-drag","onRemove"]))),128))],512),e("div",{class:oe(t.isNested?"mt-2":"mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-800")},[e("button",{onClick:f,type:"button",disabled:t.disabled,class:oe(t.isNested?"px-2 py-1 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50":"w-full px-3 py-2 text-sm bg-neutral-50 dark:bg-neutral-900 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded transition-colors disabled:opacity-50 border border-dashed border-neutral-300 dark:border-neutral-700")},[...p[1]||(p[1]=[e("span",{class:"flex items-center justify-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),$e(" Add Property ")],-1)])],10,Mf)],2)]))}}),Ef={class:"space-y-4"},Lf={key:0,class:"flex items-center justify-between"},Af={class:"text-sm font-medium"},Pf={key:0,class:"text-red-500"},Df={class:"space-y-2 border border-neutral-200 dark:border-neutral-800 rounded-lg p-4"},jf={key:0,class:"flex items-center justify-between mb-2"},Of={key:1,class:"text-center py-12"},Uf=["disabled"],Rf={class:"mt-4 text-center"},Nf={key:3,class:"mt-4"},Ff={class:"bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-lg p-4 overflow-x-auto"},Bf={class:"text-xs leading-relaxed"},qf=["innerHTML"],_a=pe({__name:"JSONSchemaInput",props:We({label:{},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>({type:"object",properties:{},required:[]})},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const n=st(t,"modelValue"),s=m([]),i=m(),l=m(!1),u=()=>{if(n.value?.properties){const b=[];n.value.required;for(const[v,y]of Object.entries(n.value.properties)){const x=y,k={id:crypto.randomUUID(),name:v,type:x.type||"string",description:x.description||""};x.enum&&(k.enum=x.enum),x.anyOf&&(k.type="anyOf",k.anyOf=r(x.anyOf)),x.type==="array"&&x.items&&(k.items=c(x.items)),x.type==="object"&&x.properties&&(k.properties=f(x.properties,x.required||[])),b.push(k)}s.value=b}},r=b=>b.map(v=>typeof v=="object"&&v.type?{id:crypto.randomUUID(),name:"",type:v.type,description:v.description||"",properties:v.properties?f(v.properties,v.required||[]):void 0,items:v.items?c(v.items):void 0,enum:v.enum}:{id:crypto.randomUUID(),name:"",type:"string",description:""}),c=b=>{const v={id:crypto.randomUUID(),name:"",type:b.type||"string",description:b.description||""};return b.enum&&(v.enum=b.enum),b.anyOf&&(v.type="anyOf",v.anyOf=r(b.anyOf)),b.type==="array"&&b.items&&(v.items=c(b.items)),b.type==="object"&&b.properties&&(v.properties=f(b.properties,b.required||[])),v},f=(b,v)=>{const y=[];for(const[x,k]of Object.entries(b)){const D=k,q={id:crypto.randomUUID(),name:x,type:D.type||"string",description:D.description||""};D.enum&&(q.enum=D.enum),D.anyOf&&(q.type="anyOf",q.anyOf=r(D.anyOf)),D.type==="array"&&D.items&&(q.items=c(D.items)),D.type==="object"&&D.properties&&(q.properties=f(D.properties,D.required||[])),y.push(q)}return y};u();const g=()=>{const b={type:"object",properties:{},required:[],additionalProperties:!1},{properties:v}=p(s.value);b.properties=v,b.required=Object.keys(v),n.value=b},d=b=>{const v={type:b.type==="anyOf"?void 0:b.type,description:b.description};if(b.type==="enum"&&b.enum&&(v.enum=b.enum,v.type="string"),b.type==="anyOf"&&b.anyOf&&(delete v.type,v.anyOf=b.anyOf.map(d)),b.type==="object"&&b.properties){const{properties:y}=p(b.properties);v.properties=y,v.required=Object.keys(y),v.additionalProperties=!1}return b.type==="array"&&b.items&&(v.items=d(b.items)),v},p=b=>{const v={},y=[];for(const x of b){const k={type:x.type==="anyOf"?void 0:x.type,description:x.description};if(y.push(x.name),x.type==="enum"&&x.enum&&(k.enum=x.enum,k.type="string"),x.type==="anyOf"&&x.anyOf&&x.anyOf.length>0&&(delete k.type,k.anyOf=x.anyOf.map(d)),x.type==="array"&&x.items&&(k.items=d(x.items)),x.type==="object"&&x.properties){const{properties:D}=p(x.properties);k.properties=D,k.required=Object.keys(D),k.additionalProperties=!1}v[x.name]=k}return{properties:v,required:y}};ve(s,()=>{g()},{deep:!0}),g();const h=W(()=>JSON.stringify(n.value,null,2).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"([^"]+)":/g,'<span class="text-blue-600 dark:text-blue-400">"$1"</span>:').replace(/:"([^"]*)"/g,':<span class="text-green-600 dark:text-green-400">"$1"</span>').replace(/:(\d+)/g,':<span class="text-yellow-600 dark:text-yellow-400">$1</span>').replace(/:(true|false)/g,':<span class="text-purple-600 dark:text-purple-400">$1</span>').replace(/:(null)/g,':<span class="text-red-600 dark:text-red-400">$1</span>')),_=async()=>{if(s.value.length===0){const b={id:crypto.randomUUID(),name:"property1",type:"string",description:""};s.value.push(b),await Ce();const v=document.querySelector(`[data-property-id="${b.id}"] input[placeholder="Property name"]`);v&&(v.focus(),v.select())}else i.value&&i.value.addProperty()};return(b,v)=>(a(),o("div",Ef,[t.label?(a(),o("div",Lf,[e("label",Af,[$e(V(t.label)+" ",1),t.required?(a(),o("span",Pf,"*")):M("",!0)])])):M("",!0),e("div",Df,[s.value.length>0?(a(),o("div",jf,[...v[2]||(v[2]=[e("h3",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300"}," Properties ",-1)])])):M("",!0),s.value.length===0?(a(),o("div",Of,[v[4]||(v[4]=e("div",{class:"mb-4"},[e("svg",{class:"w-12 h-12 mx-auto text-neutral-400 dark:text-neutral-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})])],-1)),v[5]||(v[5]=e("p",{class:"text-neutral-500 dark:text-neutral-400 text-sm mb-4"}," No properties defined ",-1)),e("button",{onClick:_,type:"button",disabled:t.disabled,class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black rounded hover:bg-neutral-800 dark:hover:bg-neutral-200 transition-colors disabled:opacity-50 font-medium text-sm"},[...v[3]||(v[3]=[e("span",{class:"flex items-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),$e(" Add Property ")],-1)])],8,Uf)])):M("",!0),s.value.length>0?(a(),se(If,{key:2,ref_key:"propertyListRef",ref:i,modelValue:s.value,"onUpdate:modelValue":v[0]||(v[0]=y=>s.value=y),disabled:t.disabled,onAddProperty:_},null,8,["modelValue","disabled"])):M("",!0),e("div",Rf,[e("button",{onClick:v[1]||(v[1]=y=>l.value=!l.value),type:"button",class:"text-xs text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-100 hover:underline transition-colors"},V(l.value?"Hide":"Show")+" JSON Schema ",1)]),l.value?(a(),o("div",Nf,[e("div",Ff,[e("pre",Bf,[e("code",{class:"font-mono",innerHTML:h.value},null,8,qf)])])])):M("",!0)])]))}}),zf={class:"prompt-input-container relative"},Hf=["contenteditable","data-placeholder"],Wf={class:"bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden min-w-[240px] max-w-[320px]"},Jf={key:0,class:"p-3 text-sm text-neutral-500"},Kf={key:1,class:"p-3 text-sm text-neutral-500"},Gf={key:2,class:"max-h-[220px] overflow-y-auto"},Xf=["onClick"],Yf={class:"font-medium flex items-center gap-2"},Zf=["title"],Qf={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},eh={key:1,class:"text-xs text-red-600 dark:text-red-400 mt-1"},th={class:"text-xs mt-1"},ah=pe({__name:"PromptInput",props:{modelValue:{},search:{},placeholder:{default:"Type @ to insert variables or prompts..."},disabled:{type:Boolean,default:!1},maxLength:{},allowedTypes:{default:()=>["variable","prompt"]}},emits:["update:modelValue","segment-click"],setup(t,{emit:n}){const s=t,i=n,l=m(),u=m(),r=to({segments:s.modelValue&&s.modelValue.length?s.modelValue:[{type:"string",value:""}],dialogOpen:!1,dialogPosition:{x:0,y:0},searchQuery:"",searchResults:[],selectedIndex:0,isSearching:!1,atTriggerIndex:-1,isComposing:!1,ignoreNextWatch:!1}),c=()=>Math.random().toString(36).slice(2)+Date.now().toString(36),f=A=>A.type==="string"?"":`@${A.type==="variable"?A.label||A.value:A.label||A.id}`,g=()=>{const A=window.getSelection();if(!A||!A.rangeCount||!l.value)return null;const $=A.getRangeAt(0);let L=0;const J=Array.from(l.value.childNodes);for(let ee=0;ee<J.length;ee++){const E=J[ee];if(E===$.startContainer||E.contains?.($.startContainer)){if(E.nodeType===Node.TEXT_NODE)return{segmentIndex:L,offset:$.startOffset};if(E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag"))return{segmentIndex:L,offset:0}}(E.nodeType===Node.TEXT_NODE||E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag"))&&L++}return{segmentIndex:0,offset:0}},d=()=>{if(!l.value)return;const A=r.segments.map($=>{if($.type==="string")return($.value||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")||"";{const L=$._uid||($._uid=c()),J=f($),ee=$.type==="variable"?{type:"variable",value:$.value,label:$.label,schema:$.schema,meta:$.meta}:{type:"prompt",id:$.id,label:$.label,schema:$.schema,meta:$.meta},E=encodeURIComponent(JSON.stringify(ee)),R=$.type==="prompt"&&$.meta&&!$.meta.isValid,Y=R?'<span class="prompt-tag-warning" title="'+($.meta.validationMessage||"").replace(/"/g,"&quot;")+'">⚠️</span>':"";return`<span class="prompt-tag prompt-tag-clickable${R?" prompt-tag-invalid":""}" contenteditable="false" data-segment-uid="${L}" data-segment="${E}">${J}${Y}</span>`}}).join("");l.value.innerHTML=A||"<br>"},p=()=>{const A=[];for(const $ of r.segments)$.type==="string"&&A.length>0&&A[A.length-1].type==="string"?A[A.length-1].value+=$.value:A.push($);r.segments=A.length?A:[{type:"string",value:""}]},h=A=>{const $=A.dataset.segmentUid;let L=r.segments.find(J=>J._uid===$);if(!L){const J=A.dataset.segment;if(J)try{const ee=JSON.parse(decodeURIComponent(J));ee&&(ee.type==="variable"||ee.type==="prompt")&&(L=ee.type==="variable"?{type:"variable",value:ee.value,label:ee.label,schema:ee.schema,meta:ee.meta,_uid:$}:{type:"prompt",id:ee.id,label:ee.label,schema:ee.schema,meta:ee.meta,_uid:$})}catch{}}return L||null},_=A=>{const $=A.target;if($.classList?.contains("prompt-tag")){const L=h($);L&&i("segment-click",L,A)}},b=A=>{if(r.isComposing)return;const $=A.target,L=[];let J="";const ee=()=>{J.length>0&&(L.push({type:"string",value:J}),J="")},E=O=>{if(O.nodeType===Node.TEXT_NODE){const S=(O.textContent||"").replace(/\u00A0/g," ");J+=S;return}if(O.nodeType===Node.ELEMENT_NODE){const S=O;if(S.classList?.contains("prompt-tag")){ee();const U=h(S);U&&L.push(U);return}if(S.tagName==="BR"){J+=`
18
- `;return}const C=Array.from(S.childNodes);for(const U of C)E(U);(S.tagName==="DIV"||S.tagName==="P"||S.tagName==="LI")&&S.nextSibling&&(J+=`
19
- `);return}},R=Array.from($.childNodes);for(const O of R)E(O);ee();const ne=L.some(O=>O.type!=="string")?L:[{type:"string",value:($.innerText||"").replace(/\r\n/g,`
20
- `)}];r.segments=ne.length?ne:[{type:"string",value:""}],p(),v(),te()},v=()=>{const A=window.getSelection();if(!A||!A.rangeCount||!l.value)return;const $=A.getRangeAt(0);if($.startContainer.nodeType!==Node.TEXT_NODE){r.dialogOpen&&x();return}const J=$.startContainer.textContent||"",ee=$.startOffset;if(ee>0&&J[ee-1]==="@")r.atTriggerIndex=ee-1,r.searchQuery="",y(),q("");else if(r.dialogOpen&&r.atTriggerIndex>=0)if($.startContainer.nodeType===Node.TEXT_NODE){const E=$.startContainer.textContent||"",R=$.startOffset;if(R<=r.atTriggerIndex){x();return}const Y=E.substring(0,R);if(Y.length>r.atTriggerIndex&&Y[r.atTriggerIndex]==="@"){const ne=Y.substring(r.atTriggerIndex+1);ne.includes(" ")||ne.includes(`
21
- `)||ne.length>r.searchQuery.length+5?x():(r.searchQuery=ne,q(ne))}else x()}else x()},y=async()=>{r.dialogOpen=!0,r.selectedIndex=0,await Ce(),k()},x=()=>{r.dialogOpen=!1,r.searchResults=[],r.searchQuery="",r.atTriggerIndex=-1,r.isSearching=!1},k=()=>{if(!u.value||!l.value)return;const A=window.getSelection();if(!A||!A.rangeCount)return;const L=A.getRangeAt(0).getBoundingClientRect(),J=l.value.getBoundingClientRect();r.dialogPosition={x:L.left-J.left,y:L.bottom-J.top+4}};let D=null;const q=async A=>{if(!s.search){r.searchResults=[];return}D&&clearTimeout(D),r.isSearching=!0,D=setTimeout(async()=>{try{const $=await s.search(A);r.searchResults=($||[]).filter(L=>s.allowedTypes?.includes(L.type))}catch($){console.error("Search error:",$),r.searchResults=[]}finally{r.isSearching=!1}},200)},B=A=>A.type==="variable"?{type:"variable",value:A.value??A.id??"",label:A.label,schema:A.schema,_uid:c(),meta:A.meta}:{type:"prompt",id:A.id??A.value??"",label:A.label,schema:A.schema,_uid:c(),meta:A.meta},N=A=>{if(r.atTriggerIndex<0||!l.value)return;const $=window.getSelection();if(!$||!$.rangeCount)return;const L=$.getRangeAt(0);if(L.startContainer.nodeType!==Node.TEXT_NODE)return;const J=L.startContainer,ee=J.data.slice(0,r.atTriggerIndex),E=J.data.slice(L.startOffset),R=document.createElement("span"),Y=B(A),ne=Y.type==="prompt"&&Y.meta&&!Y.meta.isValid;R.className=`prompt-tag${ne?" prompt-tag-invalid":""}`,R.setAttribute("contenteditable","false");const O=Y._uid||(Y._uid=c());R.dataset.segmentUid=O;const S=Y.type==="variable"?{type:"variable",value:Y.value,label:Y.label,schema:Y.schema}:{type:"prompt",id:Y.id,label:Y.label,schema:Y.schema};if(R.dataset.segment=encodeURIComponent(JSON.stringify(S)),R.textContent=f(Y),ne){const F=document.createElement("span");F.className="prompt-tag-warning",F.textContent="⚠️",F.setAttribute("title",Y.meta.validationMessage||"Validation error"),R.appendChild(F)}const C=J.parentNode,U=document.createTextNode(E),I=document.createTextNode(ee);C.insertBefore(I,J),C.insertBefore(R,J),C.insertBefore(U,J),C.removeChild(J),x(),b({target:l.value});const ae=window.getSelection();if(ae){const F=document.createRange();F.setStart(U,0),F.collapse(!0),ae.removeAllRanges(),ae.addRange(F)}l.value.focus()},T=A=>{if((A.key==="ArrowLeft"||A.key==="ArrowRight")&&setTimeout(()=>v(),0),r.dialogOpen)A.key==="ArrowDown"?(A.preventDefault(),r.selectedIndex=Math.min(r.selectedIndex+1,r.searchResults.length-1)):A.key==="ArrowUp"?(A.preventDefault(),r.selectedIndex=Math.max(r.selectedIndex-1,0)):A.key==="Enter"?(A.preventDefault(),r.searchResults[r.selectedIndex]&&N(r.searchResults[r.selectedIndex])):(A.key==="Escape"||A.key==="Esc")&&(A.preventDefault(),x());else if(A.key==="Backspace"||A.key==="Delete"){const $=g();if(A.key==="Backspace"){const L=window.getSelection();if(L&&L.rangeCount){const J=L.getRangeAt(0);if(J.collapsed&&J.startContainer.nodeType===Node.TEXT_NODE&&J.startOffset===0){let ee=J.startContainer;for(;ee&&ee!==l.value;){const E=ee.previousSibling;if(E&&E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag")){A.preventDefault(),E.parentNode?.removeChild(E),b({target:l.value});return}ee=ee.parentNode}}}}if(!$)return;if(A.key==="Backspace"&&$.offset===0&&$.segmentIndex>0)r.segments[$.segmentIndex-1].type!=="string"&&(A.preventDefault(),r.segments.splice($.segmentIndex-1,1),p(),te(),d());else if(A.key==="Delete"&&$.segmentIndex<r.segments.length-1){const L=r.segments[$.segmentIndex];L.type==="string"&&(L.value?.length??0)===$.offset&&r.segments[$.segmentIndex+1].type!=="string"&&(A.preventDefault(),r.segments.splice($.segmentIndex+1,1),p(),te(),d())}}},w=A=>{A.preventDefault();const $=A.clipboardData?.getData("text/plain")||"";document.execCommand("insertText",!1,$)},K=A=>{if(!r.dialogOpen)return;const $=u.value;$&&($.contains(A.target)||x())},te=()=>{r.ignoreNextWatch=!0;const A=r.segments.map($=>{const{_uid:L,...J}=$||{};return J});i("update:modelValue",A)},le=()=>{const A=window.getSelection();if(!A||!l.value)return;const $=A.anchorNode;$&&l.value.contains($)&&v()},H=A=>{(A.key==="Escape"||A.key==="Esc")&&r.dialogOpen&&(A.preventDefault(),x())};return Ve(()=>{s.modelValue&&s.modelValue.length&&(r.segments=JSON.parse(JSON.stringify(s.modelValue))),d(),document.addEventListener("mousedown",K),document.addEventListener("selectionchange",le),document.addEventListener("keydown",H,!0)}),Be(()=>{document.removeEventListener("mousedown",K),document.removeEventListener("selectionchange",le),document.removeEventListener("keydown",H,!0)}),ve(()=>s.modelValue,A=>{if(r.ignoreNextWatch){r.ignoreNextWatch=!1;return}A&&(r.segments=JSON.parse(JSON.stringify(A)),d())},{deep:!0}),(A,$)=>(a(),o("div",zf,[e("div",{ref_key:"editorRef",ref:l,contenteditable:!t.disabled,onInput:b,onKeydown:T,onPaste:w,onClick:_,onKeyup:$[0]||($[0]=L=>{L.key==="Escape"?(L.preventDefault(),x()):(L.key==="ArrowLeft"||L.key==="ArrowRight")&&v()}),onCompositionstart:$[1]||($[1]=L=>r.isComposing=!0),onCompositionend:$[2]||($[2]=L=>r.isComposing=!1),class:oe(["prompt-input-editor","min-h-[100px] p-3 border-2 rounded-lg","border-black dark:border-neutral-300","bg-white dark:bg-black","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",t.disabled?"opacity-50 cursor-not-allowed":""]),"data-placeholder":t.placeholder},[Me(e("div",null,[et(A.$slots,"segment",{segment:null},void 0,!0)],512),[[Ke,!1]])],42,Hf),r.dialogOpen?(a(),o("div",{key:0,ref_key:"dialogRef",ref:u,class:"absolute z-50",style:ot({left:`${r.dialogPosition.x}px`,top:`${r.dialogPosition.y}px`})},[P(Ze,{"offset-x":2,"offset-y":2,intensity:.3},{default:ge(()=>[e("div",Wf,[r.isSearching?(a(),o("div",Jf," Searching... ")):r.searchResults.length===0?(a(),o("div",Kf," No results found ")):(a(),o("div",Gf,[(a(!0),o(me,null,ye(r.searchResults,(L,J)=>(a(),o("button",{key:L.id||L.value||J,type:"button",onClick:ee=>N(L),class:oe(["w-full px-3 py-2 text-left text-sm","hover:bg-neutral-100 dark:hover:bg-neutral-900","focus:bg-neutral-100 dark:focus:bg-neutral-900 focus:outline-none",r.selectedIndex===J?"bg-neutral-100 dark:bg-neutral-900":""])},[e("div",Yf,[$e(V(L.label||L.id||L.value)+" ",1),L.type==="prompt"&&L.meta&&!L.meta.isValid?(a(),o("span",{key:0,title:L.meta.validationMessage,class:"text-red-500"},"⚠️",8,Zf)):M("",!0)]),L.description?(a(),o("div",Qf,V(L.description),1)):M("",!0),L.type==="prompt"&&L.meta&&!L.meta.isValid?(a(),o("div",eh,V(L.meta.validationMessage),1)):M("",!0),e("div",th,[e("span",{class:oe(["inline-block px-1.5 py-0.5 rounded",L.type==="variable"?"bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300":"bg-purple-100 dark:bg-purple-900 text-purple-700 dark:text-purple-300"])},V(L.type),3)])],10,Xf))),128))]))])]),_:1})],4)):M("",!0)]))}}),$a=tt(ah,[["__scopeId","data-v-7ee6148f"]]);function Ht(t,n){if(!n||!n.properties||Object.keys(n.properties).length===0)return!0;if(!t||!t.properties)return Object.keys(n.properties);const s=[],i=t.properties||{},l=n.properties||{};return(n.required||[]).forEach(r=>{r in i||s.push(r)}),Object.keys(l).forEach(r=>{!(r in i)&&!s.includes(r)&&s.push(r)}),s.length>0?s:!0}function Wt(t){return t.length===0?"":t.length===1?`Missing required field: ${t[0]}`:`Missing required fields: ${t.join(", ")}`}const oh={class:"space-y-4"},lh=pe({__name:"PromptTemplate",props:{promptText:{},beforeTool:{},afterTool:{},requiredSchema:{},currentPromptName:{}},emits:["update:promptText","update:beforeTool","update:afterTool"],setup(t,{emit:n}){const s=t,i=n,l=m([]),u=m(!1),r=h=>h.type==="text"?{type:"string",value:h.content||""}:h.type==="include"?{type:"prompt",id:h.prompt||"",label:h.prompt||""}:h.type==="string"?{type:"string",value:h.value||""}:h.type==="prompt"?{type:"prompt",id:h.id||"",label:h.label||h.id||""}:h.type==="variable"?{type:"variable",value:h.value||"",label:h.label||h.value||""}:{type:"string",value:""},c=W(()=>{if(!s.promptText)return[{type:"string",value:""}];let h=[];try{const b=JSON.parse(s.promptText);Array.isArray(b)?h=b.map(r):h=[{type:"string",value:s.promptText}]}catch{h=[{type:"string",value:s.promptText}]}const _=s.requiredSchema?JSON.parse(s.requiredSchema):{};return h.map(b=>{if(b.type==="prompt"&&b.schema){const v=Ht(_,b.schema),y=v===!0,x=y?[]:v;return{...b,meta:{isValid:y,missingFields:x,validationMessage:y?"":Wt(x)}}}return b})}),f=W(()=>{try{const h=JSON.parse(s.requiredSchema);if(h.properties&&typeof h.properties=="object")return Object.keys(h.properties)}catch{return[]}return[]}),g=async h=>{u.value=!0;try{const _=new URLSearchParams;h&&_.set("search",h);const b=await fetch(de(`/api/prompts${_.toString()?"?"+_.toString():""}`));if(b.ok){const v=await b.json();l.value=v.prompts||[]}}catch(_){console.error("Error fetching prompts:",_)}finally{u.value=!1}},d=async h=>{const _=[];return f.value.forEach(b=>{(!h||b.toLowerCase().includes(h.toLowerCase()))&&_.push({type:"variable",value:b,label:b,description:"Schema property"})}),h!==void 0&&await g(h),l.value.forEach(b=>{if(!(s.currentPromptName&&b.name===s.currentPromptName)&&(!h||b.name.toLowerCase().includes(h.toLowerCase()))){const v=s.requiredSchema?JSON.parse(s.requiredSchema):{},y=Ht(v,b.required_schema),x=y===!0,k=x?[]:y;_.push({type:"prompt",id:b.name,label:b.name,description:b.tool_description||"Available prompt",schema:b.required_schema,meta:{isValid:x,missingFields:k,validationMessage:x?"":Wt(k)}})}}),_},p=h=>{const _=h.map(b=>{const{type:v,value:y,label:x,id:k,schema:D}=b;return v==="string"?{type:v,value:y||""}:v==="variable"?{type:v,value:y||"",label:x}:v==="prompt"?{type:v,id:k||"",label:x,schema:D}:b});i("update:promptText",JSON.stringify(_))};return Ve(()=>{g()}),(h,_)=>(a(),o("div",oh,[e("div",null,[_[0]||(_[0]=e("label",{class:"block text-sm font-medium mb-2"},"Prompt Template",-1)),_[1]||(_[1]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400 mb-2"}," Type @ to insert schema properties or other prompts ",-1)),P($a,{"model-value":c.value,"onUpdate:modelValue":p,search:d,placeholder:"Enter your prompt template... Type @ to insert variables or prompts"},null,8,["model-value"])])]))}}),sh={class:"space-y-3"},nh={class:"space-y-2 pl-4 border-l-2 border-accent-200 dark:border-accent-700"},rh={class:"space-y-1"},ih={class:"space-y-1 mt-3"},dh={class:"space-y-2 pl-4 border-l-2 border-neutral-200 dark:border-neutral-700"},uh=pe({__name:"PromptToolOptions",props:{toolName:{},toolConfig:{},toolType:{default:"prompt"},disabled:{type:Boolean}},emits:["update:option"],setup(t,{emit:n}){const s=t,i=n,l=m(null),u=m(!0),r=W(()=>l.value?.properties?Object.entries(l.value.properties).map(([g,d])=>({value:g,label:g,description:d.description||d.type||""})):[]),c=async()=>{try{let g=s.toolName;if(s.toolType==="handoff"||s.toolType==="subagent"){const p=await fetch(de(`/api/agents/${encodeURIComponent(s.toolName)}`));if(p.ok){if(g=(await p.json())?.agent?.side_a_agent_prompt,!g){u.value=!1;return}}else{u.value=!1;return}}const d=await fetch(de(`/api/prompts/${encodeURIComponent(g)}`));if(d.ok){const p=await d.json();p?.prompt?.required_schema&&(l.value=p.prompt.required_schema)}}catch(g){console.error("Error fetching prompt schema:",g)}finally{u.value=!1}};Ve(()=>{c()});const f=(g,d)=>{i("update:option",g,d)};return(g,d)=>(a(),o("div",sh,[e("div",nh,[d[9]||(d[9]=e("p",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Initialization Options: ",-1)),e("div",rh,[d[5]||(d[5]=e("label",{class:"block text-xs font-medium text-neutral-700 dark:text-neutral-300"}," User message property ",-1)),P(Se,{"model-value":t.toolConfig.init_user_message_property||"","onUpdate:modelValue":d[0]||(d[0]=p=>f("init_user_message_property",p||null)),placeholder:"Don't inject a user message",options:r.value,disabled:t.disabled||u.value||r.value.length===0,loading:u.value},null,8,["model-value","options","disabled","loading"]),d[6]||(d[6]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Select which argument property should be used as the most recent user message for this sub-prompt. If not set no additional user message will be injected. ",-1))]),e("div",ih,[d[7]||(d[7]=e("label",{class:"block text-xs font-medium text-neutral-700 dark:text-neutral-300"}," Attachments property ",-1)),P(Se,{"model-value":t.toolConfig.init_attachments_property||"","onUpdate:modelValue":d[1]||(d[1]=p=>f("init_attachments_property",p||null)),placeholder:"Don't attach files",options:r.value,disabled:t.disabled||u.value||r.value.length===0,loading:u.value},null,8,["model-value","options","disabled","loading"]),d[8]||(d[8]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"},' Select which argument contains attachment path(s). Accepts a single path string or an array of paths (e.g., "/attachments/123.jpg" or ["/attachments/a.jpg", "/attachments/b.jpg"]). ',-1))])]),e("div",dh,[d[10]||(d[10]=e("p",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Sub-Prompt Response Options: ",-1)),P(Ae,{"model-value":t.toolConfig.include_text_response,"onUpdate:modelValue":d[2]||(d[2]=p=>f("include_text_response",p)),label:"Include text response","help-text":"Include the final text content from the sub-prompt",disabled:t.disabled},null,8,["model-value","disabled"]),P(Ae,{"model-value":t.toolConfig.include_tool_calls,"onUpdate:modelValue":d[3]||(d[3]=p=>f("include_tool_calls",p)),label:"Include tool calls and responses","help-text":"Include tool calls executed by the sub-prompt and their responses",disabled:t.disabled},null,8,["model-value","disabled"]),P(Ae,{"model-value":t.toolConfig.include_errors,"onUpdate:modelValue":d[4]||(d[4]=p=>f("include_errors",p)),label:"Include errors","help-text":"Include error information if the sub-prompt fails",disabled:t.disabled},null,8,["model-value","disabled"])])]))}}),ch={class:"space-y-4"},ph={class:"block text-sm font-medium mb-2"},vh={key:0,class:"text-red-500"},mh={class:"flex items-start justify-between"},fh={class:"flex items-center gap-2 flex-1"},hh={class:"flex-1"},gh={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},bh={key:1,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},xh={key:2,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},yh={key:3,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},kh={key:4,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},wh={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-1"},_h={key:1,class:"text-xs text-amber-600 dark:text-amber-400 mt-1 flex items-center gap-1"},$h=["onClick","disabled","aria-label"],Ch={key:0,class:"mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-700"},Th={class:"space-y-2"},Sh={key:0,class:"text-xs text-amber-500 dark:text-amber-400 whitespace-nowrap",title:"Required at agent or thread level"},Vh={key:1,class:"text-xs text-red-500 dark:text-red-400 mt-1"},Mh={key:0,class:"text-center py-8 text-sm text-neutral-500 dark:text-neutral-400 border border-dashed border-neutral-300 dark:border-neutral-600 rounded-lg"},Ih=pe({__name:"ToolSelectorWithOptions",props:We({label:{default:"Available Tools"},placeholder:{default:"Select a tool"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},modelId:{},providerId:{}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["unavailable-tools"],["update:modelValue"]),setup(t,{expose:n,emit:s}){const i=t,l=st(t,"modelValue"),u=m([]),r=m([]),c=m(!1),f=m(!1),g=m(),d=W(()=>[...u.value,...r.value]),p=W(()=>new Set(d.value.map(H=>v(H)))),h=H=>(H.startsWith("provider:"),p.value.has(H)),_=W(()=>l.value.filter(H=>!h(H.name)).map(H=>H.name)),b=s;ve(_,H=>{H.length>0&&b("unavailable-tools",H)},{immediate:!0}),na(async()=>{g.value,await Ce(),g.value&&l.value.length>0&&await ra({parent:g,values:l,dragHandle:".drag-handle"})});const v=H=>H.type==="provider"?`provider:${H.name}`:H.type==="mcp"?`mcp:${H.name}`:H.name,y=H=>H.startsWith("provider:")?H.slice(9):H.startsWith("mcp:")?H.slice(4):H,x=H=>H.startsWith("provider:")?"provider":H.startsWith("mcp:")?"mcp":"tool",k=W(()=>{const H=new Set(l.value.map(A=>A.name));return d.value.filter(A=>!H.has(v(A))).map(A=>{let $=A.name;return A.type==="prompt"?$=`${A.name} (prompt)`:A.type==="mcp"?$=`${A.name} (mcp)`:A.type==="provider"?$=`${A.name} (provider)`:A.type==="handoff"?$=`${A.name} (handoff agent)`:A.type==="subagent"&&($=`${A.name} (subagent)`),{value:v(A),label:$,description:A.description}})}),D=async()=>{c.value=!0;try{const H=await ze("/tools");if(H.ok){const A=await H.json();u.value=Object.entries(A).map(([$,L])=>({name:$,description:L.description||"",type:L.type,model:L.model}))}}catch(H){console.error("Error fetching tools:",H)}finally{c.value=!1}},q=async()=>{if(!i.providerId||!i.modelId){r.value=[];return}f.value=!0;try{const H=await ze(`/providers/${i.providerId}/tools?model=${encodeURIComponent(i.modelId)}`);if(H.ok){const A=await H.json();r.value=(A.tools||[]).map($=>({name:$.name,description:$.description||"",type:"provider",tenvs:$.tenvs||[]}))}else r.value=[]}catch(H){console.error("Error fetching provider tools:",H),r.value=[]}finally{f.value=!1}};ve([()=>i.providerId,()=>i.modelId],async([H,A])=>{H&&A?await q():r.value=[]},{immediate:!0});const B=H=>{if(!H||l.value.find(L=>L.name===H))return;const A=T(H),$={};if(A?.tenvs&&A.tenvs.length>0)for(const L of A.tenvs)$[L.name]="";l.value=[...l.value,{name:H,include_text_response:!0,include_tool_calls:!0,include_errors:!0,init_user_message_property:null,init_attachments_property:null,...Object.keys($).length>0?{tenvs:$}:{}}]},N=H=>{l.value=l.value.filter(A=>A.name!==H)},T=H=>{const A=d.value.find($=>v($)===H);return A||d.value.find($=>$.name===H)},w=(H,A,$)=>{l.value=l.value.map(L=>{if(L.name===H){const J={...L.tenvs||{},[A]:$||void 0};for(const ee of Object.keys(J))J[ee]||delete J[ee];return{...L,tenvs:Object.keys(J).length>0?J:void 0}}return L})},K=(H,A,$)=>{l.value=l.value.map(L=>L.name===H?{...L,[A]:$}:L)};return n({removeUnavailableTools:()=>{l.value=l.value.filter(H=>h(H.name))},getAvailableToolsOnly:()=>l.value.filter(H=>h(H.name)),unavailableTools:_}),Ve(()=>{D()}),(H,A)=>(a(),o("div",ch,[e("div",null,[e("label",ph,[$e(V(t.label)+" ",1),t.required?(a(),o("span",vh,"*")):M("",!0)]),l.value.length>0?(a(),o("div",{key:0,class:"space-y-3 mb-4",ref_key:"dragAreaRef",ref:g},[(a(!0),o(me,null,ye(l.value,$=>(a(),o("div",{key:$.name,class:oe(["border rounded-lg p-4 transition-colors",h($.name)?"border-neutral-300 dark:border-neutral-600":"border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20 opacity-75"])},[e("div",mh,[e("div",fh,[e("div",{class:oe(["drag-handle",h($.name)?"cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400":"cursor-not-allowed text-neutral-300 dark:text-neutral-700"])},[...A[0]||(A[0]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})],-1)])],2),e("div",hh,[e("h4",{class:oe(["font-medium text-sm",!h($.name)&&"text-neutral-500 dark:text-neutral-400"])},[$e(V(y($.name))+" ",1),x($.name)==="provider"?(a(),o("span",gh,"(provider)")):x($.name)==="mcp"?(a(),o("span",bh,"(mcp)")):T($.name)?.type==="prompt"?(a(),o("span",xh,"(prompt)")):T($.name)?.type==="handoff"?(a(),o("span",yh,"(handoff agent)")):T($.name)?.type==="subagent"?(a(),o("span",kh,"(subagent)")):M("",!0)],2),T($.name)?.description?(a(),o("p",wh,V(T($.name)?.description),1)):M("",!0),h($.name)?M("",!0):(a(),o("p",_h,[...A[1]||(A[1]=[e("svg",{class:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),$e(" Not available for selected model - will be removed on save ",-1)])]))])]),e("button",{onClick:L=>N($.name),type:"button",disabled:t.disabled,class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors text-neutral-500 hover:text-red-500","aria-label":`Remove ${y($.name)}`},[...A[2]||(A[2]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,$h)]),T($.name)?.type==="provider"&&T($.name)?.tenvs?.length?(a(),o("div",Ch,[A[3]||(A[3]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 mb-2 font-medium"},[$e(" Environment Variables "),e("span",{class:"text-neutral-400"},"(optional at prompt level)")],-1)),e("div",Th,[(a(!0),o(me,null,ye(T($.name)?.tenvs,L=>(a(),o("div",{key:L.name,class:"flex items-center gap-2"},[P(Ee,{"model-value":$.tenvs?.[L.name]||"","onUpdate:modelValue":J=>w($.name,L.name,J),label:L.name,placeholder:L.description||"Enter value...",disabled:t.disabled,size:"sm",class:"flex-1"},null,8,["model-value","onUpdate:modelValue","label","placeholder","disabled"]),L.required?(a(),o("span",Sh," required* ")):M("",!0)]))),128))])])):M("",!0),T($.name)?.type==="prompt"||T($.name)?.type==="handoff"||T($.name)?.type==="subagent"?(a(),se(uh,{key:1,"tool-name":$.name,"tool-config":$,"tool-type":T($.name)?.type,disabled:t.disabled,"onUpdate:option":(L,J)=>K($.name,L,J)},null,8,["tool-name","tool-config","tool-type","disabled","onUpdate:option"])):M("",!0)],2))),128))],512)):M("",!0),P(Se,{"model-value":"","onUpdate:modelValue":B,placeholder:l.value.length>0?"Add another tool...":t.placeholder,"search-placeholder":"Search tools...",options:k.value,disabled:t.disabled||c.value||k.value.length===0,loading:c.value},null,8,["placeholder","options","disabled","loading"]),t.error?(a(),o("p",Vh,V(t.error),1)):M("",!0)]),l.value.length===0&&!c.value&&k.value.length===0?(a(),o("div",Mh," No tools available. Create tools in your agentbuilder/tools directory. ")):M("",!0)]))}}),Eh={key:0,class:"min-h-[400px] flex items-center justify-center"},Lh={key:1,class:"space-y-6 pr-2 pb-4"},Ah={class:"space-y-4"},Ph={class:"space-y-4"},Dh={class:"flex justify-between"},jh={class:"flex gap-2"},Oh=["disabled"],Ca=pe({__name:"PromptModal",props:{modelValue:{type:Boolean},editPrompt:{},mode:{}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=W(()=>s.mode==="edit"),u=m(!1),r=W(()=>k.value.length===1),c=m(""),f=m(null),g=m(""),d=m(""),p=m(""),h=m({type:"object",properties:{},required:[],additionalProperties:!1}),_=m(""),b=m(!1),v=m(!1),y=m(""),x=m(""),k=m([]),D=m(!1),q=m(null),B=m("auto"),N=m(null),T=m(null),w=m(!1),K=m(!1),te=W({get:()=>N.value||"",set:ee=>N.value=ee||null}),le=W({get:()=>B.value,set:ee=>B.value=ee}),H=()=>{g.value="",c.value="",d.value="",p.value="",f.value=null,h.value={type:"object",properties:{},required:[],additionalProperties:!1},_.value="",b.value=!1,v.value=!1,y.value="",x.value="",k.value=[],D.value=!1,B.value="auto",N.value=null,T.value=null,w.value=!1,K.value=!1},A=async ee=>{if(!ee){f.value=null;return}try{const E=await ze(`/models/${ee}`);if(E.ok){const R=await E.json();f.value=R.model||R}}catch(E){console.error("Error fetching model info:",E),f.value=null}};ve(p,async ee=>{ee?await A(ee):f.value=null});const $=async()=>{if(s.editPrompt?.id){u.value=!0;try{const ee=await ze(`/prompts/${s.editPrompt.id}`);if(ee.ok){const E=await ee.json(),R=E.prompt||E;g.value=R.name||"",c.value=R.name||"",d.value=R.tool_description||"",p.value=R.model_id||"",R.model_id&&await A(R.model_id);let Y=R.required_schema;if(typeof Y=="string")try{Y=JSON.parse(Y)}catch{Y=null}h.value=Y||{type:"object",properties:{},required:[],additionalProperties:!1},_.value=R.prompt||"",b.value=R.include_chat||!1,v.value=R.include_past_tools||!1,y.value=R.before_tool||"",x.value=R.after_tool||"";const ne=R.tools||[];k.value=ne.map(S=>typeof S=="string"?{name:S,include_text_response:!0,include_tool_calls:!0,include_errors:!0,init_user_message_property:null}:S),D.value=R.parallel_tool_calls||!1,B.value=R.tool_choice||"auto";const O=R.reasoning||{};N.value=O.effort||R.reasoning_effort||null,T.value=O.maxTokens||R.reasoning_max_tokens||null,w.value=O.exclude||R.reasoning_exclude||!1,K.value=O.include||R.include_reasoning||!1}}catch(ee){console.error("Error loading prompt data:",ee)}finally{u.value=!1}}},L=async()=>{const ee=/^[a-z][a-z0-9_]*$/;if(!g.value||!ee.test(g.value)){alert("Please enter a valid name (lowercase letters, numbers, and underscores only, must start with a letter)");return}if(!d.value){alert("Please enter a description");return}if(!p.value){alert("Please select a model");return}if(!_.value){alert("Please enter the prompt template");return}q.value?.removeUnavailableTools();const E={name:g.value,tool_description:d.value,prompt:_.value,required_schema:h.value,model_id:p.value,include_chat:b.value,include_past_tools:v.value,before_tool:y.value||null,after_tool:x.value||null,parallel_tool_calls:D.value,tool_choice:B.value,tools:k.value,reasoning_effort:N.value,reasoning_max_tokens:T.value,reasoning_exclude:w.value,include_reasoning:K.value};l.value&&s.editPrompt?.id&&(E.id=s.editPrompt.id,c.value&&c.value!==g.value&&(E.originalName=c.value)),i("save",E),H(),i("update:modelValue",!1)},J=()=>{H(),i("update:modelValue",!1)};return ve(()=>k.value.length,ee=>{B.value==="function"&&ee!==1&&(B.value="auto")}),ve(()=>s.modelValue,async ee=>{ee&&(l.value?(H(),await Ce(),await $()):H())}),ve(()=>s.editPrompt,async ee=>{ee&&l.value&&s.modelValue&&(await Ce(),await $())},{immediate:!0}),(ee,E)=>(a(),se(He,{"model-value":t.modelValue,"onUpdate:modelValue":E[16]||(E[16]=R=>ee.$emit("update:modelValue",R)),title:l.value?"Edit Prompt":"Add Prompt",width:"max-w-4xl"},{footer:ge(()=>[e("div",Dh,[e("button",{onClick:J,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("div",jh,[e("button",{onClick:L,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:u.value},V(l.value?"Update Prompt":"Create Prompt"),9,Oh)])])]),default:ge(()=>[u.value?(a(),o("div",Eh,[...E[17]||(E[17]=[e("span",{class:"text-neutral-500"},"Loading prompt data...",-1)])])):(a(),o("div",Lh,[e("div",null,[P(ef,{name:g.value,"onUpdate:name":E[0]||(E[0]=R=>g.value=R),"tool-description":d.value,"onUpdate:toolDescription":E[1]||(E[1]=R=>d.value=R)},null,8,["name","tool-description"])]),e("div",null,[P(af,{modelValue:p.value,"onUpdate:modelValue":E[2]||(E[2]=R=>p.value=R)},null,8,["modelValue"])]),e("div",null,[P(_a,{modelValue:h.value,"onUpdate:modelValue":E[3]||(E[3]=R=>h.value=R),label:"Required Schema (Optional)"},null,8,["modelValue"])]),e("div",null,[P(lh,{"prompt-text":_.value,"onUpdate:promptText":E[4]||(E[4]=R=>_.value=R),"before-tool":y.value,"onUpdate:beforeTool":E[5]||(E[5]=R=>y.value=R),"after-tool":x.value,"onUpdate:afterTool":E[6]||(E[6]=R=>x.value=R),"required-schema":JSON.stringify(h.value,null,2),"current-prompt-name":l.value?g.value:void 0},null,8,["prompt-text","before-tool","after-tool","required-schema","current-prompt-name"])]),e("div",null,[P(Ih,{ref_key:"toolSelectorRef",ref:q,modelValue:k.value,"onUpdate:modelValue":E[7]||(E[7]=R=>k.value=R),"provider-id":f.value?.provider_id||f.value?.provider,"model-id":f.value?.model},null,8,["modelValue","provider-id","model-id"])]),e("div",Ah,[E[19]||(E[19]=e("h3",{class:"text-sm font-medium text-neutral-900 dark:text-neutral-100"}," Tool Configuration ",-1)),e("div",null,[P(Ae,{modelValue:D.value,"onUpdate:modelValue":E[8]||(E[8]=R=>D.value=R),label:"Allow parallel tool calls","help-text":"Allow the model to call multiple tools simultaneously in a single turn"},null,8,["modelValue"])]),e("div",null,[P(Se,{modelValue:le.value,"onUpdate:modelValue":E[9]||(E[9]=R=>le.value=R),label:"Tool Choice",options:[{value:"auto",label:"Auto",description:"Model decides"},{value:"none",label:"None",description:"No tools allowed"},{value:"required",label:"Required",description:"Must call a tool"},{value:"function",label:"Function",description:r.value?"Call specific tool":"Requires exactly 1 tool"}].filter(R=>R.value!=="function"||r.value),placeholder:"Select tool choice"},null,8,["modelValue","options"]),E[18]||(E[18]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Controls whether and how the model can call tools ",-1))])]),e("div",Ph,[E[23]||(E[23]=e("h3",{class:"text-sm font-medium text-neutral-900 dark:text-neutral-100"}," Context & Reasoning Configuration ",-1)),e("div",null,[P(Ae,{modelValue:b.value,"onUpdate:modelValue":E[10]||(E[10]=R=>b.value=R),label:"Include chat history","help-text":"Expose chat history to the LLM when this prompt is used as a full prompt (not a partial in another prompt)"},null,8,["modelValue"])]),e("div",null,[P(Ae,{modelValue:v.value,"onUpdate:modelValue":E[11]||(E[11]=R=>v.value=R),label:"Include past tool calls","help-text":"Include prior tool call history in this prompt. Uncheck to remove past tool calls"},null,8,["modelValue"])]),e("div",null,[P(Ae,{modelValue:K.value,"onUpdate:modelValue":E[12]||(E[12]=R=>K.value=R),label:"Include reasoning in message history","help-text":"When loading message history, include reasoning_details from previous responses. Required for multi-turn reasoning continuity."},null,8,["modelValue"])]),E[24]||(E[24]=e("hr",{class:"border-neutral-300 dark:border-neutral-600"},null,-1)),E[25]||(E[25]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Configure extended reasoning for models like o1, o3, Gemini Thinking, and others. Reasoning is enabled automatically when either field is set. ",-1)),e("div",null,[P(Se,{modelValue:te.value,"onUpdate:modelValue":E[13]||(E[13]=R=>te.value=R),label:"Reasoning Effort",options:[{value:"",label:"None",description:"Disabled"},{value:"low",label:"Low",description:"~20% of max_tokens"},{value:"medium",label:"Medium",description:"~50% of max_tokens"},{value:"high",label:"High",description:"~80% of max_tokens"}],placeholder:"Select reasoning effort"},null,8,["modelValue"]),E[20]||(E[20]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Controls reasoning capacity allocation. Supported by OpenAI o-series and Grok models. ",-1))]),e("div",null,[E[21]||(E[21]=e("label",{class:"block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2"}," Max Reasoning Tokens ",-1)),Me(e("input",{"onUpdate:modelValue":E[14]||(E[14]=R=>T.value=R),type:"number",min:"1024",max:"32000",step:"1024",placeholder:"Leave empty to disable or use effort level",class:"w-full px-3 py-2 text-sm border border-neutral-300 dark:border-neutral-600 rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 focus:ring-2 focus:ring-accent-500 focus:border-transparent"},null,512),[[Oe,T.value,void 0,{number:!0}]]),E[22]||(E[22]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Directly specify reasoning token limit (1024-32000). Supported by Anthropic, Gemini Thinking, and some Qwen models. ",-1))]),e("div",null,[P(Ae,{modelValue:w.value,"onUpdate:modelValue":E[15]||(E[15]=R=>w.value=R),label:"Exclude reasoning from response","help-text":"Use reasoning internally but don't return it in the response (saves tokens and cost)"},null,8,["modelValue"])])])]))]),_:1},8,["model-value","title"]))}}),Uh=pe({__name:"PromptsView",setup(t){const n=lt(),s=Ye(),i=m(!1),l=m(null);ve(()=>s.query.refresh,()=>{s.query.refresh&&(l.value?.refresh(),n.replace({path:"/prompts",query:{}}))});const u=()=>{i.value=!0},r=f=>{n.push(`/prompts/${f.id}`)},c=async f=>{try{const g=await fetch(de("/api/prompts"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(g.ok)i.value=!1,await new Promise(d=>setTimeout(d,100)),await l.value?.refresh();else{const d=await g.json();alert(d.error||"Failed to create prompt")}}catch(g){console.error("Error creating prompt:",g),alert("Failed to create prompt")}};return(f,g)=>(a(),se(at,null,{default:ge(()=>[e("div",{class:"flex justify-between items-center mb-6"},[g[1]||(g[1]=e("h1",{class:"text-3xl font-bold"},"Prompts",-1)),e("button",{onClick:u,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Create Prompt ")]),g[2]||(g[2]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Define and manage prompt templates for your agents. ",-1)),P(Km,{ref_key:"dataTableRef",ref:l,onAdd:u,onEdit:r},null,512),P(Ca,{modelValue:i.value,"onUpdate:modelValue":g[0]||(g[0]=d=>i.value=d),mode:"add",onSave:c},null,8,["modelValue"])]),_:1}))}}),Rh={class:"p-8"},Nh={key:0,class:"flex items-center justify-center min-h-[400px]"},Fh={key:2,class:"flex items-center justify-center min-h-[400px]"},Bh=pe({__name:"PromptEditView",setup(t){const n=lt(),s=Ye(),i=m(!0),l=m(null),u=m(!0),r=async()=>{const g=s.params.id;if(!g){n.push("/prompts");return}u.value=!0;try{const d=await fetch(de(`/api/prompts/${g}`));if(d.ok){const p=await d.json();l.value=p.prompt||p}else alert("Prompt not found"),n.push("/prompts")}catch(d){console.error("Error loading prompt:",d),alert("Failed to load prompt"),n.push("/prompts")}finally{u.value=!1}},c=async g=>{try{const{originalName:d,...p}=g,h=d||p.id,_=await fetch(de(`/api/prompts/${h}`),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(_.ok)n.push({path:"/prompts",query:{refresh:Date.now().toString()}});else{const b=await _.json();alert(b.error||"Failed to update prompt")}}catch(d){console.error("Error updating prompt:",d),alert("Failed to update prompt")}},f=g=>{g||n.push("/prompts")};return Ve(()=>{r()}),ve(i,g=>{g||n.push("/prompts")}),(g,d)=>(a(),o("div",Rh,[u.value?(a(),o("div",Nh,[...d[1]||(d[1]=[e("span",{class:"text-neutral-500"},"Loading prompt...",-1)])])):l.value?(a(),se(Ca,{key:1,modelValue:i.value,"onUpdate:modelValue":[d[0]||(d[0]=p=>i.value=p),f],mode:"edit","edit-prompt":l.value,onSave:c},null,8,["modelValue","edit-prompt"])):(a(),o("div",Fh,[...d[2]||(d[2]=[e("span",{class:"text-neutral-500"},"Prompt not found",-1)])]))]))}}),qh={class:"border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},zh={key:0,class:"px-4 py-2 border-b-2 border-black dark:border-neutral-300 bg-neutral-50 dark:bg-neutral-900"},Hh={class:"flex items-center justify-between"},Wh={class:"text-sm font-medium"},Jh={class:"flex items-center gap-2"},Kh={key:1,class:"px-4 py-8 flex items-center justify-center"},Gh={key:2,class:"px-4 py-8 text-center text-neutral-500"},Xh={key:3,class:"divide-y divide-neutral-200 dark:divide-neutral-700"},Yh=["onClick"],Zh={class:"flex items-start gap-3"},Qh={class:"flex-shrink-0 mt-0.5"},eg=["checked","onClick"],tg={class:"flex-1 min-w-0"},ag={class:"flex items-center gap-2"},og={class:"text-sm font-medium"},lg={key:0,class:"text-xs px-1.5 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},sg={class:"mt-1 text-xs text-neutral-600 dark:text-neutral-400 space-y-0.5"},ng={key:0},rg={key:0},ig={key:1},dg={key:2},ug=pe({__name:"ExposedSelectList",props:{providers:{default:()=>[]},modelValue:{default:()=>[]},label:{},loading:{type:Boolean}},emits:["update:modelValue"],setup(t,{emit:n}){function s(d){if(d===0)return"$0.00";const p=Math.abs(d);let h;return p<1e-4?h=p.toExponential(3):p<.001||p<.01||p<.1?h=p.toFixed(4):p<1?h=p.toFixed(3):p<10||p<100?h=p.toFixed(2):p<1e3?h=p.toFixed(1):h=p.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0}),h.includes(".")&&(h=h.replace(/\.?0+$/,""),!h.includes(".")&&p<100&&(h=p.toFixed(2))),d<0?`-$${h}`:`$${h}`}const i=t,l=n,u=d=>i.modelValue.includes(d),r=d=>{const p=[...i.modelValue],h=p.indexOf(d);h>-1?p.splice(h,1):p.push(d),l("update:modelValue",p)},c=()=>{l("update:modelValue",i.providers.map(d=>d.id))},f=()=>{l("update:modelValue",[])},g=W(()=>i.providers.length>0&&i.modelValue.length===i.providers.length);return W(()=>i.modelValue.length>0&&i.modelValue.length<i.providers.length),(d,p)=>(a(),o("div",qh,[t.label?(a(),o("div",zh,[e("div",Hh,[e("span",Wh,V(t.label),1),e("div",Jh,[e("button",{type:"button",onClick:p[0]||(p[0]=h=>g.value?f():c()),class:"text-xs px-2 py-1 border border-neutral-400 dark:border-neutral-600 rounded hover:bg-neutral-100 dark:hover:bg-neutral-800"},V(g.value?"Deselect All":"Select All"),1)])])])):M("",!0),t.loading?(a(),o("div",Kh,[...p[1]||(p[1]=[e("div",{class:"flex items-center gap-2 text-neutral-500"},[e("svg",{class:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),e("span",null,"Loading providers...")],-1)])])):t.providers.length===0?(a(),o("div",Gh," No providers available ")):(a(),o("div",Xh,[(a(!0),o(me,null,ye(t.providers,h=>(a(),o("div",{key:h.id,class:"px-4 py-3 hover:bg-neutral-50 dark:hover:bg-neutral-900 cursor-pointer",onClick:_=>r(h.id)},[e("div",Zh,[e("div",Qh,[e("input",{type:"checkbox",checked:u(h.id),onClick:Ie(_=>r(h.id),["stop"]),class:"w-4 h-4 border-2 border-black dark:border-neutral-300 rounded focus:ring-2 focus:ring-black dark:focus:ring-white"},null,8,eg)]),e("div",tg,[e("div",ag,[e("span",og,V(h.name),1),h.quantization?(a(),o("span",lg,V(h.quantization),1)):M("",!0)]),e("div",sg,[e("div",null,V(s(h.pricing.prompt*1e6))+"/M input • "+V(s(h.pricing.completion*1e6))+"/M output ",1),h.maxPromptTokens||h.maxCompletionTokens?(a(),o("div",ng,[h.maxPromptTokens?(a(),o("span",rg," Max prompt: "+V(h.maxPromptTokens.toLocaleString())+" tokens ",1)):M("",!0),h.maxPromptTokens&&h.maxCompletionTokens?(a(),o("span",ig," • ")):M("",!0),h.maxCompletionTokens?(a(),o("span",dg," Max completion: "+V(h.maxCompletionTokens.toLocaleString())+" tokens ",1)):M("",!0)])):M("",!0)])])])],8,Yh))),128))]))]))}}),cg={class:"space-y-2"},pg={key:0,class:"space-y-2"},vg={key:0,class:"block text-sm font-medium"},mg={key:0,class:"text-red-500"},fg=["src","alt"],hg={class:"flex-1 text-sm"},gg={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 ml-1"},bg=["onClick","aria-label"],xg={key:1,class:"text-xs text-red-500 dark:text-red-400"},Ct=pe({__name:"MultipleSelectionsInput",props:We({label:{},placeholder:{default:"Select an option"},searchPlaceholder:{default:"Search..."},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},options:{},addLabel:{default:"Add another"},loading:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["removeItem"],["update:modelValue"]),setup(t,{emit:n}){const s=t,i=n,l=st(t,"modelValue"),u=m();na(async()=>{u.value,await Ce(),await ra({parent:u,values:l,dragHandle:".drag-handle"})});const r=W(()=>Array.isArray(l.value)?l.value.length>0&&typeof l.value[0]=="object"?l.value:l.value.map(d=>{const p=s.options.find(h=>h.value===d);return{id:d,label:p?.label||d,description:p?.description,icon:p?.icon}}):[]),c=W(()=>{const d=r.value.map(p=>p.id);return s.options.filter(p=>!d.includes(p.value))}),f=d=>{if(!d)return;const p=s.options.find(h=>h.value===d);if(p)if(l.value.length===0||typeof l.value[0]=="string")l.value=[...l.value,d];else{const h={id:d,label:p.label,description:p.description,icon:p.icon};l.value=[...l.value,h]}},g=d=>{typeof l.value[0]=="string"?l.value=l.value.filter(p=>p!==d):l.value=l.value.filter(p=>p.id!==d),i("removeItem",d)};return(d,p)=>(a(),o("div",cg,[r.value.length>0?(a(),o("div",pg,[t.label?(a(),o("label",vg,[$e(V(t.label)+" ",1),t.required?(a(),o("span",mg,"*")):M("",!0)])):M("",!0),e("div",{class:"space-y-1",ref_key:"dragAreaRef",ref:u},[(a(!0),o(me,null,ye(r.value,h=>(a(),o("div",{key:h.id,class:oe(["flex items-center gap-2 px-3 py-2 bg-neutral-50 dark:bg-neutral-900 rounded border","border-neutral-200 dark:border-neutral-800",t.disabled?"opacity-50":""])},[p[1]||(p[1]=e("div",{class:"drag-handle cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})])],-1)),h.icon?(a(),o("img",{key:0,src:h.icon,alt:h.label,class:"w-4 h-4 flex-shrink-0"},null,8,fg)):M("",!0),e("span",hg,[$e(V(h.label)+" ",1),h.description?(a(),o("span",gg," ("+V(h.description)+") ",1)):M("",!0)]),t.disabled?M("",!0):(a(),o("button",{key:1,onClick:_=>g(h.id),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors","aria-label":`Remove ${h.label}`},[...p[0]||(p[0]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,bg))],2))),128))],512)])):M("",!0),P(Se,{"model-value":"","onUpdate:modelValue":f,label:r.value.length>0?t.addLabel:t.label,options:c.value,placeholder:t.placeholder,"search-placeholder":t.searchPlaceholder,disabled:t.disabled||c.value.length===0,loading:t.loading},null,8,["label","options","placeholder","search-placeholder","disabled","loading"]),t.error?(a(),o("p",xg,V(t.error),1)):M("",!0)]))}}),yg={key:2,class:"text-xs text-red-500 dark:text-red-400 mt-1"},kg=pe({__name:"ModelSelectorInput",props:We({label:{},placeholder:{default:"Select a model"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},allowMultiple:{type:Boolean,default:!1}},{modelValue:{required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const n=t,s=st(t,"modelValue"),i=m([]),l=m(!1),u=W(()=>i.value.map(f=>({value:f.id,label:f.name,description:f.provider_id||f.provider,icon:f.iconId}))),r=async()=>{l.value=!0;try{const f=await fetch(de("/api/models"));if(f.ok){const g=await f.json();i.value=g.models||[]}}catch(f){console.error("Error fetching models:",f)}finally{l.value=!1}},c=f=>{};return Ve(()=>{r()}),ve(()=>n.allowMultiple,()=>{n.allowMultiple&&typeof s.value=="string"?s.value=s.value?[s.value]:[]:!n.allowMultiple&&Array.isArray(s.value)&&(s.value=s.value[0]||"")}),(f,g)=>(a(),o(me,null,[t.allowMultiple?(a(),se(Ct,{key:0,modelValue:s.value,"onUpdate:modelValue":g[0]||(g[0]=d=>s.value=d),label:t.label,placeholder:t.placeholder,"search-placeholder":"Search models...",error:t.error,required:t.required,disabled:t.disabled,options:u.value,loading:l.value,"add-label":"Add another model",onRemoveItem:c},null,8,["modelValue","label","placeholder","error","required","disabled","options","loading"])):(a(),se(Se,{key:1,modelValue:s.value,"onUpdate:modelValue":g[1]||(g[1]=d=>s.value=d),label:t.label,placeholder:t.placeholder,"search-placeholder":"Search models...",options:u.value,disabled:t.disabled,loading:l.value},null,8,["modelValue","label","placeholder","options","disabled","loading"])),!t.allowMultiple&&t.error?(a(),o("p",yg,V(t.error),1)):M("",!0)],64))}}),wg={class:"space-y-4"},_g={key:0},$g={key:1},Cg=["value"],Tg={key:0,class:"mt-1 text-xs text-red-500"},Sg={key:1,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Vg={class:"px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},Mg={key:2,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Ig={key:2,class:"space-y-3"},Eg={class:"flex items-center justify-between"},Lg={key:0,class:"text-sm text-neutral-500 dark:text-neutral-400"},Ag={key:1,class:"space-y-2"},Pg={class:"grid grid-cols-2 gap-x-4 gap-y-2"},Dg={class:"grid grid-cols-2 gap-4 pt-2"},jg={key:3,class:"space-y-3"},Og={key:0,class:"text-sm text-neutral-500 dark:text-neutral-400"},Ug={key:1,class:"space-y-2"},Rg={class:"grid grid-cols-1 gap-2"},Ng=["value"],Fg={class:"flex-1 min-w-0"},Bg={class:"font-medium text-sm"},qg={class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},zg={key:0,class:"mt-1"},Hg={class:"text-xs text-amber-600 dark:text-amber-400"},Wg={key:4},Jg={key:5},Kg={class:"flex justify-end gap-2"},Gg=["disabled"],Xg=pe({__name:"ModelModal",props:{modelValue:{type:Boolean},editModel:{},mode:{default:"add"}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=m([]),u=m(""),r=m(""),c=m([]),f=m(!1),g=m(!1),d=m([]),p=m([]),h=m(!1),_=m({supportsImages:!1,supportsToolCalls:!0,supportsStreaming:!0,supportsJsonMode:!0}),b=m(null),v=m(!1),y=m([]),x=m([]),k=m(!1),D=m([]),q=W(()=>s.mode==="edit"),B=m(""),N=m(""),T=m(""),w=F=>{let G=F.replace(/[^a-zA-Z0-9\s_-]/g,"");return G=G.trim().toLowerCase().replace(/[\s-]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),G?/^[a-z][a-z0-9_]*$/.test(G)?T.value="":T.value="Name must start with a letter and contain only lowercase letters, numbers, and underscores":T.value="Name is required",G},K=F=>{const G=F.target.value;N.value=w(G)},te=m(!1),le=m(null),H=W(()=>l.value.filter(F=>F.hasApiKey).map(F=>({value:F.name,label:F.name,description:F.sdk==="openai-sdk"?"OpenAI SDK":F.sdk==="openrouter"?"OpenRouter":F.sdk,icon:F.iconId}))),A=W(()=>c.value.map(F=>({...F,icon:F.iconId}))),$=W(()=>!q.value||!le.value||te.value?!1:N.value!==le.value.name||u.value!==le.value.provider||r.value!==le.value.model||JSON.stringify(p.value.sort())!==JSON.stringify(le.value.endpoints.sort())||JSON.stringify(D.value)!==JSON.stringify(le.value.fallbacks)||JSON.stringify(_.value)!==JSON.stringify(le.value.capabilities)||JSON.stringify(x.value.sort())!==JSON.stringify(le.value.providerTools.sort())),L=W(()=>l.value.find(G=>G.name===u.value)?.sdk==="openrouter"),J=async()=>{f.value=!0;try{const F=await fetch(de("/api/providers"));if(F.ok){const G=await F.json();l.value=G.providers||[]}}catch(F){console.error("Error fetching providers:",F)}finally{f.value=!1}},ee=async()=>{if(!u.value){c.value=[];return}g.value=!0;try{const F=await fetch(de("/api/models/available"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value})});if(F.ok){const G=await F.json();c.value=G.models||[]}else{const G=await F.json();console.error("Error fetching models:",G),c.value=[],alert(G.error||"Failed to fetch available models")}}catch(F){console.error("Error fetching models:",F),c.value=[]}finally{g.value=!1}},E=async()=>{if(!(!u.value||!r.value)){v.value=!0;try{const F=await fetch(de("/api/models/capabilities"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value,modelId:r.value})});if(F.ok){const G=await F.json();G.capabilities&&(b.value=G.capabilities,_.value={supportsImages:G.capabilities.supportsImages??!1,supportsToolCalls:G.capabilities.supportsToolCalls??!0,supportsStreaming:G.capabilities.supportsStreaming??!0,supportsJsonMode:G.capabilities.supportsJsonMode??!0,maxContextTokens:G.capabilities.maxContextTokens,maxOutputTokens:G.capabilities.maxOutputTokens})}}catch(F){console.error("Error fetching capabilities:",F)}finally{v.value=!1}}},R=async()=>{if(!u.value||!r.value){y.value=[];return}k.value=!0;try{const F=await fetch(de(`/api/providers/${u.value}/tools?model=${encodeURIComponent(r.value)}`));if(F.ok){const G=await F.json();y.value=G.tools||[],q.value||(x.value=y.value.map(z=>z.name))}else y.value=[]}catch(F){console.error("Error fetching provider tools:",F),y.value=[]}finally{k.value=!1}},Y=()=>{_.value={supportsImages:!1,supportsToolCalls:!0,supportsStreaming:!0,supportsJsonMode:!0},b.value=null},ne=()=>{b.value&&(_.value={supportsImages:b.value.supportsImages??!1,supportsToolCalls:b.value.supportsToolCalls??!0,supportsStreaming:b.value.supportsStreaming??!0,supportsJsonMode:b.value.supportsJsonMode??!0,maxContextTokens:b.value.maxContextTokens,maxOutputTokens:b.value.maxOutputTokens})},O=()=>{N.value="",B.value="",u.value="",r.value="",c.value=[],D.value=[],d.value=[],p.value=[],y.value=[],x.value=[],Y(),le.value=null,te.value=!1},S=async()=>{if(s.editModel){te.value=!0;try{await J(),N.value=s.editModel.name||"",B.value=s.editModel.name||"",u.value=s.editModel.provider_id||s.editModel.provider,await ee(),r.value=s.editModel.model,await U(),s.editModel.included_providers&&s.editModel.included_providers.length>0&&(p.value=s.editModel.included_providers),await C(),s.editModel.capabilities?_.value={supportsImages:s.editModel.capabilities.supportsImages??!1,supportsToolCalls:s.editModel.capabilities.supportsToolCalls??!0,supportsStreaming:s.editModel.capabilities.supportsStreaming??!0,supportsJsonMode:s.editModel.capabilities.supportsJsonMode??!0,maxContextTokens:s.editModel.capabilities.maxContextTokens,maxOutputTokens:s.editModel.capabilities.maxOutputTokens}:await E(),await R(),s.editModel.providerTools&&Array.isArray(s.editModel.providerTools)&&(x.value=s.editModel.providerTools),le.value={name:N.value,provider:u.value,model:r.value,endpoints:[...p.value],fallbacks:[...D.value],capabilities:{..._.value},providerTools:[...x.value]}}finally{te.value=!1}}};ve(()=>s.modelValue,async F=>{F?q.value&&s.editModel?await S():(await J(),O()):O()});const C=async()=>{if(s.editModel?.id){if(s.editModel.fallbacks&&Array.isArray(s.editModel.fallbacks)){D.value=s.editModel.fallbacks.map(F=>typeof F=="string"?F:F.id);return}try{const F=await fetch(de(`/api/models/${s.editModel.id}/fallbacks`));if(F.ok){const G=await F.json();D.value=G.fallbacks.map(z=>z.fallback_model_id)}}catch(F){console.error("Error loading fallbacks:",F)}}};ve(u,async(F,G)=>{te.value||q.value&&!G&&F===(s.editModel?.provider_id||s.editModel?.provider)||(r.value="",d.value=[],p.value=[],u.value&&await ee())});const U=async()=>{if(!r.value||!u.value){d.value=[];return}const F=l.value.find(z=>z.name===u.value);if(!F||F.sdk!=="openrouter"){d.value=[];return}const G=A.value.find(z=>z.value===r.value);if(!G?.slug){console.error("Model slug not found"),d.value=[];return}h.value=!0;try{const z=await fetch(de("/api/models/endpoints"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value,modelSlug:G.slug})});if(z.ok){const j=await z.json();d.value=j.endpoints||[],q.value||(p.value=d.value.map(Q=>Q.id))}else{const j=await z.json();console.error("Error fetching endpoints:",j),d.value=[]}}catch(z){console.error("Error fetching endpoints:",z),d.value=[]}finally{h.value=!1}};ve(r,async(F,G)=>{te.value||q.value&&!G&&F===s.editModel?.model||(r.value?(await U(),await E(),await R(),G&&F!==G&&(p.value=d.value.map(z=>z.id))):(d.value=[],p.value=[],y.value=[],x.value=[],Y()))});const I=()=>{if(!u.value||!r.value){alert("Please select a provider and model");return}if(!N.value){alert("Please enter a name for the model");return}if(T.value){alert(T.value);return}const F=L.value?p.value:[],G={name:N.value,model:r.value,provider:u.value,included_providers:F,fallbacks:D.value,capabilities:_.value,providerTools:x.value};q.value&&s.editModel?.id&&(G.id=s.editModel.id,B.value&&B.value!==N.value&&(G.originalName=B.value)),i("save",G)},ae=()=>{O(),i("update:modelValue",!1)};return(F,G)=>(a(),se(He,{"model-value":t.modelValue,"onUpdate:modelValue":G[11]||(G[11]=z=>F.$emit("update:modelValue",z)),title:q.value?"Edit Model":"Add Model",width:"max-w-2xl","min-height":"min-h-[36rem]","has-changes":$.value},{footer:ge(()=>[e("div",Kg,[e("button",{onClick:ae,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:I,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:!u.value||!r.value},V(q.value?"Update Model":"Add Model"),9,Gg)])]),default:ge(()=>[e("div",wg,[P(Se,{modelValue:u.value,"onUpdate:modelValue":G[0]||(G[0]=z=>u.value=z),options:H.value,label:"Provider",placeholder:"Select a provider",disabled:f.value||q.value&&!!s.editModel},null,8,["modelValue","options","disabled"]),u.value?(a(),o("div",_g,[P(Se,{modelValue:r.value,"onUpdate:modelValue":G[1]||(G[1]=z=>r.value=z),options:A.value,label:"Model",placeholder:"Select a model","search-placeholder":"Search models...",loading:g.value},null,8,["modelValue","options","loading"])])):M("",!0),r.value?(a(),o("div",$g,[G[13]||(G[13]=e("label",{class:"block text-sm font-medium mb-2"},"Name",-1)),e("input",{value:N.value,onInput:K,type:"text",class:oe(["w-full px-3 py-2 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 focus:ring-2 focus:ring-accent-500 focus:border-transparent",T.value?"border-red-500":"border-neutral-300 dark:border-neutral-600"]),placeholder:"e.g., coding_model, planning_model, fast_response"},null,42,Cg),T.value?(a(),o("p",Tg,V(T.value),1)):N.value?(a(),o("p",Sg,[G[12]||(G[12]=$e(" Will be saved as: ",-1)),e("code",Vg,V(N.value),1)])):(a(),o("p",Mg," A descriptive name for this model (e.g., coding_model, planning_model). This becomes the filename and reference ID. "))])):M("",!0),r.value?(a(),o("div",Ig,[e("div",Eg,[G[14]||(G[14]=e("label",{class:"block text-sm font-medium"},"Model Capabilities",-1)),b.value?(a(),o("button",{key:0,onClick:ne,type:"button",class:"text-xs text-accent-600 dark:text-accent-400 hover:underline"}," Reset to detected ")):M("",!0)]),v.value?(a(),o("div",Lg," Detecting capabilities... ")):(a(),o("div",Ag,[e("div",Pg,[P(Ae,{modelValue:_.value.supportsImages,"onUpdate:modelValue":G[2]||(G[2]=z=>_.value.supportsImages=z),label:"Vision/Images","help-text":"Can process image inputs"},null,8,["modelValue"]),P(Ae,{modelValue:_.value.supportsToolCalls,"onUpdate:modelValue":G[3]||(G[3]=z=>_.value.supportsToolCalls=z),label:"Tool Calls","help-text":"Supports function calling"},null,8,["modelValue"]),P(Ae,{modelValue:_.value.supportsStreaming,"onUpdate:modelValue":G[4]||(G[4]=z=>_.value.supportsStreaming=z),label:"Streaming","help-text":"Supports streaming responses"},null,8,["modelValue"]),P(Ae,{modelValue:_.value.supportsJsonMode,"onUpdate:modelValue":G[5]||(G[5]=z=>_.value.supportsJsonMode=z),label:"JSON Mode","help-text":"Supports structured output"},null,8,["modelValue"])]),e("div",Dg,[e("div",null,[G[15]||(G[15]=e("label",{class:"block text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-1"}," Max Context Tokens ",-1)),Me(e("input",{"onUpdate:modelValue":G[6]||(G[6]=z=>_.value.maxContextTokens=z),type:"number",class:"w-full px-2 py-1.5 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 border-neutral-300 dark:border-neutral-600 focus:ring-1 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., 128000"},null,512),[[Oe,_.value.maxContextTokens,void 0,{number:!0}]])]),e("div",null,[G[16]||(G[16]=e("label",{class:"block text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-1"}," Max Output Tokens ",-1)),Me(e("input",{"onUpdate:modelValue":G[7]||(G[7]=z=>_.value.maxOutputTokens=z),type:"number",class:"w-full px-2 py-1.5 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 border-neutral-300 dark:border-neutral-600 focus:ring-1 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., 16384"},null,512),[[Oe,_.value.maxOutputTokens,void 0,{number:!0}]])])])])),G[17]||(G[17]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Capabilities are auto-detected from the provider. You can override them if needed. ",-1))])):M("",!0),r.value&&y.value.length>0?(a(),o("div",jg,[G[19]||(G[19]=e("label",{class:"block text-sm font-medium"},"Provider Tools",-1)),k.value?(a(),o("div",Og," Loading provider tools... ")):(a(),o("div",Ug,[G[18]||(G[18]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Built-in tools available for this model. Select which tools to enable. ",-1)),e("div",Rg,[(a(!0),o(me,null,ye(y.value,z=>(a(),o("label",{key:z.name,class:oe(["flex items-start gap-3 p-3 border rounded cursor-pointer hover:bg-neutral-50 dark:hover:bg-neutral-800/50 transition-colors",x.value.includes(z.name)?"border-black dark:border-white":"border-neutral-200 dark:border-neutral-700"])},[Me(e("input",{type:"checkbox",value:z.name,"onUpdate:modelValue":G[8]||(G[8]=j=>x.value=j),class:"mt-0.5 h-4 w-4 rounded border-neutral-300 dark:border-neutral-600 text-black dark:text-white focus:ring-black dark:focus:ring-white accent-black dark:accent-white"},null,8,Ng),[[sa,x.value]]),e("div",Fg,[e("div",Bg,V(z.name),1),e("div",qg,V(z.description),1),z.tenvs&&z.tenvs.length>0?(a(),o("div",zg,[e("span",Hg," Requires: "+V(z.tenvs.filter(j=>j.required).map(j=>j.name).join(", ")||"none (optional config available)"),1)])):M("",!0)])],2))),128))])]))])):M("",!0),r.value&&L.value?(a(),o("div",Wg,[G[20]||(G[20]=e("label",{class:"block text-sm font-medium mb-2"}," Available Providers ",-1)),P(ug,{modelValue:p.value,"onUpdate:modelValue":G[9]||(G[9]=z=>p.value=z),providers:d.value,loading:h.value},null,8,["modelValue","providers","loading"]),G[21]||(G[21]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Select which providers can be used for this model ",-1))])):M("",!0),r.value?(a(),o("div",Jg,[P(kg,{modelValue:D.value,"onUpdate:modelValue":G[10]||(G[10]=z=>D.value=z),label:"Fallback Models",placeholder:"Add fallback model...","allow-multiple":!0},null,8,["modelValue"]),G[22]||(G[22]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Fallback models will be used in order if the primary model fails ",-1))])):M("",!0)])]),_:1},8,["model-value","title","has-changes"]))}}),Yg={class:"flex justify-between items-center mb-6"},Zg={class:"flex items-center gap-2"},Qg=["src","alt"],eb={class:"text-sm text-neutral-600 dark:text-neutral-400 font-mono"},tb={key:0,class:"space-y-0.5"},ab=["title"],ob={class:"shrink-0 font-mono pr-2"},lb=["src","alt"],sb={class:"truncate"},nb={key:1,class:"text-neutral-400 dark:text-neutral-600 text-sm"},rb=pe({__name:"ModelsView",setup(t){const n=m(!1),s=m([]),i=m(!1),l=m(null),u=m("add"),r=[{key:"name",label:"Name",width:"w-1/4"},{key:"model",label:"Model",width:"w-1/4"},{key:"provider",label:"Provider",width:"w-1/4"},{key:"fallbacks",label:"Fallbacks",width:"w-1/4"}],c=[{icon:"edit",label:"Edit",handler:p=>{l.value=p,u.value="edit",n.value=!0}},{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this model? This action cannot be undone.",handler:async p=>{await d(p.id)}}],f=async()=>{i.value=!0;try{const p=await fetch(de("/api/models"));if(!p.ok)throw new Error("Failed to fetch models");const h=await p.json();s.value=h.models||[]}catch(p){console.error("Error fetching models:",p),s.value=[]}finally{i.value=!1}},g=async p=>{try{if(l.value){const{originalName:h,..._}=p,b=h||l.value.id,v=await fetch(de(`/api/models/${b}`),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!v.ok){const y=await v.json();alert(y.error||"Failed to update model");return}}else{const h=await fetch(de("/api/models"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!h.ok){const _=await h.json();alert(_.error||"Failed to add model");return}}await f(),n.value=!1,l.value=null,u.value="add"}catch(h){console.error("Error saving model:",h),alert("Failed to save model")}},d=async p=>{try{const h=await fetch(de(`/api/models/${p}`),{method:"DELETE"});if(!h.ok){const _=await h.json();alert(_.error||"Failed to delete model");return}await f()}catch(h){console.error("Error deleting model:",h),alert("Failed to delete model")}};return Ve(()=>{f()}),(p,h)=>(a(),se(at,null,{default:ge(()=>[e("div",Yg,[h[3]||(h[3]=e("h1",{class:"text-3xl font-bold"},"Models",-1)),e("button",{onClick:h[0]||(h[0]=()=>{u.value="add",l.value=null,n.value=!0}),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Model ")]),h[4]||(h[4]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-8"}," Configure AI models from your connected providers. Models define which AI capabilities are available to your agents. ",-1)),P(Ge,{columns:r,data:s.value,actions:c,loading:i.value,"empty-message":"No models configured yet. Add your first model to get started."},{"cell-name":ge(({value:_,row:b})=>[e("div",Zg,[b.provider?(a(),o("img",{key:0,src:`/api/providers/${b.provider}/icon?model=${encodeURIComponent(b.model||"")}`,class:"w-5 h-5 shrink-0",alt:b.provider},null,8,Qg)):M("",!0),e("span",null,V(_),1)])]),"cell-model":ge(({value:_})=>[e("span",eb,V(_||"—"),1)]),"cell-fallbacks":ge(({value:_})=>[_&&_.length>0?(a(),o("div",tb,[(a(!0),o(me,null,ye(_,(b,v)=>(a(),o("div",{key:b.id,class:"text-sm text-neutral-600 dark:text-neutral-400 flex items-center",title:b.name},[e("span",ob,V(v===_.length-1?"└─":"├─"),1),b.provider?(a(),o("img",{key:0,src:`/api/providers/${b.provider}/icon?model=${encodeURIComponent(b.model||"")}`,class:"w-4 h-4 shrink-0 mr-1.5",alt:b.provider},null,8,lb)):M("",!0),e("span",sb,V(b.name),1)],8,ab))),128))])):(a(),o("span",nb," None "))]),_:1},8,["data","loading"]),P(Xg,{modelValue:n.value,"onUpdate:modelValue":[h[1]||(h[1]=_=>n.value=_),h[2]||(h[2]=_=>{n.value=_,_||(l.value=null,u.value="add")})],"edit-model":l.value,mode:u.value,onSave:g},null,8,["modelValue","edit-model","mode"])]),_:1}))}}),ib={class:"space-y-4"},db={class:"space-y-1"},ub={class:"relative"},cb={key:0,class:"flex items-center gap-2"},pb=["src","alt"],vb={key:1,class:"text-neutral-500"},mb={key:0,class:"absolute z-10 w-full mt-1 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded shadow-lg"},fb=["onClick"],hb=["src","alt"],gb={key:0,class:"text-xs text-red-500 dark:text-red-400"},bb=pe({__name:"AddProviderModal",props:{modelValue:{type:Boolean}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=n,i=m({name:"",type:"",apiKey:"",baseUrl:""}),l=m([]),u=m(!1),r=async()=>{u.value=!0;try{const y=await fetch(de("/api/providers"));if(y.ok){const x=await y.json();l.value=(x.providers||[]).map(k=>({value:k.name,label:k.label||k.name,icon:k.iconId,sdk:k.sdk}))}}catch(y){console.error("Error fetching providers:",y)}finally{u.value=!1}};Ve(()=>{r()});const c=m(!1),f=W(()=>l.find(y=>y.value===i.value.type)),g=()=>{setTimeout(()=>{c.value=!1},200)},d=m({});ve(()=>i.value.type,y=>{if(y&&!i.value.name){const x=l.find(k=>k.value===y);x&&(i.value.name=x.label)}});const p=W(()=>i.value.type==="custom"||i.value.type==="openai"),h=()=>{d.value={};let y=!0;return i.value.name||(d.value.name="Provider name is required",y=!1),i.value.type||(d.value.type="Provider type is required",y=!1),i.value.apiKey||(d.value.apiKey="API key is required",y=!1),p.value&&i.value.type==="custom"&&!i.value.baseUrl&&(d.value.baseUrl="Base URL is required for custom providers",y=!1),y},_=()=>{h()&&(s("save",{...i.value}),v(),s("update:modelValue",!1))},b=()=>{v(),s("update:modelValue",!1)},v=()=>{i.value={name:"",type:"",apiKey:""},d.value={}};return(y,x)=>(a(),se(He,{"model-value":t.modelValue,"onUpdate:modelValue":x[4]||(x[4]=k=>y.$emit("update:modelValue",k)),title:"Add Provider",width:"max-w-md"},{footer:ge(()=>[e("div",{class:"flex gap-2 justify-end"},[e("button",{onClick:b,class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:_,class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Provider ")])]),default:ge(()=>[e("div",ib,[e("div",db,[x[6]||(x[6]=e("label",{class:"block text-sm font-medium"},[$e(" Provider Type "),e("span",{class:"text-red-500"},"*")],-1)),e("div",ub,[e("button",{type:"button",onClick:x[0]||(x[0]=k=>c.value=!c.value),onBlur:g,class:oe(["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm text-left focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white transition-colors",[d.value.type?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300"]])},[f.value?(a(),o("div",cb,[e("img",{src:f.value.icon,alt:f.value.label,class:"w-5 h-5"},null,8,pb),e("span",null,V(f.value.label),1)])):(a(),o("span",vb,"Select a provider")),x[5]||(x[5]=e("div",{class:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"})])],-1))],34),c.value?(a(),o("div",mb,[(a(!0),o(me,null,ye(l.value,k=>(a(),o("button",{key:k.value,type:"button",onClick:D=>{i.value.type=k.value,c.value=!1},class:"w-full px-3 py-2 text-left hover:bg-black/5 dark:hover:bg-white/10 transition-colors flex items-center gap-2"},[e("img",{src:k.icon,alt:k.label,class:"w-5 h-5"},null,8,hb),e("span",null,V(k.label),1)],8,fb))),128))])):M("",!0)]),d.value.type?(a(),o("p",gb,V(d.value.type),1)):M("",!0)]),P(Ee,{modelValue:i.value.name,"onUpdate:modelValue":x[1]||(x[1]=k=>i.value.name=k),label:"Provider Name",placeholder:"e.g., My OpenAI Provider",error:d.value.name,required:""},null,8,["modelValue","error"]),P(Ee,{modelValue:i.value.apiKey,"onUpdate:modelValue":x[2]||(x[2]=k=>i.value.apiKey=k),label:"API Key",type:"password",placeholder:"sk-...",error:d.value.apiKey,required:""},null,8,["modelValue","error"]),p.value?(a(),se(Ee,{key:0,modelValue:i.value.baseUrl,"onUpdate:modelValue":x[3]||(x[3]=k=>i.value.baseUrl=k),label:"Base URL",placeholder:"https://api.example.com",error:d.value.baseUrl,required:i.value.type==="custom"},null,8,["modelValue","error","required"])):M("",!0)])]),_:1},8,["model-value"]))}}),xb={class:"flex justify-between items-center mb-6"},yb=pe({__name:"ProvidersView",setup(t){const n=m(!1),s=m([]),i=m(!1),l=[{key:"name",label:"Name",width:"w-1/3"},{key:"sdk",label:"SDK Type",width:"w-1/3",formatter:g=>({"openai-sdk":"OpenAI SDK",openrouter:"OpenRouter",openai:"OpenAI"})[g]||g},{key:"hasApiKey",label:"API Key",width:"w-1/3",formatter:g=>g?"✓ Configured":"✗ Not configured"}],u=[{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this provider? This action cannot be undone.",handler:async g=>{await f(g.name)}}],r=async()=>{i.value=!0;try{const g=await fetch(de("/api/providers"));if(!g.ok)throw new Error("Failed to fetch providers");const d=await g.json();s.value=d.providers||[]}catch(g){console.error("Error fetching providers:",g),s.value=[]}finally{i.value=!1}},c=async g=>{try{const d=await fetch(de("/api/providers"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!d.ok){const p=await d.json();alert(p.error||"Failed to add provider");return}await r(),n.value=!1}catch(d){console.error("Error adding provider:",d),alert("Failed to add provider")}},f=async g=>{try{const d=await fetch(de(`/api/providers/${encodeURIComponent(g)}`),{method:"DELETE"});if(!d.ok){const p=await d.json();p.modelCount?alert(`${p.error}
11
+ `).trim():""),$=J(()=>{if(!s.log.response_body)return[];try{const N=JSON.parse(s.log.response_body)?.choices?.[0]?.message?.images;return Array.isArray(N)?N:[]}catch{return[]}}),K=J(()=>{if(!s.log.provider_tools)return[];try{const z=JSON.parse(s.log.provider_tools);return Array.isArray(z)?z:[]}catch{return[]}}),oe=J(()=>{if(!s.log.queued_tools)return[];try{const z=JSON.parse(s.log.queued_tools);return Array.isArray(z)?z:[]}catch{return[]}}),te=J(()=>{const z=[];for(const N of q.value)z.push({id:N.id||`tool-${z.length}`,name:N.function?.name||"Unknown",isProvider:!1,isQueued:!1,function:N.function});for(const N of oe.value)z.push({id:N.id||`queued-${z.length}`,name:N.function?.name||"Unknown",isProvider:!1,isQueued:!0,function:N.function,queuedAt:N.queued_at});for(const N of K.value)z.push({id:N.id,name:N.type,isProvider:!0,isQueued:!1,providerType:N.type,status:N.status,result:N.result});return z}),H=z=>{u.value.has(z)?u.value.delete(z):u.value.add(z)},P=z=>{r.value.has(z)?r.value.delete(z):r.value.add(z)},C=()=>{g.value=!g.value},L=()=>{d.value=!d.value},G=z=>{y.value.has(z)?y.value.delete(z):y.value.add(z)},ee=z=>!y.value.has(z),E=J(()=>{if(!s.log.errors)return[];try{const z=JSON.parse(s.log.errors);return Array.isArray(z)?z:[]}catch{return[]}}),U=v("standard"),Z=v(null),se=v(!1),j=v(null),M=["openai","openrouter"],w=()=>(s.log.actual_provider||s.log.provider)?.toLowerCase(),R=()=>{const z=w();z&&M.includes(z)?U.value=z:U.value="standard"},I=z=>z.charAt(0).toUpperCase()+z.slice(1);fe(U,async z=>{if(z==="standard"){Z.value=null,j.value=null;return}if(!s.threadId||!s.log.id){j.value="Missing thread or log ID";return}se.value=!0,j.value=null;try{const N=await fetch(ue(`/api/threads/${s.threadId}/logs/${s.log.id}/inspect/${z}`));if(!N.ok){const Q=await N.json();throw new Error(Q.error||"Failed to inspect")}Z.value=await N.json()}catch(N){j.value=N.message||"Failed to fetch inspected request",Z.value=null}finally{se.value=!1}}),fe(()=>s.log.id,async()=>{if(Z.value=null,j.value=null,R(),U.value!=="standard"&&s.threadId&&s.log.id){se.value=!0;try{const z=await fetch(ue(`/api/threads/${s.threadId}/logs/${s.log.id}/inspect/${U.value}`));if(!z.ok){const N=await z.json();throw new Error(N.error||"Failed to fetch inspected request")}Z.value=await z.json()}catch(z){j.value=z.message||"Failed to fetch inspected request"}finally{se.value=!1}}},{immediate:!0});const le=J(()=>{if(U.value==="standard"||!Z.value)return s.log.message_history;const z=Z.value.messagesPath,N=z?Z.value.body?.[z]:Z.value.body;return JSON.stringify(N,null,2)}),O=J(()=>U.value==="standard"||!Z.value?s.log.request_body:JSON.stringify(Z.value.body,null,2)),W=J(()=>U.value==="standard"||!Z.value?null:`${U.value} format`);fe(()=>s.log,()=>{Te(()=>{h.value?.checkHeight(),_.value?.checkHeight(),b.value?.checkHeight(),m.value?.checkHeight()})});const ce=async()=>{c.value=!0;try{if(!s.log.request_body||!s.log.model)throw new Error("Missing request data");const z=await fetch(ue(`/api/models/${s.log.model}/curl-data`));if(!z.ok)throw new Error("Failed to fetch model data");const N=await z.json(),Q=k(s.log.request_body);let we=`curl -X POST '${N.endpoint}' \\
12
+ `;we+=` -H 'Content-Type: application/json' \\
13
+ `,N.sdk?.toLowerCase()==="openrouter"?(we+=` -H 'Authorization: Bearer ${N.api_key}' \\
14
+ `,we+=` -H 'HTTP-Referer: https://agentkit.local' \\
15
+ `,we+=` -H 'X-Title: AgentKit' \\
16
+ `):N.sdk?.toLowerCase()==="openai"&&(we+=` -H 'Authorization: Bearer ${N.api_key}' \\
17
+ `),we+=` -d '${Q.replace(/'/g,"'\\''")}'`,await navigator.clipboard.writeText(we),f.value=!0,setTimeout(()=>{f.value=!1},2e3)}catch(z){console.error("Failed to copy cURL command:",z),alert(`Failed to copy cURL: ${z instanceof Error?z.message:"Unknown error"}`)}finally{c.value=!1}};return(z,N)=>(a(),o("div",{ref_key:"scrollContainer",ref:p,class:"p-4 h-full overflow-y-auto"},[e("div",Wc,[e("div",Jc,[e("div",Kc,[e("button",{onClick:N[0]||(N[0]=Q=>i("previous")),disabled:!t.hasPrevious,class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent dark:disabled:hover:bg-transparent transition-all","aria-label":"Previous log",title:"Previous log"},[...N[10]||(N[10]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("polyline",{points:"15 18 9 12 15 6"})],-1)])],8,Gc),e("button",{onClick:N[1]||(N[1]=Q=>i("next")),disabled:!t.hasNext,class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:bg-transparent dark:disabled:hover:bg-transparent transition-all","aria-label":"Next log",title:"Next log"},[...N[11]||(N[11]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("polyline",{points:"9 18 15 12 9 6"})],-1)])],8,Xc)]),e("h3",Yc,S(t.log.prompt_name||t.log.model_name||t.log.model),1)]),e("div",Qc,[e("button",{onClick:ce,disabled:c.value||!t.log.request_body,class:"px-3 py-1 text-xs font-medium bg-black text-white dark:bg-white dark:text-black rounded hover:opacity-80 disabled:opacity-50 disabled:cursor-not-allowed transition-opacity",title:t.log.request_body?"Copy cURL command":"No request data available"},[c.value?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",e0,S(f.value?"Copied!":"Copy cURL"),1))],8,Zc),e("button",{onClick:N[2]||(N[2]=Q=>i("close")),class:"w-7 h-7 flex items-center justify-center rounded border border-neutral-300 dark:border-neutral-600 text-neutral-500 hover:text-neutral-700 hover:bg-neutral-100 dark:text-neutral-400 dark:hover:text-neutral-200 dark:hover:bg-neutral-800 transition-all","aria-label":"Close details",title:"Close"},[...N[12]||(N[12]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[e("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])])])]),e("div",t0,[e("div",a0,[e("table",o0,[N[13]||(N[13]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Status "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Provider "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Prompt "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Latency "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Tokens "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Cost "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Created ")])],-1)),e("tbody",null,[e("tr",null,[e("td",{class:ae(["py-1 font-mono",t.log.error?"text-red-600 dark:text-red-400":t.log.is_complete?"text-green-600 dark:text-green-400":"text-yellow-600 dark:text-yellow-400"])},S(t.log.error?"ERROR":t.log.is_complete?"SUCCESS":"LOADING"),3),e("td",l0,S(t.log.actual_provider||t.log.provider),1),e("td",s0,[!t.log.is_complete&&!t.log.prompt_name?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",n0,S(t.log.prompt_name||"—"),1))]),e("td",r0,[!t.log.is_complete&&!t.log.latency_ms?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",i0,S(t.log.latency_ms?`${t.log.latency_ms}ms`:"—"),1))]),e("td",d0,[!t.log.is_complete&&!t.log.total_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",u0,S(t.log.total_tokens?`${t.log.input_tokens}/${t.log.output_tokens} (${t.log.total_tokens})`:"—"),1))]),e("td",c0,[!t.log.is_complete&&!t.log.cost_total?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",p0,S(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))]),e("td",m0,[A(rt,{timestamp:t.log.created_at},null,8,["timestamp"])])])])])]),e("div",v0,[e("table",f0,[N[14]||(N[14]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Status "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Provider "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Prompt ")])],-1)),e("tbody",null,[e("tr",null,[e("td",{class:ae(["py-1 font-mono",t.log.error?"text-red-600 dark:text-red-400":t.log.is_complete?"text-green-600 dark:text-green-400":"text-yellow-600 dark:text-yellow-400"])},S(t.log.error?"ERROR":t.log.is_complete?"SUCCESS":"LOADING"),3),e("td",h0,S(t.log.actual_provider||t.log.provider),1),e("td",g0,[!t.log.is_complete&&!t.log.prompt_name?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",b0,S(t.log.prompt_name||"—"),1))])])])]),e("table",x0,[N[15]||(N[15]=e("thead",null,[e("tr",{class:"border-b border-neutral-200 dark:border-neutral-800"},[e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Latency "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Tokens "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Cost "),e("th",{class:"text-left py-1 pr-4 text-neutral-600 dark:text-neutral-400 font-medium"}," Created ")])],-1)),e("tbody",null,[e("tr",null,[e("td",y0,[!t.log.is_complete&&!t.log.latency_ms?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",k0,S(t.log.latency_ms?`${t.log.latency_ms}ms`:"—"),1))]),e("td",w0,[!t.log.is_complete&&!t.log.total_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",_0,S(t.log.total_tokens?`${t.log.input_tokens}/${t.log.output_tokens} (${t.log.total_tokens})`:"—"),1))]),e("td",$0,[!t.log.is_complete&&!t.log.cost_total?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",C0,S(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))]),e("td",T0,[A(rt,{timestamp:t.log.created_at},null,8,["timestamp"])])])])])])]),e("div",S0,[e("div",V0,[e("button",{onClick:N[3]||(N[3]=Q=>l.value="request"),class:ae(["pb-2 px-1 text-sm font-medium border-b-2 transition-colors",l.value==="request"?"border-black dark:border-white text-black dark:text-white":"border-transparent text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-white"])}," Request ",2),e("button",{onClick:N[4]||(N[4]=Q=>l.value="response"),class:ae(["pb-2 px-1 text-sm font-medium border-b-2 transition-colors flex items-center gap-1",l.value==="response"?"border-black dark:border-white text-black dark:text-white":"border-transparent text-neutral-500 dark:text-neutral-400 hover:text-black dark:hover:text-white"])},[N[16]||(N[16]=Ce(" Response ",-1)),t.log.error||E.value.length>0?(a(),o("span",M0,"⚠")):V("",!0)],2)])]),e("div",I0,[Ie(e("div",E0,[e("div",L0,[N[17]||(N[17]=e("span",{class:"text-xs text-neutral-500 dark:text-neutral-400 mr-2"},"View as:",-1)),e("button",{onClick:N[5]||(N[5]=Q=>U.value="standard"),class:ae(["px-2 py-1 text-xs rounded transition-colors",U.value==="standard"?"bg-black text-white dark:bg-white dark:text-black":"bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400 hover:bg-neutral-200 dark:hover:bg-neutral-700"])}," Standard Agents ",2),(a(),o(ve,null,ke(M,Q=>e("button",{key:Q,onClick:we=>U.value=Q,class:ae(["px-2 py-1 text-xs rounded transition-colors",U.value===Q?"bg-black text-white dark:bg-white dark:text-black":"bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-400 hover:bg-neutral-200 dark:hover:bg-neutral-700"])},S(I(Q)),11,A0)),64)),se.value?(a(),ne(Se,{key:0,size:"xs",class:"ml-2"})):V("",!0),j.value?(a(),o("span",P0,S(j.value),1)):V("",!0)]),D.value.length>0?(a(),ne(pt,{key:0,ref_key:"toolsSectionRef",ref:h,title:`Available Tools (${D.value.length})`,"section-id":"tools",expanded:ee("tools"),"scroll-container":p.value,onToggle:N[6]||(N[6]=Q=>G("tools"))},{default:be(()=>[(a(!0),o(ve,null,ke(D.value,(Q,we)=>(a(),o("div",{key:we,class:"border-b border-neutral-200 dark:border-neutral-800 last:border-b-0"},[e("button",{onClick:de=>H(we),class:"w-full px-2 py-1.5 text-left hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors flex items-center justify-between text-xs"},[e("span",j0,S(Q.function?.name||Q.name||"Unknown"),1),e("span",O0,S(u.value.has(we)?"▼":"▶"),1)],8,D0),Ie(e("div",U0,[Q.function?.description||Q.description?(a(),o("div",R0,S(Q.function?.description||Q.description),1)):V("",!0),A(xt,{code:JSON.stringify(Q,null,2),language:"json"},null,8,["code"])],512),[[Ke,u.value.has(we)]])]))),128))]),_:1},8,["title","expanded","scroll-container"])):V("",!0),t.log.message_history?(a(),ne(pt,{key:1,ref_key:"messagesSectionRef",ref:_,title:`Messages (${t.log.message_history_length||0} messages)`,subtitle:W.value,"section-id":"messages",expanded:ee("messages"),"scroll-container":p.value,onToggle:N[7]||(N[7]=Q=>G("messages"))},{default:be(()=>[A(vt,{json:le.value,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])]),_:1},8,["title","subtitle","expanded","scroll-container"])):V("",!0),t.log.system_prompt?(a(),ne(pt,{key:2,ref_key:"systemPromptSectionRef",ref:b,title:"System Prompt","section-id":"system_prompt",expanded:ee("system_prompt"),"scroll-container":p.value,onToggle:N[8]||(N[8]=Q=>G("system_prompt"))},{default:be(()=>[e("div",N0,[A(xt,{code:t.log.system_prompt,language:"markdown"},null,8,["code"]),e("div",F0,[A(wa,{content:t.log.system_prompt,variant:"ghost",size:"xs"},null,8,["content"])])])]),_:1},8,["expanded","scroll-container"])):V("",!0),t.log.request_body?(a(),ne(pt,{key:3,ref_key:"requestBodySectionRef",ref:m,title:"Full Request Body",subtitle:W.value,"section-id":"request_body",expanded:ee("request_body"),"scroll-container":p.value,onToggle:N[9]||(N[9]=Q=>G("request_body"))},{default:be(()=>[A(vt,{json:O.value,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])]),_:1},8,["subtitle","expanded","scroll-container"])):V("",!0)],512),[[Ke,l.value==="request"]]),Ie(e("div",null,[E.value.length>0?(a(),o("div",B0,[e("div",q0,S(E.value.length>1?`Errors (${E.value.length})`:"Error"),1),e("div",z0,[(a(!0),o(ve,null,ke(E.value,(Q,we)=>(a(),o("div",{key:we,class:"border border-red-300 dark:border-red-700 rounded overflow-hidden"},[e("div",H0,S(Q.type||"error"),1),e("pre",W0,S(Q.message),1)]))),128))])])):t.log.error?(a(),o("div",J0,[e("div",K0," Error "+S(t.log.error_type?`(${t.log.error_type})`:""),1),e("pre",G0,S(t.log.error),1)])):V("",!0),t.log.is_complete||!t.log.error?(a(),o("div",X0,[N[25]||(N[25]=e("div",{class:"text-xs font-semibold mb-1"},"Response Stats",-1)),e("table",Y0,[e("tbody",null,[e("tr",Q0,[N[18]||(N[18]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Finish Reason ",-1)),e("td",Z0,[!t.log.is_complete&&!t.log.finish_reason?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",ep,S(t.log.finish_reason||"—"),1))])]),e("tr",tp,[N[19]||(N[19]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Input Tokens ",-1)),e("td",ap,[!t.log.is_complete&&!t.log.input_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",op,S(t.log.input_tokens||"—"),1))])]),t.log.cached_tokens||!t.log.is_complete?(a(),o("tr",lp,[N[20]||(N[20]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Cached Tokens ",-1)),e("td",sp,[!t.log.is_complete&&!t.log.cached_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",np,S(t.log.cached_tokens||0),1))])])):V("",!0),e("tr",rp,[N[21]||(N[21]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Output Tokens ",-1)),e("td",ip,[!t.log.is_complete&&!t.log.output_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",dp,S(t.log.output_tokens||"—"),1))])]),t.log.reasoning_tokens&&t.log.reasoning_tokens>0?(a(),o("tr",up,[N[22]||(N[22]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Reasoning Tokens ",-1)),e("td",cp,S(t.log.reasoning_tokens),1)])):V("",!0),e("tr",pp,[N[23]||(N[23]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Total Tokens ",-1)),e("td",mp,[!t.log.is_complete&&!t.log.total_tokens?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",vp,S(t.log.total_tokens||"—"),1))])]),e("tr",null,[N[24]||(N[24]=e("td",{class:"py-1 px-2 text-neutral-600 dark:text-neutral-400 font-medium bg-neutral-50 dark:bg-neutral-950"}," Total Cost ",-1)),e("td",fp,[!t.log.is_complete&&!t.log.cost_total?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",hp,S(t.log.cost_total?`$${t.log.cost_total.toFixed(6)}`:"—"),1))])])])])])):V("",!0),te.value.length>0?(a(),o("div",gp,[e("div",bp," Tools Called ("+S(te.value.length)+") ",1),e("div",xp,[(a(!0),o(ve,null,ke(te.value,Q=>(a(),o("div",{key:Q.id,class:"border-b border-neutral-200 dark:border-neutral-800 last:border-b-0"},[e("button",{onClick:we=>P(Q.id),class:"w-full px-2 py-1.5 text-left hover:bg-neutral-50 dark:hover:bg-neutral-900 transition-colors flex items-center justify-between text-xs"},[e("div",kp,[e("span",wp,S(Q.name),1),Q.isQueued?(a(),o("span",_p," programmatically invoked ")):V("",!0),Q.isProvider?(a(),o("span",$p," provider ")):V("",!0),Q.isProvider&&Q.status?(a(),o("span",{key:2,class:ae([Q.status==="completed"?"text-green-600 dark:text-green-400":Q.status==="failed"?"text-red-600 dark:text-red-400":"text-yellow-600 dark:text-yellow-400","text-[10px]"])},S(Q.status),3)):V("",!0)]),e("span",Cp,S(r.value.has(Q.id)?"▼":"▶"),1)],8,yp),Ie(e("div",{class:ae(["px-2 py-2 border-t border-neutral-200 dark:border-neutral-800",Q.isProvider?"bg-purple-50 dark:bg-purple-900/10":Q.isQueued?"bg-emerald-50 dark:bg-emerald-900/10":"bg-white dark:bg-neutral-950"])},[Q.isProvider?(a(),o(ve,{key:1},[e("div",Op,[N[32]||(N[32]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Provider Tool ID ",-1)),e("div",Up,S(Q.id),1)]),Q.providerType==="web_search"&&Q.result?.actions?(a(),o("div",Rp,[(a(!0),o(ve,null,ke(Q.result.actions,(we,de)=>(a(),o("div",{key:de,class:"mb-2"},[we.type==="search"?(a(),o("div",Np,[N[33]||(N[33]=e("span",{class:"font-medium"},"Searched:",-1)),Ce(' "'+S(we.query)+'" ',1)])):V("",!0),we.type==="open"?(a(),o("div",Fp,[N[34]||(N[34]=e("span",{class:"font-medium"},"Opened:",-1)),e("a",{href:we.url,target:"_blank",class:"text-blue-600 hover:underline ml-1"},S(we.url),9,Bp)])):V("",!0),we.sources?.length?(a(),o("div",qp,[(a(!0),o(ve,null,ke(we.sources.slice(0,5),(pe,ie)=>(a(),o("a",{key:ie,href:pe.url,target:"_blank",class:"block text-blue-600 hover:underline text-xs truncate"},S(pe.title||pe.url),9,zp))),128)),we.sources.length>5?(a(),o("span",Hp," ... and "+S(we.sources.length-5)+" more ",1)):V("",!0)])):V("",!0)]))),128))])):V("",!0),Q.providerType==="image_generation"?(a(),o("div",Wp,[Q.result?.imagePath?(a(),o("span",Jp,[N[35]||(N[35]=Ce(" Stored at: ",-1)),e("span",Kp,S(Q.result.imagePath),1)])):(a(),o("span",Gp," See Generated Images section below "))])):V("",!0),Q.providerType==="code_interpreter"&&Q.result?.output?(a(),o("div",Xp,[N[36]||(N[36]=e("div",{class:"font-medium text-neutral-600 dark:text-neutral-400 mb-1"},"Output:",-1)),e("pre",Yp,S(Q.result.output),1)])):V("",!0),Q.providerType==="file_search"&&Q.result?.results?.length?(a(),o("div",Qp,[e("div",Zp," Found "+S(Q.result.results.length)+" result(s) ",1)])):V("",!0)],64)):(a(),o(ve,{key:0},[Q.isQueued&&Q.queuedAt?(a(),o("div",Tp,[N[26]||(N[26]=e("div",{class:"font-semibold text-emerald-600 dark:text-emerald-400 mb-1"}," Invoked At ",-1)),e("div",Sp,[A(rt,{timestamp:Q.queuedAt},null,8,["timestamp"])])])):V("",!0),e("div",Vp,[N[27]||(N[27]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Tool Call ID ",-1)),e("div",Mp,S(Q.id),1)]),e("div",Ip,[N[28]||(N[28]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Function Name ",-1)),e("div",Ep,S(Q.function?.name),1)]),e("div",Lp,[N[29]||(N[29]=e("div",{class:"font-semibold text-neutral-600 dark:text-neutral-400 mb-1"}," Arguments ",-1)),e("div",Ap,[A(xt,{code:k(Q.function?.arguments||"{}"),language:"json"},null,8,["code"])])]),B.value.has(Q.id)?(a(),o("div",Pp,[N[30]||(N[30]=e("div",{class:"font-semibold text-green-600 dark:text-green-400 mb-1"}," Result ",-1)),e("pre",Dp,S(B.value.get(Q.id)?.content||"No content"),1)])):(a(),o("div",jp,[...N[31]||(N[31]=[e("div",{class:"font-semibold text-neutral-500 dark:text-neutral-500 mb-1"}," Result ",-1),e("div",{class:"text-xs text-neutral-500 dark:text-neutral-500 italic"}," No result available ",-1)])]))],64))],2),[[Ke,r.value.has(Q.id)]])]))),128))])])):V("",!0),$.value.length>0?(a(),o("div",em,[e("div",tm," Generated Images ("+S($.value.length)+") ",1),e("div",am,[N[37]||(N[37]=e("div",{class:"px-2 py-1.5 bg-emerald-100 dark:bg-emerald-900/30 text-xs text-emerald-800 dark:text-emerald-200 border-b border-emerald-300 dark:border-emerald-700"}," Images returned by the model ",-1)),e("div",om,[(a(!0),o(ve,null,ke($.value,(Q,we)=>(a(),o("div",{key:we,class:"relative"},[Q.image_url?.url?(a(),o("img",{key:0,src:x(Q.image_url.url)||Q.image_url.url,alt:`Generated image ${we+1}`,class:"max-w-[300px] max-h-[300px] rounded border border-emerald-200 dark:border-emerald-800 object-contain"},null,8,lm)):(a(),o("div",sm," No URL "))]))),128))])])])):V("",!0),t.log.reasoning_content?(a(),o("div",nm,[e("div",rm,[e("button",{onClick:C,class:"w-full px-2 py-1.5 bg-accent-100 dark:bg-accent-900/30 text-xs text-accent-800 dark:text-accent-200 flex items-center justify-between hover:bg-accent-200 dark:hover:bg-accent-900/50 transition-colors"},[N[38]||(N[38]=e("div",{class:"flex items-center gap-2"},[e("span",{class:"font-semibold"},"Reasoning Content"),e("span",{class:"text-accent-600 dark:text-accent-400 font-normal"}," Internal reasoning output (not displayed to users) ")],-1)),e("span",im,S(g.value?"▶":"▼"),1)]),Ie(e("pre",{class:"text-xs p-2 overflow-x-auto whitespace-pre-wrap max-h-96 text-accent-900 dark:text-accent-100 border-t border-accent-300 dark:border-accent-700"},S(T.value),513),[[Ke,!g.value]])])])):V("",!0),F.value.length>0?(a(),o("div",dm,[e("div",um,[e("button",{onClick:L,class:"w-full px-2 py-1.5 bg-purple-100 dark:bg-purple-900/30 text-xs text-purple-800 dark:text-purple-200 flex items-center justify-between hover:bg-purple-200 dark:hover:bg-purple-900/50 transition-colors"},[e("div",cm,[N[39]||(N[39]=e("span",{class:"font-semibold"},"Reasoning Details",-1)),e("span",pm,S(F.value.length)+" blocks ",1),N[40]||(N[40]=e("span",{class:"text-purple-600 dark:text-purple-400 font-normal"}," Structured reasoning from OpenRouter ",-1))]),e("span",mm,S(d.value?"▶":"▼"),1)]),Ie(e("div",vm,[(a(!0),o(ve,null,ke(F.value,(Q,we)=>(a(),o("div",{key:we,class:"p-2"},[e("div",fm,[e("span",hm,S(Q.type||"unknown"),1),Q.id?(a(),o("span",gm," ID: "+S(Q.id),1)):V("",!0),Q.format?(a(),o("span",bm," Format: "+S(Q.format),1)):V("",!0),Q.index!==void 0?(a(),o("span",xm," Index: "+S(Q.index),1)):V("",!0)]),Q.type==="reasoning.summary"&&Q.summary?(a(),o("div",ym,[N[41]||(N[41]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Summary: ",-1)),e("div",km,S(Q.summary),1)])):V("",!0),Q.type==="reasoning.encrypted"&&Q.data?(a(),o("div",wm,[N[42]||(N[42]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Encrypted Data: ",-1)),e("div",_m,S(Q.data),1)])):V("",!0),Q.type==="reasoning.text"&&Q.text?(a(),o("div",$m,[N[44]||(N[44]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Reasoning Text: ",-1)),e("div",Cm,S(Q.text),1),Q.signature?(a(),o("div",Tm,[N[43]||(N[43]=e("div",{class:"font-semibold text-purple-600 dark:text-purple-400 mb-1"}," Signature: ",-1)),e("div",Sm,S(Q.signature),1)])):V("",!0)])):V("",!0),["reasoning.summary","reasoning.encrypted","reasoning.text"].includes(Q.type)?V("",!0):(a(),o("div",Vm,[e("pre",Mm,S(JSON.stringify(Q,null,2)),1)]))]))),128))],512),[[Ke,!d.value]])])])):V("",!0),t.log.response_body?(a(),o("div",Im,[N[45]||(N[45]=e("div",{class:"text-xs font-semibold mb-1"},"Full Response Body",-1)),e("div",Em,[A(vt,{json:t.log.response_body,"thread-id":t.threadId,"show-copy-button":""},null,8,["json","thread-id"])])])):V("",!0)],512),[[Ke,l.value==="response"]])])],512))}}),Am={class:"flex flex-col h-full"},Pm={class:"px-4 py-3 border-b border-neutral-300 dark:border-neutral-700"},Dm={class:"flex items-center justify-between"},jm={class:"flex items-center gap-2"},Om={class:"flex items-center gap-2"},Um={key:0,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},Rm={key:1,class:"flex justify-center py-12"},Nm={key:2,class:"text-red-600 dark:text-red-400 text-center py-12"},Fm={key:3,class:"text-neutral-500 dark:text-neutral-400 text-center py-12"},Bm={key:4},qm={key:0,class:"border-b border-neutral-300 dark:border-neutral-700 bg-white dark:bg-black sticky top-0 z-10"},zm=["disabled"],Hm={key:1},Wm={key:2},Jm={key:3},Km={class:"w-full text-sm"},Gm=["onClick","onMouseenter"],Xm={class:"px-3 py-2 text-xs"},Ym={class:"flex items-center gap-1"},Qm={key:0,class:"text-neutral-400 dark:text-neutral-600 mr-1"},Zm={key:3},ev={class:"px-3 py-2"},tv={class:"flex items-center gap-2"},av={key:0,class:"text-red-600 dark:text-red-400",title:"Error"},ov={class:"font-mono text-xs"},lv={class:"px-3 py-2 font-mono text-xs"},sv={key:1},nv={key:1,class:"text-neutral-400"},rv={key:2},iv={key:0,class:"text-emerald-600 dark:text-emerald-400",title:"Programmatically called with state.queueTool()"},dv={key:1},uv={key:2},cv={key:0,class:"log-details-panel relative shrink-0 bg-neutral-100 dark:bg-neutral-950 border-t border-neutral-300 dark:border-neutral-700 overflow-hidden"},pv={class:"m-2 border h-[calc(100%-1rem)] border-neutral-300 shrink-0 dark:border-neutral-700 rounded-xl bg-white dark:bg-neutral-900 overflow-auto"},mv={key:0,class:"flex flex-col items-center justify-center h-full gap-3 text-neutral-500 dark:text-neutral-400"},vv={key:2,class:"absolute inset-0 bg-white/50 dark:bg-black/50 flex items-center justify-center"},qt=20,fv=20,hv=me({__name:"LogsPane",props:{threadId:{},selectedLogId:{},hoveredLogId:{}},emits:["collapse","logClick","logHover","logsLoaded"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(0),r=v(qt),{logs:c,hasMore:f,isFetching:g,error:d,wsConnected:p,wsError:h,connectWebSocket:_,disconnectWebSocket:b,refetch:m}=Sc(J(()=>i.threadId),{limit:J(()=>r.value),offset:J(()=>u.value),enableWebSocket:!0,order:"desc"}),y=v([]),x=v(!0),k=v(null),D=v(null),q=v(!1),B=v(!1),F=v(new Map),T=async()=>{await Te(),D.value&&(D.value.scrollTop=D.value.scrollHeight)},$=v(null);fe(c,async de=>{if(u.value===0)y.value=[...de].reverse(),x.value&&y.value.length>0&&(await T(),x.value=!1);else{const pe=[...de].reverse(),ie=new Map;y.value.forEach(ye=>ie.set(ye.id,ye)),pe.forEach(ye=>ie.set(ye.id,ye)),y.value=Array.from(ie.values()).sort((ye,_e)=>ye.created_at-_e.created_at)}},{deep:!0,immediate:!0}),fe(g,(de,pe)=>{if(pe&&!de&&u.value===0&&i.threadId&&$.value!==i.threadId&&y.value.length>0){$.value=i.threadId;const ie=y.value[y.value.length-1];l("logsLoaded",ie?.id??null)}});const{logDetails:K,isFetching:oe}=Vc(J(()=>i.threadId),J(()=>k.value)),te=J(()=>{if(!k.value)return null;const pe=y.value.find(ie=>ie.id===k.value);return pe?K.value?{...K.value,...pe}:pe:null}),H=J(()=>k.value?we.value.findIndex(de=>de.id===k.value):-1),P=J(()=>H.value>0),C=J(()=>H.value>=0&&H.value<we.value.length-1),L=()=>{if(P.value){const de=we.value[H.value-1];E(de)}},G=()=>{if(C.value){const de=we.value[H.value+1];E(de)}},ee=de=>{if(!D.value)return;const pe=F.value.get(de);if(!pe)return;const ie=D.value,ye=pe.getBoundingClientRect(),_e=ie.getBoundingClientRect(),Ae=ie.querySelectorAll(".sticky");let Fe=0;Ae.forEach(he=>{Fe+=he.getBoundingClientRect().height}),Fe+=16;const Re=ye.top<_e.top+Fe,xe=ye.bottom>_e.bottom;Re?ie.scrollBy({top:ye.top-_e.top-Fe,behavior:"smooth"}):xe&&ie.scrollBy({top:ye.bottom-_e.bottom,behavior:"smooth"})},E=de=>{l("logClick",de.id),k.value=de.id},U=(de,pe)=>{pe?F.value.set(de,pe):F.value.delete(de)};fe(k,async de=>{de&&(await Te(),ee(de))}),fe(()=>i.selectedLogId,de=>{de&&(k.value=de)},{immediate:!0});const Z=de=>{k.value=de},se=async de=>{await Te();const pe=F.value.get(de);if(pe&&D.value){const ie=D.value,ye=pe.getBoundingClientRect(),_e=ie.getBoundingClientRect(),Ae=ie.querySelector("thead"),Fe=ie.querySelector(":scope > div > div.sticky");let Re=0;Ae&&(Re+=Ae.getBoundingClientRect().height),Fe&&(Re+=Fe.getBoundingClientRect().height),Re+=40;const xe=ye.top<_e.top+Re,he=ye.bottom>_e.bottom;xe?ie.scrollBy({top:ye.top-_e.top-Re,behavior:"smooth"}):he&&ie.scrollBy({top:ye.bottom-_e.bottom,behavior:"smooth"})}},j=de=>{if(de.length===0)return;const pe=new Set(de);y.value=y.value.filter(ie=>!pe.has(ie.id))},M=v(!1),w=de=>y.value.some(pe=>pe.id===de),R=de=>y.value.find(pe=>pe.id===de)??null,I=(de,pe=3e3)=>new Promise(ie=>{const ye=Date.now(),_e=fe(y,()=>{y.value.length!==de&&(_e(),ie(!0))},{deep:!0}),Ae=setInterval(()=>{y.value.length!==de?(clearInterval(Ae),_e(),ie(!0)):Date.now()-ye>pe&&(clearInterval(Ae),_e(),ie(!1))},50)});n({scrollToLog:se,selectLogById:Z,removeLogsByIds:j,loadUntilLogId:async de=>{if(w(de))return!0;if(!f.value)return!1;M.value=!0;const pe=100,ie=50;try{let ye=0;for(;f.value&&!w(de)&&ye<ie;){ye++;const _e=y.value.length;if(u.value+=r.value,r.value=pe,await m(),!await I(_e))break}return w(de)}finally{M.value=!1}},hasLog:w,getLog:R,setLoadingForLog:de=>{M.value=de},waitForLogRow:async(de,pe=2e3)=>{const ie=Date.now();for(;Date.now()-ie<pe;){if(F.value.has(de))return!0;if(!we.value.some(_e=>_e.id===de)){await Te(),await new Promise(_e=>setTimeout(_e,16));continue}await Te(),await new Promise(_e=>setTimeout(_e,16))}return!1}});const ce=async()=>{if(B.value||!f.value||g.value)return;B.value=!0;const de=D.value?.scrollHeight||0;if(u.value+=r.value,r.value=fv,await m(),await Te(),D.value){const pe=D.value.scrollHeight;D.value.scrollTop+=pe-de}B.value=!1};fe(()=>i.threadId,async de=>{de?(b(),_()):b(),u.value=0,r.value=qt,y.value=[],k.value=null,q.value=!1,x.value=!0},{immediate:!0}),fe(y,async()=>{q.value||await T()},{deep:!0});const z=()=>{if(!D.value)return;const{scrollTop:de,scrollHeight:pe,clientHeight:ie}=D.value,ye=pe-de-ie<50;q.value=!ye},N=de=>{const pe=[];if(de.tools_called)try{const ie=JSON.parse(de.tools_called);Array.isArray(ie)&&pe.push(...ie.map(ye=>({name:ye,isProgrammatic:!1})))}catch{}if(de.provider_tools)try{const ie=JSON.parse(de.provider_tools);Array.isArray(ie)&&pe.push(...ie.map(ye=>({name:ye.type,isProgrammatic:!1})))}catch{}if(de.queued_tools)try{const ie=JSON.parse(de.queued_tools);Array.isArray(ie)&&pe.push(...ie.map(ye=>({name:ye.function?.name||"unknown",isProgrammatic:!0})))}catch{}return pe},Q=de=>de==null?"—":`$${de.toFixed(6)}`,we=J(()=>{const de=new Map,pe=new Map;y.value.forEach(_e=>{de.set(_e.id,_e);const Ae=_e.parent_log_id;Ae&&(pe.has(Ae)||pe.set(Ae,[]),pe.get(Ae).push(_e))});const ie=[],ye=(_e,Ae)=>{ie.push({..._e,depth:Ae}),(pe.get(_e.id)||[]).forEach(Re=>{ye(Re,Ae+1)})};return y.value.forEach(_e=>{_e.parent_log_id||ye(_e,0)}),ie});return(de,pe)=>(a(),o("div",Am,[e("div",Pm,[e("div",Dm,[e("div",jm,[A(X(la),{size:18,class:"shrink-0"}),pe[4]||(pe[4]=e("h2",{class:"text-base font-bold"},"Logs",-1)),t.threadId?(a(),ne(Vt,{key:0,connected:X(p),error:X(h)},null,8,["connected","error"])):V("",!0)]),e("div",Om,[e("button",{onClick:pe[0]||(pe[0]=ie=>l("collapse")),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Collapse pane"},[A(X(Tt),{size:20})])])])]),e("div",{ref_key:"logsScrollContainer",ref:D,class:"logs-list-container flex-1 overflow-y-auto overflow-x-auto",onScroll:z},[t.threadId?X(g)&&u.value===0?(a(),o("div",Rm,[A(Se)])):X(d)?(a(),o("div",Nm," Error loading logs: "+S(X(d)),1)):y.value.length===0?(a(),o("div",Fm," No logs yet ")):(a(),o("div",Bm,[X(f)?(a(),o("div",qm,[e("button",{onClick:ce,disabled:B.value||M.value,type:"button",class:"w-full px-3 py-2 text-xs font-medium text-neutral-700 dark:text-neutral-300 hover:bg-neutral-100 dark:hover:bg-neutral-900 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"},[B.value||M.value?(a(),ne(Se,{key:0,size:"xs"})):V("",!0),M.value?(a(),o("span",Hm,"Loading to find log...")):B.value?(a(),o("span",Wm,"Loading older logs...")):(a(),o("span",Jm,"Load previous logs"))],8,zm)])):V("",!0),e("table",Km,[e("thead",{class:ae(["border-b border-neutral-300 dark:border-neutral-700 sticky bg-white z-[10] dark:bg-black",{"top-0":!X(f),"top-[34px]":X(f)}])},[...pe[5]||(pe[5]=[e("tr",null,[e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Prompt"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Model"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Cost"),e("th",{class:"text-left px-3 py-1.5 text-xs font-semibold"},"Tools Called"),e("th",{class:"text-right px-3 py-1.5 text-xs font-semibold"},"Called At")],-1)])],2),e("tbody",null,[(a(!0),o(ve,null,ke(we.value,ie=>(a(),o("tr",{key:ie.id,ref_for:!0,ref:ye=>U(ie.id,ye),class:ae(["border-b border-neutral-200 dark:border-neutral-800 cursor-pointer transition-colors relative",{"last:border-b-0":te.value,"bg-red-50 dark:bg-red-950/20":ie.error,"bg-accent-100 dark:bg-accent-900 dark:text-white":k.value===ie.id,"ring-2 ring-inset ring-accent-400 dark:ring-accent-400":ie.id===i.selectedLogId||ie.id!==i.selectedLogId&&ie.id===i.hoveredLogId}]),onClick:ye=>E(ie),onMouseenter:ye=>l("logHover",ie.id),onMouseleave:pe[1]||(pe[1]=ye=>l("logHover",null))},[e("td",Xm,[e("div",Ym,[ie.depth>0?(a(),o("span",Qm,"└─")):V("",!0),ie.retry_of_log_id?(a(),ne(X(Za),{key:1,size:14,class:"text-neutral-500 dark:text-neutral-400 flex-shrink-0"})):V("",!0),!ie.is_complete&&!ie.prompt_name?(a(),ne(Se,{key:2,size:"xs"})):(a(),o("span",Zm,S(ie.prompt_name||"—"),1))])]),e("td",ev,[e("div",tv,[ie.error?(a(),o("span",av," ✕ ")):V("",!0),e("span",ov,S(ie.model_name||ie.model),1)])]),e("td",lv,[!ie.is_complete&&!ie.cost_total?(a(),ne(Se,{key:0,size:"xs"})):(a(),o("span",sv,S(Q(ie.cost_total)),1))]),e("td",{class:ae(["px-3 py-2 text-xs",k.value===ie.id?"text-neutral-800 dark:text-neutral-100":"text-neutral-600 dark:text-neutral-400"])},[!ie.is_complete&&N(ie).length===0?(a(),ne(Se,{key:0,size:"xs"})):N(ie).length===0?(a(),o("span",nv,"—")):(a(),o("span",rv,[(a(!0),o(ve,null,ke(N(ie),(ye,_e)=>(a(),o(ve,{key:_e},[ye.isProgrammatic?(a(),o("span",iv,[A(X(eo),{size:11,class:"inline-block -mt-0.5 mr-0.5"}),Ce(S(ye.name),1)])):(a(),o("span",dv,S(ye.name),1)),_e<N(ie).length-1?(a(),o("span",uv,", ")):V("",!0)],64))),128))]))],2),e("td",{class:ae(["px-3 py-2 text-right text-xs",k.value===ie.id?"text-neutral-800 dark:text-neutral-100":"text-neutral-500 dark:text-neutral-500"])},[A(rt,{timestamp:ie.created_at},null,8,["timestamp"])],2)],42,Gm))),128))])])])):(a(),o("div",Um," Select a thread to view logs "))],544),A(Xe,{name:"slide-up",onAfterEnter:pe[3]||(pe[3]=()=>k.value&&ee(k.value))},{default:be(()=>[te.value||M.value&&k.value?(a(),o("div",cv,[e("div",pv,[M.value&&!te.value?(a(),o("div",mv,[A(Se),pe[6]||(pe[6]=e("span",{class:"text-sm"},"Loading log...",-1))])):te.value?(a(),ne(Lm,{key:1,log:te.value,"thread-id":t.threadId,"has-previous":P.value,"has-next":C.value,onClose:pe[2]||(pe[2]=ie=>k.value=null),onPrevious:L,onNext:G},null,8,["log","thread-id","has-previous","has-next"])):V("",!0),X(oe)&&te.value?(a(),o("div",vv,[A(Se)])):V("",!0)])])):V("",!0)]),_:1})]))}}),gv=tt(hv,[["__scopeId","data-v-63163597"]]),bv={class:"space-y-4"},xv={key:0,class:"p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded text-sm text-red-800 dark:text-red-200"},yv={class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},kv={key:0},wv={key:1},_v={key:1,class:"space-y-4 p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},$v={key:3,class:"flex items-center gap-2"},Cv=["onUpdate:modelValue","id"],Tv=["for"],Sv={key:0,class:"text-red-500"},Vv={key:5,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-1"},Mv={key:2,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg text-center text-sm text-neutral-500"},Iv={key:3,class:"space-y-4"},Ev={key:0,class:"p-4 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-700 rounded-lg"},Lv={class:"space-y-3"},Av={key:0,class:"text-xs text-amber-500 dark:text-amber-400 mt-1"},Pv={key:1,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},Dv={key:4,class:"p-4 bg-neutral-50 dark:bg-neutral-900 rounded-lg text-center text-sm text-neutral-500"},jv={key:5},Ov={key:0,class:"space-y-3 mb-4 max-h-64 overflow-y-auto p-2"},Uv={class:"text-xs font-medium mb-1 opacity-70"},Rv={class:"text-sm whitespace-pre-wrap"},Nv=["onClick"],Fv={key:1,class:"text-center py-8 text-neutral-500 dark:text-neutral-400 text-sm"},Bv={class:"space-y-2"},qv={class:"flex items-stretch border border-black dark:border-neutral-300 rounded overflow-hidden bg-white dark:bg-neutral-900"},zv=["disabled","title"],Hv={class:"flex-1 relative"},Wv=["disabled","title"],Jv={class:"text-xs text-neutral-500 dark:text-neutral-400"},Kv={class:"flex justify-between"},Gv=["disabled"],Xv=["disabled"],Yv=me({__name:"CreateThreadModal",props:{modelValue:{type:Boolean},editThread:{}},emits:["update:modelValue","thread-created","thread-updated"],setup(t,{emit:n}){const s=t,i=n,l=J(()=>!!s.editThread),u=v(""),r=v(""),c=v({}),f=v([]),g=v(""),d=v(!1),p=v(""),h=v(null),_=v({}),b=v([]),m=v(!1),{data:y,isFetching:x,execute:k}=Ue(ue("/api/agents"),{immediate:!1}).json(),D=J(()=>y.value?(y.value?.agents||[]).map(w=>({value:w.id,label:w.title})):[]),q=J(()=>!u.value||!y.value?null:(y.value?.agents||[]).find(w=>w.id===u.value)),B=J(()=>q.value&&q.value.type==="ai_human"?"AI":"Side A"),F=J(()=>q.value&&q.value.type==="ai_human"?"Human":"Side B"),{data:T,isFetching:$,execute:K}=Ue(J(()=>q.value?.side_a_system_prompt?ue(`/api/prompts/${q.value.side_a_system_prompt}`):""),{immediate:!1}).json(),oe=J(()=>{if(!T.value)return null;const M=T.value?.required_schema;if(!M)return null;try{return typeof M=="string"?JSON.parse(M):M}catch{return null}}),te=J(()=>b.value.filter(M=>M.required&&!M.value&&!_.value[M.name])),H=J(()=>b.value.filter(M=>M.value!==void 0||!M.required)),P=J(()=>b.value.length>0),C=async M=>{if(!M){b.value=[],_.value={};return}m.value=!0;try{const w=await fetch(ue(`/api/agents/${M}/tenvs`));if(w.ok){const R=await w.json();b.value=R.tenvs||[],_.value=R.merged||{}}else b.value=[],_.value={}}catch(w){console.error("Error fetching agent tenvs:",w),b.value=[],_.value={}}finally{m.value=!1}},L=J(()=>{const M=oe.value;return!M||!M.properties?[]:Object.entries(M.properties).map(([w,R])=>({name:w,type:R.type||"string",description:R.description||"",required:M.required?.includes(w)||!1,enum:R.enum}))});fe(u,async M=>{M&&q.value?.side_a_system_prompt?(await K(),c.value={}):c.value={},M?await C(M):(b.value=[],_.value={})});const G=()=>{const M=h.value;M&&(M.style.height="auto",M.style.height=`${M.scrollHeight}px`)},ee=M=>{g.value.trim()&&(f.value.push({id:crypto.randomUUID(),role:M,content:g.value.trim()}),g.value="",setTimeout(()=>G(),0))},E=M=>{f.value=f.value.filter(w=>w.id!==M)},U=()=>{u.value="",r.value="",c.value={},f.value=[],g.value="",p.value="",_.value={},b.value=[]},Z=()=>{s.editThread&&(u.value=s.editThread.agent_id,r.value=s.editThread.tags?.join(", ")||"")},se=async()=>{if(!u.value){p.value="Please select an agent";return}if(!l.value&&L.value.length>0){for(const M of L.value)if(M.required&&!c.value[M.name]){p.value=`Please provide ${M.name}`;return}}if(!l.value&&te.value.length>0){for(const M of te.value)if(!_.value[M.name]){p.value=`Please provide required environment variable: ${M.name}`;return}}d.value=!0,p.value="";try{const M=r.value.split(",").map(w=>w.trim()).filter(w=>w.length>0);if(l.value){const w=await fetch(ue(`/api/threads/${s.editThread.id}`),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({tags:M})});if(!w.ok){const R=await w.json();throw new Error(R.error||"Failed to update thread")}i("thread-updated"),U(),i("update:modelValue",!1)}else{const w={agent_id:u.value,tags:M.length>0?M:void 0};f.value.length>0&&(w.initial_messages=f.value.map(O=>({role:O.role,content:O.content}))),Object.keys(c.value).length>0&&(w.data=c.value),Object.keys(_.value).length>0&&(w.tenvs=_.value);const R=await fetch(ue("/api/threads"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!R.ok){const O=await R.json();throw new Error(O.error||"Failed to create thread")}const le=(await R.json()).threadId;if(!le)throw new Error("Thread created but ID not found in response");i("thread-created",le),U(),i("update:modelValue",!1)}}catch(M){console.error(`Error ${l.value?"updating":"creating"} thread:`,M),p.value=M.message||`Failed to ${l.value?"update":"create"} thread`}finally{d.value=!1}},j=()=>{U(),i("update:modelValue",!1)};return fe(()=>s.modelValue,async M=>{M&&(await k(),U(),l.value&&Z())}),(M,w)=>(a(),ne(He,{"model-value":t.modelValue,"onUpdate:modelValue":w[8]||(w[8]=R=>M.$emit("update:modelValue",R)),title:l.value?"Edit Thread":"Create New Thread",width:"max-w-3xl"},{footer:be(()=>[e("div",Kv,[e("button",{onClick:j,type:"button",disabled:d.value,class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors disabled:opacity-50"}," Cancel ",8,Gv),e("button",{onClick:se,type:"button",disabled:d.value||X(x),class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity disabled:opacity-50"},[l.value?(a(),o(ve,{key:0},[Ce(S(d.value?"Updating...":"Update Thread"),1)],64)):(a(),o(ve,{key:1},[Ce(S(d.value?"Creating...":"Create Thread"),1)],64))],8,Xv)])]),default:be(()=>[e("div",bv,[p.value?(a(),o("div",xv,S(p.value),1)):V("",!0),e("div",null,[A(Ve,{modelValue:u.value,"onUpdate:modelValue":w[0]||(w[0]=R=>u.value=R),label:"Agent",options:D.value,disabled:X(x)||l.value,placeholder:"Select an agent...",required:""},null,8,["modelValue","options","disabled"]),e("p",yv,[l.value?(a(),o("span",kv,"Agent cannot be changed after thread creation")):(a(),o("span",wv,"Choose which agent will handle this conversation"))])]),!l.value&&L.value.length>0&&!X($)?(a(),o("div",_v,[w[9]||(w[9]=e("h4",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300"}," Required Information ",-1)),(a(!0),o(ve,null,ke(L.value,R=>(a(),o("div",{key:R.name,class:"space-y-2"},[R.enum?(a(),ne(Ve,{key:0,modelValue:c.value[R.name],"onUpdate:modelValue":I=>c.value[R.name]=I,label:R.name,options:[{value:"",label:"Select..."},...R.enum.map(I=>({value:I,label:I}))],required:R.required},null,8,["modelValue","onUpdate:modelValue","label","options","required"])):R.type==="string"?(a(),ne(Le,{key:1,modelValue:c.value[R.name],"onUpdate:modelValue":I=>c.value[R.name]=I,label:R.name,placeholder:R.description,required:R.required},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])):R.type==="number"||R.type==="integer"?(a(),ne(Le,{key:2,modelValue:c.value[R.name],"onUpdate:modelValue":I=>c.value[R.name]=I,modelModifiers:{number:!0},label:R.name,placeholder:R.description,type:"number",required:R.required},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])):R.type==="boolean"?(a(),o("div",$v,[Ie(e("input",{"onUpdate:modelValue":I=>c.value[R.name]=I,type:"checkbox",id:`field-${R.name}`,class:"w-4 h-4"},null,8,Cv),[[sa,c.value[R.name]]]),e("label",{for:`field-${R.name}`,class:"text-sm"},[Ce(S(R.name)+" ",1),R.required?(a(),o("span",Sv,"*")):V("",!0)],8,Tv)])):(a(),ne(ya,{key:4,modelValue:c.value[R.name],"onUpdate:modelValue":I=>c.value[R.name]=I,label:R.name,placeholder:R.description||`Enter ${R.name} (JSON format)`,required:R.required,rows:3},null,8,["modelValue","onUpdate:modelValue","label","placeholder","required"])),R.description?(a(),o("p",Vv,S(R.description),1)):V("",!0)]))),128))])):V("",!0),!l.value&&X($)?(a(),o("div",Mv," Loading agent requirements... ")):V("",!0),!l.value&&P.value&&!m.value?(a(),o("div",Iv,[te.value.length>0?(a(),o("div",Ev,[w[10]||(w[10]=e("h4",{class:"text-sm font-medium text-amber-800 dark:text-amber-200 mb-3"}," Required Environment Variables ",-1)),w[11]||(w[11]=e("p",{class:"text-xs text-amber-600 dark:text-amber-300 mb-3"}," These values are required by the agent's tools and must be provided. ",-1)),e("div",Lv,[(a(!0),o(ve,null,ke(te.value,R=>(a(),o("div",{key:R.name},[A(Le,{"model-value":_.value[R.name]||"","onUpdate:modelValue":I=>_.value[R.name]=I,label:R.name,placeholder:R.description||"Enter value...",required:""},null,8,["model-value","onUpdate:modelValue","label","placeholder"]),R.source?(a(),o("p",Av," Required by: "+S(R.source),1)):V("",!0)]))),128))])])):V("",!0),H.value.length>0?(a(),o("div",Pv,[w[12]||(w[12]=e("h4",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-3"}," Environment Configuration ",-1)),w[13]||(w[13]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 mb-3"}," Values inherited from the agent. Click the lock icon to override. ",-1)),A(ka,{modelValue:_.value,"onUpdate:modelValue":w[1]||(w[1]=R=>_.value=R),inherited:H.value,"allow-custom":!0},null,8,["modelValue","inherited"])])):V("",!0)])):V("",!0),!l.value&&m.value?(a(),o("div",Dv," Loading environment configuration... ")):V("",!0),l.value?V("",!0):(a(),o("div",jv,[w[16]||(w[16]=e("h4",{class:"text-sm font-medium mb-3"},"Initial Conversation",-1)),f.value.length>0?(a(),o("div",Ov,[(a(!0),o(ve,null,ke(f.value,R=>(a(),o("div",{key:R.id,class:ae(["flex items-start gap-2",{"justify-start":R.role==="assistant","justify-end":R.role==="user"}])},[e("div",{class:ae(["max-w-[80%] rounded-2xl px-4 py-2 break-words",{"bg-black text-white dark:bg-white dark:text-black":R.role==="assistant","bg-neutral-200 text-black dark:bg-neutral-800 dark:text-white":R.role==="user"}])},[e("div",Uv,S(R.role==="assistant"?B.value:F.value),1),e("div",Rv,S(R.content),1)],2),e("button",{onClick:I=>E(R.id),type:"button",class:"text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-200 text-xs mt-2"}," ✕ ",8,Nv)],2))),128))])):(a(),o("div",Fv," No messages yet. Add messages to start the conversation. ")),e("div",Bv,[e("div",qv,[e("button",{onClick:w[2]||(w[2]=R=>ee("assistant")),type:"button",disabled:!g.value.trim(),title:`Add as ${B.value}`,class:"px-3 py-2 bg-black text-white dark:bg-white dark:text-black text-sm hover:opacity-90 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap inline-flex items-center gap-1 border-r border-black dark:border-neutral-300 flex-shrink-0"},[w[14]||(w[14]=e("svg",{class:"w-[1em] h-[1em]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 10l7-7m0 0l7 7m-7-7v18"})],-1)),e("span",null,S(B.value),1)],8,zv),e("div",Hv,[Ie(e("textarea",{"onUpdate:modelValue":w[3]||(w[3]=R=>g.value=R),placeholder:"Type a message...",class:"w-full px-3 py-2 bg-transparent border-0 font-mono text-sm focus:outline-none resize-none overflow-hidden",rows:"1",ref_key:"textareaRef",ref:h,onInput:G,onKeydown:[w[4]||(w[4]=wt(Ee(R=>ee("user"),["meta"]),["enter"])),w[5]||(w[5]=wt(Ee(R=>ee("user"),["ctrl"]),["enter"]))]},null,544),[[Oe,g.value]])]),e("button",{onClick:w[6]||(w[6]=R=>ee("user")),type:"button",disabled:!g.value.trim(),title:`Add as ${F.value}`,class:"px-3 py-2 bg-black text-white dark:bg-white dark:text-black text-sm hover:opacity-90 transition-opacity disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap inline-flex items-center gap-1 border-l border-black dark:border-neutral-300 flex-shrink-0"},[w[15]||(w[15]=e("svg",{class:"w-[1em] h-[1em]",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M5 10l7-7m0 0l7 7m-7-7v18"})],-1)),e("span",null,S(F.value),1)],8,Wv)]),e("p",Jv," Type a message and click "+S(B.value)+" (left) or "+S(F.value)+" (right) to add. Or press Cmd+Enter (Mac) / Ctrl+Enter (Windows) to add as "+S(F.value)+". ",1)])])),e("div",null,[A(Le,{modelValue:r.value,"onUpdate:modelValue":w[7]||(w[7]=R=>r.value=R),label:"Tags",placeholder:"research, urgent, production"},null,8,["modelValue"]),w[17]||(w[17]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Comma-separated tags to help organize and search threads ",-1))])])]),_:1},8,["model-value","title"]))}}),Qv={class:"flex h-full overflow-hidden"},Zv={key:0,class:"flex flex-col items-center p-4"},ef={key:0,class:"flex flex-col items-center p-4"},tf={key:0,class:"flex flex-col items-center p-4"},zt=me({__name:"ThreadsView",setup(t){const n=Ye(),s=lt(),i=v(typeof n.params.id=="string"?n.params.id:null),l=v({threadList:!1,messages:!1,logs:!1}),u=v(!1),r=v(null),c=v(null),{thread:f}=St(J(()=>i.value)),g=v(null),d=v(null),p=v(null),h=v(null),_=v(null),b=C=>{h.value=C,_.value=C},m=C=>{if(h.value=C,!C){_.value=null;return}_.value=C;const L=y.value,G=x.value;if(!L||!G||L.hasWorkblockForLogId(C))return;let ee=C;const E=10;for(let U=0;U<E&&ee;U++){const Z=G.getLog(ee);if(!Z)break;const se=Z.parent_log_id;if(!se)break;if(L.hasWorkblockForLogId(se)){_.value=se;return}ee=se}},y=v(null),x=v(null);fe(()=>n.params.id,C=>{i.value=typeof C=="string"?C:null,g.value=null,d.value=null,p.value=null});const k=C=>{s.push(`/threads/${C}`)},D=C=>{window.location.href="/threads"},q=()=>{f.value&&(r.value=f.value,u.value=!0)},B=()=>{r.value=null,u.value=!0},F=C=>{c.value?.refetch(),s.push(`/threads/${C}`)},T=()=>{window.location.reload()},$=C=>{l.value[C]=!l.value[C]},K=async(C,L)=>{if(g.value=C,!L){d.value=null,p.value=null;return}const G=x.value;if(!G){d.value=L,p.value=L;return}const ee=!G.hasLog(L);if(ee&&G.setLoadingForLog(!0),d.value=L,p.value=L,ee&&!await G.loadUntilLogId(L)){console.warn(`Could not find log ${L} after loading all available logs`),G.setLoadingForLog(!1);return}if(!await G.waitForLogRow(L)){console.warn(`Log row ${L} not rendered in time`);return}G.scrollToLog(L),G.selectLogById(L)},oe=C=>{d.value=C,p.value=C,g.value=null;const L=y.value,G=x.value;if(!L||!G)return;let ee=L.scrollToLogId(C);if(ee)return;let E=C;const U=10;for(let Z=0;Z<U&&E;Z++){const se=G.getLog(E);if(!se)break;const j=se.parent_log_id;if(!j)break;if(ee=L.scrollToLogId(j),ee){p.value=j;return}E=j}},te=C=>{C&&(d.value=C)},H=C=>{x.value?.removeLogsByIds(C)},P=C=>{C&&!i.value&&s.push(`/threads/${C}`)};return(C,L)=>(a(),o("div",Qv,[e("div",{class:ae([l.value.threadList?"w-[60px]":"w-[320px]","border-r border-neutral-300 dark:border-neutral-700 flex-shrink-0 transition-all duration-200 flex flex-col min-h-0"])},[l.value.threadList?(a(),o("div",Zv,[e("button",{onClick:L[0]||(L[0]=G=>$("threadList")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Threads pane"},[A(X(Qt),{size:20})])])):(a(),ne(ji,{key:1,ref_key:"threadListPaneRef",ref:c,"selected-thread-id":i.value,onSelectThread:k,onCollapse:L[1]||(L[1]=G=>$("threadList")),onCreateThread:B,onThreadsLoaded:P},null,8,["selected-thread-id"]))],2),e("div",{class:ae([l.value.messages?"w-[60px]":"w-[380px]","border-r border-neutral-300 dark:border-neutral-700 flex-shrink-0 overflow-hidden transition-all duration-200 flex flex-col min-h-0"])},[l.value.messages?(a(),o("div",ef,[e("button",{onClick:L[2]||(L[2]=G=>$("messages")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Messages pane"},[A(X(oa),{size:20})])])):i.value?(a(),ne(X($o),{key:1,"thread-id":i.value,preload:!0,live:!0,"include-silent":!0,"use-workblocks":!0},{default:be(()=>[A(Bt,{ref_key:"messagesPaneRef",ref:y,"thread-id":i.value,"selected-message-id":g.value,"selected-log-id":p.value,"hovered-log-id":_.value,onCollapse:L[3]||(L[3]=G=>$("messages")),onMessageClick:K,onMessageHover:b,onThreadDeleted:D,onEditThread:q,onLogsDeleted:H},null,8,["thread-id","selected-message-id","selected-log-id","hovered-log-id"])]),_:1},8,["thread-id"])):l.value.messages?V("",!0):(a(),ne(Bt,{key:2,ref_key:"messagesPaneRef",ref:y,"thread-id":null,"selected-message-id":g.value,"selected-log-id":p.value,"hovered-log-id":_.value,onCollapse:L[4]||(L[4]=G=>$("messages")),onMessageClick:K,onMessageHover:b,onThreadDeleted:D,onEditThread:q,onLogsDeleted:H},null,8,["selected-message-id","selected-log-id","hovered-log-id"]))],2),e("div",{class:ae([l.value.logs?"w-[60px]":"flex-1","overflow-hidden transition-all duration-200 flex flex-col min-h-0"])},[l.value.logs?(a(),o("div",tf,[e("button",{onClick:L[5]||(L[5]=G=>$("logs")),class:"p-2 hover:bg-neutral-100 dark:hover:bg-neutral-900 rounded transition-colors",title:"Expand Logs pane"},[A(X(la),{size:20})])])):(a(),ne(gv,{key:1,ref_key:"logsPaneRef",ref:x,"thread-id":i.value,"selected-log-id":d.value,"hovered-log-id":h.value,onCollapse:L[6]||(L[6]=G=>$("logs")),onLogClick:oe,onLogHover:m,onLogsLoaded:te},null,8,["thread-id","selected-log-id","hovered-log-id"]))],2),A(Yv,{modelValue:u.value,"onUpdate:modelValue":L[7]||(L[7]=G=>u.value=G),"edit-thread":r.value,onThreadCreated:F,onThreadUpdated:T},null,8,["modelValue","edit-thread"])]))}}),af=me({__name:"PromptsDataTable",emits:["add","edit","delete"],setup(t,{expose:n,emit:s}){const i=s,l=v([]),u=v(!1),r=[{key:"name",label:"Name",width:"w-1/4"},{key:"tool_description",label:"Description",width:"w-2/5"},{key:"model_name",label:"Model",width:"w-1/5",formatter:(d,p)=>d||p.model_id||"-"},{key:"created_at",label:"Created",width:"w-1/6",formatter:d=>d?new Date(d*1e3).toLocaleDateString():"-"}],c=[{icon:"edit",label:"Edit",handler:d=>i("edit",d)},{icon:"delete",label:"Delete",handler:async d=>{await g(d)},confirm:!0,confirmMessage:"Are you sure you want to delete this prompt?"}],f=async()=>{u.value=!0;try{const d=await fetch(ue("/api/prompts"));if(d.ok){const p=await d.json();l.value=p.prompts||[]}}catch(d){console.error("Error fetching prompts:",d)}finally{u.value=!1}},g=async d=>{try{const p=await fetch(ue(`/api/prompts/${d.id}`),{method:"DELETE"});if(p.ok)await f();else{const h=await p.json();alert(h.error||"Failed to delete prompt")}}catch(p){console.error("Error deleting prompt:",p),alert("Failed to delete prompt")}};return Me(()=>{f()}),n({refresh:f}),(d,p)=>(a(),o("div",null,[A(Ge,{columns:r,data:l.value,actions:c,loading:u.value,"empty-message":"No prompts available. Create your first prompt to get started."},null,8,["data","loading"])]))}}),of={class:"space-y-4"},lf={key:0,class:"mt-1 text-sm text-red-500"},sf={key:1,class:"mt-1 text-sm text-neutral-500 dark:text-neutral-400"},nf={class:"px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},rf=["value"],df=me({__name:"PromptBasicInfo",props:{name:{},toolDescription:{}},emits:["update:name","update:toolDescription"],setup(t,{emit:n}){const s=t,i=n,l=v(""),u=c=>{let f=c.replace(/[^a-zA-Z0-9\s_]/g,"");return f=f.trim().toLowerCase().replace(/\s+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),f?/^[a-z][a-z0-9_]*$/.test(f)?l.value="":l.value="Name must start with a letter and contain only lowercase letters, numbers, and underscores":l.value="Name is required",f},r=c=>{const f=u(c);i("update:name",f)};return fe(()=>s.name,c=>{c&&u(c)},{immediate:!0}),(c,f)=>(a(),o("div",of,[e("div",null,[A(Le,{"model-value":t.name,"onUpdate:modelValue":r,label:"Prompt Name",placeholder:"Enter a unique name (will be converted to snake_case)"},null,8,["model-value"]),l.value?(a(),o("p",lf,S(l.value),1)):t.name?(a(),o("p",sf,[f[1]||(f[1]=Ce(" Will be saved as: ",-1)),e("code",nf,S(t.name),1)])):V("",!0)]),e("div",null,[f[2]||(f[2]=e("label",{class:"block text-sm font-medium mb-2"},"Tool Description",-1)),e("textarea",{value:t.toolDescription,onInput:f[0]||(f[0]=g=>i("update:toolDescription",g.target.value)),placeholder:"Describe what this prompt does (shown when used as a tool)",class:"w-full px-3 py-2 border border-black dark:border-white rounded bg-transparent resize-none",rows:"3"},null,40,rf)])]))}}),uf={class:"space-y-4"},cf=me({__name:"PromptModelSelect",props:{modelValue:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=n,i=v([]),l=v(!1),u=J(()=>i.value.map(c=>({value:c.id,label:c.name,description:c.model||c.provider,icon:c.provider?`/api/providers/${c.provider}/icon?model=${encodeURIComponent(c.model||"")}`:void 0}))),r=async()=>{l.value=!0;try{const c=await fetch(ue("/api/models"));if(c.ok){const f=await c.json();i.value=f.models||[]}}catch(c){console.error("Error fetching models:",c)}finally{l.value=!1}};return Me(()=>{r()}),(c,f)=>(a(),o("div",uf,[A(Ve,{"model-value":t.modelValue,"onUpdate:modelValue":f[0]||(f[0]=g=>s("update:modelValue",g)),options:u.value,label:"Model",placeholder:"Select a model for this prompt","search-placeholder":"Search models...",loading:l.value},null,8,["model-value","options","loading"])]))}}),pf=["data-property-id","data-nested-property-id"],mf={class:"p-3 space-y-3"},vf={class:"flex items-start gap-2"},ff={key:0,class:"drag-handle cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400 mt-2"},hf={class:"flex-1 grid grid-cols-1 md:grid-cols-3 gap-2"},gf={class:"flex items-center gap-2 mt-2"},bf=["disabled"],xf={key:0,class:"ml-6"},yf={key:0,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg space-y-2"},kf={class:"flex items-center justify-between mb-2"},wf=["disabled"],_f={key:0,class:"space-y-1"},$f=["onClick","disabled"],Cf={key:1,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},Tf={class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"},Sf={class:"space-y-2"},Vf={class:"flex items-center justify-between"},Mf=["disabled"],If={class:"space-y-2"},Ef={key:2,class:"p-3 bg-neutral-50 dark:bg-neutral-900 rounded-lg"},Lf={key:0,class:"mb-2"},Af=["disabled"],Pf={key:1,class:"space-y-2"},Df=me({__name:"PropertyEditor",props:We({propertyId:{},isNested:{type:Boolean,default:!1},parentId:{},disabled:{type:Boolean,default:!1},enableDrag:{type:Boolean,default:!0}},{modelValue:{required:!0},modelModifiers:{}}),emits:We(["remove","description-keydown","add-top-level"],["update:modelValue"]),setup(t,{emit:n}){const s=t,i=n,l=st(t,"modelValue"),u=v(!1);v();const r=[{value:"string",label:"String",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z'/%3E%3C/svg%3E"},{value:"number",label:"Number",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M7 20l4-16m2 16l4-16M6 9h14M4 15h14'/%3E%3C/svg%3E"},{value:"boolean",label:"Boolean",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z'/%3E%3C/svg%3E"},{value:"object",label:"Object",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10'/%3E%3C/svg%3E"},{value:"array",label:"Array",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 6h16M4 10h16M4 14h16M4 18h16'/%3E%3C/svg%3E"},{value:"enum",label:"Enum",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 110-4m0 4v2m0-6V4'/%3E%3C/svg%3E"},{value:"anyOf",label:"Any Of (Multiple Types)",icon:"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' class='w-4 h-4' fill='none' stroke='currentColor' viewBox='0 0 24 24'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z'/%3E%3C/svg%3E"}],c=J(()=>["object","array","enum","anyOf"].includes(l.value.type));fe(()=>l.value.type,async(b,m)=>{if(["object","array","enum","anyOf"].includes(b)&&(u.value=!0,b==="anyOf"&&!l.value.anyOf&&(l.value.anyOf=[]),b==="object"&&!l.value.properties&&(l.value.properties=[{id:crypto.randomUUID(),name:"property1",type:"string",description:""}]),b==="array"&&!l.value.items&&(l.value.items={id:crypto.randomUUID(),name:"",type:"string",description:""}),b==="enum"&&!l.value.enum&&(l.value.enum=["value1"])),m!==void 0){await Te();const y=s.isNested?`[data-nested-property-id="${s.propertyId}"] input[placeholder="Description"]`:`[data-property-id="${s.propertyId}"] input[placeholder="Description"]`,x=document.querySelector(y);x&&x.focus()}});const f=b=>{b.shiftKey&&l.value.type==="object"&&l.value.properties?h():i("add-top-level")},g=()=>{l.value.items||(l.value.items={id:crypto.randomUUID(),name:"",type:"string",description:""})},d=()=>{l.value.enum||(l.value.enum=[]),l.value.enum.push(`value${l.value.enum.length+1}`)},p=b=>{l.value.enum&&l.value.enum.splice(b,1)},h=async()=>{const b={id:crypto.randomUUID(),name:l.value.type==="anyOf"?"":`property${(l.value.properties?.length||l.value.anyOf?.length||0)+1}`,type:"string",description:""};l.value.type==="anyOf"?(l.value.anyOf||(l.value.anyOf=[]),l.value.anyOf.push(b)):(l.value.properties||(l.value.properties=[]),l.value.properties.push(b)),await Te();const m=document.querySelector(`[data-nested-property-id="${b.id}"] input[placeholder="Property name"]`);m&&(m.focus(),m.select())},_=b=>{l.value.type==="anyOf"&&l.value.anyOf?l.value.anyOf=l.value.anyOf.filter(m=>m.id!==b):l.value.properties&&(l.value.properties=l.value.properties.filter(m=>m.id!==b))};return(b,m)=>{const y=to("PropertyEditor",!0);return a(),o("div",{"data-property-id":t.isNested?void 0:t.propertyId,"data-nested-property-id":t.isNested?t.propertyId:void 0,class:ae(["border rounded-lg",t.isNested?"border-neutral-100 dark:border-neutral-900":"border-neutral-200 dark:border-neutral-800"])},[e("div",mf,[e("div",vf,[t.enableDrag?(a(),o("div",ff,[...m[10]||(m[10]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})],-1)])])):V("",!0),e("div",hf,[A(Le,{modelValue:l.value.name,"onUpdate:modelValue":m[0]||(m[0]=x=>l.value.name=x),placeholder:"Property name",disabled:t.disabled},null,8,["modelValue","disabled"]),A(Ve,{modelValue:l.value.type,"onUpdate:modelValue":m[1]||(m[1]=x=>l.value.type=x),options:r,disabled:t.disabled},null,8,["modelValue","disabled"]),A(Le,{modelValue:l.value.description,"onUpdate:modelValue":m[2]||(m[2]=x=>l.value.description=x),placeholder:"Description",disabled:t.disabled,onKeydown:m[3]||(m[3]=wt(Ee(x=>f(x),["prevent"]),["enter"]))},null,8,["modelValue","disabled"])]),e("div",gf,[c.value?(a(),o("button",{key:0,onClick:m[4]||(m[4]=x=>u.value=!u.value),type:"button",class:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-800 rounded transition-colors"},[(a(),o("svg",{class:ae(["w-4 h-4 transition-transform",u.value?"rotate-90":""]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[...m[11]||(m[11]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 5l7 7-7 7"},null,-1)])],2))])):V("",!0),e("button",{onClick:m[5]||(m[5]=x=>b.$emit("remove")),type:"button",disabled:t.disabled,class:"p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors disabled:opacity-50"},[...m[12]||(m[12]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,bf)])]),u.value&&c.value?(a(),o("div",xf,[l.value.type==="enum"?(a(),o("div",yf,[e("div",kf,[m[13]||(m[13]=e("h4",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400"}," Enum Values ",-1)),e("button",{onClick:d,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Add Value ",8,wf)]),l.value.enum?(a(),o("div",_f,[(a(!0),o(ve,null,ke(l.value.enum,(x,k)=>(a(),o("div",{key:k,class:"flex items-center gap-2"},[A(Le,{modelValue:l.value.enum[k],"onUpdate:modelValue":D=>l.value.enum[k]=D,placeholder:"Enum value",disabled:t.disabled,class:"flex-1"},null,8,["modelValue","onUpdate:modelValue","disabled"]),e("button",{onClick:D=>p(k),type:"button",disabled:t.disabled,class:"p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded transition-colors disabled:opacity-50"},[...m[14]||(m[14]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,$f)]))),128))])):V("",!0)])):V("",!0),l.value.type==="object"||l.value.type==="anyOf"?(a(),o("div",Cf,[e("h4",Tf,S(l.value.type==="anyOf"?"Type Options":"Nested Properties"),1),e("div",Sf,[e("div",Vf,[e("button",{onClick:h,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Add "+S(l.value.type==="anyOf"?"Type Option":"Property"),9,Mf)]),e("div",If,[(a(!0),o(ve,null,ke(l.value.type==="anyOf"?l.value.anyOf:l.value.properties,(x,k)=>(a(),ne(y,{key:x.id,modelValue:(l.value.type==="anyOf"?l.value.anyOf:l.value.properties)[k],"onUpdate:modelValue":D=>(l.value.type==="anyOf"?l.value.anyOf:l.value.properties)[k]=D,"property-id":x.id,"is-nested":!0,"parent-id":t.propertyId,disabled:t.disabled,"enable-drag":!1,onRemove:D=>_(x.id),onAddTopLevel:m[6]||(m[6]=D=>i("add-top-level"))},null,8,["modelValue","onUpdate:modelValue","property-id","parent-id","disabled","onRemove"]))),128))])])])):V("",!0),l.value.type==="array"?(a(),o("div",Ef,[m[15]||(m[15]=e("h4",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Array Item Type ",-1)),l.value.items?V("",!0):(a(),o("div",Lf,[e("button",{onClick:g,type:"button",disabled:t.disabled,class:"px-2 py-0.5 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50"}," Define Item Type ",8,Af)])),l.value.items?(a(),o("div",Pf,[A(y,{modelValue:l.value.items,"onUpdate:modelValue":m[7]||(m[7]=x=>l.value.items=x),"property-id":l.value.items.id,"is-nested":!0,"parent-id":t.propertyId,disabled:t.disabled,"enable-drag":!1,onRemove:m[8]||(m[8]=x=>l.value.items=null),onAddTopLevel:m[9]||(m[9]=x=>i("add-top-level"))},null,8,["modelValue","property-id","parent-id","disabled"])])):V("",!0)])):V("",!0)])):V("",!0)])],10,pf)}}}),jf={class:"space-y-2"},Of=["disabled"],Uf=me({__name:"PropertyList",props:We({disabled:{type:Boolean,default:!1},parentId:{},isNested:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["add-property","description-keydown"],["update:modelValue"]),setup(t,{expose:n,emit:s}){const i=t,l=s,u=st(t,"modelValue"),r=v();let c=!1;Me(async()=>{}),Be(()=>{});const f=async()=>{if(c)return;c=!0;const d={id:crypto.randomUUID(),name:`property${u.value.length+1}`,type:"string",description:"",required:!1};u.value=[...u.value,d],await Te();const p=i.parentId?`[data-nested-property-id="${d.id}"]`:`[data-property-id="${d.id}"]`,h=document.querySelector(`${p} input[placeholder="Property name"]`);h&&(h.focus(),h.select()),l("add-property"),c=!1},g=d=>{u.value=u.value.filter(p=>p.id!==d)};return n({addProperty:f}),(d,p)=>(a(),o("div",jf,[e("div",{ref_key:"dragAreaRef",ref:r,class:"space-y-2"},[(a(!0),o(ve,null,ke(u.value,h=>(a(),ne(Df,{key:h.id,modelValue:u.value[u.value.indexOf(h)],"onUpdate:modelValue":_=>u.value[u.value.indexOf(h)]=_,"property-id":h.id,"is-nested":t.isNested,"parent-id":t.parentId,disabled:t.disabled,"enable-drag":!t.isNested,onRemove:_=>g(h.id),onAddTopLevel:p[0]||(p[0]=_=>d.$emit("add-property"))},null,8,["modelValue","onUpdate:modelValue","property-id","is-nested","parent-id","disabled","enable-drag","onRemove"]))),128))],512),e("div",{class:ae(t.isNested?"mt-2":"mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-800")},[e("button",{onClick:f,type:"button",disabled:t.disabled,class:ae(t.isNested?"px-2 py-1 text-xs bg-neutral-800 dark:bg-neutral-200 text-white dark:text-black rounded hover:bg-neutral-700 dark:hover:bg-neutral-300 transition-colors disabled:opacity-50":"w-full px-3 py-2 text-sm bg-neutral-50 dark:bg-neutral-900 hover:bg-neutral-100 dark:hover:bg-neutral-800 text-neutral-700 dark:text-neutral-300 rounded transition-colors disabled:opacity-50 border border-dashed border-neutral-300 dark:border-neutral-700")},[...p[1]||(p[1]=[e("span",{class:"flex items-center justify-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),Ce(" Add Property ")],-1)])],10,Of)],2)]))}}),Rf={class:"space-y-4"},Nf={key:0,class:"flex items-center justify-between"},Ff={class:"text-sm font-medium"},Bf={key:0,class:"text-red-500"},qf={class:"space-y-2 border border-neutral-200 dark:border-neutral-800 rounded-lg p-4"},zf={key:0,class:"flex items-center justify-between mb-2"},Hf={key:1,class:"text-center py-12"},Wf=["disabled"],Jf={class:"mt-4 text-center"},Kf={key:3,class:"mt-4"},Gf={class:"bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 rounded-lg p-4 overflow-x-auto"},Xf={class:"text-xs leading-relaxed"},Yf=["innerHTML"],_a=me({__name:"JSONSchemaInput",props:We({label:{},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>({type:"object",properties:{},required:[]})},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const n=st(t,"modelValue"),s=v([]),i=v(),l=v(!1),u=()=>{if(n.value?.properties){const b=[];n.value.required;for(const[m,y]of Object.entries(n.value.properties)){const x=y,k={id:crypto.randomUUID(),name:m,type:x.type||"string",description:x.description||""};x.enum&&(k.enum=x.enum),x.anyOf&&(k.type="anyOf",k.anyOf=r(x.anyOf)),x.type==="array"&&x.items&&(k.items=c(x.items)),x.type==="object"&&x.properties&&(k.properties=f(x.properties,x.required||[])),b.push(k)}s.value=b}},r=b=>b.map(m=>typeof m=="object"&&m.type?{id:crypto.randomUUID(),name:"",type:m.type,description:m.description||"",properties:m.properties?f(m.properties,m.required||[]):void 0,items:m.items?c(m.items):void 0,enum:m.enum}:{id:crypto.randomUUID(),name:"",type:"string",description:""}),c=b=>{const m={id:crypto.randomUUID(),name:"",type:b.type||"string",description:b.description||""};return b.enum&&(m.enum=b.enum),b.anyOf&&(m.type="anyOf",m.anyOf=r(b.anyOf)),b.type==="array"&&b.items&&(m.items=c(b.items)),b.type==="object"&&b.properties&&(m.properties=f(b.properties,b.required||[])),m},f=(b,m)=>{const y=[];for(const[x,k]of Object.entries(b)){const D=k,q={id:crypto.randomUUID(),name:x,type:D.type||"string",description:D.description||""};D.enum&&(q.enum=D.enum),D.anyOf&&(q.type="anyOf",q.anyOf=r(D.anyOf)),D.type==="array"&&D.items&&(q.items=c(D.items)),D.type==="object"&&D.properties&&(q.properties=f(D.properties,D.required||[])),y.push(q)}return y};u();const g=()=>{const b={type:"object",properties:{},required:[],additionalProperties:!1},{properties:m}=p(s.value);b.properties=m,b.required=Object.keys(m),n.value=b},d=b=>{const m={type:b.type==="anyOf"?void 0:b.type,description:b.description};if(b.type==="enum"&&b.enum&&(m.enum=b.enum,m.type="string"),b.type==="anyOf"&&b.anyOf&&(delete m.type,m.anyOf=b.anyOf.map(d)),b.type==="object"&&b.properties){const{properties:y}=p(b.properties);m.properties=y,m.required=Object.keys(y),m.additionalProperties=!1}return b.type==="array"&&b.items&&(m.items=d(b.items)),m},p=b=>{const m={},y=[];for(const x of b){const k={type:x.type==="anyOf"?void 0:x.type,description:x.description};if(y.push(x.name),x.type==="enum"&&x.enum&&(k.enum=x.enum,k.type="string"),x.type==="anyOf"&&x.anyOf&&x.anyOf.length>0&&(delete k.type,k.anyOf=x.anyOf.map(d)),x.type==="array"&&x.items&&(k.items=d(x.items)),x.type==="object"&&x.properties){const{properties:D}=p(x.properties);k.properties=D,k.required=Object.keys(D),k.additionalProperties=!1}m[x.name]=k}return{properties:m,required:y}};fe(s,()=>{g()},{deep:!0}),g();const h=J(()=>JSON.stringify(n.value,null,2).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"([^"]+)":/g,'<span class="text-blue-600 dark:text-blue-400">"$1"</span>:').replace(/:"([^"]*)"/g,':<span class="text-green-600 dark:text-green-400">"$1"</span>').replace(/:(\d+)/g,':<span class="text-yellow-600 dark:text-yellow-400">$1</span>').replace(/:(true|false)/g,':<span class="text-purple-600 dark:text-purple-400">$1</span>').replace(/:(null)/g,':<span class="text-red-600 dark:text-red-400">$1</span>')),_=async()=>{if(s.value.length===0){const b={id:crypto.randomUUID(),name:"property1",type:"string",description:""};s.value.push(b),await Te();const m=document.querySelector(`[data-property-id="${b.id}"] input[placeholder="Property name"]`);m&&(m.focus(),m.select())}else i.value&&i.value.addProperty()};return(b,m)=>(a(),o("div",Rf,[t.label?(a(),o("div",Nf,[e("label",Ff,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",Bf,"*")):V("",!0)])])):V("",!0),e("div",qf,[s.value.length>0?(a(),o("div",zf,[...m[2]||(m[2]=[e("h3",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300"}," Properties ",-1)])])):V("",!0),s.value.length===0?(a(),o("div",Hf,[m[4]||(m[4]=e("div",{class:"mb-4"},[e("svg",{class:"w-12 h-12 mx-auto text-neutral-400 dark:text-neutral-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})])],-1)),m[5]||(m[5]=e("p",{class:"text-neutral-500 dark:text-neutral-400 text-sm mb-4"}," No properties defined ",-1)),e("button",{onClick:_,type:"button",disabled:t.disabled,class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black rounded hover:bg-neutral-800 dark:hover:bg-neutral-200 transition-colors disabled:opacity-50 font-medium text-sm"},[...m[3]||(m[3]=[e("span",{class:"flex items-center gap-2"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})]),Ce(" Add Property ")],-1)])],8,Wf)])):V("",!0),s.value.length>0?(a(),ne(Uf,{key:2,ref_key:"propertyListRef",ref:i,modelValue:s.value,"onUpdate:modelValue":m[0]||(m[0]=y=>s.value=y),disabled:t.disabled,onAddProperty:_},null,8,["modelValue","disabled"])):V("",!0),e("div",Jf,[e("button",{onClick:m[1]||(m[1]=y=>l.value=!l.value),type:"button",class:"text-xs text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-100 hover:underline transition-colors"},S(l.value?"Hide":"Show")+" JSON Schema ",1)]),l.value?(a(),o("div",Kf,[e("div",Gf,[e("pre",Xf,[e("code",{class:"font-mono",innerHTML:h.value},null,8,Yf)])])])):V("",!0)])]))}}),Qf={class:"prompt-input-container relative"},Zf=["contenteditable","data-placeholder"],eh={class:"bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden min-w-[240px] max-w-[320px]"},th={key:0,class:"p-3 text-sm text-neutral-500"},ah={key:1,class:"p-3 text-sm text-neutral-500"},oh={key:2,class:"max-h-[220px] overflow-y-auto"},lh=["onClick"],sh={class:"font-medium flex items-center gap-2"},nh=["title"],rh={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},ih={key:1,class:"text-xs text-red-600 dark:text-red-400 mt-1"},dh={class:"text-xs mt-1"},uh=me({__name:"PromptInput",props:{modelValue:{},search:{},placeholder:{default:"Type @ to insert variables or prompts..."},disabled:{type:Boolean,default:!1},maxLength:{},allowedTypes:{default:()=>["variable","prompt"]}},emits:["update:modelValue","segment-click"],setup(t,{emit:n}){const s=t,i=n,l=v(),u=v(),r=ao({segments:s.modelValue&&s.modelValue.length?s.modelValue:[{type:"string",value:""}],dialogOpen:!1,dialogPosition:{x:0,y:0},searchQuery:"",searchResults:[],selectedIndex:0,isSearching:!1,atTriggerIndex:-1,isComposing:!1,ignoreNextWatch:!1}),c=()=>Math.random().toString(36).slice(2)+Date.now().toString(36),f=P=>P.type==="string"?"":`@${P.type==="variable"?P.label||P.value:P.label||P.id}`,g=()=>{const P=window.getSelection();if(!P||!P.rangeCount||!l.value)return null;const C=P.getRangeAt(0);let L=0;const G=Array.from(l.value.childNodes);for(let ee=0;ee<G.length;ee++){const E=G[ee];if(E===C.startContainer||E.contains?.(C.startContainer)){if(E.nodeType===Node.TEXT_NODE)return{segmentIndex:L,offset:C.startOffset};if(E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag"))return{segmentIndex:L,offset:0}}(E.nodeType===Node.TEXT_NODE||E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag"))&&L++}return{segmentIndex:0,offset:0}},d=()=>{if(!l.value)return;const P=r.segments.map(C=>{if(C.type==="string")return(C.value||"").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")||"";{const L=C._uid||(C._uid=c()),G=f(C),ee=C.type==="variable"?{type:"variable",value:C.value,label:C.label,schema:C.schema,meta:C.meta}:{type:"prompt",id:C.id,label:C.label,schema:C.schema,meta:C.meta},E=encodeURIComponent(JSON.stringify(ee)),U=C.type==="prompt"&&C.meta&&!C.meta.isValid,Z=U?'<span class="prompt-tag-warning" title="'+(C.meta.validationMessage||"").replace(/"/g,"&quot;")+'">⚠️</span>':"";return`<span class="prompt-tag prompt-tag-clickable${U?" prompt-tag-invalid":""}" contenteditable="false" data-segment-uid="${L}" data-segment="${E}">${G}${Z}</span>`}}).join("");l.value.innerHTML=P||"<br>"},p=()=>{const P=[];for(const C of r.segments)C.type==="string"&&P.length>0&&P[P.length-1].type==="string"?P[P.length-1].value+=C.value:P.push(C);r.segments=P.length?P:[{type:"string",value:""}]},h=P=>{const C=P.dataset.segmentUid;let L=r.segments.find(G=>G._uid===C);if(!L){const G=P.dataset.segment;if(G)try{const ee=JSON.parse(decodeURIComponent(G));ee&&(ee.type==="variable"||ee.type==="prompt")&&(L=ee.type==="variable"?{type:"variable",value:ee.value,label:ee.label,schema:ee.schema,meta:ee.meta,_uid:C}:{type:"prompt",id:ee.id,label:ee.label,schema:ee.schema,meta:ee.meta,_uid:C})}catch{}}return L||null},_=P=>{const C=P.target;if(C.classList?.contains("prompt-tag")){const L=h(C);L&&i("segment-click",L,P)}},b=P=>{if(r.isComposing)return;const C=P.target,L=[];let G="";const ee=()=>{G.length>0&&(L.push({type:"string",value:G}),G="")},E=j=>{if(j.nodeType===Node.TEXT_NODE){const M=(j.textContent||"").replace(/\u00A0/g," ");G+=M;return}if(j.nodeType===Node.ELEMENT_NODE){const M=j;if(M.classList?.contains("prompt-tag")){ee();const R=h(M);R&&L.push(R);return}if(M.tagName==="BR"){G+=`
18
+ `;return}const w=Array.from(M.childNodes);for(const R of w)E(R);(M.tagName==="DIV"||M.tagName==="P"||M.tagName==="LI")&&M.nextSibling&&(G+=`
19
+ `);return}},U=Array.from(C.childNodes);for(const j of U)E(j);ee();const se=L.some(j=>j.type!=="string")?L:[{type:"string",value:(C.innerText||"").replace(/\r\n/g,`
20
+ `)}];r.segments=se.length?se:[{type:"string",value:""}],p(),m(),oe()},m=()=>{const P=window.getSelection();if(!P||!P.rangeCount||!l.value)return;const C=P.getRangeAt(0);if(C.startContainer.nodeType!==Node.TEXT_NODE){r.dialogOpen&&x();return}const G=C.startContainer.textContent||"",ee=C.startOffset;if(ee>0&&G[ee-1]==="@")r.atTriggerIndex=ee-1,r.searchQuery="",y(),q("");else if(r.dialogOpen&&r.atTriggerIndex>=0)if(C.startContainer.nodeType===Node.TEXT_NODE){const E=C.startContainer.textContent||"",U=C.startOffset;if(U<=r.atTriggerIndex){x();return}const Z=E.substring(0,U);if(Z.length>r.atTriggerIndex&&Z[r.atTriggerIndex]==="@"){const se=Z.substring(r.atTriggerIndex+1);se.includes(" ")||se.includes(`
21
+ `)||se.length>r.searchQuery.length+5?x():(r.searchQuery=se,q(se))}else x()}else x()},y=async()=>{r.dialogOpen=!0,r.selectedIndex=0,await Te(),k()},x=()=>{r.dialogOpen=!1,r.searchResults=[],r.searchQuery="",r.atTriggerIndex=-1,r.isSearching=!1},k=()=>{if(!u.value||!l.value)return;const P=window.getSelection();if(!P||!P.rangeCount)return;const L=P.getRangeAt(0).getBoundingClientRect(),G=l.value.getBoundingClientRect();r.dialogPosition={x:L.left-G.left,y:L.bottom-G.top+4}};let D=null;const q=async P=>{if(!s.search){r.searchResults=[];return}D&&clearTimeout(D),r.isSearching=!0,D=setTimeout(async()=>{try{const C=await s.search(P);r.searchResults=(C||[]).filter(L=>s.allowedTypes?.includes(L.type))}catch(C){console.error("Search error:",C),r.searchResults=[]}finally{r.isSearching=!1}},200)},B=P=>P.type==="variable"?{type:"variable",value:P.value??P.id??"",label:P.label,schema:P.schema,_uid:c(),meta:P.meta}:{type:"prompt",id:P.id??P.value??"",label:P.label,schema:P.schema,_uid:c(),meta:P.meta},F=P=>{if(r.atTriggerIndex<0||!l.value)return;const C=window.getSelection();if(!C||!C.rangeCount)return;const L=C.getRangeAt(0);if(L.startContainer.nodeType!==Node.TEXT_NODE)return;const G=L.startContainer,ee=G.data.slice(0,r.atTriggerIndex),E=G.data.slice(L.startOffset),U=document.createElement("span"),Z=B(P),se=Z.type==="prompt"&&Z.meta&&!Z.meta.isValid;U.className=`prompt-tag${se?" prompt-tag-invalid":""}`,U.setAttribute("contenteditable","false");const j=Z._uid||(Z._uid=c());U.dataset.segmentUid=j;const M=Z.type==="variable"?{type:"variable",value:Z.value,label:Z.label,schema:Z.schema}:{type:"prompt",id:Z.id,label:Z.label,schema:Z.schema};if(U.dataset.segment=encodeURIComponent(JSON.stringify(M)),U.textContent=f(Z),se){const O=document.createElement("span");O.className="prompt-tag-warning",O.textContent="⚠️",O.setAttribute("title",Z.meta.validationMessage||"Validation error"),U.appendChild(O)}const w=G.parentNode,R=document.createTextNode(E),I=document.createTextNode(ee);w.insertBefore(I,G),w.insertBefore(U,G),w.insertBefore(R,G),w.removeChild(G),x(),b({target:l.value});const le=window.getSelection();if(le){const O=document.createRange();O.setStart(R,0),O.collapse(!0),le.removeAllRanges(),le.addRange(O)}l.value.focus()},T=P=>{if((P.key==="ArrowLeft"||P.key==="ArrowRight")&&setTimeout(()=>m(),0),r.dialogOpen)P.key==="ArrowDown"?(P.preventDefault(),r.selectedIndex=Math.min(r.selectedIndex+1,r.searchResults.length-1)):P.key==="ArrowUp"?(P.preventDefault(),r.selectedIndex=Math.max(r.selectedIndex-1,0)):P.key==="Enter"?(P.preventDefault(),r.searchResults[r.selectedIndex]&&F(r.searchResults[r.selectedIndex])):(P.key==="Escape"||P.key==="Esc")&&(P.preventDefault(),x());else if(P.key==="Backspace"||P.key==="Delete"){const C=g();if(P.key==="Backspace"){const L=window.getSelection();if(L&&L.rangeCount){const G=L.getRangeAt(0);if(G.collapsed&&G.startContainer.nodeType===Node.TEXT_NODE&&G.startOffset===0){let ee=G.startContainer;for(;ee&&ee!==l.value;){const E=ee.previousSibling;if(E&&E.nodeType===Node.ELEMENT_NODE&&E.classList?.contains("prompt-tag")){P.preventDefault(),E.parentNode?.removeChild(E),b({target:l.value});return}ee=ee.parentNode}}}}if(!C)return;if(P.key==="Backspace"&&C.offset===0&&C.segmentIndex>0)r.segments[C.segmentIndex-1].type!=="string"&&(P.preventDefault(),r.segments.splice(C.segmentIndex-1,1),p(),oe(),d());else if(P.key==="Delete"&&C.segmentIndex<r.segments.length-1){const L=r.segments[C.segmentIndex];L.type==="string"&&(L.value?.length??0)===C.offset&&r.segments[C.segmentIndex+1].type!=="string"&&(P.preventDefault(),r.segments.splice(C.segmentIndex+1,1),p(),oe(),d())}}},$=P=>{P.preventDefault();const C=P.clipboardData?.getData("text/plain")||"";document.execCommand("insertText",!1,C)},K=P=>{if(!r.dialogOpen)return;const C=u.value;C&&(C.contains(P.target)||x())},oe=()=>{r.ignoreNextWatch=!0;const P=r.segments.map(C=>{const{_uid:L,...G}=C||{};return G});i("update:modelValue",P)},te=()=>{const P=window.getSelection();if(!P||!l.value)return;const C=P.anchorNode;C&&l.value.contains(C)&&m()},H=P=>{(P.key==="Escape"||P.key==="Esc")&&r.dialogOpen&&(P.preventDefault(),x())};return Me(()=>{s.modelValue&&s.modelValue.length&&(r.segments=JSON.parse(JSON.stringify(s.modelValue))),d(),document.addEventListener("mousedown",K),document.addEventListener("selectionchange",te),document.addEventListener("keydown",H,!0)}),Be(()=>{document.removeEventListener("mousedown",K),document.removeEventListener("selectionchange",te),document.removeEventListener("keydown",H,!0)}),fe(()=>s.modelValue,P=>{if(r.ignoreNextWatch){r.ignoreNextWatch=!1;return}P&&(r.segments=JSON.parse(JSON.stringify(P)),d())},{deep:!0}),(P,C)=>(a(),o("div",Qf,[e("div",{ref_key:"editorRef",ref:l,contenteditable:!t.disabled,onInput:b,onKeydown:T,onPaste:$,onClick:_,onKeyup:C[0]||(C[0]=L=>{L.key==="Escape"?(L.preventDefault(),x()):(L.key==="ArrowLeft"||L.key==="ArrowRight")&&m()}),onCompositionstart:C[1]||(C[1]=L=>r.isComposing=!0),onCompositionend:C[2]||(C[2]=L=>r.isComposing=!1),class:ae(["prompt-input-editor","min-h-[100px] p-3 border-2 rounded-lg","border-black dark:border-neutral-300","bg-white dark:bg-black","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white",t.disabled?"opacity-50 cursor-not-allowed":""]),"data-placeholder":t.placeholder},[Ie(e("div",null,[et(P.$slots,"segment",{segment:null},void 0,!0)],512),[[Ke,!1]])],42,Zf),r.dialogOpen?(a(),o("div",{key:0,ref_key:"dialogRef",ref:u,class:"absolute z-50",style:ot({left:`${r.dialogPosition.x}px`,top:`${r.dialogPosition.y}px`})},[A(Qe,{"offset-x":2,"offset-y":2,intensity:.3},{default:be(()=>[e("div",eh,[r.isSearching?(a(),o("div",th," Searching... ")):r.searchResults.length===0?(a(),o("div",ah," No results found ")):(a(),o("div",oh,[(a(!0),o(ve,null,ke(r.searchResults,(L,G)=>(a(),o("button",{key:L.id||L.value||G,type:"button",onClick:ee=>F(L),class:ae(["w-full px-3 py-2 text-left text-sm","hover:bg-neutral-100 dark:hover:bg-neutral-900","focus:bg-neutral-100 dark:focus:bg-neutral-900 focus:outline-none",r.selectedIndex===G?"bg-neutral-100 dark:bg-neutral-900":""])},[e("div",sh,[Ce(S(L.label||L.id||L.value)+" ",1),L.type==="prompt"&&L.meta&&!L.meta.isValid?(a(),o("span",{key:0,title:L.meta.validationMessage,class:"text-red-500"},"⚠️",8,nh)):V("",!0)]),L.description?(a(),o("div",rh,S(L.description),1)):V("",!0),L.type==="prompt"&&L.meta&&!L.meta.isValid?(a(),o("div",ih,S(L.meta.validationMessage),1)):V("",!0),e("div",dh,[e("span",{class:ae(["inline-block px-1.5 py-0.5 rounded",L.type==="variable"?"bg-blue-100 dark:bg-blue-900 text-blue-700 dark:text-blue-300":"bg-purple-100 dark:bg-purple-900 text-purple-700 dark:text-purple-300"])},S(L.type),3)])],10,lh))),128))]))])]),_:1})],4)):V("",!0)]))}}),$a=tt(uh,[["__scopeId","data-v-7ee6148f"]]);function Ht(t,n){if(!n||!n.properties||Object.keys(n.properties).length===0)return!0;if(!t||!t.properties)return Object.keys(n.properties);const s=[],i=t.properties||{},l=n.properties||{};return(n.required||[]).forEach(r=>{r in i||s.push(r)}),Object.keys(l).forEach(r=>{!(r in i)&&!s.includes(r)&&s.push(r)}),s.length>0?s:!0}function Wt(t){return t.length===0?"":t.length===1?`Missing required field: ${t[0]}`:`Missing required fields: ${t.join(", ")}`}const ch={class:"space-y-4"},ph=me({__name:"PromptTemplate",props:{promptText:{},beforeTool:{},afterTool:{},requiredSchema:{},currentPromptName:{}},emits:["update:promptText","update:beforeTool","update:afterTool"],setup(t,{emit:n}){const s=t,i=n,l=v([]),u=v(!1),r=h=>h.type==="text"?{type:"string",value:h.content||""}:h.type==="include"?{type:"prompt",id:h.prompt||"",label:h.prompt||""}:h.type==="string"?{type:"string",value:h.value||""}:h.type==="prompt"?{type:"prompt",id:h.id||"",label:h.label||h.id||""}:h.type==="variable"?{type:"variable",value:h.value||"",label:h.label||h.value||""}:{type:"string",value:""},c=J(()=>{if(!s.promptText)return[{type:"string",value:""}];let h=[];try{const b=JSON.parse(s.promptText);Array.isArray(b)?h=b.map(r):h=[{type:"string",value:s.promptText}]}catch{h=[{type:"string",value:s.promptText}]}const _=s.requiredSchema?JSON.parse(s.requiredSchema):{};return h.map(b=>{if(b.type==="prompt"&&b.schema){const m=Ht(_,b.schema),y=m===!0,x=y?[]:m;return{...b,meta:{isValid:y,missingFields:x,validationMessage:y?"":Wt(x)}}}return b})}),f=J(()=>{try{const h=JSON.parse(s.requiredSchema);if(h.properties&&typeof h.properties=="object")return Object.keys(h.properties)}catch{return[]}return[]}),g=async h=>{u.value=!0;try{const _=new URLSearchParams;h&&_.set("search",h);const b=await fetch(ue(`/api/prompts${_.toString()?"?"+_.toString():""}`));if(b.ok){const m=await b.json();l.value=m.prompts||[]}}catch(_){console.error("Error fetching prompts:",_)}finally{u.value=!1}},d=async h=>{const _=[];return f.value.forEach(b=>{(!h||b.toLowerCase().includes(h.toLowerCase()))&&_.push({type:"variable",value:b,label:b,description:"Schema property"})}),h!==void 0&&await g(h),l.value.forEach(b=>{if(!(s.currentPromptName&&b.name===s.currentPromptName)&&(!h||b.name.toLowerCase().includes(h.toLowerCase()))){const m=s.requiredSchema?JSON.parse(s.requiredSchema):{},y=Ht(m,b.required_schema),x=y===!0,k=x?[]:y;_.push({type:"prompt",id:b.name,label:b.name,description:b.tool_description||"Available prompt",schema:b.required_schema,meta:{isValid:x,missingFields:k,validationMessage:x?"":Wt(k)}})}}),_},p=h=>{const _=h.map(b=>{const{type:m,value:y,label:x,id:k,schema:D}=b;return m==="string"?{type:m,value:y||""}:m==="variable"?{type:m,value:y||"",label:x}:m==="prompt"?{type:m,id:k||"",label:x,schema:D}:b});i("update:promptText",JSON.stringify(_))};return Me(()=>{g()}),(h,_)=>(a(),o("div",ch,[e("div",null,[_[0]||(_[0]=e("label",{class:"block text-sm font-medium mb-2"},"Prompt Template",-1)),_[1]||(_[1]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400 mb-2"}," Type @ to insert schema properties or other prompts ",-1)),A($a,{"model-value":c.value,"onUpdate:modelValue":p,search:d,placeholder:"Enter your prompt template... Type @ to insert variables or prompts"},null,8,["model-value"])])]))}}),mh={class:"space-y-3"},vh={class:"space-y-2 pl-4 border-l-2 border-accent-200 dark:border-accent-700"},fh={class:"space-y-1"},hh={class:"space-y-1 mt-3"},gh={class:"space-y-2 pl-4 border-l-2 border-neutral-200 dark:border-neutral-700"},bh=me({__name:"PromptToolOptions",props:{toolName:{},toolConfig:{},toolType:{default:"prompt"},disabled:{type:Boolean}},emits:["update:option"],setup(t,{emit:n}){const s=t,i=n,l=v(null),u=v(!0),r=J(()=>l.value?.properties?Object.entries(l.value.properties).map(([g,d])=>({value:g,label:g,description:d.description||d.type||""})):[]),c=async()=>{try{let g=s.toolName;if(s.toolType==="handoff"||s.toolType==="subagent"){const p=await fetch(ue(`/api/agents/${encodeURIComponent(s.toolName)}`));if(p.ok){if(g=(await p.json())?.agent?.side_a_agent_prompt,!g){u.value=!1;return}}else{u.value=!1;return}}const d=await fetch(ue(`/api/prompts/${encodeURIComponent(g)}`));if(d.ok){const p=await d.json();p?.prompt?.required_schema&&(l.value=p.prompt.required_schema)}}catch(g){console.error("Error fetching prompt schema:",g)}finally{u.value=!1}};Me(()=>{c()});const f=(g,d)=>{i("update:option",g,d)};return(g,d)=>(a(),o("div",mh,[e("div",vh,[d[9]||(d[9]=e("p",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Initialization Options: ",-1)),e("div",fh,[d[5]||(d[5]=e("label",{class:"block text-xs font-medium text-neutral-700 dark:text-neutral-300"}," User message property ",-1)),A(Ve,{"model-value":t.toolConfig.init_user_message_property||"","onUpdate:modelValue":d[0]||(d[0]=p=>f("init_user_message_property",p||null)),placeholder:"Don't inject a user message",options:r.value,disabled:t.disabled||u.value||r.value.length===0,loading:u.value},null,8,["model-value","options","disabled","loading"]),d[6]||(d[6]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Select which argument property should be used as the most recent user message for this sub-prompt. If not set no additional user message will be injected. ",-1))]),e("div",hh,[d[7]||(d[7]=e("label",{class:"block text-xs font-medium text-neutral-700 dark:text-neutral-300"}," Attachments property ",-1)),A(Ve,{"model-value":t.toolConfig.init_attachments_property||"","onUpdate:modelValue":d[1]||(d[1]=p=>f("init_attachments_property",p||null)),placeholder:"Don't attach files",options:r.value,disabled:t.disabled||u.value||r.value.length===0,loading:u.value},null,8,["model-value","options","disabled","loading"]),d[8]||(d[8]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"},' Select which argument contains attachment path(s). Accepts a single path string or an array of paths (e.g., "/attachments/123.jpg" or ["/attachments/a.jpg", "/attachments/b.jpg"]). ',-1))])]),e("div",gh,[d[10]||(d[10]=e("p",{class:"text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-2"}," Sub-Prompt Response Options: ",-1)),A(Pe,{"model-value":t.toolConfig.include_text_response,"onUpdate:modelValue":d[2]||(d[2]=p=>f("include_text_response",p)),label:"Include text response","help-text":"Include the final text content from the sub-prompt",disabled:t.disabled},null,8,["model-value","disabled"]),A(Pe,{"model-value":t.toolConfig.include_tool_calls,"onUpdate:modelValue":d[3]||(d[3]=p=>f("include_tool_calls",p)),label:"Include tool calls and responses","help-text":"Include tool calls executed by the sub-prompt and their responses",disabled:t.disabled},null,8,["model-value","disabled"]),A(Pe,{"model-value":t.toolConfig.include_errors,"onUpdate:modelValue":d[4]||(d[4]=p=>f("include_errors",p)),label:"Include errors","help-text":"Include error information if the sub-prompt fails",disabled:t.disabled},null,8,["model-value","disabled"])])]))}}),xh={class:"space-y-4"},yh={class:"block text-sm font-medium mb-2"},kh={key:0,class:"text-red-500"},wh={class:"flex items-start justify-between"},_h={class:"flex items-center gap-2 flex-1"},$h={class:"flex-1"},Ch={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},Th={key:1,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},Sh={key:2,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},Vh={key:3,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},Mh={key:4,class:"text-xs text-neutral-500 dark:text-neutral-400 font-normal"},Ih={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-1"},Eh={key:1,class:"text-xs text-amber-600 dark:text-amber-400 mt-1 flex items-center gap-1"},Lh=["onClick","disabled","aria-label"],Ah={key:0,class:"mt-3 pt-3 border-t border-neutral-200 dark:border-neutral-700"},Ph={class:"space-y-2"},Dh={key:0,class:"text-xs text-amber-500 dark:text-amber-400 whitespace-nowrap",title:"Required at agent or thread level"},jh={key:1,class:"text-xs text-red-500 dark:text-red-400 mt-1"},Oh={key:0,class:"text-center py-8 text-sm text-neutral-500 dark:text-neutral-400 border border-dashed border-neutral-300 dark:border-neutral-600 rounded-lg"},Uh=me({__name:"ToolSelectorWithOptions",props:We({label:{default:"Available Tools"},placeholder:{default:"Select a tool"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},modelId:{},providerId:{}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["unavailable-tools"],["update:modelValue"]),setup(t,{expose:n,emit:s}){const i=t,l=st(t,"modelValue"),u=v([]),r=v([]),c=v(!1),f=v(!1),g=v(),d=J(()=>[...u.value,...r.value]),p=J(()=>new Set(d.value.map(H=>m(H)))),h=H=>(H.startsWith("provider:"),p.value.has(H)),_=J(()=>l.value.filter(H=>!h(H.name)).map(H=>H.name)),b=s;fe(_,H=>{H.length>0&&b("unavailable-tools",H)},{immediate:!0}),na(async()=>{g.value,await Te(),g.value&&l.value.length>0&&await ra({parent:g,values:l,dragHandle:".drag-handle"})});const m=H=>H.type==="provider"?`provider:${H.name}`:H.type==="mcp"?`mcp:${H.name}`:H.name,y=H=>H.startsWith("provider:")?H.slice(9):H.startsWith("mcp:")?H.slice(4):H,x=H=>H.startsWith("provider:")?"provider":H.startsWith("mcp:")?"mcp":"tool",k=J(()=>{const H=new Set(l.value.map(P=>P.name));return d.value.filter(P=>!H.has(m(P))).map(P=>{let C=P.name;return P.type==="prompt"?C=`${P.name} (prompt)`:P.type==="mcp"?C=`${P.name} (mcp)`:P.type==="provider"?C=`${P.name} (provider)`:P.type==="handoff"?C=`${P.name} (handoff agent)`:P.type==="subagent"&&(C=`${P.name} (subagent)`),{value:m(P),label:C,description:P.description}})}),D=async()=>{c.value=!0;try{const H=await ze("/tools");if(H.ok){const P=await H.json();u.value=Object.entries(P).map(([C,L])=>({name:C,description:L.description||"",type:L.type,model:L.model}))}}catch(H){console.error("Error fetching tools:",H)}finally{c.value=!1}},q=async()=>{if(!i.providerId||!i.modelId){r.value=[];return}f.value=!0;try{const H=await ze(`/providers/${i.providerId}/tools?model=${encodeURIComponent(i.modelId)}`);if(H.ok){const P=await H.json();r.value=(P.tools||[]).map(C=>({name:C.name,description:C.description||"",type:"provider",tenvs:C.tenvs||[]}))}else r.value=[]}catch(H){console.error("Error fetching provider tools:",H),r.value=[]}finally{f.value=!1}};fe([()=>i.providerId,()=>i.modelId],async([H,P])=>{H&&P?await q():r.value=[]},{immediate:!0});const B=H=>{if(!H||l.value.find(L=>L.name===H))return;const P=T(H),C={};if(P?.tenvs&&P.tenvs.length>0)for(const L of P.tenvs)C[L.name]="";l.value=[...l.value,{name:H,include_text_response:!0,include_tool_calls:!0,include_errors:!0,init_user_message_property:null,init_attachments_property:null,...Object.keys(C).length>0?{tenvs:C}:{}}]},F=H=>{l.value=l.value.filter(P=>P.name!==H)},T=H=>{const P=d.value.find(C=>m(C)===H);return P||d.value.find(C=>C.name===H)},$=(H,P,C)=>{l.value=l.value.map(L=>{if(L.name===H){const G={...L.tenvs||{},[P]:C||void 0};for(const ee of Object.keys(G))G[ee]||delete G[ee];return{...L,tenvs:Object.keys(G).length>0?G:void 0}}return L})},K=(H,P,C)=>{l.value=l.value.map(L=>L.name===H?{...L,[P]:C}:L)};return n({removeUnavailableTools:()=>{l.value=l.value.filter(H=>h(H.name))},getAvailableToolsOnly:()=>l.value.filter(H=>h(H.name)),unavailableTools:_}),Me(()=>{D()}),(H,P)=>(a(),o("div",xh,[e("div",null,[e("label",yh,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",kh,"*")):V("",!0)]),l.value.length>0?(a(),o("div",{key:0,class:"space-y-3 mb-4",ref_key:"dragAreaRef",ref:g},[(a(!0),o(ve,null,ke(l.value,C=>(a(),o("div",{key:C.name,class:ae(["border rounded-lg p-4 transition-colors",h(C.name)?"border-neutral-300 dark:border-neutral-600":"border-amber-300 dark:border-amber-700 bg-amber-50 dark:bg-amber-900/20 opacity-75"])},[e("div",wh,[e("div",_h,[e("div",{class:ae(["drag-handle",h(C.name)?"cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400":"cursor-not-allowed text-neutral-300 dark:text-neutral-700"])},[...P[0]||(P[0]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})],-1)])],2),e("div",$h,[e("h4",{class:ae(["font-medium text-sm",!h(C.name)&&"text-neutral-500 dark:text-neutral-400"])},[Ce(S(y(C.name))+" ",1),x(C.name)==="provider"?(a(),o("span",Ch,"(provider)")):x(C.name)==="mcp"?(a(),o("span",Th,"(mcp)")):T(C.name)?.type==="prompt"?(a(),o("span",Sh,"(prompt)")):T(C.name)?.type==="handoff"?(a(),o("span",Vh,"(handoff agent)")):T(C.name)?.type==="subagent"?(a(),o("span",Mh,"(subagent)")):V("",!0)],2),T(C.name)?.description?(a(),o("p",Ih,S(T(C.name)?.description),1)):V("",!0),h(C.name)?V("",!0):(a(),o("p",Eh,[...P[1]||(P[1]=[e("svg",{class:"w-3 h-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})],-1),Ce(" Not available for selected model - will be removed on save ",-1)])]))])]),e("button",{onClick:L=>F(C.name),type:"button",disabled:t.disabled,class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors text-neutral-500 hover:text-red-500","aria-label":`Remove ${y(C.name)}`},[...P[2]||(P[2]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,Lh)]),T(C.name)?.type==="provider"&&T(C.name)?.tenvs?.length?(a(),o("div",Ah,[P[3]||(P[3]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400 mb-2 font-medium"},[Ce(" Environment Variables "),e("span",{class:"text-neutral-400"},"(optional at prompt level)")],-1)),e("div",Ph,[(a(!0),o(ve,null,ke(T(C.name)?.tenvs,L=>(a(),o("div",{key:L.name,class:"flex items-center gap-2"},[A(Le,{"model-value":C.tenvs?.[L.name]||"","onUpdate:modelValue":G=>$(C.name,L.name,G),label:L.name,placeholder:L.description||"Enter value...",disabled:t.disabled,size:"sm",class:"flex-1"},null,8,["model-value","onUpdate:modelValue","label","placeholder","disabled"]),L.required?(a(),o("span",Dh," required* ")):V("",!0)]))),128))])])):V("",!0),T(C.name)?.type==="prompt"||T(C.name)?.type==="handoff"||T(C.name)?.type==="subagent"?(a(),ne(bh,{key:1,"tool-name":C.name,"tool-config":C,"tool-type":T(C.name)?.type,disabled:t.disabled,"onUpdate:option":(L,G)=>K(C.name,L,G)},null,8,["tool-name","tool-config","tool-type","disabled","onUpdate:option"])):V("",!0)],2))),128))],512)):V("",!0),A(Ve,{"model-value":"","onUpdate:modelValue":B,placeholder:l.value.length>0?"Add another tool...":t.placeholder,"search-placeholder":"Search tools...",options:k.value,disabled:t.disabled||c.value||k.value.length===0,loading:c.value},null,8,["placeholder","options","disabled","loading"]),t.error?(a(),o("p",jh,S(t.error),1)):V("",!0)]),l.value.length===0&&!c.value&&k.value.length===0?(a(),o("div",Oh," No tools available. Create tools in your agentbuilder/tools directory. ")):V("",!0)]))}}),Rh={key:0,class:"min-h-[400px] flex items-center justify-center"},Nh={key:1,class:"space-y-6 pr-2 pb-4"},Fh={class:"space-y-4"},Bh={class:"space-y-4"},qh={class:"flex justify-between"},zh={class:"flex gap-2"},Hh=["disabled"],Ca=me({__name:"PromptModal",props:{modelValue:{type:Boolean},editPrompt:{},mode:{}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=J(()=>s.mode==="edit"),u=v(!1),r=J(()=>k.value.length===1),c=v(""),f=v(null),g=v(""),d=v(""),p=v(""),h=v({type:"object",properties:{},required:[],additionalProperties:!1}),_=v(""),b=v(!1),m=v(!1),y=v(""),x=v(""),k=v([]),D=v(!1),q=v(null),B=v("auto"),F=v(null),T=v(null),$=v(!1),K=v(!1),oe=J({get:()=>F.value||"",set:ee=>F.value=ee||null}),te=J({get:()=>B.value,set:ee=>B.value=ee}),H=()=>{g.value="",c.value="",d.value="",p.value="",f.value=null,h.value={type:"object",properties:{},required:[],additionalProperties:!1},_.value="",b.value=!1,m.value=!1,y.value="",x.value="",k.value=[],D.value=!1,B.value="auto",F.value=null,T.value=null,$.value=!1,K.value=!1},P=async ee=>{if(!ee){f.value=null;return}try{const E=await ze(`/models/${ee}`);if(E.ok){const U=await E.json();f.value=U.model||U}}catch(E){console.error("Error fetching model info:",E),f.value=null}};fe(p,async ee=>{ee?await P(ee):f.value=null});const C=async()=>{if(s.editPrompt?.id){u.value=!0;try{const ee=await ze(`/prompts/${s.editPrompt.id}`);if(ee.ok){const E=await ee.json(),U=E.prompt||E;g.value=U.name||"",c.value=U.name||"",d.value=U.tool_description||"",p.value=U.model_id||"",U.model_id&&await P(U.model_id);let Z=U.required_schema;if(typeof Z=="string")try{Z=JSON.parse(Z)}catch{Z=null}h.value=Z||{type:"object",properties:{},required:[],additionalProperties:!1},_.value=U.prompt||"",b.value=U.include_chat||!1,m.value=U.include_past_tools||!1,y.value=U.before_tool||"",x.value=U.after_tool||"";const se=U.tools||[];k.value=se.map(M=>typeof M=="string"?{name:M,include_text_response:!0,include_tool_calls:!0,include_errors:!0,init_user_message_property:null}:M),D.value=U.parallel_tool_calls||!1,B.value=U.tool_choice||"auto";const j=U.reasoning||{};F.value=j.effort||U.reasoning_effort||null,T.value=j.maxTokens||U.reasoning_max_tokens||null,$.value=j.exclude||U.reasoning_exclude||!1,K.value=j.include||U.include_reasoning||!1}}catch(ee){console.error("Error loading prompt data:",ee)}finally{u.value=!1}}},L=async()=>{const ee=/^[a-z][a-z0-9_]*$/;if(!g.value||!ee.test(g.value)){alert("Please enter a valid name (lowercase letters, numbers, and underscores only, must start with a letter)");return}if(!d.value){alert("Please enter a description");return}if(!p.value){alert("Please select a model");return}if(!_.value){alert("Please enter the prompt template");return}q.value?.removeUnavailableTools();const E={name:g.value,tool_description:d.value,prompt:_.value,required_schema:h.value,model_id:p.value,include_chat:b.value,include_past_tools:m.value,before_tool:y.value||null,after_tool:x.value||null,parallel_tool_calls:D.value,tool_choice:B.value,tools:k.value,reasoning_effort:F.value,reasoning_max_tokens:T.value,reasoning_exclude:$.value,include_reasoning:K.value};l.value&&s.editPrompt?.id&&(E.id=s.editPrompt.id,c.value&&c.value!==g.value&&(E.originalName=c.value)),i("save",E),H(),i("update:modelValue",!1)},G=()=>{H(),i("update:modelValue",!1)};return fe(()=>k.value.length,ee=>{B.value==="function"&&ee!==1&&(B.value="auto")}),fe(()=>s.modelValue,async ee=>{ee&&(l.value?(H(),await Te(),await C()):H())}),fe(()=>s.editPrompt,async ee=>{ee&&l.value&&s.modelValue&&(await Te(),await C())},{immediate:!0}),(ee,E)=>(a(),ne(He,{"model-value":t.modelValue,"onUpdate:modelValue":E[16]||(E[16]=U=>ee.$emit("update:modelValue",U)),title:l.value?"Edit Prompt":"Add Prompt",width:"max-w-4xl"},{footer:be(()=>[e("div",qh,[e("button",{onClick:G,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("div",zh,[e("button",{onClick:L,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:u.value},S(l.value?"Update Prompt":"Create Prompt"),9,Hh)])])]),default:be(()=>[u.value?(a(),o("div",Rh,[...E[17]||(E[17]=[e("span",{class:"text-neutral-500"},"Loading prompt data...",-1)])])):(a(),o("div",Nh,[e("div",null,[A(df,{name:g.value,"onUpdate:name":E[0]||(E[0]=U=>g.value=U),"tool-description":d.value,"onUpdate:toolDescription":E[1]||(E[1]=U=>d.value=U)},null,8,["name","tool-description"])]),e("div",null,[A(cf,{modelValue:p.value,"onUpdate:modelValue":E[2]||(E[2]=U=>p.value=U)},null,8,["modelValue"])]),e("div",null,[A(_a,{modelValue:h.value,"onUpdate:modelValue":E[3]||(E[3]=U=>h.value=U),label:"Required Schema (Optional)"},null,8,["modelValue"])]),e("div",null,[A(ph,{"prompt-text":_.value,"onUpdate:promptText":E[4]||(E[4]=U=>_.value=U),"before-tool":y.value,"onUpdate:beforeTool":E[5]||(E[5]=U=>y.value=U),"after-tool":x.value,"onUpdate:afterTool":E[6]||(E[6]=U=>x.value=U),"required-schema":JSON.stringify(h.value,null,2),"current-prompt-name":l.value?g.value:void 0},null,8,["prompt-text","before-tool","after-tool","required-schema","current-prompt-name"])]),e("div",null,[A(Uh,{ref_key:"toolSelectorRef",ref:q,modelValue:k.value,"onUpdate:modelValue":E[7]||(E[7]=U=>k.value=U),"provider-id":f.value?.provider_id||f.value?.provider,"model-id":f.value?.model},null,8,["modelValue","provider-id","model-id"])]),e("div",Fh,[E[19]||(E[19]=e("h3",{class:"text-sm font-medium text-neutral-900 dark:text-neutral-100"}," Tool Configuration ",-1)),e("div",null,[A(Pe,{modelValue:D.value,"onUpdate:modelValue":E[8]||(E[8]=U=>D.value=U),label:"Allow parallel tool calls","help-text":"Allow the model to call multiple tools simultaneously in a single turn"},null,8,["modelValue"])]),e("div",null,[A(Ve,{modelValue:te.value,"onUpdate:modelValue":E[9]||(E[9]=U=>te.value=U),label:"Tool Choice",options:[{value:"auto",label:"Auto",description:"Model decides"},{value:"none",label:"None",description:"No tools allowed"},{value:"required",label:"Required",description:"Must call a tool"},{value:"function",label:"Function",description:r.value?"Call specific tool":"Requires exactly 1 tool"}].filter(U=>U.value!=="function"||r.value),placeholder:"Select tool choice"},null,8,["modelValue","options"]),E[18]||(E[18]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Controls whether and how the model can call tools ",-1))])]),e("div",Bh,[E[23]||(E[23]=e("h3",{class:"text-sm font-medium text-neutral-900 dark:text-neutral-100"}," Context & Reasoning Configuration ",-1)),e("div",null,[A(Pe,{modelValue:b.value,"onUpdate:modelValue":E[10]||(E[10]=U=>b.value=U),label:"Include chat history","help-text":"Expose chat history to the LLM when this prompt is used as a full prompt (not a partial in another prompt)"},null,8,["modelValue"])]),e("div",null,[A(Pe,{modelValue:m.value,"onUpdate:modelValue":E[11]||(E[11]=U=>m.value=U),label:"Include past tool calls","help-text":"Include prior tool call history in this prompt. Uncheck to remove past tool calls"},null,8,["modelValue"])]),e("div",null,[A(Pe,{modelValue:K.value,"onUpdate:modelValue":E[12]||(E[12]=U=>K.value=U),label:"Include reasoning in message history","help-text":"When loading message history, include reasoning_details from previous responses. Required for multi-turn reasoning continuity."},null,8,["modelValue"])]),E[24]||(E[24]=e("hr",{class:"border-neutral-300 dark:border-neutral-600"},null,-1)),E[25]||(E[25]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Configure extended reasoning for models like o1, o3, Gemini Thinking, and others. Reasoning is enabled automatically when either field is set. ",-1)),e("div",null,[A(Ve,{modelValue:oe.value,"onUpdate:modelValue":E[13]||(E[13]=U=>oe.value=U),label:"Reasoning Effort",options:[{value:"",label:"None",description:"Disabled"},{value:"low",label:"Low",description:"~20% of max_tokens"},{value:"medium",label:"Medium",description:"~50% of max_tokens"},{value:"high",label:"High",description:"~80% of max_tokens"}],placeholder:"Select reasoning effort"},null,8,["modelValue"]),E[20]||(E[20]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Controls reasoning capacity allocation. Supported by OpenAI o-series and Grok models. ",-1))]),e("div",null,[E[21]||(E[21]=e("label",{class:"block text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2"}," Max Reasoning Tokens ",-1)),Ie(e("input",{"onUpdate:modelValue":E[14]||(E[14]=U=>T.value=U),type:"number",min:"1024",max:"32000",step:"1024",placeholder:"Leave empty to disable or use effort level",class:"w-full px-3 py-2 text-sm border border-neutral-300 dark:border-neutral-600 rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 focus:ring-2 focus:ring-accent-500 focus:border-transparent"},null,512),[[Oe,T.value,void 0,{number:!0}]]),E[22]||(E[22]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Directly specify reasoning token limit (1024-32000). Supported by Anthropic, Gemini Thinking, and some Qwen models. ",-1))]),e("div",null,[A(Pe,{modelValue:$.value,"onUpdate:modelValue":E[15]||(E[15]=U=>$.value=U),label:"Exclude reasoning from response","help-text":"Use reasoning internally but don't return it in the response (saves tokens and cost)"},null,8,["modelValue"])])])]))]),_:1},8,["model-value","title"]))}}),Wh=me({__name:"PromptsView",setup(t){const n=lt(),s=Ye(),i=v(!1),l=v(null);fe(()=>s.query.refresh,()=>{s.query.refresh&&(l.value?.refresh(),n.replace({path:"/prompts",query:{}}))});const u=()=>{i.value=!0},r=f=>{n.push(`/prompts/${f.id}`)},c=async f=>{try{const g=await fetch(ue("/api/prompts"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(g.ok)i.value=!1,await new Promise(d=>setTimeout(d,100)),await l.value?.refresh();else{const d=await g.json();alert(d.error||"Failed to create prompt")}}catch(g){console.error("Error creating prompt:",g),alert("Failed to create prompt")}};return(f,g)=>(a(),ne(at,null,{default:be(()=>[e("div",{class:"flex justify-between items-center mb-6"},[g[1]||(g[1]=e("h1",{class:"text-3xl font-bold"},"Prompts",-1)),e("button",{onClick:u,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Create Prompt ")]),g[2]||(g[2]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Define and manage prompt templates for your agents. ",-1)),A(af,{ref_key:"dataTableRef",ref:l,onAdd:u,onEdit:r},null,512),A(Ca,{modelValue:i.value,"onUpdate:modelValue":g[0]||(g[0]=d=>i.value=d),mode:"add",onSave:c},null,8,["modelValue"])]),_:1}))}}),Jh={class:"p-8"},Kh={key:0,class:"flex items-center justify-center min-h-[400px]"},Gh={key:2,class:"flex items-center justify-center min-h-[400px]"},Xh=me({__name:"PromptEditView",setup(t){const n=lt(),s=Ye(),i=v(!0),l=v(null),u=v(!0),r=async()=>{const g=s.params.id;if(!g){n.push("/prompts");return}u.value=!0;try{const d=await fetch(ue(`/api/prompts/${g}`));if(d.ok){const p=await d.json();l.value=p.prompt||p}else alert("Prompt not found"),n.push("/prompts")}catch(d){console.error("Error loading prompt:",d),alert("Failed to load prompt"),n.push("/prompts")}finally{u.value=!1}},c=async g=>{try{const{originalName:d,...p}=g,h=d||p.id,_=await fetch(ue(`/api/prompts/${h}`),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(_.ok)n.push({path:"/prompts",query:{refresh:Date.now().toString()}});else{const b=await _.json();alert(b.error||"Failed to update prompt")}}catch(d){console.error("Error updating prompt:",d),alert("Failed to update prompt")}},f=g=>{g||n.push("/prompts")};return Me(()=>{r()}),fe(i,g=>{g||n.push("/prompts")}),(g,d)=>(a(),o("div",Jh,[u.value?(a(),o("div",Kh,[...d[1]||(d[1]=[e("span",{class:"text-neutral-500"},"Loading prompt...",-1)])])):l.value?(a(),ne(Ca,{key:1,modelValue:i.value,"onUpdate:modelValue":[d[0]||(d[0]=p=>i.value=p),f],mode:"edit","edit-prompt":l.value,onSave:c},null,8,["modelValue","edit-prompt"])):(a(),o("div",Gh,[...d[2]||(d[2]=[e("span",{class:"text-neutral-500"},"Prompt not found",-1)])]))]))}}),Yh={class:"border-2 border-black dark:border-neutral-300 rounded-lg overflow-hidden"},Qh={key:0,class:"px-4 py-2 border-b-2 border-black dark:border-neutral-300 bg-neutral-50 dark:bg-neutral-900"},Zh={class:"flex items-center justify-between"},eg={class:"text-sm font-medium"},tg={class:"flex items-center gap-2"},ag={key:1,class:"px-4 py-8 flex items-center justify-center"},og={key:2,class:"px-4 py-8 text-center text-neutral-500"},lg={key:3,class:"divide-y divide-neutral-200 dark:divide-neutral-700"},sg=["onClick"],ng={class:"flex items-start gap-3"},rg={class:"flex-shrink-0 mt-0.5"},ig=["checked","onClick"],dg={class:"flex-1 min-w-0"},ug={class:"flex items-center gap-2"},cg={class:"text-sm font-medium"},pg={key:0,class:"text-xs px-1.5 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},mg={class:"mt-1 text-xs text-neutral-600 dark:text-neutral-400 space-y-0.5"},vg={key:0},fg={key:0},hg={key:1},gg={key:2},bg=me({__name:"ExposedSelectList",props:{providers:{default:()=>[]},modelValue:{default:()=>[]},label:{},loading:{type:Boolean}},emits:["update:modelValue"],setup(t,{emit:n}){function s(d){if(d===0)return"$0.00";const p=Math.abs(d);let h;return p<1e-4?h=p.toExponential(3):p<.001||p<.01||p<.1?h=p.toFixed(4):p<1?h=p.toFixed(3):p<10||p<100?h=p.toFixed(2):p<1e3?h=p.toFixed(1):h=p.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:0}),h.includes(".")&&(h=h.replace(/\.?0+$/,""),!h.includes(".")&&p<100&&(h=p.toFixed(2))),d<0?`-$${h}`:`$${h}`}const i=t,l=n,u=d=>i.modelValue.includes(d),r=d=>{const p=[...i.modelValue],h=p.indexOf(d);h>-1?p.splice(h,1):p.push(d),l("update:modelValue",p)},c=()=>{l("update:modelValue",i.providers.map(d=>d.id))},f=()=>{l("update:modelValue",[])},g=J(()=>i.providers.length>0&&i.modelValue.length===i.providers.length);return J(()=>i.modelValue.length>0&&i.modelValue.length<i.providers.length),(d,p)=>(a(),o("div",Yh,[t.label?(a(),o("div",Qh,[e("div",Zh,[e("span",eg,S(t.label),1),e("div",tg,[e("button",{type:"button",onClick:p[0]||(p[0]=h=>g.value?f():c()),class:"text-xs px-2 py-1 border border-neutral-400 dark:border-neutral-600 rounded hover:bg-neutral-100 dark:hover:bg-neutral-800"},S(g.value?"Deselect All":"Select All"),1)])])])):V("",!0),t.loading?(a(),o("div",ag,[...p[1]||(p[1]=[e("div",{class:"flex items-center gap-2 text-neutral-500"},[e("svg",{class:"animate-spin h-5 w-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]),e("span",null,"Loading providers...")],-1)])])):t.providers.length===0?(a(),o("div",og," No providers available ")):(a(),o("div",lg,[(a(!0),o(ve,null,ke(t.providers,h=>(a(),o("div",{key:h.id,class:"px-4 py-3 hover:bg-neutral-50 dark:hover:bg-neutral-900 cursor-pointer",onClick:_=>r(h.id)},[e("div",ng,[e("div",rg,[e("input",{type:"checkbox",checked:u(h.id),onClick:Ee(_=>r(h.id),["stop"]),class:"w-4 h-4 border-2 border-black dark:border-neutral-300 rounded focus:ring-2 focus:ring-black dark:focus:ring-white"},null,8,ig)]),e("div",dg,[e("div",ug,[e("span",cg,S(h.name),1),h.quantization?(a(),o("span",pg,S(h.quantization),1)):V("",!0)]),e("div",mg,[e("div",null,S(s(h.pricing.prompt*1e6))+"/M input • "+S(s(h.pricing.completion*1e6))+"/M output ",1),h.maxPromptTokens||h.maxCompletionTokens?(a(),o("div",vg,[h.maxPromptTokens?(a(),o("span",fg," Max prompt: "+S(h.maxPromptTokens.toLocaleString())+" tokens ",1)):V("",!0),h.maxPromptTokens&&h.maxCompletionTokens?(a(),o("span",hg," • ")):V("",!0),h.maxCompletionTokens?(a(),o("span",gg," Max completion: "+S(h.maxCompletionTokens.toLocaleString())+" tokens ",1)):V("",!0)])):V("",!0)])])])],8,sg))),128))]))]))}}),xg={class:"space-y-2"},yg={key:0,class:"space-y-2"},kg={key:0,class:"block text-sm font-medium"},wg={key:0,class:"text-red-500"},_g=["src","alt"],$g={class:"flex-1 text-sm"},Cg={key:0,class:"text-xs text-neutral-500 dark:text-neutral-400 ml-1"},Tg=["onClick","aria-label"],Sg={key:1,class:"text-xs text-red-500 dark:text-red-400"},Ct=me({__name:"MultipleSelectionsInput",props:We({label:{},placeholder:{default:"Select an option"},searchPlaceholder:{default:"Search..."},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},options:{},addLabel:{default:"Add another"},loading:{type:Boolean,default:!1}},{modelValue:{required:!0,default:()=>[]},modelModifiers:{}}),emits:We(["removeItem"],["update:modelValue"]),setup(t,{emit:n}){const s=t,i=n,l=st(t,"modelValue"),u=v();na(async()=>{u.value,await Te(),await ra({parent:u,values:l,dragHandle:".drag-handle"})});const r=J(()=>Array.isArray(l.value)?l.value.length>0&&typeof l.value[0]=="object"?l.value:l.value.map(d=>{const p=s.options.find(h=>h.value===d);return{id:d,label:p?.label||d,description:p?.description,icon:p?.icon}}):[]),c=J(()=>{const d=r.value.map(p=>p.id);return s.options.filter(p=>!d.includes(p.value))}),f=d=>{if(!d)return;const p=s.options.find(h=>h.value===d);if(p)if(l.value.length===0||typeof l.value[0]=="string")l.value=[...l.value,d];else{const h={id:d,label:p.label,description:p.description,icon:p.icon};l.value=[...l.value,h]}},g=d=>{typeof l.value[0]=="string"?l.value=l.value.filter(p=>p!==d):l.value=l.value.filter(p=>p.id!==d),i("removeItem",d)};return(d,p)=>(a(),o("div",xg,[r.value.length>0?(a(),o("div",yg,[t.label?(a(),o("label",kg,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",wg,"*")):V("",!0)])):V("",!0),e("div",{class:"space-y-1",ref_key:"dragAreaRef",ref:u},[(a(!0),o(ve,null,ke(r.value,h=>(a(),o("div",{key:h.id,class:ae(["flex items-center gap-2 px-3 py-2 bg-neutral-50 dark:bg-neutral-900 rounded border","border-neutral-200 dark:border-neutral-800",t.disabled?"opacity-50":""])},[p[1]||(p[1]=e("div",{class:"drag-handle cursor-move text-neutral-400 hover:text-neutral-600 dark:text-neutral-600 dark:hover:text-neutral-400"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 8h16M4 16h16"})])],-1)),h.icon?(a(),o("img",{key:0,src:h.icon,alt:h.label,class:"w-4 h-4 flex-shrink-0"},null,8,_g)):V("",!0),e("span",$g,[Ce(S(h.label)+" ",1),h.description?(a(),o("span",Cg," ("+S(h.description)+") ",1)):V("",!0)]),t.disabled?V("",!0):(a(),o("button",{key:1,onClick:_=>g(h.id),type:"button",class:"p-1 hover:bg-neutral-200 dark:hover:bg-neutral-800 rounded transition-colors","aria-label":`Remove ${h.label}`},[...p[0]||(p[0]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])],8,Tg))],2))),128))],512)])):V("",!0),A(Ve,{"model-value":"","onUpdate:modelValue":f,label:r.value.length>0?t.addLabel:t.label,options:c.value,placeholder:t.placeholder,"search-placeholder":t.searchPlaceholder,disabled:t.disabled||c.value.length===0,loading:t.loading},null,8,["label","options","placeholder","search-placeholder","disabled","loading"]),t.error?(a(),o("p",Sg,S(t.error),1)):V("",!0)]))}}),Vg={key:2,class:"text-xs text-red-500 dark:text-red-400 mt-1"},Mg=me({__name:"ModelSelectorInput",props:We({label:{},placeholder:{default:"Select a model"},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},allowMultiple:{type:Boolean,default:!1}},{modelValue:{required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(t){const n=t,s=st(t,"modelValue"),i=v([]),l=v(!1),u=J(()=>i.value.map(f=>({value:f.id,label:f.name,description:f.provider_id||f.provider,icon:f.iconId}))),r=async()=>{l.value=!0;try{const f=await fetch(ue("/api/models"));if(f.ok){const g=await f.json();i.value=g.models||[]}}catch(f){console.error("Error fetching models:",f)}finally{l.value=!1}},c=f=>{};return Me(()=>{r()}),fe(()=>n.allowMultiple,()=>{n.allowMultiple&&typeof s.value=="string"?s.value=s.value?[s.value]:[]:!n.allowMultiple&&Array.isArray(s.value)&&(s.value=s.value[0]||"")}),(f,g)=>(a(),o(ve,null,[t.allowMultiple?(a(),ne(Ct,{key:0,modelValue:s.value,"onUpdate:modelValue":g[0]||(g[0]=d=>s.value=d),label:t.label,placeholder:t.placeholder,"search-placeholder":"Search models...",error:t.error,required:t.required,disabled:t.disabled,options:u.value,loading:l.value,"add-label":"Add another model",onRemoveItem:c},null,8,["modelValue","label","placeholder","error","required","disabled","options","loading"])):(a(),ne(Ve,{key:1,modelValue:s.value,"onUpdate:modelValue":g[1]||(g[1]=d=>s.value=d),label:t.label,placeholder:t.placeholder,"search-placeholder":"Search models...",options:u.value,disabled:t.disabled,loading:l.value},null,8,["modelValue","label","placeholder","options","disabled","loading"])),!t.allowMultiple&&t.error?(a(),o("p",Vg,S(t.error),1)):V("",!0)],64))}}),Ig={class:"space-y-4"},Eg={key:0},Lg={key:1},Ag=["value"],Pg={key:0,class:"mt-1 text-xs text-red-500"},Dg={key:1,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},jg={class:"px-1 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded"},Og={key:2,class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"},Ug={key:2,class:"space-y-3"},Rg={class:"flex items-center justify-between"},Ng={key:0,class:"text-sm text-neutral-500 dark:text-neutral-400"},Fg={key:1,class:"space-y-2"},Bg={class:"grid grid-cols-2 gap-x-4 gap-y-2"},qg={class:"grid grid-cols-2 gap-4 pt-2"},zg={key:3,class:"space-y-3"},Hg={key:0,class:"text-sm text-neutral-500 dark:text-neutral-400"},Wg={key:1,class:"space-y-2"},Jg={class:"grid grid-cols-1 gap-2"},Kg=["value"],Gg={class:"flex-1 min-w-0"},Xg={class:"font-medium text-sm"},Yg={class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},Qg={key:0,class:"mt-1"},Zg={class:"text-xs text-amber-600 dark:text-amber-400"},eb={key:4},tb={key:5},ab={class:"flex justify-end gap-2"},ob=["disabled"],lb=me({__name:"ModelModal",props:{modelValue:{type:Boolean},editModel:{},mode:{default:"add"}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=t,i=n,l=v([]),u=v(""),r=v(""),c=v([]),f=v(!1),g=v(!1),d=v([]),p=v([]),h=v(!1),_=v({supportsImages:!1,supportsToolCalls:!0,supportsStreaming:!0,supportsJsonMode:!0}),b=v(null),m=v(!1),y=v([]),x=v([]),k=v(!1),D=v([]),q=J(()=>s.mode==="edit"),B=v(""),F=v(""),T=v(""),$=O=>{let W=O.replace(/[^a-zA-Z0-9\s_-]/g,"");return W=W.trim().toLowerCase().replace(/[\s-]+/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),W?/^[a-z][a-z0-9_]*$/.test(W)?T.value="":T.value="Name must start with a letter and contain only lowercase letters, numbers, and underscores":T.value="Name is required",W},K=O=>{const W=O.target.value;F.value=$(W)},oe=v(!1),te=v(null),H=J(()=>l.value.filter(O=>O.hasApiKey).map(O=>({value:O.name,label:O.name,description:O.sdk==="openai-sdk"?"OpenAI SDK":O.sdk==="openrouter"?"OpenRouter":O.sdk,icon:O.iconId}))),P=J(()=>c.value.map(O=>({...O,icon:O.iconId}))),C=J(()=>!q.value||!te.value||oe.value?!1:F.value!==te.value.name||u.value!==te.value.provider||r.value!==te.value.model||JSON.stringify(p.value.sort())!==JSON.stringify(te.value.endpoints.sort())||JSON.stringify(D.value)!==JSON.stringify(te.value.fallbacks)||JSON.stringify(_.value)!==JSON.stringify(te.value.capabilities)||JSON.stringify(x.value.sort())!==JSON.stringify(te.value.providerTools.sort())),L=J(()=>l.value.find(W=>W.name===u.value)?.sdk==="openrouter"),G=async()=>{f.value=!0;try{const O=await fetch(ue("/api/providers"));if(O.ok){const W=await O.json();l.value=W.providers||[]}}catch(O){console.error("Error fetching providers:",O)}finally{f.value=!1}},ee=async()=>{if(!u.value){c.value=[];return}g.value=!0;try{const O=await fetch(ue("/api/models/available"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value})});if(O.ok){const W=await O.json();c.value=W.models||[]}else{const W=await O.json();console.error("Error fetching models:",W),c.value=[],alert(W.error||"Failed to fetch available models")}}catch(O){console.error("Error fetching models:",O),c.value=[]}finally{g.value=!1}},E=async()=>{if(!(!u.value||!r.value)){m.value=!0;try{const O=await fetch(ue("/api/models/capabilities"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value,modelId:r.value})});if(O.ok){const W=await O.json();W.capabilities&&(b.value=W.capabilities,_.value={supportsImages:W.capabilities.supportsImages??!1,supportsToolCalls:W.capabilities.supportsToolCalls??!0,supportsStreaming:W.capabilities.supportsStreaming??!0,supportsJsonMode:W.capabilities.supportsJsonMode??!0,maxContextTokens:W.capabilities.maxContextTokens,maxOutputTokens:W.capabilities.maxOutputTokens})}}catch(O){console.error("Error fetching capabilities:",O)}finally{m.value=!1}}},U=async()=>{if(!u.value||!r.value){y.value=[];return}k.value=!0;try{const O=await fetch(ue(`/api/providers/${u.value}/tools?model=${encodeURIComponent(r.value)}`));if(O.ok){const W=await O.json();y.value=W.tools||[],q.value||(x.value=y.value.map(ce=>ce.name))}else y.value=[]}catch(O){console.error("Error fetching provider tools:",O),y.value=[]}finally{k.value=!1}},Z=()=>{_.value={supportsImages:!1,supportsToolCalls:!0,supportsStreaming:!0,supportsJsonMode:!0},b.value=null},se=()=>{b.value&&(_.value={supportsImages:b.value.supportsImages??!1,supportsToolCalls:b.value.supportsToolCalls??!0,supportsStreaming:b.value.supportsStreaming??!0,supportsJsonMode:b.value.supportsJsonMode??!0,maxContextTokens:b.value.maxContextTokens,maxOutputTokens:b.value.maxOutputTokens})},j=()=>{F.value="",B.value="",u.value="",r.value="",c.value=[],D.value=[],d.value=[],p.value=[],y.value=[],x.value=[],Z(),te.value=null,oe.value=!1},M=async()=>{if(s.editModel){oe.value=!0;try{await G(),F.value=s.editModel.name||"",B.value=s.editModel.name||"",u.value=s.editModel.provider_id||s.editModel.provider,await ee(),r.value=s.editModel.model,await R(),s.editModel.included_providers&&s.editModel.included_providers.length>0&&(p.value=s.editModel.included_providers),await w(),s.editModel.capabilities?_.value={supportsImages:s.editModel.capabilities.supportsImages??!1,supportsToolCalls:s.editModel.capabilities.supportsToolCalls??!0,supportsStreaming:s.editModel.capabilities.supportsStreaming??!0,supportsJsonMode:s.editModel.capabilities.supportsJsonMode??!0,maxContextTokens:s.editModel.capabilities.maxContextTokens,maxOutputTokens:s.editModel.capabilities.maxOutputTokens}:await E(),await U(),s.editModel.providerTools&&Array.isArray(s.editModel.providerTools)&&(x.value=s.editModel.providerTools),te.value={name:F.value,provider:u.value,model:r.value,endpoints:[...p.value],fallbacks:[...D.value],capabilities:{..._.value},providerTools:[...x.value]}}finally{oe.value=!1}}};fe(()=>s.modelValue,async O=>{O?q.value&&s.editModel?await M():(await G(),j()):j()});const w=async()=>{if(s.editModel?.id){if(s.editModel.fallbacks&&Array.isArray(s.editModel.fallbacks)){D.value=s.editModel.fallbacks.map(O=>typeof O=="string"?O:O.id);return}try{const O=await fetch(ue(`/api/models/${s.editModel.id}/fallbacks`));if(O.ok){const W=await O.json();D.value=W.fallbacks.map(ce=>ce.fallback_model_id)}}catch(O){console.error("Error loading fallbacks:",O)}}};fe(u,async(O,W)=>{oe.value||q.value&&!W&&O===(s.editModel?.provider_id||s.editModel?.provider)||(r.value="",d.value=[],p.value=[],u.value&&await ee())});const R=async()=>{if(!r.value||!u.value){d.value=[];return}const O=l.value.find(ce=>ce.name===u.value);if(!O||O.sdk!=="openrouter"){d.value=[];return}const W=P.value.find(ce=>ce.value===r.value);if(!W?.slug){console.error("Model slug not found"),d.value=[];return}h.value=!0;try{const ce=await fetch(ue("/api/models/endpoints"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:u.value,modelSlug:W.slug})});if(ce.ok){const z=await ce.json();d.value=z.endpoints||[],q.value||(p.value=d.value.map(N=>N.id))}else{const z=await ce.json();console.error("Error fetching endpoints:",z),d.value=[]}}catch(ce){console.error("Error fetching endpoints:",ce),d.value=[]}finally{h.value=!1}};fe(r,async(O,W)=>{oe.value||q.value&&!W&&O===s.editModel?.model||(r.value?(await R(),await E(),await U(),W&&O!==W&&(p.value=d.value.map(ce=>ce.id))):(d.value=[],p.value=[],y.value=[],x.value=[],Z()))});const I=()=>{if(!u.value||!r.value){alert("Please select a provider and model");return}if(!F.value){alert("Please enter a name for the model");return}if(T.value){alert(T.value);return}const O=L.value?p.value:[],W={name:F.value,model:r.value,provider:u.value,included_providers:O,fallbacks:D.value,capabilities:_.value,providerTools:x.value};q.value&&s.editModel?.id&&(W.id=s.editModel.id,B.value&&B.value!==F.value&&(W.originalName=B.value)),i("save",W)},le=()=>{j(),i("update:modelValue",!1)};return(O,W)=>(a(),ne(He,{"model-value":t.modelValue,"onUpdate:modelValue":W[11]||(W[11]=ce=>O.$emit("update:modelValue",ce)),title:q.value?"Edit Model":"Add Model",width:"max-w-2xl","min-height":"min-h-[36rem]","has-changes":C.value},{footer:be(()=>[e("div",ab,[e("button",{onClick:le,type:"button",class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:I,type:"button",class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity",disabled:!u.value||!r.value},S(q.value?"Update Model":"Add Model"),9,ob)])]),default:be(()=>[e("div",Ig,[A(Ve,{modelValue:u.value,"onUpdate:modelValue":W[0]||(W[0]=ce=>u.value=ce),options:H.value,label:"Provider",placeholder:"Select a provider",disabled:f.value||q.value&&!!s.editModel},null,8,["modelValue","options","disabled"]),u.value?(a(),o("div",Eg,[A(Ve,{modelValue:r.value,"onUpdate:modelValue":W[1]||(W[1]=ce=>r.value=ce),options:P.value,label:"Model",placeholder:"Select a model","search-placeholder":"Search models...",loading:g.value},null,8,["modelValue","options","loading"])])):V("",!0),r.value?(a(),o("div",Lg,[W[13]||(W[13]=e("label",{class:"block text-sm font-medium mb-2"},"Name",-1)),e("input",{value:F.value,onInput:K,type:"text",class:ae(["w-full px-3 py-2 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 focus:ring-2 focus:ring-accent-500 focus:border-transparent",T.value?"border-red-500":"border-neutral-300 dark:border-neutral-600"]),placeholder:"e.g., coding_model, planning_model, fast_response"},null,42,Ag),T.value?(a(),o("p",Pg,S(T.value),1)):F.value?(a(),o("p",Dg,[W[12]||(W[12]=Ce(" Will be saved as: ",-1)),e("code",jg,S(F.value),1)])):(a(),o("p",Og," A descriptive name for this model (e.g., coding_model, planning_model). This becomes the filename and reference ID. "))])):V("",!0),r.value?(a(),o("div",Ug,[e("div",Rg,[W[14]||(W[14]=e("label",{class:"block text-sm font-medium"},"Model Capabilities",-1)),b.value?(a(),o("button",{key:0,onClick:se,type:"button",class:"text-xs text-accent-600 dark:text-accent-400 hover:underline"}," Reset to detected ")):V("",!0)]),m.value?(a(),o("div",Ng," Detecting capabilities... ")):(a(),o("div",Fg,[e("div",Bg,[A(Pe,{modelValue:_.value.supportsImages,"onUpdate:modelValue":W[2]||(W[2]=ce=>_.value.supportsImages=ce),label:"Vision/Images","help-text":"Can process image inputs"},null,8,["modelValue"]),A(Pe,{modelValue:_.value.supportsToolCalls,"onUpdate:modelValue":W[3]||(W[3]=ce=>_.value.supportsToolCalls=ce),label:"Tool Calls","help-text":"Supports function calling"},null,8,["modelValue"]),A(Pe,{modelValue:_.value.supportsStreaming,"onUpdate:modelValue":W[4]||(W[4]=ce=>_.value.supportsStreaming=ce),label:"Streaming","help-text":"Supports streaming responses"},null,8,["modelValue"]),A(Pe,{modelValue:_.value.supportsJsonMode,"onUpdate:modelValue":W[5]||(W[5]=ce=>_.value.supportsJsonMode=ce),label:"JSON Mode","help-text":"Supports structured output"},null,8,["modelValue"])]),e("div",qg,[e("div",null,[W[15]||(W[15]=e("label",{class:"block text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-1"}," Max Context Tokens ",-1)),Ie(e("input",{"onUpdate:modelValue":W[6]||(W[6]=ce=>_.value.maxContextTokens=ce),type:"number",class:"w-full px-2 py-1.5 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 border-neutral-300 dark:border-neutral-600 focus:ring-1 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., 128000"},null,512),[[Oe,_.value.maxContextTokens,void 0,{number:!0}]])]),e("div",null,[W[16]||(W[16]=e("label",{class:"block text-xs font-medium text-neutral-600 dark:text-neutral-400 mb-1"}," Max Output Tokens ",-1)),Ie(e("input",{"onUpdate:modelValue":W[7]||(W[7]=ce=>_.value.maxOutputTokens=ce),type:"number",class:"w-full px-2 py-1.5 text-sm border rounded bg-white dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100 border-neutral-300 dark:border-neutral-600 focus:ring-1 focus:ring-accent-500 focus:border-transparent",placeholder:"e.g., 16384"},null,512),[[Oe,_.value.maxOutputTokens,void 0,{number:!0}]])])])])),W[17]||(W[17]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Capabilities are auto-detected from the provider. You can override them if needed. ",-1))])):V("",!0),r.value&&y.value.length>0?(a(),o("div",zg,[W[19]||(W[19]=e("label",{class:"block text-sm font-medium"},"Provider Tools",-1)),k.value?(a(),o("div",Hg," Loading provider tools... ")):(a(),o("div",Wg,[W[18]||(W[18]=e("p",{class:"text-xs text-neutral-500 dark:text-neutral-400"}," Built-in tools available for this model. Select which tools to enable. ",-1)),e("div",Jg,[(a(!0),o(ve,null,ke(y.value,ce=>(a(),o("label",{key:ce.name,class:ae(["flex items-start gap-3 p-3 border rounded cursor-pointer hover:bg-neutral-50 dark:hover:bg-neutral-800/50 transition-colors",x.value.includes(ce.name)?"border-black dark:border-white":"border-neutral-200 dark:border-neutral-700"])},[Ie(e("input",{type:"checkbox",value:ce.name,"onUpdate:modelValue":W[8]||(W[8]=z=>x.value=z),class:"mt-0.5 h-4 w-4 rounded border-neutral-300 dark:border-neutral-600 text-black dark:text-white focus:ring-black dark:focus:ring-white accent-black dark:accent-white"},null,8,Kg),[[sa,x.value]]),e("div",Gg,[e("div",Xg,S(ce.name),1),e("div",Yg,S(ce.description),1),ce.tenvs&&ce.tenvs.length>0?(a(),o("div",Qg,[e("span",Zg," Requires: "+S(ce.tenvs.filter(z=>z.required).map(z=>z.name).join(", ")||"none (optional config available)"),1)])):V("",!0)])],2))),128))])]))])):V("",!0),r.value&&L.value?(a(),o("div",eb,[W[20]||(W[20]=e("label",{class:"block text-sm font-medium mb-2"}," Available Providers ",-1)),A(bg,{modelValue:p.value,"onUpdate:modelValue":W[9]||(W[9]=ce=>p.value=ce),providers:d.value,loading:h.value},null,8,["modelValue","providers","loading"]),W[21]||(W[21]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Select which providers can be used for this model ",-1))])):V("",!0),r.value?(a(),o("div",tb,[A(Mg,{modelValue:D.value,"onUpdate:modelValue":W[10]||(W[10]=ce=>D.value=ce),label:"Fallback Models",placeholder:"Add fallback model...","allow-multiple":!0},null,8,["modelValue"]),W[22]||(W[22]=e("p",{class:"mt-1 text-xs text-neutral-500 dark:text-neutral-400"}," Fallback models will be used in order if the primary model fails ",-1))])):V("",!0)])]),_:1},8,["model-value","title","has-changes"]))}}),sb={class:"flex justify-between items-center mb-6"},nb={class:"flex items-center gap-2"},rb=["src","alt"],ib={class:"text-sm text-neutral-600 dark:text-neutral-400 font-mono"},db={key:0,class:"space-y-0.5"},ub=["title"],cb={class:"shrink-0 font-mono pr-2"},pb=["src","alt"],mb={class:"truncate"},vb={key:1,class:"text-neutral-400 dark:text-neutral-600 text-sm"},fb=me({__name:"ModelsView",setup(t){const n=v(!1),s=v([]),i=v(!1),l=v(null),u=v("add"),r=[{key:"name",label:"Name",width:"w-1/4"},{key:"model",label:"Model",width:"w-1/4"},{key:"provider",label:"Provider",width:"w-1/4"},{key:"fallbacks",label:"Fallbacks",width:"w-1/4"}],c=[{icon:"edit",label:"Edit",handler:p=>{l.value=p,u.value="edit",n.value=!0}},{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this model? This action cannot be undone.",handler:async p=>{await d(p.id)}}],f=async()=>{i.value=!0;try{const p=await fetch(ue("/api/models"));if(!p.ok)throw new Error("Failed to fetch models");const h=await p.json();s.value=h.models||[]}catch(p){console.error("Error fetching models:",p),s.value=[]}finally{i.value=!1}},g=async p=>{try{if(l.value){const{originalName:h,..._}=p,b=h||l.value.id,m=await fetch(ue(`/api/models/${b}`),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(_)});if(!m.ok){const y=await m.json();alert(y.error||"Failed to update model");return}}else{const h=await fetch(ue("/api/models"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(p)});if(!h.ok){const _=await h.json();alert(_.error||"Failed to add model");return}}await f(),n.value=!1,l.value=null,u.value="add"}catch(h){console.error("Error saving model:",h),alert("Failed to save model")}},d=async p=>{try{const h=await fetch(ue(`/api/models/${p}`),{method:"DELETE"});if(!h.ok){const _=await h.json();alert(_.error||"Failed to delete model");return}await f()}catch(h){console.error("Error deleting model:",h),alert("Failed to delete model")}};return Me(()=>{f()}),(p,h)=>(a(),ne(at,null,{default:be(()=>[e("div",sb,[h[3]||(h[3]=e("h1",{class:"text-3xl font-bold"},"Models",-1)),e("button",{onClick:h[0]||(h[0]=()=>{u.value="add",l.value=null,n.value=!0}),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Model ")]),h[4]||(h[4]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-8"}," Configure AI models from your connected providers. Models define which AI capabilities are available to your agents. ",-1)),A(Ge,{columns:r,data:s.value,actions:c,loading:i.value,"empty-message":"No models configured yet. Add your first model to get started."},{"cell-name":be(({value:_,row:b})=>[e("div",nb,[b.provider?(a(),o("img",{key:0,src:`/api/providers/${b.provider}/icon?model=${encodeURIComponent(b.model||"")}`,class:"w-5 h-5 shrink-0",alt:b.provider},null,8,rb)):V("",!0),e("span",null,S(_),1)])]),"cell-model":be(({value:_})=>[e("span",ib,S(_||"—"),1)]),"cell-fallbacks":be(({value:_})=>[_&&_.length>0?(a(),o("div",db,[(a(!0),o(ve,null,ke(_,(b,m)=>(a(),o("div",{key:b.id,class:"text-sm text-neutral-600 dark:text-neutral-400 flex items-center",title:b.name},[e("span",cb,S(m===_.length-1?"└─":"├─"),1),b.provider?(a(),o("img",{key:0,src:`/api/providers/${b.provider}/icon?model=${encodeURIComponent(b.model||"")}`,class:"w-4 h-4 shrink-0 mr-1.5",alt:b.provider},null,8,pb)):V("",!0),e("span",mb,S(b.name),1)],8,ub))),128))])):(a(),o("span",vb," None "))]),_:1},8,["data","loading"]),A(lb,{modelValue:n.value,"onUpdate:modelValue":[h[1]||(h[1]=_=>n.value=_),h[2]||(h[2]=_=>{n.value=_,_||(l.value=null,u.value="add")})],"edit-model":l.value,mode:u.value,onSave:g},null,8,["modelValue","edit-model","mode"])]),_:1}))}}),hb={class:"space-y-4"},gb={class:"space-y-1"},bb={class:"relative"},xb={key:0,class:"flex items-center gap-2"},yb=["src","alt"],kb={key:1,class:"text-neutral-500"},wb={key:0,class:"absolute z-10 w-full mt-1 bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded shadow-lg"},_b=["onClick"],$b=["src","alt"],Cb={key:0,class:"text-xs text-red-500 dark:text-red-400"},Tb=me({__name:"AddProviderModal",props:{modelValue:{type:Boolean}},emits:["update:modelValue","save"],setup(t,{emit:n}){const s=n,i=v({name:"",type:"",apiKey:"",baseUrl:""}),l=v([]),u=v(!1),r=async()=>{u.value=!0;try{const y=await fetch(ue("/api/providers"));if(y.ok){const x=await y.json();l.value=(x.providers||[]).map(k=>({value:k.name,label:k.label||k.name,icon:k.iconId,sdk:k.sdk}))}}catch(y){console.error("Error fetching providers:",y)}finally{u.value=!1}};Me(()=>{r()});const c=v(!1),f=J(()=>l.find(y=>y.value===i.value.type)),g=()=>{setTimeout(()=>{c.value=!1},200)},d=v({});fe(()=>i.value.type,y=>{if(y&&!i.value.name){const x=l.find(k=>k.value===y);x&&(i.value.name=x.label)}});const p=J(()=>i.value.type==="custom"||i.value.type==="openai"),h=()=>{d.value={};let y=!0;return i.value.name||(d.value.name="Provider name is required",y=!1),i.value.type||(d.value.type="Provider type is required",y=!1),i.value.apiKey||(d.value.apiKey="API key is required",y=!1),p.value&&i.value.type==="custom"&&!i.value.baseUrl&&(d.value.baseUrl="Base URL is required for custom providers",y=!1),y},_=()=>{h()&&(s("save",{...i.value}),m(),s("update:modelValue",!1))},b=()=>{m(),s("update:modelValue",!1)},m=()=>{i.value={name:"",type:"",apiKey:""},d.value={}};return(y,x)=>(a(),ne(He,{"model-value":t.modelValue,"onUpdate:modelValue":x[4]||(x[4]=k=>y.$emit("update:modelValue",k)),title:"Add Provider",width:"max-w-md"},{footer:be(()=>[e("div",{class:"flex gap-2 justify-end"},[e("button",{onClick:b,class:"px-3 py-1.5 text-sm border border-black dark:border-white rounded font-medium hover:bg-black/5 dark:hover:bg-white/10 transition-colors"}," Cancel "),e("button",{onClick:_,class:"px-3 py-1.5 text-sm bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Provider ")])]),default:be(()=>[e("div",hb,[e("div",gb,[x[6]||(x[6]=e("label",{class:"block text-sm font-medium"},[Ce(" Provider Type "),e("span",{class:"text-red-500"},"*")],-1)),e("div",bb,[e("button",{type:"button",onClick:x[0]||(x[0]=k=>c.value=!c.value),onBlur:g,class:ae(["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm text-left focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white transition-colors",[d.value.type?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300"]])},[f.value?(a(),o("div",xb,[e("img",{src:f.value.icon,alt:f.value.label,class:"w-5 h-5"},null,8,yb),e("span",null,S(f.value.label),1)])):(a(),o("span",kb,"Select a provider")),x[5]||(x[5]=e("div",{class:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none"},[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 9l-7 7-7-7"})])],-1))],34),c.value?(a(),o("div",wb,[(a(!0),o(ve,null,ke(l.value,k=>(a(),o("button",{key:k.value,type:"button",onClick:D=>{i.value.type=k.value,c.value=!1},class:"w-full px-3 py-2 text-left hover:bg-black/5 dark:hover:bg-white/10 transition-colors flex items-center gap-2"},[e("img",{src:k.icon,alt:k.label,class:"w-5 h-5"},null,8,$b),e("span",null,S(k.label),1)],8,_b))),128))])):V("",!0)]),d.value.type?(a(),o("p",Cb,S(d.value.type),1)):V("",!0)]),A(Le,{modelValue:i.value.name,"onUpdate:modelValue":x[1]||(x[1]=k=>i.value.name=k),label:"Provider Name",placeholder:"e.g., My OpenAI Provider",error:d.value.name,required:""},null,8,["modelValue","error"]),A(Le,{modelValue:i.value.apiKey,"onUpdate:modelValue":x[2]||(x[2]=k=>i.value.apiKey=k),label:"API Key",type:"password",placeholder:"sk-...",error:d.value.apiKey,required:""},null,8,["modelValue","error"]),p.value?(a(),ne(Le,{key:0,modelValue:i.value.baseUrl,"onUpdate:modelValue":x[3]||(x[3]=k=>i.value.baseUrl=k),label:"Base URL",placeholder:"https://api.example.com",error:d.value.baseUrl,required:i.value.type==="custom"},null,8,["modelValue","error","required"])):V("",!0)])]),_:1},8,["model-value"]))}}),Sb={class:"flex justify-between items-center mb-6"},Vb=me({__name:"ProvidersView",setup(t){const n=v(!1),s=v([]),i=v(!1),l=[{key:"name",label:"Name",width:"w-1/3"},{key:"sdk",label:"SDK Type",width:"w-1/3",formatter:g=>({"openai-sdk":"OpenAI SDK",openrouter:"OpenRouter",openai:"OpenAI"})[g]||g},{key:"hasApiKey",label:"API Key",width:"w-1/3",formatter:g=>g?"✓ Configured":"✗ Not configured"}],u=[{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this provider? This action cannot be undone.",handler:async g=>{await f(g.name)}}],r=async()=>{i.value=!0;try{const g=await fetch(ue("/api/providers"));if(!g.ok)throw new Error("Failed to fetch providers");const d=await g.json();s.value=d.providers||[]}catch(g){console.error("Error fetching providers:",g),s.value=[]}finally{i.value=!1}},c=async g=>{try{const d=await fetch(ue("/api/providers"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!d.ok){const p=await d.json();alert(p.error||"Failed to add provider");return}await r(),n.value=!1}catch(d){console.error("Error adding provider:",d),alert("Failed to add provider")}},f=async g=>{try{const d=await fetch(ue(`/api/providers/${encodeURIComponent(g)}`),{method:"DELETE"});if(!d.ok){const p=await d.json();p.modelCount?alert(`${p.error}
22
22
 
23
- This provider has ${p.modelCount} associated model(s).`):alert(p.error||"Failed to delete provider");return}await r()}catch(d){console.error("Error deleting provider:",d),alert("Failed to delete provider")}};return Ve(()=>{r()}),(g,d)=>(a(),se(at,null,{default:ge(()=>[e("div",xb,[d[2]||(d[2]=e("h1",{class:"text-3xl font-bold"},"Providers",-1)),e("button",{onClick:d[0]||(d[0]=p=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Provider ")]),d[3]||(d[3]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-8"}," Manage API providers and authentication keys. All API keys are encrypted at rest. ",-1)),P(Ge,{columns:l,data:s.value,actions:u,loading:i.value,"empty-message":"No providers configured yet. Add your first provider to get started."},null,8,["data","loading"]),P(bb,{modelValue:n.value,"onUpdate:modelValue":d[1]||(d[1]=p=>n.value=p),onSave:c},null,8,["modelValue"])]),_:1}))}}),kb={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function wb(t,n){return a(),o("svg",kb,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4m0-4h.01"})],-1)])])}const _b=Pe({name:"lucide-info",render:wb}),$b={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Cb(t,n){return a(),o("svg",$b,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m21.73 18l-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3M12 9v4m0 4h.01"},null,-1)])])}const Jt=Pe({name:"lucide-triangle-alert",render:Cb}),Tb={class:"mb-6 p-4 border border-black/20 dark:border-white/20 rounded bg-black/5 dark:bg-white/5"},Sb={class:"flex items-start gap-3"},Vb={class:"text-sm"},Mb={class:"font-medium mb-1"},Ib={class:"px-1.5 py-0.5 bg-black/10 dark:bg-white/10 rounded font-mono text-xs"},Eb={id:"functions"},Lb=["onClick"],Ab={key:1,class:"text-left font-medium text-red-600 dark:text-red-400"},Pb={key:2,class:"relative group"},Db={key:3,class:"relative group"},jb={class:"flex justify-end"},Ob=["onClick"],Ub={key:1,class:"text-neutral-400 text-sm"},Rb={id:"prompts",class:"mt-12"},Nb=["onClick"],Fb={class:"text-neutral-600 dark:text-neutral-400"},Bb={class:"text-sm text-neutral-500 dark:text-neutral-400"},qb={id:"agents",class:"mt-12"},zb=["onClick"],Hb={class:"text-neutral-600 dark:text-neutral-400"},Wb={class:"text-sm text-neutral-500 dark:text-neutral-400"},Jb={class:"flex items-center gap-2"},Kb={key:0,class:"space-y-4"},Gb={class:"text-lg font-medium mb-2"},Xb={class:"text-sm text-neutral-600 dark:text-neutral-400 mb-4"},Yb={key:0,class:"h-96 flex items-center justify-center border border-black/20 dark:border-white/20 rounded bg-black/5 dark:bg-white/5"},Zb=pe({__name:"ToolsView",setup(t){const n=m(null),s=m(!1),{data:i}=Ue(de("/api/config")).json(),{data:l,error:u,isFetching:r,execute:c}=Ue(de("/api/tools?type=tools"),{immediate:!1}).json(),{data:f,error:g,isFetching:d,execute:p}=Ue(de("/api/tools?type=prompts&schema=true"),{immediate:!1}).json(),{data:h,error:_,isFetching:b,execute:v}=Ue(de("/api/tools?type=agents&schema=true"),{immediate:!1}).json(),{data:y,error:x,isFetching:k,execute:D}=Ue(()=>n.value?de(`/api/tools/${n.value.name}`):null,{immediate:!1}).json(),q=m([]),B=m([]),N=m([]),T=Ye(),w=async()=>{const O=T.hash;if(O){await Ce();const S=document.getElementById(O.slice(1));S&&S.scrollIntoView({behavior:"smooth"})}};ve(()=>T.hash,w);const K=async O=>{n.value=O,await D(),y.value?n.value={...O,schema:y.value.schema||null}:x.value&&console.error("Error fetching tool schema:",x.value),s.value=!0},te=async O=>{if(n.value=O,s.value=!0,!O.schema&&O.type==="prompt"){const S=await fetch(de("/api/tools?type=prompts&schema=true"));if(S.ok){const C=await S.json();C[O.name]&&(n.value={...O,schema:C[O.name].schema||null})}}},le=[{key:"name",label:"Prompt Name",width:"w-1/3"},{key:"description",label:"Description",width:"w-1/2"},{key:"model",label:"Model",width:"w-1/6"}],H=[{key:"name",label:"Tool Name",width:"w-1/3"},{key:"description",label:"Description",width:"w-1/2"},{key:"actions",label:"Actions",width:"w-1/6"}],A=O=>/^[a-z][a-z0-9_]*[a-z0-9]$/.test(O)||/^[a-z]$/.test(O),$=O=>O.hasError&&O.error?O.error:O.description||"No description available",L=()=>{l.value&&(q.value=Object.entries(l.value).map(([O,S])=>({name:O,description:S.description||"No description available",schema:null,hasError:S.hasError||!1,error:S.error,type:S.type||"tool"})))},J=()=>{f.value&&(B.value=Object.entries(f.value).map(([O,S])=>({name:O,description:S.description||"No description available",schema:S.schema||null,hasError:!1,type:"prompt",model:S.model})))},ee=()=>{h.value&&(N.value=Object.entries(h.value).map(([O,S])=>({name:O,description:S.description||"No description available",schema:S.schema||null,hasError:!1,type:"agent",model:S.model})))},E=async()=>{await c(),L()},R=async()=>{await p(),J()},Y=async()=>{await v(),ee()},ne=()=>{s.value=!1,n.value=null};return Ve(()=>{E(),R(),Y(),w()}),(O,S)=>(a(),se(at,null,{default:ge(()=>[S[11]||(S[11]=e("div",{class:"flex justify-between items-center mb-6"},[e("h1",{class:"text-3xl font-bold"},"Tools")],-1)),S[12]||(S[12]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Tools are the fundamental building blocks of how your business logic is exposed to your agents. Your prompts can expose tools for the agents to call. There are 3 types of tools: functions, prompts, and agents. Functions are actual code in your AgentKit codebase. Prompts are any prompts created in the prompts table (which can themselves expose tools). Agents are multi-turn conversations that can be invoked as tools. ",-1)),e("div",Tb,[e("div",Sb,[P(X(_b),{class:"w-5 h-5 mt-0.5 text-black/60 dark:text-white/60 flex-shrink-0"}),e("div",Vb,[e("p",Mb,[S[1]||(S[1]=$e(" To create or modify tools, edit the ",-1)),e("code",Ib,V(X(i)?.toolsDir||"agentbuilder/tools")+"/",1),S[2]||(S[2]=$e(" directory of your codebase. ",-1))]),S[3]||(S[3]=e("p",{class:"text-black/70 dark:text-white/70"}," Changes will be automatically detected. ",-1))])])]),e("div",Eb,[P(Ge,{columns:H,data:q.value,loading:X(r),"empty-message":`No tools found. Add tool files to the ${X(i)?.toolsDir||"agentbuilder/tools"}/ directory.`},{"cell-name":ge(({row:C})=>[e("div",{class:oe(["flex items-center gap-2",{"text-red-600 dark:text-red-400":C.hasError}])},[C.hasError?(a(),o("span",Ab,V(C.name),1)):(a(),o("button",{key:0,onClick:U=>K(C),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},V(C.name),9,Lb)),C.hasError?(a(),o("div",Pb,[P(X(Jt),{class:"w-4 h-4 text-red-500"}),S[4]||(S[4]=e("div",{class:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 bg-black dark:bg-white text-white dark:text-black text-xs rounded whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10"},[$e(" This tool has validation errors "),e("div",{class:"absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-black dark:border-t-white"})],-1))])):A(C.name)?M("",!0):(a(),o("div",Db,[P(X(Jt),{class:"w-4 h-4 text-amber-500"}),S[5]||(S[5]=e("div",{class:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 bg-black dark:bg-white text-white dark:text-black text-xs rounded whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10"},[$e(" Tool name should be in snake_case format (e.g., 'log_name', 'send_email') "),e("div",{class:"absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-black dark:border-t-white"})],-1))]))],2)]),"cell-description":ge(({row:C})=>[e("span",{class:oe({"text-red-600 dark:text-red-400":C.hasError,"text-neutral-600 dark:text-neutral-400":!C.hasError})},V($(C)),3)]),"cell-actions":ge(({row:C})=>[e("div",jb,[C.hasError?(a(),o("span",Ub,"—")):(a(),o("button",{key:0,onClick:U=>K(C),class:"p-1.5 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",title:"View Schema"},[P(X($t),{class:"w-4 h-4"})],8,Ob))])]),_:1},8,["data","loading","empty-message"])]),e("div",Rb,[S[6]||(S[6]=e("h2",{class:"text-2xl font-bold mb-4"},"Prompts",-1)),S[7]||(S[7]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Prompts that are exposed as tools can be called by other prompts and agents. These allow you to create reusable, composable prompt chains. ",-1)),P(Ge,{columns:le,data:B.value,loading:X(d),"empty-message":"No prompts are currently exposed as tools. Mark a prompt as 'Expose as tool' to see it here."},{"cell-name":ge(({row:C})=>[e("button",{onClick:U=>te(C),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},V(C.name),9,Nb)]),"cell-description":ge(({row:C})=>[e("span",Fb,V(C.description),1)]),"cell-model":ge(({row:C})=>[e("span",Bb,V(C.model||"-"),1)]),_:1},8,["data","loading"])]),e("div",qb,[S[8]||(S[8]=e("h2",{class:"text-2xl font-bold mb-4"},"Agents",-1)),S[9]||(S[9]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Agents that are exposed as tools can be called by other prompts and agents. When an agent is called as a tool, it uses the Side A system prompt's requirements as the tool's input schema. ",-1)),P(Ge,{columns:le,data:N.value,loading:X(b),"empty-message":"No agents are currently exposed as tools. Mark an agent as 'Expose as tool' to see it here."},{"cell-name":ge(({row:C})=>[e("button",{onClick:U=>te(C),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},V(C.name),9,zb)]),"cell-description":ge(({row:C})=>[e("span",Hb,V(C.description),1)]),"cell-model":ge(({row:C})=>[e("span",Wb,V(C.model||"-"),1)]),_:1},8,["data","loading"])]),P(He,{modelValue:s.value,"onUpdate:modelValue":S[0]||(S[0]=C=>s.value=C),onClose:ne,width:"max-w-4xl"},{header:ge(()=>[e("div",Jb,[P(X($t),{class:"w-5 h-5"}),e("span",null,V(n.value?.name)+" Schema",1)])]),footer:ge(()=>[e("button",{onClick:ne,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Close ")]),default:ge(()=>[n.value?(a(),o("div",Kb,[e("div",null,[e("h3",Gb,V(n.value.type==="prompt"?"Required Schema":"JSON Schema"),1),e("p",Xb,V(n.value.type==="prompt"?"This is the JSON schema that defines the input parameters for this prompt.":"This is the automatically generated JSON schema for the tool's arguments."),1)]),n.value.schema===null?(a(),o("div",Yb,[...S[10]||(S[10]=[e("p",{class:"text-neutral-500 dark:text-neutral-400"}," No parameters required ",-1)])])):(a(),se(vt,{key:1,value:n.value.schema,class:"h-96 border border-black/20 dark:border-white/20 rounded"},null,8,["value"]))])):M("",!0)]),_:1},8,["modelValue"])]),_:1}))}}),Qb={class:"flex justify-between items-center mb-6"},e1={class:"flex justify-end gap-2 mt-4"},t1={class:"flex justify-end gap-2 mt-4"},a1=pe({__name:"UsersView",setup(t){const n=m(!1),s=m(!1),i=m([]),l=m(!1),u=m(null),r=m({username:"",password:"",role:"admin"}),c=m({username:"",password:"",role:"admin"}),f=[{value:"admin",label:"Admin"}],g=[{key:"username",label:"Username",width:"w-1/3"},{key:"role",label:"Role",width:"w-1/4"},{key:"created_at",label:"Created",width:"w-1/3",formatter:v=>new Date(v*1e3).toLocaleString()}],d=[{icon:"edit",label:"Edit",handler:async v=>{u.value=v,c.value={username:v.username,password:"",role:v.role},s.value=!0}},{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this user? This action cannot be undone.",handler:async v=>{await b(v.id)}}],p=async()=>{l.value=!0;try{const v=await ze("/users");if(!v.ok)throw new Error("Failed to fetch users");const y=await v.json();i.value=y.users||[]}catch(v){console.error("Error fetching users:",v),i.value=[]}finally{l.value=!1}},h=async()=>{if(!r.value.username||!r.value.password){alert("Username and password are required");return}try{const v=await ze("/users",{method:"POST",body:JSON.stringify(r.value)});if(!v.ok){const y=await v.json();alert(y.error||"Failed to add user");return}await p(),n.value=!1,r.value={username:"",password:"",role:"admin"}}catch(v){console.error("Error adding user:",v),alert("Failed to add user")}},_=async()=>{if(!c.value.username){alert("Username is required");return}try{const v={username:c.value.username,role:c.value.role};c.value.password&&(v.password=c.value.password);const y=await ze(`/users/${u.value.id}`,{method:"PUT",body:JSON.stringify(v)});if(!y.ok){const x=await y.json();alert(x.error||"Failed to update user");return}await p(),s.value=!1,u.value=null}catch(v){console.error("Error updating user:",v),alert("Failed to update user")}},b=async v=>{try{const y=await ze(`/users/${v}`,{method:"DELETE"});if(!y.ok){const x=await y.json();alert(x.error||"Failed to delete user");return}await p()}catch(y){console.error("Error deleting user:",y),alert("Failed to delete user")}};return Ve(()=>{p()}),(v,y)=>(a(),se(at,null,{default:ge(()=>[e("div",Qb,[y[13]||(y[13]=e("div",null,[e("h1",{class:"text-3xl font-bold"},"Users"),e("p",{class:"text-neutral-600 dark:text-neutral-400 mt-2"}," Manage user accounts and permissions ")],-1)),e("button",{onClick:y[0]||(y[0]=x=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Add User ")]),P(Ge,{columns:g,data:i.value,actions:d,loading:l.value,"empty-message":"No users found"},null,8,["data","loading"]),P(He,{modelValue:n.value,"onUpdate:modelValue":y[5]||(y[5]=x=>n.value=x),title:"Add User",onClose:y[6]||(y[6]=x=>n.value=!1)},{default:ge(()=>[e("form",{onSubmit:Ie(h,["prevent"]),class:"space-y-4"},[e("div",null,[y[14]||(y[14]=e("label",{class:"block text-sm font-medium mb-1"},"Username",-1)),Me(e("input",{"onUpdate:modelValue":y[1]||(y[1]=x=>r.value.username=x),type:"text",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.username]])]),e("div",null,[y[15]||(y[15]=e("label",{class:"block text-sm font-medium mb-1"},"Password",-1)),Me(e("input",{"onUpdate:modelValue":y[2]||(y[2]=x=>r.value.password=x),type:"password",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.password]])]),e("div",null,[P(Se,{modelValue:r.value.role,"onUpdate:modelValue":y[3]||(y[3]=x=>r.value.role=x),options:f,label:"Role",placeholder:"Select role"},null,8,["modelValue"])]),e("div",e1,[e("button",{type:"button",onClick:y[4]||(y[4]=x=>n.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),y[16]||(y[16]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Add User ",-1))])],32)]),_:1},8,["modelValue"]),P(He,{modelValue:s.value,"onUpdate:modelValue":y[11]||(y[11]=x=>s.value=x),title:"Edit User",onClose:y[12]||(y[12]=x=>s.value=!1)},{default:ge(()=>[e("form",{onSubmit:Ie(_,["prevent"]),class:"space-y-4"},[e("div",null,[y[17]||(y[17]=e("label",{class:"block text-sm font-medium mb-1"},"Username",-1)),Me(e("input",{"onUpdate:modelValue":y[7]||(y[7]=x=>c.value.username=x),type:"text",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,c.value.username]])]),e("div",null,[y[18]||(y[18]=e("label",{class:"block text-sm font-medium mb-1"},"Password (leave blank to keep current)",-1)),Me(e("input",{"onUpdate:modelValue":y[8]||(y[8]=x=>c.value.password=x),type:"password",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,c.value.password]])]),e("div",null,[P(Se,{modelValue:c.value.role,"onUpdate:modelValue":y[9]||(y[9]=x=>c.value.role=x),options:f,label:"Role",placeholder:"Select role"},null,8,["modelValue"])]),e("div",t1,[e("button",{type:"button",onClick:y[10]||(y[10]=x=>s.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),y[19]||(y[19]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Update User ",-1))])],32)]),_:1},8,["modelValue"])]),_:1}))}}),o1={class:"flex justify-between items-center mb-6"},l1={class:"flex justify-end gap-2 mt-4"},s1={class:"space-y-4"},n1={class:"flex gap-2"},r1=["value"],i1={class:"bg-accent-50 dark:bg-accent-900/30 border border-accent-200 dark:border-accent-800 text-accent-800 dark:text-accent-400 px-4 py-3 rounded"},d1={class:"block mt-2 bg-white dark:bg-neutral-800 px-3 py-2 rounded text-xs"},u1={class:"flex justify-end mt-4"},c1=pe({__name:"ApiKeysView",setup(t){const n=m(!1),s=m(!1),i=m([]),l=m(!1),u=m(""),r=m({name:""}),c=[{key:"name",label:"Name",width:"w-1/3"},{key:"keyPreview",label:"API Key",width:"w-1/3",html:!0,formatter:_=>`<code class="bg-neutral-100 dark:bg-neutral-800 px-2 py-1 rounded text-sm">${_}</code>`},{key:"createdAt",label:"Created",width:"w-1/6",formatter:_=>new Date(_*1e3).toLocaleDateString()},{key:"lastUsedAt",label:"Last Used",width:"w-1/6",formatter:_=>_?new Date(_*1e3).toLocaleDateString():"Never"}],f=[{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this API key? This action cannot be undone.",handler:async _=>{await p(_.id)}}],g=async()=>{l.value=!0;try{const _=await ze("/api-keys");if(!_.ok)throw new Error("Failed to fetch API keys");const b=await _.json();i.value=(b.keys||[]).map(v=>({...v,keyPreview:`${v.key_prefix}...${v.last_five}`,createdAt:v.created_at,lastUsedAt:v.last_used_at}))}catch(_){console.error("Error fetching API keys:",_),i.value=[]}finally{l.value=!1}},d=async()=>{if(!r.value.name){alert("Name is required");return}try{const _=await ze("/api-keys",{method:"POST",body:JSON.stringify(r.value)}),b=await _.json();if(!_.ok){alert(b.error||"Failed to create API key");return}u.value=b.key,n.value=!1,s.value=!0,await g(),r.value={name:""}}catch(_){console.error("Error creating API key:",_),alert("Failed to create API key")}},p=async _=>{try{const b=await ze(`/api-keys/${_}`,{method:"DELETE"});if(!b.ok){const v=await b.json();alert(v.error||"Failed to delete API key");return}await g()}catch(b){console.error("Error deleting API key:",b),alert("Failed to delete API key")}},h=async _=>{try{await navigator.clipboard.writeText(_),alert("API key copied to clipboard!")}catch(b){console.error("Failed to copy:",b)}};return Ve(()=>{g()}),(_,b)=>(a(),se(at,null,{default:ge(()=>[e("div",o1,[b[9]||(b[9]=e("div",null,[e("h1",{class:"text-3xl font-bold"},"API Keys"),e("p",{class:"text-neutral-600 dark:text-neutral-400 mt-2"}," Manage API keys for programmatic access ")],-1)),e("button",{onClick:b[0]||(b[0]=v=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Create API Key ")]),P(Ge,{columns:c,data:i.value,actions:f,loading:l.value,"empty-message":"No API keys found"},null,8,["data","loading"]),P(He,{modelValue:n.value,"onUpdate:modelValue":b[3]||(b[3]=v=>n.value=v),title:"Create API Key",onClose:b[4]||(b[4]=v=>n.value=!1)},{default:ge(()=>[e("form",{onSubmit:Ie(d,["prevent"]),class:"space-y-4"},[e("div",null,[b[10]||(b[10]=e("label",{class:"block text-sm font-medium mb-1"},"Name",-1)),Me(e("input",{"onUpdate:modelValue":b[1]||(b[1]=v=>r.value.name=v),type:"text",required:"",placeholder:"e.g., Production API Key",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.name]]),b[11]||(b[11]=e("p",{class:"text-sm text-neutral-500 dark:text-neutral-400 mt-1"}," A descriptive name to help you identify this key ",-1))]),e("div",l1,[e("button",{type:"button",onClick:b[2]||(b[2]=v=>n.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),b[12]||(b[12]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Create Key ",-1))])],32)]),_:1},8,["modelValue"]),P(He,{modelValue:s.value,"onUpdate:modelValue":b[7]||(b[7]=v=>s.value=v),title:"API Key Created",onClose:b[8]||(b[8]=v=>s.value=!1)},{default:ge(()=>[e("div",s1,[b[15]||(b[15]=e("div",{class:"bg-yellow-50 dark:bg-yellow-900/30 border border-yellow-200 dark:border-yellow-800 text-yellow-800 dark:text-yellow-400 px-4 py-3 rounded"},[e("p",{class:"font-semibold"},"Important: Save this key now!"),e("p",{class:"text-sm mt-1"}," You won't be able to see it again. If you lose this key, you'll need to create a new one. ")],-1)),e("div",null,[b[13]||(b[13]=e("label",{class:"block text-sm font-medium mb-2"},"Your new API key:",-1)),e("div",n1,[e("input",{value:u.value,type:"text",readonly:"",class:"flex-1 px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700 font-mono text-sm"},null,8,r1),e("button",{onClick:b[5]||(b[5]=v=>h(u.value)),class:"px-4 py-2 bg-neutral-200 dark:bg-neutral-700 rounded hover:bg-neutral-300 dark:hover:bg-neutral-600"}," Copy ")])]),e("div",i1,[b[14]||(b[14]=e("p",{class:"text-sm"}," Use this key in the Authorization header of your API requests: ",-1)),e("code",d1," Authorization: Bearer "+V(u.value),1)]),e("div",u1,[e("button",{onClick:b[6]||(b[6]=v=>s.value=!1),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Done ")])])]),_:1},8,["modelValue"])]),_:1}))}}),p1={class:"login-container flex-1 flex items-center justify-center px-4"},v1={class:"max-w-md w-full space-y-8"},m1={class:"flex justify-center"},f1=["src"],h1={class:"bg-white dark:bg-neutral-900 border border-neutral-300 dark:border-neutral-700 py-8 px-6 rounded-lg"},g1={key:0,class:"bg-red-50 dark:bg-red-950 border border-red-500 text-red-700 dark:text-red-400 px-4 py-3"},b1=["disabled"],x1={key:0,class:"mt-6"},y1=pe({__name:"LoginView",setup(t){function n(x){if(x.startsWith("/src/")||x.startsWith("data:"))return x;const k=it();return k==="/"?x.replace("/agents/","/"):x.replace("/agents/",`${k}/`)}const s=n(ha),i=n(ga),l=lt(),u=Ye(),r=m(""),c=m(""),f=m(""),g=m(!1),d=m(!1),p=m(!1),h=m(!1),_=W(()=>h.value?i:s);Ve(async()=>{const x=localStorage.getItem("theme");h.value=x==="dark"||!x&&window.matchMedia("(prefers-color-scheme: dark)").matches;const k=u.query.token,D=u.query.error;if(k){localStorage.setItem("auth_token",k),l.push("/");return}D&&(D==="oauth_failed"?f.value="OAuth authentication failed. Please try again.":D==="oauth_not_configured"&&(f.value="OAuth provider is not configured."));try{const q=await fetch(de("/api/auth/config"));if(q.ok){const B=await q.json();d.value=B.github||!1,p.value=B.google||!1}}catch(q){console.error("Failed to fetch auth config:",q)}});async function b(){f.value="",g.value=!0;try{const x=await fetch(de("/api/auth/login"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r.value,password:c.value})}),k=await x.json();x.ok?(localStorage.setItem("auth_token",k.token),l.push("/")):f.value=k.error||"Login failed"}catch{f.value="Network error. Please try again."}finally{g.value=!1}}function v(){window.location.href=de("/api/auth/oauth/github")}function y(){window.location.href=de("/api/auth/oauth/google")}return(x,k)=>(a(),o("div",p1,[e("div",v1,[e("div",m1,[e("img",{src:_.value,alt:"AgentBuilder",class:"h-16 pointer-events-none select-none"},null,8,f1)]),P(Ze,{offsetX:8,offsetY:8,intensity:.2,pattern:"crosshatch"},{default:ge(()=>[e("div",h1,[e("form",{class:"space-y-6",onSubmit:Ie(b,["prevent"])},[f.value?(a(),o("div",g1,V(f.value),1)):M("",!0),P(Ee,{modelValue:r.value,"onUpdate:modelValue":k[0]||(k[0]=D=>r.value=D),label:"Username",type:"text",disabled:g.value,placeholder:"Enter your username"},null,8,["modelValue","disabled"]),P(Ee,{modelValue:c.value,"onUpdate:modelValue":k[1]||(k[1]=D=>c.value=D),label:"Password",type:"password",disabled:g.value,placeholder:"Enter your password"},null,8,["modelValue","disabled"]),e("div",null,[e("button",{type:"submit",disabled:g.value,class:"w-full px-4 py-2.5 bg-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 rounded-md font-medium hover:bg-neutral-800 dark:hover:bg-neutral-200 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},V(g.value?"Signing in...":"Sign in"),9,b1)])],32),d.value||p.value?(a(),o("div",x1,[k[4]||(k[4]=e("div",{class:"relative"},[e("div",{class:"absolute inset-0 flex items-center"},[e("div",{class:"w-full border-t border-neutral-300 dark:border-neutral-600"})]),e("div",{class:"relative flex justify-center text-sm"},[e("span",{class:"px-2 bg-white dark:bg-neutral-900 text-neutral-500 dark:text-neutral-400"},"Or continue with")])],-1)),e("div",{class:oe(["mt-6 grid gap-3",d.value&&p.value?"grid-cols-2":"grid-cols-1"])},[d.value?(a(),o("button",{key:0,onClick:v,type:"button",class:"w-full inline-flex justify-center items-center px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 rounded-md font-medium hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors"},[...k[2]||(k[2]=[e("svg",{class:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20"},[e("path",{"fill-rule":"evenodd",d:"M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z","clip-rule":"evenodd"})],-1),e("span",{class:"ml-2"},"GitHub",-1)])])):M("",!0),p.value?(a(),o("button",{key:1,onClick:y,type:"button",class:"w-full inline-flex justify-center items-center px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 rounded-md font-medium hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors"},[...k[3]||(k[3]=[e("svg",{class:"h-5 w-5",viewBox:"0 0 24 24"},[e("path",{fill:"currentColor",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e("path",{fill:"currentColor",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e("path",{fill:"currentColor",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e("path",{fill:"currentColor",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})],-1),e("span",{class:"ml-2"},"Google",-1)])])):M("",!0)],2)])):M("",!0)])]),_:1})])]))}}),k1={class:"space-y-1"},w1={key:0,class:"block text-sm font-medium"},_1={key:0,class:"text-red-500"},$1=["value","placeholder","disabled"],C1={key:1,class:"text-xs text-red-500 dark:text-red-400"},yt=pe({__name:"MultilineInput",props:{modelValue:{},label:{},placeholder:{},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","focus","blur"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=m(null),r=W(()=>["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white","transition-colors resize-none overflow-hidden",i.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",i.disabled?"opacity-50 cursor-not-allowed":""]),c=()=>{const p=u.value;p&&(p.style.height="auto",p.style.height=`${p.scrollHeight+2}px`)},f=p=>{const h=p.target;l("update:modelValue",h.value),c()},g=p=>{l("focus",p)},d=p=>{l("blur",p)};return Ve(()=>{c()}),ve(()=>i.modelValue,async()=>{await Ce(),c()}),n({textareaRef:u,adjustHeight:c}),(p,h)=>(a(),o("div",k1,[t.label?(a(),o("label",w1,[$e(V(t.label)+" ",1),t.required?(a(),o("span",_1,"*")):M("",!0)])):M("",!0),e("textarea",{ref_key:"textareaRef",ref:u,value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,class:oe(r.value),rows:"1",onInput:f,onFocus:g,onBlur:d},null,42,$1),t.error?(a(),o("p",C1,V(t.error),1)):M("",!0)]))}}),T1={class:"p-8 space-y-6"},S1={class:"mt-12"},V1={class:"mb-6"},M1={class:"mb-6"},I1={class:"mb-6"},E1={class:"mt-8"},L1={class:"border-2 border-red-500 p-4 h-32 overflow-hidden relative"},A1={class:"mt-12"},P1={class:"mb-6"},D1={class:"border-2 border-accent-500 p-4 h-32 overflow-hidden relative"},j1={class:"mt-12"},O1={class:"mb-6"},U1={class:"mb-6"},R1={class:"mt-12"},N1={class:"mb-6"},F1={class:"mt-2 text-sm"},B1={class:"mb-6"},q1={class:"mt-2 text-sm"},z1={class:"mb-6"},H1={class:"mb-6"},W1={class:"mt-12"},J1={class:"mb-6"},K1={class:"mt-4 p-4 bg-neutral-100 dark:bg-neutral-900 rounded"},G1={class:"text-xs overflow-x-auto"},X1=pe({__name:"TestView",setup(t){const n=m(""),s=m(""),i=m(""),l=m(`Line 1
23
+ This provider has ${p.modelCount} associated model(s).`):alert(p.error||"Failed to delete provider");return}await r()}catch(d){console.error("Error deleting provider:",d),alert("Failed to delete provider")}};return Me(()=>{r()}),(g,d)=>(a(),ne(at,null,{default:be(()=>[e("div",Sb,[d[2]||(d[2]=e("h1",{class:"text-3xl font-bold"},"Providers",-1)),e("button",{onClick:d[0]||(d[0]=p=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Add Provider ")]),d[3]||(d[3]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-8"}," Manage API providers and authentication keys. All API keys are encrypted at rest. ",-1)),A(Ge,{columns:l,data:s.value,actions:u,loading:i.value,"empty-message":"No providers configured yet. Add your first provider to get started."},null,8,["data","loading"]),A(Tb,{modelValue:n.value,"onUpdate:modelValue":d[1]||(d[1]=p=>n.value=p),onSave:c},null,8,["modelValue"])]),_:1}))}}),Mb={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ib(t,n){return a(),o("svg",Mb,[...n[0]||(n[0]=[e("g",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4m0-4h.01"})],-1)])])}const Eb=De({name:"lucide-info",render:Ib}),Lb={viewBox:"0 0 24 24",width:"1.2em",height:"1.2em"};function Ab(t,n){return a(),o("svg",Lb,[...n[0]||(n[0]=[e("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"m21.73 18l-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3M12 9v4m0 4h.01"},null,-1)])])}const Jt=De({name:"lucide-triangle-alert",render:Ab}),Pb={class:"mb-6 p-4 border border-black/20 dark:border-white/20 rounded bg-black/5 dark:bg-white/5"},Db={class:"flex items-start gap-3"},jb={class:"text-sm"},Ob={class:"font-medium mb-1"},Ub={class:"px-1.5 py-0.5 bg-black/10 dark:bg-white/10 rounded font-mono text-xs"},Rb={id:"functions"},Nb=["onClick"],Fb={key:1,class:"text-left font-medium text-red-600 dark:text-red-400"},Bb={key:2,class:"relative group"},qb={key:3,class:"relative group"},zb={class:"flex justify-end"},Hb=["onClick"],Wb={key:1,class:"text-neutral-400 text-sm"},Jb={id:"prompts",class:"mt-12"},Kb=["onClick"],Gb={class:"text-neutral-600 dark:text-neutral-400"},Xb={class:"text-sm text-neutral-500 dark:text-neutral-400"},Yb={id:"agents",class:"mt-12"},Qb=["onClick"],Zb={class:"text-neutral-600 dark:text-neutral-400"},e1={class:"text-sm text-neutral-500 dark:text-neutral-400"},t1={class:"flex items-center gap-2"},a1={key:0,class:"space-y-4"},o1={class:"text-lg font-medium mb-2"},l1={class:"text-sm text-neutral-600 dark:text-neutral-400 mb-4"},s1={key:0,class:"h-96 flex items-center justify-center border border-black/20 dark:border-white/20 rounded bg-black/5 dark:bg-white/5"},n1=me({__name:"ToolsView",setup(t){const n=v(null),s=v(!1),{data:i}=Ue(ue("/api/config")).json(),{data:l,error:u,isFetching:r,execute:c}=Ue(ue("/api/tools?type=tools"),{immediate:!1}).json(),{data:f,error:g,isFetching:d,execute:p}=Ue(ue("/api/tools?type=prompts&schema=true"),{immediate:!1}).json(),{data:h,error:_,isFetching:b,execute:m}=Ue(ue("/api/tools?type=agents&schema=true"),{immediate:!1}).json(),{data:y,error:x,isFetching:k,execute:D}=Ue(()=>n.value?ue(`/api/tools/${n.value.name}`):null,{immediate:!1}).json(),q=v([]),B=v([]),F=v([]),T=Ye(),$=async()=>{const j=T.hash;if(j){await Te();const M=document.getElementById(j.slice(1));M&&M.scrollIntoView({behavior:"smooth"})}};fe(()=>T.hash,$);const K=async j=>{n.value=j,await D(),y.value?n.value={...j,schema:y.value.schema||null}:x.value&&console.error("Error fetching tool schema:",x.value),s.value=!0},oe=async j=>{if(n.value=j,s.value=!0,!j.schema&&j.type==="prompt"){const M=await fetch(ue("/api/tools?type=prompts&schema=true"));if(M.ok){const w=await M.json();w[j.name]&&(n.value={...j,schema:w[j.name].schema||null})}}},te=[{key:"name",label:"Prompt Name",width:"w-1/3"},{key:"description",label:"Description",width:"w-1/2"},{key:"model",label:"Model",width:"w-1/6"}],H=[{key:"name",label:"Tool Name",width:"w-1/3"},{key:"description",label:"Description",width:"w-1/2"},{key:"actions",label:"Actions",width:"w-1/6"}],P=j=>/^[a-z][a-z0-9_]*[a-z0-9]$/.test(j)||/^[a-z]$/.test(j),C=j=>j.hasError&&j.error?j.error:j.description||"No description available",L=()=>{l.value&&(q.value=Object.entries(l.value).map(([j,M])=>({name:j,description:M.description||"No description available",schema:null,hasError:M.hasError||!1,error:M.error,type:M.type||"tool"})))},G=()=>{f.value&&(B.value=Object.entries(f.value).map(([j,M])=>({name:j,description:M.description||"No description available",schema:M.schema||null,hasError:!1,type:"prompt",model:M.model})))},ee=()=>{h.value&&(F.value=Object.entries(h.value).map(([j,M])=>({name:j,description:M.description||"No description available",schema:M.schema||null,hasError:!1,type:"agent",model:M.model})))},E=async()=>{await c(),L()},U=async()=>{await p(),G()},Z=async()=>{await m(),ee()},se=()=>{s.value=!1,n.value=null};return Me(()=>{E(),U(),Z(),$()}),(j,M)=>(a(),ne(at,null,{default:be(()=>[M[11]||(M[11]=e("div",{class:"flex justify-between items-center mb-6"},[e("h1",{class:"text-3xl font-bold"},"Tools")],-1)),M[12]||(M[12]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Tools are the fundamental building blocks of how your business logic is exposed to your agents. Your prompts can expose tools for the agents to call. There are 3 types of tools: functions, prompts, and agents. Functions are actual code in your AgentKit codebase. Prompts are any prompts created in the prompts table (which can themselves expose tools). Agents are multi-turn conversations that can be invoked as tools. ",-1)),e("div",Pb,[e("div",Db,[A(X(Eb),{class:"w-5 h-5 mt-0.5 text-black/60 dark:text-white/60 flex-shrink-0"}),e("div",jb,[e("p",Ob,[M[1]||(M[1]=Ce(" To create or modify tools, edit the ",-1)),e("code",Ub,S(X(i)?.toolsDir||"agentbuilder/tools")+"/",1),M[2]||(M[2]=Ce(" directory of your codebase. ",-1))]),M[3]||(M[3]=e("p",{class:"text-black/70 dark:text-white/70"}," Changes will be automatically detected. ",-1))])])]),e("div",Rb,[A(Ge,{columns:H,data:q.value,loading:X(r),"empty-message":`No tools found. Add tool files to the ${X(i)?.toolsDir||"agentbuilder/tools"}/ directory.`},{"cell-name":be(({row:w})=>[e("div",{class:ae(["flex items-center gap-2",{"text-red-600 dark:text-red-400":w.hasError}])},[w.hasError?(a(),o("span",Fb,S(w.name),1)):(a(),o("button",{key:0,onClick:R=>K(w),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},S(w.name),9,Nb)),w.hasError?(a(),o("div",Bb,[A(X(Jt),{class:"w-4 h-4 text-red-500"}),M[4]||(M[4]=e("div",{class:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 bg-black dark:bg-white text-white dark:text-black text-xs rounded whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10"},[Ce(" This tool has validation errors "),e("div",{class:"absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-black dark:border-t-white"})],-1))])):P(w.name)?V("",!0):(a(),o("div",qb,[A(X(Jt),{class:"w-4 h-4 text-amber-500"}),M[5]||(M[5]=e("div",{class:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 bg-black dark:bg-white text-white dark:text-black text-xs rounded whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10"},[Ce(" Tool name should be in snake_case format (e.g., 'log_name', 'send_email') "),e("div",{class:"absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-black dark:border-t-white"})],-1))]))],2)]),"cell-description":be(({row:w})=>[e("span",{class:ae({"text-red-600 dark:text-red-400":w.hasError,"text-neutral-600 dark:text-neutral-400":!w.hasError})},S(C(w)),3)]),"cell-actions":be(({row:w})=>[e("div",zb,[w.hasError?(a(),o("span",Wb,"—")):(a(),o("button",{key:0,onClick:R=>K(w),class:"p-1.5 rounded hover:bg-black/10 dark:hover:bg-white/10 transition-colors",title:"View Schema"},[A(X($t),{class:"w-4 h-4"})],8,Hb))])]),_:1},8,["data","loading","empty-message"])]),e("div",Jb,[M[6]||(M[6]=e("h2",{class:"text-2xl font-bold mb-4"},"Prompts",-1)),M[7]||(M[7]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Prompts that are exposed as tools can be called by other prompts and agents. These allow you to create reusable, composable prompt chains. ",-1)),A(Ge,{columns:te,data:B.value,loading:X(d),"empty-message":"No prompts are currently exposed as tools. Mark a prompt as 'Expose as tool' to see it here."},{"cell-name":be(({row:w})=>[e("button",{onClick:R=>oe(w),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},S(w.name),9,Kb)]),"cell-description":be(({row:w})=>[e("span",Gb,S(w.description),1)]),"cell-model":be(({row:w})=>[e("span",Xb,S(w.model||"-"),1)]),_:1},8,["data","loading"])]),e("div",Yb,[M[8]||(M[8]=e("h2",{class:"text-2xl font-bold mb-4"},"Agents",-1)),M[9]||(M[9]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-6"}," Agents that are exposed as tools can be called by other prompts and agents. When an agent is called as a tool, it uses the Side A system prompt's requirements as the tool's input schema. ",-1)),A(Ge,{columns:te,data:F.value,loading:X(b),"empty-message":"No agents are currently exposed as tools. Mark an agent as 'Expose as tool' to see it here."},{"cell-name":be(({row:w})=>[e("button",{onClick:R=>oe(w),class:"text-left font-medium hover:text-black/70 dark:hover:text-white/70 transition-colors underline decoration-transparent hover:decoration-current"},S(w.name),9,Qb)]),"cell-description":be(({row:w})=>[e("span",Zb,S(w.description),1)]),"cell-model":be(({row:w})=>[e("span",e1,S(w.model||"-"),1)]),_:1},8,["data","loading"])]),A(He,{modelValue:s.value,"onUpdate:modelValue":M[0]||(M[0]=w=>s.value=w),onClose:se,width:"max-w-4xl"},{header:be(()=>[e("div",t1,[A(X($t),{class:"w-5 h-5"}),e("span",null,S(n.value?.name)+" Schema",1)])]),footer:be(()=>[e("button",{onClick:se,class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded font-medium hover:opacity-90 transition-opacity"}," Close ")]),default:be(()=>[n.value?(a(),o("div",a1,[e("div",null,[e("h3",o1,S(n.value.type==="prompt"?"Required Schema":"JSON Schema"),1),e("p",l1,S(n.value.type==="prompt"?"This is the JSON schema that defines the input parameters for this prompt.":"This is the automatically generated JSON schema for the tool's arguments."),1)]),n.value.schema===null?(a(),o("div",s1,[...M[10]||(M[10]=[e("p",{class:"text-neutral-500 dark:text-neutral-400"}," No parameters required ",-1)])])):(a(),ne(vt,{key:1,value:n.value.schema,class:"h-96 border border-black/20 dark:border-white/20 rounded"},null,8,["value"]))])):V("",!0)]),_:1},8,["modelValue"])]),_:1}))}}),r1={class:"flex justify-between items-center mb-6"},i1={class:"flex justify-end gap-2 mt-4"},d1={class:"flex justify-end gap-2 mt-4"},u1=me({__name:"UsersView",setup(t){const n=v(!1),s=v(!1),i=v([]),l=v(!1),u=v(null),r=v({username:"",password:"",role:"admin"}),c=v({username:"",password:"",role:"admin"}),f=[{value:"admin",label:"Admin"}],g=[{key:"username",label:"Username",width:"w-1/3"},{key:"role",label:"Role",width:"w-1/4"},{key:"created_at",label:"Created",width:"w-1/3",formatter:m=>new Date(m*1e3).toLocaleString()}],d=[{icon:"edit",label:"Edit",handler:async m=>{u.value=m,c.value={username:m.username,password:"",role:m.role},s.value=!0}},{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this user? This action cannot be undone.",handler:async m=>{await b(m.id)}}],p=async()=>{l.value=!0;try{const m=await ze("/users");if(!m.ok)throw new Error("Failed to fetch users");const y=await m.json();i.value=y.users||[]}catch(m){console.error("Error fetching users:",m),i.value=[]}finally{l.value=!1}},h=async()=>{if(!r.value.username||!r.value.password){alert("Username and password are required");return}try{const m=await ze("/users",{method:"POST",body:JSON.stringify(r.value)});if(!m.ok){const y=await m.json();alert(y.error||"Failed to add user");return}await p(),n.value=!1,r.value={username:"",password:"",role:"admin"}}catch(m){console.error("Error adding user:",m),alert("Failed to add user")}},_=async()=>{if(!c.value.username){alert("Username is required");return}try{const m={username:c.value.username,role:c.value.role};c.value.password&&(m.password=c.value.password);const y=await ze(`/users/${u.value.id}`,{method:"PUT",body:JSON.stringify(m)});if(!y.ok){const x=await y.json();alert(x.error||"Failed to update user");return}await p(),s.value=!1,u.value=null}catch(m){console.error("Error updating user:",m),alert("Failed to update user")}},b=async m=>{try{const y=await ze(`/users/${m}`,{method:"DELETE"});if(!y.ok){const x=await y.json();alert(x.error||"Failed to delete user");return}await p()}catch(y){console.error("Error deleting user:",y),alert("Failed to delete user")}};return Me(()=>{p()}),(m,y)=>(a(),ne(at,null,{default:be(()=>[e("div",r1,[y[13]||(y[13]=e("div",null,[e("h1",{class:"text-3xl font-bold"},"Users"),e("p",{class:"text-neutral-600 dark:text-neutral-400 mt-2"}," Manage user accounts and permissions ")],-1)),e("button",{onClick:y[0]||(y[0]=x=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Add User ")]),A(Ge,{columns:g,data:i.value,actions:d,loading:l.value,"empty-message":"No users found"},null,8,["data","loading"]),A(He,{modelValue:n.value,"onUpdate:modelValue":y[5]||(y[5]=x=>n.value=x),title:"Add User",onClose:y[6]||(y[6]=x=>n.value=!1)},{default:be(()=>[e("form",{onSubmit:Ee(h,["prevent"]),class:"space-y-4"},[e("div",null,[y[14]||(y[14]=e("label",{class:"block text-sm font-medium mb-1"},"Username",-1)),Ie(e("input",{"onUpdate:modelValue":y[1]||(y[1]=x=>r.value.username=x),type:"text",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.username]])]),e("div",null,[y[15]||(y[15]=e("label",{class:"block text-sm font-medium mb-1"},"Password",-1)),Ie(e("input",{"onUpdate:modelValue":y[2]||(y[2]=x=>r.value.password=x),type:"password",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.password]])]),e("div",null,[A(Ve,{modelValue:r.value.role,"onUpdate:modelValue":y[3]||(y[3]=x=>r.value.role=x),options:f,label:"Role",placeholder:"Select role"},null,8,["modelValue"])]),e("div",i1,[e("button",{type:"button",onClick:y[4]||(y[4]=x=>n.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),y[16]||(y[16]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Add User ",-1))])],32)]),_:1},8,["modelValue"]),A(He,{modelValue:s.value,"onUpdate:modelValue":y[11]||(y[11]=x=>s.value=x),title:"Edit User",onClose:y[12]||(y[12]=x=>s.value=!1)},{default:be(()=>[e("form",{onSubmit:Ee(_,["prevent"]),class:"space-y-4"},[e("div",null,[y[17]||(y[17]=e("label",{class:"block text-sm font-medium mb-1"},"Username",-1)),Ie(e("input",{"onUpdate:modelValue":y[7]||(y[7]=x=>c.value.username=x),type:"text",required:"",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,c.value.username]])]),e("div",null,[y[18]||(y[18]=e("label",{class:"block text-sm font-medium mb-1"},"Password (leave blank to keep current)",-1)),Ie(e("input",{"onUpdate:modelValue":y[8]||(y[8]=x=>c.value.password=x),type:"password",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,c.value.password]])]),e("div",null,[A(Ve,{modelValue:c.value.role,"onUpdate:modelValue":y[9]||(y[9]=x=>c.value.role=x),options:f,label:"Role",placeholder:"Select role"},null,8,["modelValue"])]),e("div",d1,[e("button",{type:"button",onClick:y[10]||(y[10]=x=>s.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),y[19]||(y[19]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Update User ",-1))])],32)]),_:1},8,["modelValue"])]),_:1}))}}),c1={class:"flex justify-between items-center mb-6"},p1={class:"flex justify-end gap-2 mt-4"},m1={class:"space-y-4"},v1={class:"flex gap-2"},f1=["value"],h1={class:"bg-accent-50 dark:bg-accent-900/30 border border-accent-200 dark:border-accent-800 text-accent-800 dark:text-accent-400 px-4 py-3 rounded"},g1={class:"block mt-2 bg-white dark:bg-neutral-800 px-3 py-2 rounded text-xs"},b1={class:"flex justify-end mt-4"},x1=me({__name:"ApiKeysView",setup(t){const n=v(!1),s=v(!1),i=v([]),l=v(!1),u=v(""),r=v({name:""}),c=[{key:"name",label:"Name",width:"w-1/3"},{key:"keyPreview",label:"API Key",width:"w-1/3",html:!0,formatter:_=>`<code class="bg-neutral-100 dark:bg-neutral-800 px-2 py-1 rounded text-sm">${_}</code>`},{key:"createdAt",label:"Created",width:"w-1/6",formatter:_=>new Date(_*1e3).toLocaleDateString()},{key:"lastUsedAt",label:"Last Used",width:"w-1/6",formatter:_=>_?new Date(_*1e3).toLocaleDateString():"Never"}],f=[{icon:"delete",label:"Delete",confirm:!0,confirmMessage:"Are you sure you want to delete this API key? This action cannot be undone.",handler:async _=>{await p(_.id)}}],g=async()=>{l.value=!0;try{const _=await ze("/api-keys");if(!_.ok)throw new Error("Failed to fetch API keys");const b=await _.json();i.value=(b.keys||[]).map(m=>({...m,keyPreview:`${m.key_prefix}...${m.last_five}`,createdAt:m.created_at,lastUsedAt:m.last_used_at}))}catch(_){console.error("Error fetching API keys:",_),i.value=[]}finally{l.value=!1}},d=async()=>{if(!r.value.name){alert("Name is required");return}try{const _=await ze("/api-keys",{method:"POST",body:JSON.stringify(r.value)}),b=await _.json();if(!_.ok){alert(b.error||"Failed to create API key");return}u.value=b.key,n.value=!1,s.value=!0,await g(),r.value={name:""}}catch(_){console.error("Error creating API key:",_),alert("Failed to create API key")}},p=async _=>{try{const b=await ze(`/api-keys/${_}`,{method:"DELETE"});if(!b.ok){const m=await b.json();alert(m.error||"Failed to delete API key");return}await g()}catch(b){console.error("Error deleting API key:",b),alert("Failed to delete API key")}},h=async _=>{try{await navigator.clipboard.writeText(_),alert("API key copied to clipboard!")}catch(b){console.error("Failed to copy:",b)}};return Me(()=>{g()}),(_,b)=>(a(),ne(at,null,{default:be(()=>[e("div",c1,[b[9]||(b[9]=e("div",null,[e("h1",{class:"text-3xl font-bold"},"API Keys"),e("p",{class:"text-neutral-600 dark:text-neutral-400 mt-2"}," Manage API keys for programmatic access ")],-1)),e("button",{onClick:b[0]||(b[0]=m=>n.value=!0),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Create API Key ")]),A(Ge,{columns:c,data:i.value,actions:f,loading:l.value,"empty-message":"No API keys found"},null,8,["data","loading"]),A(He,{modelValue:n.value,"onUpdate:modelValue":b[3]||(b[3]=m=>n.value=m),title:"Create API Key",onClose:b[4]||(b[4]=m=>n.value=!1)},{default:be(()=>[e("form",{onSubmit:Ee(d,["prevent"]),class:"space-y-4"},[e("div",null,[b[10]||(b[10]=e("label",{class:"block text-sm font-medium mb-1"},"Name",-1)),Ie(e("input",{"onUpdate:modelValue":b[1]||(b[1]=m=>r.value.name=m),type:"text",required:"",placeholder:"e.g., Production API Key",class:"w-full px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700"},null,512),[[Oe,r.value.name]]),b[11]||(b[11]=e("p",{class:"text-sm text-neutral-500 dark:text-neutral-400 mt-1"}," A descriptive name to help you identify this key ",-1))]),e("div",p1,[e("button",{type:"button",onClick:b[2]||(b[2]=m=>n.value=!1),class:"px-4 py-2 border border-neutral-300 dark:border-neutral-600 rounded hover:bg-neutral-50 dark:hover:bg-neutral-700"}," Cancel "),b[12]||(b[12]=e("button",{type:"submit",class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Create Key ",-1))])],32)]),_:1},8,["modelValue"]),A(He,{modelValue:s.value,"onUpdate:modelValue":b[7]||(b[7]=m=>s.value=m),title:"API Key Created",onClose:b[8]||(b[8]=m=>s.value=!1)},{default:be(()=>[e("div",m1,[b[15]||(b[15]=e("div",{class:"bg-yellow-50 dark:bg-yellow-900/30 border border-yellow-200 dark:border-yellow-800 text-yellow-800 dark:text-yellow-400 px-4 py-3 rounded"},[e("p",{class:"font-semibold"},"Important: Save this key now!"),e("p",{class:"text-sm mt-1"}," You won't be able to see it again. If you lose this key, you'll need to create a new one. ")],-1)),e("div",null,[b[13]||(b[13]=e("label",{class:"block text-sm font-medium mb-2"},"Your new API key:",-1)),e("div",v1,[e("input",{value:u.value,type:"text",readonly:"",class:"flex-1 px-3 py-2 border border-neutral-300 dark:border-neutral-600 rounded-md dark:bg-neutral-700 font-mono text-sm"},null,8,f1),e("button",{onClick:b[5]||(b[5]=m=>h(u.value)),class:"px-4 py-2 bg-neutral-200 dark:bg-neutral-700 rounded hover:bg-neutral-300 dark:hover:bg-neutral-600"}," Copy ")])]),e("div",h1,[b[14]||(b[14]=e("p",{class:"text-sm"}," Use this key in the Authorization header of your API requests: ",-1)),e("code",g1," Authorization: Bearer "+S(u.value),1)]),e("div",b1,[e("button",{onClick:b[6]||(b[6]=m=>s.value=!1),class:"px-4 py-2 bg-black text-white dark:bg-white dark:text-black rounded hover:bg-black/80 dark:hover:bg-white/80 font-medium"}," Done ")])])]),_:1},8,["modelValue"])]),_:1}))}}),y1={class:"login-container flex-1 flex items-center justify-center px-4"},k1={class:"max-w-md w-full space-y-8"},w1={class:"flex justify-center"},_1=["src"],$1={class:"bg-white dark:bg-neutral-900 border border-neutral-300 dark:border-neutral-700 py-8 px-6 rounded-lg"},C1={key:0,class:"bg-red-50 dark:bg-red-950 border border-red-500 text-red-700 dark:text-red-400 px-4 py-3"},T1=["disabled"],S1={key:0,class:"mt-6"},V1=me({__name:"LoginView",setup(t){function n(x){if(x.startsWith("/src/")||x.startsWith("data:"))return x;const k=dt();return k==="/"?x.replace("/agents/","/"):x.replace("/agents/",`${k}/`)}const s=n(ha),i=n(ga),l=lt(),u=Ye(),r=v(""),c=v(""),f=v(""),g=v(!1),d=v(!1),p=v(!1),h=v(!1),_=J(()=>h.value?i:s);Me(async()=>{const x=localStorage.getItem("theme");h.value=x==="dark"||!x&&window.matchMedia("(prefers-color-scheme: dark)").matches;const k=u.query.token,D=u.query.error;if(k){localStorage.setItem("auth_token",k),l.push("/");return}D&&(D==="oauth_failed"?f.value="OAuth authentication failed. Please try again.":D==="oauth_not_configured"&&(f.value="OAuth provider is not configured."));try{const q=await fetch(ue("/api/auth/config"));if(q.ok){const B=await q.json();d.value=B.github||!1,p.value=B.google||!1}}catch(q){console.error("Failed to fetch auth config:",q)}});async function b(){f.value="",g.value=!0;try{const x=await fetch(ue("/api/auth/login"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r.value,password:c.value})}),k=await x.json();x.ok?(localStorage.setItem("auth_token",k.token),l.push("/")):f.value=k.error||"Login failed"}catch{f.value="Network error. Please try again."}finally{g.value=!1}}function m(){window.location.href=ue("/api/auth/oauth/github")}function y(){window.location.href=ue("/api/auth/oauth/google")}return(x,k)=>(a(),o("div",y1,[e("div",k1,[e("div",w1,[e("img",{src:_.value,alt:"AgentBuilder",class:"h-16 pointer-events-none select-none"},null,8,_1)]),A(Qe,{offsetX:8,offsetY:8,intensity:.2,pattern:"crosshatch"},{default:be(()=>[e("div",$1,[e("form",{class:"space-y-6",onSubmit:Ee(b,["prevent"])},[f.value?(a(),o("div",C1,S(f.value),1)):V("",!0),A(Le,{modelValue:r.value,"onUpdate:modelValue":k[0]||(k[0]=D=>r.value=D),label:"Username",type:"text",disabled:g.value,placeholder:"Enter your username"},null,8,["modelValue","disabled"]),A(Le,{modelValue:c.value,"onUpdate:modelValue":k[1]||(k[1]=D=>c.value=D),label:"Password",type:"password",disabled:g.value,placeholder:"Enter your password"},null,8,["modelValue","disabled"]),e("div",null,[e("button",{type:"submit",disabled:g.value,class:"w-full px-4 py-2.5 bg-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 rounded-md font-medium hover:bg-neutral-800 dark:hover:bg-neutral-200 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"},S(g.value?"Signing in...":"Sign in"),9,T1)])],32),d.value||p.value?(a(),o("div",S1,[k[4]||(k[4]=e("div",{class:"relative"},[e("div",{class:"absolute inset-0 flex items-center"},[e("div",{class:"w-full border-t border-neutral-300 dark:border-neutral-600"})]),e("div",{class:"relative flex justify-center text-sm"},[e("span",{class:"px-2 bg-white dark:bg-neutral-900 text-neutral-500 dark:text-neutral-400"},"Or continue with")])],-1)),e("div",{class:ae(["mt-6 grid gap-3",d.value&&p.value?"grid-cols-2":"grid-cols-1"])},[d.value?(a(),o("button",{key:0,onClick:m,type:"button",class:"w-full inline-flex justify-center items-center px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 rounded-md font-medium hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors"},[...k[2]||(k[2]=[e("svg",{class:"h-5 w-5",fill:"currentColor",viewBox:"0 0 20 20"},[e("path",{"fill-rule":"evenodd",d:"M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z","clip-rule":"evenodd"})],-1),e("span",{class:"ml-2"},"GitHub",-1)])])):V("",!0),p.value?(a(),o("button",{key:1,onClick:y,type:"button",class:"w-full inline-flex justify-center items-center px-4 py-2.5 border border-neutral-300 dark:border-neutral-600 bg-white dark:bg-neutral-800 text-neutral-700 dark:text-neutral-200 rounded-md font-medium hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors"},[...k[3]||(k[3]=[e("svg",{class:"h-5 w-5",viewBox:"0 0 24 24"},[e("path",{fill:"currentColor",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e("path",{fill:"currentColor",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e("path",{fill:"currentColor",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e("path",{fill:"currentColor",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})],-1),e("span",{class:"ml-2"},"Google",-1)])])):V("",!0)],2)])):V("",!0)])]),_:1})])]))}}),M1={class:"space-y-1"},I1={key:0,class:"block text-sm font-medium"},E1={key:0,class:"text-red-500"},L1=["value","placeholder","disabled"],A1={key:1,class:"text-xs text-red-500 dark:text-red-400"},yt=me({__name:"MultilineInput",props:{modelValue:{},label:{},placeholder:{},error:{},required:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1}},emits:["update:modelValue","focus","blur"],setup(t,{expose:n,emit:s}){const i=t,l=s,u=v(null),r=J(()=>["w-full px-3 py-2 bg-white dark:bg-black border rounded font-mono text-sm","focus:outline-none focus:ring-2 focus:ring-black dark:focus:ring-white","transition-colors resize-none overflow-hidden",i.error?"border-red-500 dark:border-red-400":"border-black dark:border-neutral-300",i.disabled?"opacity-50 cursor-not-allowed":""]),c=()=>{const p=u.value;p&&(p.style.height="auto",p.style.height=`${p.scrollHeight+2}px`)},f=p=>{const h=p.target;l("update:modelValue",h.value),c()},g=p=>{l("focus",p)},d=p=>{l("blur",p)};return Me(()=>{c()}),fe(()=>i.modelValue,async()=>{await Te(),c()}),n({textareaRef:u,adjustHeight:c}),(p,h)=>(a(),o("div",M1,[t.label?(a(),o("label",I1,[Ce(S(t.label)+" ",1),t.required?(a(),o("span",E1,"*")):V("",!0)])):V("",!0),e("textarea",{ref_key:"textareaRef",ref:u,value:t.modelValue,placeholder:t.placeholder,disabled:t.disabled,class:ae(r.value),rows:"1",onInput:f,onFocus:g,onBlur:d},null,42,L1),t.error?(a(),o("p",A1,S(t.error),1)):V("",!0)]))}}),P1={class:"p-8 space-y-6"},D1={class:"mt-12"},j1={class:"mb-6"},O1={class:"mb-6"},U1={class:"mb-6"},R1={class:"mt-8"},N1={class:"border-2 border-red-500 p-4 h-32 overflow-hidden relative"},F1={class:"mt-12"},B1={class:"mb-6"},q1={class:"border-2 border-accent-500 p-4 h-32 overflow-hidden relative"},z1={class:"mt-12"},H1={class:"mb-6"},W1={class:"mb-6"},J1={class:"mt-12"},K1={class:"mb-6"},G1={class:"mt-2 text-sm"},X1={class:"mb-6"},Y1={class:"mt-2 text-sm"},Q1={class:"mb-6"},Z1={class:"mb-6"},ex={class:"mt-12"},tx={class:"mb-6"},ax={class:"mt-4 p-4 bg-neutral-100 dark:bg-neutral-900 rounded"},ox={class:"text-xs overflow-x-auto"},lx=me({__name:"TestView",setup(t){const n=v(""),s=v(""),i=v(""),l=v(`Line 1
24
24
  Line 2
25
- Line 3`),u=m(""),r=m(""),c=m("option2"),f=m(""),g=m(""),d=m(""),p=m([]),h=m(["test1","test2"]),_=m(!1),b=m(!0),v=m(!1),y=m(!1),x=m({type:"object",properties:{},required:[]}),k=m(0);Ve(()=>{window.resetJSONSchema=()=>{x.value={type:"object",properties:{},required:[]},k.value++}});const D=[{value:"option1",label:"Option One"},{value:"option2",label:"Option Two"},{value:"option3",label:"Option Three"},{value:"option4",label:"Option Four"}],q=[{value:"item1",label:"Item One",description:"First item description"},{value:"item2",label:"Item Two",description:"Second item description"},{value:"item3",label:"Item Three",description:"Third item description"},{value:"item4",label:"Item Four",description:"Fourth item description"}],B=[{value:"test1",label:"Test Item 1",description:"First test item"},{value:"test2",label:"Test Item 2",description:"Second test item"},{value:"test3",label:"Test Item 3",description:"Third test item"},{value:"test4",label:"Test Item 4",description:"Fourth test item"},{value:"test5",label:"Test Item 5",description:"Fifth test item"}];return(N,T)=>(a(),o("div",T1,[T[30]||(T[30]=e("h1",{class:"text-2xl font-bold"},"Component Test Page",-1)),e("div",null,[P(Ee,{modelValue:n.value,"onUpdate:modelValue":T[0]||(T[0]=w=>n.value=w),label:"Test Label",placeholder:"Enter text..."},null,8,["modelValue"]),e("p",null,V(n.value),1)]),e("div",null,[P(Ee,{modelValue:s.value,"onUpdate:modelValue":T[1]||(T[1]=w=>s.value=w),label:"Email",error:"Invalid email address",required:""},null,8,["modelValue"])]),e("div",S1,[T[18]||(T[18]=e("h2",{class:"text-xl font-bold mb-4"},"MultilineInput Tests",-1)),e("div",V1,[P(yt,{modelValue:i.value,"onUpdate:modelValue":T[2]||(T[2]=w=>i.value=w),label:"Multiline Text",placeholder:"Type multiple lines..."},null,8,["modelValue"]),e("p",null,V(i.value),1)]),e("div",M1,[P(yt,{modelValue:l.value,"onUpdate:modelValue":T[3]||(T[3]=w=>l.value=w),label:"Pre-filled Multiline",placeholder:"Already has content..."},null,8,["modelValue"]),e("pre",null,V(l.value),1)]),e("div",I1,[P(yt,{modelValue:u.value,"onUpdate:modelValue":T[4]||(T[4]=w=>u.value=w),label:"Required Field",error:"This field is required",required:""},null,8,["modelValue"])])]),e("div",null,[P(Se,{modelValue:r.value,"onUpdate:modelValue":T[5]||(T[5]=w=>r.value=w),options:D,label:"Select Option",placeholder:"Choose an option..."},null,8,["modelValue"]),e("p",null,V(r.value),1)]),e("div",null,[P(Se,{modelValue:r.value,"onUpdate:modelValue":T[6]||(T[6]=w=>r.value=w),options:D,label:"Required Select",placeholder:"Please select an option"},null,8,["modelValue"])]),e("div",null,[P(Se,{modelValue:c.value,"onUpdate:modelValue":T[7]||(T[7]=w=>c.value=w),options:D,label:"Disabled Select",disabled:""},null,8,["modelValue"])]),e("div",E1,[T[20]||(T[20]=e("h2",{class:"text-lg font-semibold mb-2"},"Overflow Test",-1)),e("div",L1,[T[19]||(T[19]=e("p",{class:"text-sm text-neutral-600 mb-2"}," This container has overflow:hidden and limited height ",-1)),P(Se,{modelValue:f.value,"onUpdate:modelValue":T[8]||(T[8]=w=>f.value=w),options:D,label:"Select in Overflow Container",placeholder:"Should break out of container..."},null,8,["modelValue"])]),T[21]||(T[21]=e("p",{class:"mt-2 text-sm text-neutral-500"}," The dropdown should appear above the red border (in top layer) ",-1))]),e("div",A1,[T[25]||(T[25]=e("h2",{class:"text-xl font-bold mb-4"},"DropdownList Tests",-1)),e("div",P1,[P(Se,{modelValue:g.value,"onUpdate:modelValue":T[9]||(T[9]=w=>g.value=w),options:q,label:"Select Item",placeholder:"Choose an item..."},null,8,["modelValue"]),e("p",null,V(g.value),1)]),e("div",null,[T[23]||(T[23]=e("h3",{class:"text-lg font-semibold mb-2"},"DropdownList Overflow Test",-1)),e("div",D1,[T[22]||(T[22]=e("p",{class:"text-sm text-neutral-600 mb-2"}," This container has overflow:hidden and limited height ",-1)),P(Se,{modelValue:d.value,"onUpdate:modelValue":T[10]||(T[10]=w=>d.value=w),options:q,label:"Dropdown in Overflow Container",placeholder:"Should use popover API..."},null,8,["modelValue"])]),T[24]||(T[24]=e("p",{class:"mt-2 text-sm text-neutral-500"}," The dropdown should appear above the blue border (using Popover API) ",-1))])]),e("div",j1,[T[26]||(T[26]=e("h2",{class:"text-xl font-bold mb-4"},"MultipleSelectionsInput Tests",-1)),e("div",O1,[P(Ct,{modelValue:p.value,"onUpdate:modelValue":T[11]||(T[11]=w=>p.value=w),options:B,label:"Select Multiple Items",placeholder:"Choose items...","add-label":"Add another"},null,8,["modelValue"]),e("p",null,V(p.value),1)]),e("div",U1,[P(Ct,{modelValue:h.value,"onUpdate:modelValue":T[12]||(T[12]=w=>h.value=w),options:B,label:"Disabled Multiple Select",placeholder:"Cannot select...",disabled:""},null,8,["modelValue"])])]),e("div",R1,[T[27]||(T[27]=e("h2",{class:"text-xl font-bold mb-4"},"CheckboxInput Tests",-1)),e("div",N1,[P(Ae,{modelValue:_.value,"onUpdate:modelValue":T[13]||(T[13]=w=>_.value=w),label:"Basic Checkbox"},null,8,["modelValue"]),e("p",F1," Value: "+V(_.value),1)]),e("div",B1,[P(Ae,{modelValue:b.value,"onUpdate:modelValue":T[14]||(T[14]=w=>b.value=w),label:"Checkbox with Help Text",helpText:"This is helpful information about what this checkbox does. Notice how the checkbox stays aligned with the label.",required:""},null,8,["modelValue"]),e("p",q1," Value: "+V(b.value),1)]),e("div",z1,[P(Ae,{modelValue:v.value,"onUpdate:modelValue":T[15]||(T[15]=w=>v.value=w),label:"Disabled Checkbox",helpText:"This checkbox is disabled and cannot be changed.",disabled:""},null,8,["modelValue"])]),e("div",H1,[P(Ae,{modelValue:y.value,"onUpdate:modelValue":T[16]||(T[16]=w=>y.value=w),label:"Checkbox with Error",error:"You must accept the terms and conditions",required:""},null,8,["modelValue"])])]),e("div",W1,[T[29]||(T[29]=e("h2",{class:"text-xl font-bold mb-4"},"JSONSchemaInput Tests",-1)),e("div",J1,[(a(),se(_a,{key:k.value,modelValue:x.value,"onUpdate:modelValue":T[17]||(T[17]=w=>x.value=w),label:"JSON Schema Builder"},null,8,["modelValue"])),e("div",K1,[T[28]||(T[28]=e("p",{class:"text-sm font-mono mb-2"},"Generated Schema:",-1)),e("pre",G1,V(JSON.stringify(x.value,null,2)),1)])])])]))}}),Y1={class:"relative"},Z1=["value","placeholder","rows"],Q1={class:"bg-white dark:bg-black rounded-lg"},ex={class:"px-3 py-2 border-b border-black dark:border-neutral-300"},tx={class:"text-xs font-medium text-neutral-600 dark:text-neutral-400"},ax={key:0,class:"max-h-[200px] overflow-y-auto"},ox=["onClick"],lx={class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},sx={class:"flex-1"},nx={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-0.5"},rx={key:1,class:"px-3 py-4 text-sm text-neutral-500 dark:text-neutral-400 text-center"},ix=pe({__name:"ReferenceInput",props:{modelValue:{},search:{type:Function},placeholder:{},rows:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=m(null),u=m(null),r=m(!1),c=m(""),f=m([]),g=m(0),d=m(-1),p=m(-1),h=m(0),_=m({top:0,left:0}),b=async w=>{const K=w.target,te=K.value,le=K.selectionStart;i("update:modelValue",te),te[le-1]==="@"&&!r.value?v(le):r.value&&await x(te,le)},v=async w=>{d.value=w-1,p.value=w,c.value="",h.value=0,r.value=!0,g.value=0,await y(),await k("")},y=async()=>{if(!l.value)return;await Ce();const w=l.value.getBoundingClientRect(),K=window.getComputedStyle(l.value),te=parseInt(K.lineHeight||"20"),le=parseInt(K.paddingTop||"8"),A=s.modelValue.substring(0,p.value).split(`
26
- `),$=A.length,L=A[A.length-1],ee=Math.min(L.length*8,200);_.value={top:w.top+le+$*te+4,left:w.left+le+ee}},x=async(w,K)=>{if(K<=d.value){q();return}const te=d.value+1,le=w.substring(te,K);if(f.value.length===0?h.value++:h.value=0,f.value.length===0&&h.value>=5){q();return}c.value=le,await k(le)},k=async w=>{if(!s.search){f.value=[];return}const K=await s.search(w);f.value=Array.isArray(K)?K:[],g.value>=f.value.length&&(g.value=0)},D=w=>{if(!l.value)return;const K=s.modelValue,te=K.substring(0,d.value),le=K.substring(p.value+c.value.length),H=`@${w.value}`,A=te+H+le;i("update:modelValue",A),Ce(()=>{if(!l.value)return;const $=te.length+H.length;l.value.focus(),l.value.setSelectionRange($,$)}),q()},q=()=>{r.value=!1,c.value="",f.value=[],g.value=0,d.value=-1,p.value=-1,h.value=0},B=w=>{if(r.value)switch(w.key){case"Escape":w.preventDefault(),q();break;case"ArrowDown":w.preventDefault(),g.value=Math.min(g.value+1,f.value.length-1);break;case"ArrowUp":w.preventDefault(),g.value=Math.max(g.value-1,0);break;case"Enter":f.value.length>0&&(w.preventDefault(),D(f.value[g.value]));break;case"Tab":f.value.length>0&&(w.preventDefault(),D(f.value[g.value]));break}},N=()=>{if(!r.value||!l.value)return;l.value.selectionStart<=d.value&&q()},T=w=>{if(!u.value||!r.value)return;const K=w.target;!u.value.contains(K)&&K!==l.value&&q()};return ve(r,w=>{w?document.addEventListener("click",T):document.removeEventListener("click",T)}),(w,K)=>(a(),o("div",Y1,[e("textarea",{ref_key:"textarea",ref:l,value:t.modelValue,onInput:b,onKeydown:B,onSelect:N,placeholder:t.placeholder||"Type @ to insert references...",rows:t.rows||10,class:"w-full px-3 py-2 border border-black dark:border-neutral-300 rounded bg-transparent font-mono text-sm resize-none focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white"},null,40,Z1),(a(),se(rt,{to:"body"},[r.value?(a(),o("div",{key:0,ref_key:"searchDialog",ref:u,class:"fixed z-50 min-w-[200px] max-w-[400px] bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg",style:ot({top:`${_.value.top}px`,left:`${_.value.left}px`,boxShadow:"4px 4px 0 0 rgba(0, 0, 0, 0.25)",backgroundImage:`
25
+ Line 3`),u=v(""),r=v(""),c=v("option2"),f=v(""),g=v(""),d=v(""),p=v([]),h=v(["test1","test2"]),_=v(!1),b=v(!0),m=v(!1),y=v(!1),x=v({type:"object",properties:{},required:[]}),k=v(0);Me(()=>{window.resetJSONSchema=()=>{x.value={type:"object",properties:{},required:[]},k.value++}});const D=[{value:"option1",label:"Option One"},{value:"option2",label:"Option Two"},{value:"option3",label:"Option Three"},{value:"option4",label:"Option Four"}],q=[{value:"item1",label:"Item One",description:"First item description"},{value:"item2",label:"Item Two",description:"Second item description"},{value:"item3",label:"Item Three",description:"Third item description"},{value:"item4",label:"Item Four",description:"Fourth item description"}],B=[{value:"test1",label:"Test Item 1",description:"First test item"},{value:"test2",label:"Test Item 2",description:"Second test item"},{value:"test3",label:"Test Item 3",description:"Third test item"},{value:"test4",label:"Test Item 4",description:"Fourth test item"},{value:"test5",label:"Test Item 5",description:"Fifth test item"}];return(F,T)=>(a(),o("div",P1,[T[30]||(T[30]=e("h1",{class:"text-2xl font-bold"},"Component Test Page",-1)),e("div",null,[A(Le,{modelValue:n.value,"onUpdate:modelValue":T[0]||(T[0]=$=>n.value=$),label:"Test Label",placeholder:"Enter text..."},null,8,["modelValue"]),e("p",null,S(n.value),1)]),e("div",null,[A(Le,{modelValue:s.value,"onUpdate:modelValue":T[1]||(T[1]=$=>s.value=$),label:"Email",error:"Invalid email address",required:""},null,8,["modelValue"])]),e("div",D1,[T[18]||(T[18]=e("h2",{class:"text-xl font-bold mb-4"},"MultilineInput Tests",-1)),e("div",j1,[A(yt,{modelValue:i.value,"onUpdate:modelValue":T[2]||(T[2]=$=>i.value=$),label:"Multiline Text",placeholder:"Type multiple lines..."},null,8,["modelValue"]),e("p",null,S(i.value),1)]),e("div",O1,[A(yt,{modelValue:l.value,"onUpdate:modelValue":T[3]||(T[3]=$=>l.value=$),label:"Pre-filled Multiline",placeholder:"Already has content..."},null,8,["modelValue"]),e("pre",null,S(l.value),1)]),e("div",U1,[A(yt,{modelValue:u.value,"onUpdate:modelValue":T[4]||(T[4]=$=>u.value=$),label:"Required Field",error:"This field is required",required:""},null,8,["modelValue"])])]),e("div",null,[A(Ve,{modelValue:r.value,"onUpdate:modelValue":T[5]||(T[5]=$=>r.value=$),options:D,label:"Select Option",placeholder:"Choose an option..."},null,8,["modelValue"]),e("p",null,S(r.value),1)]),e("div",null,[A(Ve,{modelValue:r.value,"onUpdate:modelValue":T[6]||(T[6]=$=>r.value=$),options:D,label:"Required Select",placeholder:"Please select an option"},null,8,["modelValue"])]),e("div",null,[A(Ve,{modelValue:c.value,"onUpdate:modelValue":T[7]||(T[7]=$=>c.value=$),options:D,label:"Disabled Select",disabled:""},null,8,["modelValue"])]),e("div",R1,[T[20]||(T[20]=e("h2",{class:"text-lg font-semibold mb-2"},"Overflow Test",-1)),e("div",N1,[T[19]||(T[19]=e("p",{class:"text-sm text-neutral-600 mb-2"}," This container has overflow:hidden and limited height ",-1)),A(Ve,{modelValue:f.value,"onUpdate:modelValue":T[8]||(T[8]=$=>f.value=$),options:D,label:"Select in Overflow Container",placeholder:"Should break out of container..."},null,8,["modelValue"])]),T[21]||(T[21]=e("p",{class:"mt-2 text-sm text-neutral-500"}," The dropdown should appear above the red border (in top layer) ",-1))]),e("div",F1,[T[25]||(T[25]=e("h2",{class:"text-xl font-bold mb-4"},"DropdownList Tests",-1)),e("div",B1,[A(Ve,{modelValue:g.value,"onUpdate:modelValue":T[9]||(T[9]=$=>g.value=$),options:q,label:"Select Item",placeholder:"Choose an item..."},null,8,["modelValue"]),e("p",null,S(g.value),1)]),e("div",null,[T[23]||(T[23]=e("h3",{class:"text-lg font-semibold mb-2"},"DropdownList Overflow Test",-1)),e("div",q1,[T[22]||(T[22]=e("p",{class:"text-sm text-neutral-600 mb-2"}," This container has overflow:hidden and limited height ",-1)),A(Ve,{modelValue:d.value,"onUpdate:modelValue":T[10]||(T[10]=$=>d.value=$),options:q,label:"Dropdown in Overflow Container",placeholder:"Should use popover API..."},null,8,["modelValue"])]),T[24]||(T[24]=e("p",{class:"mt-2 text-sm text-neutral-500"}," The dropdown should appear above the blue border (using Popover API) ",-1))])]),e("div",z1,[T[26]||(T[26]=e("h2",{class:"text-xl font-bold mb-4"},"MultipleSelectionsInput Tests",-1)),e("div",H1,[A(Ct,{modelValue:p.value,"onUpdate:modelValue":T[11]||(T[11]=$=>p.value=$),options:B,label:"Select Multiple Items",placeholder:"Choose items...","add-label":"Add another"},null,8,["modelValue"]),e("p",null,S(p.value),1)]),e("div",W1,[A(Ct,{modelValue:h.value,"onUpdate:modelValue":T[12]||(T[12]=$=>h.value=$),options:B,label:"Disabled Multiple Select",placeholder:"Cannot select...",disabled:""},null,8,["modelValue"])])]),e("div",J1,[T[27]||(T[27]=e("h2",{class:"text-xl font-bold mb-4"},"CheckboxInput Tests",-1)),e("div",K1,[A(Pe,{modelValue:_.value,"onUpdate:modelValue":T[13]||(T[13]=$=>_.value=$),label:"Basic Checkbox"},null,8,["modelValue"]),e("p",G1," Value: "+S(_.value),1)]),e("div",X1,[A(Pe,{modelValue:b.value,"onUpdate:modelValue":T[14]||(T[14]=$=>b.value=$),label:"Checkbox with Help Text",helpText:"This is helpful information about what this checkbox does. Notice how the checkbox stays aligned with the label.",required:""},null,8,["modelValue"]),e("p",Y1," Value: "+S(b.value),1)]),e("div",Q1,[A(Pe,{modelValue:m.value,"onUpdate:modelValue":T[15]||(T[15]=$=>m.value=$),label:"Disabled Checkbox",helpText:"This checkbox is disabled and cannot be changed.",disabled:""},null,8,["modelValue"])]),e("div",Z1,[A(Pe,{modelValue:y.value,"onUpdate:modelValue":T[16]||(T[16]=$=>y.value=$),label:"Checkbox with Error",error:"You must accept the terms and conditions",required:""},null,8,["modelValue"])])]),e("div",ex,[T[29]||(T[29]=e("h2",{class:"text-xl font-bold mb-4"},"JSONSchemaInput Tests",-1)),e("div",tx,[(a(),ne(_a,{key:k.value,modelValue:x.value,"onUpdate:modelValue":T[17]||(T[17]=$=>x.value=$),label:"JSON Schema Builder"},null,8,["modelValue"])),e("div",ax,[T[28]||(T[28]=e("p",{class:"text-sm font-mono mb-2"},"Generated Schema:",-1)),e("pre",ox,S(JSON.stringify(x.value,null,2)),1)])])])]))}}),sx={class:"relative"},nx=["value","placeholder","rows"],rx={class:"bg-white dark:bg-black rounded-lg"},ix={class:"px-3 py-2 border-b border-black dark:border-neutral-300"},dx={class:"text-xs font-medium text-neutral-600 dark:text-neutral-400"},ux={key:0,class:"max-h-[200px] overflow-y-auto"},cx=["onClick"],px={class:"text-xs text-neutral-500 dark:text-neutral-400 mt-0.5"},mx={class:"flex-1"},vx={key:0,class:"text-xs text-neutral-600 dark:text-neutral-400 mt-0.5"},fx={key:1,class:"px-3 py-4 text-sm text-neutral-500 dark:text-neutral-400 text-center"},hx=me({__name:"ReferenceInput",props:{modelValue:{},search:{type:Function},placeholder:{},rows:{}},emits:["update:modelValue"],setup(t,{emit:n}){const s=t,i=n,l=v(null),u=v(null),r=v(!1),c=v(""),f=v([]),g=v(0),d=v(-1),p=v(-1),h=v(0),_=v({top:0,left:0}),b=async $=>{const K=$.target,oe=K.value,te=K.selectionStart;i("update:modelValue",oe),oe[te-1]==="@"&&!r.value?m(te):r.value&&await x(oe,te)},m=async $=>{d.value=$-1,p.value=$,c.value="",h.value=0,r.value=!0,g.value=0,await y(),await k("")},y=async()=>{if(!l.value)return;await Te();const $=l.value.getBoundingClientRect(),K=window.getComputedStyle(l.value),oe=parseInt(K.lineHeight||"20"),te=parseInt(K.paddingTop||"8"),P=s.modelValue.substring(0,p.value).split(`
26
+ `),C=P.length,L=P[P.length-1],ee=Math.min(L.length*8,200);_.value={top:$.top+te+C*oe+4,left:$.left+te+ee}},x=async($,K)=>{if(K<=d.value){q();return}const oe=d.value+1,te=$.substring(oe,K);if(f.value.length===0?h.value++:h.value=0,f.value.length===0&&h.value>=5){q();return}c.value=te,await k(te)},k=async $=>{if(!s.search){f.value=[];return}const K=await s.search($);f.value=Array.isArray(K)?K:[],g.value>=f.value.length&&(g.value=0)},D=$=>{if(!l.value)return;const K=s.modelValue,oe=K.substring(0,d.value),te=K.substring(p.value+c.value.length),H=`@${$.value}`,P=oe+H+te;i("update:modelValue",P),Te(()=>{if(!l.value)return;const C=oe.length+H.length;l.value.focus(),l.value.setSelectionRange(C,C)}),q()},q=()=>{r.value=!1,c.value="",f.value=[],g.value=0,d.value=-1,p.value=-1,h.value=0},B=$=>{if(r.value)switch($.key){case"Escape":$.preventDefault(),q();break;case"ArrowDown":$.preventDefault(),g.value=Math.min(g.value+1,f.value.length-1);break;case"ArrowUp":$.preventDefault(),g.value=Math.max(g.value-1,0);break;case"Enter":f.value.length>0&&($.preventDefault(),D(f.value[g.value]));break;case"Tab":f.value.length>0&&($.preventDefault(),D(f.value[g.value]));break}},F=()=>{if(!r.value||!l.value)return;l.value.selectionStart<=d.value&&q()},T=$=>{if(!u.value||!r.value)return;const K=$.target;!u.value.contains(K)&&K!==l.value&&q()};return fe(r,$=>{$?document.addEventListener("click",T):document.removeEventListener("click",T)}),($,K)=>(a(),o("div",sx,[e("textarea",{ref_key:"textarea",ref:l,value:t.modelValue,onInput:b,onKeydown:B,onSelect:F,placeholder:t.placeholder||"Type @ to insert references...",rows:t.rows||10,class:"w-full px-3 py-2 border border-black dark:border-neutral-300 rounded bg-transparent font-mono text-sm resize-none focus:outline-none focus:ring-1 focus:ring-black dark:focus:ring-white"},null,40,nx),(a(),ne(it,{to:"body"},[r.value?(a(),o("div",{key:0,ref_key:"searchDialog",ref:u,class:"fixed z-50 min-w-[200px] max-w-[400px] bg-white dark:bg-black border-2 border-black dark:border-neutral-300 rounded-lg",style:ot({top:`${_.value.top}px`,left:`${_.value.left}px`,boxShadow:"4px 4px 0 0 rgba(0, 0, 0, 0.25)",backgroundImage:`
27
27
  repeating-linear-gradient(
28
28
  45deg,
29
29
  transparent,
@@ -31,18 +31,18 @@ Line 3`),u=m(""),r=m(""),c=m("option2"),f=m(""),g=m(""),d=m(""),p=m([]),h=m(["te
31
31
  rgba(0, 0, 0, 0.03) 2px,
32
32
  rgba(0, 0, 0, 0.03) 4px
33
33
  )
34
- `})},[e("div",Q1,[e("div",ex,[e("div",tx," Search: "+V(c.value||"..."),1)]),f.value.length>0?(a(),o("div",ax,[(a(!0),o(me,null,ye(f.value,(te,le)=>(a(),o("button",{key:`${te.type}-${te.value}`,onClick:H=>D(te),class:oe(["w-full px-3 py-2 text-left hover:bg-black/5 dark:hover:bg-white/10 transition-colors flex items-start gap-2 text-sm",{"bg-black/10 dark:bg-white/10":le===g.value}])},[e("span",lx,V(te.type),1),e("div",sx,[e("div",null,V(te.label),1),te.description?(a(),o("div",nx,V(te.description),1)):M("",!0)])],10,ox))),128))])):(a(),o("div",rx," No results found ")),K[0]||(K[0]=e("div",{class:"px-3 py-2 border-t border-neutral-200 dark:border-neutral-700 text-xs text-neutral-500 dark:text-neutral-400"},[e("div",null,"↑↓ Navigate • Enter/Tab Select • Esc Cancel")],-1))])],4)):M("",!0)]))]))}}),dx={class:"min-h-screen bg-white dark:bg-black p-8"},ux={class:"max-w-4xl mx-auto space-y-8"},cx={class:"space-y-4"},px={class:"block"},vx={class:"p-4 border border-neutral-300 dark:border-neutral-700 rounded"},mx={class:"text-sm font-mono whitespace-pre-wrap"},fx=pe({__name:"TestReferenceInput",setup(t){const n=m("Hello, type @ to see search suggestions"),s=async i=>{await new Promise(u=>setTimeout(u,100));const l=[{type:"variable",value:"userName",label:"userName",description:"Current user name"},{type:"variable",value:"userEmail",label:"userEmail",description:"Current user email"},{type:"function",value:"getCurrentDate()",label:"getCurrentDate",description:"Get current date"},{type:"prompt",value:"{{prompt:welcome}}",label:"welcome",description:"Welcome message prompt"},{type:"prompt",value:"{{prompt:goodbye}}",label:"goodbye",description:"Goodbye message prompt"}];return i?l.filter(u=>u.label.toLowerCase().includes(i.toLowerCase())):l};return(i,l)=>(a(),o("div",dx,[e("div",ux,[l[4]||(l[4]=e("div",null,[e("h1",{class:"text-2xl font-bold mb-2"},"ReferenceInput Component Test"),e("p",{class:"text-neutral-600 dark:text-neutral-400"}," Type @ to trigger search mode and test the reference input functionality ")],-1)),e("div",cx,[e("label",px,[l[1]||(l[1]=e("span",{class:"text-sm font-medium mb-2 block"},"Test Reference Input",-1)),P(ix,{modelValue:n.value,"onUpdate:modelValue":l[0]||(l[0]=u=>n.value=u),search:s,placeholder:"Type @ to insert references...",rows:10},null,8,["modelValue"])]),e("div",vx,[l[2]||(l[2]=e("h3",{class:"text-sm font-medium mb-2"},"Current Value:",-1)),e("pre",mx,V(n.value),1)]),l[3]||(l[3]=e("div",{class:"p-4 bg-neutral-100 dark:bg-neutral-900 rounded"},[e("h3",{class:"text-sm font-medium mb-2"},"Test Instructions:"),e("ul",{class:"text-sm space-y-1 list-disc list-inside"},[e("li",null,"Type @ anywhere in the textarea to trigger search mode"),e("li",null,"Type characters after @ to filter results"),e("li",null,"Use arrow keys to navigate results"),e("li",null,"Press Enter or Tab to select a result"),e("li",null,"Press Escape to cancel search mode"),e("li",null,"Search exits if no results and you type 5+ more characters"),e("li",null,"Moving cursor before @ also exits search mode")])],-1))])])]))}}),hx={class:"p-8 space-y-8"},gx={class:"space-y-2 mb-4"},bx={class:"mt-4 p-2 bg-neutral-100 rounded"},xx=pe({__name:"DebugView",setup(t){const n=m([{id:"1",name:"Item 1"}]),s=()=>{console.log("Adding item...");const u={id:crypto.randomUUID(),name:`Item ${n.value.length+1}`};n.value.push(u),console.log("Item added, total:",n.value.length)};ve(n,()=>{console.log("Items changed:",n.value.length)},{deep:!0});const i={props:["modelValue"],emits:["update:modelValue"],template:`
34
+ `})},[e("div",rx,[e("div",ix,[e("div",dx," Search: "+S(c.value||"..."),1)]),f.value.length>0?(a(),o("div",ux,[(a(!0),o(ve,null,ke(f.value,(oe,te)=>(a(),o("button",{key:`${oe.type}-${oe.value}`,onClick:H=>D(oe),class:ae(["w-full px-3 py-2 text-left hover:bg-black/5 dark:hover:bg-white/10 transition-colors flex items-start gap-2 text-sm",{"bg-black/10 dark:bg-white/10":te===g.value}])},[e("span",px,S(oe.type),1),e("div",mx,[e("div",null,S(oe.label),1),oe.description?(a(),o("div",vx,S(oe.description),1)):V("",!0)])],10,cx))),128))])):(a(),o("div",fx," No results found ")),K[0]||(K[0]=e("div",{class:"px-3 py-2 border-t border-neutral-200 dark:border-neutral-700 text-xs text-neutral-500 dark:text-neutral-400"},[e("div",null,"↑↓ Navigate • Enter/Tab Select • Esc Cancel")],-1))])],4)):V("",!0)]))]))}}),gx={class:"min-h-screen bg-white dark:bg-black p-8"},bx={class:"max-w-4xl mx-auto space-y-8"},xx={class:"space-y-4"},yx={class:"block"},kx={class:"p-4 border border-neutral-300 dark:border-neutral-700 rounded"},wx={class:"text-sm font-mono whitespace-pre-wrap"},_x=me({__name:"TestReferenceInput",setup(t){const n=v("Hello, type @ to see search suggestions"),s=async i=>{await new Promise(u=>setTimeout(u,100));const l=[{type:"variable",value:"userName",label:"userName",description:"Current user name"},{type:"variable",value:"userEmail",label:"userEmail",description:"Current user email"},{type:"function",value:"getCurrentDate()",label:"getCurrentDate",description:"Get current date"},{type:"prompt",value:"{{prompt:welcome}}",label:"welcome",description:"Welcome message prompt"},{type:"prompt",value:"{{prompt:goodbye}}",label:"goodbye",description:"Goodbye message prompt"}];return i?l.filter(u=>u.label.toLowerCase().includes(i.toLowerCase())):l};return(i,l)=>(a(),o("div",gx,[e("div",bx,[l[4]||(l[4]=e("div",null,[e("h1",{class:"text-2xl font-bold mb-2"},"ReferenceInput Component Test"),e("p",{class:"text-neutral-600 dark:text-neutral-400"}," Type @ to trigger search mode and test the reference input functionality ")],-1)),e("div",xx,[e("label",yx,[l[1]||(l[1]=e("span",{class:"text-sm font-medium mb-2 block"},"Test Reference Input",-1)),A(hx,{modelValue:n.value,"onUpdate:modelValue":l[0]||(l[0]=u=>n.value=u),search:s,placeholder:"Type @ to insert references...",rows:10},null,8,["modelValue"])]),e("div",kx,[l[2]||(l[2]=e("h3",{class:"text-sm font-medium mb-2"},"Current Value:",-1)),e("pre",wx,S(n.value),1)]),l[3]||(l[3]=e("div",{class:"p-4 bg-neutral-100 dark:bg-neutral-900 rounded"},[e("h3",{class:"text-sm font-medium mb-2"},"Test Instructions:"),e("ul",{class:"text-sm space-y-1 list-disc list-inside"},[e("li",null,"Type @ anywhere in the textarea to trigger search mode"),e("li",null,"Type characters after @ to filter results"),e("li",null,"Use arrow keys to navigate results"),e("li",null,"Press Enter or Tab to select a result"),e("li",null,"Press Escape to cancel search mode"),e("li",null,"Search exits if no results and you type 5+ more characters"),e("li",null,"Moving cursor before @ also exits search mode")])],-1))])])]))}}),$x={class:"p-8 space-y-8"},Cx={class:"space-y-2 mb-4"},Tx={class:"mt-4 p-2 bg-neutral-100 rounded"},Sx=me({__name:"DebugView",setup(t){const n=v([{id:"1",name:"Item 1"}]),s=()=>{console.log("Adding item...");const u={id:crypto.randomUUID(),name:`Item ${n.value.length+1}`};n.value.push(u),console.log("Item added, total:",n.value.length)};fe(n,()=>{console.log("Items changed:",n.value.length)},{deep:!0});const i={props:["modelValue"],emits:["update:modelValue"],template:`
35
35
  <div>
36
36
  <div v-for="item in modelValue" :key="item.id">
37
37
  {{ item.name }}
38
38
  </div>
39
39
  <button @click="addChild">Add in Child</button>
40
40
  </div>
41
- `,setup(u,{emit:r}){return{addChild:()=>{console.log("Child adding item...");const f={id:crypto.randomUUID(),name:`Child Item ${u.modelValue.length+1}`};r("update:modelValue",[...u.modelValue,f])}}}},l=m([{id:"1",name:"Parent Item 1"}]);return(u,r)=>(a(),o("div",hx,[e("div",null,[r[1]||(r[1]=e("h2",{class:"text-xl font-bold mb-4"},"Direct Array Test",-1)),e("div",gx,[(a(!0),o(me,null,ye(n.value,c=>(a(),o("div",{key:c.id,class:"p-2 border"},V(c.name),1))),128))]),e("button",{onClick:s,class:"px-4 py-2 bg-black text-white rounded"}," Add Item ")]),e("div",null,[r[2]||(r[2]=e("h2",{class:"text-xl font-bold mb-4"},"Parent-Child Test",-1)),P(i,{modelValue:l.value,"onUpdate:modelValue":r[0]||(r[0]=c=>l.value=c)},null,8,["modelValue"]),e("pre",bx,V(JSON.stringify(l.value,null,2)),1)])]))}}),yx={class:"min-h-screen bg-white dark:bg-black p-8"},kx={class:"max-w-4xl mx-auto"},wx={class:"space-y-8"},_x={class:"space-y-4"},$x={class:"space-y-4"},Cx={class:"p-4 bg-neutral-100 dark:bg-neutral-900 rounded-lg"},Tx={class:"text-sm text-black dark:text-white"},Sx=pe({__name:"TestPromptInput",setup(t){const n=m([{type:"string",value:""}]),s=r=>{n.value=r};Ve(()=>{window.setPromptSegments=s}),ao(()=>{delete window.setPromptSegments});const i=async r=>{await new Promise(g=>setTimeout(g,300));const c=(r||"").toLowerCase();return[{type:"variable",value:"first_name",label:"First Name",description:"The user's first name"},{type:"variable",value:"current_date",label:"current_date",description:"Today's date in ISO format"},{type:"variable",value:"system_time",label:"system_time",description:"Current system time"},{type:"variable",value:"api_key",label:"api_key",description:"API key for external services"},{type:"variable",value:"workspace_id",label:"workspace_id",description:"Current workspace identifier"},{type:"prompt",id:"7102973",label:"Onboarding Prompt",schema:{type:"object",properties:{first_name:{type:"string",description:"the first name of the user"}},required:["first_name"],additionalProperties:!1}},{type:"prompt",id:"error_handler",label:"Error Handler",description:"Error handling prompt",schema:{type:"object",properties:{error_message:{type:"string"}},required:["error_message"]}},{type:"prompt",id:"code_review",label:"Code Review",description:"Code review assistant prompt"},{type:"prompt",id:"data_analysis",label:"Data Analysis",description:"Data analysis insights generator"},{type:"prompt",id:"summary_generator",label:"Summary Generator",description:"Creates concise summaries of long text"}].filter(g=>(g.label||g.id||g.value||"").toLowerCase().includes(c)).slice(0,8)},l=r=>{n.value=r,console.log("Updated:",r)},u=(r,c)=>{console.log("Segment clicked:",r),r.type==="prompt"?alert(`Prompt clicked: ${r.label||r.id}
41
+ `,setup(u,{emit:r}){return{addChild:()=>{console.log("Child adding item...");const f={id:crypto.randomUUID(),name:`Child Item ${u.modelValue.length+1}`};r("update:modelValue",[...u.modelValue,f])}}}},l=v([{id:"1",name:"Parent Item 1"}]);return(u,r)=>(a(),o("div",$x,[e("div",null,[r[1]||(r[1]=e("h2",{class:"text-xl font-bold mb-4"},"Direct Array Test",-1)),e("div",Cx,[(a(!0),o(ve,null,ke(n.value,c=>(a(),o("div",{key:c.id,class:"p-2 border"},S(c.name),1))),128))]),e("button",{onClick:s,class:"px-4 py-2 bg-black text-white rounded"}," Add Item ")]),e("div",null,[r[2]||(r[2]=e("h2",{class:"text-xl font-bold mb-4"},"Parent-Child Test",-1)),A(i,{modelValue:l.value,"onUpdate:modelValue":r[0]||(r[0]=c=>l.value=c)},null,8,["modelValue"]),e("pre",Tx,S(JSON.stringify(l.value,null,2)),1)])]))}}),Vx={class:"min-h-screen bg-white dark:bg-black p-8"},Mx={class:"max-w-4xl mx-auto"},Ix={class:"space-y-8"},Ex={class:"space-y-4"},Lx={class:"space-y-4"},Ax={class:"p-4 bg-neutral-100 dark:bg-neutral-900 rounded-lg"},Px={class:"text-sm text-black dark:text-white"},Dx=me({__name:"TestPromptInput",setup(t){const n=v([{type:"string",value:""}]),s=r=>{n.value=r};Me(()=>{window.setPromptSegments=s}),oo(()=>{delete window.setPromptSegments});const i=async r=>{await new Promise(g=>setTimeout(g,300));const c=(r||"").toLowerCase();return[{type:"variable",value:"first_name",label:"First Name",description:"The user's first name"},{type:"variable",value:"current_date",label:"current_date",description:"Today's date in ISO format"},{type:"variable",value:"system_time",label:"system_time",description:"Current system time"},{type:"variable",value:"api_key",label:"api_key",description:"API key for external services"},{type:"variable",value:"workspace_id",label:"workspace_id",description:"Current workspace identifier"},{type:"prompt",id:"7102973",label:"Onboarding Prompt",schema:{type:"object",properties:{first_name:{type:"string",description:"the first name of the user"}},required:["first_name"],additionalProperties:!1}},{type:"prompt",id:"error_handler",label:"Error Handler",description:"Error handling prompt",schema:{type:"object",properties:{error_message:{type:"string"}},required:["error_message"]}},{type:"prompt",id:"code_review",label:"Code Review",description:"Code review assistant prompt"},{type:"prompt",id:"data_analysis",label:"Data Analysis",description:"Data analysis insights generator"},{type:"prompt",id:"summary_generator",label:"Summary Generator",description:"Creates concise summaries of long text"}].filter(g=>(g.label||g.id||g.value||"").toLowerCase().includes(c)).slice(0,8)},l=r=>{n.value=r,console.log("Updated:",r)},u=(r,c)=>{console.log("Segment clicked:",r),r.type==="prompt"?alert(`Prompt clicked: ${r.label||r.id}
42
42
 
43
43
  In a real app, this could:
44
44
  - Show a modal with prompt details
45
45
  - Expand inline to show the full prompt
46
46
  - Navigate to the prompt editor`):r.type==="variable"&&alert(`Variable clicked: ${r.label||r.value}
47
47
 
48
- Description: ${r.meta?.description||"No description"}`)};return(r,c)=>(a(),o("div",yx,[e("div",kx,[c[5]||(c[5]=e("h1",{class:"text-3xl font-bold mb-8 text-black dark:text-white"}," PromptInput Component Test ",-1)),e("div",wx,[e("div",_x,[c[0]||(c[0]=e("h2",{class:"text-xl font-semibold text-black dark:text-white"}," Basic Usage ",-1)),c[1]||(c[1]=e("p",{class:"text-neutral-600 dark:text-neutral-400"}," Type @ to trigger the autocomplete menu. Use arrow keys to navigate and Enter to select. ",-1)),e("div",null,[P($a,{"model-value":n.value,search:i,placeholder:"Type @ to insert variables or prompts...","onUpdate:modelValue":l,onSegmentClick:u},null,8,["model-value"])])]),e("div",$x,[c[3]||(c[3]=e("h2",{class:"text-xl font-semibold text-black dark:text-white"}," Current Value ",-1)),e("div",Cx,[c[2]||(c[2]=e("h3",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2"}," Segments (value): ",-1)),e("pre",Tx,V(JSON.stringify(n.value,null,2)),1)])]),c[4]||(c[4]=oo('<div class="space-y-4"><h2 class="text-xl font-semibold text-black dark:text-white"> Testing Instructions </h2><ul class="list-disc list-inside space-y-2 text-neutral-600 dark:text-neutral-400"><li>Type @ anywhere in the text to open the search dialog</li><li>Continue typing to search for variables or prompts</li><li>Use arrow keys (↑↓) to navigate results</li><li>Press Enter to select a result or click with mouse</li><li>Press Escape to close the dialog</li><li>Click outside the dialog to close it</li><li>Use Backspace/Delete to remove tags</li><li> The dialog will auto-close after typing 5+ characters without selection </li><li><strong>NEW: Click on any tag to see action handling!</strong></li></ul></div><div class="space-y-4"><h2 class="text-xl font-semibold text-black dark:text-white"> Test Scenarios </h2><div class="grid grid-cols-1 md:grid-cols-2 gap-4"><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Variables </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Try: @user, @date, @time, @api, @work </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Prompts </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Try: @greet, @error, @code, @data, @summ </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Mixed Content </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Mix text with multiple tags and test editing </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Edge Cases </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Test @ at start/end, multiple @@ symbols, etc. </p></div></div></div>',2))])])]))}}),Vx={class:"relative"},Mx={key:0,class:"mt-1 text-sm text-red-500"},Ix=pe({__name:"JsonEditor",props:{modelValue:{},placeholder:{},error:{},rows:{},readonly:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:n}){self.MonacoEnvironment={getWorker(_,b){return b==="json"?new io:new uo}};const s=t,i=n,l=m(null);let u=null,r=!1;const c=m(!1),f={minimap:{enabled:!1},fontSize:14,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:24,padding:{top:12,bottom:12},scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,readOnly:s.readonly,quickSuggestions:{other:"on",comments:"off",strings:"on"},suggestOnTriggerCharacters:!0,acceptSuggestionOnCommitCharacter:!0,tabSize:2,detectIndentation:!1,renderLineHighlight:"none",scrollbar:{vertical:"auto",horizontal:"hidden",verticalScrollbarSize:10}},g=()=>{if(!(!u||s.readonly))try{const _=u.getValue(),b=JSON.parse(_),v=JSON.stringify(b,null,2);v!==_&&(r=!0,u.setValue(v),r=!1)}catch{}},d=()=>{c.value=document.documentElement.classList.contains("dark"),u&&Dt.setTheme(c.value?"vs-dark":"vs")},p=()=>{l.value&&(u=Dt.create(l.value,{value:s.modelValue||"{}",language:"json",theme:c.value?"vs-dark":"vs",...f})(l.value).__monacoEditor=u,u.onDidChangeModelContent(()=>{if(!r){const _=u.getValue();i("update:modelValue",_)}}),u.onDidBlurEditorText(()=>{i("blur"),g()}))};Ve(async()=>{d(),await Ce(),p();const _=new MutationObserver(d);_.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),Be(()=>{_.disconnect(),u&&u.dispose()})}),ve(()=>s.modelValue,_=>{u&&u.getValue()!==_&&(r=!0,u.setValue(_||""),r=!1)}),ve(()=>s.readonly,_=>{u&&u.updateOptions({readOnly:_})});const h=s.rows?`${s.rows*1.5}rem`:"18rem";return(_,b)=>(a(),o("div",Vx,[e("div",{class:oe(["border rounded overflow-hidden bg-white dark:bg-black",[t.error?"border-red-500":"border-black dark:border-neutral-300"]])},[e("div",{ref_key:"containerRef",ref:l,class:"monaco-editor-container",style:ot({height:X(h)})},null,4)],2),t.error?(a(),o("div",Mx,V(t.error),1)):M("",!0)]))}}),Kt=tt(Ix,[["__scopeId","data-v-1393c576"]]),Ex={class:"p-8"},Lx={class:"space-y-4"},Ax={class:"space-y-4"},Px={class:"space-y-4"},Dx=pe({__name:"TestJsonEditorModal",setup(t){const n=m(!1),s=m(JSON.stringify({name:"Test",value:123},null,2)),i=m(!1),l=m(JSON.stringify({editable:!0,count:0},null,2));return(u,r)=>(a(),o("div",Ex,[r[13]||(r[13]=e("h1",{class:"text-3xl font-bold mb-6"},"JsonEditor in Modal Test",-1)),e("div",Lx,[e("div",null,[r[7]||(r[7]=e("h2",{class:"text-xl font-semibold mb-2"}," Read-only JsonEditor in Modal ",-1)),r[8]||(r[8]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-4"}," This should NOT show unsaved changes warning when closing ",-1)),e("button",{onClick:r[0]||(r[0]=c=>n.value=!0),class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black border-2 border-black dark:border-white"}," Open Read-only Modal ")]),e("div",null,[r[9]||(r[9]=e("h2",{class:"text-xl font-semibold mb-2"},"Editable JsonEditor in Modal",-1)),r[10]||(r[10]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-4"}," This should NOT show unsaved changes warning on initial close, but SHOULD show it after editing ",-1)),e("button",{onClick:r[1]||(r[1]=c=>i.value=!0),class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black border-2 border-black dark:border-white"}," Open Editable Modal ")])]),P(He,{modelValue:n.value,"onUpdate:modelValue":r[3]||(r[3]=c=>n.value=c),title:"Read-only JSON Schema",width:"max-w-4xl"},{footer:ge(()=>[e("button",{onClick:r[2]||(r[2]=c=>n.value=!1),class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white"}," Close ")]),default:ge(()=>[e("div",Ax,[r[11]||(r[11]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400"}," This is a read-only JSON editor. No changes can be made. ",-1)),P(Kt,{"model-value":s.value,readonly:!0},null,8,["model-value"])])]),_:1},8,["modelValue"]),P(He,{modelValue:i.value,"onUpdate:modelValue":r[6]||(r[6]=c=>i.value=c),title:"Editable JSON Schema",width:"max-w-4xl"},{footer:ge(()=>[e("button",{onClick:r[5]||(r[5]=c=>i.value=!1),class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white"}," Close ")]),default:ge(()=>[e("div",Px,[r[12]||(r[12]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400"}," This is an editable JSON editor. Changes will be tracked. ",-1)),P(Kt,{modelValue:l.value,"onUpdate:modelValue":r[4]||(r[4]=c=>l.value=c)},null,8,["modelValue"])])]),_:1},8,["modelValue"])]))}}),jx={class:"p-8 max-w-2xl mx-auto"},Ox={class:"mb-6"},Ux={class:"p-4 bg-neutral-100 dark:bg-neutral-800 rounded font-mono text-sm"},Rx={key:0},Nx={class:"whitespace-pre-wrap"},Fx={key:1,class:"text-neutral-500"},Bx={class:"mb-6"},qx={class:"space-y-2"},zx={class:"mt-6"},Hx={class:"p-4 bg-green-50 dark:bg-green-900 rounded min-h-[100px]"},Wx={key:0,class:"font-mono"},Jx={key:1,class:"text-neutral-500"},Kx="10000000-0000-0000-0000-000000000101",Gt="10000000-0000-0000-0000-000000000102",Gx=pe({__name:"TestPromptInterpolation",setup(t){const n=m([]),s=m(null),i=m(null),l=m(""),u=m("Alice Johnson"),r=m("alice@example.com"),c=m("28"),{data:f,error:g}=Ue(de(`/api/prompts/${Kx}`)).json(),{data:d,error:p}=Ue(de(`/api/prompts/${Gt}`)).json();ve(f,b=>{if(b){s.value=b;try{n.value=JSON.parse(b.prompt)}catch(v){console.error("Failed to parse prompt A:",v)}}},{immediate:!0}),ve(d,b=>{b&&(i.value=b)},{immediate:!0});function h(b,v){return b.map(y=>{if(y.type==="string")return y.value||"";if(y.type==="variable"){const x=v[y.value];return x===void 0?`{{${y.value}}}`:typeof x=="string"?x:JSON.stringify(x)}else if(y.type==="prompt"){if(y.id===Gt&&i.value)try{const x=JSON.parse(i.value.prompt);return h(x,v)}catch{return`[Error loading prompt: ${y.label}]`}return""}return""}).join("")}function _(){const b={name:u.value,email:r.value,age:c.value};l.value=h(n.value,b)}return(b,v)=>(a(),o("div",jx,[v[11]||(v[11]=e("h1",{class:"text-2xl font-bold mb-6"},"Prompt Interpolation Test",-1)),e("div",Ox,[v[4]||(v[4]=e("h2",{class:"text-lg font-semibold mb-2"},"Prompt Template",-1)),e("div",Ux,[s.value?(a(),o("div",Rx,[v[3]||(v[3]=e("div",{class:"font-bold mb-2"},"Prompt A:",-1)),e("pre",Nx,V(JSON.stringify(n.value,null,2)),1)])):(a(),o("div",Fx,"Loading..."))])]),e("div",Bx,[v[8]||(v[8]=e("h2",{class:"text-lg font-semibold mb-2"},"Context Values",-1)),e("div",qx,[e("div",null,[v[5]||(v[5]=e("label",{class:"block text-sm mb-1"},"Name:",-1)),Me(e("input",{"onUpdate:modelValue":v[0]||(v[0]=y=>u.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,u.value]])]),e("div",null,[v[6]||(v[6]=e("label",{class:"block text-sm mb-1"},"Email:",-1)),Me(e("input",{"onUpdate:modelValue":v[1]||(v[1]=y=>r.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,r.value]])]),e("div",null,[v[7]||(v[7]=e("label",{class:"block text-sm mb-1"},"Age:",-1)),Me(e("input",{"onUpdate:modelValue":v[2]||(v[2]=y=>c.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,c.value]])])])]),e("button",{onClick:_,class:"px-4 py-2 bg-black text-white rounded hover:bg-neutral-800"}," Render Prompt "),e("div",zx,[v[9]||(v[9]=e("h2",{class:"text-lg font-semibold mb-2"},"Rendered Output",-1)),e("div",Hx,[l.value?(a(),o("div",Wx,V(l.value),1)):(a(),o("div",Jx,' Click "Render Prompt" to see output '))]),v[10]||(v[10]=e("div",{class:"mt-4 p-4 bg-accent-50 dark:bg-accent-900 rounded text-sm"},[e("div",{class:"font-semibold mb-1"}," Expected Output (when feature is implemented): "),e("div",{class:"font-mono"}," User Profile: Alice Johnson <alice@example.com> (Age: 28) ")],-1))])]))}}),Ta=lo({history:so(it()),routes:[{path:"/login",name:"login",component:y1,meta:{public:!0}},{path:"/",redirect:"/threads"},{path:"/agents",name:"agents",component:Vr},{path:"/threads",name:"threads",component:zt},{path:"/threads/:id",name:"thread-detail",component:zt},{path:"/prompts",name:"prompts",component:Uh},{path:"/prompts/:id",name:"prompt-edit",component:Bh},{path:"/models",name:"models",component:rb},{path:"/providers",name:"providers",component:yb},{path:"/tools",name:"tools",component:Zb},{path:"/settings/users",name:"users",component:a1},{path:"/settings/api-keys",name:"api-keys",component:c1},{path:"/test",name:"test",component:X1},{path:"/test-reference-input",name:"test-reference-input",component:fx},{path:"/debug",name:"debug",component:xx},{path:"/test-prompt-input",name:"test-prompt-input",component:Sx},{path:"/test-json-editor-modal",name:"test-json-editor-modal",component:Dx},{path:"/test-prompt-interpolation",name:"test-prompt-interpolation",component:Gx}]});Ta.beforeEach(async(t,n,s)=>{const i=t.meta.public===!0,l=localStorage.getItem("auth_token");!i&&!l?s({name:"login"}):i&&l&&t.name==="login"?s({name:"threads"}):s()});const Xx=window.fetch;window.fetch=async function(t,n){const s=typeof t=="string"?t:t instanceof URL?t.toString():t.url,i=it(),l=i==="/"?"/api/":`${i}/api/`,u=s.includes(l)||i==="/"&&s.startsWith("/api/");if(u){const f=localStorage.getItem("auth_token");f&&n?n.headers={...n.headers,Authorization:`Bearer ${f}`}:f&&(n={...n,headers:{Authorization:`Bearer ${f}`}})}const r=await Xx(t,n),c=s.includes("/api/auth/");return r.status===401&&u&&!c&&(localStorage.removeItem("auth_token"),window.location.href=de("/login")),r};const Mt=no(ls);Mt.use(xo,{endpoint:de("/api")});Mt.use(Ta);Mt.mount("#app");
48
+ Description: ${r.meta?.description||"No description"}`)};return(r,c)=>(a(),o("div",Vx,[e("div",Mx,[c[5]||(c[5]=e("h1",{class:"text-3xl font-bold mb-8 text-black dark:text-white"}," PromptInput Component Test ",-1)),e("div",Ix,[e("div",Ex,[c[0]||(c[0]=e("h2",{class:"text-xl font-semibold text-black dark:text-white"}," Basic Usage ",-1)),c[1]||(c[1]=e("p",{class:"text-neutral-600 dark:text-neutral-400"}," Type @ to trigger the autocomplete menu. Use arrow keys to navigate and Enter to select. ",-1)),e("div",null,[A($a,{"model-value":n.value,search:i,placeholder:"Type @ to insert variables or prompts...","onUpdate:modelValue":l,onSegmentClick:u},null,8,["model-value"])])]),e("div",Lx,[c[3]||(c[3]=e("h2",{class:"text-xl font-semibold text-black dark:text-white"}," Current Value ",-1)),e("div",Ax,[c[2]||(c[2]=e("h3",{class:"text-sm font-medium text-neutral-700 dark:text-neutral-300 mb-2"}," Segments (value): ",-1)),e("pre",Px,S(JSON.stringify(n.value,null,2)),1)])]),c[4]||(c[4]=lo('<div class="space-y-4"><h2 class="text-xl font-semibold text-black dark:text-white"> Testing Instructions </h2><ul class="list-disc list-inside space-y-2 text-neutral-600 dark:text-neutral-400"><li>Type @ anywhere in the text to open the search dialog</li><li>Continue typing to search for variables or prompts</li><li>Use arrow keys (↑↓) to navigate results</li><li>Press Enter to select a result or click with mouse</li><li>Press Escape to close the dialog</li><li>Click outside the dialog to close it</li><li>Use Backspace/Delete to remove tags</li><li> The dialog will auto-close after typing 5+ characters without selection </li><li><strong>NEW: Click on any tag to see action handling!</strong></li></ul></div><div class="space-y-4"><h2 class="text-xl font-semibold text-black dark:text-white"> Test Scenarios </h2><div class="grid grid-cols-1 md:grid-cols-2 gap-4"><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Variables </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Try: @user, @date, @time, @api, @work </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Prompts </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Try: @greet, @error, @code, @data, @summ </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Mixed Content </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Mix text with multiple tags and test editing </p></div><div class="p-4 border-2 border-neutral-300 dark:border-neutral-700 rounded-lg"><h3 class="font-medium text-black dark:text-white mb-2"> Edge Cases </h3><p class="text-sm text-neutral-600 dark:text-neutral-400"> Test @ at start/end, multiple @@ symbols, etc. </p></div></div></div>',2))])])]))}}),jx={class:"relative"},Ox={key:0,class:"mt-1 text-sm text-red-500"},Ux=me({__name:"JsonEditor",props:{modelValue:{},placeholder:{},error:{},rows:{},readonly:{type:Boolean}},emits:["update:modelValue","blur"],setup(t,{emit:n}){self.MonacoEnvironment={getWorker(_,b){return b==="json"?new uo:new co}};const s=t,i=n,l=v(null);let u=null,r=!1;const c=v(!1),f={minimap:{enabled:!1},fontSize:14,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace',lineHeight:24,padding:{top:12,bottom:12},scrollBeyondLastLine:!1,wordWrap:"on",automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,readOnly:s.readonly,quickSuggestions:{other:"on",comments:"off",strings:"on"},suggestOnTriggerCharacters:!0,acceptSuggestionOnCommitCharacter:!0,tabSize:2,detectIndentation:!1,renderLineHighlight:"none",scrollbar:{vertical:"auto",horizontal:"hidden",verticalScrollbarSize:10}},g=()=>{if(!(!u||s.readonly))try{const _=u.getValue(),b=JSON.parse(_),m=JSON.stringify(b,null,2);m!==_&&(r=!0,u.setValue(m),r=!1)}catch{}},d=()=>{c.value=document.documentElement.classList.contains("dark"),u&&Dt.setTheme(c.value?"vs-dark":"vs")},p=()=>{l.value&&(u=Dt.create(l.value,{value:s.modelValue||"{}",language:"json",theme:c.value?"vs-dark":"vs",...f})(l.value).__monacoEditor=u,u.onDidChangeModelContent(()=>{if(!r){const _=u.getValue();i("update:modelValue",_)}}),u.onDidBlurEditorText(()=>{i("blur"),g()}))};Me(async()=>{d(),await Te(),p();const _=new MutationObserver(d);_.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),Be(()=>{_.disconnect(),u&&u.dispose()})}),fe(()=>s.modelValue,_=>{u&&u.getValue()!==_&&(r=!0,u.setValue(_||""),r=!1)}),fe(()=>s.readonly,_=>{u&&u.updateOptions({readOnly:_})});const h=s.rows?`${s.rows*1.5}rem`:"18rem";return(_,b)=>(a(),o("div",jx,[e("div",{class:ae(["border rounded overflow-hidden bg-white dark:bg-black",[t.error?"border-red-500":"border-black dark:border-neutral-300"]])},[e("div",{ref_key:"containerRef",ref:l,class:"monaco-editor-container",style:ot({height:X(h)})},null,4)],2),t.error?(a(),o("div",Ox,S(t.error),1)):V("",!0)]))}}),Kt=tt(Ux,[["__scopeId","data-v-1393c576"]]),Rx={class:"p-8"},Nx={class:"space-y-4"},Fx={class:"space-y-4"},Bx={class:"space-y-4"},qx=me({__name:"TestJsonEditorModal",setup(t){const n=v(!1),s=v(JSON.stringify({name:"Test",value:123},null,2)),i=v(!1),l=v(JSON.stringify({editable:!0,count:0},null,2));return(u,r)=>(a(),o("div",Rx,[r[13]||(r[13]=e("h1",{class:"text-3xl font-bold mb-6"},"JsonEditor in Modal Test",-1)),e("div",Nx,[e("div",null,[r[7]||(r[7]=e("h2",{class:"text-xl font-semibold mb-2"}," Read-only JsonEditor in Modal ",-1)),r[8]||(r[8]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-4"}," This should NOT show unsaved changes warning when closing ",-1)),e("button",{onClick:r[0]||(r[0]=c=>n.value=!0),class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black border-2 border-black dark:border-white"}," Open Read-only Modal ")]),e("div",null,[r[9]||(r[9]=e("h2",{class:"text-xl font-semibold mb-2"},"Editable JsonEditor in Modal",-1)),r[10]||(r[10]=e("p",{class:"text-neutral-600 dark:text-neutral-400 mb-4"}," This should NOT show unsaved changes warning on initial close, but SHOULD show it after editing ",-1)),e("button",{onClick:r[1]||(r[1]=c=>i.value=!0),class:"px-4 py-2 bg-black dark:bg-white text-white dark:text-black border-2 border-black dark:border-white"}," Open Editable Modal ")])]),A(He,{modelValue:n.value,"onUpdate:modelValue":r[3]||(r[3]=c=>n.value=c),title:"Read-only JSON Schema",width:"max-w-4xl"},{footer:be(()=>[e("button",{onClick:r[2]||(r[2]=c=>n.value=!1),class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white"}," Close ")]),default:be(()=>[e("div",Fx,[r[11]||(r[11]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400"}," This is a read-only JSON editor. No changes can be made. ",-1)),A(Kt,{"model-value":s.value,readonly:!0},null,8,["model-value"])])]),_:1},8,["modelValue"]),A(He,{modelValue:i.value,"onUpdate:modelValue":r[6]||(r[6]=c=>i.value=c),title:"Editable JSON Schema",width:"max-w-4xl"},{footer:be(()=>[e("button",{onClick:r[5]||(r[5]=c=>i.value=!1),class:"px-4 py-2 border-2 border-black dark:border-white bg-white dark:bg-black text-black dark:text-white"}," Close ")]),default:be(()=>[e("div",Bx,[r[12]||(r[12]=e("p",{class:"text-sm text-neutral-600 dark:text-neutral-400"}," This is an editable JSON editor. Changes will be tracked. ",-1)),A(Kt,{modelValue:l.value,"onUpdate:modelValue":r[4]||(r[4]=c=>l.value=c)},null,8,["modelValue"])])]),_:1},8,["modelValue"])]))}}),zx={class:"p-8 max-w-2xl mx-auto"},Hx={class:"mb-6"},Wx={class:"p-4 bg-neutral-100 dark:bg-neutral-800 rounded font-mono text-sm"},Jx={key:0},Kx={class:"whitespace-pre-wrap"},Gx={key:1,class:"text-neutral-500"},Xx={class:"mb-6"},Yx={class:"space-y-2"},Qx={class:"mt-6"},Zx={class:"p-4 bg-green-50 dark:bg-green-900 rounded min-h-[100px]"},ey={key:0,class:"font-mono"},ty={key:1,class:"text-neutral-500"},ay="10000000-0000-0000-0000-000000000101",Gt="10000000-0000-0000-0000-000000000102",oy=me({__name:"TestPromptInterpolation",setup(t){const n=v([]),s=v(null),i=v(null),l=v(""),u=v("Alice Johnson"),r=v("alice@example.com"),c=v("28"),{data:f,error:g}=Ue(ue(`/api/prompts/${ay}`)).json(),{data:d,error:p}=Ue(ue(`/api/prompts/${Gt}`)).json();fe(f,b=>{if(b){s.value=b;try{n.value=JSON.parse(b.prompt)}catch(m){console.error("Failed to parse prompt A:",m)}}},{immediate:!0}),fe(d,b=>{b&&(i.value=b)},{immediate:!0});function h(b,m){return b.map(y=>{if(y.type==="string")return y.value||"";if(y.type==="variable"){const x=m[y.value];return x===void 0?`{{${y.value}}}`:typeof x=="string"?x:JSON.stringify(x)}else if(y.type==="prompt"){if(y.id===Gt&&i.value)try{const x=JSON.parse(i.value.prompt);return h(x,m)}catch{return`[Error loading prompt: ${y.label}]`}return""}return""}).join("")}function _(){const b={name:u.value,email:r.value,age:c.value};l.value=h(n.value,b)}return(b,m)=>(a(),o("div",zx,[m[11]||(m[11]=e("h1",{class:"text-2xl font-bold mb-6"},"Prompt Interpolation Test",-1)),e("div",Hx,[m[4]||(m[4]=e("h2",{class:"text-lg font-semibold mb-2"},"Prompt Template",-1)),e("div",Wx,[s.value?(a(),o("div",Jx,[m[3]||(m[3]=e("div",{class:"font-bold mb-2"},"Prompt A:",-1)),e("pre",Kx,S(JSON.stringify(n.value,null,2)),1)])):(a(),o("div",Gx,"Loading..."))])]),e("div",Xx,[m[8]||(m[8]=e("h2",{class:"text-lg font-semibold mb-2"},"Context Values",-1)),e("div",Yx,[e("div",null,[m[5]||(m[5]=e("label",{class:"block text-sm mb-1"},"Name:",-1)),Ie(e("input",{"onUpdate:modelValue":m[0]||(m[0]=y=>u.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,u.value]])]),e("div",null,[m[6]||(m[6]=e("label",{class:"block text-sm mb-1"},"Email:",-1)),Ie(e("input",{"onUpdate:modelValue":m[1]||(m[1]=y=>r.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,r.value]])]),e("div",null,[m[7]||(m[7]=e("label",{class:"block text-sm mb-1"},"Age:",-1)),Ie(e("input",{"onUpdate:modelValue":m[2]||(m[2]=y=>c.value=y),type:"text",class:"w-full px-3 py-2 border rounded"},null,512),[[Oe,c.value]])])])]),e("button",{onClick:_,class:"px-4 py-2 bg-black text-white rounded hover:bg-neutral-800"}," Render Prompt "),e("div",Qx,[m[9]||(m[9]=e("h2",{class:"text-lg font-semibold mb-2"},"Rendered Output",-1)),e("div",Zx,[l.value?(a(),o("div",ey,S(l.value),1)):(a(),o("div",ty,' Click "Render Prompt" to see output '))]),m[10]||(m[10]=e("div",{class:"mt-4 p-4 bg-accent-50 dark:bg-accent-900 rounded text-sm"},[e("div",{class:"font-semibold mb-1"}," Expected Output (when feature is implemented): "),e("div",{class:"font-mono"}," User Profile: Alice Johnson <alice@example.com> (Age: 28) ")],-1))])]))}}),Ta=so({history:no(dt()),routes:[{path:"/login",name:"login",component:V1,meta:{public:!0}},{path:"/",redirect:"/threads"},{path:"/agents",name:"agents",component:Mr},{path:"/threads",name:"threads",component:zt},{path:"/threads/:id",name:"thread-detail",component:zt},{path:"/prompts",name:"prompts",component:Wh},{path:"/prompts/:id",name:"prompt-edit",component:Xh},{path:"/models",name:"models",component:fb},{path:"/providers",name:"providers",component:Vb},{path:"/tools",name:"tools",component:n1},{path:"/settings/users",name:"users",component:u1},{path:"/settings/api-keys",name:"api-keys",component:x1},{path:"/test",name:"test",component:lx},{path:"/test-reference-input",name:"test-reference-input",component:_x},{path:"/debug",name:"debug",component:Sx},{path:"/test-prompt-input",name:"test-prompt-input",component:Dx},{path:"/test-json-editor-modal",name:"test-json-editor-modal",component:qx},{path:"/test-prompt-interpolation",name:"test-prompt-interpolation",component:oy}]});Ta.beforeEach(async(t,n,s)=>{const i=t.meta.public===!0,l=localStorage.getItem("auth_token");!i&&!l?s({name:"login"}):i&&l&&t.name==="login"?s({name:"threads"}):s()});const ly=window.fetch;window.fetch=async function(t,n){const s=typeof t=="string"?t:t instanceof URL?t.toString():t.url,i=dt(),l=i==="/"?"/api/":`${i}/api/`,u=s.includes(l)||i==="/"&&s.startsWith("/api/");if(u){const f=localStorage.getItem("auth_token");f&&n?n.headers={...n.headers,Authorization:`Bearer ${f}`}:f&&(n={...n,headers:{Authorization:`Bearer ${f}`}})}const r=await ly(t,n),c=s.includes("/api/auth/");return r.status===401&&u&&!c&&(localStorage.removeItem("auth_token"),window.location.href=ue("/login")),r};const Mt=ro(ss);Mt.use(yo,{endpoint:ue("/api")});Mt.use(Ta);Mt.mount("#app");