@singlebase/elements 0.6.0 → 0.8.0

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/authui-display-C2o9gApg.cjs +961 -0
  2. package/dist/authui-display-C2o9gApg.cjs.map +1 -0
  3. package/dist/{authui-display-CKfGK5va.js → authui-display-CRUABt43.js} +1034 -913
  4. package/dist/authui-display-CRUABt43.js.map +1 -0
  5. package/dist/authui.cjs +1 -1
  6. package/dist/authui.js +2 -2
  7. package/dist/{chat-C-gsskho.cjs → chat-BWcGH9lr.cjs} +310 -287
  8. package/dist/chat-BWcGH9lr.cjs.map +1 -0
  9. package/dist/chat-messages.d.ts +8 -1
  10. package/dist/{chat-CEh6RygY.js → chat-t4o5FsxM.js} +796 -656
  11. package/dist/chat-t4o5FsxM.js.map +1 -0
  12. package/dist/chat.cjs +1 -1
  13. package/dist/chat.d.ts +1 -1
  14. package/dist/chat.js +1 -1
  15. package/dist/elements/authui-account.d.ts +0 -1
  16. package/dist/elements/authui-buttons.d.ts +1 -1
  17. package/dist/elements/authui.d.ts +25 -5
  18. package/dist/elements/chat.d.ts +46 -8
  19. package/dist/elements/uploader.d.ts +0 -6
  20. package/dist/files-4T62wkwj.cjs +77 -0
  21. package/dist/files-4T62wkwj.cjs.map +1 -0
  22. package/dist/{files-DDJWPzZW.js → files-DS-H-3yN.js} +56 -57
  23. package/dist/files-DS-H-3yN.js.map +1 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.js +4 -4
  26. package/dist/messages.d.ts +34 -5
  27. package/dist/singlebase-elements.min.js +2555 -2292
  28. package/dist/singlebase-elements.min.js.map +1 -1
  29. package/dist/upload-messages.d.ts +0 -1
  30. package/dist/{uploader-660JIgIN.cjs → uploader-C57vgFME.cjs} +33 -7
  31. package/dist/uploader-C57vgFME.cjs.map +1 -0
  32. package/dist/{uploader-vfczkX51.js → uploader-Cz9yfzfV.js} +261 -262
  33. package/dist/uploader-Cz9yfzfV.js.map +1 -0
  34. package/dist/uploader.cjs +1 -1
  35. package/dist/uploader.js +2 -2
  36. package/dist/utils/auth-errors.d.ts +7 -0
  37. package/dist/utils/branding.d.ts +5 -5
  38. package/dist/utils/oauth.d.ts +24 -0
  39. package/dist/utils/password.d.ts +16 -0
  40. package/package.json +3 -3
  41. package/dist/authui-display-CKfGK5va.js.map +0 -1
  42. package/dist/authui-display-aWNht0cW.cjs +0 -956
  43. package/dist/authui-display-aWNht0cW.cjs.map +0 -1
  44. package/dist/chat-C-gsskho.cjs.map +0 -1
  45. package/dist/chat-CEh6RygY.js.map +0 -1
  46. package/dist/files-DDJWPzZW.js.map +0 -1
  47. package/dist/files-DyxcjZsx.cjs +0 -75
  48. package/dist/files-DyxcjZsx.cjs.map +0 -1
  49. package/dist/uploader-660JIgIN.cjs.map +0 -1
  50. package/dist/uploader-vfczkX51.js.map +0 -1
