llmxray 0.2.1 → 0.3.1

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 (50) hide show
  1. package/dist/assets/AITrainingPage-BmiTLvwB.js +1 -0
  2. package/dist/assets/{BenchmarkPage-yZ1Kt8KK.js → BenchmarkPage-CwCXzzrb.js} +2 -2
  3. package/dist/assets/ComparisonPage-nfG681cT.js +1 -0
  4. package/dist/assets/DashboardPage-CKQaBKDw.js +101 -0
  5. package/dist/assets/EmbeddingsPage-DJdyD65Q.js +1 -0
  6. package/dist/assets/EmbeddingsPage-DtEKy4qg.css +1 -0
  7. package/dist/assets/{GoogleCallbackPage-DqfqxXhg.js → GoogleCallbackPage-2hfuqKEi.js} +1 -1
  8. package/dist/assets/{JsonTreeNode-BE6Ps90W.js → JsonTreeNode-DckR4Nv8.js} +2 -2
  9. package/dist/assets/ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-DUHfiPBt.js +1 -0
  10. package/dist/assets/RAGPage-jMq_Sg9F.js +1 -0
  11. package/dist/assets/SessionPage-C6jIbcq2.js +14 -0
  12. package/dist/assets/SettingsPage-CpDVuxxG.js +1 -0
  13. package/dist/assets/StatusBadge.vue_vue_type_script_setup_true_lang-D24kGmB6.js +1 -0
  14. package/dist/assets/StorageGauge.vue_vue_type_style_index_0_lang-CLdARZMv.js +1 -0
  15. package/dist/assets/SystemPage-BbfTFebq.js +2 -0
  16. package/dist/assets/{TabBar.vue_vue_type_script_setup_true_lang-CnQ8vq8x.js → TabBar.vue_vue_type_script_setup_true_lang-BV7bRKLd.js} +1 -1
  17. package/dist/assets/{TokenStreamDisplay.vue_vue_type_script_setup_true_lang-CJW7ndOY.js → TokenStreamDisplay.vue_vue_type_script_setup_true_lang-Cilrzwrg.js} +1 -1
  18. package/dist/assets/{ToolWorkshopPage-gO5DvECk.css → ToolWorkshopPage-7TRbWVVL.css} +1 -1
  19. package/dist/assets/{ToolWorkshopPage-DoVwZp_3.js → ToolWorkshopPage-BEFjvNVE.js} +88 -88
  20. package/dist/assets/{agent-store-_RIMRfEn.js → agent-store-tglPObkH.js} +1 -1
  21. package/dist/assets/generate-service-UqpNGQas.js +3 -0
  22. package/dist/assets/{google-auth-store-BnEs-xLw.js → google-auth-store-pjk41Wop.js} +1 -1
  23. package/dist/assets/index-CCnJ2vPZ.css +1 -0
  24. package/dist/assets/{index-D87kMEMb.js → index-Cq76cPsM.js} +1 -1
  25. package/dist/assets/index-DVvWJgFn.js +6 -0
  26. package/dist/assets/{metrics-store-HzdMIV8O.js → metrics-store-oAZX_4PZ.js} +1 -1
  27. package/dist/assets/{rag-store-VWnttX_x.js → rag-store-D6KNr_hW.js} +1 -1
  28. package/dist/assets/{storage-store-B1XevdC4.js → storage-store-D4WuNdQB.js} +1 -1
  29. package/dist/assets/{stream-handler-29OjEvbo.js → stream-handler-_fccIkW6.js} +2 -2
  30. package/dist/assets/{tool-workshop-store-Btx8DDqg.js → tool-workshop-store-Dz7QH2FM.js} +1 -1
  31. package/dist/assets/{toolcall-store-BumXt8DE.js → toolcall-store-BFoy2Mdx.js} +1 -1
  32. package/dist/assets/trash-2-CbznmmWI.js +1 -0
  33. package/dist/index.html +2 -2
  34. package/dist/social-card.svg +150 -0
  35. package/package.json +5 -2
  36. package/dist/assets/AITrainingPage-BbRryhHe.js +0 -1
  37. package/dist/assets/ComparisonPage-BnBp-VsC.js +0 -1
  38. package/dist/assets/DashboardPage-DTXPIpEx.js +0 -101
  39. package/dist/assets/EmbeddingsPage-Bo3g8-qN.css +0 -1
  40. package/dist/assets/EmbeddingsPage-CghkdGEr.js +0 -1
  41. package/dist/assets/ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-CsL7aDHj.js +0 -1
  42. package/dist/assets/RAGPage-B_c1Nogo.js +0 -1
  43. package/dist/assets/SessionPage-lWGESxx3.js +0 -14
  44. package/dist/assets/SettingsPage-k9HWgy9B.js +0 -1
  45. package/dist/assets/StatusBadge.vue_vue_type_script_setup_true_lang-f9O-U2FX.js +0 -1
  46. package/dist/assets/StorageGauge.vue_vue_type_style_index_0_lang-hO4dId5t.js +0 -1
  47. package/dist/assets/SystemPage-BgwBHFJB.js +0 -2
  48. package/dist/assets/generate-service-mPYQA7Xh.js +0 -3
  49. package/dist/assets/index-BqB3FY2M.js +0 -4
  50. package/dist/assets/index-C0qd34Zo.css +0 -1
