@cuadra-ai/uikit 0.4.7 → 0.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -17,6 +17,6 @@
17
17
  `))+1))}const a="#".repeat(i),c=t.enter("headingAtx"),s=t.enter("phrasing");o.move(a+" ");let l=t.containerPhrasing(e,{before:"# ",after:`
18
18
  `,...o.current()});return/^[\t ]/.test(l)&&(l=ge(l.charCodeAt(0))+l.slice(1)),l=l?a+" "+l:a,t.options.closeAtx&&(l+=" "+a),s(),c(),l}Ot.peek=Aa;function Ot(e){return e.value||""}function Aa(){return"<"}Bt.peek=Sa;function Bt(e,r,t,n){const i=Ke(t),o=i==='"'?"Quote":"Apostrophe",a=t.enter("image");let c=t.enter("label");const s=t.createTracker(n);let l=s.move("![");return l+=s.move(t.safe(e.alt,{before:l,after:"]",...s.current()})),l+=s.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=t.enter("destinationLiteral"),l+=s.move("<"),l+=s.move(t.safe(e.url,{before:l,after:">",...s.current()})),l+=s.move(">")):(c=t.enter("destinationRaw"),l+=s.move(t.safe(e.url,{before:l,after:e.title?" ":")",...s.current()}))),c(),e.title&&(c=t.enter(`title${o}`),l+=s.move(" "+i),l+=s.move(t.safe(e.title,{before:l,after:i,...s.current()})),l+=s.move(i),c()),l+=s.move(")"),a(),l}function Sa(){return"!"}qt.peek=Ma;function qt(e,r,t,n){const i=e.referenceType,o=t.enter("imageReference");let a=t.enter("label");const c=t.createTracker(n);let s=c.move("![");const l=t.safe(e.alt,{before:s,after:"]",...c.current()});s+=c.move(l+"]["),a();const f=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...c.current()});return a(),t.stack=f,o(),i==="full"||!l||l!==u?s+=c.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=c.move("]"),s}function Ma(){return"!"}Wt.peek=Pa;function Wt(e,r,t){let n=e.value||"",i="`",o=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(n);)i+="`";for(/[^ \r\n]/.test(n)&&(/^[ \r\n]/.test(n)&&/[ \r\n]$/.test(n)||/^`|`$/.test(n))&&(n=" "+n+" ");++o<t.unsafe.length;){const a=t.unsafe[o],c=t.compilePattern(a);let s;if(a.atBreak)for(;s=c.exec(n);){let l=s.index;n.charCodeAt(l)===10&&n.charCodeAt(l-1)===13&&l--,n=n.slice(0,l)+" "+n.slice(s.index+1)}}return i+n+i}function Pa(){return"`"}function Ht(e,r){const t=zt(e);return!!(!r.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(t===e.url||"mailto:"+t===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Vt.peek=_a;function Vt(e,r,t,n){const i=Ke(t),o=i==='"'?"Quote":"Apostrophe",a=t.createTracker(n);let c,s;if(Ht(e,t)){const f=t.stack;t.stack=[],c=t.enter("autolink");let u=a.move("<");return u+=a.move(t.containerPhrasing(e,{before:u,after:">",...a.current()})),u+=a.move(">"),c(),t.stack=f,u}c=t.enter("link"),s=t.enter("label");let l=a.move("[");return l+=a.move(t.containerPhrasing(e,{before:l,after:"](",...a.current()})),l+=a.move("]("),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=t.enter("destinationLiteral"),l+=a.move("<"),l+=a.move(t.safe(e.url,{before:l,after:">",...a.current()})),l+=a.move(">")):(s=t.enter("destinationRaw"),l+=a.move(t.safe(e.url,{before:l,after:e.title?" ":")",...a.current()}))),s(),e.title&&(s=t.enter(`title${o}`),l+=a.move(" "+i),l+=a.move(t.safe(e.title,{before:l,after:i,...a.current()})),l+=a.move(i),s()),l+=a.move(")"),c(),l}function _a(e,r,t){return Ht(e,t)?"<":"["}Kt.peek=Na;function Kt(e,r,t,n){const i=e.referenceType,o=t.enter("linkReference");let a=t.enter("label");const c=t.createTracker(n);let s=c.move("[");const l=t.containerPhrasing(e,{before:s,after:"]",...c.current()});s+=c.move(l+"]["),a();const f=t.stack;t.stack=[],a=t.enter("reference");const u=t.safe(t.associationId(e),{before:s,after:"]",...c.current()});return a(),t.stack=f,o(),i==="full"||!l||l!==u?s+=c.move(u+"]"):i==="shortcut"?s=s.slice(0,-1):s+=c.move("]"),s}function Na(){return"["}function Qe(e){const r=e.options.bullet||"*";if(r!=="*"&&r!=="+"&&r!=="-")throw new Error("Cannot serialize items with `"+r+"` for `options.bullet`, expected `*`, `+`, or `-`");return r}function Ea(e){const r=Qe(e),t=e.options.bulletOther;if(!t)return r==="*"?"-":"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(t===r)throw new Error("Expected `bullet` (`"+r+"`) and `bulletOther` (`"+t+"`) to be different");return t}function Ra(e){const r=e.options.bulletOrdered||".";if(r!=="."&&r!==")")throw new Error("Cannot serialize items with `"+r+"` for `options.bulletOrdered`, expected `.` or `)`");return r}function Qt(e){const r=e.options.rule||"*";if(r!=="*"&&r!=="-"&&r!=="_")throw new Error("Cannot serialize rules with `"+r+"` for `options.rule`, expected `*`, `-`, or `_`");return r}function La(e,r,t,n){const i=t.enter("list"),o=t.bulletCurrent;let a=e.ordered?Ra(t):Qe(t);const c=e.ordered?a==="."?")":".":Ea(t);let s=r&&t.bulletLastUsed?a===t.bulletLastUsed:!1;if(!e.ordered){const f=e.children?e.children[0]:void 0;if((a==="*"||a==="-")&&f&&(!f.children||!f.children[0])&&t.stack[t.stack.length-1]==="list"&&t.stack[t.stack.length-2]==="listItem"&&t.stack[t.stack.length-3]==="list"&&t.stack[t.stack.length-4]==="listItem"&&t.indexStack[t.indexStack.length-1]===0&&t.indexStack[t.indexStack.length-2]===0&&t.indexStack[t.indexStack.length-3]===0&&(s=!0),Qt(t)===a&&f){let u=-1;for(;++u<e.children.length;){const g=e.children[u];if(g&&g.type==="listItem"&&g.children&&g.children[0]&&g.children[0].type==="thematicBreak"){s=!0;break}}}}s&&(a=c),t.bulletCurrent=a;const l=t.containerFlow(e,n);return t.bulletLastUsed=a,t.bulletCurrent=o,i(),l}function Da(e){const r=e.options.listItemIndent||"one";if(r!=="tab"&&r!=="one"&&r!=="mixed")throw new Error("Cannot serialize items with `"+r+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return r}function Fa(e,r,t,n){const i=Da(t);let o=t.bulletCurrent||Qe(t);r&&r.type==="list"&&r.ordered&&(o=(typeof r.start=="number"&&r.start>-1?r.start:1)+(t.options.incrementListMarker===!1?0:r.children.indexOf(e))+o);let a=o.length+1;(i==="tab"||i==="mixed"&&(r&&r.type==="list"&&r.spread||e.spread))&&(a=Math.ceil(a/4)*4);const c=t.createTracker(n);c.move(o+" ".repeat(a-o.length)),c.shift(a);const s=t.enter("listItem"),l=t.indentLines(t.containerFlow(e,c.current()),f);return s(),l;function f(u,g,m){return g?(m?"":" ".repeat(a))+u:(m?o:o+" ".repeat(a-o.length))+u}}function Ua(e,r,t,n){const i=t.enter("paragraph"),o=t.enter("phrasing"),a=t.containerPhrasing(e,n);return o(),i(),a}const za=Me(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function $a(e,r,t,n){return(e.children.some(function(a){return za(a)})?t.containerPhrasing:t.containerFlow).call(t,e,n)}function Oa(e){const r=e.options.strong||"*";if(r!=="*"&&r!=="_")throw new Error("Cannot serialize strong with `"+r+"` for `options.strong`, expected `*`, or `_`");return r}Gt.peek=Ba;function Gt(e,r,t,n){const i=Oa(t),o=t.enter("strong"),a=t.createTracker(n),c=a.move(i+i);let s=a.move(t.containerPhrasing(e,{after:i,before:c,...a.current()}));const l=s.charCodeAt(0),f=Ie(n.before.charCodeAt(n.before.length-1),l,i);f.inside&&(s=ge(l)+s.slice(1));const u=s.charCodeAt(s.length-1),g=Ie(n.after.charCodeAt(0),u,i);g.inside&&(s=s.slice(0,-1)+ge(u));const m=a.move(i+i);return o(),t.attentionEncodeSurroundingInfo={after:g.outside,before:f.outside},c+s+m}function Ba(e,r,t){return t.options.strong||"*"}function qa(e,r,t,n){return t.safe(e.value,n)}function Wa(e){const r=e.options.ruleRepetition||3;if(r<3)throw new Error("Cannot serialize rules with repetition `"+r+"` for `options.ruleRepetition`, expected `3` or more");return r}function Ha(e,r,t){const n=(Qt(t)+(t.options.ruleSpaces?" ":"")).repeat(Wa(t));return t.options.ruleSpaces?n.slice(0,-1):n}const Yt={blockquote:da,break:ht,code:xa,definition:ba,emphasis:Ut,hardBreak:ht,heading:Ia,html:Ot,image:Bt,imageReference:qt,inlineCode:Wt,link:Vt,linkReference:Kt,list:La,listItem:Fa,paragraph:Ua,root:$a,strong:Gt,text:qa,thematicBreak:Ha};function Va(){return{enter:{table:Ka,tableData:pt,tableHeader:pt,tableRow:Ga},exit:{codeText:Ya,table:Qa,tableData:Fe,tableHeader:Fe,tableRow:Fe}}}function Ka(e){const r=e._align;this.enter({type:"table",align:r.map(function(t){return t==="none"?null:t}),children:[]},e),this.data.inTable=!0}function Qa(e){this.exit(e),this.data.inTable=void 0}function Ga(e){this.enter({type:"tableRow",children:[]},e)}function Fe(e){this.exit(e)}function pt(e){this.enter({type:"tableCell",children:[]},e)}function Ya(e){let r=this.resume();this.data.inTable&&(r=r.replace(/\\([\\|])/g,Ja));const t=this.stack[this.stack.length-1];t.type,t.value=r,this.exit(e)}function Ja(e,r){return r==="|"?r:e}function Xa(e){const r=e||{},t=r.tableCellPadding,n=r.tablePipeAlign,i=r.stringLength,o=t?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