@@ -1,4 +1,4 @@
1
- "use strict";var Kt=Object.defineProperty;var bt=l=>{throw TypeError(l)};var Wt=(l,o,e)=>o in l?Kt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[o]=e;var O=(l,o,e)=>Wt(l,typeof o!="symbol"?o+"":o,e),ft=(l,o,e)=>o.has(l)||bt("Cannot "+e);var h=(l,o,e)=>(ft(l,o,"read from private field"),e?e.call(l):o.get(l)),p=(l,o,e)=>o.has(l)?bt("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(l):o.set(l,e),u=(l,o,e,t)=>(ft(l,o,"write to private field"),t?t.call(l,e):o.set(l,e),e);const s=require("lit"),g=require("lit/decorators.js"),Jt=require("lit/directives/repeat.js"),Ht=require("@singlebase/core"),T=require("./files-DyxcjZsx.cjs");if(typeof CSS<"u"&&"registerProperty"in CSS)try{CSS.registerProperty({name:"--sb-ai-angle",syntax:"<angle>",inherits:!1,initialValue:"0deg"})}catch{}const qt=s.css`
1
+ "use strict";var Jt=Object.defineProperty;var xt=l=>{throw TypeError(l)};var qt=(l,o,e)=>o in l?Jt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[o]=e;var I=(l,o,e)=>qt(l,typeof o!="symbol"?o+"":o,e),yt=(l,o,e)=>o.has(l)||xt("Cannot "+e);var d=(l,o,e)=>(yt(l,o,"read from private field"),e?e.call(l):o.get(l)),p=(l,o,e)=>o.has(l)?xt("Cannot add the same private member more than once"):o instanceof WeakSet?o.add(l):o.set(l,e),u=(l,o,e,t)=>(yt(l,o,"write to private field"),t?t.call(l,e):o.set(l,e),e);const i=require("lit"),g=require("lit/decorators.js"),Gt=require("lit/directives/repeat.js"),Vt=require("@singlebase/core"),T=require("./files-4T62wkwj.cjs");if(typeof CSS<"u"&&"registerProperty"in CSS)try{CSS.registerProperty({name:"--sb-ai-angle",syntax:"<angle>",inherits:!1,initialValue:"0deg"})}catch{}const Xt=i.css`
2
2
  :host {
3
3
  --c-ink: var(--sb-ink, #16181a);
4
4
  --c-ink2: var(--sb-ink-2, #41464b);
@@ -2034,6 +2034,11 @@
2034
2034
  min-width: 0;
2035
2035
  }
2036
2036
 
2037
+ .pending-file.kept {
2038
+ background: var(--c-bg);
2039
+ border-style: dashed;
2040
+ }
2041
+
2037
2042
  .pending-file .name {
2038
2043
  max-width: 160px;
2039
2044
  overflow: hidden;
@@ -2429,19 +2434,19 @@
2429
2434
  height: auto;
2430
2435
  }
2431
2436
  }
2432
- `,Nt={eyebrowChat:"Chat",eyebrowRag:"Grounded answers",headingChat:"What can I help with?",headingRag:"Ask your knowledge base",descriptionChat:"Ask anything. Attach text files to give it more context.",descriptionRag:"Answers are grounded in your sources, with a citation for every claim. Attach text files to search them too.",placeholderChat:"Message {name}…",placeholderRag:"Ask about your sources…",footnote:"{name} can make mistakes. Check important details.",attach:"Attach files",send:"Send message",stop:"Stop generating",removeFile:"Remove file",dropTitle:"Drop files to attach",dropSub:"Text, Markdown, CSV and JSON files are added as context.",thinking:"Thinking",searching:"Searching sources",chats:"Chats",newChat:"New chat",searchChats:"Search chats",groupBookmarked:"Bookmarked",groupToday:"Today",groupYesterday:"Yesterday",groupWeek:"Previous 7 days",groupOlder:"Older",noChats:"No chats yet.",noMatch:"No chats match “{query}”.",loadingChats:"Loading chats",showChats:"Show chats",hideSidebar:"Hide sidebar",untitled:"New chat",renameChat:"Rename chat",bookmarkChat:"Bookmark chat",unbookmarkChat:"Remove chat bookmark",exportChat:"Export chat",deleteChat:"Delete chat",expand:"Expand",restore:"Restore size",minimize:"Minimize chat",exportHeading:"Export this chat",exportMarkdown:"Markdown",exportJson:"JSON",exportText:"Plain text",exportCopy:"Copy as Markdown",copy:"Copy",copied:"Copied",edit:"Edit and resend",saveResend:"Save & resend",cancel:"Cancel",regenerate:"Regenerate",helpful:"Helpful",notHelpful:"Not helpful",markedHelpful:"Marked helpful",thanksFeedback:"Thanks for the feedback",bookmarkMessage:"Bookmark message",unbookmarkMessage:"Remove bookmark",deleteMessage:"Delete message",saved:"Saved",stopped:"Stopped",emptyReply:"(empty response)",newReply:"New reply",you:"You",sourcesCited:"Cited sources",sourcesRetrieved:"Sources",searchedSources:"Searched {n} sources",sourceLabel:"Source {n}",openSource:"Open source {n}",citedPassage:"Cited passage",copyReference:"Copy passage with reference",alsoCited:"Also cited",close:"Close",renderingChart:"Rendering chart",renderingSvg:"Rendering drawing",copySvg:"Copy SVG",showRaw:"View raw",showFormatted:"View formatted",showingRows:"Showing {n} of {total} rows",calloutNote:"Note",calloutTip:"Tip",calloutImportant:"Important",calloutWarning:"Warning",calloutCaution:"Caution",undo:"Undo",chatDeleted:"Chat deleted",messageDeleted:"Message deleted",messageBookmarked:"Message bookmarked",bookmarkRemoved:"Bookmark removed",chatBookmarked:"Chat bookmarked",chatUnbookmarked:"Chat removed from bookmarks",exported:"Exported {name}",copiedMarkdown:"Copied as Markdown",fileTooLarge:"{name} is larger than {size}.",fileType:"{name} isn't a text file.",tooManyFiles:"Attach up to {n} files at a time.",errGeneric:"Something went wrong.",errNotFound:"This chat no longer exists. Retry to start a new one.",errNoClient:"Chat isn't connected. Create a SinglebaseClient() on this page.",errLoad:"Couldn't load this chat.",retry:"Retry",offline:"You're offline. Messages will send when you reconnect.",bubbleText:"Hi! Questions? Ask me here.",openChat:"Open chat",closeChat:"Close chat",dismiss:"Dismiss",brandingLabel:"Chat by Singlebase"};function At(l){return{...Nt,...l??{}}}const Gt=/^\|.*\|$/,xt=/^\|[\s:|-]+\|$/,vt=/^!\[([^\]]*)\]\(([^)]*)\)$/,yt=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,wt=/^\[( |x|X)\]\s+/,Vt=/^(-{3,}|\*{3,}|_{3,})$/,Xt=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i,Yt=["note","tip","important","warning","caution"];function Rt(l){const o=[],e=(l??"").replace(/\r/g,"").split("```");return e.forEach((t,i)=>{if(i%2===1){const a=t.indexOf(`
2433
- `),r=(a>-1?t.slice(0,a):t).trim(),n=(a>-1?t.slice(a+1):"").replace(/\n$/,"");o.push(Qt(r,n,i===e.length-1));return}for(const a of t.split(/\n{2,}/))a.trim()&&o.push(...Et(a))}),o}function Qt(l,o,e){const[t="",...i]=l.split(/\s+/),a=t.toLowerCase();if(a==="chart"){const r=e?null:ei(o);return r?{type:"chart",spec:r}:{type:"pending",kind:"chart"}}if(a==="svg")return e||!/<svg[\s>]/i.test(o)?{type:"pending",kind:"svg"}:{type:"svg",source:o.trim()};if(!e&&(a==="csv"||a==="tsv")){const r=Zt(o,a==="tsv"?" ":",");if(r.length>1)return{type:"table",head:r[0],rows:r.slice(1),align:r[0].map(()=>null)}}if(!e&&a==="json")try{return{type:"json",value:JSON.parse(o),source:o}}catch{}if(a==="callout"){const r=(i[0]??"").toLowerCase(),n=Yt.includes(r);return{type:"callout",kind:n?r:"note",title:(n?i.slice(1):i).join(" "),text:o.trim()}}return{type:"code",lang:a||"code",text:o}}function Et(l){const o=l.split(`
2434
- `).filter(i=>i.trim()),e=o.map(i=>i.trim());if(e.length>1&&e.every(i=>Gt.test(i))){const i=c=>c.replace(/^\||\|$/g,"").split("|").map(b=>b.trim()),a=e.findIndex(c=>xt.test(c)),r=a>-1?i(e[a]).map(c=>/^:-+:$/.test(c)?"center":/^-+:$/.test(c)?"right":/^:-+$/.test(c)?"left":null):[],n=e.filter(c=>!xt.test(c)).map(i),d=n[0]??[];return[{type:"table",head:d,rows:n.slice(1),align:d.map((c,b)=>r[b]??null)}]}if(e.length===1&&Vt.test(e[0]))return[{type:"hr"}];if(e.every(i=>vt.test(i)))return[{type:"img",images:e.map(i=>{const a=i.match(vt);return{alt:a[1],src:a[2]}})}];if(e.every(i=>i.startsWith(">"))){const i=e.map(r=>r.replace(/^>\s?/,"")),a=i[0].match(Xt);return a?[{type:"callout",kind:a[1].toLowerCase(),title:a[2].trim(),text:i.slice(1).join(`
2435
- `).trim()}]:[{type:"quote",text:i.join(" ")}]}if(yt.test(o[0])){const i=[];for(const a of o){const r=a.match(yt);if(r){const n=r[3].match(wt);i.push({text:n?r[3].replace(wt,""):r[3],depth:Math.min(3,Math.floor(r[1].replace(/\t/g," ").length/2)),checked:n?n[1]!==" ":null})}else i[i.length-1].text+=` ${a.trim()}`}return[{type:"list",ordered:/^\s*\d/.test(o[0]),items:i}]}const t=e[0].match(/^(#{1,4})\s+(.*)$/);if(t){const i=o.slice(1).join(`
2436
- `);return[{type:"h",level:t[1].length,text:t[2]},...i?Et(i):[]]}return[{type:"p",text:e.join(" ")}]}function Zt(l,o=","){var d;const e=[];let t=[],i="",a=!1;const r=l.replace(/\r/g,"");for(let c=0;c<r.length;c++){const b=r[c];a?b==='"'&&r[c+1]==='"'?(i+='"',c++):b==='"'?a=!1:i+=b:b==='"'&&i===""?a=!0:b===o?(t.push(i.trim()),i=""):b===`
2437
- `?(t.push(i.trim()),t.some(Boolean)&&e.push(t),t=[],i=""):i+=b}t.push(i.trim()),t.some(Boolean)&&e.push(t);const n=((d=e[0])==null?void 0:d.length)??0;return e.map(c=>c.length<n?[...c,...Array(n-c.length).fill("")]:c)}function ei(l){let o;try{o=JSON.parse(l)}catch{return null}if(!o||typeof o!="object")return null;const e=(Array.isArray(o.series)?o.series:[]).filter(i=>i&&Array.isArray(i.values)).map((i,a)=>({name:String(i.name??`Series ${a+1}`),values:i.values.map(r=>Number(r)||0)}));if(!e.length)return null;const t=Array.isArray(o.labels)?o.labels.map(String):e[0].values.map((i,a)=>String(a+1));return{type:o.type==="line"?"line":"bar",title:String(o.title??""),unit:String(o.unit??""),labels:t,series:e}}const kt=new RegExp([/\*\*([^*]+)\*\*/.source,/~~([^~]+)~~/.source,/`([^`]+)`/.source,/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/.source,/(https?:\/\/[^\s<>()]*[^\s<>().,;:!?'"\]])/.source,new RegExp("(?<![\\w*])\\*(?![\\s*])([^*\\n]+?)\\*(?![\\w*])").source,new RegExp("(?<![\\w_])_(?![\\s_])([^_\\n]+?)_(?![\\w_])").source,/\s?\[(\d+(?:\s*,\s*\d+)*)\]/.source].join("|"),"g");function Bt(l,o=0){const e=[];let t=0,i;kt.lastIndex=0;const a=r=>{if(!r)return;const n=e[e.length-1];(n==null?void 0:n.type)==="text"?n.text+=r:e.push({type:"text",text:r})};for(;i=kt.exec(l);){if(a(l.slice(t,i.index)),i[1]!==void 0)e.push({type:"bold",text:i[1]});else if(i[2]!==void 0)e.push({type:"strike",text:i[2]});else if(i[3]!==void 0)e.push({type:"code",text:i[3]});else if(i[4]!==void 0)e.push({type:"link",text:i[4],href:i[5]});else if(i[6]!==void 0)e.push({type:"link",text:i[6],href:i[6]});else if(i[7]!==void 0)e.push({type:"italic",text:i[7]});else if(i[8]!==void 0)e.push({type:"italic",text:i[8]});else{const n=i[9].split(",").map(d=>Number(d.trim())).filter(d=>d>=1&&d<=o);o?n.forEach(d=>e.push({type:"cite",n:d})):a(i[0])}t=i.index+i[0].length}return a(l.slice(t)),e}function Dt(l){if(((l??"").match(/```/g)??[]).length%2===1)return l;const o=l.lastIndexOf(`
2438
-
2439
- `),e=o>-1?l.slice(0,o+2):"";let t=o>-1?l.slice(o+2):l;const i=t.split(`
2440
- `),a=i[i.length-1];a.trimStart().startsWith("|")&&!a.trimEnd().endsWith("|")&&i.pop(),t=i.join(`
2441
- `),t=t.replace(/!?\[[^\]\n]*(\]\([^)\n]*)?$/,"");for(const r of["**","~~","`"])if((t.split(r).length-1)%2===1){const d=t.lastIndexOf(r);t=t.slice(0,d)+t.slice(d+r.length)}return e+t}function ut(l){const o=new Set;for(const e of(l??"").match(/\[(\d+(?:\s*,\s*\d+)*)\]/g)??[])e.replace(/[[\]]/g,"").split(",").forEach(t=>o.add(Number(t.trim())));return o}function ti(l){return[["",...l.series.map(o=>o.name)],...l.labels.map((o,e)=>[o,...l.series.map(t=>t.values[e]===void 0?"":`${t.values[e]}${l.unit}`)])]}const $t=l=>l.map(o=>o.join(" · ")).join(`
2442
- `),ii={note:"Note",tip:"Tip",important:"Important",warning:"Warning",caution:"Caution"};function Ft(l,o){if(o==="rich")return l;const e=o==="plain";return l.map(t=>{switch(t.type){case"chart":{const[i,...a]=ti(t.spec);return e?{type:"raw",text:[t.spec.title,$t([i,...a])].filter(Boolean).join(`
2443
- `)}:{type:"table",head:t.spec.title?[t.spec.title,...i.slice(1)]:i,rows:a,align:i.map(()=>null)}}case"pending":return t.kind==="svg"&&!e?t:{type:"raw",text:""};case"callout":return{type:"quote",text:`**${t.title||ii[t.kind]}** ${t.text}`.trim()};case"img":return{type:"p",text:t.images.map(i=>`Image: ${i.alt||"untitled"}`).join(" · ")};case"table":return e?{type:"raw",text:$t([t.head,...t.rows])}:t;case"json":return e?{type:"code",lang:"json",text:t.source}:t;case"svg":return e?{type:"code",lang:"svg",text:t.source}:t;default:return t}})}function gt(l){const o=l??"",e=o.search(/FOLLOWUPS:/i);if(e<0)return{text:o.trim(),followups:[]};const i=o.slice(e).replace(/^FOLLOWUPS:/i,"").split(/\||\n/).map(a=>a.replace(/^\s*(?:[-*↳→]|\d+[.)])\s*/,"").trim()).filter(Boolean).slice(0,3);return{text:o.slice(0,e).trim(),followups:i}}function si(l){return(l??"").replace(/```(\w*)[\s\S]*?(```|$)/g,(o,e)=>e==="chart"?"[Chart] ":e==="svg"?"[Drawing] ":"[Code] ").replace(/!\[([^\]]*)\]\([^)]*\)/g,"[Image: $1]").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,"$1").replace(/\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/gi,"").replace(/[*#>`~]/g,"").replace(/\|/g," ").replace(/\s?\[\d+(?:\s*,\s*\d+)*\]/g,"").replace(/\s+/g," ").trim()}function ai(l,o=48){const e=si(l);if(e.length<=o)return e;const t=e.slice(0,o),i=t.lastIndexOf(" ");return(i>o/2?t.slice(0,i):t).trim()}function ri(l){return String(l??"").split(`
2444
- `)[0].trim().replace(/^["'“”‘’]+|["'“”‘’]+$/g,"").replace(/^title:\s*/i,"").replace(/[.!?:;,]+$/,"").trim().slice(0,80)}function Ct(l,o=!1){return/^https?:\/\//i.test(l)?!0:o&&/^(blob:|data:image\/)/i.test(l)}const ni=2e5,oi=new Set(["script","foreignobject","iframe","object","embed","image","audio","video","animate","set","animatemotion","animatetransform","handler","listener"]);function Ut(l){if(!l||l.length>ni||typeof DOMParser>"u")return null;const o=new DOMParser().parseFromString(l,"image/svg+xml"),e=o.documentElement;if(!e||e.nodeName.toLowerCase()!=="svg"||o.querySelector("parsererror"))return null;const t=a=>{for(const r of Array.from(a.children)){const n=r.nodeName.toLowerCase();if(oi.has(n))r.remove();else if(n==="a"){const d=Array.from(r.childNodes);r.replaceWith(...d),d.forEach(c=>c instanceof Element&&t(c))}else t(r)}for(const r of Array.from(a.attributes)){const n=r.name.toLowerCase(),d=r.value.trim().toLowerCase(),c=(n==="href"||n.endsWith(":href"))&&!d.startsWith("#"),b=d.includes("javascript:")||/url\(\s*['"]?(?!#)/.test(d);(n.startsWith("on")||c||b)&&a.removeAttribute(r.name)}};t(e);for(const a of Array.from(e.querySelectorAll("style")))a.textContent=(a.textContent??"").replace(/@import[^;]*;?/gi,"").replace(/url\(\s*['"]?(?!#)[^)]*\)/gi,"none");e.setAttribute("xmlns","http://www.w3.org/2000/svg");const i=new XMLSerializer().serializeToString(e);return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(i)}`}var Pt=Object.defineProperty,li=Object.getOwnPropertyDescriptor,ci=(l,o,e)=>o in l?Pt(l,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[o]=e,m=(l,o,e,t)=>{for(var i=t>1?void 0:t?li(o,e):o,a=l.length-1,r;a>=0;a--)(r=l[a])&&(i=(t?r(o,e,i):r(i))||i);return t&&i&&Pt(o,e,i),i},di=(l,o,e)=>ci(l,o+"",e);const St=["embed","mode","format","renderers","beforeSend","afterParse","glow","position","sidebar","showTitle","assistantName","logoUrl","heading","description","eyebrow","prompts","bubbleText","greetingBubble","unreadBadge","allowUpload","allowExport","allowRaw","allowCopy","allowRegenerate","allowBookmark","allowDelete","allowRename","allowFeedback","showTime","showComposer","footnote","brandingText","brandingUrl","branding","followups","showFollowups","showSources","showNewChat","showBookmarked","allowSearch","autoTitle","model","params","systemMessage","retrieval","metadata","messages","theme","radius"],mt={fromAttribute:l=>{if(l)try{return JSON.parse(l)}catch{console.warn("[singlebase-chat] an attribute holds invalid JSON; ignoring it");return}},toAttribute:l=>JSON.stringify(l??null)},S={fromAttribute:l=>l===null?!0:l!=="false",toAttribute:l=>l?null:"false"},hi={fromAttribute:l=>l===null?"auto":l===""||l==="true"?"open":l==="false"?"closed":["auto","open","closed","none"].includes(l)?l:"auto",toAttribute:l=>l==="auto"?null:l},pi=272,ui=820,gi=940,Tt=5,Ot=512*1024,mi=/\.(md|markdown|txt|csv|tsv|json|html?|ya?ml|xml|log)$/i,bi=5e3,fi=200,It=2e3,xi={note:"calloutNote",tip:"calloutTip",important:"calloutImportant",warning:"calloutWarning",caution:"calloutCaution"},vi=2600,_=["var(--c-ink)","oklch(0.58 0.13 255)","oklch(0.63 0.1 175)","oklch(0.74 0.12 70)"],Mt={chat:"Be helpful and concise. Use Markdown when it helps: headings, lists, **bold**, code blocks and tables.",rag:"Answer ONLY from the sources provided with each message, numbered in the order given. Put a citation like [1] right after each claim it supports. If the sources don't cover the question, say so plainly."},yi={raw:"Reply in plain text. Don't use Markdown or any other markup.",plain:"Format with light Markdown only: short paragraphs, lists, **bold**, *italics*, `inline code`, code blocks and links. Don't use tables, charts, callouts, images or other special blocks.",advanced:`You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. Don't use charts, callouts or images.`,rich:'When the answer is about data, lead with one sentence stating the key finding, with key numbers in **bold**, then show the data visually. You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. For trends and comparisons, use a fenced "chart" block containing only JSON: {"type":"bar"|"line","title":string,"unit":string,"labels":[string],"series":[{"name":string,"values":[number]}]}. For notes and warnings, use callouts: a quote starting with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION]. Images use ![alt](https://…).'},wi="After the answer, on a final line write FOLLOWUPS: followed by three short follow-up questions the user might ask next, separated by |.",zt={chat:[["Write","Draft a short welcome email for new users"],["Explain","Explain how refresh tokens work, simply"],["Code","Write a JavaScript debounce function"],["Plan","Outline a one-week plan to learn TypeScript"]],rag:[["Overview","What topics do these sources cover?"],["Summarize","Summarize the most important points"],["Find","Where is the refund policy described?"],["Explain","Explain the setup steps in plain language"]]},I=(l,o="")=>s.html`<svg class="i ${o}" viewBox="0 0 16 16" aria-hidden="true">${l}</svg>`,y={sidebar:()=>I(s.svg`<rect x="2" y="2.5" width="12" height="11" rx="1.5"></rect><path d="M6 2.5v11"></path>`),plus:()=>I(s.svg`<path d="M8 3v10M3 8h10"></path>`),bookmark:(l=!1)=>I(s.svg`<path d="M4.5 2.5h7v11L8 11l-3.5 2.5z"></path>`,l?"filled":""),download:()=>I(s.svg`<path d="M8 2.5v8M4.5 7.5L8 11l3.5-3.5M2.5 13.5h11"></path>`),trash:()=>I(s.svg`<path d="M2.5 4.5h11M6.5 4.5v-2h3v2M4 4.5l.7 9h6.6l.7-9"></path>`),pencil:()=>I(s.svg`<path d="M10.5 2.5l3 3L6 13H3v-3z"></path>`),copy:()=>I(s.svg`<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"></rect><path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2"></path>`),raw:()=>I(s.svg`<path d="M5.5 4.5L2 8l3.5 3.5M10.5 4.5L14 8l-3.5 3.5"></path>`),refresh:()=>I(s.svg`<path d="M13.5 8A5.5 5.5 0 1 1 11.9 4.1M13.5 2v3.5H10"></path>`),thumb:(l=!1)=>s.html`<svg
2437
+ `,Et={eyebrowChat:"Chat",eyebrowRag:"Grounded answers",headingChat:"What can I help with?",headingRag:"Ask your knowledge base",descriptionChat:"Ask anything. Attach text files to give it more context.",descriptionRag:"Answers are grounded in your sources, with a citation for every claim. Attach text files to search them too.",eyebrowKb:"Knowledge base",headingKb:"Ask the knowledge base",descriptionKb:"Answers come only from the knowledge base, with a citation for every claim.",placeholderChat:"Message {name}…",placeholderRag:"Ask about your sources…",placeholderKb:"Ask the knowledge base…",footnote:"{name} can make mistakes. Check important details.",attach:"Attach files",send:"Send message",stop:"Stop generating",removeFile:"Remove file",inThisChat:"In this chat",removeFromChat:"Remove from this chat",attachmentFailed:"Couldn't read {name}.",dropTitle:"Drop files to attach",dropSub:"Text, Markdown, CSV and JSON files are added as context.",thinking:"Thinking",searching:"Searching sources",chats:"Chats",newChat:"New chat",searchChats:"Search chats",groupBookmarked:"Bookmarked",groupToday:"Today",groupYesterday:"Yesterday",groupWeek:"Previous 7 days",groupOlder:"Older",noChats:"No chats yet.",noMatch:"No chats match “{query}”.",loadingChats:"Loading chats",showChats:"Show chats",hideSidebar:"Hide sidebar",untitled:"New chat",renameChat:"Rename chat",bookmarkChat:"Bookmark chat",unbookmarkChat:"Remove chat bookmark",exportChat:"Export chat",deleteChat:"Delete chat",expand:"Expand",restore:"Restore size",minimize:"Minimize chat",exportHeading:"Export this chat",exportMarkdown:"Markdown",exportJson:"JSON",exportText:"Plain text",exportCopy:"Copy as Markdown",copy:"Copy",copied:"Copied",edit:"Edit and resend",saveResend:"Save & resend",cancel:"Cancel",regenerate:"Regenerate",helpful:"Helpful",notHelpful:"Not helpful",markedHelpful:"Marked helpful",thanksFeedback:"Thanks for the feedback",bookmarkMessage:"Bookmark message",unbookmarkMessage:"Remove bookmark",deleteMessage:"Delete message",saved:"Saved",stopped:"Stopped",emptyReply:"(empty response)",newReply:"New reply",you:"You",sourcesCited:"Cited sources",sourcesRetrieved:"Sources",searchedSources:"Searched {n} sources",sourceLabel:"Source {n}",openSource:"Open source {n}",citedPassage:"Cited passage",copyReference:"Copy passage with reference",alsoCited:"Also cited",close:"Close",renderingChart:"Rendering chart",renderingSvg:"Rendering drawing",copySvg:"Copy SVG",showRaw:"View raw",showFormatted:"View formatted",showingRows:"Showing {n} of {total} rows",calloutNote:"Note",calloutTip:"Tip",calloutImportant:"Important",calloutWarning:"Warning",calloutCaution:"Caution",undo:"Undo",chatDeleted:"Chat deleted",messageDeleted:"Message deleted",messageBookmarked:"Message bookmarked",bookmarkRemoved:"Bookmark removed",chatBookmarked:"Chat bookmarked",chatUnbookmarked:"Chat removed from bookmarks",exported:"Exported {name}",copiedMarkdown:"Copied as Markdown",fileTooLarge:"{name} is larger than {size}.",fileType:"{name} isn't a text file.",tooManyFiles:"Attach up to {n} files at a time.",errGeneric:"Something went wrong.",errNotFound:"This chat no longer exists. Retry to start a new one.",errKbSource:"No knowledge base is set up for this chat.",errNoClient:"Chat isn't connected. Create a SinglebaseClient() on this page.",errLoad:"Couldn't load this chat.",retry:"Retry",offline:"You're offline. Messages will send when you reconnect.",bubbleText:"Hi! Questions? Ask me here.",openChat:"Open chat",closeChat:"Close chat",dismiss:"Dismiss"};function Bt(l){return{...Et,...l??{}}}const Yt=/^\|.*\|$/,wt=/^\|[\s:|-]+\|$/,kt=/^!\[([^\]]*)\]\(([^)]*)\)$/,$t=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,Ct=/^\[( |x|X)\]\s+/,Qt=/^(-{3,}|\*{3,}|_{3,})$/,Zt=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i,es=["note","tip","important","warning","caution"];function Dt(l){const o=[],e=(l??"").replace(/\r/g,"").split("```");return e.forEach((t,s)=>{if(s%2===1){const a=t.indexOf(`
2438
+ `),r=(a>-1?t.slice(0,a):t).trim(),n=(a>-1?t.slice(a+1):"").replace(/\n$/,"");o.push(ts(r,n,s===e.length-1));return}for(const a of t.split(/\n{2,}/))a.trim()&&o.push(...Ft(a))}),o}function ts(l,o,e){const[t="",...s]=l.split(/\s+/),a=t.toLowerCase();if(a==="chart"){const r=e?null:is(o);return r?{type:"chart",spec:r}:{type:"pending",kind:"chart"}}if(a==="svg")return e||!/<svg[\s>]/i.test(o)?{type:"pending",kind:"svg"}:{type:"svg",source:o.trim()};if(!e&&(a==="csv"||a==="tsv")){const r=ss(o,a==="tsv"?" ":",");if(r.length>1)return{type:"table",head:r[0],rows:r.slice(1),align:r[0].map(()=>null)}}if(!e&&a==="json")try{return{type:"json",value:JSON.parse(o),source:o}}catch{}if(a==="callout"){const r=(s[0]??"").toLowerCase(),n=es.includes(r);return{type:"callout",kind:n?r:"note",title:(n?s.slice(1):s).join(" "),text:o.trim()}}return{type:"code",lang:a||"code",text:o}}function Ft(l){const o=l.split(`
2439
+ `).filter(s=>s.trim()),e=o.map(s=>s.trim());if(e.length>1&&e.every(s=>Yt.test(s))){const s=c=>c.replace(/^\||\|$/g,"").split("|").map(f=>f.trim()),a=e.findIndex(c=>wt.test(c)),r=a>-1?s(e[a]).map(c=>/^:-+:$/.test(c)?"center":/^-+:$/.test(c)?"right":/^:-+$/.test(c)?"left":null):[],n=e.filter(c=>!wt.test(c)).map(s),h=n[0]??[];return[{type:"table",head:h,rows:n.slice(1),align:h.map((c,f)=>r[f]??null)}]}if(e.length===1&&Qt.test(e[0]))return[{type:"hr"}];if(e.every(s=>kt.test(s)))return[{type:"img",images:e.map(s=>{const a=s.match(kt);return{alt:a[1],src:a[2]}})}];if(e.every(s=>s.startsWith(">"))){const s=e.map(r=>r.replace(/^>\s?/,"")),a=s[0].match(Zt);return a?[{type:"callout",kind:a[1].toLowerCase(),title:a[2].trim(),text:s.slice(1).join(`
2440
+ `).trim()}]:[{type:"quote",text:s.join(" ")}]}if($t.test(o[0])){const s=[];for(const a of o){const r=a.match($t);if(r){const n=r[3].match(Ct);s.push({text:n?r[3].replace(Ct,""):r[3],depth:Math.min(3,Math.floor(r[1].replace(/\t/g," ").length/2)),checked:n?n[1]!==" ":null})}else s[s.length-1].text+=` ${a.trim()}`}return[{type:"list",ordered:/^\s*\d/.test(o[0]),items:s}]}const t=e[0].match(/^(#{1,4})\s+(.*)$/);if(t){const s=o.slice(1).join(`
2441
+ `);return[{type:"h",level:t[1].length,text:t[2]},...s?Ft(s):[]]}return[{type:"p",text:e.join(" ")}]}function ss(l,o=","){var h;const e=[];let t=[],s="",a=!1;const r=l.replace(/\r/g,"");for(let c=0;c<r.length;c++){const f=r[c];a?f==='"'&&r[c+1]==='"'?(s+='"',c++):f==='"'?a=!1:s+=f:f==='"'&&s===""?a=!0:f===o?(t.push(s.trim()),s=""):f===`
2442
+ `?(t.push(s.trim()),t.some(Boolean)&&e.push(t),t=[],s=""):s+=f}t.push(s.trim()),t.some(Boolean)&&e.push(t);const n=((h=e[0])==null?void 0:h.length)??0;return e.map(c=>c.length<n?[...c,...Array(n-c.length).fill("")]:c)}function is(l){let o;try{o=JSON.parse(l)}catch{return null}if(!o||typeof o!="object")return null;const e=(Array.isArray(o.series)?o.series:[]).filter(s=>s&&Array.isArray(s.values)).map((s,a)=>({name:String(s.name??`Series ${a+1}`),values:s.values.map(r=>Number(r)||0)}));if(!e.length)return null;const t=Array.isArray(o.labels)?o.labels.map(String):e[0].values.map((s,a)=>String(a+1));return{type:o.type==="line"?"line":"bar",title:String(o.title??""),unit:String(o.unit??""),labels:t,series:e}}const St=new RegExp([/\*\*([^*]+)\*\*/.source,/~~([^~]+)~~/.source,/`([^`]+)`/.source,/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/.source,/(https?:\/\/[^\s<>()]*[^\s<>().,;:!?'"\]])/.source,new RegExp("(?<![\\w*])\\*(?![\\s*])([^*\\n]+?)\\*(?![\\w*])").source,new RegExp("(?<![\\w_])_(?![\\s_])([^_\\n]+?)_(?![\\w_])").source,/\s?\[(\d+(?:\s*,\s*\d+)*)\]/.source].join("|"),"g");function Kt(l,o=0){const e=[];let t=0,s;St.lastIndex=0;const a=r=>{if(!r)return;const n=e[e.length-1];(n==null?void 0:n.type)==="text"?n.text+=r:e.push({type:"text",text:r})};for(;s=St.exec(l);){if(a(l.slice(t,s.index)),s[1]!==void 0)e.push({type:"bold",text:s[1]});else if(s[2]!==void 0)e.push({type:"strike",text:s[2]});else if(s[3]!==void 0)e.push({type:"code",text:s[3]});else if(s[4]!==void 0)e.push({type:"link",text:s[4],href:s[5]});else if(s[6]!==void 0)e.push({type:"link",text:s[6],href:s[6]});else if(s[7]!==void 0)e.push({type:"italic",text:s[7]});else if(s[8]!==void 0)e.push({type:"italic",text:s[8]});else{const n=s[9].split(",").map(h=>Number(h.trim())).filter(h=>h>=1&&h<=o);o?n.forEach(h=>e.push({type:"cite",n:h})):a(s[0])}t=s.index+s[0].length}return a(l.slice(t)),e}function Pt(l){if(((l??"").match(/```/g)??[]).length%2===1)return l;const o=l.lastIndexOf(`
2443
+
2444
+ `),e=o>-1?l.slice(0,o+2):"";let t=o>-1?l.slice(o+2):l;const s=t.split(`
2445
+ `),a=s[s.length-1];a.trimStart().startsWith("|")&&!a.trimEnd().endsWith("|")&&s.pop(),t=s.join(`
2446
+ `),t=t.replace(/!?\[[^\]\n]*(\]\([^)\n]*)?$/,"");for(const r of["**","~~","`"])if((t.split(r).length-1)%2===1){const h=t.lastIndexOf(r);t=t.slice(0,h)+t.slice(h+r.length)}return e+t}function bt(l){const o=new Set;for(const e of(l??"").match(/\[(\d+(?:\s*,\s*\d+)*)\]/g)??[])e.replace(/[[\]]/g,"").split(",").forEach(t=>o.add(Number(t.trim())));return o}function as(l){return[["",...l.series.map(o=>o.name)],...l.labels.map((o,e)=>[o,...l.series.map(t=>t.values[e]===void 0?"":`${t.values[e]}${l.unit}`)])]}const Tt=l=>l.map(o=>o.join(" · ")).join(`
2447
+ `),rs={note:"Note",tip:"Tip",important:"Important",warning:"Warning",caution:"Caution"};function Ut(l,o){if(o==="rich")return l;const e=o==="plain";return l.map(t=>{switch(t.type){case"chart":{const[s,...a]=as(t.spec);return e?{type:"raw",text:[t.spec.title,Tt([s,...a])].filter(Boolean).join(`
2448
+ `)}:{type:"table",head:t.spec.title?[t.spec.title,...s.slice(1)]:s,rows:a,align:s.map(()=>null)}}case"pending":return t.kind==="svg"&&!e?t:{type:"raw",text:""};case"callout":return{type:"quote",text:`**${t.title||rs[t.kind]}** ${t.text}`.trim()};case"img":return{type:"p",text:t.images.map(s=>`Image: ${s.alt||"untitled"}`).join(" · ")};case"table":return e?{type:"raw",text:Tt([t.head,...t.rows])}:t;case"json":return e?{type:"code",lang:"json",text:t.source}:t;case"svg":return e?{type:"code",lang:"svg",text:t.source}:t;default:return t}})}function ft(l){const o=l??"",e=o.search(/FOLLOWUPS:/i);if(e<0)return{text:o.trim(),followups:[]};const s=o.slice(e).replace(/^FOLLOWUPS:/i,"").split(/\||\n/).map(a=>a.replace(/^\s*(?:[-*↳→]|\d+[.)])\s*/,"").trim()).filter(Boolean).slice(0,3);return{text:o.slice(0,e).trim(),followups:s}}function ns(l){return(l??"").replace(/```(\w*)[\s\S]*?(```|$)/g,(o,e)=>e==="chart"?"[Chart] ":e==="svg"?"[Drawing] ":"[Code] ").replace(/!\[([^\]]*)\]\([^)]*\)/g,"[Image: $1]").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g,"$1").replace(/\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]/gi,"").replace(/[*#>`~]/g,"").replace(/\|/g," ").replace(/\s?\[\d+(?:\s*,\s*\d+)*\]/g,"").replace(/\s+/g," ").trim()}function os(l,o=48){const e=ns(l);if(e.length<=o)return e;const t=e.slice(0,o),s=t.lastIndexOf(" ");return(s>o/2?t.slice(0,s):t).trim()}function ls(l){return String(l??"").split(`
2449
+ `)[0].trim().replace(/^["'“”‘’]+|["'“”‘’]+$/g,"").replace(/^title:\s*/i,"").replace(/[.!?:;,]+$/,"").trim().slice(0,80)}function It(l,o=!1){return/^https?:\/\//i.test(l)?!0:o&&/^(blob:|data:image\/)/i.test(l)}const cs=2e5,hs=new Set(["script","foreignobject","iframe","object","embed","image","audio","video","animate","set","animatemotion","animatetransform","handler","listener"]);function Wt(l){if(!l||l.length>cs||typeof DOMParser>"u")return null;const o=new DOMParser().parseFromString(l,"image/svg+xml"),e=o.documentElement;if(!e||e.nodeName.toLowerCase()!=="svg"||o.querySelector("parsererror"))return null;const t=a=>{for(const r of Array.from(a.children)){const n=r.nodeName.toLowerCase();if(hs.has(n))r.remove();else if(n==="a"){const h=Array.from(r.childNodes);r.replaceWith(...h),h.forEach(c=>c instanceof Element&&t(c))}else t(r)}for(const r of Array.from(a.attributes)){const n=r.name.toLowerCase(),h=r.value.trim().toLowerCase(),c=(n==="href"||n.endsWith(":href"))&&!h.startsWith("#"),f=h.includes("javascript:")||/url\(\s*['"]?(?!#)/.test(h);(n.startsWith("on")||c||f)&&a.removeAttribute(r.name)}};t(e);for(const a of Array.from(e.querySelectorAll("style")))a.textContent=(a.textContent??"").replace(/@import[^;]*;?/gi,"").replace(/url\(\s*['"]?(?!#)[^)]*\)/gi,"none");e.setAttribute("xmlns","http://www.w3.org/2000/svg");const s=new XMLSerializer().serializeToString(e);return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(s)}`}var Ht=Object.defineProperty,ds=Object.getOwnPropertyDescriptor,ps=(l,o,e)=>o in l?Ht(l,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[o]=e,m=(l,o,e,t)=>{for(var s=t>1?void 0:t?ds(o,e):o,a=l.length-1,r;a>=0;a--)(r=l[a])&&(s=(t?r(o,e,s):r(s))||s);return t&&s&&Ht(o,e,s),s},us=(l,o,e)=>ps(l,o+"",e);const Mt=["embed","mode","format","renderers","beforeSend","afterParse","glow","position","sidebar","showTitle","assistantName","logoUrl","heading","description","eyebrow","prompts","bubbleText","greetingBubble","unreadBadge","allowUpload","allowExport","allowRaw","allowCopy","allowRegenerate","allowBookmark","allowDelete","allowRename","allowFeedback","showTime","showComposer","footnote","branding","followups","docsets","attachmentsMode","saveAttachments","showFollowups","showSources","showNewChat","showBookmarked","allowSearch","autoTitle","model","params","systemMessage","retrieval","metadata","messages","theme","radius"],vt={fromAttribute:l=>{if(l)try{return JSON.parse(l)}catch{console.warn("[singlebase-chat] an attribute holds invalid JSON; ignoring it");return}},toAttribute:l=>JSON.stringify(l??null)},S={fromAttribute:l=>l===null?!0:l!=="false",toAttribute:l=>l?null:"false"},gs={fromAttribute:l=>l===null?"auto":l===""||l==="true"?"open":l==="false"?"closed":["auto","open","closed","none"].includes(l)?l:"auto",toAttribute:l=>l==="auto"?null:l},ms=272,bs=820,fs=940,Ot=5,zt=512*1024,vs=/\.(md|markdown|txt|csv|tsv|json|html?|ya?ml|xml|log)$/i,xs=5e3,ys=200,_t=2e3,ws={note:"calloutNote",tip:"calloutTip",important:"calloutImportant",warning:"calloutWarning",caution:"calloutCaution"},ks=2600,_=["var(--c-ink)","oklch(0.58 0.13 255)","oklch(0.63 0.1 175)","oklch(0.74 0.12 70)"],Lt={chat:"Be helpful and concise. Use Markdown when it helps: headings, lists, **bold**, code blocks and tables.",rag:"Prefer the sources provided with each message, numbered in the order given, and put a citation like [1] right after each claim they support. If they don't cover the question, you may answer from general knowledge, but say clearly that it isn't from the sources.",kb:"Answer ONLY from the sources provided with each message, numbered in the order given. Put a citation like [1] right after each claim. Do not use outside knowledge. If the sources don't contain the answer, say that you can't find it in the available sources."},$s={raw:"Reply in plain text. Don't use Markdown or any other markup.",plain:"Format with light Markdown only: short paragraphs, lists, **bold**, *italics*, `inline code`, code blocks and links. Don't use tables, charts, callouts, images or other special blocks.",advanced:`You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. Don't use charts, callouts or images.`,rich:'When the answer is about data, lead with one sentence stating the key finding, with key numbers in **bold**, then show the data visually. You can use Markdown: headings, lists, task lists, **bold**, *italics*, links, code blocks and pipe tables. For data, use a fenced "csv" block or a fenced "json" block. For a diagram or illustration, write a self-contained fenced "svg" block with a viewBox, and no scripts, links or external images. For trends and comparisons, use a fenced "chart" block containing only JSON: {"type":"bar"|"line","title":string,"unit":string,"labels":[string],"series":[{"name":string,"values":[number]}]}. For notes and warnings, use callouts: a quote starting with [!NOTE], [!TIP], [!IMPORTANT], [!WARNING] or [!CAUTION]. Images use ![alt](https://…).'},Cs="After the answer, on a final line write FOLLOWUPS: followed by three short follow-up questions the user might ask next, separated by |.",jt={chat:[["Write","Draft a short welcome email for new users"],["Explain","Explain how refresh tokens work, simply"],["Code","Write a JavaScript debounce function"],["Plan","Outline a one-week plan to learn TypeScript"]],rag:[["Overview","What topics do these sources cover?"],["Summarize","Summarize the most important points"],["Find","Where is the refund policy described?"],["Explain","Explain the setup steps in plain language"]],kb:[["Find","Where is the refund policy described?"],["How to","How do I reset my password?"],["Limits","What are the plan limits?"],["Policy","What happens when my account is deleted?"]]},M=(l,o="")=>i.html`<svg class="i ${o}" viewBox="0 0 16 16" aria-hidden="true">${l}</svg>`,y={sidebar:()=>M(i.svg`<rect x="2" y="2.5" width="12" height="11" rx="1.5"></rect><path d="M6 2.5v11"></path>`),plus:()=>M(i.svg`<path d="M8 3v10M3 8h10"></path>`),bookmark:(l=!1)=>M(i.svg`<path d="M4.5 2.5h7v11L8 11l-3.5 2.5z"></path>`,l?"filled":""),download:()=>M(i.svg`<path d="M8 2.5v8M4.5 7.5L8 11l3.5-3.5M2.5 13.5h11"></path>`),trash:()=>M(i.svg`<path d="M2.5 4.5h11M6.5 4.5v-2h3v2M4 4.5l.7 9h6.6l.7-9"></path>`),pencil:()=>M(i.svg`<path d="M10.5 2.5l3 3L6 13H3v-3z"></path>`),copy:()=>M(i.svg`<rect x="5.5" y="5.5" width="8" height="8" rx="1.5"></rect><path d="M10.5 5.5v-2a1 1 0 0 0-1-1h-6a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2"></path>`),raw:()=>M(i.svg`<path d="M5.5 4.5L2 8l3.5 3.5M10.5 4.5L14 8l-3.5 3.5"></path>`),refresh:()=>M(i.svg`<path d="M13.5 8A5.5 5.5 0 1 1 11.9 4.1M13.5 2v3.5H10"></path>`),thumb:(l=!1)=>i.html`<svg
2445
2450
  class="i"
2446
2451
  viewBox="0 0 16 16"
2447
2452
  aria-hidden="true"
@@ -2450,7 +2455,7 @@
2450
2455
  <path
2451
2456
  d="M5 7v6.5H2.5V7zM5 7l2.5-4.5a1.3 1.3 0 0 1 1.9 1.4L9 6.5h3.6a1 1 0 0 1 1 1.2l-1 4.8a1 1 0 0 1-1 .8H5"
2452
2457
  ></path>
2453
- </svg>`,expand:()=>I(s.svg`<path d="M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9"></path>`),restore:()=>I(s.svg`<path d="M13.5 6.5h-4v-4M9.5 6.5l4-4M2.5 9.5h4v4M6.5 9.5l-4 4"></path>`),minimize:()=>I(s.svg`<path d="M4 8h8"></path>`),close:()=>I(s.svg`<path d="M4 4l8 8M12 4l-8 8"></path>`),clip:()=>I(s.svg`<path d="M13 7.5l-5.3 5.3a3 3 0 0 1-4.3-4.3L9 2.9a2 2 0 0 1 2.9 2.9L6.4 11.3a1 1 0 0 1-1.4-1.4L10 5"></path>`),up:()=>I(s.svg`<path d="M8 13V3M3.5 7.5L8 3l4.5 4.5"></path>`),stop:()=>I(s.svg`<rect x="4.5" y="4.5" width="7" height="7" rx="1"></rect>`),chat:()=>s.html`<svg
2458
+ </svg>`,expand:()=>M(i.svg`<path d="M9.5 2.5h4v4M13.5 2.5L9 7M6.5 13.5h-4v-4M2.5 13.5L7 9"></path>`),restore:()=>M(i.svg`<path d="M13.5 6.5h-4v-4M9.5 6.5l4-4M2.5 9.5h4v4M6.5 9.5l-4 4"></path>`),minimize:()=>M(i.svg`<path d="M4 8h8"></path>`),close:()=>M(i.svg`<path d="M4 4l8 8M12 4l-8 8"></path>`),clip:()=>M(i.svg`<path d="M13 7.5l-5.3 5.3a3 3 0 0 1-4.3-4.3L9 2.9a2 2 0 0 1 2.9 2.9L6.4 11.3a1 1 0 0 1-1.4-1.4L10 5"></path>`),up:()=>M(i.svg`<path d="M8 13V3M3.5 7.5L8 3l4.5 4.5"></path>`),stop:()=>M(i.svg`<rect x="4.5" y="4.5" width="7" height="7" rx="1"></rect>`),chat:()=>i.html`<svg
2454
2459
  width="22"
2455
2460
  height="22"
2456
2461
  viewBox="0 0 22 22"
@@ -2460,7 +2465,7 @@
2460
2465
  <path
2461
2466
  d="M4 5.5A2.5 2.5 0 0 1 6.5 3h9A2.5 2.5 0 0 1 18 5.5v7a2.5 2.5 0 0 1-2.5 2.5H9l-4 3.5V15H6.5"
2462
2467
  ></path>
2463
- </svg>`,chevronDown:()=>s.html`<svg
2468
+ </svg>`,chevronDown:()=>i.html`<svg
2464
2469
  width="20"
2465
2470
  height="20"
2466
2471
  viewBox="0 0 20 20"
@@ -2468,19 +2473,19 @@
2468
2473
  style="fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round"
2469
2474
  >
2470
2475
  <path d="M5 8l5 5 5-5"></path>
2471
- </svg>`};let ki=0;const pt=()=>`m${Date.now().toString(36)}${(ki++).toString(36)}`;function _t(l){var e;const o=l;return(o==null?void 0:o.message)==="NOT_FOUND"||(o==null?void 0:o.code)==="NOT_FOUND"||((e=o==null?void 0:o.details)==null?void 0:e.status)===404}function $i(l){const o=l;return(o==null?void 0:o.code)||(o==null?void 0:o.message)||"UNKNOWN"}const Ci=()=>typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches,ht=(l,o)=>(Number.isInteger(l)?l.toLocaleString("en-US"):l.toFixed(1))+o,Lt=l=>{const o=l.lastIndexOf(".");return o>0?l.slice(o+1,o+5).toUpperCase():"FILE"};function L(l,o){const e=l??{},t=e.metadata&&typeof e.metadata=="object"?e.metadata:{},i=(...n)=>n.find(d=>typeof d=="string"&&d.trim()),a=i(e.content,e.text,e.page_content,e.body,e.snippet,e.chunk,t.content)??JSON.stringify(e,null,2),r=[e.score,e.relevance,e._score,t.score].find(n=>typeof n=="number");return{n:o,title:i(e.title,e.name,e.filename,t.title,t.name)??`Source ${o}`,path:i(e.path,e.url,e.key,e.source,t.path,t.url)??"",collection:i(e.collection,e.namespace,e.dbname,t.collection)??"",updated:i(e.updated,e._modified_at,t.updated)??"",text:a,score:r===void 0?null:Math.max(0,Math.min(1,r))}}function Si(l){const o=[],e=[];for(const t of l)if(/\.csv$/i.test(t.name))o.push({type:"csv",data:t.content});else if(/\.json$/i.test(t.name))try{o.push({type:"json",data:JSON.parse(t.content)})}catch{e.push({title:t.name,content:t.content})}else e.push({title:t.name,content:t.content});return e.length&&o.push({type:"docs",payload:{documents:e}}),o}function Ti(l){const o=l?Date.parse(l):NaN;if(Number.isNaN(o))return"older";const e=new Date;e.setHours(0,0,0,0);const t=864e5;return o>=e.getTime()?"today":o>=e.getTime()-t?"yesterday":o>=e.getTime()-7*t?"week":"older"}var j,N,A,R,E,B,D,F,U,P,K,W,J,H,q,G,V,X,Y,Q,Z,ee,te,ie,se,ae,re,ne,oe,le,ce,de,he,pe,ue,ge,me,be,fe,xe,ve,ye,we,ke,$e,Ce,Se,Te,Oe,Ie,Me,ze,_e,Le,je,Ne,Ae,Re,Ee,Be,De,Fe,Ue,Pe,Ke,We,Je,He,qe,Ge,Ve,Xe,Ye,Qe,Ze,et,tt,it,st,at,rt,nt,ot,lt,ct,dt,jt;exports.SinglebaseChat=(jt=class extends s.LitElement{constructor(){super(...arguments);p(this,j,null);p(this,N,{});p(this,A);p(this,R);p(this,E,"chat");p(this,B,"advanced");p(this,D,{});p(this,F,null);p(this,U,null);p(this,P,"subtle");p(this,K,!0);p(this,W,!0);p(this,J,!0);p(this,H,!0);p(this,q,!0);p(this,G,!0);p(this,V,!0);p(this,X,"");p(this,Y,{});p(this,Q,"");p(this,Z,[]);p(this,ee,{});p(this,te,"page");p(this,ie,"right");p(this,se,"auto");p(this,ae,!0);p(this,re,"");p(this,ne,"Assistant");p(this,oe,"");p(this,le,"");p(this,ce,"");p(this,de);p(this,he,"");p(this,pe,"");p(this,ue,!1);p(this,ge,!1);p(this,me,!0);p(this,be,!0);p(this,fe,!0);p(this,xe,!0);p(this,ve,!0);p(this,ye,!0);p(this,we,!0);p(this,ke,!0);p(this,$e,!0);p(this,Ce,!0);p(this,Se);p(this,Te,!1);p(this,Oe,!0);p(this,Ie,"");p(this,Me,"");p(this,ze,[]);p(this,_e,"idle");p(this,Le,null);p(this,je,"");p(this,Ne,!1);p(this,Ae,[]);p(this,Re,!1);p(this,Ee,"");p(this,Be,!1);p(this,De,"");p(this,Fe,[]);p(this,Ue,"");p(this,Pe,null);p(this,Ke,0);p(this,We,null);p(this,Je,!1);p(this,He,"");p(this,qe,"");p(this,Ge,!1);p(this,Ve,"");p(this,Xe,null);p(this,Ye,"");p(this,Qe,new Set);p(this,Ze,new Set);p(this,et,!1);p(this,tt,new Map);p(this,it,"");p(this,st,!1);p(this,at,!1);p(this,rt,!1);p(this,nt,!1);p(this,ot,!1);p(this,lt,!1);p(this,ct,!1);p(this,dt,!1);O(this,"run",0);O(this,"abort",null);O(this,"revealTimer");O(this,"timers",new Set);O(this,"toastTimer");O(this,"stick",!0);O(this,"renamed",new Set);O(this,"observer",null);O(this,"observed",null);O(this,"media",null);O(this,"focusNext","");O(this,"bubbleScheduled",!1);O(this,"pendingChatId","");O(this,"onNetwork",()=>{this.offline=navigator.onLine===!1});O(this,"onMedia",()=>{var e;this.mobile=!!((e=this.media)!=null&&e.matches)})}get client(){return h(this,j)}set client(e){u(this,j,e)}get messages(){return h(this,N)}set messages(e){u(this,N,e)}get theme(){return h(this,A)}set theme(e){u(this,A,e)}get radius(){return h(this,R)}set radius(e){u(this,R,e)}get mode(){return h(this,E)}set mode(e){u(this,E,e)}get format(){return h(this,B)}set format(e){u(this,B,e)}get renderers(){return h(this,D)}set renderers(e){u(this,D,e)}get beforeSend(){return h(this,F)}set beforeSend(e){u(this,F,e)}get afterParse(){return h(this,U)}set afterParse(e){u(this,U,e)}get glow(){return h(this,P)}set glow(e){u(this,P,e)}get followups(){return h(this,K)}set followups(e){u(this,K,e)}get showSources(){return h(this,W)}set showSources(e){u(this,W,e)}get showNewChat(){return h(this,J)}set showNewChat(e){u(this,J,e)}get showBookmarked(){return h(this,H)}set showBookmarked(e){u(this,H,e)}get showFollowups(){return h(this,q)}set showFollowups(e){u(this,q,e)}get allowSearch(){return h(this,G)}set allowSearch(e){u(this,G,e)}get autoTitle(){return h(this,V)}set autoTitle(e){u(this,V,e)}get model(){return h(this,X)}set model(e){u(this,X,e)}get params(){return h(this,Y)}set params(e){u(this,Y,e)}get systemMessage(){return h(this,Q)}set systemMessage(e){u(this,Q,e)}get retrieval(){return h(this,Z)}set retrieval(e){u(this,Z,e)}get metadata(){return h(this,ee)}set metadata(e){u(this,ee,e)}get embed(){return h(this,te)}set embed(e){u(this,te,e)}get position(){return h(this,ie)}set position(e){u(this,ie,e)}get sidebar(){return h(this,se)}set sidebar(e){u(this,se,e)}get showTitle(){return h(this,ae)}set showTitle(e){u(this,ae,e)}get chatIdAttr(){return h(this,re)}set chatIdAttr(e){u(this,re,e)}get assistantName(){return h(this,ne)}set assistantName(e){u(this,ne,e)}get logoUrl(){return h(this,oe)}set logoUrl(e){u(this,oe,e)}get heading(){return h(this,le)}set heading(e){u(this,le,e)}get description(){return h(this,ce)}set description(e){u(this,ce,e)}get eyebrow(){return h(this,de)}set eyebrow(e){u(this,de,e)}get prompts(){return h(this,he)}set prompts(e){u(this,he,e)}get bubbleText(){return h(this,pe)}set bubbleText(e){u(this,pe,e)}get greetingBubble(){return h(this,ue)}set greetingBubble(e){u(this,ue,e)}get unreadBadge(){return h(this,ge)}set unreadBadge(e){u(this,ge,e)}get allowUpload(){return h(this,me)}set allowUpload(e){u(this,me,e)}get allowExport(){return h(this,be)}set allowExport(e){u(this,be,e)}get allowCopy(){return h(this,fe)}set allowCopy(e){u(this,fe,e)}get allowRegenerate(){return h(this,xe)}set allowRegenerate(e){u(this,xe,e)}get allowBookmark(){return h(this,ve)}set allowBookmark(e){u(this,ve,e)}get allowDelete(){return h(this,ye)}set allowDelete(e){u(this,ye,e)}get allowRename(){return h(this,we)}set allowRename(e){u(this,we,e)}get allowFeedback(){return h(this,ke)}set allowFeedback(e){u(this,ke,e)}get showComposer(){return h(this,$e)}set showComposer(e){u(this,$e,e)}get showTime(){return h(this,Ce)}set showTime(e){u(this,Ce,e)}get footnote(){return h(this,Se)}set footnote(e){u(this,Se,e)}get allowRaw(){return h(this,Te)}set allowRaw(e){u(this,Te,e)}get branding(){return h(this,Oe)}set branding(e){u(this,Oe,e)}get brandingText(){return h(this,Ie)}set brandingText(e){u(this,Ie,e)}get brandingUrl(){return h(this,Me)}set brandingUrl(e){u(this,Me,e)}get chatList(){return h(this,ze)}set chatList(e){u(this,ze,e)}get listState(){return h(this,_e)}set listState(e){u(this,_e,e)}get activeId(){return h(this,Le)}set activeId(e){u(this,Le,e)}get chatTitle(){return h(this,je)}set chatTitle(e){u(this,je,e)}get bookmarked(){return h(this,Ne)}set bookmarked(e){u(this,Ne,e)}get msgs(){return h(this,Ae)}set msgs(e){u(this,Ae,e)}get loadingThread(){return h(this,Re)}set loadingThread(e){u(this,Re,e)}get threadError(){return h(this,Ee)}set threadError(e){u(this,Ee,e)}get busy(){return h(this,Be)}set busy(e){u(this,Be,e)}get draft(){return h(this,De)}set draft(e){u(this,De,e)}get files(){return h(this,Fe)}set files(e){u(this,Fe,e)}get search(){return h(this,Ue)}set search(e){u(this,Ue,e)}get sidebarOpen(){return h(this,Pe)}set sidebarOpen(e){u(this,Pe,e)}get width(){return h(this,Ke)}set width(e){u(this,Ke,e)}get panel(){return h(this,We)}set panel(e){u(this,We,e)}get menuOpen(){return h(this,Je)}set menuOpen(e){u(this,Je,e)}get editingKey(){return h(this,He)}set editingKey(e){u(this,He,e)}get editDraft(){return h(this,qe)}set editDraft(e){u(this,qe,e)}get editingTitle(){return h(this,Ge)}set editingTitle(e){u(this,Ge,e)}get renamingId(){return h(this,Ve)}set renamingId(e){u(this,Ve,e)}get toast(){return h(this,Xe)}set toast(e){u(this,Xe,e)}get copiedKey(){return h(this,Ye)}set copiedKey(e){u(this,Ye,e)}get retrievalOpen(){return h(this,Qe)}set retrievalOpen(e){u(this,Qe,e)}get rawKeys(){return h(this,Ze)}set rawKeys(e){u(this,Ze,e)}get hasSidebarContent(){return h(this,et)}set hasSidebarContent(e){u(this,et,e)}get sorts(){return h(this,tt)}set sorts(e){u(this,tt,e)}get arrivedKey(){return h(this,it)}set arrivedKey(e){u(this,it,e)}get dragging(){return h(this,st)}set dragging(e){u(this,st,e)}get showJump(){return h(this,at)}set showJump(e){u(this,at,e)}get offline(){return h(this,rt)}set offline(e){u(this,rt,e)}get isOpen(){return h(this,nt)}set isOpen(e){u(this,nt,e)}get expanded(){return h(this,ot)}set expanded(e){u(this,ot,e)}get bubble(){return h(this,lt)}set bubble(e){u(this,lt,e)}get seen(){return h(this,ct)}set seen(e){u(this,ct,e)}get mobile(){return h(this,dt)}set mobile(e){u(this,dt,e)}get msg(){return At(this.messages)}get resolvedClient(){return this.client??Ht.getDefaultClient()??null}get chatId(){return this.activeId}get thread(){return this.msgs}get formatLevel(){return["raw","plain","advanced","rich"].includes(this.format)?this.format:"advanced"}get chats(){return this.chatList}set config(e){if(!e)return;const t=this;"client"in e&&(this.client=e.client??null);for(const i of St)i in e&&(t[i]=e[i]);e.chatId&&e.chatId!==this.activeId&&(this.hasUpdated?this.openChat(e.chatId):this.chatIdAttr=e.chatId)}configure(e){return this.config=e,this}get config(){const e=this;return{client:this.client,chatId:this.activeId??"",...Object.fromEntries(St.map(t=>[t,e[t]]))}}connectedCallback(){var e,t;super.connectedCallback(),this.offline=typeof navigator<"u"&&navigator.onLine===!1,window.addEventListener("online",this.onNetwork),window.addEventListener("offline",this.onNetwork),this.media=typeof matchMedia<"u"?matchMedia("(max-width: 559px)"):null,this.mobile=!!((e=this.media)!=null&&e.matches),(t=this.media)==null||t.addEventListener("change",this.onMedia)}disconnectedCallback(){var e,t;super.disconnectedCallback(),window.removeEventListener("online",this.onNetwork),window.removeEventListener("offline",this.onNetwork),(e=this.media)==null||e.removeEventListener("change",this.onMedia),(t=this.observer)==null||t.disconnect(),this.observer=null,this.observed=null,this.flushToast(),this.halt(),this.timers.forEach(clearTimeout),this.timers.clear()}willUpdate(e){if(e.has("retrieval")&&!Array.isArray(this.retrieval)){const t=this.retrieval;this.retrieval=t&&typeof t=="object"?[t]:[]}e.has("params")&&(!this.params||typeof this.params!="object")&&(this.params={}),e.has("metadata")&&(!this.metadata||typeof this.metadata!="object")&&(this.metadata={}),e.has("sidebar")&&(this.sidebar==="open"?this.sidebarOpen=!0:this.sidebar==="closed"||this.sidebar==="none"?this.sidebarOpen=!1:this.width&&(this.sidebarOpen=this.docked)),this.embed==="launcher"&&this.greetingBubble&&!this.bubbleScheduled&&(this.bubbleScheduled=!0,this.later(()=>{!this.isOpen&&!this.seen&&(this.bubble=!0)},1200))}firstUpdated(){this.chatIdAttr&&this.openChat(this.chatIdAttr)}updated(){var t;const e=this.renderRoot.querySelector(".root");if(e!==this.observed&&((t=this.observer)==null||t.disconnect(),this.observed=e,e&&typeof ResizeObserver<"u"&&(this.observer??(this.observer=new ResizeObserver(([i])=>{const a=Math.round(i.contentRect.width);a!==this.width&&(this.width=a,this.sidebarOpen===null&&(this.sidebarOpen=this.sidebar==="auto"&&this.docked))})),this.observer.observe(e))),this.sidebarOpen&&this.listState==="idle"&&this.resolvedClient&&this.loadChats(),this.pendingChatId&&this.resolvedClient&&this.openChat(this.pendingChatId),this.focusNext){const i=this.renderRoot.querySelector(this.focusNext);this.focusNext="",i&&(i.focus(),"select"in i&&i.tagName==="INPUT"&&i.select())}}later(e,t){const i=setTimeout(()=>{this.timers.delete(i),e()},t);this.timers.add(i)}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}get docked(){return this.embed==="page"&&this.width>=ui}get panelDocked(){const e=this.docked&&this.sidebarOpen?pi:0;return this.width-e>=gi}newChat(){this.halt(),this.pendingChatId="",this.loadingThread=!1,this.activeId=null,this.chatTitle="",this.bookmarked=!1,this.msgs=[],this.threadError="",this.resetViewState(),this.focusNext="textarea.input"}async openChat(e){const t=this.resolvedClient;if(!e)return;this.halt();const i=this.chatList.find(r=>r._id===e);if(this.activeId=e,this.chatTitle=(i==null?void 0:i.title)??"",this.bookmarked=!!(i!=null&&i.bookmarked),this.msgs=[],this.threadError="",this.resetViewState(),!t){this.pendingChatId=e,this.loadingThread=!0;return}const a=++this.run;this.pendingChatId="",this.loadingThread=!0;try{const r=await t.llm.call("get_chat",{_id:e});if(a!==this.run)return;this.chatTitle=(r==null?void 0:r.title)??"",this.bookmarked=!!(r!=null&&r.bookmarked),this.msgs=((r==null?void 0:r.messages)??[]).filter(n=>n&&(n.role==="user"||n.role==="assistant")).map(n=>this.fromServer(n)),this.upsertChat({...i,...r,_id:e}),this.stick=!0,this.scrollToBottom()}catch(r){if(a!==this.run)return;_t(r)?(this.chatList=this.chatList.filter(n=>n._id!==e),this.newChat(),this.showToast(this.msg.errNotFound)):this.threadError=this.msg.errLoad}finally{a===this.run&&(this.loadingThread=!1)}}async send(e){const t=(typeof e=="string"?e:this.draft).trim();if(!t||this.busy)return;const i=this.files;this.draft="",this.files=[];const a=this.renderRoot.querySelector("textarea.input");a&&(a.style.height="auto"),await this.runTurn(this.userMessage(t,i))}stop(){if(!this.busy)return;const e=this.msgs[this.msgs.length-1];this.halt(),(e==null?void 0:e.role)==="assistant"&&(e.phase==="pending"||e.phase==="streaming")&&(e.phase="done",e.stopped=!0,e.followups=[],this.msgs=[...this.msgs])}exportChat(e="md"){var M;if(!this.msgs.length)return;this.menuOpen=!1;const t=this.chatTitle||this.msg.untitled,i=x=>x.role==="user"?this.msg.you:this.assistantName,a=x=>new Date(x||Date.now()).toLocaleString(),r=x=>x.sources.map(($,w)=>{const z=L($,w+1);return`[${z.n}] ${z.title}${z.path?` — ${z.path}`:""}`}),n=x=>(x.attachments??[]).map($=>$.name);let d,c="text/markdown",b="md";if(e==="json"?(d=JSON.stringify({exportedAt:new Date().toISOString(),id:this.activeId,title:t,mode:this.mode,bookmarked:this.bookmarked,messages:this.msgs.map(x=>({role:x.role,text:x.content,at:new Date(x.at||Date.now()).toISOString(),bookmarked:x.bookmarked,attachments:n(x),sources:r(x)}))},null,2),c="application/json",b="json"):e==="txt"?(d=`${t}
2476
+ </svg>`};let Ss=0;const gt=()=>`m${Date.now().toString(36)}${(Ss++).toString(36)}`;function At(l){var e;const o=l;return(o==null?void 0:o.message)==="NOT_FOUND"||(o==null?void 0:o.code)==="NOT_FOUND"||((e=o==null?void 0:o.details)==null?void 0:e.status)===404}function Ts(l){const o=l;return(o==null?void 0:o.code)||(o==null?void 0:o.message)||"UNKNOWN"}const Is=()=>typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches,ut=(l,o)=>(Number.isInteger(l)?l.toLocaleString("en-US"):l.toFixed(1))+o,mt=l=>{const o=l.lastIndexOf(".");return o>0?l.slice(o+1,o+5).toUpperCase():"FILE"};function L(l,o){const e=l??{},t=e.metadata&&typeof e.metadata=="object"?e.metadata:{},s=(...h)=>h.find(c=>typeof c=="string"&&c.trim()),a=s(e.content,e.text,e.page_content,e.body,e.snippet,e.chunk,t.content)??JSON.stringify(e,null,2),r=[e.score,e.relevance,e._score,t.score].find(h=>typeof h=="number"),n=typeof e.n=="number"&&e.n>0?e.n:o;return{n,title:s(e.title,e.name,e.filename,t.title,t.name)??`Source ${n}`,section:s(e.section,e.heading,t.section)??"",path:s(e.path,e.url,e.key,t.path,t.url)??"",collection:s(e.collection,e.namespace,e.dbname,t.collection)??"",updated:s(e.updated,e._modified_at,t.updated)??"",text:a,score:r===void 0?null:Math.max(0,Math.min(1,r))}}function Nt(l){return Array.isArray(l)?l.filter(o=>o&&typeof o=="object"&&(o._id||o.id)).filter(o=>o.saved!==!1&&o.status!=="failed").map(o=>({id:String(o._id??o.id),name:String(o.name??"file"),type:o.type,mime:o.mime,size:typeof o.size=="number"?o.size:void 0,status:o.status})):[]}function Ms(l){const o=[],e=[];for(const t of l)if(/\.csv$/i.test(t.name))o.push({source:"csv",data:t.content});else if(/\.json$/i.test(t.name))try{o.push({source:"json",data:JSON.parse(t.content)})}catch{e.push({title:t.name,content:t.content})}else e.push({title:t.name,content:t.content});return e.length&&o.push({source:"docs",payload:{documents:e}}),o}function Os(l){const o=l?Date.parse(l):NaN;if(Number.isNaN(o))return"older";const e=new Date;e.setHours(0,0,0,0);const t=864e5;return o>=e.getTime()?"today":o>=e.getTime()-t?"yesterday":o>=e.getTime()-7*t?"week":"older"}var j,A,N,R,E,B,D,F,K,P,U,W,H,J,q,G,V,X,Y,Q,Z,ee,te,se,ie,ae,re,ne,oe,le,ce,he,de,pe,ue,ge,me,be,fe,ve,xe,ye,we,ke,$e,Ce,Se,Te,Ie,Me,Oe,ze,_e,Le,je,Ae,Ne,Re,Ee,Be,De,Fe,Ke,Pe,Ue,We,He,Je,qe,Ge,Ve,Xe,Ye,Qe,Ze,et,tt,st,it,at,rt,nt,ot,lt,ct,ht,dt,pt,Rt;exports.SinglebaseChat=(Rt=class extends i.LitElement{constructor(){super(...arguments);p(this,j,null);p(this,A,{});p(this,N);p(this,R);p(this,E,"chat");p(this,B,"advanced");p(this,D,{});p(this,F,null);p(this,K,null);p(this,P,"subtle");p(this,U,"");p(this,W,"payload");p(this,H,!0);p(this,J,!0);p(this,q,!0);p(this,G,!0);p(this,V,!0);p(this,X,!0);p(this,Y,!0);p(this,Q,!0);p(this,Z,"");p(this,ee,{});p(this,te,"");p(this,se,[]);p(this,ie,{});p(this,ae,"page");p(this,re,"right");p(this,ne,"auto");p(this,oe,!0);p(this,le,"");p(this,ce,"Assistant");p(this,he,"");p(this,de,"");p(this,pe,"");p(this,ue);p(this,ge,"");p(this,me,"");p(this,be,!1);p(this,fe,!1);p(this,ve,!0);p(this,xe,!0);p(this,ye,!0);p(this,we,!0);p(this,ke,!0);p(this,$e,!0);p(this,Ce,!0);p(this,Se,!0);p(this,Te,!0);p(this,Ie,!0);p(this,Me);p(this,Oe,!1);p(this,ze,!0);p(this,_e,[]);p(this,Le,"idle");p(this,je,null);p(this,Ae,"");p(this,Ne,!1);p(this,Re,[]);p(this,Ee,!1);p(this,Be,"");p(this,De,!1);p(this,Fe,"");p(this,Ke,[]);p(this,Pe,"");p(this,Ue,null);p(this,We,0);p(this,He,null);p(this,Je,!1);p(this,qe,"");p(this,Ge,"");p(this,Ve,!1);p(this,Xe,"");p(this,Ye,null);p(this,Qe,"");p(this,Ze,new Set);p(this,et,new Set);p(this,tt,[]);p(this,st,!1);p(this,it,new Map);p(this,at,"");p(this,rt,!1);p(this,nt,!1);p(this,ot,!1);p(this,lt,!1);p(this,ct,!1);p(this,ht,!1);p(this,dt,!1);p(this,pt,!1);I(this,"run",0);I(this,"abort",null);I(this,"revealTimer");I(this,"timers",new Set);I(this,"toastTimer");I(this,"stick",!0);I(this,"renamed",new Set);I(this,"observer",null);I(this,"observed",null);I(this,"media",null);I(this,"focusNext","");I(this,"bubbleScheduled",!1);I(this,"pendingChatId","");I(this,"onNetwork",()=>{this.offline=navigator.onLine===!1});I(this,"onMedia",()=>{var e;this.mobile=!!((e=this.media)!=null&&e.matches)})}get client(){return d(this,j)}set client(e){u(this,j,e)}get messages(){return d(this,A)}set messages(e){u(this,A,e)}get theme(){return d(this,N)}set theme(e){u(this,N,e)}get radius(){return d(this,R)}set radius(e){u(this,R,e)}get mode(){return d(this,E)}set mode(e){u(this,E,e)}get format(){return d(this,B)}set format(e){u(this,B,e)}get renderers(){return d(this,D)}set renderers(e){u(this,D,e)}get beforeSend(){return d(this,F)}set beforeSend(e){u(this,F,e)}get afterParse(){return d(this,K)}set afterParse(e){u(this,K,e)}get glow(){return d(this,P)}set glow(e){u(this,P,e)}get docsets(){return d(this,U)}set docsets(e){u(this,U,e)}get attachmentsMode(){return d(this,W)}set attachmentsMode(e){u(this,W,e)}get saveAttachments(){return d(this,H)}set saveAttachments(e){u(this,H,e)}get followups(){return d(this,J)}set followups(e){u(this,J,e)}get showSources(){return d(this,q)}set showSources(e){u(this,q,e)}get showNewChat(){return d(this,G)}set showNewChat(e){u(this,G,e)}get showBookmarked(){return d(this,V)}set showBookmarked(e){u(this,V,e)}get showFollowups(){return d(this,X)}set showFollowups(e){u(this,X,e)}get allowSearch(){return d(this,Y)}set allowSearch(e){u(this,Y,e)}get autoTitle(){return d(this,Q)}set autoTitle(e){u(this,Q,e)}get model(){return d(this,Z)}set model(e){u(this,Z,e)}get params(){return d(this,ee)}set params(e){u(this,ee,e)}get systemMessage(){return d(this,te)}set systemMessage(e){u(this,te,e)}get retrieval(){return d(this,se)}set retrieval(e){u(this,se,e)}get metadata(){return d(this,ie)}set metadata(e){u(this,ie,e)}get embed(){return d(this,ae)}set embed(e){u(this,ae,e)}get position(){return d(this,re)}set position(e){u(this,re,e)}get sidebar(){return d(this,ne)}set sidebar(e){u(this,ne,e)}get showTitle(){return d(this,oe)}set showTitle(e){u(this,oe,e)}get chatIdAttr(){return d(this,le)}set chatIdAttr(e){u(this,le,e)}get assistantName(){return d(this,ce)}set assistantName(e){u(this,ce,e)}get logoUrl(){return d(this,he)}set logoUrl(e){u(this,he,e)}get heading(){return d(this,de)}set heading(e){u(this,de,e)}get description(){return d(this,pe)}set description(e){u(this,pe,e)}get eyebrow(){return d(this,ue)}set eyebrow(e){u(this,ue,e)}get prompts(){return d(this,ge)}set prompts(e){u(this,ge,e)}get bubbleText(){return d(this,me)}set bubbleText(e){u(this,me,e)}get greetingBubble(){return d(this,be)}set greetingBubble(e){u(this,be,e)}get unreadBadge(){return d(this,fe)}set unreadBadge(e){u(this,fe,e)}get allowUpload(){return d(this,ve)}set allowUpload(e){u(this,ve,e)}get allowExport(){return d(this,xe)}set allowExport(e){u(this,xe,e)}get allowCopy(){return d(this,ye)}set allowCopy(e){u(this,ye,e)}get allowRegenerate(){return d(this,we)}set allowRegenerate(e){u(this,we,e)}get allowBookmark(){return d(this,ke)}set allowBookmark(e){u(this,ke,e)}get allowDelete(){return d(this,$e)}set allowDelete(e){u(this,$e,e)}get allowRename(){return d(this,Ce)}set allowRename(e){u(this,Ce,e)}get allowFeedback(){return d(this,Se)}set allowFeedback(e){u(this,Se,e)}get showComposer(){return d(this,Te)}set showComposer(e){u(this,Te,e)}get showTime(){return d(this,Ie)}set showTime(e){u(this,Ie,e)}get footnote(){return d(this,Me)}set footnote(e){u(this,Me,e)}get allowRaw(){return d(this,Oe)}set allowRaw(e){u(this,Oe,e)}get branding(){return d(this,ze)}set branding(e){u(this,ze,e)}get chatList(){return d(this,_e)}set chatList(e){u(this,_e,e)}get listState(){return d(this,Le)}set listState(e){u(this,Le,e)}get activeId(){return d(this,je)}set activeId(e){u(this,je,e)}get chatTitle(){return d(this,Ae)}set chatTitle(e){u(this,Ae,e)}get bookmarked(){return d(this,Ne)}set bookmarked(e){u(this,Ne,e)}get msgs(){return d(this,Re)}set msgs(e){u(this,Re,e)}get loadingThread(){return d(this,Ee)}set loadingThread(e){u(this,Ee,e)}get threadError(){return d(this,Be)}set threadError(e){u(this,Be,e)}get busy(){return d(this,De)}set busy(e){u(this,De,e)}get draft(){return d(this,Fe)}set draft(e){u(this,Fe,e)}get files(){return d(this,Ke)}set files(e){u(this,Ke,e)}get search(){return d(this,Pe)}set search(e){u(this,Pe,e)}get sidebarOpen(){return d(this,Ue)}set sidebarOpen(e){u(this,Ue,e)}get width(){return d(this,We)}set width(e){u(this,We,e)}get panel(){return d(this,He)}set panel(e){u(this,He,e)}get menuOpen(){return d(this,Je)}set menuOpen(e){u(this,Je,e)}get editingKey(){return d(this,qe)}set editingKey(e){u(this,qe,e)}get editDraft(){return d(this,Ge)}set editDraft(e){u(this,Ge,e)}get editingTitle(){return d(this,Ve)}set editingTitle(e){u(this,Ve,e)}get renamingId(){return d(this,Xe)}set renamingId(e){u(this,Xe,e)}get toast(){return d(this,Ye)}set toast(e){u(this,Ye,e)}get copiedKey(){return d(this,Qe)}set copiedKey(e){u(this,Qe,e)}get retrievalOpen(){return d(this,Ze)}set retrievalOpen(e){u(this,Ze,e)}get rawKeys(){return d(this,et)}set rawKeys(e){u(this,et,e)}get savedFiles(){return d(this,tt)}set savedFiles(e){u(this,tt,e)}get hasSidebarContent(){return d(this,st)}set hasSidebarContent(e){u(this,st,e)}get sorts(){return d(this,it)}set sorts(e){u(this,it,e)}get arrivedKey(){return d(this,at)}set arrivedKey(e){u(this,at,e)}get dragging(){return d(this,rt)}set dragging(e){u(this,rt,e)}get showJump(){return d(this,nt)}set showJump(e){u(this,nt,e)}get offline(){return d(this,ot)}set offline(e){u(this,ot,e)}get isOpen(){return d(this,lt)}set isOpen(e){u(this,lt,e)}get expanded(){return d(this,ct)}set expanded(e){u(this,ct,e)}get bubble(){return d(this,ht)}set bubble(e){u(this,ht,e)}get seen(){return d(this,dt)}set seen(e){u(this,dt,e)}get mobile(){return d(this,pt)}set mobile(e){u(this,pt,e)}get msg(){return Bt(this.messages)}get resolvedClient(){return this.client??Vt.getDefaultClient()??null}get chatId(){return this.activeId}get thread(){return this.msgs}get docsetIds(){const e=this.docsets,t=Array.isArray(e)?e:String(e??"").split(/[\s,]+/);return[...new Set(t.map(s=>String(s).trim()).filter(Boolean))]}get attachments(){return this.savedFiles}get formatLevel(){return["raw","plain","advanced","rich"].includes(this.format)?this.format:"advanced"}get chats(){return this.chatList}set config(e){if(!e)return;const t=this;"client"in e&&(this.client=e.client??null);for(const s of Mt)s in e&&(t[s]=e[s]);e.chatId&&e.chatId!==this.activeId&&(this.hasUpdated?this.openChat(e.chatId):this.chatIdAttr=e.chatId)}configure(e){return this.config=e,this}get config(){const e=this;return{client:this.client,chatId:this.activeId??"",...Object.fromEntries(Mt.map(t=>[t,e[t]]))}}connectedCallback(){var e,t;super.connectedCallback(),this.offline=typeof navigator<"u"&&navigator.onLine===!1,window.addEventListener("online",this.onNetwork),window.addEventListener("offline",this.onNetwork),this.media=typeof matchMedia<"u"?matchMedia("(max-width: 559px)"):null,this.mobile=!!((e=this.media)!=null&&e.matches),(t=this.media)==null||t.addEventListener("change",this.onMedia)}disconnectedCallback(){var e,t;super.disconnectedCallback(),window.removeEventListener("online",this.onNetwork),window.removeEventListener("offline",this.onNetwork),(e=this.media)==null||e.removeEventListener("change",this.onMedia),(t=this.observer)==null||t.disconnect(),this.observer=null,this.observed=null,this.flushToast(),this.halt(),this.timers.forEach(clearTimeout),this.timers.clear()}willUpdate(e){if(e.has("retrieval")&&!Array.isArray(this.retrieval)){const t=this.retrieval;this.retrieval=t&&typeof t=="object"?[t]:[]}e.has("params")&&(!this.params||typeof this.params!="object")&&(this.params={}),e.has("metadata")&&(!this.metadata||typeof this.metadata!="object")&&(this.metadata={}),e.has("sidebar")&&(this.sidebar==="open"?this.sidebarOpen=!0:this.sidebar==="closed"||this.sidebar==="none"?this.sidebarOpen=!1:this.width&&(this.sidebarOpen=this.docked)),this.embed==="launcher"&&this.greetingBubble&&!this.bubbleScheduled&&(this.bubbleScheduled=!0,this.later(()=>{!this.isOpen&&!this.seen&&(this.bubble=!0)},1200))}firstUpdated(){this.chatIdAttr&&this.openChat(this.chatIdAttr)}updated(){var t;const e=this.renderRoot.querySelector(".root");if(e!==this.observed&&((t=this.observer)==null||t.disconnect(),this.observed=e,e&&typeof ResizeObserver<"u"&&(this.observer??(this.observer=new ResizeObserver(([s])=>{const a=Math.round(s.contentRect.width);a!==this.width&&(this.width=a,this.sidebarOpen===null&&(this.sidebarOpen=this.sidebar==="auto"&&this.docked))})),this.observer.observe(e))),this.sidebarOpen&&this.listState==="idle"&&this.resolvedClient&&this.loadChats(),this.pendingChatId&&this.resolvedClient&&this.openChat(this.pendingChatId),this.focusNext){const s=this.renderRoot.querySelector(this.focusNext);this.focusNext="",s&&(s.focus(),"select"in s&&s.tagName==="INPUT"&&s.select())}}later(e,t){const s=setTimeout(()=>{this.timers.delete(s),e()},t);this.timers.add(s)}emit(e,t){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}get docked(){return this.embed==="page"&&this.width>=bs}get panelDocked(){const e=this.docked&&this.sidebarOpen?ms:0;return this.width-e>=fs}newChat(){this.halt(),this.pendingChatId="",this.savedFiles=[],this.loadingThread=!1,this.activeId=null,this.chatTitle="",this.bookmarked=!1,this.msgs=[],this.threadError="",this.resetViewState(),this.focusNext="textarea.input"}async openChat(e){const t=this.resolvedClient;if(!e)return;this.halt(),this.savedFiles=[];const s=this.chatList.find(r=>r._id===e);if(this.activeId=e,this.chatTitle=(s==null?void 0:s.title)??"",this.bookmarked=!!(s!=null&&s.bookmarked),this.msgs=[],this.threadError="",this.resetViewState(),!t){this.pendingChatId=e,this.loadingThread=!0;return}const a=++this.run;this.pendingChatId="",this.loadingThread=!0;try{const r=await t.llm.call("get_chat",{_id:e});if(a!==this.run)return;this.chatTitle=(r==null?void 0:r.title)??"",this.bookmarked=!!(r!=null&&r.bookmarked),this.msgs=((r==null?void 0:r.messages)??[]).filter(n=>n&&(n.role==="user"||n.role==="assistant")).map(n=>this.fromServer(n)),this.savedFiles=Nt(r==null?void 0:r.attachments),this.upsertChat({...s,...r,_id:e}),this.stick=!0,this.scrollToBottom()}catch(r){if(a!==this.run)return;At(r)?(this.chatList=this.chatList.filter(n=>n._id!==e),this.newChat(),this.showToast(this.msg.errNotFound)):this.threadError=this.msg.errLoad}finally{a===this.run&&(this.loadingThread=!1)}}async send(e){const t=(typeof e=="string"?e:this.draft).trim();if(!t||this.busy)return;const s=this.files;this.draft="",this.files=[];const a=this.renderRoot.querySelector("textarea.input");a&&(a.style.height="auto"),await this.runTurn(this.userMessage(t,s))}stop(){if(!this.busy)return;const e=this.msgs[this.msgs.length-1];this.halt(),(e==null?void 0:e.role)==="assistant"&&(e.phase==="pending"||e.phase==="streaming")&&(e.phase="done",e.stopped=!0,e.followups=[],this.msgs=[...this.msgs])}exportChat(e="md"){var O;if(!this.msgs.length)return;this.menuOpen=!1;const t=this.chatTitle||this.msg.untitled,s=v=>v.role==="user"?this.msg.you:this.assistantName,a=v=>new Date(v||Date.now()).toLocaleString(),r=v=>v.sources.map((C,k)=>{const z=L(C,k+1);return`[${z.n}] ${z.title}${z.path?` — ${z.path}`:""}`}),n=v=>(v.attachments??[]).map(C=>C.name);let h,c="text/markdown",f="md";if(e==="json"?(h=JSON.stringify({exportedAt:new Date().toISOString(),id:this.activeId,title:t,mode:this.mode,bookmarked:this.bookmarked,messages:this.msgs.map(v=>({role:v.role,text:v.content,at:new Date(v.at||Date.now()).toISOString(),bookmarked:v.bookmarked,attachments:n(v),sources:r(v)}))},null,2),c="application/json",f="json"):e==="txt"?(h=`${t}
2472
2477
  ${"=".repeat(t.length)}
2473
2478
 
2474
- `+this.msgs.map(x=>[`${i(x)} · ${a(x.at)}`,n(x).length?`Attachments: ${n(x).join(", ")}`:"",x.content,r(x).length?`Sources:
2475
- ${r(x).join(`
2479
+ `+this.msgs.map(v=>[`${s(v)} · ${a(v.at)}`,n(v).length?`Attachments: ${n(v).join(", ")}`:"",v.content,r(v).length?`Sources:
2480
+ ${r(v).join(`
2476
2481
  `)}`:""].filter(Boolean).join(`
2477
2482
  `)).join(`
2478
2483
 
2479
- `),c="text/plain",b="txt"):d=`# ${t}
2484
+ `),c="text/plain",f="txt"):h=`# ${t}
2480
2485
 
2481
- `+this.msgs.map(x=>[`### ${i(x)} · ${a(x.at)}`,n(x).length?`Attachments: ${n(x).join(", ")}`:"",x.content,r(x).length?`**Sources**
2486
+ `+this.msgs.map(v=>[`### ${s(v)} · ${a(v.at)}`,n(v).length?`Attachments: ${n(v).join(", ")}`:"",v.content,r(v).length?`**Sources**
2482
2487
 
2483
- ${r(x).map($=>`- ${$}`).join(`
2488
+ ${r(v).map(C=>`- ${C}`).join(`
2484
2489
  `)}`:""].filter(Boolean).join(`
2485
2490
 
2486
2491
  `)).join(`
@@ -2488,12 +2493,12 @@ ${r(x).map($=>`- ${$}`).join(`
2488
2493
  ---
2489
2494
 
2490
2495
  `)+`
2491
- `,this.emit("singlebase-chat-export",{chatId:this.activeId,format:e}),e==="copy"){(M=navigator.clipboard)==null||M.writeText(d).catch(()=>{}),this.showToast(this.msg.copiedMarkdown);return}const k=`${t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"chat"}-${new Date().toISOString().slice(0,10)}.${b}`,C=URL.createObjectURL(new Blob([d],{type:c})),v=document.createElement("a");v.href=C,v.download=k,document.body.appendChild(v),v.click(),v.remove(),setTimeout(()=>URL.revokeObjectURL(C),2e3),this.showToast(T.fill(this.msg.exported,{name:k}))}expand(){this.expanded=!0,this.emit("singlebase-chat-expand",{expanded:!0})}collapse(){this.expanded=!1,this.emit("singlebase-chat-expand",{expanded:!1})}open(){this.isOpen=!0,this.seen=!0,this.bubble=!1,this.focusNext="textarea.input",this.emit("singlebase-chat-open",{})}close(){this.isOpen=!1,this.expanded=!1,this.emit("singlebase-chat-close",{})}userMessage(e,t=[]){return{key:pt(),id:null,role:"user",content:e,at:Date.now(),bookmarked:!1,sources:[],followups:[],phase:"done",attachments:t}}systemPrompt(){return[this.systemMessage,Mt[this.mode]??Mt.chat,yi[this.formatLevel],this.followups?wi:""].filter(Boolean).join(`
2496
+ `,this.emit("singlebase-chat-export",{chatId:this.activeId,format:e}),e==="copy"){(O=navigator.clipboard)==null||O.writeText(h).catch(()=>{}),this.showToast(this.msg.copiedMarkdown);return}const w=`${t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"chat"}-${new Date().toISOString().slice(0,10)}.${f}`,$=URL.createObjectURL(new Blob([h],{type:c})),x=document.createElement("a");x.href=$,x.download=w,document.body.appendChild(x),x.click(),x.remove(),setTimeout(()=>URL.revokeObjectURL($),2e3),this.showToast(T.fill(this.msg.exported,{name:w}))}expand(){this.expanded=!0,this.emit("singlebase-chat-expand",{expanded:!0})}collapse(){this.expanded=!1,this.emit("singlebase-chat-expand",{expanded:!1})}open(){this.isOpen=!0,this.seen=!0,this.bubble=!1,this.focusNext="textarea.input",this.emit("singlebase-chat-open",{})}close(){this.isOpen=!1,this.expanded=!1,this.emit("singlebase-chat-close",{})}userMessage(e,t=[]){return{key:gt(),id:null,role:"user",content:e,at:Date.now(),bookmarked:!1,sources:[],followups:[],phase:"done",attachments:t}}systemPrompt(){return[this.systemMessage,Lt[this.mode]??Lt.chat,$s[this.formatLevel],this.followups?Cs:""].filter(Boolean).join(`
2492
2497
 
2493
- `)}payloadFor(e){const t={message:e.content,format:"markdown"};this.activeId?t._id=this.activeId:(t.title=ai(e.content),t.system_message=this.systemPrompt()),this.model&&(t.model=this.model),Object.keys(this.params??{}).length&&(t.params=this.params);const i=(e.attachments??[]).map(r=>r.name);(Object.keys(this.metadata??{}).length||i.length)&&(t.metadata={...this.metadata,...i.length?{attachments:i}:{}});const a=[...this.retrieval??[],...Si(e.attachments??[])];return a.length&&(t.retrieval=a),t}async runTurn(e){const t={key:pt(),id:null,role:"assistant",content:"",at:Date.now(),bookmarked:!1,sources:[],followups:[],phase:"pending"};this.msgs=[...this.msgs,e,t],this.busy=!0,this.panel=null,this.stick=!0,this.scrollToBottom(),this.emit("singlebase-chat-send",{chatId:this.activeId,text:e.content});const i=this.resolvedClient;if(!i){this.failTurn(t,this.msg.errNoClient,"NO_CLIENT"),this.busy=!1;return}const a=++this.run,r=new AbortController;this.abort=r;const n=!this.activeId;let d=this.payloadFor(e);if(this.beforeSend){let c;try{c=await this.beforeSend(d,{chatId:this.activeId,isNew:n,message:e})}catch(f){c=f}if(a!==this.run)return;if(c===!1){this.msgs=this.msgs.filter(f=>f!==e&&f!==t),this.draft=e.content,this.busy=!1,this.abort=null;return}if(!(!!c&&typeof c=="object"&&typeof c.message=="string")||!c.message.trim()){console.error("[singlebase-chat] beforeSend must return the request object (with a message) or false to cancel; the message was not sent.",c),this.failTurn(t,this.msg.errGeneric,"BEFORE_SEND_INVALID"),this.busy=!1,this.abort=null;return}d=c}try{const c=await i.llm.call("chat",d,{signal:r.signal}),b=(c==null?void 0:c._id)||(c==null?void 0:c.chat_id)||this.activeId;if(n&&b&&this.upsertChat({_id:b,title:(c==null?void 0:c.title)||d.title,bookmarked:!!(c!=null&&c.bookmarked),_modified_at:new Date().toISOString()}),a!==this.run)return;b&&(this.activeId=b),n?(this.chatTitle=(c==null?void 0:c.title)||d.title,this.bookmarked=!!(c!=null&&c.bookmarked)):b&&this.touchChat(b);const f=(c==null?void 0:c.message)??{},k=typeof f.content=="string"?f.content:(c==null?void 0:c.json)!==void 0?JSON.stringify(c.json,null,2):"",{text:C,followups:v}=gt(k);e.id=f.reply_to??null,Object.assign(t,{id:f._id??null,content:C,sources:Array.isArray(f.sources)?f.sources:[],followups:v,execTime:typeof f.exec_time=="number"?f.exec_time:void 0,model:f.model,at:Date.now()}),this.emit("singlebase-chat-response",{chatId:b,message:t}),await this.reveal(t,a),n&&b&&this.autoTitle&&this.retitle(b,e.content,t.content)}catch(c){if(a!==this.run)return;const b=_t(c);b&&(this.chatList=this.chatList.filter(f=>f._id!==this.activeId),this.activeId=null),this.failTurn(t,b?this.msg.errNotFound:this.msg.errGeneric,$i(c))}finally{a===this.run&&(this.busy=!1,this.abort=null,this.stick&&this.scrollToBottom())}}failTurn(e,t,i){e.phase="error",e.error=t,this.msgs=[...this.msgs],this.emit("singlebase-chat-error",{chatId:this.activeId,code:i,message:t})}reveal(e,t){const i=e.content.length,a=()=>{e.phase="done",this.msgs=[...this.msgs],this.arrivedKey=e.key,this.later(()=>{this.arrivedKey===e.key&&(this.arrivedKey="")},vi),this.stick?this.scrollToBottom():this.showJump=!0};if(!i||Ci())return a(),Promise.resolve();const r=e.content,n=Math.max(4,Math.ceil(i/90));let d=0;return e.phase="streaming",e.content="",new Promise(c=>{this.revealTimer=setInterval(()=>{if(t!==this.run){clearInterval(this.revealTimer),c();return}if(d=Math.min(i,d+n),e.content=r.slice(0,d),d>=i){clearInterval(this.revealTimer),a(),c();return}this.msgs=[...this.msgs],this.stick&&this.scrollToBottom()},16)})}halt(){var e;this.run++,(e=this.abort)==null||e.abort(),this.abort=null,clearInterval(this.revealTimer),this.busy=!1}async retitle(e,t,i){const a=this.resolvedClient;if(!(!a||this.renamed.has(e)))try{const r=await a.llm.call("generate",{user_input:`user: ${t}
2494
- assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6 words, sentence case, no quotes, no trailing punctuation) for this conversation.",format:"text"}),n=ri(r==null?void 0:r.result);if(!n||this.renamed.has(e))return;await a.llm.call("update_chat",{_id:e,title:n}),this.applyTitle(e,n,!0)}catch{}}applyTitle(e,t,i){this.chatList=this.chatList.map(a=>a._id===e?{...a,title:t}:a),this.activeId===e&&(this.chatTitle=t),this.emit("singlebase-chat-title",{chatId:e,title:t,auto:i})}commitTitle(e){this.editingTitle&&(this.editingTitle=!1,this.activeId&&this.renameChat(this.activeId,e))}commitRename(e,t){this.renamingId===e&&(this.renamingId="",this.renameChat(e,t))}async renameChat(e,t){var r,n;const i=t.trim().slice(0,80),a=((r=this.chatList.find(d=>d._id===e))==null?void 0:r.title)??this.chatTitle;if(!(!i||i===a)){this.renamed.add(e),this.applyTitle(e,i,!1);try{await((n=this.resolvedClient)==null?void 0:n.llm.call("update_chat",{_id:e,title:i}))}catch{this.applyTitle(e,a??"",!1),this.showToast(this.msg.errGeneric)}}}fromServer(e){const t=e.role==="assistant",{text:i,followups:a}=t?gt(String(e.content??"")):{text:String(e.content??""),followups:[]};return{key:pt(),id:e._id??null,role:t?"assistant":"user",content:i,at:Date.parse(e._created_at??"")||0,bookmarked:!!e.bookmarked,sources:Array.isArray(e.sources)?e.sources:[],followups:a,phase:"done",execTime:typeof e.exec_time=="number"?e.exec_time:void 0,model:e.model}}async loadChats(){const e=this.resolvedClient;if(e){this.listState="loading";try{const t=await e.llm.call("list_chats",{limit:100});this.chatList=[...(t==null?void 0:t.items)??[]],this.listState="ready"}catch{this.listState="error"}}}upsertChat(e){const t=this.chatList.filter(a=>a._id!==e._id),i=this.chatList.find(a=>a._id===e._id);this.chatList=[{...i,...e},...t]}touchChat(e){const t=this.chatList.find(i=>i._id===e);t&&this.upsertChat({...t,_modified_at:new Date().toISOString()})}resetViewState(){this.panel=null,this.menuOpen=!1,this.editingKey="",this.editingTitle=!1,this.showJump=!1,this.retrievalOpen=new Set,this.sidebarOpen&&!this.docked&&(this.sidebarOpen=!1)}async deleteOnServer(e){const t=this.resolvedClient,i=this.activeId;if(!(!t||!i))for(const a of e)a&&await t.llm.call("delete_chat_message",{_id:i,message_id:a}).catch(()=>{})}async regenerate(){if(this.busy)return;const e=this.msgs.map(a=>a.role).lastIndexOf("assistant"),t=this.msgs[e-1];if(e<1||(t==null?void 0:t.role)!=="user")return;const i=this.msgs.slice(e-1);this.msgs=this.msgs.slice(0,e-1),await this.deleteOnServer(i.map(a=>a.id)),await this.runTurn(this.userMessage(t.content,t.attachments))}async retry(e){if(this.busy)return;const t=this.msgs.indexOf(e),i=this.msgs[t-1];(i==null?void 0:i.role)==="user"&&(this.msgs=this.msgs.slice(0,t-1),await this.runTurn(this.userMessage(i.content,i.attachments)))}async saveEdit(e){const t=this.editDraft.trim(),i=this.msgs.indexOf(e);if(this.editingKey="",!t||i<0||this.busy)return;const a=this.msgs.slice(i);this.msgs=this.msgs.slice(0,i),await this.deleteOnServer(a.map(r=>r.id)),await this.runTurn(this.userMessage(t,e.attachments))}toggleRaw(e){const t=new Set(this.rawKeys);t.has(e)?t.delete(e):t.add(e),this.rawKeys=t}copy(e,t){var i;(i=navigator.clipboard)==null||i.writeText(t).catch(()=>{}),this.copiedKey=e,this.later(()=>{this.copiedKey===e&&(this.copiedKey="")},1400)}async toggleMessageBookmark(e){var i;const t=this.activeId;if(!(!t||!e.id)){e.bookmarked=!e.bookmarked,this.msgs=[...this.msgs],this.showToast(e.bookmarked?this.msg.messageBookmarked:this.msg.bookmarkRemoved),this.emit("singlebase-chat-bookmark",{chatId:t,messageId:e.id,bookmarked:e.bookmarked});try{await((i=this.resolvedClient)==null?void 0:i.llm.call("bookmark_chat_message",{_id:t,message_id:e.id,bookmarked:e.bookmarked}))}catch{e.bookmarked=!e.bookmarked,this.msgs=[...this.msgs],this.showToast(this.msg.errGeneric)}}}async toggleChatBookmark(e){var r,n;const t=((r=this.chatList.find(d=>d._id===e))==null?void 0:r.bookmarked)??(e===this.activeId?this.bookmarked:!1),i=!t,a=d=>{this.chatList=this.chatList.map(c=>c._id===e?{...c,bookmarked:d}:c),e===this.activeId&&(this.bookmarked=d)};a(i),this.showToast(i?this.msg.chatBookmarked:this.msg.chatUnbookmarked),this.emit("singlebase-chat-bookmark",{chatId:e,bookmarked:i});try{await((n=this.resolvedClient)==null?void 0:n.llm.call("bookmark_chat",{_id:e,bookmarked:i}))}catch{a(t),this.showToast(this.msg.errGeneric)}}deleteMessage(e){var a;const t=this.activeId,i=this.msgs.indexOf(e);i<0||(this.msgs=this.msgs.filter(r=>r!==e),((a=this.panel)==null?void 0:a.key)===e.key&&(this.panel=null),this.showToast(this.msg.messageDeleted,{undo:()=>{if(this.activeId!==t)return;const r=[...this.msgs];r.splice(i,0,e),this.msgs=r},commit:()=>{var r;this.emit("singlebase-chat-message-delete",{chatId:t,messageId:e.id}),t&&e.id&&((r=this.resolvedClient)==null||r.llm.call("delete_chat_message",{_id:t,message_id:e.id}).catch(()=>{}))}}))}deleteChat(e){const t=this.chatList.findIndex(n=>n._id===e),i=this.chatList[t]??{_id:e,title:this.chatTitle,bookmarked:this.bookmarked},a=e===this.activeId,r=a?{title:this.chatTitle,bookmarked:this.bookmarked,msgs:this.msgs}:null;this.chatList=this.chatList.filter(n=>n._id!==e),a&&this.newChat(),this.showToast(this.msg.chatDeleted,{undo:()=>{const n=[...this.chatList];n.splice(Math.max(0,t),0,i),this.chatList=n,r&&!this.activeId&&!this.msgs.length&&(this.activeId=e,this.chatTitle=r.title,this.bookmarked=r.bookmarked,this.msgs=r.msgs)},commit:()=>{var n;this.emit("singlebase-chat-delete",{chatId:e}),(n=this.resolvedClient)==null||n.llm.call("delete_chat",{_id:e}).catch(()=>{})}})}feedback(e,t){e.feedback=t,this.msgs=[...this.msgs],this.emit("singlebase-chat-feedback",{chatId:this.activeId,messageId:e.id,value:t,text:e.content})}showToast(e,t={}){this.flushToast();const i={key:Date.now(),text:e,...t};this.toast=i,this.toastTimer=setTimeout(()=>{this.toast===i&&this.flushToast()},bi)}flushToast(){var t;const e=this.toast;clearTimeout(this.toastTimer),this.toast=null,(t=e==null?void 0:e.commit)==null||t.call(e)}undo(){var t;const e=this.toast;clearTimeout(this.toastTimer),this.toast=null,(t=e==null?void 0:e.undo)==null||t.call(e)}async addFiles(e){const t=Array.from(e??[]);if(!t.length)return;const i=[];for(const a of t){if(this.files.length+i.length>=Tt){this.showToast(T.fill(this.msg.tooManyFiles,{n:Tt}));break}if(!mi.test(a.name)&&!a.type.startsWith("text/")){this.showToast(T.fill(this.msg.fileType,{name:a.name}));continue}if(a.size>Ot){this.showToast(T.fill(this.msg.fileTooLarge,{name:a.name,size:T.formatSize(Ot)}));continue}i.push({name:a.name,size:a.size,content:await a.text()})}i.length&&(this.files=[...this.files,...i],this.emit("singlebase-chat-files",{files:i.map(({name:a,size:r})=>({name:a,size:r}))}))}async scrollToBottom(){await this.updateComplete;const e=this.renderRoot.querySelector(".scroller");e&&(e.scrollTop=e.scrollHeight),this.showJump=!1}onScroll(e){const t=e.currentTarget;this.stick=t.scrollHeight-t.scrollTop-t.clientHeight<80,this.stick&&(this.showJump=!1)}jumpToLatest(){this.stick=!0,this.scrollToBottom()}onKeydown(e){if(e.key==="Escape"){if(this.menuOpen)this.menuOpen=!1;else if(this.panel)this.panel=null;else if(this.sidebarOpen&&!this.docked)this.sidebarOpen=!1;else if(this.expanded)this.collapse();else if(this.embed==="launcher"&&this.isOpen)this.close();else return;e.stopPropagation()}}onComposerKey(e){e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.send())}onComposerInput(e){const t=e.target;t.style.height="auto",t.style.height=`${Math.min(176,t.scrollHeight)}px`,this.draft=t.value}onDragEnter(e){var t;!this.allowUpload||!this.showComposer||Array.from(((t=e.dataTransfer)==null?void 0:t.types)??[]).includes("Files")&&(e.preventDefault(),this.dragging=!0)}onDragLeave(e){e.currentTarget.contains(e.relatedTarget)||(this.dragging=!1)}onDrop(e){var t;e.preventDefault(),this.dragging=!1,this.allowUpload&&this.addFiles((t=e.dataTransfer)==null?void 0:t.files)}render(){if(this.embed==="launcher")return this.renderLauncher();const e=["frame",this.embed==="inline"?"inline boxed":"",this.expanded?"expanded boxed":""].join(" ");return s.html`<div class=${e} part="frame">${this.renderWorkspace()}</div>`}renderLauncher(){const e=this.msg,t=["frame launcher boxed",this.expanded?"expanded":"",this.mobile?"full":""].join(" "),i=this.isOpen?s.html`<div class=${t} role="dialog" aria-label=${this.assistantName} part="frame">
2498
+ `)}payloadFor(e){const t={message:e.content,format:"markdown"};this.activeId?t._id=this.activeId:(t.title=os(e.content),t.system_message=this.systemPrompt()),t.mode=this.mode,this.model&&(t.model=this.model),Object.keys(this.params??{}).length&&(t.params=this.params);const s=e.attachments??[],a=this.attachmentsMode==="payload";a&&s.length&&(t.attachments=s.map(c=>({type:"content",content:c.content,name:c.name,...c.mime?{mime:c.mime}:{},size:c.size,save_attachment:this.saveAttachments})));const r=a?[]:s.map(c=>c.name);(Object.keys(this.metadata??{}).length||r.length)&&(t.metadata={...this.metadata,...r.length?{attachments:r}:{}});const n=this.docsetIds,h=[...n.length?[{source:"docset",ids:n}]:[],...this.retrieval??[],...a?[]:Ms(s)];return h.length&&(t.retrieval=h),t}async runTurn(e){const t={key:gt(),id:null,role:"assistant",content:"",at:Date.now(),bookmarked:!1,sources:[],followups:[],phase:"pending"};this.msgs=[...this.msgs,e,t],this.busy=!0,this.panel=null,this.stick=!0,this.scrollToBottom(),this.emit("singlebase-chat-send",{chatId:this.activeId,text:e.content});const s=this.resolvedClient;if(!s){this.failTurn(t,this.msg.errNoClient,"NO_CLIENT"),this.busy=!1;return}const a=++this.run,r=new AbortController;this.abort=r;const n=!this.activeId;let h=this.payloadFor(e);if(this.beforeSend){let c;try{c=await this.beforeSend(h,{chatId:this.activeId,isNew:n,message:e})}catch(b){c=b}if(a!==this.run)return;if(c===!1){this.msgs=this.msgs.filter(b=>b!==e&&b!==t),this.draft=e.content,this.busy=!1,this.abort=null;return}if(!(!!c&&typeof c=="object"&&typeof c.message=="string")||!c.message.trim()){console.error("[singlebase-chat] beforeSend must return the request object (with a message) or false to cancel; the message was not sent.",c),this.failTurn(t,this.msg.errGeneric,"BEFORE_SEND_INVALID"),this.busy=!1,this.abort=null;return}h=c}try{const c=await s.llm.call("chat",h,{signal:r.signal}),f=(c==null?void 0:c._id)||(c==null?void 0:c.chat_id)||this.activeId;if(n&&f&&this.upsertChat({_id:f,title:(c==null?void 0:c.title)||h.title,bookmarked:!!(c!=null&&c.bookmarked),_modified_at:new Date().toISOString()}),a!==this.run)return;f&&(this.activeId=f),n&&(this.chatTitle=(c==null?void 0:c.title)||h.title,this.bookmarked=!!(c!=null&&c.bookmarked));const b=(c==null?void 0:c.message)??{},w=typeof b.content=="string"?b.content:(c==null?void 0:c.json)!==void 0?JSON.stringify(c.json,null,2):"",{text:$,followups:x}=ft(w);e.id=b.reply_to??null,this.applyAttachmentResults(c==null?void 0:c.attachments),Object.assign(t,{id:b._id??null,content:$,sources:Array.isArray(b.sources)?b.sources:[],followups:x,execTime:typeof b.exec_time=="number"?b.exec_time:void 0,model:b.model,at:Date.now()}),this.emit("singlebase-chat-response",{chatId:f,message:t}),await this.reveal(t,a),n&&f&&this.autoTitle&&this.retitle(f,e.content,t.content)}catch(c){if(a!==this.run)return;const f=At(c);f&&(this.chatList=this.chatList.filter($=>$._id!==this.activeId),this.activeId=null);const b=Ts(c),w=f?this.msg.errNotFound:b==="KB_SOURCE_REQUIRED"?this.msg.errKbSource:this.msg.errGeneric;this.failTurn(t,w,b)}finally{a===this.run&&(this.busy=!1,this.abort=null,this.stick&&this.scrollToBottom())}}failTurn(e,t,s){e.phase="error",e.error=t,this.msgs=[...this.msgs],this.emit("singlebase-chat-error",{chatId:this.activeId,code:s,message:t})}reveal(e,t){const s=e.content.length,a=()=>{e.phase="done",this.msgs=[...this.msgs],this.arrivedKey=e.key,this.later(()=>{this.arrivedKey===e.key&&(this.arrivedKey="")},ks),this.stick?this.scrollToBottom():this.showJump=!0};if(!s||Is())return a(),Promise.resolve();const r=e.content,n=Math.max(4,Math.ceil(s/90));let h=0;return e.phase="streaming",e.content="",new Promise(c=>{this.revealTimer=setInterval(()=>{if(t!==this.run){clearInterval(this.revealTimer),c();return}if(h=Math.min(s,h+n),e.content=r.slice(0,h),h>=s){clearInterval(this.revealTimer),a(),c();return}this.msgs=[...this.msgs],this.stick&&this.scrollToBottom()},16)})}halt(){var e;this.run++,(e=this.abort)==null||e.abort(),this.abort=null,clearInterval(this.revealTimer),this.busy=!1}async retitle(e,t,s){const a=this.resolvedClient;if(!(!a||this.renamed.has(e)))try{const r=await a.llm.call("generate",{user_input:`user: ${t}
2499
+ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6 words, sentence case, no quotes, no trailing punctuation) for this conversation.",format:"text"}),n=ls(r==null?void 0:r.result);if(!n||this.renamed.has(e))return;await a.llm.call("update_chat",{_id:e,title:n}),this.applyTitle(e,n,!0)}catch{}}applyTitle(e,t,s){this.chatList=this.chatList.map(a=>a._id===e?{...a,title:t}:a),this.activeId===e&&(this.chatTitle=t),this.emit("singlebase-chat-title",{chatId:e,title:t,auto:s})}commitTitle(e){this.editingTitle&&(this.editingTitle=!1,this.activeId&&this.renameChat(this.activeId,e))}commitRename(e,t){this.renamingId===e&&(this.renamingId="",this.renameChat(e,t))}async renameChat(e,t){var r,n;const s=t.trim().slice(0,80),a=((r=this.chatList.find(h=>h._id===e))==null?void 0:r.title)??this.chatTitle;if(!(!s||s===a)){this.renamed.add(e),this.applyTitle(e,s,!1);try{await((n=this.resolvedClient)==null?void 0:n.llm.call("update_chat",{_id:e,title:s}))}catch{this.applyTitle(e,a??"",!1),this.showToast(this.msg.errGeneric)}}}fromServer(e){const t=e.role==="assistant",{text:s,followups:a}=t?ft(String(e.content??"")):{text:String(e.content??""),followups:[]};return{key:gt(),id:e._id??null,role:t?"assistant":"user",content:s,at:Date.parse(e._created_at??"")||0,bookmarked:!!e.bookmarked,sources:Array.isArray(e.sources)?e.sources:[],followups:a,phase:"done",execTime:typeof e.exec_time=="number"?e.exec_time:void 0,model:e.model}}async loadChats(){const e=this.resolvedClient;if(e){this.listState="loading";try{const t=await e.llm.call("list_chats",{limit:100});this.chatList=[...(t==null?void 0:t.items)??[]],this.listState="ready"}catch{this.listState="error"}}}upsertChat(e){const t=this.chatList.findIndex(r=>r._id===e._id);if(t<0){this.chatList=[e,...this.chatList];return}const s=this.chatList[t],a=[...this.chatList];a[t]={...s,...e,_created_at:s._created_at??e._created_at,_modified_at:s._modified_at??e._modified_at},this.chatList=a}resetViewState(){this.panel=null,this.menuOpen=!1,this.editingKey="",this.editingTitle=!1,this.showJump=!1,this.retrievalOpen=new Set,this.sidebarOpen&&!this.docked&&(this.sidebarOpen=!1)}async deleteOnServer(e){const t=this.resolvedClient,s=this.activeId;if(!(!t||!s))for(const a of e)a&&await t.llm.call("delete_chat_message",{_id:s,message_id:a}).catch(()=>{})}async regenerate(){if(this.busy)return;const e=this.msgs.map(a=>a.role).lastIndexOf("assistant"),t=this.msgs[e-1];if(e<1||(t==null?void 0:t.role)!=="user")return;const s=this.msgs.slice(e-1);this.msgs=this.msgs.slice(0,e-1),await this.deleteOnServer(s.map(a=>a.id)),await this.runTurn(this.userMessage(t.content,t.attachments))}async retry(e){if(this.busy)return;const t=this.msgs.indexOf(e),s=this.msgs[t-1];(s==null?void 0:s.role)==="user"&&(this.msgs=this.msgs.slice(0,t-1),await this.runTurn(this.userMessage(s.content,s.attachments)))}async saveEdit(e){const t=this.editDraft.trim(),s=this.msgs.indexOf(e);if(this.editingKey="",!t||s<0||this.busy)return;const a=this.msgs.slice(s);this.msgs=this.msgs.slice(0,s),await this.deleteOnServer(a.map(r=>r.id)),await this.runTurn(this.userMessage(t,e.attachments))}toggleRaw(e){const t=new Set(this.rawKeys);t.has(e)?t.delete(e):t.add(e),this.rawKeys=t}applyAttachmentResults(e){if(!Array.isArray(e))return;const t=Nt(e).filter(a=>!this.savedFiles.some(r=>r.id===a.id));t.length&&(this.savedFiles=[...this.savedFiles,...t]);const s=e.filter(a=>(a==null?void 0:a.status)==="failed").map(a=>String(a.name??"file"));s.length&&this.showToast(T.fill(this.msg.attachmentFailed,{name:s.join(", ")}))}async removeSavedFile(e){var a;const t=this.activeId;if(!t)return;const s=this.savedFiles;this.savedFiles=s.filter(r=>r!==e);try{await((a=this.resolvedClient)==null?void 0:a.llm.call("remove_chat_attachment",{_id:t,attachment_id:e.id}))}catch{this.activeId===t&&(this.savedFiles=s),this.showToast(this.msg.errGeneric)}}copy(e,t){var s;(s=navigator.clipboard)==null||s.writeText(t).catch(()=>{}),this.copiedKey=e,this.later(()=>{this.copiedKey===e&&(this.copiedKey="")},1400)}async toggleMessageBookmark(e){var s;const t=this.activeId;if(!(!t||!e.id)){e.bookmarked=!e.bookmarked,this.msgs=[...this.msgs],this.showToast(e.bookmarked?this.msg.messageBookmarked:this.msg.bookmarkRemoved),this.emit("singlebase-chat-bookmark",{chatId:t,messageId:e.id,bookmarked:e.bookmarked});try{await((s=this.resolvedClient)==null?void 0:s.llm.call("bookmark_chat_message",{_id:t,message_id:e.id,bookmarked:e.bookmarked}))}catch{e.bookmarked=!e.bookmarked,this.msgs=[...this.msgs],this.showToast(this.msg.errGeneric)}}}async toggleChatBookmark(e){var r,n;const t=((r=this.chatList.find(h=>h._id===e))==null?void 0:r.bookmarked)??(e===this.activeId?this.bookmarked:!1),s=!t,a=h=>{this.chatList=this.chatList.map(c=>c._id===e?{...c,bookmarked:h}:c),e===this.activeId&&(this.bookmarked=h)};a(s),this.showToast(s?this.msg.chatBookmarked:this.msg.chatUnbookmarked),this.emit("singlebase-chat-bookmark",{chatId:e,bookmarked:s});try{await((n=this.resolvedClient)==null?void 0:n.llm.call("bookmark_chat",{_id:e,bookmarked:s}))}catch{a(t),this.showToast(this.msg.errGeneric)}}deleteMessage(e){var a;const t=this.activeId,s=this.msgs.indexOf(e);s<0||(this.msgs=this.msgs.filter(r=>r!==e),((a=this.panel)==null?void 0:a.key)===e.key&&(this.panel=null),this.showToast(this.msg.messageDeleted,{undo:()=>{if(this.activeId!==t)return;const r=[...this.msgs];r.splice(s,0,e),this.msgs=r},commit:()=>{var r;this.emit("singlebase-chat-message-delete",{chatId:t,messageId:e.id}),t&&e.id&&((r=this.resolvedClient)==null||r.llm.call("delete_chat_message",{_id:t,message_id:e.id}).catch(()=>{}))}}))}deleteChat(e){const t=this.chatList.findIndex(n=>n._id===e),s=this.chatList[t]??{_id:e,title:this.chatTitle,bookmarked:this.bookmarked},a=e===this.activeId,r=a?{title:this.chatTitle,bookmarked:this.bookmarked,msgs:this.msgs}:null;this.chatList=this.chatList.filter(n=>n._id!==e),a&&this.newChat(),this.showToast(this.msg.chatDeleted,{undo:()=>{const n=[...this.chatList];n.splice(Math.max(0,t),0,s),this.chatList=n,r&&!this.activeId&&!this.msgs.length&&(this.activeId=e,this.chatTitle=r.title,this.bookmarked=r.bookmarked,this.msgs=r.msgs)},commit:()=>{var n;this.emit("singlebase-chat-delete",{chatId:e}),(n=this.resolvedClient)==null||n.llm.call("delete_chat",{_id:e}).catch(()=>{})}})}feedback(e,t){e.feedback=t,this.msgs=[...this.msgs],this.emit("singlebase-chat-feedback",{chatId:this.activeId,messageId:e.id,value:t,text:e.content})}showToast(e,t={}){this.flushToast();const s={key:Date.now(),text:e,...t};this.toast=s,this.toastTimer=setTimeout(()=>{this.toast===s&&this.flushToast()},xs)}flushToast(){var t;const e=this.toast;clearTimeout(this.toastTimer),this.toast=null,(t=e==null?void 0:e.commit)==null||t.call(e)}undo(){var t;const e=this.toast;clearTimeout(this.toastTimer),this.toast=null,(t=e==null?void 0:e.undo)==null||t.call(e)}async addFiles(e){const t=Array.from(e??[]);if(!t.length)return;const s=[];for(const a of t){if(this.files.length+s.length>=Ot){this.showToast(T.fill(this.msg.tooManyFiles,{n:Ot}));break}if(!vs.test(a.name)&&!a.type.startsWith("text/")){this.showToast(T.fill(this.msg.fileType,{name:a.name}));continue}if(a.size>zt){this.showToast(T.fill(this.msg.fileTooLarge,{name:a.name,size:T.formatSize(zt)}));continue}s.push({name:a.name,size:a.size,content:await a.text(),...a.type?{mime:a.type}:{}})}s.length&&(this.files=[...this.files,...s],this.emit("singlebase-chat-files",{files:s.map(({name:a,size:r})=>({name:a,size:r}))}))}async scrollToBottom(){await this.updateComplete;const e=this.renderRoot.querySelector(".scroller");e&&(e.scrollTop=e.scrollHeight),this.showJump=!1}onScroll(e){const t=e.currentTarget;this.stick=t.scrollHeight-t.scrollTop-t.clientHeight<80,this.stick&&(this.showJump=!1)}jumpToLatest(){this.stick=!0,this.scrollToBottom()}onKeydown(e){if(e.key==="Escape"){if(this.menuOpen)this.menuOpen=!1;else if(this.panel)this.panel=null;else if(this.sidebarOpen&&!this.docked)this.sidebarOpen=!1;else if(this.expanded)this.collapse();else if(this.embed==="launcher"&&this.isOpen)this.close();else return;e.stopPropagation()}}onComposerKey(e){e.key==="Enter"&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),this.send())}onComposerInput(e){const t=e.target;t.style.height="auto",t.style.height=`${Math.min(176,t.scrollHeight)}px`,this.draft=t.value}onDragEnter(e){var t;!this.allowUpload||!this.showComposer||Array.from(((t=e.dataTransfer)==null?void 0:t.types)??[]).includes("Files")&&(e.preventDefault(),this.dragging=!0)}onDragLeave(e){e.currentTarget.contains(e.relatedTarget)||(this.dragging=!1)}onDrop(e){var t;e.preventDefault(),this.dragging=!1,this.allowUpload&&this.addFiles((t=e.dataTransfer)==null?void 0:t.files)}render(){if(this.embed==="launcher")return this.renderLauncher();const e=["frame",this.embed==="inline"?"inline boxed":"",this.expanded?"expanded boxed":""].join(" ");return i.html`<div class=${e} part="frame">${this.renderWorkspace()}</div>`}renderLauncher(){const e=this.msg,t=["frame launcher boxed",this.expanded?"expanded":"",this.mobile?"full":""].join(" "),s=this.isOpen?i.html`<div class=${t} role="dialog" aria-label=${this.assistantName} part="frame">
2495
2500
  ${this.renderWorkspace()}
2496
- </div>`:s.nothing,a=this.bubble&&!this.isOpen?s.html`<div class="bubble" part="bubble">
2501
+ </div>`:i.nothing,a=this.bubble&&!this.isOpen?i.html`<div class="bubble" part="bubble">
2497
2502
  <button type="button" class="bubble-text" @click=${()=>this.open()}>
2498
2503
  ${this.bubbleText||e.bubbleText}
2499
2504
  </button>
@@ -2506,7 +2511,7 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2506
2511
  >
2507
2512
  ${y.close()}
2508
2513
  </button>
2509
- </div>`:s.nothing,n=this.isOpen&&(this.expanded||this.mobile)?s.nothing:s.html`<button
2514
+ </div>`:i.nothing,n=this.isOpen&&(this.expanded||this.mobile)?i.nothing:i.html`<button
2510
2515
  type="button"
2511
2516
  class="launcher-btn"
2512
2517
  part="launcher"
@@ -2515,17 +2520,17 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2515
2520
  @click=${()=>this.isOpen?this.close():this.open()}
2516
2521
  >
2517
2522
  ${this.isOpen?y.chevronDown():y.chat()}
2518
- ${this.unreadBadge&&!this.seen&&!this.isOpen?s.html`<span class="badge"></span>`:s.nothing}
2519
- </button>`;return s.html`${i}${a}${n}`}renderWorkspace(){const e=!this.docked;return s.html`<div class="root" @keydown=${this.onKeydown}>
2520
- ${this.sidebarOpen&&e?s.html`<div class="scrim" @click=${()=>this.sidebarOpen=!1}></div>`:s.nothing}
2521
- ${this.sidebarOpen&&this.sidebar!=="none"?this.renderSidebar(e):s.nothing}
2523
+ ${this.unreadBadge&&!this.seen&&!this.isOpen?i.html`<span class="badge"></span>`:i.nothing}
2524
+ </button>`;return i.html`${s}${a}${n}`}renderWorkspace(){const e=!this.docked;return i.html`<div class="root" @keydown=${this.onKeydown}>
2525
+ ${this.sidebarOpen&&e?i.html`<div class="scrim" @click=${()=>this.sidebarOpen=!1}></div>`:i.nothing}
2526
+ ${this.sidebarOpen&&this.sidebar!=="none"?this.renderSidebar(e):i.nothing}
2522
2527
  <main
2523
2528
  class="main"
2524
2529
  @dragenter=${this.onDragEnter}
2525
2530
  @dragover=${t=>t.preventDefault()}
2526
2531
  >
2527
2532
  ${this.renderHeader()}
2528
- ${this.offline?s.html`<div class="banner" role="status">${this.msg.offline}</div>`:s.nothing}
2533
+ ${this.offline?i.html`<div class="banner" role="status">${this.msg.offline}</div>`:i.nothing}
2529
2534
  <div
2530
2535
  class="scroller"
2531
2536
  role="log"
@@ -2536,31 +2541,30 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2536
2541
  >
2537
2542
  ${this.msgs.length||this.loadingThread||this.threadError?this.renderThread():this.renderWelcome()}
2538
2543
  </div>
2539
- ${this.showJump?s.html`<button type="button" class="jump" @click=${this.jumpToLatest}>
2544
+ ${this.showJump?i.html`<button type="button" class="jump" @click=${this.jumpToLatest}>
2540
2545
  ↓ ${this.msg.newReply}
2541
- </button>`:s.nothing}
2542
- ${this.renderComposer()}
2543
- ${T.renderBranding(this.branding,this.brandingText,this.msg.brandingLabel,this.brandingUrl)}
2544
- ${this.toast?s.html`<div class="toast" role="status">
2546
+ </button>`:i.nothing}
2547
+ ${this.renderComposer()} ${T.renderBranding(this.branding,"Chat")}
2548
+ ${this.toast?i.html`<div class="toast" role="status">
2545
2549
  <span>${this.toast.text}</span>
2546
- ${this.toast.undo?s.html`<button type="button" @click=${this.undo}>${this.msg.undo}</button>`:s.nothing}
2547
- </div>`:s.nothing}
2548
- ${this.dragging?s.html`<div
2550
+ ${this.toast.undo?i.html`<button type="button" @click=${this.undo}>${this.msg.undo}</button>`:i.nothing}
2551
+ </div>`:i.nothing}
2552
+ ${this.dragging?i.html`<div
2549
2553
  class="drop"
2550
2554
  @dragover=${t=>t.preventDefault()}
2551
2555
  @dragleave=${this.onDragLeave}
2552
2556
  @drop=${this.onDrop}
2553
2557
  >
2554
2558
  <strong>${this.msg.dropTitle}</strong><span>${this.msg.dropSub}</span>
2555
- </div>`:s.nothing}
2559
+ </div>`:i.nothing}
2556
2560
  </main>
2557
2561
  ${this.renderPanel()}
2558
- </div>`}renderSidebar(e){const t=this.msg,i=this.allowSearch?this.search.trim().toLowerCase():"",a=this.chatList.filter(b=>!i||(b.title??"").toLowerCase().includes(i)),r=b=>this.showBookmarked&&!!b.bookmarked,n=b=>a.filter(f=>!r(f)&&Ti(f._modified_at??f._created_at)===b),d=[[t.groupBookmarked,a.filter(r)],[t.groupToday,n("today")],[t.groupYesterday,n("yesterday")],[t.groupWeek,n("week")],[t.groupOlder,n("older")]];let c;return this.listState==="loading"&&!this.chatList.length?c=s.html`<div aria-label=${t.loadingChats}>
2559
- ${[1,2,3,4].map(()=>s.html`<div class="skeleton"></div>`)}
2560
- </div>`:a.length?c=d.filter(([,b])=>b.length).map(([b,f])=>s.html`<div class="group">${b}</div>
2561
- ${f.map(k=>this.renderThreadRow(k))}`):c=s.html`<span class="side-note"
2562
- >${i?T.fill(t.noMatch,{query:this.search.trim()}):t.noChats}</span
2563
- >`,s.html`<aside
2562
+ </div>`}renderSidebar(e){const t=this.msg,s=this.allowSearch?this.search.trim().toLowerCase():"",a=this.chatList.filter(f=>!s||(f.title??"").toLowerCase().includes(s)),r=f=>this.showBookmarked&&!!f.bookmarked,n=f=>a.filter(b=>!r(b)&&Os(b._modified_at??b._created_at)===f),h=[[t.groupBookmarked,a.filter(r)],[t.groupToday,n("today")],[t.groupYesterday,n("yesterday")],[t.groupWeek,n("week")],[t.groupOlder,n("older")]];let c;return this.listState==="loading"&&!this.chatList.length?c=i.html`<div aria-label=${t.loadingChats}>
2563
+ ${[1,2,3,4].map(()=>i.html`<div class="skeleton"></div>`)}
2564
+ </div>`:a.length?c=h.filter(([,f])=>f.length).map(([f,b])=>i.html`<div class="group">${f}</div>
2565
+ ${b.map(w=>this.renderThreadRow(w))}`):c=i.html`<span class="side-note"
2566
+ >${s?T.fill(t.noMatch,{query:this.search.trim()}):t.noChats}</span
2567
+ >`,i.html`<aside
2564
2568
  class="sidebar ${e?"overlay":"docked"}"
2565
2569
  part="sidebar"
2566
2570
  aria-label=${t.chats}
@@ -2578,26 +2582,26 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2578
2582
  </button>
2579
2583
  </div>
2580
2584
  <div class="side-tools">
2581
- ${this.showNewChat?s.html`<button type="button" class="new-chat" @click=${()=>this.newChat()}>
2585
+ ${this.showNewChat?i.html`<button type="button" class="new-chat" @click=${()=>this.newChat()}>
2582
2586
  ${y.plus()}<span>${t.newChat}</span>
2583
- </button>`:s.nothing}
2584
- ${this.allowSearch?s.html`<input
2587
+ </button>`:i.nothing}
2588
+ ${this.allowSearch?i.html`<input
2585
2589
  class="search"
2586
2590
  type="search"
2587
2591
  placeholder=${t.searchChats}
2588
2592
  aria-label=${t.searchChats}
2589
2593
  .value=${this.search}
2590
- @input=${b=>this.search=b.target.value}
2591
- />`:s.nothing}
2594
+ @input=${f=>this.search=f.target.value}
2595
+ />`:i.nothing}
2592
2596
  </div>
2593
2597
  <div class="threads">${c}</div>
2594
2598
  <div class="side-extra ${this.hasSidebarContent?"filled":""}" part="sidebar-extra">
2595
2599
  <slot
2596
2600
  name="sidebar"
2597
- @slotchange=${b=>this.hasSidebarContent=b.target.assignedNodes().length>0}
2601
+ @slotchange=${f=>this.hasSidebarContent=f.target.assignedNodes().length>0}
2598
2602
  ></slot>
2599
2603
  </div>
2600
- </aside>`}renderThreadRow(e){const t=this.msg,i=e._id===this.activeId,a=e.title||t.untitled;if(this.renamingId===e._id)return s.html`<div class="thread active">
2604
+ </aside>`}renderThreadRow(e){const t=this.msg,s=e._id===this.activeId,a=e.title||t.untitled;if(this.renamingId===e._id)return i.html`<div class="thread active">
2601
2605
  <input
2602
2606
  class="thread-rename"
2603
2607
  maxlength="80"
@@ -2606,17 +2610,17 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2606
2610
  @keydown=${n=>{n.key==="Enter"&&this.commitRename(e._id,n.target.value),n.key==="Escape"&&(n.stopPropagation(),this.renamingId="")}}
2607
2611
  @blur=${n=>this.commitRename(e._id,n.target.value)}
2608
2612
  />
2609
- </div>`;const r=n=>d=>{d.stopPropagation(),n()};return s.html`<div
2610
- class="thread ${i?"active":""}"
2613
+ </div>`;const r=n=>h=>{h.stopPropagation(),n()};return i.html`<div
2614
+ class="thread ${s?"active":""}"
2611
2615
  role="button"
2612
2616
  tabindex="0"
2613
- aria-current=${i?"true":"false"}
2617
+ aria-current=${s?"true":"false"}
2614
2618
  @click=${()=>this.openChat(e._id)}
2615
2619
  @keydown=${n=>n.key==="Enter"&&this.openChat(e._id)}
2616
2620
  >
2617
2621
  <span class="thread-title">${a}</span>
2618
2622
  <span class="thread-actions">
2619
- ${this.allowBookmark?s.html`<button
2623
+ ${this.allowBookmark?i.html`<button
2620
2624
  type="button"
2621
2625
  class="icon sm ${e.bookmarked?"on":""}"
2622
2626
  title=${e.bookmarked?t.unbookmarkChat:t.bookmarkChat}
@@ -2624,8 +2628,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2624
2628
  @click=${r(()=>this.toggleChatBookmark(e._id))}
2625
2629
  >
2626
2630
  ${y.bookmark(!!e.bookmarked)}
2627
- </button>`:s.nothing}
2628
- ${this.allowRename?s.html`<button
2631
+ </button>`:i.nothing}
2632
+ ${this.allowRename?i.html`<button
2629
2633
  type="button"
2630
2634
  class="icon sm"
2631
2635
  title=${t.renameChat}
@@ -2633,8 +2637,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2633
2637
  @click=${r(()=>{this.renamingId=e._id,this.focusNext="input.thread-rename"})}
2634
2638
  >
2635
2639
  ${y.pencil()}
2636
- </button>`:s.nothing}
2637
- ${this.allowDelete?s.html`<button
2640
+ </button>`:i.nothing}
2641
+ ${this.allowDelete?i.html`<button
2638
2642
  type="button"
2639
2643
  class="icon sm danger"
2640
2644
  title=${t.deleteChat}
@@ -2642,16 +2646,16 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2642
2646
  @click=${r(()=>this.deleteChat(e._id))}
2643
2647
  >
2644
2648
  ${y.trash()}
2645
- </button>`:s.nothing}
2649
+ </button>`:i.nothing}
2646
2650
  </span>
2647
- </div>`}renderHeader(){const e=this.msg,t=!!this.activeId,i=(this.embed==="inline"||this.embed==="launcher")&&!this.mobile,a=this.embed==="launcher"?()=>this.close():this.expanded?()=>this.collapse():null;let r=s.nothing;return this.showTitle&&(r=this.editingTitle?s.html`<input
2651
+ </div>`}renderHeader(){const e=this.msg,t=!!this.activeId,s=(this.embed==="inline"||this.embed==="launcher")&&!this.mobile,a=this.embed==="launcher"?()=>this.close():this.expanded?()=>this.collapse():null;let r=i.nothing;return this.showTitle&&(r=this.editingTitle?i.html`<input
2648
2652
  class="title-input"
2649
2653
  maxlength="80"
2650
2654
  .value=${this.chatTitle}
2651
2655
  aria-label=${e.renameChat}
2652
2656
  @keydown=${n=>{n.key==="Enter"&&this.commitTitle(n.target.value),n.key==="Escape"&&(n.stopPropagation(),this.editingTitle=!1)}}
2653
2657
  @blur=${n=>this.commitTitle(n.target.value)}
2654
- />`:s.html`<button
2658
+ />`:i.html`<button
2655
2659
  type="button"
2656
2660
  class="title"
2657
2661
  part="title"
@@ -2660,9 +2664,9 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2660
2664
  @click=${()=>{this.editingTitle=!0,this.focusNext="input.title-input"}}
2661
2665
  >
2662
2666
  ${this.chatTitle||e.untitled}
2663
- </button>`),s.html`<header class="header" part="header">
2667
+ </button>`),i.html`<header class="header" part="header">
2664
2668
  <div class="header-left">
2665
- ${this.sidebar==="none"||this.sidebarOpen&&this.docked?s.nothing:s.html`<button
2669
+ ${this.sidebar==="none"||this.sidebarOpen&&this.docked?i.nothing:i.html`<button
2666
2670
  type="button"
2667
2671
  class="icon"
2668
2672
  title=${e.showChats}
@@ -2674,7 +2678,7 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2674
2678
  ${r}
2675
2679
  </div>
2676
2680
  <div class="header-right">
2677
- ${this.sidebar==="none"&&this.showNewChat?s.html`<button
2681
+ ${this.sidebar==="none"&&this.showNewChat?i.html`<button
2678
2682
  type="button"
2679
2683
  class="icon"
2680
2684
  ?disabled=${!this.msgs.length&&!t}
@@ -2683,8 +2687,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2683
2687
  @click=${()=>this.newChat()}
2684
2688
  >
2685
2689
  ${y.plus()}
2686
- </button>`:s.nothing}
2687
- ${this.allowBookmark?s.html`<button
2690
+ </button>`:i.nothing}
2691
+ ${this.allowBookmark?i.html`<button
2688
2692
  type="button"
2689
2693
  class="icon ${this.bookmarked?"on":""}"
2690
2694
  ?disabled=${!t}
@@ -2693,8 +2697,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2693
2697
  @click=${()=>this.activeId&&this.toggleChatBookmark(this.activeId)}
2694
2698
  >
2695
2699
  ${y.bookmark(this.bookmarked)}
2696
- </button>`:s.nothing}
2697
- ${this.allowExport?s.html`<div class="menu-wrap">
2700
+ </button>`:i.nothing}
2701
+ ${this.allowExport?i.html`<div class="menu-wrap">
2698
2702
  <button
2699
2703
  type="button"
2700
2704
  class="icon ${this.menuOpen?"on":""}"
@@ -2707,9 +2711,9 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2707
2711
  >
2708
2712
  ${y.download()}
2709
2713
  </button>
2710
- ${this.menuOpen?this.renderExportMenu():s.nothing}
2711
- </div>`:s.nothing}
2712
- ${this.allowDelete?s.html`<button
2714
+ ${this.menuOpen?this.renderExportMenu():i.nothing}
2715
+ </div>`:i.nothing}
2716
+ ${this.allowDelete?i.html`<button
2713
2717
  type="button"
2714
2718
  class="icon danger"
2715
2719
  ?disabled=${!t}
@@ -2718,8 +2722,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2718
2722
  @click=${()=>this.activeId&&this.deleteChat(this.activeId)}
2719
2723
  >
2720
2724
  ${y.trash()}
2721
- </button>`:s.nothing}
2722
- ${i||a?s.html`<span class="divider"></span> ${i?s.html`<button
2725
+ </button>`:i.nothing}
2726
+ ${s||a?i.html`<span class="divider"></span> ${s?i.html`<button
2723
2727
  type="button"
2724
2728
  class="icon"
2725
2729
  title=${this.expanded?e.restore:e.expand}
@@ -2727,8 +2731,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2727
2731
  @click=${()=>this.expanded?this.collapse():this.expand()}
2728
2732
  >
2729
2733
  ${this.expanded?y.restore():y.expand()}
2730
- </button>`:s.nothing}
2731
- ${a?s.html`<button
2734
+ </button>`:i.nothing}
2735
+ ${a?i.html`<button
2732
2736
  type="button"
2733
2737
  class="icon"
2734
2738
  title=${e.minimize}
@@ -2736,30 +2740,30 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2736
2740
  @click=${a}
2737
2741
  >
2738
2742
  ${y.minimize()}
2739
- </button>`:s.nothing}`:s.nothing}
2743
+ </button>`:i.nothing}`:i.nothing}
2740
2744
  </div>
2741
- </header>`}renderExportMenu(){const e=this.msg,t=[[e.exportMarkdown,".md","md"],[e.exportJson,".json","json"],[e.exportText,".txt","txt"],[e.exportCopy,"","copy"]];return s.html`<div class="menu-scrim" @click=${()=>this.menuOpen=!1}></div>
2745
+ </header>`}renderExportMenu(){const e=this.msg,t=[[e.exportMarkdown,".md","md"],[e.exportJson,".json","json"],[e.exportText,".txt","txt"],[e.exportCopy,"","copy"]];return i.html`<div class="menu-scrim" @click=${()=>this.menuOpen=!1}></div>
2742
2746
  <div class="menu" role="menu">
2743
2747
  <span class="label">${e.exportHeading}</span>
2744
- ${t.map(([i,a,r])=>s.html`<button
2748
+ ${t.map(([s,a,r])=>i.html`<button
2745
2749
  type="button"
2746
2750
  role="menuitem"
2747
2751
  class="menu-item"
2748
2752
  @click=${()=>this.exportChat(r)}
2749
2753
  >
2750
- <span>${i}</span><span class="ext">${a}</span>
2754
+ <span>${s}</span><span class="ext">${a}</span>
2751
2755
  </button>`)}
2752
- </div>`}promptList(){const e=this.prompts;return Array.isArray(e)?e.map(t=>typeof t=="string"?{text:t}:t).filter(t=>t==null?void 0:t.text).slice(0,4):typeof e=="string"&&e.trim().toLowerCase()==="none"?[]:typeof e=="string"&&e.trim()?e.split("|").map(t=>t.trim()).filter(Boolean).slice(0,4).map(t=>({text:t})):(zt[this.mode]??zt.chat).map(([t,i])=>({label:t,text:i}))}renderWelcome(){const e=this.msg,t=this.mode==="rag"?"Rag":"Chat",i=n=>e[`${n}${t}`],a=this.eyebrow??i("eyebrow"),r=this.promptList();return s.html`<div class="welcome-slot">
2756
+ </div>`}promptList(){const e=this.prompts;return Array.isArray(e)?e.map(t=>typeof t=="string"?{text:t}:t).filter(t=>t==null?void 0:t.text).slice(0,4):typeof e=="string"&&e.trim().toLowerCase()==="none"?[]:typeof e=="string"&&e.trim()?e.split("|").map(t=>t.trim()).filter(Boolean).slice(0,4).map(t=>({text:t})):(jt[this.mode]??jt.chat).map(([t,s])=>({label:t,text:s}))}renderWelcome(){const e=this.msg,t=this.mode==="rag"?"Rag":this.mode==="kb"?"Kb":"Chat",s=n=>e[`${n}${t}`],a=this.eyebrow??s("eyebrow"),r=this.promptList();return i.html`<div class="welcome-slot">
2753
2757
  <slot name="welcome"
2754
2758
  ><div class="welcome" part="welcome">
2755
2759
  <div class="welcome-head">
2756
- ${this.logoUrl&&Ct(this.logoUrl,!0)?s.html`<img class="welcome-logo" src=${this.logoUrl} alt="" />`:s.nothing}
2757
- ${a?s.html`<span class="label">${a}</span>`:s.nothing}
2758
- <h2>${this.heading||i("heading")}</h2>
2759
- <p>${this.description||i("description")}</p>
2760
+ ${this.logoUrl&&It(this.logoUrl,!0)?i.html`<img class="welcome-logo" src=${this.logoUrl} alt="" />`:i.nothing}
2761
+ ${a?i.html`<span class="label">${a}</span>`:i.nothing}
2762
+ <h2>${this.heading||s("heading")}</h2>
2763
+ <p>${this.description||s("description")}</p>
2760
2764
  </div>
2761
- ${r.length?s.html`<div class="prompts">
2762
- ${r.map(n=>s.html`<button
2765
+ ${r.length?i.html`<div class="prompts">
2766
+ ${r.map(n=>i.html`<button
2763
2767
  type="button"
2764
2768
  class="prompt"
2765
2769
  part="prompt"
@@ -2768,27 +2772,27 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2768
2772
  <span class="label">${n.label||"Suggested"}</span>
2769
2773
  <span class="prompt-text">${n.text}</span>
2770
2774
  </button>`)}
2771
- </div>`:s.nothing}
2775
+ </div>`:i.nothing}
2772
2776
  </div></slot
2773
2777
  >
2774
- </div>`}renderThread(){const e=this.msgs.map(t=>t.role).lastIndexOf("assistant");return s.html`<div class="thread-view">
2775
- ${this.threadError?s.html`<div class="error-card" role="alert">
2778
+ </div>`}renderThread(){const e=this.msgs.map(t=>t.role).lastIndexOf("assistant");return i.html`<div class="thread-view">
2779
+ ${this.threadError?i.html`<div class="error-card" role="alert">
2776
2780
  <span>${this.threadError}</span>
2777
- ${this.activeId?s.html`<button
2781
+ ${this.activeId?i.html`<button
2778
2782
  type="button"
2779
2783
  class="btn"
2780
2784
  @click=${()=>this.openChat(this.activeId)}
2781
2785
  >
2782
2786
  ${this.msg.retry}
2783
- </button>`:s.nothing}
2784
- </div>`:s.nothing}
2785
- ${this.loadingThread?s.html`${[1,2].map(()=>s.html`<div class="skeleton" style="height:48px"></div>`)}`:s.nothing}
2786
- ${Jt.repeat(this.msgs,t=>t.key,(t,i)=>t.role==="user"?this.renderUser(t):this.renderBot(t,i===e))}
2787
- </div>`}renderUser(e){const t=this.msg,i=e.at?new Date(e.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):"",a=e.attachments??[];return s.html`<div class="msg user" part="message user">
2788
- ${a.length?s.html`<div class="attachments">
2789
- ${a.map(r=>s.html`<span class="doc-chip"><span class="ext">${Lt(r.name)}</span><span class="name">${r.name}</span></span>`)}
2790
- </div>`:s.nothing}
2791
- ${this.editingKey===e.key?s.html`<div class="edit-box">
2787
+ </button>`:i.nothing}
2788
+ </div>`:i.nothing}
2789
+ ${this.loadingThread?i.html`${[1,2].map(()=>i.html`<div class="skeleton" style="height:48px"></div>`)}`:i.nothing}
2790
+ ${Gt.repeat(this.msgs,t=>t.key,(t,s)=>t.role==="user"?this.renderUser(t):this.renderBot(t,s===e))}
2791
+ </div>`}renderUser(e){const t=this.msg,s=e.at?new Date(e.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):"",a=e.attachments??[];return i.html`<div class="msg user" part="message user">
2792
+ ${a.length?i.html`<div class="attachments">
2793
+ ${a.map(r=>i.html`<span class="doc-chip"><span class="ext">${mt(r.name)}</span><span class="name">${r.name}</span></span>`)}
2794
+ </div>`:i.nothing}
2795
+ ${this.editingKey===e.key?i.html`<div class="edit-box">
2792
2796
  <textarea
2793
2797
  rows="3"
2794
2798
  class="edit-input"
@@ -2804,11 +2808,11 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2804
2808
  ${t.saveResend}
2805
2809
  </button>
2806
2810
  </div>
2807
- </div>`:s.html`<div class="bubble-user">${e.content}</div>
2811
+ </div>`:i.html`<div class="bubble-user">${e.content}</div>
2808
2812
  <div class="toolbar">
2809
- ${this.allowBookmark&&e.bookmarked?s.html`<span class="saved">${y.bookmark(!0)}${t.saved}</span>`:s.nothing}
2810
- ${this.showTime?s.html`<span class="time">${i}</span>`:s.nothing}
2811
- ${this.busy?s.nothing:s.html`<button
2813
+ ${this.allowBookmark&&e.bookmarked?i.html`<span class="saved">${y.bookmark(!0)}${t.saved}</span>`:i.nothing}
2814
+ ${this.showTime?i.html`<span class="time">${s}</span>`:i.nothing}
2815
+ ${this.busy?i.nothing:i.html`<button
2812
2816
  type="button"
2813
2817
  class="icon"
2814
2818
  title=${t.edit}
@@ -2817,7 +2821,7 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2817
2821
  >
2818
2822
  ${y.pencil()}
2819
2823
  </button>`}
2820
- ${this.allowCopy?s.html`<button
2824
+ ${this.allowCopy?i.html`<button
2821
2825
  type="button"
2822
2826
  class="icon"
2823
2827
  title=${this.copiedKey===e.key?t.copied:t.copy}
@@ -2825,8 +2829,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2825
2829
  @click=${()=>this.copy(e.key,e.content)}
2826
2830
  >
2827
2831
  ${y.copy()}
2828
- </button>`:s.nothing}
2829
- ${this.allowBookmark&&e.id?s.html`<button
2832
+ </button>`:i.nothing}
2833
+ ${this.allowBookmark&&e.id?i.html`<button
2830
2834
  type="button"
2831
2835
  class="icon ${e.bookmarked?"on":""}"
2832
2836
  title=${e.bookmarked?t.unbookmarkMessage:t.bookmarkMessage}
@@ -2834,8 +2838,8 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2834
2838
  @click=${()=>this.toggleMessageBookmark(e)}
2835
2839
  >
2836
2840
  ${y.bookmark(e.bookmarked)}
2837
- </button>`:s.nothing}
2838
- ${this.allowDelete?s.html`<button
2841
+ </button>`:i.nothing}
2842
+ ${this.allowDelete?i.html`<button
2839
2843
  type="button"
2840
2844
  class="icon danger"
2841
2845
  title=${t.deleteMessage}
@@ -2843,139 +2847,140 @@ assistant: ${i.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
2843
2847
  @click=${()=>this.deleteMessage(e)}
2844
2848
  >
2845
2849
  ${y.trash()}
2846
- </button>`:s.nothing}
2850
+ </button>`:i.nothing}
2847
2851
  </div>`}
2848
- </div>`}pillLabel(){return this.mode==="rag"?this.msg.searching:this.msg.thinking}renderBot(e,t){const i=this.msg,a=e.phase==="pending",r=e.phase==="done",n=e.sources.length,d=ut(e.content),c=e.sources.map((v,M)=>L(v,M+1)),b=d.size?c.filter(v=>d.has(v.n)):c,f=e.at?new Date(e.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):"",k=e.content+(b.length?`
2852
+ </div>`}pillLabel(){return this.mode==="rag"||this.mode==="kb"?this.msg.searching:this.msg.thinking}renderBot(e,t){const s=this.msg,a=e.phase==="pending",r=e.phase==="done",n=e.sources.length,h=bt(e.content),c=e.sources.map((x,O)=>L(x,O+1)),f=h.size?c.filter(x=>h.has(x.n)):c,b=e.at?new Date(e.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):"",w=e.content+(f.length?`
2849
2853
 
2850
2854
  Sources:
2851
- ${b.map(v=>`[${v.n}] ${v.title}`).join(`
2852
- `)}`:""),C=this.retrievalOpen.has(e.key);return s.html`<div class="msg bot" part="message assistant">
2853
- ${a?s.html`<div class="halo"></div>`:s.nothing}
2854
- ${this.arrivedKey===e.key?s.html`<div class="arrived">
2855
+ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
2856
+ `)}`:""),$=this.retrievalOpen.has(e.key);return i.html`<div class="msg bot" part="message assistant">
2857
+ ${a?i.html`<div class="halo"></div>`:i.nothing}
2858
+ ${this.arrivedKey===e.key?i.html`<div class="arrived">
2855
2859
  <div class="wash"></div>
2856
2860
  <div class="ring"></div>
2857
2861
  <div class="sweep"></div>
2858
- </div>`:s.nothing}
2862
+ </div>`:i.nothing}
2859
2863
  <div class="bot-body">
2860
- ${this.allowBookmark&&e.bookmarked?s.html`<span class="saved">${y.bookmark(!0)}${i.saved}</span>`:s.nothing}
2861
- ${a?s.html`<div class="pill" role="status">
2864
+ ${this.allowBookmark&&e.bookmarked?i.html`<span class="saved">${y.bookmark(!0)}${s.saved}</span>`:i.nothing}
2865
+ ${a?i.html`<div class="pill" role="status">
2862
2866
  <span class="ring"></span><span class="dot"></span>
2863
2867
  <span class="shimmer">${this.pillLabel()}</span>
2864
- </div>`:s.nothing}
2865
- ${this.showSources&&n&&!a?s.html`<div class="retrieval">
2868
+ </div>`:i.nothing}
2869
+ ${this.showSources&&n&&!a?i.html`<div class="retrieval">
2866
2870
  <button
2867
2871
  type="button"
2868
2872
  class="retrieval-toggle"
2869
- aria-expanded=${C?"true":"false"}
2870
- @click=${()=>{const v=new Set(this.retrievalOpen);v.has(e.key)?v.delete(e.key):v.add(e.key),this.retrievalOpen=v}}
2873
+ aria-expanded=${$?"true":"false"}
2874
+ @click=${()=>{const x=new Set(this.retrievalOpen);x.has(e.key)?x.delete(e.key):x.add(e.key),this.retrievalOpen=x}}
2871
2875
  >
2872
- <span class="chev">${C?"▾":"▸"}</span>
2873
- <span style="flex:1">${T.fill(i.searchedSources,{n})}</span>
2874
- ${e.execTime!==void 0?s.html`<span class="ms">${e.execTime.toFixed(1)}s</span>`:s.nothing}
2876
+ <span class="chev">${$?"▾":"▸"}</span>
2877
+ <span style="flex:1">${T.fill(s.searchedSources,{n})}</span>
2878
+ ${e.execTime!==void 0?i.html`<span class="ms">${e.execTime.toFixed(1)}s</span>`:i.nothing}
2875
2879
  </button>
2876
- ${C?s.html`<div class="retrieval-list">
2877
- ${c.map(v=>s.html`<button
2880
+ ${$?i.html`<div class="retrieval-list">
2881
+ ${c.map(x=>i.html`<button
2878
2882
  type="button"
2879
2883
  class="passage"
2880
- @click=${()=>this.panel={key:e.key,n:v.n}}
2884
+ @click=${()=>this.panel={key:e.key,n:x.n}}
2881
2885
  >
2882
- <span class="n">${v.n}</span>
2886
+ <span class="n">${x.n}</span>
2883
2887
  <span class="what"
2884
- ><span>${v.title}</span><span>${v.collection||v.path}</span></span
2888
+ ><span>${x.title}${x.section?` · ${x.section}`:""}</span
2889
+ ><span>${x.collection||x.path}</span></span
2885
2890
  >
2886
- ${v.score!==null?s.html`<span class="relevance"
2887
- ><span class="score">${v.score.toFixed(2)}</span>
2891
+ ${x.score!==null?i.html`<span class="relevance"
2892
+ ><span class="score">${x.score.toFixed(2)}</span>
2888
2893
  <span class="relevance-track"
2889
2894
  ><span
2890
2895
  class="relevance-fill"
2891
- style="width:${Math.round(v.score*100)}%"
2896
+ style="width:${Math.round(x.score*100)}%"
2892
2897
  ></span></span
2893
- ></span>`:s.html`<span></span>`}
2898
+ ></span>`:i.html`<span></span>`}
2894
2899
  </button>`)}
2895
- </div>`:s.nothing}
2896
- </div>`:s.nothing}
2897
- ${a?s.nothing:this.renderAnswer(e)}
2898
- ${e.phase==="streaming"?s.html`<span class="caret"></span>`:s.nothing}
2899
- ${e.phase==="error"?s.html`<div class="error-card" role="alert">
2900
+ </div>`:i.nothing}
2901
+ </div>`:i.nothing}
2902
+ ${a?i.nothing:this.renderAnswer(e)}
2903
+ ${e.phase==="streaming"?i.html`<span class="caret"></span>`:i.nothing}
2904
+ ${e.phase==="error"?i.html`<div class="error-card" role="alert">
2900
2905
  <span>${e.error}</span>
2901
2906
  <button type="button" class="btn" @click=${()=>this.retry(e)}>
2902
- ${i.retry}
2907
+ ${s.retry}
2903
2908
  </button>
2904
- </div>`:s.nothing}
2905
- ${this.showSources&&r&&b.length?s.html`<div class="cards">
2906
- <span class="label">${d.size?i.sourcesCited:i.sourcesRetrieved}</span>
2909
+ </div>`:i.nothing}
2910
+ ${this.showSources&&r&&f.length?i.html`<div class="cards">
2911
+ <span class="label">${h.size?s.sourcesCited:s.sourcesRetrieved}</span>
2907
2912
  <div class="card-grid">
2908
- ${b.map(v=>{var M;return s.html`<button
2913
+ ${f.map(x=>{var O;return i.html`<button
2909
2914
  type="button"
2910
- class="source-card ${((M=this.panel)==null?void 0:M.key)===e.key&&this.panel.n===v.n?"active":""}"
2911
- @click=${()=>this.panel={key:e.key,n:v.n}}
2915
+ class="source-card ${((O=this.panel)==null?void 0:O.key)===e.key&&this.panel.n===x.n?"active":""}"
2916
+ @click=${()=>this.panel={key:e.key,n:x.n}}
2912
2917
  >
2913
2918
  <span class="top"
2914
- ><span class="num">${v.n}</span
2915
- >${v.collection?s.html`<span class="label">${v.collection}</span>`:s.nothing}</span
2919
+ ><span class="num">${x.n}</span
2920
+ >${x.collection?i.html`<span class="label">${x.collection}</span>`:i.nothing}</span
2916
2921
  >
2917
- <span class="t">${v.title}</span>
2918
- <span class="s">${v.text}</span>
2922
+ <span class="t">${x.title}${x.section?` · ${x.section}`:""}</span>
2923
+ <span class="s">${x.text}</span>
2919
2924
  </button>`})}
2920
2925
  </div>
2921
- </div>`:s.nothing}
2922
- ${r?s.html`<div class="toolbar ${t?"pinned":""}">
2923
- ${this.allowCopy?s.html`<button
2926
+ </div>`:i.nothing}
2927
+ ${r?i.html`<div class="toolbar ${t?"pinned":""}">
2928
+ ${this.allowCopy?i.html`<button
2924
2929
  type="button"
2925
2930
  class="icon"
2926
- title=${this.copiedKey===e.key?i.copied:i.copy}
2927
- aria-label=${i.copy}
2928
- @click=${()=>this.copy(e.key,k)}
2931
+ title=${this.copiedKey===e.key?s.copied:s.copy}
2932
+ aria-label=${s.copy}
2933
+ @click=${()=>this.copy(e.key,w)}
2929
2934
  >
2930
2935
  ${y.copy()}
2931
- </button>`:s.nothing}
2932
- ${this.allowRaw&&this.formatLevel!=="raw"&&e.content?s.html`<button
2936
+ </button>`:i.nothing}
2937
+ ${this.allowRaw&&this.formatLevel!=="raw"&&e.content?i.html`<button
2933
2938
  type="button"
2934
2939
  class="icon ${this.rawKeys.has(e.key)?"on":""}"
2935
- title=${this.rawKeys.has(e.key)?i.showFormatted:i.showRaw}
2936
- aria-label=${i.showRaw}
2940
+ title=${this.rawKeys.has(e.key)?s.showFormatted:s.showRaw}
2941
+ aria-label=${s.showRaw}
2937
2942
  aria-pressed=${this.rawKeys.has(e.key)?"true":"false"}
2938
2943
  @click=${()=>this.toggleRaw(e.key)}
2939
2944
  >
2940
2945
  ${y.raw()}
2941
- </button>`:s.nothing}
2942
- ${this.allowRegenerate&&t&&!this.busy?s.html`<button
2946
+ </button>`:i.nothing}
2947
+ ${this.allowRegenerate&&t&&!this.busy?i.html`<button
2943
2948
  type="button"
2944
2949
  class="icon"
2945
- title=${i.regenerate}
2946
- aria-label=${i.regenerate}
2950
+ title=${s.regenerate}
2951
+ aria-label=${s.regenerate}
2947
2952
  @click=${()=>this.regenerate()}
2948
2953
  >
2949
2954
  ${y.refresh()}
2950
- </button>`:s.nothing}
2951
- ${this.allowBookmark&&e.id?s.html`<button
2955
+ </button>`:i.nothing}
2956
+ ${this.allowBookmark&&e.id?i.html`<button
2952
2957
  type="button"
2953
2958
  class="icon ${e.bookmarked?"on":""}"
2954
- title=${e.bookmarked?i.unbookmarkMessage:i.bookmarkMessage}
2955
- aria-label=${e.bookmarked?i.unbookmarkMessage:i.bookmarkMessage}
2959
+ title=${e.bookmarked?s.unbookmarkMessage:s.bookmarkMessage}
2960
+ aria-label=${e.bookmarked?s.unbookmarkMessage:s.bookmarkMessage}
2956
2961
  @click=${()=>this.toggleMessageBookmark(e)}
2957
2962
  >
2958
2963
  ${y.bookmark(e.bookmarked)}
2959
- </button>`:s.nothing}
2960
- ${this.allowDelete?s.html`<button
2964
+ </button>`:i.nothing}
2965
+ ${this.allowDelete?i.html`<button
2961
2966
  type="button"
2962
2967
  class="icon danger"
2963
- title=${i.deleteMessage}
2964
- aria-label=${i.deleteMessage}
2968
+ title=${s.deleteMessage}
2969
+ aria-label=${s.deleteMessage}
2965
2970
  @click=${()=>this.deleteMessage(e)}
2966
2971
  >
2967
2972
  ${y.trash()}
2968
- </button>`:s.nothing}
2969
- ${this.showTime?s.html`<span class="time">${f}</span>`:s.nothing}
2970
- ${e.stopped?s.html`<span class="note">${i.stopped}</span>`:s.nothing}
2973
+ </button>`:i.nothing}
2974
+ ${this.showTime?i.html`<span class="time">${b}</span>`:i.nothing}
2975
+ ${e.stopped?i.html`<span class="note">${s.stopped}</span>`:i.nothing}
2971
2976
  <span class="spacer"></span>
2972
- ${this.allowFeedback?e.feedback?s.html`<span class="note"
2973
- >${e.feedback==="up"?i.markedHelpful:i.thanksFeedback}</span
2974
- >`:s.html`<button
2977
+ ${this.allowFeedback?e.feedback?i.html`<span class="note"
2978
+ >${e.feedback==="up"?s.markedHelpful:s.thanksFeedback}</span
2979
+ >`:i.html`<button
2975
2980
  type="button"
2976
2981
  class="icon"
2977
- title=${i.helpful}
2978
- aria-label=${i.helpful}
2982
+ title=${s.helpful}
2983
+ aria-label=${s.helpful}
2979
2984
  @click=${()=>this.feedback(e,"up")}
2980
2985
  >
2981
2986
  ${y.thumb()}
@@ -2983,121 +2988,121 @@ ${b.map(v=>`[${v.n}] ${v.title}`).join(`
2983
2988
  <button
2984
2989
  type="button"
2985
2990
  class="icon"
2986
- title=${i.notHelpful}
2987
- aria-label=${i.notHelpful}
2991
+ title=${s.notHelpful}
2992
+ aria-label=${s.notHelpful}
2988
2993
  @click=${()=>this.feedback(e,"down")}
2989
2994
  >
2990
2995
  ${y.thumb(!0)}
2991
- </button>`:s.nothing}
2992
- </div>`:s.nothing}
2993
- ${this.showFollowups&&r&&t&&!this.busy&&e.followups.length?s.html`<div class="followups">
2994
- ${e.followups.map(v=>s.html`<button type="button" class="followup" @click=${()=>this.send(v)}>
2995
- <span class="arrow">↳</span><span>${v}</span>
2996
+ </button>`:i.nothing}
2997
+ </div>`:i.nothing}
2998
+ ${this.showFollowups&&r&&t&&!this.busy&&e.followups.length?i.html`<div class="followups">
2999
+ ${e.followups.map(x=>i.html`<button type="button" class="followup" @click=${()=>this.send(x)}>
3000
+ <span class="arrow">↳</span><span>${x}</span>
2996
3001
  </button>`)}
2997
- </div>`:s.nothing}
3002
+ </div>`:i.nothing}
2998
3003
  </div>
2999
- </div>`}renderAnswer(e){if(e.phase==="error"&&!e.content)return s.nothing;if(e.phase==="done"&&!e.content)return e.stopped?s.nothing:s.html`<div class="answer"><p class="note">${this.msg.emptyReply}</p></div>`;const t=this.formatLevel;if(t==="raw"||this.allowRaw&&this.rawKeys.has(e.key))return s.html`<div class="answer" part="answer"><p class="raw">${e.content}</p></div>`;const i=e.phase==="streaming"?Dt(e.content):e.content;let a=Ft(Rt(i),t);if(this.afterParse)try{const n=this.afterParse(a,{message:e,format:t});Array.isArray(n)?a=n:console.warn("[singlebase-chat] afterParse must return an array of blocks; showing the original.")}catch(n){console.warn("[singlebase-chat] afterParse failed; showing the original.",n)}const r=e.sources.length;return s.html`<div class="answer" part="answer">
3000
- ${a.map((n,d)=>this.renderBlock(n,e,r,d))}
3001
- </div>`}renderInline(e,t,i){return Bt(e,i).map(a=>{var r;switch(a.type){case"bold":return s.html`<strong>${a.text}</strong>`;case"italic":return s.html`<em>${a.text}</em>`;case"strike":return s.html`<s>${a.text}</s>`;case"code":return s.html`<code class="inline">${a.text}</code>`;case"link":return s.html`<a href=${a.href} target="_blank" rel="noopener noreferrer nofollow"
3004
+ </div>`}renderAnswer(e){if(e.phase==="error"&&!e.content)return i.nothing;if(e.phase==="done"&&!e.content)return e.stopped?i.nothing:i.html`<div class="answer"><p class="note">${this.msg.emptyReply}</p></div>`;const t=this.formatLevel;if(t==="raw"||this.allowRaw&&this.rawKeys.has(e.key))return i.html`<div class="answer" part="answer"><p class="raw">${e.content}</p></div>`;const s=e.phase==="streaming"?Pt(e.content):e.content;let a=Ut(Dt(s),t);if(this.afterParse)try{const n=this.afterParse(a,{message:e,format:t});Array.isArray(n)?a=n:console.warn("[singlebase-chat] afterParse must return an array of blocks; showing the original.")}catch(n){console.warn("[singlebase-chat] afterParse failed; showing the original.",n)}const r=e.sources.reduce((n,h,c)=>Math.max(n,L(h,c+1).n),0);return i.html`<div class="answer" part="answer">
3005
+ ${a.map((n,h)=>this.renderBlock(n,e,r,h))}
3006
+ </div>`}renderInline(e,t,s){return Kt(e,s).map(a=>{var r;switch(a.type){case"bold":return i.html`<strong>${a.text}</strong>`;case"italic":return i.html`<em>${a.text}</em>`;case"strike":return i.html`<s>${a.text}</s>`;case"code":return i.html`<code class="inline">${a.text}</code>`;case"link":return i.html`<a href=${a.href} target="_blank" rel="noopener noreferrer nofollow"
3002
3007
  >${a.text}</a
3003
- >`;case"cite":{const n=((r=this.panel)==null?void 0:r.key)===t.key&&this.panel.n===a.n?"cite active":"cite",d=T.fill(this.msg.openSource,{n:a.n}),c=()=>this.panel={key:t.key,n:a.n};return s.html`<button type="button" class=${n} aria-label=${d} @click=${c}>${a.n}</button>`}default:return a.text}})}renderBlock(e,t,i,a){switch(e.type){case"p":return s.html`<p>${this.renderInline(e.text,t,i)}</p>`;case"raw":return s.html`<p class="raw">${e.text}</p>`;case"h":return s.html`<h3 class="h${e.level}">${this.renderInline(e.text,t,i)}</h3>`;case"hr":return s.html`<hr />`;case"list":return this.renderList(e.ordered,e.items,t,i);case"quote":return s.html`<div class="quote">${this.renderInline(e.text,t,i)}</div>`;case"callout":return s.html`<div class="callout ${e.kind}" role="note" part="callout">
3008
+ >`;case"cite":{const n=((r=this.panel)==null?void 0:r.key)===t.key&&this.panel.n===a.n?"cite active":"cite",h=T.fill(this.msg.openSource,{n:a.n}),c=()=>this.panel={key:t.key,n:a.n};return i.html`<button type="button" class=${n} aria-label=${h} @click=${c}>${a.n}</button>`}default:return a.text}})}renderBlock(e,t,s,a){switch(e.type){case"p":return i.html`<p>${this.renderInline(e.text,t,s)}</p>`;case"raw":return i.html`<p class="raw">${e.text}</p>`;case"h":return i.html`<h3 class="h${e.level}">${this.renderInline(e.text,t,s)}</h3>`;case"hr":return i.html`<hr />`;case"list":return this.renderList(e.ordered,e.items,t,s);case"quote":return i.html`<div class="quote">${this.renderInline(e.text,t,s)}</div>`;case"callout":return i.html`<div class="callout ${e.kind}" role="note" part="callout">
3004
3009
  <strong class="callout-title"
3005
- >${e.title||this.msg[xi[e.kind]]}</strong
3010
+ >${e.title||this.msg[ws[e.kind]]}</strong
3006
3011
  >
3007
3012
  ${e.text.split(`
3008
- `).filter(r=>r.trim()).map(r=>s.html`<p>${this.renderInline(r,t,i)}</p>`)}
3009
- </div>`;case"code":return this.renderCustom(e.lang,e.text,t)??this.renderCode(e.lang,e.text,`${t.key}:${a}`);case"table":return this.renderTable(e.head,e.rows,e.align,t,i,`${t.key}:${a}`);case"json":return this.renderJsonBlock(e.value,e.source,`${t.key}:${a}`);case"svg":{const r=Ut(e.source);if(!r)return this.renderCode("svg",e.source,`${t.key}:${a}`);const n=`${t.key}:${a}`;return s.html`<figure class="svg" part="svg">
3013
+ `).filter(r=>r.trim()).map(r=>i.html`<p>${this.renderInline(r,t,s)}</p>`)}
3014
+ </div>`;case"code":return this.renderCustom(e.lang,e.text,t)??this.renderCode(e.lang,e.text,`${t.key}:${a}`);case"table":return this.renderTable(e.head,e.rows,e.align,t,s,`${t.key}:${a}`);case"json":return this.renderJsonBlock(e.value,e.source,`${t.key}:${a}`);case"svg":{const r=Wt(e.source);if(!r)return this.renderCode("svg",e.source,`${t.key}:${a}`);const n=`${t.key}:${a}`;return i.html`<figure class="svg" part="svg">
3010
3015
  <img src=${r} alt="Drawing" />
3011
3016
  <figcaption>
3012
3017
  <button type="button" class="text-btn" @click=${()=>this.copy(n,e.source)}>
3013
3018
  ${this.copiedKey===n?this.msg.copied:this.msg.copySvg}
3014
3019
  </button>
3015
3020
  </figcaption>
3016
- </figure>`}case"pending":return s.html`<div class="chart-pending">
3021
+ </figure>`}case"pending":return i.html`<div class="chart-pending">
3017
3022
  <span class="label"
3018
3023
  >${e.kind==="svg"?this.msg.renderingSvg:this.msg.renderingChart}</span
3019
3024
  >
3020
- </div>`;case"chart":return this.renderChart(e.spec);case"img":return s.html`<div class="gallery ${e.images.length>1?"many":""}">
3021
- ${e.images.map(r=>s.html`<figure>
3022
- ${r.src&&Ct(r.src,!0)?s.html`<img
3025
+ </div>`;case"chart":return this.renderChart(e.spec);case"img":return i.html`<div class="gallery ${e.images.length>1?"many":""}">
3026
+ ${e.images.map(r=>i.html`<figure>
3027
+ ${r.src&&It(r.src,!0)?i.html`<img
3023
3028
  src=${r.src}
3024
3029
  alt=${r.alt}
3025
3030
  loading="lazy"
3026
3031
  referrerpolicy="no-referrer"
3027
- />`:s.html`<div class="img-missing"><span class="label">Image</span></div>`}
3028
- ${r.alt?s.html`<figcaption>${r.alt}</figcaption>`:s.nothing}
3032
+ />`:i.html`<div class="img-missing"><span class="label">Image</span></div>`}
3033
+ ${r.alt?i.html`<figcaption>${r.alt}</figcaption>`:i.nothing}
3029
3034
  </figure>`)}
3030
- </div>`;default:return s.nothing}}renderList(e,t,i,a){const r=t.map(n=>s.html`<li
3035
+ </div>`;default:return i.nothing}}renderList(e,t,s,a){const r=t.map(n=>i.html`<li
3031
3036
  class=${n.checked===null?"":"task"}
3032
3037
  style=${n.depth?`margin-left:${n.depth*20}px`:""}
3033
3038
  >
3034
- ${n.checked===null?s.nothing:s.html`<input type="checkbox" disabled .checked=${n.checked} aria-hidden="true" />`}
3035
- ${this.renderInline(n.text,i,a)}
3036
- </li>`);return e?s.html`<ol>
3039
+ ${n.checked===null?i.nothing:i.html`<input type="checkbox" disabled .checked=${n.checked} aria-hidden="true" />`}
3040
+ ${this.renderInline(n.text,s,a)}
3041
+ </li>`);return e?i.html`<ol>
3037
3042
  ${r}
3038
- </ol>`:s.html`<ul>
3043
+ </ol>`:i.html`<ul>
3039
3044
  ${r}
3040
- </ul>`}renderCode(e,t,i){return s.html`<div class="code">
3045
+ </ul>`}renderCode(e,t,s){return i.html`<div class="code">
3041
3046
  <div class="code-head">
3042
3047
  <span class="label">${e}</span>
3043
- <button type="button" class="text-btn" @click=${()=>this.copy(i,t)}>
3044
- ${this.copiedKey===i?this.msg.copied:this.msg.copy}
3048
+ <button type="button" class="text-btn" @click=${()=>this.copy(s,t)}>
3049
+ ${this.copiedKey===s?this.msg.copied:this.msg.copy}
3045
3050
  </button>
3046
3051
  </div>
3047
3052
  <pre><code>${t}</code></pre>
3048
- </div>`}renderCustom(e,t,i){var r;const a=this.formatLevel==="rich"?(r=this.renderers)==null?void 0:r[e]:void 0;if(typeof a!="function"||i.phase==="streaming")return null;try{const n=a(t,{lang:e,message:i});return n==null?null:s.html`<div class="custom-block">${n}</div>`}catch(n){return console.warn(`[singlebase-chat] the "${e}" renderer failed; showing the source`,n),null}}renderTable(e,t,i,a,r,n){const d=x=>/^[-+]?[$€£¥]?\s?[\d,.]+\s?%?$/.test(x.trim())&&/\d/.test(x),c=x=>Number(x.replace(/[^\d.+-]/g,"")),b=e.map((x,$)=>{if(i[$])return i[$];const w=t.map(z=>z[$]??"").filter(Boolean);return w.length&&w.filter(d).length/w.length>=.8?"right":null}),f=this.sorts.get(n);let k=t;f&&(k=[...t].sort((x,$)=>{const w=x[f.col]??"",z=$[f.col]??"";return(d(w)&&d(z)?c(w)-c(z):w.localeCompare(z,void 0,{numeric:!0}))*f.dir}));const C=k.length;k=k.slice(0,fi);const v=x=>{const $=new Map(this.sorts),w=$.get(n);(w==null?void 0:w.col)===x&&w.dir===-1?$.delete(n):$.set(n,{col:x,dir:(w==null?void 0:w.col)===x?-1:1}),this.sorts=$},M=x=>b[x]?`text-align:${b[x]}`:"";return s.html`<div class="table" part="table">
3053
+ </div>`}renderCustom(e,t,s){var r;const a=this.formatLevel==="rich"?(r=this.renderers)==null?void 0:r[e]:void 0;if(typeof a!="function"||s.phase==="streaming")return null;try{const n=a(t,{lang:e,message:s});return n==null?null:i.html`<div class="custom-block">${n}</div>`}catch(n){return console.warn(`[singlebase-chat] the "${e}" renderer failed; showing the source`,n),null}}renderTable(e,t,s,a,r,n){const h=v=>/^[-+]?[$€£¥]?\s?[\d,.]+\s?%?$/.test(v.trim())&&/\d/.test(v),c=v=>Number(v.replace(/[^\d.+-]/g,"")),f=e.map((v,C)=>{if(s[C])return s[C];const k=t.map(z=>z[C]??"").filter(Boolean);return k.length&&k.filter(h).length/k.length>=.8?"right":null}),b=this.sorts.get(n);let w=t;b&&(w=[...t].sort((v,C)=>{const k=v[b.col]??"",z=C[b.col]??"";return(h(k)&&h(z)?c(k)-c(z):k.localeCompare(z,void 0,{numeric:!0}))*b.dir}));const $=w.length;w=w.slice(0,ys);const x=v=>{const C=new Map(this.sorts),k=C.get(n);(k==null?void 0:k.col)===v&&k.dir===-1?C.delete(n):C.set(n,{col:v,dir:(k==null?void 0:k.col)===v?-1:1}),this.sorts=C},O=v=>f[v]?`text-align:${f[v]}`:"";return i.html`<div class="table" part="table">
3049
3054
  <table>
3050
3055
  <thead>
3051
3056
  <tr>
3052
- ${e.map((x,$)=>{const w=(f==null?void 0:f.col)===$?f.dir===1?"ascending":"descending":"none";return s.html`<th style=${M($)} aria-sort=${w}>
3053
- ${t.length>1?s.html`<button type="button" class="sort" @click=${()=>v($)}>
3054
- ${this.renderInline(x,a,r)}<span class="arrow"
3055
- >${w==="ascending"?"↑":w==="descending"?"↓":"↕"}</span
3057
+ ${e.map((v,C)=>{const k=(b==null?void 0:b.col)===C?b.dir===1?"ascending":"descending":"none";return i.html`<th style=${O(C)} aria-sort=${k}>
3058
+ ${t.length>1?i.html`<button type="button" class="sort" @click=${()=>x(C)}>
3059
+ ${this.renderInline(v,a,r)}<span class="arrow"
3060
+ >${k==="ascending"?"↑":k==="descending"?"↓":"↕"}</span
3056
3061
  >
3057
- </button>`:this.renderInline(x,a,r)}
3062
+ </button>`:this.renderInline(v,a,r)}
3058
3063
  </th>`})}
3059
3064
  </tr>
3060
3065
  </thead>
3061
3066
  <tbody>
3062
- ${k.map(x=>s.html`<tr>
3063
- ${e.map(($,w)=>s.html`<td style=${M(w)}>
3064
- ${this.renderInline(x[w]??"",a,r)}
3067
+ ${w.map(v=>i.html`<tr>
3068
+ ${e.map((C,k)=>i.html`<td style=${O(k)}>
3069
+ ${this.renderInline(v[k]??"",a,r)}
3065
3070
  </td>`)}
3066
3071
  </tr>`)}
3067
3072
  </tbody>
3068
3073
  </table>
3069
- ${C>k.length?s.html`<div class="table-note">
3070
- ${T.fill(this.msg.showingRows,{n:k.length,total:C})}
3071
- </div>`:s.nothing}
3072
- </div>`}renderJsonBlock(e,t,i){let a=0;const r=d=>{a++,a<=It&&d&&typeof d=="object"&&Object.values(d).forEach(r)};if(r(e),a>It)return this.renderCode("json",t,i);const n=(d,c,b)=>{const f=b===void 0?s.nothing:s.html`<span class="jkey">${b}</span>: `;if(d&&typeof d=="object"){const C=Object.entries(d),v=Array.isArray(d)?`[${C.length}]`:`{${C.length}}`;return s.html`<details class="jnode" ?open=${c<2}>
3073
- <summary>${f}<span class="jmeta">${v}</span></summary>
3074
- <div class="jkids">${C.map(([M,x])=>n(x,c+1,M))}</div>
3075
- </details>`}const k=d===null?"null":typeof d;return s.html`<div class="jleaf">
3076
- ${f}<span class="jv ${k}">${JSON.stringify(d)}</span>
3077
- </div>`};return s.html`<div class="code json" part="json">
3074
+ ${$>w.length?i.html`<div class="table-note">
3075
+ ${T.fill(this.msg.showingRows,{n:w.length,total:$})}
3076
+ </div>`:i.nothing}
3077
+ </div>`}renderJsonBlock(e,t,s){let a=0;const r=h=>{a++,a<=_t&&h&&typeof h=="object"&&Object.values(h).forEach(r)};if(r(e),a>_t)return this.renderCode("json",t,s);const n=(h,c,f)=>{const b=f===void 0?i.nothing:i.html`<span class="jkey">${f}</span>: `;if(h&&typeof h=="object"){const $=Object.entries(h),x=Array.isArray(h)?`[${$.length}]`:`{${$.length}}`;return i.html`<details class="jnode" ?open=${c<2}>
3078
+ <summary>${b}<span class="jmeta">${x}</span></summary>
3079
+ <div class="jkids">${$.map(([O,v])=>n(v,c+1,O))}</div>
3080
+ </details>`}const w=h===null?"null":typeof h;return i.html`<div class="jleaf">
3081
+ ${b}<span class="jv ${w}">${JSON.stringify(h)}</span>
3082
+ </div>`};return i.html`<div class="code json" part="json">
3078
3083
  <div class="code-head">
3079
3084
  <span class="label">json</span>
3080
- <button type="button" class="text-btn" @click=${()=>this.copy(i,t)}>
3081
- ${this.copiedKey===i?this.msg.copied:this.msg.copy}
3085
+ <button type="button" class="text-btn" @click=${()=>this.copy(s,t)}>
3086
+ ${this.copiedKey===s?this.msg.copied:this.msg.copy}
3082
3087
  </button>
3083
3088
  </div>
3084
3089
  <div class="jtree">${n(e,0)}</div>
3085
- </div>`}renderChart(e){const t=e.series.length>1?s.html`<span class="legend">
3086
- ${e.series.map((n,d)=>s.html`<span
3090
+ </div>`}renderChart(e){const t=e.series.length>1?i.html`<span class="legend">
3091
+ ${e.series.map((n,h)=>i.html`<span
3087
3092
  ><span
3088
3093
  class="swatch"
3089
- style="background:${_[d%_.length]}"
3094
+ style="background:${_[h%_.length]}"
3090
3095
  ></span
3091
3096
  >${n.name}</span
3092
3097
  >`)}
3093
- </span>`:s.nothing,i=s.html`<div class="chart-head">
3098
+ </span>`:i.nothing,s=i.html`<div class="chart-head">
3094
3099
  <span class="chart-title">${e.title}</span>${t}
3095
- </div>`;if(e.type==="line"){const n=Math.max(0,...e.series.flatMap(f=>f.values)),d=Math.pow(10,Math.floor(Math.log10(n||1))),c=Math.ceil(n/d*2)/2*d||1,b=Math.max(e.labels.length,...e.series.map(f=>f.values.length));return s.html`<figure class="chart" part="chart" aria-label=${e.title}>
3096
- ${i}
3100
+ </div>`;if(e.type==="line"){const n=Math.max(0,...e.series.flatMap(b=>b.values)),h=Math.pow(10,Math.floor(Math.log10(n||1))),c=Math.ceil(n/h*2)/2*h||1,f=Math.max(e.labels.length,...e.series.map(b=>b.values.length));return i.html`<figure class="chart" part="chart" aria-label=${e.title}>
3101
+ ${s}
3097
3102
  <div class="line-chart">
3098
3103
  <div class="plot">
3099
- ${[1,.5,0].map(f=>s.html`<div class="tick ${f===0?"base":""}" style="top:${(1-f)*100}%">
3100
- <span>${ht(Math.round(c*f),e.unit)}</span>
3104
+ ${[1,.5,0].map(b=>i.html`<div class="tick ${b===0?"base":""}" style="top:${(1-b)*100}%">
3105
+ <span>${ut(Math.round(c*b),e.unit)}</span>
3101
3106
  </div>`)}
3102
3107
  <svg
3103
3108
  viewBox="0 0 600 170"
@@ -3105,80 +3110,81 @@ ${b.map(v=>`[${v.n}] ${v.title}`).join(`
3105
3110
  role="img"
3106
3111
  aria-label=${e.title}
3107
3112
  >
3108
- ${e.series.map((f,k)=>s.svg`<polyline pathLength="1" stroke=${_[k%_.length]}
3109
- points=${f.values.map((C,v)=>`${(b>1?v/(b-1)*600:300).toFixed(1)},${(170-C/c*170).toFixed(1)}`).join(" ")}><title>${f.name}: ${f.values.map(C=>ht(C,e.unit)).join(", ")}</title></polyline>`)}
3113
+ ${e.series.map((b,w)=>i.svg`<polyline pathLength="1" stroke=${_[w%_.length]}
3114
+ points=${b.values.map(($,x)=>`${(f>1?x/(f-1)*600:300).toFixed(1)},${(170-$/c*170).toFixed(1)}`).join(" ")}><title>${b.name}: ${b.values.map($=>ut($,e.unit)).join(", ")}</title></polyline>`)}
3110
3115
  </svg>
3111
3116
  </div>
3112
- <div class="x-labels">${e.labels.map(f=>s.html`<span>${f}</span>`)}</div>
3117
+ <div class="x-labels">${e.labels.map(b=>i.html`<span>${b}</span>`)}</div>
3113
3118
  </div>
3114
- </figure>`}const a=e.labels.map((n,d)=>e.series.reduce((c,b)=>c+(b.values[d]||0),0)),r=Math.max(0,...a)||1;return s.html`<figure class="chart" part="chart" aria-label=${e.title}>
3115
- ${i}
3119
+ </figure>`}const a=e.labels.map((n,h)=>e.series.reduce((c,f)=>c+(f.values[h]||0),0)),r=Math.max(0,...a)||1;return i.html`<figure class="chart" part="chart" aria-label=${e.title}>
3120
+ ${s}
3116
3121
  <div class="bars">
3117
- ${e.labels.map((n,d)=>s.html`<div class="bar-row" title="${n}: ${ht(a[d],e.unit)}">
3122
+ ${e.labels.map((n,h)=>i.html`<div class="bar-row" title="${n}: ${ut(a[h],e.unit)}">
3118
3123
  <span class="bar-label">${n}</span>
3119
3124
  <span class="bar-track"
3120
- ><span class="bar-fill" style="width:${Math.max(0,a[d])/r*100}%">
3121
- ${e.series.map((c,b)=>s.html`<span
3122
- style="flex:${Math.max(0,c.values[d]||0)};background:${e.series.length>1?_[b%_.length]:"var(--c-ink)"}"
3125
+ ><span class="bar-fill" style="width:${Math.max(0,a[h])/r*100}%">
3126
+ ${e.series.map((c,f)=>i.html`<span
3127
+ style="flex:${Math.max(0,c.values[h]||0)};background:${e.series.length>1?_[f%_.length]:"var(--c-ink)"}"
3123
3128
  ></span>`)}
3124
3129
  </span></span
3125
3130
  >
3126
- <span class="bar-value">${ht(a[d],e.unit)}</span>
3131
+ <span class="bar-value">${ut(a[h],e.unit)}</span>
3127
3132
  </div>`)}
3128
3133
  </div>
3129
- </figure>`}renderPanel(){if(!this.panel)return s.nothing;const e=this.msgs.find(f=>f.key===this.panel.key),t=e==null?void 0:e.sources[this.panel.n-1];if(!e||!t)return s.nothing;const i=this.msg,a=L(t,this.panel.n),r=ut(e.content),n=e.sources.map((f,k)=>L(f,k+1)).filter(f=>f.n!==a.n&&(!r.size||r.has(f.n))),d=`ref:${e.key}:${a.n}`,c=`"${a.text}"
3130
- — ${a.title} [${a.n}]${a.path?`
3131
- ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated ${a.updated}`:"",a.score!==null?`Relevance ${a.score.toFixed(2)}`:""].filter(Boolean).join(" · ");return s.html`<aside
3134
+ </figure>`}renderPanel(){if(!this.panel)return i.nothing;const e=this.msgs.find(b=>b.key===this.panel.key);if(!e)return i.nothing;const t=e.sources.map((b,w)=>L(b,w+1)),s=t.find(b=>b.n===this.panel.n);if(!s)return i.nothing;const a=this.msg,r=bt(e.content),n=t.filter(b=>b.n!==s.n&&(!r.size||r.has(b.n))),h=`ref:${e.key}:${s.n}`,c=`"${s.text}"
3135
+ — ${s.title} [${s.n}]${s.path?`
3136
+ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated ${s.updated}`:"",s.score!==null?`Relevance ${s.score.toFixed(2)}`:""].filter(Boolean).join(" · ");return i.html`<aside
3132
3137
  class="panel ${this.panelDocked?"docked":"overlay"}"
3133
3138
  part="panel"
3134
3139
  role="region"
3135
- aria-label=${T.fill(i.sourceLabel,{n:a.n})}
3140
+ aria-label=${T.fill(a.sourceLabel,{n:s.n})}
3136
3141
  >
3137
3142
  <div class="panel-head">
3138
3143
  <span class="label"
3139
- >${T.fill(i.sourceLabel,{n:a.n})}${a.collection?` · ${a.collection}`:""}</span
3144
+ >${T.fill(a.sourceLabel,{n:s.n})}${s.collection?` · ${s.collection}`:""}</span
3140
3145
  >
3141
3146
  <button type="button" class="text-btn underline" @click=${()=>this.panel=null}>
3142
- ${i.close}
3147
+ ${a.close}
3143
3148
  </button>
3144
3149
  </div>
3145
3150
  <div class="panel-body">
3146
3151
  <div class="panel-meta">
3147
- <h3>${a.title}</h3>
3148
- ${a.path?s.html`<span class="path">${a.path}</span>`:s.nothing}
3149
- ${b?s.html`<span class="meta">${b}</span>`:s.nothing}
3152
+ <h3>${s.title}</h3>
3153
+ ${s.section?i.html`<span class="meta">${s.section}</span>`:i.nothing}
3154
+ ${s.path?i.html`<span class="path">${s.path}</span>`:i.nothing}
3155
+ ${f?i.html`<span class="meta">${f}</span>`:i.nothing}
3150
3156
  </div>
3151
3157
  <div class="passage-box">
3152
- <span class="text">${a.text}</span>
3158
+ <span class="text">${s.text}</span>
3153
3159
  <div class="passage-foot">
3154
- <span class="label">${i.citedPassage}</span>
3160
+ <span class="label">${a.citedPassage}</span>
3155
3161
  <button
3156
3162
  type="button"
3157
3163
  class="copy-ref"
3158
- title=${i.copyReference}
3159
- aria-label=${i.copyReference}
3160
- @click=${()=>this.copy(d,c)}
3164
+ title=${a.copyReference}
3165
+ aria-label=${a.copyReference}
3166
+ @click=${()=>this.copy(h,c)}
3161
3167
  >
3162
- ${y.copy()}<span>${this.copiedKey===d?i.copied:i.copy}</span>
3168
+ ${y.copy()}<span>${this.copiedKey===h?a.copied:a.copy}</span>
3163
3169
  </button>
3164
3170
  </div>
3165
3171
  </div>
3166
3172
  </div>
3167
- ${n.length?s.html`<div class="panel-foot">
3168
- <span class="label">${i.alsoCited}</span>
3173
+ ${n.length?i.html`<div class="panel-foot">
3174
+ <span class="label">${a.alsoCited}</span>
3169
3175
  <div class="chips">
3170
- ${n.map(f=>s.html`<button
3176
+ ${n.map(b=>i.html`<button
3171
3177
  type="button"
3172
3178
  class="chip"
3173
- @click=${()=>this.panel={key:e.key,n:f.n}}
3179
+ @click=${()=>this.panel={key:e.key,n:b.n}}
3174
3180
  >
3175
- ${f.n} · ${f.title}
3181
+ ${b.n} · ${b.title}
3176
3182
  </button>`)}
3177
3183
  </div>
3178
- </div>`:s.nothing}
3179
- </aside>`}renderComposer(){const e=this.msg,t=this.mode==="rag"?e.placeholderRag:T.fill(e.placeholderChat,{name:this.assistantName}),i=!this.draft.trim(),a=this.footnote===""?s.nothing:s.html`<span class="footnote" part="footnote"
3184
+ </div>`:i.nothing}
3185
+ </aside>`}renderComposer(){const e=this.msg,t=this.mode==="rag"?e.placeholderRag:this.mode==="kb"?e.placeholderKb:T.fill(e.placeholderChat,{name:this.assistantName}),s=!this.draft.trim(),a=this.footnote===""?i.nothing:i.html`<span class="footnote" part="footnote"
3180
3186
  >${this.footnote??T.fill(e.footnote,{name:this.assistantName})}</span
3181
- >`;return this.showComposer?s.html`<div class="composer-wrap">
3187
+ >`;return this.showComposer?i.html`<div class="composer-wrap">
3182
3188
  <div class="composer-col">
3183
3189
  <input
3184
3190
  type="file"
@@ -3188,11 +3194,28 @@ ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated
3188
3194
  @change=${r=>{const n=r.target;this.addFiles(n.files).then(()=>n.value="")}}
3189
3195
  />
3190
3196
  <div class="composer-box">
3191
- ${this.busy?s.html`<div class="composer-glow"></div>`:s.nothing}
3197
+ ${this.busy?i.html`<div class="composer-glow"></div>`:i.nothing}
3192
3198
  <div class="composer ${this.busy?"busy":""}" part="composer">
3193
- ${this.files.length?s.html`<div class="pending-files">
3194
- ${this.files.map(r=>s.html`<div class="pending-file">
3195
- <span class="ext">${Lt(r.name)}</span>
3199
+ ${this.savedFiles.length?i.html`<div class="pending-files" part="saved-files">
3200
+ ${this.savedFiles.map(r=>i.html`<div class="pending-file kept">
3201
+ <span class="ext">${mt(r.name)}</span>
3202
+ <span class="meta"
3203
+ ><span class="name">${r.name}</span
3204
+ ><span class="size">${e.inThisChat}</span></span
3205
+ >
3206
+ <button
3207
+ type="button"
3208
+ aria-label=${e.removeFromChat}
3209
+ title=${e.removeFromChat}
3210
+ @click=${()=>this.removeSavedFile(r)}
3211
+ >
3212
+ ×
3213
+ </button>
3214
+ </div>`)}
3215
+ </div>`:i.nothing}
3216
+ ${this.files.length?i.html`<div class="pending-files">
3217
+ ${this.files.map(r=>i.html`<div class="pending-file">
3218
+ <span class="ext">${mt(r.name)}</span>
3196
3219
  <span class="meta"
3197
3220
  ><span class="name">${r.name}</span
3198
3221
  ><span class="size">${T.formatSize(r.size)}</span></span
@@ -3206,7 +3229,7 @@ ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated
3206
3229
  ×
3207
3230
  </button>
3208
3231
  </div>`)}
3209
- </div>`:s.nothing}
3232
+ </div>`:i.nothing}
3210
3233
  <textarea
3211
3234
  class="input"
3212
3235
  rows="1"
@@ -3218,7 +3241,7 @@ ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated
3218
3241
  ></textarea>
3219
3242
  <div class="composer-row">
3220
3243
  <div>
3221
- ${this.allowUpload?s.html`<button
3244
+ ${this.allowUpload?i.html`<button
3222
3245
  type="button"
3223
3246
  class="attach"
3224
3247
  title=${e.attach}
@@ -3226,9 +3249,9 @@ ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated
3226
3249
  @click=${()=>{var r;return(r=this.renderRoot.querySelector("input[type=file]"))==null?void 0:r.click()}}
3227
3250
  >
3228
3251
  ${y.clip()}
3229
- </button>`:s.nothing}
3252
+ </button>`:i.nothing}
3230
3253
  </div>
3231
- ${this.busy?s.html`<button
3254
+ ${this.busy?i.html`<button
3232
3255
  type="button"
3233
3256
  class="send stop"
3234
3257
  title=${e.stop}
@@ -3236,23 +3259,23 @@ ${a.path}`:""}${a.updated?` · Updated ${a.updated}`:""}`,b=[a.updated?`Updated
3236
3259
  @click=${()=>this.stop()}
3237
3260
  >
3238
3261
  ${y.stop()}
3239
- </button>`:s.html`<button
3262
+ </button>`:i.html`<button
3240
3263
  type="button"
3241
3264
  class="send"
3242
3265
  title=${e.send}
3243
3266
  aria-label=${e.send}
3244
- ?disabled=${i}
3267
+ ?disabled=${s}
3245
3268
  @click=${()=>this.send()}
3246
3269
  >
3247
3270
  ${y.up()}
3248
3271
  </button>`}
3249
3272
  </div>
3250
3273
  </div>
3251
- ${this.busy?s.html`<div class="composer-ring"><div class="ring"></div></div>`:s.nothing}
3274
+ ${this.busy?i.html`<div class="composer-ring"><div class="ring"></div></div>`:i.nothing}
3252
3275
  </div>
3253
3276
  ${a}
3254
3277
  </div>
3255
- </div>`:s.html`<div class="composer-wrap reader">
3278
+ </div>`:i.html`<div class="composer-wrap reader">
3256
3279
  <div class="composer-col">${a}</div>
3257
- </div>`}},j=new WeakMap,N=new WeakMap,A=new WeakMap,R=new WeakMap,E=new WeakMap,B=new WeakMap,D=new WeakMap,F=new WeakMap,U=new WeakMap,P=new WeakMap,K=new WeakMap,W=new WeakMap,J=new WeakMap,H=new WeakMap,q=new WeakMap,G=new WeakMap,V=new WeakMap,X=new WeakMap,Y=new WeakMap,Q=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,ie=new WeakMap,se=new WeakMap,ae=new WeakMap,re=new WeakMap,ne=new WeakMap,oe=new WeakMap,le=new WeakMap,ce=new WeakMap,de=new WeakMap,he=new WeakMap,pe=new WeakMap,ue=new WeakMap,ge=new WeakMap,me=new WeakMap,be=new WeakMap,fe=new WeakMap,xe=new WeakMap,ve=new WeakMap,ye=new WeakMap,we=new WeakMap,ke=new WeakMap,$e=new WeakMap,Ce=new WeakMap,Se=new WeakMap,Te=new WeakMap,Oe=new WeakMap,Ie=new WeakMap,Me=new WeakMap,ze=new WeakMap,_e=new WeakMap,Le=new WeakMap,je=new WeakMap,Ne=new WeakMap,Ae=new WeakMap,Re=new WeakMap,Ee=new WeakMap,Be=new WeakMap,De=new WeakMap,Fe=new WeakMap,Ue=new WeakMap,Pe=new WeakMap,Ke=new WeakMap,We=new WeakMap,Je=new WeakMap,He=new WeakMap,qe=new WeakMap,Ge=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Ye=new WeakMap,Qe=new WeakMap,Ze=new WeakMap,et=new WeakMap,tt=new WeakMap,it=new WeakMap,st=new WeakMap,at=new WeakMap,rt=new WeakMap,nt=new WeakMap,ot=new WeakMap,lt=new WeakMap,ct=new WeakMap,dt=new WeakMap,jt);di(exports.SinglebaseChat,"styles",[T.tokenDefaults,T.brandingStyles,qt]);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"client",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"messages",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"theme",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"radius",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"mode",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"format",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"renderers",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"beforeSend",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"afterParse",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"glow",1);m([g.property({converter:S})],exports.SinglebaseChat.prototype,"followups",1);m([g.property({converter:S,attribute:"show-sources"})],exports.SinglebaseChat.prototype,"showSources",1);m([g.property({converter:S,attribute:"show-new-chat"})],exports.SinglebaseChat.prototype,"showNewChat",1);m([g.property({converter:S,attribute:"show-bookmarked"})],exports.SinglebaseChat.prototype,"showBookmarked",1);m([g.property({converter:S,attribute:"show-followups"})],exports.SinglebaseChat.prototype,"showFollowups",1);m([g.property({converter:S,attribute:"allow-search"})],exports.SinglebaseChat.prototype,"allowSearch",1);m([g.property({converter:S,attribute:"auto-title"})],exports.SinglebaseChat.prototype,"autoTitle",1);m([g.property()],exports.SinglebaseChat.prototype,"model",1);m([g.property({converter:mt})],exports.SinglebaseChat.prototype,"params",1);m([g.property({attribute:"system-message"})],exports.SinglebaseChat.prototype,"systemMessage",1);m([g.property({converter:mt})],exports.SinglebaseChat.prototype,"retrieval",1);m([g.property({converter:mt})],exports.SinglebaseChat.prototype,"metadata",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"embed",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"position",1);m([g.property({converter:hi})],exports.SinglebaseChat.prototype,"sidebar",1);m([g.property({converter:S,attribute:"show-title"})],exports.SinglebaseChat.prototype,"showTitle",1);m([g.property({attribute:"chat-id"})],exports.SinglebaseChat.prototype,"chatIdAttr",1);m([g.property({attribute:"assistant-name"})],exports.SinglebaseChat.prototype,"assistantName",1);m([g.property({attribute:"logo-url"})],exports.SinglebaseChat.prototype,"logoUrl",1);m([g.property()],exports.SinglebaseChat.prototype,"heading",1);m([g.property()],exports.SinglebaseChat.prototype,"description",1);m([g.property()],exports.SinglebaseChat.prototype,"eyebrow",1);m([g.property()],exports.SinglebaseChat.prototype,"prompts",1);m([g.property({attribute:"bubble-text"})],exports.SinglebaseChat.prototype,"bubbleText",1);m([g.property({type:Boolean,attribute:"greeting-bubble"})],exports.SinglebaseChat.prototype,"greetingBubble",1);m([g.property({type:Boolean,attribute:"unread-badge"})],exports.SinglebaseChat.prototype,"unreadBadge",1);m([g.property({converter:S,attribute:"allow-upload"})],exports.SinglebaseChat.prototype,"allowUpload",1);m([g.property({converter:S,attribute:"allow-export"})],exports.SinglebaseChat.prototype,"allowExport",1);m([g.property({converter:S,attribute:"allow-copy"})],exports.SinglebaseChat.prototype,"allowCopy",1);m([g.property({converter:S,attribute:"allow-regenerate"})],exports.SinglebaseChat.prototype,"allowRegenerate",1);m([g.property({converter:S,attribute:"allow-bookmark"})],exports.SinglebaseChat.prototype,"allowBookmark",1);m([g.property({converter:S,attribute:"allow-delete"})],exports.SinglebaseChat.prototype,"allowDelete",1);m([g.property({converter:S,attribute:"allow-rename"})],exports.SinglebaseChat.prototype,"allowRename",1);m([g.property({converter:S,attribute:"allow-feedback"})],exports.SinglebaseChat.prototype,"allowFeedback",1);m([g.property({converter:S,attribute:"show-composer"})],exports.SinglebaseChat.prototype,"showComposer",1);m([g.property({converter:S,attribute:"show-time"})],exports.SinglebaseChat.prototype,"showTime",1);m([g.property()],exports.SinglebaseChat.prototype,"footnote",1);m([g.property({type:Boolean,attribute:"allow-raw"})],exports.SinglebaseChat.prototype,"allowRaw",1);m([g.property({converter:S})],exports.SinglebaseChat.prototype,"branding",1);m([g.property({attribute:"branding-text"})],exports.SinglebaseChat.prototype,"brandingText",1);m([g.property({attribute:"branding-url"})],exports.SinglebaseChat.prototype,"brandingUrl",1);m([g.state()],exports.SinglebaseChat.prototype,"chatList",1);m([g.state()],exports.SinglebaseChat.prototype,"listState",1);m([g.state()],exports.SinglebaseChat.prototype,"activeId",1);m([g.state()],exports.SinglebaseChat.prototype,"chatTitle",1);m([g.state()],exports.SinglebaseChat.prototype,"bookmarked",1);m([g.state()],exports.SinglebaseChat.prototype,"msgs",1);m([g.state()],exports.SinglebaseChat.prototype,"loadingThread",1);m([g.state()],exports.SinglebaseChat.prototype,"threadError",1);m([g.state()],exports.SinglebaseChat.prototype,"busy",1);m([g.state()],exports.SinglebaseChat.prototype,"draft",1);m([g.state()],exports.SinglebaseChat.prototype,"files",1);m([g.state()],exports.SinglebaseChat.prototype,"search",1);m([g.state()],exports.SinglebaseChat.prototype,"sidebarOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"width",1);m([g.state()],exports.SinglebaseChat.prototype,"panel",1);m([g.state()],exports.SinglebaseChat.prototype,"menuOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"editingKey",1);m([g.state()],exports.SinglebaseChat.prototype,"editDraft",1);m([g.state()],exports.SinglebaseChat.prototype,"editingTitle",1);m([g.state()],exports.SinglebaseChat.prototype,"renamingId",1);m([g.state()],exports.SinglebaseChat.prototype,"toast",1);m([g.state()],exports.SinglebaseChat.prototype,"copiedKey",1);m([g.state()],exports.SinglebaseChat.prototype,"retrievalOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"rawKeys",1);m([g.state()],exports.SinglebaseChat.prototype,"hasSidebarContent",1);m([g.state()],exports.SinglebaseChat.prototype,"sorts",1);m([g.state()],exports.SinglebaseChat.prototype,"arrivedKey",1);m([g.state()],exports.SinglebaseChat.prototype,"dragging",1);m([g.state()],exports.SinglebaseChat.prototype,"showJump",1);m([g.state()],exports.SinglebaseChat.prototype,"offline",1);m([g.state()],exports.SinglebaseChat.prototype,"isOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"expanded",1);m([g.state()],exports.SinglebaseChat.prototype,"bubble",1);m([g.state()],exports.SinglebaseChat.prototype,"seen",1);m([g.state()],exports.SinglebaseChat.prototype,"mobile",1);exports.SinglebaseChat=m([g.customElement("singlebase-chat")],exports.SinglebaseChat);exports.adaptBlocks=Ft;exports.citedNumbers=ut;exports.defaultChatMessages=Nt;exports.describeSource=L;exports.parseInline=Bt;exports.parseMarkdown=Rt;exports.resolveChatMessages=At;exports.settleStreaming=Dt;exports.splitFollowups=gt;exports.svgDataUrl=Ut;
3258
- //# sourceMappingURL=chat-C-gsskho.cjs.map
3280
+ </div>`}},j=new WeakMap,A=new WeakMap,N=new WeakMap,R=new WeakMap,E=new WeakMap,B=new WeakMap,D=new WeakMap,F=new WeakMap,K=new WeakMap,P=new WeakMap,U=new WeakMap,W=new WeakMap,H=new WeakMap,J=new WeakMap,q=new WeakMap,G=new WeakMap,V=new WeakMap,X=new WeakMap,Y=new WeakMap,Q=new WeakMap,Z=new WeakMap,ee=new WeakMap,te=new WeakMap,se=new WeakMap,ie=new WeakMap,ae=new WeakMap,re=new WeakMap,ne=new WeakMap,oe=new WeakMap,le=new WeakMap,ce=new WeakMap,he=new WeakMap,de=new WeakMap,pe=new WeakMap,ue=new WeakMap,ge=new WeakMap,me=new WeakMap,be=new WeakMap,fe=new WeakMap,ve=new WeakMap,xe=new WeakMap,ye=new WeakMap,we=new WeakMap,ke=new WeakMap,$e=new WeakMap,Ce=new WeakMap,Se=new WeakMap,Te=new WeakMap,Ie=new WeakMap,Me=new WeakMap,Oe=new WeakMap,ze=new WeakMap,_e=new WeakMap,Le=new WeakMap,je=new WeakMap,Ae=new WeakMap,Ne=new WeakMap,Re=new WeakMap,Ee=new WeakMap,Be=new WeakMap,De=new WeakMap,Fe=new WeakMap,Ke=new WeakMap,Pe=new WeakMap,Ue=new WeakMap,We=new WeakMap,He=new WeakMap,Je=new WeakMap,qe=new WeakMap,Ge=new WeakMap,Ve=new WeakMap,Xe=new WeakMap,Ye=new WeakMap,Qe=new WeakMap,Ze=new WeakMap,et=new WeakMap,tt=new WeakMap,st=new WeakMap,it=new WeakMap,at=new WeakMap,rt=new WeakMap,nt=new WeakMap,ot=new WeakMap,lt=new WeakMap,ct=new WeakMap,ht=new WeakMap,dt=new WeakMap,pt=new WeakMap,Rt);us(exports.SinglebaseChat,"styles",[T.tokenDefaults,T.brandingStyles,Xt]);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"client",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"messages",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"theme",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"radius",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"mode",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"format",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"renderers",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"beforeSend",1);m([g.property({attribute:!1})],exports.SinglebaseChat.prototype,"afterParse",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"glow",1);m([g.property()],exports.SinglebaseChat.prototype,"docsets",1);m([g.property({attribute:"attachments-mode"})],exports.SinglebaseChat.prototype,"attachmentsMode",1);m([g.property({converter:S,attribute:"save-attachments"})],exports.SinglebaseChat.prototype,"saveAttachments",1);m([g.property({converter:S})],exports.SinglebaseChat.prototype,"followups",1);m([g.property({converter:S,attribute:"show-sources"})],exports.SinglebaseChat.prototype,"showSources",1);m([g.property({converter:S,attribute:"show-new-chat"})],exports.SinglebaseChat.prototype,"showNewChat",1);m([g.property({converter:S,attribute:"show-bookmarked"})],exports.SinglebaseChat.prototype,"showBookmarked",1);m([g.property({converter:S,attribute:"show-followups"})],exports.SinglebaseChat.prototype,"showFollowups",1);m([g.property({converter:S,attribute:"allow-search"})],exports.SinglebaseChat.prototype,"allowSearch",1);m([g.property({converter:S,attribute:"auto-title"})],exports.SinglebaseChat.prototype,"autoTitle",1);m([g.property()],exports.SinglebaseChat.prototype,"model",1);m([g.property({converter:vt})],exports.SinglebaseChat.prototype,"params",1);m([g.property({attribute:"system-message"})],exports.SinglebaseChat.prototype,"systemMessage",1);m([g.property({converter:vt})],exports.SinglebaseChat.prototype,"retrieval",1);m([g.property({converter:vt})],exports.SinglebaseChat.prototype,"metadata",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"embed",1);m([g.property({reflect:!0})],exports.SinglebaseChat.prototype,"position",1);m([g.property({converter:gs})],exports.SinglebaseChat.prototype,"sidebar",1);m([g.property({converter:S,attribute:"show-title"})],exports.SinglebaseChat.prototype,"showTitle",1);m([g.property({attribute:"chat-id"})],exports.SinglebaseChat.prototype,"chatIdAttr",1);m([g.property({attribute:"assistant-name"})],exports.SinglebaseChat.prototype,"assistantName",1);m([g.property({attribute:"logo-url"})],exports.SinglebaseChat.prototype,"logoUrl",1);m([g.property()],exports.SinglebaseChat.prototype,"heading",1);m([g.property()],exports.SinglebaseChat.prototype,"description",1);m([g.property()],exports.SinglebaseChat.prototype,"eyebrow",1);m([g.property()],exports.SinglebaseChat.prototype,"prompts",1);m([g.property({attribute:"bubble-text"})],exports.SinglebaseChat.prototype,"bubbleText",1);m([g.property({type:Boolean,attribute:"greeting-bubble"})],exports.SinglebaseChat.prototype,"greetingBubble",1);m([g.property({type:Boolean,attribute:"unread-badge"})],exports.SinglebaseChat.prototype,"unreadBadge",1);m([g.property({converter:S,attribute:"allow-upload"})],exports.SinglebaseChat.prototype,"allowUpload",1);m([g.property({converter:S,attribute:"allow-export"})],exports.SinglebaseChat.prototype,"allowExport",1);m([g.property({converter:S,attribute:"allow-copy"})],exports.SinglebaseChat.prototype,"allowCopy",1);m([g.property({converter:S,attribute:"allow-regenerate"})],exports.SinglebaseChat.prototype,"allowRegenerate",1);m([g.property({converter:S,attribute:"allow-bookmark"})],exports.SinglebaseChat.prototype,"allowBookmark",1);m([g.property({converter:S,attribute:"allow-delete"})],exports.SinglebaseChat.prototype,"allowDelete",1);m([g.property({converter:S,attribute:"allow-rename"})],exports.SinglebaseChat.prototype,"allowRename",1);m([g.property({converter:S,attribute:"allow-feedback"})],exports.SinglebaseChat.prototype,"allowFeedback",1);m([g.property({converter:S,attribute:"show-composer"})],exports.SinglebaseChat.prototype,"showComposer",1);m([g.property({converter:S,attribute:"show-time"})],exports.SinglebaseChat.prototype,"showTime",1);m([g.property()],exports.SinglebaseChat.prototype,"footnote",1);m([g.property({type:Boolean,attribute:"allow-raw"})],exports.SinglebaseChat.prototype,"allowRaw",1);m([g.property({converter:S})],exports.SinglebaseChat.prototype,"branding",1);m([g.state()],exports.SinglebaseChat.prototype,"chatList",1);m([g.state()],exports.SinglebaseChat.prototype,"listState",1);m([g.state()],exports.SinglebaseChat.prototype,"activeId",1);m([g.state()],exports.SinglebaseChat.prototype,"chatTitle",1);m([g.state()],exports.SinglebaseChat.prototype,"bookmarked",1);m([g.state()],exports.SinglebaseChat.prototype,"msgs",1);m([g.state()],exports.SinglebaseChat.prototype,"loadingThread",1);m([g.state()],exports.SinglebaseChat.prototype,"threadError",1);m([g.state()],exports.SinglebaseChat.prototype,"busy",1);m([g.state()],exports.SinglebaseChat.prototype,"draft",1);m([g.state()],exports.SinglebaseChat.prototype,"files",1);m([g.state()],exports.SinglebaseChat.prototype,"search",1);m([g.state()],exports.SinglebaseChat.prototype,"sidebarOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"width",1);m([g.state()],exports.SinglebaseChat.prototype,"panel",1);m([g.state()],exports.SinglebaseChat.prototype,"menuOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"editingKey",1);m([g.state()],exports.SinglebaseChat.prototype,"editDraft",1);m([g.state()],exports.SinglebaseChat.prototype,"editingTitle",1);m([g.state()],exports.SinglebaseChat.prototype,"renamingId",1);m([g.state()],exports.SinglebaseChat.prototype,"toast",1);m([g.state()],exports.SinglebaseChat.prototype,"copiedKey",1);m([g.state()],exports.SinglebaseChat.prototype,"retrievalOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"rawKeys",1);m([g.state()],exports.SinglebaseChat.prototype,"savedFiles",1);m([g.state()],exports.SinglebaseChat.prototype,"hasSidebarContent",1);m([g.state()],exports.SinglebaseChat.prototype,"sorts",1);m([g.state()],exports.SinglebaseChat.prototype,"arrivedKey",1);m([g.state()],exports.SinglebaseChat.prototype,"dragging",1);m([g.state()],exports.SinglebaseChat.prototype,"showJump",1);m([g.state()],exports.SinglebaseChat.prototype,"offline",1);m([g.state()],exports.SinglebaseChat.prototype,"isOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"expanded",1);m([g.state()],exports.SinglebaseChat.prototype,"bubble",1);m([g.state()],exports.SinglebaseChat.prototype,"seen",1);m([g.state()],exports.SinglebaseChat.prototype,"mobile",1);exports.SinglebaseChat=m([g.customElement("singlebase-chat")],exports.SinglebaseChat);exports.adaptBlocks=Ut;exports.citedNumbers=bt;exports.defaultChatMessages=Et;exports.describeSource=L;exports.parseInline=Kt;exports.parseMarkdown=Dt;exports.resolveChatMessages=Bt;exports.settleStreaming=Pt;exports.splitFollowups=ft;exports.svgDataUrl=Wt;
3281
+ //# sourceMappingURL=chat-BWcGH9lr.cjs.map