llmxray 0.4.0 → 0.4.2

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.
Files changed (49) hide show
  1. package/README.md +276 -244
  2. package/dist/assets/{AITrainingPage-Ck1bDWWB.js → AITrainingPage-DEU4UAR7.js} +1 -1
  3. package/dist/assets/AnalyticsPage-C7mNUAil.js +1 -0
  4. package/dist/assets/{BenchmarkPage-VzMNGUEy.js → BenchmarkPage-jiUqdHmg.js} +2 -2
  5. package/dist/assets/{ComparisonPage-BBliPm7K.js → ComparisonPage-BoBWSObY.js} +3 -3
  6. package/dist/assets/CostDashboardPage-BKQDsZhx.js +1 -0
  7. package/dist/assets/DashboardPage-CV8Ejgxv.js +116 -0
  8. package/dist/assets/{EmbeddingsPage-BIHHeJq6.js → EmbeddingsPage-DXjVT4eU.js} +1 -1
  9. package/dist/assets/{GoogleCallbackPage-2gGq0Swg.js → GoogleCallbackPage-BUIkYpZv.js} +1 -1
  10. package/dist/assets/{JsonTreeNode-CDR0az7J.js → JsonTreeNode-C0UNUwZm.js} +1 -1
  11. package/dist/assets/{ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-DkuvrY_5.js → ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-vQNvYFzV.js} +1 -1
  12. package/dist/assets/{RAGPage-BdXerRDW.js → RAGPage-Dv4UDEyz.js} +1 -1
  13. package/dist/assets/SessionPage-B0fMQGSB.js +15 -0
  14. package/dist/assets/{SettingsPage-B1wm-L6T.js → SettingsPage-DTJP-4xU.js} +1 -1
  15. package/dist/assets/{StatusBadge.vue_vue_type_script_setup_true_lang-J8rYaobd.js → StatusBadge.vue_vue_type_script_setup_true_lang-BiB0M6lv.js} +1 -1
  16. package/dist/assets/{StorageGauge.vue_vue_type_style_index_0_lang-Begwajgo.js → StorageGauge.vue_vue_type_style_index_0_lang-DToi3R0q.js} +1 -1
  17. package/dist/assets/{SystemPage-DDZrsYds.js → SystemPage-BPK15qwe.js} +2 -2
  18. package/dist/assets/{TabBar.vue_vue_type_script_setup_true_lang-DVCeD1qL.js → TabBar.vue_vue_type_script_setup_true_lang-BtGCdMZK.js} +1 -1
  19. package/dist/assets/{TokenStreamDisplay.vue_vue_type_script_setup_true_lang-rJpx5sU7.js → TokenStreamDisplay.vue_vue_type_script_setup_true_lang-B6juPZsY.js} +1 -1
  20. package/dist/assets/{ToolWorkshopPage-DnHp32vX.js → ToolWorkshopPage-DmpoHHaD.js} +3 -3
  21. package/dist/assets/{agent-store-BWO6HamI.js → agent-store-C6w1zV86.js} +1 -1
  22. package/dist/assets/{canvas-ai-db-anWOo2F0.js → canvas-ai-db-BpqhUp6k.js} +1 -1
  23. package/dist/assets/{download-BqPPd3_X.js → download-pCIjWOn5.js} +1 -1
  24. package/dist/assets/{generate-service-C3Z8NZaT.js → generate-service-DmtXqq_h.js} +1 -1
  25. package/dist/assets/{google-auth-store-CgUWvtRU.js → google-auth-store-Dgv2FihL.js} +1 -1
  26. package/dist/assets/index-534TcCbY.js +8 -0
  27. package/dist/assets/index-B72Sw9uL.css +1 -0
  28. package/dist/assets/{index-KhnkHbiC.js → index-ClITfJ3t.js} +1 -1
  29. package/dist/assets/{index-B7GdQF1S.js → index-DHuj6tKB.js} +1 -1
  30. package/dist/assets/info-Eg1tUw1x.js +1 -0
  31. package/dist/assets/{metrics-store-BMhkZ9B4.js → metrics-store-7m97Sb7w.js} +1 -1
  32. package/dist/assets/{papaparse.min-z5sNvmdo.js → papaparse.min-3FeAYh4d.js} +1 -1
  33. package/dist/assets/{pencil-Csf0-tn3.js → pencil-CZp68oBU.js} +1 -1
  34. package/dist/assets/{rag-store-Ch0N5LTe.js → rag-store-Bm0nxdec.js} +3 -3
  35. package/dist/assets/session-store-BQ0TF24S.js +1 -0
  36. package/dist/assets/{share-2-DIi3V2dc.js → share-2-CJJGZsZO.js} +1 -1
  37. package/dist/assets/{storage-store-uPTARmbg.js → storage-store-6qFwk_C5.js} +1 -1
  38. package/dist/assets/stream-handler-BM5egg14.js +4 -0
  39. package/dist/assets/{tool-workshop-store-koPpdoxb.js → tool-workshop-store-9_FKfdnT.js} +1 -1
  40. package/dist/assets/toolcall-store-C4Trr01T.js +1 -0
  41. package/dist/assets/{trash-2-aeVGvgIz.js → trash-2-DjfJXqVK.js} +1 -1
  42. package/dist/index.html +2 -2
  43. package/package.json +1 -1
  44. package/dist/assets/DashboardPage-CH15t_MS.js +0 -116
  45. package/dist/assets/SessionPage-B39x2A8D.js +0 -15
  46. package/dist/assets/index-ClE7gpZb.js +0 -8
  47. package/dist/assets/index-Dr1ztyT3.css +0 -1
  48. package/dist/assets/stream-handler-BuwD741F.js +0 -4
  49. package/dist/assets/toolcall-store-JKmpIFj3.js +0 -1
