@scrimpify-software/rag-widgets 1.2.0 → 1.3.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/README.md CHANGED
@@ -37,7 +37,7 @@ import { KnowLayerWidget } from "@scrimpify-software/rag-widgets";
37
37
  | `welcomeMessage` | Yes | Greeting in the chat, or intro text above the search box |
38
38
  | `apiUrl` | No | KnowLayer API base URL |
39
39
  | `getToken` / `getFirebaseIdToken` | No | Signed-in users (see [Authentication](#authentication)) |
40
- | `theme` | No | `"light"` (default) or `"dark"` |
40
+ | `theme` | No | `"light"` (default), `"dark"`, or custom hex colors, e.g. `{ primary: "#4F46E5" }` (see Theming) |
41
41
 
42
42
  Every widget shows a "Powered by KnowLayer" footer.
43
43
 
@@ -254,12 +254,59 @@ Rendering your own UI? `uniqueCitations(sources, { minScore })` and the `ChatSou
254
254
  | `clientId` | `string` | Yes | OAuth client ID (public). Never pass `clientSecret`. |
255
255
  | `getToken` | `() => Promise<string \| { token, expires_in }>` | No | Your backend returns a widget JWT. Mutually exclusive with `getFirebaseIdToken`. |
256
256
  | `getFirebaseIdToken` | `() => Promise<string>` | No | KnowLayer / Firebase ID token (dashboard). Mutually exclusive with `getToken`. |
257
- | `theme` | `"light" \| "dark"` | No | Color theme (default: `"light"`) |
257
+ | `theme` | `"light" \| "dark" \| ThemeConfig` | No | Preset, or custom hex colors (default: `"light"`). See [Theming](#theming) |
258
258
  | `placeholder` | `string` | No | Input placeholder text |
259
259
  | `showScopeHint` | `boolean` | No | Caption for what the widget answers from (default: `true`) |
260
260
  | `showCitations` | `boolean` | No | Show the sources panel (default: `true`) |
261
261
  | `citationMinScore` | `number` | No | Relevance cut-off for scored sources (default: `0.65`) |
262
262
 
263
+ ### Theming
264
+
265
+ `theme` accepts `"light"`, `"dark"`, or an object of hex colors (`#rgb` or `#rrggbb`). Every key is optional.
266
+
267
+ ```tsx
268
+ <KnowLayerWidget
269
+ chatType="floating"
270
+ theme={{
271
+ launcherBackground: "#4F46E5",
272
+ headerBackground: "#4F46E5",
273
+ headerText: "#ffffff",
274
+ chatBackground: "#F9FAFB",
275
+ userBubbleBackground: "#4F46E5",
276
+ botBubbleBackground: "#E5E7EB",
277
+ sendButtonBackground: "#4F46E5",
278
+ inputBackground: "#ffffff",
279
+ }}
280
+ /* ...other props */
281
+ />
282
+ ```
283
+
284
+ **Per-region keys** (these always win):
285
+
286
+ | Region | Keys |
287
+ |--------|------|
288
+ | Floating launcher bubble | `launcherBackground`, `launcherIcon` |
289
+ | Header | `headerBackground`, `headerText` |
290
+ | Chat area | `chatBackground`, `userBubbleBackground`, `userBubbleText`, `botBubbleBackground`, `botBubbleText` |
291
+ | Send button | `sendButtonBackground`, `sendButtonIcon` |
292
+ | Question input | `inputBackground`, `inputText`, `inputBorder` |
293
+ | Dividers | `borderColor` |
294
+
295
+ If you set a region's background but not its text color, the text becomes black or white, whichever is readable.
296
+
297
+ **Quick start keys** (each sets several regions at once, use them if you don't want to style every part):
298
+
299
+ | Key | Drives |
300
+ |-----|--------|
301
+ | `primary` | Launcher, send button and your message bubbles |
302
+ | `background` | Chat panel, header and input background. Card, border and bot bubble shades are derived. |
303
+ | `text` | Main text, header text, input text, bot bubble text |
304
+ | `mode` | `"light"` / `"dark"` base palette. Inferred from `background` if omitted. |
305
+
306
+ Combine them freely: `{ primary: "#4F46E5", headerBackground: "#111827" }` gives an indigo widget with a dark header.
307
+
308
+ An invalid hex is ignored with a console warning and the default is used. The `search` widget uses the input, send button (Ask) and text keys.
309
+
263
310
  ### FloatingChat Props
264
311
 
265
312
  | Prop | Type | Default | Description |
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),a=require("react"),ee=require("react-dom"),te=3e4,M=600,ne=3600,re="KnowLayer widgets: getToken and getFirebaseIdToken are mutually exclusive.",oe=5e3;function ie(e,n){return e?"getToken":n?"firebase":"public"}function se(e,n){if(e&&typeof e=="object"&&"detail"in e){const r=e.detail;if(typeof r=="string"&&r.trim())return r}return n}function ae(e){return e.includes("eyJ")||e.length>300?"Couldn't start the assistant. Please try again.":e}function de(e){if(typeof e=="string"){if(!e)throw new Error("getToken returned an empty token.");return{token:e,expiresIn:M}}const n=e&&typeof e.token=="string"&&e.token?e.token:e&&typeof e.access_token=="string"?e.access_token:"";if(!n)throw new Error("getToken must return a token string or { token, expires_in }.");const r=typeof e.expires_in=="number"?e.expires_in:M;return{token:n,expiresIn:r}}async function K(e,n){if(!e.ok){const i=await e.json().catch(()=>({}));throw new Error(se(i,`Widget token request failed (${e.status})`))}const r=await e.json();if(!r||typeof r.token!="string"||!r.token)throw new Error("Widget token response missing token.");const s=typeof r.expires_in=="number"?r.expires_in:n;return{token:r.token,expiresIn:s}}function z({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s}){if(s&&r)throw new Error(re);const i=ie(s,r),f=`${e}|${n}|${i}`,g=a.useRef(s),k=a.useRef(r);g.current=s,k.current=r;const o=a.useRef(null),u=a.useRef(null),m=a.useRef(null),y=a.useRef(0),w=a.useCallback(()=>{o.current=null,u.current=null,m.current=null,y.current+=1},[]),x=a.useCallback(async()=>{const l=y.current,b=m.current;if(b&&b.key===f&&Date.now()-b.at<oe)throw new Error(b.message);try{let c;if(i==="getToken"&&g.current)c=de(await g.current());else if(i==="firebase"&&k.current){const h=await k.current(),j=await fetch(`${e}/api/v1/teams/widget-token`,{method:"POST",headers:{"X-KL-Client-Id":n,"X-Firebase-Id-Token":h}});c=await K(j,ne)}else{const h=await fetch(`${e}/api/v1/teams/public-widget-session`,{method:"POST",headers:{"X-KL-Client-Id":n}});c=await K(h,M)}return l!==y.current||(o.current={key:f,token:c.token,expiresAt:Date.now()+c.expiresIn*1e3},m.current=null),c.token}catch(c){const h=ae(c instanceof Error?c.message:"Couldn't start the assistant. Please try again.");throw l===y.current&&(m.current={key:f,at:Date.now(),message:h}),new Error(h)}},[e,n,i,f]);return{getWidgetToken:a.useCallback(async()=>{const l=o.current;if(l&&l.key===f&&l.expiresAt-te>Date.now())return l.token;const b=u.current;if(b&&b.key===f)return b.promise;const c=x().finally(()=>{var h;((h=u.current)==null?void 0:h.promise)===c&&(u.current=null)});return u.current={key:f,promise:c},c},[f,x]),invalidateWidgetToken:w,authMode:i}}const le="http://localhost:8000",A="Chat quota is exhausted. Please contact your organization admin.";function O(e){return e==="public"?"Public documents":"Signed in · includes your teams"}const ue="Hello! Ask me anything about your documentation.";let ce=0;function I(){return`msg_${Date.now()}_${++ce}`}async function q(e,n,r){return fetch(`${e}/api/v1/teams/me/chat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({query:r})})}function Q({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,welcomeMessage:i=ue,signedInWelcomeMessage:f}){const{getWidgetToken:g,invalidateWidgetToken:k,authMode:o}=z({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s}),u=o!=="public"&&f?f:i,[m,y]=a.useState(()=>[{id:I(),role:"assistant",content:u}]),[w,x]=a.useState(!1),[R,l]=a.useState(null),b=a.useRef(0),c=a.useCallback(()=>{b.current+=1,y([{id:I(),role:"assistant",content:u}]),l(null),x(!1)},[u]),h=a.useRef(o);a.useEffect(()=>{h.current!==o&&(h.current=o,c())},[o,c]);const j=a.useCallback(async C=>{const v=C.trim();if(!v||w)return;const T=b.current,S=()=>T===b.current,$={id:I(),role:"user",content:v};y(B=>[...B,$]),x(!0),l(null);try{const B=await g();let d=await q(e,B,v);if(d.status===401){k();const L=await g();d=await q(e,L,v)}if(!S())return;if(!d.ok){if(d.status===402){l(A),y(_=>[..._,{id:I(),role:"assistant",content:A}]);return}const L=await d.json().catch(()=>({}));throw new Error(L.detail||`Request failed (${d.status})`)}const E=await d.json();if(!S())return;const W=Array.isArray(E.sources)&&!E.llm_unavailable,p={id:I(),role:"assistant",content:E.answer??"No response received.",sources:W?E.sources:void 0};y(L=>[...L,p])}catch(B){if(!S())return;const d=B instanceof Error?B.message:"Something went wrong.",E=d.includes("eyJ")||d.length>300?"Couldn't start the assistant. Please try again.":d;l(E),y(W=>[...W,{id:I(),role:"assistant",content:"Sorry, I couldn't get a response. Please try again."}])}finally{S()&&x(!1)}},[e,g,k,w]);return{messages:m,isLoading:w,error:R,authMode:o,sendMessage:j,reset:c}}function X({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,suggestedQuestions:i}){const[f,g]=a.useState([]),{getWidgetToken:k,invalidateWidgetToken:o,authMode:u}=z({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s}),m=!!(i&&i.length>0);return a.useEffect(()=>{if(m)return;let y=!1;return g([]),(async()=>{const w=x=>fetch(`${e}/api/v1/teams/me/suggested-questions`,{headers:{Authorization:`Bearer ${x}`}});try{let x=await w(await k());if(x.status===401&&!y&&(o(),x=await w(await k())),!x.ok||y)return;const R=await x.json();if(y)return;const l=Array.isArray(R.questions)?R.questions.filter(b=>typeof b=="string"&&b.trim().length>0):[];g(l)}catch{}})(),()=>{y=!0}},[e,u,k,o,m]),m?i:f}const D=.65;function fe(e){const n=(e.team_id??"").toString().trim().toLowerCase(),r=n?`team:${n}|`:"",s=(e.filename??"").trim().toLowerCase();if(s)return`${r}file:${s}`;const i=(e.document_id??"").toString().trim().toLowerCase();return i?`${r}id:${i}`:`${r}text:${(e.text??"").slice(0,60)}`}function V(e,{minScore:n=D}={}){const r=new Map,s=[];for(const i of e){if(i.score!=null&&i.score<n)continue;const f=fe(i),g=r.get(f);if(!g){r.set(f,i),s.push(f);continue}(i.score??0)>(g.score??0)&&r.set(f,i)}return s.map(i=>r.get(i))}function pe(e){return new Set(e.map(r=>(r.team_id??"").toString()).filter(r=>r.length>0)).size>1}function xe(e){const n=(e.clause_number??"").toString().trim(),r=(e.section_title??"").trim();return n&&r?`§ ${n} ${r}`:n?`§ ${n}`:r||(e.title??"").trim()||null}function P({sources:e,colors:n,compact:r=!1,minScore:s=D}){const[i,f]=a.useState(!1),g=a.useMemo(()=>V(e,{minScore:s}),[e,s]),k=a.useMemo(()=>pe(g),[g]);if(g.length===0)return null;const o=r?11:12;return t.jsxs("div",{style:ge(n),children:[t.jsxs("button",{onClick:()=>f(u=>!u),style:he(n,o),children:[t.jsx(je,{size:r?12:14,color:n.textMuted}),t.jsxs("span",{children:[g.length," source",g.length>1?"s":""," cited"]}),t.jsx(Se,{direction:i?"up":"down",size:r?12:14,color:n.textMuted})]}),i&&t.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",marginTop:6},children:g.map((u,m)=>{const y=u.filename??"Unknown source",w=k&&u.team_name?`${u.team_name} · ${y}`:y,x=xe(u);return t.jsxs("li",{style:ye(n,m>0),children:[t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[t.jsx("span",{style:be(n),children:m+1}),t.jsx("span",{title:w,style:{fontWeight:600,fontSize:o,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:w}),u.score!=null&&t.jsxs("span",{style:me(),children:[(u.score*100).toFixed(0),"%"]})]}),x&&t.jsx("p",{style:ke(n,o),children:x}),u.text&&t.jsx("p",{style:we(n,o),children:u.text.length>120?u.text.slice(0,120)+"…":u.text})]},`${u.team_id??""}-${u.filename??u.document_id??"source"}-${m}`)})})]})}function ge(e){return{marginTop:6,borderRadius:8,border:`1px solid ${e.border}`,background:e.cardBg,padding:"6px 10px"}}function he(e,n){return{display:"flex",alignItems:"center",gap:5,width:"100%",background:"none",border:"none",padding:0,cursor:"pointer",fontSize:n,fontWeight:500,color:e.textMuted}}function ye(e,n){return{padding:"6px 0",borderTop:n?`1px solid ${e.border}`:"none"}}function be(e){return{width:18,height:18,borderRadius:4,background:e.primary+"1a",color:e.primary,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0}}function me(){return{fontSize:10,fontWeight:600,color:"#22c55e",background:"rgba(34,197,94,0.12)",borderRadius:999,padding:"1px 6px",flexShrink:0}}function ke(e,n){return{margin:"2px 0 0 24px",fontSize:n-1,fontWeight:500,color:e.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}function we(e,n){return{margin:"4px 0 0 24px",fontSize:n-1,lineHeight:1.45,color:e.textMuted,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"}}function je({size:e,color:n}){return t.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:n,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),t.jsx("polyline",{points:"14 2 14 8 20 8"}),t.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),t.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}function Se({direction:e,size:n,color:r}){return t.jsx("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:"auto"},children:e==="down"?t.jsx("polyline",{points:"6 9 12 15 18 9"}):t.jsx("polyline",{points:"18 15 12 9 6 15"})})}function F({colors:e}){return t.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"6px 12px",fontSize:11,color:e.textMuted},children:[t.jsx("span",{children:"Powered by"}),t.jsx(ve,{color:e.primary}),t.jsx("span",{style:{fontWeight:600,color:e.text},children:"KnowLayer"})]})}function ve({color:e}){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:e,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.jsx("polygon",{points:"12 2 2 7 12 12 22 7 12 2"}),t.jsx("polyline",{points:"2 17 12 22 22 17"}),t.jsx("polyline",{points:"2 12 12 17 22 12"})]})}const Be={bg:"#ffffff",cardBg:"#f8fafc",border:"#e2e8f0",text:"#1e293b",textMuted:"#64748b",primary:"#2563eb",primaryText:"#ffffff",inputBg:"#ffffff",userBubbleBg:"#2563eb",userBubbleText:"#ffffff",assistantBubbleBg:"#f1f5f9",headerBg:"#ffffff",headerText:"#1e293b",dot:"#22c55e"},Re={bg:"#0f172a",cardBg:"#1e293b",border:"#334155",text:"#f1f5f9",textMuted:"#94a3b8",primary:"#3b82f6",primaryText:"#ffffff",inputBg:"#1e293b",userBubbleBg:"#3b82f6",userBubbleText:"#ffffff",assistantBubbleBg:"#334155",headerBg:"#1e293b",headerText:"#f1f5f9",dot:"#22c55e"};function H(e){return e==="dark"?Re:Be}function J(e){const n=e.split(`
2
- `),r=[];for(let s=0;s<n.length;s++)s>0&&r.push(a.createElement("br",{key:`br_${s}`})),r.push(a.createElement(a.Fragment,{key:`line_${s}`},...Te(n[s])));return a.createElement(a.Fragment,null,...r)}function Te(e){const n=[],r=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g;let s=0,i,f=0;for(;(i=r.exec(e))!==null;)i.index>s&&n.push(e.slice(s,i.index)),i[2]!==void 0?n.push(a.createElement("strong",{key:`b_${f++}`},i[2])):i[3]!==void 0?n.push(a.createElement("em",{key:`i_${f++}`},i[3])):i[4]!==void 0&&n.push(a.createElement("code",{key:`c_${f++}`,style:{background:"rgba(0,0,0,0.08)",padding:"1px 4px",borderRadius:3,fontSize:"0.9em"}},i[4])),s=i.index+i[0].length;return s<e.length&&n.push(e.slice(s)),n.length===0&&n.push(""),n}function Y({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,title:i="KnowLayer Assistant",placeholder:f="Ask a question…",welcomeMessage:g,signedInWelcomeMessage:k,theme:o="light",position:u="bottom-right",buttonSize:m=56,popupWidth:y="380px",popupHeight:w="520px",suggestedQuestions:x,showScopeHint:R=!0,showCitations:l=!0,citationMinScore:b}){const[c,h]=a.useState(!1),j=H(o),C=X({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,suggestedQuestions:x});return ee.createPortal(t.jsxs(t.Fragment,{children:[c&&t.jsx(Ce,{apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,title:i,placeholder:f,welcomeMessage:g,signedInWelcomeMessage:k,colors:j,position:u,buttonSize:m,popupWidth:y,popupHeight:w,onClose:()=>h(!1),suggestedQuestions:C,showScopeHint:R,showCitations:l,citationMinScore:b}),t.jsx("button",{onClick:()=>h(v=>!v),style:Ee(j,u,m),"aria-label":c?"Close chat":"Open chat",children:c?t.jsx(G,{}):t.jsx($e,{})})]}),document.body)}function Ce({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,title:i,placeholder:f,welcomeMessage:g,signedInWelcomeMessage:k,colors:o,position:u,buttonSize:m,popupWidth:y,popupHeight:w,onClose:x,suggestedQuestions:R=[],showScopeHint:l,showCitations:b,citationMinScore:c}){const{messages:h,isLoading:j,error:C,authMode:v,sendMessage:T}=Q({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,welcomeMessage:g,signedInWelcomeMessage:k}),[S,$]=a.useState(""),B=a.useRef(null);a.useEffect(()=>{var p;(p=B.current)==null||p.scrollIntoView({behavior:"smooth"})},[h,j]);const d=p=>{p.preventDefault(),S.trim()&&(T(S),$(""))},E=m+16,W=u==="bottom-left"?{left:20,bottom:E}:{right:20,bottom:E};return t.jsxs("div",{style:{position:"fixed",...W,width:y,height:w,zIndex:2147483645,fontFamily:"system-ui, -apple-system, sans-serif",display:"flex",flexDirection:"column",borderRadius:16,border:`1px solid ${o.border}`,background:o.bg,color:o.text,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden",animation:"knowlayer-fadein 0.2s ease-out"},children:[t.jsx("style",{children:"@keyframes knowlayer-fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }"}),t.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${o.border}`,background:o.headerBg},children:[t.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:o.dot,flexShrink:0}}),t.jsx("span",{style:{fontWeight:600,fontSize:14,flex:1},children:i}),l&&t.jsx("span",{style:{fontSize:10,color:o.textMuted},children:O(v)}),t.jsx("button",{onClick:x,style:{background:"none",border:"none",cursor:"pointer",color:o.textMuted,padding:4,display:"flex"},"aria-label":"Close",children:t.jsx(G,{})})]}),t.jsxs("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:14},children:[h.map(p=>t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:p.role==="user"?"flex-end":"flex-start",marginBottom:10},children:[t.jsx("div",{style:{maxWidth:"82%",padding:"8px 12px",borderRadius:12,fontSize:13,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",background:p.role==="user"?o.userBubbleBg:o.assistantBubbleBg,color:p.role==="user"?o.userBubbleText:o.text},children:p.role==="assistant"?J(p.content):p.content}),b&&p.role==="assistant"&&p.sources&&p.sources.length>0&&t.jsx("div",{style:{maxWidth:"82%"},children:t.jsx(P,{sources:p.sources,colors:o,compact:!0,minScore:c})})]},p.id)),j&&t.jsx("div",{style:{marginBottom:10},children:t.jsx("div",{style:{maxWidth:"82%",padding:"8px 12px",borderRadius:12,fontSize:13,background:o.assistantBubbleBg,color:o.textMuted},children:"Thinking…"})}),C&&t.jsx("div",{style:{padding:"6px 10px",borderRadius:8,background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",fontSize:12,marginBottom:10},children:C}),t.jsx("div",{ref:B})]}),R.length>0&&h.length<=1&&t.jsxs("div",{style:{padding:"8px 12px",borderTop:`1px solid ${o.border}`,background:o.cardBg},children:[t.jsx("span",{style:{display:"block",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:o.textMuted,marginBottom:5},children:"Try asking"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:R.map(p=>t.jsx("button",{type:"button",onClick:()=>{T(p)},style:{background:"none",border:`1px solid ${o.border}`,borderRadius:999,padding:"3px 8px",fontSize:11,color:o.textMuted,cursor:"pointer",whiteSpace:"nowrap"},children:p},p))})]}),t.jsxs("form",{onSubmit:d,style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderTop:`1px solid ${o.border}`,background:o.cardBg},children:[t.jsx("input",{value:S,onChange:p=>$(p.target.value),placeholder:f,style:{flex:1,padding:"7px 10px",borderRadius:8,border:`1px solid ${o.border}`,background:o.inputBg,color:o.text,fontSize:13,outline:"none"}}),t.jsx("button",{type:"submit",disabled:!S.trim()||j,style:{width:32,height:32,borderRadius:8,border:"none",background:!S.trim()||j?o.border:o.primary,color:o.primaryText,cursor:!S.trim()||j?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,opacity:!S.trim()||j?.5:1},children:t.jsx(Le,{})})]}),t.jsx(F,{colors:o})]})}function Ee(e,n,r){return{position:"fixed",...n==="bottom-left"?{left:20,bottom:20}:{right:20,bottom:20},width:r,height:r,borderRadius:"50%",border:"none",background:e.primary,color:e.primaryText,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 14px rgba(0,0,0,0.25)",zIndex:2147483646,transition:"transform 0.15s"}}function $e(){return t.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:t.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function G(){return t.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),t.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Le(){return t.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),t.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function Z({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,title:i="KnowLayer Assistant",placeholder:f="Ask a question…",welcomeMessage:g,signedInWelcomeMessage:k,theme:o="light",height:u="500px",className:m,suggestedQuestions:y,showScopeHint:w=!0,showCitations:x=!0,citationMinScore:R}){const l=H(o),{messages:b,isLoading:c,error:h,authMode:j,sendMessage:C}=Q({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,welcomeMessage:g,signedInWelcomeMessage:k}),v=X({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,suggestedQuestions:y}),[T,S]=a.useState(""),$=a.useRef(null);a.useEffect(()=>{var d;(d=$.current)==null||d.scrollIntoView({behavior:"smooth"})},[b,c]);const B=d=>{d.preventDefault(),T.trim()&&(C(T),S(""))};return t.jsxs("div",{className:m,style:We(l,u),children:[t.jsxs("div",{style:Ie(l),children:[t.jsx("span",{style:_e(l)}),t.jsx("span",{style:{fontWeight:600,fontSize:14,flex:1},children:i}),w&&t.jsx("span",{style:{fontSize:11,color:l.textMuted},children:O(j)})]}),t.jsxs("div",{style:Me(l),children:[b.map(d=>t.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:d.role==="user"?"flex-end":"flex-start",marginBottom:12},children:[t.jsx("div",{style:N(d.role,l),children:d.role==="assistant"?J(d.content):d.content}),x&&d.role==="assistant"&&d.sources&&d.sources.length>0&&t.jsx("div",{style:{maxWidth:"80%"},children:t.jsx(P,{sources:d.sources,colors:l,minScore:R})})]},d.id)),c&&t.jsx("div",{style:{marginBottom:12},children:t.jsx("div",{style:N("assistant",l),children:t.jsx("span",{style:{opacity:.6},children:"Thinking…"})})}),h&&t.jsx("div",{style:{padding:"8px 12px",borderRadius:8,background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",fontSize:13,marginBottom:12},children:h}),t.jsx("div",{ref:$})]}),v.length>0&&b.length<=1&&t.jsxs("div",{style:De(l),children:[t.jsx("span",{style:Pe(l),children:"Try asking"}),t.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:v.map(d=>t.jsx("button",{type:"button",onClick:()=>{C(d)},style:Fe(l),children:d},d))})]}),t.jsxs("form",{onSubmit:B,style:Ae(l),children:[t.jsx("input",{value:T,onChange:d=>S(d.target.value),placeholder:f,style:ze(l)}),t.jsx("button",{type:"submit",disabled:!T.trim()||c,style:Oe(l,!T.trim()||c),children:t.jsx(He,{})})]}),t.jsx(F,{colors:l})]})}function We(e,n){return{fontFamily:"system-ui, -apple-system, sans-serif",display:"flex",flexDirection:"column",height:n,borderRadius:12,border:`1px solid ${e.border}`,background:e.bg,color:e.text,overflow:"hidden"}}function Ie(e){return{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${e.border}`,background:e.headerBg,color:e.headerText}}function _e(e){return{width:8,height:8,borderRadius:"50%",background:e.dot,flexShrink:0}}function Me(e){return{flex:1,minHeight:0,overflowY:"auto",padding:16,background:e.bg}}function N(e,n){const r=e==="user";return{maxWidth:"80%",padding:"10px 14px",borderRadius:12,fontSize:14,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",background:r?n.userBubbleBg:n.assistantBubbleBg,color:r?n.userBubbleText:n.text}}function Ae(e){return{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderTop:`1px solid ${e.border}`,background:e.cardBg}}function ze(e){return{flex:1,padding:"8px 12px",borderRadius:8,border:`1px solid ${e.border}`,background:e.inputBg,color:e.text,fontSize:14,outline:"none"}}function Oe(e,n){return{width:36,height:36,borderRadius:8,border:"none",background:n?e.border:e.primary,color:e.primaryText,cursor:n?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,opacity:n?.5:1,transition:"opacity 0.15s"}}function De(e){return{padding:"8px 14px",borderTop:`1px solid ${e.border}`,background:e.cardBg}}function Pe(e){return{display:"block",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:e.textMuted,marginBottom:6}}function Fe(e){return{background:"none",border:`1px solid ${e.border}`,borderRadius:999,padding:"4px 10px",fontSize:12,color:e.textMuted,cursor:"pointer",whiteSpace:"nowrap"}}function He(){return t.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[t.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),t.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function U({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s,welcomeMessage:i,placeholder:f="Ask a question…",theme:g="light",showScopeHint:k=!0,showCitations:o=!0,citationMinScore:u}){const[m,y]=a.useState(""),[w,x]=a.useState(null),[R,l]=a.useState([]),[b,c]=a.useState(!1),h=H(g),{getWidgetToken:j,invalidateWidgetToken:C,authMode:v}=z({apiUrl:e,clientId:n,getFirebaseIdToken:r,getToken:s}),T=a.useRef(0),S=a.useRef(v);a.useEffect(()=>{S.current!==v&&(S.current=v,T.current+=1,x(null),l([]),c(!1))},[v]);const $=async()=>{if(!m.trim())return;const B=++T.current,d=()=>B===T.current;c(!0),x(null),l([]);try{const E=await j(),W=_=>fetch(`${e}/api/v1/teams/me/chat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${_}`},body:JSON.stringify({query:m})});let p=await W(E);if(p.status===401){C();const _=await j();p=await W(_)}if(!d())return;if(!p.ok){if(p.status===402){x(A);return}x("Something went wrong.");return}const L=await p.json();if(!d())return;x(L.answer??"No response received."),Array.isArray(L.sources)&&!L.llm_unavailable&&l(L.sources)}catch{d()&&x("Something went wrong.")}finally{d()&&c(!1)}};return t.jsxs("div",{style:{fontFamily:"system-ui, sans-serif"},children:[i&&t.jsx("p",{style:{marginTop:0,marginBottom:8,fontSize:14,color:h.text},children:i}),t.jsxs("div",{style:{display:"flex",gap:8},children:[t.jsx("input",{type:"text",value:m,onChange:B=>y(B.target.value),onKeyDown:B=>B.key==="Enter"&&$(),placeholder:f,style:{flex:1,padding:"8px 12px",borderRadius:6,border:"1px solid #ccc",fontSize:14}}),t.jsx("button",{onClick:$,disabled:b,style:{padding:"8px 16px",borderRadius:6,border:"none",background:"#2563eb",color:"#fff",cursor:"pointer",fontSize:14},children:b?"…":"Ask"})]}),k&&t.jsx("div",{style:{marginTop:4,fontSize:11,color:h.textMuted},children:O(v)}),w&&t.jsx("div",{style:{marginTop:12,padding:12,borderRadius:6,background:"#f8fafc",border:"1px solid #e2e8f0",whiteSpace:"pre-wrap",fontSize:14},children:w}),o&&R.length>0&&t.jsx(P,{sources:R,colors:h,minScore:u}),t.jsx(F,{colors:h})]})}function Ke({chatType:e,apiUrl:n=le,...r}){switch(e){case"floating":return t.jsx(Y,{apiUrl:n,...r});case"embedded":return t.jsx(Z,{apiUrl:n,...r});case"search":return t.jsx(U,{apiUrl:n,...r})}}exports.CITATION_SCORE_THRESHOLD=D;exports.EmbeddedChat=Z;exports.FloatingChat=Y;exports.KnowLayerWidget=Ke;exports.SearchWidget=U;exports.uniqueCitations=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),l=require("react"),de=require("react-dom"),le=3e4,P=600,ce=3600,fe="KnowLayer widgets: getToken and getFirebaseIdToken are mutually exclusive.",xe=5e3;function ge(e,t){return e?"getToken":t?"firebase":"public"}function pe(e,t){if(e&&typeof e=="object"&&"detail"in e){const r=e.detail;if(typeof r=="string"&&r.trim())return r}return t}function he(e){return e.includes("eyJ")||e.length>300?"Couldn't start the assistant. Please try again.":e}function be(e){if(typeof e=="string"){if(!e)throw new Error("getToken returned an empty token.");return{token:e,expiresIn:P}}const t=e&&typeof e.token=="string"&&e.token?e.token:e&&typeof e.access_token=="string"?e.access_token:"";if(!t)throw new Error("getToken must return a token string or { token, expires_in }.");const r=typeof e.expires_in=="number"?e.expires_in:P;return{token:t,expiresIn:r}}async function X(e,t){if(!e.ok){const i=await e.json().catch(()=>({}));throw new Error(pe(i,`Widget token request failed (${e.status})`))}const r=await e.json();if(!r||typeof r.token!="string"||!r.token)throw new Error("Widget token response missing token.");const o=typeof r.expires_in=="number"?r.expires_in:t;return{token:r.token,expiresIn:o}}function K({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o}){if(o&&r)throw new Error(fe);const i=ge(o,r),x=`${e}|${t}|${i}`,a=l.useRef(o),k=l.useRef(r);a.current=o,k.current=r;const s=l.useRef(null),u=l.useRef(null),y=l.useRef(null),p=l.useRef(0),B=l.useCallback(()=>{s.current=null,u.current=null,y.current=null,p.current+=1},[]),d=l.useCallback(async()=>{const c=p.current,m=y.current;if(m&&m.key===x&&Date.now()-m.at<xe)throw new Error(m.message);try{let h;if(i==="getToken"&&a.current)h=be(await a.current());else if(i==="firebase"&&k.current){const g=await k.current(),j=await fetch(`${e}/api/v1/teams/widget-token`,{method:"POST",headers:{"X-KL-Client-Id":t,"X-Firebase-Id-Token":g}});h=await X(j,ce)}else{const g=await fetch(`${e}/api/v1/teams/public-widget-session`,{method:"POST",headers:{"X-KL-Client-Id":t}});h=await X(g,P)}return c!==p.current||(s.current={key:x,token:h.token,expiresAt:Date.now()+h.expiresIn*1e3},y.current=null),h.token}catch(h){const g=he(h instanceof Error?h.message:"Couldn't start the assistant. Please try again.");throw c===p.current&&(y.current={key:x,at:Date.now(),message:g}),new Error(g)}},[e,t,i,x]);return{getWidgetToken:l.useCallback(async()=>{const c=s.current;if(c&&c.key===x&&c.expiresAt-le>Date.now())return c.token;const m=u.current;if(m&&m.key===x)return m.promise;const h=d().finally(()=>{var g;((g=u.current)==null?void 0:g.promise)===h&&(u.current=null)});return u.current={key:x,promise:h},h},[x,d]),invalidateWidgetToken:B,authMode:i}}const ye="http://localhost:8000",F="Chat quota is exhausted. Please contact your organization admin.";function q(e){return e==="public"?"Public documents":"Signed in · includes your teams"}const me="Hello! Ask me anything about your documentation.";let ke=0;function W(){return`msg_${Date.now()}_${++ke}`}async function J(e,t,r){return fetch(`${e}/api/v1/teams/me/chat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify({query:r})})}function Z({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,welcomeMessage:i=me,signedInWelcomeMessage:x}){const{getWidgetToken:a,invalidateWidgetToken:k,authMode:s}=K({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o}),u=s!=="public"&&x?x:i,[y,p]=l.useState(()=>[{id:W(),role:"assistant",content:u}]),[B,d]=l.useState(!1),[w,c]=l.useState(null),m=l.useRef(0),h=l.useCallback(()=>{m.current+=1,p([{id:W(),role:"assistant",content:u}]),c(null),d(!1)},[u]),g=l.useRef(s);l.useEffect(()=>{g.current!==s&&(g.current=s,h())},[s,h]);const j=l.useCallback(async C=>{const T=C.trim();if(!T||B)return;const R=m.current,S=()=>R===m.current,E={id:W(),role:"user",content:T};p(v=>[...v,E]),d(!0),c(null);try{const v=await a();let f=await J(e,v,T);if(f.status===401){k();const $=await a();f=await J(e,$,T)}if(!S())return;if(!f.ok){if(f.status===402){c(F),p(A=>[...A,{id:W(),role:"assistant",content:F}]);return}const $=await f.json().catch(()=>({}));throw new Error($.detail||`Request failed (${f.status})`)}const I=await f.json();if(!S())return;const L=Array.isArray(I.sources)&&!I.llm_unavailable,b={id:W(),role:"assistant",content:I.answer??"No response received.",sources:L?I.sources:void 0};p($=>[...$,b])}catch(v){if(!S())return;const f=v instanceof Error?v.message:"Something went wrong.",I=f.includes("eyJ")||f.length>300?"Couldn't start the assistant. Please try again.":f;c(I),p(L=>[...L,{id:W(),role:"assistant",content:"Sorry, I couldn't get a response. Please try again."}])}finally{S()&&d(!1)}},[e,a,k,B]);return{messages:y,isLoading:B,error:w,authMode:s,sendMessage:j,reset:h}}function ee({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,suggestedQuestions:i}){const[x,a]=l.useState([]),{getWidgetToken:k,invalidateWidgetToken:s,authMode:u}=K({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o}),y=!!(i&&i.length>0);return l.useEffect(()=>{if(y)return;let p=!1;return a([]),(async()=>{const B=d=>fetch(`${e}/api/v1/teams/me/suggested-questions`,{headers:{Authorization:`Bearer ${d}`}});try{let d=await B(await k());if(d.status===401&&!p&&(s(),d=await B(await k())),!d.ok||p)return;const w=await d.json();if(p)return;const c=Array.isArray(w.questions)?w.questions.filter(m=>typeof m=="string"&&m.trim().length>0):[];a(c)}catch{}})(),()=>{p=!0}},[e,u,k,s,y]),y?i:x}const N=.65;function Be(e){const t=(e.team_id??"").toString().trim().toLowerCase(),r=t?`team:${t}|`:"",o=(e.filename??"").trim().toLowerCase();if(o)return`${r}file:${o}`;const i=(e.document_id??"").toString().trim().toLowerCase();return i?`${r}id:${i}`:`${r}text:${(e.text??"").slice(0,60)}`}function te(e,{minScore:t=N}={}){const r=new Map,o=[];for(const i of e){if(i.score!=null&&i.score<t)continue;const x=Be(i),a=r.get(x);if(!a){r.set(x,i),o.push(x);continue}(i.score??0)>(a.score??0)&&r.set(x,i)}return o.map(i=>r.get(i))}function we(e){return new Set(e.map(r=>(r.team_id??"").toString()).filter(r=>r.length>0)).size>1}function je(e){const t=(e.clause_number??"").toString().trim(),r=(e.section_title??"").trim();return t&&r?`§ ${t} ${r}`:t?`§ ${t}`:r||(e.title??"").trim()||null}function Q({sources:e,colors:t,compact:r=!1,minScore:o=N}){const[i,x]=l.useState(!1),a=l.useMemo(()=>te(e,{minScore:o}),[e,o]),k=l.useMemo(()=>we(a),[a]);if(a.length===0)return null;const s=r?11:12;return n.jsxs("div",{style:Se(t),children:[n.jsxs("button",{onClick:()=>x(u=>!u),style:Te(t,s),children:[n.jsx($e,{size:r?12:14,color:t.textMuted}),n.jsxs("span",{children:[a.length," source",a.length>1?"s":""," cited"]}),n.jsx(Le,{direction:i?"up":"down",size:r?12:14,color:t.textMuted})]}),i&&n.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",marginTop:6},children:a.map((u,y)=>{const p=u.filename??"Unknown source",B=k&&u.team_name?`${u.team_name} · ${p}`:p,d=je(u);return n.jsxs("li",{style:ve(t,y>0),children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[n.jsx("span",{style:Re(t),children:y+1}),n.jsx("span",{title:B,style:{fontWeight:600,fontSize:s,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",flex:1,minWidth:0},children:B}),u.score!=null&&n.jsxs("span",{style:Ce(),children:[(u.score*100).toFixed(0),"%"]})]}),d&&n.jsx("p",{style:Ie(t,s),children:d}),u.text&&n.jsx("p",{style:Ee(t,s),children:u.text.length>120?u.text.slice(0,120)+"…":u.text})]},`${u.team_id??""}-${u.filename??u.document_id??"source"}-${y}`)})})]})}function Se(e){return{marginTop:6,borderRadius:8,border:`1px solid ${e.border}`,background:e.cardBg,padding:"6px 10px"}}function Te(e,t){return{display:"flex",alignItems:"center",gap:5,width:"100%",background:"none",border:"none",padding:0,cursor:"pointer",fontSize:t,fontWeight:500,color:e.textMuted}}function ve(e,t){return{padding:"6px 0",borderTop:t?`1px solid ${e.border}`:"none"}}function Re(e){return{width:18,height:18,borderRadius:4,background:e.primary+"1a",color:e.primary,display:"inline-flex",alignItems:"center",justifyContent:"center",fontSize:10,fontWeight:700,flexShrink:0}}function Ce(){return{fontSize:10,fontWeight:600,color:"#22c55e",background:"rgba(34,197,94,0.12)",borderRadius:999,padding:"1px 6px",flexShrink:0}}function Ie(e,t){return{margin:"2px 0 0 24px",fontSize:t-1,fontWeight:500,color:e.textMuted,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}function Ee(e,t){return{margin:"4px 0 0 24px",fontSize:t-1,lineHeight:1.45,color:e.textMuted,display:"-webkit-box",WebkitLineClamp:2,WebkitBoxOrient:"vertical",overflow:"hidden"}}function $e({size:e,color:t}){return n.jsxs("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:t,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),n.jsx("polyline",{points:"14 2 14 8 20 8"}),n.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),n.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}function Le({direction:e,size:t,color:r}){return n.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:r,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{marginLeft:"auto"},children:e==="down"?n.jsx("polyline",{points:"6 9 12 15 18 9"}):n.jsx("polyline",{points:"18 15 12 9 6 15"})})}function V({colors:e}){return n.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",gap:4,padding:"6px 12px",fontSize:11,color:e.textMuted},children:[n.jsx("span",{children:"Powered by"}),n.jsx(Me,{color:e.primary}),n.jsx("span",{style:{fontWeight:600,color:e.text},children:"KnowLayer"})]})}function Me({color:e}){return n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:e,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[n.jsx("polygon",{points:"12 2 2 7 12 12 22 7 12 2"}),n.jsx("polyline",{points:"2 17 12 22 22 17"}),n.jsx("polyline",{points:"2 12 12 17 22 12"})]})}const ne={bg:"#ffffff",cardBg:"#f8fafc",border:"#e2e8f0",text:"#1e293b",textMuted:"#64748b",primary:"#2563eb",primaryText:"#ffffff",inputBg:"#ffffff",userBubbleBg:"#2563eb",userBubbleText:"#ffffff",assistantBubbleBg:"#f1f5f9",assistantBubbleText:"#1e293b",headerBg:"#ffffff",headerText:"#1e293b",dot:"#22c55e",launcherBg:"#2563eb",launcherIcon:"#ffffff",sendBtnBg:"#2563eb",sendBtnText:"#ffffff",inputText:"#1e293b",inputBorder:"#e2e8f0"},We={bg:"#0f172a",cardBg:"#1e293b",border:"#334155",text:"#f1f5f9",textMuted:"#94a3b8",primary:"#3b82f6",primaryText:"#ffffff",inputBg:"#1e293b",userBubbleBg:"#3b82f6",userBubbleText:"#ffffff",assistantBubbleBg:"#334155",assistantBubbleText:"#f1f5f9",headerBg:"#1e293b",headerText:"#f1f5f9",dot:"#22c55e",launcherBg:"#3b82f6",launcherIcon:"#ffffff",sendBtnBg:"#3b82f6",sendBtnText:"#ffffff",inputText:"#f1f5f9",inputBorder:"#334155"};function M(e){if(typeof e!="string")return null;const t=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());if(!t)return null;let r=t[1]??"";r.length===3&&(r=r.split("").map(i=>i+i).join(""));const o=parseInt(r,16);return[o>>16&255,o>>8&255,o&255]}function re([e,t,r]){return"#"+[e,t,r].map(o=>Math.round(Math.min(255,Math.max(0,o))).toString(16).padStart(2,"0")).join("")}function H([e,t,r]){const o=i=>{const x=i/255;return x<=.03928?x/12.92:Math.pow((x+.055)/1.055,2.4)};return .2126*o(e)+.7152*o(t)+.0722*o(r)}function Y(e,t){const r=H(e),o=H(t);return(Math.max(r,o)+.05)/(Math.min(r,o)+.05)}function D(e){return Y(e,[255,255,255])>=Y(e,[0,0,0])?"#ffffff":"#000000"}function z(e,t,r){return re([e[0]+(t[0]-e[0])*r,e[1]+(t[1]-e[1])*r,e[2]+(t[2]-e[2])*r])}function _(e,t){if(e==null||e==="")return null;const r=M(e);return r?re(r):(typeof console<"u"&&console.warn(`[KnowLayer widget] Ignoring invalid theme color for "${t}": ${String(e)}. Use #rgb or #rrggbb.`),null)}function G(e){return e==="dark"?We:ne}const _e={launcherBackground:"launcherBg",launcherIcon:"launcherIcon",headerBackground:"headerBg",headerText:"headerText",chatBackground:"bg",userBubbleBackground:"userBubbleBg",userBubbleText:"userBubbleText",botBubbleBackground:"assistantBubbleBg",botBubbleText:"assistantBubbleText",sendButtonBackground:"sendBtnBg",sendButtonIcon:"sendBtnText",inputBackground:"inputBg",inputText:"inputText",inputBorder:"inputBorder",borderColor:"border"};function O(e){if(e===void 0||e==="light"||e==="dark")return G(e??"light");if(typeof e!="object"||e===null)return ne;const t=_(e.background,"background"),r=_(e.chatBackground,"chatBackground"),o=t??r,i=o?M(o):null,x=e.mode==="dark"||e.mode==="light"?e.mode:i&&H(i)<.4?"dark":"light",a={...G(x)},k=i??M(a.bg),u=_(e.text,"text")??(i?D(i):null),y=u?M(u):null;if(o){const d=y??M(a.text);a.bg=o,a.cardBg=z(k,d,.04),a.assistantBubbleBg=z(k,d,.08),a.border=z(k,d,.15),a.inputBorder=a.border,t&&(a.inputBg=t,a.headerBg=t)}u&&y&&(a.text=u,a.headerText=u,a.inputText=u,a.assistantBubbleText=u,a.textMuted=z(y,k,.4));const p=_(e.primary,"primary");if(p){const d=D(M(p));a.primary=p,a.primaryText=d,a.userBubbleBg=p,a.userBubbleText=d,a.launcherBg=p,a.launcherIcon=d,a.sendBtnBg=p,a.sendBtnText=d}const B=[["launcherBackground","launcherIcon","launcherIcon"],["headerBackground","headerText","headerText"],["userBubbleBackground","userBubbleText","userBubbleText"],["botBubbleBackground","botBubbleText","assistantBubbleText"],["sendButtonBackground","sendButtonIcon","sendBtnText"],["inputBackground","inputText","inputText"]];for(const[d,w,c]of B){const m=_(e[d],d);m&&!e[w]&&(a[c]=D(M(m)))}for(const[d,w]of Object.entries(_e)){const c=_(e[d],d);c&&(a[w]=c)}return a}function oe(e){const t=e.split(`
2
+ `),r=[];for(let o=0;o<t.length;o++)o>0&&r.push(l.createElement("br",{key:`br_${o}`})),r.push(l.createElement(l.Fragment,{key:`line_${o}`},...Ae(t[o])));return l.createElement(l.Fragment,null,...r)}function Ae(e){const t=[],r=/(\*\*(.+?)\*\*|\*(.+?)\*|`(.+?)`)/g;let o=0,i,x=0;for(;(i=r.exec(e))!==null;)i.index>o&&t.push(e.slice(o,i.index)),i[2]!==void 0?t.push(l.createElement("strong",{key:`b_${x++}`},i[2])):i[3]!==void 0?t.push(l.createElement("em",{key:`i_${x++}`},i[3])):i[4]!==void 0&&t.push(l.createElement("code",{key:`c_${x++}`,style:{background:"rgba(0,0,0,0.08)",padding:"1px 4px",borderRadius:3,fontSize:"0.9em"}},i[4])),o=i.index+i[0].length;return o<e.length&&t.push(e.slice(o)),t.length===0&&t.push(""),t}function ie({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,title:i="KnowLayer Assistant",placeholder:x="Ask a question…",welcomeMessage:a,signedInWelcomeMessage:k,theme:s="light",position:u="bottom-right",buttonSize:y=56,popupWidth:p="380px",popupHeight:B="520px",suggestedQuestions:d,showScopeHint:w=!0,showCitations:c=!0,citationMinScore:m}){const[h,g]=l.useState(!1),j=O(s),C=ee({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,suggestedQuestions:d});return de.createPortal(n.jsxs(n.Fragment,{children:[h&&n.jsx(ze,{apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,title:i,placeholder:x,welcomeMessage:a,signedInWelcomeMessage:k,colors:j,position:u,buttonSize:y,popupWidth:p,popupHeight:B,onClose:()=>g(!1),suggestedQuestions:C,showScopeHint:w,showCitations:c,citationMinScore:m}),n.jsx("button",{onClick:()=>g(T=>!T),style:Oe(j,u,y),"aria-label":h?"Close chat":"Open chat",children:h?n.jsx(se,{}):n.jsx(De,{})})]}),document.body)}function ze({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,title:i,placeholder:x,welcomeMessage:a,signedInWelcomeMessage:k,colors:s,position:u,buttonSize:y,popupWidth:p,popupHeight:B,onClose:d,suggestedQuestions:w=[],showScopeHint:c,showCitations:m,citationMinScore:h}){const{messages:g,isLoading:j,error:C,authMode:T,sendMessage:R}=Z({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,welcomeMessage:a,signedInWelcomeMessage:k}),[S,E]=l.useState(""),v=l.useRef(null);l.useEffect(()=>{var b;(b=v.current)==null||b.scrollIntoView({behavior:"smooth"})},[g,j]);const f=b=>{b.preventDefault(),S.trim()&&(R(S),E(""))},I=y+16,L=u==="bottom-left"?{left:20,bottom:I}:{right:20,bottom:I};return n.jsxs("div",{style:{position:"fixed",...L,width:p,height:B,zIndex:2147483645,fontFamily:"system-ui, -apple-system, sans-serif",display:"flex",flexDirection:"column",borderRadius:16,border:`1px solid ${s.border}`,background:s.bg,color:s.text,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",overflow:"hidden",animation:"knowlayer-fadein 0.2s ease-out"},children:[n.jsx("style",{children:"@keyframes knowlayer-fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }"}),n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${s.border}`,background:s.headerBg,color:s.headerText},children:[n.jsx("span",{style:{width:8,height:8,borderRadius:"50%",background:s.dot,flexShrink:0}}),n.jsx("span",{style:{fontWeight:600,fontSize:14,flex:1},children:i}),c&&n.jsx("span",{style:{fontSize:10,color:s.headerText,opacity:.7},children:q(T)}),n.jsx("button",{onClick:d,style:{background:"none",border:"none",cursor:"pointer",color:s.headerText,opacity:.7,padding:4,display:"flex"},"aria-label":"Close",children:n.jsx(se,{})})]}),n.jsxs("div",{style:{flex:1,minHeight:0,overflowY:"auto",padding:14},children:[g.map(b=>n.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:b.role==="user"?"flex-end":"flex-start",marginBottom:10},children:[n.jsx("div",{style:{maxWidth:"82%",padding:"8px 12px",borderRadius:12,fontSize:13,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word",background:b.role==="user"?s.userBubbleBg:s.assistantBubbleBg,color:b.role==="user"?s.userBubbleText:s.assistantBubbleText},children:b.role==="assistant"?oe(b.content):b.content}),m&&b.role==="assistant"&&b.sources&&b.sources.length>0&&n.jsx("div",{style:{maxWidth:"82%"},children:n.jsx(Q,{sources:b.sources,colors:s,compact:!0,minScore:h})})]},b.id)),j&&n.jsx("div",{style:{marginBottom:10},children:n.jsx("div",{style:{maxWidth:"82%",padding:"8px 12px",borderRadius:12,fontSize:13,background:s.assistantBubbleBg,color:s.textMuted},children:"Thinking…"})}),C&&n.jsx("div",{style:{padding:"6px 10px",borderRadius:8,background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",fontSize:12,marginBottom:10},children:C}),n.jsx("div",{ref:v})]}),w.length>0&&g.length<=1&&n.jsxs("div",{style:{padding:"8px 12px",borderTop:`1px solid ${s.border}`,background:s.cardBg},children:[n.jsx("span",{style:{display:"block",fontSize:10,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:s.textMuted,marginBottom:5},children:"Try asking"}),n.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:5},children:w.map(b=>n.jsx("button",{type:"button",onClick:()=>{R(b)},style:{background:"none",border:`1px solid ${s.border}`,borderRadius:999,padding:"3px 8px",fontSize:11,color:s.textMuted,cursor:"pointer",whiteSpace:"nowrap"},children:b},b))})]}),n.jsxs("form",{onSubmit:f,style:{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderTop:`1px solid ${s.border}`,background:s.cardBg},children:[n.jsx("input",{value:S,onChange:b=>E(b.target.value),placeholder:x,style:{flex:1,padding:"7px 10px",borderRadius:8,border:`1px solid ${s.inputBorder}`,background:s.inputBg,color:s.inputText,fontSize:13,outline:"none"}}),n.jsx("button",{type:"submit",disabled:!S.trim()||j,style:{width:32,height:32,borderRadius:8,border:"none",background:!S.trim()||j?s.border:s.sendBtnBg,color:s.sendBtnText,cursor:!S.trim()||j?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,opacity:!S.trim()||j?.5:1},children:n.jsx(Pe,{})})]}),n.jsx(V,{colors:s})]})}function Oe(e,t,r){return{position:"fixed",...t==="bottom-left"?{left:20,bottom:20}:{right:20,bottom:20},width:r,height:r,borderRadius:"50%",border:"none",background:e.launcherBg,color:e.launcherIcon,cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 14px rgba(0,0,0,0.25)",zIndex:2147483646,transition:"transform 0.15s"}}function De(){return n.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:n.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function se(){return n.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),n.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Pe(){return n.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),n.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function ae({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,title:i="KnowLayer Assistant",placeholder:x="Ask a question…",welcomeMessage:a,signedInWelcomeMessage:k,theme:s="light",height:u="500px",className:y,suggestedQuestions:p,showScopeHint:B=!0,showCitations:d=!0,citationMinScore:w}){const c=O(s),{messages:m,isLoading:h,error:g,authMode:j,sendMessage:C}=Z({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,welcomeMessage:a,signedInWelcomeMessage:k}),T=ee({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,suggestedQuestions:p}),[R,S]=l.useState(""),E=l.useRef(null);l.useEffect(()=>{var f;(f=E.current)==null||f.scrollIntoView({behavior:"smooth"})},[m,h]);const v=f=>{f.preventDefault(),R.trim()&&(C(R),S(""))};return n.jsxs("div",{className:y,style:Fe(c,u),children:[n.jsxs("div",{style:He(c),children:[n.jsx("span",{style:Ke(c)}),n.jsx("span",{style:{fontWeight:600,fontSize:14,flex:1},children:i}),B&&n.jsx("span",{style:{fontSize:11,color:c.headerText,opacity:.7},children:q(j)})]}),n.jsxs("div",{style:qe(c),children:[m.map(f=>n.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:f.role==="user"?"flex-end":"flex-start",marginBottom:12},children:[n.jsx("div",{style:U(f.role,c),children:f.role==="assistant"?oe(f.content):f.content}),d&&f.role==="assistant"&&f.sources&&f.sources.length>0&&n.jsx("div",{style:{maxWidth:"80%"},children:n.jsx(Q,{sources:f.sources,colors:c,minScore:w})})]},f.id)),h&&n.jsx("div",{style:{marginBottom:12},children:n.jsx("div",{style:U("assistant",c),children:n.jsx("span",{style:{opacity:.6},children:"Thinking…"})})}),g&&n.jsx("div",{style:{padding:"8px 12px",borderRadius:8,background:"#fef2f2",border:"1px solid #fecaca",color:"#dc2626",fontSize:13,marginBottom:12},children:g}),n.jsx("div",{ref:E})]}),T.length>0&&m.length<=1&&n.jsxs("div",{style:Xe(c),children:[n.jsx("span",{style:Je(c),children:"Try asking"}),n.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6},children:T.map(f=>n.jsx("button",{type:"button",onClick:()=>{C(f)},style:Ye(c),children:f},f))})]}),n.jsxs("form",{onSubmit:v,style:Ne(c),children:[n.jsx("input",{value:R,onChange:f=>S(f.target.value),placeholder:x,style:Qe(c)}),n.jsx("button",{type:"submit",disabled:!R.trim()||h,style:Ve(c,!R.trim()||h),children:n.jsx(Ge,{})})]}),n.jsx(V,{colors:c})]})}function Fe(e,t){return{fontFamily:"system-ui, -apple-system, sans-serif",display:"flex",flexDirection:"column",height:t,borderRadius:12,border:`1px solid ${e.border}`,background:e.bg,color:e.text,overflow:"hidden"}}function He(e){return{display:"flex",alignItems:"center",gap:8,padding:"12px 16px",borderBottom:`1px solid ${e.border}`,background:e.headerBg,color:e.headerText}}function Ke(e){return{width:8,height:8,borderRadius:"50%",background:e.dot,flexShrink:0}}function qe(e){return{flex:1,minHeight:0,overflowY:"auto",padding:16,background:e.bg}}function U(e,t){const r=e==="user";return{maxWidth:"80%",padding:"10px 14px",borderRadius:12,fontSize:14,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",background:r?t.userBubbleBg:t.assistantBubbleBg,color:r?t.userBubbleText:t.assistantBubbleText}}function Ne(e){return{display:"flex",alignItems:"center",gap:8,padding:"10px 12px",borderTop:`1px solid ${e.border}`,background:e.cardBg}}function Qe(e){return{flex:1,padding:"8px 12px",borderRadius:8,border:`1px solid ${e.inputBorder}`,background:e.inputBg,color:e.inputText,fontSize:14,outline:"none"}}function Ve(e,t){return{width:36,height:36,borderRadius:8,border:"none",background:t?e.border:e.sendBtnBg,color:e.sendBtnText,cursor:t?"not-allowed":"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,opacity:t?.5:1,transition:"opacity 0.15s"}}function Xe(e){return{padding:"8px 14px",borderTop:`1px solid ${e.border}`,background:e.cardBg}}function Je(e){return{display:"block",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.05em",color:e.textMuted,marginBottom:6}}function Ye(e){return{background:"none",border:`1px solid ${e.border}`,borderRadius:999,padding:"4px 10px",fontSize:12,color:e.textMuted,cursor:"pointer",whiteSpace:"nowrap"}}function Ge(){return n.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[n.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),n.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function ue({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o,welcomeMessage:i,placeholder:x="Ask a question…",theme:a="light",showScopeHint:k=!0,showCitations:s=!0,citationMinScore:u}){const[y,p]=l.useState(""),[B,d]=l.useState(null),[w,c]=l.useState([]),[m,h]=l.useState(!1),g=O(a),{getWidgetToken:j,invalidateWidgetToken:C,authMode:T}=K({apiUrl:e,clientId:t,getFirebaseIdToken:r,getToken:o}),R=l.useRef(0),S=l.useRef(T);l.useEffect(()=>{S.current!==T&&(S.current=T,R.current+=1,d(null),c([]),h(!1))},[T]);const E=async()=>{if(!y.trim())return;const v=++R.current,f=()=>v===R.current;h(!0),d(null),c([]);try{const I=await j(),L=A=>fetch(`${e}/api/v1/teams/me/chat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${A}`},body:JSON.stringify({query:y})});let b=await L(I);if(b.status===401){C();const A=await j();b=await L(A)}if(!f())return;if(!b.ok){if(b.status===402){d(F);return}d("Something went wrong.");return}const $=await b.json();if(!f())return;d($.answer??"No response received."),Array.isArray($.sources)&&!$.llm_unavailable&&c($.sources)}catch{f()&&d("Something went wrong.")}finally{f()&&h(!1)}};return n.jsxs("div",{style:{fontFamily:"system-ui, sans-serif"},children:[i&&n.jsx("p",{style:{marginTop:0,marginBottom:8,fontSize:14,color:g.text},children:i}),n.jsxs("div",{style:{display:"flex",gap:8},children:[n.jsx("input",{type:"text",value:y,onChange:v=>p(v.target.value),onKeyDown:v=>v.key==="Enter"&&E(),placeholder:x,style:{flex:1,padding:"8px 12px",borderRadius:6,border:`1px solid ${g.inputBorder}`,background:g.inputBg,color:g.inputText,fontSize:14}}),n.jsx("button",{onClick:E,disabled:m,style:{padding:"8px 16px",borderRadius:6,border:"none",background:g.sendBtnBg,color:g.sendBtnText,cursor:"pointer",fontSize:14},children:m?"…":"Ask"})]}),k&&n.jsx("div",{style:{marginTop:4,fontSize:11,color:g.textMuted},children:q(T)}),B&&n.jsx("div",{style:{marginTop:12,padding:12,borderRadius:6,background:g.cardBg,border:`1px solid ${g.border}`,color:g.text,whiteSpace:"pre-wrap",fontSize:14},children:B}),s&&w.length>0&&n.jsx(Q,{sources:w,colors:g,minScore:u}),n.jsx(V,{colors:g})]})}function Ue({chatType:e,apiUrl:t=ye,...r}){switch(e){case"floating":return n.jsx(ie,{apiUrl:t,...r});case"embedded":return n.jsx(ae,{apiUrl:t,...r});case"search":return n.jsx(ue,{apiUrl:t,...r})}}exports.CITATION_SCORE_THRESHOLD=N;exports.EmbeddedChat=ae;exports.FloatingChat=ie;exports.KnowLayerWidget=Ue;exports.SearchWidget=ue;exports.resolveTheme=O;exports.uniqueCitations=te;
package/dist/index.d.ts CHANGED
@@ -31,7 +31,8 @@ export declare interface EmbeddedChatProps {
31
31
  welcomeMessage?: string;
32
32
  /** Greeting while a user is signed in (defaults to welcomeMessage). */
33
33
  signedInWelcomeMessage?: string;
34
- theme?: "light" | "dark";
34
+ /** `"light"` | `"dark"`, or a custom hex palette: `{ primary: "#4F46E5", background: "#fff" }`. */
35
+ theme?: WidgetTheme;
35
36
  height?: string;
36
37
  className?: string;
37
38
  suggestedQuestions?: string[];
@@ -54,7 +55,8 @@ export declare interface FloatingChatProps {
54
55
  welcomeMessage?: string;
55
56
  /** Greeting while a user is signed in (defaults to welcomeMessage). */
56
57
  signedInWelcomeMessage?: string;
57
- theme?: "light" | "dark";
58
+ /** `"light"` | `"dark"`, or a custom hex palette: `{ primary: "#4F46E5", background: "#fff" }`. */
59
+ theme?: WidgetTheme;
58
60
  position?: "bottom-right" | "bottom-left";
59
61
  buttonSize?: number;
60
62
  popupWidth?: string;
@@ -82,9 +84,16 @@ export declare interface KnowLayerWidgetProps {
82
84
  /** Customer-backend mint for signed-in users. Mutually exclusive with `getFirebaseIdToken`. */
83
85
  getToken?: () => Promise<GetTokenResult>;
84
86
  getFirebaseIdToken?: () => Promise<string>;
85
- theme?: "light" | "dark";
87
+ /** `"light"` | `"dark"`, or a custom hex palette: `{ primary: "#4F46E5", background: "#fff" }`. */
88
+ theme?: WidgetTheme;
86
89
  }
87
90
 
91
+ /**
92
+ * Resolves any accepted `theme` value to a full palette. Invalid colors are
93
+ * ignored (with a console warning) so a typo never breaks the widget.
94
+ */
95
+ export declare function resolveTheme(theme?: WidgetTheme): ThemeColors;
96
+
88
97
  export declare function SearchWidget({ apiUrl, clientId, getFirebaseIdToken, getToken, welcomeMessage, placeholder, theme, showScopeHint, showCitations, citationMinScore, }: SearchWidgetProps): JSX.Element;
89
98
 
90
99
  export declare interface SearchWidgetProps {
@@ -97,7 +106,8 @@ export declare interface SearchWidgetProps {
97
106
  /** Intro text shown above the search box. */
98
107
  welcomeMessage?: string;
99
108
  placeholder?: string;
100
- theme?: "light" | "dark";
109
+ /** `"light"` | `"dark"`, or a custom hex palette: `{ primary: "#4F46E5", background: "#fff" }`. */
110
+ theme?: WidgetTheme;
101
111
  /** Show "Public documents" / "Signed in · includes your teams" under the search box. */
102
112
  showScopeHint?: boolean;
103
113
  showCitations?: boolean;
@@ -105,6 +115,69 @@ export declare interface SearchWidgetProps {
105
115
  citationMinScore?: number;
106
116
  }
107
117
 
118
+ export declare interface ThemeColors {
119
+ bg: string;
120
+ cardBg: string;
121
+ border: string;
122
+ text: string;
123
+ textMuted: string;
124
+ primary: string;
125
+ primaryText: string;
126
+ inputBg: string;
127
+ userBubbleBg: string;
128
+ userBubbleText: string;
129
+ assistantBubbleBg: string;
130
+ assistantBubbleText: string;
131
+ headerBg: string;
132
+ headerText: string;
133
+ dot: string;
134
+ launcherBg: string;
135
+ launcherIcon: string;
136
+ sendBtnBg: string;
137
+ sendBtnText: string;
138
+ inputText: string;
139
+ inputBorder: string;
140
+ }
141
+
142
+ /**
143
+ * Custom theme. Every color is a hex string (`#rgb` or `#rrggbb`) and every
144
+ * key is optional.
145
+ *
146
+ * Quick start: set `primary` (and optionally `background` / `text`) and the rest
147
+ * is derived, including readable text on top of colored surfaces. Then use the
148
+ * per-region keys below to override exactly the parts you care about; those
149
+ * always win over the derived values.
150
+ */
151
+ export declare interface ThemeConfig {
152
+ /** Base palette to start from. Inferred from `background` when omitted. */
153
+ mode?: ThemeMode;
154
+ /** Accent for launcher, send button and your message bubbles. */
155
+ primary?: string;
156
+ /** Surface for the chat panel, header and input. */
157
+ background?: string;
158
+ /** Main text color. */
159
+ text?: string;
160
+ launcherBackground?: string;
161
+ launcherIcon?: string;
162
+ headerBackground?: string;
163
+ headerText?: string;
164
+ /** Background of the chat panel / message area. */
165
+ chatBackground?: string;
166
+ userBubbleBackground?: string;
167
+ userBubbleText?: string;
168
+ botBubbleBackground?: string;
169
+ botBubbleText?: string;
170
+ sendButtonBackground?: string;
171
+ sendButtonIcon?: string;
172
+ inputBackground?: string;
173
+ inputText?: string;
174
+ inputBorder?: string;
175
+ /** Other lines and dividers. */
176
+ borderColor?: string;
177
+ }
178
+
179
+ export declare type ThemeMode = "light" | "dark";
180
+
108
181
  /** One citation per document per team. Keeps the highest-scoring chunk when several match. */
109
182
  export declare function uniqueCitations(sources: ChatSource[], { minScore }?: UniqueCitationsOptions): ChatSource[];
110
183
 
@@ -116,6 +189,9 @@ declare interface UniqueCitationsOptions {
116
189
  /** Which credential the widget is currently using. Changes when the host signs a user in or out. */
117
190
  export declare type WidgetAuthMode = "public" | "firebase" | "getToken";
118
191
 
192
+ /** `"light"` / `"dark"` presets, or a custom {@link ThemeConfig}. */
193
+ export declare type WidgetTheme = ThemeMode | ThemeConfig;
194
+
119
195
  declare type WidgetTokenResponse = {
120
196
  token?: string;
121
197
  access_token?: string;