@brainbase-labs/chat-widget 0.1.17 → 0.1.18

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.cjs CHANGED
@@ -14,4 +14,4 @@
14
14
  `});++r<e.length;)r&&t.push({type:"text",value:`
15
15
  `}),t.push(e[r]);return n&&e.length>0&&t.push({type:"text",value:`
16
16
  `}),t}function Mt(e){let n=0,t=e.charCodeAt(n);for(;t===9||t===32;)n++,t=e.charCodeAt(n);return e.slice(n)}function Dt(e,n){const t=Qa(e,n),r=t.one(e,void 0),i=Ra(t),l=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&l.children.push({type:"text",value:`
17
- `},i),l}function ns(e,n){return e&&"run"in e?async function(t,r){const i=Dt(t,{file:r,...n});await e.run(i,r)}:function(t,r){return Dt(t,{file:r,...e||n})}}function Bt(e){if(e)throw e}var kn,Ot;function ts(){if(Ot)return kn;Ot=1;var e=Object.prototype.hasOwnProperty,n=Object.prototype.toString,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(s){return typeof Array.isArray=="function"?Array.isArray(s):n.call(s)==="[object Array]"},l=function(s){if(!s||n.call(s)!=="[object Object]")return!1;var u=e.call(s,"constructor"),p=s.constructor&&s.constructor.prototype&&e.call(s.constructor.prototype,"isPrototypeOf");if(s.constructor&&!u&&!p)return!1;var m;for(m in s);return typeof m>"u"||e.call(s,m)},o=function(s,u){t&&u.name==="__proto__"?t(s,u.name,{enumerable:!0,configurable:!0,value:u.newValue,writable:!0}):s[u.name]=u.newValue},a=function(s,u){if(u==="__proto__")if(e.call(s,u)){if(r)return r(s,u).value}else return;return s[u]};return kn=function c(){var s,u,p,m,h,S,I=arguments[0],E=1,b=arguments.length,P=!1;for(typeof I=="boolean"&&(P=I,I=arguments[1]||{},E=2),(I==null||typeof I!="object"&&typeof I!="function")&&(I={});E<b;++E)if(s=arguments[E],s!=null)for(u in s)p=a(I,u),m=a(s,u),I!==m&&(P&&m&&(l(m)||(h=i(m)))?(h?(h=!1,S=p&&i(p)?p:[]):S=p&&l(p)?p:{},o(I,{name:u,newValue:c(P,S,m)})):typeof m<"u"&&o(I,{name:u,newValue:m}));return I},kn}var rs=ts();const bn=rr(rs);function Bn(e){if(typeof e!="object"||e===null)return!1;const n=Object.getPrototypeOf(e);return(n===null||n===Object.prototype||Object.getPrototypeOf(n)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function is(){const e=[],n={run:t,use:r};return n;function t(...i){let l=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(c,...s){const u=e[++l];let p=-1;if(c){o(c);return}for(;++p<i.length;)(s[p]===null||s[p]===void 0)&&(s[p]=i[p]);i=s,u?ls(u,a)(...s):o(null,...s)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),n}}function ls(e,n){let t;return r;function r(...o){const a=e.length>o.length;let c;a&&o.push(i);try{c=e.apply(this,o)}catch(s){const u=s;if(a&&t)throw u;return i(u)}a||(c&&c.then&&typeof c.then=="function"?c.then(l,i):c instanceof Error?i(c):l(c))}function i(o,...a){t||(t=!0,n(o,...a))}function l(o){i(null,o)}}const me={basename:os,dirname:as,extname:ss,join:us,sep:"/"};function os(e,n){if(n!==void 0&&typeof n!="string")throw new TypeError('"ext" argument must be a string');Ge(e);let t=0,r=-1,i=e.length,l;if(n===void 0||n.length===0||n.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(l){t=i+1;break}}else r<0&&(l=!0,r=i+1);return r<0?"":e.slice(t,r)}if(n===e)return"";let o=-1,a=n.length-1;for(;i--;)if(e.codePointAt(i)===47){if(l){t=i+1;break}}else o<0&&(l=!0,o=i+1),a>-1&&(e.codePointAt(i)===n.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return t===r?r=o:r<0&&(r=e.length),e.slice(t,r)}function as(e){if(Ge(e),e.length===0)return".";let n=-1,t=e.length,r;for(;--t;)if(e.codePointAt(t)===47){if(r){n=t;break}}else r||(r=!0);return n<0?e.codePointAt(0)===47?"/":".":n===1&&e.codePointAt(0)===47?"//":e.slice(0,n)}function ss(e){Ge(e);let n=e.length,t=-1,r=0,i=-1,l=0,o;for(;n--;){const a=e.codePointAt(n);if(a===47){if(o){r=n+1;break}continue}t<0&&(o=!0,t=n+1),a===46?i<0?i=n:l!==1&&(l=1):i>-1&&(l=-1)}return i<0||t<0||l===0||l===1&&i===t-1&&i===r+1?"":e.slice(i,t)}function us(...e){let n=-1,t;for(;++n<e.length;)Ge(e[n]),e[n]&&(t=t===void 0?e[n]:t+"/"+e[n]);return t===void 0?".":cs(t)}function cs(e){Ge(e);const n=e.codePointAt(0)===47;let t=ps(e,!n);return t.length===0&&!n&&(t="."),t.length>0&&e.codePointAt(e.length-1)===47&&(t+="/"),n?"/"+t:t}function ps(e,n){let t="",r=0,i=-1,l=0,o=-1,a,c;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||l===1))if(i!==o-1&&l===2){if(t.length<2||r!==2||t.codePointAt(t.length-1)!==46||t.codePointAt(t.length-2)!==46){if(t.length>2){if(c=t.lastIndexOf("/"),c!==t.length-1){c<0?(t="",r=0):(t=t.slice(0,c),r=t.length-1-t.lastIndexOf("/")),i=o,l=0;continue}}else if(t.length>0){t="",r=0,i=o,l=0;continue}}n&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+e.slice(i+1,o):t=e.slice(i+1,o),r=o-i-1;i=o,l=0}else a===46&&l>-1?l++:l=-1}return t}function Ge(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const hs={cwd:fs};function fs(){return"/"}function On(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function ds(e){if(typeof e=="string")e=new URL(e);else if(!On(e)){const n=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw n.code="ERR_INVALID_ARG_TYPE",n}if(e.protocol!=="file:"){const n=new TypeError("The URL must be of scheme file");throw n.code="ERR_INVALID_URL_SCHEME",n}return ms(e)}function ms(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const n=e.pathname;let t=-1;for(;++t<n.length;)if(n.codePointAt(t)===37&&n.codePointAt(t+1)===50){const r=n.codePointAt(t+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(n)}const wn=["history","path","basename","stem","extname","dirname"];class Pr{constructor(n){let t;n?On(n)?t={path:n}:typeof n=="string"||gs(n)?t={value:n}:t=n:t={},this.cwd="cwd"in t?"":hs.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<wn.length;){const l=wn[r];l in t&&t[l]!==void 0&&t[l]!==null&&(this[l]=l==="history"?[...t[l]]:t[l])}let i;for(i in t)wn.includes(i)||(this[i]=t[i])}get basename(){return typeof this.path=="string"?me.basename(this.path):void 0}set basename(n){Sn(n,"basename"),Cn(n,"basename"),this.path=me.join(this.dirname||"",n)}get dirname(){return typeof this.path=="string"?me.dirname(this.path):void 0}set dirname(n){Rt(this.basename,"dirname"),this.path=me.join(n||"",this.basename)}get extname(){return typeof this.path=="string"?me.extname(this.path):void 0}set extname(n){if(Cn(n,"extname"),Rt(this.dirname,"extname"),n){if(n.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(n.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=me.join(this.dirname,this.stem+(n||""))}get path(){return this.history[this.history.length-1]}set path(n){On(n)&&(n=ds(n)),Sn(n,"path"),this.path!==n&&this.history.push(n)}get stem(){return typeof this.path=="string"?me.basename(this.path,this.extname):void 0}set stem(n){Sn(n,"stem"),Cn(n,"stem"),this.path=me.join(this.dirname||"",n+(this.extname||""))}fail(n,t,r){const i=this.message(n,t,r);throw i.fatal=!0,i}info(n,t,r){const i=this.message(n,t,r);return i.fatal=void 0,i}message(n,t,r){const i=new te(n,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(n){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(n||void 0).decode(this.value)}}function Cn(e,n){if(e&&e.includes(me.sep))throw new Error("`"+n+"` cannot be a path: did not expect `"+me.sep+"`")}function Sn(e,n){if(!e)throw new Error("`"+n+"` cannot be empty")}function Rt(e,n){if(!e)throw new Error("Setting `"+n+"` requires `path` to be set too")}function gs(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const ys=(function(e){const r=this.constructor.prototype,i=r[e],l=function(){return i.apply(l,arguments)};return Object.setPrototypeOf(l,r),l}),xs={}.hasOwnProperty;class et extends ys{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=is()}copy(){const n=new et;let t=-1;for(;++t<this.attachers.length;){const r=this.attachers[t];n.use(...r)}return n.data(bn(!0,{},this.namespace)),n}data(n,t){return typeof n=="string"?arguments.length===2?(En("data",this.frozen),this.namespace[n]=t,this):xs.call(this.namespace,n)&&this.namespace[n]||void 0:n?(En("data",this.frozen),this.namespace=n,this):this.namespace}freeze(){if(this.frozen)return this;const n=this;for(;++this.freezeIndex<this.attachers.length;){const[t,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=t.call(n,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(n){this.freeze();const t=rn(n),r=this.parser||this.Parser;return _n("parse",r),r(String(t),t)}process(n,t){const r=this;return this.freeze(),_n("process",this.parser||this.Parser),In("process",this.compiler||this.Compiler),t?i(void 0,t):new Promise(i);function i(l,o){const a=rn(n),c=r.parse(a);r.run(c,a,function(u,p,m){if(u||!p||!m)return s(u);const h=p,S=r.stringify(h,m);ws(S)?m.value=S:m.result=S,s(u,m)});function s(u,p){u||!p?o(u):l?l(p):t(void 0,p)}}}processSync(n){let t=!1,r;return this.freeze(),_n("processSync",this.parser||this.Parser),In("processSync",this.compiler||this.Compiler),this.process(n,i),$t("processSync","process",t),r;function i(l,o){t=!0,Bt(l),r=o}}run(n,t,r){Ft(n),this.freeze();const i=this.transformers;return!r&&typeof t=="function"&&(r=t,t=void 0),r?l(void 0,r):new Promise(l);function l(o,a){const c=rn(t);i.run(n,c,s);function s(u,p,m){const h=p||n;u?a(u):o?o(h):r(void 0,h,m)}}}runSync(n,t){let r=!1,i;return this.run(n,t,l),$t("runSync","run",r),i;function l(o,a){Bt(o),i=a,r=!0}}stringify(n,t){this.freeze();const r=rn(t),i=this.compiler||this.Compiler;return In("stringify",i),Ft(n),i(n,r)}use(n,...t){const r=this.attachers,i=this.namespace;if(En("use",this.frozen),n!=null)if(typeof n=="function")c(n,t);else if(typeof n=="object")Array.isArray(n)?a(n):o(n);else throw new TypeError("Expected usable value, not `"+n+"`");return this;function l(s){if(typeof s=="function")c(s,[]);else if(typeof s=="object")if(Array.isArray(s)){const[u,...p]=s;c(u,p)}else o(s);else throw new TypeError("Expected usable value, not `"+s+"`")}function o(s){if(!("plugins"in s)&&!("settings"in s))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(s.plugins),s.settings&&(i.settings=bn(!0,i.settings,s.settings))}function a(s){let u=-1;if(s!=null)if(Array.isArray(s))for(;++u<s.length;){const p=s[u];l(p)}else throw new TypeError("Expected a list of plugins, not `"+s+"`")}function c(s,u){let p=-1,m=-1;for(;++p<r.length;)if(r[p][0]===s){m=p;break}if(m===-1)r.push([s,...u]);else if(u.length>0){let[h,...S]=u;const I=r[m][1];Bn(I)&&Bn(h)&&(h=bn(!0,I,h)),r[m]=[s,h,...S]}}}}const ks=new et().freeze();function _n(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function In(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function En(e,n){if(n)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Ft(e){if(!Bn(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function $t(e,n,t){if(!t)throw new Error("`"+e+"` finished async. Use `"+n+"` instead")}function rn(e){return bs(e)?e:new Pr(e)}function bs(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function ws(e){return typeof e=="string"||Cs(e)}function Cs(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Ss="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Ht=[],Vt={allowDangerousHtml:!0},_s=/^(https?|ircs?|mailto|xmpp)$/i,Is=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Es(e){const n=vs(e),t=Ts(e);return Ls(n.runSync(n.parse(t),t),e)}function vs(e){const n=e.rehypePlugins||Ht,t=e.remarkPlugins||Ht,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Vt}:Vt;return ks().use(oa).use(t).use(ns,r).use(n)}function Ts(e){const n=e.children||"",t=new Pr;return typeof n=="string"&&(t.value=n),t}function Ls(e,n){const t=n.allowedElements,r=n.allowElement,i=n.components,l=n.disallowedElements,o=n.skipHtml,a=n.unwrapDisallowed,c=n.urlTransform||Ns;for(const u of Is)Object.hasOwn(n,u.from)&&(""+u.from+(u.to?"use `"+u.to+"` instead":"remove it")+Ss+u.id,void 0);return Nr(e,s),Oi(e,{Fragment:g.Fragment,components:i,ignoreInvalidStyle:!0,jsx:g.jsx,jsxs:g.jsxs,passKeys:!0,passNode:!0});function s(u,p,m){if(u.type==="raw"&&m&&typeof p=="number")return o?m.children.splice(p,1):m.children[p]={type:"text",value:u.value},p;if(u.type==="element"){let h;for(h in gn)if(Object.hasOwn(gn,h)&&Object.hasOwn(u.properties,h)){const S=u.properties[h],I=gn[h];(I===null||I.includes(u.tagName))&&(u.properties[h]=c(String(S||""),h,u))}}if(u.type==="element"){let h=t?!t.includes(u.tagName):l?l.includes(u.tagName):!1;if(!h&&r&&typeof p=="number"&&(h=!r(u,p,m)),h&&m&&typeof p=="number")return a&&u.children?m.children.splice(p,1,...u.children):m.children.splice(p,1),p}}}function Ns(e){const n=e.indexOf(":"),t=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return n===-1||i!==-1&&n>i||t!==-1&&n>t||r!==-1&&n>r||_s.test(e.slice(0,n))?e:""}const Ps="_messageWrapper_1thak_1",As="_user_1thak_19",js="_assistant_1thak_24",zs="_avatar_1thak_28",Ms="_avatarPlaceholder_1thak_43",Ds="_brainbaseLogo_1thak_53",Bs="_messageBubble_1thak_58",Os="_error_1thak_76",Rs="_content_1thak_81",Fs="_markdown_1thak_92",$s="_cursor_1thak_183",Hs="_errorIndicator_1thak_202",ce={messageWrapper:Ps,user:As,assistant:js,avatar:zs,avatarPlaceholder:Ms,brainbaseLogo:Ds,messageBubble:Bs,error:Os,content:Rs,markdown:Fs,cursor:$s,errorIndicator:Hs},Ar=({message:e,agentName:n,agentLogoUrl:t})=>{const r=e.role==="user",i=e.status==="streaming",l=e.status==="error";return g.jsxs("div",{className:`${ce.messageWrapper} ${r?ce.user:ce.assistant}`,children:[!r&&g.jsx("div",{className:ce.avatar,children:t?g.jsx("img",{src:t,alt:n||"AI"}):g.jsx("div",{className:ce.avatarPlaceholder,children:g.jsx(Qe,{className:ce.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),g.jsxs("div",{className:`${ce.messageBubble} ${l?ce.error:""}`,role:"article","aria-label":`${r?"Your message":`${n||"AI"} says`}`,children:[g.jsxs("div",{className:`${ce.content} ${r?"":ce.markdown}`,children:[r?e.content:g.jsx(Es,{components:{a:({href:o,children:a})=>o?g.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",children:a}):g.jsx(g.Fragment,{children:a})},children:e.content}),i&&g.jsx("span",{className:ce.cursor})]}),l&&g.jsxs("div",{className:ce.errorIndicator,children:[g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",children:[g.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2"}),g.jsx("path",{d:"M12 8V12M12 16H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),g.jsx("span",{children:"Failed to send"})]})]})]})},Vs="_toolCall_1wby1_1",Us="_iconWrapper_1wby1_24",qs="_spinner_1wby1_33",Ws="_checkIcon_1wby1_48",Ys="_errorIcon_1wby1_54",Xs="_content_1wby1_60",Ks="_label_1wby1_66",Qs="_name_1wby1_73",Zs="_pending_1wby1_78",Js="_completed_1wby1_82",Gs="_error_1wby1_54",de={toolCall:Vs,iconWrapper:Us,spinner:qs,checkIcon:Ws,errorIcon:Ys,content:Xs,label:Ks,name:Qs,pending:Zs,completed:Js,error:Gs},jr=({toolCall:e})=>{const n=e.status==="pending"||e.status==="executing",t=e.status==="completed",r=e.status==="error",i=l=>l.replace(/_/g," ").replace(/([A-Z])/g," $1").trim().toLowerCase().replace(/^./,o=>o.toUpperCase());return g.jsxs("div",{className:`${de.toolCall} ${n?de.pending:""} ${t?de.completed:""} ${r?de.error:""}`,children:[g.jsx("div",{className:de.iconWrapper,children:n?g.jsx("div",{className:de.spinner}):t?g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:de.checkIcon,children:g.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:de.errorIcon,children:g.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),g.jsxs("div",{className:de.content,children:[g.jsx("span",{className:de.label,children:n?"Running":t?"Completed":"Failed"}),g.jsx("span",{className:de.name,children:i(e.name)})]})]})},eu="_wrapper_10rss_2",nu="_avatar_10rss_22",tu="_avatarPlaceholder_10rss_37",ru="_brainbaseLogo_10rss_47",iu="_bubble_10rss_52",lu="_dot_10rss_63",Ce={wrapper:eu,avatar:nu,avatarPlaceholder:tu,brainbaseLogo:ru,bubble:iu,dot:lu},zr=({agentName:e="AI",agentLogoUrl:n})=>g.jsxs("div",{className:Ce.wrapper,role:"status","aria-label":`${e} is typing`,children:[g.jsx("div",{className:Ce.avatar,children:n?g.jsx("img",{src:n,alt:e}):g.jsx("div",{className:Ce.avatarPlaceholder,children:g.jsx(Qe,{className:Ce.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),g.jsxs("div",{className:Ce.bubble,children:[g.jsx("span",{className:Ce.dot}),g.jsx("span",{className:Ce.dot}),g.jsx("span",{className:Ce.dot})]})]}),ou="_messageList_241kk_1",au="_emptyState_241kk_29",su="_emptyIcon_241kk_40",uu="_emptyText_241kk_52",ln={messageList:ou,emptyState:au,emptyIcon:su,emptyText:uu},Mr=({messages:e,toolCalls:n=[],isLoading:t,agentName:r,agentLogoUrl:i})=>{var c;const l=O.useRef(null),o=O.useRef(null);O.useEffect(()=>{var s;(s=o.current)==null||s.scrollIntoView({behavior:"smooth"})},[e,n,t]);const a=n.filter(s=>s.status==="pending"||s.status==="executing");return g.jsxs("div",{className:ln.messageList,ref:l,role:"log","aria-live":"polite",children:[e.length===0&&!t&&g.jsxs("div",{className:ln.emptyState,children:[g.jsx("div",{className:ln.emptyIcon,children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),g.jsx("p",{className:ln.emptyText,children:"Start a conversation"})]}),e.map(s=>g.jsx(Ar,{message:s,agentName:r,agentLogoUrl:i},s.id)),a.map(s=>g.jsx(jr,{toolCall:s},s.id)),t&&((c=e[e.length-1])==null?void 0:c.role)==="user"&&g.jsx(zr,{agentName:r,agentLogoUrl:i}),g.jsx("div",{ref:o})]})},cu="_inputWrapper_5lgg7_1",pu="_inputContainer_5lgg7_7",hu="_textarea_5lgg7_23",fu="_sendButton_5lgg7_50",du="_hint_5lgg7_89",We={inputWrapper:cu,inputContainer:pu,textarea:hu,sendButton:fu,hint:du},Dr=({onSend:e,disabled:n=!1,placeholder:t="Send a message..."})=>{const[r,i]=O.useState(""),l=O.useRef(null),o=O.useCallback(()=>{const s=l.current;s&&(s.style.height="auto",s.style.height=`${Math.min(s.scrollHeight,150)}px`)},[]);O.useEffect(()=>{o()},[r,o]);const a=O.useCallback(s=>{s==null||s.preventDefault();const u=r.trim();u&&!n&&(e(u),i(""),l.current&&(l.current.style.height="auto"))},[r,n,e]),c=O.useCallback(s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),a())},[a]);return g.jsxs("form",{className:We.inputWrapper,onSubmit:a,children:[g.jsxs("div",{className:We.inputContainer,children:[g.jsx("textarea",{ref:l,className:We.textarea,value:r,onChange:s=>i(s.target.value),onKeyDown:c,placeholder:t,disabled:n,rows:1,"aria-label":"Message input"}),g.jsx("button",{type:"submit",className:We.sendButton,disabled:n||!r.trim(),"aria-label":"Send message",children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),g.jsxs("div",{className:We.hint,children:["Press ",g.jsx("kbd",{children:"Enter"})," to send, ",g.jsx("kbd",{children:"Shift + Enter"})," for new line"]})]})},mu="_poweredBy_9jh5q_1",gu="_logo_9jh5q_20",yu="_poweredText_9jh5q_24",xu="_text_9jh5q_36",on={poweredBy:mu,logo:gu,poweredText:yu,text:xu},ku=({className:e})=>g.jsxs("svg",{className:e,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:"currentColor"}),g.jsx("circle",{cx:"400",cy:"400",r:"400",fill:"currentColor"}),g.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:"currentColor"}),g.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:"currentColor"}),g.jsx("circle",{cx:"400",cy:"400",r:"350",fill:"currentColor"}),g.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:"currentColor"}),g.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:"var(--bb-surface-bg, #ffffff)"})]}),bu=({showBranding:e=!0})=>e?g.jsxs("a",{href:"https://brainbaselabs.com/",target:"_blank",rel:"noopener noreferrer",className:on.poweredBy,"aria-label":"Powered by Brainbase Labs",children:[g.jsx("span",{className:on.poweredText,children:"Powered by"}),g.jsx(ku,{className:on.logo}),g.jsx("span",{className:on.text,children:"Brainbase Labs"})]}):null,wu="_container_m2o9l_1",Cu="_body_m2o9l_26",Su="_confirmationOverlay_m2o9l_35",_u="_confirmationDialog_m2o9l_56",Iu="_confirmationText_m2o9l_78",Eu="_confirmationButtons_m2o9l_86",vu="_cancelButton_m2o9l_91",Tu="_confirmButton_m2o9l_92",Se={container:wu,body:Cu,confirmationOverlay:Su,confirmationDialog:_u,confirmationText:Iu,confirmationButtons:Eu,cancelButton:vu,confirmButton:Tu},Br=({config:e,messages:n,toolCalls:t=[],isLoading:r,onSendMessage:i,onClose:l,onNewChat:o})=>{var h;const[a,c]=O.useState(!1),s=n.length>0,u=()=>{c(!0)},p=()=>{c(!1),o==null||o()},m=()=>{c(!1)};return g.jsxs("div",{className:Se.container,role:"dialog","aria-label":"Chat window",children:[g.jsx(Kt,{agentName:e.agentName,agentLogoUrl:e.agentLogoUrl,welcomeTitle:e.welcomeMessage||"Hello there.",welcomeSubtitle:e.welcomeMessage?void 0:"How can we help?",onClose:l,onNewChatRequest:u,showNewChatButton:s,compact:s}),g.jsxs("div",{className:Se.body,children:[g.jsx(Mr,{messages:n,toolCalls:t,isLoading:r,agentName:e.agentName,agentLogoUrl:e.agentLogoUrl}),g.jsx(Dr,{onSend:i,disabled:r,placeholder:"Ask a question..."})]}),g.jsx(bu,{showBranding:((h=e.styling)==null?void 0:h.showBranding)??!0}),a&&g.jsx("div",{className:Se.confirmationOverlay,children:g.jsxs("div",{className:Se.confirmationDialog,children:[g.jsx("p",{className:Se.confirmationText,children:"End current chat and start a new conversation?"}),g.jsxs("div",{className:Se.confirmationButtons,children:[g.jsx("button",{className:Se.cancelButton,onClick:m,type:"button",children:"Cancel"}),g.jsx("button",{className:Se.confirmButton,onClick:p,type:"button",children:"End Chat"})]})]})})]})},Lu="_toggleButton_11dqz_1",Nu="_icon_11dqz_31",Pu="_agentLogo_11dqz_36",Au="_unreadBadge_11dqz_43",an={toggleButton:Lu,icon:Nu,agentLogo:Pu,unreadBadge:Au},Rn=({onClick:e,agentLogoUrl:n,unreadCount:t=0})=>g.jsxs("button",{className:an.toggleButton,onClick:e,"aria-label":"Open chat",type:"button",children:[n?g.jsx("img",{src:n,alt:"",className:an.agentLogo}):g.jsx("svg",{className:an.icon,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:g.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),t>0&&g.jsx("span",{className:an.unreadBadge,children:t>9?"9+":t})]}),ju="_container_kgfgt_1",zu="_header_kgfgt_25",Mu="_logoWrapper_kgfgt_38",Du="_logo_kgfgt_38",Bu="_closeButton_kgfgt_51",Ou="_content_kgfgt_74",Ru="_iconWrapper_kgfgt_84",Fu="_errorIcon_kgfgt_95",$u="_title_kgfgt_101",Hu="_description_kgfgt_109",Vu="_retryButton_kgfgt_117",Uu="_footer_kgfgt_139",qu="_poweredBy_kgfgt_146",Wu="_footerLogo_kgfgt_160",ne={container:ju,header:zu,logoWrapper:Mu,logo:Du,closeButton:Bu,content:Ou,iconWrapper:Ru,errorIcon:Fu,title:$u,description:Hu,retryButton:Vu,footer:Uu,poweredBy:qu,footerLogo:Wu},Yu=({errorType:e,message:n,onRetry:t,onClose:r})=>{const i=()=>{switch(e){case"not_found":return{title:"Chat Not Found",description:n||"This chat widget is not configured correctly. Please check the embed ID.",icon:g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:[g.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5"}),g.jsx("path",{d:"M12 7V13M12 16V16.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};case"network":return{title:"Connection Error",description:n||"Unable to connect to the chat service. Please check your internet connection.",icon:g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:[g.jsx("path",{d:"M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z",stroke:"currentColor",strokeWidth:"1.5"}),g.jsx("path",{d:"M8 15L16 9M8 9L16 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};default:return{title:"Something Went Wrong",description:n||"An unexpected error occurred. Please try again later.",icon:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:g.jsx("path",{d:"M12 9V13M12 17H12.01M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}}},{title:l,description:o,icon:a}=i();return g.jsxs("div",{className:ne.container,children:[g.jsxs("div",{className:ne.header,children:[g.jsx("div",{className:ne.logoWrapper,children:g.jsx(Qe,{className:ne.logo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),r&&g.jsx("button",{className:ne.closeButton,onClick:r,"aria-label":"Close",type:"button",children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),g.jsxs("div",{className:ne.content,children:[g.jsx("div",{className:ne.iconWrapper,children:a}),g.jsx("h2",{className:ne.title,children:l}),g.jsx("p",{className:ne.description,children:o}),t&&g.jsx("button",{className:ne.retryButton,onClick:t,type:"button",children:"Try Again"})]}),g.jsx("div",{className:ne.footer,children:g.jsxs("a",{href:"https://brainbaselabs.com",target:"_blank",rel:"noopener noreferrer",className:ne.poweredBy,children:["Powered by"," ",g.jsx(Qe,{className:ne.footerLogo,color:"var(--bb-text-tertiary)",cutoutColor:"var(--bb-surface-bg)"}),g.jsx("span",{children:"Brainbase Labs"})]})})]})},Xu="_widget_1ehud_1",Ku="_inline_1ehud_25",je={widget:Xu,"bottom-right":"_bottom-right_1ehud_10","bottom-left":"_bottom-left_1ehud_17",inline:Ku},Qu=({embedId:e,apiBaseUrl:n=Wt,mockMode:t=!1,mockResponses:r,position:i="bottom-right",defaultOpen:l=!1,primaryColor:o,agentName:a,agentLogoUrl:c,welcomeMessage:s,showBranding:u,className:p,onSessionStart:m,onSessionEnd:h,onMessage:S,onError:I})=>{const[E,b]=O.useState(l),[P,v]=O.useState(null),[R,V]=O.useState(!0),[k,D]=O.useState(null),[U,F]=O.useState(),$=O.useRef(!1),N=O.useMemo(()=>t?Xt({},r):Yt(n),[t,r,n]),C=O.useCallback(async()=>{if(!($.current&&P)){V(!0),D(null),F(void 0);try{const f=await N.getDeploymentConfig(e);v(f),$.current=!0}catch(f){const J=f instanceof Error?f:new Error("Failed to load config");J.message.includes("404")?(D("not_found"),F("The chat widget with this embed ID was not found.")):J.message.includes("Failed to fetch")||J.message.includes("network")?D("network"):D("unknown"),t&&(v({embedId:e,deploymentId:"mock-deployment",workerId:"mock-worker",flowId:"mock-flow",primaryColor:"#1a1a2e",agentName:"AI Assistant",styling:{}}),D(null),$.current=!0),I==null||I(J)}finally{V(!1)}}},[e,t,N,I,P]);O.useEffect(()=>{$.current=!1,C()},[e,t,N]);const j=O.useMemo(()=>{const f=P??{embedId:e,deploymentId:"",workerId:"",flowId:""};return{...f,primaryColor:o??f.primaryColor??"#1a1a2e",agentName:a??f.agentName,agentLogoUrl:c??f.agentLogoUrl,welcomeMessage:s??f.welcomeMessage,styling:{...f.styling??{},...u!==void 0?{showBranding:u}:{}}}},[P,e,o,a,c,s,u]),T=qt({config:j,apiClient:N,mockMode:t,onSessionStart:m,onSessionEnd:h,onMessage:S,onError:I}),x=O.useMemo(()=>({"--bb-primary-color":j.primaryColor??"#1a1a2e"}),[j.primaryColor]),A=()=>{T.endSession(),T.startNewSession()},L=()=>{b(!1)},q=()=>{C()},Q=i==="inline";return R?null:k&&!t?!Q&&!E?g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:g.jsx(Rn,{onClick:()=>b(!0),agentName:a})}):g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:g.jsx(Yu,{errorType:k,message:U,onRetry:q,onClose:Q?void 0:L})}):g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:E||Q?g.jsx(Br,{config:j,messages:T.messages,isLoading:T.isLoading,onSendMessage:T.sendMessage,onClose:Q?void 0:L,onNewChat:A}):g.jsx(Rn,{onClick:()=>b(!0),agentName:j.agentName,agentLogoUrl:j.agentLogoUrl})})};function Zu(){if(typeof crypto<"u"&&crypto.randomUUID)return`bb-${crypto.randomUUID()}`;const e=Date.now().toString(36),n=Math.random().toString(36).substring(2,15),t=Math.random().toString(36).substring(2,15);return`bb-${e}-${n}${t}`}exports.ChatContainer=Br;exports.ChatHeader=Kt;exports.ChatToggleButton=Rn;exports.ChatWidget=Qu;exports.Message=Ar;exports.MessageInput=Dr;exports.MessageList=Mr;exports.ToolCallDisplay=jr;exports.TypingIndicator=zr;exports.clearSession=Tn;exports.createAPIClient=Yt;exports.createMockAPIClient=Xt;exports.generateSessionId=Zu;exports.getStoredSession=Ut;exports.storeSession=vn;exports.useChat=qt;
17
+ `},i),l}function ns(e,n){return e&&"run"in e?async function(t,r){const i=Dt(t,{file:r,...n});await e.run(i,r)}:function(t,r){return Dt(t,{file:r,...e||n})}}function Bt(e){if(e)throw e}var kn,Ot;function ts(){if(Ot)return kn;Ot=1;var e=Object.prototype.hasOwnProperty,n=Object.prototype.toString,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(s){return typeof Array.isArray=="function"?Array.isArray(s):n.call(s)==="[object Array]"},l=function(s){if(!s||n.call(s)!=="[object Object]")return!1;var u=e.call(s,"constructor"),p=s.constructor&&s.constructor.prototype&&e.call(s.constructor.prototype,"isPrototypeOf");if(s.constructor&&!u&&!p)return!1;var m;for(m in s);return typeof m>"u"||e.call(s,m)},o=function(s,u){t&&u.name==="__proto__"?t(s,u.name,{enumerable:!0,configurable:!0,value:u.newValue,writable:!0}):s[u.name]=u.newValue},a=function(s,u){if(u==="__proto__")if(e.call(s,u)){if(r)return r(s,u).value}else return;return s[u]};return kn=function c(){var s,u,p,m,h,S,I=arguments[0],E=1,b=arguments.length,P=!1;for(typeof I=="boolean"&&(P=I,I=arguments[1]||{},E=2),(I==null||typeof I!="object"&&typeof I!="function")&&(I={});E<b;++E)if(s=arguments[E],s!=null)for(u in s)p=a(I,u),m=a(s,u),I!==m&&(P&&m&&(l(m)||(h=i(m)))?(h?(h=!1,S=p&&i(p)?p:[]):S=p&&l(p)?p:{},o(I,{name:u,newValue:c(P,S,m)})):typeof m<"u"&&o(I,{name:u,newValue:m}));return I},kn}var rs=ts();const bn=rr(rs);function Bn(e){if(typeof e!="object"||e===null)return!1;const n=Object.getPrototypeOf(e);return(n===null||n===Object.prototype||Object.getPrototypeOf(n)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function is(){const e=[],n={run:t,use:r};return n;function t(...i){let l=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(c,...s){const u=e[++l];let p=-1;if(c){o(c);return}for(;++p<i.length;)(s[p]===null||s[p]===void 0)&&(s[p]=i[p]);i=s,u?ls(u,a)(...s):o(null,...s)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),n}}function ls(e,n){let t;return r;function r(...o){const a=e.length>o.length;let c;a&&o.push(i);try{c=e.apply(this,o)}catch(s){const u=s;if(a&&t)throw u;return i(u)}a||(c&&c.then&&typeof c.then=="function"?c.then(l,i):c instanceof Error?i(c):l(c))}function i(o,...a){t||(t=!0,n(o,...a))}function l(o){i(null,o)}}const me={basename:os,dirname:as,extname:ss,join:us,sep:"/"};function os(e,n){if(n!==void 0&&typeof n!="string")throw new TypeError('"ext" argument must be a string');Ge(e);let t=0,r=-1,i=e.length,l;if(n===void 0||n.length===0||n.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(l){t=i+1;break}}else r<0&&(l=!0,r=i+1);return r<0?"":e.slice(t,r)}if(n===e)return"";let o=-1,a=n.length-1;for(;i--;)if(e.codePointAt(i)===47){if(l){t=i+1;break}}else o<0&&(l=!0,o=i+1),a>-1&&(e.codePointAt(i)===n.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return t===r?r=o:r<0&&(r=e.length),e.slice(t,r)}function as(e){if(Ge(e),e.length===0)return".";let n=-1,t=e.length,r;for(;--t;)if(e.codePointAt(t)===47){if(r){n=t;break}}else r||(r=!0);return n<0?e.codePointAt(0)===47?"/":".":n===1&&e.codePointAt(0)===47?"//":e.slice(0,n)}function ss(e){Ge(e);let n=e.length,t=-1,r=0,i=-1,l=0,o;for(;n--;){const a=e.codePointAt(n);if(a===47){if(o){r=n+1;break}continue}t<0&&(o=!0,t=n+1),a===46?i<0?i=n:l!==1&&(l=1):i>-1&&(l=-1)}return i<0||t<0||l===0||l===1&&i===t-1&&i===r+1?"":e.slice(i,t)}function us(...e){let n=-1,t;for(;++n<e.length;)Ge(e[n]),e[n]&&(t=t===void 0?e[n]:t+"/"+e[n]);return t===void 0?".":cs(t)}function cs(e){Ge(e);const n=e.codePointAt(0)===47;let t=ps(e,!n);return t.length===0&&!n&&(t="."),t.length>0&&e.codePointAt(e.length-1)===47&&(t+="/"),n?"/"+t:t}function ps(e,n){let t="",r=0,i=-1,l=0,o=-1,a,c;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||l===1))if(i!==o-1&&l===2){if(t.length<2||r!==2||t.codePointAt(t.length-1)!==46||t.codePointAt(t.length-2)!==46){if(t.length>2){if(c=t.lastIndexOf("/"),c!==t.length-1){c<0?(t="",r=0):(t=t.slice(0,c),r=t.length-1-t.lastIndexOf("/")),i=o,l=0;continue}}else if(t.length>0){t="",r=0,i=o,l=0;continue}}n&&(t=t.length>0?t+"/..":"..",r=2)}else t.length>0?t+="/"+e.slice(i+1,o):t=e.slice(i+1,o),r=o-i-1;i=o,l=0}else a===46&&l>-1?l++:l=-1}return t}function Ge(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const hs={cwd:fs};function fs(){return"/"}function On(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function ds(e){if(typeof e=="string")e=new URL(e);else if(!On(e)){const n=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw n.code="ERR_INVALID_ARG_TYPE",n}if(e.protocol!=="file:"){const n=new TypeError("The URL must be of scheme file");throw n.code="ERR_INVALID_URL_SCHEME",n}return ms(e)}function ms(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const n=e.pathname;let t=-1;for(;++t<n.length;)if(n.codePointAt(t)===37&&n.codePointAt(t+1)===50){const r=n.codePointAt(t+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(n)}const wn=["history","path","basename","stem","extname","dirname"];class Pr{constructor(n){let t;n?On(n)?t={path:n}:typeof n=="string"||gs(n)?t={value:n}:t=n:t={},this.cwd="cwd"in t?"":hs.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<wn.length;){const l=wn[r];l in t&&t[l]!==void 0&&t[l]!==null&&(this[l]=l==="history"?[...t[l]]:t[l])}let i;for(i in t)wn.includes(i)||(this[i]=t[i])}get basename(){return typeof this.path=="string"?me.basename(this.path):void 0}set basename(n){Sn(n,"basename"),Cn(n,"basename"),this.path=me.join(this.dirname||"",n)}get dirname(){return typeof this.path=="string"?me.dirname(this.path):void 0}set dirname(n){Rt(this.basename,"dirname"),this.path=me.join(n||"",this.basename)}get extname(){return typeof this.path=="string"?me.extname(this.path):void 0}set extname(n){if(Cn(n,"extname"),Rt(this.dirname,"extname"),n){if(n.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(n.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=me.join(this.dirname,this.stem+(n||""))}get path(){return this.history[this.history.length-1]}set path(n){On(n)&&(n=ds(n)),Sn(n,"path"),this.path!==n&&this.history.push(n)}get stem(){return typeof this.path=="string"?me.basename(this.path,this.extname):void 0}set stem(n){Sn(n,"stem"),Cn(n,"stem"),this.path=me.join(this.dirname||"",n+(this.extname||""))}fail(n,t,r){const i=this.message(n,t,r);throw i.fatal=!0,i}info(n,t,r){const i=this.message(n,t,r);return i.fatal=void 0,i}message(n,t,r){const i=new te(n,t,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(n){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(n||void 0).decode(this.value)}}function Cn(e,n){if(e&&e.includes(me.sep))throw new Error("`"+n+"` cannot be a path: did not expect `"+me.sep+"`")}function Sn(e,n){if(!e)throw new Error("`"+n+"` cannot be empty")}function Rt(e,n){if(!e)throw new Error("Setting `"+n+"` requires `path` to be set too")}function gs(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const ys=(function(e){const r=this.constructor.prototype,i=r[e],l=function(){return i.apply(l,arguments)};return Object.setPrototypeOf(l,r),l}),xs={}.hasOwnProperty;class et extends ys{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=is()}copy(){const n=new et;let t=-1;for(;++t<this.attachers.length;){const r=this.attachers[t];n.use(...r)}return n.data(bn(!0,{},this.namespace)),n}data(n,t){return typeof n=="string"?arguments.length===2?(En("data",this.frozen),this.namespace[n]=t,this):xs.call(this.namespace,n)&&this.namespace[n]||void 0:n?(En("data",this.frozen),this.namespace=n,this):this.namespace}freeze(){if(this.frozen)return this;const n=this;for(;++this.freezeIndex<this.attachers.length;){const[t,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=t.call(n,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(n){this.freeze();const t=rn(n),r=this.parser||this.Parser;return _n("parse",r),r(String(t),t)}process(n,t){const r=this;return this.freeze(),_n("process",this.parser||this.Parser),In("process",this.compiler||this.Compiler),t?i(void 0,t):new Promise(i);function i(l,o){const a=rn(n),c=r.parse(a);r.run(c,a,function(u,p,m){if(u||!p||!m)return s(u);const h=p,S=r.stringify(h,m);ws(S)?m.value=S:m.result=S,s(u,m)});function s(u,p){u||!p?o(u):l?l(p):t(void 0,p)}}}processSync(n){let t=!1,r;return this.freeze(),_n("processSync",this.parser||this.Parser),In("processSync",this.compiler||this.Compiler),this.process(n,i),$t("processSync","process",t),r;function i(l,o){t=!0,Bt(l),r=o}}run(n,t,r){Ft(n),this.freeze();const i=this.transformers;return!r&&typeof t=="function"&&(r=t,t=void 0),r?l(void 0,r):new Promise(l);function l(o,a){const c=rn(t);i.run(n,c,s);function s(u,p,m){const h=p||n;u?a(u):o?o(h):r(void 0,h,m)}}}runSync(n,t){let r=!1,i;return this.run(n,t,l),$t("runSync","run",r),i;function l(o,a){Bt(o),i=a,r=!0}}stringify(n,t){this.freeze();const r=rn(t),i=this.compiler||this.Compiler;return In("stringify",i),Ft(n),i(n,r)}use(n,...t){const r=this.attachers,i=this.namespace;if(En("use",this.frozen),n!=null)if(typeof n=="function")c(n,t);else if(typeof n=="object")Array.isArray(n)?a(n):o(n);else throw new TypeError("Expected usable value, not `"+n+"`");return this;function l(s){if(typeof s=="function")c(s,[]);else if(typeof s=="object")if(Array.isArray(s)){const[u,...p]=s;c(u,p)}else o(s);else throw new TypeError("Expected usable value, not `"+s+"`")}function o(s){if(!("plugins"in s)&&!("settings"in s))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(s.plugins),s.settings&&(i.settings=bn(!0,i.settings,s.settings))}function a(s){let u=-1;if(s!=null)if(Array.isArray(s))for(;++u<s.length;){const p=s[u];l(p)}else throw new TypeError("Expected a list of plugins, not `"+s+"`")}function c(s,u){let p=-1,m=-1;for(;++p<r.length;)if(r[p][0]===s){m=p;break}if(m===-1)r.push([s,...u]);else if(u.length>0){let[h,...S]=u;const I=r[m][1];Bn(I)&&Bn(h)&&(h=bn(!0,I,h)),r[m]=[s,h,...S]}}}}const ks=new et().freeze();function _n(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function In(e,n){if(typeof n!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function En(e,n){if(n)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Ft(e){if(!Bn(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function $t(e,n,t){if(!t)throw new Error("`"+e+"` finished async. Use `"+n+"` instead")}function rn(e){return bs(e)?e:new Pr(e)}function bs(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function ws(e){return typeof e=="string"||Cs(e)}function Cs(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Ss="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Ht=[],Vt={allowDangerousHtml:!0},_s=/^(https?|ircs?|mailto|xmpp)$/i,Is=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function Es(e){const n=vs(e),t=Ts(e);return Ls(n.runSync(n.parse(t),t),e)}function vs(e){const n=e.rehypePlugins||Ht,t=e.remarkPlugins||Ht,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Vt}:Vt;return ks().use(oa).use(t).use(ns,r).use(n)}function Ts(e){const n=e.children||"",t=new Pr;return typeof n=="string"&&(t.value=n),t}function Ls(e,n){const t=n.allowedElements,r=n.allowElement,i=n.components,l=n.disallowedElements,o=n.skipHtml,a=n.unwrapDisallowed,c=n.urlTransform||Ns;for(const u of Is)Object.hasOwn(n,u.from)&&(""+u.from+(u.to?"use `"+u.to+"` instead":"remove it")+Ss+u.id,void 0);return Nr(e,s),Oi(e,{Fragment:g.Fragment,components:i,ignoreInvalidStyle:!0,jsx:g.jsx,jsxs:g.jsxs,passKeys:!0,passNode:!0});function s(u,p,m){if(u.type==="raw"&&m&&typeof p=="number")return o?m.children.splice(p,1):m.children[p]={type:"text",value:u.value},p;if(u.type==="element"){let h;for(h in gn)if(Object.hasOwn(gn,h)&&Object.hasOwn(u.properties,h)){const S=u.properties[h],I=gn[h];(I===null||I.includes(u.tagName))&&(u.properties[h]=c(String(S||""),h,u))}}if(u.type==="element"){let h=t?!t.includes(u.tagName):l?l.includes(u.tagName):!1;if(!h&&r&&typeof p=="number"&&(h=!r(u,p,m)),h&&m&&typeof p=="number")return a&&u.children?m.children.splice(p,1,...u.children):m.children.splice(p,1),p}}}function Ns(e){const n=e.indexOf(":"),t=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return n===-1||i!==-1&&n>i||t!==-1&&n>t||r!==-1&&n>r||_s.test(e.slice(0,n))?e:""}const Ps="_messageWrapper_1thak_1",As="_user_1thak_19",js="_assistant_1thak_24",zs="_avatar_1thak_28",Ms="_avatarPlaceholder_1thak_43",Ds="_brainbaseLogo_1thak_53",Bs="_messageBubble_1thak_58",Os="_error_1thak_76",Rs="_content_1thak_81",Fs="_markdown_1thak_92",$s="_cursor_1thak_183",Hs="_errorIndicator_1thak_202",ce={messageWrapper:Ps,user:As,assistant:js,avatar:zs,avatarPlaceholder:Ms,brainbaseLogo:Ds,messageBubble:Bs,error:Os,content:Rs,markdown:Fs,cursor:$s,errorIndicator:Hs},Ar=({message:e,agentName:n,agentLogoUrl:t})=>{const r=e.role==="user",i=e.status==="streaming",l=e.status==="error";return g.jsxs("div",{className:`${ce.messageWrapper} ${r?ce.user:ce.assistant}`,children:[!r&&g.jsx("div",{className:ce.avatar,children:t?g.jsx("img",{src:t,alt:n||"AI"}):g.jsx("div",{className:ce.avatarPlaceholder,children:g.jsx(Qe,{className:ce.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),g.jsxs("div",{className:`${ce.messageBubble} ${l?ce.error:""}`,role:"article","aria-label":`${r?"Your message":`${n||"AI"} says`}`,children:[g.jsxs("div",{className:`${ce.content} ${r?"":ce.markdown}`,children:[r?e.content:g.jsx(Es,{components:{a:({href:o,children:a})=>o?g.jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",children:a}):g.jsx(g.Fragment,{children:a})},children:e.content}),i&&g.jsx("span",{className:ce.cursor})]}),l&&g.jsxs("div",{className:ce.errorIndicator,children:[g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",children:[g.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2"}),g.jsx("path",{d:"M12 8V12M12 16H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),g.jsx("span",{children:"Failed to send"})]})]})]})},Vs="_toolCall_1wby1_1",Us="_iconWrapper_1wby1_24",qs="_spinner_1wby1_33",Ws="_checkIcon_1wby1_48",Ys="_errorIcon_1wby1_54",Xs="_content_1wby1_60",Ks="_label_1wby1_66",Qs="_name_1wby1_73",Zs="_pending_1wby1_78",Js="_completed_1wby1_82",Gs="_error_1wby1_54",de={toolCall:Vs,iconWrapper:Us,spinner:qs,checkIcon:Ws,errorIcon:Ys,content:Xs,label:Ks,name:Qs,pending:Zs,completed:Js,error:Gs},jr=({toolCall:e})=>{const n=e.status==="pending"||e.status==="executing",t=e.status==="completed",r=e.status==="error",i=l=>l.replace(/_/g," ").replace(/([A-Z])/g," $1").trim().toLowerCase().replace(/^./,o=>o.toUpperCase());return g.jsxs("div",{className:`${de.toolCall} ${n?de.pending:""} ${t?de.completed:""} ${r?de.error:""}`,children:[g.jsx("div",{className:de.iconWrapper,children:n?g.jsx("div",{className:de.spinner}):t?g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:de.checkIcon,children:g.jsx("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}):g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:de.errorIcon,children:g.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),g.jsxs("div",{className:de.content,children:[g.jsx("span",{className:de.label,children:n?"Running":t?"Completed":"Failed"}),g.jsx("span",{className:de.name,children:i(e.name)})]})]})},eu="_wrapper_10rss_2",nu="_avatar_10rss_22",tu="_avatarPlaceholder_10rss_37",ru="_brainbaseLogo_10rss_47",iu="_bubble_10rss_52",lu="_dot_10rss_63",Ce={wrapper:eu,avatar:nu,avatarPlaceholder:tu,brainbaseLogo:ru,bubble:iu,dot:lu},zr=({agentName:e="AI",agentLogoUrl:n})=>g.jsxs("div",{className:Ce.wrapper,role:"status","aria-label":`${e} is typing`,children:[g.jsx("div",{className:Ce.avatar,children:n?g.jsx("img",{src:n,alt:e}):g.jsx("div",{className:Ce.avatarPlaceholder,children:g.jsx(Qe,{className:Ce.brainbaseLogo,color:"white",cutoutColor:"var(--bb-primary-color)"})})}),g.jsxs("div",{className:Ce.bubble,children:[g.jsx("span",{className:Ce.dot}),g.jsx("span",{className:Ce.dot}),g.jsx("span",{className:Ce.dot})]})]}),ou="_messageList_9tkjc_1",au="_emptyState_9tkjc_30",su="_emptyIcon_9tkjc_41",uu="_emptyText_9tkjc_53",ln={messageList:ou,emptyState:au,emptyIcon:su,emptyText:uu},Mr=({messages:e,toolCalls:n=[],isLoading:t,agentName:r,agentLogoUrl:i})=>{var c;const l=O.useRef(null),o=O.useRef(null);O.useEffect(()=>{var s;(s=o.current)==null||s.scrollIntoView({behavior:"smooth"})},[e,n,t]);const a=n.filter(s=>s.status==="pending"||s.status==="executing");return g.jsxs("div",{className:ln.messageList,ref:l,role:"log","aria-live":"polite",children:[e.length===0&&!t&&g.jsxs("div",{className:ln.emptyState,children:[g.jsx("div",{className:ln.emptyIcon,children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),g.jsx("p",{className:ln.emptyText,children:"Start a conversation"})]}),e.map(s=>g.jsx(Ar,{message:s,agentName:r,agentLogoUrl:i},s.id)),a.map(s=>g.jsx(jr,{toolCall:s},s.id)),t&&((c=e[e.length-1])==null?void 0:c.role)==="user"&&g.jsx(zr,{agentName:r,agentLogoUrl:i}),g.jsx("div",{ref:o})]})},cu="_inputWrapper_5lgg7_1",pu="_inputContainer_5lgg7_7",hu="_textarea_5lgg7_23",fu="_sendButton_5lgg7_50",du="_hint_5lgg7_89",We={inputWrapper:cu,inputContainer:pu,textarea:hu,sendButton:fu,hint:du},Dr=({onSend:e,disabled:n=!1,placeholder:t="Send a message..."})=>{const[r,i]=O.useState(""),l=O.useRef(null),o=O.useCallback(()=>{const s=l.current;s&&(s.style.height="auto",s.style.height=`${Math.min(s.scrollHeight,150)}px`)},[]);O.useEffect(()=>{o()},[r,o]);const a=O.useCallback(s=>{s==null||s.preventDefault();const u=r.trim();u&&!n&&(e(u),i(""),l.current&&(l.current.style.height="auto"))},[r,n,e]),c=O.useCallback(s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),a())},[a]);return g.jsxs("form",{className:We.inputWrapper,onSubmit:a,children:[g.jsxs("div",{className:We.inputContainer,children:[g.jsx("textarea",{ref:l,className:We.textarea,value:r,onChange:s=>i(s.target.value),onKeyDown:c,placeholder:t,disabled:n,rows:1,"aria-label":"Message input"}),g.jsx("button",{type:"submit",className:We.sendButton,disabled:n||!r.trim(),"aria-label":"Send message",children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),g.jsxs("div",{className:We.hint,children:["Press ",g.jsx("kbd",{children:"Enter"})," to send, ",g.jsx("kbd",{children:"Shift + Enter"})," for new line"]})]})},mu="_poweredBy_9jh5q_1",gu="_logo_9jh5q_20",yu="_poweredText_9jh5q_24",xu="_text_9jh5q_36",on={poweredBy:mu,logo:gu,poweredText:yu,text:xu},ku=({className:e})=>g.jsxs("svg",{className:e,viewBox:"0 0 800 800",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H788C794.627 400 800 405.373 800 412V740C800 773.137 773.137 800 740 800H412C405.373 800 400 794.627 400 788V412Z",fill:"currentColor"}),g.jsx("circle",{cx:"400",cy:"400",r:"400",fill:"currentColor"}),g.jsx("path",{d:"M0 60C0 26.8629 26.8629 0 60 0H397.614C398.932 0 400 1.06811 400 2.38569V2.38569C400 221.982 221.982 400 2.38569 400V400C1.06811 400 0 398.932 0 397.614V60Z",fill:"currentColor"}),g.jsx("path",{d:"M400 412C400 405.373 405.373 400 412 400H738C744.627 400 750 405.373 750 412V725C750 738.807 738.807 750 725 750H412C405.373 750 400 744.627 400 738V412Z",fill:"currentColor"}),g.jsx("circle",{cx:"400",cy:"400",r:"350",fill:"currentColor"}),g.jsx("path",{d:"M50 75C50 61.1929 61.1929 50 75 50H388C394.627 50 400 55.3726 400 62V388C400 394.627 394.627 400 388 400H62C55.3726 400 50 394.627 50 388V75Z",fill:"currentColor"}),g.jsx("rect",{x:"399.919",y:"209",width:"270",height:"270",rx:"12",transform:"rotate(45 399.919 209)",fill:"var(--bb-surface-bg, #ffffff)"})]}),bu=({showBranding:e=!0})=>e?g.jsxs("a",{href:"https://brainbaselabs.com/",target:"_blank",rel:"noopener noreferrer",className:on.poweredBy,"aria-label":"Powered by Brainbase Labs",children:[g.jsx("span",{className:on.poweredText,children:"Powered by"}),g.jsx(ku,{className:on.logo}),g.jsx("span",{className:on.text,children:"Brainbase Labs"})]}):null,wu="_container_m2o9l_1",Cu="_body_m2o9l_26",Su="_confirmationOverlay_m2o9l_35",_u="_confirmationDialog_m2o9l_56",Iu="_confirmationText_m2o9l_78",Eu="_confirmationButtons_m2o9l_86",vu="_cancelButton_m2o9l_91",Tu="_confirmButton_m2o9l_92",Se={container:wu,body:Cu,confirmationOverlay:Su,confirmationDialog:_u,confirmationText:Iu,confirmationButtons:Eu,cancelButton:vu,confirmButton:Tu},Br=({config:e,messages:n,toolCalls:t=[],isLoading:r,onSendMessage:i,onClose:l,onNewChat:o})=>{var h;const[a,c]=O.useState(!1),s=n.length>0,u=()=>{c(!0)},p=()=>{c(!1),o==null||o()},m=()=>{c(!1)};return g.jsxs("div",{className:Se.container,role:"dialog","aria-label":"Chat window",children:[g.jsx(Kt,{agentName:e.agentName,agentLogoUrl:e.agentLogoUrl,welcomeTitle:e.welcomeMessage||"Hello there.",welcomeSubtitle:e.welcomeMessage?void 0:"How can we help?",onClose:l,onNewChatRequest:u,showNewChatButton:s,compact:s}),g.jsxs("div",{className:Se.body,children:[g.jsx(Mr,{messages:n,toolCalls:t,isLoading:r,agentName:e.agentName,agentLogoUrl:e.agentLogoUrl}),g.jsx(Dr,{onSend:i,disabled:r,placeholder:"Ask a question..."})]}),g.jsx(bu,{showBranding:((h=e.styling)==null?void 0:h.showBranding)??!0}),a&&g.jsx("div",{className:Se.confirmationOverlay,children:g.jsxs("div",{className:Se.confirmationDialog,children:[g.jsx("p",{className:Se.confirmationText,children:"End current chat and start a new conversation?"}),g.jsxs("div",{className:Se.confirmationButtons,children:[g.jsx("button",{className:Se.cancelButton,onClick:m,type:"button",children:"Cancel"}),g.jsx("button",{className:Se.confirmButton,onClick:p,type:"button",children:"End Chat"})]})]})})]})},Lu="_toggleButton_11dqz_1",Nu="_icon_11dqz_31",Pu="_agentLogo_11dqz_36",Au="_unreadBadge_11dqz_43",an={toggleButton:Lu,icon:Nu,agentLogo:Pu,unreadBadge:Au},Rn=({onClick:e,agentLogoUrl:n,unreadCount:t=0})=>g.jsxs("button",{className:an.toggleButton,onClick:e,"aria-label":"Open chat",type:"button",children:[n?g.jsx("img",{src:n,alt:"",className:an.agentLogo}):g.jsx("svg",{className:an.icon,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:g.jsx("path",{d:"M8 12H8.01M12 12H12.01M16 12H16.01M21 12C21 16.4183 16.9706 20 12 20C10.4607 20 9.01172 19.6565 7.74467 19.0511L3 20L4.39499 16.28C3.51156 15.0423 3 13.5743 3 12C3 7.58172 7.02944 4 12 4C16.9706 4 21 7.58172 21 12Z",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),t>0&&g.jsx("span",{className:an.unreadBadge,children:t>9?"9+":t})]}),ju="_container_kgfgt_1",zu="_header_kgfgt_25",Mu="_logoWrapper_kgfgt_38",Du="_logo_kgfgt_38",Bu="_closeButton_kgfgt_51",Ou="_content_kgfgt_74",Ru="_iconWrapper_kgfgt_84",Fu="_errorIcon_kgfgt_95",$u="_title_kgfgt_101",Hu="_description_kgfgt_109",Vu="_retryButton_kgfgt_117",Uu="_footer_kgfgt_139",qu="_poweredBy_kgfgt_146",Wu="_footerLogo_kgfgt_160",ne={container:ju,header:zu,logoWrapper:Mu,logo:Du,closeButton:Bu,content:Ou,iconWrapper:Ru,errorIcon:Fu,title:$u,description:Hu,retryButton:Vu,footer:Uu,poweredBy:qu,footerLogo:Wu},Yu=({errorType:e,message:n,onRetry:t,onClose:r})=>{const i=()=>{switch(e){case"not_found":return{title:"Chat Not Found",description:n||"This chat widget is not configured correctly. Please check the embed ID.",icon:g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:[g.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"1.5"}),g.jsx("path",{d:"M12 7V13M12 16V16.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};case"network":return{title:"Connection Error",description:n||"Unable to connect to the chat service. Please check your internet connection.",icon:g.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:[g.jsx("path",{d:"M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z",stroke:"currentColor",strokeWidth:"1.5"}),g.jsx("path",{d:"M8 15L16 9M8 9L16 15",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]})};default:return{title:"Something Went Wrong",description:n||"An unexpected error occurred. Please try again later.",icon:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",className:ne.errorIcon,children:g.jsx("path",{d:"M12 9V13M12 17H12.01M21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3C16.9706 3 21 7.02944 21 12Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}}},{title:l,description:o,icon:a}=i();return g.jsxs("div",{className:ne.container,children:[g.jsxs("div",{className:ne.header,children:[g.jsx("div",{className:ne.logoWrapper,children:g.jsx(Qe,{className:ne.logo,color:"white",cutoutColor:"var(--bb-primary-color)"})}),r&&g.jsx("button",{className:ne.closeButton,onClick:r,"aria-label":"Close",type:"button",children:g.jsx("svg",{viewBox:"0 0 24 24",fill:"none",children:g.jsx("path",{d:"M6 18L18 6M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),g.jsxs("div",{className:ne.content,children:[g.jsx("div",{className:ne.iconWrapper,children:a}),g.jsx("h2",{className:ne.title,children:l}),g.jsx("p",{className:ne.description,children:o}),t&&g.jsx("button",{className:ne.retryButton,onClick:t,type:"button",children:"Try Again"})]}),g.jsx("div",{className:ne.footer,children:g.jsxs("a",{href:"https://brainbaselabs.com",target:"_blank",rel:"noopener noreferrer",className:ne.poweredBy,children:["Powered by"," ",g.jsx(Qe,{className:ne.footerLogo,color:"var(--bb-text-tertiary)",cutoutColor:"var(--bb-surface-bg)"}),g.jsx("span",{children:"Brainbase Labs"})]})})]})},Xu="_widget_1ehud_1",Ku="_inline_1ehud_25",je={widget:Xu,"bottom-right":"_bottom-right_1ehud_10","bottom-left":"_bottom-left_1ehud_17",inline:Ku},Qu=({embedId:e,apiBaseUrl:n=Wt,mockMode:t=!1,mockResponses:r,position:i="bottom-right",defaultOpen:l=!1,primaryColor:o,agentName:a,agentLogoUrl:c,welcomeMessage:s,showBranding:u,className:p,onSessionStart:m,onSessionEnd:h,onMessage:S,onError:I})=>{const[E,b]=O.useState(l),[P,v]=O.useState(null),[R,V]=O.useState(!0),[k,D]=O.useState(null),[U,F]=O.useState(),$=O.useRef(!1),N=O.useMemo(()=>t?Xt({},r):Yt(n),[t,r,n]),C=O.useCallback(async()=>{if(!($.current&&P)){V(!0),D(null),F(void 0);try{const f=await N.getDeploymentConfig(e);v(f),$.current=!0}catch(f){const J=f instanceof Error?f:new Error("Failed to load config");J.message.includes("404")?(D("not_found"),F("The chat widget with this embed ID was not found.")):J.message.includes("Failed to fetch")||J.message.includes("network")?D("network"):D("unknown"),t&&(v({embedId:e,deploymentId:"mock-deployment",workerId:"mock-worker",flowId:"mock-flow",primaryColor:"#1a1a2e",agentName:"AI Assistant",styling:{}}),D(null),$.current=!0),I==null||I(J)}finally{V(!1)}}},[e,t,N,I,P]);O.useEffect(()=>{$.current=!1,C()},[e,t,N]);const j=O.useMemo(()=>{const f=P??{embedId:e,deploymentId:"",workerId:"",flowId:""};return{...f,primaryColor:o??f.primaryColor??"#1a1a2e",agentName:a??f.agentName,agentLogoUrl:c??f.agentLogoUrl,welcomeMessage:s??f.welcomeMessage,styling:{...f.styling??{},...u!==void 0?{showBranding:u}:{}}}},[P,e,o,a,c,s,u]),T=qt({config:j,apiClient:N,mockMode:t,onSessionStart:m,onSessionEnd:h,onMessage:S,onError:I}),x=O.useMemo(()=>({"--bb-primary-color":j.primaryColor??"#1a1a2e"}),[j.primaryColor]),A=()=>{T.endSession(),T.startNewSession()},L=()=>{b(!1)},q=()=>{C()},Q=i==="inline";return R?null:k&&!t?!Q&&!E?g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:g.jsx(Rn,{onClick:()=>b(!0),agentName:a})}):g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:g.jsx(Yu,{errorType:k,message:U,onRetry:q,onClose:Q?void 0:L})}):g.jsx("div",{className:`${je.widget} ${je[i]} ${p??""}`,style:x,children:E||Q?g.jsx(Br,{config:j,messages:T.messages,isLoading:T.isLoading,onSendMessage:T.sendMessage,onClose:Q?void 0:L,onNewChat:A}):g.jsx(Rn,{onClick:()=>b(!0),agentName:j.agentName,agentLogoUrl:j.agentLogoUrl})})};function Zu(){if(typeof crypto<"u"&&crypto.randomUUID)return`bb-${crypto.randomUUID()}`;const e=Date.now().toString(36),n=Math.random().toString(36).substring(2,15),t=Math.random().toString(36).substring(2,15);return`bb-${e}-${n}${t}`}exports.ChatContainer=Br;exports.ChatHeader=Kt;exports.ChatToggleButton=Rn;exports.ChatWidget=Qu;exports.Message=Ar;exports.MessageInput=Dr;exports.MessageList=Mr;exports.ToolCallDisplay=jr;exports.TypingIndicator=zr;exports.clearSession=Tn;exports.createAPIClient=Yt;exports.createMockAPIClient=Xt;exports.generateSessionId=Zu;exports.getStoredSession=Ut;exports.storeSession=vn;exports.useChat=qt;