@singlebase/elements 0.8.0 → 0.9.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.
- package/dist/{chat-BWcGH9lr.cjs → chat-Bj6DrOaW.cjs} +237 -168
- package/dist/chat-Bj6DrOaW.cjs.map +1 -0
- package/dist/{chat-t4o5FsxM.js → chat-DNiqYF6F.js} +1095 -822
- package/dist/chat-DNiqYF6F.js.map +1 -0
- package/dist/chat-messages.d.ts +5 -0
- package/dist/chat.cjs +1 -1
- package/dist/chat.js +1 -1
- package/dist/elements/chat.d.ts +73 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/singlebase-elements.min.js +2409 -2136
- package/dist/singlebase-elements.min.js.map +1 -1
- package/package.json +3 -3
- package/dist/chat-BWcGH9lr.cjs.map +0 -1
- package/dist/chat-t4o5FsxM.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var is=Object.defineProperty;var Mt=l=>{throw TypeError(l)};var as=(l,n,e)=>n in l?is(l,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[n]=e;var S=(l,n,e)=>as(l,typeof n!="symbol"?n+"":n,e),_t=(l,n,e)=>n.has(l)||Mt("Cannot "+e);var d=(l,n,e)=>(_t(l,n,"read from private field"),e?e.call(l):n.get(l)),p=(l,n,e)=>n.has(l)?Mt("Cannot add the same private member more than once"):n instanceof WeakSet?n.add(l):n.set(l,e),u=(l,n,e,t)=>(_t(l,n,"write to private field"),t?t.call(l,e):n.set(l,e),e);const i=require("lit"),g=require("lit/decorators.js"),rs=require("lit/directives/repeat.js"),ns=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 os=i.css`
|
|
2
2
|
:host {
|
|
3
3
|
--c-ink: var(--sb-ink, #16181a);
|
|
4
4
|
--c-ink2: var(--sb-ink-2, #41464b);
|
|
@@ -723,6 +723,20 @@
|
|
|
723
723
|
box-shadow: 0 6px 18px -10px rgba(22, 24, 26, 0.25);
|
|
724
724
|
}
|
|
725
725
|
|
|
726
|
+
/* A starter question that hasn't arrived yet. */
|
|
727
|
+
.prompt.skeleton {
|
|
728
|
+
min-height: 62px;
|
|
729
|
+
cursor: default;
|
|
730
|
+
background: var(--c-soft, rgba(22, 24, 26, 0.04));
|
|
731
|
+
border-style: dashed;
|
|
732
|
+
animation: aiBreathe 1.6s ease-in-out infinite;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.prompt.skeleton:hover {
|
|
736
|
+
border-color: var(--c-line);
|
|
737
|
+
box-shadow: none;
|
|
738
|
+
}
|
|
739
|
+
|
|
726
740
|
.prompt .label {
|
|
727
741
|
font-size: 10.5px;
|
|
728
742
|
letter-spacing: 0.06em;
|
|
@@ -1705,6 +1719,12 @@
|
|
|
1705
1719
|
background: var(--c-bg);
|
|
1706
1720
|
}
|
|
1707
1721
|
|
|
1722
|
+
.source-card .nums {
|
|
1723
|
+
display: inline-flex;
|
|
1724
|
+
flex-wrap: wrap;
|
|
1725
|
+
gap: 3px;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1708
1728
|
.source-card .t {
|
|
1709
1729
|
font-size: 13px;
|
|
1710
1730
|
font-weight: 500;
|
|
@@ -1803,6 +1823,19 @@
|
|
|
1803
1823
|
border: 1px solid var(--c-strong);
|
|
1804
1824
|
}
|
|
1805
1825
|
|
|
1826
|
+
/* The passage the reader clicked, among several from one document. */
|
|
1827
|
+
.passage-box.current {
|
|
1828
|
+
border-color: var(--c-ink);
|
|
1829
|
+
box-shadow: 0 0 0 1px var(--c-ink);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
.passage-head {
|
|
1833
|
+
display: flex;
|
|
1834
|
+
align-items: center;
|
|
1835
|
+
gap: 8px;
|
|
1836
|
+
min-width: 0;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1806
1839
|
.passage-box .text {
|
|
1807
1840
|
font-size: 13px;
|
|
1808
1841
|
line-height: 1.6;
|
|
@@ -2434,19 +2467,19 @@
|
|
|
2434
2467
|
height: auto;
|
|
2435
2468
|
}
|
|
2436
2469
|
}
|
|
2437
|
-
`,
|
|
2438
|
-
`),r=(a>-1?t.slice(0,a):t).trim(),
|
|
2439
|
-
`).filter(s=>s.trim()),e=
|
|
2440
|
-
`).trim()}]:[{type:"quote",text:s.join(" ")}]}if(
|
|
2441
|
-
`);return[{type:"h",level:t[1].length,text:t[2]},...s?
|
|
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
|
|
2470
|
+
`,Jt={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",viewOptions:"View options",viewHeading:"Show in answers",viewFollowups:"Suggested questions",viewSources:"Sources",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",passageCount:"{n} passages",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 qt(l){return{...Jt,...l??{}}}const ls=/^\|.*\|$/,zt=/^\|[\s:|-]+\|$/,Lt=/^!\[([^\]]*)\]\(([^)]*)\)$/,jt=/^(\s*)([-*+]|\d+[.)])\s+(.*)$/,At=/^\[( |x|X)\]\s+/,cs=/^(-{3,}|\*{3,}|_{3,})$/,hs=/^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*(.*)$/i,ds=["note","tip","important","warning","caution"];function Gt(l){const n=[],e=(l??"").replace(/\r/g,"").split("```");return e.forEach((t,s)=>{if(s%2===1){const a=t.indexOf(`
|
|
2471
|
+
`),r=(a>-1?t.slice(0,a):t).trim(),o=(a>-1?t.slice(a+1):"").replace(/\n$/,"");n.push(ps(r,o,s===e.length-1));return}for(const a of t.split(/\n{2,}/))a.trim()&&n.push(...Xt(a))}),n}function ps(l,n,e){const[t="",...s]=l.split(/\s+/),a=t.toLowerCase();if(a==="chart"){const r=e?null:gs(n);return r?{type:"chart",spec:r}:{type:"pending",kind:"chart"}}if(a==="svg")return e||!/<svg[\s>]/i.test(n)?{type:"pending",kind:"svg"}:{type:"svg",source:n.trim()};if(!e&&(a==="csv"||a==="tsv")){const r=us(n,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(n),source:n}}catch{}if(a==="callout"){const r=(s[0]??"").toLowerCase(),o=ds.includes(r);return{type:"callout",kind:o?r:"note",title:(o?s.slice(1):s).join(" "),text:n.trim()}}return{type:"code",lang:a||"code",text:n}}function Xt(l){const n=l.split(`
|
|
2472
|
+
`).filter(s=>s.trim()),e=n.map(s=>s.trim());if(e.length>1&&e.every(s=>ls.test(s))){const s=c=>c.replace(/^\||\|$/g,"").split("|").map(f=>f.trim()),a=e.findIndex(c=>zt.test(c)),r=a>-1?s(e[a]).map(c=>/^:-+:$/.test(c)?"center":/^-+:$/.test(c)?"right":/^:-+$/.test(c)?"left":null):[],o=e.filter(c=>!zt.test(c)).map(s),h=o[0]??[];return[{type:"table",head:h,rows:o.slice(1),align:h.map((c,f)=>r[f]??null)}]}if(e.length===1&&cs.test(e[0]))return[{type:"hr"}];if(e.every(s=>Lt.test(s)))return[{type:"img",images:e.map(s=>{const a=s.match(Lt);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(hs);return a?[{type:"callout",kind:a[1].toLowerCase(),title:a[2].trim(),text:s.slice(1).join(`
|
|
2473
|
+
`).trim()}]:[{type:"quote",text:s.join(" ")}]}if(jt.test(n[0])){const s=[];for(const a of n){const r=a.match(jt);if(r){const o=r[3].match(At);s.push({text:o?r[3].replace(At,""):r[3],depth:Math.min(3,Math.floor(r[1].replace(/\t/g," ").length/2)),checked:o?o[1]!==" ":null})}else s[s.length-1].text+=` ${a.trim()}`}return[{type:"list",ordered:/^\s*\d/.test(n[0]),items:s}]}const t=e[0].match(/^(#{1,4})\s+(.*)$/);if(t){const s=n.slice(1).join(`
|
|
2474
|
+
`);return[{type:"h",level:t[1].length,text:t[2]},...s?Xt(s):[]]}return[{type:"p",text:e.join(" ")}]}function us(l,n=","){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===n?(t.push(s.trim()),s=""):f===`
|
|
2475
|
+
`?(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 o=((h=e[0])==null?void 0:h.length)??0;return e.map(c=>c.length<o?[...c,...Array(o-c.length).fill("")]:c)}function gs(l){let n;try{n=JSON.parse(l)}catch{return null}if(!n||typeof n!="object")return null;const e=(Array.isArray(n.series)?n.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(n.labels)?n.labels.map(String):e[0].values.map((s,a)=>String(a+1));return{type:n.type==="line"?"line":"bar",title:String(n.title??""),unit:String(n.unit??""),labels:t,series:e}}const Rt=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 Yt(l,n=0){const e=[];let t=0,s;Rt.lastIndex=0;const a=r=>{if(!r)return;const o=e[e.length-1];(o==null?void 0:o.type)==="text"?o.text+=r:e.push({type:"text",text:r})};for(;s=Rt.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 o=s[9].split(",").map(h=>Number(h.trim())).filter(h=>h>=1&&h<=n);n?o.forEach(h=>e.push({type:"cite",n:h})):a(s[0])}t=s.index+s[0].length}return a(l.slice(t)),e}function Qt(l){if(((l??"").match(/```/g)??[]).length%2===1)return l;const n=l.lastIndexOf(`
|
|
2443
2476
|
|
|
2444
|
-
`),e=
|
|
2477
|
+
`),e=n>-1?l.slice(0,n+2):"";let t=n>-1?l.slice(n+2):l;const s=t.split(`
|
|
2445
2478
|
`),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
|
|
2447
|
-
`),
|
|
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||
|
|
2449
|
-
`)[0].trim().replace(/^["'“”‘’]+|["'“”‘’]+$/g,"").replace(/^title:\s*/i,"").replace(/[.!?:;,]+$/,"").trim().slice(0,80)}function
|
|
2479
|
+
`),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 Tt(l){const n=new Set;for(const e of(l??"").match(/\[(\d+(?:\s*,\s*\d+)*)\]/g)??[])e.replace(/[[\]]/g,"").split(",").forEach(t=>n.add(Number(t.trim())));return n}function ms(l){return[["",...l.series.map(n=>n.name)],...l.labels.map((n,e)=>[n,...l.series.map(t=>t.values[e]===void 0?"":`${t.values[e]}${l.unit}`)])]}const Nt=l=>l.map(n=>n.join(" · ")).join(`
|
|
2480
|
+
`),bs={note:"Note",tip:"Tip",important:"Important",warning:"Warning",caution:"Caution"};function Zt(l,n){if(n==="rich")return l;const e=n==="plain";return l.map(t=>{switch(t.type){case"chart":{const[s,...a]=ms(t.spec);return e?{type:"raw",text:[t.spec.title,Nt([s,...a])].filter(Boolean).join(`
|
|
2481
|
+
`)}:{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||bs[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:Nt([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 Ot(l){const n=l??"",e=n.search(/FOLLOWUPS:/i);if(e<0)return{text:n.trim(),followups:[]};const s=n.slice(e).replace(/^FOLLOWUPS:/i,"").split(/\||\n/).map(a=>a.replace(/^\s*(?:[-*↳→]|\d+[.)])\s*/,"").trim()).filter(Boolean).slice(0,3);return{text:n.slice(0,e).trim(),followups:s}}function fs(l){return(l??"").replace(/```(\w*)[\s\S]*?(```|$)/g,(n,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 Et(l,n=48){const e=fs(l);if(e.length<=n)return e;const t=e.slice(0,n),s=t.lastIndexOf(" ");return(s>n/2?t.slice(0,s):t).trim()}function vs(l){return String(l??"").split(`
|
|
2482
|
+
`)[0].trim().replace(/^["'“”‘’]+|["'“”‘’]+$/g,"").replace(/^title:\s*/i,"").replace(/[.!?:;,]+$/,"").trim().slice(0,80)}function Bt(l,n=!1){return/^https?:\/\//i.test(l)?!0:n&&/^(blob:|data:image\/)/i.test(l)}const xs=2e5,ws=new Set(["script","foreignobject","iframe","object","embed","image","audio","video","animate","set","animatemotion","animatetransform","handler","listener"]);function es(l){if(!l||l.length>xs||typeof DOMParser>"u")return null;const n=new DOMParser().parseFromString(l,"image/svg+xml"),e=n.documentElement;if(!e||e.nodeName.toLowerCase()!=="svg"||n.querySelector("parsererror"))return null;const t=a=>{for(const r of Array.from(a.children)){const o=r.nodeName.toLowerCase();if(ws.has(o))r.remove();else if(o==="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 o=r.name.toLowerCase(),h=r.value.trim().toLowerCase(),c=(o==="href"||o.endsWith(":href"))&&!h.startsWith("#"),f=h.includes("javascript:")||/url\(\s*['"]?(?!#)/.test(h);(o.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 ts=Object.defineProperty,ys=Object.getOwnPropertyDescriptor,ks=(l,n,e)=>n in l?ts(l,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[n]=e,m=(l,n,e,t)=>{for(var s=t>1?void 0:t?ys(n,e):n,a=l.length-1,r;a>=0;a--)(r=l[a])&&(s=(t?r(n,e,s):r(s))||s);return t&&s&&ts(n,e,s),s},$s=(l,n,e)=>ks(l,n+"",e);const Ft=["embed","mode","format","renderers","beforeSend","afterParse","glow","position","sidebar","showTitle","assistantName","logoUrl","heading","description","eyebrow","prompts","chatKey","bubbleText","greetingBubble","unreadBadge","allowUpload","allowExport","allowRaw","allowCopy","allowRegenerate","allowBookmark","allowDelete","allowRename","allowFeedback","showTime","showComposer","footnote","branding","followups","docsets","attachmentsMode","saveAttachments","showFollowups","showSources","allowViewOptions","showNewChat","showBookmarked","allowSearch","autoTitle","model","params","systemMessage","retrieval","metadata","messages","theme","radius"],It={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)},O={fromAttribute:l=>l===null?!0:l!=="false",toAttribute:l=>l?null:"false"},Cs={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},Ss=272,Ts=820,Os=940,Dt=5,Kt=512*1024,Is=/\.(md|markdown|txt|csv|tsv|json|html?|ya?ml|xml|log)$/i,Ms=5e3,_s=200,Pt=2e3,zs={note:"calloutNote",tip:"calloutTip",important:"calloutImportant",warning:"calloutWarning",caution:"calloutCaution"},Ls=2600,z=["var(--c-ink)","oklch(0.58 0.13 255)","oklch(0.63 0.1 175)","oklch(0.74 0.12 70)"],Ut={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."},js={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 .'},As="After the answer, on a final line write FOLLOWUPS: followed by three short follow-up questions the user might ask next, separated by |.",Ht={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,n="")=>i.html`<svg class="i ${n}" 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
|
|
2450
2483
|
class="i"
|
|
2451
2484
|
viewBox="0 0 16 16"
|
|
2452
2485
|
aria-hidden="true"
|
|
@@ -2455,7 +2488,7 @@
|
|
|
2455
2488
|
<path
|
|
2456
2489
|
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"
|
|
2457
2490
|
></path>
|
|
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
|
|
2491
|
+
</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>`),view:()=>M(i.svg`<path d="M2.5 4.5h7M12.5 4.5h1M2.5 11.5h1M6.5 11.5h7"></path><circle cx="11" cy="4.5" r="1.5"></circle><circle cx="5" cy="11.5" r="1.5"></circle>`),check:()=>M(i.svg`<path d="M3.5 8.5l3 3 6-7"></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
|
|
2459
2492
|
width="22"
|
|
2460
2493
|
height="22"
|
|
2461
2494
|
viewBox="0 0 22 22"
|
|
@@ -2473,19 +2506,19 @@
|
|
|
2473
2506
|
style="fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round"
|
|
2474
2507
|
>
|
|
2475
2508
|
<path d="M5 8l5 5 5-5"></path>
|
|
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}
|
|
2509
|
+
</svg>`};let Rs=0;const kt=()=>`m${Date.now().toString(36)}${(Rs++).toString(36)}`,ss="singlebase-chat:view";function Ns(){var l;try{const n=JSON.parse(((l=globalThis.localStorage)==null?void 0:l.getItem(ss))??"{}");return{followups:(n==null?void 0:n.followups)===!0,sources:(n==null?void 0:n.sources)===!0}}catch{return{}}}function Es(l){var n;try{(n=globalThis.localStorage)==null||n.setItem(ss,JSON.stringify(l))}catch{}}function $t(l){var e;const n=l;return(n==null?void 0:n.message)==="NOT_FOUND"||(n==null?void 0:n.code)==="NOT_FOUND"||((e=n==null?void 0:n.details)==null?void 0:e.status)===404}function Bs(l){const n=l;return(n==null?void 0:n.code)||(n==null?void 0:n.message)||"UNKNOWN"}const Fs=()=>typeof matchMedia<"u"&&matchMedia("(prefers-reduced-motion: reduce)").matches,xt=(l,n)=>(Number.isInteger(l)?l.toLocaleString("en-US"):l.toFixed(1))+n,Ct=l=>{const n=l.lastIndexOf(".");return n>0?l.slice(n+1,n+5).toUpperCase():"FILE"};function L(l,n){const e=l??{},t=e.metadata&&typeof e.metadata=="object"?e.metadata:{},s=(...$)=>$.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($=>typeof $=="number"),o=typeof e.n=="number"&&e.n>0?e.n:n,h=s(e.title,e.name,e.filename,t.title,t.name)??`Source ${o}`,c=s(e.path,e.url,e.key,t.path,t.url)??"",f=s(e.collection,e.namespace,e.dbname,t.collection)??"",v=s(e.document_id,e.id,e._id,e.attachment_id,e.file_id,t.document_id)??(c||h);return{n:o,doc:`${typeof e.type=="string"?e.type:""}|${f}|${v}`,title:h,section:s(e.section,e.heading,t.section)??"",path:c,collection:f,updated:s(e.updated,e._modified_at,t.updated)??"",text:a,score:r===void 0?null:Math.max(0,Math.min(1,r))}}function St(l){const n=new Map;for(const e of l){const t=n.get(e.doc);t?t.items.push(e):n.set(e.doc,{doc:e.doc,first:e,items:[e]})}return[...n.values()]}function Wt(l){return Array.isArray(l)?l.filter(n=>n&&typeof n=="object"&&(n._id||n.id)).filter(n=>n.saved!==!1&&n.status!=="failed").map(n=>({id:String(n._id??n.id),name:String(n.name??"file"),type:n.type,mime:n.mime,size:typeof n.size=="number"?n.size:void 0,status:n.status})):[]}function Ds(l){const n=[],e=[];for(const t of l)if(/\.csv$/i.test(t.name))n.push({source:"csv",data:t.content});else if(/\.json$/i.test(t.name))try{n.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&&n.push({source:"docs",payload:{documents:e}}),n}function Ks(l){const n=l?Date.parse(l):NaN;if(Number.isNaN(n))return"older";const e=new Date;e.setHours(0,0,0,0);const t=864e5;return n>=e.getTime()?"today":n>=e.getTime()-t?"yesterday":n>=e.getTime()-7*t?"week":"older"}var j,A,R,N,E,B,F,D,K,P,U,H,W,V,J,q,G,X,Y,Q,Z,ee,te,se,ie,ae,re,ne,oe,le,ce,he,de,pe,ue,ge,me,be,fe,ve,xe,we,ye,ke,$e,Ce,Se,Te,Oe,Ie,Me,_e,ze,Le,je,Ae,Re,Ne,Ee,Be,Fe,De,Ke,Pe,Ue,He,We,Ve,Je,qe,Ge,Xe,Ye,Qe,Ze,et,tt,st,it,at,rt,nt,ot,lt,ct,ht,dt,pt,ut,gt,mt,bt,ft,vt,Vt;exports.SinglebaseChat=(Vt=class extends i.LitElement{constructor(){super(...arguments);p(this,j,null);p(this,A,{});p(this,R);p(this,N);p(this,E,"chat");p(this,B,"advanced");p(this,F,{});p(this,D,null);p(this,K,null);p(this,P,"subtle");p(this,U,"");p(this,H,"payload");p(this,W,!0);p(this,V,!0);p(this,J,!0);p(this,q,!0);p(this,G,!0);p(this,X,!0);p(this,Y,!1);p(this,Q,!0);p(this,Z,!0);p(this,ee,"");p(this,te,{});p(this,se,"");p(this,ie,[]);p(this,ae,{});p(this,re,"page");p(this,ne,"right");p(this,oe,"auto");p(this,le,!0);p(this,ce,"");p(this,he,"");p(this,de,"Assistant");p(this,pe,"");p(this,ue,"");p(this,ge,"");p(this,me);p(this,be,"");p(this,fe,"");p(this,ve,!1);p(this,xe,!1);p(this,we,!0);p(this,ye,!0);p(this,ke,!0);p(this,$e,!0);p(this,Ce,!0);p(this,Se,!0);p(this,Te,!0);p(this,Oe,!0);p(this,Ie,!0);p(this,Me,!0);p(this,_e);p(this,ze,!1);p(this,Le,!0);p(this,je,[]);p(this,Ae,"idle");p(this,Re,null);p(this,Ne,"");p(this,Ee,!1);p(this,Be,[]);p(this,Fe,!1);p(this,De,"");p(this,Ke,!1);p(this,Pe,"");p(this,Ue,[]);p(this,He,"");p(this,We,null);p(this,Ve,0);p(this,Je,null);p(this,qe,!1);p(this,Ge,!1);p(this,Xe,Ns());p(this,Ye,"");p(this,Qe,"");p(this,Ze,!1);p(this,et,"");p(this,tt,null);p(this,st,"");p(this,it,new Set);p(this,at,new Set);p(this,rt,[]);p(this,nt,!1);p(this,ot,new Map);p(this,lt,"");p(this,ct,!1);p(this,ht,!1);p(this,dt,!1);p(this,pt,!1);p(this,ut,!1);p(this,gt,!1);p(this,mt,!1);p(this,bt,!1);S(this,"run",0);S(this,"abort",null);S(this,"revealTimer");S(this,"timers",new Set);S(this,"toastTimer");S(this,"stick",!0);S(this,"renamed",new Set);S(this,"observer",null);S(this,"observed",null);S(this,"resizeTimer");S(this,"shownPassage","");S(this,"media",null);S(this,"focusNext","");S(this,"bubbleScheduled",!1);S(this,"pendingChatId","");p(this,ft,[]);p(this,vt,!1);S(this,"boundKey","");S(this,"prepared",!1);S(this,"syncedKey","");S(this,"syncSignature","");S(this,"syncRun",0);S(this,"onNetwork",()=>{this.offline=navigator.onLine===!1});S(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,R)}set theme(e){u(this,R,e)}get radius(){return d(this,N)}set radius(e){u(this,N,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,F)}set renderers(e){u(this,F,e)}get beforeSend(){return d(this,D)}set beforeSend(e){u(this,D,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,H)}set attachmentsMode(e){u(this,H,e)}get saveAttachments(){return d(this,W)}set saveAttachments(e){u(this,W,e)}get followups(){return d(this,V)}set followups(e){u(this,V,e)}get showSources(){return d(this,J)}set showSources(e){u(this,J,e)}get showNewChat(){return d(this,q)}set showNewChat(e){u(this,q,e)}get showBookmarked(){return d(this,G)}set showBookmarked(e){u(this,G,e)}get showFollowups(){return d(this,X)}set showFollowups(e){u(this,X,e)}get allowViewOptions(){return d(this,Y)}set allowViewOptions(e){u(this,Y,e)}get allowSearch(){return d(this,Q)}set allowSearch(e){u(this,Q,e)}get autoTitle(){return d(this,Z)}set autoTitle(e){u(this,Z,e)}get model(){return d(this,ee)}set model(e){u(this,ee,e)}get params(){return d(this,te)}set params(e){u(this,te,e)}get systemMessage(){return d(this,se)}set systemMessage(e){u(this,se,e)}get retrieval(){return d(this,ie)}set retrieval(e){u(this,ie,e)}get metadata(){return d(this,ae)}set metadata(e){u(this,ae,e)}get embed(){return d(this,re)}set embed(e){u(this,re,e)}get position(){return d(this,ne)}set position(e){u(this,ne,e)}get sidebar(){return d(this,oe)}set sidebar(e){u(this,oe,e)}get showTitle(){return d(this,le)}set showTitle(e){u(this,le,e)}get chatIdAttr(){return d(this,ce)}set chatIdAttr(e){u(this,ce,e)}get chatKey(){return d(this,he)}set chatKey(e){u(this,he,e)}get assistantName(){return d(this,de)}set assistantName(e){u(this,de,e)}get logoUrl(){return d(this,pe)}set logoUrl(e){u(this,pe,e)}get heading(){return d(this,ue)}set heading(e){u(this,ue,e)}get description(){return d(this,ge)}set description(e){u(this,ge,e)}get eyebrow(){return d(this,me)}set eyebrow(e){u(this,me,e)}get prompts(){return d(this,be)}set prompts(e){u(this,be,e)}get bubbleText(){return d(this,fe)}set bubbleText(e){u(this,fe,e)}get greetingBubble(){return d(this,ve)}set greetingBubble(e){u(this,ve,e)}get unreadBadge(){return d(this,xe)}set unreadBadge(e){u(this,xe,e)}get allowUpload(){return d(this,we)}set allowUpload(e){u(this,we,e)}get allowExport(){return d(this,ye)}set allowExport(e){u(this,ye,e)}get allowCopy(){return d(this,ke)}set allowCopy(e){u(this,ke,e)}get allowRegenerate(){return d(this,$e)}set allowRegenerate(e){u(this,$e,e)}get allowBookmark(){return d(this,Ce)}set allowBookmark(e){u(this,Ce,e)}get allowDelete(){return d(this,Se)}set allowDelete(e){u(this,Se,e)}get allowRename(){return d(this,Te)}set allowRename(e){u(this,Te,e)}get allowFeedback(){return d(this,Oe)}set allowFeedback(e){u(this,Oe,e)}get showComposer(){return d(this,Ie)}set showComposer(e){u(this,Ie,e)}get showTime(){return d(this,Me)}set showTime(e){u(this,Me,e)}get footnote(){return d(this,_e)}set footnote(e){u(this,_e,e)}get allowRaw(){return d(this,ze)}set allowRaw(e){u(this,ze,e)}get branding(){return d(this,Le)}set branding(e){u(this,Le,e)}get chatList(){return d(this,je)}set chatList(e){u(this,je,e)}get listState(){return d(this,Ae)}set listState(e){u(this,Ae,e)}get activeId(){return d(this,Re)}set activeId(e){u(this,Re,e)}get chatTitle(){return d(this,Ne)}set chatTitle(e){u(this,Ne,e)}get bookmarked(){return d(this,Ee)}set bookmarked(e){u(this,Ee,e)}get msgs(){return d(this,Be)}set msgs(e){u(this,Be,e)}get loadingThread(){return d(this,Fe)}set loadingThread(e){u(this,Fe,e)}get threadError(){return d(this,De)}set threadError(e){u(this,De,e)}get busy(){return d(this,Ke)}set busy(e){u(this,Ke,e)}get draft(){return d(this,Pe)}set draft(e){u(this,Pe,e)}get files(){return d(this,Ue)}set files(e){u(this,Ue,e)}get search(){return d(this,He)}set search(e){u(this,He,e)}get sidebarOpen(){return d(this,We)}set sidebarOpen(e){u(this,We,e)}get width(){return d(this,Ve)}set width(e){u(this,Ve,e)}get panel(){return d(this,Je)}set panel(e){u(this,Je,e)}get menuOpen(){return d(this,qe)}set menuOpen(e){u(this,qe,e)}get viewOpen(){return d(this,Ge)}set viewOpen(e){u(this,Ge,e)}get viewHidden(){return d(this,Xe)}set viewHidden(e){u(this,Xe,e)}get editingKey(){return d(this,Ye)}set editingKey(e){u(this,Ye,e)}get editDraft(){return d(this,Qe)}set editDraft(e){u(this,Qe,e)}get editingTitle(){return d(this,Ze)}set editingTitle(e){u(this,Ze,e)}get renamingId(){return d(this,et)}set renamingId(e){u(this,et,e)}get toast(){return d(this,tt)}set toast(e){u(this,tt,e)}get copiedKey(){return d(this,st)}set copiedKey(e){u(this,st,e)}get retrievalOpen(){return d(this,it)}set retrievalOpen(e){u(this,it,e)}get rawKeys(){return d(this,at)}set rawKeys(e){u(this,at,e)}get savedFiles(){return d(this,rt)}set savedFiles(e){u(this,rt,e)}get hasSidebarContent(){return d(this,nt)}set hasSidebarContent(e){u(this,nt,e)}get sorts(){return d(this,ot)}set sorts(e){u(this,ot,e)}get arrivedKey(){return d(this,lt)}set arrivedKey(e){u(this,lt,e)}get dragging(){return d(this,ct)}set dragging(e){u(this,ct,e)}get showJump(){return d(this,ht)}set showJump(e){u(this,ht,e)}get offline(){return d(this,dt)}set offline(e){u(this,dt,e)}get isOpen(){return d(this,pt)}set isOpen(e){u(this,pt,e)}get expanded(){return d(this,ut)}set expanded(e){u(this,ut,e)}get bubble(){return d(this,gt)}set bubble(e){u(this,gt,e)}get seen(){return d(this,mt)}set seen(e){u(this,mt,e)}get mobile(){return d(this,bt)}set mobile(e){u(this,bt,e)}get starterList(){return d(this,ft)}set starterList(e){u(this,ft,e)}get startersLoading(){return d(this,vt)}set startersLoading(e){u(this,vt,e)}get msg(){return qt(this.messages)}get resolvedClient(){return this.client??ns.getDefaultClient()??null}get chatId(){return this.activeId}get thread(){return this.msgs}get starters(){return this.starterList}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 Ft)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(Ft.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(),clearTimeout(this.resizeTimer),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 s,a;const e=this.renderRoot.querySelector(".root");e!==this.observed&&((s=this.observer)==null||s.disconnect(),this.observed=e,e&&typeof ResizeObserver<"u"&&(this.observer??(this.observer=new ResizeObserver(([r])=>{const o=Math.round(r.contentRect.width);o!==this.width&&(clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>{this.width=o,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.syncKeyedChat();const t=this.panel?`${this.panel.key}:${this.panel.n}`:"";if(t!==this.shownPassage&&(this.shownPassage=t,(a=this.renderRoot.querySelector(".passage-box.current"))==null||a.scrollIntoView({block:"nearest"})),this.focusNext){const r=this.renderRoot.querySelector(this.focusNext);this.focusNext="",r&&(r.focus(),"select"in r&&r.tagName==="INPUT"&&r.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>=Ts}get panelDocked(){const e=this.docked&&this.sidebarOpen?Ss:0;return this.width-e>=Os}newChat(){this.halt(),this.leaveKeyedChat(),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.leaveKeyedChat(),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.showChat(r),this.upsertChat({...s,...r,_id:e})}catch(r){if(a!==this.run)return;$t(r)?(this.chatList=this.chatList.filter(o=>o._id!==e),this.newChat(),this.showToast(this.msg.errNotFound)):this.threadError=this.msg.errLoad}finally{a===this.run&&(this.loadingThread=!1)}}get followupsVisible(){return this.showFollowups&&!(this.allowViewOptions&&this.viewHidden.followups)}get sourcesVisible(){return this.showSources&&!(this.allowViewOptions&&this.viewHidden.sources)}toggleView(e){this.viewHidden={...this.viewHidden,[e]:!this.viewHidden[e]},Es(this.viewHidden),this.emit("singlebase-chat-view",{followups:this.followupsVisible,sources:this.sourcesVisible})}showChat(e){this.chatTitle=(e==null?void 0:e.title)??"",this.bookmarked=!!(e!=null&&e.bookmarked),this.msgs=((e==null?void 0:e.messages)??[]).filter(t=>t&&(t.role==="user"||t.role==="assistant")).map(t=>this.fromServer(t)),this.savedFiles=Wt(e==null?void 0:e.attachments),this.stick=!0,this.scrollToBottom()}get wantsStarters(){return typeof this.prompts=="string"&&this.prompts.trim().toLowerCase()==="auto"}leaveKeyedChat(){this.syncRun+=1,this.boundKey="",this.prepared=!1,this.startersLoading=!1}baseRetrieval(){const e=this.docsetIds;return[...e.length?[{source:"docset",ids:e}]:[],...this.retrieval??[]]}async syncKeyedChat(){const e=this.resolvedClient,t=this.chatKey.trim(),s=this.wantsStarters;if(!e||!t&&!s||this.chatIdAttr||this.pendingChatId)return;const a=this.baseRetrieval(),r=JSON.stringify([t,s,this.mode,a]);if(r===this.syncSignature)return;this.syncSignature=r;const o=t!==this.syncedKey;if(this.syncedKey=t,!o&&(this.msgs.length||this.busy))return;o&&(this.halt(),this.activeId=null,this.chatTitle="",this.bookmarked=!1,this.msgs=[],this.savedFiles=[],this.threadError="");const h=++this.syncRun;this.boundKey=t,this.prepared=!1,this.starterList=[],this.startersLoading=s,this.loadingThread=!!t;try{let c=null;if(s){const f={system_message:this.systemPrompt(),mode:this.mode,starters:4};t&&(f.key=t),this.model&&(f.model=this.model),Object.keys(this.params??{}).length&&(f.params=this.params),Object.keys(this.metadata??{}).length&&(f.metadata=this.metadata),a.length&&(f.retrieval=a);try{c=await e.llm.call("prepare_chat",f)}catch(v){if(!t)throw v}}if(!(c!=null&&c._id)&&t&&(c=await e.llm.call("get_chat",{key:t})),h!==this.syncRun||this.msgs.length||this.busy)return;c!=null&&c._id&&(this.activeId=c._id,this.showChat(c),this.prepared=this.msgs.length===0,this.prepared||this.upsertChat(c),this.starterList=Array.isArray(c.starters)?c.starters.map(f=>String(f).trim()).filter(Boolean):[],this.starterList.length&&this.emit("singlebase-chat-starters",{chatId:c._id,starters:this.starterList}))}catch(c){if(h!==this.syncRun)return;t&&!s&&!$t(c)&&(this.threadError=this.msg.errLoad)}finally{h===this.syncRun&&(this.startersLoading=!1,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 x;if(!this.msgs.length)return;this.menuOpen=!1;const t=this.chatTitle||this.msg.untitled,s=b=>b.role==="user"?this.msg.you:this.assistantName,a=b=>new Date(b||Date.now()).toLocaleString(),r=b=>b.sources.map((w,k)=>{const _=L(w,k+1);return`[${_.n}] ${_.title}${_.path?` — ${_.path}`:""}`}),o=b=>(b.attachments??[]).map(w=>w.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(b=>({role:b.role,text:b.content,at:new Date(b.at||Date.now()).toISOString(),bookmarked:b.bookmarked,attachments:o(b),sources:r(b)}))},null,2),c="application/json",f="json"):e==="txt"?(h=`${t}
|
|
2477
2510
|
${"=".repeat(t.length)}
|
|
2478
2511
|
|
|
2479
|
-
`+this.msgs.map(
|
|
2480
|
-
${r(
|
|
2512
|
+
`+this.msgs.map(b=>[`${s(b)} · ${a(b.at)}`,o(b).length?`Attachments: ${o(b).join(", ")}`:"",b.content,r(b).length?`Sources:
|
|
2513
|
+
${r(b).join(`
|
|
2481
2514
|
`)}`:""].filter(Boolean).join(`
|
|
2482
2515
|
`)).join(`
|
|
2483
2516
|
|
|
2484
2517
|
`),c="text/plain",f="txt"):h=`# ${t}
|
|
2485
2518
|
|
|
2486
|
-
`+this.msgs.map(
|
|
2519
|
+
`+this.msgs.map(b=>[`### ${s(b)} · ${a(b.at)}`,o(b).length?`Attachments: ${o(b).join(", ")}`:"",b.content,r(b).length?`**Sources**
|
|
2487
2520
|
|
|
2488
|
-
${r(
|
|
2521
|
+
${r(b).map(w=>`- ${w}`).join(`
|
|
2489
2522
|
`)}`:""].filter(Boolean).join(`
|
|
2490
2523
|
|
|
2491
2524
|
`)).join(`
|
|
@@ -2493,10 +2526,10 @@ ${r(v).map(C=>`- ${C}`).join(`
|
|
|
2493
2526
|
---
|
|
2494
2527
|
|
|
2495
2528
|
`)+`
|
|
2496
|
-
`,this.emit("singlebase-chat-export",{chatId:this.activeId,format:e}),e==="copy"){(
|
|
2529
|
+
`,this.emit("singlebase-chat-export",{chatId:this.activeId,format:e}),e==="copy"){(x=navigator.clipboard)==null||x.writeText(h).catch(()=>{}),this.showToast(this.msg.copiedMarkdown);return}const $=`${t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"chat"}-${new Date().toISOString().slice(0,10)}.${f}`,C=URL.createObjectURL(new Blob([h],{type:c})),I=document.createElement("a");I.href=C,I.download=$,document.body.appendChild(I),I.click(),I.remove(),setTimeout(()=>URL.revokeObjectURL(C),2e3),this.showToast(T.fill(this.msg.exported,{name:$}))}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:kt(),id:null,role:"user",content:e,at:Date.now(),bookmarked:!1,sources:[],followups:[],phase:"done",attachments:t}}systemPrompt(){return[this.systemMessage,Ut[this.mode]??Ut.chat,js[this.formatLevel],this.followups?As:""].filter(Boolean).join(`
|
|
2497
2530
|
|
|
2498
|
-
`)}payloadFor(e){const t={message:e.content,format:"markdown"};this.activeId?t._id=this.activeId:(t.title=
|
|
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"}),
|
|
2531
|
+
`)}payloadFor(e){const t={message:e.content,format:"markdown"};this.activeId?(t._id=this.activeId,this.prepared&&(t.title=Et(e.content))):(t.title=Et(e.content),t.system_message=this.systemPrompt(),this.boundKey&&(t.key=this.boundKey)),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(h=>({type:"content",content:h.content,name:h.name,...h.mime?{mime:h.mime}:{},size:h.size,save_attachment:this.saveAttachments})));const r=a?[]:s.map(h=>h.name);(Object.keys(this.metadata??{}).length||r.length)&&(t.metadata={...this.metadata,...r.length?{attachments:r}:{}});const o=[...this.baseRetrieval(),...a?[]:Ds(s)];return o.length&&(t.retrieval=o),t}async runTurn(e){const t={key:kt(),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 o=!this.activeId||this.prepared;let h=this.payloadFor(e);if(this.beforeSend){let c;try{c=await this.beforeSend(h,{chatId:this.activeId,isNew:o,message:e})}catch(v){c=v}if(a!==this.run)return;if(c===!1){this.msgs=this.msgs.filter(v=>v!==e&&v!==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(o&&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),this.prepared=!1,o&&(this.chatTitle=(c==null?void 0:c.title)||h.title,this.bookmarked=!!(c!=null&&c.bookmarked));const v=(c==null?void 0:c.message)??{},$=typeof v.content=="string"?v.content:(c==null?void 0:c.json)!==void 0?JSON.stringify(c.json,null,2):"",{text:C,followups:I}=Ot($);e.id=v.reply_to??null,this.applyAttachmentResults(c==null?void 0:c.attachments),Object.assign(t,{id:v._id??null,content:C,sources:Array.isArray(v.sources)?v.sources:[],followups:I,execTime:typeof v.exec_time=="number"?v.exec_time:void 0,model:v.model,at:Date.now()}),this.emit("singlebase-chat-response",{chatId:f,message:t}),await this.reveal(t,a),o&&f&&this.autoTitle&&this.retitle(f,e.content,t.content)}catch(c){if(a!==this.run)return;const f=$t(c);f&&(this.chatList=this.chatList.filter(C=>C._id!==this.activeId),this.activeId=null);const v=Bs(c),$=f?this.msg.errNotFound:v==="KB_SOURCE_REQUIRED"?this.msg.errKbSource:this.msg.errGeneric;this.failTurn(t,$,v)}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="")},Ls),this.stick?this.scrollToBottom():this.showJump=!0};if(!s||Fs())return a(),Promise.resolve();const r=e.content,o=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+o),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}
|
|
2532
|
+
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"}),o=vs(r==null?void 0:r.result);if(!o||this.renamed.has(e))return;await a.llm.call("update_chat",{_id:e,title:o}),this.applyTitle(e,o,!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,o;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((o=this.resolvedClient)==null?void 0:o.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?Ot(String(e.content??"")):{text:String(e.content??""),followups:[]};return{key:kt(),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.viewOpen=!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=Wt(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,o;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((o=this.resolvedClient)==null?void 0:o.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(o=>o._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(o=>o._id!==e),a&&this.newChat(),this.showToast(this.msg.chatDeleted,{undo:()=>{const o=[...this.chatList];o.splice(Math.max(0,t),0,s),this.chatList=o,r&&!this.activeId&&!this.msgs.length&&(this.activeId=e,this.chatTitle=r.title,this.bookmarked=r.bookmarked,this.msgs=r.msgs)},commit:()=>{var o;this.emit("singlebase-chat-delete",{chatId:e}),(o=this.resolvedClient)==null||o.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()},Ms)}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>=Dt){this.showToast(T.fill(this.msg.tooManyFiles,{n:Dt}));break}if(!Is.test(a.name)&&!a.type.startsWith("text/")){this.showToast(T.fill(this.msg.fileType,{name:a.name}));continue}if(a.size>Kt){this.showToast(T.fill(this.msg.fileTooLarge,{name:a.name,size:T.formatSize(Kt)}));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.viewOpen)this.viewOpen=!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">
|
|
2500
2533
|
${this.renderWorkspace()}
|
|
2501
2534
|
</div>`:i.nothing,a=this.bubble&&!this.isOpen?i.html`<div class="bubble" part="bubble">
|
|
2502
2535
|
<button type="button" class="bubble-text" @click=${()=>this.open()}>
|
|
@@ -2511,7 +2544,7 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2511
2544
|
>
|
|
2512
2545
|
${y.close()}
|
|
2513
2546
|
</button>
|
|
2514
|
-
</div>`:i.nothing,
|
|
2547
|
+
</div>`:i.nothing,o=this.isOpen&&(this.expanded||this.mobile)?i.nothing:i.html`<button
|
|
2515
2548
|
type="button"
|
|
2516
2549
|
class="launcher-btn"
|
|
2517
2550
|
part="launcher"
|
|
@@ -2521,7 +2554,7 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2521
2554
|
>
|
|
2522
2555
|
${this.isOpen?y.chevronDown():y.chat()}
|
|
2523
2556
|
${this.unreadBadge&&!this.seen&&!this.isOpen?i.html`<span class="badge"></span>`:i.nothing}
|
|
2524
|
-
</button>`;return i.html`${s}${a}${
|
|
2557
|
+
</button>`;return i.html`${s}${a}${o}`}renderWorkspace(){const e=!this.docked;return i.html`<div class="root" @keydown=${this.onKeydown}>
|
|
2525
2558
|
${this.sidebarOpen&&e?i.html`<div class="scrim" @click=${()=>this.sidebarOpen=!1}></div>`:i.nothing}
|
|
2526
2559
|
${this.sidebarOpen&&this.sidebar!=="none"?this.renderSidebar(e):i.nothing}
|
|
2527
2560
|
<main
|
|
@@ -2559,10 +2592,10 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2559
2592
|
</div>`:i.nothing}
|
|
2560
2593
|
</main>
|
|
2561
2594
|
${this.renderPanel()}
|
|
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,
|
|
2595
|
+
</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,o=f=>a.filter(v=>!r(v)&&Ks(v._modified_at??v._created_at)===f),h=[[t.groupBookmarked,a.filter(r)],[t.groupToday,o("today")],[t.groupYesterday,o("yesterday")],[t.groupWeek,o("week")],[t.groupOlder,o("older")]];let c;return this.listState==="loading"&&!this.chatList.length?c=i.html`<div aria-label=${t.loadingChats}>
|
|
2563
2596
|
${[1,2,3,4].map(()=>i.html`<div class="skeleton"></div>`)}
|
|
2564
|
-
</div>`:a.length?c=h.filter(([,f])=>f.length).map(([f,
|
|
2565
|
-
${
|
|
2597
|
+
</div>`:a.length?c=h.filter(([,f])=>f.length).map(([f,v])=>i.html`<div class="group">${f}</div>
|
|
2598
|
+
${v.map($=>this.renderThreadRow($))}`):c=i.html`<span class="side-note"
|
|
2566
2599
|
>${s?T.fill(t.noMatch,{query:this.search.trim()}):t.noChats}</span
|
|
2567
2600
|
>`,i.html`<aside
|
|
2568
2601
|
class="sidebar ${e?"overlay":"docked"}"
|
|
@@ -2607,16 +2640,16 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2607
2640
|
maxlength="80"
|
|
2608
2641
|
.value=${a}
|
|
2609
2642
|
aria-label=${t.renameChat}
|
|
2610
|
-
@keydown=${
|
|
2611
|
-
@blur=${
|
|
2643
|
+
@keydown=${o=>{o.key==="Enter"&&this.commitRename(e._id,o.target.value),o.key==="Escape"&&(o.stopPropagation(),this.renamingId="")}}
|
|
2644
|
+
@blur=${o=>this.commitRename(e._id,o.target.value)}
|
|
2612
2645
|
/>
|
|
2613
|
-
</div>`;const r=
|
|
2646
|
+
</div>`;const r=o=>h=>{h.stopPropagation(),o()};return i.html`<div
|
|
2614
2647
|
class="thread ${s?"active":""}"
|
|
2615
2648
|
role="button"
|
|
2616
2649
|
tabindex="0"
|
|
2617
2650
|
aria-current=${s?"true":"false"}
|
|
2618
2651
|
@click=${()=>this.openChat(e._id)}
|
|
2619
|
-
@keydown=${
|
|
2652
|
+
@keydown=${o=>o.key==="Enter"&&this.openChat(e._id)}
|
|
2620
2653
|
>
|
|
2621
2654
|
<span class="thread-title">${a}</span>
|
|
2622
2655
|
<span class="thread-actions">
|
|
@@ -2653,8 +2686,8 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2653
2686
|
maxlength="80"
|
|
2654
2687
|
.value=${this.chatTitle}
|
|
2655
2688
|
aria-label=${e.renameChat}
|
|
2656
|
-
@keydown=${
|
|
2657
|
-
@blur=${
|
|
2689
|
+
@keydown=${o=>{o.key==="Enter"&&this.commitTitle(o.target.value),o.key==="Escape"&&(o.stopPropagation(),this.editingTitle=!1)}}
|
|
2690
|
+
@blur=${o=>this.commitTitle(o.target.value)}
|
|
2658
2691
|
/>`:i.html`<button
|
|
2659
2692
|
type="button"
|
|
2660
2693
|
class="title"
|
|
@@ -2698,6 +2731,20 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2698
2731
|
>
|
|
2699
2732
|
${y.bookmark(this.bookmarked)}
|
|
2700
2733
|
</button>`:i.nothing}
|
|
2734
|
+
${this.allowViewOptions&&(this.showFollowups||this.showSources)?i.html`<div class="menu-wrap">
|
|
2735
|
+
<button
|
|
2736
|
+
type="button"
|
|
2737
|
+
class="icon ${this.viewOpen?"on":""}"
|
|
2738
|
+
title=${e.viewOptions}
|
|
2739
|
+
aria-label=${e.viewOptions}
|
|
2740
|
+
aria-haspopup="menu"
|
|
2741
|
+
aria-expanded=${this.viewOpen?"true":"false"}
|
|
2742
|
+
@click=${()=>{this.menuOpen=!1,this.viewOpen=!this.viewOpen}}
|
|
2743
|
+
>
|
|
2744
|
+
${y.view()}
|
|
2745
|
+
</button>
|
|
2746
|
+
${this.viewOpen?this.renderViewMenu():i.nothing}
|
|
2747
|
+
</div>`:i.nothing}
|
|
2701
2748
|
${this.allowExport?i.html`<div class="menu-wrap">
|
|
2702
2749
|
<button
|
|
2703
2750
|
type="button"
|
|
@@ -2707,7 +2754,7 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2707
2754
|
aria-label=${e.exportChat}
|
|
2708
2755
|
aria-haspopup="menu"
|
|
2709
2756
|
aria-expanded=${this.menuOpen?"true":"false"}
|
|
2710
|
-
@click=${()=>this.menuOpen=!this.menuOpen}
|
|
2757
|
+
@click=${()=>{this.viewOpen=!1,this.menuOpen=!this.menuOpen}}
|
|
2711
2758
|
>
|
|
2712
2759
|
${y.download()}
|
|
2713
2760
|
</button>
|
|
@@ -2742,7 +2789,19 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2742
2789
|
${y.minimize()}
|
|
2743
2790
|
</button>`:i.nothing}`:i.nothing}
|
|
2744
2791
|
</div>
|
|
2745
|
-
</header>`}
|
|
2792
|
+
</header>`}renderViewMenu(){const e=this.msg,t=[];return this.showFollowups&&t.push([e.viewFollowups,"followups",this.followupsVisible]),this.showSources&&t.push([e.viewSources,"sources",this.sourcesVisible]),i.html`<div class="menu-scrim" @click=${()=>this.viewOpen=!1}></div>
|
|
2793
|
+
<div class="menu" role="menu">
|
|
2794
|
+
<span class="label">${e.viewHeading}</span>
|
|
2795
|
+
${t.map(([s,a,r])=>i.html`<button
|
|
2796
|
+
type="button"
|
|
2797
|
+
role="menuitemcheckbox"
|
|
2798
|
+
aria-checked=${r?"true":"false"}
|
|
2799
|
+
class="menu-item"
|
|
2800
|
+
@click=${()=>this.toggleView(a)}
|
|
2801
|
+
>
|
|
2802
|
+
<span>${s}</span><span class="ext">${r?y.check():i.nothing}</span>
|
|
2803
|
+
</button>`)}
|
|
2804
|
+
</div>`}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>
|
|
2746
2805
|
<div class="menu" role="menu">
|
|
2747
2806
|
<span class="label">${e.exportHeading}</span>
|
|
2748
2807
|
${t.map(([s,a,r])=>i.html`<button
|
|
@@ -2753,26 +2812,28 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2753
2812
|
>
|
|
2754
2813
|
<span>${s}</span><span class="ext">${a}</span>
|
|
2755
2814
|
</button>`)}
|
|
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})):(
|
|
2815
|
+
</div>`}promptList(){const e=this.wantsStarters?"":this.prompts;return this.wantsStarters&&this.starterList.length?this.starterList.slice(0,4).map(t=>({text:t})):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})):(Ht[this.mode]??Ht.chat).map(([t,s])=>({label:t,text:s}))}renderWelcome(){const e=this.msg,t=this.mode==="rag"?"Rag":this.mode==="kb"?"Kb":"Chat",s=o=>e[`${o}${t}`],a=this.eyebrow??s("eyebrow"),r=this.promptList();return i.html`<div class="welcome-slot">
|
|
2757
2816
|
<slot name="welcome"
|
|
2758
2817
|
><div class="welcome" part="welcome">
|
|
2759
2818
|
<div class="welcome-head">
|
|
2760
|
-
${this.logoUrl&&
|
|
2819
|
+
${this.logoUrl&&Bt(this.logoUrl,!0)?i.html`<img class="welcome-logo" src=${this.logoUrl} alt="" />`:i.nothing}
|
|
2761
2820
|
${a?i.html`<span class="label">${a}</span>`:i.nothing}
|
|
2762
2821
|
<h2>${this.heading||s("heading")}</h2>
|
|
2763
2822
|
<p>${this.description||s("description")}</p>
|
|
2764
2823
|
</div>
|
|
2765
|
-
${
|
|
2766
|
-
${
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2824
|
+
${this.startersLoading?i.html`<div class="prompts" aria-hidden="true">
|
|
2825
|
+
${[0,1,2,3].map(()=>i.html`<div class="prompt skeleton"></div>`)}
|
|
2826
|
+
</div>`:r.length?i.html`<div class="prompts">
|
|
2827
|
+
${r.map(o=>i.html`<button
|
|
2828
|
+
type="button"
|
|
2829
|
+
class="prompt"
|
|
2830
|
+
part="prompt"
|
|
2831
|
+
@click=${()=>this.send(o.text)}
|
|
2832
|
+
>
|
|
2833
|
+
<span class="label">${o.label||"Suggested"}</span>
|
|
2834
|
+
<span class="prompt-text">${o.text}</span>
|
|
2835
|
+
</button>`)}
|
|
2836
|
+
</div>`:i.nothing}
|
|
2776
2837
|
</div></slot
|
|
2777
2838
|
>
|
|
2778
2839
|
</div>`}renderThread(){const e=this.msgs.map(t=>t.role).lastIndexOf("assistant");return i.html`<div class="thread-view">
|
|
@@ -2787,10 +2848,10 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2787
2848
|
</button>`:i.nothing}
|
|
2788
2849
|
</div>`:i.nothing}
|
|
2789
2850
|
${this.loadingThread?i.html`${[1,2].map(()=>i.html`<div class="skeleton" style="height:48px"></div>`)}`:i.nothing}
|
|
2790
|
-
${
|
|
2851
|
+
${rs.repeat(this.msgs,t=>t.key,(t,s)=>t.role==="user"?this.renderUser(t):this.renderBot(t,s===e))}
|
|
2791
2852
|
</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
2853
|
${a.length?i.html`<div class="attachments">
|
|
2793
|
-
${a.map(r=>i.html`<span class="doc-chip"><span class="ext">${
|
|
2854
|
+
${a.map(r=>i.html`<span class="doc-chip"><span class="ext">${Ct(r.name)}</span><span class="name">${r.name}</span></span>`)}
|
|
2794
2855
|
</div>`:i.nothing}
|
|
2795
2856
|
${this.editingKey===e.key?i.html`<div class="edit-box">
|
|
2796
2857
|
<textarea
|
|
@@ -2849,11 +2910,11 @@ assistant: ${s.slice(0,1500)}`,custom_instructions:"Write a concise title (3–6
|
|
|
2849
2910
|
${y.trash()}
|
|
2850
2911
|
</button>`:i.nothing}
|
|
2851
2912
|
</div>`}
|
|
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",
|
|
2913
|
+
</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",o=e.sources.length,h=Tt(e.content),c=e.sources.map((b,w)=>L(b,w+1)),f=St(h.size?c.filter(b=>h.has(b.n)):c),v=St(c),$=b=>{var w;return((w=this.panel)==null?void 0:w.key)===e.key&&b.items.some(k=>k.n===this.panel.n)},C=e.at?new Date(e.at).toLocaleTimeString([],{hour:"numeric",minute:"2-digit"}):"",I=e.content+(f.length?`
|
|
2853
2914
|
|
|
2854
2915
|
Sources:
|
|
2855
|
-
${f.map(
|
|
2856
|
-
`)}`:"")
|
|
2916
|
+
${f.map(b=>`${b.items.map(w=>`[${w.n}]`).join("")} ${b.first.title}`).join(`
|
|
2917
|
+
`)}`:""),x=this.retrievalOpen.has(e.key);return i.html`<div class="msg bot" part="message assistant">
|
|
2857
2918
|
${a?i.html`<div class="halo"></div>`:i.nothing}
|
|
2858
2919
|
${this.arrivedKey===e.key?i.html`<div class="arrived">
|
|
2859
2920
|
<div class="wash"></div>
|
|
@@ -2866,37 +2927,37 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
2866
2927
|
<span class="ring"></span><span class="dot"></span>
|
|
2867
2928
|
<span class="shimmer">${this.pillLabel()}</span>
|
|
2868
2929
|
</div>`:i.nothing}
|
|
2869
|
-
${this.
|
|
2930
|
+
${this.sourcesVisible&&o&&!a?i.html`<div class="retrieval">
|
|
2870
2931
|
<button
|
|
2871
2932
|
type="button"
|
|
2872
2933
|
class="retrieval-toggle"
|
|
2873
|
-
aria-expanded=${
|
|
2874
|
-
@click=${()=>{const
|
|
2934
|
+
aria-expanded=${x?"true":"false"}
|
|
2935
|
+
@click=${()=>{const b=new Set(this.retrievalOpen);b.has(e.key)?b.delete(e.key):b.add(e.key),this.retrievalOpen=b}}
|
|
2875
2936
|
>
|
|
2876
|
-
<span class="chev">${
|
|
2877
|
-
<span style="flex:1">${T.fill(s.searchedSources,{n})}</span>
|
|
2937
|
+
<span class="chev">${x?"▾":"▸"}</span>
|
|
2938
|
+
<span style="flex:1">${T.fill(s.searchedSources,{n:v.length})}</span>
|
|
2878
2939
|
${e.execTime!==void 0?i.html`<span class="ms">${e.execTime.toFixed(1)}s</span>`:i.nothing}
|
|
2879
2940
|
</button>
|
|
2880
|
-
${
|
|
2881
|
-
${
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2941
|
+
${x?i.html`<div class="retrieval-list">
|
|
2942
|
+
${v.map(b=>{const w=b.first,k=b.items.map(yt=>yt.score).filter(yt=>yt!==null),_=k.length?Math.max(...k):null,wt=b.items.length>1?T.fill(s.passageCount,{n:b.items.length}):w.section;return i.html`<button
|
|
2943
|
+
type="button"
|
|
2944
|
+
class="passage"
|
|
2945
|
+
@click=${()=>this.panel={key:e.key,n:w.n}}
|
|
2946
|
+
>
|
|
2947
|
+
<span class="n">${w.n}</span>
|
|
2948
|
+
<span class="what"
|
|
2949
|
+
><span>${w.title}${wt?` · ${wt}`:""}</span
|
|
2950
|
+
><span>${w.collection||w.path}</span></span
|
|
2885
2951
|
>
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
class="relevance-fill"
|
|
2896
|
-
style="width:${Math.round(x.score*100)}%"
|
|
2897
|
-
></span></span
|
|
2898
|
-
></span>`:i.html`<span></span>`}
|
|
2899
|
-
</button>`)}
|
|
2952
|
+
${_!==null?i.html`<span class="relevance"
|
|
2953
|
+
><span class="score">${_.toFixed(2)}</span>
|
|
2954
|
+
<span class="relevance-track"
|
|
2955
|
+
><span
|
|
2956
|
+
class="relevance-fill"
|
|
2957
|
+
style="width:${Math.round(_*100)}%"
|
|
2958
|
+
></span></span
|
|
2959
|
+
></span>`:i.html`<span></span>`}
|
|
2960
|
+
</button>`})}
|
|
2900
2961
|
</div>`:i.nothing}
|
|
2901
2962
|
</div>`:i.nothing}
|
|
2902
2963
|
${a?i.nothing:this.renderAnswer(e)}
|
|
@@ -2907,21 +2968,22 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
2907
2968
|
${s.retry}
|
|
2908
2969
|
</button>
|
|
2909
2970
|
</div>`:i.nothing}
|
|
2910
|
-
${this.
|
|
2971
|
+
${this.sourcesVisible&&r&&f.length?i.html`<div class="cards">
|
|
2911
2972
|
<span class="label">${h.size?s.sourcesCited:s.sourcesRetrieved}</span>
|
|
2912
2973
|
<div class="card-grid">
|
|
2913
|
-
${f.map(
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2974
|
+
${f.map(b=>{const w=b.first,k=b.items.length>1?T.fill(s.passageCount,{n:b.items.length}):w.section;return i.html`<button
|
|
2975
|
+
type="button"
|
|
2976
|
+
class="source-card ${$(b)?"active":""}"
|
|
2977
|
+
@click=${()=>this.panel={key:e.key,n:w.n}}
|
|
2978
|
+
>
|
|
2979
|
+
<span class="top"
|
|
2980
|
+
><span class="nums"
|
|
2981
|
+
>${b.items.map(_=>i.html`<span class="num">${_.n}</span>`)}</span
|
|
2982
|
+
>${w.collection?i.html`<span class="label">${w.collection}</span>`:i.nothing}</span
|
|
2917
2983
|
>
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
>
|
|
2922
|
-
<span class="t">${x.title}${x.section?` · ${x.section}`:""}</span>
|
|
2923
|
-
<span class="s">${x.text}</span>
|
|
2924
|
-
</button>`})}
|
|
2984
|
+
<span class="t">${w.title}${k?` · ${k}`:""}</span>
|
|
2985
|
+
<span class="s">${w.text}</span>
|
|
2986
|
+
</button>`})}
|
|
2925
2987
|
</div>
|
|
2926
2988
|
</div>`:i.nothing}
|
|
2927
2989
|
${r?i.html`<div class="toolbar ${t?"pinned":""}">
|
|
@@ -2930,7 +2992,7 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
2930
2992
|
class="icon"
|
|
2931
2993
|
title=${this.copiedKey===e.key?s.copied:s.copy}
|
|
2932
2994
|
aria-label=${s.copy}
|
|
2933
|
-
@click=${()=>this.copy(e.key,
|
|
2995
|
+
@click=${()=>this.copy(e.key,I)}
|
|
2934
2996
|
>
|
|
2935
2997
|
${y.copy()}
|
|
2936
2998
|
</button>`:i.nothing}
|
|
@@ -2971,7 +3033,7 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
2971
3033
|
>
|
|
2972
3034
|
${y.trash()}
|
|
2973
3035
|
</button>`:i.nothing}
|
|
2974
|
-
${this.showTime?i.html`<span class="time">${
|
|
3036
|
+
${this.showTime?i.html`<span class="time">${C}</span>`:i.nothing}
|
|
2975
3037
|
${e.stopped?i.html`<span class="note">${s.stopped}</span>`:i.nothing}
|
|
2976
3038
|
<span class="spacer"></span>
|
|
2977
3039
|
${this.allowFeedback?e.feedback?i.html`<span class="note"
|
|
@@ -2995,27 +3057,27 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
2995
3057
|
${y.thumb(!0)}
|
|
2996
3058
|
</button>`:i.nothing}
|
|
2997
3059
|
</div>`:i.nothing}
|
|
2998
|
-
${this.
|
|
2999
|
-
${e.followups.map(
|
|
3000
|
-
<span class="arrow">↳</span><span>${
|
|
3060
|
+
${this.followupsVisible&&r&&t&&!this.busy&&e.followups.length?i.html`<div class="followups">
|
|
3061
|
+
${e.followups.map(b=>i.html`<button type="button" class="followup" @click=${()=>this.send(b)}>
|
|
3062
|
+
<span class="arrow">↳</span><span>${b}</span>
|
|
3001
3063
|
</button>`)}
|
|
3002
3064
|
</div>`:i.nothing}
|
|
3003
3065
|
</div>
|
|
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"?
|
|
3005
|
-
${a.map((
|
|
3006
|
-
</div>`}renderInline(e,t,s){return
|
|
3066
|
+
</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"?Qt(e.content):e.content;let a=Zt(Gt(s),t);if(this.afterParse)try{const o=this.afterParse(a,{message:e,format:t});Array.isArray(o)?a=o:console.warn("[singlebase-chat] afterParse must return an array of blocks; showing the original.")}catch(o){console.warn("[singlebase-chat] afterParse failed; showing the original.",o)}const r=e.sources.reduce((o,h,c)=>Math.max(o,L(h,c+1).n),0);return i.html`<div class="answer" part="answer">
|
|
3067
|
+
${a.map((o,h)=>this.renderBlock(o,e,r,h))}
|
|
3068
|
+
</div>`}renderInline(e,t,s){return Yt(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"
|
|
3007
3069
|
>${a.text}</a
|
|
3008
|
-
>`;case"cite":{const
|
|
3070
|
+
>`;case"cite":{const o=((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=${o} 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">
|
|
3009
3071
|
<strong class="callout-title"
|
|
3010
|
-
>${e.title||this.msg[
|
|
3072
|
+
>${e.title||this.msg[zs[e.kind]]}</strong
|
|
3011
3073
|
>
|
|
3012
3074
|
${e.text.split(`
|
|
3013
3075
|
`).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=
|
|
3076
|
+
</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=es(e.source);if(!r)return this.renderCode("svg",e.source,`${t.key}:${a}`);const o=`${t.key}:${a}`;return i.html`<figure class="svg" part="svg">
|
|
3015
3077
|
<img src=${r} alt="Drawing" />
|
|
3016
3078
|
<figcaption>
|
|
3017
|
-
<button type="button" class="text-btn" @click=${()=>this.copy(
|
|
3018
|
-
${this.copiedKey===
|
|
3079
|
+
<button type="button" class="text-btn" @click=${()=>this.copy(o,e.source)}>
|
|
3080
|
+
${this.copiedKey===o?this.msg.copied:this.msg.copySvg}
|
|
3019
3081
|
</button>
|
|
3020
3082
|
</figcaption>
|
|
3021
3083
|
</figure>`}case"pending":return i.html`<div class="chart-pending">
|
|
@@ -3024,7 +3086,7 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
3024
3086
|
>
|
|
3025
3087
|
</div>`;case"chart":return this.renderChart(e.spec);case"img":return i.html`<div class="gallery ${e.images.length>1?"many":""}">
|
|
3026
3088
|
${e.images.map(r=>i.html`<figure>
|
|
3027
|
-
${r.src&&
|
|
3089
|
+
${r.src&&Bt(r.src,!0)?i.html`<img
|
|
3028
3090
|
src=${r.src}
|
|
3029
3091
|
alt=${r.alt}
|
|
3030
3092
|
loading="lazy"
|
|
@@ -3032,12 +3094,12 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
3032
3094
|
/>`:i.html`<div class="img-missing"><span class="label">Image</span></div>`}
|
|
3033
3095
|
${r.alt?i.html`<figcaption>${r.alt}</figcaption>`:i.nothing}
|
|
3034
3096
|
</figure>`)}
|
|
3035
|
-
</div>`;default:return i.nothing}}renderList(e,t,s,a){const r=t.map(
|
|
3036
|
-
class=${
|
|
3037
|
-
style=${
|
|
3097
|
+
</div>`;default:return i.nothing}}renderList(e,t,s,a){const r=t.map(o=>i.html`<li
|
|
3098
|
+
class=${o.checked===null?"":"task"}
|
|
3099
|
+
style=${o.depth?`margin-left:${o.depth*20}px`:""}
|
|
3038
3100
|
>
|
|
3039
|
-
${
|
|
3040
|
-
${this.renderInline(
|
|
3101
|
+
${o.checked===null?i.nothing:i.html`<input type="checkbox" disabled .checked=${o.checked} aria-hidden="true" />`}
|
|
3102
|
+
${this.renderInline(o.text,s,a)}
|
|
3041
3103
|
</li>`);return e?i.html`<ol>
|
|
3042
3104
|
${r}
|
|
3043
3105
|
</ol>`:i.html`<ul>
|
|
@@ -3050,35 +3112,35 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
3050
3112
|
</button>
|
|
3051
3113
|
</div>
|
|
3052
3114
|
<pre><code>${t}</code></pre>
|
|
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
|
|
3115
|
+
</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 o=a(t,{lang:e,message:s});return o==null?null:i.html`<div class="custom-block">${o}</div>`}catch(o){return console.warn(`[singlebase-chat] the "${e}" renderer failed; showing the source`,o),null}}renderTable(e,t,s,a,r,o){const h=b=>/^[-+]?[$€£¥]?\s?[\d,.]+\s?%?$/.test(b.trim())&&/\d/.test(b),c=b=>Number(b.replace(/[^\d.+-]/g,"")),f=e.map((b,w)=>{if(s[w])return s[w];const k=t.map(_=>_[w]??"").filter(Boolean);return k.length&&k.filter(h).length/k.length>=.8?"right":null}),v=this.sorts.get(o);let $=t;v&&($=[...t].sort((b,w)=>{const k=b[v.col]??"",_=w[v.col]??"";return(h(k)&&h(_)?c(k)-c(_):k.localeCompare(_,void 0,{numeric:!0}))*v.dir}));const C=$.length;$=$.slice(0,_s);const I=b=>{const w=new Map(this.sorts),k=w.get(o);(k==null?void 0:k.col)===b&&k.dir===-1?w.delete(o):w.set(o,{col:b,dir:(k==null?void 0:k.col)===b?-1:1}),this.sorts=w},x=b=>f[b]?`text-align:${f[b]}`:"";return i.html`<div class="table" part="table">
|
|
3054
3116
|
<table>
|
|
3055
3117
|
<thead>
|
|
3056
3118
|
<tr>
|
|
3057
|
-
${e.map((
|
|
3058
|
-
${t.length>1?i.html`<button type="button" class="sort" @click=${()=>
|
|
3059
|
-
${this.renderInline(
|
|
3119
|
+
${e.map((b,w)=>{const k=(v==null?void 0:v.col)===w?v.dir===1?"ascending":"descending":"none";return i.html`<th style=${x(w)} aria-sort=${k}>
|
|
3120
|
+
${t.length>1?i.html`<button type="button" class="sort" @click=${()=>I(w)}>
|
|
3121
|
+
${this.renderInline(b,a,r)}<span class="arrow"
|
|
3060
3122
|
>${k==="ascending"?"↑":k==="descending"?"↓":"↕"}</span
|
|
3061
3123
|
>
|
|
3062
|
-
</button>`:this.renderInline(
|
|
3124
|
+
</button>`:this.renderInline(b,a,r)}
|
|
3063
3125
|
</th>`})}
|
|
3064
3126
|
</tr>
|
|
3065
3127
|
</thead>
|
|
3066
3128
|
<tbody>
|
|
3067
|
-
${
|
|
3068
|
-
${e.map((
|
|
3069
|
-
${this.renderInline(
|
|
3129
|
+
${$.map(b=>i.html`<tr>
|
|
3130
|
+
${e.map((w,k)=>i.html`<td style=${x(k)}>
|
|
3131
|
+
${this.renderInline(b[k]??"",a,r)}
|
|
3070
3132
|
</td>`)}
|
|
3071
3133
|
</tr>`)}
|
|
3072
3134
|
</tbody>
|
|
3073
3135
|
</table>
|
|
3074
|
-
${
|
|
3075
|
-
${T.fill(this.msg.showingRows,{n
|
|
3136
|
+
${C>$.length?i.html`<div class="table-note">
|
|
3137
|
+
${T.fill(this.msg.showingRows,{n:$.length,total:C})}
|
|
3076
3138
|
</div>`:i.nothing}
|
|
3077
|
-
</div>`}renderJsonBlock(e,t,s){let a=0;const r=h=>{a++,a<=
|
|
3078
|
-
<summary>${
|
|
3079
|
-
<div class="jkids">${
|
|
3080
|
-
</details>`}const
|
|
3081
|
-
${
|
|
3139
|
+
</div>`}renderJsonBlock(e,t,s){let a=0;const r=h=>{a++,a<=Pt&&h&&typeof h=="object"&&Object.values(h).forEach(r)};if(r(e),a>Pt)return this.renderCode("json",t,s);const o=(h,c,f)=>{const v=f===void 0?i.nothing:i.html`<span class="jkey">${f}</span>: `;if(h&&typeof h=="object"){const C=Object.entries(h),I=Array.isArray(h)?`[${C.length}]`:`{${C.length}}`;return i.html`<details class="jnode" ?open=${c<2}>
|
|
3140
|
+
<summary>${v}<span class="jmeta">${I}</span></summary>
|
|
3141
|
+
<div class="jkids">${C.map(([x,b])=>o(b,c+1,x))}</div>
|
|
3142
|
+
</details>`}const $=h===null?"null":typeof h;return i.html`<div class="jleaf">
|
|
3143
|
+
${v}<span class="jv ${$}">${JSON.stringify(h)}</span>
|
|
3082
3144
|
</div>`};return i.html`<div class="code json" part="json">
|
|
3083
3145
|
<div class="code-head">
|
|
3084
3146
|
<span class="label">json</span>
|
|
@@ -3086,23 +3148,23 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
3086
3148
|
${this.copiedKey===s?this.msg.copied:this.msg.copy}
|
|
3087
3149
|
</button>
|
|
3088
3150
|
</div>
|
|
3089
|
-
<div class="jtree">${
|
|
3151
|
+
<div class="jtree">${o(e,0)}</div>
|
|
3090
3152
|
</div>`}renderChart(e){const t=e.series.length>1?i.html`<span class="legend">
|
|
3091
|
-
${e.series.map((
|
|
3153
|
+
${e.series.map((o,h)=>i.html`<span
|
|
3092
3154
|
><span
|
|
3093
3155
|
class="swatch"
|
|
3094
|
-
style="background:${
|
|
3156
|
+
style="background:${z[h%z.length]}"
|
|
3095
3157
|
></span
|
|
3096
|
-
>${
|
|
3158
|
+
>${o.name}</span
|
|
3097
3159
|
>`)}
|
|
3098
3160
|
</span>`:i.nothing,s=i.html`<div class="chart-head">
|
|
3099
3161
|
<span class="chart-title">${e.title}</span>${t}
|
|
3100
|
-
</div>`;if(e.type==="line"){const
|
|
3162
|
+
</div>`;if(e.type==="line"){const o=Math.max(0,...e.series.flatMap(v=>v.values)),h=Math.pow(10,Math.floor(Math.log10(o||1))),c=Math.ceil(o/h*2)/2*h||1,f=Math.max(e.labels.length,...e.series.map(v=>v.values.length));return i.html`<figure class="chart" part="chart" aria-label=${e.title}>
|
|
3101
3163
|
${s}
|
|
3102
3164
|
<div class="line-chart">
|
|
3103
3165
|
<div class="plot">
|
|
3104
|
-
${[1,.5,0].map(
|
|
3105
|
-
<span>${
|
|
3166
|
+
${[1,.5,0].map(v=>i.html`<div class="tick ${v===0?"base":""}" style="top:${(1-v)*100}%">
|
|
3167
|
+
<span>${xt(Math.round(c*v),e.unit)}</span>
|
|
3106
3168
|
</div>`)}
|
|
3107
3169
|
<svg
|
|
3108
3170
|
viewBox="0 0 600 170"
|
|
@@ -3110,30 +3172,30 @@ ${f.map(x=>`[${x.n}] ${x.title}`).join(`
|
|
|
3110
3172
|
role="img"
|
|
3111
3173
|
aria-label=${e.title}
|
|
3112
3174
|
>
|
|
3113
|
-
${e.series.map((
|
|
3114
|
-
points=${
|
|
3175
|
+
${e.series.map((v,$)=>i.svg`<polyline pathLength="1" stroke=${z[$%z.length]}
|
|
3176
|
+
points=${v.values.map((C,I)=>`${(f>1?I/(f-1)*600:300).toFixed(1)},${(170-C/c*170).toFixed(1)}`).join(" ")}><title>${v.name}: ${v.values.map(C=>xt(C,e.unit)).join(", ")}</title></polyline>`)}
|
|
3115
3177
|
</svg>
|
|
3116
3178
|
</div>
|
|
3117
|
-
<div class="x-labels">${e.labels.map(
|
|
3179
|
+
<div class="x-labels">${e.labels.map(v=>i.html`<span>${v}</span>`)}</div>
|
|
3118
3180
|
</div>
|
|
3119
|
-
</figure>`}const a=e.labels.map((
|
|
3181
|
+
</figure>`}const a=e.labels.map((o,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
3182
|
${s}
|
|
3121
3183
|
<div class="bars">
|
|
3122
|
-
${e.labels.map((
|
|
3123
|
-
<span class="bar-label">${
|
|
3184
|
+
${e.labels.map((o,h)=>i.html`<div class="bar-row" title="${o}: ${xt(a[h],e.unit)}">
|
|
3185
|
+
<span class="bar-label">${o}</span>
|
|
3124
3186
|
<span class="bar-track"
|
|
3125
3187
|
><span class="bar-fill" style="width:${Math.max(0,a[h])/r*100}%">
|
|
3126
3188
|
${e.series.map((c,f)=>i.html`<span
|
|
3127
|
-
style="flex:${Math.max(0,c.values[h]||0)};background:${e.series.length>1?
|
|
3189
|
+
style="flex:${Math.max(0,c.values[h]||0)};background:${e.series.length>1?z[f%z.length]:"var(--c-ink)"}"
|
|
3128
3190
|
></span>`)}
|
|
3129
3191
|
</span></span
|
|
3130
3192
|
>
|
|
3131
|
-
<span class="bar-value">${
|
|
3193
|
+
<span class="bar-value">${xt(a[h],e.unit)}</span>
|
|
3132
3194
|
</div>`)}
|
|
3133
3195
|
</div>
|
|
3134
|
-
</figure>`}renderPanel(){if(!this.panel)return i.nothing;const e=this.msgs.find(
|
|
3135
|
-
— ${
|
|
3136
|
-
${
|
|
3196
|
+
</figure>`}renderPanel(){var I;if(!this.panel)return i.nothing;const e=this.msgs.find(x=>x.key===this.panel.key);if(!e)return i.nothing;const t=e.sources.map((x,b)=>L(x,b+1)),s=t.find(x=>x.n===this.panel.n);if(!s)return i.nothing;const a=this.msg,r=Tt(e.content),o=t.filter(x=>x.n===s.n||!r.size||r.has(x.n)),h=St(o),c=((I=h.find(x=>x.doc===s.doc))==null?void 0:I.items)??[s],f=h.filter(x=>x.doc!==s.doc),v=c.map(x=>x.score).filter(x=>x!==null),$=[s.updated?`Updated ${s.updated}`:"",v.length?`Relevance ${Math.max(...v).toFixed(2)}`:"",c.length>1?T.fill(a.passageCount,{n:c.length}):""].filter(Boolean).join(" · "),C=x=>`"${x.text}"
|
|
3197
|
+
— ${x.title} [${x.n}]${x.path?`
|
|
3198
|
+
${x.path}`:""}${x.updated?` · Updated ${x.updated}`:""}`;return i.html`<aside
|
|
3137
3199
|
class="panel ${this.panelDocked?"docked":"overlay"}"
|
|
3138
3200
|
part="panel"
|
|
3139
3201
|
role="region"
|
|
@@ -3141,7 +3203,7 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3141
3203
|
>
|
|
3142
3204
|
<div class="panel-head">
|
|
3143
3205
|
<span class="label"
|
|
3144
|
-
>${T.fill(a.sourceLabel,{n:
|
|
3206
|
+
>${T.fill(a.sourceLabel,{n:c.map(x=>x.n).join(", ")})}${s.collection?` · ${s.collection}`:""}</span
|
|
3145
3207
|
>
|
|
3146
3208
|
<button type="button" class="text-btn underline" @click=${()=>this.panel=null}>
|
|
3147
3209
|
${a.close}
|
|
@@ -3150,35 +3212,42 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3150
3212
|
<div class="panel-body">
|
|
3151
3213
|
<div class="panel-meta">
|
|
3152
3214
|
<h3>${s.title}</h3>
|
|
3153
|
-
${s.section?i.html`<span class="meta">${s.section}</span>`:i.nothing}
|
|
3215
|
+
${c.length===1&&s.section?i.html`<span class="meta">${s.section}</span>`:i.nothing}
|
|
3154
3216
|
${s.path?i.html`<span class="path">${s.path}</span>`:i.nothing}
|
|
3155
|
-
${
|
|
3156
|
-
</div>
|
|
3157
|
-
<div class="passage-box">
|
|
3158
|
-
<span class="text">${s.text}</span>
|
|
3159
|
-
<div class="passage-foot">
|
|
3160
|
-
<span class="label">${a.citedPassage}</span>
|
|
3161
|
-
<button
|
|
3162
|
-
type="button"
|
|
3163
|
-
class="copy-ref"
|
|
3164
|
-
title=${a.copyReference}
|
|
3165
|
-
aria-label=${a.copyReference}
|
|
3166
|
-
@click=${()=>this.copy(h,c)}
|
|
3167
|
-
>
|
|
3168
|
-
${y.copy()}<span>${this.copiedKey===h?a.copied:a.copy}</span>
|
|
3169
|
-
</button>
|
|
3170
|
-
</div>
|
|
3217
|
+
${$?i.html`<span class="meta">${$}</span>`:i.nothing}
|
|
3171
3218
|
</div>
|
|
3219
|
+
${c.map(x=>{const b=`ref:${e.key}:${x.n}`;return i.html`<div
|
|
3220
|
+
class="passage-box ${c.length>1&&x.n===s.n?"current":""}"
|
|
3221
|
+
data-n=${x.n}
|
|
3222
|
+
>
|
|
3223
|
+
${c.length>1?i.html`<span class="passage-head"
|
|
3224
|
+
><span class="num">${x.n}</span
|
|
3225
|
+
>${x.section?i.html`<span class="meta">${x.section}</span>`:i.nothing}</span
|
|
3226
|
+
>`:i.nothing}
|
|
3227
|
+
<span class="text">${x.text}</span>
|
|
3228
|
+
<div class="passage-foot">
|
|
3229
|
+
<span class="label">${a.citedPassage}</span>
|
|
3230
|
+
<button
|
|
3231
|
+
type="button"
|
|
3232
|
+
class="copy-ref"
|
|
3233
|
+
title=${a.copyReference}
|
|
3234
|
+
aria-label=${a.copyReference}
|
|
3235
|
+
@click=${()=>this.copy(b,C(x))}
|
|
3236
|
+
>
|
|
3237
|
+
${y.copy()}<span>${this.copiedKey===b?a.copied:a.copy}</span>
|
|
3238
|
+
</button>
|
|
3239
|
+
</div>
|
|
3240
|
+
</div>`})}
|
|
3172
3241
|
</div>
|
|
3173
|
-
${
|
|
3242
|
+
${f.length?i.html`<div class="panel-foot">
|
|
3174
3243
|
<span class="label">${a.alsoCited}</span>
|
|
3175
3244
|
<div class="chips">
|
|
3176
|
-
${
|
|
3245
|
+
${f.map(x=>i.html`<button
|
|
3177
3246
|
type="button"
|
|
3178
3247
|
class="chip"
|
|
3179
|
-
@click=${()=>this.panel={key:e.key,n:
|
|
3248
|
+
@click=${()=>this.panel={key:e.key,n:x.first.n}}
|
|
3180
3249
|
>
|
|
3181
|
-
${b.n} · ${
|
|
3250
|
+
${x.items.map(b=>b.n).join(", ")} · ${x.first.title}
|
|
3182
3251
|
</button>`)}
|
|
3183
3252
|
</div>
|
|
3184
3253
|
</div>`:i.nothing}
|
|
@@ -3191,14 +3260,14 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3191
3260
|
multiple
|
|
3192
3261
|
hidden
|
|
3193
3262
|
accept=".md,.markdown,.txt,.csv,.tsv,.json,.html,.htm,.yaml,.yml,.xml,.log,text/*"
|
|
3194
|
-
@change=${r=>{const
|
|
3263
|
+
@change=${r=>{const o=r.target;this.addFiles(o.files).then(()=>o.value="")}}
|
|
3195
3264
|
/>
|
|
3196
3265
|
<div class="composer-box">
|
|
3197
3266
|
${this.busy?i.html`<div class="composer-glow"></div>`:i.nothing}
|
|
3198
3267
|
<div class="composer ${this.busy?"busy":""}" part="composer">
|
|
3199
3268
|
${this.savedFiles.length?i.html`<div class="pending-files" part="saved-files">
|
|
3200
3269
|
${this.savedFiles.map(r=>i.html`<div class="pending-file kept">
|
|
3201
|
-
<span class="ext">${
|
|
3270
|
+
<span class="ext">${Ct(r.name)}</span>
|
|
3202
3271
|
<span class="meta"
|
|
3203
3272
|
><span class="name">${r.name}</span
|
|
3204
3273
|
><span class="size">${e.inThisChat}</span></span
|
|
@@ -3215,7 +3284,7 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3215
3284
|
</div>`:i.nothing}
|
|
3216
3285
|
${this.files.length?i.html`<div class="pending-files">
|
|
3217
3286
|
${this.files.map(r=>i.html`<div class="pending-file">
|
|
3218
|
-
<span class="ext">${
|
|
3287
|
+
<span class="ext">${Ct(r.name)}</span>
|
|
3219
3288
|
<span class="meta"
|
|
3220
3289
|
><span class="name">${r.name}</span
|
|
3221
3290
|
><span class="size">${T.formatSize(r.size)}</span></span
|
|
@@ -3224,7 +3293,7 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3224
3293
|
type="button"
|
|
3225
3294
|
aria-label=${e.removeFile}
|
|
3226
3295
|
title=${e.removeFile}
|
|
3227
|
-
@click=${()=>this.files=this.files.filter(
|
|
3296
|
+
@click=${()=>this.files=this.files.filter(o=>o!==r)}
|
|
3228
3297
|
>
|
|
3229
3298
|
×
|
|
3230
3299
|
</button>
|
|
@@ -3277,5 +3346,5 @@ ${s.path}`:""}${s.updated?` · Updated ${s.updated}`:""}`,f=[s.updated?`Updated
|
|
|
3277
3346
|
</div>
|
|
3278
3347
|
</div>`:i.html`<div class="composer-wrap reader">
|
|
3279
3348
|
<div class="composer-col">${a}</div>
|
|
3280
|
-
</div>`}},j=new WeakMap,A=new WeakMap,
|
|
3281
|
-
//# sourceMappingURL=chat-
|
|
3349
|
+
</div>`}},j=new WeakMap,A=new WeakMap,R=new WeakMap,N=new WeakMap,E=new WeakMap,B=new WeakMap,F=new WeakMap,D=new WeakMap,K=new WeakMap,P=new WeakMap,U=new WeakMap,H=new WeakMap,W=new WeakMap,V=new WeakMap,J=new WeakMap,q=new WeakMap,G=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,we=new WeakMap,ye=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,_e=new WeakMap,ze=new WeakMap,Le=new WeakMap,je=new WeakMap,Ae=new WeakMap,Re=new WeakMap,Ne=new WeakMap,Ee=new WeakMap,Be=new WeakMap,Fe=new WeakMap,De=new WeakMap,Ke=new WeakMap,Pe=new WeakMap,Ue=new WeakMap,He=new WeakMap,We=new WeakMap,Ve=new WeakMap,Je=new WeakMap,qe=new WeakMap,Ge=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,ut=new WeakMap,gt=new WeakMap,mt=new WeakMap,bt=new WeakMap,ft=new WeakMap,vt=new WeakMap,Vt);$s(exports.SinglebaseChat,"styles",[T.tokenDefaults,T.brandingStyles,os]);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:O,attribute:"save-attachments"})],exports.SinglebaseChat.prototype,"saveAttachments",1);m([g.property({converter:O})],exports.SinglebaseChat.prototype,"followups",1);m([g.property({converter:O,attribute:"show-sources"})],exports.SinglebaseChat.prototype,"showSources",1);m([g.property({converter:O,attribute:"show-new-chat"})],exports.SinglebaseChat.prototype,"showNewChat",1);m([g.property({converter:O,attribute:"show-bookmarked"})],exports.SinglebaseChat.prototype,"showBookmarked",1);m([g.property({converter:O,attribute:"show-followups"})],exports.SinglebaseChat.prototype,"showFollowups",1);m([g.property({type:Boolean,attribute:"allow-view-options"})],exports.SinglebaseChat.prototype,"allowViewOptions",1);m([g.property({converter:O,attribute:"allow-search"})],exports.SinglebaseChat.prototype,"allowSearch",1);m([g.property({converter:O,attribute:"auto-title"})],exports.SinglebaseChat.prototype,"autoTitle",1);m([g.property()],exports.SinglebaseChat.prototype,"model",1);m([g.property({converter:It})],exports.SinglebaseChat.prototype,"params",1);m([g.property({attribute:"system-message"})],exports.SinglebaseChat.prototype,"systemMessage",1);m([g.property({converter:It})],exports.SinglebaseChat.prototype,"retrieval",1);m([g.property({converter:It})],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:Cs})],exports.SinglebaseChat.prototype,"sidebar",1);m([g.property({converter:O,attribute:"show-title"})],exports.SinglebaseChat.prototype,"showTitle",1);m([g.property({attribute:"chat-id"})],exports.SinglebaseChat.prototype,"chatIdAttr",1);m([g.property({attribute:"chat-key"})],exports.SinglebaseChat.prototype,"chatKey",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:O,attribute:"allow-upload"})],exports.SinglebaseChat.prototype,"allowUpload",1);m([g.property({converter:O,attribute:"allow-export"})],exports.SinglebaseChat.prototype,"allowExport",1);m([g.property({converter:O,attribute:"allow-copy"})],exports.SinglebaseChat.prototype,"allowCopy",1);m([g.property({converter:O,attribute:"allow-regenerate"})],exports.SinglebaseChat.prototype,"allowRegenerate",1);m([g.property({converter:O,attribute:"allow-bookmark"})],exports.SinglebaseChat.prototype,"allowBookmark",1);m([g.property({converter:O,attribute:"allow-delete"})],exports.SinglebaseChat.prototype,"allowDelete",1);m([g.property({converter:O,attribute:"allow-rename"})],exports.SinglebaseChat.prototype,"allowRename",1);m([g.property({converter:O,attribute:"allow-feedback"})],exports.SinglebaseChat.prototype,"allowFeedback",1);m([g.property({converter:O,attribute:"show-composer"})],exports.SinglebaseChat.prototype,"showComposer",1);m([g.property({converter:O,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:O})],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,"viewOpen",1);m([g.state()],exports.SinglebaseChat.prototype,"viewHidden",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);m([g.state()],exports.SinglebaseChat.prototype,"starterList",1);m([g.state()],exports.SinglebaseChat.prototype,"startersLoading",1);exports.SinglebaseChat=m([g.customElement("singlebase-chat")],exports.SinglebaseChat);exports.adaptBlocks=Zt;exports.citedNumbers=Tt;exports.defaultChatMessages=Jt;exports.describeSource=L;exports.parseInline=Yt;exports.parseMarkdown=Gt;exports.resolveChatMessages=qt;exports.settleStreaming=Qt;exports.splitFollowups=Ot;exports.svgDataUrl=es;
|
|
3350
|
+
//# sourceMappingURL=chat-Bj6DrOaW.cjs.map
|