@bangdb/web-sdk 1.0.6 → 1.0.8
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/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.global.js +1303 -182
- package/dist/index.js +779 -101
- package/dist/index.mjs +779 -101
- package/package.json +37 -29
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Re=Object.create;var _=Object.defineProperty;var Be=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty;var Ue=(n,e)=>{for(var t in e)_(n,t,{get:e[t],enumerable:!0})},Q=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Pe(e))!Fe.call(n,r)&&r!==t&&_(n,r,{get:()=>e[r],enumerable:!(o=Be(e,r))||o.enumerable});return n};var A=(n,e,t)=>(t=n!=null?Re(_e(n)):{},Q(e||!n||!n.__esModule?_(t,"default",{value:n,enumerable:!0}):t,n)),Ke=n=>Q(_({},"__esModule",{value:!0}),n);var St={};Ue(St,{ChatWidget:()=>P,init:()=>Ne});module.exports=Ke(St);var Z=`
|
|
2
2
|
:root {
|
|
3
3
|
--thread-content-max-width: 32rem;
|
|
4
4
|
}
|
|
@@ -583,7 +583,7 @@ code.hljs {
|
|
|
583
583
|
.hljs-strong {
|
|
584
584
|
font-weight: bold
|
|
585
585
|
}
|
|
586
|
-
}`;var
|
|
586
|
+
}`;var ee=`
|
|
587
587
|
:root {
|
|
588
588
|
--border-xheavy: var(--border);
|
|
589
589
|
}
|
|
@@ -1046,10 +1046,281 @@ code.hljs {
|
|
|
1046
1046
|
.prose > :last-child:not(.not-prose *) {
|
|
1047
1047
|
margin-bottom: 0;
|
|
1048
1048
|
}
|
|
1049
|
-
`;var
|
|
1049
|
+
`;var ge=require("@reduxjs/toolkit");var te=require("@reduxjs/toolkit"),Ge={activeIndex:"",activeSession:"",sessions:[],useGenAi:!1,mode:0,tools:[]},oe=(0,te.createSlice)({name:"chat",initialState:Ge,reducers:{changeMode:(n,e)=>{n.mode=e.payload},setActiveIndex:(n,e)=>{n.activeIndex=e.payload},setActiveSession:(n,e)=>{n.activeSession=e.payload},setSessions:(n,e)=>{n.sessions=e.payload},setUseGenAi:(n,e)=>{n.useGenAi=e.payload},addTool:(n,e)=>{n.tools.some(t=>t.id===e.payload.id)||n.tools.push(e.payload)},removeTool:(n,e)=>{n.tools=n.tools.filter(t=>t.id!==e.payload)}}}),{setActiveIndex:re,setActiveSession:ne,setSessions:It,setUseGenAi:qt,changeMode:I,addTool:ae,removeTool:K}=oe.actions,ie=oe.reducer;var D=require("@reduxjs/toolkit");var S=class{constructor(e){this.rawResponse=e}detectModelVersion(){let e=this.extractOutput();return!e||e.length===0||!Array.isArray(e)?"unknown":e?.[0]?.content||e?.[1]?.content?"gpt5":e[0]?.message?"gpt4":e?.some(t=>t?.text)?"file-chat":"unknown"}extractOutput(){let e=this.rawResponse;return e?.choices||e?.a?.choices||e?.output||e?.a?.output||e?.content||e?.a?.content||[]}normalizeGPT4Choice(e){return{output:e?.message?.content||""}}normalizeFileChatResponse(e){return{output:e?.text?.value}}normalizeGPT5Output(e){return{output:e.content.map(t=>t.text).join(`
|
|
1050
1050
|
|
|
1051
|
-
`)}}parse(){let e=this.extractOutput(),t=this.detectModelVersion(),
|
|
1052
|
-
`);return!
|
|
1051
|
+
`)}}parse(){let e=this.extractOutput(),t=this.detectModelVersion(),o=[];return t==="gpt4"?o=e?.filter(({message:r})=>r?.content).map(r=>this.normalizeGPT4Choice(r)):t==="gpt5"?o=e?.filter(r=>r?.content?.length>0).map(r=>this.normalizeGPT5Output(r)):t==="file-chat"&&(o=e?.filter(({text:r})=>r)?.map(r=>this.normalizeFileChatResponse(r))),{messages:o,model:t,raw:this.rawResponse}}};var se=async({baseURL:n,payload:e,apikey:t})=>{try{return await(await fetch("https://"+n+"/ai/vector/chat",{method:"POST",body:JSON.stringify(e),headers:{"x-bang-api-key":t,"x-bang-api-src":"chat-applet"}})).json()}catch{return{error:"Failed to get the response"}}},G=async({baseURL:n,payload:e,apikey:t})=>{try{return await(await fetch("https://"+n+"/ai/vector/metadata",{method:"POST",body:JSON.stringify(e),headers:{"x-bang-api-key":t,"x-bang-api-src":"chat-applet"}})).json()}catch(o){console.error(o)}};var Ye={},O={query:"",chatData:[],streamingMessage:null,isLoading:!1},ce=(0,D.createSlice)({name:"chatSession",initialState:Ye,reducers:{initSession:(n,e)=>{let t=e.payload;n[t]||(n[t]=O)},setLoading:(n,e)=>{let{sessionId:t,loading:o}=e.payload;n[t]||(n[t]=O),n[t].isLoading=o},setQuery:(n,e)=>{let{sessionId:t,query:o}=e.payload;n[t]||(n[t]=O),n[t].query=o},appendChatData:(n,e)=>{let{sessionId:t,chatData:o}=e.payload;n[t]||(n[t]=O),n[t].chatData=[...n[t].chatData||[],...o]},setChatData:(n,e)=>{let{sessionId:t,chatData:o}=e.payload;n[t]||(n[t]=O),n[t].chatData=o},setStreamingMessage:(n,e)=>{let{sessionId:t,message:o}=e.payload;n[t]&&(n[t].streamingMessage=o)}}}),{initSession:We,setQuery:F,setChatData:Ft,appendChatData:le,setStreamingMessage:Y,setLoading:de}=ce.actions,pe=(0,D.createAsyncThunk)("chatSession/streamResponse",async({sessionId:n,query:e,indexName:t,config:{backendURL:o,apikey:r,userid:a}},{getState:s,dispatch:i})=>{let c=s(),{chatData:p,isLoading:d}=c.chatSessions[n];if(!e?.trim()||d)return;i(de({sessionId:n,loading:!0}));let l={query:e,a:{choices:[]}};i(Y({sessionId:n,message:l})),i(F({sessionId:n,query:""}));let g=p?.filter(x=>x&&x?.op!=="ADD_FILES"&&!x?.source_file&&!x?.source)?.length,h=Array.isArray(p)?p?.map(x=>{let{messages:E}=new S(x).parse(),L=E?.map(j=>j?.output)?.filter(Boolean)?.join(`
|
|
1052
|
+
`);return!x?.query||!L||L.startsWith("Error: ")?null:{q:x?.query,a:L}})?.filter(x=>x!==null):[],{tools:b}=c.chat,m=b?.[0],u=m?.id==="feeling-lucky"?"GenAI":void 0,y=m?.id==="kpi",w=Date.now(),k=await se({baseURL:o,apikey:r,payload:{name:t,qnum:g?g+1:1,fall_back:u,type:y?"kpi":void 0,sessionid:n,userid:a,prev_qa:y?void 0:h,query:l?.query}}),v=new S(k),{raw:C,messages:f}=v.parse();if(i(de({sessionId:n,loading:!1})),f?.length>0){for(let x=0;x<f.length;x++){let L=(f[x]?.output||"")?.split(" "),j="";for(let z=0;z<L.length;z++)await new Promise(H=>setTimeout(H,20)),j=j+(j?" ":"")+L[z],i(Y({sessionId:n,message:{...l,a:{choices:[{message:{content:j}}]}}}))}i(le({sessionId:n,chatData:[{...C,query:l?.query,queryTime:Date.now()-w}]})),i(Y({sessionId:n,message:null}))}else i(le({sessionId:n,chatData:[{query:l?.query,queryTime:Date.now()-w,a:{choices:[{message:{content:C?.a?.choices?.[0]?.message?.content||C?.error||"There is no context in the vector index and fall back option is null"}}]}}]}))}),he=(0,D.createAsyncThunk)("chatSession/initializeState",async({indexName:n},{dispatch:e})=>{let t="GUEST_SESSION";e(re(n)),e(ne(t)),e(We(t))});var be=ce.reducer;var me=(0,ge.configureStore)({reducer:{chat:ie,chatSessions:be}});var W=A(require("highlight.js")),ye=A(require("markdown-it")),ve=A(require("@vscode/markdown-it-katex"));var Je=function(n,e,t){let o=t,r=0,a=n.length;for(;o<e.length;){let s=e[o];if(r<=0&&e.slice(o,o+a)===n)return o;s==="\\"?o++:s==="{"?r++:s==="}"&&r--,o++}return-1},Ve=function(n){return n.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")},Xe=/^\\begin{/,Qe=function(n,e){let t,o=[],r=new RegExp("("+e.map(a=>Ve(a.left)).join("|")+")");for(;t=n.search(r),t!==-1;){t>0&&(o.push({type:"text",data:n.slice(0,t)}),n=n.slice(t));let a=e.findIndex(c=>n.startsWith(c.left));if(t=Je(e[a].right,n,e[a].left.length),t===-1)break;let s=n.slice(0,t+e[a].right.length),i=Xe.test(s)?s:n.slice(e[a].left.length,t);o.push({type:"math",data:i,rawData:s,display:e[a].display}),n=n.slice(t+e[a].right.length)}return n!==""&&o.push({type:"text",data:n}),o},ue=Qe;var to=require("katex/dist/contrib/mhchem.min.js");function fe(n){return new Promise(e=>{setTimeout(e,n)})}var xe=require("lodash"),we=new ye.default({html:!0,breaks:!0,linkify:!0,highlight:function(n,e){let t=e??"auto";if(e&&W.default.getLanguage(e))try{return`<pre class="language-${e}"><div class="ai-chat-code-title">${e}<a class="ai-chat-code-copy cursor-pointer">Copy</a></div><code class="hljs">`+W.default.highlight(n,{language:t,ignoreIllegals:!0}).value+"</code></pre>"}catch{}return'<pre><code class="hljs">'+n+"</code></pre>"}}).enable(["table","code","fence","blockquote","heading","lheading","paragraph"]).enable(["autolink","linkify","backticks","image","link","newline"]).enable(["emphasis","html_inline"]).use(ve.default);typeof window<"u"&&window.document.addEventListener("click",n=>{if(n.target?.classList?.contains("ai-chat-code-copy")){let e=n.target.parentNode?.nextSibling?.innerText;navigator.clipboard.writeText(e).then(async()=>{n.target.innerHTML='<span style="margin-right:3px">Copied</span>\u2705',await fe(3e3),n.target.innerText="Copy"}).catch(t=>{alert(`Error copying code: ${t.message}`)})}});var Ze={fn:n=>{n()}},ro=(0,xe.debounce)((n=()=>{})=>{Ze.fn(n)},10);var et=n=>n.replace(/(```mermaid)(?![^]*?```)/g,"```"),tt=n=>ue(n,[{left:"\\[",right:"\\]",display:!0},{left:"\\(",right:"\\)",display:!1}]).reduce((t,o)=>{if(o.type==="text")return t+o.data;let r=o.display?`$$${o.data}$$`:`$${o.data}$`;return t+r},""),ot=n=>{let e="",t="",o=!1,r="think-wrapper",a=s=>{let i=s.replace(/<script([^>]*)>/gi,"<script$1>");return i=i.replace(/<\/script>/gi,"</script>"),i=i.replace(/<script([^>]*)\s*\/>/gi,"<script$1 />"),i};for(let s=0;s<n.length;s++){let i=n[s],c=n.slice(s,s+7),p=n.slice(s,s+8);if(!o&&c==="<think>"){o=!0,e+=`<div class="${r}">`,s+=6;continue}if(o&&p==="</think>"){o=!1,e+="</div>",s+=7;continue}o?t+=i:e+=i}if(t){let s=a(t),i=we.render(s);e=e.replace(`<div class="${r}">`,`<div class="${r}">${i}`)}return e},rt=n=>n.replace(/\[source_id:\s*([^\]|]+)(?:\s*\|\s*category:\s*([^\]]+))?\]\.?/g,(e,t,o)=>o?`<source-tag data-source-id="${t.trim()}" data-category="${o.trim()}"></source-tag>`:`<source-tag data-source-id="${t.trim()}"></source-tag>`),$=n=>{let e=ot(n),t=tt(e),o=et(t),r=rt(o);return we.render(r)};var Te=A(require("echarts")),lo=require("echarts/theme/dark-bold.js"),M=require("ag-grid-community");function ke(n,e="",t={}){if(typeof n!="object"||n===null||Array.isArray(n))return t;for(let[o,r]of Object.entries(n)){let a=e?`${e}.${o}`:o;typeof r=="object"&&r!==null&&!Array.isArray(r)?ke(r,a,t):t[a]=r}return t}var nt=["#5470c6","#c5e542","#9d9ec1","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],at={color:nt,backgroundColor:"transparent",tooltip:{trigger:"axis",axisPointer:{type:"shadow"}},legend:{show:!0,type:"scroll",bottom:0,top:null},toolbox:{show:!0,feature:{saveAsImage:{}}}},q=class{constructor(e){this.data=e}parse(){let e=[];if(!this.data)return{charts:[],errors:["Invalid input: null or undefined"]};if(typeof this.data!="object")return{charts:[],errors:[`Invalid input type: expected object, got ${typeof this.data}`]};let t=this.extractArrays(this.data,[]),o=Object.entries(this.data).filter(([,a])=>typeof a=="number"&&!Number.isNaN(a)).map(([a,s])=>({title:a,type:"card",options:{title:a,value:s}}));if(t.length===0&&o.length===0)return{charts:[],errors:["No valid categorical data found"]};let r=[...o];for(let{title:a,items:s}of t){if(s.length===0){e.push(`"${a}": Array is empty \u2014 skipped`);continue}let i=s.map(p=>ke(p)).filter(p=>typeof p=="object"&&p!==null&&!Array.isArray(p)),c=this.detectChartStructure(i);if(c){let p=this.convertToChartData(i,c);if(p.length===0){e.push(`"${a}": No valid rows after conversion \u2014 skipped`);continue}let d=this.isSimpleCategoricalPie(p)?"pie":"bar";r.push({title:a,type:d,options:{...at,...this.toChartSeries(p,d)}})}else r.push({title:a,type:"table",options:{columns:Array.from(new Set(i.flatMap(p=>Object.keys(p)))),rows:i}})}return e.length>0?{charts:r,errors:e}:{charts:r}}extractArrays(e,t){if(Array.isArray(e)){let o=e.flatMap((a,s)=>Array.isArray(a)?[]:[a]),r=e.flatMap((a,s)=>Array.isArray(a)?this.extractArrays(a,[...t,`[${s}]`]):[]);return[...o.length?[{title:t.length?t.join("."):"Root Data",items:o}]:[],...r]}return e&&typeof e=="object"?Object.entries(e).flatMap(([o,r])=>this.extractArrays(r,[...t,o])):[]}detectChartStructure(e){if(e.length===0)return null;let t=new Set;for(let s of e)for(let i of Object.keys(s))t.add(i);let o=Array.from(t),r=o.filter(s=>typeof e[0]?.[s]=="string"),a=o.filter(s=>typeof e[0]?.[s]=="number");return a.length===0||r.length>1?null:{labelKey:r[0]??"__auto__",valueKeys:a}}isSimpleCategoricalPie(e){return e.length?e.every(t=>t.values.length===1):!1}convertToChartData(e,t){return e.map((o,r)=>{let a=t.labelKey==="__auto__"?null:o[t.labelKey];return{labelValue:a!=null?String(a):`Item ${r+1}`,labelKey:t.labelKey,values:t.valueKeys.map(i=>({[i]:Number(o[i])||0}))}})}toChartSeries(e,t){if(t==="bar"){let r={};return e.forEach((a,s)=>{a.values.forEach(i=>{let[c,p]=Object.entries(i)[0];r[c]||(r[c]=new Array(e.length).fill(0)),r[c][s]=p})}),{xAxis:{type:"category",data:e.map(a=>a.labelValue).filter(Boolean)},yAxis:{type:"value"},series:Object.entries(r).map(([a,s])=>({name:a,type:"bar",stack:"total",data:s}))}}let o=Object.keys(e[0]?.values?.[0]??{})[0]??"value";return{tooltip:{trigger:"item"},series:[{name:"Data",type:"pie",radius:["40%","70%"],label:{show:!1},labelLine:{show:!1},avoidLabelOverlap:!1,data:e.map(r=>({name:r.labelValue,value:r.values[0]?.[o]??0}))}]}}};var Ce=!1;function it(){Ce||(M.ModuleRegistry.registerModules([M.AllCommunityModule]),Ce=!0)}var st=M.themeQuartz.withPart(M.colorSchemeVariable).withParams({fontFamily:"var(--font-body)",headerFontFamily:"var(--font-body)",borderColor:"var(--border)",backgroundColor:"var(--background)",foregroundColor:"var(--foreground)",headerTextColor:"var(--foreground)",headerBackgroundColor:"var(--card)",rowVerticalPaddingScale:1.4,headerColumnResizeHandleColor:"var(--secondary)",wrapperBorderRadius:2});function lt(n){if(typeof n!="string")return!1;try{return JSON.parse(n),!0}catch{return!1}}function dt(n,e){return n<=1||e==="table"?1:e==="card"?Math.min(n,4):2}function ct(n,e){return e===1||n==="table"?"1 / -1":"span 1"}function pt(n){let e=document.createElement("div");e.style.cssText=`
|
|
1053
|
+
background: var(--card);
|
|
1054
|
+
border-radius: var(--radius-md);
|
|
1055
|
+
padding: 1rem 1.25rem;
|
|
1056
|
+
display: flex;
|
|
1057
|
+
flex-direction: column;
|
|
1058
|
+
gap: 0.5rem;
|
|
1059
|
+
height: 6rem;
|
|
1060
|
+
justify-content: center;
|
|
1061
|
+
`;let t=document.createElement("span");t.style.cssText="font-size: 0.875rem; font-weight: 500; color: var(--foreground); text-transform: capitalize;",t.textContent=String(n.title??"").replace(/_/g," ").replace(/\./g," ");let o=document.createElement("span");o.style.cssText="font-size: 1.25rem; font-weight: 700; color: var(--foreground); line-height: 1.2;";let r=n.value;return typeof r=="number"&&Number.isFinite(r)&&!Number.isInteger(r)?o.textContent=String(Number.parseFloat(r.toFixed(4))):o.textContent=String(r??"\u2014"),e.appendChild(t),e.appendChild(o),e}function ht(n){it();let e=document.createElement("div");e.style.cssText="width: 100%; height: 400px;";let t={theme:st,rowData:n.rows,columnDefs:(n.columns??[]).map(r=>({headerName:r,field:r})),pagination:!0,paginationPageSize:50,animateRows:!0},o=()=>{e.__bdbGridInitialized||(e.__bdbGridInitialized=!0,(0,M.createGrid)(e,t))};return requestAnimationFrame(()=>{if(e.isConnected)o();else{let r=new MutationObserver(()=>{e.isConnected&&(r.disconnect(),o())});r.observe(document.body,{childList:!0,subtree:!0})}}),e}function bt(n,e){let t=document.createElement("div");t.style.cssText=`
|
|
1062
|
+
width: 100%;
|
|
1063
|
+
height: 360px;
|
|
1064
|
+
`;let o=null,r=()=>{if(o)return;o=Te.init(t,"dark-bold",{renderer:"canvas"}),o.setOption(n,!0),new ResizeObserver(()=>o?.resize()).observe(t)};return requestAnimationFrame(()=>{if(document.contains(t)||t.isConnected)r();else{let a=new MutationObserver(()=>{t.isConnected&&(a.disconnect(),r())});a.observe(document.body,{childList:!0,subtree:!0})}}),t}function Ee(n){let e=document.createElement("div");e.style.cssText="margin-top: 1rem; display: flex; flex-direction: column; gap: 1.25rem;";let t=n;if(lt(n))try{t=JSON.parse(n)}catch{return e}let o=t?.tool_results??[];if(!o.length)return e;let r=o.length;for(let a=0;a<o.length;a++){let s=o[a],i=s?.data;if(!i)continue;let{charts:c}=new q(i).parse();if(!c.length)continue;let p=document.createElement("div");if(p.style.cssText="width: 100%;",s?.tool){let h=document.createElement("h4");h.style.cssText=`
|
|
1065
|
+
font-size: 13px;
|
|
1066
|
+
font-weight: 600;
|
|
1067
|
+
color: var(--foreground);
|
|
1068
|
+
margin: 0 0 0.25rem 0;
|
|
1069
|
+
font-family: var(--font-body);
|
|
1070
|
+
text-transform: capitalize;
|
|
1071
|
+
`,h.textContent=String(s.tool).replace(/_/g," "),p.appendChild(h)}if(s?.description){let h=document.createElement("p");h.style.cssText=`
|
|
1072
|
+
font-size: 12px;
|
|
1073
|
+
color: var(--muted-foreground);
|
|
1074
|
+
margin: 0 0 0.75rem 0;
|
|
1075
|
+
font-family: var(--font-body);
|
|
1076
|
+
line-height: 1.5;
|
|
1077
|
+
`,h.textContent=s.description,p.appendChild(h)}let d=document.createElement("hr");d.style.cssText="border: none; border-top: 1px solid var(--border); margin-bottom: 0.75rem;",p.appendChild(d);let l=dt(r,c[0]?.type),g=document.createElement("div");g.style.cssText=`
|
|
1078
|
+
display: grid;
|
|
1079
|
+
grid-template-columns: repeat(${l}, minmax(0, 1fr));
|
|
1080
|
+
gap: 0.5rem;
|
|
1081
|
+
width: 100%;
|
|
1082
|
+
padding: 1rem 0;
|
|
1083
|
+
`;for(let h=0;h<c.length;h++){let b=c[h],m=document.createElement("div");m.style.gridColumn=ct(b.type,r);let u;switch(b.type){case"card":u=pt(b.options);break;case"table":u=ht(b.options);break;case"bar":case"pie":u=bt(b.options,b.type);break;default:u=document.createElement("div")}m.appendChild(u),g.appendChild(m)}p.appendChild(g),e.appendChild(p)}return e}function Se(n,e="",t={}){for(let o in n){let r=n[o],a=e?`${e}.${o}`:o;typeof r=="object"&&r!==null&&!Array.isArray(r)?Se(r,a,t):(typeof r=="number"||typeof r=="string")&&(t[a]=r)}return t}var R=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1084
|
+
<rect width="14" height="14" x="8" y="8" rx="2" ry="2"/>
|
|
1085
|
+
<path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>
|
|
1086
|
+
</svg>`,gt=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1087
|
+
<circle cx="12" cy="12" r="10"/>
|
|
1088
|
+
<path d="M12 16v-4M12 8h.01"/>
|
|
1089
|
+
</svg>`,mt=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1090
|
+
<circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/>
|
|
1091
|
+
</svg>`,ut=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1092
|
+
<path d="M20 6 9 17l-5-5"/>
|
|
1093
|
+
</svg>`,ft=`
|
|
1094
|
+
display: inline-flex;
|
|
1095
|
+
align-items: center;
|
|
1096
|
+
justify-content: center;
|
|
1097
|
+
width: 30px;
|
|
1098
|
+
height: 30px;
|
|
1099
|
+
border-radius: var(--radius-md);
|
|
1100
|
+
border: 1px solid var(--border);
|
|
1101
|
+
background: var(--card);
|
|
1102
|
+
color: var(--muted-foreground);
|
|
1103
|
+
cursor: pointer;
|
|
1104
|
+
transition: background 0.15s, color 0.15s, border-color 0.15s;
|
|
1105
|
+
flex-shrink: 0;
|
|
1106
|
+
`;function N(n,e){let t=document.createElement("button");return t.setAttribute("aria-label",e),t.style.cssText=ft,t.innerHTML=n,t.addEventListener("mouseenter",()=>{t.style.background="color-mix(in oklab, var(--foreground) 7%, transparent)",t.style.color="var(--foreground)",t.style.borderColor="var(--ring)"}),t.addEventListener("mouseleave",()=>{t.style.background="var(--card)",t.style.color="var(--muted-foreground)",t.style.borderColor="var(--border)"}),t}function yt(n,e){let t=document.querySelector(".bdb-usage-dropdown");if(t){t.remove();return}let o=document.createElement("div");o.className="bdb-usage-dropdown",o.style.cssText=`
|
|
1107
|
+
position: absolute;
|
|
1108
|
+
bottom: calc(100% + 6px);
|
|
1109
|
+
right: 0;
|
|
1110
|
+
min-width: 220px;
|
|
1111
|
+
background: var(--card);
|
|
1112
|
+
border: 1px solid var(--border);
|
|
1113
|
+
border-radius: var(--radius-md);
|
|
1114
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.35);
|
|
1115
|
+
z-index: 100;
|
|
1116
|
+
overflow: hidden;
|
|
1117
|
+
animation: bdb-fade-in 0.12s ease;
|
|
1118
|
+
`;let r=document.createElement("div");r.style.cssText=`
|
|
1119
|
+
font-size: 11px;
|
|
1120
|
+
font-weight: 600;
|
|
1121
|
+
color: var(--muted-foreground);
|
|
1122
|
+
padding: 0.5rem 0.75rem 0.375rem;
|
|
1123
|
+
letter-spacing: 0.05em;
|
|
1124
|
+
text-transform: uppercase;
|
|
1125
|
+
border-bottom: 1px solid var(--border);
|
|
1126
|
+
`,r.textContent="Usage Stats",o.appendChild(r);let a=document.createElement("div");a.style.cssText="padding: 0.25rem 0;";for(let[c,p]of Object.entries(e)){let d=document.createElement("div");d.style.cssText=`
|
|
1127
|
+
display: flex;
|
|
1128
|
+
align-items: center;
|
|
1129
|
+
justify-content: space-between;
|
|
1130
|
+
gap: 0.5rem;
|
|
1131
|
+
padding: 0.3rem 0.75rem;
|
|
1132
|
+
font-size: 12px;
|
|
1133
|
+
color: var(--foreground);
|
|
1134
|
+
`,d.addEventListener("mouseenter",()=>{d.style.background="color-mix(in oklab, var(--foreground) 5%, transparent)"}),d.addEventListener("mouseleave",()=>{d.style.background="transparent"});let l=document.createElement("span");l.style.cssText="color: var(--muted-foreground); text-transform: capitalize;",l.textContent=c.split(".").pop()?.replace(/_/g," ")??c;let g=document.createElement("span");g.style.cssText="font-weight: 500; font-variant-numeric: tabular-nums;",g.textContent=String(p),d.appendChild(l),d.appendChild(g),a.appendChild(d)}o.appendChild(a);let s=n.parentElement;s.style.position="relative",s.appendChild(o);let i=c=>{!o.contains(c.target)&&c.target!==n&&(o.remove(),document.removeEventListener("click",i,!0))};setTimeout(()=>document.addEventListener("click",i,!0),0)}function vt(n){return n<1e3?`${n}ms`:`${(n/1e3).toFixed(1)}s`}var xt=`<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
1135
|
+
<circle cx="12" cy="12" r="10"/>
|
|
1136
|
+
<path d="M12 6v6l4 2"/>
|
|
1137
|
+
</svg>`;function Le(n){let{textToCopy:e,queryTimeMs:t,usageData:o,onInfo:r}=n,a=document.createElement("div");a.style.cssText=`
|
|
1138
|
+
display: flex;
|
|
1139
|
+
align-items: center;
|
|
1140
|
+
justify-content: space-between;
|
|
1141
|
+
gap: 0.5rem;
|
|
1142
|
+
padding: 0.375rem 0;
|
|
1143
|
+
min-height: 38px;
|
|
1144
|
+
`;let s=document.createElement("div");s.style.cssText="display: flex; align-items: center; gap: 6px;";let i=N(R,"Copy to clipboard");if(i.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),i.innerHTML=ut,i.style.color="var(--primary)",i.style.borderColor="var(--primary)",setTimeout(()=>{i.innerHTML=R,i.style.color="",i.style.borderColor=""},2e3)}catch{}}),s.appendChild(i),r){let c=N(gt,"View response context");c.addEventListener("click",()=>r()),s.appendChild(c)}if(typeof t=="number"&&Number.isFinite(t)){let c=document.createElement("span");c.style.cssText="display: inline-flex; align-items: center; gap: 4px; padding-inline: 4px; font-size: 11px; color: var(--muted-foreground); user-select: none;";let p=document.createElement("span");p.innerHTML=xt,p.style.display="inline-flex";let d=document.createElement("span");d.textContent=`Thought for ${vt(t)}`,c.appendChild(p),c.appendChild(d),s.appendChild(c)}if(a.appendChild(s),o&&typeof o=="object"){let c=Se(o);if(Object.keys(c).length>0){let p=document.createElement("div");p.style.cssText="display: flex; align-items: center; position: relative;";let d=N(mt,"Show usage stats");d.addEventListener("click",l=>{l.stopPropagation(),yt(d,c)}),p.appendChild(d),a.appendChild(p)}}return a}var je=!1;function wt(n){if(je)return;je=!0;let e=document.createElement("style");e.textContent=`
|
|
1145
|
+
@keyframes bdb-drawer-in {
|
|
1146
|
+
from { transform: translateX(100%); opacity: 0; }
|
|
1147
|
+
to { transform: translateX(0); opacity: 1; }
|
|
1148
|
+
}
|
|
1149
|
+
@keyframes bdb-drawer-out {
|
|
1150
|
+
from { transform: translateX(0); opacity: 1; }
|
|
1151
|
+
to { transform: translateX(100%); opacity: 0; }
|
|
1152
|
+
}
|
|
1153
|
+
@keyframes bdb-fade-in {
|
|
1154
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
1155
|
+
to { opacity: 1; transform: translateY(0); }
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
.bdb-drawer-overlay {
|
|
1159
|
+
position: fixed;
|
|
1160
|
+
inset: 0;
|
|
1161
|
+
background: rgba(0,0,0,0.45);
|
|
1162
|
+
z-index: 1000000;
|
|
1163
|
+
backdrop-filter: blur(2px);
|
|
1164
|
+
animation: bdb-fade-in 0.18s ease;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
.bdb-drawer-panel {
|
|
1168
|
+
position: fixed;
|
|
1169
|
+
top: 0;
|
|
1170
|
+
right: 0;
|
|
1171
|
+
bottom: 0;
|
|
1172
|
+
width: min(520px, 100vw);
|
|
1173
|
+
background: var(--background);
|
|
1174
|
+
border-left: 1px solid var(--border);
|
|
1175
|
+
z-index: 1000001;
|
|
1176
|
+
display: flex;
|
|
1177
|
+
flex-direction: column;
|
|
1178
|
+
overflow: hidden;
|
|
1179
|
+
animation: bdb-drawer-in 0.22s cubic-bezier(0.32, 0.72, 0, 1) both;
|
|
1180
|
+
font-family: var(--font-body);
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
.bdb-drawer-header {
|
|
1184
|
+
display: flex;
|
|
1185
|
+
align-items: center;
|
|
1186
|
+
justify-content: space-between;
|
|
1187
|
+
padding: 0 1.25rem;
|
|
1188
|
+
height: 3.25rem;
|
|
1189
|
+
flex-shrink: 0;
|
|
1190
|
+
border-bottom: 1px solid var(--border);
|
|
1191
|
+
background: var(--card);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
.bdb-drawer-title {
|
|
1195
|
+
font-size: 14px;
|
|
1196
|
+
font-weight: 600;
|
|
1197
|
+
color: var(--foreground);
|
|
1198
|
+
margin: 0;
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
.bdb-drawer-close {
|
|
1202
|
+
display: flex;
|
|
1203
|
+
align-items: center;
|
|
1204
|
+
justify-content: center;
|
|
1205
|
+
width: 28px;
|
|
1206
|
+
height: 28px;
|
|
1207
|
+
border-radius: var(--radius-md);
|
|
1208
|
+
border: none;
|
|
1209
|
+
background: transparent;
|
|
1210
|
+
color: var(--muted-foreground);
|
|
1211
|
+
cursor: pointer;
|
|
1212
|
+
transition: background 0.15s, color 0.15s;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
.bdb-drawer-close:hover {
|
|
1216
|
+
background: color-mix(in oklab, var(--foreground) 8%, transparent);
|
|
1217
|
+
color: var(--foreground);
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
.bdb-drawer-tabs {
|
|
1221
|
+
display: flex;
|
|
1222
|
+
border-bottom: 1px solid var(--border);
|
|
1223
|
+
flex-shrink: 0;
|
|
1224
|
+
background: var(--card);
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
.bdb-drawer-tab {
|
|
1228
|
+
flex: 1;
|
|
1229
|
+
padding: 0.65rem 0.75rem;
|
|
1230
|
+
font-size: 12px;
|
|
1231
|
+
font-weight: 500;
|
|
1232
|
+
text-align: center;
|
|
1233
|
+
cursor: pointer;
|
|
1234
|
+
border: none;
|
|
1235
|
+
background: transparent;
|
|
1236
|
+
color: var(--muted-foreground);
|
|
1237
|
+
border-bottom: 2px solid transparent;
|
|
1238
|
+
transition: color 0.15s, border-color 0.15s;
|
|
1239
|
+
font-family: var(--font-body);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
.bdb-drawer-tab:hover {
|
|
1243
|
+
color: var(--foreground);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
.bdb-drawer-tab.active {
|
|
1247
|
+
color: var(--foreground);
|
|
1248
|
+
border-bottom-color: var(--primary);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
.bdb-drawer-body {
|
|
1252
|
+
flex: 1;
|
|
1253
|
+
overflow-y: auto;
|
|
1254
|
+
scrollbar-width: thin;
|
|
1255
|
+
scrollbar-color: color-mix(in oklab, var(--foreground) 12%, transparent) transparent;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
.bdb-drawer-tab-content {
|
|
1259
|
+
display: none;
|
|
1260
|
+
padding: 1.25rem;
|
|
1261
|
+
height: 100%;
|
|
1262
|
+
box-sizing: border-box;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
.bdb-drawer-tab-content.active {
|
|
1266
|
+
display: block;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
.bdb-json-pre {
|
|
1270
|
+
background: var(--card);
|
|
1271
|
+
border: 1px solid var(--border);
|
|
1272
|
+
border-radius: var(--radius-md);
|
|
1273
|
+
padding: 1rem;
|
|
1274
|
+
font-family: var(--font-mono, "JetBrains Mono", monospace);
|
|
1275
|
+
font-size: 11.5px;
|
|
1276
|
+
line-height: 1.65;
|
|
1277
|
+
color: var(--foreground);
|
|
1278
|
+
white-space: pre-wrap;
|
|
1279
|
+
word-break: break-all;
|
|
1280
|
+
overflow-x: auto;
|
|
1281
|
+
margin: 0;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/* Simple JSON syntax coloring */
|
|
1285
|
+
.bdb-json-pre .json-key { color: #88aece; }
|
|
1286
|
+
.bdb-json-pre .json-str { color: #b5bd68; }
|
|
1287
|
+
.bdb-json-pre .json-num { color: #f08d49; }
|
|
1288
|
+
.bdb-json-pre .json-bool { color: #c59bc1; }
|
|
1289
|
+
.bdb-json-pre .json-null { color: #de7176; }
|
|
1290
|
+
`,n.appendChild?n.appendChild(e):document.head.appendChild(e)}function kt(n){return JSON.stringify(n,null,2).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+-]?\d+)?)/g,t=>{let o="json-num";return/^"/.test(t)?o=/:$/.test(t)?"json-key":"json-str":/true|false/.test(t)?o="json-bool":/null/.test(t)&&(o="json-null"),`<span class="${o}">${t}</span>`})}function Ct(n,e,t){n.forEach(o=>o.classList.toggle("active",o.dataset.tab===t)),e.forEach(o=>o.classList.toggle("active",o.dataset.content===t))}function Me(n){let{item:e,indexName:t,shadowRoot:o,onClose:r}=n;wt(o);let a=document.createElement("div");a.style.cssText="position: fixed; inset: 0; z-index: 1000000;";let s=document.createElement("div");s.className="bdb-drawer-overlay",s.addEventListener("click",v),a.appendChild(s);let i=document.createElement("div");i.className="bdb-drawer-panel",a.appendChild(i);let c=document.createElement("div");c.className="bdb-drawer-header";let p=document.createElement("h3");p.className="bdb-drawer-title",p.textContent="Response Details";let d=document.createElement("button");d.className="bdb-drawer-close",d.setAttribute("aria-label","Close drawer"),d.innerHTML=`<svg width="14" height="14" viewBox="0 0 14 14" fill="none">
|
|
1291
|
+
<path d="M1 1l12 12M13 1L1 13" stroke="currentColor" stroke-width="1.75" stroke-linecap="round"/>
|
|
1292
|
+
</svg>`,d.addEventListener("click",v),c.appendChild(p),c.appendChild(d),i.appendChild(c);let l=document.createElement("div");l.className="bdb-drawer-tabs",[{id:"response",label:"Response"},{id:"json",label:"Response JSON"}].forEach(({id:f,label:x})=>{let E=document.createElement("button");E.className="bdb-drawer-tab"+(f==="response"?" active":""),E.dataset.tab=f,E.textContent=x,E.addEventListener("click",()=>{let L=i.querySelectorAll(".bdb-drawer-tab"),j=i.querySelectorAll(".bdb-drawer-tab-content");Ct(L,j,f)}),l.appendChild(E)}),i.appendChild(l);let h=document.createElement("div");h.className="bdb-drawer-body",i.appendChild(h);let b=document.createElement("div");if(b.className="bdb-drawer-tab-content active",b.dataset.content="response",e?.query){let f=document.createElement("div");f.style.cssText=`
|
|
1293
|
+
display: flex;
|
|
1294
|
+
justify-content: flex-end;
|
|
1295
|
+
margin-bottom: 1rem;
|
|
1296
|
+
`;let x=document.createElement("div");x.style.cssText=`
|
|
1297
|
+
max-width: 80%;
|
|
1298
|
+
background: var(--secondary);
|
|
1299
|
+
color: var(--secondary-foreground);
|
|
1300
|
+
border-radius: 18px 18px 4px 18px;
|
|
1301
|
+
padding: 0.6rem 1rem;
|
|
1302
|
+
font-size: 13px;
|
|
1303
|
+
line-height: 1.55;
|
|
1304
|
+
word-break: break-word;
|
|
1305
|
+
`,x.textContent=e.query,f.appendChild(x),b.appendChild(f)}let m=new S(e),{messages:u}=m.parse(),y=u.map(f=>f.output??"").join(`
|
|
1306
|
+
|
|
1307
|
+
`);if(y){let f=document.createElement("div");f.className="bdb-ai-bubble ai-md prose",f.style.cssText="font-size: 13px; line-height: 1.65; color: var(--foreground);",f.innerHTML=$(y),b.appendChild(f)}h.appendChild(b);let w=document.createElement("div");w.className="bdb-drawer-tab-content",w.dataset.content="json";let k=document.createElement("pre");k.className="bdb-json-pre",k.innerHTML=kt(e),w.appendChild(k),h.appendChild(w);function v(){i.style.animation="bdb-drawer-out 0.18s ease-in both",s.style.opacity="0",s.style.transition="opacity 0.18s",setTimeout(()=>{a.remove(),r()},180)}let C=f=>{f.key==="Escape"&&(v(),document.removeEventListener("keydown",C))};return document.addEventListener("keydown",C),a}var ze=require("jspdf"),Ae=A(require("jspdf-autotable")),Ie=A(require("echarts"));function J(n,e){let t=URL.createObjectURL(n),o=document.createElement("a");o.href=t,o.download=e,document.body.appendChild(o),o.click(),setTimeout(()=>{document.body.removeChild(o),URL.revokeObjectURL(t)},100)}function qe(n){let{messages:e}=new S(n).parse();return e.map(t=>t.output).filter(Boolean).join(`
|
|
1308
|
+
|
|
1309
|
+
`)}function He(n,e){let t=`# ${e}
|
|
1310
|
+
|
|
1311
|
+
`;t+=`*Exported on ${new Date().toLocaleString()}*
|
|
1312
|
+
|
|
1313
|
+
`,t+=`---
|
|
1314
|
+
|
|
1315
|
+
`;for(let r of n){r.query&&(t+=`**User:**
|
|
1316
|
+
${r.query}
|
|
1317
|
+
|
|
1318
|
+
`);let a=qe(r);a&&(t+=`**AI:**
|
|
1319
|
+
${a}
|
|
1320
|
+
|
|
1321
|
+
`)}let o=new Blob([t],{type:"text/markdown"});J(o,`chat-${new Date().toISOString().split("T")[0]}.md`)}function Oe(n){let e=new Blob([JSON.stringify(n,null,2)],{type:"application/json"});J(e,`chat-${new Date().toISOString().split("T")[0]}.json`)}function Tt(n){let e=n?._data??n?.a?._data;if(!e)return[];let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return[]}let o=t?.tool_results??[];if(!o.length)return[];let r=[];for(let a of o){if(!a?.data)continue;let{charts:s}=new q(a.data).parse();for(let i of s)r.push({...i,title:a.tool?String(a.tool).replace(/_/g," "):i.title})}return r}function Et(n,e=800,t=480){let o=document.createElement("div");o.style.cssText=`position: fixed; left: -10000px; top: 0; width: ${e}px; height: ${t}px;`,document.body.appendChild(o);try{let r=Ie.init(o,null,{renderer:"canvas",width:e,height:t}),a={...n,backgroundColor:"#ffffff",animation:!1,toolbox:{show:!1}};r.setOption(a,!0);let s=r.getDataURL({type:"png",pixelRatio:2,backgroundColor:"#ffffff"});return r.dispose(),s}catch(r){return console.error("[BangDB] chart render failed:",r),null}finally{document.body.removeChild(o)}}function De(n,e){try{let t=new ze.jsPDF,o=t.internal.pageSize.height,r=t.internal.pageSize.width,a=14,s=r-a*2,i=20,c=(d=10)=>{i>o-a-d&&(t.addPage(),i=a+10)};t.setFontSize(18),t.setFont("helvetica","bold"),t.setTextColor(0,0,0),t.text(e,a,i),i+=8,t.setFontSize(10),t.setFont("helvetica","normal"),t.setTextColor(100,100,100),t.text(`Exported on ${new Date().toLocaleString()}`,a,i),i+=8,t.setDrawColor(180,180,180),t.setLineWidth(.4),t.line(a,i,a+s,i),i+=8;for(let d of n){if(d.query){c(20),t.setFontSize(11),t.setFont("helvetica","bold"),t.setTextColor(60,130,100),t.text("You:",a,i),i+=6,t.setFont("helvetica","normal"),t.setTextColor(30,30,30);let h=t.splitTextToSize(d.query,s-4);for(let b of h)c(),t.text(b,a+4,i),i+=5.5;i+=4}let l=qe(d);if(l){c(20),t.setFontSize(11),t.setFont("helvetica","bold"),t.setTextColor(80,80,200),t.text("AI:",a,i),i+=6,t.setFont("helvetica","normal"),t.setTextColor(30,30,30);let h=l.replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/#{1,6}\s/g,"").replace(/\[([^\]]+)\]\([^)]+\)/g,"$1").replace(/\n{3,}/g,`
|
|
1322
|
+
|
|
1323
|
+
`),b=t.splitTextToSize(h,s-4);for(let m of b)c(),t.text(m,a+4,i),i+=5.5;i+=4}let g=Tt(d);if(g.length>0){i+=2;for(let h of g)if(c(30),h.title&&(t.setFontSize(10),t.setFont("helvetica","bold"),t.setTextColor(60,60,60),t.text(String(h.title).replace(/_/g," ").replace(/\./g," "),a+4,i),i+=5),h.type==="card"){let b=h.options;t.setFontSize(10),t.setFont("helvetica","normal"),t.setTextColor(80,80,80);let m=String(b.title??"").replace(/_/g," "),u,y=b.value;typeof y=="number"&&Number.isFinite(y)&&!Number.isInteger(y)?u=String(Number.parseFloat(y.toFixed(4))):u=String(y??"\u2014"),t.text(`${m}: `,a+4,i),t.setFont("helvetica","bold"),t.setTextColor(30,30,30);let w=t.getTextWidth(`${m}: `);t.text(u,a+4+w,i),i+=7}else if(h.type==="table"){let b=h.options,m=b.columns??[],u=(b.rows??[]).map(w=>m.map(k=>{let v=w[k];return v==null?"":typeof v=="object"?JSON.stringify(v):String(v)}));(0,Ae.default)(t,{startY:i,head:[m],body:u,margin:{left:a+4,right:a},styles:{fontSize:8,cellPadding:2},headStyles:{fillColor:[240,240,240],textColor:[40,40,40],fontStyle:"bold"},theme:"grid"}),i=(t.lastAutoTable?.finalY??i)+6}else if(h.type==="bar"||h.type==="pie"){let b=s-4,m=b*.6;c(m+10);let u=Et(h.options,800,480);if(u)try{t.addImage(u,"PNG",a+4,i,b,m),i+=m+6}catch(y){console.error("[BangDB] addImage failed:",y)}}}c(5),t.setDrawColor(220,220,220),t.setLineWidth(.2),t.line(a,i,a+s,i),i+=6}let p=t.output("blob");J(p,`chat-${new Date().toISOString().split("T")[0]}.pdf`)}catch(t){console.error("[BangDB] PDF export failed:",t)}}var B=class B{constructor(e){this.font={body:'"Inter", sans-serif',mono:'"JetBrains Mono", monospace'};this.tools=[];this.TOKENS={background:"oklch(0.2223 0.0060 271.1393)",foreground:"oklch(0.9551 0 0)",card:"oklch(0.2568 0.0076 274.6528)",cardForeground:"oklch(0.9551 0 0)",primary:"oklch(0.611 0.1217 157.75)",primaryForeground:"oklch(0.9491 0 0)",secondary:"oklch(0.2940 0.0130 272.9312)",secondaryForeground:"oklch(0.9551 0 0)",muted:"oklch(0.2940 0.0130 272.9312)",mutedForeground:"oklch(0.7058 0 0)",accent:"oklch(0.2795 0.0368 260.0310)",accentForeground:"oklch(0.7857 0.1153 246.6596)",border:"oklch(0.3289 0.0092 268.3843)",input:"oklch(0.3289 0.0092 268.3843)",ring:"oklch(0.611 0.1217 157.75)",radius:"0.5rem",shadowPanel:"0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06)",shadowBubble:"0 8px 32px color-mix(in oklab, oklch(0.611 0.1217 157.75) 40%, transparent)",shadowInput:"0 0 0 2px color-mix(in oklab, oklch(0.611 0.1217 157.75) 50%, transparent)"};this.store=me;this.apiConfig=null;this.bubbleEl=null;this.chatUIEl=null;this.chatAreaEl=null;this.renderedMessageIds=new Set;this.chatTitle="Chat with AI";this.logoUrl="";e.colorTokens&&(this.TOKENS={...this.TOKENS,...e.colorTokens}),e.title&&(this.chatTitle=e.title),e.logo&&(this.logoUrl=e.logo);let t=e.tools||B.DEFAULT_TOOLS,o=new Set(B.DEFAULT_TOOLS.map(r=>r.id));this.tools=t.filter(r=>o.has(r.id)).map(r=>({id:r.id,name:r.name})),this.apiConfig=e.config,this.container=document.createElement("div"),this.container.id="ai-chat-widget-root",document.body.appendChild(this.container),this.root=this.container.attachShadow({mode:"open"}),this.injectGlobalFonts(),this.injectThemeVars(),this.root,this.init().then(()=>{this.mount(),this.store.subscribe(()=>{let r=this.store.getState(),a=r?.chat?.mode,{chatData:s,streamingMessage:i,isLoading:c}=r?.chatSessions?.[r?.chat?.activeSession]??{};this.handleModeChange(a),this.handleChatDataChange({streamingMessage:i,chatData:s,isLoading:c})})})}injectThemeVars(){let e=this.TOKENS,t=document.createElement("style");t.textContent=`
|
|
1053
1324
|
:host {
|
|
1054
1325
|
--background: ${e.background};
|
|
1055
1326
|
--foreground: ${e.foreground};
|
|
@@ -1078,13 +1349,16 @@ code.hljs {
|
|
|
1078
1349
|
--font-body: ${this.font.body};
|
|
1079
1350
|
--font-mono: ${this.font.mono};
|
|
1080
1351
|
}
|
|
1081
|
-
`,this.root.appendChild(t)}injectGlobalFonts(){let e="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800",t=document.createElement("link");t.rel="preconnect",t.href="https://fonts.googleapis.com";let
|
|
1352
|
+
`,this.root.appendChild(t)}injectGlobalFonts(){let e="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=JetBrains+Mono:ital,wght@0,100..800;1,100..800",t=document.createElement("link");t.rel="preconnect",t.href="https://fonts.googleapis.com";let o=document.createElement("link");o.rel="preconnect",o.href="https://fonts.gstatic.com",o.crossOrigin="";let r=document.createElement("link");r.type="text/css",r.rel="stylesheet",r.href=e,this.root.appendChild(t),this.root.appendChild(o),this.root.appendChild(r),document.head.appendChild(t),document.head.appendChild(o),document.head.appendChild(r)}mount(){let e=this.createChatBubble();this.root.appendChild(e),this.bubbleEl=e}async init(){await this.store.dispatch(he({indexName:this.apiConfig?.indexName}))}handleChatDataChange({chatData:e,streamingMessage:t,isLoading:o}){if(!this.chatAreaEl)return;e||(e=[]);let r=this.chatAreaEl.querySelector(".chat-data-container"),a=this.chatAreaEl.querySelector("#bangdb-chat-area"),s=this.chatAreaEl.querySelector("#bdb-empty-state"),i=()=>{requestAnimationFrame(()=>{a.scrollTo({top:a.scrollHeight,behavior:"smooth"})})},c=e.length>0||!!t?.query;s.style.display=c?"none":"flex";for(let b=0;b<e.length;b++){let m=e[b],u=`msg-${b}`;if(m?.query&&!this.renderedMessageIds.has(u)){this.renderedMessageIds.add(u),r.insertBefore(this.userRequestMessage(m.query),r.querySelector("#chat-window-anchor"));let y=new S(m),{messages:w}=y.parse();w?.length>0&&r.insertBefore(this.aiResponseMessage(m),r.querySelector("#chat-window-anchor")),i()}}let p="bdb-streaming-msg",d=this.root.querySelector(`#${p}`);if(t?.query){d||(d=document.createElement("div"),d.id=p,r.insertBefore(d,r.querySelector("#chat-window-anchor")),d.appendChild(this.userRequestMessage(t.query)),d.style.minHeight=`${a.clientHeight*.8}px`);let b=d.querySelector(".bdb-streaming-ai-area"),m=t.output?.output??"";if(o&&!m&&!b)b=document.createElement("div"),b.className="bdb-streaming-ai-area",b.appendChild(this.loadingIndicator()),d.appendChild(b);else if(m){b||(b=document.createElement("div"),b.className="bdb-streaming-ai-area",d.appendChild(b));let u=b.querySelector(".ai-md");u?u.innerHTML=$(m):(b.innerHTML="",b.appendChild(this.aiResponseMessage(t)))}s.style.display="none",i()}else d&&(d.style.minHeight="0",d.remove());let l=this.chatAreaEl.querySelector(".bdb-textarea"),g=this.chatAreaEl.querySelector(".bdb-send-btn"),h=this.chatAreaEl.querySelector(".bdb-tools-trigger");l&&(l.style.opacity="1"),g&&(g.disabled=!!o||!l?.value.trim()),h&&(h.disabled=!!o,h.style.opacity=o?"0.5":"1",h.style.pointerEvents=o?"none":"auto")}handleModeChange(e){let t=this.bubbleEl?.querySelector(".chat-bubble");if(t)switch(e){case 0:if(t.classList.remove("is-open"),t.setAttribute("aria-label","Open chat"),this.chatUIEl){let r=this.chatUIEl.querySelector(".bdb-chat-panel");r&&(r.style.animation="bdb-panel-out 0.18s ease-in both",r&&(r.style.animation="bdb-panel-out 0.18s ease-in both"),setTimeout(()=>{this.chatUIEl&&(this.chatUIEl.style.display="none")},180))}break;case 1:if(t.setAttribute("aria-label","Close chat"),!this.chatUIEl)this.chatUIEl=this.createChatUI(),this.bubbleEl?.appendChild(this.chatUIEl);else{this.chatUIEl.style.display="";let r=this.chatUIEl.querySelector(".bdb-chat-panel");r&&(r.style.animation="bdb-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both")}t.classList.add("is-open"),this.chatUIEl?.querySelector(".bdb-chat-panel")?.classList.remove("is-fullscreen"),requestAnimationFrame(()=>this.updatePanelPosition());break;case 2:if(t.setAttribute("aria-label","Close chat"),!this.chatUIEl)this.chatUIEl=this.createChatUI(),this.bubbleEl?.appendChild(this.chatUIEl);else{this.chatUIEl.style.display="";let r=this.chatUIEl.querySelector(".bdb-chat-panel");r&&(r.style.animation="bdb-panel-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both")}t.classList.add("is-open");let o=this.chatUIEl?.querySelector(".bdb-chat-panel");o&&(o.classList.add("is-fullscreen"),o.style.top="",o.style.bottom="",o.style.left="",o.style.right="");break}}updatePanelPosition(){if(!this.chatUIEl||!this.bubbleEl)return;let e=this.chatUIEl.querySelector(".bdb-chat-panel");if(!e||e.classList.contains("is-fullscreen"))return;let t=parseInt(this.bubbleEl.style.left)||0,o=parseInt(this.bubbleEl.style.top)||0,r=52,a=52,s=750,i=window.innerWidth,c=window.innerHeight,p=12,d=o+a/2;if(d<c/3)e.style.top=a+p+"px",e.style.bottom="auto";else if(d>2*c/3)e.style.bottom=a+p+"px",e.style.top="auto";else{let l=d-s/2,g=Math.max(8,Math.min(l,c-s-8));e.style.top=g-o+"px",e.style.bottom="auto"}t+r/2<i/2?(e.style.left="0",e.style.right="auto"):(e.style.right="0",e.style.left="auto")}createChatBubble(){let e=document.createElement("div");e.classList.add("bdb-bubble-container"),e.innerHTML=`
|
|
1082
1353
|
<style>
|
|
1083
1354
|
.bdb-bubble-container {
|
|
1084
1355
|
position: fixed;
|
|
1085
1356
|
bottom: 1.5rem;
|
|
1086
1357
|
right: 1.5rem;
|
|
1087
1358
|
z-index: 999999;
|
|
1359
|
+
width: 52px;
|
|
1360
|
+
height: 52px;
|
|
1361
|
+
overflow: visible;
|
|
1088
1362
|
}
|
|
1089
1363
|
|
|
1090
1364
|
.chat-bubble::before {
|
|
@@ -1122,24 +1396,15 @@ code.hljs {
|
|
|
1122
1396
|
box-shadow: 0 12px 40px color-mix(in oklab, var(--primary) 50%, transparent);
|
|
1123
1397
|
}
|
|
1124
1398
|
|
|
1125
|
-
.chat-bubble .icon-chat
|
|
1126
|
-
.chat-bubble .icon-close {
|
|
1399
|
+
.chat-bubble .icon-chat {
|
|
1127
1400
|
position: absolute;
|
|
1128
1401
|
transition: transform 0.2s ease, opacity 0.15s ease;
|
|
1129
1402
|
color: var(--primary-foreground);
|
|
1130
1403
|
}
|
|
1131
|
-
.chat-bubble .icon-close {
|
|
1132
|
-
opacity: 0;
|
|
1133
|
-
transform: rotate(-90deg) scale(0.6);
|
|
1134
|
-
}
|
|
1135
1404
|
.chat-bubble.is-open .icon-chat {
|
|
1136
1405
|
opacity: 0;
|
|
1137
1406
|
transform: rotate(90deg) scale(0.6);
|
|
1138
1407
|
}
|
|
1139
|
-
.chat-bubble.is-open .icon-close {
|
|
1140
|
-
opacity: 1;
|
|
1141
|
-
transform: rotate(0deg) scale(1);
|
|
1142
|
-
}
|
|
1143
1408
|
</style>
|
|
1144
1409
|
|
|
1145
1410
|
|
|
@@ -1149,14 +1414,10 @@ code.hljs {
|
|
|
1149
1414
|
<path d="M28,32 C28,32 23.2863266,30.1450667 19.4727818,28.6592 L3.43749107,28.6592 C1.53921989,28.6592 0,27.0272 0,25.0144 L0,3.6448 C0,1.632 1.53921989,0 3.43749107,0 L24.5615088,0 C26.45978,0 27.9989999,1.632 27.9989999,3.6448 L27.9989999,22.0490667 L28,22.0490667 L28,32 Z M23.8614088,20.0181333 C23.5309223,19.6105242 22.9540812,19.5633836 22.5692242,19.9125333 C22.5392199,19.9392 19.5537934,22.5941333 13.9989999,22.5941333 C8.51321617,22.5941333 5.48178311,19.9584 5.4277754,19.9104 C5.04295119,19.5629428 4.46760991,19.6105095 4.13759108,20.0170667 C3.97913051,20.2124916 3.9004494,20.4673395 3.91904357,20.7249415 C3.93763774,20.9825435 4.05196575,21.2215447 4.23660523,21.3888 C4.37862552,21.5168 7.77411059,24.5386667 13.9989999,24.5386667 C20.2248893,24.5386667 23.6203743,21.5168 23.7623946,21.3888 C23.9467342,21.2215726 24.0608642,20.9827905 24.0794539,20.7254507 C24.0980436,20.4681109 24.0195551,20.2135019 23.8614088,20.0181333 Z"/>
|
|
1150
1415
|
</svg>
|
|
1151
1416
|
</span>
|
|
1152
|
-
|
|
1153
|
-
<svg width="18" height="18" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1154
|
-
<path d="M1 1l12 12M13 1L1 13" stroke="white" stroke-width="2" stroke-linecap="round"/>
|
|
1155
|
-
</svg>
|
|
1156
|
-
</span>
|
|
1417
|
+
|
|
1157
1418
|
</button>
|
|
1158
|
-
`,e.
|
|
1159
|
-
<style>
|
|
1419
|
+
`,e.addEventListener("click",()=>{if(e._didDrag)return;let{chat:t}=this.store.getState();t?.mode===0&&this.store.dispatch(I(1))});{let t=!1,o=0,r=0,a=0,s=0,i=window.innerWidth-24-52,c=window.innerHeight-24-52;try{let p=localStorage.getItem("bdb-bubble-position");if(p){let{left:d,top:l}=JSON.parse(p);i=d,c=l}}catch{}e.style.bottom="auto",e.style.right="auto",e.style.left=i+"px",e.style.top=c+"px",e.addEventListener("pointerdown",p=>{t=!0,e._didDrag=!1,o=p.clientX,r=p.clientY,a=i,s=c,e.style.transition="none",e.setPointerCapture(p.pointerId)}),e.addEventListener("pointermove",p=>{if(!t)return;let d=p.clientX-o,l=p.clientY-r;Math.hypot(d,l)>4&&(e._didDrag=!0),i=a+d,c=s+l,e.style.left=i+"px",e.style.top=c+"px"}),e.addEventListener("pointerup",p=>{if(!t||(t=!1,e.releasePointerCapture(p.pointerId),!e._didDrag))return;let d=52,l=52,g=24,h=window.innerWidth,b=window.innerHeight,m=i+d/2,u=c+l/2,y=[{left:g,top:g},{left:(h-d)/2,top:g},{left:h-g-d,top:g},{left:g,top:(b-l)/2},{left:h-g-d,top:(b-l)/2},{left:g,top:b-g-l},{left:(h-d)/2,top:b-g-l},{left:h-g-d,top:b-g-l}],w=y[0],k=1/0;for(let v of y){let C=Math.hypot(v.left+d/2-m,v.top+l/2-u);C<k&&(k=C,w=v)}i=w.left,c=w.top,e.style.transition="left 0.4s cubic-bezier(0.2,0.8,0.2,1), top 0.4s cubic-bezier(0.2,0.8,0.2,1)",e.style.left=i+"px",e.style.top=c+"px";try{localStorage.setItem("bdb-bubble-position",JSON.stringify({left:i,top:c}))}catch{}this.updatePanelPosition()})}return e}createChatUI(){let e=document.createElement("div");e.addEventListener("click",l=>l.stopPropagation()),e.addEventListener("pointerdown",l=>l.stopPropagation()),e.innerHTML=`
|
|
1420
|
+
<style>
|
|
1160
1421
|
.bdb-chat-widget {
|
|
1161
1422
|
display: flex;
|
|
1162
1423
|
flex-direction: column;
|
|
@@ -1173,27 +1434,55 @@ code.hljs {
|
|
|
1173
1434
|
display: flex;
|
|
1174
1435
|
align-items: center;
|
|
1175
1436
|
justify-content: space-between;
|
|
1437
|
+
position: relative;
|
|
1438
|
+
z-index: 20;
|
|
1176
1439
|
padding: 0 1.25rem;
|
|
1177
1440
|
height: 3.25rem;
|
|
1178
1441
|
flex-shrink: 0;
|
|
1179
1442
|
background: var(--card);
|
|
1180
1443
|
border-bottom: 1px solid var(--border);
|
|
1444
|
+
cursor: grab;
|
|
1445
|
+
user-select: none;
|
|
1446
|
+
-webkit-user-select: none;
|
|
1447
|
+
overflow: visible;
|
|
1448
|
+
min-width: 0;
|
|
1449
|
+
box-sizing: border-box;
|
|
1181
1450
|
}
|
|
1182
|
-
|
|
1183
|
-
.bdb-chat-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1451
|
+
|
|
1452
|
+
.bdb-chat-header:active {
|
|
1453
|
+
cursor: grabbing;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/* Don't show grab cursor over interactive controls */
|
|
1457
|
+
.bdb-chat-header button,
|
|
1458
|
+
.bdb-chat-header a,
|
|
1459
|
+
.bdb-chat-header input,
|
|
1460
|
+
.bdb-chat-header select,
|
|
1461
|
+
.bdb-chat-header textarea {
|
|
1462
|
+
cursor: pointer;
|
|
1189
1463
|
}
|
|
1190
1464
|
|
|
1465
|
+
.bdb-chat-panel.is-fullscreen .bdb-chat-header {
|
|
1466
|
+
width: 100%;
|
|
1467
|
+
max-width: 100%;
|
|
1468
|
+
margin: 0;
|
|
1469
|
+
background: transparent;
|
|
1470
|
+
border-bottom: 1px solid var(--border);
|
|
1471
|
+
flex-shrink: 0;
|
|
1472
|
+
box-sizing: border-box;
|
|
1473
|
+
padding: 0 1.25rem;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1191
1476
|
.bdb-chat-title-container {
|
|
1192
1477
|
display: flex;
|
|
1193
1478
|
align-items: center;
|
|
1194
1479
|
gap: 0.25rem;
|
|
1480
|
+
overflow: hidden;
|
|
1481
|
+
min-width: 0;
|
|
1482
|
+
flex: 1;
|
|
1483
|
+
max-width: calc(100% - 150px);
|
|
1195
1484
|
}
|
|
1196
|
-
|
|
1485
|
+
|
|
1197
1486
|
.bdb-chat-title {
|
|
1198
1487
|
font-size: 15px;
|
|
1199
1488
|
font-weight: 600;
|
|
@@ -1201,6 +1490,120 @@ code.hljs {
|
|
|
1201
1490
|
letter-spacing: -0.01em;
|
|
1202
1491
|
color: var(--foreground);
|
|
1203
1492
|
margin: 0;
|
|
1493
|
+
overflow: hidden;
|
|
1494
|
+
text-overflow: ellipsis;
|
|
1495
|
+
white-space: nowrap;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
.bdb-info-tooltip {
|
|
1499
|
+
position: relative;
|
|
1500
|
+
display: inline-flex;
|
|
1501
|
+
align-items: center;
|
|
1502
|
+
flex-shrink: 0;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
.bdb-info-trigger {
|
|
1506
|
+
display: inline-flex;
|
|
1507
|
+
align-items: center;
|
|
1508
|
+
justify-content: center;
|
|
1509
|
+
width: 20px;
|
|
1510
|
+
height: 20px;
|
|
1511
|
+
border-radius: 9999px;
|
|
1512
|
+
color: var(--muted-foreground);
|
|
1513
|
+
border: none;
|
|
1514
|
+
background: transparent;
|
|
1515
|
+
cursor: pointer;
|
|
1516
|
+
padding: 0;
|
|
1517
|
+
transition: background 0.15s, color 0.15s;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
.bdb-info-trigger:hover {
|
|
1521
|
+
background: color-mix(in oklab, var(--foreground) 7%, transparent);
|
|
1522
|
+
color: var(--foreground);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
.bdb-info-trigger:focus-visible {
|
|
1526
|
+
outline: 2px solid color-mix(in oklab, var(--foreground) 30%, transparent);
|
|
1527
|
+
outline-offset: 2px;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
.bdb-info-popover {
|
|
1531
|
+
position: absolute;
|
|
1532
|
+
top: 100%;
|
|
1533
|
+
left: 50%;
|
|
1534
|
+
transform: translateX(-50%);
|
|
1535
|
+
margin-top: 8px;
|
|
1536
|
+
min-width: 220px;
|
|
1537
|
+
max-width: 280px;
|
|
1538
|
+
padding: 10px 12px;
|
|
1539
|
+
border-radius: 12px;
|
|
1540
|
+
background: color-mix(in oklab, var(--card) 92%, black);
|
|
1541
|
+
color: var(--foreground);
|
|
1542
|
+
border: 1px solid color-mix(in oklab, var(--border) 85%, transparent);
|
|
1543
|
+
box-shadow: 0 10px 26px rgba(0,0,0,0.32);
|
|
1544
|
+
z-index: 1001;
|
|
1545
|
+
|
|
1546
|
+
opacity: 0;
|
|
1547
|
+
visibility: hidden;
|
|
1548
|
+
pointer-events: none;
|
|
1549
|
+
transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
.bdb-info-popover::before {
|
|
1553
|
+
content: "";
|
|
1554
|
+
position: absolute;
|
|
1555
|
+
top: -6px;
|
|
1556
|
+
left: 50%;
|
|
1557
|
+
transform: translateX(-50%) rotate(45deg);
|
|
1558
|
+
width: 12px;
|
|
1559
|
+
height: 12px;
|
|
1560
|
+
background: inherit;
|
|
1561
|
+
border-left: 1px solid color-mix(in oklab, var(--border) 85%, transparent);
|
|
1562
|
+
border-top: 1px solid color-mix(in oklab, var(--border) 85%, transparent);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
/* Hover bridge so you can move cursor from icon to popover without it closing */
|
|
1566
|
+
.bdb-info-popover::after {
|
|
1567
|
+
content: "";
|
|
1568
|
+
position: absolute;
|
|
1569
|
+
left: 0;
|
|
1570
|
+
right: 0;
|
|
1571
|
+
top: -12px;
|
|
1572
|
+
height: 12px;
|
|
1573
|
+
background: transparent;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
.bdb-info-tooltip:hover .bdb-info-popover,
|
|
1577
|
+
.bdb-info-tooltip:focus-within .bdb-info-popover {
|
|
1578
|
+
opacity: 1;
|
|
1579
|
+
visibility: visible;
|
|
1580
|
+
pointer-events: auto;
|
|
1581
|
+
transform: translateX(-50%) translateY(2px);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
.bdb-info-popover-title {
|
|
1585
|
+
font-size: 13px;
|
|
1586
|
+
font-weight: 600;
|
|
1587
|
+
margin: 0 0 6px 0;
|
|
1588
|
+
letter-spacing: -0.01em;
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
.bdb-info-popover a {
|
|
1592
|
+
color: var(--primary);
|
|
1593
|
+
text-decoration: none;
|
|
1594
|
+
font-size: 13px;
|
|
1595
|
+
line-height: 1.2;
|
|
1596
|
+
word-break: break-word;
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
.bdb-info-popover a:hover {
|
|
1600
|
+
text-decoration: underline;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
.bdb-info-popover-desc {
|
|
1604
|
+
margin: 0;
|
|
1605
|
+
font-size: 12px;
|
|
1606
|
+
color: var(--muted-foreground);
|
|
1204
1607
|
}
|
|
1205
1608
|
|
|
1206
1609
|
.bdb-header-status {
|
|
@@ -1228,6 +1631,8 @@ code.hljs {
|
|
|
1228
1631
|
display: flex;
|
|
1229
1632
|
align-items: center;
|
|
1230
1633
|
gap: 4px;
|
|
1634
|
+
flex-shrink: 0;
|
|
1635
|
+
flex-wrap: nowrap;
|
|
1231
1636
|
}
|
|
1232
1637
|
|
|
1233
1638
|
.bdb-icon-btn {
|
|
@@ -1249,12 +1654,51 @@ code.hljs {
|
|
|
1249
1654
|
color: var(--foreground);
|
|
1250
1655
|
}
|
|
1251
1656
|
|
|
1657
|
+
.bdb-download-dropdown {
|
|
1658
|
+
position: absolute;
|
|
1659
|
+
top: 100%;
|
|
1660
|
+
right: 0;
|
|
1661
|
+
margin-top: 4px;
|
|
1662
|
+
background: var(--card);
|
|
1663
|
+
border: 1px solid var(--border);
|
|
1664
|
+
border-radius: var(--radius-md);
|
|
1665
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
|
1666
|
+
display: none;
|
|
1667
|
+
flex-direction: column;
|
|
1668
|
+
min-width: 140px;
|
|
1669
|
+
z-index: 1000;
|
|
1670
|
+
padding: 4px;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
.bdb-download-dropdown.show {
|
|
1674
|
+
display: flex;
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
.bdb-dropdown-item {
|
|
1678
|
+
display: flex;
|
|
1679
|
+
align-items: center;
|
|
1680
|
+
gap: 8px;
|
|
1681
|
+
padding: 8px 12px;
|
|
1682
|
+
border: none;
|
|
1683
|
+
background: transparent;
|
|
1684
|
+
color: var(--foreground);
|
|
1685
|
+
font-size: 13px;
|
|
1686
|
+
cursor: pointer;
|
|
1687
|
+
border-radius: var(--radius-sm);
|
|
1688
|
+
text-align: left;
|
|
1689
|
+
font-family: inherit;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
.bdb-dropdown-item:hover {
|
|
1693
|
+
background: var(--secondary);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1252
1696
|
.bdb-chat-panel {
|
|
1253
1697
|
display: flex;
|
|
1254
1698
|
flex-direction: column;
|
|
1255
|
-
position:
|
|
1256
|
-
bottom:
|
|
1257
|
-
right:
|
|
1699
|
+
position: absolute;
|
|
1700
|
+
bottom: 68px;
|
|
1701
|
+
right: 0;
|
|
1258
1702
|
width: 500px;
|
|
1259
1703
|
height: 750px;
|
|
1260
1704
|
background: var(--background);
|
|
@@ -1273,26 +1717,35 @@ code.hljs {
|
|
|
1273
1717
|
}
|
|
1274
1718
|
|
|
1275
1719
|
.bdb-chat-panel.is-fullscreen {
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1720
|
+
position: fixed !important;
|
|
1721
|
+
inset: 0 !important;
|
|
1722
|
+
top: 0 !important;
|
|
1723
|
+
left: 0 !important;
|
|
1724
|
+
right: 0 !important;
|
|
1725
|
+
bottom: 0 !important;
|
|
1726
|
+
width: 100% !important;
|
|
1727
|
+
height: 100% !important;
|
|
1728
|
+
border-radius: 0 !important;
|
|
1729
|
+
display: flex !important;
|
|
1730
|
+
align-items: center !important;
|
|
1731
|
+
justify-content: center !important;
|
|
1732
|
+
background: color-mix(in oklab, var(--card) 55%, transparent) !important;
|
|
1733
|
+
backdrop-filter: blur(2px) !important;
|
|
1734
|
+
transform: none !important;
|
|
1735
|
+
margin: 0 !important;
|
|
1736
|
+
overflow: hidden !important;
|
|
1737
|
+
z-index: 999998 !important;
|
|
1288
1738
|
}
|
|
1289
|
-
|
|
1739
|
+
|
|
1290
1740
|
.bdb-chat-panel.is-fullscreen .bdb-chat-widget {
|
|
1291
|
-
width:
|
|
1292
|
-
height:
|
|
1741
|
+
width: 90%;
|
|
1742
|
+
height: 90%;
|
|
1293
1743
|
border-radius: var(--radius-lg);
|
|
1294
1744
|
box-shadow: var(--shadow-panel);
|
|
1295
1745
|
border: 1px solid var(--border);
|
|
1746
|
+
display: flex !important;
|
|
1747
|
+
flex-direction: column !important;
|
|
1748
|
+
overflow: hidden !important;
|
|
1296
1749
|
}
|
|
1297
1750
|
</style>
|
|
1298
1751
|
|
|
@@ -1306,20 +1759,61 @@ code.hljs {
|
|
|
1306
1759
|
|
|
1307
1760
|
<div class="bdb-chat-title-container">
|
|
1308
1761
|
<h3 class="bdb-chat-title">${this.chatTitle}</h3>
|
|
1309
|
-
|
|
1762
|
+
<span class="bdb-info-tooltip">
|
|
1763
|
+
<button
|
|
1764
|
+
type="button"
|
|
1765
|
+
class="bdb-info-trigger"
|
|
1766
|
+
aria-label="Integration settings"
|
|
1767
|
+
aria-haspopup="dialog"
|
|
1768
|
+
>
|
|
1769
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
|
|
1770
|
+
<path d="M12 22c5.523 0 10-4.477 10-10S17.523 2 12 2 2 6.477 2 12s4.477 10 10 10Z" stroke="currentColor" stroke-width="1.8"/>
|
|
1771
|
+
<path d="M12 10.5v6" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/>
|
|
1772
|
+
<path d="M12 7.5h.01" stroke="currentColor" stroke-width="2.6" stroke-linecap="round"/>
|
|
1773
|
+
</svg>
|
|
1774
|
+
</button>
|
|
1775
|
+
|
|
1776
|
+
<span class="bdb-info-popover" role="tooltip">
|
|
1777
|
+
<div class="bdb-info-popover-title">Chat documentation</div>
|
|
1778
|
+
<p class="bdb-info-popover-desc" style="margin: 0 0 8px 0;">Learn how to integrate and configure chat.</p>
|
|
1779
|
+
<a
|
|
1780
|
+
href="https://bvector.bangdb.com/settings/integration"
|
|
1781
|
+
target="_blank"
|
|
1782
|
+
rel="noopener noreferrer"
|
|
1783
|
+
>
|
|
1784
|
+
Open chat docs
|
|
1785
|
+
</a>
|
|
1786
|
+
</span>
|
|
1787
|
+
</span>
|
|
1788
|
+
</div>
|
|
1310
1789
|
|
|
1311
|
-
<div class="bdb-header-actions">
|
|
1790
|
+
<div class="bdb-header-actions" style="position: relative;">
|
|
1312
1791
|
<button class="bdb-icon-btn js-fullscreen-btn" aria-label="Toggle fullscreen" title="Fullscreen">
|
|
1313
1792
|
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1314
1793
|
<path d="M1.5 1h4v1.5h-2.5v2.5h-1.5v-4zm8 0h4v4h-1.5v-2.5h-2.5v-1.5zm-8 8h1.5v2.5h2.5v1.5h-4v-4zm10.5 2.5v-2.5h1.5v4h-4v-1.5h2.5z" fill="currentColor"/>
|
|
1315
1794
|
</svg>
|
|
1316
1795
|
</button>
|
|
1317
1796
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1797
|
+
<button class="bdb-icon-btn js-download-btn" aria-label="Download chat" title="Download">
|
|
1798
|
+
<svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
1799
|
+
<path d="M7.5 10.5l-4-4h2.5v-5h3v5h2.5l-4 4zm-5 2h10v1.5h-10v-1.5z" fill="currentColor"/>
|
|
1800
|
+
</svg>
|
|
1801
|
+
</button>
|
|
1802
|
+
|
|
1803
|
+
<div class="bdb-download-dropdown" id="bdb-download-dropdown">
|
|
1804
|
+
<button class="bdb-dropdown-item" id="js-download-md">
|
|
1805
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>
|
|
1806
|
+
Markdown (.md)
|
|
1807
|
+
</button>
|
|
1808
|
+
<button class="bdb-dropdown-item" id="js-download-pdf">
|
|
1809
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M9 15v-6h2a2 2 0 0 1 2 2v2a2 2 0 0 1-2 2h-2"></path></svg>
|
|
1810
|
+
PDF (.pdf)
|
|
1811
|
+
</button>
|
|
1812
|
+
<button class="bdb-dropdown-item" id="js-download-json">
|
|
1813
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><path d="M8 13h2m0 0v4m0-4v-2a2 2 0 0 1 4 0v2m0 0h2"></path></svg>
|
|
1814
|
+
JSON (.json)
|
|
1815
|
+
</button>
|
|
1816
|
+
</div>
|
|
1323
1817
|
|
|
1324
1818
|
<button class="bdb-icon-btn js-close-btn" aria-label="Close chat" title="Close">
|
|
1325
1819
|
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -1332,14 +1826,14 @@ code.hljs {
|
|
|
1332
1826
|
<div class="bdb-chat-body" style="display: flex; flex-direction: column; flex: 1; overflow: hidden;"></div>
|
|
1333
1827
|
</div>
|
|
1334
1828
|
</div>
|
|
1335
|
-
`;let t=e.querySelector(".bdb-chat-panel"),
|
|
1829
|
+
`;let t=e.querySelector(".bdb-chat-panel"),o=e.querySelector(".bdb-chat-body"),r=e.querySelector(".bdb-chat-title-container"),a=e.querySelector(".bdb-chat-header");if(a&&this.bubbleEl){let l=!1,g=0,h=0,b=0,m=0,u=parseInt(this.bubbleEl.style.left)||0,y=parseInt(this.bubbleEl.style.top)||0;a.addEventListener("pointerdown",k=>{k.target?.closest("button, a, input, textarea, select, [role='button']")||(l=!0,this.bubbleEl._didDrag=!1,g=k.clientX,h=k.clientY,u=parseInt(this.bubbleEl.style.left)||0,y=parseInt(this.bubbleEl.style.top)||0,b=u,m=y,this.bubbleEl.style.transition="none",a.setPointerCapture(k.pointerId))}),a.addEventListener("pointermove",k=>{if(!l)return;let v=k.clientX-g,C=k.clientY-h;Math.hypot(v,C)>4&&(this.bubbleEl._didDrag=!0),u=b+v,y=m+C,this.bubbleEl.style.left=u+"px",this.bubbleEl.style.top=y+"px",this.updatePanelPosition()});let w=k=>{if(!l)return;l=!1;try{a.releasePointerCapture(k.pointerId)}catch{}if(!this.bubbleEl._didDrag)return;let v=52,C=52,f=24,x=window.innerWidth,E=window.innerHeight,L=u+v/2,j=y+C/2,z=[{left:f,top:f},{left:(x-v)/2,top:f},{left:x-f-v,top:f},{left:f,top:(E-C)/2},{left:x-f-v,top:(E-C)/2},{left:f,top:E-f-C},{left:(x-v)/2,top:E-f-C},{left:x-f-v,top:E-f-C}],H=z[0],V=1/0;for(let U of z){let X=Math.hypot(U.left+v/2-L,U.top+C/2-j);X<V&&(V=X,H=U)}u=H.left,y=H.top,this.bubbleEl.style.transition="left 0.4s cubic-bezier(0.2,0.8,0.2,1), top 0.4s cubic-bezier(0.2,0.8,0.2,1)",this.bubbleEl.style.left=u+"px",this.bubbleEl.style.top=y+"px";try{localStorage.setItem("bdb-bubble-position",JSON.stringify({left:u,top:y}))}catch{}this.updatePanelPosition()};a.addEventListener("pointerup",w),a.addEventListener("pointercancel",w)}if(t.querySelector(".js-fullscreen-btn")?.addEventListener("click",()=>{this.store.getState().chat.mode===2?this.store.dispatch(I(1)):this.store.dispatch(I(2))}),t.querySelector(".js-close-btn")?.addEventListener("click",()=>{let l=this.store.getState().chat.mode;l===2?this.store.dispatch(I(1)):l===1&&this.store.dispatch(I(0))}),this.logoUrl){let l=document.createElement("div"),g=document.createElement("img");g.src=this.logoUrl,g.style.cssText="width: 24px; height: 24px; margin-right: 0.5rem;",l.appendChild(g),r.prepend(l)}let s=t.querySelector(".js-download-btn"),i=t.querySelector("#bdb-download-dropdown"),c=t.querySelector("#js-download-md"),p=t.querySelector("#js-download-pdf"),d=t.querySelector("#js-download-json");if(s&&i){s.addEventListener("click",h=>{h.stopPropagation(),i.classList.toggle("show")});let l=h=>{let b=h.composedPath();!b.includes(i)&&!b.includes(s)&&i.classList.remove("show")};this.root.addEventListener("click",l,!0),document.addEventListener("click",l,!0);let g=()=>{let h=this.store.getState(),b=h.chat.activeSession;return h.chatSessions[b]?.chatData||[]};c?.addEventListener("click",()=>{He(g(),this.chatTitle),i.classList.remove("show")}),p?.addEventListener("click",()=>{De(g(),this.chatTitle),i.classList.remove("show")}),d?.addEventListener("click",()=>{Oe(g()),i.classList.remove("show")})}return o.appendChild(this.chatArea()),e}chatArea(){let e=document.createElement("div");e.style.cssText="display: flex; flex-direction: column; flex: 1; overflow: hidden; position: relative;",e.innerHTML=`
|
|
1336
1830
|
<style>
|
|
1337
1831
|
.bdb-scroll {
|
|
1338
1832
|
scrollbar-width: thin;
|
|
1339
1833
|
scrollbar-color: color-mix(in oklab, var(--foreground) 10%, transparent) transparent;
|
|
1340
1834
|
scroll-behavior: smooth;
|
|
1341
1835
|
}
|
|
1342
|
-
|
|
1836
|
+
|
|
1343
1837
|
.bdb-scroll:hover {
|
|
1344
1838
|
scrollbar-color: color-mix(in oklab, var(--foreground) 18%, transparent) transparent;
|
|
1345
1839
|
}
|
|
@@ -1355,7 +1849,7 @@ code.hljs {
|
|
|
1355
1849
|
text-align: center;
|
|
1356
1850
|
padding: 2rem;
|
|
1357
1851
|
}
|
|
1358
|
-
|
|
1852
|
+
|
|
1359
1853
|
.bdb-empty-icon {
|
|
1360
1854
|
width: 48px;
|
|
1361
1855
|
height: 48px;
|
|
@@ -1367,7 +1861,7 @@ code.hljs {
|
|
|
1367
1861
|
color: var(--primary-foreground);
|
|
1368
1862
|
margin-bottom: 0.25rem;
|
|
1369
1863
|
}
|
|
1370
|
-
|
|
1864
|
+
|
|
1371
1865
|
.bdb-empty-title {
|
|
1372
1866
|
font-size: 15px;
|
|
1373
1867
|
font-weight: 600;
|
|
@@ -1387,39 +1881,78 @@ code.hljs {
|
|
|
1387
1881
|
bottom: 0.5rem;
|
|
1388
1882
|
left: 50%;
|
|
1389
1883
|
transform: translateX(-50%);
|
|
1390
|
-
background: var(--
|
|
1391
|
-
|
|
1392
|
-
border-radius: var(--radius-full);
|
|
1884
|
+
background: var(--primary);
|
|
1885
|
+
color: var(--primary-foreground);
|
|
1393
1886
|
width: 32px;
|
|
1394
1887
|
height: 32px;
|
|
1888
|
+
border-radius: 50%;
|
|
1395
1889
|
display: flex;
|
|
1396
1890
|
align-items: center;
|
|
1397
1891
|
justify-content: center;
|
|
1398
1892
|
cursor: pointer;
|
|
1399
|
-
color: var(--foreground);
|
|
1400
|
-
box-shadow: 0 4px 12px rgba(0,0,0,0.4);
|
|
1401
|
-
transition: opacity 0.2s, transform 0.2s;
|
|
1402
1893
|
opacity: 0;
|
|
1403
1894
|
pointer-events: none;
|
|
1895
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
1896
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.15);
|
|
1897
|
+
border: none;
|
|
1404
1898
|
z-index: 10;
|
|
1405
1899
|
}
|
|
1900
|
+
|
|
1901
|
+
.bdb-chat-widget table {
|
|
1902
|
+
width: 100%;
|
|
1903
|
+
border-collapse: collapse;
|
|
1904
|
+
margin-top: 0.5rem;
|
|
1905
|
+
font-size: 14px;
|
|
1906
|
+
}
|
|
1907
|
+
.bdb-chat-widget th {
|
|
1908
|
+
text-align: left;
|
|
1909
|
+
font-weight: 600;
|
|
1910
|
+
padding: 8px 12px;
|
|
1911
|
+
border-bottom: 1px solid var(--border);
|
|
1912
|
+
color: var(--muted-foreground);
|
|
1913
|
+
}
|
|
1914
|
+
.bdb-chat-widget td {
|
|
1915
|
+
padding: 8px 12px;
|
|
1916
|
+
border-bottom: 1px solid var(--border);
|
|
1917
|
+
color: var(--foreground);
|
|
1918
|
+
}
|
|
1919
|
+
.bdb-chat-widget tr:last-child td {
|
|
1920
|
+
border-bottom: none;
|
|
1921
|
+
}
|
|
1406
1922
|
.bdb-scroll-fab.visible {
|
|
1407
1923
|
opacity: 1;
|
|
1408
1924
|
pointer-events: auto;
|
|
1409
1925
|
}
|
|
1410
|
-
|
|
1926
|
+
|
|
1411
1927
|
.bdb-chat-panel.is-fullscreen #chat-query-container {
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1928
|
+
width: 100%;
|
|
1929
|
+
flex-shrink: 0;
|
|
1930
|
+
box-sizing: border-box;
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
.bdb-chat-panel.is-fullscreen #chat-query-container > * {
|
|
1934
|
+
max-width: 56rem;
|
|
1935
|
+
margin: 0 auto;
|
|
1936
|
+
width: 100%;
|
|
1937
|
+
box-sizing: border-box;
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
/* Prevent message content from overflowing in fullscreen */
|
|
1941
|
+
#bangdb-chat-area pre,
|
|
1942
|
+
#bangdb-chat-area code,
|
|
1943
|
+
#bangdb-chat-area table,
|
|
1944
|
+
#bangdb-chat-area img {
|
|
1945
|
+
max-width: 100%;
|
|
1946
|
+
overflow-x: auto;
|
|
1947
|
+
box-sizing: border-box;
|
|
1415
1948
|
}
|
|
1416
1949
|
</style>
|
|
1417
1950
|
|
|
1418
|
-
<div style="position: relative; flex: 1; overflow: hidden;">
|
|
1951
|
+
<div style="position: relative; flex: 1; overflow: hidden; width: 100%;">
|
|
1419
1952
|
<div class="bdb-scroll" id="bangdb-chat-area"
|
|
1420
|
-
style="height: 100%; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column;">
|
|
1953
|
+
style="height: 100%; overflow-x: hidden; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; width: 100%; box-sizing: border-box;">
|
|
1421
1954
|
|
|
1422
|
-
<div style="
|
|
1955
|
+
<div style="width: 100%; display: flex; flex-direction: column; gap: 0.25rem; flex: 1; box-sizing: border-box;">
|
|
1423
1956
|
<div class="bdb-empty-state" id="bdb-empty-state">
|
|
1424
1957
|
<div class="bdb-empty-icon">
|
|
1425
1958
|
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
|
|
@@ -1444,9 +1977,9 @@ code.hljs {
|
|
|
1444
1977
|
</div>
|
|
1445
1978
|
|
|
1446
1979
|
<div id="chat-query-container"
|
|
1447
|
-
style="flex-shrink: 0; background: var(--background); padding: 0.75rem 1rem 1rem;">
|
|
1980
|
+
style="flex-shrink: 0; background: var(--background); padding: 0.75rem 1rem 1rem; width: 100%; box-sizing: border-box;">
|
|
1448
1981
|
</div>
|
|
1449
|
-
`;let t=e.querySelector("#bangdb-chat-area"),
|
|
1982
|
+
`;let t=e.querySelector("#bangdb-chat-area"),o=e.querySelector("#chat-query-container"),r=e.querySelector("#bdb-scroll-fab");return o.appendChild(this.chatQueryForm()),t.addEventListener("scroll",()=>{let a=t.scrollHeight-t.scrollTop-t.clientHeight;r.classList.toggle("visible",a>100)}),r.addEventListener("click",()=>{t.scrollTo({top:t.scrollHeight,behavior:"smooth"})}),this.chatAreaEl=e,e}loadingIndicator(){let e=document.createElement("div");return e.innerHTML=`
|
|
1450
1983
|
<style>
|
|
1451
1984
|
.bdb-loading {
|
|
1452
1985
|
display: flex;
|
|
@@ -1474,18 +2007,27 @@ code.hljs {
|
|
|
1474
2007
|
40% { transform: translateY(-6px); opacity: 1; }
|
|
1475
2008
|
}
|
|
1476
2009
|
</style>
|
|
1477
|
-
|
|
2010
|
+
|
|
1478
2011
|
<div class="bdb-loading">
|
|
1479
2012
|
<div class="bdb-typing-dots">
|
|
1480
2013
|
<span></span><span></span><span></span>
|
|
1481
2014
|
</div>
|
|
1482
2015
|
<span>Thinking\u2026</span>
|
|
1483
2016
|
</div>
|
|
1484
|
-
`,e}userRequestMessage(e){let t=document.createElement("div");
|
|
2017
|
+
`,e}userRequestMessage(e){let t=document.createElement("div");t.style.cssText="display: flex; justify-content: flex-end; margin-block: 0.375rem;",t.innerHTML=`
|
|
1485
2018
|
<style>
|
|
2019
|
+
.bdb-user-stack {
|
|
2020
|
+
display: inline-flex;
|
|
2021
|
+
flex-direction: column;
|
|
2022
|
+
align-items: flex-end;
|
|
2023
|
+
gap: 6px;
|
|
2024
|
+
max-width: 75%;
|
|
2025
|
+
}
|
|
2026
|
+
|
|
1486
2027
|
.bdb-user-bubble {
|
|
1487
|
-
|
|
1488
|
-
|
|
2028
|
+
width: fit-content;
|
|
2029
|
+
max-width: 100%;
|
|
2030
|
+
background: var(--secondary);
|
|
1489
2031
|
color: var(--secondary-foreground);
|
|
1490
2032
|
border-radius: 18px 18px 4px 18px;
|
|
1491
2033
|
padding: 0.6rem 1rem;
|
|
@@ -1494,19 +2036,37 @@ code.hljs {
|
|
|
1494
2036
|
word-break: break-word;
|
|
1495
2037
|
box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
|
|
1496
2038
|
}
|
|
2039
|
+
|
|
2040
|
+
.bdb-user-actionbar {
|
|
2041
|
+
width: fit-content;
|
|
2042
|
+
max-width: 100%;
|
|
2043
|
+
display: flex;
|
|
2044
|
+
justify-content: flex-end;
|
|
2045
|
+
padding: 0.125rem 0;
|
|
2046
|
+
min-height: 32px;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
.bdb-user-actionbar button {
|
|
2050
|
+
/* mimic action bar button baseline spacing */
|
|
2051
|
+
transform: translateY(-2px);
|
|
2052
|
+
}
|
|
1497
2053
|
</style>
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
2054
|
+
|
|
2055
|
+
<div class="bdb-user-stack">
|
|
2056
|
+
<div class="bdb-user-bubble"></div>
|
|
2057
|
+
<div class="bdb-user-actionbar"></div>
|
|
2058
|
+
</div>
|
|
2059
|
+
`,t.querySelector(".bdb-user-bubble").textContent=e;let o=t.querySelector(".bdb-user-actionbar"),r=N(R,"Copy to clipboard");return r.addEventListener("click",async()=>{try{await navigator.clipboard.writeText(e),r.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></svg>',r.style.color="var(--primary)",r.style.borderColor="var(--primary)",setTimeout(()=>{r.innerHTML=R,r.style.color="",r.style.borderColor=""},2e3)}catch{}}),o.appendChild(r),t}aiResponseMessage(e){let t=document.createElement("div");t.style.cssText="display: flex; gap: 0.625rem; align-items: flex-start; margin-block: 0.375rem;";let o=document.createElement("style");o.textContent=`
|
|
2060
|
+
${ee}
|
|
2061
|
+
${Z}
|
|
2062
|
+
|
|
1504
2063
|
.ai-md pre {
|
|
1505
2064
|
padding: 1rem;
|
|
1506
2065
|
background: var(--card);
|
|
1507
2066
|
border-radius: var(--radius-md);
|
|
1508
2067
|
}
|
|
1509
|
-
|
|
2068
|
+
|
|
2069
|
+
/* Bubble wrapper \u2014 flex column so charts + action bar stack below text */
|
|
1510
2070
|
.bdb-ai-bubble {
|
|
1511
2071
|
flex: 1;
|
|
1512
2072
|
min-width: 0;
|
|
@@ -1514,29 +2074,35 @@ code.hljs {
|
|
|
1514
2074
|
font-size: 14px;
|
|
1515
2075
|
line-height: 1.65;
|
|
1516
2076
|
color: var(--foreground);
|
|
2077
|
+
display: flex;
|
|
2078
|
+
flex-direction: column;
|
|
2079
|
+
gap: 0;
|
|
1517
2080
|
}
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
2081
|
+
|
|
2082
|
+
@keyframes bdb-fade-in {
|
|
2083
|
+
from { opacity: 0; transform: translateY(4px); }
|
|
2084
|
+
to { opacity: 1; transform: translateY(0); }
|
|
2085
|
+
}
|
|
2086
|
+
`,t.appendChild(o);let r=document.createElement("div");r.className="bdb-ai-bubble",t.appendChild(r);let a=document.createElement("div");a.className="ai-md prose",r.appendChild(a);let s=new S(e),{messages:i}=s.parse(),c=i.map(m=>m?.output??"").join("");a.innerHTML=$(c),this.renderSourceTags(a,e);let p=e?._data??e?.a?._data;if(p){let m=Ee(String(p));m.children.length>0&&r.appendChild(m)}let d=i.map(m=>m?.output??"").join(`
|
|
2087
|
+
|
|
2088
|
+
`),l=e?.a?.usage??null,g=this.apiConfig?.indexName??"",h=this.root,b=Le({textToCopy:d,queryTimeMs:e?.queryTime,usageData:l,onInfo:()=>{let m=h.querySelector(".bdb-context-drawer-host");if(m){m.remove();return}let u=document.createElement("div");u.className="bdb-context-drawer-host";let y=Me({item:e,indexName:g,shadowRoot:h,onClose:()=>u.remove()});u.appendChild(y),h.appendChild(u)}});return r.appendChild(b),t}async renderSourceTags(e,t){let o=e.querySelectorAll("source-tag");if(!o.length)return;let r=t?.a?.metadata||t?.metadata||[];for(let a of o){let s=a.getAttribute("data-source-id"),i=a.getAttribute("data-category");if(!s||s.toLowerCase()==="na"){a.remove();continue}let c=document.createElement("span");c.style.cssText="display: block; padding: 0.75rem 0;";let p=s.split("##"),d=p[1]??s,l=p[2],g=document.createElement("span");if(g.style.cssText="display: block; font-size: 12px; color: var(--accent-foreground); padding-bottom: 0.5rem;",g.innerHTML=`
|
|
1522
2089
|
<span style="text-decoration: underline; color: var(--accent-foreground);">
|
|
1523
|
-
Source: ${decodeURIComponent(
|
|
1524
|
-
${
|
|
2090
|
+
Source: ${decodeURIComponent(d)}
|
|
2091
|
+
${l?`<span style="padding: 0 0.5rem;">|</span>Page: ${l}`:""}
|
|
1525
2092
|
</span>
|
|
1526
|
-
${
|
|
1527
|
-
`,c.appendChild(
|
|
2093
|
+
${i?`<span style="padding: 0 0.5rem;">|</span>Category: ${i}`:""}
|
|
2094
|
+
`,c.appendChild(g),r.length>0){let h=r.find(b=>b?.source_id===s);h?.table_ids?.length&&await this.renderTables(c,h.table_ids),h?.image_ids?.length&&await this.renderImages(c,h.image_ids)}a.replaceWith(c)}}async renderTables(e,t){for(let o of t){let r=document.createElement("div");r.innerHTML=`<div style="display:grid;grid-template-columns:repeat(9,1fr);gap:2px;">
|
|
1528
2095
|
${Array.from({length:36}).map(()=>'<div style="height:2rem;background:rgba(255,255,255,0.05);border-radius:2px;"></div>').join("")}
|
|
1529
|
-
</div>`,e.appendChild(
|
|
1530
|
-
<div style="height:8rem; background-image:url('${
|
|
1531
|
-
<div style="padding:0.375rem 0.5rem; font-size:11px; color:#a1a1aa; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${
|
|
1532
|
-
`,
|
|
2096
|
+
</div>`,e.appendChild(r);try{let a=await G({baseURL:this.apiConfig.backendURL,apikey:this.apiConfig.apikey,payload:{name:this.apiConfig.indexName,type:"table",id:o}});a?.metadata?.text_as_html&&(r.innerHTML=`<div style="overflow-x:auto;margin-bottom:1rem;">${a.metadata.text_as_html}</div>`)}catch{r.innerHTML='<div style="color:#f87171;font-size:12px;margin-bottom:0.5rem;">Failed to load table</div>'}}}async renderImages(e,t){let o=document.createElement("div");o.style.cssText="display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; margin-top: 0.5rem;",e.appendChild(o);let{backendURL:r,resourceURL:a,apikey:s,indexName:i}=this.apiConfig,c=`${i}_img_bucket`;for(let p of t){let d=document.createElement("div");d.style.cssText="border-radius: 8px; overflow: hidden; border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.03);",d.innerHTML='<div style="height: 8rem; background: rgba(255,255,255,0.05); display:flex; align-items:center; justify-content:center; color: #71717a; font-size:12px;">Loading\u2026</div>',o.appendChild(d);try{let l=await G({baseURL:r,apikey:s,payload:{name:i,type:"image",id:p}});if(!l?.file_name){d.remove();continue}let g=`https://${a}/brs/get/${s}/${c}/${p}_${l.file_name}`;d.innerHTML=`
|
|
2097
|
+
<div style="height:8rem; background-image:url('${g}'); background-size:cover; background-position:center; cursor:pointer;"></div>
|
|
2098
|
+
<div style="padding:0.375rem 0.5rem; font-size:11px; color:#a1a1aa; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">${l.file_name}</div>
|
|
2099
|
+
`,d.querySelector("div")?.addEventListener("click",()=>{let h=document.createElement("div");h.style.cssText="position:fixed;inset:0;background:rgba(0,0,0,0.9);z-index:9999999;display:flex;align-items:center;justify-content:center;cursor:zoom-out;",h.innerHTML=`<img src="${g}" alt="image" style="max-width:90vw;max-height:90vh;border-radius:8px;object-fit:contain;" />`,h.addEventListener("click",()=>h.remove()),document.body.appendChild(h)})}catch{d.remove()}}}chatQueryForm(){let e=document.createElement("div");e.innerHTML=`
|
|
1533
2100
|
<style>
|
|
1534
2101
|
.bdb-form-wrap {
|
|
1535
2102
|
border-radius: var(--radius-lg);
|
|
1536
2103
|
border: 1px solid var(--input);
|
|
1537
2104
|
background: var(--card);
|
|
1538
2105
|
transition: border-color 0.18s, box-shadow 0.18s;
|
|
1539
|
-
overflow: hidden;
|
|
1540
2106
|
}
|
|
1541
2107
|
|
|
1542
2108
|
.bdb-form-wrap:focus-within {
|
|
@@ -1571,11 +2137,106 @@ code.hljs {
|
|
|
1571
2137
|
.bdb-form-footer {
|
|
1572
2138
|
display: flex;
|
|
1573
2139
|
align-items: center;
|
|
1574
|
-
justify-content:
|
|
2140
|
+
justify-content: space-between;
|
|
1575
2141
|
padding: 0.4rem 0.625rem 0.625rem;
|
|
1576
2142
|
gap: 0.5rem;
|
|
1577
2143
|
}
|
|
1578
2144
|
|
|
2145
|
+
.bdb-form-tools-left {
|
|
2146
|
+
display: flex;
|
|
2147
|
+
align-items: center;
|
|
2148
|
+
gap: 0.5rem;
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
.bdb-tools-btn {
|
|
2152
|
+
display: flex;
|
|
2153
|
+
align-items: center;
|
|
2154
|
+
gap: 0.375rem;
|
|
2155
|
+
padding: 0.375rem 0.625rem;
|
|
2156
|
+
border-radius: var(--radius-md);
|
|
2157
|
+
border: none;
|
|
2158
|
+
background: transparent;
|
|
2159
|
+
color: var(--muted-foreground);
|
|
2160
|
+
font-size: 13px;
|
|
2161
|
+
font-family: var(--font-body);
|
|
2162
|
+
font-weight: 500;
|
|
2163
|
+
cursor: pointer;
|
|
2164
|
+
transition: color 0.15s, background 0.15s;
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
.bdb-tools-btn:hover {
|
|
2168
|
+
background: color-mix(in oklab, var(--foreground) 6%, transparent);
|
|
2169
|
+
color: var(--foreground);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
.bdb-tools-dropdown {
|
|
2173
|
+
position: absolute;
|
|
2174
|
+
bottom: calc(100% + 8px);
|
|
2175
|
+
left: 0;
|
|
2176
|
+
min-width: 200px;
|
|
2177
|
+
background: var(--card);
|
|
2178
|
+
border: 1px solid var(--border);
|
|
2179
|
+
border-radius: var(--radius-md);
|
|
2180
|
+
box-shadow: 0 8px 24px rgba(0,0,0,0.35);
|
|
2181
|
+
z-index: 100;
|
|
2182
|
+
padding: 0.375rem;
|
|
2183
|
+
display: none;
|
|
2184
|
+
flex-direction: column;
|
|
2185
|
+
animation: bdb-fade-in 0.12s ease;
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
.bdb-tools-dropdown.show {
|
|
2189
|
+
display: flex;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
.bdb-tool-item {
|
|
2193
|
+
padding: 0.4rem 0.75rem;
|
|
2194
|
+
font-size: 13px;
|
|
2195
|
+
color: var(--foreground);
|
|
2196
|
+
cursor: pointer;
|
|
2197
|
+
border-radius: calc(var(--radius-md) - 2px);
|
|
2198
|
+
transition: background 0.15s;
|
|
2199
|
+
text-align: left;
|
|
2200
|
+
border: none;
|
|
2201
|
+
background: transparent;
|
|
2202
|
+
font-family: var(--font-body);
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
.bdb-tool-item:hover {
|
|
2206
|
+
background: color-mix(in oklab, var(--foreground) 6%, transparent);
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
.bdb-tool-badge {
|
|
2210
|
+
display: inline-flex;
|
|
2211
|
+
align-items: center;
|
|
2212
|
+
gap: 0.25rem;
|
|
2213
|
+
padding: 0.125rem 0.375rem 0.125rem 0.5rem;
|
|
2214
|
+
background: color-mix(in oklab, var(--primary) 15%, transparent);
|
|
2215
|
+
color: var(--primary);
|
|
2216
|
+
border-radius: var(--radius-sm);
|
|
2217
|
+
font-size: 12px;
|
|
2218
|
+
font-weight: 500;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
.bdb-tool-clear {
|
|
2222
|
+
display: inline-flex;
|
|
2223
|
+
align-items: center;
|
|
2224
|
+
justify-content: center;
|
|
2225
|
+
width: 16px;
|
|
2226
|
+
height: 16px;
|
|
2227
|
+
border-radius: 50%;
|
|
2228
|
+
border: none;
|
|
2229
|
+
background: transparent;
|
|
2230
|
+
color: inherit;
|
|
2231
|
+
cursor: pointer;
|
|
2232
|
+
opacity: 0.7;
|
|
2233
|
+
}
|
|
2234
|
+
.bdb-tool-clear:hover {
|
|
2235
|
+
opacity: 1;
|
|
2236
|
+
background: color-mix(in oklab, var(--primary) 20%, transparent);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
|
|
1579
2240
|
.bdb-send-btn {
|
|
1580
2241
|
display: flex;
|
|
1581
2242
|
align-items: center;
|
|
@@ -1611,9 +2272,26 @@ code.hljs {
|
|
|
1611
2272
|
aria-label="Chat message"
|
|
1612
2273
|
></textarea>
|
|
1613
2274
|
<div class="bdb-form-footer">
|
|
2275
|
+
<div class="bdb-form-tools-left">
|
|
2276
|
+
<div id="bdb-active-tool-badge" class="bdb-tool-badge" style="display: none;">
|
|
2277
|
+
<span id="bdb-active-tool-name"></span>
|
|
2278
|
+
<button class="bdb-tool-clear" aria-label="Clear tool">
|
|
2279
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
|
2280
|
+
</button>
|
|
2281
|
+
</div>
|
|
2282
|
+
<div style="position: relative;">
|
|
2283
|
+
<button class="bdb-tools-btn" id="bdb-tools-trigger" aria-haspopup="true" aria-expanded="false">
|
|
2284
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>
|
|
2285
|
+
Tools
|
|
2286
|
+
</button>
|
|
2287
|
+
<div class="bdb-tools-dropdown" id="bdb-tools-dropdown">
|
|
2288
|
+
<!-- Dynamically populated -->
|
|
2289
|
+
</div>
|
|
2290
|
+
</div>
|
|
2291
|
+
</div>
|
|
1614
2292
|
<button class="bdb-send-btn" disabled aria-label="Send message">
|
|
1615
2293
|
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-send" aria-hidden="true"><path d="M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z"></path><path d="m21.854 2.147-10.94 10.939"></path></svg>
|
|
1616
2294
|
</button>
|
|
1617
2295
|
</div>
|
|
1618
2296
|
</div>
|
|
1619
|
-
`;let t=e.querySelector(".bdb-textarea"),
|
|
2297
|
+
`;let t=e.querySelector(".bdb-textarea"),o=e.querySelector(".bdb-send-btn"),r=e.querySelector("#bdb-tools-trigger"),a=e.querySelector("#bdb-tools-dropdown"),s=e.querySelector("#bdb-active-tool-badge"),i=e.querySelector("#bdb-active-tool-name"),c=e.querySelector(".bdb-tool-clear"),p=this.tools;p.length===0?r.style.display="none":(p.forEach(l=>{let g=document.createElement("button");g.className="bdb-tool-item",g.textContent=l.name,g.addEventListener("click",()=>{let h=this.store.getState().chat.tools;for(let b of h)b.id!==l.id&&this.store.dispatch(K(b.id));this.store.dispatch(ae({id:l.id,name:l.name})),i.textContent=l.name,s.style.display="inline-flex",a.classList.remove("show")}),a.appendChild(g)}),r.addEventListener("click",l=>{l.stopPropagation(),a.classList.toggle("show")}),document.addEventListener("click",l=>{!a.contains(l.target)&&l.target!==r&&a.classList.remove("show")})),c.addEventListener("click",()=>{let l=this.store.getState().chat.tools;for(let g of l)this.store.dispatch(K(g.id));s.style.display="none"});let d=()=>{t.style.height="auto",t.style.height=Math.min(t.scrollHeight,180)+"px"};return this.store.subscribe(()=>{let{chatSessions:l,chat:g}=this.store.getState(),h=l[g.activeSession]?.query||"";t.value!==h&&(t.value=h,d(),o.disabled=!h.trim())}),t.addEventListener("input",()=>{d();let l=t.value;o.disabled=!l.trim();let{activeSession:g}=this.store.getState().chat;this.store.dispatch(F({sessionId:g,query:l}))}),t.addEventListener("keydown",async l=>{l.key==="Enter"&&!l.shiftKey&&(l.preventDefault(),o.disabled||await this.sendQuery())}),o.addEventListener("click",()=>this.sendQuery()),e}async sendQuery(){let{chatSessions:e,chat:t}=this.store.getState(),{activeSession:o,activeIndex:r}=t,{query:a,isLoading:s}=e[o];if(s||!a?.trim())return;let i={query:a,output:[]};this.store.dispatch(F({sessionId:o,query:""})),await this.store.dispatch(pe({query:i?.query,sessionId:o,indexName:r,config:this.apiConfig}))}downloadChat(){}};B.DEFAULT_TOOLS=[{id:"kpi",name:"KPI (MCP)"}];var P=B;var $e=null;function Ne(n){return $e=new P(n),$e}typeof window<"u"&&(window.BangdbChatWidget={init:Ne});0&&(module.exports={ChatWidget,init});
|