@@ -1,101 +0,0 @@
1
- import{u as et}from"./metrics-store-HzdMIV8O.js";import{_ as xs,o as ze,n as pe,r as M,d as vs,w as ee,c as j,a as te,b as h,e as g,f as r,g as D,t as S,h as Se,i as A,F as O,j as Q,k as bs,u as x,l as ys,m as Ae,T as ks,p as G,q as zt,s as Et,v as Le,x as ws,y as Ss,z as tt,A as It,B as U,C as Z,D as Pt,E as Ke,G as Dt,H as $s}from"./index-BqB3FY2M.js";import{f as we,a as Fe,b as Ze,c as Bt,d as Cs}from"./format-BqVZ9rwM.js";import{u as He,a as Ts}from"./toolcall-store-BumXt8DE.js";import{a as _s,s as Ms}from"./generate-service-mPYQA7Xh.js";import{u as Rs,a as As,_ as Ns,b as Be}from"./StatusBadge.vue_vue_type_script_setup_true_lang-f9O-U2FX.js";import{u as st}from"./tool-workshop-store-Btx8DDqg.js";import{u as zs,a as jt,b as Es}from"./agent-store-_RIMRfEn.js";import{e as Is}from"./stream-handler-29OjEvbo.js";import{d as Ps,p as Ds,u as Lt}from"./rag-store-VWnttX_x.js";import{messageMemoryDB as Ft}from"./message-memory-db-C3Ifhs2B.js";import{_ as bt}from"./ModelCapabilityIcons.vue_vue_type_script_setup_true_lang-CsL7aDHj.js";import"./vector-db-ChAzHl5A.js";async function Bs(s,e){const t=performance.now();try{let o;return s.implementation.mode==="code"?o=await js(s.implementation.code,e):o=await Ls(s.implementation.blocks,e),{success:!0,result:o,durationMs:performance.now()-t}}catch(o){return{success:!1,result:null,durationMs:performance.now()-t,error:o instanceof Error?o.message:String(o)}}}async function js(s,e){if(!s.trim())throw new Error("Tool has no implementation code");const t=Object.getPrototypeOf(async function(){}).constructor;return await new t("args","fetch","getGoogleToken",s)(e,fetch.bind(globalThis),qs)}async function Ls(s,e){if(s.length===0)throw new Error("Tool has no action blocks");const t=new Map;for(const[l,a]of Object.entries(e))t.set(l,a);const o=[...s].sort((l,a)=>l.order-a.order);let n=null;for(const l of o)switch(l.type){case"http_request":await Fs(l.config,t);break;case"extract_field":Os(l.config,t);break;case"template":Vs(l.config,t);break;case"return_value":n=Us(l.config,t);break}return n}async function Fs(s,e){const t=Ne(s.url,e),o=s.body?Ne(s.body,e):void 0,n={};for(const[i,d]of Object.entries(s.headers))n[i]=Ne(d,e);const l=await fetch(t,{method:s.method,headers:n,body:s.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(s.outputVariable||"response",a)}function Os(s,e){const t=e.get(s.input);if(t==null){e.set(s.outputVariable||"value",null);return}const o=s.fieldPath.split(".");let n=t;for(const l of o){if(n==null||typeof n!="object"){n=null;break}n=n[l]}e.set(s.outputVariable||"value",n)}function Vs(s,e){const t=Ne(s.template,e);e.set(s.outputVariable||"text",t)}function Us(s,e){const t=s.expression.trim();return e.has(t)?e.get(t):Ne(t,e)}async function qs(){const{getAccessToken:s,isConnected:e}=await xs(async()=>{const{getAccessToken:t,isConnected:o}=await import("./google-auth-CfEcVMA7.js");return{getAccessToken:t,isConnected:o}},[]);if(!e())throw new Error("Google account not connected. Go to Settings to connect your Google account.");return s()}function Ne(s,e){return s.replace(/\{\{(\w+(?:\.\w+)*)\}\}/g,(t,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 Hs=5;async function Gs(s){const e=He(),t=Rs(),o=s.messages.map(c=>`[${c.role}] ${c.content}`).join(`
2
- `),n=e.createSession({mode:"chat",model:s.model,prompt:o,messages:s.messages,options:s.options});e.setActiveSession(n);const l=_s(n,s.messages);t.setAnatomy(n,l);const a=new AbortController;return Ws(n,s.model,[...s.messages],s.tools,s.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 Ws(s,e,t,o,n,l){const a=Ts(),c=st(),i=zs();let d=0,p=0;for(;d<Hs;){if(l.aborted)return;const m=await ze.streamChat({model:e,messages:t,tools:o,options:n,logprobs:!0},l),b=await Is(s,m,l);if(b.toolCalls.length===0)return;t.push({role:"assistant",content:"",tool_calls:b.toolCalls});for(const k of b.toolCalls){const f=c.findByFunctionName(k.function.name),$=a.getToolCalls(s).find(V=>V.functionName===k.function.name&&V.status==="pending");if(!f){const V=`Tool "${k.function.name}" has no implementation`;i.addNode(s,{id:pe(),type:"error",label:`No impl: ${k.function.name}`,sessionId:s,stepIndex:p++,state:{tool:k.function.name,error:V},timestamp:Date.now()}),$&&a.updateToolCall(s,$.id,{status:"failed",error:V,completedAt:Date.now()}),t.push({role:"tool",content:JSON.stringify({error:V})});continue}$&&a.updateToolCall(s,$.id,{status:"executing"});const I=await Bs(f,k.function.arguments);i.addNode(s,{id:pe(),type:I.success?"output":"error",label:I.success?`Tool Result: ${k.function.name}`:`Tool Failed: ${k.function.name}`,sessionId:s,stepIndex:p++,state:{tool:k.function.name,success:I.success,durationMs:I.durationMs},timestamp:Date.now()}),$&&a.updateToolCall(s,$.id,{status:I.success?"completed":"failed",result:I.result,error:I.error,completedAt:Date.now(),durationMs:I.durationMs});const L=I.success?typeof I.result=="string"?I.result:JSON.stringify(I.result):JSON.stringify({error:I.error});t.push({role:"tool",content:L})}i.addNode(s,{id:pe(),type:"llm_call",label:`LLM Round ${d+2} (with tool results)`,sessionId:s,stepIndex:p++,state:{round:d+1},timestamp:Date.now()}),d++}}function Ks(){const s=M(!1),e=M(null),t=M(null);let o=null;async function n(c,i,d,p){s.value=!0,e.value=null;try{const m=await Ms({model:c,prompt:i,system:p,options:d});return t.value=m.sessionId,o=m.abort,m.sessionId}catch(m){throw e.value=m instanceof Error?m.message:"Failed to start generation",s.value=!1,m}}async function l(c,i,d,p){s.value=!0,e.value=null;try{const m=await Gs({model:c,messages:i,tools:p,options:d});return t.value=m.sessionId,o=m.abort,m.sessionId}catch(m){throw e.value=m instanceof Error?m.message:"Failed to start chat",s.value=!1,m}}function a(){o&&(o(),o=null),s.value=!1}return{isStreaming:s,error:e,currentSessionId:t,startGenerate:n,startChatStream:l,cancel:a}}const Oe=[{name:"help",description:"Show all available commands",usage:"/help",category:"chat",execute(s,e){const t=Ot(),o=[`Available commands:
3
- `];for(const[n,l]of Object.entries(t)){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(s,e){e.clearConversation(),e.showNotification("Conversation cleared.")}},{name:"new",description:"Start a new chat session",usage:"/new",category:"chat",execute(s,e){e.newChat(),e.showNotification("New chat started.")}},{name:"summarize",description:"Ask the model to summarize the conversation",usage:"/summarize",category:"chat",execute(s,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(s,e){const t=s.trim()==="text"?"text":"json";e.exportConversation(t),e.showNotification(`Conversation exported as ${t}.`)}},{name:"copy",description:"Copy last assistant response to clipboard",usage:"/copy",category:"chat",execute(s,e){e.copyLastResponse()}},{name:"history",description:"Show recent conversations",usage:"/history",category:"chat",execute(s,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(s,e){const t=s.trim();if(!t){const n=e.availableModels.join(", ");e.showNotification(`Available models: ${n}
5
- Current: ${e.currentModel}`);return}const o=e.availableModels.find(n=>n===t||n.startsWith(t));o?(e.switchModel(o),e.showNotification(`Switched to ${o}.`)):e.showNotification(`Model "${t}" not found. Available: ${e.availableModels.join(", ")}`)}},{name:"system",description:"Set the system prompt",usage:"/system <prompt>",category:"settings",execute(s,e){const t=s.trim();if(!t){const o=e.chatSettings.value.systemPrompt||"(none)";e.showNotification(`Current system prompt: ${o}`);return}e.setSystemPrompt(t),e.showNotification("System prompt updated.")}},{name:"temperature",description:"Set temperature (0-2)",usage:"/temperature <value>",category:"settings",execute(s,e){const t=parseFloat(s.trim());if(isNaN(t)||t<0||t>2){e.showNotification(`Current: ${e.chatSettings.value.options.temperature??.7}. Usage: /temperature 0.0-2.0`);return}e.setOption("temperature",t),e.showNotification(`Temperature set to ${t}.`)}},{name:"top_p",description:"Set top-p / nucleus sampling (0-1)",usage:"/top_p <value>",category:"settings",execute(s,e){const t=parseFloat(s.trim());if(isNaN(t)||t<0||t>1){e.showNotification(`Current: ${e.chatSettings.value.options.top_p??.9}. Usage: /top_p 0.0-1.0`);return}e.setOption("top_p",t),e.showNotification(`Top-p set to ${t}.`)}},{name:"top_k",description:"Set top-k sampling (1-100)",usage:"/top_k <value>",category:"settings",execute(s,e){const t=parseInt(s.trim(),10);if(isNaN(t)||t<1||t>100){e.showNotification(`Current: ${e.chatSettings.value.options.top_k??40}. Usage: /top_k 1-100`);return}e.setOption("top_k",t),e.showNotification(`Top-k set to ${t}.`)}},{name:"context",description:"Set context window size",usage:"/context <size>",category:"settings",execute(s,e){const t=parseInt(s.trim(),10),o=[2048,4096,8192,16384,32768,65536,131072];if(isNaN(t)||!o.includes(t)){e.showNotification(`Current: ${we(e.chatSettings.value.options.num_ctx??4096)}. Valid sizes: ${o.join(", ")}`);return}e.setOption("num_ctx",t),e.showNotification(`Context window set to ${we(t)}.`)}},{name:"repeat_penalty",description:"Set repeat penalty (1.0-2.0)",usage:"/repeat_penalty <value>",category:"settings",execute(s,e){const t=parseFloat(s.trim());if(isNaN(t)||t<1||t>2){e.showNotification(`Current: ${e.chatSettings.value.options.repeat_penalty??1.1}. Usage: /repeat_penalty 1.0-2.0`);return}e.setOption("repeat_penalty",t),e.showNotification(`Repeat penalty set to ${t}.`)}},{name:"seed",description:"Set seed for reproducibility (-1 for random)",usage:"/seed <value>",category:"settings",execute(s,e){const t=parseInt(s.trim(),10);if(isNaN(t)){e.showNotification(`Current: ${e.chatSettings.value.options.seed??-1}. Usage: /seed <number>`);return}e.setOption("seed",t===-1?void 0:t),e.showNotification(t===-1?"Seed set to random.":`Seed set to ${t}.`)}},{name:"stop",description:"Set stop sequences (comma-separated)",usage:"/stop <sequences>",category:"settings",execute(s,e){const t=s.trim();if(!t){const n=e.chatSettings.value.options.stop?.join(", ")||"(none)";e.showNotification(`Current stop sequences: ${n}`);return}const o=t.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(s,e){const t=parseInt(s.trim(),10);if(![0,1,2].includes(t)){e.showNotification(`Current: ${e.chatSettings.value.options.mirostat??0}. Usage: /mirostat 0|1|2`);return}e.setOption("mirostat",t),e.showNotification(t===0?"Mirostat disabled.":`Mirostat v${t} enabled.`)}},{name:"format",description:"Toggle JSON output format",usage:"/format [json]",category:"settings",execute(s,e){const t=s.trim().toLowerCase()==="json";e.setJsonFormat(t),e.showNotification(t?"JSON format enabled.":"JSON format disabled.")}},{name:"reset",description:"Reset all settings to defaults",usage:"/reset",category:"settings",execute(s,e){e.resetSettings(),e.showNotification("All settings reset to defaults.")}},{name:"rag",description:"Toggle RAG context on/off",usage:"/rag",category:"navigation",execute(s,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(s,e){e.openSettings(),e.showNotification("Settings panel opened.")}},{name:"status",description:"Show Ollama connection status and model info",usage:"/status",category:"navigation",async execute(s,e){const t=await e.getOllamaStatus();e.showNotification(`Ollama: ${t.connected?"Connected":"Disconnected"}
6
- Model: ${t.model||"(none)"}`)}},{name:"tokens",description:"Show token count for current session",usage:"/tokens",category:"navigation",execute(s,e){const t=e.getSessionTokenCount();if(!t){e.showNotification("No active session.");return}e.showNotification(`Prompt tokens: ${we(t.prompt)}
7
- Completion tokens: ${we(t.completion)}
8
- Total: ${we(t.prompt+t.completion)}`)}},{name:"speed",description:"Show average generation speed across sessions",usage:"/speed",category:"navigation",execute(s,e){const t=e.getAverageSpeed();if(t===null){e.showNotification("No sessions recorded yet.");return}e.showNotification(`Average speed: ${Fe(t)}`)}},{name:"compare",description:"Navigate to the Compare page",usage:"/compare",category:"navigation",execute(s,e){e.navigate("/compare")}},{name:"session",description:"View current session details",usage:"/session",category:"navigation",execute(s,e){e.openSessionDetails()}},{name:"remember",description:"Remember a fact about you across conversations",usage:"/remember <fact>",category:"memory",execute(s,e){const t=s.trim();if(!t){e.showNotification(`Usage: /remember <something to remember>
9
- Example: /remember I prefer TypeScript over JavaScript`);return}e.addFact(t),e.showNotification(`Remembered: "${t}"`)}},{name:"forget",description:"Forget a previously remembered fact",usage:"/forget <search>",category:"memory",execute(s,e){const t=s.trim();if(!t){e.showNotification(`Usage: /forget <part of the fact to remove>
10
- Example: /forget TypeScript`);return}e.removeFact(t)?e.showNotification(`Forgot fact matching "${t}".`):e.showNotification(`No fact found matching "${t}". Use /memories to see all facts.`)}},{name:"memories",description:"Show all remembered facts",usage:"/memories",category:"memory",execute(s,e){const t=e.getFacts();if(t.length===0){e.showNotification("No memories stored yet. Use /remember <fact> to add one.");return}const o=t.map((n,l)=>`${l+1}. ${n.content}`);e.showNotification(`Your memories (${t.length}):
11
- ${o.join(`
12
- `)}`)}}];function Zs(s){const e=s.toLowerCase().replace(/^\//,"");return e?Oe.filter(t=>t.name.startsWith(e)):Oe}function Qs(s){return Oe.find(e=>e.name===s.toLowerCase())}function Ot(){const s={};for(const e of Oe){const t=e.category==="chat"?"Chat & Conversation":e.category==="settings"?"Model & Settings":e.category==="memory"?"Memory":"Features & Navigation";(s[t]??=[]).push(e)}return s}const yt={slidingWindow:{enabled:!0,maxMessages:50},autoSummarize:{enabled:!1,triggerThreshold:30},ragMemory:{enabled:!1,embeddingModel:"",topK:3},userFacts:{enabled:!0}},kt="llmxray-memory-settings",wt="llmxray-user-facts";function St(s,e){try{const t=localStorage.getItem(s);return t?JSON.parse(t):e}catch{return e}}function $t(s,e){localStorage.setItem(s,JSON.stringify(e))}const Vt=vs("memory",()=>{const s=M(St(kt,{...yt}));ee(s,f=>$t(kt,f),{deep:!0});function e(f){s.value={...s.value,...f}}function t(){s.value={...yt}}const o=M(St(wt,[]));ee(o,f=>$t(wt,f),{deep:!0});const n=j(()=>o.value.length);function l(f){const z={id:pe(),content:f.trim(),createdAt:Date.now()};return o.value=[...o.value,z],z}function a(f){o.value=o.value.filter(z=>z.id!==f)}function c(f){const z=f.toLowerCase().trim(),$=o.value.findIndex(I=>I.content.toLowerCase().includes(z));return $===-1?!1:(o.value=[...o.value.slice(0,$),...o.value.slice($+1)],!0)}function i(){o.value=[]}function d(){return o.value.length===0?"":`The user has asked you to remember these facts about them:
13
- ${o.value.map(z=>`- ${z.content}`).join(`
14
- `)}
15
-
16
- Keep these in mind when responding.`}const p=M(new Map);function m(f,z,$){p.value.set(f,{conversationId:f,summary:z,messageCount:$,createdAt:Date.now()})}function b(f){return p.value.get(f)}function k(f){p.value.delete(f)}return{settings:s,updateSettings:e,resetSettings:t,facts:o,factCount:n,addFact:l,removeFact:a,removeFactByContent:c,clearFacts:i,getFactsAsSystemPrompt:d,summaries:p,setSummary:m,getSummary:b,clearSummary:k}});async function Js(s){let e=[...s.messages],t;s.settings.userFacts.enabled&&s.userFactsPrompt&&e.unshift({role:"system",content:s.userFactsPrompt});const o=e.filter(n=>n.role!=="system");if(s.settings.autoSummarize.enabled&&o.length>s.settings.autoSummarize.triggerThreshold){const n=Math.floor(s.settings.autoSummarize.triggerThreshold/3),l=e.filter(p=>p.role==="system"),a=o.slice(0,-n),c=o.slice(-n),i=s.existingSummary?`Previous summary:
17
- ${s.existingSummary}
18
-
19
- New messages to incorporate:
20
- `:"",d=await Ys(s.model,i+a.map(p=>`${p.role}: ${p.content}`).join(`
21
- `));d&&(t=d,e=[...l,{role:"system",content:`Summary of earlier conversation:
22
- ${d}`},...c])}if(s.settings.slidingWindow.enabled){const n=e.filter(c=>c.role==="system"),l=e.filter(c=>c.role!=="system"),a=s.settings.slidingWindow.maxMessages;if(l.length>a){const c=l.slice(-a);e=[...n,...c]}}if(s.settings.ragMemory.enabled&&s.settings.ragMemory.embeddingModel)try{const n=await en(s.conversationId,e,s.settings.ragMemory.embeddingModel,s.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:t}}async function Xs(s,e,t){if(!t||e.length===0)return;const o=e.map(a=>a.content),n=await ze.embed({model:t,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:pe(),conversationId:s,role:i.role,content:i.content,embedding:c,timestamp:i.timestamp})}await Ft.storeMessages(l)}async function Ys(s,e){try{return(await ze.chat({model:s,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 en(s,e,t,o){const n=e.filter(m=>m.role==="user"),l=n[n.length-1];if(!l)return null;const c=(await ze.embed({model:t,input:[l.content]})).embeddings[0];if(!c)return null;const d=(await Ft.search(c,o,s)).filter(m=>m.score>.5);return d.length===0?null:`Relevant messages from past conversations:
23
- ${d.map(m=>`[${m.message.role}, relevance: ${(m.score*100).toFixed(0)}%] ${m.message.content}`).join(`
24
-
25
- `)}
26
-
27
- Use this context if helpful, but prioritize the current conversation.`}function nt(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var be=nt();function Ut(s){be=s}var xe={exec:()=>null};function P(s,e=""){let t=typeof s=="string"?s:s.source,o={replace:(n,l)=>{let a=typeof l=="string"?l:l.source;return a=a.replace(W.caret,"$1"),t=t.replace(n,a),o},getRegex:()=>new RegExp(t,e)};return o}var tn=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),W={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:s=>new RegExp(`^( {0,3}${s})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}#`),htmlBeginRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}<(?:[a-z].*>|!--)`,"i"),blockquoteBeginRegex:s=>new RegExp(`^ {0,${Math.min(3,s-1)}}>`)},sn=/^(?:[ \t]*(?:\n|$))+/,nn=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,on=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Ee=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,rn=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ot=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,qt=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ht=P(qt).replace(/bull/g,ot).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(),an=P(qt).replace(/bull/g,ot).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(),rt=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,ln=/^[^\n]+/,at=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,cn=P(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",at).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),un=P(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ot).getRegex(),Ge="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",lt=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,dn=P("^ {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",lt).replace("tag",Ge).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Gt=P(rt).replace("hr",Ee).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",Ge).getRegex(),pn=P(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Gt).getRegex(),it={blockquote:pn,code:nn,def:cn,fences:on,heading:rn,hr:Ee,html:dn,lheading:Ht,list:un,newline:sn,paragraph:Gt,table:xe,text:ln},Ct=P("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Ee).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",Ge).getRegex(),mn={...it,lheading:an,table:Ct,paragraph:P(rt).replace("hr",Ee).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ct).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",Ge).getRegex()},hn={...it,html:P(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",lt).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:xe,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:P(rt).replace("hr",Ee).replace("heading",` *#{1,6} *[^
28
- ]`).replace("lheading",Ht).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},gn=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,fn=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Wt=/^( {2,}|\\)\n(?!\s*$)/,xn=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,We=/[\p{P}\p{S}]/u,ct=/[\s\p{P}\p{S}]/u,Kt=/[^\s\p{P}\p{S}]/u,vn=P(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,ct).getRegex(),Zt=/(?!~)[\p{P}\p{S}]/u,bn=/(?!~)[\s\p{P}\p{S}]/u,yn=/(?:[^\s\p{P}\p{S}]|~)/u,Qt=/(?![*_])[\p{P}\p{S}]/u,kn=/(?![*_])[\s\p{P}\p{S}]/u,wn=/(?:[^\s\p{P}\p{S}]|[*_])/u,Sn=P(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",tn?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Jt=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,$n=P(Jt,"u").replace(/punct/g,We).getRegex(),Cn=P(Jt,"u").replace(/punct/g,Zt).getRegex(),Xt="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Tn=P(Xt,"gu").replace(/notPunctSpace/g,Kt).replace(/punctSpace/g,ct).replace(/punct/g,We).getRegex(),_n=P(Xt,"gu").replace(/notPunctSpace/g,yn).replace(/punctSpace/g,bn).replace(/punct/g,Zt).getRegex(),Mn=P("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Kt).replace(/punctSpace/g,ct).replace(/punct/g,We).getRegex(),Rn=P(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,Qt).getRegex(),An="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",Nn=P(An,"gu").replace(/notPunctSpace/g,wn).replace(/punctSpace/g,kn).replace(/punct/g,Qt).getRegex(),zn=P(/\\(punct)/,"gu").replace(/punct/g,We).getRegex(),En=P(/^<(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(),In=P(lt).replace("(?:-->|$)","-->").getRegex(),Pn=P("^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",In).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ve=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,Dn=P(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",Ve).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Yt=P(/^!?\[(label)\]\[(ref)\]/).replace("label",Ve).replace("ref",at).getRegex(),es=P(/^!?\[(ref)\](?:\[\])?/).replace("ref",at).getRegex(),Bn=P("reflink|nolink(?!\\()","g").replace("reflink",Yt).replace("nolink",es).getRegex(),Tt=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,ut={_backpedal:xe,anyPunctuation:zn,autolink:En,blockSkip:Sn,br:Wt,code:fn,del:xe,delLDelim:xe,delRDelim:xe,emStrongLDelim:$n,emStrongRDelimAst:Tn,emStrongRDelimUnd:Mn,escape:gn,link:Dn,nolink:es,punctuation:vn,reflink:Yt,reflinkSearch:Bn,tag:Pn,text:xn,url:xe},jn={...ut,link:P(/^!?\[(label)\]\((.*?)\)/).replace("label",Ve).getRegex(),reflink:P(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Ve).getRegex()},Qe={...ut,emStrongRDelimAst:_n,emStrongLDelim:Cn,delLDelim:Rn,delRDelim:Nn,url:P(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Tt).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:P(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Tt).getRegex()},Ln={...Qe,br:P(Wt).replace("{2,}","*").getRegex(),text:P(Qe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},je={normal:it,gfm:mn,pedantic:hn},_e={normal:ut,gfm:Qe,breaks:Ln,pedantic:jn},Fn={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},_t=s=>Fn[s];function re(s,e){if(e){if(W.escapeTest.test(s))return s.replace(W.escapeReplace,_t)}else if(W.escapeTestNoEncode.test(s))return s.replace(W.escapeReplaceNoEncode,_t);return s}function Mt(s){try{s=encodeURI(s).replace(W.percentDecode,"%")}catch{return null}return s}function Rt(s,e){let t=s.replace(W.findPipe,(l,a,c)=>{let i=!1,d=a;for(;--d>=0&&c[d]==="\\";)i=!i;return i?"|":" |"}),o=t.split(W.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(W.slashPipe,"|");return o}function Me(s,e,t){let o=s.length;if(o===0)return"";let n=0;for(;n<o&&s.charAt(o-n-1)===e;)n++;return s.slice(0,o-n)}function On(s,e){if(s.indexOf(e[1])===-1)return-1;let t=0;for(let o=0;o<s.length;o++)if(s[o]==="\\")o++;else if(s[o]===e[0])t++;else if(s[o]===e[1]&&(t--,t<0))return o;return t>0?-2:-1}function Vn(s,e=0){let t=e,o="";for(let n of s)if(n===" "){let l=4-t%4;o+=" ".repeat(l),t+=l}else o+=n,t++;return o}function At(s,e,t,o,n){let l=e.href,a=e.title||null,c=s[1].replace(n.other.outputLinkReplace,"$1");o.state.inLink=!0;let i={type:s[0].charAt(0)==="!"?"image":"link",raw:t,href:l,title:a,text:c,tokens:o.inlineTokens(c)};return o.state.inLink=!1,i}function Un(s,e,t){let o=s.match(t.other.indentCodeCompensation);if(o===null)return e;let n=o[1];return e.split(`
29
- `).map(l=>{let a=l.match(t.other.beginningSpace);if(a===null)return l;let[c]=a;return c.length>=n.length?l.slice(n.length):l}).join(`
30
- `)}var Ue=class{options;rules;lexer;constructor(s){this.options=s||be}space(s){let e=this.rules.block.newline.exec(s);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(s){let e=this.rules.block.code.exec(s);if(e){let t=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?t:Me(t,`
31
- `)}}}fences(s){let e=this.rules.block.fences.exec(s);if(e){let t=e[0],o=Un(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:o}}}heading(s){let e=this.rules.block.heading.exec(s);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let o=Me(t,"#");(this.options.pedantic||!o||this.rules.other.endingSpaceChar.test(o))&&(t=o.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(s){let e=this.rules.block.hr.exec(s);if(e)return{type:"hr",raw:Me(e[0],`
32
- `)}}blockquote(s){let e=this.rules.block.blockquote.exec(s);if(e){let t=Me(e[0],`
33
- `).split(`
34
- `),o="",n="",l=[];for(;t.length>0;){let a=!1,c=[],i;for(i=0;i<t.length;i++)if(this.rules.other.blockquoteStart.test(t[i]))c.push(t[i]),a=!0;else if(!a)c.push(t[i]);else break;t=t.slice(i);let d=c.join(`
35
- `),p=d.replace(this.rules.other.blockquoteSetextReplace,`
36
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");o=o?`${o}
37
- ${d}`:d,n=n?`${n}
38
- ${p}`:p;let m=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,l,!0),this.lexer.state.top=m,t.length===0)break;let b=l.at(-1);if(b?.type==="code")break;if(b?.type==="blockquote"){let k=b,f=k.raw+`
39
- `+t.join(`
40
- `),z=this.blockquote(f);l[l.length-1]=z,o=o.substring(0,o.length-k.raw.length)+z.raw,n=n.substring(0,n.length-k.text.length)+z.text;break}else if(b?.type==="list"){let k=b,f=k.raw+`
41
- `+t.join(`
42
- `),z=this.list(f);l[l.length-1]=z,o=o.substring(0,o.length-b.raw.length)+z.raw,n=n.substring(0,n.length-k.raw.length)+z.raw,t=f.substring(l.at(-1).raw.length).split(`
43
- `);continue}}return{type:"blockquote",raw:o,tokens:l,text:n}}}list(s){let e=this.rules.block.list.exec(s);if(e){let t=e[1].trim(),o=t.length>1,n={type:"list",raw:"",ordered:o,start:o?+t.slice(0,-1):"",loose:!1,items:[]};t=o?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=o?t:"[*+-]");let l=this.rules.other.listItemRegex(t),a=!1;for(;s;){let i=!1,d="",p="";if(!(e=l.exec(s))||this.rules.block.hr.test(s))break;d=e[0],s=s.substring(d.length);let m=Vn(e[2].split(`
44
- `,1)[0],e[1].length),b=s.split(`
45
- `,1)[0],k=!m.trim(),f=0;if(this.options.pedantic?(f=2,p=m.trimStart()):k?f=e[1].length+1:(f=m.search(this.rules.other.nonSpaceChar),f=f>4?1:f,p=m.slice(f),f+=e[1].length),k&&this.rules.other.blankLine.test(b)&&(d+=b+`
46
- `,s=s.substring(b.length+1),i=!0),!i){let z=this.rules.other.nextBulletRegex(f),$=this.rules.other.hrRegex(f),I=this.rules.other.fencesBeginRegex(f),L=this.rules.other.headingBeginRegex(f),V=this.rules.other.htmlBeginRegex(f),J=this.rules.other.blockquoteBeginRegex(f);for(;s;){let q=s.split(`
47
- `,1)[0],K;if(b=q,this.options.pedantic?(b=b.replace(this.rules.other.listReplaceNesting," "),K=b):K=b.replace(this.rules.other.tabCharGlobal," "),I.test(b)||L.test(b)||V.test(b)||J.test(b)||z.test(b)||$.test(b))break;if(K.search(this.rules.other.nonSpaceChar)>=f||!b.trim())p+=`
48
- `+K.slice(f);else{if(k||m.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||I.test(m)||L.test(m)||$.test(m))break;p+=`
49
- `+b}k=!b.trim(),d+=q+`
50
- `,s=s.substring(q.length+1),m=K.slice(f)}}n.loose||(a?n.loose=!0:this.rules.other.doubleBlankLine.test(d)&&(a=!0)),n.items.push({type:"list_item",raw:d,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=d}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 p=this.lexer.inlineQueue.length-1;p>=0;p--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[p].src)){this.lexer.inlineQueue[p].src=this.lexer.inlineQueue[p].src.replace(this.rules.other.listReplaceTask,"");break}}let d=this.rules.other.listTaskCheckbox.exec(i.raw);if(d){let p={type:"checkbox",raw:d[0]+" ",checked:d[0]!=="[ ]"};i.checked=p.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=p.raw+i.tokens[0].raw,i.tokens[0].text=p.raw+i.tokens[0].text,i.tokens[0].tokens.unshift(p)):i.tokens.unshift({type:"paragraph",raw:p.raw,text:p.raw,tokens:[p]}):i.tokens.unshift(p)}}if(!n.loose){let d=i.tokens.filter(m=>m.type==="space"),p=d.length>0&&d.some(m=>this.rules.other.anyLine.test(m.raw));n.loose=p}}if(n.loose)for(let i of n.items){i.loose=!0;for(let d of i.tokens)d.type==="text"&&(d.type="paragraph")}return n}}html(s){let e=this.rules.block.html.exec(s);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(s){let e=this.rules.block.def.exec(s);if(e){let t=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:t,raw:e[0],href:o,title:n}}}table(s){let e=this.rules.block.table.exec(s);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=Rt(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(t.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<t.length;a++)l.header.push({text:t[a],tokens:this.lexer.inline(t[a]),header:!0,align:l.align[a]});for(let a of n)l.rows.push(Rt(a,l.header.length).map((c,i)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:l.align[i]})));return l}}lheading(s){let e=this.rules.block.lheading.exec(s);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(s){let e=this.rules.block.paragraph.exec(s);if(e){let t=e[1].charAt(e[1].length-1)===`
52
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(s){let e=this.rules.block.text.exec(s);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(s){let e=this.rules.inline.escape.exec(s);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(s){let e=this.rules.inline.tag.exec(s);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(s){let e=this.rules.inline.link.exec(s);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let l=Me(t.slice(0,-1),"\\");if((t.length-l.length)%2===0)return}else{let l=On(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(t)?o=o.slice(1):o=o.slice(1,-1)),At(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(s,e){let t;if((t=this.rules.inline.reflink.exec(s))||(t=this.rules.inline.nolink.exec(s))){let o=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[o.toLowerCase()];if(!n){let l=t[0].charAt(0);return{type:"text",raw:l,text:l}}return At(t,n,t[0],this.lexer,this.rules)}}emStrong(s,e,t=""){let o=this.rules.inline.emStrongLDelim.exec(s);if(!(!o||o[3]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(o[1]||o[2])||!t||this.rules.inline.punctuation.exec(t))){let n=[...o[0]].length-1,l,a,c=n,i=0,d=o[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(d.lastIndex=0,e=e.slice(-1*s.length+n);(o=d.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 p=[...o[0]][0].length,m=s.slice(0,n+o.index+p+a);if(Math.min(n,a)%2){let k=m.slice(1,-1);return{type:"em",raw:m,text:k,tokens:this.lexer.inlineTokens(k)}}let b=m.slice(2,-2);return{type:"strong",raw:m,text:b,tokens:this.lexer.inlineTokens(b)}}}}codespan(s){let e=this.rules.inline.code.exec(s);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),o=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return o&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(s){let e=this.rules.inline.br.exec(s);if(e)return{type:"br",raw:e[0]}}del(s,e,t=""){let o=this.rules.inline.delLDelim.exec(s);if(o&&(!o[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...o[0]].length-1,l,a,c=n,i=this.rules.inline.delRDelim;for(i.lastIndex=0,e=e.slice(-1*s.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 d=[...o[0]][0].length,p=s.slice(0,n+o.index+d+a),m=p.slice(n,-n);return{type:"del",raw:p,text:m,tokens:this.lexer.inlineTokens(m)}}}}autolink(s){let e=this.rules.inline.autolink.exec(s);if(e){let t,o;return e[2]==="@"?(t=e[1],o="mailto:"+t):(t=e[1],o=t),{type:"link",raw:e[0],text:t,href:o,tokens:[{type:"text",raw:t,text:t}]}}}url(s){let e;if(e=this.rules.inline.url.exec(s)){let t,o;if(e[2]==="@")t=e[0],o="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?o="http://"+e[0]:o=e[0]}return{type:"link",raw:e[0],text:t,href:o,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(s){let e=this.rules.inline.text.exec(s);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},se=class Je{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||be,this.options.tokenizer=this.options.tokenizer||new Ue,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 t={other:W,block:je.normal,inline:_e.normal};this.options.pedantic?(t.block=je.pedantic,t.inline=_e.pedantic):this.options.gfm&&(t.block=je.gfm,this.options.breaks?t.inline=_e.breaks:t.inline=_e.gfm),this.tokenizer.rules=t}static get rules(){return{block:je,inline:_e}}static lex(e,t){return new Je(t).lex(e)}static lexInline(e,t){return new Je(t).inlineTokens(e)}lex(e){e=e.replace(W.carriageReturn,`
53
- `),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let o=this.inlineQueue[t];this.inlineTokens(o.src,o.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],o=!1){for(this.options.pedantic&&(e=e.replace(W.tabCharGlobal," ").replace(W.spaceLine,""));e;){let n;if(this.options.extensions?.block?.some(a=>(n=a.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),!0):!1))continue;if(n=this.tokenizer.space(e)){e=e.substring(n.raw.length);let a=t.at(-1);n.raw.length===1&&a!==void 0?a.raw+=`
54
- `:t.push(n);continue}if(n=this.tokenizer.code(e)){e=e.substring(n.raw.length);let a=t.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):t.push(n);continue}if(n=this.tokenizer.fences(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.heading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.hr(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.blockquote(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.list(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.html(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.def(e)){e=e.substring(n.raw.length);let a=t.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},t.push(n));continue}if(n=this.tokenizer.table(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.lheading(e)){e=e.substring(n.raw.length),t.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(d=>{i=d.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=t.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):t.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=t.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):t.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,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){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(p=>(i=p.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.escape(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.tag(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.link(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(i.raw.length);let p=t.at(-1);i.type==="text"&&p?.type==="text"?(p.raw+=i.raw,p.text+=i.text):t.push(i);continue}if(i=this.tokenizer.emStrong(e,o,c)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.codespan(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.br(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.del(e,o,c)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.autolink(e)){e=e.substring(i.raw.length),t.push(i);continue}if(!this.state.inLink&&(i=this.tokenizer.url(e))){e=e.substring(i.raw.length),t.push(i);continue}let d=e;if(this.options.extensions?.startInline){let p=1/0,m=e.slice(1),b;this.options.extensions.startInline.forEach(k=>{b=k.call({lexer:this},m),typeof b=="number"&&b>=0&&(p=Math.min(p,b))}),p<1/0&&p>=0&&(d=e.substring(0,p+1))}if(i=this.tokenizer.inlineText(d)){e=e.substring(i.raw.length),i.raw.slice(-1)!=="_"&&(c=i.raw.slice(-1)),a=!0;let p=t.at(-1);p?.type==="text"?(p.raw+=i.raw,p.text+=i.text):t.push(i);continue}if(e){let p="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(p);break}else throw new Error(p)}}return t}},qe=class{options;parser;constructor(s){this.options=s||be}space(s){return""}code({text:s,lang:e,escaped:t}){let o=(e||"").match(W.notSpaceStart)?.[0],n=s.replace(W.endingNewline,"")+`
67
- `;return o?'<pre><code class="language-'+re(o)+'">'+(t?n:re(n,!0))+`</code></pre>
68
- `:"<pre><code>"+(t?n:re(n,!0))+`</code></pre>
69
- `}blockquote({tokens:s}){return`<blockquote>
70
- ${this.parser.parse(s)}</blockquote>
71
- `}html({text:s}){return s}def(s){return""}heading({tokens:s,depth:e}){return`<h${e}>${this.parser.parseInline(s)}</h${e}>
72
- `}hr(s){return`<hr>
73
- `}list(s){let e=s.ordered,t=s.start,o="";for(let a=0;a<s.items.length;a++){let c=s.items[a];o+=this.listitem(c)}let n=e?"ol":"ul",l=e&&t!==1?' start="'+t+'"':"";return"<"+n+l+`>
74
- `+o+"</"+n+`>
75
- `}listitem(s){return`<li>${this.parser.parse(s.tokens)}</li>
76
- `}checkbox({checked:s}){return"<input "+(s?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:s}){return`<p>${this.parser.parseInline(s)}</p>
77
- `}table(s){let e="",t="";for(let n=0;n<s.header.length;n++)t+=this.tablecell(s.header[n]);e+=this.tablerow({text:t});let o="";for(let n=0;n<s.rows.length;n++){let l=s.rows[n];t="";for(let a=0;a<l.length;a++)t+=this.tablecell(l[a]);o+=this.tablerow({text:t})}return o&&(o=`<tbody>${o}</tbody>`),`<table>
78
- <thead>
79
- `+e+`</thead>
80
- `+o+`</table>
81
- `}tablerow({text:s}){return`<tr>
82
- ${s}</tr>
83
- `}tablecell(s){let e=this.parser.parseInline(s.tokens),t=s.header?"th":"td";return(s.align?`<${t} align="${s.align}">`:`<${t}>`)+e+`</${t}>
84
- `}strong({tokens:s}){return`<strong>${this.parser.parseInline(s)}</strong>`}em({tokens:s}){return`<em>${this.parser.parseInline(s)}</em>`}codespan({text:s}){return`<code>${re(s,!0)}</code>`}br(s){return"<br>"}del({tokens:s}){return`<del>${this.parser.parseInline(s)}</del>`}link({href:s,title:e,tokens:t}){let o=this.parser.parseInline(t),n=Mt(s);if(n===null)return o;s=n;let l='<a href="'+s+'"';return e&&(l+=' title="'+re(e)+'"'),l+=">"+o+"</a>",l}image({href:s,title:e,text:t,tokens:o}){o&&(t=this.parser.parseInline(o,this.parser.textRenderer));let n=Mt(s);if(n===null)return re(t);s=n;let l=`<img src="${s}" alt="${re(t)}"`;return e&&(l+=` title="${re(e)}"`),l+=">",l}text(s){return"tokens"in s&&s.tokens?this.parser.parseInline(s.tokens):"escaped"in s&&s.escaped?s.text:re(s.text)}},dt=class{strong({text:s}){return s}em({text:s}){return s}codespan({text:s}){return s}del({text:s}){return s}html({text:s}){return s}text({text:s}){return s}link({text:s}){return""+s}image({text:s}){return""+s}br(){return""}checkbox({raw:s}){return s}},ne=class Xe{options;renderer;textRenderer;constructor(e){this.options=e||be,this.options.renderer=this.options.renderer||new qe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new dt}static parse(e,t){return new Xe(t).parse(e)}static parseInline(e,t){return new Xe(t).parseInline(e)}parse(e){let t="";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)){t+=c||"";continue}}let l=n;switch(l.type){case"space":{t+=this.renderer.space(l);break}case"hr":{t+=this.renderer.hr(l);break}case"heading":{t+=this.renderer.heading(l);break}case"code":{t+=this.renderer.code(l);break}case"table":{t+=this.renderer.table(l);break}case"blockquote":{t+=this.renderer.blockquote(l);break}case"list":{t+=this.renderer.list(l);break}case"checkbox":{t+=this.renderer.checkbox(l);break}case"html":{t+=this.renderer.html(l);break}case"def":{t+=this.renderer.def(l);break}case"paragraph":{t+=this.renderer.paragraph(l);break}case"text":{t+=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 t}parseInline(e,t=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+=t.text(a);break}case"html":{o+=t.html(a);break}case"link":{o+=t.link(a);break}case"image":{o+=t.image(a);break}case"checkbox":{o+=t.checkbox(a);break}case"strong":{o+=t.strong(a);break}case"em":{o+=t.em(a);break}case"codespan":{o+=t.codespan(a);break}case"br":{o+=t.br(a);break}case"del":{o+=t.del(a);break}case"text":{o+=t.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}},Re=class{options;block;constructor(s){this.options=s||be}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(s){return s}postprocess(s){return s}processAllTokens(s){return s}emStrongMask(s){return s}provideLexer(){return this.block?se.lex:se.lexInline}provideParser(){return this.block?ne.parse:ne.parseInline}},ts=class{defaults=nt();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=ne;Renderer=qe;TextRenderer=dt;Lexer=se;Tokenizer=Ue;Hooks=Re;constructor(...s){this.use(...s)}walkTokens(s,e){let t=[];for(let o of s)switch(t=t.concat(e.call(this,o)),o.type){case"table":{let n=o;for(let l of n.header)t=t.concat(this.walkTokens(l.tokens,e));for(let l of n.rows)for(let a of l)t=t.concat(this.walkTokens(a.tokens,e));break}case"list":{let n=o;t=t.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);t=t.concat(this.walkTokens(a,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...s){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return s.forEach(t=>{let o={...t};if(o.async=this.defaults.async||o.async||!1,t.extensions&&(t.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),t.renderer){let n=this.defaults.renderer||new qe(this.defaults);for(let l in t.renderer){if(!(l in n))throw new Error(`renderer '${l}' does not exist`);if(["options","parser"].includes(l))continue;let a=l,c=t.renderer[a],i=n[a];n[a]=(...d)=>{let p=c.apply(n,d);return p===!1&&(p=i.apply(n,d)),p||""}}o.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new Ue(this.defaults);for(let l in t.tokenizer){if(!(l in n))throw new Error(`tokenizer '${l}' does not exist`);if(["options","rules","lexer"].includes(l))continue;let a=l,c=t.tokenizer[a],i=n[a];n[a]=(...d)=>{let p=c.apply(n,d);return p===!1&&(p=i.apply(n,d)),p}}o.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new Re;for(let l in t.hooks){if(!(l in n))throw new Error(`hook '${l}' does not exist`);if(["options","block"].includes(l))continue;let a=l,c=t.hooks[a],i=n[a];Re.passThroughHooks.has(l)?n[a]=d=>{if(this.defaults.async&&Re.passThroughHooksRespectAsync.has(l))return(async()=>{let m=await c.call(n,d);return i.call(n,m)})();let p=c.call(n,d);return i.call(n,p)}:n[a]=(...d)=>{if(this.defaults.async)return(async()=>{let m=await c.apply(n,d);return m===!1&&(m=await i.apply(n,d)),m})();let p=c.apply(n,d);return p===!1&&(p=i.apply(n,d)),p}}o.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,l=t.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(s){return this.defaults={...this.defaults,...s},this}lexer(s,e){return se.lex(s,e??this.defaults)}parser(s,e){return ne.parse(s,e??this.defaults)}parseMarkdown(s){return(e,t)=>{let o={...t},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=s),n.async)return(async()=>{let a=n.hooks?await n.hooks.preprocess(e):e,c=await(n.hooks?await n.hooks.provideLexer():s?se.lex:se.lexInline)(a,n),i=n.hooks?await n.hooks.processAllTokens(c):c;n.walkTokens&&await Promise.all(this.walkTokens(i,n.walkTokens));let d=await(n.hooks?await n.hooks.provideParser():s?ne.parse:ne.parseInline)(i,n);return n.hooks?await n.hooks.postprocess(d):d})().catch(l);try{n.hooks&&(e=n.hooks.preprocess(e));let a=(n.hooks?n.hooks.provideLexer():s?se.lex:se.lexInline)(e,n);n.hooks&&(a=n.hooks.processAllTokens(a)),n.walkTokens&&this.walkTokens(a,n.walkTokens);let c=(n.hooks?n.hooks.provideParser():s?ne.parse:ne.parseInline)(a,n);return n.hooks&&(c=n.hooks.postprocess(c)),c}catch(a){return l(a)}}}onError(s,e){return t=>{if(t.message+=`
85
- Please report this to https://github.com/markedjs/marked.`,s){let o="<p>An error occurred:</p><pre>"+re(t.message+"",!0)+"</pre>";return e?Promise.resolve(o):o}if(e)return Promise.reject(t);throw t}}},ve=new ts;function B(s,e){return ve.parse(s,e)}B.options=B.setOptions=function(s){return ve.setOptions(s),B.defaults=ve.defaults,Ut(B.defaults),B};B.getDefaults=nt;B.defaults=be;B.use=function(...s){return ve.use(...s),B.defaults=ve.defaults,Ut(B.defaults),B};B.walkTokens=function(s,e){return ve.walkTokens(s,e)};B.parseInline=ve.parseInline;B.Parser=ne;B.parser=ne.parse;B.Renderer=qe;B.TextRenderer=dt;B.Lexer=se;B.lexer=se.lex;B.Tokenizer=Ue;B.Hooks=Re;B.parse=B;B.options;B.setOptions;B.use;B.walkTokens;B.parseInline;ne.parse;se.lex;const qn=new ts({breaks:!0,gfm:!0});function Hn(s){return s?qn.parse(s):""}const Gn={key:0,class:"my-2"},Wn={key:0,class:"relative inline-flex h-4 w-4 items-center justify-center"},Kn={key:1,class:"text-text-muted"},Zn={key:0,class:"mt-1 ml-2 rounded-lg border-l-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"},Qn={key:0,class:"inline-flex items-center gap-0.5 ml-1 align-text-bottom"},Jn=te({__name:"InlineThinkingBlock",props:{isThinking:{type:Boolean},content:{},completed:{type:Boolean}},setup(s){const e=M(!1);return(t,o)=>s.isThinking||s.completed&&s.content?(h(),g("div",Gn,[r("button",{class:D(["flex items-center gap-2 rounded-lg px-3 py-1.5 text-xs transition-colors",s.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)},[s.isThinking?(h(),g("span",Wn,[...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)])])):(h(),g("span",Kn,"💭")),r("span",null,S(s.isThinking?"Thinking...":"Thought process"),1),r("span",{class:D(["text-text-muted transition-transform",{"rotate-180":e.value}])},"▾",2)],2),e.value?(h(),g("div",Zn,[Se(S(s.content)+" ",1),s.isThinking?(h(),g("span",Qn,[...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)])])):A("",!0)])):A("",!0)])):A("",!0)}}),Xn={class:"text-sm leading-relaxed text-text-primary"},Yn=te({__name:"AssistantTokenStream",props:{sessionId:{}},setup(s){const e=s,t=jt(),{getColor:o}=As(ys(e,"sessionId")),n=j(()=>t.getTokens(e.sessionId)),l=j(()=>{const a=n.value,c=[];let i=!1,d="";for(const p of a){if(d+=p.text,!i&&d.includes("<think>")){i=!0;const m=d.split("<think>")[0]??"";m&&c.length===0&&c.push({...p,text:m});continue}if(i){if(d.includes("</think>")){i=!1;const m=d.split("</think>").pop()??"",b=p.text;if(m.endsWith(b)&&b.includes("</think>")){const k=b.split("</think>").pop()??"";k&&c.push({...p,text:k})}}continue}c.push(p)}return c});return(a,c)=>(h(),g("div",Xn,[(h(!0),g(O,null,Q(l.value,i=>(h(),g("span",{key:i.id,class:"inline",style:bs({borderBottom:`2px solid ${x(o)(i.confidence)}`})},S(i.text),5))),128))]))}}),eo={key:0,class:"mb-1.5 space-y-1.5"},to=["src","alt","onClick"],so={class:"mt-0.5 flex items-center gap-1.5 text-[10px] opacity-60"},no={class:"truncate"},oo={class:"flex flex-wrap gap-1.5"},ro={class:"max-w-[100px] truncate opacity-90"},ao={class:"opacity-60"},lo=["src"],io=te({__name:"AttachmentBubble",props:{attachments:{}},setup(s){const e=M(null);function t(n){n.content&&(e.value=n.content)}function o(){e.value=null}return(n,l)=>s.attachments.length>0?(h(),g("div",eo,[(h(!0),g(O,null,Q(s.attachments.filter(a=>a.type==="image"&&a.content),a=>(h(),g("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=>t(a)},null,8,to),r("div",so,[r("span",no,S(a.name),1),r("span",null,S(x(Ze)(a.sizeBytes)),1)])]))),128)),r("div",oo,[(h(!0),g(O,null,Q(s.attachments.filter(a=>a.type==="document"),a=>(h(),g("div",{key:a.id,class:"flex items-center gap-1.5 rounded-md bg-white/10 px-2 py-1 text-[11px]"},[l[1]||(l[1]=r("svg",{class:"h-3.5 w-3.5 opacity-70",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),r("polyline",{points:"14 2 14 8 20 8"})],-1)),r("span",ro,S(a.name),1),r("span",ao,S(x(Ze)(a.sizeBytes)),1)]))),128))]),(h(),Ae(ks,{to:"body"},[G(zt,{"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:Et(()=>[e.value?(h(),g("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]=Le(()=>{},["stop"]))},null,8,lo),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},[...l[2]||(l[2]=[r("svg",{class:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])])])):A("",!0)]),_:1})]))])):A("",!0)}}),co={class:"text-sm leading-relaxed whitespace-pre-wrap"},uo=["innerHTML"],po={key:3,class:"inline-flex items-center gap-1 py-1"},mo={key:4,class:"mt-1 text-[10px] text-warning"},ho={key:2,class:"mt-1.5 flex items-center gap-2 text-[10px] text-text-muted"},go={class:"text-[10px] opacity-50"},fo=te({__name:"ChatBubble",props:{message:{}},setup(s){const e=s,t=He(),o=Es(),n=et(),l=j(()=>e.message.sessionId?n.getMetrics(e.message.sessionId):null),a=j(()=>e.message.sessionId?t.sessionById(e.message.sessionId)?.doneReason==="length":!1),c=j(()=>e.message.sessionId?o.getThinking(e.message.sessionId):{isThinking:!1,content:""}),i=j(()=>e.message.role==="user"),d=j(()=>{if(i.value){if(e.message.attachments?.length){const b=`
86
-
87
- ---
88
-
89
- `,k=e.message.content.lastIndexOf(b);if(k!==-1)return e.message.content.slice(k+b.length)}return e.message.content}return e.message.isStreaming?"":e.message.content.replace(/<think>[\s\S]*?<\/think>/g,"").trim()}),p=j(()=>i.value||!d.value?"":Hn(d.value)),m=j(()=>new Date(e.message.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}));return(b,k)=>(h(),g("div",{class:D(["flex w-full",i.value?"justify-end":"justify-start"])},[r("div",{class:D(["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?(h(),g(O,{key:0},[s.message.attachments?.length?(h(),Ae(io,{key:0,attachments:s.message.attachments},null,8,["attachments"])):A("",!0),r("p",co,S(d.value),1)],64)):(h(),g(O,{key:1},[s.message.sessionId?(h(),Ae(Jn,{key:0,"is-thinking":c.value.isThinking,content:c.value.content,completed:!s.message.isStreaming},null,8,["is-thinking","content","completed"])):A("",!0),s.message.isStreaming&&s.message.sessionId?(h(),Ae(Yn,{key:1,"session-id":s.message.sessionId},null,8,["session-id"])):d.value?(h(),g("div",{key:2,class:"markdown-prose",innerHTML:p.value},null,8,uo)):A("",!0),s.message.isStreaming&&!d.value?(h(),g("span",po,[...k[0]||(k[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)])])):A("",!0),a.value&&!s.message.isStreaming?(h(),g("div",mo," Response was truncated — increase num_predict in settings for longer responses ")):A("",!0)],64)),!i.value&&!s.message.isStreaming&&l.value?(h(),g("div",ho,[r("span",null,S(l.value.completionTokenCount)+" tokens",1),k[1]||(k[1]=r("span",{class:"opacity-40"},"·",-1)),r("span",null,S(l.value.tokensPerSecond.toFixed(1))+" tok/s",1),k[2]||(k[2]=r("span",{class:"opacity-40"},"·",-1)),r("span",null,S(l.value.ttftMs<1e3?l.value.ttftMs.toFixed(0)+"ms":(l.value.ttftMs/1e3).toFixed(1)+"s")+" TTFT",1)])):A("",!0),r("div",{class:D(["mt-1",i.value?"text-right":""])},[r("span",go,S(m.value),1)],2)],2)],2))}}),xo={key:0,class:"flex items-center justify-center"},vo=te({__name:"ChatMessageList",props:{messages:{}},setup(s,{expose:e}){const t=s,o=M(null);function n(){Ss(()=>{o.value&&(o.value.scrollTop=o.value.scrollHeight)})}return ee(()=>t.messages.length,()=>n()),ee(()=>t.messages[t.messages.length-1]?.content,()=>n()),e({scrollToBottom:n}),(l,a)=>(h(),g("div",{ref_key:"containerRef",ref:o,class:"flex-1 overflow-y-auto px-4 py-6"},[r("div",{class:D(["mx-auto max-w-3xl space-y-4",s.messages.length===0?"flex min-h-full flex-col justify-center":""])},[s.messages.length===0?(h(),g("div",xo,[...a[0]||(a[0]=[ws('<div class="text-center"><svg class="mx-auto mb-4 h-20 w-20 text-text-muted/20" viewBox="0 0 297.5 297.5"><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"></path></svg><p class="text-2xl font-semibold text-text-primary mb-2">LLMxRay</p><p class="text-sm text-text-muted">Start a conversation with a local model</p></div>',1)])])):A("",!0),(h(!0),g(O,null,Q(s.messages,c=>(h(),Ae(fo,{key:c.id,message:c},null,8,["message"]))),128))],2)],512))}}),bo=new Set(["png","jpg","jpeg","gif","webp"]),yo=new Set(["pdf","docx","txt","md","csv"]);function ss(s){return s.split(".").pop()?.toLowerCase()??""}function Ye(s){return bo.has(ss(s))}function ns(s){return yo.has(ss(s))}function ko(s){return Ye(s)||ns(s)}const wo=".pdf,.docx,.txt,.md,.csv,.png,.jpg,.jpeg,.gif,.webp",Nt=8e3;function So(){const s=M([]),e=j(()=>s.value.some(c=>c.status==="parsing"));async function t(c){for(const i of c){if(!ko(i.name))continue;const d={id:pe(),name:i.name,type:Ye(i.name)?"image":"document",mimeType:i.type,sizeBytes:i.size,status:"pending"};s.value.push(d),Ye(i.name)?o(i,d):ns(i.name)&&n(i,d)}}function o(c,i){i.status="parsing";const d=i.id,p=new FileReader;p.onload=()=>{const m=s.value.find(b=>b.id===d);m&&(m.content=p.result,m.status="ready")},p.onerror=()=>{const m=s.value.find(b=>b.id===d);m&&(m.error="Failed to read image",m.status="error")},p.readAsDataURL(c)}async function n(c,i){i.status="parsing";const d=i.id;try{const p=Ps(c.name);if(!p){const k=s.value.find(f=>f.id===d);k&&(k.error="Unsupported format",k.status="error");return}let m=await Ds(c,p);m.length>Nt&&(m=m.slice(0,Nt)+`
90
-
91
- [... truncated]`);const b=s.value.find(k=>k.id===d);b&&(b.content=m,b.status="ready")}catch(p){const m=s.value.find(b=>b.id===d);m&&(m.error=p instanceof Error?p.message:"Parse failed",m.status="error")}}function l(c){s.value=s.value.filter(i=>i.id!==c)}function a(){s.value=[]}return{attachments:s,isProcessing:e,addFiles:t,removeAttachment:l,clearAttachments:a}}const $o={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"},Co={class:"p-1.5"},To=["onMouseenter","onClick"],_o={class:"shrink-0 font-mono text-xs text-accent"},Mo={class:"truncate text-xs text-text-muted"},Ro={class:"ml-auto shrink-0 rounded bg-surface-overlay px-1.5 py-0.5 text-[10px] text-text-muted"},Ao=te({__name:"SlashCommandDropdown",props:{filter:{},visible:{type:Boolean}},emits:["select","close"],setup(s,{expose:e,emit:t}){const o=s,n=t,l=M(0),a=j(()=>{if(!o.visible)return[];const d=o.filter.replace(/^\//,"");return d?Zs(d):Object.values(Ot()).flat()});ee(()=>o.filter,()=>{l.value=0});function c(d){return!o.visible||a.value.length===0?!1:d.key==="ArrowDown"?(d.preventDefault(),l.value=(l.value+1)%a.value.length,!0):d.key==="ArrowUp"?(d.preventDefault(),l.value=l.value<=0?a.value.length-1:l.value-1,!0):d.key==="Tab"||d.key==="Enter"&&a.value.length>0?(d.preventDefault(),n("select",a.value[l.value]),!0):d.key==="Escape"?(d.preventDefault(),n("close"),!0):!1}e({handleKeydown:c});const i={chat:"Chat & Conversation",settings:"Model & Settings",navigation:"Features & Navigation"};return(d,p)=>s.visible&&a.value.length>0?(h(),g("div",$o,[r("div",Co,[(h(!0),g(O,null,Q(a.value,(m,b)=>(h(),g("button",{key:m.name,class:D(["flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-sm transition-colors",b===l.value?"bg-accent/10 text-accent":"text-text-primary hover:bg-surface-overlay"]),onMouseenter:k=>l.value=b,onClick:k=>d.$emit("select",m)},[r("span",_o,"/"+S(m.name),1),r("span",Mo,S(m.description),1),r("span",Ro,S(i[m.category]??m.category),1)],42,To))),128))])])):A("",!0)}}),No={key:0,class:"flex flex-wrap gap-2 px-2.5 pb-1.5 pt-1"},zo=["src","alt"],Eo={key:1,class:"text-text-muted"},Io={class:"max-w-[120px] truncate text-text-primary"},Po={class:"text-text-muted"},Do={key:2,class:"h-3 w-3 animate-spin rounded-full border-2 border-accent border-t-transparent"},Bo={key:3,class:"text-error",title:"Parse error"},jo=["onClick"],Lo=te({__name:"AttachmentPreview",props:{attachments:{}},emits:["remove"],setup(s){return(e,t)=>s.attachments.length>0?(h(),g("div",No,[(h(!0),g(O,null,Q(s.attachments,o=>(h(),g("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?(h(),g("img",{key:0,src:o.content,alt:o.name,class:"h-6 w-6 rounded object-cover"},null,8,zo)):o.type==="document"?(h(),g("span",Eo,[...t[0]||(t[0]=[r("svg",{class:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),r("polyline",{points:"14 2 14 8 20 8"})],-1)])])):A("",!0),r("span",Io,S(o.name),1),r("span",Po,S(x(Ze)(o.sizeBytes)),1),o.status==="parsing"?(h(),g("span",Do)):o.status==="error"?(h(),g("span",Bo,"!")):A("",!0),r("button",{class:"text-text-muted hover:text-error transition-colors",onClick:n=>e.$emit("remove",o.id)},[...t[1]||(t[1]=[r("svg",{class:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])],8,jo)]))),128))])):A("",!0)}}),Fo={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"},Oo={class:"relative mx-auto max-w-3xl"},Vo=["accept"],Uo={class:"mx-auto flex max-w-3xl flex-col rounded-xl border border-border-default bg-surface transition-colors focus-within:border-accent"},qo=["disabled","title"],Ho={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:"Vision model — can process images"},Go=["disabled"],Wo=["disabled","placeholder"],Ko=["disabled"],Zo=te({__name:"ChatInput",props:{isStreaming:{type:Boolean},selectedModel:{},isVisionModel:{type:Boolean}},emits:["send","command","cancel"],setup(s,{expose:e,emit:t}){const o=t;e({focus:L});const n=tt(),l=M(""),a=M(null),c=M(null),i=M(null),d=M(!1),{attachments:p,isProcessing:m,addFiles:b,removeAttachment:k,clearAttachments:f}=So();It(()=>{n.fetchModels()});const z=j(()=>{const C=l.value;return C.startsWith("/")&&!C.includes(`
92
- `)}),$=j(()=>{if(!z.value)return"";const C=l.value.indexOf(" ");return C===-1?l.value:l.value.slice(0,C)}),I=j(()=>{const C=l.value.trim().length>0,R=p.value.length>0;return(C||R)&&!m.value});function L(){a.value?.focus()}function V(C){z.value&&i.value&&i.value.handleKeydown(C)||C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),q())}function J(C){l.value=`/${C.name} `,a.value?.focus()}function q(){const C=l.value.trim();if(!(!C&&p.value.length===0)){if(C.startsWith("/")&&p.value.length===0){const R=C.indexOf(" "),oe=R===-1?C.slice(1):C.slice(1,R),he=R===-1?"":C.slice(R+1);o("command",oe,he)}else o("send",C,[...p.value]),f();l.value="",a.value&&(a.value.style.height="auto")}}function K(C){const R=C.target;R.style.height="auto",R.style.height=Math.min(R.scrollHeight,200)+"px"}function ce(){l.value=""}function X(){l.value="/",a.value?.focus()}function me(){c.value?.click()}function $e(C){const R=C.target;R.files&&R.files.length>0&&(b(R.files),R.value="")}function Ce(C){C.preventDefault(),d.value=!0}function T(){d.value=!1}function u(C){C.preventDefault(),d.value=!1,C.dataTransfer?.files&&C.dataTransfer.files.length>0&&b(C.dataTransfer.files)}function y(C){const R=C.clipboardData?.items;if(!R)return;const oe=[];for(const he of R)if(he.type.startsWith("image/")){const ae=he.getAsFile();ae&&oe.push(ae)}oe.length>0&&(C.preventDefault(),b(oe))}return(C,R)=>(h(),g("div",{class:"relative border-t border-border-default bg-surface-raised px-4 py-3",onDragover:Ce,onDragleave:T,onDrop:u},[d.value?(h(),g("div",Fo,[...R[2]||(R[2]=[r("span",{class:"text-sm text-accent"},"Drop files to attach",-1)])])):A("",!0),r("div",Oo,[G(Ao,{ref_key:"dropdownRef",ref:i,filter:$.value,visible:z.value,onSelect:J,onClose:ce},null,8,["filter","visible"])]),r("input",{ref_key:"fileInputRef",ref:c,type:"file",multiple:"",accept:x(wo),class:"hidden",onChange:$e},null,40,Vo),r("div",Uo,[G(Lo,{attachments:x(p),onRemove:x(k)},null,8,["attachments","onRemove"]),r("div",{class:D(["flex items-end gap-2 p-1.5",{"pt-0":x(p).length>0}])},[r("button",{disabled:s.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:s.isVisionModel?"Attach files or images":"Attach files",onClick:me},[R[4]||(R[4]=r("svg",{class:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})],-1)),s.isVisionModel?(h(),g("span",Ho,[...R[3]||(R[3]=[r("svg",{class:"h-2.5 w-2.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"3"},[r("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),r("circle",{cx:"12",cy:"12",r:"3"})],-1)])])):A("",!0)],8,qo),r("button",{disabled:s.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:"Commands",onClick:X},[...R[5]||(R[5]=[r("svg",{class:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round"},[r("line",{x1:"17",y1:"4",x2:"7",y2:"20"})],-1)])],8,Go),U(r("textarea",{ref_key:"textareaRef",ref:a,"onUpdate:modelValue":R[0]||(R[0]=oe=>l.value=oe),disabled:s.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:s.isVisionModel?"Send a message or paste/drop an image...":"Send a message... (Shift+Enter for new line)",onKeydown:V,onInput:K,onPaste:y},null,40,Wo),[[Z,l.value]]),s.isStreaming?(h(),g("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:"Stop generating",onClick:R[1]||(R[1]=oe=>C.$emit("cancel"))},[...R[6]||(R[6]=[r("span",{class:"inline-block h-2.5 w-2.5 rounded-sm bg-white"},null,-1)])])):(h(),g("button",{key:1,disabled:!I.value||!s.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:"Send message",onClick:q},[...R[7]||(R[7]=[r("svg",{class:"h-4 w-4",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})],-1)])],8,Ko))],2)])],32))}}),Qo={class:"flex h-full flex-col overflow-y-auto"},Jo={class:"space-y-5 p-4 pb-12"},Xo={class:"flex items-center justify-between"},Yo={class:"flex items-center gap-2"},er=["disabled"],tr={key:0,class:"text-[10px] text-text-muted -mt-3"},sr={key:1,class:"text-[10px] text-text-muted -mt-3"},nr={class:"mb-1.5 flex items-center justify-between"},or={class:"text-xs text-text-muted"},rr={class:"mb-1.5 flex items-center justify-between"},ar={class:"text-xs text-text-muted"},lr={class:"mb-1.5 flex items-center justify-between"},ir={class:"text-xs text-text-muted"},cr={key:2,class:"space-y-4 pl-1"},ur={class:"mb-1.5 flex items-center justify-between"},dr={class:"text-xs text-text-muted"},pr={class:"mb-1.5 flex items-center justify-between"},mr={class:"text-xs text-text-muted"},hr={class:"mb-1.5 flex items-center justify-between"},gr={class:"text-xs text-text-muted"},fr={class:"mb-1.5 flex items-center justify-between"},xr={class:"text-xs text-text-muted"},vr={class:"mb-1.5 flex items-center justify-between"},br={class:"text-xs text-text-muted"},yr={key:0,class:"ml-1 text-accent"},kr={key:0,class:"pl-1 space-y-2"},wr={key:0,class:"space-y-1"},Sr=["onClick"],$r={key:1,class:"text-[10px] text-text-muted px-2"},Cr={key:0,class:"ml-1 text-accent"},Tr={key:4,class:"space-y-4 pl-1"},_r={class:"flex items-center justify-between"},Mr={key:0},Rr={class:"mb-1 flex items-center justify-between"},Ar={class:"text-[10px] text-text-muted"},Nr={class:"flex items-center justify-between"},zr={key:1},Er={class:"mb-1 flex items-center justify-between"},Ir={class:"text-[10px] text-text-muted"},Pr={class:"flex items-center justify-between"},Dr={key:2,class:"space-y-1"},Br={class:"flex-1 text-text-secondary"},jr=["onClick"],Lr={class:"flex items-center justify-between"},Fr={key:3,class:"space-y-2"},Or=["value"],Vr={key:0,class:"rounded-lg border border-accent/20 bg-accent/5 p-2"},Ur={class:"space-y-1.5"},qr={class:"min-w-0 flex-1"},Hr={class:"truncate text-[11px] font-mono text-text-primary"},Gr={class:"text-[9px] text-text-muted"},Wr=["disabled","onClick"],Kr={key:0,class:"mt-2 text-[9px] text-text-muted"},Zr={class:"mb-1 flex items-center justify-between"},Qr={class:"text-[10px] text-text-muted"},Jr=te({__name:"ChatSettingsPanel",props:{modelValue:{},selectedModel:{},ragEnabled:{type:Boolean}},emits:["update:modelValue","update:ragEnabled"],setup(s,{emit:e}){const t=s,o=e,n=M(t.modelValue.systemPrompt),l=M(t.modelValue.options.temperature??.7),a=M(t.modelValue.options.num_predict??-1),c=M(t.modelValue.options.num_ctx??4096),i=M(t.modelValue.options.top_p??.9),d=M(t.modelValue.options.top_k??40),p=M(t.modelValue.options.repeat_penalty??1.1),m=M(t.modelValue.options.seed??-1),b=M(t.modelValue.options.stop?.join(", ")??""),k=M(t.modelValue.options.mirostat??0);ee(()=>t.modelValue.options,T=>{l.value=T.temperature??.7,a.value=T.num_predict??-1,c.value=T.num_ctx??4096,i.value=T.top_p??.9,d.value=T.top_k??40,p.value=T.repeat_penalty??1.1,m.value=T.seed??-1,b.value=T.stop?.join(", ")??"",k.value=T.mirostat??0},{deep:!0}),ee([n,l,a,c,i,d,p,m,b,k],()=>{const T=b.value.split(",").map(u=>u.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:d.value,repeat_penalty:p.value,seed:m.value===-1?void 0:m.value,stop:T.length>0?T:void 0,mirostat:k.value}})},{deep:!0}),ee(()=>t.modelValue,T=>{n.value=T.systemPrompt,l.value=T.options.temperature??.7,a.value=T.options.num_predict??-1,c.value=T.options.num_ctx??4096,i.value=T.options.top_p??.9,d.value=T.options.top_k??40,p.value=T.options.repeat_penalty??1.1,m.value=T.options.seed??-1,k.value=T.options.mirostat??0});const f=st(),z=Pt(),$=Vt(),I=tt(),L=Lt(),V=j(()=>I.supportsTools(t.selectedModel));ee(()=>t.selectedModel,T=>{T&&!I.supportsTools(T)&&f.enabledTools.length>0&&f.disableAll()});const J=M(!1),q=M(!1),K=M(!1),ce=M(!1),X=M(""),me=M(""),$e=[{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 Ce(T){ce.value=!0,me.value=T,X.value="Starting download...";try{await ze.pullModel(T,(u,y,C)=>{if(y&&C){const R=Math.round(y/C*100);X.value=`${u} ${R}%`}else X.value=u}),X.value="Done!",await I.fetchModels(),$.settings.ragMemory.embeddingModel=T}catch(u){X.value=`Failed: ${u instanceof Error?u.message:"Unknown error"}`}finally{ce.value=!1,setTimeout(()=>{X.value="",me.value=""},3e3)}}return(T,u)=>(h(),g("div",Qo,[r("div",Jo,[r("div",null,[u[25]||(u[25]=r("label",{class:"mb-1.5 block text-xs font-medium text-text-secondary"},"System Prompt",-1)),U(r("textarea",{"onUpdate:modelValue":u[0]||(u[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:"You are a helpful assistant..."},null,512),[[Z,n.value]]),u[26]||(u[26]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Instructions sent before the conversation. Sets the model's behavior and persona. ",-1))]),r("div",Xo,[r("div",Yo,[u[27]||(u[27]=r("span",{class:"text-xs font-medium text-text-secondary"},"Knowledge Base",-1)),r("span",{class:D(["rounded-full px-1.5 py-0.5 text-[9px] font-medium",s.ragEnabled&&x(L).readyDocuments.length>0?"bg-accent/10 text-accent":"bg-surface-overlay text-text-muted"])},S(s.ragEnabled&&x(L).readyDocuments.length>0?"KB Enabled":"KB Disabled"),3)]),r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",s.ragEnabled&&x(L).readyDocuments.length>0?"bg-accent":"bg-surface-overlay"]),disabled:x(L).readyDocuments.length===0,onClick:u[1]||(u[1]=y=>o("update:ragEnabled",!s.ragEnabled))},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",s.ragEnabled&&x(L).readyDocuments.length>0?"translate-x-3.5":"translate-x-0.5"])},null,2)],10,er)]),x(L).readyDocuments.length>0?(h(),g("p",tr,[Se(S(x(L).enabledDocuments.length)+"/"+S(x(L).readyDocuments.length)+" documents · ",1),r("button",{class:"text-accent hover:underline",onClick:u[2]||(u[2]=y=>x(z).push("/rag"))},"Manage")])):(h(),g("p",sr,[u[28]||(u[28]=Se(" No documents ingested · ",-1)),r("button",{class:"text-accent hover:underline",onClick:u[3]||(u[3]=y=>x(z).push("/rag"))},"Add documents")])),r("div",null,[r("div",nr,[u[29]||(u[29]=r("label",{class:"text-xs font-medium text-text-secondary"},"Temperature",-1)),r("span",or,S(l.value.toFixed(2)),1)]),U(r("input",{"onUpdate:modelValue":u[4]||(u[4]=y=>l.value=y),type:"range",min:"0",max:"2",step:"0.05",class:"w-full accent-accent"},null,512),[[Z,l.value,void 0,{number:!0}]]),u[30]||(u[30]=r("div",{class:"mt-0.5 flex justify-between text-[10px] text-text-muted"},[r("span",null,"Precise"),r("span",null,"Creative")],-1))]),r("div",null,[r("div",rr,[u[31]||(u[31]=r("label",{class:"text-xs font-medium text-text-secondary"},"Max Tokens",-1)),r("span",ar,S(a.value===-1?"Unlimited":a.value),1)]),U(r("input",{"onUpdate:modelValue":u[5]||(u[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:"-1 for unlimited"},null,512),[[Z,a.value,void 0,{number:!0}]]),u[32]||(u[32]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Maximum response length. -1 = unlimited. ",-1))]),r("div",null,[r("div",lr,[u[33]||(u[33]=r("label",{class:"text-xs font-medium text-text-secondary"},"Context Window",-1)),r("span",ir,S(c.value.toLocaleString()),1)]),U(r("select",{"onUpdate:modelValue":u[6]||(u[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"},[...u[34]||(u[34]=[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),[[Ke,c.value,void 0,{number:!0}]]),u[35]||(u[35]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Total context the model can see. Higher = more memory, slower. ",-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:u[7]||(u[7]=y=>J.value=!J.value)},[u[36]||(u[36]=r("span",null,"Advanced Sampling",-1)),r("span",{class:D(["transition-transform",{"rotate-180":J.value}])},"▾",2)]),J.value?(h(),g("div",cr,[r("div",null,[r("div",ur,[u[37]||(u[37]=r("label",{class:"text-xs font-medium text-text-secondary"},"Top-P",-1)),r("span",dr,S(i.value.toFixed(2)),1)]),U(r("input",{"onUpdate:modelValue":u[8]||(u[8]=y=>i.value=y),type:"range",min:"0",max:"1",step:"0.05",class:"w-full accent-accent"},null,512),[[Z,i.value,void 0,{number:!0}]]),u[38]||(u[38]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Nucleus sampling. Lower = more focused on likely tokens. ",-1))]),r("div",null,[r("div",pr,[u[39]||(u[39]=r("label",{class:"text-xs font-medium text-text-secondary"},"Top-K",-1)),r("span",mr,S(d.value),1)]),U(r("input",{"onUpdate:modelValue":u[9]||(u[9]=y=>d.value=y),type:"range",min:"1",max:"100",step:"1",class:"w-full accent-accent"},null,512),[[Z,d.value,void 0,{number:!0}]]),u[40]||(u[40]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Limits sampling to the top K tokens at each step. ",-1))]),r("div",null,[r("div",hr,[u[41]||(u[41]=r("label",{class:"text-xs font-medium text-text-secondary"},"Repeat Penalty",-1)),r("span",gr,S(p.value.toFixed(2)),1)]),U(r("input",{"onUpdate:modelValue":u[10]||(u[10]=y=>p.value=y),type:"range",min:"1.0",max:"2.0",step:"0.05",class:"w-full accent-accent"},null,512),[[Z,p.value,void 0,{number:!0}]]),u[42]||(u[42]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Penalizes tokens that already appeared. Higher = less repetition. ",-1))]),r("div",null,[r("div",fr,[u[43]||(u[43]=r("label",{class:"text-xs font-medium text-text-secondary"},"Mirostat",-1)),r("span",xr,S(k.value===0?"Off":`v${k.value}`),1)]),U(r("select",{"onUpdate:modelValue":u[11]||(u[11]=y=>k.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"},[...u[44]||(u[44]=[r("option",{value:0},"Disabled",-1),r("option",{value:1},"Mirostat v1",-1),r("option",{value:2},"Mirostat v2",-1)])],512),[[Ke,k.value,void 0,{number:!0}]]),u[45]||(u[45]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Adaptive perplexity-based sampling. Overrides top-p/top-k when enabled. ",-1))]),r("div",null,[r("div",vr,[u[46]||(u[46]=r("label",{class:"text-xs font-medium text-text-secondary"},"Seed",-1)),r("span",br,S(m.value===-1?"Random":m.value),1)]),U(r("input",{"onUpdate:modelValue":u[12]||(u[12]=y=>m.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:"-1 for random"},null,512),[[Z,m.value,void 0,{number:!0}]]),u[47]||(u[47]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Fixed seed for reproducible outputs. -1 = random. ",-1))]),r("div",null,[u[48]||(u[48]=r("label",{class:"mb-1.5 block text-xs font-medium text-text-secondary"},"Stop Sequences",-1)),U(r("input",{"onUpdate:modelValue":u[13]||(u[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:"e.g. Human:, \\n\\n"},null,512),[[Z,b.value]]),u[49]||(u[49]=r("p",{class:"mt-1 text-[10px] text-text-muted"}," Comma-separated strings that stop generation when produced. ",-1))])])):A("",!0),V.value?(h(),g(O,{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:u[14]||(u[14]=y=>q.value=!q.value)},[r("span",null,[u[50]||(u[50]=Se(" Tools ",-1)),x(f).enabledDefinitions.length>0?(h(),g("span",yr," ("+S(x(f).enabledDefinitions.length)+" active) ",1)):A("",!0)]),r("span",{class:D(["transition-transform",{"rotate-180":q.value}])},"▾",2)]),q.value?(h(),g("div",kr,[x(f).allTools.length>0?(h(),g("div",wr,[(h(!0),g(O,null,Q(x(f).allTools,y=>(h(),g("div",{key:y.id,class:"flex items-center gap-2 rounded-md bg-surface px-2 py-1.5 text-[11px]"},[r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",y.enabled?"bg-accent":"bg-surface-overlay"]),onClick:C=>x(f).toggleEnabled(y.id)},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",y.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],10,Sr),r("span",{class:D(["font-mono",y.enabled?"text-text-primary":"text-text-muted"])},S(y.definition.function.name),3)]))),128))])):(h(),g("p",$r,"No tools defined yet")),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:u[15]||(u[15]=y=>x(z).push("/tools"))}," Manage in Tool Workshop... ")])):A("",!0)],64)):A("",!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:u[16]||(u[16]=y=>K.value=!K.value)},[r("span",null,[u[51]||(u[51]=Se(" Memory ",-1)),x($).factCount>0?(h(),g("span",Cr," ("+S(x($).factCount)+" facts) ",1)):A("",!0)]),r("span",{class:D(["transition-transform",{"rotate-180":K.value}])},"▾",2)]),K.value?(h(),g("div",Tr,[r("div",_r,[u[52]||(u[52]=r("div",null,[r("p",{class:"text-xs font-medium text-text-secondary"},"Sliding Window"),r("p",{class:"text-[10px] text-text-muted"},"Keep only the last N messages")],-1)),r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",x($).settings.slidingWindow.enabled?"bg-accent":"bg-surface-overlay"]),onClick:u[17]||(u[17]=y=>x($).settings.slidingWindow.enabled=!x($).settings.slidingWindow.enabled)},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",x($).settings.slidingWindow.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),x($).settings.slidingWindow.enabled?(h(),g("div",Mr,[r("div",Rr,[u[53]||(u[53]=r("label",{class:"text-[10px] text-text-muted"},"Max messages",-1)),r("span",Ar,S(x($).settings.slidingWindow.maxMessages),1)]),U(r("input",{"onUpdate:modelValue":u[18]||(u[18]=y=>x($).settings.slidingWindow.maxMessages=y),type:"range",min:"10",max:"200",step:"10",class:"w-full accent-accent"},null,512),[[Z,x($).settings.slidingWindow.maxMessages,void 0,{number:!0}]])])):A("",!0),r("div",Nr,[u[54]||(u[54]=r("div",null,[r("p",{class:"text-xs font-medium text-text-secondary"},"Auto-Summarize"),r("p",{class:"text-[10px] text-text-muted"},"Summarize older messages automatically")],-1)),r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",x($).settings.autoSummarize.enabled?"bg-accent":"bg-surface-overlay"]),onClick:u[19]||(u[19]=y=>x($).settings.autoSummarize.enabled=!x($).settings.autoSummarize.enabled)},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",x($).settings.autoSummarize.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),x($).settings.autoSummarize.enabled?(h(),g("div",zr,[r("div",Er,[u[55]||(u[55]=r("label",{class:"text-[10px] text-text-muted"},"Trigger after",-1)),r("span",Ir,S(x($).settings.autoSummarize.triggerThreshold)+" messages",1)]),U(r("input",{"onUpdate:modelValue":u[20]||(u[20]=y=>x($).settings.autoSummarize.triggerThreshold=y),type:"range",min:"10",max:"100",step:"5",class:"w-full accent-accent"},null,512),[[Z,x($).settings.autoSummarize.triggerThreshold,void 0,{number:!0}]])])):A("",!0),r("div",Pr,[u[56]||(u[56]=r("div",null,[r("p",{class:"text-xs font-medium text-text-secondary"},"User Memories"),r("p",{class:"text-[10px] text-text-muted"},"/remember facts injected into context")],-1)),r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",x($).settings.userFacts.enabled?"bg-accent":"bg-surface-overlay"]),onClick:u[21]||(u[21]=y=>x($).settings.userFacts.enabled=!x($).settings.userFacts.enabled)},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",x($).settings.userFacts.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),x($).settings.userFacts.enabled&&x($).facts.length>0?(h(),g("div",Dr,[(h(!0),g(O,null,Q(x($).facts,y=>(h(),g("div",{key:y.id,class:"flex items-center gap-2 rounded-md bg-surface px-2 py-1 text-[11px]"},[r("span",Br,S(y.content),1),r("button",{class:"shrink-0 text-text-muted hover:text-error transition-colors",onClick:C=>x($).removeFact(y.id)},[...u[57]||(u[57]=[r("svg",{class:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])],8,jr)]))),128))])):A("",!0),r("div",Lr,[u[58]||(u[58]=r("div",null,[r("p",{class:"text-xs font-medium text-text-secondary"},"Message Memory (RAG)"),r("p",{class:"text-[10px] text-text-muted"},"Retrieve relevant past messages via embeddings")],-1)),r("button",{class:D(["h-4 w-7 shrink-0 rounded-full transition-colors",x($).settings.ragMemory.enabled?"bg-accent":"bg-surface-overlay"]),onClick:u[22]||(u[22]=y=>x($).settings.ragMemory.enabled=!x($).settings.ragMemory.enabled)},[r("span",{class:D(["block h-3 w-3 rounded-full bg-white transition-transform",x($).settings.ragMemory.enabled?"translate-x-3.5":"translate-x-0.5"])},null,2)],2)]),x($).settings.ragMemory.enabled?(h(),g("div",Fr,[r("div",null,[u[60]||(u[60]=r("label",{class:"mb-1 block text-[10px] text-text-muted"},"Embedding Model",-1)),U(r("select",{"onUpdate:modelValue":u[23]||(u[23]=y=>x($).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"},[u[59]||(u[59]=r("option",{value:"",disabled:""},"Select embedding model...",-1)),(h(!0),g(O,null,Q(x(I).embeddingModelNames,y=>(h(),g("option",{key:y,value:y},S(y)+" "+S(x(I).capabilityIcons(y)),9,Or))),128))],512),[[Ke,x($).settings.ragMemory.embeddingModel]])]),x(I).embeddingModelNames.length===0?(h(),g("div",Vr,[u[61]||(u[61]=r("p",{class:"mb-2 text-[10px] text-accent"},"No embedding models found. Pull one:",-1)),r("div",Ur,[(h(),g(O,null,Q($e,y=>r("div",{key:y.name,class:"flex items-center gap-2"},[r("div",qr,[r("p",Hr,S(y.name),1),r("p",Gr,S(y.description)+" ("+S(y.size)+")",1)]),r("button",{disabled:ce.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:C=>Ce(y.name)},S(ce.value&&me.value===y.name?"Pulling...":"Pull"),9,Wr)])),64))]),X.value?(h(),g("p",Kr,S(X.value),1)):A("",!0)])):A("",!0),r("div",null,[r("div",Zr,[u[62]||(u[62]=r("label",{class:"text-[10px] text-text-muted"},"Retrieve top",-1)),r("span",Qr,S(x($).settings.ragMemory.topK)+" messages",1)]),U(r("input",{"onUpdate:modelValue":u[24]||(u[24]=y=>x($).settings.ragMemory.topK=y),type:"range",min:"1",max:"10",step:"1",class:"w-full accent-accent"},null,512),[[Z,x($).settings.ragMemory.topK,void 0,{number:!0}]])])])):A("",!0)])):A("",!0)])]))}}),Xr={class:"flex h-full flex-col"},Yr={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"},ea={class:"flex items-start gap-3"},ta={class:"max-w-md whitespace-pre-wrap text-sm text-text-primary"},sa={class:"flex items-center justify-between border-b border-border-default bg-surface-raised px-4 py-2"},na={class:"flex items-center gap-3"},oa={class:"relative"},ra={key:0,class:"text-text-muted"},aa={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"},la=["onMousedown"],ia={key:0,class:"flex items-center"},ca={class:"truncate"},ua={class:"flex items-center gap-2"},da={class:"flex flex-1 min-h-0"},pa={key:0,class:"w-64 shrink-0 border-r border-border-default bg-surface-raised flex flex-col"},ma={class:"flex items-center justify-between border-b border-border-default px-4 py-2"},ha={class:"flex-1 overflow-y-auto p-2"},ga={key:0,class:"px-2 py-4 text-[10px] text-text-muted italic text-center"},fa={key:1,class:"space-y-0.5"},xa=["onClick"],va={key:0,class:"flex-1 min-w-0"},ba=["onBlur","onKeydown"],ya={class:"flex-1 min-w-0"},ka={class:"truncate text-[11px]"},wa={class:"truncate text-[9px] text-text-muted"},Sa={class:"hidden shrink-0 items-center gap-0.5 group-hover:flex"},$a=["onClick"],Ca=["onClick"],Ta={class:"flex flex-1 flex-col min-w-0"},_a={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"},Ma={key:1,class:"w-72 shrink-0 border-l border-border-default bg-surface-raised"},Ra={class:"flex items-center justify-between border-b border-border-default px-4 py-2"},Aa=te({__name:"ChatConversation",setup(s){const e=Pt(),t=Dt(),o=tt(),n=He(),l=Lt(),a=et(),c=st(),i=Vt(),d=jt(),{isStreaming:p,currentSessionId:m,startChatStream:b,cancel:k}=Ks(),f=M(""),z=M(!1);function $(){setTimeout(()=>{z.value=!1},150)}const I=M(!0),L=M(!1),V=M(!1),J=M(null),q=M("");function K(_){t.setActiveConversation(_)}function ce(_,v){J.value=_,q.value=v}function X(_){const v=q.value.trim();v&&t.renameConversation(_,v),J.value=null}function me(){J.value=null}function $e(_,v){_.key==="Enter"?X(v):_.key==="Escape"&&me()}function Ce(_){const w=Date.now()-_,N=Math.floor(w/6e4);if(N<1)return"Just now";if(N<60)return`${N}m ago`;const E=Math.floor(N/60);if(E<24)return`${E}h ago`;const F=Math.floor(E/24);return F<7?`${F}d ago`:new Date(_).toLocaleDateString()}const T=M({systemPrompt:"",options:{}}),u=M(null);let y=null;const C=j(()=>t.activeConversation),R=j(()=>C.value?.messages??[]),oe=j(()=>o.isVisionModel(f.value)),he=j(()=>{const _=ae.value??m.value;if(!_)return null;const v=n.sessionById(_);return v?.status==="error"&&v.error?v.error:null}),ae=j(()=>{const _=R.value;for(let v=_.length-1;v>=0;v--)if(_[v].sessionId)return _[v].sessionId;return null}),ye=M("Untitled"),Te=M(!1),Ie=M(""),pt=j(()=>C.value?.name??ye.value);function os(){Ie.value=pt.value,Te.value=!0}function mt(){const _=Ie.value.trim();if(!_){Te.value=!1;return}C.value?t.renameConversation(C.value.id,_):ye.value=_,Te.value=!1}function rs(){Te.value=!1}function as(_){_.key==="Enter"?mt():_.key==="Escape"&&rs()}It(async()=>{await o.fetchModels(),o.chatModelNames.length>0&&!f.value&&(f.value=o.chatModelNames[0]),await l.loadDocuments()}),ee(f,_=>{if(!_)return;const v=o.getModelDefaults(_);Object.keys(v).length>0&&(T.value={systemPrompt:T.value.systemPrompt,options:{...v}})}),ee(()=>t.activeConversationId,async _=>{if(!_)return;const v=t.conversations.get(_);if(v){v.model&&o.chatModelNames.includes(v.model)&&(f.value=v.model);try{const w=await $s.getSessionsByConversation(_);for(const N of w)n.sessionById(N.id)||(n.sessions.set(N.id,{id:N.id,mode:N.mode,model:N.model,status:N.status,createdAt:N.createdAt,prompt:N.prompt,messages:N.messages,options:N.options,outputText:N.outputText,metrics:N.metrics,error:N.error,doneReason:N.doneReason}),n.linkSessionToConversation(N.id,_)),await d.loadTokens(N.id)}catch(w){console.error("Failed to restore sessions for conversation:",w)}}});async function ht(_,v=[]){if(!f.value)return;let w=t.activeConversationId;w||(w=t.createConversation(f.value),ye.value!=="Untitled"&&t.renameConversation(w,ye.value),ye.value="Untitled");const N=t.conversations.get(w);N&&N.model!==f.value&&(N.model=f.value);const E=v.filter(H=>H.type==="document"&&H.content),F=v.filter(H=>H.type==="image"&&H.content);let ue=_;E.length>0&&(ue=E.map(Y=>`[Attached: ${Y.name}]
93
- ${Y.content}`).join(`
94
-
95
- `)+`
96
-
97
- ---
98
-
99
- `+_);const ke={id:pe(),conversationId:w,role:"user",content:ue,timestamp:Date.now(),isStreaming:!1,attachments:v.length>0?v:void 0};t.addMessage(w,ke);const fe=pe(),Pe={id:fe,conversationId:w,role:"assistant",content:"",timestamp:Date.now(),isStreaming:!0};t.addMessage(w,Pe);const le=t.getMessagesAsOllamaFormat(w).slice(0,-1);if(F.length>0){const H=[...le].reverse().find(Y=>Y.role==="user");H&&(H.images=F.map(Y=>Y.content.replace(/^data:[^;]+;base64,/,"")))}if(T.value.systemPrompt.trim()&&le.unshift({role:"system",content:T.value.systemPrompt.trim()}),I.value&&l.enabledDocuments.length>0)try{const H=await l.getContextForQuery(_,f.value,5);H&&le.unshift({role:"system",content:H})}catch{}let gt=le;try{const H=i.getSummary(w)?.summary,Y=await Js({conversationId:w,messages:le,model:f.value,settings:i.settings,userFactsPrompt:i.getFactsAsSystemPrompt(),existingSummary:H});if(gt=Y.messages,Y.newSummary){const de=le.filter(ft=>ft.role!=="system");i.setSummary(w,Y.newSummary,de.length)}}catch{}try{const H={...C.value?.options,...T.value.options},Y=c.enabledDefinitions,de=await b(f.value,gt,H,Y.length>0?Y:void 0),xt=t.conversations.get(w)?.messages.find(ie=>ie.id===fe);xt&&(xt.sessionId=de),n.linkSessionToConversation(de,w);const ms=ee(()=>n.sessionById(de)?.outputText,ie=>{ie!==void 0&&t.updateAssistantContent(w,fe,ie)}),vt=w,hs=_,gs=ee(()=>n.sessionById(de)?.status,ie=>{if((ie==="completed"||ie==="error"||ie==="cancelled")&&(t.finalizeMessage(vt,fe),p.value=!1,ms(),gs(),d.persistTokens(de),ie==="completed"&&i.settings.ragMemory.enabled&&i.settings.ragMemory.embeddingModel)){const fs=n.sessionById(de)?.outputText??"";Xs(vt,[{role:"user",content:hs,timestamp:ke.timestamp},{role:"assistant",content:fs,timestamp:Date.now()}],i.settings.ragMemory.embeddingModel).catch(()=>{})}})}catch{t.finalizeMessage(w,fe)}}function ls(){k()}function is(){t.setActiveConversation(null),ye.value="Untitled"}function cs(_){e.push({name:"session",params:{id:_}})}function ge(_){u.value=_,y&&clearTimeout(y),y=setTimeout(()=>{u.value=null},5e3)}function us(){u.value=null,y&&clearTimeout(y)}const ds={systemPrompt:"",options:{}};async function ps(_,v){const w=Qs(_);if(!w){ge(`Unknown command: /${_}. Type /help for available commands.`);return}const N={clearConversation:()=>t.setActiveConversation(null),newChat:()=>t.setActiveConversation(null),sendAsUser:E=>ht(E),copyLastResponse:()=>{const E=R.value.filter(ue=>ue.role==="assistant"),F=E[E.length-1];F?.content?(navigator.clipboard.writeText(F.content),ge("Copied to clipboard.")):ge("No assistant response to copy.")},exportConversation:E=>{const F=C.value;if(!F||F.messages.length===0){ge("No conversation to export.");return}let ue,ke;E==="json"?(ue=JSON.stringify(F.messages,null,2),ke=`chat-${F.id}.json`):(ue=F.messages.map(le=>`[${le.role}] ${le.content}`).join(`
100
-
101
- `),ke=`chat-${F.id}.txt`);const fe=new Blob([ue],{type:"text/plain"}),Pe=URL.createObjectURL(fe),De=document.createElement("a");De.href=Pe,De.download=ke,De.click(),URL.revokeObjectURL(Pe)},setSystemPrompt:E=>{T.value={...T.value,systemPrompt:E}},setOption:(E,F)=>{T.value={...T.value,options:{...T.value.options,[E]:F}}},resetSettings:()=>{T.value={...ds}},setJsonFormat:E=>{ge("JSON format toggled. This affects the next request.")},switchModel:E=>{f.value=E},availableModels:o.chatModelNames,currentModel:f.value,toggleRag:()=>{I.value=!I.value},ragEnabled:I.value,navigate:E=>e.push(E),openSettings:()=>{L.value=!0},openSessionDetails:()=>{const E=ae.value;E?e.push({name:"session",params:{id:E}}):ge("No active session.")},addFact:E=>i.addFact(E),removeFact:E=>i.removeFactByContent(E),getFacts:()=>i.facts,showNotification:ge,messages:R.value,chatSettings:T,currentSessionId:ae.value??m.value,getSessionTokenCount:()=>{const E=ae.value??m.value;if(!E)return null;const F=a.getMetrics(E);return F?{prompt:F.promptTokenCount,completion:F.completionTokenCount}:null},getAverageSpeed:()=>{const E=a.aggregate;return E.totalSessions>0?E.avgTps:null},getOllamaStatus:async()=>{try{return{connected:(await fetch("/api/tags")).ok,model:f.value}}catch{return{connected:!1,model:f.value}}}};await w.execute(v,N)}return(_,v)=>(h(),g("div",Xr,[G(zt,{"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:Et(()=>[u.value?(h(),g("div",Yr,[r("div",ea,[r("p",ta,S(u.value),1),r("button",{class:"shrink-0 text-text-muted hover:text-text-primary transition-colors text-xs",onClick:us}," ✕ ")])])):A("",!0)]),_:1}),r("div",sa,[r("div",na,[r("div",oa,[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:v[0]||(v[0]=w=>z.value=!z.value),onBlur:$},[f.value?(h(),g(O,{key:1},[r("span",null,S(f.value),1),G(bt,{"model-name":f.value},null,8,["model-name"])],64)):(h(),g("span",ra,"No models")),(h(),g("svg",{class:D(["h-3 w-3 text-text-muted transition-transform",z.value?"rotate-180":""]),viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[...v[12]||(v[12]=[r("path",{d:"M6 9l6 6 6-6"},null,-1)])],2))],32),z.value?(h(),g("div",aa,[(h(!0),g(O,null,Q(x(o).chatModelNames,w=>(h(),g("button",{key:w,class:D(["flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm transition-colors",w===f.value?"bg-accent/10 text-accent":"text-text-primary hover:bg-surface-overlay"]),onMousedown:Le(N=>{f.value=w,z.value=!1},["prevent"])},[r("span",null,S(w),1),G(bt,{"model-name":w},null,8,["model-name"])],42,la))),128))])):A("",!0)]),Te.value?(h(),g("div",ia,[U(r("input",{"onUpdate:modelValue":v[1]||(v[1]=w=>Ie.value=w),class:"w-48 rounded border border-accent bg-surface px-2 py-0.5 text-xs text-text-primary outline-none",onBlur:mt,onKeydown:as,onVnodeMounted:v[2]||(v[2]=w=>{w.el.focus(),w.el.select()})},null,544),[[Z,Ie.value]])])):(h(),g("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:"Click to rename",onClick:os},[r("span",ca,S(pt.value),1),v[13]||(v[13]=r("svg",{class:"h-2.5 w-2.5 shrink-0 opacity-0 group-hover:opacity-100",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"})],-1))]))]),r("div",ua,[ae.value?(h(),g("button",{key:0,class:"rounded-lg px-3 py-1.5 text-xs text-accent hover:bg-surface-overlay transition-colors",onClick:v[3]||(v[3]=w=>cs(ae.value))}," View session details ")):A("",!0),r("button",{class:D(["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:v[4]||(v[4]=w=>V.value=!V.value)},[...v[14]||(v[14]=[r("svg",{class:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M12 8v4l3 3"}),r("circle",{cx:"12",cy:"12",r:"10"})],-1),r("span",null,"History",-1)])],2),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:is}," + New Chat "),r("button",{class:D(["flex items-center gap-1 rounded-lg px-3 py-1.5 text-xs transition-colors",L.value?"bg-accent/10 text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:v[5]||(v[5]=w=>L.value=!L.value)},[...v[15]||(v[15]=[r("svg",{class:"h-3.5 w-3.5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}),r("circle",{cx:"12",cy:"12",r:"3"})],-1),r("span",null,"Settings",-1)])],2)])]),r("div",da,[V.value?(h(),g("div",pa,[r("div",ma,[v[16]||(v[16]=r("span",{class:"text-xs font-medium text-text-secondary"},"Chat History",-1)),r("button",{class:"text-text-muted hover:text-text-primary transition-colors text-xs",onClick:v[6]||(v[6]=w=>V.value=!1)}," ✕ ")]),r("div",ha,[x(t).recentConversations.length===0?(h(),g("p",ga," No conversations yet. ")):(h(),g("div",fa,[(h(!0),g(O,null,Q(x(t).recentConversations,w=>(h(),g("div",{key:w.id,class:D(["group flex items-center gap-1 rounded-lg px-2.5 py-2 text-xs transition-colors cursor-pointer",w.id===x(t).activeConversationId?"bg-surface-overlay text-accent":"text-text-secondary hover:bg-surface-overlay hover:text-text-primary"]),onClick:N=>K(w.id)},[J.value===w.id?(h(),g("div",va,[U(r("input",{"onUpdate:modelValue":v[7]||(v[7]=N=>q.value=N),class:"w-full rounded bg-surface px-1.5 py-0.5 text-xs text-text-primary outline-none border border-accent",onBlur:N=>X(w.id),onKeydown:N=>$e(N,w.id),onVnodeMounted:v[8]||(v[8]=N=>{N.el.focus(),N.el.select()})},null,40,ba),[[Z,q.value]])])):(h(),g(O,{key:1},[r("div",ya,[r("p",ka,S(w.name),1),r("p",wa,S(w.model)+" · "+S(Ce(w.updatedAt)),1)]),r("div",Sa,[r("button",{class:"rounded p-0.5 text-text-muted hover:text-text-primary transition-colors",title:"Rename",onClick:Le(N=>ce(w.id,w.name),["stop"])},[...v[17]||(v[17]=[r("svg",{class:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("path",{d:"M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z"})],-1)])],8,$a),r("button",{class:"rounded p-0.5 text-text-muted hover:text-error transition-colors",title:"Delete",onClick:Le(N=>x(t).deleteConversation(w.id),["stop"])},[...v[18]||(v[18]=[r("svg",{class:"h-3 w-3",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[r("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r("line",{x1:"6",y1:"6",x2:"18",y2:"18"})],-1)])],8,Ca)])],64))],10,xa))),128))]))])])):A("",!0),r("div",Ta,[he.value?(h(),g("div",_a,[v[19]||(v[19]=r("span",{class:"font-medium"},"Error:",-1)),Se(" "+S(he.value),1)])):A("",!0),G(vo,{messages:R.value},null,8,["messages"]),G(Zo,{"is-streaming":x(p),"selected-model":f.value,"is-vision-model":oe.value,onSend:ht,onCommand:ps,onCancel:ls},null,8,["is-streaming","selected-model","is-vision-model"])]),L.value?(h(),g("div",Ma,[r("div",Ra,[v[20]||(v[20]=r("span",{class:"text-xs font-medium text-text-secondary"},"Chat Settings",-1)),r("button",{class:"text-text-muted hover:text-text-primary transition-colors text-xs",onClick:v[9]||(v[9]=w=>L.value=!1)}," ✕ ")]),G(Jr,{modelValue:T.value,"onUpdate:modelValue":v[10]||(v[10]=w=>T.value=w),"selected-model":f.value,"rag-enabled":I.value,"onUpdate:ragEnabled":v[11]||(v[11]=w=>I.value=w)},null,8,["modelValue","selected-model","rag-enabled"])])):A("",!0)])]))}}),Na={class:"rounded-lg border border-border-default bg-surface-raised"},za={class:"overflow-x-auto"},Ea={class:"w-full text-sm"},Ia=["onClick"],Pa={class:"px-4 py-2 font-medium text-text-primary"},Da={class:"px-4 py-2"},Ba={class:"px-4 py-2 text-text-secondary"},ja={class:"px-4 py-2 text-text-secondary"},La={class:"px-4 py-2 text-text-secondary"},Fa={class:"px-4 py-2 text-text-muted"},Oa={key:0},Va=te({__name:"SessionHistoryTable",setup(s){const e=He();return(t,o)=>(h(),g("div",Na,[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",za,[r("table",Ea,[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,[(h(!0),g(O,null,Q(x(e).recentSessions.slice(0,20),n=>(h(),g("tr",{key:n.id,class:"border-b border-border-default last:border-0 hover:bg-surface-overlay cursor-pointer transition-colors",onClick:l=>t.$router.push({name:"session",params:{id:n.id}})},[r("td",Pa,S(n.model),1),r("td",Da,[G(Ns,{status:n.status,detail:n.error},null,8,["status","detail"])]),r("td",Ba,S(n.metrics?n.metrics.totalTokenCount:"—"),1),r("td",ja,S(n.metrics?x(Fe)(n.metrics.tokensPerSecond):"—"),1),r("td",La,S(n.metrics?x(Bt)(n.metrics.totalDurationMs):"—"),1),r("td",Fa,S(x(Cs)(n.createdAt)),1)],8,Ia))),128)),x(e).recentSessions.length===0?(h(),g("tr",Oa,[...o[0]||(o[0]=[r("td",{colspan:"6",class:"px-4 py-8 text-center text-text-muted"},"No sessions yet",-1)])])):A("",!0)])])])]))}}),Ua={class:"flex h-full flex-col"},qa={class:"flex-1 min-h-0"},Ha={key:0,class:"border-t border-border-default"},Ga={key:0,class:"max-h-80 overflow-auto px-4 pb-4 space-y-4"},Wa={class:"grid grid-cols-2 gap-3 lg:grid-cols-4"},Ka={key:1,class:"border-t border-border-default px-4 py-2"},Za={class:"flex gap-2 overflow-x-auto pb-1"},Qa=["onClick"],ul=te({__name:"DashboardPage",setup(s){const e=et(),t=Dt(),o=M(!1),n=j(()=>e.aggregate),l=j(()=>n.value.totalSessions>0),a=j(()=>t.recentConversations);return(c,i)=>(h(),g("div",Ua,[r("div",qa,[G(Aa)]),l.value?(h(),g("div",Ha,[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]=d=>o.value=!o.value)},[r("span",null,S(n.value.totalSessions)+" sessions · Avg "+S(x(Fe)(n.value.avgTps)),1),r("span",{class:D(["transition-transform",{"rotate-180":o.value}])},"▾",2)]),o.value?(h(),g("div",Ga,[r("div",Wa,[G(Be,{label:"Total Sessions",value:n.value.totalSessions},null,8,["value"]),G(Be,{label:"Avg TTFT",value:x(Bt)(n.value.avgTtftMs)},null,8,["value"]),G(Be,{label:"Avg Speed",value:x(Fe)(n.value.avgTps)},null,8,["value"]),G(Be,{label:"Total Tokens",value:x(we)(n.value.totalTokensGenerated),unit:"tok"},null,8,["value"])]),G(Va)])):A("",!0)])):A("",!0),a.value.length>1?(h(),g("div",Ka,[i[1]||(i[1]=r("p",{class:"text-[10px] uppercase tracking-wider text-text-muted mb-1"},"Recent Chats",-1)),r("div",Za,[(h(!0),g(O,null,Q(a.value.slice(0,5),d=>(h(),g("button",{key:d.id,class:D(["shrink-0 rounded-lg px-3 py-1.5 text-xs transition-colors",x(t).activeConversationId===d.id?"bg-accent/10 text-accent":"bg-surface-overlay text-text-secondary hover:text-text-primary"]),onClick:p=>x(t).setActiveConversation(d.id)},S(d.name),11,Qa))),128))])])):A("",!0)]))}});export{ul as default};
@@ -1 +0,0 @@
1
- .fade-enter-active[data-v-51d9d185],.fade-leave-active[data-v-51d9d185]{transition:opacity .3s ease}.fade-enter-from[data-v-51d9d185],.fade-leave-to[data-v-51d9d185]{opacity:0}
@@ -1 +0,0 @@
1
- import{d as le,r as _,c as N,o as ae,n as ne,a as U,b as o,e as a,g as Y,f as e,A as oe,w as Q,t as r,i as z,k as H,x as ie,F as B,j as L,L as re,p as F,q as Z,s as G,h as j,y as ee,z as de,B as W,E as J,u as S,m as ue,C as X,M as ce,v as te}from"./index-BqB3FY2M.js";import{c as I}from"./format-BqVZ9rwM.js";import{u as me}from"./storage-store-B1XevdC4.js";import{_ as ve}from"./StorageGauge.vue_vue_type_style_index_0_lang-hO4dId5t.js";import{_ as xe}from"./_plugin-vue_export-helper-DlAUqK2U.js";const pe=le("embeddings",()=>{const y=_([]),n=_(!1),s=_(null),b=N(()=>[...y.value].sort((u,m)=>m.timestamp-u.timestamp));async function v(u,m){n.value=!0,s.value=null;const f=Date.now();try{const w=(await ae.embed({model:u,input:m})).embeddings[0];if(!w)throw new Error("No embedding returned");const x={id:ne(),model:u,input:m,vector:w,dimensions:w.length,timestamp:Date.now(),durationMs:Date.now()-f};return y.value.push(x),x}catch(M){throw s.value=M instanceof Error?M.message:"Embedding failed",M}finally{n.value=!1}}function g(u,m){if(u.length!==m.length)return 0;let f=0,M=0,w=0;for(let d=0;d<u.length;d++)f+=u[d]*m[d],M+=u[d]*u[d],w+=m[d]*m[d];const x=Math.sqrt(M)*Math.sqrt(w);return x===0?0:f/x}function h(u,m){return{score:g(u.vector,m.vector),a:u,b:m}}function R(){y.value=[]}function T(u){y.value=y.value.filter(m=>m.id!==u)}return{results:y,recentResults:b,loading:n,error:s,embed:v,cosineSimilarity:g,comparePair:h,clearResults:R,removeResult:T}}),O=U({__name:"LoadingSpinner",props:{size:{}},setup(y){return(n,s)=>(o(),a("div",{class:Y(["inline-block animate-spin rounded-full border-2 border-current border-t-transparent text-accent",{"h-4 w-4":y.size==="sm"||!y.size,"h-6 w-6":y.size==="md","h-8 w-8":y.size==="lg"}]),role:"status"},[...s[0]||(s[0]=[e("span",{class:"sr-only"},"Loading...",-1)])],2))}}),fe={class:"space-y-1"},be={key:0,class:"text-xs text-text-muted"},ge=["height"],he={class:"text-text-muted"},ye={class:"flex items-center justify-between text-[10px] text-text-muted"},K=U({__name:"EmbeddingVectorViz",props:{vector:{},label:{},height:{}},setup(y){const n=y,s=_(null),b=_(null),v=_(null),g=N(()=>n.height??120);function h(){const u=s.value,m=b.value;if(!u||!m)return;const f=u.getContext("2d");if(!f)return;const M=n.vector,w=m.clientWidth,x=g.value,d=window.devicePixelRatio||1;u.width=w*d,u.height=x*d,u.style.width=`${w}px`,u.style.height=`${x}px`,f.scale(d,d),f.clearRect(0,0,w,x);const c=w/M.length,i=x/2;let p=0;for(const k of M)Math.abs(k)>p&&(p=Math.abs(k));p===0&&(p=1);for(let k=0;k<M.length;k++){const C=M[k],P=C/p,A=Math.abs(P)*(i-2),$=.3+Math.abs(P)*.7;C>=0?(f.fillStyle=`rgba(139, 92, 246, ${$})`,f.fillRect(k*c,i-A,Math.max(c,.5),A)):(f.fillStyle=`rgba(251, 146, 60, ${$})`,f.fillRect(k*c,i,Math.max(c,.5),A))}f.strokeStyle="rgba(100, 116, 139, 0.3)",f.lineWidth=1,f.beginPath(),f.moveTo(0,i),f.lineTo(w,i),f.stroke()}function R(u){const m=s.value;if(!m)return;const f=m.getBoundingClientRect(),M=u.clientX-f.left,w=f.width/n.vector.length,x=Math.floor(M/w);x>=0&&x<n.vector.length?v.value={index:x,value:n.vector[x],x:u.clientX-f.left,y:u.clientY-f.top}:v.value=null}function T(){v.value=null}return oe(h),Q(()=>n.vector,h),(u,m)=>(o(),a("div",fe,[y.label?(o(),a("div",be,r(y.label),1)):z("",!0),e("div",{ref_key:"containerRef",ref:b,class:"relative overflow-hidden rounded-lg border border-border-default bg-surface"},[e("canvas",{ref_key:"canvasRef",ref:s,height:g.value,class:"w-full cursor-crosshair",onMousemove:R,onMouseleave:T},null,40,ge),v.value?(o(),a("div",{key:0,class:"pointer-events-none absolute z-10 rounded border border-border-default bg-surface-raised px-2 py-1 text-[10px] shadow-lg",style:H({left:`${Math.min(v.value.x,(b.value?.clientWidth??200)-120)}px`,top:`${v.value.y-36}px`})},[e("span",he,"dim["+r(v.value.index)+"]",1),e("span",{class:Y(["ml-1.5 font-mono",v.value.value>=0?"text-accent":"text-warning"])},r(v.value.value.toFixed(6)),3)],4)):z("",!0)],512),e("div",ye,[m[0]||(m[0]=ie('<div class="flex items-center gap-3"><span class="flex items-center gap-1"><span class="inline-block h-1.5 w-1.5 rounded-full bg-[rgb(139,92,246)]"></span> Positive </span><span class="flex items-center gap-1"><span class="inline-block h-1.5 w-1.5 rounded-full bg-[rgb(251,146,60)]"></span> Negative </span></div>',1)),e("span",null,"All "+r(y.vector.length)+" dimensions",1)])]))}}),_e={class:"grid grid-cols-4 gap-2 text-xs lg:grid-cols-8"},we={class:"text-text-muted"},ke={class:"font-medium text-text-primary"},Me={class:"pointer-events-none absolute bottom-full left-1/2 z-50 mb-2 -translate-x-1/2 opacity-0 transition-opacity group-hover:opacity-100"},$e={class:"w-52 rounded-lg border border-border-default bg-surface-raised px-3 py-2 text-[10px] leading-relaxed text-text-secondary shadow-lg"},Se=U({__name:"EmbeddingStats",props:{result:{}},setup(y){const n=y,s=N(()=>{const v=n.result.vector;let g=1/0,h=-1/0,R=0,T=0,u=0;for(const x of v)x<g&&(g=x),x>h&&(h=x),R+=x,T+=x*x,Math.abs(x)<.001&&u++;const m=R/v.length,f=T/v.length-m*m,M=Math.sqrt(T),w=u/v.length*100;return{dimensions:v.length,min:g.toFixed(4),max:h.toFixed(4),mean:m.toFixed(4),stdDev:Math.sqrt(Math.max(0,f)).toFixed(4),l2Norm:M.toFixed(4),sparsity:w.toFixed(1),duration:I(n.result.durationMs),memoryBytes:v.length*8}}),b=N(()=>[{key:"dims",label:"Dims",value:s.value.dimensions,tooltip:"Number of dimensions in the embedding vector. Higher dimensions capture more semantic nuance but use more memory."},{key:"min",label:"Min",value:s.value.min,tooltip:"Smallest value across all dimensions. Shows the negative activation floor of the embedding space."},{key:"max",label:"Max",value:s.value.max,tooltip:"Largest value across all dimensions. Shows the positive activation ceiling of the embedding space."},{key:"mean",label:"Mean",value:s.value.mean,tooltip:"Average value across all dimensions. Near-zero means the vector is well-centered, which is typical for normalized embeddings."},{key:"stdDev",label:"Std Dev",value:s.value.stdDev,tooltip:"Standard deviation — measures how spread out the values are. Higher means more varied activations across dimensions."},{key:"l2Norm",label:"L2 Norm",value:s.value.l2Norm,tooltip:"Euclidean length of the vector. Normalized embeddings have L2 norm close to 1.0, making cosine similarity equivalent to dot product."},{key:"sparsity",label:"Sparsity",value:`${s.value.sparsity}%`,tooltip:"Percentage of dimensions with near-zero values (|v| < 0.001). High sparsity means the text activates only a subset of the semantic dimensions."},{key:"duration",label:"Time",value:s.value.duration,tooltip:"Time taken by the model to compute the embedding vector from the input text."}]);return(v,g)=>(o(),a("div",_e,[(o(!0),a(B,null,L(b.value,h=>(o(),a("div",{key:h.key,class:"group relative rounded-lg bg-surface p-2 cursor-help"},[e("div",we,r(h.label),1),e("div",ke,r(h.value),1),e("div",Me,[e("div",$e,r(h.tooltip),1),g[0]||(g[0]=e("div",{class:"mx-auto h-2 w-2 -translate-y-1 rotate-45 border-b border-r border-border-default bg-surface-raised"},null,-1))])]))),128))]))}}),Ce={key:0,class:"relative overflow-hidden rounded-lg border border-border-default bg-surface p-4"},Re={class:"mb-3 flex items-center justify-between text-[10px] text-text-muted"},Te={key:0},ze={key:1},Ee={key:2},Be={key:3,class:"font-mono"},Fe={class:"relative h-24 flex items-center justify-center"},De={key:0,class:"absolute inset-0 flex flex-wrap items-center justify-center gap-1.5 px-4"},Ae={key:0,class:"absolute inset-0 flex items-center justify-center"},Ne={class:"flex items-end gap-px h-16"},Ve={class:"text-text-muted"},Pe={class:"mt-3 flex items-center justify-between"},je={class:"flex items-center gap-3 text-[10px] text-text-muted"},qe={key:0,class:"text-text-muted"},Le={class:"flex items-center gap-2 text-[10px] text-text-muted shrink-0"},We=U({__name:"EmbeddingTransformViz",props:{inputText:{},isEmbedding:{type:Boolean},vector:{}},setup(y){const n=y,s=_("idle"),b=_(0),v=_(null),g=_(null),h=_(null);let R=0,T=0;const u=N(()=>n.inputText.split(/\s+/).filter(Boolean).slice(0,20)),m=N(()=>{if(!n.vector)return null;let d=0,c=0;for(const k of n.vector)k>=0?d++:c++;const i=d/n.vector.length;let p;return i>.7?p="Mostly positive activations":i<.3?p="Mostly negative activations":p="Balanced activation spread",{positive:d,negative:c,character:p}});function f(){const d=g.value,c=h.value;if(!d||!c||!n.vector)return;const i=d.getContext("2d");if(!i)return;const p=n.vector,k=c.clientWidth,C=96,P=window.devicePixelRatio||1;d.width=k*P,d.height=C*P,d.style.width=`${k}px`,d.style.height=`${C}px`,i.scale(P,P),i.clearRect(0,0,k,C);const A=k/p.length,$=C/2;let q=0;for(const V of p)Math.abs(V)>q&&(q=Math.abs(V));q===0&&(q=1);for(let V=0;V<p.length;V++){const E=p[V],t=E/q,l=Math.abs(t)*($-2),D=.3+Math.abs(t)*.7;E>=0?(i.fillStyle=`rgba(139, 92, 246, ${D})`,i.fillRect(V*A,$-l,Math.max(A,.5),l)):(i.fillStyle=`rgba(251, 146, 60, ${D})`,i.fillRect(V*A,$,Math.max(A,.5),l))}i.strokeStyle="rgba(100, 116, 139, 0.3)",i.lineWidth=1,i.beginPath(),i.moveTo(0,$),i.lineTo(k,$),i.stroke()}function M(d){const c=g.value;if(!c||!n.vector)return;const i=c.getBoundingClientRect(),p=d.clientX-i.left,k=i.width/n.vector.length,C=Math.floor(p/k);C>=0&&C<n.vector.length?v.value={index:C,value:n.vector[C],x:d.clientX-i.left,y:d.clientY-i.top}:v.value=null}function w(){v.value=null}function x(d){T||(T=d);const c=d-T;c<600?(s.value="decomposing",b.value=c/600):c<1200&&(s.value="transforming",b.value=(c-600)/600),n.isEmbedding&&(R=requestAnimationFrame(x))}return Q(()=>n.isEmbedding,d=>{d?(T=0,b.value=0,v.value=null,s.value="decomposing",R=requestAnimationFrame(x)):(cancelAnimationFrame(R),n.vector?(s.value="complete",b.value=1,ee(f)):(s.value="idle",b.value=0))}),Q(()=>n.vector,()=>{s.value==="complete"&&n.vector&&ee(f)}),re(()=>cancelAnimationFrame(R)),(d,c)=>s.value!=="idle"||y.vector?(o(),a("div",Ce,[e("div",Re,[s.value==="decomposing"?(o(),a("span",Te,"Tokenizing text...")):s.value==="transforming"?(o(),a("span",ze,"Projecting into embedding space...")):s.value==="complete"&&m.value?(o(),a("span",Ee,r(m.value.character),1)):z("",!0),y.vector?(o(),a("span",Be,r(y.vector.length)+" dimensions · "+r(m.value?.positive)+" positive · "+r(m.value?.negative)+" negative ",1)):z("",!0)]),e("div",Fe,[F(Z,{name:"fade"},{default:G(()=>[s.value==="decomposing"||s.value==="idle"&&!y.vector?(o(),a("div",De,[(o(!0),a(B,null,L(u.value,(i,p)=>(o(),a("span",{key:p,class:"inline-block rounded bg-accent/10 px-1.5 py-0.5 font-mono text-xs text-accent transition-all duration-500",style:H({opacity:s.value==="decomposing"?Math.max(0,1-b.value*1.5+p*.1):1,transform:s.value==="decomposing"?`translateY(${b.value*20*(p%2===0?-1:1)}px) scale(${1-b.value*.3})`:"none"})},r(i),5))),128))])):z("",!0)]),_:1}),F(Z,{name:"fade"},{default:G(()=>[s.value==="transforming"?(o(),a("div",Ae,[e("div",Ne,[(o(),a(B,null,L(60,i=>e("div",{key:i,class:"w-1 rounded-full transition-all duration-300",style:H({height:`${Math.abs(Math.sin(i*.5+b.value*10))*b.value*100}%`,backgroundColor:Math.sin(i*.5+b.value*10)>=0?`rgba(139, 92, 246, ${.3+b.value*.5})`:`rgba(251, 146, 60, ${.3+b.value*.5})`,opacity:Math.min(1,b.value*2)})},null,4)),64))])])):z("",!0)]),_:1}),F(Z,{name:"fade"},{default:G(()=>[s.value==="complete"&&y.vector?(o(),a("div",{key:0,ref_key:"canvasContainerRef",ref:h,class:"absolute inset-0"},[e("canvas",{ref_key:"canvasRef",ref:g,class:"w-full h-full cursor-crosshair",onMousemove:M,onMouseleave:w},null,544),v.value?(o(),a("div",{key:0,class:"pointer-events-none absolute z-10 rounded border border-border-default bg-surface-raised px-2 py-1 text-[10px] shadow-lg",style:H({left:`${Math.min(v.value.x,(h.value?.clientWidth??200)-120)}px`,top:`${v.value.y-36}px`})},[e("span",Ve,"dim["+r(v.value.index)+"]",1),e("span",{class:Y(["ml-1.5 font-mono",v.value.value>=0?"text-accent":"text-warning"])},r(v.value.value.toFixed(6)),3)],4)):z("",!0)],512)):z("",!0)]),_:1})]),e("div",Pe,[e("div",je,[c[0]||(c[0]=e("span",{class:"flex items-center gap-1"},[e("span",{class:"inline-block h-2 w-2 rounded-full bg-[rgb(139,92,246)]"}),j(" Positive activation ")],-1)),c[1]||(c[1]=e("span",{class:"flex items-center gap-1"},[e("span",{class:"inline-block h-2 w-2 rounded-full bg-[rgb(251,146,60)]"}),j(" Negative activation ")],-1)),s.value==="complete"?(o(),a("span",qe," · Each bar = one semantic dimension. Taller = stronger signal. ")):z("",!0)]),e("div",Le,[c[2]||(c[2]=e("span",{class:"rounded bg-surface-overlay px-1.5 py-0.5"},"Text",-1)),c[3]||(c[3]=e("span",null,"→",-1)),c[4]||(c[4]=e("span",{class:"rounded bg-surface-overlay px-1.5 py-0.5"},"Tokens",-1)),c[5]||(c[5]=e("span",null,"→",-1)),e("span",{class:Y(["rounded px-1.5 py-0.5",s.value==="complete"?"bg-accent/10 text-accent":"bg-surface-overlay"])}," Vector ",2)])])])):z("",!0)}}),Ie=xe(We,[["__scopeId","data-v-51d9d185"]]),Ue={class:"flex flex-col items-center gap-2"},He={class:"relative h-32 w-32"},Xe={viewBox:"0 0 100 100",class:"h-full w-full -rotate-90"},Ke=["stroke","stroke-dasharray"],Ye={class:"absolute inset-0 flex flex-col items-center justify-center"},Ze={class:"text-2xl font-bold text-text-primary"},se=U({__name:"SimilarityMeter",props:{score:{}},setup(y){const n=y,s=N(()=>Math.round(n.score*100)),b=N(()=>n.score>=.8?"#4ade80":n.score>=.5?"#fbbf24":"#f87171"),v=N(()=>n.score>=.9?"Very Similar":n.score>=.7?"Similar":n.score>=.5?"Somewhat Similar":n.score>=.3?"Weakly Related":"Dissimilar");return(g,h)=>(o(),a("div",Ue,[e("div",He,[(o(),a("svg",Xe,[h[0]||(h[0]=e("circle",{cx:"50",cy:"50",r:"42",fill:"none",class:"stroke-surface-overlay","stroke-width":"8"},null,-1)),e("circle",{cx:"50",cy:"50",r:"42",fill:"none",stroke:b.value,"stroke-width":"8","stroke-linecap":"round","stroke-dasharray":`${s.value*2.64} 264`},null,8,Ke)])),e("div",Ye,[e("span",Ze,r(s.value)+"%",1)])]),e("span",{class:"text-sm font-medium",style:H({color:b.value})},r(v.value),5),h[1]||(h[1]=e("span",{class:"text-xs text-text-muted"},"Cosine Similarity",-1))]))}}),Ge={class:"space-y-8"},Je={class:"flex items-center gap-3"},Oe={key:0,value:"",disabled:""},Qe=["value"],et={key:0,class:"text-xs text-warning"},tt={class:"rounded-lg border border-border-default bg-surface-raised p-5 space-y-4"},st=["disabled","onKeydown"],ot={class:"flex items-center gap-3"},lt=["disabled"],at={key:0,class:"flex items-center gap-2"},nt={key:1},it={key:0,class:"text-sm text-error"},rt={class:"text-xs"},dt={class:"cursor-pointer text-text-muted hover:text-text-secondary"},ut={class:"mt-2 grid grid-cols-5 gap-1 font-mono text-text-secondary"},ct=["title"],mt={class:"rounded-lg border border-border-default bg-surface-raised p-5 space-y-4"},vt={class:"grid grid-cols-1 gap-4 lg:grid-cols-2"},xt=["disabled"],pt=["disabled"],ft=["disabled"],bt={key:0,class:"flex items-center gap-2"},gt={key:1},ht={key:0,class:"flex flex-col items-center gap-6 py-4 lg:flex-row lg:items-start lg:justify-center"},yt={class:"flex-1 space-y-2"},_t={class:"rounded-lg bg-surface p-3 text-sm text-text-secondary"},wt={class:"flex-1 space-y-2"},kt={class:"rounded-lg bg-surface p-3 text-sm text-text-secondary"},Mt={class:"rounded-lg border border-border-default bg-surface-raised p-5 space-y-4"},$t={class:"grid grid-cols-1 gap-4 lg:grid-cols-2"},St=["disabled"],Ct=["value"],Rt=["disabled"],Tt=["value"],zt=["disabled"],Et=["disabled"],Bt={key:0,class:"flex items-center gap-2"},Ft={key:1},Dt={class:"grid grid-cols-1 gap-4 lg:grid-cols-2"},At={class:"space-y-3 rounded-lg border border-border-default bg-surface p-3"},Nt={class:"flex items-center justify-between"},Vt={class:"text-xs font-medium text-accent"},Pt={class:"text-[10px] text-text-muted"},jt={class:"grid grid-cols-4 gap-1.5 text-[10px]"},qt={class:"rounded bg-surface-overlay p-1.5"},Lt={class:"font-medium text-text-primary"},Wt={class:"rounded bg-surface-overlay p-1.5"},It={class:"font-medium text-text-primary"},Ut={class:"rounded bg-surface-overlay p-1.5"},Ht={class:"font-medium text-text-primary"},Xt={class:"rounded bg-surface-overlay p-1.5"},Kt={class:"font-medium text-text-primary"},Yt={class:"space-y-3 rounded-lg border border-border-default bg-surface p-3"},Zt={class:"flex items-center justify-between"},Gt={class:"text-xs font-medium text-accent"},Jt={class:"text-[10px] text-text-muted"},Ot={class:"grid grid-cols-4 gap-1.5 text-[10px]"},Qt={class:"rounded bg-surface-overlay p-1.5"},es={class:"font-medium text-text-primary"},ts={class:"rounded bg-surface-overlay p-1.5"},ss={class:"font-medium text-text-primary"},os={class:"rounded bg-surface-overlay p-1.5"},ls={class:"font-medium text-text-primary"},as={class:"rounded bg-surface-overlay p-1.5"},ns={class:"font-medium text-text-primary"},is={class:"rounded-lg border border-border-default bg-surface p-4 text-center"},rs={class:"mt-2 text-xs text-text-muted"},ds={class:"text-sm text-text-muted py-2"},us={key:1,class:"rounded-lg border border-border-default bg-surface-raised p-5 space-y-4"},cs={class:"flex items-center justify-between"},ms={class:"space-y-2"},vs=["onClick"],xs={class:"flex-1 min-w-0"},ps={class:"truncate text-sm text-text-primary"},fs={class:"flex gap-3 text-xs text-text-muted mt-0.5"},bs=["onClick"],ks=U({__name:"EmbeddingsPage",setup(y){const n=de(),s=pe(),b=me(),v=N(()=>b.getDatabaseById("message-memory")),g=_(""),h=_(""),R=_(null),T=_(""),u=_(""),m=_(null),f=_(null),M=_(null),w=_(!1),x=_(""),d=_(""),c=_(""),i=_(null),p=_(null),k=_(null),C=_(!1);async function P(){if(!(!x.value||!d.value||!c.value.trim())){C.value=!0,k.value=null,i.value=null,p.value=null;try{const[E,t]=await Promise.all([s.embed(x.value,c.value.trim()),s.embed(d.value,c.value.trim())]);i.value=E,p.value=t,E.dimensions===t.dimensions&&(k.value=s.cosineSimilarity(E.vector,t.vector))}catch{}finally{C.value=!1}}}const A=N(()=>n.models.filter(E=>E.name.includes("embed")||E.name.includes("nomic")||E.name.includes("minilm")||E.name.includes("snowflake")||E.name.includes("mxbai")||E.name.includes("bge"))),$=N(()=>A.value.length>0?A.value:n.models);async function q(){if(!(!g.value||!h.value.trim()))try{R.value=await s.embed(g.value,h.value.trim())}catch{}}async function V(){if(!(!g.value||!T.value.trim()||!u.value.trim())){w.value=!0,M.value=null;try{const[E,t]=await Promise.all([s.embed(g.value,T.value.trim()),s.embed(g.value,u.value.trim())]);m.value=E,f.value=t,M.value=s.cosineSimilarity(E.vector,t.vector)}catch{}finally{w.value=!1}}}return oe(async()=>{n.models.length===0&&await n.fetchModels(),$.value.length>0&&!g.value&&(g.value=$.value[0].name),$.value.length>=2?(x.value=$.value[0].name,d.value=$.value[1].name):$.value.length===1&&(x.value=$.value[0].name,d.value=$.value[0].name),await b.refreshIfStale()}),(E,t)=>(o(),a("div",Ge,[e("div",Je,[W(e("select",{"onUpdate:modelValue":t[0]||(t[0]=l=>g.value=l),class:"rounded-lg border border-border-default bg-surface px-3 py-2 text-sm text-text-primary focus:border-accent focus:outline-none"},[$.value.length===0?(o(),a("option",Oe,"No models available")):z("",!0),(o(!0),a(B,null,L($.value,l=>(o(),a("option",{key:l.name,value:l.name},r(l.name)+" "+r(S(n).capabilityIcons(l.name)),9,Qe))),128))],512),[[J,g.value]]),A.value.length===0&&S(n).models.length>0?(o(),a("span",et," No embedding models found. Pull one: ollama pull nomic-embed-text ")):z("",!0)]),S(b).origin&&v.value?(o(),ue(ve,{key:0,used:v.value.totalBytes,total:S(b).origin.quota,compact:"",label:`Embedding Memory · ${v.value.recordCount.toLocaleString()} records`},null,8,["used","total","label"])):z("",!0),e("section",tt,[t[9]||(t[9]=e("h2",{class:"text-base font-semibold text-text-primary"},"Embed Playground",-1)),t[10]||(t[10]=e("p",{class:"text-sm text-text-muted"},"Enter text to generate its embedding vector and inspect the dimensions.",-1)),W(e("textarea",{"onUpdate:modelValue":t[1]||(t[1]=l=>h.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-4 py-3 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none resize-none",rows:"3",placeholder:"Enter text to embed...",disabled:S(s).loading,onKeydown:ce(te(q,["ctrl"]),["enter"])},null,40,st),[[X,h.value]]),e("div",ot,[e("button",{class:"rounded-lg bg-accent px-4 py-2 text-sm font-medium text-surface hover:bg-accent-hover transition-colors disabled:opacity-50",disabled:S(s).loading||!g.value||!h.value.trim(),onClick:q},[S(s).loading?(o(),a("span",at,[F(O,{size:"sm"}),t[8]||(t[8]=j(" Embedding... ",-1))])):(o(),a("span",nt,"Embed"))],8,lt),S(s).error?(o(),a("span",it,r(S(s).error),1)):z("",!0)]),F(Ie,{"input-text":h.value,"is-embedding":S(s).loading,vector:R.value?.vector??null},null,8,["input-text","is-embedding","vector"]),R.value?(o(),a(B,{key:0},[F(Se,{result:R.value},null,8,["result"]),e("details",rt,[e("summary",dt," Show raw values (first 50 of "+r(R.value.dimensions)+") ",1),e("div",ut,[(o(!0),a(B,null,L(R.value.vector.slice(0,50),(l,D)=>(o(),a("span",{key:D,class:"rounded bg-surface px-1.5 py-0.5",title:`dim[${D}]`},r(l.toFixed(4)),9,ct))),128))])])],64)):z("",!0)]),e("section",mt,[t[16]||(t[16]=e("h2",{class:"text-base font-semibold text-text-primary"},"Similarity Calculator",-1)),t[17]||(t[17]=e("p",{class:"text-sm text-text-muted"},"Compare two texts to measure their semantic similarity using cosine distance.",-1)),e("div",vt,[e("div",null,[t[11]||(t[11]=e("label",{class:"block text-xs font-medium text-text-muted mb-1"},"Text A",-1)),W(e("textarea",{"onUpdate:modelValue":t[2]||(t[2]=l=>T.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-4 py-3 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none resize-none",rows:"3",placeholder:"First text...",disabled:w.value},null,8,xt),[[X,T.value]])]),e("div",null,[t[12]||(t[12]=e("label",{class:"block text-xs font-medium text-text-muted mb-1"},"Text B",-1)),W(e("textarea",{"onUpdate:modelValue":t[3]||(t[3]=l=>u.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-4 py-3 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none resize-none",rows:"3",placeholder:"Second text...",disabled:w.value},null,8,pt),[[X,u.value]])])]),e("button",{class:"rounded-lg bg-accent px-4 py-2 text-sm font-medium text-surface hover:bg-accent-hover transition-colors disabled:opacity-50",disabled:w.value||!g.value||!T.value.trim()||!u.value.trim(),onClick:V},[w.value?(o(),a("span",bt,[F(O,{size:"sm"}),t[13]||(t[13]=j(" Comparing... ",-1))])):(o(),a("span",gt,"Compare"))],8,ft),M.value!==null&&m.value&&f.value?(o(),a("div",ht,[e("div",yt,[t[14]||(t[14]=e("div",{class:"text-xs font-medium text-text-muted"},"Text A",-1)),e("div",_t,r(m.value.input),1),F(K,{vector:m.value.vector,height:80},null,8,["vector"])]),F(se,{score:M.value},null,8,["score"]),e("div",wt,[t[15]||(t[15]=e("div",{class:"text-xs font-medium text-text-muted"},"Text B",-1)),e("div",kt,r(f.value.input),1),F(K,{vector:f.value.vector,height:80},null,8,["vector"])])])):z("",!0)]),e("section",Mt,[t[31]||(t[31]=e("h2",{class:"text-base font-semibold text-text-primary"},"Model Comparison",-1)),t[32]||(t[32]=e("p",{class:"text-sm text-text-muted"},"Embed the same text with two models to compare how they represent meaning.",-1)),e("div",$t,[e("div",null,[t[18]||(t[18]=e("label",{class:"block text-xs font-medium text-text-muted mb-1"},"Model A",-1)),W(e("select",{"onUpdate:modelValue":t[4]||(t[4]=l=>x.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:border-accent",disabled:C.value},[(o(!0),a(B,null,L($.value,l=>(o(),a("option",{key:l.name,value:l.name},r(l.name)+" "+r(S(n).capabilityIcons(l.name)),9,Ct))),128))],8,St),[[J,x.value]])]),e("div",null,[t[19]||(t[19]=e("label",{class:"block text-xs font-medium text-text-muted mb-1"},"Model B",-1)),W(e("select",{"onUpdate:modelValue":t[5]||(t[5]=l=>d.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-3 py-2 text-sm text-text-primary outline-none focus:border-accent",disabled:C.value},[(o(!0),a(B,null,L($.value,l=>(o(),a("option",{key:l.name,value:l.name},r(l.name)+" "+r(S(n).capabilityIcons(l.name)),9,Tt))),128))],8,Rt),[[J,d.value]])])]),W(e("textarea",{"onUpdate:modelValue":t[6]||(t[6]=l=>c.value=l),class:"w-full rounded-lg border border-border-default bg-surface px-4 py-3 text-sm text-text-primary placeholder-text-muted focus:border-accent focus:outline-none resize-none",rows:"2",placeholder:"Enter text to embed with both models...",disabled:C.value},null,8,zt),[[X,c.value]]),e("button",{class:"rounded-lg bg-accent px-4 py-2 text-sm font-medium text-surface hover:bg-accent-hover transition-colors disabled:opacity-50",disabled:C.value||!x.value||!d.value||!c.value.trim(),onClick:P},[C.value?(o(),a("span",Bt,[F(O,{size:"sm"}),t[20]||(t[20]=j(" Comparing models... ",-1))])):(o(),a("span",Ft,"Compare Models"))],8,Et),i.value&&p.value?(o(),a(B,{key:0},[e("div",Dt,[e("div",At,[e("div",Nt,[e("span",Vt,r(i.value.model),1),e("span",Pt,r(i.value.dimensions)+"d · "+r(S(I)(i.value.durationMs)),1)]),F(K,{vector:i.value.vector,height:80},null,8,["vector"]),e("div",jt,[e("div",qt,[t[21]||(t[21]=e("div",{class:"text-text-muted"},"Dims",-1)),e("div",Lt,r(i.value.dimensions),1)]),e("div",Wt,[t[22]||(t[22]=e("div",{class:"text-text-muted"},"L2 Norm",-1)),e("div",It,r(Math.sqrt(i.value.vector.reduce((l,D)=>l+D*D,0)).toFixed(2)),1)]),e("div",Ut,[t[23]||(t[23]=e("div",{class:"text-text-muted"},"Sparsity",-1)),e("div",Ht,r((i.value.vector.filter(l=>Math.abs(l)<.001).length/i.value.dimensions*100).toFixed(1))+"%",1)]),e("div",Xt,[t[24]||(t[24]=e("div",{class:"text-text-muted"},"Time",-1)),e("div",Kt,r(S(I)(i.value.durationMs)),1)])])]),e("div",Yt,[e("div",Zt,[e("span",Gt,r(p.value.model),1),e("span",Jt,r(p.value.dimensions)+"d · "+r(S(I)(p.value.durationMs)),1)]),F(K,{vector:p.value.vector,height:80},null,8,["vector"]),e("div",Ot,[e("div",Qt,[t[25]||(t[25]=e("div",{class:"text-text-muted"},"Dims",-1)),e("div",es,r(p.value.dimensions),1)]),e("div",ts,[t[26]||(t[26]=e("div",{class:"text-text-muted"},"L2 Norm",-1)),e("div",ss,r(Math.sqrt(p.value.vector.reduce((l,D)=>l+D*D,0)).toFixed(2)),1)]),e("div",os,[t[27]||(t[27]=e("div",{class:"text-text-muted"},"Sparsity",-1)),e("div",ls,r((p.value.vector.filter(l=>Math.abs(l)<.001).length/p.value.dimensions*100).toFixed(1))+"%",1)]),e("div",as,[t[28]||(t[28]=e("div",{class:"text-text-muted"},"Time",-1)),e("div",ns,r(S(I)(p.value.durationMs)),1)])])])]),e("div",is,[k.value!==null?(o(),a(B,{key:0},[F(se,{score:k.value},null,8,["score"]),e("p",rs,[t[29]||(t[29]=j(" Cross-model similarity — how similarly these models represent the same text. ",-1)),k.value<.5?(o(),a(B,{key:0},[j(" These models encode meaning very differently.")],64)):k.value<.8?(o(),a(B,{key:1},[j(" Moderate agreement — the models share some semantic structure.")],64)):(o(),a(B,{key:2},[j(" High agreement — these models represent this text similarly.")],64))])],64)):(o(),a(B,{key:1},[e("p",ds," Dimensions differ ("+r(i.value.dimensions)+" vs "+r(p.value.dimensions)+") — direct cosine similarity not possible. ",1),t[30]||(t[30]=e("p",{class:"text-xs text-text-muted"}," Compare stats above to evaluate each model's representation quality. ",-1))],64))])],64)):z("",!0)]),S(s).recentResults.length>0?(o(),a("section",us,[e("div",cs,[t[33]||(t[33]=e("h2",{class:"text-base font-semibold text-text-primary"},"Recent Embeddings",-1)),e("button",{class:"text-xs text-text-muted hover:text-error transition-colors",onClick:t[7]||(t[7]=l=>S(s).clearResults())}," Clear all ")]),e("div",ms,[(o(!0),a(B,null,L(S(s).recentResults.slice(0,10),l=>(o(),a("div",{key:l.id,class:"flex items-center justify-between rounded-lg bg-surface px-4 py-2 hover:bg-surface-overlay transition-colors cursor-pointer",onClick:D=>R.value=l},[e("div",xs,[e("div",ps,r(l.input),1),e("div",fs,[e("span",null,r(l.model),1),e("span",null,r(l.dimensions)+"d",1),e("span",null,r(S(I)(l.durationMs)),1)])]),e("button",{class:"ml-3 text-text-muted hover:text-error text-xs",onClick:te(D=>S(s).removeResult(l.id),["stop"])}," ✕ ",8,bs)],8,vs))),128))])])):z("",!0)]))}});export{ks as default};
@@ -1 +0,0 @@
1
- import{a as r,z as i,b as s,e as t,F as c,j as d,g as m,f as p,i as u,c as _,J as k}from"./index-BqB3FY2M.js";const h={key:0,class:"inline-flex items-center gap-0.5"},g=["title"],C=["d"],x=r({__name:"ModelCapabilityIcons",props:{modelName:{}},setup(a){const n=a,l=i(),o=_(()=>k(l.getCapabilities(n.modelName)));return(f,v)=>o.value.length>0?(s(),t("span",h,[(s(!0),t(c,null,d(o.value,e=>(s(),t("svg",{key:e.key,class:m(["h-3 w-3 shrink-0",e.color]),title:e.label,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[p("path",{d:e.svg},null,8,C)],10,g))),128))])):u("",!0)}});export{x as _};
@@ -1 +0,0 @@
1
- import{a as k,b as l,e as i,v as $,g as y,f as e,r as _,F as w,j as D,i as v,t as r,h as S,B as I,C as M,M as A,k as F,z as N,A as R,w as T,E,u as x,p as b,c as C}from"./index-BqB3FY2M.js";import{d as B,u as P}from"./rag-store-VWnttX_x.js";import{u as V}from"./storage-store-B1XevdC4.js";import{_ as j}from"./StorageGauge.vue_vue_type_style_index_0_lang-hO4dId5t.js";import{b as z}from"./format-BqVZ9rwM.js";import"./vector-db-ChAzHl5A.js";const G=".pdf,.docx,.txt,.md,.csv",U=k({__name:"DocumentUploadZone",emits:["upload"],setup(m,{emit:s}){const g=s,d=_(!1),u=_(null);function f(c){d.value=!1;const n=Array.from(c.dataTransfer?.files??[]).filter(a=>B(a.name)!==null);n.length>0&&g("upload",n)}function p(c){const t=c.target,a=Array.from(t.files??[]).filter(h=>B(h.name)!==null);a.length>0&&g("upload",a),t.value=""}function o(){u.value?.click()}return(c,t)=>(l(),i("div",{class:y(["relative rounded-xl border-2 border-dashed p-8 text-center transition-colors cursor-pointer",d.value?"border-accent bg-accent/5":"border-border-default hover:border-accent/50"]),onDragover:t[0]||(t[0]=$(n=>d.value=!0,["prevent"])),onDragleave:t[1]||(t[1]=$(n=>d.value=!1,["prevent"])),onDrop:$(f,["prevent"]),onClick:o},[e("input",{ref_key:"fileInput",ref:u,type:"file",accept:G,multiple:"",class:"hidden",onChange:p},null,544),t[2]||(t[2]=e("div",{class:"space-y-2"},[e("div",{class:"text-3xl"},"📄"),e("p",{class:"text-sm font-medium text-text-primary"}," Drop files here or click to browse "),e("p",{class:"text-xs text-text-muted"}," Supports PDF, DOCX, TXT, Markdown, CSV ")],-1))],34))}}),K={key:0,class:"rounded-lg bg-surface-overlay p-6 text-center"},L={key:1,class:"space-y-2"},q=["onClick"],X={key:0,class:"text-xs"},O={key:1,class:"h-5 w-5"},Z={class:"text-lg"},H={class:"flex-1 min-w-0"},J={class:"text-sm font-medium text-text-primary truncate"},Q={class:"text-xs text-text-muted"},W={key:0,class:"ml-1"},Y={class:"text-xs text-text-muted shrink-0"},ee=["onClick"],te=768,se=k({__name:"DocumentList",props:{documents:{},enabledIds:{}},emits:["toggle","remove"],setup(m,{emit:s}){const g=s;function d(o){return o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/(1024*1024)).toFixed(1)} MB`}function u(o){return new Date(o).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function f(o){return o.sizeBytes+o.chunkCount*te*8}const p={pdf:"📕",docx:"📘",txt:"📝",md:"📋",csv:"📊"};return(o,c)=>m.documents.length===0?(l(),i("div",K,[...c[0]||(c[0]=[e("p",{class:"text-sm text-text-muted"},"No documents ingested yet",-1)])])):(l(),i("div",L,[(l(!0),i(w,null,D(m.documents,t=>(l(),i("div",{key:t.id,class:"flex items-center gap-3 rounded-lg border border-border-default bg-surface-raised px-4 py-3 transition-colors"},[t.status==="ready"?(l(),i("button",{key:0,class:y(["flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors",m.enabledIds.has(t.id)?"border-accent bg-accent text-white":"border-border-default hover:border-accent"]),title:"Toggle RAG context",onClick:n=>g("toggle",t.id)},[m.enabledIds.has(t.id)?(l(),i("span",X,"✓")):v("",!0)],10,q)):(l(),i("span",O)),e("span",Z,r(p[t.format]??"📄"),1),e("div",H,[e("p",J,r(t.name),1),e("p",Q,[S(r(d(t.sizeBytes))+" · "+r(t.chunkCount)+" chunks · ~"+r(d(f(t)))+" stored · "+r(t.embeddingModel)+" ",1),t.status!=="ready"?(l(),i("span",W,[c[1]||(c[1]=S(" · ",-1)),e("span",{class:y(t.status==="error"?"text-error":"text-accent")},r(t.status),3)])):v("",!0)])]),e("span",Y,r(u(t.addedAt)),1),e("button",{class:"shrink-0 rounded p-1 text-text-muted hover:text-error transition-colors",title:"Remove document",onClick:n=>g("remove",t.id)}," ✕ ",8,ee)]))),128))]))}}),ne={class:"space-y-4"},oe={class:"flex gap-2"},re=["disabled"],ae={key:0,class:"space-y-3"},le={class:"text-xs text-text-muted"},ie={class:"mb-2 flex items-center justify-between"},de={class:"text-xs font-medium text-text-secondary"},ce=["onClick"],ue=["onClick"],me=k({__name:"RAGSearchPanel",props:{results:{},isSearching:{type:Boolean}},emits:["search"],setup(m,{emit:s}){const g=s,d=_(""),u=_(new Set);function f(){const o=d.value.trim();o&&(u.value=new Set,g("search",o))}function p(o){const c=new Set(u.value);c.has(o)?c.delete(o):c.add(o),u.value=c}return(o,c)=>(l(),i("div",ne,[e("div",oe,[I(e("input",{"onUpdate:modelValue":c[0]||(c[0]=t=>d.value=t),type:"text",placeholder:"Search your documents...",class:"flex-1 rounded-lg border border-border-default bg-surface px-4 py-2 text-sm text-text-primary placeholder-text-muted outline-none focus:border-accent",onKeydown:A(f,["enter"])},null,544),[[M,d.value]]),e("button",{disabled:!d.value.trim()||m.isSearching,class:"rounded-lg bg-accent px-4 py-2 text-sm text-white transition-colors hover:bg-accent-hover disabled:opacity-40",onClick:f},r(m.isSearching?"Searching...":"Search"),9,re)]),m.results.length>0?(l(),i("div",ae,[e("p",le,r(m.results.length)+" results",1),(l(!0),i(w,null,D(m.results,(t,n)=>(l(),i("div",{key:n,class:"rounded-lg border border-border-default bg-surface-raised p-4"},[e("div",ie,[e("span",de,r(t.documentName),1),e("span",{class:y(["rounded-full px-2 py-0.5 text-[10px] font-medium",t.score>.8?"bg-success/10 text-success":t.score>.5?"bg-warning/10 text-warning":"bg-surface-overlay text-text-muted"])},r((t.score*100).toFixed(1))+"% ",3)]),e("p",{class:y(["text-sm text-text-primary leading-relaxed whitespace-pre-wrap cursor-pointer",u.value.has(n)?"":"line-clamp-4"]),onClick:a=>p(n)},r(t.chunk.content),11,ce),e("button",{class:"mt-1.5 text-[10px] text-accent hover:underline",onClick:a=>p(n)},r(u.value.has(n)?"Show less":"Show full chunk"),9,ue)]))),128))])):v("",!0)]))}}),xe={key:0,class:"rounded-lg border border-accent/30 bg-accent/5 p-4"},ge={class:"flex items-center justify-between mb-2"},fe={class:"text-sm font-medium text-text-primary"},pe={class:"text-xs text-text-muted"},he={class:"h-1.5 rounded-full bg-surface-overlay overflow-hidden"},ve=k({__name:"IngestProgress",props:{progress:{}},setup(m){return(s,g)=>m.progress?(l(),i("div",xe,[e("div",ge,[e("span",fe,r(m.progress.message),1),e("span",pe,r((m.progress.progress*100).toFixed(0))+"%",1)]),e("div",he,[e("div",{class:"h-full rounded-full bg-accent transition-all duration-300",style:F({width:`${m.progress.progress*100}%`})},null,4)])])):v("",!0)}}),be={class:"space-y-6"},ye={class:"flex items-center justify-between"},_e={key:0,value:"",disabled:""},ke=["value"],we={key:0,class:"rounded-lg border border-border-default bg-surface-raised p-3 space-y-2"},Se={class:"flex items-center justify-between text-xs"},$e={class:"text-text-muted"},De={key:1,class:"rounded-lg border border-error/30 bg-error/5 px-4 py-3 text-sm text-error"},Ce={class:"mb-3 text-sm font-medium text-text-secondary"},Re=k({__name:"RAGPage",setup(m){const s=P(),g=N(),d=V(),u=_(""),f=C(()=>d.getDatabaseById("rag")),p=C(()=>s.readyDocuments.reduce((n,a)=>n+a.chunkCount,0));R(async()=>{await g.fetchModels(),u.value=g.embeddingModelNames[0]??"",await s.loadDocuments(),await d.refreshIfStale()}),T(()=>s.isIngesting,(n,a)=>{!n&&a&&d.refresh()});async function o(n){if(u.value)for(const a of n)try{await s.addDocument(a,u.value)}catch{}}async function c(n){await s.removeDocument(n),await d.refresh()}async function t(n){u.value&&await s.search(n,u.value)}return(n,a)=>(l(),i("div",be,[e("div",ye,[a[1]||(a[1]=e("div",null,[e("h2",{class:"text-lg font-semibold text-text-primary"},"Document Knowledge Base"),e("p",{class:"text-sm text-text-muted"},"Ingest documents for RAG-powered conversations")],-1)),I(e("select",{"onUpdate:modelValue":a[0]||(a[0]=h=>u.value=h),class:"rounded-lg border border-border-default bg-surface px-3 py-1.5 text-sm text-text-primary outline-none focus:border-accent"},[x(g).embeddingModelNames.length===0?(l(),i("option",_e,"No embedding models")):v("",!0),(l(!0),i(w,null,D(x(g).embeddingModelNames,h=>(l(),i("option",{key:h,value:h},r(h)+" "+r(x(g).capabilityIcons(h)),9,ke))),128))],512),[[E,u.value]])]),x(d).origin?(l(),i("div",we,[e("div",Se,[a[2]||(a[2]=e("span",{class:"text-text-secondary font-medium"},"Knowledge Base Storage",-1)),e("span",$e,[S(r(x(s).readyDocuments.length)+" documents · "+r(p.value.toLocaleString())+" chunks ",1),f.value?(l(),i(w,{key:0},[S("· "+r(x(z)(f.value.totalBytes))+" stored",1)],64)):v("",!0)])]),b(j,{used:f.value?.totalBytes??0,total:x(d).origin.quota,label:"RAG Storage",animating:x(s).isIngesting,compact:""},null,8,["used","total","animating"])])):v("",!0),b(U,{onUpload:o}),b(ve,{progress:x(s).ingestProgress},null,8,["progress"]),x(s).error?(l(),i("div",De,r(x(s).error),1)):v("",!0),e("div",null,[e("h3",Ce," Documents ("+r(x(s).readyDocuments.length)+") ",1),b(se,{documents:x(s).documents,"enabled-ids":x(s).enabledDocumentIds,onToggle:x(s).toggleDocument,onRemove:c},null,8,["documents","enabled-ids","onToggle"])]),e("div",null,[a[3]||(a[3]=e("h3",{class:"mb-3 text-sm font-medium text-text-secondary"},"Semantic Search",-1)),b(me,{results:x(s).searchResults,"is-searching":x(s).isSearching,onSearch:t},null,8,["results","is-searching"])])]))}});export{Re as default};