19
19
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:g,table:a,tableCell:s,tableRow:c}};function a(m,h,b,x){return l(f(m,b,x),m.align)}function c(m,h,b,x){const w=u(m,b,x),C=l([w]);return C.slice(0,C.indexOf(`
20
- `))}function s(m,h,b,x){const w=b.enter("tableCell"),C=b.enter("phrasing"),v=b.containerPhrasing(m,{...x,before:o,after:o});return C(),w(),v}function l(m,h){return la(m,{align:h,alignDelimiters:n,padding:t,stringLength:i})}function f(m,h,b){const x=m.children;let w=-1;const C=[],v=h.enter("table");for(;++w<x.length;)C[w]=u(x[w],h,b);return v(),C}function u(m,h,b){const x=m.children;let w=-1;const C=[],v=h.enter("tableRow");for(;++w<x.length;)C[w]=s(x[w],m,h,b);return v(),C}function g(m,h,b){let x=Yt.inlineCode(m,h,b);return b.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function Za(){return{exit:{taskListCheckValueChecked:gt,taskListCheckValueUnchecked:gt,paragraph:ti}}}function ei(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:ri}}}function gt(e){const r=this.stack[this.stack.length-2];r.type,r.checked=e.type==="taskListCheckValueChecked"}function ti(e){const r=this.stack[this.stack.length-2];if(r&&r.type==="listItem"&&typeof r.checked=="boolean"){const t=this.stack[this.stack.length-1];t.type;const n=t.children[0];if(n&&n.type==="text"){const i=r.children;let o=-1,a;for(;++o<i.length;){const c=i[o];if(c.type==="paragraph"){a=c;break}}a===t&&(n.value=n.value.slice(1),n.value.length===0?t.children.shift():t.position&&n.position&&typeof n.position.start.offset=="number"&&(n.position.start.column++,n.position.start.offset++,t.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function ri(e,r,t,n){const i=e.children[0],o=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",c=t.createTracker(n);o&&c.move(a);let s=Yt.listItem(e,r,t,{...n,...c.current()});return o&&(s=s.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),s;function l(f){return f+a}}function ni(){return[Nn(),Zn(),na(),Va(),Za()]}function ai(e){return{extensions:[En(),ea(e),aa(),Xa(e),ei()]}}function ve(e,r,t,n){const i=e.length;let o=0,a;if(r<0?r=-r>i?0:i+r:r=r>i?i:r,t=t>0?t:0,n.length<1e4)a=Array.from(n),a.unshift(r,t),e.splice(...a);else for(t&&e.splice(r,t);o<n.length;)a=n.slice(o,o+1e4),a.unshift(r,0),e.splice(...a),o+=1e4,r+=1e4}const xt={}.hasOwnProperty;function ii(e){const r={};let t=-1;for(;++t<e.length;)oi(r,e[t]);return r}function oi(e,r){let t;for(t in r){const i=(xt.call(e,t)?e[t]:void 0)||(e[t]={}),o=r[t];let a;if(o)for(a in o){xt.call(i,a)||(i[a]=[]);const c=o[a];si(i[a],Array.isArray(c)?c:c?[c]:[])}}}function si(e,r){let t=-1;const n=[];for(;++t<r.length;)(r[t].add==="after"?e:n).push(r[t]);ve(e,0,0,n)}const ci={tokenize:mi,partial:!0},Jt={tokenize:pi,partial:!0},Xt={tokenize:gi,partial:!0},Zt={tokenize:xi,partial:!0},li={tokenize:yi,partial:!0},er={name:"wwwAutolink",tokenize:fi,previous:rr},tr={name:"protocolAutolink",tokenize:hi,previous:nr},te={name:"emailAutolink",tokenize:di,previous:ar},J={};function ui(){return{text:J}}let ie=48;for(;ie<123;)J[ie]=te,ie++,ie===58?ie=65:ie===91&&(ie=97);J[43]=te;J[45]=te;J[46]=te;J[95]=te;J[72]=[te,tr];J[104]=[te,tr];J[87]=[te,er];J[119]=[te,er];function di(e,r,t){const n=this;let i,o;return a;function a(u){return!qe(u)||!ar.call(n,n.previous)||Ge(n.events)?t(u):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),c(u))}function c(u){return qe(u)?(e.consume(u),c):u===64?(e.consume(u),s):t(u)}function s(u){return u===46?e.check(li,f,l)(u):u===45||u===95||Ve(u)?(o=!0,e.consume(u),s):f(u)}function l(u){return e.consume(u),i=!0,s}function f(u){return o&&i&&pe(n.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),r(u)):t(u)}}function fi(e,r,t){const n=this;return i;function i(a){return a!==87&&a!==119||!rr.call(n,n.previous)||Ge(n.events)?t(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(ci,e.attempt(Jt,e.attempt(Xt,o),t),t)(a))}function o(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),r(a)}}function hi(e,r,t){const n=this;let i="",o=!1;return a;function a(u){return(u===72||u===104)&&nr.call(n,n.previous)&&!Ge(n.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(u),e.consume(u),c):t(u)}function c(u){if(pe(u)&&i.length<5)return i+=String.fromCodePoint(u),e.consume(u),c;if(u===58){const g=i.toLowerCase();if(g==="http"||g==="https")return e.consume(u),s}return t(u)}function s(u){return u===47?(e.consume(u),o?l:(o=!0,s)):t(u)}function l(u){return u===null||yn(u)||q(u)||oe(u)||Ae(u)?t(u):e.attempt(Jt,e.attempt(Xt,f),t)(u)}function f(u){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),r(u)}}function mi(e,r,t){let n=0;return i;function i(a){return(a===87||a===119)&&n<3?(n++,e.consume(a),i):a===46&&n===3?(e.consume(a),o):t(a)}function o(a){return a===null?t(a):r(a)}}function pi(e,r,t){let n,i,o;return a;function a(l){return l===46||l===95?e.check(Zt,s,c)(l):l===null||q(l)||oe(l)||l!==45&&Ae(l)?s(l):(o=!0,e.consume(l),a)}function c(l){return l===95?n=!0:(i=n,n=void 0),e.consume(l),a}function s(l){return i||n||!o?t(l):r(l)}}function gi(e,r){let t=0,n=0;return i;function i(a){return a===40?(t++,e.consume(a),i):a===41&&n<t?o(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(Zt,r,o)(a):a===null||q(a)||oe(a)?r(a):(e.consume(a),i)}function o(a){return a===41&&n++,e.consume(a),i}}function xi(e,r,t){return n;function n(c){return c===33||c===34||c===39||c===41||c===42||c===44||c===46||c===58||c===59||c===63||c===95||c===126?(e.consume(c),n):c===38?(e.consume(c),o):c===93?(e.consume(c),i):c===60||c===null||q(c)||oe(c)?r(c):t(c)}function i(c){return c===null||c===40||c===91||q(c)||oe(c)?r(c):n(c)}function o(c){return pe(c)?a(c):t(c)}function a(c){return c===59?(e.consume(c),n):pe(c)?(e.consume(c),a):t(c)}}function yi(e,r,t){return n;function n(o){return e.consume(o),i}function i(o){return Ve(o)?t(o):r(o)}}function rr(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||q(e)}function nr(e){return!pe(e)}function ar(e){return!(e===47||qe(e))}function qe(e){return e===43||e===45||e===46||e===95||Ve(e)}function Ge(e){let r=e.length,t=!1;for(;r--;){const n=e[r][1];if((n.type==="labelLink"||n.type==="labelImage")&&!n._balanced){t=!0;break}if(n._gfmAutolinkLiteralWalkedInto){t=!1;break}}return e.length>0&&!t&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),t}function bi(e,r,t){const n=[];let i=-1;for(;++i<e.length;){const o=e[i].resolveAll;o&&!n.includes(o)&&(r=o(r,t),n.push(o))}return r}function ee(e,r,t,n){const i=n?n-1:Number.POSITIVE_INFINITY;let o=0;return a;function a(s){return Z(s)?(e.enter(t),c(s)):r(s)}function c(s){return Z(s)&&o++<i?(e.consume(s),c):(e.exit(t),r(s))}}const wi={partial:!0,tokenize:ki};function ki(e,r,t){return n;function n(o){return Z(o)?ee(e,i,"linePrefix")(o):i(o)}function i(o){return o===null||le(o)?r(o):t(o)}}const Ci={tokenize:Pi,partial:!0};function vi(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Ai,continuation:{tokenize:Si},exit:Mi}},text:{91:{name:"gfmFootnoteCall",tokenize:Ii},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Ti,resolveTo:ji}}}}function Ti(e,r,t){const n=this;let i=n.events.length;const o=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let a;for(;i--;){const s=n.events[i][1];if(s.type==="labelImage"){a=s;break}if(s.type==="gfmFootnoteCall"||s.type==="labelLink"||s.type==="label"||s.type==="image"||s.type==="link")break}return c;function c(s){if(!a||!a._balanced)return t(s);const l=xe(n.sliceSerialize({start:a.end,end:n.now()}));return l.codePointAt(0)!==94||!o.includes(l.slice(1))?t(s):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(s),e.exit("gfmFootnoteCallLabelMarker"),r(s))}}function ji(e,r){let t=e.length;for(;t--;)if(e[t][1].type==="labelImage"&&e[t][0]==="enter"){e[t][1];break}e[t+1][1].type="data",e[t+3][1].type="gfmFootnoteCallLabelMarker";const n={type:"gfmFootnoteCall",start:Object.assign({},e[t+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[t+3][1].end),end:Object.assign({},e[t+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},c=[e[t+1],e[t+2],["enter",n,r],e[t+3],e[t+4],["enter",i,r],["exit",i,r],["enter",o,r],["enter",a,r],["exit",a,r],["exit",o,r],e[e.length-2],e[e.length-1],["exit",n,r]];return e.splice(t,e.length-t+1,...c),e}function Ii(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o=0,a;return c;function c(u){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),s}function s(u){return u!==94?t(u):(e.enter("gfmFootnoteCallMarker"),e.consume(u),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(u){if(o>999||u===93&&!a||u===null||u===91||q(u))return t(u);if(u===93){e.exit("chunkString");const g=e.exit("gfmFootnoteCallString");return i.includes(xe(n.sliceSerialize(g)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),r):t(u)}return q(u)||(a=!0),o++,e.consume(u),u===92?f:l}function f(u){return u===91||u===92||u===93?(e.consume(u),o++,l):l(u)}}function Ai(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o,a=0,c;return s;function s(h){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),l}function l(h){return h===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",f):t(h)}function f(h){if(a>999||h===93&&!c||h===null||h===91||q(h))return t(h);if(h===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return o=xe(n.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),g}return q(h)||(c=!0),a++,e.consume(h),h===92?u:f}function u(h){return h===91||h===92||h===93?(e.consume(h),a++,f):f(h)}function g(h){return h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),i.includes(o)||i.push(o),ee(e,m,"gfmFootnoteDefinitionWhitespace")):t(h)}function m(h){return r(h)}}function Si(e,r,t){return e.check(wi,r,e.attempt(Ci,r,t))}function Mi(e){e.exit("gfmFootnoteDefinition")}function Pi(e,r,t){const n=this;return ee(e,i,"gfmFootnoteDefinitionIndent",5);function i(o){const a=n.events[n.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?r(o):t(o)}}function _i(e){let t=(e||{}).singleTilde;const n={name:"strikethrough",tokenize:o,resolveAll:i};return t==null&&(t=!0),{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function i(a,c){let s=-1;for(;++s<a.length;)if(a[s][0]==="enter"&&a[s][1].type==="strikethroughSequenceTemporary"&&a[s][1]._close){let l=s;for(;l--;)if(a[l][0]==="exit"&&a[l][1].type==="strikethroughSequenceTemporary"&&a[l][1]._open&&a[s][1].end.offset-a[s][1].start.offset===a[l][1].end.offset-a[l][1].start.offset){a[s][1].type="strikethroughSequence",a[l][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},a[l][1].start),end:Object.assign({},a[s][1].end)},u={type:"strikethroughText",start:Object.assign({},a[l][1].end),end:Object.assign({},a[s][1].start)},g=[["enter",f,c],["enter",a[l][1],c],["exit",a[l][1],c],["enter",u,c]],m=c.parser.constructs.insideSpan.null;m&&ve(g,g.length,0,bi(m,a.slice(l+1,s),c)),ve(g,g.length,0,[["exit",u,c],["enter",a[s][1],c],["exit",a[s][1],c],["exit",f,c]]),ve(a,l-1,s-l+3,g),s=l+g.length-2;break}}for(s=-1;++s<a.length;)a[s][1].type==="strikethroughSequenceTemporary"&&(a[s][1].type="data");return a}function o(a,c,s){const l=this.previous,f=this.events;let u=0;return g;function g(h){return l===126&&f[f.length-1][1].type!=="characterEscape"?s(h):(a.enter("strikethroughSequenceTemporary"),m(h))}function m(h){const b=je(l);if(h===126)return u>1?s(h):(a.consume(h),u++,m);if(u<2&&!t)return s(h);const x=a.exit("strikethroughSequenceTemporary"),w=je(h);return x._open=!w||w===2&&!!b,x._close=!b||b===2&&!!w,c(h)}}}class Ni{constructor(){this.map=[]}add(r,t,n){Ei(this,r,t,n)}consume(r){if(this.map.sort(function(o,a){return o[0]-a[0]}),this.map.length===0)return;let t=this.map.length;const n=[];for(;t>0;)t-=1,n.push(r.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),r.length=this.map[t][0];n.push(r.slice()),r.length=0;let i=n.pop();for(;i;){for(const o of i)r.push(o);i=n.pop()}this.map.length=0}}function Ei(e,r,t,n){let i=0;if(!(t===0&&n.length===0)){for(;i<e.map.length;){if(e.map[i][0]===r){e.map[i][1]+=t,e.map[i][2].push(...n);return}i+=1}e.map.push([r,t,n])}}function Ri(e,r){let t=!1;const n=[];for(;r<e.length;){const i=e[r];if(t){if(i[0]==="enter")i[1].type==="tableContent"&&n.push(e[r+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[r-1][1].type==="tableDelimiterMarker"){const o=n.length-1;n[o]=n[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(t=!0);r+=1}return n}function Li(){return{flow:{null:{name:"table",tokenize:Di,resolveAll:Fi}}}}function Di(e,r,t){const n=this;let i=0,o=0,a;return c;function c(p){let F=n.events.length-1;for(;F>-1;){const E=n.events[F][1].type;if(E==="lineEnding"||E==="linePrefix")F--;else break}const K=F>-1?n.events[F][1].type:null,A=K==="tableHead"||K==="tableRow"?P:s;return A===P&&n.parser.lazy[n.now().line]?t(p):A(p)}function s(p){return e.enter("tableHead"),e.enter("tableRow"),l(p)}function l(p){return p===124||(a=!0,o+=1),f(p)}function f(p){return p===null?t(p):le(p)?o>1?(o=0,n.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),m):t(p):Z(p)?ee(e,f,"whitespace")(p):(o+=1,a&&(a=!1,i+=1),p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),a=!0,f):(e.enter("data"),u(p)))}function u(p){return p===null||p===124||q(p)?(e.exit("data"),f(p)):(e.consume(p),p===92?g:u)}function g(p){return p===92||p===124?(e.consume(p),u):u(p)}function m(p){return n.interrupt=!1,n.parser.lazy[n.now().line]?t(p):(e.enter("tableDelimiterRow"),a=!1,Z(p)?ee(e,h,"linePrefix",n.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(p):h(p))}function h(p){return p===45||p===58?x(p):p===124?(a=!0,e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),b):M(p)}function b(p){return Z(p)?ee(e,x,"whitespace")(p):x(p)}function x(p){return p===58?(o+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),w):p===45?(o+=1,w(p)):p===null||le(p)?_(p):M(p)}function w(p){return p===45?(e.enter("tableDelimiterFiller"),C(p)):M(p)}function C(p){return p===45?(e.consume(p),C):p===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(p))}function v(p){return Z(p)?ee(e,_,"whitespace")(p):_(p)}function _(p){return p===124?h(p):p===null||le(p)?!a||i!==o?M(p):(e.exit("tableDelimiterRow"),e.exit("tableHead"),r(p)):M(p)}function M(p){return t(p)}function P(p){return e.enter("tableRow"),O(p)}function O(p){return p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),O):p===null||le(p)?(e.exit("tableRow"),r(p)):Z(p)?ee(e,O,"whitespace")(p):(e.enter("data"),S(p))}function S(p){return p===null||p===124||q(p)?(e.exit("data"),O(p)):(e.consume(p),p===92?N:S)}function N(p){return p===92||p===124?(e.consume(p),S):S(p)}}function Fi(e,r){let t=-1,n=!0,i=0,o=[0,0,0,0],a=[0,0,0,0],c=!1,s=0,l,f,u;const g=new Ni;for(;++t<e.length;){const m=e[t],h=m[1];m[0]==="enter"?h.type==="tableHead"?(c=!1,s!==0&&(yt(g,r,s,l,f),f=void 0,s=0),l={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},g.add(t,0,[["enter",l,r]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(n=!0,u=void 0,o=[0,0,0,0],a=[0,t+1,0,0],c&&(c=!1,f={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},g.add(t,0,[["enter",f,r]])),i=h.type==="tableDelimiterRow"?2:f?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(n=!1,a[2]===0&&(o[1]!==0&&(a[0]=a[1],u=Ce(g,r,o,i,void 0,u),o=[0,0,0,0]),a[2]=t)):h.type==="tableCellDivider"&&(n?n=!1:(o[1]!==0&&(a[0]=a[1],u=Ce(g,r,o,i,void 0,u)),o=a,a=[o[1],t,0,0])):h.type==="tableHead"?(c=!0,s=t):h.type==="tableRow"||h.type==="tableDelimiterRow"?(s=t,o[1]!==0?(a[0]=a[1],u=Ce(g,r,o,i,t,u)):a[1]!==0&&(u=Ce(g,r,a,i,t,u)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(a[3]=t)}for(s!==0&&yt(g,r,s,l,f),g.consume(r.events),t=-1;++t<r.events.length;){const m=r.events[t];m[0]==="enter"&&m[1].type==="table"&&(m[1]._align=Ri(r.events,t))}return e}function Ce(e,r,t,n,i,o){const a=n===1?"tableHeader":n===2?"tableDelimiter":"tableData",c="tableContent";t[0]!==0&&(o.end=Object.assign({},ce(r.events,t[0])),e.add(t[0],0,[["exit",o,r]]));const s=ce(r.events,t[1]);if(o={type:a,start:Object.assign({},s),end:Object.assign({},s)},e.add(t[1],0,[["enter",o,r]]),t[2]!==0){const l=ce(r.events,t[2]),f=ce(r.events,t[3]),u={type:c,start:Object.assign({},l),end:Object.assign({},f)};if(e.add(t[2],0,[["enter",u,r]]),n!==2){const g=r.events[t[2]],m=r.events[t[3]];if(g[1].end=Object.assign({},m[1].end),g[1].type="chunkText",g[1].contentType="text",t[3]>t[2]+1){const h=t[2]+1,b=t[3]-t[2]-1;e.add(h,b,[])}}e.add(t[3]+1,0,[["exit",u,r]])}return i!==void 0&&(o.end=Object.assign({},ce(r.events,i)),e.add(i,0,[["exit",o,r]]),o=void 0),o}function yt(e,r,t,n,i){const o=[],a=ce(r.events,t);i&&(i.end=Object.assign({},a),o.push(["exit",i,r])),n.end=Object.assign({},a),o.push(["exit",n,r]),e.add(t+1,0,o)}function ce(e,r){const t=e[r],n=t[0]==="enter"?"start":"end";return t[1][n]}const Ui={name:"tasklistCheck",tokenize:$i};function zi(){return{text:{91:Ui}}}function $i(e,r,t){const n=this;return i;function i(s){return n.previous!==null||!n._gfmTasklistFirstContentOfListItem?t(s):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),o)}function o(s){return q(s)?(e.enter("taskListCheckValueUnchecked"),e.consume(s),e.exit("taskListCheckValueUnchecked"),a):s===88||s===120?(e.enter("taskListCheckValueChecked"),e.consume(s),e.exit("taskListCheckValueChecked"),a):t(s)}function a(s){return s===93?(e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),c):t(s)}function c(s){return le(s)?r(s):Z(s)?e.check({tokenize:Oi},r,t)(s):t(s)}}function Oi(e,r,t){return ee(e,n,"whitespace");function n(i){return i===null?t(i):r(i)}}function Bi(e){return ii([ui(),vi(),_i(e),Li(),zi()])}const qi={};function Wi(e){const r=this,t=e||qi,n=r.data(),i=n.micromarkExtensions||(n.micromarkExtensions=[]),o=n.fromMarkdownExtensions||(n.fromMarkdownExtensions=[]),a=n.toMarkdownExtensions||(n.toMarkdownExtensions=[]);i.push(Bi(t)),o.push(ni()),a.push(ai(t))}function z(...e){return e.filter(Boolean).join(" ")}const Hi=({content:e})=>d.jsx($e.MarkdownTextPrimitive,{remarkPlugins:[Wi],className:"cuadra-aui-md",components:Qi,children:e}),Ye=y.memo(Hi),Vi=({language:e,code:r})=>{const{isCopied:t,copyToClipboard:n}=Ki(),i=()=>{!r||t||n(r)};return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-4 cuadra-mt-4 cuadra-rounded-t-lg cuadra-bg-muted/50 cuadra-border-b cuadra-border-border cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-font-brand",children:[d.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),d.jsxs("button",{onClick:i,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!t&&d.jsx(Tr,{className:"cuadra-h-4 cuadra-w-4"}),t&&d.jsx(wt,{className:"cuadra-h-4 cuadra-w-4"})]})]})},Ki=({copiedDuration:e=3e3}={})=>{const[r,t]=y.useState(!1);return{isCopied:r,copyToClipboard:i=>{i&&navigator.clipboard.writeText(i).then(()=>{t(!0),setTimeout(()=>t(!1),e)})}}},Qi=$e.unstable_memoizeMarkdownComponents({h1:({className:e,...r})=>d.jsx("h1",{className:z("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...r}),h2:({className:e,...r})=>d.jsx("h2",{className:z("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h3:({className:e,...r})=>d.jsx("h3",{className:z("cuadra-mb-3 cuadra-mt-5 cuadra-scroll-m-20 cuadra-text-lg cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h4:({className:e,...r})=>d.jsx("h4",{className:z("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h5:({className:e,...r})=>d.jsx("h5",{className:z("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h6:({className:e,...r})=>d.jsx("h6",{className:z("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...r}),p:({className:e,...r})=>d.jsx("p",{className:z("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),a:({className:e,...r})=>d.jsx("a",{className:z("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...r}),blockquote:({className:e,...r})=>d.jsx("blockquote",{className:z("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...r}),ul:({className:e,...r})=>d.jsx("ul",{className:z("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...r}),ol:({className:e,...r})=>d.jsx("ol",{className:z("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...r}),hr:({className:e,...r})=>d.jsx("hr",{className:z("cuadra-my-5 cuadra-border-b",e),...r}),table:({className:e,...r})=>d.jsx("table",{className:z("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...r}),th:({className:e,...r})=>d.jsx("th",{className:z("cuadra-bg-muted cuadra-px-4 cuadra-py-2 cuadra-text-left cuadra-font-normal first:cuadra-rounded-tl-lg last:cuadra-rounded-tr-lg [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),td:({className:e,...r})=>d.jsx("td",{className:z("cuadra-border-b cuadra-border-l cuadra-px-4 cuadra-py-2 cuadra-text-left last:cuadra-border-r [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),tr:({className:e,...r})=>d.jsx("tr",{className:z("cuadra-m-0 cuadra-border-b cuadra-p-0 first:cuadra-border-t [&:last-child>td:first-child]:cuadra-rounded-bl-lg [&:last-child>td:last-child]:cuadra-rounded-br-lg",e),...r}),sup:({className:e,...r})=>d.jsx("sup",{className:z("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...r}),pre:({className:e,...r})=>d.jsx("pre",{className:z("cuadra-overflow-x-auto cuadra-whitespace-pre-wrap cuadra-break-words cuadra-rounded-b-lg !cuadra-rounded-t-none cuadra-bg-muted cuadra-p-4 cuadra-text-foreground font-brand",e),...r}),code:function({className:r,...t}){const n=$e.useIsMarkdownCodeBlock();return d.jsx("code",{className:z(!n&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",r),...t})},CodeHeader:Vi});function Je({className:e="",variant:r="default",...t}){const n="cuadra-inline-flex cuadra-items-center cuadra-rounded-md cuadra-px-3 cuadra-py-1.5 cuadra-text-xs cuadra-font-medium font-brand",i={default:"cuadra-border cuadra-border-border cuadra-bg-muted cuadra-text-muted-foreground",subtle:"cuadra-border cuadra-border-border/50 cuadra-bg-muted/50 cuadra-text-muted-foreground",outline:"cuadra-border cuadra-border-border cuadra-bg-background cuadra-text-foreground",ghost:"cuadra-text-muted-foreground"};return d.jsx("div",{className:`${n} ${i[r]||i.default} ${e}`,...t})}function Gi(e){const r=new Map;for(const t of e){const n=r.get(t.filename);(!n||t.score>n.score)&&r.set(t.filename,t)}return Array.from(r.values()).sort((t,n)=>n.score-t.score)}function ir({sources:e,maxVisible:r=3}){if(!e||e.length===0)return null;const t=Gi(e),n=t.slice(0,r),i=t.length-r;return d.jsxs("div",{className:"cuadra-mt-4 cuadra-pt-3 cuadra-border-t cuadra-border-border",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-mb-2.5",children:[d.jsx(kt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),d.jsx("span",{className:"cuadra-text-xs cuadra-font-medium cuadra-text-muted-foreground font-brand",children:"Sources"})]}),d.jsxs("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-gap-2",children:[n.map((o,a)=>d.jsx(Ji,{source:o},o.sourceId||a)),i>0&&d.jsxs(Je,{variant:"subtle",children:["+",i," more"]})]})]})}function Yi(e){switch(e.split(".").pop()?.toLowerCase()){case"csv":case"xlsx":case"xls":return Ir;case"md":case"txt":return Mr;default:return kt}}function Ji({source:e}){const{filename:r,score:t}=e,n=Yi(r);return d.jsxs(Je,{className:"cuadra-gap-2 cuadra-cursor-default",title:t<1?`${Math.round(t*100)}% relevant`:void 0,children:[d.jsx(n,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-opacity-60"}),d.jsx("span",{className:"cuadra-truncate cuadra-max-w-[180px]",children:r}),t<1&&t>0&&d.jsxs("span",{className:"cuadra-opacity-50 cuadra-text-[10px] cuadra-tabular-nums",children:[Math.round(t*100),"%"]})]})}const Xi=y.forwardRef(function({welcomeTitle:r="What shall we explore today?",extraTopPadding:t,suggestions:n,inputPlaceholder:i="Reply...",enableAttachments:o=!1,preMadeResponseDelay:a=1e3,streamingSpeed:c=50,safeArea:s=!1,composerBorder:l=!1,models:f,selectedModelId:u,onModelChange:g,showChatHeader:m=!1},h){const b=T.useThreadRuntime(),x=T.useAssistantApi(),[w,C]=y.useState(!1),[v,_]=y.useState(null),[M,P]=y.useState(!1),O=T.useThread(A=>{const E=A.messages;return!E||E.length===0}),S=O&&!w,N=y.useCallback((A,E,Q)=>{if(!M)try{const U=Q?.streamingSpeed??c,k=Q?.delay??a;Pt(A,E,U,k),x.composer().setText(A),setTimeout(()=>{x.composer().send()},10)}catch{}},[M,c,a,x]),p=y.useCallback(A=>{try{x.composer().setText(A),setTimeout(()=>{x.composer().send()},10)}catch{}},[x]),F=y.useCallback(async A=>{if(!(M||!b))try{if(A.response){const E=A.responseDelay??a;await N(A.prompt,A.response,{delay:E,streamingSpeed:c})}else p(A.prompt)}catch{}},[b,M,a,c,N,p]),K=y.useCallback(async()=>{try{const E=window.__cuadraThreadListRuntime?.threadList;E?.switchToNewThread&&await E.switchToNewThread()}catch{}},[]);return y.useImperativeHandle(h,()=>({sendMessage:p,sendPreMadeQA:N,clearChat:K}),[p,N,K]),y.useEffect(()=>{if(!b){C(!1);return}try{const A=b?.store;if(!A){C(!1);return}const E=A.subscribe?.(U=>{const k=U?.threadId,j=U?.messages||[],R=U?.isLoadingHistory||!1,L=j.length;k&&k!==v&&_(k),C(R&&L===0)}),Q=A.getState?.();if(Q){const U=Q?.threadId,k=Q?.messages||[],j=Q?.isLoadingHistory||!1,R=k.length;U&&U!==v&&_(U),C(j&&R===0)}return()=>{E&&E()}}catch{C(!1)}},[b,v]),d.jsxs(T.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full cuadra-relative",children:[m&&d.jsx(io,{}),d.jsxs(T.ComposerPrimitive.AttachmentDropzone,{disabled:!o,className:`cuadra-flex-1 cuadra-flex cuadra-flex-col cuadra-min-h-0 cuadra-relative ${S?"cuadra-justify-center":""}`,children:[d.jsx("div",{className:"cuadra-dropzone-overlay cuadra-pointer-events-none cuadra-absolute cuadra-inset-0 cuadra-z-50 cuadra-flex cuadra-items-center cuadra-justify-center cuadra-rounded-lg cuadra-transition-opacity cuadra-duration-200",style:{opacity:0},children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-14 cuadra-rounded-2xl",style:{backgroundColor:"var(--cuadra-primary)",color:"white"},children:d.jsx(Ur,{className:"cuadra-h-6 cuadra-w-6"})}),d.jsx("p",{className:"cuadra-text-sm cuadra-font-medium cuadra-text-foreground font-brand",children:"Drop files here"})]})}),d.jsx(T.ThreadPrimitive.Viewport,{className:`cuadra-w-full cuadra-bg-inherit cuadra-relative scrollbar-thin ${S?"cuadra-flex-none":"cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto"}`,style:{paddingTop:S?"0":t||(m?"0.5rem":"2rem")},children:w?d.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[d.jsx(Ct,{className:"cuadra-h-5 cuadra-w-5 cuadra-animate-spin cuadra-text-muted-foreground"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):d.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full cuadra-px-4",children:[d.jsx(T.ThreadPrimitive.Empty,{children:d.jsx(Zi,{title:r})}),d.jsx(T.ThreadPrimitive.Messages,{components:{UserMessage:eo,AssistantMessage:no}})]})}),d.jsx("div",{className:`cuadra-w-full cuadra-px-4 cuadra-pt-2 ${S?"cuadra-pb-2":"cuadra-pb-4"}`,style:s?{paddingBottom:"calc(env(safe-area-inset-bottom) + 1rem)"}:void 0,children:d.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:[o&&d.jsx(T.ComposerPrimitive.Attachments,{components:{Attachment:()=>{const A=T.useAssistantState(({attachment:E})=>E);return A?d.jsxs("div",{className:"cuadra-relative cuadra-inline-flex cuadra-items-center cuadra-gap-2 cuadra-mb-2 cuadra-px-3 cuadra-py-1.5 cuadra-rounded-lg cuadra-transition-colors",style:{backgroundColor:"var(--cuadra-muted)",border:"1px solid rgba(0,0,0,0.06)"},children:[d.jsx(vt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground",strokeWidth:1.5}),d.jsx("span",{className:"cuadra-text-xs cuadra-text-foreground font-brand",children:A.name||"Attachment"}),d.jsx(T.AttachmentPrimitive.Remove,{asChild:!0,children:d.jsx("button",{type:"button",className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-4 cuadra-rounded-full hover:cuadra-bg-background/60 cuadra-transition-colors cuadra-ml-1","aria-label":"Remove attachment",children:d.jsx($r,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})})]}):null}}}),d.jsxs(T.ComposerPrimitive.Root,{className:"cuadra-relative cuadra-w-full cuadra-rounded-2xl cuadra-transition-shadow cuadra-duration-300 cuadra-flex cuadra-flex-col",style:{backgroundColor:"var(--cuadra-composer)",boxShadow:"var(--cuadra-composer-shadow)",border:l?"1px solid hsl(var(--cuadra-border))":"none"},children:[d.jsx(T.ComposerPrimitive.Input,{asChild:!0,children:d.jsx("textarea",{rows:1,placeholder:i,className:"cuadra-flex cuadra-min-h-[44px] cuadra-w-full cuadra-rounded-t-2xl cuadra-border-0 cuadra-bg-transparent cuadra-px-4 cuadra-pt-3.5 cuadra-pb-1 cuadra-text-base cuadra-text-foreground placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-resize-none font-brand",style:{fontSize:"1rem",lineHeight:"1.5"}})}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-pb-2.5 cuadra-pt-1",children:[d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:o&&d.jsx(T.ComposerPrimitive.AddAttachment,{multiple:!0,asChild:!0,children:d.jsxs("button",{type:"button",className:"cuadra-group cuadra-relative cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-8 cuadra-rounded-lg hover:cuadra-bg-muted/60 cuadra-transition-colors","aria-label":"Attach files",children:[d.jsx(Tt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground",strokeWidth:1.5}),d.jsx("span",{className:"cuadra-pointer-events-none cuadra-absolute cuadra-bottom-full cuadra-left-1/2 cuadra--translate-x-1/2 cuadra-mb-1.5 cuadra-whitespace-nowrap cuadra-rounded-md cuadra-px-2.5 cuadra-py-1 cuadra-text-xs cuadra-text-foreground cuadra-opacity-0 group-hover:cuadra-opacity-100 cuadra-transition-opacity cuadra-duration-150 cuadra-delay-300 font-brand",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:"Attach files"})]})})}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[f&&f.length>0&&d.jsx(ao,{models:f,selectedModelId:u,onModelChange:g,threadIsEmpty:O,onNewChat:K}),d.jsx(T.ComposerPrimitive.Send,{asChild:!0,children:d.jsx("button",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-8 cuadra-rounded-full cuadra-transition-all cuadra-duration-200 hover:cuadra-opacity-90 disabled:cuadra-opacity-30 disabled:cuadra-cursor-not-allowed",style:{backgroundColor:"var(--cuadra-primary)",color:"white"},"aria-label":"Send message",type:"button",children:d.jsx(wr,{className:"cuadra-h-4 cuadra-w-4",strokeWidth:2})})})]})]})]})]})}),S&&n&&n.length>0&&d.jsx("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-justify-center cuadra-gap-2 cuadra-px-4 cuadra-pb-6 cuadra-pt-1 cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:n.map((A,E)=>d.jsx("button",{type:"button",onClick:()=>F(A),disabled:M,className:"cuadra-px-3.5 cuadra-py-2 cuadra-rounded-full cuadra-text-sm cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-all cuadra-duration-200 font-brand cuadra-cursor-pointer disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed",style:{backgroundColor:"var(--cuadra-composer)",boxShadow:"0 0 0 1px rgba(0,0,0,0.06)"},children:A.prompt},`suggestion-${E}`))})]})]})});function Zi({title:e}){return d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-text-center cuadra-py-6",children:d.jsx("h2",{className:"cuadra-text-4xl cuadra-font-normal cuadra-text-muted-foreground cuadra-tracking-tight",style:{fontFamily:"var(--cuadra-font-logo), Outfit, -apple-system, sans-serif"},children:e})})}function eo(){return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-end cuadra-py-2.5",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-end cuadra-gap-2 cuadra-max-w-[80%]",children:[d.jsx(T.MessagePrimitive.Attachments,{components:{Attachment:()=>{const e=T.useAssistantState(({attachment:o})=>o);if(!e)return null;const r=e.type==="image",t=e.file,n=e.content?.find(o=>o.type==="image"),i=t?URL.createObjectURL(t):n?.image;return d.jsx("div",{className:"cuadra-mb-1",children:r&&i?d.jsx("img",{src:i,alt:e.name||"Attachment",className:"cuadra-rounded-2xl cuadra-max-h-64 cuadra-max-w-full cuadra-object-contain",style:{border:"1px solid rgba(0,0,0,0.06)"}}):d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 cuadra-rounded-xl cuadra-px-3 cuadra-py-2",style:{backgroundColor:"var(--cuadra-muted)",border:"1px solid rgba(0,0,0,0.06)"},children:[d.jsx(vt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),d.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground font-brand",children:e.name||"Attachment"})]})})}}}),d.jsx("div",{className:"cuadra-break-words cuadra-text-foreground font-brand",style:{borderRadius:"1.25rem",backgroundColor:"var(--cuadra-muted)",paddingLeft:"1rem",paddingRight:"1rem",paddingTop:"0.625rem",paddingBottom:"0.625rem",wordBreak:"break-word",fontSize:"0.9375rem",lineHeight:"1.625"},children:d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(Ye,{content:e||""})}})})]})})}function to({text:e}){const[r,t]=y.useState(!1),n=T.useAssistantState(({message:i})=>i?.status?.type==="running");return e?n?d.jsx("div",{className:"cuadra-mb-3 cuadra-py-1",children:d.jsx("div",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand cuadra-animate-text-shimmer",children:e})}):d.jsxs("div",{className:"cuadra-mb-3",children:[d.jsxs("button",{type:"button",onClick:()=>t(!r),className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-py-1 cuadra-text-sm cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-colors font-brand",children:[d.jsx(We,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-transition-transform cuadra-duration-200 ${r?"":"cuadra--rotate-90"}`}),d.jsx("span",{children:"Reasoning"})]}),d.jsx("div",{className:`cuadra-overflow-hidden cuadra-transition-all cuadra-duration-200 cuadra-ease-out ${r?"cuadra-max-h-[2000px] cuadra-opacity-100":"cuadra-max-h-0 cuadra-opacity-0"}`,children:d.jsx("div",{className:"cuadra-pl-5 cuadra-pt-2 cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand",children:d.jsx(Ye,{content:e})})})]}):null}function ro(){return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2.5 cuadra-text-muted-foreground cuadra-text-sm font-brand cuadra-py-3",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:[d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"0ms",backgroundColor:"var(--cuadra-primary)",opacity:.7}}),d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"150ms",backgroundColor:"var(--cuadra-primary)",opacity:.5}}),d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"300ms",backgroundColor:"var(--cuadra-primary)",opacity:.3}})]}),d.jsx("span",{children:"Thinking..."})]})}function no(){const e=T.useAssistantState(({message:a})=>a?.status?.type==="running"),r=T.useAssistantState(({message:a})=>{const c=a?.content;return!c||!Array.isArray(c)?!1:c.some(s=>!!(s.type==="text"&&s.text&&s.text.length>0||s.type==="reasoning"&&s.text&&s.text.length>0))}),t=y.useRef(!1),[n,i]=y.useState(null);y.useEffect(()=>{if(e&&r&&!t.current){const a=X.getCurrentMessageId();a&&(t.current=!0,i(a))}},[e,r]);const o=y.useSyncExternalStore(a=>X.subscribe(a),()=>{if(n){const a=X.getForMessage(n);return a.sources?.length?a.sources:null}if(e&&r){const a=X.getCurrentMessageId();if(a){const c=X.getForMessage(a);return c.sources?.length?c.sources:null}}return null},()=>null);return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-start cuadra-py-2.5",children:d.jsxs("div",{className:"cuadra-text-foreground cuadra-max-w-full cuadra-break-words font-brand",style:{fontSize:"0.9375rem",lineHeight:"1.75"},children:[d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:a})=>d.jsx(Ye,{content:a||""}),Reasoning:({text:a})=>d.jsx(to,{text:a||""})}}),e&&!r&&d.jsx(ro,{}),o&&o.length>0&&d.jsx(ir,{sources:o})]})})}function ao({models:e,selectedModelId:r,onModelChange:t,threadIsEmpty:n,onNewChat:i}){const[o,a]=y.useState(!1),c=e.find(l=>l.id===r)||e[0];if(!c)return null;const s=async l=>{a(!1),!n&&l!==r&&await i?.(),t?.(l)};return d.jsxs("div",{className:"cuadra-relative",children:[d.jsxs("button",{type:"button",onClick:()=>a(!o),className:"cuadra-flex cuadra-items-center cuadra-gap-1 cuadra-px-2.5 cuadra-py-1.5 cuadra-rounded-lg cuadra-text-xs cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-colors font-brand",children:[d.jsx("span",{children:c.name}),d.jsx(We,{className:"cuadra-h-3 cuadra-w-3"})]}),o&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>a(!1)}),d.jsx("div",{className:"cuadra-absolute cuadra-bottom-full cuadra-right-0 cuadra-mb-2 cuadra-z-50 cuadra-rounded-xl cuadra-min-w-[200px] cuadra-overflow-hidden cuadra-py-1",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)"},children:e.map(l=>d.jsxs("button",{type:"button",className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted/60 cuadra-transition-colors font-brand",onClick:()=>s(l.id),children:[d.jsxs("div",{className:"cuadra-flex cuadra-flex-col",children:[d.jsx("span",{className:"cuadra-text-foreground",children:l.name}),l.description&&d.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground",children:l.description})]}),l.id===r&&d.jsx(wt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-primary cuadra-flex-shrink-0"})]},l.id))})]})]})}function io(){const e=T.useAssistantState(({threadListItem:i})=>i?.title??null),[r,t]=y.useState(!1),n=e||"Untitled chat";return d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-px-3 cuadra-py-2 cuadra-min-h-[48px]",children:d.jsxs("div",{className:"cuadra-relative",children:[d.jsxs("button",{type:"button",onClick:()=>t(!r),className:"cuadra-flex cuadra-items-center cuadra-gap-1 cuadra-text-sm cuadra-text-foreground hover:cuadra-bg-muted/60 cuadra-rounded-lg cuadra-px-2 cuadra-py-1.5 cuadra-transition-colors font-brand",children:[d.jsx("span",{className:"cuadra-font-medium cuadra-truncate cuadra-max-w-[200px]",children:n}),d.jsx(We,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground cuadra-flex-shrink-0 cuadra-transition-transform cuadra-duration-200 ${r?"cuadra-rotate-180":""}`})]}),r&&d.jsx(oo,{onClose:()=>t(!1)})]})})}function oo({onClose:e}){return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:e}),d.jsx("div",{className:"cuadra-absolute cuadra-left-0 cuadra-top-full cuadra-mt-1 cuadra-z-50 cuadra-w-[300px] cuadra-rounded-xl cuadra-overflow-hidden cuadra-flex cuadra-flex-col",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)"},children:d.jsxs(T.ThreadListPrimitive.Root,{className:"cuadra-flex cuadra-flex-col",children:[d.jsx("div",{className:"cuadra-px-2 cuadra-py-1.5",children:d.jsxs(T.ThreadListPrimitive.New,{className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-gap-2.5 cuadra-px-3 cuadra-py-2 cuadra-rounded-lg cuadra-text-sm cuadra-text-foreground hover:cuadra-bg-muted cuadra-transition-colors cuadra-cursor-pointer font-brand",onClick:e,children:[d.jsx(Tt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),"New Chat"]})}),d.jsx(so,{onSelect:e})]})})]})}function so({onSelect:e}){const r=T.useAssistantState(({threads:i})=>i?.threadIds??[]),t=T.useAssistantState(({threads:i})=>i?.newThreadId);return r.some(i=>i!==t)?d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-mx-3 cuadra-my-0.5",style:{borderTop:"1px solid rgba(0,0,0,0.06)"}}),d.jsx("div",{className:"cuadra-overflow-y-auto cuadra-px-2 cuadra-pb-1.5 scrollbar-thin",style:{maxHeight:"340px"},children:d.jsx(T.ThreadListPrimitive.Items,{components:{ThreadListItem:i=>d.jsx(co,{...i,onSelect:e})}})})]}):null}function co({onSelect:e}){const r=T.useThreadListItem(),t=T.useThreadListItemRuntime(),n=T.useAssistantRuntime(),i=T.useThread(x=>x.threadId),o=r?.id===i,[a,c]=y.useState(!1),[s,l]=y.useState(!1),[f,u]=y.useState(r?.title||""),[g,m]=y.useState(!1),h=async()=>{if(!r?.remoteId||!f||f===r.title){l(!1);return}try{m(!0),await t.rename(f)}catch{}finally{m(!1),l(!1)}},b=async x=>{x.stopPropagation();try{o&&await n.switchToNewThread(),await t.delete()}catch(w){console.error("[CuadraChat] Failed to delete thread:",w)}};return y.useEffect(()=>{r?.title&&!s&&u(r.title)},[r?.title,s]),r?d.jsxs(T.ThreadListItemPrimitive.Root,{className:`cuadra-relative cuadra-flex cuadra-items-center cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer ${o?"cuadra-bg-muted":"hover:cuadra-bg-muted/60"}`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[s?d.jsx("div",{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0",onClick:x=>x.stopPropagation(),onMouseDown:x=>x.stopPropagation(),onKeyDown:x=>x.stopPropagation(),onKeyUp:x=>x.stopPropagation(),onKeyPress:x=>x.stopPropagation(),children:d.jsx("input",{className:"cuadra-w-full cuadra-bg-transparent cuadra-border-0 cuadra-border-b cuadra-text-sm cuadra-text-foreground cuadra-py-0.5 cuadra-px-0 cuadra-outline-none font-brand",style:{borderBottomColor:"var(--cuadra-primary)",borderBottomWidth:"1.5px"},value:f,onChange:x=>u(x.target.value),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&h(),x.key==="Escape"&&(l(!1),u(r.title||""))},onBlur:()=>void h(),disabled:g,autoFocus:!0})}):d.jsx(T.ThreadListItemPrimitive.Trigger,{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:d.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground cuadra-truncate cuadra-block cuadra-text-left font-brand",children:r.title||"Chat"})}),(a||o)&&!s&&d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-0.5 cuadra-mr-1.5 cuadra-flex-shrink-0",children:[d.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/60 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),l(!0),u(r.title||"Chat")},title:"Rename",children:d.jsx(Er,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})}),d.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-destructive/10 cuadra-transition-colors",onClick:b,title:"Delete",children:d.jsx(Dr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-destructive"})})]})]}):null}const Ue=({children:e,className:r="",paddingX:t="px-0",paddingY:n="py-0",borderSizePx:i=2,style:o,contentStyle:a})=>d.jsx("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-lg cuadra-overflow-hidden cuadra-flex cuadra-flex-col ${t} ${n} ${r}`,style:{border:i>0?`${i}px solid var(--cuadra-primary)`:"none",...o,...a},children:e}),lo=y.createContext(void 0),ze=({children:e,value:r})=>d.jsx(lo.Provider,{value:r,children:e});function uo(){y.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const r=document.createElement("div");r.className="cuadra-flex",document.body.appendChild(r);const t=window.getComputedStyle(r).display==="flex";if(document.body.removeChild(r),t)return;const n=document.createElement("link");n.setAttribute("data-cuadra-uikit","true"),n.rel="stylesheet",n.type="text/css";const i=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:ue&&ue.tagName.toUpperCase()==="SCRIPT"&&ue.src||new URL("index.cjs",document.baseURI).href).href];let o=!1;for(const a of i)if(n.href=a,n.onload=()=>{o=!0},n.onerror=()=>{},document.head.appendChild(n),o)break},[])}const fo=y.forwardRef(function({config:r},t){uo();const n=y.useRef(null),i=y.useRef(!1),{baseUrl:o,proxyUrl:a,sessionToken:c,mode:s="multiChat",modelMode:l="fixed",modelId:f,onModelChange:u,ephemeral:g=!1,systemPrompt:m,enableReasoning:h=!1,initialThreadId:b,welcomeTitle:x,welcomeSubtitle:w,extraTopPadding:C,suggestions:v,inputPlaceholder:_,preMadeResponseDelay:M=1e3,streamingSpeed:P=50,initialMessage:O,initialPreMadeQA:S,theme:N="system",onError:p,onChatCreated:F,onUserMessage:K,onThreadIdUpdate:A,enableAttachments:E=!1,onBeforeRequest:Q,mockResponseOnBlocked:U}=r;y.useImperativeHandle(t,()=>({sendMessage:D=>{n.current?.sendMessage(D)},sendPreMadeQA:(D,ae,ne)=>{n.current?.sendPreMadeQA(D,ae,ne)},clearChat:()=>{n.current?.clearChat()}}),[]),y.useEffect(()=>{if(i.current)return;const D=setTimeout(()=>{S?(i.current=!0,n.current?.sendPreMadeQA(S.question,S.answer,{delay:M,streamingSpeed:P})):O&&(i.current=!0,n.current?.sendMessage(O))},500);return()=>clearTimeout(D)},[O,S,M,P]);const k=a||o||"",j=!!a,R=y.useMemo(()=>new It(k,c||void 0,j),[k,c,j]),[L,V]=y.useState(null),[I,B]=y.useState(!1),[G,re]=y.useState(null),[ye,be]=y.useState(!1);y.useEffect(()=>{s==="multiChat"&&be(!0)},[s]);const H=y.useCallback(async()=>{if(l==="selector"){B(!0),re(null);try{const D=await R.listModels();V(D)}catch(D){re(D instanceof Error?D:new Error("Failed to load models"))}finally{B(!1)}}},[R,l]);y.useEffect(()=>{l==="selector"&&H()},[l,H]),y.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=H),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[H]);const[Y,Ze]=y.useState(l==="fixed"&&f||null),et=y.useRef(Y),we=y.useCallback(D=>{const ae=et.current;Ze(D),et.current=D,u?.(D),ae!==null&&ae!==D&&s==="multiChat"&&setTimeout(()=>{const ne=window.__cuadraThreadListRuntime;if(ne?.threads?.switchToNewThread)try{ne.threads.switchToNewThread()}catch{}else if(ne?.threads?.createThread)try{ne.threads.createThread()}catch{}else if(ne?.switchToNewThread)try{ne.switchToNewThread()}catch{}},100)},[u,s]);y.useEffect(()=>{if(l==="selector"&&L?.items&&L.items.length>0&&!Y){const D=L.items[0];if(D?.id){const ae=D.id;Ze(ae),u?.(ae)}}},[l,L?.items,Y,u]);const ur=l==="fixed"?!!f:!!Y,_e=y.useMemo(()=>(L?.items||[]).filter(D=>D?.id&&D?.displayName).map(D=>({id:D.id,name:D.displayName})),[L]),Ne=y.useMemo(()=>({currentModelId:Y||"",models:_e,modelsLoading:I,modelsError:G,onModelChange:we,refetchModels:H}),[Y,_e,I,G,we,H]);return l==="selector"&&I||s==="multiChat"&&ye?d.jsx(ze,{value:Ne,children:d.jsx(Ue,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",borderSizePx:r.borderless?0:2,children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx(Ct,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):l==="selector"&&!ur&&G?d.jsx(ze,{value:Ne,children:d.jsx(Ue,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:d.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):d.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:d.jsx(ze,{value:Ne,children:d.jsx(pn,{baseUrl:j?k:o||k,sessionToken:c,isProxyMode:j,mode:s,modelMode:l,modelId:Y||f||void 0,onModelChange:we,ephemeral:g,systemPrompt:m,enableReasoning:h,initialThreadId:b,enableAttachments:E,onError:p,onChatCreated:F,onUserMessage:K,onThreadIdUpdate:A,onBeforeRequest:Q,mockResponseOnBlocked:U,onChatsLoaded:()=>{s==="multiChat"&&be(!1)},children:d.jsx(Ue,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${r.containerClass||""}`,borderSizePx:r.borderless?0:2,style:{height:"100%"},children:d.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:d.jsx("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0",children:d.jsx(Xi,{ref:n,welcomeTitle:x,welcomeSubtitle:w,extraTopPadding:C,suggestions:v,inputPlaceholder:_,enableAttachments:E,preMadeResponseDelay:M,streamingSpeed:P,safeArea:r.safeArea,showChatHeader:s==="multiChat",models:l==="selector"?_e:void 0,selectedModelId:Y||void 0,onModelChange:l==="selector"?we:void 0,theme:N})})})})})})})})});function or(e,r=":root"){if(typeof document>"u")return;const t=document.documentElement;if(e.light&&mo(e.light,t),e.dark){let n=document.getElementById("cuadra-theme-dark");n||(n=document.createElement("style"),n.id="cuadra-theme-dark",document.head.appendChild(n));const i=po(e.dark);n.textContent=`.dark { ${i} }`}}const ho={background:"background",foreground:"foreground",card:"card",cardForeground:"card-foreground",popover:"popover",popoverForeground:"popover-foreground",primary:"primary",primaryForeground:"primary-foreground",primaryLight:"primary-light",primaryLighter:"primary-lighter",secondary:"secondary",secondaryForeground:"secondary-foreground",muted:"muted",mutedForeground:"muted-foreground",accent:"accent",accentForeground:"accent-foreground",border:"border",input:"input",ring:"ring",destructive:"destructive",destructiveForeground:"destructive-foreground",success:"success",successForeground:"success-foreground",info:"info",infoForeground:"info-foreground",warning:"warning",warningForeground:"warning-foreground"};function sr(e){const r=ho[e];return r?`--cuadra-${r}`:`--cuadra-${e.replace(/([A-Z])/g,"-$1").toLowerCase()}`}function mo(e,r){Object.entries(e).forEach(([t,n])=>{if(n){const i=sr(t);r.style.setProperty(i,n)}})}function po(e){return Object.entries(e).map(([r,t])=>t?`${sr(r)}: ${t};`:"").filter(Boolean).join(" ")}function go(){if(typeof document>"u")return;const e=document.documentElement;Array.from(e.style).filter(n=>n.startsWith("--cuadra-")).forEach(n=>e.style.removeProperty(n));const t=document.getElementById("cuadra-theme-dark");t&&t.remove()}function xo({onReset:e,error:r}){return d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-h-full cuadra-p-6 cuadra-text-center",children:[d.jsx("div",{className:"cuadra-mb-4",children:d.jsx("svg",{className:"cuadra-w-12 cuadra-h-12 cuadra-text-destructive cuadra-mx-auto",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),d.jsx("h3",{className:"cuadra-text-lg cuadra-font-medium cuadra-text-foreground cuadra-mb-2",children:"Something went wrong"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-mb-4 cuadra-max-w-sm",children:r?.message||"An unexpected error occurred. Please try again."}),d.jsx("button",{onClick:e,className:"cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-medium cuadra-rounded-md cuadra-transition-colors",style:{backgroundColor:"var(--cuadra-primary)",color:"hsl(var(--cuadra-primary-foreground))"},children:"Try Again"})]})}class Xe extends y.Component{constructor(t){super(t);$(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){this.props.onError?.(t,n)}render(){if(this.state.hasError){const{fallback:t}=this.props,{error:n}=this.state;return typeof t=="function"?t(n,this.reset):t||d.jsx(xo,{error:n,onReset:this.reset})}return this.props.children}}function yo(e,r){const t=n=>d.jsx(Xe,{...r,children:d.jsx(e,{...n})});return t.displayName=`withErrorBoundary(${e.displayName||e.name||"Component"})`,t}const fe=y.createContext(null);fe.displayName="CuadraChatContext";function bo(){const e=y.useContext(fe);if(e===null)throw new Error("useCuadraChat must be used within a CuadraChatProvider. Wrap your component tree with <CuadraChatProvider>...</CuadraChatProvider>");return{controls:e.controls,isReady:e.controls!==null}}function wo(){const e=y.useContext(fe);return e===null?null:{controls:e.controls,isReady:e.controls!==null}}function ko({children:e}){const[r,t]=y.useState(null),n=y.useCallback(a=>{t(a)},[]),i=y.useCallback(()=>{t(null)},[]),o=y.useMemo(()=>({controls:r,registerControls:n,unregisterControls:i}),[r,n,i]);return d.jsx(fe.Provider,{value:o,children:e})}function cr(e){return"connection"in e&&typeof e.connection=="object"}function lr(e){return cr(e)?Co(e):vo(e)}function Co(e){return{connection:{baseUrl:e.connection.baseUrl||"",proxyUrl:e.connection.proxyUrl||"",sessionToken:e.connection.sessionToken??null},chat:{mode:e.chat?.mode??"multiChat",modelMode:e.chat?.modelMode??"fixed",modelId:e.chat?.modelId??"",systemPrompt:e.chat?.systemPrompt??"",ephemeral:e.chat?.ephemeral??!1,enableReasoning:e.chat?.enableReasoning??!1,enableAttachments:e.chat?.enableAttachments??!1,initialThreadId:e.chat?.initialThreadId},ui:{theme:e.ui?.theme??"system",customTheme:e.ui?.customTheme,showThemeToggle:e.ui?.showThemeToggle??!0,language:e.ui?.language,welcomeTitle:e.ui?.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.ui?.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.ui?.suggestions,inputPlaceholder:e.ui?.inputPlaceholder??"Type your message...",extraTopPadding:e.ui?.extraTopPadding,borderless:e.ui?.borderless,safeArea:e.ui?.safeArea,orgName:e.ui?.orgName,primaryColor:e.ui?.primaryColor},preMade:{responseDelay:e.preMade?.responseDelay??1e3,streamingSpeed:e.preMade?.streamingSpeed??50},initial:{message:e.initial?.message,preMadeQA:e.initial?.preMadeQA},interceptors:{onBeforeRequest:e.interceptors?.onBeforeRequest,mockResponseOnBlocked:e.interceptors?.mockResponseOnBlocked},callbacks:{onChatCreated:e.callbacks?.onChatCreated,onError:e.callbacks?.onError,onUserMessage:e.callbacks?.onUserMessage,onModelChange:e.callbacks?.onModelChange,onThreadIdUpdate:e.callbacks?.onThreadIdUpdate,onLogout:e.callbacks?.onLogout},className:e.className,errorFallback:e.errorFallback}}function vo(e){return typeof process<"u"&&process.env?.NODE_ENV==="development"&&console.warn(`[CuadraUIKit] Using legacy flat props format. Consider migrating to grouped props for better organization.
20
+ `))}function s(m,h,b,x){const w=b.enter("tableCell"),C=b.enter("phrasing"),v=b.containerPhrasing(m,{...x,before:o,after:o});return C(),w(),v}function l(m,h){return la(m,{align:h,alignDelimiters:n,padding:t,stringLength:i})}function f(m,h,b){const x=m.children;let w=-1;const C=[],v=h.enter("table");for(;++w<x.length;)C[w]=u(x[w],h,b);return v(),C}function u(m,h,b){const x=m.children;let w=-1;const C=[],v=h.enter("tableRow");for(;++w<x.length;)C[w]=s(x[w],m,h,b);return v(),C}function g(m,h,b){let x=Yt.inlineCode(m,h,b);return b.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function Za(){return{exit:{taskListCheckValueChecked:gt,taskListCheckValueUnchecked:gt,paragraph:ti}}}function ei(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:ri}}}function gt(e){const r=this.stack[this.stack.length-2];r.type,r.checked=e.type==="taskListCheckValueChecked"}function ti(e){const r=this.stack[this.stack.length-2];if(r&&r.type==="listItem"&&typeof r.checked=="boolean"){const t=this.stack[this.stack.length-1];t.type;const n=t.children[0];if(n&&n.type==="text"){const i=r.children;let o=-1,a;for(;++o<i.length;){const c=i[o];if(c.type==="paragraph"){a=c;break}}a===t&&(n.value=n.value.slice(1),n.value.length===0?t.children.shift():t.position&&n.position&&typeof n.position.start.offset=="number"&&(n.position.start.column++,n.position.start.offset++,t.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function ri(e,r,t,n){const i=e.children[0],o=typeof e.checked=="boolean"&&i&&i.type==="paragraph",a="["+(e.checked?"x":" ")+"] ",c=t.createTracker(n);o&&c.move(a);let s=Yt.listItem(e,r,t,{...n,...c.current()});return o&&(s=s.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),s;function l(f){return f+a}}function ni(){return[Nn(),Zn(),na(),Va(),Za()]}function ai(e){return{extensions:[En(),ea(e),aa(),Xa(e),ei()]}}function ve(e,r,t,n){const i=e.length;let o=0,a;if(r<0?r=-r>i?0:i+r:r=r>i?i:r,t=t>0?t:0,n.length<1e4)a=Array.from(n),a.unshift(r,t),e.splice(...a);else for(t&&e.splice(r,t);o<n.length;)a=n.slice(o,o+1e4),a.unshift(r,0),e.splice(...a),o+=1e4,r+=1e4}const xt={}.hasOwnProperty;function ii(e){const r={};let t=-1;for(;++t<e.length;)oi(r,e[t]);return r}function oi(e,r){let t;for(t in r){const i=(xt.call(e,t)?e[t]:void 0)||(e[t]={}),o=r[t];let a;if(o)for(a in o){xt.call(i,a)||(i[a]=[]);const c=o[a];si(i[a],Array.isArray(c)?c:c?[c]:[])}}}function si(e,r){let t=-1;const n=[];for(;++t<r.length;)(r[t].add==="after"?e:n).push(r[t]);ve(e,0,0,n)}const ci={tokenize:mi,partial:!0},Jt={tokenize:pi,partial:!0},Xt={tokenize:gi,partial:!0},Zt={tokenize:xi,partial:!0},li={tokenize:yi,partial:!0},er={name:"wwwAutolink",tokenize:fi,previous:rr},tr={name:"protocolAutolink",tokenize:hi,previous:nr},te={name:"emailAutolink",tokenize:di,previous:ar},J={};function ui(){return{text:J}}let ie=48;for(;ie<123;)J[ie]=te,ie++,ie===58?ie=65:ie===91&&(ie=97);J[43]=te;J[45]=te;J[46]=te;J[95]=te;J[72]=[te,tr];J[104]=[te,tr];J[87]=[te,er];J[119]=[te,er];function di(e,r,t){const n=this;let i,o;return a;function a(u){return!qe(u)||!ar.call(n,n.previous)||Ge(n.events)?t(u):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),c(u))}function c(u){return qe(u)?(e.consume(u),c):u===64?(e.consume(u),s):t(u)}function s(u){return u===46?e.check(li,f,l)(u):u===45||u===95||Ve(u)?(o=!0,e.consume(u),s):f(u)}function l(u){return e.consume(u),i=!0,s}function f(u){return o&&i&&pe(n.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),r(u)):t(u)}}function fi(e,r,t){const n=this;return i;function i(a){return a!==87&&a!==119||!rr.call(n,n.previous)||Ge(n.events)?t(a):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(ci,e.attempt(Jt,e.attempt(Xt,o),t),t)(a))}function o(a){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),r(a)}}function hi(e,r,t){const n=this;let i="",o=!1;return a;function a(u){return(u===72||u===104)&&nr.call(n,n.previous)&&!Ge(n.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(u),e.consume(u),c):t(u)}function c(u){if(pe(u)&&i.length<5)return i+=String.fromCodePoint(u),e.consume(u),c;if(u===58){const g=i.toLowerCase();if(g==="http"||g==="https")return e.consume(u),s}return t(u)}function s(u){return u===47?(e.consume(u),o?l:(o=!0,s)):t(u)}function l(u){return u===null||yn(u)||q(u)||oe(u)||Ae(u)?t(u):e.attempt(Jt,e.attempt(Xt,f),t)(u)}function f(u){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),r(u)}}function mi(e,r,t){let n=0;return i;function i(a){return(a===87||a===119)&&n<3?(n++,e.consume(a),i):a===46&&n===3?(e.consume(a),o):t(a)}function o(a){return a===null?t(a):r(a)}}function pi(e,r,t){let n,i,o;return a;function a(l){return l===46||l===95?e.check(Zt,s,c)(l):l===null||q(l)||oe(l)||l!==45&&Ae(l)?s(l):(o=!0,e.consume(l),a)}function c(l){return l===95?n=!0:(i=n,n=void 0),e.consume(l),a}function s(l){return i||n||!o?t(l):r(l)}}function gi(e,r){let t=0,n=0;return i;function i(a){return a===40?(t++,e.consume(a),i):a===41&&n<t?o(a):a===33||a===34||a===38||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===60||a===63||a===93||a===95||a===126?e.check(Zt,r,o)(a):a===null||q(a)||oe(a)?r(a):(e.consume(a),i)}function o(a){return a===41&&n++,e.consume(a),i}}function xi(e,r,t){return n;function n(c){return c===33||c===34||c===39||c===41||c===42||c===44||c===46||c===58||c===59||c===63||c===95||c===126?(e.consume(c),n):c===38?(e.consume(c),o):c===93?(e.consume(c),i):c===60||c===null||q(c)||oe(c)?r(c):t(c)}function i(c){return c===null||c===40||c===91||q(c)||oe(c)?r(c):n(c)}function o(c){return pe(c)?a(c):t(c)}function a(c){return c===59?(e.consume(c),n):pe(c)?(e.consume(c),a):t(c)}}function yi(e,r,t){return n;function n(o){return e.consume(o),i}function i(o){return Ve(o)?t(o):r(o)}}function rr(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||q(e)}function nr(e){return!pe(e)}function ar(e){return!(e===47||qe(e))}function qe(e){return e===43||e===45||e===46||e===95||Ve(e)}function Ge(e){let r=e.length,t=!1;for(;r--;){const n=e[r][1];if((n.type==="labelLink"||n.type==="labelImage")&&!n._balanced){t=!0;break}if(n._gfmAutolinkLiteralWalkedInto){t=!1;break}}return e.length>0&&!t&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),t}function bi(e,r,t){const n=[];let i=-1;for(;++i<e.length;){const o=e[i].resolveAll;o&&!n.includes(o)&&(r=o(r,t),n.push(o))}return r}function ee(e,r,t,n){const i=n?n-1:Number.POSITIVE_INFINITY;let o=0;return a;function a(s){return Z(s)?(e.enter(t),c(s)):r(s)}function c(s){return Z(s)&&o++<i?(e.consume(s),c):(e.exit(t),r(s))}}const wi={partial:!0,tokenize:ki};function ki(e,r,t){return n;function n(o){return Z(o)?ee(e,i,"linePrefix")(o):i(o)}function i(o){return o===null||le(o)?r(o):t(o)}}const Ci={tokenize:Pi,partial:!0};function vi(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Ai,continuation:{tokenize:Si},exit:Mi}},text:{91:{name:"gfmFootnoteCall",tokenize:Ii},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Ti,resolveTo:ji}}}}function Ti(e,r,t){const n=this;let i=n.events.length;const o=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let a;for(;i--;){const s=n.events[i][1];if(s.type==="labelImage"){a=s;break}if(s.type==="gfmFootnoteCall"||s.type==="labelLink"||s.type==="label"||s.type==="image"||s.type==="link")break}return c;function c(s){if(!a||!a._balanced)return t(s);const l=xe(n.sliceSerialize({start:a.end,end:n.now()}));return l.codePointAt(0)!==94||!o.includes(l.slice(1))?t(s):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(s),e.exit("gfmFootnoteCallLabelMarker"),r(s))}}function ji(e,r){let t=e.length;for(;t--;)if(e[t][1].type==="labelImage"&&e[t][0]==="enter"){e[t][1];break}e[t+1][1].type="data",e[t+3][1].type="gfmFootnoteCallLabelMarker";const n={type:"gfmFootnoteCall",start:Object.assign({},e[t+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[t+3][1].end),end:Object.assign({},e[t+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const o={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},a={type:"chunkString",contentType:"string",start:Object.assign({},o.start),end:Object.assign({},o.end)},c=[e[t+1],e[t+2],["enter",n,r],e[t+3],e[t+4],["enter",i,r],["exit",i,r],["enter",o,r],["enter",a,r],["exit",a,r],["exit",o,r],e[e.length-2],e[e.length-1],["exit",n,r]];return e.splice(t,e.length-t+1,...c),e}function Ii(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o=0,a;return c;function c(u){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),s}function s(u){return u!==94?t(u):(e.enter("gfmFootnoteCallMarker"),e.consume(u),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(u){if(o>999||u===93&&!a||u===null||u===91||q(u))return t(u);if(u===93){e.exit("chunkString");const g=e.exit("gfmFootnoteCallString");return i.includes(xe(n.sliceSerialize(g)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(u),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),r):t(u)}return q(u)||(a=!0),o++,e.consume(u),u===92?f:l}function f(u){return u===91||u===92||u===93?(e.consume(u),o++,l):l(u)}}function Ai(e,r,t){const n=this,i=n.parser.gfmFootnotes||(n.parser.gfmFootnotes=[]);let o,a=0,c;return s;function s(h){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),l}function l(h){return h===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",f):t(h)}function f(h){if(a>999||h===93&&!c||h===null||h===91||q(h))return t(h);if(h===93){e.exit("chunkString");const b=e.exit("gfmFootnoteDefinitionLabelString");return o=xe(n.sliceSerialize(b)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),g}return q(h)||(c=!0),a++,e.consume(h),h===92?u:f}function u(h){return h===91||h===92||h===93?(e.consume(h),a++,f):f(h)}function g(h){return h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),i.includes(o)||i.push(o),ee(e,m,"gfmFootnoteDefinitionWhitespace")):t(h)}function m(h){return r(h)}}function Si(e,r,t){return e.check(wi,r,e.attempt(Ci,r,t))}function Mi(e){e.exit("gfmFootnoteDefinition")}function Pi(e,r,t){const n=this;return ee(e,i,"gfmFootnoteDefinitionIndent",5);function i(o){const a=n.events[n.events.length-1];return a&&a[1].type==="gfmFootnoteDefinitionIndent"&&a[2].sliceSerialize(a[1],!0).length===4?r(o):t(o)}}function _i(e){let t=(e||{}).singleTilde;const n={name:"strikethrough",tokenize:o,resolveAll:i};return t==null&&(t=!0),{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function i(a,c){let s=-1;for(;++s<a.length;)if(a[s][0]==="enter"&&a[s][1].type==="strikethroughSequenceTemporary"&&a[s][1]._close){let l=s;for(;l--;)if(a[l][0]==="exit"&&a[l][1].type==="strikethroughSequenceTemporary"&&a[l][1]._open&&a[s][1].end.offset-a[s][1].start.offset===a[l][1].end.offset-a[l][1].start.offset){a[s][1].type="strikethroughSequence",a[l][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},a[l][1].start),end:Object.assign({},a[s][1].end)},u={type:"strikethroughText",start:Object.assign({},a[l][1].end),end:Object.assign({},a[s][1].start)},g=[["enter",f,c],["enter",a[l][1],c],["exit",a[l][1],c],["enter",u,c]],m=c.parser.constructs.insideSpan.null;m&&ve(g,g.length,0,bi(m,a.slice(l+1,s),c)),ve(g,g.length,0,[["exit",u,c],["enter",a[s][1],c],["exit",a[s][1],c],["exit",f,c]]),ve(a,l-1,s-l+3,g),s=l+g.length-2;break}}for(s=-1;++s<a.length;)a[s][1].type==="strikethroughSequenceTemporary"&&(a[s][1].type="data");return a}function o(a,c,s){const l=this.previous,f=this.events;let u=0;return g;function g(h){return l===126&&f[f.length-1][1].type!=="characterEscape"?s(h):(a.enter("strikethroughSequenceTemporary"),m(h))}function m(h){const b=je(l);if(h===126)return u>1?s(h):(a.consume(h),u++,m);if(u<2&&!t)return s(h);const x=a.exit("strikethroughSequenceTemporary"),w=je(h);return x._open=!w||w===2&&!!b,x._close=!b||b===2&&!!w,c(h)}}}class Ni{constructor(){this.map=[]}add(r,t,n){Ei(this,r,t,n)}consume(r){if(this.map.sort(function(o,a){return o[0]-a[0]}),this.map.length===0)return;let t=this.map.length;const n=[];for(;t>0;)t-=1,n.push(r.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),r.length=this.map[t][0];n.push(r.slice()),r.length=0;let i=n.pop();for(;i;){for(const o of i)r.push(o);i=n.pop()}this.map.length=0}}function Ei(e,r,t,n){let i=0;if(!(t===0&&n.length===0)){for(;i<e.map.length;){if(e.map[i][0]===r){e.map[i][1]+=t,e.map[i][2].push(...n);return}i+=1}e.map.push([r,t,n])}}function Ri(e,r){let t=!1;const n=[];for(;r<e.length;){const i=e[r];if(t){if(i[0]==="enter")i[1].type==="tableContent"&&n.push(e[r+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[r-1][1].type==="tableDelimiterMarker"){const o=n.length-1;n[o]=n[o]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(t=!0);r+=1}return n}function Li(){return{flow:{null:{name:"table",tokenize:Di,resolveAll:Fi}}}}function Di(e,r,t){const n=this;let i=0,o=0,a;return c;function c(p){let F=n.events.length-1;for(;F>-1;){const E=n.events[F][1].type;if(E==="lineEnding"||E==="linePrefix")F--;else break}const K=F>-1?n.events[F][1].type:null,A=K==="tableHead"||K==="tableRow"?P:s;return A===P&&n.parser.lazy[n.now().line]?t(p):A(p)}function s(p){return e.enter("tableHead"),e.enter("tableRow"),l(p)}function l(p){return p===124||(a=!0,o+=1),f(p)}function f(p){return p===null?t(p):le(p)?o>1?(o=0,n.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),m):t(p):Z(p)?ee(e,f,"whitespace")(p):(o+=1,a&&(a=!1,i+=1),p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),a=!0,f):(e.enter("data"),u(p)))}function u(p){return p===null||p===124||q(p)?(e.exit("data"),f(p)):(e.consume(p),p===92?g:u)}function g(p){return p===92||p===124?(e.consume(p),u):u(p)}function m(p){return n.interrupt=!1,n.parser.lazy[n.now().line]?t(p):(e.enter("tableDelimiterRow"),a=!1,Z(p)?ee(e,h,"linePrefix",n.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(p):h(p))}function h(p){return p===45||p===58?x(p):p===124?(a=!0,e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),b):M(p)}function b(p){return Z(p)?ee(e,x,"whitespace")(p):x(p)}function x(p){return p===58?(o+=1,a=!0,e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),w):p===45?(o+=1,w(p)):p===null||le(p)?_(p):M(p)}function w(p){return p===45?(e.enter("tableDelimiterFiller"),C(p)):M(p)}function C(p){return p===45?(e.consume(p),C):p===58?(a=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(p))}function v(p){return Z(p)?ee(e,_,"whitespace")(p):_(p)}function _(p){return p===124?h(p):p===null||le(p)?!a||i!==o?M(p):(e.exit("tableDelimiterRow"),e.exit("tableHead"),r(p)):M(p)}function M(p){return t(p)}function P(p){return e.enter("tableRow"),O(p)}function O(p){return p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),O):p===null||le(p)?(e.exit("tableRow"),r(p)):Z(p)?ee(e,O,"whitespace")(p):(e.enter("data"),S(p))}function S(p){return p===null||p===124||q(p)?(e.exit("data"),O(p)):(e.consume(p),p===92?N:S)}function N(p){return p===92||p===124?(e.consume(p),S):S(p)}}function Fi(e,r){let t=-1,n=!0,i=0,o=[0,0,0,0],a=[0,0,0,0],c=!1,s=0,l,f,u;const g=new Ni;for(;++t<e.length;){const m=e[t],h=m[1];m[0]==="enter"?h.type==="tableHead"?(c=!1,s!==0&&(yt(g,r,s,l,f),f=void 0,s=0),l={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},g.add(t,0,[["enter",l,r]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(n=!0,u=void 0,o=[0,0,0,0],a=[0,t+1,0,0],c&&(c=!1,f={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},g.add(t,0,[["enter",f,r]])),i=h.type==="tableDelimiterRow"?2:f?3:1):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(n=!1,a[2]===0&&(o[1]!==0&&(a[0]=a[1],u=Ce(g,r,o,i,void 0,u),o=[0,0,0,0]),a[2]=t)):h.type==="tableCellDivider"&&(n?n=!1:(o[1]!==0&&(a[0]=a[1],u=Ce(g,r,o,i,void 0,u)),o=a,a=[o[1],t,0,0])):h.type==="tableHead"?(c=!0,s=t):h.type==="tableRow"||h.type==="tableDelimiterRow"?(s=t,o[1]!==0?(a[0]=a[1],u=Ce(g,r,o,i,t,u)):a[1]!==0&&(u=Ce(g,r,a,i,t,u)),i=0):i&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(a[3]=t)}for(s!==0&&yt(g,r,s,l,f),g.consume(r.events),t=-1;++t<r.events.length;){const m=r.events[t];m[0]==="enter"&&m[1].type==="table"&&(m[1]._align=Ri(r.events,t))}return e}function Ce(e,r,t,n,i,o){const a=n===1?"tableHeader":n===2?"tableDelimiter":"tableData",c="tableContent";t[0]!==0&&(o.end=Object.assign({},ce(r.events,t[0])),e.add(t[0],0,[["exit",o,r]]));const s=ce(r.events,t[1]);if(o={type:a,start:Object.assign({},s),end:Object.assign({},s)},e.add(t[1],0,[["enter",o,r]]),t[2]!==0){const l=ce(r.events,t[2]),f=ce(r.events,t[3]),u={type:c,start:Object.assign({},l),end:Object.assign({},f)};if(e.add(t[2],0,[["enter",u,r]]),n!==2){const g=r.events[t[2]],m=r.events[t[3]];if(g[1].end=Object.assign({},m[1].end),g[1].type="chunkText",g[1].contentType="text",t[3]>t[2]+1){const h=t[2]+1,b=t[3]-t[2]-1;e.add(h,b,[])}}e.add(t[3]+1,0,[["exit",u,r]])}return i!==void 0&&(o.end=Object.assign({},ce(r.events,i)),e.add(i,0,[["exit",o,r]]),o=void 0),o}function yt(e,r,t,n,i){const o=[],a=ce(r.events,t);i&&(i.end=Object.assign({},a),o.push(["exit",i,r])),n.end=Object.assign({},a),o.push(["exit",n,r]),e.add(t+1,0,o)}function ce(e,r){const t=e[r],n=t[0]==="enter"?"start":"end";return t[1][n]}const Ui={name:"tasklistCheck",tokenize:$i};function zi(){return{text:{91:Ui}}}function $i(e,r,t){const n=this;return i;function i(s){return n.previous!==null||!n._gfmTasklistFirstContentOfListItem?t(s):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),o)}function o(s){return q(s)?(e.enter("taskListCheckValueUnchecked"),e.consume(s),e.exit("taskListCheckValueUnchecked"),a):s===88||s===120?(e.enter("taskListCheckValueChecked"),e.consume(s),e.exit("taskListCheckValueChecked"),a):t(s)}function a(s){return s===93?(e.enter("taskListCheckMarker"),e.consume(s),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),c):t(s)}function c(s){return le(s)?r(s):Z(s)?e.check({tokenize:Oi},r,t)(s):t(s)}}function Oi(e,r,t){return ee(e,n,"whitespace");function n(i){return i===null?t(i):r(i)}}function Bi(e){return ii([ui(),vi(),_i(e),Li(),zi()])}const qi={};function Wi(e){const r=this,t=e||qi,n=r.data(),i=n.micromarkExtensions||(n.micromarkExtensions=[]),o=n.fromMarkdownExtensions||(n.fromMarkdownExtensions=[]),a=n.toMarkdownExtensions||(n.toMarkdownExtensions=[]);i.push(Bi(t)),o.push(ni()),a.push(ai(t))}function z(...e){return e.filter(Boolean).join(" ")}const Hi=({content:e})=>d.jsx($e.MarkdownTextPrimitive,{remarkPlugins:[Wi],className:"cuadra-aui-md",components:Qi,children:e}),Ye=y.memo(Hi),Vi=({language:e,code:r})=>{const{isCopied:t,copyToClipboard:n}=Ki(),i=()=>{!r||t||n(r)};return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-4 cuadra-mt-4 cuadra-rounded-t-lg cuadra-bg-muted/50 cuadra-border-b cuadra-border-border cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-normal cuadra-text-foreground cuadra-font-brand",children:[d.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),d.jsxs("button",{onClick:i,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!t&&d.jsx(Tr,{className:"cuadra-h-4 cuadra-w-4"}),t&&d.jsx(wt,{className:"cuadra-h-4 cuadra-w-4"})]})]})},Ki=({copiedDuration:e=3e3}={})=>{const[r,t]=y.useState(!1);return{isCopied:r,copyToClipboard:i=>{i&&navigator.clipboard.writeText(i).then(()=>{t(!0),setTimeout(()=>t(!1),e)})}}},Qi=$e.unstable_memoizeMarkdownComponents({h1:({className:e,...r})=>d.jsx("h1",{className:z("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...r}),h2:({className:e,...r})=>d.jsx("h2",{className:z("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h3:({className:e,...r})=>d.jsx("h3",{className:z("cuadra-mb-3 cuadra-mt-5 cuadra-scroll-m-20 cuadra-text-lg cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h4:({className:e,...r})=>d.jsx("h4",{className:z("cuadra-mb-4 cuadra-mt-6 cuadra-scroll-m-20 cuadra-text-xl cuadra-font-normal cuadra-tracking-tight first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h5:({className:e,...r})=>d.jsx("h5",{className:z("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),h6:({className:e,...r})=>d.jsx("h6",{className:z("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...r}),p:({className:e,...r})=>d.jsx("p",{className:z("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...r}),a:({className:e,...r})=>d.jsx("a",{className:z("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...r}),blockquote:({className:e,...r})=>d.jsx("blockquote",{className:z("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...r}),ul:({className:e,...r})=>d.jsx("ul",{className:z("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...r}),ol:({className:e,...r})=>d.jsx("ol",{className:z("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...r}),hr:({className:e,...r})=>d.jsx("hr",{className:z("cuadra-my-5 cuadra-border-b",e),...r}),table:({className:e,...r})=>d.jsx("table",{className:z("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...r}),th:({className:e,...r})=>d.jsx("th",{className:z("cuadra-bg-muted cuadra-px-4 cuadra-py-2 cuadra-text-left cuadra-font-normal first:cuadra-rounded-tl-lg last:cuadra-rounded-tr-lg [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),td:({className:e,...r})=>d.jsx("td",{className:z("cuadra-border-b cuadra-border-l cuadra-px-4 cuadra-py-2 cuadra-text-left last:cuadra-border-r [&[align=center]]:cuadra-text-center [&[align=right]]:cuadra-text-right font-brand",e),...r}),tr:({className:e,...r})=>d.jsx("tr",{className:z("cuadra-m-0 cuadra-border-b cuadra-p-0 first:cuadra-border-t [&:last-child>td:first-child]:cuadra-rounded-bl-lg [&:last-child>td:last-child]:cuadra-rounded-br-lg",e),...r}),sup:({className:e,...r})=>d.jsx("sup",{className:z("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...r}),pre:({className:e,...r})=>d.jsx("pre",{className:z("cuadra-overflow-x-auto cuadra-whitespace-pre-wrap cuadra-break-words cuadra-rounded-b-lg !cuadra-rounded-t-none cuadra-bg-muted cuadra-p-4 cuadra-text-foreground font-brand",e),...r}),code:function({className:r,...t}){const n=$e.useIsMarkdownCodeBlock();return d.jsx("code",{className:z(!n&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",r),...t})},CodeHeader:Vi});function Je({className:e="",variant:r="default",...t}){const n="cuadra-inline-flex cuadra-items-center cuadra-rounded-md cuadra-px-3 cuadra-py-1.5 cuadra-text-xs cuadra-font-medium font-brand",i={default:"cuadra-border cuadra-border-border cuadra-bg-muted cuadra-text-muted-foreground",subtle:"cuadra-border cuadra-border-border/50 cuadra-bg-muted/50 cuadra-text-muted-foreground",outline:"cuadra-border cuadra-border-border cuadra-bg-background cuadra-text-foreground",ghost:"cuadra-text-muted-foreground"};return d.jsx("div",{className:`${n} ${i[r]||i.default} ${e}`,...t})}function Gi(e){const r=new Map;for(const t of e){const n=r.get(t.filename);(!n||t.score>n.score)&&r.set(t.filename,t)}return Array.from(r.values()).sort((t,n)=>n.score-t.score)}function ir({sources:e,maxVisible:r=3}){if(!e||e.length===0)return null;const t=Gi(e),n=t.slice(0,r),i=t.length-r;return d.jsxs("div",{className:"cuadra-mt-4 cuadra-pt-3 cuadra-border-t cuadra-border-border",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-mb-2.5",children:[d.jsx(kt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),d.jsx("span",{className:"cuadra-text-xs cuadra-font-medium cuadra-text-muted-foreground font-brand",children:"Sources"})]}),d.jsxs("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-gap-2",children:[n.map((o,a)=>d.jsx(Ji,{source:o},o.sourceId||a)),i>0&&d.jsxs(Je,{variant:"subtle",children:["+",i," more"]})]})]})}function Yi(e){switch(e.split(".").pop()?.toLowerCase()){case"csv":case"xlsx":case"xls":return Ir;case"md":case"txt":return Mr;default:return kt}}function Ji({source:e}){const{filename:r,score:t}=e,n=Yi(r);return d.jsxs(Je,{className:"cuadra-gap-2 cuadra-cursor-default",title:t<1?`${Math.round(t*100)}% relevant`:void 0,children:[d.jsx(n,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-opacity-60"}),d.jsx("span",{className:"cuadra-truncate cuadra-max-w-[180px]",children:r}),t<1&&t>0&&d.jsxs("span",{className:"cuadra-opacity-50 cuadra-text-[10px] cuadra-tabular-nums",children:[Math.round(t*100),"%"]})]})}const Xi=y.forwardRef(function({welcomeTitle:r="What shall we explore today?",extraTopPadding:t,suggestions:n,inputPlaceholder:i="Reply...",enableAttachments:o=!1,preMadeResponseDelay:a=1e3,streamingSpeed:c=50,safeArea:s=!1,composerBorder:l=!1,models:f,selectedModelId:u,onModelChange:g,showChatHeader:m=!1},h){const b=T.useThreadRuntime(),x=T.useAssistantApi(),[w,C]=y.useState(!1),[v,_]=y.useState(null),[M,P]=y.useState(!1),O=T.useThread(A=>{const E=A.messages;return!E||E.length===0}),S=O&&!w,N=y.useCallback((A,E,Q)=>{if(!M)try{const U=Q?.streamingSpeed??c,k=Q?.delay??a;Pt(A,E,U,k),x.composer().setText(A),setTimeout(()=>{x.composer().send()},10)}catch{}},[M,c,a,x]),p=y.useCallback(A=>{try{x.composer().setText(A),setTimeout(()=>{x.composer().send()},10)}catch{}},[x]),F=y.useCallback(async A=>{if(!(M||!b))try{if(A.response){const E=A.responseDelay??a;await N(A.prompt,A.response,{delay:E,streamingSpeed:c})}else p(A.prompt)}catch{}},[b,M,a,c,N,p]),K=y.useCallback(async()=>{try{const E=window.__cuadraThreadListRuntime?.threadList;E?.switchToNewThread&&await E.switchToNewThread()}catch{}},[]);return y.useImperativeHandle(h,()=>({sendMessage:p,sendPreMadeQA:N,clearChat:K}),[p,N,K]),y.useEffect(()=>{if(!b){C(!1);return}try{const A=b?.store;if(!A){C(!1);return}const E=A.subscribe?.(U=>{const k=U?.threadId,j=U?.messages||[],R=U?.isLoadingHistory||!1,L=j.length;k&&k!==v&&_(k),C(R&&L===0)}),Q=A.getState?.();if(Q){const U=Q?.threadId,k=Q?.messages||[],j=Q?.isLoadingHistory||!1,R=k.length;U&&U!==v&&_(U),C(j&&R===0)}return()=>{E&&E()}}catch{C(!1)}},[b,v]),d.jsxs(T.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full cuadra-relative",children:[m&&d.jsx(io,{}),d.jsxs(T.ComposerPrimitive.AttachmentDropzone,{disabled:!o,className:`cuadra-flex-1 cuadra-flex cuadra-flex-col cuadra-min-h-0 cuadra-relative ${S?"cuadra-justify-center":""}`,children:[d.jsx("div",{className:"cuadra-dropzone-overlay cuadra-pointer-events-none cuadra-absolute cuadra-inset-0 cuadra-z-50 cuadra-flex cuadra-items-center cuadra-justify-center cuadra-rounded-lg cuadra-transition-opacity cuadra-duration-200",style:{opacity:0},children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-14 cuadra-rounded-2xl",style:{backgroundColor:"var(--cuadra-primary)",color:"white"},children:d.jsx(Ur,{className:"cuadra-h-6 cuadra-w-6"})}),d.jsx("p",{className:"cuadra-text-sm cuadra-font-medium cuadra-text-foreground font-brand",children:"Drop files here"})]})}),d.jsx(T.ThreadPrimitive.Viewport,{className:`cuadra-w-full cuadra-bg-inherit cuadra-relative scrollbar-thin ${S?"cuadra-flex-none":"cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto"}`,style:{paddingTop:S?"0":t||(m?"0.5rem":"2rem")},children:w?d.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[d.jsx(Ct,{className:"cuadra-h-5 cuadra-w-5 cuadra-animate-spin cuadra-text-muted-foreground"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):d.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full cuadra-px-4",children:[d.jsx(T.ThreadPrimitive.Empty,{children:d.jsx(Zi,{title:r})}),d.jsx(T.ThreadPrimitive.Messages,{components:{UserMessage:eo,AssistantMessage:no}})]})}),d.jsx("div",{className:`cuadra-w-full cuadra-px-4 cuadra-pt-2 ${S?"cuadra-pb-2":"cuadra-pb-4"}`,style:s?{paddingBottom:"calc(env(safe-area-inset-bottom) + 1rem)"}:void 0,children:d.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:[o&&d.jsx(T.ComposerPrimitive.Attachments,{components:{Attachment:()=>{const A=T.useAssistantState(({attachment:E})=>E);return A?d.jsxs("div",{className:"cuadra-relative cuadra-inline-flex cuadra-items-center cuadra-gap-2 cuadra-mb-2 cuadra-px-3 cuadra-py-1.5 cuadra-rounded-lg cuadra-transition-colors",style:{backgroundColor:"var(--cuadra-muted)",border:"1px solid rgba(0,0,0,0.06)"},children:[d.jsx(vt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground",strokeWidth:1.5}),d.jsx("span",{className:"cuadra-text-xs cuadra-text-foreground font-brand",children:A.name||"Attachment"}),d.jsx(T.AttachmentPrimitive.Remove,{asChild:!0,children:d.jsx("button",{type:"button",className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-4 cuadra-rounded-full hover:cuadra-bg-background/60 cuadra-transition-colors cuadra-ml-1","aria-label":"Remove attachment",children:d.jsx($r,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})})]}):null}}}),d.jsxs(T.ComposerPrimitive.Root,{className:"cuadra-relative cuadra-w-full cuadra-rounded-2xl cuadra-transition-shadow cuadra-duration-300 cuadra-flex cuadra-flex-col",style:{backgroundColor:"var(--cuadra-composer)",boxShadow:"var(--cuadra-composer-shadow)",border:l?"1px solid hsl(var(--cuadra-border))":"none"},children:[d.jsx(T.ComposerPrimitive.Input,{asChild:!0,children:d.jsx("textarea",{rows:1,placeholder:i,className:"cuadra-flex cuadra-min-h-[44px] cuadra-w-full cuadra-rounded-t-2xl cuadra-border-0 cuadra-bg-transparent cuadra-px-4 cuadra-pt-3.5 cuadra-pb-1 cuadra-text-base cuadra-text-foreground placeholder:cuadra-text-muted-foreground focus-visible:cuadra-outline-none disabled:cuadra-cursor-not-allowed disabled:cuadra-opacity-50 cuadra-resize-none font-brand",style:{fontSize:"1rem",lineHeight:"1.5"}})}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-pb-2.5 cuadra-pt-1",children:[d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:o&&d.jsx(T.ComposerPrimitive.AddAttachment,{multiple:!0,asChild:!0,children:d.jsxs("button",{type:"button",className:"cuadra-group cuadra-relative cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-8 cuadra-rounded-lg hover:cuadra-bg-muted/60 cuadra-transition-colors","aria-label":"Attach files",children:[d.jsx(Tt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground",strokeWidth:1.5}),d.jsx("span",{className:"cuadra-pointer-events-none cuadra-absolute cuadra-bottom-full cuadra-left-1/2 cuadra--translate-x-1/2 cuadra-mb-1.5 cuadra-whitespace-nowrap cuadra-rounded-md cuadra-px-2.5 cuadra-py-1 cuadra-text-xs cuadra-text-foreground cuadra-opacity-0 group-hover:cuadra-opacity-100 cuadra-transition-opacity cuadra-duration-150 cuadra-delay-300 font-brand",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:"Attach files"})]})})}),d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[f&&f.length>0&&d.jsx(ao,{models:f,selectedModelId:u,onModelChange:g,threadIsEmpty:O,onNewChat:K}),d.jsx(T.ComposerPrimitive.Send,{asChild:!0,children:d.jsx("button",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-size-8 cuadra-rounded-full cuadra-transition-all cuadra-duration-200 hover:cuadra-opacity-90 disabled:cuadra-opacity-30 disabled:cuadra-cursor-not-allowed",style:{backgroundColor:"var(--cuadra-primary)",color:"white"},"aria-label":"Send message",type:"button",children:d.jsx(wr,{className:"cuadra-h-4 cuadra-w-4",strokeWidth:2})})})]})]})]})]})}),S&&n&&n.length>0&&d.jsx("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-justify-center cuadra-gap-2 cuadra-px-4 cuadra-pb-6 cuadra-pt-1 cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:n.map((A,E)=>d.jsx("button",{type:"button",onClick:()=>F(A),disabled:M,className:"cuadra-px-3.5 cuadra-py-2 cuadra-rounded-full cuadra-text-sm cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-all cuadra-duration-200 font-brand cuadra-cursor-pointer disabled:cuadra-opacity-50 disabled:cuadra-cursor-not-allowed",style:{backgroundColor:"var(--cuadra-composer)",boxShadow:"0 0 0 1px rgba(0,0,0,0.06)"},children:A.prompt},`suggestion-${E}`))})]})]})});function Zi({title:e}){return d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-text-center cuadra-py-6",children:d.jsx("h2",{className:"cuadra-text-4xl cuadra-font-normal cuadra-text-muted-foreground cuadra-tracking-tight",style:{fontFamily:"var(--cuadra-font-logo), Outfit, -apple-system, sans-serif"},children:e})})}function eo(){return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-end cuadra-py-2.5",children:d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-end cuadra-gap-2 cuadra-max-w-[80%]",children:[d.jsx(T.MessagePrimitive.Attachments,{components:{Attachment:()=>{const e=T.useAssistantState(({attachment:o})=>o);if(!e)return null;const r=e.type==="image",t=e.file,n=e.content?.find(o=>o.type==="image"),i=t?URL.createObjectURL(t):n?.image;return d.jsx("div",{className:"cuadra-mb-1",children:r&&i?d.jsx("img",{src:i,alt:e.name||"Attachment",className:"cuadra-rounded-2xl cuadra-max-h-64 cuadra-max-w-full cuadra-object-contain",style:{border:"1px solid rgba(0,0,0,0.06)"}}):d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 cuadra-rounded-xl cuadra-px-3 cuadra-py-2",style:{backgroundColor:"var(--cuadra-muted)",border:"1px solid rgba(0,0,0,0.06)"},children:[d.jsx(vt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),d.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground font-brand",children:e.name||"Attachment"})]})})}}}),d.jsx("div",{className:"cuadra-break-words cuadra-text-foreground font-brand",style:{borderRadius:"1.25rem",backgroundColor:"var(--cuadra-muted)",paddingLeft:"1rem",paddingRight:"1rem",paddingTop:"0.625rem",paddingBottom:"0.625rem",wordBreak:"break-word",fontSize:"0.9375rem",lineHeight:"1.625"},children:d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>d.jsx(Ye,{content:e||""})}})})]})})}function to({text:e}){const[r,t]=y.useState(!1),n=T.useAssistantState(({message:i})=>i?.status?.type==="running");return e?n?d.jsx("div",{className:"cuadra-mb-3 cuadra-py-1",children:d.jsx("div",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand cuadra-animate-text-shimmer",children:e})}):d.jsxs("div",{className:"cuadra-mb-3",children:[d.jsxs("button",{type:"button",onClick:()=>t(!r),className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-py-1 cuadra-text-sm cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-colors font-brand",children:[d.jsx(We,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-transition-transform cuadra-duration-200 ${r?"":"cuadra--rotate-90"}`}),d.jsx("span",{children:"Reasoning"})]}),d.jsx("div",{className:`cuadra-overflow-hidden cuadra-transition-all cuadra-duration-200 cuadra-ease-out ${r?"cuadra-max-h-[2000px] cuadra-opacity-100":"cuadra-max-h-0 cuadra-opacity-0"}`,children:d.jsx("div",{className:"cuadra-pl-5 cuadra-pt-2 cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand",children:d.jsx(Ye,{content:e})})})]}):null}function ro(){return d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2.5 cuadra-text-muted-foreground cuadra-text-sm font-brand cuadra-py-3",children:[d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:[d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"0ms",backgroundColor:"var(--cuadra-primary)",opacity:.7}}),d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"150ms",backgroundColor:"var(--cuadra-primary)",opacity:.5}}),d.jsx("span",{className:"cuadra-inline-block cuadra-w-1.5 cuadra-h-1.5 cuadra-rounded-full cuadra-animate-bounce",style:{animationDelay:"300ms",backgroundColor:"var(--cuadra-primary)",opacity:.3}})]}),d.jsx("span",{children:"Thinking..."})]})}function no(){const e=T.useAssistantState(({message:a})=>a?.status?.type==="running"),r=T.useAssistantState(({message:a})=>{const c=a?.content;return!c||!Array.isArray(c)?!1:c.some(s=>!!(s.type==="text"&&s.text&&s.text.length>0||s.type==="reasoning"&&s.text&&s.text.length>0))}),t=y.useRef(!1),[n,i]=y.useState(null);y.useEffect(()=>{if(e&&r&&!t.current){const a=X.getCurrentMessageId();a&&(t.current=!0,i(a))}},[e,r]);const o=y.useSyncExternalStore(a=>X.subscribe(a),()=>{if(n){const a=X.getForMessage(n);return a.sources?.length?a.sources:null}if(e&&r){const a=X.getCurrentMessageId();if(a){const c=X.getForMessage(a);return c.sources?.length?c.sources:null}}return null},()=>null);return d.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-start cuadra-py-2.5",children:d.jsxs("div",{className:"cuadra-text-foreground cuadra-max-w-full cuadra-break-words font-brand",style:{fontSize:"0.9375rem",lineHeight:"1.75"},children:[d.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:a})=>d.jsx(Ye,{content:a||""}),Reasoning:({text:a})=>d.jsx(to,{text:a||""})}}),e&&!r&&d.jsx(ro,{}),o&&o.length>0&&d.jsx(ir,{sources:o})]})})}function ao({models:e,selectedModelId:r,onModelChange:t,threadIsEmpty:n,onNewChat:i}){const[o,a]=y.useState(!1),c=e.find(l=>l.id===r)||e[0];if(!c)return null;const s=async l=>{a(!1),!n&&l!==r&&await i?.(),t?.(l)};return d.jsxs("div",{className:"cuadra-relative",children:[d.jsxs("button",{type:"button",onClick:()=>a(!o),className:"cuadra-flex cuadra-items-center cuadra-gap-1 cuadra-px-2.5 cuadra-py-1.5 cuadra-rounded-lg cuadra-text-xs cuadra-text-muted-foreground hover:cuadra-text-foreground cuadra-transition-colors font-brand",children:[d.jsx("span",{children:c.name}),d.jsx(We,{className:"cuadra-h-3 cuadra-w-3"})]}),o&&d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>a(!1)}),d.jsx("div",{className:"cuadra-absolute cuadra-bottom-full cuadra-right-0 cuadra-mb-2 cuadra-z-50 cuadra-rounded-xl cuadra-min-w-[200px] cuadra-overflow-hidden cuadra-py-1",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)"},children:e.map(l=>d.jsxs("button",{type:"button",className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted/60 cuadra-transition-colors font-brand",onClick:()=>s(l.id),children:[d.jsxs("div",{className:"cuadra-flex cuadra-flex-col",children:[d.jsx("span",{className:"cuadra-text-foreground",children:l.name}),l.description&&d.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground",children:l.description})]}),l.id===r&&d.jsx(wt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-primary cuadra-flex-shrink-0"})]},l.id))})]})]})}function io(){const e=T.useAssistantState(({threadListItem:i})=>i?.title??null),[r,t]=y.useState(!1),n=e||"Untitled chat";return d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-px-3 cuadra-py-2 cuadra-min-h-[48px]",children:d.jsxs("div",{className:"cuadra-relative",children:[d.jsxs("button",{type:"button",onClick:()=>t(!r),className:"cuadra-flex cuadra-items-center cuadra-gap-1 cuadra-text-sm cuadra-text-foreground hover:cuadra-bg-muted/60 cuadra-rounded-lg cuadra-px-2 cuadra-py-1.5 cuadra-transition-colors font-brand",children:[d.jsx("span",{className:"cuadra-font-medium cuadra-truncate cuadra-max-w-[200px]",children:n}),d.jsx(We,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground cuadra-flex-shrink-0 cuadra-transition-transform cuadra-duration-200 ${r?"cuadra-rotate-180":""}`})]}),r&&d.jsx(oo,{onClose:()=>t(!1)})]})})}function oo({onClose:e}){return d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:e}),d.jsx("div",{className:"cuadra-absolute cuadra-left-0 cuadra-top-full cuadra-mt-1 cuadra-z-50 cuadra-w-[300px] cuadra-rounded-xl cuadra-overflow-hidden cuadra-flex cuadra-flex-col",style:{backgroundColor:"var(--cuadra-popover)",boxShadow:"0 4px 24px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)"},children:d.jsxs(T.ThreadListPrimitive.Root,{className:"cuadra-flex cuadra-flex-col",children:[d.jsx("div",{className:"cuadra-px-2 cuadra-py-1.5",children:d.jsxs(T.ThreadListPrimitive.New,{className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-gap-2.5 cuadra-px-3 cuadra-py-2 cuadra-rounded-lg cuadra-text-sm cuadra-text-foreground hover:cuadra-bg-muted cuadra-transition-colors cuadra-cursor-pointer font-brand",onClick:e,children:[d.jsx(Tt,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),"New Chat"]})}),d.jsx(so,{onSelect:e})]})})]})}function so({onSelect:e}){const r=T.useAssistantState(({threads:i})=>i?.threadIds??[]),t=T.useAssistantState(({threads:i})=>i?.newThreadId);return r.some(i=>i!==t)?d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"cuadra-mx-3 cuadra-my-0.5",style:{borderTop:"1px solid rgba(0,0,0,0.06)"}}),d.jsx("div",{className:"cuadra-overflow-y-auto cuadra-px-2 cuadra-pb-1.5 scrollbar-thin",style:{maxHeight:"340px"},children:d.jsx(T.ThreadListPrimitive.Items,{components:{ThreadListItem:i=>d.jsx(co,{...i,onSelect:e})}})})]}):null}function co({onSelect:e}){const r=T.useThreadListItem(),t=T.useThreadListItemRuntime(),n=T.useAssistantRuntime(),i=T.useThread(x=>x.threadId),o=r?.id===i,[a,c]=y.useState(!1),[s,l]=y.useState(!1),[f,u]=y.useState(r?.title||""),[g,m]=y.useState(!1),h=async()=>{if(!r?.remoteId||!f||f===r.title){l(!1);return}try{m(!0),await t.rename(f)}catch{}finally{m(!1),l(!1)}},b=async x=>{x.stopPropagation();try{await t.delete(),o&&await n.switchToNewThread()}catch(w){console.error("[CuadraChat] Failed to delete thread:",w)}};return y.useEffect(()=>{r?.title&&!s&&u(r.title)},[r?.title,s]),r?d.jsxs(T.ThreadListItemPrimitive.Root,{className:`cuadra-relative cuadra-flex cuadra-items-center cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer ${o?"cuadra-bg-muted":"hover:cuadra-bg-muted/60"}`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[s?d.jsx("div",{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0",onClick:x=>x.stopPropagation(),onMouseDown:x=>x.stopPropagation(),onKeyDown:x=>x.stopPropagation(),onKeyUp:x=>x.stopPropagation(),onKeyPress:x=>x.stopPropagation(),children:d.jsx("input",{className:"cuadra-w-full cuadra-bg-transparent cuadra-border-0 cuadra-border-b cuadra-text-sm cuadra-text-foreground cuadra-py-0.5 cuadra-px-0 cuadra-outline-none font-brand",style:{borderBottomColor:"var(--cuadra-primary)",borderBottomWidth:"1.5px"},value:f,onChange:x=>u(x.target.value),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&h(),x.key==="Escape"&&(l(!1),u(r.title||""))},onBlur:()=>void h(),disabled:g,autoFocus:!0})}):d.jsx(T.ThreadListItemPrimitive.Trigger,{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:d.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground cuadra-truncate cuadra-block cuadra-text-left font-brand",children:r.title||"Chat"})}),(a||o)&&!s&&d.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-0.5 cuadra-mr-1.5 cuadra-flex-shrink-0",children:[d.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/60 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),l(!0),u(r.title||"Chat")},title:"Rename",children:d.jsx(Er,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})}),d.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-destructive/10 cuadra-transition-colors",onClick:b,title:"Delete",children:d.jsx(Dr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-destructive"})})]})]}):null}const Ue=({children:e,className:r="",paddingX:t="px-0",paddingY:n="py-0",borderSizePx:i=2,style:o,contentStyle:a})=>d.jsx("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-lg cuadra-overflow-hidden cuadra-flex cuadra-flex-col ${t} ${n} ${r}`,style:{border:i>0?`${i}px solid var(--cuadra-primary)`:"none",...o,...a},children:e}),lo=y.createContext(void 0),ze=({children:e,value:r})=>d.jsx(lo.Provider,{value:r,children:e});function uo(){y.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const r=document.createElement("div");r.className="cuadra-flex",document.body.appendChild(r);const t=window.getComputedStyle(r).display==="flex";if(document.body.removeChild(r),t)return;const n=document.createElement("link");n.setAttribute("data-cuadra-uikit","true"),n.rel="stylesheet",n.type="text/css";const i=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:ue&&ue.tagName.toUpperCase()==="SCRIPT"&&ue.src||new URL("index.cjs",document.baseURI).href).href];let o=!1;for(const a of i)if(n.href=a,n.onload=()=>{o=!0},n.onerror=()=>{},document.head.appendChild(n),o)break},[])}const fo=y.forwardRef(function({config:r},t){uo();const n=y.useRef(null),i=y.useRef(!1),{baseUrl:o,proxyUrl:a,sessionToken:c,mode:s="multiChat",modelMode:l="fixed",modelId:f,onModelChange:u,ephemeral:g=!1,systemPrompt:m,enableReasoning:h=!1,initialThreadId:b,welcomeTitle:x,welcomeSubtitle:w,extraTopPadding:C,suggestions:v,inputPlaceholder:_,preMadeResponseDelay:M=1e3,streamingSpeed:P=50,initialMessage:O,initialPreMadeQA:S,theme:N="system",onError:p,onChatCreated:F,onUserMessage:K,onThreadIdUpdate:A,enableAttachments:E=!1,onBeforeRequest:Q,mockResponseOnBlocked:U}=r;y.useImperativeHandle(t,()=>({sendMessage:D=>{n.current?.sendMessage(D)},sendPreMadeQA:(D,ae,ne)=>{n.current?.sendPreMadeQA(D,ae,ne)},clearChat:()=>{n.current?.clearChat()}}),[]),y.useEffect(()=>{if(i.current)return;const D=setTimeout(()=>{S?(i.current=!0,n.current?.sendPreMadeQA(S.question,S.answer,{delay:M,streamingSpeed:P})):O&&(i.current=!0,n.current?.sendMessage(O))},500);return()=>clearTimeout(D)},[O,S,M,P]);const k=a||o||"",j=!!a,R=y.useMemo(()=>new It(k,c||void 0,j),[k,c,j]),[L,V]=y.useState(null),[I,B]=y.useState(!1),[G,re]=y.useState(null),[ye,be]=y.useState(!1);y.useEffect(()=>{s==="multiChat"&&be(!0)},[s]);const H=y.useCallback(async()=>{if(l==="selector"){B(!0),re(null);try{const D=await R.listModels();V(D)}catch(D){re(D instanceof Error?D:new Error("Failed to load models"))}finally{B(!1)}}},[R,l]);y.useEffect(()=>{l==="selector"&&H()},[l,H]),y.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=H),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[H]);const[Y,Ze]=y.useState(l==="fixed"&&f||null),et=y.useRef(Y),we=y.useCallback(D=>{const ae=et.current;Ze(D),et.current=D,u?.(D),ae!==null&&ae!==D&&s==="multiChat"&&setTimeout(()=>{const ne=window.__cuadraThreadListRuntime;if(ne?.threads?.switchToNewThread)try{ne.threads.switchToNewThread()}catch{}else if(ne?.threads?.createThread)try{ne.threads.createThread()}catch{}else if(ne?.switchToNewThread)try{ne.switchToNewThread()}catch{}},100)},[u,s]);y.useEffect(()=>{if(l==="selector"&&L?.items&&L.items.length>0&&!Y){const D=L.items[0];if(D?.id){const ae=D.id;Ze(ae),u?.(ae)}}},[l,L?.items,Y,u]);const ur=l==="fixed"?!!f:!!Y,_e=y.useMemo(()=>(L?.items||[]).filter(D=>D?.id&&D?.displayName).map(D=>({id:D.id,name:D.displayName})),[L]),Ne=y.useMemo(()=>({currentModelId:Y||"",models:_e,modelsLoading:I,modelsError:G,onModelChange:we,refetchModels:H}),[Y,_e,I,G,we,H]);return l==="selector"&&I||s==="multiChat"&&ye?d.jsx(ze,{value:Ne,children:d.jsx(Ue,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",borderSizePx:r.borderless?0:2,children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx(Ct,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):l==="selector"&&!ur&&G?d.jsx(ze,{value:Ne,children:d.jsx(Ue,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:d.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:d.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:d.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):d.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:d.jsx(ze,{value:Ne,children:d.jsx(pn,{baseUrl:j?k:o||k,sessionToken:c,isProxyMode:j,mode:s,modelMode:l,modelId:Y||f||void 0,onModelChange:we,ephemeral:g,systemPrompt:m,enableReasoning:h,initialThreadId:b,enableAttachments:E,onError:p,onChatCreated:F,onUserMessage:K,onThreadIdUpdate:A,onBeforeRequest:Q,mockResponseOnBlocked:U,onChatsLoaded:()=>{s==="multiChat"&&be(!1)},children:d.jsx(Ue,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${r.containerClass||""}`,borderSizePx:r.borderless?0:2,style:{height:"100%"},children:d.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:d.jsx("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:d.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0",children:d.jsx(Xi,{ref:n,welcomeTitle:x,welcomeSubtitle:w,extraTopPadding:C,suggestions:v,inputPlaceholder:_,enableAttachments:E,preMadeResponseDelay:M,streamingSpeed:P,safeArea:r.safeArea,showChatHeader:s==="multiChat",models:l==="selector"?_e:void 0,selectedModelId:Y||void 0,onModelChange:l==="selector"?we:void 0,theme:N})})})})})})})})});function or(e,r=":root"){if(typeof document>"u")return;const t=document.documentElement;if(e.light&&mo(e.light,t),e.dark){let n=document.getElementById("cuadra-theme-dark");n||(n=document.createElement("style"),n.id="cuadra-theme-dark",document.head.appendChild(n));const i=po(e.dark);n.textContent=`.dark { ${i} }`}}const ho={background:"background",foreground:"foreground",card:"card",cardForeground:"card-foreground",popover:"popover",popoverForeground:"popover-foreground",primary:"primary",primaryForeground:"primary-foreground",primaryLight:"primary-light",primaryLighter:"primary-lighter",secondary:"secondary",secondaryForeground:"secondary-foreground",muted:"muted",mutedForeground:"muted-foreground",accent:"accent",accentForeground:"accent-foreground",border:"border",input:"input",ring:"ring",destructive:"destructive",destructiveForeground:"destructive-foreground",success:"success",successForeground:"success-foreground",info:"info",infoForeground:"info-foreground",warning:"warning",warningForeground:"warning-foreground"};function sr(e){const r=ho[e];return r?`--cuadra-${r}`:`--cuadra-${e.replace(/([A-Z])/g,"-$1").toLowerCase()}`}function mo(e,r){Object.entries(e).forEach(([t,n])=>{if(n){const i=sr(t);r.style.setProperty(i,n)}})}function po(e){return Object.entries(e).map(([r,t])=>t?`${sr(r)}: ${t};`:"").filter(Boolean).join(" ")}function go(){if(typeof document>"u")return;const e=document.documentElement;Array.from(e.style).filter(n=>n.startsWith("--cuadra-")).forEach(n=>e.style.removeProperty(n));const t=document.getElementById("cuadra-theme-dark");t&&t.remove()}function xo({onReset:e,error:r}){return d.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-h-full cuadra-p-6 cuadra-text-center",children:[d.jsx("div",{className:"cuadra-mb-4",children:d.jsx("svg",{className:"cuadra-w-12 cuadra-h-12 cuadra-text-destructive cuadra-mx-auto",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:d.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),d.jsx("h3",{className:"cuadra-text-lg cuadra-font-medium cuadra-text-foreground cuadra-mb-2",children:"Something went wrong"}),d.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-mb-4 cuadra-max-w-sm",children:r?.message||"An unexpected error occurred. Please try again."}),d.jsx("button",{onClick:e,className:"cuadra-px-4 cuadra-py-2 cuadra-text-sm cuadra-font-medium cuadra-rounded-md cuadra-transition-colors",style:{backgroundColor:"var(--cuadra-primary)",color:"hsl(var(--cuadra-primary-foreground))"},children:"Try Again"})]})}class Xe extends y.Component{constructor(t){super(t);$(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(t){return{hasError:!0,error:t}}componentDidCatch(t,n){this.props.onError?.(t,n)}render(){if(this.state.hasError){const{fallback:t}=this.props,{error:n}=this.state;return typeof t=="function"?t(n,this.reset):t||d.jsx(xo,{error:n,onReset:this.reset})}return this.props.children}}function yo(e,r){const t=n=>d.jsx(Xe,{...r,children:d.jsx(e,{...n})});return t.displayName=`withErrorBoundary(${e.displayName||e.name||"Component"})`,t}const fe=y.createContext(null);fe.displayName="CuadraChatContext";function bo(){const e=y.useContext(fe);if(e===null)throw new Error("useCuadraChat must be used within a CuadraChatProvider. Wrap your component tree with <CuadraChatProvider>...</CuadraChatProvider>");return{controls:e.controls,isReady:e.controls!==null}}function wo(){const e=y.useContext(fe);return e===null?null:{controls:e.controls,isReady:e.controls!==null}}function ko({children:e}){const[r,t]=y.useState(null),n=y.useCallback(a=>{t(a)},[]),i=y.useCallback(()=>{t(null)},[]),o=y.useMemo(()=>({controls:r,registerControls:n,unregisterControls:i}),[r,n,i]);return d.jsx(fe.Provider,{value:o,children:e})}function cr(e){return"connection"in e&&typeof e.connection=="object"}function lr(e){return cr(e)?Co(e):vo(e)}function Co(e){return{connection:{baseUrl:e.connection.baseUrl||"",proxyUrl:e.connection.proxyUrl||"",sessionToken:e.connection.sessionToken??null},chat:{mode:e.chat?.mode??"multiChat",modelMode:e.chat?.modelMode??"fixed",modelId:e.chat?.modelId??"",systemPrompt:e.chat?.systemPrompt??"",ephemeral:e.chat?.ephemeral??!1,enableReasoning:e.chat?.enableReasoning??!1,enableAttachments:e.chat?.enableAttachments??!1,initialThreadId:e.chat?.initialThreadId},ui:{theme:e.ui?.theme??"system",customTheme:e.ui?.customTheme,showThemeToggle:e.ui?.showThemeToggle??!0,language:e.ui?.language,welcomeTitle:e.ui?.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.ui?.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.ui?.suggestions,inputPlaceholder:e.ui?.inputPlaceholder??"Type your message...",extraTopPadding:e.ui?.extraTopPadding,borderless:e.ui?.borderless,safeArea:e.ui?.safeArea,orgName:e.ui?.orgName,primaryColor:e.ui?.primaryColor},preMade:{responseDelay:e.preMade?.responseDelay??1e3,streamingSpeed:e.preMade?.streamingSpeed??50},initial:{message:e.initial?.message,preMadeQA:e.initial?.preMadeQA},interceptors:{onBeforeRequest:e.interceptors?.onBeforeRequest,mockResponseOnBlocked:e.interceptors?.mockResponseOnBlocked},callbacks:{onChatCreated:e.callbacks?.onChatCreated,onError:e.callbacks?.onError,onUserMessage:e.callbacks?.onUserMessage,onModelChange:e.callbacks?.onModelChange,onThreadIdUpdate:e.callbacks?.onThreadIdUpdate,onLogout:e.callbacks?.onLogout},className:e.className,errorFallback:e.errorFallback}}function vo(e){return typeof process<"u"&&process.env?.NODE_ENV==="development"&&console.warn(`[CuadraUIKit] Using legacy flat props format. Consider migrating to grouped props for better organization.
21
21
  See: https://docs.cuadra.ai/guides/uikit-migration`),{connection:{baseUrl:e.baseUrl||"",proxyUrl:e.proxyUrl||"",sessionToken:e.sessionToken??null},chat:{mode:e.mode??"multiChat",modelMode:e.modelMode??"fixed",modelId:e.modelId??"",systemPrompt:e.systemPrompt??"",ephemeral:e.ephemeral??!1,enableReasoning:e.enableReasoning??!1,enableAttachments:e.enableAttachments??!1,initialThreadId:e.initialThreadId},ui:{theme:e.theme??"system",customTheme:e.customTheme,showThemeToggle:e.showThemeToggle??!0,language:e.language,welcomeTitle:e.welcomeTitle??"Hi, how can I help you today?",welcomeSubtitle:e.welcomeSubtitle??"Start exploring our platform and discover what you can build.",suggestions:e.suggestions,inputPlaceholder:e.inputPlaceholder??"Type your message...",extraTopPadding:e.extraTopPadding,borderless:!1,safeArea:!1,orgName:void 0,primaryColor:void 0},preMade:{responseDelay:e.preMadeResponseDelay??1e3,streamingSpeed:e.streamingSpeed??50},initial:{message:e.initialMessage,preMadeQA:e.initialPreMadeQA},interceptors:{onBeforeRequest:e.onBeforeRequest,mockResponseOnBlocked:e.mockResponseOnBlocked},callbacks:{onChatCreated:e.onChatCreated,onError:e.onError,onUserMessage:e.onUserMessage,onModelChange:e.onModelChange,onThreadIdUpdate:e.onThreadIdUpdate,onLogout:e.onLogout},className:e.className,errorFallback:e.errorFallback}}const To=y.forwardRef(function({config:r},t){const n=y.useRef(null),i=y.useContext(fe);y.useEffect(()=>{r.ui.customTheme&&or(r.ui.customTheme)},[r.ui.customTheme]),y.useEffect(()=>{if(r.ui.primaryColor&&typeof document<"u"){const c=document.documentElement,s=l=>{const f=l.replace("#",""),u=parseInt(f.slice(0,2),16)/255,g=parseInt(f.slice(2,4),16)/255,m=parseInt(f.slice(4,6),16)/255,h=Math.max(u,g,m),b=Math.min(u,g,m);let x=0,w=0;const C=(h+b)/2;if(h!==b){const v=h-b;switch(w=C>.5?v/(2-h-b):v/(h+b),h){case u:x=((g-m)/v+(g<m?6:0))/6;break;case g:x=((m-u)/v+2)/6;break;case m:x=((u-g)/v+4)/6;break}}return`${Math.round(x*360)} ${Math.round(w*100)}% ${Math.round(C*100)}%`};try{const l=s(r.ui.primaryColor);c.style.setProperty("--primary",l),c.style.setProperty("--cuadra-primary",`hsl(${l})`)}catch{}return()=>{c.style.removeProperty("--primary"),c.style.removeProperty("--cuadra-primary")}}},[r.ui.primaryColor]);const o=y.useMemo(()=>({sendMessage:c=>n.current?.sendMessage(c),sendPreMadeQA:(c,s,l)=>n.current?.sendPreMadeQA(c,s,l),clearChat:()=>n.current?.clearChat()}),[]);y.useImperativeHandle(t,()=>o,[]),y.useEffect(()=>{if(i)return i.registerControls(o),()=>i.unregisterControls()},[i,o]),y.useEffect(()=>(typeof window<"u"&&(process.env.NODE_ENV==="development"&&console.warn("[CuadraUIKit] window.__cuadraChatControls is deprecated. Use CuadraChatProvider and useCuadraChat() hook instead. See: https://docs.cuadra.ai/guides/uikit-migration"),window.__cuadraChatControls=o),()=>{typeof window<"u"&&delete window.__cuadraChatControls}),[o]);const a={baseUrl:r.connection.baseUrl||void 0,proxyUrl:r.connection.proxyUrl||void 0,sessionToken:r.connection.sessionToken,mode:r.chat.mode,modelMode:r.chat.modelMode,modelId:r.chat.modelId||void 0,systemPrompt:r.chat.systemPrompt||void 0,ephemeral:r.chat.ephemeral,enableReasoning:r.chat.enableReasoning,enableAttachments:r.chat.enableAttachments,initialThreadId:r.chat.initialThreadId,theme:r.ui.theme,showThemeToggle:r.ui.showThemeToggle,language:r.ui.language,welcomeTitle:r.ui.welcomeTitle,welcomeSubtitle:r.ui.welcomeSubtitle,suggestions:r.ui.suggestions,inputPlaceholder:r.ui.inputPlaceholder,extraTopPadding:r.ui.extraTopPadding,containerClass:r.className,borderless:r.ui.borderless,safeArea:r.ui.safeArea,orgName:r.ui.orgName,primaryColor:r.ui.primaryColor,preMadeResponseDelay:r.preMade.responseDelay,streamingSpeed:r.preMade.streamingSpeed,initialMessage:r.initial.message,initialPreMadeQA:r.initial.preMadeQA,onBeforeRequest:r.interceptors.onBeforeRequest,mockResponseOnBlocked:r.interceptors.mockResponseOnBlocked,onChatCreated:r.callbacks.onChatCreated,onError:r.callbacks.onError,onUserMessage:r.callbacks.onUserMessage,onModelChange:r.callbacks.onModelChange,onThreadIdUpdate:r.callbacks.onThreadIdUpdate,onLogout:r.callbacks.onLogout};return d.jsx(fo,{ref:n,config:a})}),jo=y.forwardRef(function(r,t){const n=lr(r),i=n.errorFallback;return d.jsx(Xe,{fallback:i,onError:(o,a)=>{n.callbacks.onError?.(o),process.env.NODE_ENV==="development"&&console.error("[CuadraChat] Error caught by boundary:",o,a)},children:d.jsx(To,{ref:t,config:n})})});exports.AttachmentValidationError=he;exports.Badge=Je;exports.CuadraChat=jo;exports.CuadraChatContext=fe;exports.CuadraChatProvider=ko;exports.CuadraErrorBoundary=Xe;exports.SourceCitations=ir;exports.applyTheme=or;exports.createAttachmentAdapter=He;exports.escapeHtml=Vr;exports.generateSecureUUID=jt;exports.isV2Props=cr;exports.isValidUrl=qr;exports.normalizeCuadraChatProps=lr;exports.removeTheme=go;exports.sanitizeSystemPrompt=Br;exports.streamingMetadataStore=X;exports.useCuadraChat=bo;exports.useCuadraChatOptional=wo;exports.validateBaseUrl=Wr;exports.withErrorBoundary=yo;
22
22
  //# sourceMappingURL=index.cjs.map