@@ -1,116 +0,0 @@
1
- import{u as at}from"./metrics-store-BMhkZ9B4.js";import{c as Pe,_ as Ts,o as Ie,n as be,r as N,d as Ms,w as te,a as F,b as ne,e as x,f as r,g as P,t as d,h as Ce,i as z,j as m,F as H,k as X,l as Rs,u as f,m as As,p as I,q as ze,T as Ns,s as Bt,v as Ve,X as Ke,x as Ft,y as zs,z as Ot,A as rt,B as Ut,E as Es,C as W,D as Q,G as Ye,H as Vt,I as qt,S as Ps,J as Is}from"./index-ClE7gpZb.js";import{f as _e,a as qe,b as et,c as Ht,d as Ds}from"./format-BqVZ9rwM.js";import{u as Je,a as js}from"./toolcall-store-JKmpIFj3.js";import{a as Ls,s as Bs,C as Fs}from"./generate-service-C3Z8NZaT.js";import{u as Os,a as Us,_ as Vs,b as Oe}from"./StatusBadge.vue_vue_type_script_setup_true_lang-J8rYaobd.js";import{u as lt}from"./tool-workshop-store-koPpdoxb.js";import{u as qs,a as Wt,b as Hs}from"./agent-store-BWO6HamI.js";import{e as Ws}from"./stream-handler-BuwD741F.js";import{d as Gs,p as Zs,u as Gt}from"./rag-store-Ch0N5LTe.js";import{messageMemoryDB as Zt}from"./message-memory-db-C3Ifhs2B.js";import{_ as _t}from"./ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-DkuvrY_5.js";import{P as Ct}from"./pencil-Csf0-tn3.js";import{D as Ks}from"./download-BqPPd3_X.js";import"./vector-db-ChAzHl5A.js";const Js=Pe("clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6l4 2",key:"mmk7yg"}]]);const Kt=Pe("file-text",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);const Qs=Pe("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]]);const Xs=Pe("send",[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]);const Ys=Pe("slash",[["path",{d:"M22 2 2 22",key:"y4kqgn"}]]);async function en(t,e){const s=performance.now();try{let o;return t.implementation.mode==="code"?o=await tn(t.implementation.code,e):o=await sn(t.implementation.blocks,e),{success:!0,result:o,durationMs:performance.now()-s}}catch(o){return{success:!1,result:null,durationMs:performance.now()-s,error:o instanceof Error?o.message:String(o)}}}async function tn(t,e){if(!t.trim())throw new Error("Tool has no implementation code");const s=Object.getPrototypeOf(async function(){}).constructor;return await new s("args","fetch","getGoogleToken",t)(e,fetch.bind(globalThis),ln)}async function sn(t,e){if(t.length===0)throw new Error("Tool has no action blocks");const s=new Map;for(const[l,a]of Object.entries(e))s.set(l,a);const o=[...t].sort((l,a)=>l.order-a.order);let n=null;for(const l of o)switch(l.type){case"http_request":await nn(l.config,s);break;case"extract_field":on(l.config,s);break;case"template":an(l.config,s);break;case"return_value":n=rn(l.config,s);break}return n}async function nn(t,e){const s=Ee(t.url,e),o=t.body?Ee(t.body,e):void 0,n={};for(const[i,p]of Object.entries(t.headers))n[i]=Ee(p,e);const l=await fetch(s,{method:t.method,headers:n,body:t.method!=="GET"?o:void 0});let a;(l.headers.get("content-type")??"").includes("application/json")?a=await l.json():a=await l.text(),e.set(t.outputVariable||"response",a)}function on(t,e){const s=e.get(t.input);if(s==null){e.set(t.outputVariable||"value",null);return}const o=t.fieldPath.split(".");let n=s;for(const l of o){if(n==null||typeof n!="object"){n=null;break}n=n[l]}e.set(t.outputVariable||"value",n)}function an(t,e){const s=Ee(t.template,e);e.set(t.outputVariable||"text",s)}function rn(t,e){const s=t.expression.trim();return e.has(s)?e.get(s):Ee(s,e)}async function ln(){const{getAccessToken:t,isConnected:e}=await Ts(async()=>{const{getAccessToken:s,isConnected:o}=await import("./google-auth-CfEcVMA7.js");return{getAccessToken:s,isConnected:o}},[]);if(!e())throw new Error("Google account not connected. Go to Settings to connect your Google account.");return t()}function Ee(t,e){return t.replace(/\{\{(\w+(?:\.\w+)*)\}\}/g,(s,o)=>{const n=o.split(".");let l=e.get(n[0]??"");for(let a=1;a<n.length;a++){if(l==null||typeof l!="object")return"";l=l[n[a]??""]}return l==null?"":typeof l=="object"?JSON.stringify(l):String(l)})}const cn=5;async function un(t){const e=Je(),s=Os(),o=t.messages.map(c=>`[${c.role}] ${c.content}`).join(`
2
- `),n=e.createSession({mode:"chat",model:t.model,prompt:o,messages:t.messages,options:t.options});e.setActiveSession(n);const l=Ls(n,t.messages);s.setAnatomy(n,l);const a=new AbortController;return dn(n,t.model,[...t.messages],t.tools,t.options,a.signal).catch(c=>{a.signal.aborted||e.setSessionError(n,c instanceof Error?c.message:"Chat failed")}),{sessionId:n,abort:()=>{a.abort(),e.cancelSession(n)}}}async function dn(t,e,s,o,n,l){const a=js(),c=lt(),i=qs();let p=0,u=0;for(;p<cn;){if(l.aborted)return;const h=await Ie.streamChat({model:e,messages:s,tools:o,options:n,logprobs:!0},l),b=await Ws(t,h,l);if(b.toolCalls.length===0)return;s.push({role:"assistant",content:"",tool_calls:b.toolCalls});for(const S of b.toolCalls){const C=c.findByFunctionName(S.function.name),_=a.getToolCalls(t).find(q=>q.functionName===S.function.name&&q.status==="pending");if(!C){const q=`Tool "${S.function.name}" has no implementation`;i.addNode(t,{id:be(),type:"error",label:`No impl: ${S.function.name}`,sessionId:t,stepIndex:u++,state:{tool:S.function.name,error:q},timestamp:Date.now()}),_&&a.updateToolCall(t,_.id,{status:"failed",error:q,completedAt:Date.now()}),s.push({role:"tool",content:JSON.stringify({error:q})});continue}_&&a.updateToolCall(t,_.id,{status:"executing"});const j=await en(C,S.function.arguments);i.addNode(t,{id:be(),type:j.success?"output":"error",label:j.success?`Tool Result: ${S.function.name}`:`Tool Failed: ${S.function.name}`,sessionId:t,stepIndex:u++,state:{tool:S.function.name,success:j.success,durationMs:j.durationMs},timestamp:Date.now()}),_&&a.updateToolCall(t,_.id,{status:j.success?"completed":"failed",result:j.result,error:j.error,completedAt:Date.now(),durationMs:j.durationMs});const U=j.success?typeof j.result=="string"?j.result:JSON.stringify(j.result):JSON.stringify({error:j.error});s.push({role:"tool",content:U})}i.addNode(t,{id:be(),type:"llm_call",label:`LLM Round ${p+2} (with tool results)`,sessionId:t,stepIndex:u++,state:{round:p+1},timestamp:Date.now()}),p++}}function pn(){const t=N(!1),e=N(null),s=N(null);let o=null;async function n(c,i,p,u){t.value=!0,e.value=null;try{const h=await Bs({model:c,prompt:i,system:u,options:p});return s.value=h.sessionId,o=h.abort,h.sessionId}catch(h){throw e.value=h instanceof Error?h.message:"Failed to start generation",t.value=!1,h}}async function l(c,i,p,u){t.value=!0,e.value=null;try{const h=await un({model:c,messages:i,tools:u,options:p});return s.value=h.sessionId,o=h.abort,h.sessionId}catch(h){throw e.value=h instanceof Error?h.message:"Failed to start chat",t.value=!1,h}}function a(){o&&(o(),o=null),t.value=!1}return{isStreaming:t,error:e,currentSessionId:s,startGenerate:n,startChatStream:l,cancel:a}}const He=[{name:"help",description:"Show all available commands",usage:"/help",category:"chat",execute(t,e){const s=Jt(),o=[`Available commands:
3
- `];for(const[n,l]of Object.entries(s)){o.push(`**${n}**`);for(const a of l)o.push(` ${a.usage} — ${a.description}`);o.push("")}e.showNotification(o.join(`
4
- `))}},{name:"clear",description:"Clear current conversation",usage:"/clear",category:"chat",execute(t,e){e.clearConversation(),e.showNotification("Conversation cleared.")}},{name:"new",description:"Start a new chat session",usage:"/new",category:"chat",execute(t,e){e.newChat(),e.showNotification("New chat started.")}},{name:"summarize",description:"Ask the model to summarize the conversation",usage:"/summarize",category:"chat",execute(t,e){if(e.messages.length===0){e.showNotification("Nothing to summarize — conversation is empty.");return}e.sendAsUser("Please summarize our conversation so far in a concise way.")}},{name:"save",description:"Export conversation as JSON or text",usage:"/save [json|text]",category:"chat",execute(t,e){const s=t.trim()==="text"?"text":"json";e.exportConversation(s),e.showNotification(`Conversation exported as ${s}.`)}},{name:"copy",description:"Copy last assistant response to clipboard",usage:"/copy",category:"chat",execute(t,e){e.copyLastResponse()}},{name:"history",description:"Show recent conversations",usage:"/history",category:"chat",execute(t,e){e.showNotification("Scroll down to the recent chats section, or start a /new chat.")}},{name:"model",description:"Switch model or list available models",usage:"/model [name]",category:"settings",execute(t,e){const s=t.trim();if(!s){const n=e.availableModels.join(", ");e.showNotification(`Available models: ${n}
5
- Current: ${e.currentModel}`);return}const o=e.availableModels.find(n=>n===s||n.startsWith(s));o?(e.switchModel(o),e.showNotification(`Switched to ${o}.`)):e.showNotification(`Model "${s}" not found. Available: ${e.availableModels.join(", ")}`)}},{name:"system",description:"Set the system prompt",usage:"/system <prompt>",category:"settings",execute(t,e){const s=t.trim();if(!s){const o=e.chatSettings.value.systemPrompt||"(none)";e.showNotification(`Current system prompt: ${o}`);return}e.setSystemPrompt(s),e.showNotification("System prompt updated.")}},{name:"temperature",description:"Set temperature (0-2)",usage:"/temperature <value>",category:"settings",execute(t,e){const s=parseFloat(t.trim());if(isNaN(s)||s<0||s>2){e.showNotification(`Current: ${e.chatSettings.value.options.temperature??.7}. Usage: /temperature 0.0-2.0`);return}e.setOption("temperature",s),e.showNotification(`Temperature set to ${s}.`)}},{name:"top_p",description:"Set top-p / nucleus sampling (0-1)",usage:"/top_p <value>",category:"settings",execute(t,e){const s=parseFloat(t.trim());if(isNaN(s)||s<0||s>1){e.showNotification(`Current: ${e.chatSettings.value.options.top_p??.9}. Usage: /top_p 0.0-1.0`);return}e.setOption("top_p",s),e.showNotification(`Top-p set to ${s}.`)}},{name:"top_k",description:"Set top-k sampling (1-100)",usage:"/top_k <value>",category:"settings",execute(t,e){const s=parseInt(t.trim(),10);if(isNaN(s)||s<1||s>100){e.showNotification(`Current: ${e.chatSettings.value.options.top_k??40}. Usage: /top_k 1-100`);return}e.setOption("top_k",s),e.showNotification(`Top-k set to ${s}.`)}},{name:"context",description:"Set context window size",usage:"/context <size>",category:"settings",execute(t,e){const s=parseInt(t.trim(),10),o=[2048,4096,8192,16384,32768,65536,131072];if(isNaN(s)||!o.includes(s)){e.showNotification(`Current: ${_e(e.chatSettings.value.options.num_ctx??4096)}. Valid sizes: ${o.join(", ")}`);return}e.setOption("num_ctx",s),e.showNotification(`Context window set to ${_e(s)}.`)}},{name:"repeat_penalty",description:"Set repeat penalty (1.0-2.0)",usage:"/repeat_penalty <value>",category:"settings",execute(t,e){const s=parseFloat(t.trim());if(isNaN(s)||s<1||s>2){e.showNotification(`Current: ${e.chatSettings.value.options.repeat_penalty??1.1}. Usage: /repeat_penalty 1.0-2.0`);return}e.setOption("repeat_penalty",s),e.showNotification(`Repeat penalty set to ${s}.`)}},{name:"seed",description:"Set seed for reproducibility (-1 for random)",usage:"/seed <value>",category:"settings",execute(t,e){const s=parseInt(t.trim(),10);if(isNaN(s)){e.showNotification(`Current: ${e.chatSettings.value.options.seed??-1}. Usage: /seed <number>`);return}e.setOption("seed",s===-1?void 0:s),e.showNotification(s===-1?"Seed set to random.":`Seed set to ${s}.`)}},{name:"stop",description:"Set stop sequences (comma-separated)",usage:"/stop <sequences>",category:"settings",execute(t,e){const s=t.trim();if(!s){const n=e.chatSettings.value.options.stop?.join(", ")||"(none)";e.showNotification(`Current stop sequences: ${n}`);return}const o=s.split(",").map(n=>n.trim()).filter(Boolean);e.setOption("stop",o.length>0?o:void 0),e.showNotification(`Stop sequences set: ${o.join(", ")}`)}},{name:"mirostat",description:"Set mirostat mode (0=off, 1=v1, 2=v2)",usage:"/mirostat <0|1|2>",category:"settings",execute(t,e){const s=parseInt(t.trim(),10);if(![0,1,2].includes(s)){e.showNotification(`Current: ${e.chatSettings.value.options.mirostat??0}. Usage: /mirostat 0|1|2`);return}e.setOption("mirostat",s),e.showNotification(s===0?"Mirostat disabled.":`Mirostat v${s} enabled.`)}},{name:"format",description:"Toggle JSON output format",usage:"/format [json]",category:"settings",execute(t,e){const s=t.trim().toLowerCase()==="json";e.setJsonFormat(s),e.showNotification(s?"JSON format enabled.":"JSON format disabled.")}},{name:"reset",description:"Reset all settings to defaults",usage:"/reset",category:"settings",execute(t,e){e.resetSettings(),e.showNotification("All settings reset to defaults.")}},{name:"rag",description:"Toggle RAG context on/off",usage:"/rag",category:"navigation",execute(t,e){e.toggleRag(),e.showNotification(e.ragEnabled?"RAG context disabled.":"RAG context enabled.")}},{name:"tools",description:"Open tools settings panel",usage:"/tools",category:"navigation",execute(t,e){e.openSettings(),e.showNotification("Settings panel opened.")}},{name:"status",description:"Show Ollama connection status and model info",usage:"/status",category:"navigation",async execute(t,e){const s=await e.getOllamaStatus();e.showNotification(`Ollama: ${s.connected?"Connected":"Disconnected"}
6
- Model: ${s.model||"(none)"}`)}},{name:"tokens",description:"Show token count for current session",usage:"/tokens",category:"navigation",execute(t,e){const s=e.getSessionTokenCount();if(!s){e.showNotification("No active session.");return}e.showNotification(`Prompt tokens: ${_e(s.prompt)}
7
- Completion tokens: ${_e(s.completion)}
8
- Total: ${_e(s.prompt+s.completion)}`)}},{name:"speed",description:"Show average generation speed across sessions",usage:"/speed",category:"navigation",execute(t,e){const s=e.getAverageSpeed();if(s===null){e.showNotification("No sessions recorded yet.");return}e.showNotification(`Average speed: ${qe(s)}`)}},{name:"compare",description:"Navigate to the Compare page",usage:"/compare",category:"navigation",execute(t,e){e.navigate("/compare")}},{name:"session",description:"View current session details",usage:"/session",category:"navigation",execute(t,e){e.openSessionDetails()}},{name:"remember",description:"Remember a fact about you across conversations",usage:"/remember <fact>",category:"memory",execute(t,e){const s=t.trim();if(!s){e.showNotification(`Usage: /remember <something to remember>
9
- Example: /remember I prefer TypeScript over JavaScript`);return}e.addFact(s),e.showNotification(`Remembered: "${s}"`)}},{name:"forget",description:"Forget a previously remembered fact",usage:"/forget <search>",category:"memory",execute(t,e){const s=t.trim();if(!s){e.showNotification(`Usage: /forget <part of the fact to remove>
10
- Example: /forget TypeScript`);return}e.removeFact(s)?e.showNotification(`Forgot fact matching "${s}".`):e.showNotification(`No fact found matching "${s}". Use /memories to see all facts.`)}},{name:"memories",description:"Show all remembered facts",usage:"/memories",category:"memory",execute(t,e){const s=e.getFacts();if(s.length===0){e.showNotification("No memories stored yet. Use /remember <fact> to add one.");return}const o=s.map((n,l)=>`${l+1}. ${n.content}`);e.showNotification(`Your memories (${s.length}):
11
- ${o.join(`
12
- `)}`)}}];function hn(t){const e=t.toLowerCase().replace(/^\//,"");return e?He.filter(s=>s.name.startsWith(e)):He}function mn(t){return He.find(e=>e.name===t.toLowerCase())}function Jt(){const t={};for(const e of He){const s=e.category==="chat"?"Chat & Conversation":e.category==="settings"?"Model & Settings":e.category==="memory"?"Memory":"Features & Navigation";(t[s]??=[]).push(e)}return t}const Tt={slidingWindow:{enabled:!0,maxMessages:50},autoSummarize:{enabled:!1,triggerThreshold:30},ragMemory:{enabled:!1,embeddingModel:"",topK:3},userFacts:{enabled:!0}},Mt="llmxray-memory-settings",Rt="llmxray-user-facts";function At(t,e){try{const s=localStorage.getItem(t);return s?JSON.parse(s):e}catch{return e}}function Nt(t,e){localStorage.setItem(t,JSON.stringify(e))}const Qt=Ms("memory",()=>{const t=N(At(Mt,{...Tt}));te(t,C=>Nt(Mt,C),{deep:!0});function e(C){t.value={...t.value,...C}}function s(){t.value={...Tt}}const o=N(At(Rt,[]));te(o,C=>Nt(Rt,C),{deep:!0});const n=F(()=>o.value.length);function l(C){const M={id:be(),content:C.trim(),createdAt:Date.now()};return o.value=[...o.value,M],M}function a(C){o.value=o.value.filter(M=>M.id!==C)}function c(C){const M=C.toLowerCase().trim(),_=o.value.findIndex(j=>j.content.toLowerCase().includes(M));return _===-1?!1:(o.value=[...o.value.slice(0,_),...o.value.slice(_+1)],!0)}function i(){o.value=[]}function p(){return o.value.length===0?"":`The user has asked you to remember these facts about them:
13
- ${o.value.map(M=>`- ${M.content}`).join(`
14
- `)}
15
-
16
- Keep these in mind when responding.`}const u=N(new Map);function h(C,M,_){u.value.set(C,{conversationId:C,summary:M,messageCount:_,createdAt:Date.now()})}function b(C){return u.value.get(C)}function S(C){u.value.delete(C)}return{settings:t,updateSettings:e,resetSettings:s,facts:o,factCount:n,addFact:l,removeFact:a,removeFactByContent:c,clearFacts:i,getFactsAsSystemPrompt:p,summaries:u,setSummary:h,getSummary:b,clearSummary:S}});async function gn(t){let e=[...t.messages],s;t.settings.userFacts.enabled&&t.userFactsPrompt&&e.unshift({role:"system",content:t.userFactsPrompt});const o=e.filter(n=>n.role!=="system");if(t.settings.autoSummarize.enabled&&o.length>t.settings.autoSummarize.triggerThreshold){const n=Math.floor(t.settings.autoSummarize.triggerThreshold/3),l=e.filter(u=>u.role==="system"),a=o.slice(0,-n),c=o.slice(-n),i=t.existingSummary?`Previous summary:
17
- ${t.existingSummary}
18
-
19
- New messages to incorporate:
20
- `:"",p=await xn(t.model,i+a.map(u=>`${u.role}: ${u.content}`).join(`
21
- `));p&&(s=p,e=[...l,{role:"system",content:`Summary of earlier conversation:
22
- ${p}`},...c])}if(t.settings.slidingWindow.enabled){const n=e.filter(c=>c.role==="system"),l=e.filter(c=>c.role!=="system"),a=t.settings.slidingWindow.maxMessages;if(l.length>a){const c=l.slice(-a);e=[...n,...c]}}if(t.settings.ragMemory.enabled&&t.settings.ragMemory.embeddingModel)try{const n=await bn(t.conversationId,e,t.settings.ragMemory.embeddingModel,t.settings.ragMemory.topK);if(n){const l=e.filter(c=>c.role==="system"),a=e.filter(c=>c.role!=="system");e=[...l,{role:"system",content:n},...a]}}catch{}return{messages:e,newSummary:s}}async function fn(t,e,s){if(!s||e.length===0)return;const o=e.map(a=>a.content),n=await Ie.embed({model:s,input:o}),l=[];for(let a=0;a<e.length;a++){const c=n.embeddings[a];if(!c)continue;const i=e[a];l.push({id:be(),conversationId:t,role:i.role,content:i.content,embedding:c,timestamp:i.timestamp})}await Zt.storeMessages(l)}async function xn(t,e){try{return(await Ie.chat({model:t,messages:[{role:"system",content:"You are a helpful assistant. Summarize the following conversation concisely, preserving key facts, decisions, and context that would be important for continuing the conversation. Keep it under 300 words."},{role:"user",content:e}],stream:!1})).message.content.trim()||null}catch{return null}}async function bn(t,e,s,o){const n=e.filter(h=>h.role==="user"),l=n[n.length-1];if(!l)return null;const c=(await Ie.embed({model:s,input:[l.content]})).embeddings[0];if(!c)return null;const p=(await Zt.search(c,o,t)).filter(h=>h.score>.5);return p.length===0?null:`Relevant messages from past conversations:
23
- ${p.map(h=>`[${h.message.role}, relevance: ${(h.score*100).toFixed(0)}%] ${h.message.content}`).join(`
24
-
25
- `)}
26
-
27
- Use this context if helpful, but prioritize the current conversation.`}function it(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var we=it();function Xt(t){we=t}var ye={exec:()=>null};function E(t,e=""){let s=typeof t=="string"?t:t.source,o={replace:(n,l)=>{let a=typeof l=="string"?l:l.source;return a=a.replace(Z.caret,"$1"),s=s.replace(n,a),o},getRegex:()=>new RegExp(s,e)};return o}var vn=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),Z={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}>`)},yn=/^(?:[ \t]*(?:\n|$))+/,kn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,wn=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,De=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,$n=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ct=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Yt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,es=E(Yt).replace(/bull/g,ct).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Sn=E(Yt).replace(/bull/g,ct).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ut=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,_n=/^[^\n]+/,dt=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,Cn=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",dt).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Tn=E(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ct).getRegex(),Qe="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",pt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Mn=E("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",pt).replace("tag",Qe).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ts=E(ut).replace("hr",De).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),Rn=E(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ts).getRegex(),ht={blockquote:Rn,code:kn,def:Cn,fences:wn,heading:$n,hr:De,html:Mn,lheading:es,list:Tn,newline:yn,paragraph:ts,table:ye,text:_n},zt=E("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",De).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex(),An={...ht,lheading:Sn,table:zt,paragraph:E(ut).replace("hr",De).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",zt).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Qe).getRegex()},Nn={...ht,html:E(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",pt).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ye,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(ut).replace("hr",De).replace("heading",` *#{1,6} *[^
28
- ]`).replace("lheading",es).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},zn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,En=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ss=/^( {2,}|\\)\n(?!\s*$)/,Pn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Xe=/[\p{P}\p{S}]/u,mt=/[\s\p{P}\p{S}]/u,ns=/[^\s\p{P}\p{S}]/u,In=E(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,mt).getRegex(),os=/(?!~)[\p{P}\p{S}]/u,Dn=/(?!~)[\s\p{P}\p{S}]/u,jn=/(?:[^\s\p{P}\p{S}]|~)/u,as=/(?![*_])[\p{P}\p{S}]/u,Ln=/(?![*_])[\s\p{P}\p{S}]/u,Bn=/(?:[^\s\p{P}\p{S}]|[*_])/u,Fn=E(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",vn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),rs=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,On=E(rs,"u").replace(/punct/g,Xe).getRegex(),Un=E(rs,"u").replace(/punct/g,os).getRegex(),ls="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Vn=E(ls,"gu").replace(/notPunctSpace/g,ns).replace(/punctSpace/g,mt).replace(/punct/g,Xe).getRegex(),qn=E(ls,"gu").replace(/notPunctSpace/g,jn).replace(/punctSpace/g,Dn).replace(/punct/g,os).getRegex(),Hn=E("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ns).replace(/punctSpace/g,mt).replace(/punct/g,Xe).getRegex(),Wn=E(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,as).getRegex(),Gn="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Zn=E(Gn,"gu").replace(/notPunctSpace/g,Bn).replace(/punctSpace/g,Ln).replace(/punct/g,as).getRegex(),Kn=E(/\\(punct)/,"gu").replace(/punct/g,Xe).getRegex(),Jn=E(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Qn=E(pt).replace("(?:-->|$)","-->").getRegex(),Xn=E("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Qn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),We=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Yn=E(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",We).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),is=E(/^!?\[(label)\]\[(ref)\]/).replace("label",We).replace("ref",dt).getRegex(),cs=E(/^!?\[(ref)\](?:\[\])?/).replace("ref",dt).getRegex(),eo=E("reflink|nolink(?!\\()","g").replace("reflink",is).replace("nolink",cs).getRegex(),Et=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,gt={_backpedal:ye,anyPunctuation:Kn,autolink:Jn,blockSkip:Fn,br:ss,code:En,del:ye,delLDelim:ye,delRDelim:ye,emStrongLDelim:On,emStrongRDelimAst:Vn,emStrongRDelimUnd:Hn,escape:zn,link:Yn,nolink:cs,punctuation:In,reflink:is,reflinkSearch:eo,tag:Xn,text:Pn,url:ye},to={...gt,link:E(/^!?\[(label)\]\((.*?)\)/).replace("label",We).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",We).getRegex()},tt={...gt,emStrongRDelimAst:qn,emStrongLDelim:Un,delLDelim:Wn,delRDelim:Zn,url:E(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Et).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:E(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Et).getRegex()},so={...tt,br:E(ss).replace("{2,}","*").getRegex(),text:E(tt.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},Ue={normal:ht,gfm:An,pedantic:Nn},Re={normal:gt,gfm:tt,breaks:so,pedantic:to},no={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Pt=t=>no[t];function ie(t,e){if(e){if(Z.escapeTest.test(t))return t.replace(Z.escapeReplace,Pt)}else if(Z.escapeTestNoEncode.test(t))return t.replace(Z.escapeReplaceNoEncode,Pt);return t}function It(t){try{t=encodeURI(t).replace(Z.percentDecode,"%")}catch{return null}return t}function Dt(t,e){let s=t.replace(Z.findPipe,(l,a,c)=>{let i=!1,p=a;for(;--p>=0&&c[p]==="\\";)i=!i;return i?"|":" |"}),o=s.split(Z.splitPipe),n=0;if(o[0].trim()||o.shift(),o.length>0&&!o.at(-1)?.trim()&&o.pop(),e)if(o.length>e)o.splice(e);else for(;o.length<e;)o.push("");for(;n<o.length;n++)o[n]=o[n].trim().replace(Z.slashPipe,"|");return o}function Ae(t,e,s){let o=t.length;if(o===0)return"";let n=0;for(;n<o&&t.charAt(o-n-1)===e;)n++;return t.slice(0,o-n)}function oo(t,e){if(t.indexOf(e[1])===-1)return-1;let s=0;for(let o=0;o<t.length;o++)if(t[o]==="\\")o++;else if(t[o]===e[0])s++;else if(t[o]===e[1]&&(s--,s<0))return o;return s>0?-2:-1}function ao(t,e=0){let s=e,o="";for(let n of t)if(n===" "){let l=4-s%4;o+=" ".repeat(l),s+=l}else o+=n,s++;return o}function jt(t,e,s,o,n){let l=e.href,a=e.title||null,c=t[1].replace(n.other.outputLinkReplace,"$1");o.state.inLink=!0;let i={type:t[0].charAt(0)==="!"?"image":"link",raw:s,href:l,title:a,text:c,tokens:o.inlineTokens(c)};return o.state.inLink=!1,i}function ro(t,e,s){let o=t.match(s.other.indentCodeCompensation);if(o===null)return e;let n=o[1];return e.split(`
29
- `).map(l=>{let a=l.match(s.other.beginningSpace);if(a===null)return l;let[c]=a;return c.length>=n.length?l.slice(n.length):l}).join(`
30
- `)}var Ge=class{options;rules;lexer;constructor(t){this.options=t||we}space(t){let e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){let e=this.rules.block.code.exec(t);if(e){let s=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?s:Ae(s,`
31
- `)}}}fences(t){let e=this.rules.block.fences.exec(t);if(e){let s=e[0],o=ro(s,e[3]||"",this.rules);return{type:"code",raw:s,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:o}}}heading(t){let e=this.rules.block.heading.exec(t);if(e){let s=e[2].trim();if(this.rules.other.endingHash.test(s)){let o=Ae(s,"#");(this.options.pedantic||!o||this.rules.other.endingSpaceChar.test(o))&&(s=o.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:s,tokens:this.lexer.inline(s)}}}hr(t){let e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:Ae(e[0],`
32
- `)}}blockquote(t){let e=this.rules.block.blockquote.exec(t);if(e){let s=Ae(e[0],`
33
- `).split(`
34
- `),o="",n="",l=[];for(;s.length>0;){let a=!1,c=[],i;for(i=0;i<s.length;i++)if(this.rules.other.blockquoteStart.test(s[i]))c.push(s[i]),a=!0;else if(!a)c.push(s[i]);else break;s=s.slice(i);let p=c.join(`
35
- `),u=p.replace(this.rules.other.blockquoteSetextReplace,`
36
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");o=o?`${o}
37
- ${p}`:p,n=n?`${n}
38
- ${u}`:u;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,l,!0),this.lexer.state.top=h,s.length===0)break;let b=l.at(-1);if(b?.type==="code")break;if(b?.type==="blockquote"){let S=b,C=S.raw+`
39
- `+s.join(`
40
- `),M=this.blockquote(C);l[l.length-1]=M,o=o.substring(0,o.length-S.raw.length)+M.raw,n=n.substring(0,n.length-S.text.length)+M.text;break}else if(b?.type==="list"){let S=b,C=S.raw+`
41
- `+s.join(`
42
- `),M=this.list(C);l[l.length-1]=M,o=o.substring(0,o.length-b.raw.length)+M.raw,n=n.substring(0,n.length-S.raw.length)+M.raw,s=C.substring(l.at(-1).raw.length).split(`
43
- `);continue}}return{type:"blockquote",raw:o,tokens:l,text:n}}}list(t){let e=this.rules.block.list.exec(t);if(e){let s=e[1].trim(),o=s.length>1,n={type:"list",raw:"",ordered:o,start:o?+s.slice(0,-1):"",loose:!1,items:[]};s=o?`\\d{1,9}\\${s.slice(-1)}`:`\\${s}`,this.options.pedantic&&(s=o?s:"[*+-]");let l=this.rules.other.listItemRegex(s),a=!1;for(;t;){let i=!1,p="",u="";if(!(e=l.exec(t))||this.rules.block.hr.test(t))break;p=e[0],t=t.substring(p.length);let h=ao(e[2].split(`
44
- `,1)[0],e[1].length),b=t.split(`
45
- `,1)[0],S=!h.trim(),C=0;if(this.options.pedantic?(C=2,u=h.trimStart()):S?C=e[1].length+1:(C=h.search(this.rules.other.nonSpaceChar),C=C>4?1:C,u=h.slice(C),C+=e[1].length),S&&this.rules.other.blankLine.test(b)&&(p+=b+`
46
- `,t=t.substring(b.length+1),i=!0),!i){let M=this.rules.other.nextBulletRegex(C),_=this.rules.other.hrRegex(C),j=this.rules.other.fencesBeginRegex(C),U=this.rules.other.headingBeginRegex(C),q=this.rules.other.htmlBeginRegex(C),K=this.rules.other.blockquoteBeginRegex(C);for(;t;){let V=t.split(`
47
- `,1)[0],J;if(b=V,this.options.pedantic?(b=b.replace(this.rules.other.listReplaceNesting," "),J=b):J=b.replace(this.rules.other.tabCharGlobal," "),j.test(b)||U.test(b)||q.test(b)||K.test(b)||M.test(b)||_.test(b))break;if(J.search(this.rules.other.nonSpaceChar)>=C||!b.trim())u+=`
48
- `+J.slice(C);else{if(S||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||j.test(h)||U.test(h)||_.test(h))break;u+=`
49
- `+b}S=!b.trim(),p+=V+`
50
- `,t=t.substring(V.length+1),h=J.slice(C)}}n.loose||(a?n.loose=!0:this.rules.other.doubleBlankLine.test(p)&&(a=!0)),n.items.push({type:"list_item",raw:p,task:!!this.options.gfm&&this.rules.other.listIsTask.test(u),loose:!1,text:u,tokens:[]}),n.raw+=p}let c=n.items.at(-1);if(c)c.raw=c.raw.trimEnd(),c.text=c.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let i of n.items){if(this.lexer.state.top=!1,i.tokens=this.lexer.blockTokens(i.text,[]),i.task){if(i.text=i.text.replace(this.rules.other.listReplaceTask,""),i.tokens[0]?.type==="text"||i.tokens[0]?.type==="paragraph"){i.tokens[0].raw=i.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),i.tokens[0].text=i.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let u=this.lexer.inlineQueue.length-1;u>=0;u--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[u].src)){this.lexer.inlineQueue[u].src=this.lexer.inlineQueue[u].src.replace(this.rules.other.listReplaceTask,"");break}}let p=this.rules.other.listTaskCheckbox.exec(i.raw);if(p){let u={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};i.checked=u.checked,n.loose?i.tokens[0]&&["paragraph","text"].includes(i.tokens[0].type)&&"tokens"in i.tokens[0]&&i.tokens[0].tokens?(i.tokens[0].raw=u.raw+i.tokens[0].raw,i.tokens[0].text=u.raw+i.tokens[0].text,i.tokens[0].tokens.unshift(u)):i.tokens.unshift({type:"paragraph",raw:u.raw,text:u.raw,tokens:[u]}):i.tokens.unshift(u)}}if(!n.loose){let p=i.tokens.filter(h=>h.type==="space"),u=p.length>0&&p.some(h=>this.rules.other.anyLine.test(h.raw));n.loose=u}}if(n.loose)for(let i of n.items){i.loose=!0;for(let p of i.tokens)p.type==="text"&&(p.type="paragraph")}return n}}html(t){let e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){let e=this.rules.block.def.exec(t);if(e){let s=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),o=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:s,raw:e[0],href:o,title:n}}}table(t){let e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let s=Dt(e[1]),o=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
51
- `):[],l={type:"table",raw:e[0],header:[],align:[],rows:[]};if(s.length===o.length){for(let a of o)this.rules.other.tableAlignRight.test(a)?l.align.push("right"):this.rules.other.tableAlignCenter.test(a)?l.align.push("center"):this.rules.other.tableAlignLeft.test(a)?l.align.push("left"):l.align.push(null);for(let a=0;a<s.length;a++)l.header.push({text:s[a],tokens:this.lexer.inline(s[a]),header:!0,align:l.align[a]});for(let a of n)l.rows.push(Dt(a,l.header.length).map((c,i)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:l.align[i]})));return l}}lheading(t){let e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){let e=this.rules.block.paragraph.exec(t);if(e){let s=e[1].charAt(e[1].length-1)===`
52
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:s,tokens:this.lexer.inline(s)}}}text(t){let e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){let e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){let e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){let e=this.rules.inline.link.exec(t);if(e){let s=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(s)){if(!this.rules.other.endAngleBracket.test(s))return;let l=Ae(s.slice(0,-1),"\\");if((s.length-l.length)%2===0)return}else{let l=oo(e[2],"()");if(l===-2)return;if(l>-1){let a=(e[0].indexOf("!")===0?5:4)+e[1].length+l;e[2]=e[2].substring(0,l),e[0]=e[0].substring(0,a).trim(),e[3]=""}}let o=e[2],n="";if(this.options.pedantic){let l=this.rules.other.pedanticHrefTitle.exec(o);l&&(o=l[1],n=l[3])}else n=e[3]?e[3].slice(1,-1):"";return o=o.trim(),this.rules.other.startAngleBracket.test(o)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(s)?o=o.slice(1):o=o.slice(1,-1)),jt(e,{href:o&&o.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let s;if((s=this.rules.inline.reflink.exec(t))||(s=this.rules.inline.nolink.exec(t))){let o=(s[2]||s[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[o.toLowerCase()];if(!n){let l=s[0].charAt(0);return{type:"text",raw:l,text:l}}return jt(s,n,s[0],this.lexer,this.rules)}}emStrong(t,e,s=""){let o=this.rules.inline.emStrongLDelim.exec(t);if(!(!o||o[3]&&s.match(this.rules.other.unicodeAlphaNumeric))&&(!(o[1]||o[2])||!s||this.rules.inline.punctuation.exec(s))){let n=[...o[0]].length-1,l,a,c=n,i=0,p=o[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(p.lastIndex=0,e=e.slice(-1*t.length+n);(o=p.exec(e))!=null;){if(l=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!l)continue;if(a=[...l].length,o[3]||o[4]){c+=a;continue}else if((o[5]||o[6])&&n%3&&!((n+a)%3)){i+=a;continue}if(c-=a,c>0)continue;a=Math.min(a,a+c+i);let u=[...o[0]][0].length,h=t.slice(0,n+o.index+u+a);if(Math.min(n,a)%2){let S=h.slice(1,-1);return{type:"em",raw:h,text:S,tokens:this.lexer.inlineTokens(S)}}let b=h.slice(2,-2);return{type:"strong",raw:h,text:b,tokens:this.lexer.inlineTokens(b)}}}}codespan(t){let e=this.rules.inline.code.exec(t);if(e){let s=e[2].replace(this.rules.other.newLineCharGlobal," "),o=this.rules.other.nonSpaceChar.test(s),n=this.rules.other.startingSpaceChar.test(s)&&this.rules.other.endingSpaceChar.test(s);return o&&n&&(s=s.substring(1,s.length-1)),{type:"codespan",raw:e[0],text:s}}}br(t){let e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t,e,s=""){let o=this.rules.inline.delLDelim.exec(t);if(o&&(!o[1]||!s||this.rules.inline.punctuation.exec(s))){let n=[...o[0]].length-1,l,a,c=n,i=this.rules.inline.delRDelim;for(i.lastIndex=0,e=e.slice(-1*t.length+n);(o=i.exec(e))!=null;){if(l=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!l||(a=[...l].length,a!==n))continue;if(o[3]||o[4]){c+=a;continue}if(c-=a,c>0)continue;a=Math.min(a,a+c);let p=[...o[0]][0].length,u=t.slice(0,n+o.index+p+a),h=u.slice(n,-n);return{type:"del",raw:u,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(t){let e=this.rules.inline.autolink.exec(t);if(e){let s,o;return e[2]==="@"?(s=e[1],o="mailto:"+s):(s=e[1],o=s),{type:"link",raw:e[0],text:s,href:o,tokens:[{type:"text",raw:s,text:s}]}}}url(t){let e;if(e=this.rules.inline.url.exec(t)){let s,o;if(e[2]==="@")s=e[0],o="mailto:"+s;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);s=e[0],e[1]==="www."?o="http://"+e[0]:o=e[0]}return{type:"link",raw:e[0],text:s,href:o,tokens:[{type:"text",raw:s,text:s}]}}}inlineText(t){let e=this.rules.inline.text.exec(t);if(e){let s=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:s}}}},oe=class st{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||we,this.options.tokenizer=this.options.tokenizer||new Ge,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let s={other:Z,block:Ue.normal,inline:Re.normal};this.options.pedantic?(s.block=Ue.pedantic,s.inline=Re.pedantic):this.options.gfm&&(s.block=Ue.gfm,this.options.breaks?s.inline=Re.breaks:s.inline=Re.gfm),this.tokenizer.rules=s}static get rules(){return{block:Ue,inline:Re}}static lex(e,s){return new st(s).lex(e)}static lexInline(e,s){return new st(s).inlineTokens(e)}lex(e){e=e.replace(Z.carriageReturn,`
53
- `),this.blockTokens(e,this.tokens);for(let s=0;s<this.inlineQueue.length;s++){let o=this.inlineQueue[s];this.inlineTokens(o.src,o.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,s=[],o=!1){for(this.options.pedantic&&(e=e.replace(Z.tabCharGlobal," ").replace(Z.spaceLine,""));e;){let n;if(this.options.extensions?.block?.some(a=>(n=a.call({lexer:this},e,s))?(e=e.substring(n.raw.length),s.push(n),!0):!1))continue;if(n=this.tokenizer.space(e)){e=e.substring(n.raw.length);let a=s.at(-1);n.raw.length===1&&a!==void 0?a.raw+=`
54
- `:s.push(n);continue}if(n=this.tokenizer.code(e)){e=e.substring(n.raw.length);let a=s.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
55
- `)?"":`
56
- `)+n.raw,a.text+=`
57
- `+n.text,this.inlineQueue.at(-1).src=a.text):s.push(n);continue}if(n=this.tokenizer.fences(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.heading(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.hr(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.blockquote(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.list(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.html(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.def(e)){e=e.substring(n.raw.length);let a=s.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
58
- `)?"":`
59
- `)+n.raw,a.text+=`
60
- `+n.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title},s.push(n));continue}if(n=this.tokenizer.table(e)){e=e.substring(n.raw.length),s.push(n);continue}if(n=this.tokenizer.lheading(e)){e=e.substring(n.raw.length),s.push(n);continue}let l=e;if(this.options.extensions?.startBlock){let a=1/0,c=e.slice(1),i;this.options.extensions.startBlock.forEach(p=>{i=p.call({lexer:this},c),typeof i=="number"&&i>=0&&(a=Math.min(a,i))}),a<1/0&&a>=0&&(l=e.substring(0,a+1))}if(this.state.top&&(n=this.tokenizer.paragraph(l))){let a=s.at(-1);o&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`
61
- `)?"":`
62
- `)+n.raw,a.text+=`
63
- `+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):s.push(n),o=l.length!==e.length,e=e.substring(n.raw.length);continue}if(n=this.tokenizer.text(e)){e=e.substring(n.raw.length);let a=s.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`
64
- `)?"":`
65
- `)+n.raw,a.text+=`
66
- `+n.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):s.push(n);continue}if(e){let a="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,s}inline(e,s=[]){return this.inlineQueue.push({src:e,tokens:s}),s}inlineTokens(e,s=[]){let o=e,n=null;if(this.tokens.links){let i=Object.keys(this.tokens.links);if(i.length>0)for(;(n=this.tokenizer.rules.inline.reflinkSearch.exec(o))!=null;)i.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(o=o.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+o.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(n=this.tokenizer.rules.inline.anyPunctuation.exec(o))!=null;)o=o.slice(0,n.index)+"++"+o.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let l;for(;(n=this.tokenizer.rules.inline.blockSkip.exec(o))!=null;)l=n[2]?n[2].length:0,o=o.slice(0,n.index+l)+"["+"a".repeat(n[0].length-l-2)+"]"+o.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);o=this.options.hooks?.emStrongMask?.call({lexer:this},o)??o;let a=!1,c="";for(;e;){a||(c=""),a=!1;let i;if(this.options.extensions?.inline?.some(u=>(i=u.call({lexer:this},e,s))?(e=e.substring(i.raw.length),s.push(i),!0):!1))continue;if(i=this.tokenizer.escape(e)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.tag(e)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.link(e)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(i.raw.length);let u=s.at(-1);i.type==="text"&&u?.type==="text"?(u.raw+=i.raw,u.text+=i.text):s.push(i);continue}if(i=this.tokenizer.emStrong(e,o,c)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.codespan(e)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.br(e)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.del(e,o,c)){e=e.substring(i.raw.length),s.push(i);continue}if(i=this.tokenizer.autolink(e)){e=e.substring(i.raw.length),s.push(i);continue}if(!this.state.inLink&&(i=this.tokenizer.url(e))){e=e.substring(i.raw.length),s.push(i);continue}let p=e;if(this.options.extensions?.startInline){let u=1/0,h=e.slice(1),b;this.options.extensions.startInline.forEach(S=>{b=S.call({lexer:this},h),typeof b=="number"&&b>=0&&(u=Math.min(u,b))}),u<1/0&&u>=0&&(p=e.substring(0,u+1))}if(i=this.tokenizer.inlineText(p)){e=e.substring(i.raw.length),i.raw.slice(-1)!=="_"&&(c=i.raw.slice(-1)),a=!0;let u=s.at(-1);u?.type==="text"?(u.raw+=i.raw,u.text+=i.text):s.push(i);continue}if(e){let u="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(u);break}else throw new Error(u)}}return s}},Ze=class{options;parser;constructor(t){this.options=t||we}space(t){return""}code({text:t,lang:e,escaped:s}){let o=(e||"").match(Z.notSpaceStart)?.[0],n=t.replace(Z.endingNewline,"")+`
67
- `;return o?'<pre><code class="language-'+ie(o)+'">'+(s?n:ie(n,!0))+`</code></pre>
68
- `:"<pre><code>"+(s?n:ie(n,!0))+`</code></pre>
69
- `}blockquote({tokens:t}){return`<blockquote>
70
- ${this.parser.parse(t)}</blockquote>
71
- `}html({text:t}){return t}def(t){return""}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
72
- `}hr(t){return`<hr>
73
- `}list(t){let e=t.ordered,s=t.start,o="";for(let a=0;a<t.items.length;a++){let c=t.items[a];o+=this.listitem(c)}let n=e?"ol":"ul",l=e&&s!==1?' start="'+s+'"':"";return"<"+n+l+`>
74
- `+o+"</"+n+`>
75
- `}listitem(t){return`<li>${this.parser.parse(t.tokens)}</li>
76
- `}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
77
- `}table(t){let e="",s="";for(let n=0;n<t.header.length;n++)s+=this.tablecell(t.header[n]);e+=this.tablerow({text:s});let o="";for(let n=0;n<t.rows.length;n++){let l=t.rows[n];s="";for(let a=0;a<l.length;a++)s+=this.tablecell(l[a]);o+=this.tablerow({text:s})}return o&&(o=`<tbody>${o}</tbody>`),`<table>
78
- <thead>
79
- `+e+`</thead>
80
- `+o+`</table>
81
- `}tablerow({text:t}){return`<tr>
82
- ${t}</tr>
83
- `}tablecell(t){let e=this.parser.parseInline(t.tokens),s=t.header?"th":"td";return(t.align?`<${s} align="${t.align}">`:`<${s}>`)+e+`</${s}>
84
- `}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${ie(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:s}){let o=this.parser.parseInline(s),n=It(t);if(n===null)return o;t=n;let l='<a href="'+t+'"';return e&&(l+=' title="'+ie(e)+'"'),l+=">"+o+"</a>",l}image({href:t,title:e,text:s,tokens:o}){o&&(s=this.parser.parseInline(o,this.parser.textRenderer));let n=It(t);if(n===null)return ie(s);t=n;let l=`<img src="${t}" alt="${ie(s)}"`;return e&&(l+=` title="${ie(e)}"`),l+=">",l}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:ie(t.text)}},ft=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}checkbox({raw:t}){return t}},ae=class nt{options;renderer;textRenderer;constructor(e){this.options=e||we,this.options.renderer=this.options.renderer||new Ze,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ft}static parse(e,s){return new nt(s).parse(e)}static parseInline(e,s){return new nt(s).parseInline(e)}parse(e){let s="";for(let o=0;o<e.length;o++){let n=e[o];if(this.options.extensions?.renderers?.[n.type]){let a=n,c=this.options.extensions.renderers[a.type].call({parser:this},a);if(c!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){s+=c||"";continue}}let l=n;switch(l.type){case"space":{s+=this.renderer.space(l);break}case"hr":{s+=this.renderer.hr(l);break}case"heading":{s+=this.renderer.heading(l);break}case"code":{s+=this.renderer.code(l);break}case"table":{s+=this.renderer.table(l);break}case"blockquote":{s+=this.renderer.blockquote(l);break}case"list":{s+=this.renderer.list(l);break}case"checkbox":{s+=this.renderer.checkbox(l);break}case"html":{s+=this.renderer.html(l);break}case"def":{s+=this.renderer.def(l);break}case"paragraph":{s+=this.renderer.paragraph(l);break}case"text":{s+=this.renderer.text(l);break}default:{let a='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}parseInline(e,s=this.renderer){let o="";for(let n=0;n<e.length;n++){let l=e[n];if(this.options.extensions?.renderers?.[l.type]){let c=this.options.extensions.renderers[l.type].call({parser:this},l);if(c!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(l.type)){o+=c||"";continue}}let a=l;switch(a.type){case"escape":{o+=s.text(a);break}case"html":{o+=s.html(a);break}case"link":{o+=s.link(a);break}case"image":{o+=s.image(a);break}case"checkbox":{o+=s.checkbox(a);break}case"strong":{o+=s.strong(a);break}case"em":{o+=s.em(a);break}case"codespan":{o+=s.codespan(a);break}case"br":{o+=s.br(a);break}case"del":{o+=s.del(a);break}case"text":{o+=s.text(a);break}default:{let c='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return o}},Ne=class{options;block;constructor(t){this.options=t||we}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}emStrongMask(t){return t}provideLexer(){return this.block?oe.lex:oe.lexInline}provideParser(){return this.block?ae.parse:ae.parseInline}},us=class{defaults=it();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=ae;Renderer=Ze;TextRenderer=ft;Lexer=oe;Tokenizer=Ge;Hooks=Ne;constructor(...t){this.use(...t)}walkTokens(t,e){let s=[];for(let o of t)switch(s=s.concat(e.call(this,o)),o.type){case"table":{let n=o;for(let l of n.header)s=s.concat(this.walkTokens(l.tokens,e));for(let l of n.rows)for(let a of l)s=s.concat(this.walkTokens(a.tokens,e));break}case"list":{let n=o;s=s.concat(this.walkTokens(n.items,e));break}default:{let n=o;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(l=>{let a=n[l].flat(1/0);s=s.concat(this.walkTokens(a,e))}):n.tokens&&(s=s.concat(this.walkTokens(n.tokens,e)))}}return s}use(...t){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(s=>{let o={...s};if(o.async=this.defaults.async||o.async||!1,s.extensions&&(s.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let l=e.renderers[n.name];l?e.renderers[n.name]=function(...a){let c=n.renderer.apply(this,a);return c===!1&&(c=l.apply(this,a)),c}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let l=e[n.level];l?l.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),o.extensions=e),s.renderer){let n=this.defaults.renderer||new Ze(this.defaults);for(let l in s.renderer){if(!(l in n))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let a=l,c=s.renderer[a],i=n[a];n[a]=(...p)=>{let u=c.apply(n,p);return u===!1&&(u=i.apply(n,p)),u||""}}o.renderer=n}if(s.tokenizer){let n=this.defaults.tokenizer||new Ge(this.defaults);for(let l in s.tokenizer){if(!(l in n))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let a=l,c=s.tokenizer[a],i=n[a];n[a]=(...p)=>{let u=c.apply(n,p);return u===!1&&(u=i.apply(n,p)),u}}o.tokenizer=n}if(s.hooks){let n=this.defaults.hooks||new Ne;for(let l in s.hooks){if(!(l in n))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let a=l,c=s.hooks[a],i=n[a];Ne.passThroughHooks.has(l)?n[a]=p=>{if(this.defaults.async&&Ne.passThroughHooksRespectAsync.has(l))return(async()=>{let h=await c.call(n,p);return i.call(n,h)})();let u=c.call(n,p);return i.call(n,u)}:n[a]=(...p)=>{if(this.defaults.async)return(async()=>{let h=await c.apply(n,p);return h===!1&&(h=await i.apply(n,p)),h})();let u=c.apply(n,p);return u===!1&&(u=i.apply(n,p)),u}}o.hooks=n}if(s.walkTokens){let n=this.defaults.walkTokens,l=s.walkTokens;o.walkTokens=function(a){let c=[];return c.push(l.call(this,a)),n&&(c=c.concat(n.call(this,a))),c}}this.defaults={...this.defaults,...o}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return oe.lex(t,e??this.defaults)}parser(t,e){return ae.parse(t,e??this.defaults)}parseMarkdown(t){return(e,s)=>{let o={...s},n={...this.defaults,...o},l=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&o.async===!1)return l(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=t),n.async)return(async()=>{let a=n.hooks?await n.hooks.preprocess(e):e,c=await(n.hooks?await n.hooks.provideLexer():t?oe.lex:oe.lexInline)(a,n),i=n.hooks?await n.hooks.processAllTokens(c):c;n.walkTokens&&await Promise.all(this.walkTokens(i,n.walkTokens));let p=await(n.hooks?await n.hooks.provideParser():t?ae.parse:ae.parseInline)(i,n);return n.hooks?await n.hooks.postprocess(p):p})().catch(l);try{n.hooks&&(e=n.hooks.preprocess(e));let a=(n.hooks?n.hooks.provideLexer():t?oe.lex:oe.lexInline)(e,n);n.hooks&&(a=n.hooks.processAllTokens(a)),n.walkTokens&&this.walkTokens(a,n.walkTokens);let c=(n.hooks?n.hooks.provideParser():t?ae.parse:ae.parseInline)(a,n);return n.hooks&&(c=n.hooks.postprocess(c)),c}catch(a){return l(a)}}}onError(t,e){return s=>{if(s.message+=`
85
- Please report this to https://github.com/markedjs/marked.`,t){let o="<p>An error occurred:</p><pre>"+ie(s.message+"",!0)+"</pre>";return e?Promise.resolve(o):o}if(e)return Promise.reject(s);throw s}}},ke=new us;function B(t,e){return ke.parse(t,e)}B.options=B.setOptions=function(t){return ke.setOptions(t),B.defaults=ke.defaults,Xt(B.defaults),B};B.getDefaults=it;B.defaults=we;B.use=function(...t){return ke.use(...t),B.defaults=ke.defaults,Xt(B.defaults),B};B.walkTokens=function(t,e){return ke.walkTokens(t,e)};B.parseInline=ke.parseInline;B.Parser=ae;B.parser=ae.parse;B.Renderer=Ze;B.TextRenderer=ft;B.Lexer=oe;B.lexer=oe.lex;B.Tokenizer=Ge;B.Hooks=Ne;B.parse=B;B.options;B.setOptions;B.use;B.walkTokens;B.parseInline;ae.parse;oe.lex;const lo=new us({breaks:!0,gfm:!0});function io(t){return t?lo.parse(t):""}const co={key:0,class:"my-2"},uo={key:0,class:"relative inline-flex h-4 w-4 items-center justify-center"},po={key:1,class:"text-text-muted"},ho={key:0,class:"mt-1 ms-2 rounded-lg border-s-2 border-[#a78bfa]/30 bg-surface px-4 py-3 text-sm text-text-secondary leading-relaxed whitespace-pre-wrap max-h-80 overflow-auto"},mo={key:0,class:"inline-flex items-center gap-0.5 ms-1 align-text-bottom"},go=ne({__name:"InlineThinkingBlock",props:{isThinking:{type:Boolean},content:{},completed:{type:Boolean}},setup(t){const e=N(!1);return(s,o)=>t.isThinking||t.completed&&t.content?(m(),x("div",co,[r("button",{class:P(["flex items-center gap-2 rounded-lg px-3 py-1.5 text-xs transition-colors",t.isThinking?"bg-[#a78bfa]/10 text-[#a78bfa]":"bg-surface-overlay text-text-secondary hover:text-text-primary"]),onClick:o[0]||(o[0]=n=>e.value=!e.value)},[t.isThinking?(m(),x("span",uo,[...o[1]||(o[1]=[r("span",{class:"absolute h-full w-full rounded-full border-2 border-[#a78bfa]/30"},null,-1),r("span",{class:"absolute h-full w-full rounded-full border-2 border-transparent border-t-[#a78bfa]",style:{animation:"thinking-orbit 1s linear infinite"}},null,-1),r("span",{class:"h-1.5 w-1.5 rounded-full bg-[#a78bfa]"},null,-1)])])):(m(),x("span",po,"💭")),r("span",null,d(t.isThinking?"Thinking...":"Thought process"),1),r("span",{class:P(["text-text-muted transition-transform",{"rotate-180":e.value}])},"▾",2)],2),e.value?(m(),x("div",ho,[Ce(d(t.content)+" ",1),t.isThinking?(m(),x("span",mo,[...o[2]||(o[2]=[r("span",{class:"h-1 w-1 rounded-full bg-[#a78bfa]",style:{animation:"typing-bounce 1.2s ease-in-out infinite"}},null,-1),r("span",{class:"h-1 w-1 rounded-full bg-[#a78bfa]",style:{animation:"typing-bounce 1.2s ease-in-out 0.2s infinite"}},null,-1),r("span",{class:"h-1 w-1 rounded-full bg-[#a78bfa]",style:{animation:"typing-bounce 1.2s ease-in-out 0.4s infinite"}},null,-1)])])):z("",!0)])):z("",!0)])):z("",!0)}}),fo={class:"text-sm leading-relaxed text-text-primary"},xo=ne({__name:"AssistantTokenStream",props:{sessionId:{}},setup(t){const e=t,s=Wt(),{getColor:o}=Us(As(e,"sessionId")),n=F(()=>s.getTokens(e.sessionId)),l=F(()=>{const a=n.value,c=[];let i=!1,p="";for(const u of a){if(p+=u.text,!i&&p.includes("<think>")){i=!0;const h=p.split("<think>")[0]??"";h&&c.length===0&&c.push({...u,text:h});continue}if(i){if(p.includes("</think>")){i=!1;const h=p.split("</think>").pop()??"",b=u.text;if(h.endsWith(b)&&b.includes("</think>")){const S=b.split("</think>").pop()??"";S&&c.push({...u,text:S})}}continue}c.push(u)}return c});return(a,c)=>(m(),x("div",fo,[(m(!0),x(H,null,X(l.value,i=>(m(),x("span",{key:i.id,class:"inline",style:Rs({borderBottom:`2px solid ${f(o)(i.confidence)}`})},d(i.text),5))),128))]))}}),bo={key:0,class:"mb-1.5 space-y-1.5"},vo=["src","alt","onClick"],yo={class:"mt-0.5 flex items-center gap-1.5 text-[10px] opacity-60"},ko={class:"truncate"},wo={class:"flex flex-wrap gap-1.5"},$o={class:"max-w-[100px] truncate opacity-90"},So={class:"opacity-60"},_o=["src"],Co=ne({__name:"AttachmentBubble",props:{attachments:{}},setup(t){const e=N(null);function s(n){n.content&&(e.value=n.content)}function o(){e.value=null}return(n,l)=>t.attachments.length>0?(m(),x("div",bo,[(m(!0),x(H,null,X(t.attachments.filter(a=>a.type==="image"&&a.content),a=>(m(),x("div",{key:a.id},[r("img",{src:a.content,alt:a.name,class:"max-h-48 max-w-full cursor-pointer rounded-lg object-contain",onClick:c=>s(a)},null,8,vo),r("div",yo,[r("span",ko,d(a.name),1),r("span",null,d(f(et)(a.sizeBytes)),1)])]))),128)),r("div",wo,[(m(!0),x(H,null,X(t.attachments.filter(a=>a.type==="document"),a=>(m(),x("div",{key:a.id,class:"flex items-center gap-1.5 rounded-md bg-white/10 px-2 py-1 text-[11px]"},[I(f(Kt),{class:"h-3.5 w-3.5 opacity-70"}),r("span",$o,d(a.name),1),r("span",So,d(f(et)(a.sizeBytes)),1)]))),128))]),(m(),ze(Ns,{to:"body"},[I(Ft,{"enter-active-class":"transition-opacity duration-150","enter-from-class":"opacity-0","leave-active-class":"transition-opacity duration-150","leave-to-class":"opacity-0"},{default:Bt(()=>[e.value?(m(),x("div",{key:0,class:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:o},[r("img",{src:e.value,class:"max-h-[90vh] max-w-[90vw] rounded-lg object-contain shadow-2xl",onClick:l[0]||(l[0]=Ve(()=>{},["stop"]))},null,8,_o),r("button",{class:"absolute right-4 top-4 flex h-8 w-8 items-center justify-center rounded-full bg-white/10 text-white transition-colors hover:bg-white/20",onClick:o},[I(f(Ke),{class:"h-5 w-5"})])])):z("",!0)]),_:1})]))])):z("",!0)}}),To={class:"text-sm leading-relaxed whitespace-pre-wrap"},Mo=["innerHTML"],Ro={key:3,class:"inline-flex items-center gap-1 py-1"},Ao={key:4,class:"mt-1 text-[10px] text-warning"},No={key:2,class:"mt-1.5 flex items-center gap-2 text-[10px] text-text-muted"},zo={class:"text-[10px] opacity-50"},Eo=ne({__name:"ChatBubble",props:{message:{}},setup(t){const e=t,s=Je(),o=Hs(),n=at(),l=F(()=>e.message.sessionId?n.getMetrics(e.message.sessionId):null),a=F(()=>e.message.sessionId?s.sessionById(e.message.sessionId)?.doneReason==="length":!1),c=F(()=>e.message.sessionId?o.getThinking(e.message.sessionId):{isThinking:!1,content:""}),i=F(()=>e.message.role==="user"),p=F(()=>{if(i.value){if(e.message.attachments?.length){const b=`
86
-
87
- ---
88
-
89
- `,S=e.message.content.lastIndexOf(b);if(S!==-1)return e.message.content.slice(S+b.length)}return e.message.content}return e.message.isStreaming?"":e.message.content.replace(/<think>[\s\S]*?<\/think>/g,"").trim()}),u=F(()=>i.value||!p.value?"":io(p.value)),h=F(()=>new Date(e.message.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}));return(b,S)=>(m(),x("div",{class:P(["flex w-full",i.value?"justify-end":"justify-start"])},[r("div",{class:P(["max-w-[80%] rounded-2xl px-4 py-2.5",i.value?"bg-accent text-white rounded-br-md":"bg-surface-raised border border-border-default rounded-bl-md"])},[i.value?(m(),x(H,{key:0},[t.message.attachments?.length?(m(),ze(Co,{key:0,attachments:t.message.attachments},null,8,["attachments"])):z("",!0),r("p",To,d(p.value),1)],64)):(m(),x(H,{key:1},[t.message.sessionId?(m(),ze(go,{key:0,"is-thinking":c.value.isThinking,content:c.value.content,completed:!t.message.isStreaming},null,8,["is-thinking","content","completed"])):z("",!0),t.message.isStreaming&&t.message.sessionId?(m(),ze(xo,{key:1,"session-id":t.message.sessionId},null,8,["session-id"])):p.value?(m(),x("div",{key:2,class:"markdown-prose",innerHTML:u.value},null,8,Mo)):z("",!0),t.message.isStreaming&&!p.value?(m(),x("span",Ro,[...S[0]||(S[0]=[r("span",{class:"h-1.5 w-1.5 rounded-full bg-accent",style:{animation:"typing-bounce 1.2s ease-in-out infinite"}},null,-1),r("span",{class:"h-1.5 w-1.5 rounded-full bg-accent",style:{animation:"typing-bounce 1.2s ease-in-out 0.2s infinite"}},null,-1),r("span",{class:"h-1.5 w-1.5 rounded-full bg-accent",style:{animation:"typing-bounce 1.2s ease-in-out 0.4s infinite"}},null,-1)])])):z("",!0),a.value&&!t.message.isStreaming?(m(),x("div",Ao,d(b.$t("dashboard.bubble.truncatedWarning")),1)):z("",!0)],64)),!i.value&&!t.message.isStreaming&&l.value?(m(),x("div",No,[r("span",null,d(l.value.completionTokenCount)+" "+d(b.$t("dashboard.bubble.tokens")),1),S[1]||(S[1]=r("span",{class:"opacity-40"},"·",-1)),r("span",null,d(l.value.tokensPerSecond.toFixed(1))+" "+d(b.$t("dashboard.bubble.tokPerSec")),1),S[2]||(S[2]=r("span",{class:"opacity-40"},"·",-1)),r("span",null,d(l.value.ttftMs<1e3?l.value.ttftMs.toFixed(0)+"ms":(l.value.ttftMs/1e3).toFixed(1)+"s")+" "+d(b.$t("dashboard.bubble.ttft")),1)])):z("",!0),r("div",{class:P(["mt-1",i.value?"text-end":""])},[r("span",zo,d(h.value),1)],2)],2)],2))}}),Po={key:0,class:"flex items-center justify-center"},Io={class:"text-center"},Do={class:"text-sm text-text-muted"},jo=ne({__name:"ChatMessageList",props:{messages:{}},setup(t,{expose:e}){const s=t,o=N(null);function n(){zs(()=>{o.value&&(o.value.scrollTop=o.value.scrollHeight)})}return te(()=>s.messages.length,()=>n()),te(()=>s.messages[s.messages.length-1]?.content,()=>n()),e({scrollToBottom:n}),(l,a)=>(m(),x("div",{ref_key:"containerRef",ref:o,class:"flex-1 overflow-y-auto px-4 py-6"},[r("div",{class:P(["mx-auto max-w-3xl space-y-4",t.messages.length===0?"flex min-h-full flex-col justify-center":""])},[t.messages.length===0?(m(),x("div",Po,[r("div",Io,[a[0]||(a[0]=r("svg",{class:"mx-auto mb-4 h-20 w-20 text-text-muted/20",viewBox:"0 0 297.5 297.5"},[r("path",{fill:"currentColor",d:"M179.293,23.839c-64.904,0-117.707,52.804-117.707,117.707c0,1.832,0.056,3.651,0.14,5.463H9.933 c-5.486,0-9.933,4.448-9.933,9.933v46.189c0,5.486,4.448,9.933,9.933,9.933h22.349v43.209h-6.953c-4.663,0-8.443,3.78-8.443,8.443 c0,4.663,3.78,8.443,8.443,8.443h30.793c4.663,0,8.443-3.78,8.443-8.443c0-4.663-3.78-8.443-8.443-8.443h-6.953v-43.209h36.713 c21.533,28.059,55.39,46.189,93.411,46.189c64.904,0,117.707-52.804,117.707-117.707S244.196,23.839,179.293,23.839z M19.866,166.876h213.087c-5.257,11.091-13.854,20.295-24.483,26.323H19.866V166.876z M119.942,141.547 c0-32.726,26.624-59.35,59.35-59.35s59.35,26.624,59.35,59.35c0,1.843-0.096,3.663-0.261,5.463H120.206 C120.04,145.21,119.942,143.39,119.942,141.547z M179.293,239.388c-25.75,0-49.202-10.003-66.689-26.323h32.684 c10.31,4.925,21.837,7.698,34.005,7.698c43.68,0,79.217-35.536,79.217-79.217S222.973,62.33,179.293,62.33 s-79.217,35.536-79.217,79.217c0,1.839,0.086,3.657,0.214,5.463H81.611c-0.101-1.809-0.16-3.629-0.16-5.463 c0-48.871,36.016-89.488,82.901-96.702c-0.758,1.266-1.201,2.741-1.201,4.324c0,4.663,3.78,8.443,8.443,8.443h15.396 c4.663,0,8.443-3.78,8.443-8.443c0-1.583-0.443-3.058-1.201-4.324c46.884,7.214,82.901,47.83,82.901,96.702 C277.134,195.497,233.243,239.388,179.293,239.388z"})],-1)),a[1]||(a[1]=r("p",{class:"text-2xl font-semibold text-text-primary mb-2"},"LLMxRay",-1)),r("p",Do,d(l.$t("dashboard.empty.startConversation")),1)])])):z("",!0),(m(!0),x(H,null,X(t.messages,c=>(m(),ze(Eo,{key:c.id,message:c},null,8,["message"]))),128))],2)],512))}}),Lo=new Set(["png","jpg","jpeg","gif","webp"]),Bo=new Set(["pdf","docx","txt","md","csv"]);function ds(t){return t.split(".").pop()?.toLowerCase()??""}function ot(t){return Lo.has(ds(t))}function ps(t){return Bo.has(ds(t))}function Fo(t){return ot(t)||ps(t)}const Oo=".pdf,.docx,.txt,.md,.csv,.png,.jpg,.jpeg,.gif,.webp",Lt=8e3;function Uo(){const t=N([]),e=F(()=>t.value.some(c=>c.status==="parsing"));async function s(c){for(const i of c){if(!Fo(i.name))continue;const p={id:be(),name:i.name,type:ot(i.name)?"image":"document",mimeType:i.type,sizeBytes:i.size,status:"pending"};t.value.push(p),ot(i.name)?o(i,p):ps(i.name)&&n(i,p)}}function o(c,i){i.status="parsing";const p=i.id,u=new FileReader;u.onload=()=>{const h=t.value.find(b=>b.id===p);h&&(h.content=u.result,h.status="ready")},u.onerror=()=>{const h=t.value.find(b=>b.id===p);h&&(h.error="Failed to read image",h.status="error")},u.readAsDataURL(c)}async function n(c,i){i.status="parsing";const p=i.id;try{const u=Gs(c.name);if(!u){const S=t.value.find(C=>C.id===p);S&&(S.error="Unsupported format",S.status="error");return}let h=await Zs(c,u);h.length>Lt&&(h=h.slice(0,Lt)+`
90
-
91
- [... truncated]`);const b=t.value.find(S=>S.id===p);b&&(b.content=h,b.status="ready")}catch(u){const h=t.value.find(b=>b.id===p);h&&(h.error=u instanceof Error?u.message:"Parse failed",h.status="error")}}function l(c){t.value=t.value.filter(i=>i.id!==c)}function a(){t.value=[]}return{attachments:t,isProcessing:e,addFiles:s,removeAttachment:l,clearAttachments:a}}const Vo={key:0,class:"absolute bottom-full left-0 right-0 mb-2 max-h-64 overflow-y-auto rounded-xl border border-border-default bg-surface-raised shadow-lg"},qo={class:"p-1.5"},Ho=["onMouseenter","onClick"],Wo={class:"shrink-0 font-mono text-xs text-accent"},Go={class:"truncate text-xs text-text-muted"},Zo={class:"ms-auto shrink-0 rounded bg-surface-overlay px-1.5 py-0.5 text-[10px] text-text-muted"},Ko=ne({__name:"SlashCommandDropdown",props:{filter:{},visible:{type:Boolean}},emits:["select","close"],setup(t,{expose:e,emit:s}){const{t:o}=Ot(),n=t,l=s,a=N(0),c=F(()=>{if(!n.visible)return[];const u=n.filter.replace(/^\//,"");return u?hn(u):Object.values(Jt()).flat()});te(()=>n.filter,()=>{a.value=0});function i(u){return!n.visible||c.value.length===0?!1:u.key==="ArrowDown"?(u.preventDefault(),a.value=(a.value+1)%c.value.length,!0):u.key==="ArrowUp"?(u.preventDefault(),a.value=a.value<=0?c.value.length-1:a.value-1,!0):u.key==="Tab"||u.key==="Enter"&&c.value.length>0?(u.preventDefault(),l("select",c.value[a.value]),!0):u.key==="Escape"?(u.preventDefault(),l("close"),!0):!1}e({handleKeydown:i});const p=F(()=>({chat:o("dashboard.slashCommands.chatConversation"),settings:o("dashboard.slashCommands.modelSettings"),navigation:o("dashboard.slashCommands.featuresNavigation")}));return(u,h)=>t.visible&&c.value.length>0?(m(),x("div",Vo,[r("div",qo,[(m(!0),x(H,null,X(c.value,(b,S)=>(m(),x("button",{key:b.name,class:P(["flex w-full items-center gap-3 rounded-lg px-3 py-2 text-start text-sm transition-colors",S===a.value?"bg-accent/10 text-accent":"text-text-primary hover:bg-surface-overlay"]),onMouseenter:C=>a.value=S,onClick:C=>u.$emit("select",b)},[r("span",Wo,"/"+d(b.name),1),r("span",Go,d(b.description),1),r("span",Zo,d(p.value[b.category]??b.category),1)],42,Ho))),128))])])):z("",!0)}}),Jo={key:0,class:"flex flex-wrap gap-2 px-2.5 pb-1.5 pt-1"},Qo=["src","alt"],Xo={key:1,class:"text-text-muted"},Yo={class:"max-w-[120px] truncate text-text-primary"},ea={class:"text-text-muted"},ta={key:2,class:"h-3 w-3 animate-spin rounded-full border-2 border-accent border-t-transparent"},sa={key:3,class:"text-error",title:"Parse error"},na=["onClick"],oa=ne({__name:"AttachmentPreview",props:{attachments:{}},emits:["remove"],setup(t){return(e,s)=>t.attachments.length>0?(m(),x("div",Jo,[(m(!0),x(H,null,X(t.attachments,o=>(m(),x("div",{key:o.id,class:"flex items-center gap-2 rounded-lg border border-border-default bg-surface-overlay px-2.5 py-1.5 text-xs"},[o.type==="image"&&o.content?(m(),x("img",{key:0,src:o.content,alt:o.name,class:"h-6 w-6 rounded object-cover"},null,8,Qo)):o.type==="document"?(m(),x("span",Xo,[I(f(Kt),{class:"h-4 w-4"})])):z("",!0),r("span",Yo,d(o.name),1),r("span",ea,d(f(et)(o.sizeBytes)),1),o.status==="parsing"?(m(),x("span",ta)):o.status==="error"?(m(),x("span",sa,"!")):z("",!0),r("button",{class:"text-text-muted hover:text-error transition-colors",onClick:n=>e.$emit("remove",o.id)},[I(f(Ke),{class:"h-3.5 w-3.5"})],8,na)]))),128))])):z("",!0)}}),aa={key:0,class:"pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl border-2 border-dashed border-accent bg-accent/5"},ra={class:"text-sm text-accent"},la={class:"relative mx-auto max-w-3xl"},ia=["accept"],ca={class:"mx-auto flex max-w-3xl flex-col rounded-xl border border-border-default bg-surface transition-colors focus-within:border-accent"},ua=["disabled","title"],da=["title"],pa=["disabled","title"],ha=["disabled","placeholder"],ma=["title"],ga=["disabled","title"],fa=ne({__name:"ChatInput",props:{isStreaming:{type:Boolean},selectedModel:{},isVisionModel:{type:Boolean}},emits:["send","command","cancel"],setup(t,{expose:e,emit:s}){const o=s;e({focus:U});const n=rt(),l=N(""),a=N(null),c=N(null),i=N(null),p=N(!1),{attachments:u,isProcessing:h,addFiles:b,removeAttachment:S,clearAttachments:C}=Uo();Ut(()=>{n.fetchModels()});const M=F(()=>{const T=l.value;return T.startsWith("/")&&!T.includes(`
92
- `)}),_=F(()=>{if(!M.value)return"";const T=l.value.indexOf(" ");return T===-1?l.value:l.value.slice(0,T)}),j=F(()=>{const T=l.value.trim().length>0,D=u.value.length>0;return(T||D)&&!h.value});function U(){a.value?.focus()}function q(T){M.value&&i.value&&i.value.handleKeydown(T)||T.key==="Enter"&&!T.shiftKey&&(T.preventDefault(),V())}function K(T){l.value=`/${T.name} `,a.value?.focus()}function V(){const T=l.value.trim();if(!(!T&&u.value.length===0)){if(T.startsWith("/")&&u.value.length===0){const D=T.indexOf(" "),O=D===-1?T.slice(1):T.slice(1,D),le=D===-1?"":T.slice(D+1);o("command",O,le)}else o("send",T,[...u.value]),C();l.value="",a.value&&(a.value.style.height="auto")}}function J(T){const D=T.target;D.style.height="auto",D.style.height=Math.min(D.scrollHeight,200)+"px"}function he(){l.value=""}function se(){l.value="/",a.value?.focus()}function re(){c.value?.click()}function me(T){const D=T.target;D.files&&D.files.length>0&&(b(D.files),D.value="")}function Te(T){T.preventDefault(),p.value=!0}function g(){p.value=!1}function $(T){T.preventDefault(),p.value=!1,T.dataTransfer?.files&&T.dataTransfer.files.length>0&&b(T.dataTransfer.files)}function y(T){const D=T.clipboardData?.items;if(!D)return;const O=[];for(const le of D)if(le.type.startsWith("image/")){const ge=le.getAsFile();ge&&O.push(ge)}O.length>0&&(T.preventDefault(),b(O))}return(T,D)=>(m(),x("div",{class:"relative border-t border-border-default bg-surface-raised px-4 py-3",onDragover:Te,onDragleave:g,onDrop:$},[p.value?(m(),x("div",aa,[r("span",ra,d(T.$t("dashboard.dropZone")),1)])):z("",!0),r("div",la,[I(Ko,{ref_key:"dropdownRef",ref:i,filter:_.value,visible:M.value,onSelect:K,onClose:he},null,8,["filter","visible"])]),r("input",{ref_key:"fileInputRef",ref:c,type:"file",multiple:"",accept:f(Oo),class:"hidden",onChange:me},null,40,ia),r("div",ca,[I(oa,{attachments:f(u),onRemove:f(S)},null,8,["attachments","onRemove"]),r("div",{class:P(["flex items-end gap-2 p-1.5",{"pt-0":f(u).length>0}])},[r("button",{disabled:t.isStreaming,class:"relative flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-text-muted transition-colors hover:bg-surface-overlay hover:text-text-primary disabled:opacity-30",title:t.isVisionModel?T.$t("dashboard.input.attachFilesVision"):T.$t("dashboard.input.attachFiles"),onClick:re},[I(f(Qs),{class:"h-4 w-4"}),t.isVisionModel?(m(),x("span",{key:0,class:"absolute -right-0.5 -top-0.5 flex h-3.5 w-3.5 items-center justify-center rounded-full bg-success text-[8px] text-white",title:T.$t("dashboard.input.visionBadge")},[I(f(Es),{class:"h-2.5 w-2.5","stroke-width":3})],8,da)):z("",!0)],8,ua),r("button",{disabled:t.isStreaming,class:"flex h-8 shrink-0 items-center justify-center rounded-lg px-1.5 text-text-muted transition-colors hover:bg-surface-overlay hover:text-text-primary disabled:opacity-30",title:T.$t("dashboard.input.commands"),onClick:se},[I(f(Ys),{class:"h-4 w-4"})],8,pa),W(r("textarea",{ref_key:"textareaRef",ref:a,"onUpdate:modelValue":D[0]||(D[0]=O=>l.value=O),disabled:t.isStreaming,rows:"1",class:"flex-1 resize-none bg-transparent px-1 py-1 text-sm text-text-primary placeholder-text-muted outline-none disabled:opacity-50",placeholder:t.isVisionModel?T.$t("dashboard.input.placeholderVision"):T.$t("dashboard.input.placeholder"),onKeydown:q,onInput:J,onPaste:y},null,40,ha),[[Q,l.value]]),t.isStreaming?(m(),x("button",{key:0,class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-error text-white transition-colors hover:bg-error/80",title:T.$t("dashboard.input.stopGenerating"),onClick:D[1]||(D[1]=O=>T.$emit("cancel"))},[...D[2]||(D[2]=[r("span",{class:"inline-block h-2.5 w-2.5 rounded-sm bg-white"},null,-1)])],8,ma)):(m(),x("button",{key:1,disabled:!j.value||!t.selectedModel,class:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-accent text-white transition-colors hover:bg-accent-hover disabled:opacity-30 disabled:cursor-not-allowed",title:T.$t("dashboard.input.sendMessage"),onClick:V},[I(f(Xs),{class:"h-4 w-4 rtl:-scale-x-100"})],8,ga))],2)])],32))}}),xa={class:"flex h-full flex-col overflow-y-auto"},ba={class:"space-y-5 p-4 pb-12"},va={class:"mb-1.5 block text-xs font-medium text-text-secondary"},ya=["placeholder"],ka={class:"mt-1 text-[10px] text-text-muted"},wa={class:"flex items-center justify-between"},$a={class:"flex items-center gap-2"},Sa={class:"text-xs font-medium text-text-secondary"},_a=["disabled"],Ca={key:0,class:"text-[10px] text-text-muted -mt-3"},Ta={key:1,class:"text-[10px] text-text-muted -mt-3"},Ma={class:"mb-1.5 flex items-center justify-between"},Ra={class:"text-xs font-medium text-text-secondary"},Aa={class:"text-xs text-text-muted"},Na={class:"mt-0.5 flex justify-between text-[10px] text-text-muted"},za={class:"mb-1.5 flex items-center justify-between"},Ea={class:"text-xs font-medium text-text-secondary"},Pa={class:"text-xs text-text-muted"},Ia=["placeholder"],Da={class:"mt-1 text-[10px] text-text-muted"},ja={class:"mb-1.5 flex items-center justify-between"},La={class:"text-xs font-medium text-text-secondary"},Ba={class:"text-xs text-text-muted"},Fa={class:"mt-1 text-[10px] text-text-muted"},Oa={key:2,class:"space-y-4 ps-1"},Ua={class:"mb-1.5 flex items-center justify-between"},Va={class:"text-xs font-medium text-text-secondary"},qa={class:"text-xs text-text-muted"},Ha={class:"mt-1 text-[10px] text-text-muted"},Wa={class:"mb-1.5 flex items-center justify-between"},Ga={class:"text-xs font-medium text-text-secondary"},Za={class:"text-xs text-text-muted"},Ka={class:"mt-1 text-[10px] text-text-muted"},Ja={class:"mb-1.5 flex items-center justify-between"},Qa={class:"text-xs font-medium text-text-secondary"},Xa={class:"text-xs text-text-muted"},Ya={class:"mt-1 text-[10px] text-text-muted"},er={class:"mb-1.5 flex items-center justify-between"},tr={class:"text-xs font-medium text-text-secondary"},sr={class:"text-xs text-text-muted"},nr={value:0},or={value:1},ar={value:2},rr={class:"mt-1 text-[10px] text-text-muted"},lr={class:"mb-1.5 flex items-center justify-between"},ir={class:"text-xs font-medium text-text-secondary"},cr={class:"text-xs text-text-muted"},ur=["placeholder"],dr={class:"mt-1 text-[10px] text-text-muted"},pr={class:"mb-1.5 block text-xs font-medium text-text-secondary"},hr=["placeholder"],mr={class:"mt-1 text-[10px] text-text-muted"},gr={key:0,class:"ms-1 text-accent"},fr={key:0,class:"ps-1 space-y-2"},xr={key:0,class:"space-y-1"},br=["onClick"],vr={key:1,class:"text-[10px] text-text-muted px-2"},yr={key:0,class:"ms-1 text-accent"},kr={key:4,class:"space-y-4 ps-1"},wr={class:"flex items-center justify-between"},$r={class:"text-xs font-medium text-text-secondary"},Sr={class:"text-[10px] text-text-muted"},_r={key:0},Cr={class:"mb-1 flex items-center justify-between"},Tr={class:"text-[10px] text-text-muted"},Mr={class:"text-[10px] text-text-muted"},Rr={class:"flex items-center justify-between"},Ar={class:"text-xs font-medium text-text-secondary"},Nr={class:"text-[10px] text-text-muted"},zr={key:1},Er={class:"mb-1 flex items-center justify-between"},Pr={class:"text-[10px] text-text-muted"},Ir={class:"text-[10px] text-text-muted"},Dr={class:"flex items-center justify-between"},jr={class:"text-xs font-medium text-text-secondary"},Lr={class:"text-[10px] text-text-muted"},Br={key:2,class:"space-y-1"},Fr={class:"flex-1 text-text-secondary"},Or=["onClick"],Ur={class:"flex items-center justify-between"},Vr={class:"text-xs font-medium text-text-secondary"},qr={class:"text-[10px] text-text-muted"},Hr={key:3,class:"space-y-2"},Wr={class:"mb-1 block text-[10px] text-text-muted"},Gr={value:"",disabled:""},Zr=["value"],Kr={key:0,class:"rounded-lg border border-accent/20 bg-accent/5 p-2"},Jr={class:"mb-2 text-[10px] text-accent"},Qr={class:"space-y-1.5"},Xr={class:"min-w-0 flex-1"},Yr={class:"truncate text-[11px] font-mono text-text-primary"},el={class:"text-[9px] text-text-muted"},tl=["disabled","onClick"],sl={key:0,class:"mt-2 text-[9px] text-text-muted"},nl={class:"mb-1 flex items-center justify-between"},ol={class:"text-[10px] text-text-muted"},al={class:"text-[10px] text-text-muted"},rl=ne({__name:"ChatSettingsPanel",props:{modelValue:{},selectedModel:{},ragEnabled:{type:Boolean}},emits:["update:modelValue","update:ragEnabled"],setup(t,{emit:e}){const s=t,o=e,n=N(s.modelValue.systemPrompt),l=N(s.modelValue.options.temperature??.7),a=N(s.modelValue.options.num_predict??-1),c=N(s.modelValue.options.num_ctx??4096),i=N(s.modelValue.options.top_p??.9),p=N(s.modelValue.options.top_k??40),u=N(s.modelValue.options.repeat_penalty??1.1),h=N(s.modelValue.options.seed??-1),b=N(s.modelValue.options.stop?.join(", ")??""),S=N(s.modelValue.options.mirostat??0);te(()=>s.modelValue.options,g=>{l.value=g.temperature??.7,a.value=g.num_predict??-1,c.value=g.num_ctx??4096,i.value=g.top_p??.9,p.value=g.top_k??40,u.value=g.repeat_penalty??1.1,h.value=g.seed??-1,b.value=g.stop?.join(", ")??"",S.value=g.mirostat??0},{deep:!0}),te([n,l,a,c,i,p,u,h,b,S],()=>{const g=b.value.split(",").map($=>$.trim()).filter(Boolean);o("update:modelValue",{systemPrompt:n.value,options:{temperature:l.value,num_predict:a.value===-1?void 0:a.value,num_ctx:c.value,top_p:i.value,top_k:p.value,repeat_penalty:u.value,seed:h.value===-1?void 0:h.value,stop:g.length>0?g:void 0,mirostat:S.value}})},{deep:!0}),te(()=>s.modelValue,g=>{n.value=g.systemPrompt,l.value=g.options.temperature??.7,a.value=g.options.num_predict??-1,c.value=g.options.num_ctx??4096,i.value=g.options.top_p??.9,p.value=g.options.top_k??40,u.value=g.options.repeat_penalty??1.1,h.value=g.options.seed??-1,S.value=g.options.mirostat??0});const C=lt(),M=Vt(),_=Qt(),j=rt(),U=Gt(),q=F(()=>j.supportsTools(s.selectedModel));te(()=>s.selectedModel,g=>{g&&!j.supportsTools(g)&&C.enabledTools.length>0&&C.disableAll()});const K=N(!1),V=N(!1),J=N(!1),he=N(!1),se=N(""),re=N(""),me=[{name:"nomic-embed-text",description:"Nomic — 137M params, fast & good",size:"274 MB"},{name:"mxbai-embed-large",description:"mixedbread.ai — 335M params, high quality",size:"670 MB"},{name:"all-minilm",description:"MiniLM — 23M params, very lightweight",size:"46 MB"},{name:"snowflake-arctic-embed",description:"Snowflake — 110M params, balanced",size:"229 MB"}];async function Te(g){he.value=!0,re.value=g,se.value="Starting download...";try{await Ie.pullModel(g,($,y,T)=>{if(y&&T){const D=Math.round(y/T*100);se.value=`${$} ${D}%`}else se.value=$}),se.value="Done!",await j.fetchModels(),_.settings.ragMemory.embeddingModel=g}catch($){se.value=`Failed: ${$ instanceof Error?$.message:"Unknown error"}`}finally{he.value=!1,setTimeout(()=>{se.value="",re.value=""},3e3)}}return(g,$)=>(m(),x("div",xa,[r("div",ba,[r("div",null,[r("label",va,d(g.$t("dashboard.settings.systemPrompt")),1),W(r("textarea",{"onUpdate:modelValue":$[0]||($[0]=y=>n.value=y),rows:"6",class:"w-full resize-y rounded-lg border border-border-default bg-surface px-3 py-2 text-sm text-text-primary placeholder-text-muted outline-none focus:border-accent",placeholder:g.$t("dashboard.settings.systemPromptPlaceholder")},null,8,ya),[[Q,n.value]]),r("p",ka,d(g.$t("dashboard.settings.systemPromptHint")),1)]),r("div",wa,[r("div",$a,[r("span",Sa,d(g.$t("dashboard.settings.knowledgeBase")),1),r("span",{class:P(["rounded-full px-1.5 py-0.5 text-[9px] font-medium",t.ragEnabled&&f(U).readyDocuments.length>0?"bg-accent/10 text-accent":"bg-surface-overlay text-text-muted"])},d(t.ragEnabled&&f(U).readyDocuments.length>0?g.$t("dashboard.settings.kbEnabled"):g.$t("dashboard.settings.kbDisabled")),3)]),r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",t.ragEnabled&&f(U).readyDocuments.length>0?"bg-accent":"bg-surface-overlay"]),disabled:f(U).readyDocuments.length===0,onClick:$[1]||($[1]=y=>o("update:ragEnabled",!t.ragEnabled))},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",t.ragEnabled&&f(U).readyDocuments.length>0?"translate-x-3.5":"translate-x-0.5"])},null,2)],10,_a)]),f(U).readyDocuments.length>0?(m(),x("p",Ca,[Ce(d(f(U).enabledDocuments.length)+"/"+d(f(U).readyDocuments.length)+" "+d(g.$t("dashboard.settings.documents"))+" · ",1),r("button",{class:"text-accent hover:underline",onClick:$[2]||($[2]=y=>f(M).push("/rag"))},d(g.$t("dashboard.settings.manage")),1)])):(m(),x("p",Ta,[Ce(d(g.$t("dashboard.settings.noDocumentsIngested"))+" · ",1),r("button",{class:"text-accent hover:underline",onClick:$[3]||($[3]=y=>f(M).push("/rag"))},d(g.$t("dashboard.settings.addDocuments")),1)])),r("div",null,[r("div",Ma,[r("label",Ra,d(g.$t("dashboard.settings.temperature")),1),r("span",Aa,d(l.value.toFixed(2)),1)]),W(r("input",{"onUpdate:modelValue":$[4]||($[4]=y=>l.value=y),type:"range",min:"0",max:"2",step:"0.05",class:"w-full accent-accent"},null,512),[[Q,l.value,void 0,{number:!0}]]),r("div",Na,[r("span",null,d(g.$t("dashboard.settings.precise")),1),r("span",null,d(g.$t("dashboard.settings.creative")),1)])]),r("div",null,[r("div",za,[r("label",Ea,d(g.$t("dashboard.settings.maxTokens")),1),r("span",Pa,d(a.value===-1?g.$t("dashboard.settings.unlimited"):a.value),1)]),W(r("input",{"onUpdate:modelValue":$[5]||($[5]=y=>a.value=y),type:"number",min:"-1",max:"32768",class:"w-full rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none focus:border-accent",placeholder:g.$t("dashboard.settings.maxTokensPlaceholder")},null,8,Ia),[[Q,a.value,void 0,{number:!0}]]),r("p",Da,d(g.$t("dashboard.settings.maxTokensHint")),1)]),r("div",null,[r("div",ja,[r("label",La,d(g.$t("dashboard.settings.contextWindow")),1),r("span",Ba,d(c.value.toLocaleString()),1)]),W(r("select",{"onUpdate:modelValue":$[6]||($[6]=y=>c.value=y),class:"w-full rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none focus:border-accent"},[...$[25]||($[25]=[r("option",{value:2048},"2,048",-1),r("option",{value:4096},"4,096",-1),r("option",{value:8192},"8,192",-1),r("option",{value:16384},"16,384",-1),r("option",{value:32768},"32,768",-1),r("option",{value:65536},"65,536",-1),r("option",{value:131072},"131,072",-1)])],512),[[Ye,c.value,void 0,{number:!0}]]),r("p",Fa,d(g.$t("dashboard.settings.contextWindowHint")),1)]),r("button",{class:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-xs text-text-secondary hover:bg-surface-overlay transition-colors",onClick:$[7]||($[7]=y=>K.value=!K.value)},[r("span",null,d(g.$t("dashboard.settings.advancedSampling")),1),r("span",{class:P(["transition-transform",{"rotate-180":K.value}])},"▾",2)]),K.value?(m(),x("div",Oa,[r("div",null,[r("div",Ua,[r("label",Va,d(g.$t("dashboard.settings.topP")),1),r("span",qa,d(i.value.toFixed(2)),1)]),W(r("input",{"onUpdate:modelValue":$[8]||($[8]=y=>i.value=y),type:"range",min:"0",max:"1",step:"0.05",class:"w-full accent-accent"},null,512),[[Q,i.value,void 0,{number:!0}]]),r("p",Ha,d(g.$t("dashboard.settings.topPHint")),1)]),r("div",null,[r("div",Wa,[r("label",Ga,d(g.$t("dashboard.settings.topK")),1),r("span",Za,d(p.value),1)]),W(r("input",{"onUpdate:modelValue":$[9]||($[9]=y=>p.value=y),type:"range",min:"1",max:"100",step:"1",class:"w-full accent-accent"},null,512),[[Q,p.value,void 0,{number:!0}]]),r("p",Ka,d(g.$t("dashboard.settings.topKHint")),1)]),r("div",null,[r("div",Ja,[r("label",Qa,d(g.$t("dashboard.settings.repeatPenalty")),1),r("span",Xa,d(u.value.toFixed(2)),1)]),W(r("input",{"onUpdate:modelValue":$[10]||($[10]=y=>u.value=y),type:"range",min:"1.0",max:"2.0",step:"0.05",class:"w-full accent-accent"},null,512),[[Q,u.value,void 0,{number:!0}]]),r("p",Ya,d(g.$t("dashboard.settings.repeatPenaltyHint")),1)]),r("div",null,[r("div",er,[r("label",tr,d(g.$t("dashboard.settings.mirostat")),1),r("span",sr,d(S.value===0?g.$t("dashboard.settings.mirostatOff"):`v${S.value}`),1)]),W(r("select",{"onUpdate:modelValue":$[11]||($[11]=y=>S.value=y),class:"w-full rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none focus:border-accent"},[r("option",nr,d(g.$t("dashboard.settings.mirostatDisabled")),1),r("option",or,d(g.$t("dashboard.settings.mirostatV1")),1),r("option",ar,d(g.$t("dashboard.settings.mirostatV2")),1)],512),[[Ye,S.value,void 0,{number:!0}]]),r("p",rr,d(g.$t("dashboard.settings.mirostatHint")),1)]),r("div",null,[r("div",lr,[r("label",ir,d(g.$t("dashboard.settings.seed")),1),r("span",cr,d(h.value===-1?g.$t("dashboard.settings.seedRandom"):h.value),1)]),W(r("input",{"onUpdate:modelValue":$[12]||($[12]=y=>h.value=y),type:"number",min:"-1",class:"w-full rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none focus:border-accent",placeholder:g.$t("dashboard.settings.seedPlaceholder")},null,8,ur),[[Q,h.value,void 0,{number:!0}]]),r("p",dr,d(g.$t("dashboard.settings.seedHint")),1)]),r("div",null,[r("label",pr,d(g.$t("dashboard.settings.stopSequences")),1),W(r("input",{"onUpdate:modelValue":$[13]||($[13]=y=>b.value=y),type:"text",class:"w-full rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary placeholder-text-muted outline-none focus:border-accent",placeholder:g.$t("dashboard.settings.stopSequencesPlaceholder")},null,8,hr),[[Q,b.value]]),r("p",mr,d(g.$t("dashboard.settings.stopSequencesHint")),1)])])):z("",!0),q.value?(m(),x(H,{key:3},[r("button",{class:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-xs text-text-secondary hover:bg-surface-overlay transition-colors",onClick:$[14]||($[14]=y=>V.value=!V.value)},[r("span",null,[Ce(d(g.$t("dashboard.settings.tools"))+" ",1),f(C).enabledDefinitions.length>0?(m(),x("span",gr," ("+d(f(C).enabledDefinitions.length)+" "+d(g.$t("dashboard.settings.active"))+") ",1)):z("",!0)]),r("span",{class:P(["transition-transform",{"rotate-180":V.value}])},"▾",2)]),V.value?(m(),x("div",fr,[f(C).allTools.length>0?(m(),x("div",xr,[(m(!0),x(H,null,X(f(C).allTools,y=>(m(),x("div",{key:y.id,class:"flex items-center gap-2 rounded-md bg-surface px-2 py-1.5 text-[11px]"},[r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",y.enabled?"bg-accent":"bg-surface-overlay"]),onClick:T=>f(C).toggleEnabled(y.id)},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",y.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],10,br),r("span",{class:P(["font-mono",y.enabled?"text-text-primary":"text-text-muted"])},d(y.definition.function.name),3)]))),128))])):(m(),x("p",vr,d(g.$t("dashboard.settings.noToolsDefined")),1)),r("button",{class:"w-full rounded-lg border border-dashed border-border-default px-3 py-1.5 text-[11px] text-text-muted hover:border-accent hover:text-text-primary transition-colors",onClick:$[15]||($[15]=y=>f(M).push("/tools"))},d(g.$t("dashboard.settings.manageInToolWorkshop")),1)])):z("",!0)],64)):z("",!0),r("button",{class:"flex w-full items-center justify-between rounded-lg px-3 py-2 text-xs text-text-secondary hover:bg-surface-overlay transition-colors",onClick:$[16]||($[16]=y=>J.value=!J.value)},[r("span",null,[Ce(d(g.$t("dashboard.memory.memory"))+" ",1),f(_).factCount>0?(m(),x("span",yr," ("+d(f(_).factCount)+" "+d(g.$t("dashboard.memory.facts"))+") ",1)):z("",!0)]),r("span",{class:P(["transition-transform",{"rotate-180":J.value}])},"▾",2)]),J.value?(m(),x("div",kr,[r("div",wr,[r("div",null,[r("p",$r,d(g.$t("dashboard.memory.slidingWindow")),1),r("p",Sr,d(g.$t("dashboard.memory.slidingWindowHint")),1)]),r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",f(_).settings.slidingWindow.enabled?"bg-accent":"bg-surface-overlay"]),onClick:$[17]||($[17]=y=>f(_).settings.slidingWindow.enabled=!f(_).settings.slidingWindow.enabled)},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",f(_).settings.slidingWindow.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),f(_).settings.slidingWindow.enabled?(m(),x("div",_r,[r("div",Cr,[r("label",Tr,d(g.$t("dashboard.memory.maxMessages")),1),r("span",Mr,d(f(_).settings.slidingWindow.maxMessages),1)]),W(r("input",{"onUpdate:modelValue":$[18]||($[18]=y=>f(_).settings.slidingWindow.maxMessages=y),type:"range",min:"10",max:"200",step:"10",class:"w-full accent-accent"},null,512),[[Q,f(_).settings.slidingWindow.maxMessages,void 0,{number:!0}]])])):z("",!0),r("div",Rr,[r("div",null,[r("p",Ar,d(g.$t("dashboard.memory.autoSummarize")),1),r("p",Nr,d(g.$t("dashboard.memory.autoSummarizeHint")),1)]),r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",f(_).settings.autoSummarize.enabled?"bg-accent":"bg-surface-overlay"]),onClick:$[19]||($[19]=y=>f(_).settings.autoSummarize.enabled=!f(_).settings.autoSummarize.enabled)},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",f(_).settings.autoSummarize.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),f(_).settings.autoSummarize.enabled?(m(),x("div",zr,[r("div",Er,[r("label",Pr,d(g.$t("dashboard.memory.triggerAfter")),1),r("span",Ir,d(f(_).settings.autoSummarize.triggerThreshold)+" "+d(g.$t("dashboard.memory.messages")),1)]),W(r("input",{"onUpdate:modelValue":$[20]||($[20]=y=>f(_).settings.autoSummarize.triggerThreshold=y),type:"range",min:"10",max:"100",step:"5",class:"w-full accent-accent"},null,512),[[Q,f(_).settings.autoSummarize.triggerThreshold,void 0,{number:!0}]])])):z("",!0),r("div",Dr,[r("div",null,[r("p",jr,d(g.$t("dashboard.memory.userMemories")),1),r("p",Lr,d(g.$t("dashboard.memory.userMemoriesHint")),1)]),r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",f(_).settings.userFacts.enabled?"bg-accent":"bg-surface-overlay"]),onClick:$[21]||($[21]=y=>f(_).settings.userFacts.enabled=!f(_).settings.userFacts.enabled)},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",f(_).settings.userFacts.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),f(_).settings.userFacts.enabled&&f(_).facts.length>0?(m(),x("div",Br,[(m(!0),x(H,null,X(f(_).facts,y=>(m(),x("div",{key:y.id,class:"flex items-center gap-2 rounded-md bg-surface px-2 py-1 text-[11px]"},[r("span",Fr,d(y.content),1),r("button",{class:"shrink-0 text-text-muted hover:text-error transition-colors",onClick:T=>f(_).removeFact(y.id)},[I(f(Ke),{class:"h-3 w-3"})],8,Or)]))),128))])):z("",!0),r("div",Ur,[r("div",null,[r("p",Vr,d(g.$t("dashboard.memory.messageMemoryRag")),1),r("p",qr,d(g.$t("dashboard.memory.messageMemoryHint")),1)]),r("button",{class:P(["h-4 w-7 shrink-0 rounded-full transition-colors",f(_).settings.ragMemory.enabled?"bg-accent":"bg-surface-overlay"]),onClick:$[22]||($[22]=y=>f(_).settings.ragMemory.enabled=!f(_).settings.ragMemory.enabled)},[r("span",{class:P(["block h-3 w-3 rounded-full bg-white transition-transform",f(_).settings.ragMemory.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),f(_).settings.ragMemory.enabled?(m(),x("div",Hr,[r("div",null,[r("label",Wr,d(g.$t("dashboard.memory.embeddingModel")),1),W(r("select",{"onUpdate:modelValue":$[23]||($[23]=y=>f(_).settings.ragMemory.embeddingModel=y),class:"w-full rounded-lg border border-border-default bg-surface px-2 py-1 text-xs text-text-primary outline-none focus:border-accent"},[r("option",Gr,d(g.$t("dashboard.memory.selectEmbeddingModel")),1),(m(!0),x(H,null,X(f(j).embeddingModelNames,y=>(m(),x("option",{key:y,value:y},d(y)+" "+d(f(j).capabilityIcons(y)),9,Zr))),128))],512),[[Ye,f(_).settings.ragMemory.embeddingModel]])]),f(j).embeddingModelNames.length===0?(m(),x("div",Kr,[r("p",Jr,d(g.$t("dashboard.memory.noEmbeddingModels")),1),r("div",Qr,[(m(),x(H,null,X(me,y=>r("div",{key:y.name,class:"flex items-center gap-2"},[r("div",Xr,[r("p",Yr,d(y.name),1),r("p",el,d(y.description)+" ("+d(y.size)+")",1)]),r("button",{disabled:he.value,class:"shrink-0 rounded-md bg-accent px-2 py-0.5 text-[10px] text-white hover:bg-accent-hover disabled:opacity-30 transition-colors",onClick:T=>Te(y.name)},d(he.value&&re.value===y.name?g.$t("dashboard.settings.pulling"):g.$t("dashboard.settings.pull")),9,tl)])),64))]),se.value?(m(),x("p",sl,d(se.value),1)):z("",!0)])):z("",!0),r("div",null,[r("div",nl,[r("label",ol,d(g.$t("dashboard.memory.retrieveTop")),1),r("span",al,d(f(_).settings.ragMemory.topK)+" "+d(g.$t("dashboard.memory.messages")),1)]),W(r("input",{"onUpdate:modelValue":$[24]||($[24]=y=>f(_).settings.ragMemory.topK=y),type:"range",min:"1",max:"10",step:"1",class:"w-full accent-accent"},null,512),[[Q,f(_).settings.ragMemory.topK,void 0,{number:!0}]])])])):z("",!0)])):z("",!0)])]))}}),ll={class:"flex h-full flex-col"},il={key:0,class:"absolute left-1/2 top-16 z-50 -translate-x-1/2 rounded-xl border border-border-default bg-surface-raised px-4 py-3 shadow-lg"},cl={class:"flex items-start gap-3"},ul={class:"max-w-md whitespace-pre-wrap text-sm text-text-primary"},dl={class:"flex items-center justify-between border-b border-border-default bg-surface-raised px-4 py-2"},pl={class:"flex items-center gap-3"},hl={class:"relative"},ml={key:0,class:"text-text-muted"},gl={key:0,class:"absolute left-0 top-full z-50 mt-1 max-h-64 w-max min-w-full overflow-y-auto rounded-lg border border-border-default bg-surface-raised shadow-lg"},fl=["onMousedown"],xl={key:0,class:"flex items-center"},bl=["title"],vl={class:"truncate"},yl={class:"flex items-center gap-2"},kl={class:"relative"},wl={key:1,class:"absolute end-0 top-full z-20 mt-1 w-48 rounded-lg border border-border-default bg-surface-raised shadow-lg py-1"},$l={class:"flex flex-1 min-h-0"},Sl={key:0,class:"w-64 shrink-0 border-e border-border-default bg-surface-raised flex flex-col"},_l={class:"flex items-center justify-between border-b border-border-default px-4 py-2"},Cl={class:"text-xs font-medium text-text-secondary"},Tl={class:"flex-1 overflow-y-auto p-2"},Ml={key:0,class:"px-2 py-4 text-[10px] text-text-muted italic text-center"},Rl={key:1,class:"space-y-0.5"},Al=["onClick"],Nl={key:0,class:"flex-1 min-w-0"},zl=["onBlur","onKeydown"],El={class:"flex-1 min-w-0"},Pl={class:"truncate text-[11px]"},Il={class:"truncate text-[9px] text-text-muted"},Dl={class:"hidden shrink-0 items-center gap-0.5 group-hover:flex"},jl=["title","onClick"],Ll=["title","onClick"],Bl={class:"flex flex-1 flex-col min-w-0"},Fl={key:0,class:"mx-4 mt-2 rounded-lg border border-error/30 bg-error/10 px-4 py-2.5 text-sm text-error"},Ol={class:"font-medium"},Ul={key:1,class:"w-72 shrink-0 border-s border-border-default bg-surface-raised"},Vl={class:"flex items-center justify-between border-b border-border-default px-4 py-2"},ql={class:"text-xs font-medium text-text-secondary"},Hl=ne({__name:"ChatConversation",setup(t){const{t:e}=Ot(),s=Vt(),o=qt(),n=rt(),l=Je(),a=Gt(),c=at(),i=lt(),p=Qt(),u=Wt(),{isStreaming:h,currentSessionId:b,startChatStream:S,cancel:C}=pn(),M=N(""),_=N(!1);function j(){setTimeout(()=>{_.value=!1},150)}const U=N(!0),q=N(!1),K=N(!1),V=N(!1);function J(){const v=ce.value;if(!v||v.messages.length===0)return;const w=JSON.stringify(v.messages,null,2),k=new Blob([w],{type:"application/json"}),R=URL.createObjectURL(k),A=document.createElement("a");A.href=R,A.download=`chat-${v.id}.json`,A.click(),URL.revokeObjectURL(R),V.value=!1}function he(){const v=ce.value;if(!v||v.messages.length===0)return;const w=v.messages.map(Y=>{const fe=Y.role.charAt(0).toUpperCase()+Y.role.slice(1),ue=new Date(Y.timestamp).toLocaleString();return`### ${fe}
93
- *${ue}*
94
-
95
- ${Y.content}`}),k=`# Chat Export — ${v.name}
96
-
97
- ${w.join(`
98
-
99
- ---
100
-
101
- `)}
102
-
103
- ---
104
- *Generated by LLMxRay — Local LLM Observatory*
105
- `,R=new Blob([k],{type:"text/markdown"}),A=URL.createObjectURL(R),L=document.createElement("a");L.href=A,L.download=`chat-${v.id}.md`,L.click(),URL.revokeObjectURL(A),V.value=!1}function se(){const v=ce.value;if(!v||v.messages.length===0)return;const w=v.messages.map(L=>`[${L.role}] ${L.content}`).join(`
106
-
107
- `),k=new Blob([w],{type:"text/plain"}),R=URL.createObjectURL(k),A=document.createElement("a");A.href=R,A.download=`chat-${v.id}.txt`,A.click(),URL.revokeObjectURL(R),V.value=!1}const re=N(null),me=N("");function Te(v){o.setActiveConversation(v)}function g(v,w){re.value=v,me.value=w}function $(v){const w=me.value.trim();w&&o.renameConversation(v,w),re.value=null}function y(){re.value=null}function T(v,w){v.key==="Enter"?$(w):v.key==="Escape"&&y()}function D(v){const k=Date.now()-v,R=Math.floor(k/6e4);if(R<1)return e("common.time.justNow");if(R<60)return e("dashboard.conversation.minutesAgo",{n:R});const A=Math.floor(R/60);if(A<24)return e("dashboard.conversation.hoursAgo",{n:A});const L=Math.floor(A/24);return L<7?e("dashboard.conversation.daysAgo",{n:L}):new Date(v).toLocaleDateString()}const O=N({systemPrompt:"",options:{}}),le=N(null);let ge=null;const ce=F(()=>o.activeConversation),je=F(()=>ce.value?.messages??[]),hs=F(()=>n.isVisionModel(M.value)),xt=F(()=>{const v=$e.value??b.value;if(!v)return null;const w=l.sessionById(v);return w?.status==="error"&&w.error?w.error:null}),$e=F(()=>{const v=je.value;for(let w=v.length-1;w>=0;w--)if(v[w].sessionId)return v[w].sessionId;return null}),Se=N(e("dashboard.conversation.untitled")),Me=N(!1),Le=N(""),bt=F(()=>ce.value?.name??Se.value);function ms(){Le.value=bt.value,Me.value=!0}function vt(){const v=Le.value.trim();if(!v){Me.value=!1;return}ce.value?o.renameConversation(ce.value.id,v):Se.value=v,Me.value=!1}function gs(){Me.value=!1}function fs(v){v.key==="Enter"?vt():v.key==="Escape"&&gs()}Ut(async()=>{await n.fetchModels(),n.chatModelNames.length>0&&!M.value&&(M.value=n.chatModelNames[0]),await a.loadDocuments()}),te(M,v=>{if(!v)return;const w=n.getModelDefaults(v);Object.keys(w).length>0&&(O.value={systemPrompt:O.value.systemPrompt,options:{...w}})}),te(()=>o.activeConversationId,async v=>{if(!v)return;const w=o.conversations.get(v);if(w){w.model&&n.chatModelNames.includes(w.model)&&(M.value=w.model);try{const k=await Is.getSessionsByConversation(v);for(const R of k)l.sessionById(R.id)||(l.sessions.set(R.id,{id:R.id,mode:R.mode,model:R.model,status:R.status,createdAt:R.createdAt,prompt:R.prompt,messages:R.messages,options:R.options,outputText:R.outputText,metrics:R.metrics,error:R.error,doneReason:R.doneReason}),l.linkSessionToConversation(R.id,v)),await u.loadTokens(R.id)}catch(k){console.error("Failed to restore sessions for conversation:",k)}}});async function yt(v,w=[]){if(!M.value)return;let k=o.activeConversationId;k||(k=o.createConversation(M.value),Se.value!==e("dashboard.conversation.untitled")&&o.renameConversation(k,Se.value),Se.value=e("dashboard.conversation.untitled"));const R=o.conversations.get(k);R&&R.model!==M.value&&(R.model=M.value);const A=w.filter(G=>G.type==="document"&&G.content),L=w.filter(G=>G.type==="image"&&G.content);let Y=v;A.length>0&&(Y=A.map(ee=>`[Attached: ${ee.name}]
108
- ${ee.content}`).join(`
109
-
110
- `)+`
111
-
112
- ---
113
-
114
- `+v);const fe={id:be(),conversationId:k,role:"user",content:Y,timestamp:Date.now(),isStreaming:!1,attachments:w.length>0?w:void 0};o.addMessage(k,fe);const ue=be(),Be={id:ue,conversationId:k,role:"assistant",content:"",timestamp:Date.now(),isStreaming:!0};o.addMessage(k,Be);const de=o.getMessagesAsOllamaFormat(k).slice(0,-1);if(L.length>0){const G=[...de].reverse().find(ee=>ee.role==="user");G&&(G.images=L.map(ee=>ee.content.replace(/^data:[^;]+;base64,/,"")))}if(O.value.systemPrompt.trim()&&de.unshift({role:"system",content:O.value.systemPrompt.trim()}),U.value&&a.enabledDocuments.length>0)try{const G=await a.getContextForQuery(v,M.value,5);G&&de.unshift({role:"system",content:G})}catch{}let kt=de;try{const G=p.getSummary(k)?.summary,ee=await gn({conversationId:k,messages:de,model:M.value,settings:p.settings,userFactsPrompt:p.getFactsAsSystemPrompt(),existingSummary:G});if(kt=ee.messages,ee.newSummary){const xe=de.filter(wt=>wt.role!=="system");p.setSummary(k,ee.newSummary,xe.length)}}catch{}try{const G={...ce.value?.options,...O.value.options},ee=i.enabledDefinitions,xe=await S(M.value,kt,G,ee.length>0?ee:void 0),$t=o.conversations.get(k)?.messages.find(pe=>pe.id===ue);$t&&($t.sessionId=xe),l.linkSessionToConversation(xe,k);const $s=te(()=>l.sessionById(xe)?.outputText,pe=>{pe!==void 0&&o.updateAssistantContent(k,ue,pe)}),St=k,Ss=v,_s=te(()=>l.sessionById(xe)?.status,pe=>{if((pe==="completed"||pe==="error"||pe==="cancelled")&&(o.finalizeMessage(St,ue),h.value=!1,$s(),_s(),u.persistTokens(xe),pe==="completed"&&p.settings.ragMemory.enabled&&p.settings.ragMemory.embeddingModel)){const Cs=l.sessionById(xe)?.outputText??"";fn(St,[{role:"user",content:Ss,timestamp:fe.timestamp},{role:"assistant",content:Cs,timestamp:Date.now()}],p.settings.ragMemory.embeddingModel).catch(()=>{})}})}catch{o.finalizeMessage(k,ue)}}function xs(){C()}function bs(){o.setActiveConversation(null),Se.value=e("dashboard.conversation.untitled")}function vs(v){s.push({name:"session",params:{id:v}})}function ve(v){le.value=v,ge&&clearTimeout(ge),ge=setTimeout(()=>{le.value=null},5e3)}function ys(){le.value=null,ge&&clearTimeout(ge)}const ks={systemPrompt:"",options:{}};async function ws(v,w){const k=mn(v);if(!k){ve(`Unknown command: /${v}. Type /help for available commands.`);return}const R={clearConversation:()=>o.setActiveConversation(null),newChat:()=>o.setActiveConversation(null),sendAsUser:A=>yt(A),copyLastResponse:()=>{const A=je.value.filter(Y=>Y.role==="assistant"),L=A[A.length-1];L?.content?(navigator.clipboard.writeText(L.content),ve("Copied to clipboard.")):ve("No assistant response to copy.")},exportConversation:A=>{const L=ce.value;if(!L||L.messages.length===0){ve("No conversation to export.");return}let Y,fe;A==="json"?(Y=JSON.stringify(L.messages,null,2),fe=`chat-${L.id}.json`):(Y=L.messages.map(de=>`[${de.role}] ${de.content}`).join(`
115
-
116
- `),fe=`chat-${L.id}.txt`);const ue=new Blob([Y],{type:"text/plain"}),Be=URL.createObjectURL(ue),Fe=document.createElement("a");Fe.href=Be,Fe.download=fe,Fe.click(),URL.revokeObjectURL(Be)},setSystemPrompt:A=>{O.value={...O.value,systemPrompt:A}},setOption:(A,L)=>{O.value={...O.value,options:{...O.value.options,[A]:L}}},resetSettings:()=>{O.value={...ks}},setJsonFormat:A=>{ve("JSON format toggled. This affects the next request.")},switchModel:A=>{M.value=A},availableModels:n.chatModelNames,currentModel:M.value,toggleRag:()=>{U.value=!U.value},ragEnabled:U.value,navigate:A=>s.push(A),openSettings:()=>{q.value=!0},openSessionDetails:()=>{const A=$e.value;A?s.push({name:"session",params:{id:A}}):ve("No active session.")},addFact:A=>p.addFact(A),removeFact:A=>p.removeFactByContent(A),getFacts:()=>p.facts,showNotification:ve,messages:je.value,chatSettings:O,currentSessionId:$e.value??b.value,getSessionTokenCount:()=>{const A=$e.value??b.value;if(!A)return null;const L=c.getMetrics(A);return L?{prompt:L.promptTokenCount,completion:L.completionTokenCount}:null},getAverageSpeed:()=>{const A=c.aggregate;return A.totalSessions>0?A.avgTps:null},getOllamaStatus:async()=>{try{return{connected:(await fetch("/api/tags")).ok,model:M.value}}catch{return{connected:!1,model:M.value}}}};await k.execute(w,R)}return(v,w)=>(m(),x("div",ll,[I(Ft,{"enter-active-class":"transition-all duration-200 ease-out","enter-from-class":"opacity-0 -translate-y-2","leave-active-class":"transition-all duration-150 ease-in","leave-to-class":"opacity-0 -translate-y-2"},{default:Bt(()=>[le.value?(m(),x("div",il,[r("div",cl,[r("p",ul,d(le.value),1),r("button",{class:"shrink-0 text-text-muted hover:text-text-primary transition-colors text-xs",onClick:ys}," ✕ ")])])):z("",!0)]),_:1}),r("div",dl,[r("div",pl,[r("div",hl,[r("button",{class:"flex items-center gap-2 rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none hover:border-accent/50 focus:border-accent",onClick:w[0]||(w[0]=k=>_.value=!_.value),onBlur:j},[M.value?(m(),x(H,{key:1},[r("span",null,d(M.value),1),I(_t,{"model-name":M.value},null,8,["model-name"])],64)):(m(),x("span",ml,d(v.$t("common.model.noModels")),1)),I(f(Fs),{class:P(["h-3 w-3 text-text-muted transition-transform",_.value?"rotate-180":""])},null,8,["class"])],32),_.value?(m(),x("div",gl,[(m(!0),x(H,null,X(f(n).chatModelNames,k=>(m(),x("button",{key:k,class:P(["flex w-full items-center gap-2 px-3 py-1.5 text-start text-sm transition-colors",k===M.value?"bg-accent/10 text-accent":"text-text-primary hover:bg-surface-overlay"]),onMousedown:Ve(R=>{M.value=k,_.value=!1},["prevent"])},[r("span",null,d(k),1),I(_t,{"model-name":k},null,8,["model-name"])],42,fl))),128))])):z("",!0)]),Me.value?(m(),x("div",xl,[W(r("input",{"onUpdate:modelValue":w[1]||(w[1]=k=>Le.value=k),class:"w-48 rounded border border-accent bg-surface px-2 py-0.5 text-xs text-text-primary outline-none",onBlur:vt,onKeydown:fs,onVnodeMounted:w[2]||(w[2]=k=>{k.el.focus(),k.el.select()})},null,544),[[Q,Le.value]])])):(m(),x("button",{key:1,class:"flex items-center gap-1 rounded px-1.5 py-0.5 text-xs text-text-muted hover:text-text-primary hover:bg-surface-overlay transition-colors truncate max-w-[200px]",title:v.$t("dashboard.conversation.clickToRename"),onClick:ms},[r("span",vl,d(bt.value),1),I(f(Ct),{class:"h-2.5 w-2.5 shrink-0 opacity-0 group-hover:opacity-100"})],8,bl))]),r("div",yl,[$e.value?(m(),x("button",{key:0,class:"rounded-lg px-3 py-1.5 text-xs text-accent hover:bg-surface-overlay transition-colors",onClick:w[3]||(w[3]=k=>vs($e.value))},d(v.$t("dashboard.conversation.viewSessionDetails")),1)):z("",!0),r("button",{class:P(["flex items-center gap-1 rounded-lg px-3 py-1.5 text-xs transition-colors",K.value?"bg-accent/10 text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:w[4]||(w[4]=k=>K.value=!K.value)},[I(f(Js),{class:"h-3.5 w-3.5"}),r("span",null,d(v.$t("dashboard.conversation.history")),1)],2),r("div",kl,[r("button",{class:P(["flex items-center gap-1 rounded-lg px-3 py-1.5 text-xs transition-colors",V.value?"bg-accent/10 text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:w[5]||(w[5]=k=>V.value=!V.value)},[I(f(Ks),{class:"h-3.5 w-3.5"}),r("span",null,d(v.$t("common.actions.export")),1)],2),V.value?(m(),x("div",{key:0,class:"fixed inset-0 z-10",onClick:w[6]||(w[6]=k=>V.value=!1)})):z("",!0),V.value?(m(),x("div",wl,[r("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:J},d(v.$t("dashboard.export.downloadJson")),1),r("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:he},d(v.$t("dashboard.export.downloadMarkdown")),1),r("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:se},d(v.$t("dashboard.export.downloadText")),1)])):z("",!0)]),r("button",{class:"rounded-lg px-3 py-1.5 text-xs text-text-secondary hover:bg-surface-overlay hover:text-text-primary transition-colors",onClick:bs},d(v.$t("dashboard.conversation.newChatButton")),1),r("button",{class:P(["flex items-center gap-1 rounded-lg px-3 py-1.5 text-xs transition-colors",q.value?"bg-accent/10 text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:w[7]||(w[7]=k=>q.value=!q.value)},[I(f(Ps),{class:"h-3.5 w-3.5"}),r("span",null,d(v.$t("dashboard.settings.chatSettings")),1)],2)])]),r("div",$l,[K.value?(m(),x("div",Sl,[r("div",_l,[r("span",Cl,d(v.$t("dashboard.conversation.chatHistory")),1),r("button",{class:"text-text-muted hover:text-text-primary transition-colors text-xs",onClick:w[8]||(w[8]=k=>K.value=!1)}," ✕ ")]),r("div",Tl,[f(o).recentConversations.length===0?(m(),x("p",Ml,d(v.$t("dashboard.conversation.noConversationsYet")),1)):(m(),x("div",Rl,[(m(!0),x(H,null,X(f(o).recentConversations,k=>(m(),x("div",{key:k.id,class:P(["group flex items-center gap-1 rounded-lg px-2.5 py-2 text-xs transition-colors cursor-pointer",k.id===f(o).activeConversationId?"bg-surface-overlay text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:R=>Te(k.id)},[re.value===k.id?(m(),x("div",Nl,[W(r("input",{"onUpdate:modelValue":w[9]||(w[9]=R=>me.value=R),class:"w-full rounded bg-surface px-1.5 py-0.5 text-xs text-text-primary outline-none border border-accent",onBlur:R=>$(k.id),onKeydown:R=>T(R,k.id),onVnodeMounted:w[10]||(w[10]=R=>{R.el.focus(),R.el.select()})},null,40,zl),[[Q,me.value]])])):(m(),x(H,{key:1},[r("div",El,[r("p",Pl,d(k.name),1),r("p",Il,d(k.model)+" · "+d(D(k.updatedAt)),1)]),r("div",Dl,[r("button",{class:"rounded p-0.5 text-text-muted hover:text-text-primary transition-colors",title:v.$t("dashboard.conversation.rename"),onClick:Ve(R=>g(k.id,k.name),["stop"])},[I(f(Ct),{class:"h-3 w-3"})],8,jl),r("button",{class:"rounded p-0.5 text-text-muted hover:text-error transition-colors",title:v.$t("common.actions.delete"),onClick:Ve(R=>f(o).deleteConversation(k.id),["stop"])},[I(f(Ke),{class:"h-3 w-3"})],8,Ll)])],64))],10,Al))),128))]))])])):z("",!0),r("div",Bl,[xt.value?(m(),x("div",Fl,[r("span",Ol,d(v.$t("common.status.error"))+":",1),Ce(" "+d(xt.value),1)])):z("",!0),I(jo,{messages:je.value},null,8,["messages"]),I(fa,{"is-streaming":f(h),"selected-model":M.value,"is-vision-model":hs.value,onSend:yt,onCommand:ws,onCancel:xs},null,8,["is-streaming","selected-model","is-vision-model"])]),q.value?(m(),x("div",Ul,[r("div",Vl,[r("span",ql,d(v.$t("dashboard.settings.chatSettings")),1),r("button",{class:"text-text-muted hover:text-text-primary transition-colors text-xs",onClick:w[11]||(w[11]=k=>q.value=!1)}," ✕ ")]),I(rl,{modelValue:O.value,"onUpdate:modelValue":w[12]||(w[12]=k=>O.value=k),"selected-model":M.value,"rag-enabled":U.value,"onUpdate:ragEnabled":w[13]||(w[13]=k=>U.value=k)},null,8,["modelValue","selected-model","rag-enabled"])])):z("",!0)])]))}}),Wl={class:"rounded-lg border border-border-default bg-surface-raised"},Gl={class:"overflow-x-auto"},Zl={class:"w-full text-sm"},Kl=["onClick"],Jl={class:"px-4 py-2 font-medium text-text-primary"},Ql={class:"px-4 py-2"},Xl={class:"px-4 py-2 text-text-secondary"},Yl={class:"px-4 py-2 text-text-secondary"},ei={class:"px-4 py-2 text-text-secondary"},ti={class:"px-4 py-2 text-text-muted"},si={key:0},ni=ne({__name:"SessionHistoryTable",setup(t){const e=Je();return(s,o)=>(m(),x("div",Wl,[o[2]||(o[2]=r("div",{class:"px-4 py-3 border-b border-border-default"},[r("h3",{class:"text-sm font-medium text-text-secondary"},"Recent Sessions")],-1)),r("div",Gl,[r("table",Zl,[o[1]||(o[1]=r("thead",null,[r("tr",{class:"border-b border-border-default text-left text-xs text-text-muted uppercase tracking-wide"},[r("th",{class:"px-4 py-2"},"Model"),r("th",{class:"px-4 py-2"},"Status"),r("th",{class:"px-4 py-2"},"Tokens"),r("th",{class:"px-4 py-2"},"Speed"),r("th",{class:"px-4 py-2"},"Duration"),r("th",{class:"px-4 py-2"},"When")])],-1)),r("tbody",null,[(m(!0),x(H,null,X(f(e).recentSessions.slice(0,20),n=>(m(),x("tr",{key:n.id,class:"border-b border-border-default last:border-0 hover:bg-surface-overlay cursor-pointer transition-colors",onClick:l=>s.$router.push({name:"session",params:{id:n.id}})},[r("td",Jl,d(n.model),1),r("td",Ql,[I(Vs,{status:n.status,detail:n.error},null,8,["status","detail"])]),r("td",Xl,d(n.metrics?n.metrics.totalTokenCount:"—"),1),r("td",Yl,d(n.metrics?f(qe)(n.metrics.tokensPerSecond):"—"),1),r("td",ei,d(n.metrics?f(Ht)(n.metrics.totalDurationMs):"—"),1),r("td",ti,d(f(Ds)(n.createdAt)),1)],8,Kl))),128)),f(e).recentSessions.length===0?(m(),x("tr",si,[...o[0]||(o[0]=[r("td",{colspan:"6",class:"px-4 py-8 text-center text-text-muted"},"No sessions yet",-1)])])):z("",!0)])])])]))}}),oi={class:"flex h-full flex-col"},ai={class:"flex-1 min-h-0"},ri={key:0,class:"border-t border-border-default"},li={key:0,class:"max-h-80 overflow-auto px-4 pb-4 space-y-4"},ii={class:"grid grid-cols-2 gap-3 lg:grid-cols-4"},ci={key:1,class:"border-t border-border-default px-4 py-2"},ui={class:"text-[10px] uppercase tracking-wider text-text-muted mb-1"},di={class:"flex gap-2 overflow-x-auto pb-1"},pi=["onClick"],Mi=ne({__name:"DashboardPage",setup(t){const e=at(),s=qt(),o=N(!1),n=F(()=>e.aggregate),l=F(()=>n.value.totalSessions>0),a=F(()=>s.recentConversations);return(c,i)=>(m(),x("div",oi,[r("div",ai,[I(Hl)]),l.value?(m(),x("div",ri,[r("button",{class:"flex w-full items-center justify-between px-4 py-2 text-xs text-text-secondary hover:bg-surface-overlay transition-colors",onClick:i[0]||(i[0]=p=>o.value=!o.value)},[r("span",null,d(n.value.totalSessions)+" "+d(c.$t("dashboard.metrics.sessions"))+" · Avg "+d(f(qe)(n.value.avgTps)),1),r("span",{class:P(["transition-transform",{"rotate-180":o.value}])},"▾",2)]),o.value?(m(),x("div",li,[r("div",ii,[I(Oe,{label:c.$t("dashboard.metrics.totalSessions"),value:n.value.totalSessions},null,8,["label","value"]),I(Oe,{label:c.$t("dashboard.metrics.avgTtft"),value:f(Ht)(n.value.avgTtftMs)},null,8,["label","value"]),I(Oe,{label:c.$t("dashboard.metrics.avgSpeed"),value:f(qe)(n.value.avgTps)},null,8,["label","value"]),I(Oe,{label:c.$t("dashboard.metrics.totalTokens"),value:f(_e)(n.value.totalTokensGenerated),unit:"tok"},null,8,["label","value"])]),I(ni)])):z("",!0)])):z("",!0),a.value.length>1?(m(),x("div",ci,[r("p",ui,d(c.$t("dashboard.metrics.recentChats")),1),r("div",di,[(m(!0),x(H,null,X(a.value.slice(0,5),p=>(m(),x("button",{key:p.id,class:P(["shrink-0 rounded-lg px-3 py-1.5 text-xs transition-colors",f(s).activeConversationId===p.id?"bg-accent/10 text-accent":"bg-surface-overlay text-text-secondary hover:text-text-primary"]),onClick:u=>f(s).setActiveConversation(p.id)},d(p.name),11,pi))),128))])])):z("",!0)]))}});export{Mi as default};
@@ -1,15 +0,0 @@
1
- import{a as xe,u as fe}from"./toolcall-store-JKmpIFj3.js";import{u as be}from"./metrics-store-BMhkZ9B4.js";import{b as ve,a as te,u as ge}from"./agent-store-BWO6HamI.js";import{d as ye,a as he,b as ke}from"./download-WPaeALA4.js";import{_ as _e}from"./TabBar.vue_vue_type_script_setup_true_lang-DVCeD1qL.js";import{b as $e,_ as se,n as we,s as O,u as Ce}from"./StatusBadge.vue_vue_type_script_setup_true_lang-J8rYaobd.js";import{_ as Me}from"./TokenStreamDisplay.vue_vue_type_script_setup_true_lang-rJpx5sU7.js";import{c as B,a as Te,f as Y,e as Se}from"./format-BqVZ9rwM.js";import{C as J,a as K,L as U,P as ze,b as Le,p as oe,c as Q,d as ne,i as Ne,e as Ae,B as re,f as ae}from"./index-KhnkHbiC.js";import{c as Ie,b as L,e as l,f as e,t as c,p as w,u as C,a as $,j as s,F as N,k as A,q as P,g as F,h as T,d as Pe,r as S,A as le,i as y,K as je,l as H,L as De,M as Fe,B as X,w as V,C as W,G as Re,v as ie,T as Oe,X as Be,D as Z,H as qe,z as He}from"./index-ClE7gpZb.js";import{u as Ee}from"./tool-workshop-store-koPpdoxb.js";import{s as Ve,J as We,g as Ge}from"./JsonTreeNode-CDR0az7J.js";import{D as Je}from"./download-BqPPd3_X.js";import"./_plugin-vue_export-helper-DlAUqK2U.js";const j=Ie("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),Ke={class:"rounded-lg border border-border-default bg-surface-raised p-4"},Ue={class:"mb-3 text-sm font-medium text-text-secondary"},Qe={class:"h-40"},Xe=L({__name:"LatencyChart",props:{tokenLatencies:{},title:{}},setup(t){J.register(K,U,ze,Le,oe,Q,ne,Ne);const a=t,r=$(()=>({labels:a.tokenLatencies.map((m,d)=>`${d}`),datasets:[{label:"Token Latency (ms)",data:a.tokenLatencies,borderColor:"#a855f7",backgroundColor:"rgba(168, 85, 247, 0.1)",borderWidth:1.5,pointRadius:0,fill:!0,tension:.3}]})),n={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1},title:{display:!1}},scales:{x:{display:!1},y:{ticks:{color:"#94a3b8",font:{size:10}},grid:{color:"rgba(71, 85, 105, 0.3)"}}}};return(m,d)=>(s(),l("div",Ke,[e("h3",Ue,c(t.title??"Token Latency"),1),e("div",Qe,[w(C(Ae),{data:r.value,options:n},null,8,["data"])])]))}}),Ye={class:"rounded-lg border border-border-default bg-surface-raised p-4"},Ze={class:"h-20"},et={class:"mt-2 flex gap-4 text-xs text-text-muted"},tt=L({__name:"TokenCountBar",props:{promptTokens:{},completionTokens:{}},setup(t){J.register(K,U,re,oe,Q,ne);const a=t,r=$(()=>({labels:["Tokens"],datasets:[{label:"Prompt",data:[a.promptTokens],backgroundColor:"#818cf8"},{label:"Completion",data:[a.completionTokens],backgroundColor:"#a855f7"}]})),n={indexAxis:"y",responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"bottom",labels:{color:"#94a3b8",font:{size:11}}}},scales:{x:{stacked:!0,ticks:{color:"#94a3b8",font:{size:10}},grid:{color:"rgba(71, 85, 105, 0.3)"}},y:{stacked:!0,display:!1}}};return(m,d)=>(s(),l("div",Ye,[d[0]||(d[0]=e("h3",{class:"mb-3 text-sm font-medium text-text-secondary"},"Token Distribution",-1)),e("div",Ze,[w(C(ae),{data:r.value,options:n},null,8,["data"])]),e("div",et,[e("span",null,"Total: "+c(t.promptTokens+t.completionTokens),1)])]))}}),st={key:0,class:"space-y-4"},ot={class:"grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6"},nt={class:"grid grid-cols-1 gap-3 lg:grid-cols-2"},rt={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},at=L({__name:"MetricsDashboard",props:{metrics:{}},setup(t){const a=t,r=$(()=>{const n=a.metrics;return n?[{label:"Time to First Token",value:B(n.ttftMs),unit:""},{label:"Tokens/Second",value:Te(n.tokensPerSecond),unit:""},{label:"Total Duration",value:B(n.totalDurationMs),unit:""},{label:"Prompt Tokens",value:Y(n.promptTokenCount),unit:"tok"},{label:"Completion Tokens",value:Y(n.completionTokenCount),unit:"tok"},{label:"Model Load",value:B(n.loadDurationMs),unit:""}]:[]});return(n,m)=>t.metrics?(s(),l("div",st,[e("div",ot,[(s(!0),l(N,null,A(r.value,d=>(s(),P($e,{key:d.label,label:d.label,value:d.value,unit:d.unit},null,8,["label","value","unit"]))),128))]),e("div",nt,[w(Xe,{"token-latencies":t.metrics.tokenLatencies},null,8,["token-latencies"]),w(tt,{"prompt-tokens":t.metrics.promptTokenCount,"completion-tokens":t.metrics.completionTokenCount},null,8,["prompt-tokens","completion-tokens"])])])):(s(),l("div",rt," Metrics will appear after generation completes. "))}}),lt={class:"flex gap-3"},it={class:"flex flex-col items-center"},dt={class:"flex h-8 w-8 items-center justify-center rounded-full bg-surface-overlay text-sm"},ut={class:"flex-1 pb-4"},ct={class:"flex items-center gap-2 mb-1"},mt={class:"text-xs text-text-muted"},pt={class:"rounded-lg border border-border-default bg-surface p-3 text-sm text-text-primary leading-relaxed"},xt=L({__name:"ReasoningStep",props:{step:{}},setup(t){const a={thought:{color:"text-accent",icon:"💭"},observation:{color:"text-success",icon:"👁"},action:{color:"text-warning",icon:"⚡"},conclusion:{color:"text-[#a78bfa]",icon:"✓"},reflection:{color:"text-[#f472b6]",icon:"↻"}};return(r,n)=>(s(),l("div",lt,[e("div",it,[e("div",dt,c(a[t.step.type]?.icon??"•"),1),n[0]||(n[0]=e("div",{class:"flex-1 w-px bg-border-default"},null,-1))]),e("div",ut,[e("div",ct,[e("span",{class:F(["text-xs font-semibold uppercase tracking-wide",a[t.step.type]?.color??"text-text-secondary"])},c(t.step.type),3),e("span",mt," Step "+c(t.step.index+1)+" · "+c(C(B)(t.step.durationMs)),1)]),e("div",pt,c(t.step.content),1)])]))}}),ft={class:"space-y-4"},bt={class:"flex items-center gap-4 rounded-lg border border-border-default bg-surface-raised p-4"},vt={class:"text-sm text-text-secondary"},gt={class:"font-semibold text-text-primary"},yt={class:"flex gap-2"},ht={key:0,class:"space-y-0"},kt={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},_t=L({__name:"ReasoningViewer",props:{sessionId:{}},setup(t){const a=t,r=ve(),n=$(()=>r.getSteps(a.sessionId)),m=$(()=>{const d={};for(const p of n.value)d[p.type]=(d[p.type]??0)+1;return d});return(d,p)=>(s(),l("div",ft,[e("div",bt,[e("div",vt,[e("span",gt,c(n.value.length),1),p[0]||(p[0]=T(" reasoning steps detected ",-1))]),e("div",yt,[(s(!0),l(N,null,A(m.value,(i,u)=>(s(),l("span",{key:u,class:"rounded-full bg-surface-overlay px-2.5 py-0.5 text-xs text-text-secondary"},c(u)+": "+c(i),1))),128))])]),n.value.length>0?(s(),l("div",ht,[(s(!0),l(N,null,A(n.value,i=>(s(),P(xt,{key:i.id,step:i},null,8,["step"]))),128))])):(s(),l("div",kt,[...p[1]||(p[1]=[e("p",null,"No reasoning steps detected.",-1),e("p",{class:"mt-1"},"Use a model with chain-of-thought support (e.g., DeepSeek-R1) or structured reasoning patterns.",-1)])]))]))}}),de=Pe("introspection",()=>{const t=S(new Map),a=S(new Map),r=S(new Map);function n(x){return t.value.get(x)??null}function m(x,b){t.value.set(x,b)}function d(x){return a.value.get(x)??[]}function p(x,b){a.value.set(x,b)}function i(x){return r.value.get(x)??[]}function u(x,b){r.value.set(x,b)}return{architectureByModel:t,attentionPatterns:a,layerActivations:r,getArchitecture:n,setArchitecture:m,getAttentionPatterns:d,setAttentionPatterns:p,getLayerActivations:i,setLayerActivations:u}});function $t(t,a){const r=a.model_info,n=a.details.family||"unknown",m=R(r,"block_count")??32,d=R(r,"embedding_length")??4096,p=R(r,"attention.head_count")??32,i=R(r,"attention.head_count_kv")??p,u=R(r,"context_length")??4096,x=R(r,"feed_forward_length")??d*4,b=a.details.parameter_size||"0",g=Mt(b),v=Tt(m);return{family:n,blockCount:m,embeddingLength:d,attentionHeadCount:p,kvHeadCount:i,contextLength:u,feedForwardLength:x,layers:v,totalParameters:g,quantization:a.details.quantization_level||"unknown"}}function wt(t,a,r){const n=[],m=t.length,d=Math.min(a,2),p=Math.min(r,2);for(let i=0;i<p;i++)for(let u=0;u<d;u++){const x=[];for(let b=0;b<m;b++){const g=[];for(let k=0;k<m;k++)if(k>b)g.push(0);else{const M=b-k,o=Math.exp(-M*(.1+i*.05)),f=Math.random()*.15,h=k===b?.3:0;g.push(Math.min(1,o+f+h))}const v=g.reduce((k,M)=>k+M,0);x.push(v>0?g.map(k=>k/v):g)}n.push({tokenLabels:t,matrix:x,headIndex:u,layerIndex:i})}return n}function Ct(t){const a=[];for(const r of t.layers){const n=Math.sqrt(t.embeddingLength)*(1+Math.random()*.5),m=r.type==="attention"?1:r.type==="feed_forward"?1.3:.8;a.push({layerIndex:r.index,layerName:r.name,meanActivation:(.5+Math.random()*.5)*m,maxActivation:(2+Math.random()*3)*m,norm:n*m*(.8+Math.random()*.4)})}return a}function R(t,a){for(const[r,n]of Object.entries(t))if(r.endsWith(a)&&typeof n=="number")return n}function Mt(t){const a=t.match(/([\d.]+)\s*([BMK])?/i);if(!a)return 0;const r=parseFloat(a[1]),n=(a[2]??"").toUpperCase();return n==="B"?r*1e9:n==="M"?r*1e6:n==="K"?r*1e3:r}function Tt(t){const a=[];let r=0;a.push({index:r++,name:"token_embedding",type:"embedding",parameterCount:0});for(let n=0;n<t;n++)a.push({index:r++,name:`block_${n}_attention`,type:"attention",parameterCount:0}),a.push({index:r++,name:`block_${n}_ffn`,type:"feed_forward",parameterCount:0}),a.push({index:r++,name:`block_${n}_norm`,type:"norm",parameterCount:0});return a.push({index:r++,name:"output",type:"output",parameterCount:0}),a}async function St(t){const a=le(),r=de();await a.fetchModelInfo(t);const n=a.getModelDetails(t);if(n){const m=$t(t,n);r.setArchitecture(t,m)}}const zt={class:"space-y-4"},Lt={key:0,class:"rounded-lg bg-surface p-4"},Nt={class:"flex items-center gap-2 flex-wrap"},At=["onMouseenter"],It={key:1,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-56 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},Pt={class:"grid grid-cols-2 gap-3 lg:grid-cols-4"},jt={class:"flex items-center gap-1 text-xs text-text-muted"},Dt={class:"text-sm font-medium text-text-primary"},Ft={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-56 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},Rt={class:"flex items-center gap-1 text-xs text-text-muted"},Ot={class:"text-sm font-medium text-text-primary"},Bt={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-56 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},qt={class:"flex items-center gap-1 text-xs text-text-muted"},Ht={class:"text-sm font-medium text-text-primary"},Et={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-64 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},Vt={class:"flex items-center gap-1 text-xs text-text-muted"},Wt={class:"text-sm font-medium text-text-primary"},Gt={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-64 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},Jt={class:"rounded-lg bg-surface p-4"},Kt={class:"flex items-center gap-1 mb-3"},Ut={class:"text-xs font-medium text-text-muted uppercase tracking-wide"},Qt={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-64 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},Xt={class:"flex items-center gap-2 flex-wrap"},Yt=["onMouseenter"],Zt={class:"text-xs text-text-primary"},es={class:"text-xs text-text-muted"},ts={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-60 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},ss={class:"grid grid-cols-2 gap-3 text-xs"},os={class:"ms-1 text-text-primary"},ns={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-60 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},rs={class:"ms-1 text-text-primary"},as={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-64 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},ls={class:"ms-1 text-text-primary"},is={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-60 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},ds={class:"ms-1 text-text-primary"},us={key:0,class:"absolute top-full left-1/2 -translate-x-1/2 mt-2 w-64 rounded-lg border border-border-default bg-surface-overlay px-3 py-2 text-xs text-text-secondary shadow-lg z-10"},cs={key:1,class:"rounded-lg bg-surface"},ms={key:0,class:"border-t border-border-default px-4 pb-4 pt-2"},ps={class:"w-full text-xs"},xs={class:"py-1.5 pe-4 text-text-muted font-mono"},fs={class:"py-1.5 text-text-primary font-mono"},bs={key:2,class:"rounded-lg bg-surface"},vs={key:0,class:"border-t border-border-default px-4 pb-4 pt-2"},gs={class:"overflow-auto rounded-lg bg-surface-raised p-3 text-xs text-text-secondary font-mono leading-relaxed"},ys=L({__name:"ModelArchitectureDiagram",props:{architecture:{},modelName:{}},setup(t){const a=t,r=le(),n=$(()=>a.modelName?r.getModelDetails(a.modelName)??null:null),m=$(()=>{if(!n.value?.parameters)return null;const M=De(n.value.parameters);return Object.keys(M).length>0?M:null}),d=$(()=>n.value?.template??null),p=S(!1),i=S(!1),u=$(()=>a.modelName?Fe(r.getCapabilities(a.modelName)):[]),x={embedding:"#818cf8",attention:"#a855f7",feed_forward:"#fb923c",norm:"#94a3b8",output:"#4ade80"},b=$(()=>{const M=a.architecture;return[{label:"Embedding",color:x.embedding,count:1,desc:"Converts input tokens into dense numerical vectors the model can process"},{label:"Attention",color:x.attention,count:M.blockCount,desc:"Lets each token attend to every other token to capture relationships and context"},{label:"FFN",color:x.feed_forward,count:M.blockCount,desc:"Feed-Forward Network — applies non-linear transformations to refine representations"},{label:"LayerNorm",color:x.norm,count:M.blockCount,desc:"Normalizes activations between layers to stabilize and speed up training"},{label:"Output",color:x.output,count:1,desc:"Projects the final hidden state back to vocabulary size to predict the next token"}]}),g=S(null);function v(M){g.value=M}function k(){g.value=null}return(M,o)=>(s(),l("div",zt,[u.value.length>0?(s(),l("div",Lt,[o[12]||(o[12]=e("h4",{class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-3"},"Capabilities",-1)),e("div",Nt,[(s(!0),l(N,null,A(u.value,f=>(s(),l("div",{key:f.key,class:"relative flex items-center gap-1.5 rounded-lg border border-border-default px-3 py-1.5",onMouseenter:h=>v("cap-"+f.key),onMouseleave:k},[f.icon?(s(),P(je(f.icon),{key:0,class:F(["h-3.5 w-3.5 shrink-0",f.color])},null,8,["class"])):y("",!0),e("span",{class:F(["text-xs font-medium",f.color])},c(f.label),3),g.value==="cap-"+f.key?(s(),l("div",It,[T(c(f.desc)+" ",1),o[11]||(o[11]=e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1))])):y("",!0)],40,At))),128))])])):y("",!0),e("div",Pt,[e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[0]||(o[0]=f=>v("family")),onMouseleave:k},[e("div",jt,[o[13]||(o[13]=T(" Family ",-1)),w(C(j),{class:"h-3 w-3"})]),e("div",Dt,c(t.architecture.family),1),g.value==="family"?(s(),l("div",Ft,[...o[14]||(o[14]=[T(" The base model architecture family (e.g. llama, qwen). Models in the same family share the same neural network design. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[1]||(o[1]=f=>v("params")),onMouseleave:k},[e("div",Rt,[o[15]||(o[15]=T(" Parameters ",-1)),w(C(j),{class:"h-3 w-3"})]),e("div",Ot,c(C(Se)(t.architecture.totalParameters)),1),g.value==="params"?(s(),l("div",Bt,[...o[16]||(o[16]=[T(" Total number of trainable weights in the model. More parameters generally means greater capability but requires more memory and compute. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[2]||(o[2]=f=>v("ctx")),onMouseleave:k},[e("div",qt,[o[17]||(o[17]=T(" Context Length ",-1)),w(C(j),{class:"h-3 w-3"})]),e("div",Ht,c(t.architecture.contextLength.toLocaleString()),1),g.value==="ctx"?(s(),l("div",Et,[...o[18]||(o[18]=[T(" Maximum number of tokens (prompt + response) the model can process in a single conversation. Longer context allows more detailed instructions and longer conversations. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[3]||(o[3]=f=>v("quant")),onMouseleave:k},[e("div",Vt,[o[19]||(o[19]=T(" Quantization ",-1)),w(C(j),{class:"h-3 w-3"})]),e("div",Wt,c(t.architecture.quantization),1),g.value==="quant"?(s(),l("div",Gt,[...o[20]||(o[20]=[T(" How model weights are compressed. Q4_K_M means 4-bit quantization with K-quant medium quality — smaller file size and faster inference with a small quality trade-off vs full precision (F16/F32). ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32)]),e("div",Jt,[e("div",Kt,[e("h4",Ut,"Layer Structure ("+c(t.architecture.blockCount)+" blocks)",1),e("div",{class:"relative",onMouseenter:o[4]||(o[4]=f=>v("layers")),onMouseleave:k},[w(C(j),{class:"h-3 w-3 text-text-muted"}),g.value==="layers"?(s(),l("div",Qt,[...o[21]||(o[21]=[T(" Transformer models are built from repeated blocks. Each block contains attention, feed-forward, and normalization layers. More blocks = deeper model. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32)]),e("div",Xt,[(s(!0),l(N,null,A(b.value,f=>(s(),l("div",{key:f.label,class:"relative flex items-center gap-2 rounded-lg border border-border-default px-3 py-2",onMouseenter:h=>v("block-"+f.label),onMouseleave:k},[e("div",{class:"h-3 w-3 rounded-sm",style:H({backgroundColor:f.color})},null,4),e("span",Zt,c(f.label),1),e("span",es,"×"+c(f.count),1),g.value==="block-"+f.label?(s(),l("div",ts,[T(c(f.desc)+" ",1),o[22]||(o[22]=e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1))])):y("",!0)],40,Yt))),128))])]),e("div",ss,[e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[5]||(o[5]=f=>v("aheads")),onMouseleave:k},[o[24]||(o[24]=e("span",{class:"text-text-muted"},"Attention Heads",-1)),w(C(j),{class:"inline ms-1 h-3 w-3 text-text-muted align-text-top"}),e("span",os,c(t.architecture.attentionHeadCount),1),g.value==="aheads"?(s(),l("div",ns,[...o[23]||(o[23]=[T(" Number of parallel attention computations per layer. Each head learns to focus on different patterns (syntax, semantics, position, etc.). ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[6]||(o[6]=f=>v("kvheads")),onMouseleave:k},[o[26]||(o[26]=e("span",{class:"text-text-muted"},"KV Heads",-1)),w(C(j),{class:"inline ms-1 h-3 w-3 text-text-muted align-text-top"}),e("span",rs,c(t.architecture.kvHeadCount),1),g.value==="kvheads"?(s(),l("div",as,[...o[25]||(o[25]=[T(" Key-Value heads used in Grouped Query Attention (GQA). Fewer KV heads than attention heads means memory savings — multiple query heads share the same key/value projections. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[7]||(o[7]=f=>v("embdim")),onMouseleave:k},[o[28]||(o[28]=e("span",{class:"text-text-muted"},"Embedding Dim",-1)),w(C(j),{class:"inline ms-1 h-3 w-3 text-text-muted align-text-top"}),e("span",ls,c(t.architecture.embeddingLength),1),g.value==="embdim"?(s(),l("div",is,[...o[27]||(o[27]=[T(" Size of the vector representing each token inside the model. Larger dimensions can capture richer semantic information but increase memory and compute. ",-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32),e("div",{class:"relative rounded-lg bg-surface p-3",onMouseenter:o[8]||(o[8]=f=>v("ffndim")),onMouseleave:k},[o[30]||(o[30]=e("span",{class:"text-text-muted"},"FFN Dim",-1)),w(C(j),{class:"inline ms-1 h-3 w-3 text-text-muted align-text-top"}),e("span",ds,c(t.architecture.feedForwardLength),1),g.value==="ffndim"?(s(),l("div",us,[...o[29]||(o[29]=[T(` Width of the feed-forward network's hidden layer. Typically 2-4x the embedding dimension. This is where much of the model's "knowledge" is stored as learned patterns. `,-1),e("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 -mb-px border-4 border-transparent border-b-surface-overlay"},null,-1)])])):y("",!0)],32)]),m.value?(s(),l("div",cs,[e("button",{class:"flex w-full items-center justify-between p-4 text-start",onClick:o[9]||(o[9]=f=>p.value=!p.value)},[o[32]||(o[32]=e("h4",{class:"text-xs font-medium text-text-muted uppercase tracking-wide"},"Model Defaults",-1)),(s(),l("svg",{class:F(["h-4 w-4 text-text-muted transition-transform",p.value?"rotate-180":""]),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[...o[31]||(o[31]=[e("path",{d:"M6 9l6 6 6-6"},null,-1)])],2))]),p.value?(s(),l("div",ms,[e("table",ps,[(s(!0),l(N,null,A(m.value,(f,h)=>(s(),l("tr",{key:h,class:"border-b border-border-default/50 last:border-0"},[e("td",xs,c(h),1),e("td",fs,c(f),1)]))),128))])])):y("",!0)])):y("",!0),d.value?(s(),l("div",bs,[e("button",{class:"flex w-full items-center justify-between p-4 text-start",onClick:o[10]||(o[10]=f=>i.value=!i.value)},[o[34]||(o[34]=e("h4",{class:"text-xs font-medium text-text-muted uppercase tracking-wide"},"Chat Template",-1)),(s(),l("svg",{class:F(["h-4 w-4 text-text-muted transition-transform",i.value?"rotate-180":""]),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[...o[33]||(o[33]=[e("path",{d:"M6 9l6 6 6-6"},null,-1)])],2))]),i.value?(s(),l("div",vs,[e("pre",gs,c(d.value),1)])):y("",!0)])):y("",!0)]))}}),hs={class:"space-y-3"},ks={class:"flex items-center justify-between"},_s=["value"],$s={key:0,class:"overflow-auto rounded-lg border border-border-default bg-surface p-2"},ws=L({__name:"AttentionHeatmap",props:{patterns:{}},setup(t){const a=t,r=S(0),n=S(null),m=$(()=>a.patterns[r.value]??null);function d(){const p=n.value,i=m.value;if(!p||!i)return;const u=p.getContext("2d");if(!u)return;const x=i.matrix.length,b=Math.min(Math.floor(400/x),20),g=x*b;p.width=g,p.height=g;for(let v=0;v<x;v++)for(let k=0;k<x;k++){const M=i.matrix[v]?.[k]??0,o=Math.floor(M*255);u.fillStyle=`rgb(${Math.floor(56+M*100)}, ${Math.floor(100+o*.5)}, ${o})`,u.fillRect(k*b,v*b,b,b)}}return X(d),V([m],d),(p,i)=>(s(),l("div",hs,[e("div",ks,[i[1]||(i[1]=e("div",{class:"flex items-center gap-2"},[e("h4",{class:"text-sm font-medium text-text-secondary"},"Attention Pattern"),e("span",{class:"rounded-full bg-warning/20 px-2 py-0.5 text-xs text-warning"},"Illustrative")],-1)),t.patterns.length>1?W((s(),l("select",{key:0,"onUpdate:modelValue":i[0]||(i[0]=u=>r.value=u),class:"rounded border border-border-default bg-surface px-2 py-1 text-xs text-text-primary"},[(s(!0),l(N,null,A(t.patterns,(u,x)=>(s(),l("option",{key:x,value:x}," Layer "+c(u.layerIndex)+" / Head "+c(u.headIndex),9,_s))),128))],512)),[[Re,r.value,void 0,{number:!0}]]):y("",!0)]),m.value?(s(),l("div",$s,[e("canvas",{ref_key:"canvasRef",ref:n,class:"max-w-full"},null,512)])):y("",!0),i[2]||(i[2]=e("p",{class:"text-xs text-text-muted leading-relaxed"},[T(" This is a "),e("strong",{class:"text-warning"},"synthetic illustration"),T(" of how attention patterns work in transformer models — it shows causal masking (tokens can only attend to previous tokens) and positional decay (nearby tokens get more attention). Real attention weights are not available through the Ollama API, so this visualization demonstrates the concept rather than reflecting actual model behavior. ")],-1))]))}}),Cs={class:"space-y-3"},Ms={class:"h-48 rounded-lg border border-border-default bg-surface-raised p-4"},Ts=L({__name:"LayerActivationChart",props:{activations:{}},setup(t){J.register(K,U,re,Q);const a=t,r=$(()=>({labels:a.activations.map(m=>m.layerName.replace(/^block_\d+_/,"")),datasets:[{label:"Norm",data:a.activations.map(m=>m.norm),backgroundColor:"#a855f7"}]})),n={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1}},scales:{x:{display:!1},y:{ticks:{color:"#94a3b8",font:{size:10}},grid:{color:"rgba(71, 85, 105, 0.3)"}}}};return(m,d)=>(s(),l("div",Cs,[d[0]||(d[0]=e("div",{class:"flex items-center gap-2"},[e("h4",{class:"text-sm font-medium text-text-secondary"},"Layer Activation Norms"),e("span",{class:"rounded-full bg-warning/20 px-2 py-0.5 text-xs text-warning"},"Simulated")],-1)),e("div",Ms,[w(C(ae),{data:r.value,options:n},null,8,["data"])]),d[1]||(d[1]=e("p",{class:"text-xs text-text-muted leading-relaxed"},[T(" This is a "),e("strong",{class:"text-warning"},"simulated visualization"),T(" of activation norms across the model's layers. In a real model, these norms reveal how much each layer contributes to the output — unusually high norms can indicate exploding gradients or bottleneck layers, while low norms may suggest underutilized capacity. Actual activation data requires hooking into the inference engine, which the Ollama API does not expose. ")],-1))]))}}),Ss={class:"space-y-6"},zs={key:0},Ls={key:1},Ns={key:2},As={key:3,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},Is=L({__name:"IntrospectionPanel",props:{sessionId:{},modelName:{}},setup(t){const a=t,r=de(),n=te(),m=$(()=>r.getArchitecture(a.modelName)),d=$(()=>r.getAttentionPatterns(a.sessionId)),p=$(()=>r.getLayerActivations(a.sessionId));return X(async()=>{m.value||await St(a.modelName);const i=m.value;if(i){if(d.value.length===0){const x=n.getTokens(a.sessionId).slice(0,30).map(b=>b.text);if(x.length>0){const b=wt(x,i.attentionHeadCount,i.blockCount);r.setAttentionPatterns(a.sessionId,b)}}if(p.value.length===0){const u=Ct(i);r.setLayerActivations(a.sessionId,u)}}}),(i,u)=>(s(),l("div",Ss,[m.value?(s(),l("div",zs,[u[0]||(u[0]=e("h3",{class:"mb-3 text-sm font-medium text-text-secondary"},"Model Architecture",-1)),w(ys,{architecture:m.value,"model-name":t.modelName},null,8,["architecture","model-name"])])):y("",!0),d.value.length>0?(s(),l("div",Ls,[w(ws,{patterns:d.value},null,8,["patterns"])])):y("",!0),p.value.length>0?(s(),l("div",Ns,[w(Ts,{activations:p.value},null,8,["activations"])])):y("",!0),m.value?y("",!0):(s(),l("div",As," Loading model introspection data... "))]))}}),Ps={class:"overflow-auto rounded-lg bg-surface p-3 text-xs text-text-secondary font-mono max-h-80"},G=L({__name:"JsonViewer",props:{data:{},maxDepth:{}},setup(t){const a=t,r=$(()=>{try{return JSON.stringify(a.data,null,2)}catch{return String(a.data)}});return(n,m)=>(s(),l("pre",Ps,c(r.value),1))}}),js={class:"rounded-lg border border-border-default bg-surface-raised"},Ds={class:"flex items-center gap-3"},Fs={class:"text-sm font-medium text-text-primary"},Rs={class:"ms-2 text-xs text-text-muted"},Os={class:"flex items-center gap-2"},Bs={key:0,class:"border-t border-border-default p-4 space-y-3"},qs={key:0},Hs={key:1},Es={class:"rounded-lg bg-error/10 p-3 text-xs text-error"},Vs=L({__name:"ToolCallCard",props:{entry:{}},emits:["optimize"],setup(t,{emit:a}){const r=t,n=a,m=$(()=>r.entry.status==="completed"&&r.entry.result!=null&&typeof r.entry.result=="object"),d=S(!1);return(p,i)=>(s(),l("div",js,[e("button",{class:"flex w-full items-center justify-between px-4 py-3 text-start hover:bg-surface-overlay transition-colors",onClick:i[0]||(i[0]=u=>d.value=!d.value)},[e("div",Ds,[i[2]||(i[2]=e("span",{class:"text-base"},"⚡",-1)),e("div",null,[e("span",Fs,c(t.entry.functionName),1),e("span",Rs,c(t.entry.durationMs!=null?C(B)(t.entry.durationMs):"pending"),1)])]),e("div",Os,[w(se,{status:t.entry.status},null,8,["status"]),e("span",{class:F(["text-text-muted transition-transform text-xs",{"rotate-180":d.value}])},"▾",2)])]),d.value?(s(),l("div",Bs,[e("div",null,[i[3]||(i[3]=e("div",{class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-1"},"Arguments",-1)),w(G,{data:t.entry.arguments},null,8,["data"])]),t.entry.result!==void 0?(s(),l("div",qs,[i[4]||(i[4]=e("div",{class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-1"},"Result",-1)),w(G,{data:t.entry.result},null,8,["data"])])):y("",!0),t.entry.error?(s(),l("div",Hs,[i[5]||(i[5]=e("div",{class:"text-xs font-medium text-error uppercase tracking-wide mb-1"},"Error",-1)),e("pre",Es,c(t.entry.error),1)])):y("",!0),m.value?(s(),l("button",{key:2,class:"mt-1 rounded-md border border-border-default px-3 py-1.5 text-xs font-medium text-accent hover:bg-surface-overlay transition-colors",onClick:i[1]||(i[1]=ie(u=>n("optimize",t.entry),["stop"]))}," Optimize this Tool ")):y("",!0)])):y("",!0)]))}}),Ws={class:"space-y-4"},Gs={class:"flex items-center gap-4 rounded-lg border border-border-default bg-surface-raised p-4"},Js={class:"text-sm text-text-secondary"},Ks={class:"font-semibold text-text-primary"},Us={key:0,class:"text-sm text-text-secondary"},Qs={class:"text-text-primary"},Xs={key:0,class:"space-y-3"},Ys={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},Zs=L({__name:"ToolCallTimeline",props:{sessionId:{}},emits:["optimize"],setup(t,{emit:a}){const r=t,n=a,m=xe(),d=$(()=>m.getToolCalls(r.sessionId)),p=$(()=>d.value.reduce((i,u)=>i+(u.durationMs??0),0));return(i,u)=>(s(),l("div",Ws,[e("div",Gs,[e("div",Js,[e("span",Ks,c(d.value.length),1),u[1]||(u[1]=T(" tool calls ",-1))]),p.value>0?(s(),l("div",Us,[u[2]||(u[2]=T(" Total: ",-1)),e("span",Qs,c(C(B)(p.value)),1)])):y("",!0)]),d.value.length>0?(s(),l("div",Xs,[(s(!0),l(N,null,A(d.value,x=>(s(),P(Vs,{key:x.id,entry:x,onOptimize:u[0]||(u[0]=b=>n("optimize",b))},null,8,["entry"]))),128))])):(s(),l("div",Ys,[...u[3]||(u[3]=[e("p",null,"No tool calls in this session.",-1),e("p",{class:"mt-1"},"Use chat mode with tool definitions to see tool call activity.",-1)])]))]))}});function eo(t){const a=ge(),r=$(()=>a.getGraph(t.value)),n=S(800),m=S(400),d=$(()=>{const i=r.value?.nodes??[];if(i.length===0)return[];const u=180,x=60,b=60,g=m.value/2,v=i.length*(u+b);return n.value=Math.max(800,v+100),i.map((k,M)=>({...k,x:50+M*(u+b),y:g-x/2}))}),p=$(()=>{const i=r.value?.edges??[],u=new Map(d.value.map(x=>[x.id,x]));return i.map(x=>{const b=u.get(x.source),g=u.get(x.target);return!b||!g?null:{...x,x1:b.x+180,y1:b.y+30,x2:g.x,y2:g.y+30}}).filter(x=>x!==null)});return{graph:r,layoutNodes:d,layoutEdges:p,svgWidth:n,svgHeight:m}}const to=["transform"],so=["stroke"],oo={x:"12",y:"24",class:"fill-text-primary text-xs font-medium","font-size":"12"},no={x:"12",y:"44",class:"fill-text-secondary text-xs","font-size":"11"},ro=L({__name:"AgentNode",props:{node:{},selected:{type:Boolean}},emits:["select"],setup(t){const a=t,r=$(()=>we[a.node.type]??"#94a3b8"),n={start:"▶",llm_call:"◈",tool_call:"⚡",decision:"◇",output:"■",error:"✕"};return(m,d)=>(s(),l("g",{transform:`translate(${t.node.x}, ${t.node.y})`,class:"cursor-pointer",onClick:d[0]||(d[0]=p=>m.$emit("select",t.node.id))},[e("rect",{width:"180",height:"60",rx:"8",class:F(["fill-surface-raised stroke-2",{"stroke-[3]":t.selected}]),stroke:r.value},null,10,so),e("text",oo,c(n[t.node.type]??"•")+" "+c(t.node.type),1),e("text",no,c(t.node.label.slice(0,22))+c(t.node.label.length>22?"...":""),1)],8,to))}}),ao={key:0,class:"rounded-lg border border-border-default bg-surface-raised p-4 space-y-3"},lo={class:"text-sm font-medium text-text-primary"},io={class:"grid grid-cols-2 gap-2 text-xs text-text-secondary"},uo={class:"text-text-primary"},co={class:"text-text-primary"},mo={key:0},po=L({__name:"AgentStateDiff",props:{node:{}},setup(t){return(a,r)=>t.node?(s(),l("div",ao,[e("h4",lo,c(t.node.label),1),e("div",io,[e("div",null,[r[0]||(r[0]=T("Type: ",-1)),e("span",uo,c(t.node.type),1)]),e("div",null,[r[1]||(r[1]=T("Step: ",-1)),e("span",co,c(t.node.stepIndex),1)])]),Object.keys(t.node.state).length>0?(s(),l("div",mo,[r[2]||(r[2]=e("div",{class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-1"},"State",-1)),w(G,{data:t.node.state},null,8,["data"])])):y("",!0)])):y("",!0)}}),xo={class:"space-y-4"},fo={key:0,class:"flex gap-4"},bo={class:"flex-1 overflow-auto rounded-lg border border-border-default bg-surface"},vo=["width","height"],go=["x1","y1","x2","y2"],yo={class:"w-72 shrink-0"},ho={key:0,class:"rounded-lg border border-border-default bg-surface-raised p-4 text-center text-sm text-text-muted"},ko={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},_o=L({__name:"AgentGraphView",props:{sessionId:{}},setup(t){const a=t,r=$(()=>a.sessionId),{layoutNodes:n,layoutEdges:m,svgWidth:d,svgHeight:p}=eo(r),i=S(null),u=$(()=>i.value?n.value.find(x=>x.id===i.value)??null:null);return(x,b)=>(s(),l("div",xo,[C(n).length>0?(s(),l("div",fo,[e("div",bo,[(s(),l("svg",{width:C(d),height:C(p),class:"min-w-full"},[(s(!0),l(N,null,A(C(m),g=>(s(),l("line",{key:g.id,x1:g.x1,y1:g.y1,x2:g.x2,y2:g.y2,class:"stroke-border-default","stroke-width":"2","marker-end":"url(#arrowhead)"},null,8,go))),128)),b[1]||(b[1]=e("defs",null,[e("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"10",refY:"3.5",orient:"auto"},[e("polygon",{points:"0 0, 10 3.5, 0 7",class:"fill-border-default"})])],-1)),(s(!0),l(N,null,A(C(n),g=>(s(),P(ro,{key:g.id,node:g,selected:i.value===g.id,onSelect:b[0]||(b[0]=v=>i.value=v)},null,8,["node","selected"]))),128))],8,vo))]),e("div",yo,[w(po,{node:u.value},null,8,["node"]),u.value?y("",!0):(s(),l("div",ho," Click a node to inspect its state. "))])])):(s(),l("div",ko,[...b[2]||(b[2]=[e("p",null,"No agent graph data for this session.",-1),e("p",{class:"mt-1"},"Agent graph nodes are created during generation.",-1)])]))]))}}),$o={class:"rounded-lg border border-border-default bg-surface-raised overflow-hidden"},wo={class:"flex items-center justify-between px-4 py-2 border-b border-border-default"},Co={class:"flex items-center gap-2"},Mo={class:"text-sm font-medium text-text-primary"},To={class:"rounded-full bg-surface-overlay px-2 py-0.5 text-xs text-text-muted"},So={class:"flex items-center gap-3 text-xs text-text-secondary"},zo={class:"text-text-muted"},Lo={class:"h-1 bg-surface"},No={class:"px-4 py-3 text-xs text-text-secondary font-mono whitespace-pre-wrap max-h-40 overflow-auto"},Ao=L({__name:"PromptSection",props:{section:{},totalTokens:{}},setup(t){const r=O[t.section.type]??O.unknown;return(n,m)=>(s(),l("div",$o,[e("div",wo,[e("div",Co,[e("div",{class:"h-3 w-3 rounded-sm",style:H({backgroundColor:C(r)})},null,4),e("span",Mo,c(t.section.label),1),e("span",To,c(t.section.type),1)]),e("div",So,[e("span",null,"~"+c(t.section.tokenCount)+" tokens",1),e("span",zo,c(t.section.percentage.toFixed(1))+"%",1)])]),e("div",Lo,[e("div",{class:"h-full transition-all",style:H({width:`${t.section.percentage}%`,backgroundColor:C(r)})},null,4)]),e("pre",No,c(t.section.content),1)]))}}),Io={class:"rounded-lg border border-border-default bg-surface-raised p-4"},Po={class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-3"},jo={class:"flex h-6 overflow-hidden rounded-lg"},Do=["title"],Fo={class:"mt-3 flex flex-wrap gap-3 text-xs"},Ro={class:"text-text-secondary"},Oo={class:"text-text-muted"},Bo=L({__name:"PromptTokenCount",props:{sections:{},totalTokens:{}},setup(t){return(a,r)=>(s(),l("div",Io,[e("h4",Po," Token Distribution (~"+c(t.totalTokens)+" total) ",1),e("div",jo,[(s(!0),l(N,null,A(t.sections,n=>(s(),l("div",{key:n.id,class:"transition-all",style:H({width:`${n.percentage}%`,backgroundColor:C(O)[n.type]??C(O).unknown,minWidth:n.percentage>0?"2px":"0"}),title:`${n.label}: ~${n.tokenCount} tokens (${n.percentage.toFixed(1)}%)`},null,12,Do))),128))]),e("div",Fo,[(s(!0),l(N,null,A(t.sections,n=>(s(),l("div",{key:n.id,class:"flex items-center gap-1.5"},[e("div",{class:"h-2.5 w-2.5 rounded-sm",style:H({backgroundColor:C(O)[n.type]??C(O).unknown})},null,4),e("span",Ro,c(n.label),1),e("span",Oo,"("+c(n.percentage.toFixed(0))+"%)",1)]))),128))])]))}}),qo={key:0,class:"space-y-4"},Ho={class:"space-y-3"},Eo={key:0,class:"rounded-lg border border-border-default bg-surface-raised p-4"},Vo={class:"space-y-2"},Wo={class:"flex items-center gap-2"},Go={class:"rounded-full bg-surface-overlay px-2 py-0.5 text-xs text-text-muted"},Jo={class:"text-text-secondary truncate max-w-md"},Ko={class:"text-xs text-text-muted"},Uo={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-8 text-center text-sm text-text-muted"},Qo=L({__name:"PromptInspector",props:{sessionId:{}},setup(t){const a=t,r=Ce(),n=$(()=>r.getAnatomy(a.sessionId)),m=$(()=>r.getSections(a.sessionId));return(d,p)=>n.value?(s(),l("div",qo,[w(Bo,{sections:m.value,"total-tokens":n.value.totalTokenCount},null,8,["sections","total-tokens"]),e("div",Ho,[(s(!0),l(N,null,A(m.value,i=>(s(),P(Ao,{key:i.id,section:i,"total-tokens":n.value.totalTokenCount},null,8,["section","total-tokens"]))),128))]),n.value.messages&&n.value.messages.length>0?(s(),l("div",Eo,[p[0]||(p[0]=e("h4",{class:"text-xs font-medium text-text-muted uppercase tracking-wide mb-3"},"Message Breakdown",-1)),e("div",Vo,[(s(!0),l(N,null,A(n.value.messages,(i,u)=>(s(),l("div",{key:u,class:"flex items-center justify-between rounded-lg bg-surface px-3 py-2 text-sm"},[e("div",Wo,[e("span",Go,c(i.role),1),e("span",Jo,c(i.content.slice(0,80))+c(i.content.length>80?"...":""),1)]),e("span",Ko,"~"+c(i.tokenCount)+" tok",1)]))),128))])])):y("",!0)])):(s(),l("div",Uo," No prompt anatomy data available. "))}});function Xo(t,a){if(a.length===0)return t;const r=Ve(a,"__raw"),n=t.split(`
2
- `);let m=-1;for(let v=n.length-1;v>=0;v--)if(/^\s*return\s+/.test(n[v]??"")){m=v;break}if(m===-1)return`${t}
3
-
4
- // Optimized: return selected fields only
5
- const __raw = args
6
- ${r}`;const d=n[m],i=d.match(/^(\s*)return\s+/)?.[1]??" ";let u=d.replace(/^\s*return\s+/,"").trim(),x=m;if(u.includes("{")&&!ee(u))for(let v=m+1;v<n.length&&(u+=`
7
- `+n[v],x=v,!ee(u));v++);const b=[`${i}const __raw = ${u.trim()}`,`${i}${r}`].join(`
8
- `);return[...n.slice(0,m),"",`${i}// Optimized: return selected fields only`,b,...n.slice(x+1)].join(`
9
- `)}function ee(t){let a=0;for(const r of t)if(r==="{"&&a++,r==="}"&&a--,a<0)return!1;return a===0}const Yo={class:"relative flex h-full w-full max-w-2xl flex-col border-s border-border-default bg-bg-base shadow-xl"},Zo={class:"flex items-center justify-between border-b border-border-default px-5 py-4"},en={class:"text-base font-semibold text-text-primary"},tn={key:0,class:"flex flex-1 flex-col items-center justify-center gap-4 p-8"},sn={class:"text-sm text-text-secondary"},on={class:"font-mono text-accent"},nn={class:"flex-1 overflow-y-auto"},rn={class:"grid grid-cols-3 gap-0 border-b border-border-default"},an={class:"col-span-2 border-e border-border-default p-4"},ln={class:"max-h-64 overflow-auto rounded-lg border border-border-default bg-surface-raised p-3"},dn={class:"p-4"},un={class:"mb-2 text-xs font-medium uppercase tracking-wide text-text-muted"},cn={key:0,class:"text-xs text-text-muted italic"},mn={key:1,class:"space-y-1"},pn=["title"],xn=["onClick"],fn={class:"border-b border-border-default p-4"},bn={class:"mb-2 flex items-center justify-between"},vn=["value"],gn={class:"space-y-3 p-4"},yn={key:0,class:"rounded-lg bg-warning/10 p-3 text-xs text-warning"},hn={class:"flex items-center justify-end gap-3 border-t border-border-default px-5 py-4"},kn=["disabled"],_n=L({__name:"ResponseOptimizerDrawer",props:{entry:{}},emits:["close"],setup(t,{emit:a}){const r=t,n=a,m=qe(),d=Ee(),p=S(new Set),i=S(`${r.entry.functionName}_optimized`),u=S(""),x=S(""),b=S(!1),g=S(!1),v=S(null),k=$(()=>d.findByFunctionName(r.entry.functionName)),M=$(()=>k.value?.implementation.code??""),o=$(()=>Array.from(p.value));V(o,z=>{if(z.length>0){const _=z.map(I=>I.split(".").pop()??I).join(", ");u.value=`Optimized ${r.entry.functionName} returning only: ${_}`}else u.value=""}),V(o,z=>{b.value||(x.value=f(z))});function f(z){return z.length===0?M.value:M.value?Xo(M.value,z):` // No original code found — filtering raw result
10
- const fullResult = await args
11
- return {
12
- ${Ge(z).map(E=>` ${E.returnKey}: args.${E.jsonPath}`).join(`,
13
- `)}
14
- }`}function h(z){const _=new Set(p.value);_.has(z)?_.delete(z):_.add(z),p.value=_}function D(z){const _=new Set(p.value);_.delete(z),p.value=_}function ue(z){x.value=z.target.value,b.value=!0}function ce(){x.value=f(o.value),b.value=!1}function me(){const z=k.value,_=z?JSON.parse(JSON.stringify(z.definition)):{type:"function",function:{name:i.value,description:u.value,parameters:{type:"object",properties:{},required:[]}}};_.function.name=i.value,_.function.description=u.value;const I=d.addTool({definition:_,implementation:{mode:"code",blocks:[],code:x.value},category:z?.category??"custom",optimizedFrom:{originalToolName:r.entry.functionName,selectedPaths:o.value,sampleResponse:r.entry.result}});v.value=I,g.value=!0}function pe(){v.value&&d.selectTool(v.value),m.push("/tools"),n("close")}function q(){n("close")}return(z,_)=>(s(),P(Oe,{to:"body"},[e("div",{class:"fixed inset-0 z-50 flex justify-end",onClick:ie(q,["self"])},[e("div",{class:"absolute inset-0 bg-black/50",onClick:q}),e("div",Yo,[e("div",Zo,[e("h3",en," Optimize: "+c(t.entry.functionName),1),e("button",{class:"rounded p-1 text-text-muted hover:bg-surface-overlay hover:text-text-primary transition-colors",onClick:q},[w(C(Be),{class:"h-5 w-5"})])]),g.value?(s(),l("div",tn,[_[3]||(_[3]=e("div",{class:"text-4xl"},"✓",-1)),_[4]||(_[4]=e("p",{class:"text-lg font-medium text-text-primary"},"Tool created successfully",-1)),e("p",sn,[e("span",on,c(i.value),1),_[2]||(_[2]=T(" has been added to your workshop. ",-1))]),e("div",{class:"mt-4 flex gap-3"},[e("button",{class:"rounded-lg border border-border-default px-4 py-2 text-sm text-text-secondary hover:bg-surface-overlay transition-colors",onClick:q}," Stay Here "),e("button",{class:"rounded-lg bg-accent px-4 py-2 text-sm font-medium text-white hover:bg-accent-hover transition-colors",onClick:pe}," Go to Workshop ")])])):(s(),l(N,{key:1},[e("div",nn,[e("div",rn,[e("div",an,[_[5]||(_[5]=e("div",{class:"mb-2 text-xs font-medium uppercase tracking-wide text-text-muted"}," Response (click fields to select) ",-1)),e("div",ln,[w(We,{label:"result",value:t.entry.result,path:"","selected-paths":p.value,onTogglePath:h},null,8,["value","selected-paths"])])]),e("div",dn,[e("div",un," Selected ("+c(p.value.size)+") ",1),p.value.size===0?(s(),l("div",cn," Click fields in the tree to select them ")):(s(),l("div",mn,[(s(!0),l(N,null,A(o.value,I=>(s(),l("div",{key:I,class:"flex items-center justify-between rounded px-2 py-1 text-xs font-mono bg-surface-raised"},[e("span",{class:"truncate text-text-secondary",title:I},c(I),9,pn),e("button",{class:"ms-2 flex-shrink-0 text-text-muted hover:text-error transition-colors",onClick:E=>D(I)}," × ",8,xn)]))),128))]))])]),e("div",fn,[e("div",bn,[_[6]||(_[6]=e("span",{class:"text-xs font-medium uppercase tracking-wide text-text-muted"}," Code (editable) ",-1)),b.value?(s(),l("button",{key:0,class:"rounded px-2 py-0.5 text-xs text-accent hover:bg-surface-overlay transition-colors",onClick:ce}," Regenerate ")):y("",!0)]),e("textarea",{value:x.value,onInput:ue,class:"w-full rounded-lg border border-border-default bg-surface-raised p-3 font-mono text-xs text-text-primary placeholder-text-muted focus:border-accent focus:outline-none resize-y",rows:"10",spellcheck:"false",placeholder:"Select fields above to generate code..."},null,40,vn)]),e("div",gn,[e("div",null,[_[7]||(_[7]=e("label",{class:"mb-1 block text-xs font-medium text-text-muted"},"Tool Name",-1)),W(e("input",{"onUpdate:modelValue":_[0]||(_[0]=I=>i.value=I),class:"w-full rounded-lg border border-border-default bg-surface-raised px-3 py-2 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none"},null,512),[[Z,i.value]])]),e("div",null,[_[8]||(_[8]=e("label",{class:"mb-1 block text-xs font-medium text-text-muted"},"Description",-1)),W(e("input",{"onUpdate:modelValue":_[1]||(_[1]=I=>u.value=I),class:"w-full rounded-lg border border-border-default bg-surface-raised px-3 py-2 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none",placeholder:"What does this optimized tool return?"},null,512),[[Z,u.value]])]),k.value?y("",!0):(s(),l("div",yn,' Original tool "'+c(t.entry.functionName)+'" not found in workshop. The optimized tool will be created with a blank parameter schema. ',1))])]),e("div",hn,[e("button",{class:"rounded-lg border border-border-default px-4 py-2 text-sm text-text-secondary hover:bg-surface-overlay transition-colors",onClick:q}," Cancel "),e("button",{class:"rounded-lg bg-accent px-4 py-2 text-sm font-medium text-white hover:bg-accent-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed",disabled:p.value.size===0||!i.value.trim(),onClick:me}," Create Optimized Tool ",8,kn)])],64))])])]))}}),$n={key:0,class:"space-y-4"},wn={class:"flex items-center justify-between"},Cn={class:"flex items-center gap-3"},Mn={class:"text-lg font-semibold"},Tn={class:"text-xs text-text-muted"},Sn={class:"flex items-center justify-between"},zn={class:"relative"},Ln={key:1,class:"absolute end-0 top-full z-20 mt-1 w-56 rounded-lg border border-border-default bg-surface-raised shadow-lg py-1"},Nn={class:"mt-4"},An={key:0,class:"space-y-4"},In={key:1,class:"flex items-center justify-center py-20 text-text-muted"},Kn=L({__name:"SessionPage",props:{id:{}},setup(t){const a=t,r=fe(),n=be(),m=te(),{t:d}=He(),p=S("stream"),i=S(!1);function u(){const o=v.value;if(!o)return;const f={session:o,metrics:k.value,tokens:m.getTokens(a.id)};ye(f,`session-${o.id.slice(0,8)}.json`),i.value=!1}function x(){const o=v.value;if(!o)return;const f=k.value,h=["# Session Report — LLMxRay","",`**Model:** ${o.model}`,`**Session ID:** ${o.id}`,`**Status:** ${o.status}`,`**Created:** ${new Date(o.createdAt).toLocaleString()}`];f&&(h.push(""),h.push("## Metrics"),h.push(""),f.tokensPerSecond&&h.push(`- **Speed:** ${f.tokensPerSecond.toFixed(1)} tok/s`),f.ttftMs&&h.push(`- **TTFT:** ${f.ttftMs.toFixed(0)} ms`),f.completionTokenCount&&h.push(`- **Tokens generated:** ${f.completionTokenCount}`),f.promptTokenCount&&h.push(`- **Prompt tokens:** ${f.promptTokenCount}`)),o.prompt&&(h.push(""),h.push("## Prompt"),h.push(""),h.push(o.prompt)),o.outputText&&(h.push(""),h.push("## Response"),h.push(""),h.push(o.outputText)),h.push(""),h.push("---"),h.push("*Generated by LLMxRay — Local LLM Observatory*"),he(h.join(`
15
- `),`session-${o.id.slice(0,8)}.md`),i.value=!1}function b(){const o=m.getTokens(a.id);if(o.length===0)return;const f=["Index","Token","Timestamp","Confidence","Logprob","InterTokenLatencyMs"],h=o.map(D=>[String(D.index),D.text,String(D.timestamp),String(D.confidence),String(D.logprob??""),String(D.interTokenLatencyMs)]);ke(f,h,`token-stream-${a.id.slice(0,8)}.csv`),i.value=!1}const g=$(()=>[{key:"stream",label:d("session.tabs.stream")},{key:"reasoning",label:d("session.tabs.reasoning")},{key:"introspection",label:d("session.tabs.introspection")},{key:"tools",label:d("session.tabs.tools")},{key:"agent",label:d("session.tabs.agent")},{key:"prompt",label:d("session.tabs.prompt")}]),v=$(()=>r.sessionById(a.id)??null),k=$(()=>n.getMetrics(a.id)),M=S(null);return X(()=>{r.setActiveSession(a.id)}),(o,f)=>(s(),l(N,null,[v.value?(s(),l("div",$n,[e("div",wn,[e("div",Cn,[e("h2",Mn,c(v.value.model),1),w(se,{status:v.value.status},null,8,["status"])]),e("div",Tn,c(o.$t("session.sessionId",{id:v.value.id.slice(0,8)})),1)]),e("div",Sn,[w(_e,{tabs:g.value,"active-tab":p.value,"onUpdate:activeTab":f[0]||(f[0]=h=>p.value=h)},null,8,["tabs","active-tab"]),e("div",zn,[e("button",{class:"flex items-center gap-1 rounded-lg border border-border-default px-2.5 py-1 text-xs text-text-secondary hover:text-text-primary transition-colors",onClick:f[1]||(f[1]=h=>i.value=!i.value)},[w(C(Je),{class:"h-3.5 w-3.5"}),T(" "+c(o.$t("session.export.title")),1)]),i.value?(s(),l("div",{key:0,class:"fixed inset-0 z-10",onClick:f[2]||(f[2]=h=>i.value=!1)})):y("",!0),i.value?(s(),l("div",Ln,[e("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:u},c(o.$t("session.export.downloadJson")),1),e("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:x},c(o.$t("session.export.downloadMarkdown")),1),e("button",{class:"w-full px-3 py-2 text-start text-xs text-text-secondary hover:bg-surface-overlay",onClick:b},c(o.$t("session.export.downloadTokenCsv")),1)])):y("",!0)])]),e("div",Nn,[p.value==="stream"?(s(),l("div",An,[w(Me,{"session-id":t.id},null,8,["session-id"]),w(at,{metrics:k.value},null,8,["metrics"])])):p.value==="reasoning"?(s(),P(_t,{key:1,"session-id":t.id},null,8,["session-id"])):p.value==="introspection"?(s(),P(Is,{key:2,"session-id":t.id,"model-name":v.value.model},null,8,["session-id","model-name"])):p.value==="tools"?(s(),P(Zs,{key:3,"session-id":t.id,onOptimize:f[3]||(f[3]=h=>M.value=h)},null,8,["session-id"])):p.value==="agent"?(s(),P(_o,{key:4,"session-id":t.id},null,8,["session-id"])):p.value==="prompt"?(s(),P(Qo,{key:5,"session-id":t.id},null,8,["session-id"])):y("",!0)])])):(s(),l("div",In,c(o.$t("session.notFound")),1)),M.value?(s(),P(_n,{key:2,entry:M.value,onClose:f[4]||(f[4]=h=>M.value=null)},null,8,["entry"])):y("",!0)],64))}});export{Kn as default};