@cuadra-ai/uikit 0.4.13 → 0.4.14

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,7 +17,7 @@
17
17
  `))+1))}const i="#".repeat(n),c=r.enter("headingAtx"),o=r.enter("phrasing");s.move(i+" ");let l=r.containerPhrasing(e,{before:"# ",after:`
18
18
  `,...s.current()});return/^[\t ]/.test(l)&&(l=be(l.charCodeAt(0))+l.slice(1)),l=l?i+" "+l:i,r.options.closeAtx&&(l+=" "+i),o(),c(),l}Qt.peek=zn;function Qt(e){return e.value||""}function zn(){return"<"}Gt.peek=$n;function Gt(e,t,r,a){const n=Ye(r),s=n==='"'?"Quote":"Apostrophe",i=r.enter("image");let c=r.enter("label");const o=r.createTracker(a);let l=o.move("![");return l+=o.move(r.safe(e.alt,{before:l,after:"]",...o.current()})),l+=o.move("]("),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=r.enter("destinationLiteral"),l+=o.move("<"),l+=o.move(r.safe(e.url,{before:l,after:">",...o.current()})),l+=o.move(">")):(c=r.enter("destinationRaw"),l+=o.move(r.safe(e.url,{before:l,after:e.title?" ":")",...o.current()}))),c(),e.title&&(c=r.enter(`title${s}`),l+=o.move(" "+n),l+=o.move(r.safe(e.title,{before:l,after:n,...o.current()})),l+=o.move(n),c()),l+=o.move(")"),i(),l}function $n(){return"!"}Yt.peek=On;function Yt(e,t,r,a){const n=e.referenceType,s=r.enter("imageReference");let i=r.enter("label");const c=r.createTracker(a);let o=c.move("![");const l=r.safe(e.alt,{before:o,after:"]",...c.current()});o+=c.move(l+"]["),i();const f=r.stack;r.stack=[],i=r.enter("reference");const d=r.safe(r.associationId(e),{before:o,after:"]",...c.current()});return i(),r.stack=f,s(),n==="full"||!l||l!==d?o+=c.move(d+"]"):n==="shortcut"?o=o.slice(0,-1):o+=c.move("]"),o}function On(){return"!"}Jt.peek=Bn;function Jt(e,t,r){let a=e.value||"",n="`",s=-1;for(;new RegExp("(^|[^`])"+n+"([^`]|$)").test(a);)n+="`";for(/[^ \r\n]/.test(a)&&(/^[ \r\n]/.test(a)&&/[ \r\n]$/.test(a)||/^`|`$/.test(a))&&(a=" "+a+" ");++s<r.unsafe.length;){const i=r.unsafe[s],c=r.compilePattern(i);let o;if(i.atBreak)for(;o=c.exec(a);){let l=o.index;a.charCodeAt(l)===10&&a.charCodeAt(l-1)===13&&l--,a=a.slice(0,l)+" "+a.slice(o.index+1)}}return n+a+n}function Bn(){return"`"}function Xt(e,t){const r=Ht(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(r===e.url||"mailto:"+r===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Zt.peek=qn;function Zt(e,t,r,a){const n=Ye(r),s=n==='"'?"Quote":"Apostrophe",i=r.createTracker(a);let c,o;if(Xt(e,r)){const f=r.stack;r.stack=[],c=r.enter("autolink");let d=i.move("<");return d+=i.move(r.containerPhrasing(e,{before:d,after:">",...i.current()})),d+=i.move(">"),c(),r.stack=f,d}c=r.enter("link"),o=r.enter("label");let l=i.move("[");return l+=i.move(r.containerPhrasing(e,{before:l,after:"](",...i.current()})),l+=i.move("]("),o(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(o=r.enter("destinationLiteral"),l+=i.move("<"),l+=i.move(r.safe(e.url,{before:l,after:">",...i.current()})),l+=i.move(">")):(o=r.enter("destinationRaw"),l+=i.move(r.safe(e.url,{before:l,after:e.title?" ":")",...i.current()}))),o(),e.title&&(o=r.enter(`title${s}`),l+=i.move(" "+n),l+=i.move(r.safe(e.title,{before:l,after:n,...i.current()})),l+=i.move(n),o()),l+=i.move(")"),c(),l}function qn(e,t,r){return Xt(e,r)?"<":"["}er.peek=Vn;function er(e,t,r,a){const n=e.referenceType,s=r.enter("linkReference");let i=r.enter("label");const c=r.createTracker(a);let o=c.move("[");const l=r.containerPhrasing(e,{before:o,after:"]",...c.current()});o+=c.move(l+"]["),i();const f=r.stack;r.stack=[],i=r.enter("reference");const d=r.safe(r.associationId(e),{before:o,after:"]",...c.current()});return i(),r.stack=f,s(),n==="full"||!l||l!==d?o+=c.move(d+"]"):n==="shortcut"?o=o.slice(0,-1):o+=c.move("]"),o}function Vn(){return"["}function Je(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function Wn(e){const t=Je(e),r=e.options.bulletOther;if(!r)return t==="*"?"-":"*";if(r!=="*"&&r!=="+"&&r!=="-")throw new Error("Cannot serialize items with `"+r+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(r===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+r+"`) to be different");return r}function Hn(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function tr(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function Kn(e,t,r,a){const n=r.enter("list"),s=r.bulletCurrent;let i=e.ordered?Hn(r):Je(r);const c=e.ordered?i==="."?")":".":Wn(r);let o=t&&r.bulletLastUsed?i===r.bulletLastUsed:!1;if(!e.ordered){const f=e.children?e.children[0]:void 0;if((i==="*"||i==="-")&&f&&(!f.children||!f.children[0])&&r.stack[r.stack.length-1]==="list"&&r.stack[r.stack.length-2]==="listItem"&&r.stack[r.stack.length-3]==="list"&&r.stack[r.stack.length-4]==="listItem"&&r.indexStack[r.indexStack.length-1]===0&&r.indexStack[r.indexStack.length-2]===0&&r.indexStack[r.indexStack.length-3]===0&&(o=!0),tr(r)===i&&f){let d=-1;for(;++d<e.children.length;){const m=e.children[d];if(m&&m.type==="listItem"&&m.children&&m.children[0]&&m.children[0].type==="thematicBreak"){o=!0;break}}}}o&&(i=c),r.bulletCurrent=i;const l=r.containerFlow(e,a);return r.bulletLastUsed=i,r.bulletCurrent=s,n(),l}function Qn(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function Gn(e,t,r,a){const n=Qn(r);let s=r.bulletCurrent||Je(r);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(r.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let i=s.length+1;(n==="tab"||n==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(i=Math.ceil(i/4)*4);const c=r.createTracker(a);c.move(s+" ".repeat(i-s.length)),c.shift(i);const o=r.enter("listItem"),l=r.indentLines(r.containerFlow(e,c.current()),f);return o(),l;function f(d,m,g){return m?(g?"":" ".repeat(i))+d:(g?s:s+" ".repeat(i-s.length))+d}}function Yn(e,t,r,a){const n=r.enter("paragraph"),s=r.enter("phrasing"),i=r.containerPhrasing(e,a);return s(),n(),i}const Jn=_e(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function Xn(e,t,r,a){return(e.children.some(function(i){return Jn(i)})?r.containerPhrasing:r.containerFlow).call(r,e,a)}function Zn(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}rr.peek=ei;function rr(e,t,r,a){const n=Zn(r),s=r.enter("strong"),i=r.createTracker(a),c=i.move(n+n);let o=i.move(r.containerPhrasing(e,{after:n,before:c,...i.current()}));const l=o.charCodeAt(0),f=Me(a.before.charCodeAt(a.before.length-1),l,n);f.inside&&(o=be(l)+o.slice(1));const d=o.charCodeAt(o.length-1),m=Me(a.after.charCodeAt(0),d,n);m.inside&&(o=o.slice(0,-1)+be(d));const g=i.move(n+n);return s(),r.attentionEncodeSurroundingInfo={after:m.outside,before:f.outside},c+o+g}function ei(e,t,r){return r.options.strong||"*"}function ti(e,t,r,a){return r.safe(e.value,a)}function ri(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function ai(e,t,r){const a=(tr(r)+(r.options.ruleSpaces?" ":"")).repeat(ri(r));return r.options.ruleSpaces?a.slice(0,-1):a}const ar={blockquote:vn,break:bt,code:An,definition:_n,emphasis:Wt,hardBreak:bt,heading:Un,html:Qt,image:Gt,imageReference:Yt,inlineCode:Jt,link:Zt,linkReference:er,list:Kn,listItem:Gn,paragraph:Yn,root:Xn,strong:rr,text:ti,thematicBreak:ai};function ni(){return{enter:{table:ii,tableData:kt,tableHeader:kt,tableRow:oi},exit:{codeText:ci,table:si,tableData:$e,tableHeader:$e,tableRow:$e}}}function ii(e){const t=e._align;this.enter({type:"table",align:t.map(function(r){return r==="none"?null:r}),children:[]},e),this.data.inTable=!0}function si(e){this.exit(e),this.data.inTable=void 0}function oi(e){this.enter({type:"tableRow",children:[]},e)}function $e(e){this.exit(e)}function kt(e){this.enter({type:"tableCell",children:[]},e)}function ci(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,li));const r=this.stack[this.stack.length-1];r.type,r.value=t,this.exit(e)}function li(e,t){return t==="|"?t:e}function ui(e){const t=e||{},r=t.tableCellPadding,a=t.tablePipeAlign,n=t.stringLength,s=r?" ":"|";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:m,table:i,tableCell:o,tableRow:c}};function i(g,h,w,x){return l(f(g,w,x),g.align)}function c(g,h,w,x){const b=d(g,w,x),C=l([b]);return C.slice(0,C.indexOf(`
20
- `))}function o(g,h,w,x){const b=w.enter("tableCell"),C=w.enter("phrasing"),v=w.containerPhrasing(g,{...x,before:s,after:s});return C(),b(),v}function l(g,h){return kn(g,{align:h,alignDelimiters:a,padding:r,stringLength:n})}function f(g,h,w){const x=g.children;let b=-1;const C=[],v=h.enter("table");for(;++b<x.length;)C[b]=d(x[b],h,w);return v(),C}function d(g,h,w){const x=g.children;let b=-1;const C=[],v=h.enter("tableRow");for(;++b<x.length;)C[b]=o(x[b],g,h,w);return v(),C}function m(g,h,w){let x=ar.inlineCode(g,h,w);return w.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function di(){return{exit:{taskListCheckValueChecked:Ct,taskListCheckValueUnchecked:Ct,paragraph:fi}}}function hi(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:mi}}}function Ct(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function fi(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const r=this.stack[this.stack.length-1];r.type;const a=r.children[0];if(a&&a.type==="text"){const n=t.children;let s=-1,i;for(;++s<n.length;){const c=n[s];if(c.type==="paragraph"){i=c;break}}i===r&&(a.value=a.value.slice(1),a.value.length===0?r.children.shift():r.position&&a.position&&typeof a.position.start.offset=="number"&&(a.position.start.column++,a.position.start.offset++,r.position.start=Object.assign({},a.position.start)))}}this.exit(e)}function mi(e,t,r,a){const n=e.children[0],s=typeof e.checked=="boolean"&&n&&n.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",c=r.createTracker(a);s&&c.move(i);let o=ar.listItem(e,t,r,{...a,...c.current()});return s&&(o=o.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),o;function l(f){return f+i}}function pi(){return[qa(),dn(),pn(),ni(),di()]}function gi(e){return{extensions:[Va(),hn(e),gn(),ui(e),hi()]}}function je(e,t,r,a){const n=e.length;let s=0,i;if(t<0?t=-t>n?0:n+t:t=t>n?n:t,r=r>0?r:0,a.length<1e4)i=Array.from(a),i.unshift(t,r),e.splice(...i);else for(r&&e.splice(t,r);s<a.length;)i=a.slice(s,s+1e4),i.unshift(t,0),e.splice(...i),s+=1e4,t+=1e4}const vt={}.hasOwnProperty;function xi(e){const t={};let r=-1;for(;++r<e.length;)yi(t,e[r]);return t}function yi(e,t){let r;for(r in t){const n=(vt.call(e,r)?e[r]:void 0)||(e[r]={}),s=t[r];let i;if(s)for(i in s){vt.call(n,i)||(n[i]=[]);const c=s[i];bi(n[i],Array.isArray(c)?c:c?[c]:[])}}}function bi(e,t){let r=-1;const a=[];for(;++r<t.length;)(t[r].add==="after"?e:a).push(t[r]);je(e,0,0,a)}const wi={tokenize:Si,partial:!0},nr={tokenize:Ii,partial:!0},ir={tokenize:Mi,partial:!0},sr={tokenize:Ai,partial:!0},ki={tokenize:Ni,partial:!0},or={name:"wwwAutolink",tokenize:Ti,previous:lr},cr={name:"protocolAutolink",tokenize:ji,previous:ur},ae={name:"emailAutolink",tokenize:vi,previous:dr},G={};function Ci(){return{text:G}}let se=48;for(;se<123;)G[se]=ae,se++,se===58?se=65:se===91&&(se=97);G[43]=ae;G[45]=ae;G[46]=ae;G[95]=ae;G[72]=[ae,cr];G[104]=[ae,cr];G[87]=[ae,or];G[119]=[ae,or];function vi(e,t,r){const a=this;let n,s;return i;function i(d){return!He(d)||!dr.call(a,a.previous)||Xe(a.events)?r(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),c(d))}function c(d){return He(d)?(e.consume(d),c):d===64?(e.consume(d),o):r(d)}function o(d){return d===46?e.check(ki,f,l)(d):d===45||d===95||Ge(d)?(s=!0,e.consume(d),o):f(d)}function l(d){return e.consume(d),n=!0,o}function f(d){return s&&n&&ye(a.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):r(d)}}function Ti(e,t,r){const a=this;return n;function n(i){return i!==87&&i!==119||!lr.call(a,a.previous)||Xe(a.events)?r(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(wi,e.attempt(nr,e.attempt(ir,s),r),r)(i))}function s(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function ji(e,t,r){const a=this;let n="",s=!1;return i;function i(d){return(d===72||d===104)&&ur.call(a,a.previous)&&!Xe(a.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),n+=String.fromCodePoint(d),e.consume(d),c):r(d)}function c(d){if(ye(d)&&n.length<5)return n+=String.fromCodePoint(d),e.consume(d),c;if(d===58){const m=n.toLowerCase();if(m==="http"||m==="https")return e.consume(d),o}return r(d)}function o(d){return d===47?(e.consume(d),s?l:(s=!0,o)):r(d)}function l(d){return d===null||Aa(d)||V(d)||oe(d)||Ae(d)?r(d):e.attempt(nr,e.attempt(ir,f),r)(d)}function f(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function Si(e,t,r){let a=0;return n;function n(i){return(i===87||i===119)&&a<3?(a++,e.consume(i),n):i===46&&a===3?(e.consume(i),s):r(i)}function s(i){return i===null?r(i):t(i)}}function Ii(e,t,r){let a,n,s;return i;function i(l){return l===46||l===95?e.check(sr,o,c)(l):l===null||V(l)||oe(l)||l!==45&&Ae(l)?o(l):(s=!0,e.consume(l),i)}function c(l){return l===95?a=!0:(n=a,a=void 0),e.consume(l),i}function o(l){return n||a||!s?r(l):t(l)}}function Mi(e,t){let r=0,a=0;return n;function n(i){return i===40?(r++,e.consume(i),n):i===41&&a<r?s(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(sr,t,s)(i):i===null||V(i)||oe(i)?t(i):(e.consume(i),n)}function s(i){return i===41&&a++,e.consume(i),n}}function Ai(e,t,r){return a;function a(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),a):c===38?(e.consume(c),s):c===93?(e.consume(c),n):c===60||c===null||V(c)||oe(c)?t(c):r(c)}function n(c){return c===null||c===40||c===91||V(c)||oe(c)?t(c):a(c)}function s(c){return ye(c)?i(c):r(c)}function i(c){return c===59?(e.consume(c),a):ye(c)?(e.consume(c),i):r(c)}}function Ni(e,t,r){return a;function a(s){return e.consume(s),n}function n(s){return Ge(s)?r(s):t(s)}}function lr(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||V(e)}function ur(e){return!ye(e)}function dr(e){return!(e===47||He(e))}function He(e){return e===43||e===45||e===46||e===95||Ge(e)}function Xe(e){let t=e.length,r=!1;for(;t--;){const a=e[t][1];if((a.type==="labelLink"||a.type==="labelImage")&&!a._balanced){r=!0;break}if(a._gfmAutolinkLiteralWalkedInto){r=!1;break}}return e.length>0&&!r&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),r}function _i(e,t,r){const a=[];let n=-1;for(;++n<e.length;){const s=e[n].resolveAll;s&&!a.includes(s)&&(t=s(t,r),a.push(s))}return t}function re(e,t,r,a){const n=a?a-1:Number.POSITIVE_INFINITY;let s=0;return i;function i(o){return te(o)?(e.enter(r),c(o)):t(o)}function c(o){return te(o)&&s++<n?(e.consume(o),c):(e.exit(r),t(o))}}const Pi={partial:!0,tokenize:Ei};function Ei(e,t,r){return a;function a(s){return te(s)?re(e,n,"linePrefix")(s):n(s)}function n(s){return s===null||he(s)?t(s):r(s)}}const Ri={tokenize:Bi,partial:!0};function Li(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:zi,continuation:{tokenize:$i},exit:Oi}},text:{91:{name:"gfmFootnoteCall",tokenize:Ui},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Di,resolveTo:Fi}}}}function Di(e,t,r){const a=this;let n=a.events.length;const s=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let i;for(;n--;){const o=a.events[n][1];if(o.type==="labelImage"){i=o;break}if(o.type==="gfmFootnoteCall"||o.type==="labelLink"||o.type==="label"||o.type==="image"||o.type==="link")break}return c;function c(o){if(!i||!i._balanced)return r(o);const l=we(a.sliceSerialize({start:i.end,end:a.now()}));return l.codePointAt(0)!==94||!s.includes(l.slice(1))?r(o):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(o),e.exit("gfmFootnoteCallLabelMarker"),t(o))}}function Fi(e,t){let r=e.length;for(;r--;)if(e[r][1].type==="labelImage"&&e[r][0]==="enter"){e[r][1];break}e[r+1][1].type="data",e[r+3][1].type="gfmFootnoteCallLabelMarker";const a={type:"gfmFootnoteCall",start:Object.assign({},e[r+3][1].start),end:Object.assign({},e[e.length-1][1].end)},n={type:"gfmFootnoteCallMarker",start:Object.assign({},e[r+3][1].end),end:Object.assign({},e[r+3][1].end)};n.end.column++,n.end.offset++,n.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},n.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},c=[e[r+1],e[r+2],["enter",a,t],e[r+3],e[r+4],["enter",n,t],["exit",n,t],["enter",s,t],["enter",i,t],["exit",i,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",a,t]];return e.splice(r,e.length-r+1,...c),e}function Ui(e,t,r){const a=this,n=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let s=0,i;return c;function c(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),o}function o(d){return d!==94?r(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(d){if(s>999||d===93&&!i||d===null||d===91||V(d))return r(d);if(d===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return n.includes(we(a.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):r(d)}return V(d)||(i=!0),s++,e.consume(d),d===92?f:l}function f(d){return d===91||d===92||d===93?(e.consume(d),s++,l):l(d)}}function zi(e,t,r){const a=this,n=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let s,i=0,c;return o;function o(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):r(h)}function f(h){if(i>999||h===93&&!c||h===null||h===91||V(h))return r(h);if(h===93){e.exit("chunkString");const w=e.exit("gfmFootnoteDefinitionLabelString");return s=we(a.sliceSerialize(w)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return V(h)||(c=!0),i++,e.consume(h),h===92?d:f}function d(h){return h===91||h===92||h===93?(e.consume(h),i++,f):f(h)}function m(h){return h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),n.includes(s)||n.push(s),re(e,g,"gfmFootnoteDefinitionWhitespace")):r(h)}function g(h){return t(h)}}function $i(e,t,r){return e.check(Pi,t,e.attempt(Ri,t,r))}function Oi(e){e.exit("gfmFootnoteDefinition")}function Bi(e,t,r){const a=this;return re(e,n,"gfmFootnoteDefinitionIndent",5);function n(s){const i=a.events[a.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(s):r(s)}}function qi(e){let r=(e||{}).singleTilde;const a={name:"strikethrough",tokenize:s,resolveAll:n};return r==null&&(r=!0),{text:{126:a},insideSpan:{null:[a]},attentionMarkers:{null:[126]}};function n(i,c){let o=-1;for(;++o<i.length;)if(i[o][0]==="enter"&&i[o][1].type==="strikethroughSequenceTemporary"&&i[o][1]._close){let l=o;for(;l--;)if(i[l][0]==="exit"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._open&&i[o][1].end.offset-i[o][1].start.offset===i[l][1].end.offset-i[l][1].start.offset){i[o][1].type="strikethroughSequence",i[l][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},i[l][1].start),end:Object.assign({},i[o][1].end)},d={type:"strikethroughText",start:Object.assign({},i[l][1].end),end:Object.assign({},i[o][1].start)},m=[["enter",f,c],["enter",i[l][1],c],["exit",i[l][1],c],["enter",d,c]],g=c.parser.constructs.insideSpan.null;g&&je(m,m.length,0,_i(g,i.slice(l+1,o),c)),je(m,m.length,0,[["exit",d,c],["enter",i[o][1],c],["exit",i[o][1],c],["exit",f,c]]),je(i,l-1,o-l+3,m),o=l+m.length-2;break}}for(o=-1;++o<i.length;)i[o][1].type==="strikethroughSequenceTemporary"&&(i[o][1].type="data");return i}function s(i,c,o){const l=this.previous,f=this.events;let d=0;return m;function m(h){return l===126&&f[f.length-1][1].type!=="characterEscape"?o(h):(i.enter("strikethroughSequenceTemporary"),g(h))}function g(h){const w=Ie(l);if(h===126)return d>1?o(h):(i.consume(h),d++,g);if(d<2&&!r)return o(h);const x=i.exit("strikethroughSequenceTemporary"),b=Ie(h);return x._open=!b||b===2&&!!w,x._close=!w||w===2&&!!b,c(h)}}}class Vi{constructor(){this.map=[]}add(t,r,a){Wi(this,t,r,a)}consume(t){if(this.map.sort(function(s,i){return s[0]-i[0]}),this.map.length===0)return;let r=this.map.length;const a=[];for(;r>0;)r-=1,a.push(t.slice(this.map[r][0]+this.map[r][1]),this.map[r][2]),t.length=this.map[r][0];a.push(t.slice()),t.length=0;let n=a.pop();for(;n;){for(const s of n)t.push(s);n=a.pop()}this.map.length=0}}function Wi(e,t,r,a){let n=0;if(!(r===0&&a.length===0)){for(;n<e.map.length;){if(e.map[n][0]===t){e.map[n][1]+=r,e.map[n][2].push(...a);return}n+=1}e.map.push([t,r,a])}}function Hi(e,t){let r=!1;const a=[];for(;t<e.length;){const n=e[t];if(r){if(n[0]==="enter")n[1].type==="tableContent"&&a.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(n[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=a.length-1;a[s]=a[s]==="left"?"center":"right"}}else if(n[1].type==="tableDelimiterRow")break}else n[0]==="enter"&&n[1].type==="tableDelimiterRow"&&(r=!0);t+=1}return a}function Ki(){return{flow:{null:{name:"table",tokenize:Qi,resolveAll:Gi}}}}function Qi(e,t,r){const a=this;let n=0,s=0,i;return c;function c(p){let L=a.events.length-1;for(;L>-1;){const K=a.events[L][1].type;if(K==="lineEnding"||K==="linePrefix")L--;else break}const W=L>-1?a.events[L][1].type:null,H=W==="tableHead"||W==="tableRow"?I:o;return H===I&&a.parser.lazy[a.now().line]?r(p):H(p)}function o(p){return e.enter("tableHead"),e.enter("tableRow"),l(p)}function l(p){return p===124||(i=!0,s+=1),f(p)}function f(p){return p===null?r(p):he(p)?s>1?(s=0,a.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),g):r(p):te(p)?re(e,f,"whitespace")(p):(s+=1,i&&(i=!1,n+=1),p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),i=!0,f):(e.enter("data"),d(p)))}function d(p){return p===null||p===124||V(p)?(e.exit("data"),f(p)):(e.consume(p),p===92?m:d)}function m(p){return p===92||p===124?(e.consume(p),d):d(p)}function g(p){return a.interrupt=!1,a.parser.lazy[a.now().line]?r(p):(e.enter("tableDelimiterRow"),i=!1,te(p)?re(e,h,"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(p):h(p))}function h(p){return p===45||p===58?x(p):p===124?(i=!0,e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),w):N(p)}function w(p){return te(p)?re(e,x,"whitespace")(p):x(p)}function x(p){return p===58?(s+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),b):p===45?(s+=1,b(p)):p===null||he(p)?P(p):N(p)}function b(p){return p===45?(e.enter("tableDelimiterFiller"),C(p)):N(p)}function C(p){return p===45?(e.consume(p),C):p===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(p))}function v(p){return te(p)?re(e,P,"whitespace")(p):P(p)}function P(p){return p===124?h(p):p===null||he(p)?!i||n!==s?N(p):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(p)):N(p)}function N(p){return r(p)}function I(p){return e.enter("tableRow"),q(p)}function q(p){return p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),q):p===null||he(p)?(e.exit("tableRow"),t(p)):te(p)?re(e,q,"whitespace")(p):(e.enter("data"),M(p))}function M(p){return p===null||p===124||V(p)?(e.exit("data"),q(p)):(e.consume(p),p===92?U:M)}function U(p){return p===92||p===124?(e.consume(p),M):M(p)}}function Gi(e,t){let r=-1,a=!0,n=0,s=[0,0,0,0],i=[0,0,0,0],c=!1,o=0,l,f,d;const m=new Vi;for(;++r<e.length;){const g=e[r],h=g[1];g[0]==="enter"?h.type==="tableHead"?(c=!1,o!==0&&(Tt(m,t,o,l,f),f=void 0,o=0),l={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},m.add(r,0,[["enter",l,t]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(a=!0,d=void 0,s=[0,0,0,0],i=[0,r+1,0,0],c&&(c=!1,f={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},m.add(r,0,[["enter",f,t]])),n=h.type==="tableDelimiterRow"?2:f?3:1):n&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(a=!1,i[2]===0&&(s[1]!==0&&(i[0]=i[1],d=ve(m,t,s,n,void 0,d),s=[0,0,0,0]),i[2]=r)):h.type==="tableCellDivider"&&(a?a=!1:(s[1]!==0&&(i[0]=i[1],d=ve(m,t,s,n,void 0,d)),s=i,i=[s[1],r,0,0])):h.type==="tableHead"?(c=!0,o=r):h.type==="tableRow"||h.type==="tableDelimiterRow"?(o=r,s[1]!==0?(i[0]=i[1],d=ve(m,t,s,n,r,d)):i[1]!==0&&(d=ve(m,t,i,n,r,d)),n=0):n&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(i[3]=r)}for(o!==0&&Tt(m,t,o,l,f),m.consume(t.events),r=-1;++r<t.events.length;){const g=t.events[r];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=Hi(t.events,r))}return e}function ve(e,t,r,a,n,s){const i=a===1?"tableHeader":a===2?"tableDelimiter":"tableData",c="tableContent";r[0]!==0&&(s.end=Object.assign({},ue(t.events,r[0])),e.add(r[0],0,[["exit",s,t]]));const o=ue(t.events,r[1]);if(s={type:i,start:Object.assign({},o),end:Object.assign({},o)},e.add(r[1],0,[["enter",s,t]]),r[2]!==0){const l=ue(t.events,r[2]),f=ue(t.events,r[3]),d={type:c,start:Object.assign({},l),end:Object.assign({},f)};if(e.add(r[2],0,[["enter",d,t]]),a!==2){const m=t.events[r[2]],g=t.events[r[3]];if(m[1].end=Object.assign({},g[1].end),m[1].type="chunkText",m[1].contentType="text",r[3]>r[2]+1){const h=r[2]+1,w=r[3]-r[2]-1;e.add(h,w,[])}}e.add(r[3]+1,0,[["exit",d,t]])}return n!==void 0&&(s.end=Object.assign({},ue(t.events,n)),e.add(n,0,[["exit",s,t]]),s=void 0),s}function Tt(e,t,r,a,n){const s=[],i=ue(t.events,r);n&&(n.end=Object.assign({},i),s.push(["exit",n,t])),a.end=Object.assign({},i),s.push(["exit",a,t]),e.add(r+1,0,s)}function ue(e,t){const r=e[t],a=r[0]==="enter"?"start":"end";return r[1][a]}const Yi={name:"tasklistCheck",tokenize:Xi};function Ji(){return{text:{91:Yi}}}function Xi(e,t,r){const a=this;return n;function n(o){return a.previous!==null||!a._gfmTasklistFirstContentOfListItem?r(o):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),s)}function s(o){return V(o)?(e.enter("taskListCheckValueUnchecked"),e.consume(o),e.exit("taskListCheckValueUnchecked"),i):o===88||o===120?(e.enter("taskListCheckValueChecked"),e.consume(o),e.exit("taskListCheckValueChecked"),i):r(o)}function i(o){return o===93?(e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),c):r(o)}function c(o){return he(o)?t(o):te(o)?e.check({tokenize:Zi},t,r)(o):r(o)}}function Zi(e,t,r){return re(e,a,"whitespace");function a(n){return n===null?r(n):t(n)}}function es(e){return xi([Ci(),Li(),qi(e),Ki(),Ji()])}const ts={};function rs(e){const t=this,r=e||ts,a=t.data(),n=a.micromarkExtensions||(a.micromarkExtensions=[]),s=a.fromMarkdownExtensions||(a.fromMarkdownExtensions=[]),i=a.toMarkdownExtensions||(a.toMarkdownExtensions=[]);n.push(es(r)),s.push(pi()),i.push(gi(r))}function $(...e){return e.filter(Boolean).join(" ")}const as=({content:e})=>u.jsx(qe.MarkdownTextPrimitive,{remarkPlugins:[rs],className:"cuadra-aui-md",components:ss,children:e}),Ze=y.memo(as),ns=({language:e,code:t})=>{const{isCopied:r,copyToClipboard:a}=is(),n=()=>{!t||r||a(t)};return u.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:[u.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),u.jsxs("button",{onClick:n,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!r&&u.jsx(Lr,{className:"cuadra-h-4 cuadra-w-4"}),r&&u.jsx(It,{className:"cuadra-h-4 cuadra-w-4"})]})]})},is=({copiedDuration:e=3e3}={})=>{const[t,r]=y.useState(!1);return{isCopied:t,copyToClipboard:n=>{n&&navigator.clipboard.writeText(n).then(()=>{r(!0),setTimeout(()=>r(!1),e)})}}},ss=qe.unstable_memoizeMarkdownComponents({h1:({className:e,...t})=>u.jsx("h1",{className:$("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...t}),h2:({className:e,...t})=>u.jsx("h2",{className:$("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),...t}),h3:({className:e,...t})=>u.jsx("h3",{className:$("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),...t}),h4:({className:e,...t})=>u.jsx("h4",{className:$("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),...t}),h5:({className:e,...t})=>u.jsx("h5",{className:$("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...t}),h6:({className:e,...t})=>u.jsx("h6",{className:$("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...t}),p:({className:e,...t})=>u.jsx("p",{className:$("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...t}),a:({className:e,...t})=>u.jsx("a",{className:$("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...t}),blockquote:({className:e,...t})=>u.jsx("blockquote",{className:$("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...t}),ul:({className:e,...t})=>u.jsx("ul",{className:$("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...t}),ol:({className:e,...t})=>u.jsx("ol",{className:$("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...t}),hr:({className:e,...t})=>u.jsx("hr",{className:$("cuadra-my-5 cuadra-border-b",e),...t}),table:({className:e,...t})=>u.jsx("table",{className:$("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...t}),th:({className:e,...t})=>u.jsx("th",{className:$("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),...t}),td:({className:e,...t})=>u.jsx("td",{className:$("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),...t}),tr:({className:e,...t})=>u.jsx("tr",{className:$("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),...t}),sup:({className:e,...t})=>u.jsx("sup",{className:$("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...t}),pre:({className:e,...t})=>u.jsx("pre",{className:$("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),...t}),code:function({className:t,...r}){const a=qe.useIsMarkdownCodeBlock();return u.jsx("code",{className:$(!a&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",t),...r})},CodeHeader:ns});function et({className:e="",variant:t="default",...r}){const a="cuadra-inline-flex cuadra-items-center cuadra-rounded-md cuadra-px-3 cuadra-py-1.5 cuadra-text-xs cuadra-font-medium font-brand",n={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 u.jsx("div",{className:`${a} ${n[t]||n.default} ${e}`,...r})}function os(e){const t=new Map;for(const r of e){const a=t.get(r.filename);(!a||r.score>a.score)&&t.set(r.filename,r)}return Array.from(t.values()).sort((r,a)=>a.score-r.score)}function hr({sources:e,maxVisible:t=3}){if(!e||e.length===0)return null;const r=os(e),a=r.slice(0,t),n=r.length-t;return u.jsxs("div",{className:"cuadra-mt-4 cuadra-pt-3 cuadra-border-t cuadra-border-border",children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-mb-2.5",children:[u.jsx(Mt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-text-xs cuadra-font-medium cuadra-text-muted-foreground font-brand",children:"Sources"})]}),u.jsxs("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-gap-2",children:[a.map((s,i)=>u.jsx(ls,{source:s},s.sourceId||i)),n>0&&u.jsxs(et,{variant:"subtle",children:["+",n," more"]})]})]})}function cs(e){switch(e.split(".").pop()?.toLowerCase()){case"csv":case"xlsx":case"xls":return Ur;case"md":case"txt":return Or;default:return Mt}}function ls({source:e}){const{filename:t,score:r}=e,a=cs(t);return u.jsxs(et,{className:"cuadra-gap-2 cuadra-cursor-default",title:r<1?`${Math.round(r*100)}% relevant`:void 0,children:[u.jsx(a,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-opacity-60"}),u.jsx("span",{className:"cuadra-truncate cuadra-max-w-[180px]",children:t}),r<1&&r>0&&u.jsxs("span",{className:"cuadra-opacity-50 cuadra-text-[10px] cuadra-tabular-nums",children:[Math.round(r*100),"%"]})]})}const us=y.forwardRef(function({welcomeTitle:t="What shall we explore today?",welcomeSubtitle:r,extraTopPadding:a,suggestions:n,inputPlaceholder:s="Reply...",enableAttachments:i=!1,preMadeResponseDelay:c=1e3,streamingSpeed:o=50,safeArea:l=!1,composerBorder:f=!1,models:d,selectedModelId:m,onModelChange:g,showChatHeader:h=!1},w){const x=T.useThreadRuntime(),b=T.useAssistantApi(),[C,v]=y.useState(!1),[P,N]=y.useState(null),[I,q]=y.useState(!1),M=y.useSyncExternalStore(de.subscribe,de.getSnapshot);y.useEffect(()=>{if(M){const A=setTimeout(()=>de.clear(),4e3);return()=>clearTimeout(A)}},[M]);const U=T.useThread(A=>{const R=A.messages;return!R||R.length===0}),p=U&&!C,L=y.useCallback((A,R,k)=>{if(!I)try{const j=k?.streamingSpeed??o,_=k?.delay??c;Ft(A,R,j,_),b.composer().setText(A),setTimeout(()=>{b.composer().send()},10)}catch{}},[I,o,c,b]),W=y.useCallback(A=>{try{b.composer().setText(A),setTimeout(()=>{b.composer().send()},10)}catch{}},[b]),H=y.useCallback(async A=>{if(!(I||!x))try{if(A.response){const R=A.responseDelay??c;await L(A.prompt,A.response,{delay:R,streamingSpeed:o})}else W(A.prompt)}catch{}},[x,I,c,o,L,W]),K=y.useCallback(async()=>{try{const R=window.__cuadraThreadListRuntime?.threadList;R?.switchToNewThread&&await R.switchToNewThread()}catch{}},[]);return y.useImperativeHandle(w,()=>({sendMessage:W,sendPreMadeQA:L,clearChat:K}),[W,L,K]),y.useEffect(()=>{if(!x){v(!1);return}try{const A=x?.store;if(!A){v(!1);return}const R=A.subscribe?.(j=>{const _=j?.threadId,F=j?.messages||[],D=j?.isLoadingHistory||!1,S=F.length;_&&_!==P&&N(_),v(D&&S===0)}),k=A.getState?.();if(k){const j=k?.threadId,_=k?.messages||[],F=k?.isLoadingHistory||!1,D=_.length;j&&j!==P&&N(j),v(F&&D===0)}return()=>{R&&R()}}catch{v(!1)}},[x,P]),u.jsxs(T.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full cuadra-relative",children:[h&&u.jsx(xs,{}),u.jsxs(T.ComposerPrimitive.AttachmentDropzone,{disabled:!i,className:`cuadra-flex-1 cuadra-flex cuadra-flex-col cuadra-min-h-0 cuadra-relative ${p?"cuadra-justify-center":""}`,children:[u.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:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[u.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:u.jsx(Yr,{className:"cuadra-h-6 cuadra-w-6"})}),u.jsx("p",{className:"cuadra-text-sm cuadra-font-medium cuadra-text-foreground font-brand",children:"Drop files here"})]})}),u.jsx(T.ThreadPrimitive.Viewport,{className:`cuadra-w-full cuadra-bg-inherit cuadra-relative scrollbar-thin ${p?"cuadra-flex-none":"cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto"}`,style:{paddingTop:p?"0":a||(h?"0.5rem":"2rem")},children:C?u.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[u.jsx(At,{className:"cuadra-h-5 cuadra-w-5 cuadra-animate-spin cuadra-text-muted-foreground"}),u.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):u.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full cuadra-px-4",children:[u.jsx(T.ThreadPrimitive.Empty,{children:u.jsx(ds,{title:t,subtitle:r})}),u.jsx(T.ThreadPrimitive.Messages,{components:{UserMessage:hs,AssistantMessage:ps}})]})}),u.jsx("div",{className:`cuadra-w-full cuadra-px-4 cuadra-pt-2 ${p?"cuadra-pb-2":"cuadra-pb-4"}`,style:l?{paddingBottom:"calc(env(safe-area-inset-bottom) + 1rem)"}:void 0,children:u.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:[M&&u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 cuadra-mb-2 cuadra-px-3 cuadra-py-2 cuadra-rounded-lg cuadra-text-xs font-brand cuadra-animate-in cuadra-fade-in cuadra-slide-in-from-bottom-2",style:{backgroundColor:"var(--cuadra-muted)",color:"var(--cuadra-foreground)",opacity:.85},children:[u.jsx(Er,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-flex-shrink-0 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-flex-1 cuadra-text-muted-foreground",children:M.message}),u.jsx("button",{type:"button",onClick:()=>de.clear(),className:"cuadra-flex-shrink-0 cuadra-p-0.5 cuadra-rounded hover:cuadra-bg-black/5 cuadra-transition-colors","aria-label":"Dismiss",children:u.jsx(ut,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})]}),i&&u.jsx(T.ComposerPrimitive.Attachments,{components:{Attachment:()=>{const A=T.useAssistantState(({attachment:R})=>R);return A?u.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:[u.jsx(Nt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground",strokeWidth:1.5}),u.jsx("span",{className:"cuadra-text-xs cuadra-text-foreground font-brand",children:A.name||"Attachment"}),u.jsx(T.AttachmentPrimitive.Remove,{asChild:!0,children:u.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:u.jsx(ut,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})})]}):null}}}),u.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:f?"1px solid hsl(var(--cuadra-border))":"none"},children:[u.jsx(T.ComposerPrimitive.Input,{asChild:!0,children:u.jsx("textarea",{rows:1,placeholder:s,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"}})}),u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-pb-2.5 cuadra-pt-1",children:[u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:i&&u.jsx(T.ComposerPrimitive.AddAttachment,{multiple:!0,asChild:!0,children:u.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:[u.jsx(_t,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground",strokeWidth:1.5}),u.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"})]})})}),u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[d&&d.length>0&&u.jsx(gs,{models:d,selectedModelId:m,onModelChange:g,threadIsEmpty:U,onNewChat:K}),u.jsx(T.ComposerPrimitive.Send,{asChild:!0,children:u.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:u.jsx(Mr,{className:"cuadra-h-4 cuadra-w-4",strokeWidth:2})})})]})]})]})]})}),p&&n&&n.length>0&&u.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,R)=>u.jsx("button",{type:"button",onClick:()=>H(A),disabled:I,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-${R}`))})]})]})});function ds({title:e,subtitle:t}){return u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-text-center cuadra-py-6",children:[u.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}),t&&u.jsx("p",{className:"cuadra-text-base cuadra-text-muted-foreground/70 cuadra-mt-3 cuadra-max-w-lg cuadra-whitespace-pre-line",children:t})]})}function hs(){return u.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-end cuadra-py-2.5",children:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-end cuadra-gap-2 cuadra-max-w-[80%]",children:[u.jsx(T.MessagePrimitive.Attachments,{components:{Attachment:()=>{const e=T.useAssistantState(({attachment:s})=>s);if(!e)return null;const t=e.type==="image",r=e.file,a=e.content?.find(s=>s.type==="image"),n=r?URL.createObjectURL(r):a?.image;return u.jsx("div",{className:"cuadra-mb-1",children:t&&n?u.jsx("img",{src:n,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)"}}):u.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:[u.jsx(Nt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground font-brand",children:e.name||"Attachment"})]})})}}}),u.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:u.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>u.jsx(Ze,{content:e||""})}})})]})})}function fs({text:e}){const[t,r]=y.useState(!1),a=T.useAssistantState(({message:n})=>n?.status?.type==="running");return e?a?u.jsx("div",{className:"cuadra-mb-3 cuadra-py-1",children:u.jsx("div",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand cuadra-animate-text-shimmer",children:e})}):u.jsxs("div",{className:"cuadra-mb-3",children:[u.jsxs("button",{type:"button",onClick:()=>r(!t),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:[u.jsx(Ke,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-transition-transform cuadra-duration-200 ${t?"":"cuadra--rotate-90"}`}),u.jsx("span",{children:"Reasoning"})]}),u.jsx("div",{className:`cuadra-overflow-hidden cuadra-transition-all cuadra-duration-200 cuadra-ease-out ${t?"cuadra-max-h-[2000px] cuadra-opacity-100":"cuadra-max-h-0 cuadra-opacity-0"}`,children:u.jsx("div",{className:"cuadra-pl-5 cuadra-pt-2 cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand",children:u.jsx(Ze,{content:e})})})]}):null}function ms(){return u.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:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:[u.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}}),u.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}}),u.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}})]}),u.jsx("span",{children:"Thinking..."})]})}function ps(){const e=T.useAssistantState(({message:i})=>i?.status?.type==="running"),t=T.useAssistantState(({message:i})=>{const c=i?.content;return!c||!Array.isArray(c)?!1:c.some(o=>!!(o.type==="text"&&o.text&&o.text.length>0||o.type==="reasoning"&&o.text&&o.text.length>0))}),r=y.useRef(!1),[a,n]=y.useState(null);y.useEffect(()=>{if(e&&t&&!r.current){const i=ee.getCurrentMessageId();i&&(r.current=!0,n(i))}},[e,t]);const s=y.useSyncExternalStore(i=>ee.subscribe(i),()=>{if(a){const i=ee.getForMessage(a);return i.sources?.length?i.sources:null}if(e&&t){const i=ee.getCurrentMessageId();if(i){const c=ee.getForMessage(i);return c.sources?.length?c.sources:null}}return null},()=>null);return u.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-start cuadra-py-2.5",children:u.jsxs("div",{className:"cuadra-text-foreground cuadra-max-w-full cuadra-break-words font-brand",style:{fontSize:"0.9375rem",lineHeight:"1.75"},children:[u.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:i})=>u.jsx(Ze,{content:i||""}),Reasoning:({text:i})=>u.jsx(fs,{text:i||""})}}),e&&!t&&u.jsx(ms,{}),s&&s.length>0&&u.jsx(hr,{sources:s})]})})}function Te({label:e,children:t}){return u.jsxs("span",{className:"cuadra-relative cuadra-inline-flex cuadra-group/tip",children:[t,u.jsx("span",{className:"cuadra-absolute cuadra-bottom-full cuadra-left-1/2 cuadra-mb-1.5 cuadra-hidden group-hover/tip:cuadra-flex cuadra-items-center cuadra-whitespace-nowrap cuadra-rounded-md cuadra-px-2 cuadra-py-1 cuadra-text-[10px] cuadra-pointer-events-none cuadra-z-50 font-brand",style:{backgroundColor:"var(--cuadra-popover)",color:"var(--cuadra-foreground)",boxShadow:"0 2px 8px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)",transform:"translateX(-50%)"},children:e})]})}function gs({models:e,selectedModelId:t,onModelChange:r,threadIsEmpty:a,onNewChat:n}){const[s,i]=y.useState(!1),c=e.find(l=>l.id===t)||e[0];if(!c)return null;const o=async l=>{i(!1),!a&&l!==t&&await n?.(),r?.(l)};return u.jsxs("div",{className:"cuadra-relative",children:[u.jsxs("button",{type:"button",onClick:()=>i(!s),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:[u.jsx("span",{children:c.name}),c.supportsReasoning&&u.jsx(Te,{label:"Reasoning",children:u.jsx(ct,{className:"cuadra-h-3 cuadra-w-3"})}),c.supportsVision&&u.jsx(Te,{label:"Vision",children:u.jsx(lt,{className:"cuadra-h-3 cuadra-w-3"})}),u.jsx(Ke,{className:"cuadra-h-3 cuadra-w-3"})]}),s&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>i(!1)}),u.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-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=>u.jsxs("button",{type:"button",className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-3 cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted/60 cuadra-transition-colors font-brand",onClick:()=>o(l.id),children:[u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-min-w-0",children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5",children:[u.jsx("span",{className:"cuadra-text-foreground cuadra-truncate",children:l.name}),l.supportsReasoning&&u.jsx(Te,{label:"Reasoning",children:u.jsx(ct,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground cuadra-flex-shrink-0"})}),l.supportsVision&&u.jsx(Te,{label:"Vision",children:u.jsx(lt,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground cuadra-flex-shrink-0"})})]}),l.description&&u.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground",children:l.description})]}),l.id===t&&u.jsx(It,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-primary cuadra-flex-shrink-0"})]},l.id))})]})]})}function xs(){const e=T.useAssistantState(({threadListItem:n})=>n?.title??null),[t,r]=y.useState(!1),a=e||"Untitled chat";return u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-px-3 cuadra-py-2 cuadra-min-h-[48px]",children:u.jsxs("div",{className:"cuadra-relative",children:[u.jsxs("button",{type:"button",onClick:()=>r(!t),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:[u.jsx("span",{className:"cuadra-font-medium cuadra-truncate cuadra-max-w-[200px]",children:a}),u.jsx(Ke,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground cuadra-flex-shrink-0 cuadra-transition-transform cuadra-duration-200 ${t?"cuadra-rotate-180":""}`})]}),t&&u.jsx(ys,{onClose:()=>r(!1)})]})})}function ys({onClose:e}){return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:e}),u.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:u.jsxs(T.ThreadListPrimitive.Root,{className:"cuadra-flex cuadra-flex-col",children:[u.jsx("div",{className:"cuadra-px-2 cuadra-py-1.5",children:u.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:[u.jsx(_t,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),"New Chat"]})}),u.jsx(bs,{onSelect:e})]})})]})}function bs({onSelect:e}){const t=T.useAssistantState(({threads:n})=>n?.threadIds??[]),r=T.useAssistantState(({threads:n})=>n?.newThreadId);return t.some(n=>n!==r)?u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-mx-3 cuadra-my-0.5",style:{borderTop:"1px solid rgba(0,0,0,0.06)"}}),u.jsx("div",{className:"cuadra-overflow-y-auto cuadra-px-2 cuadra-pb-1.5 scrollbar-thin",style:{maxHeight:"340px"},children:u.jsx(T.ThreadListPrimitive.Items,{components:{ThreadListItem:n=>u.jsx(ws,{...n,onSelect:e})}})})]}):null}function ws({onSelect:e}){const t=T.useThreadListItem(),r=T.useThreadListItemRuntime(),a=T.useAssistantRuntime(),n=T.useThread(x=>x.threadId),s=t?.id===n,[i,c]=y.useState(!1),[o,l]=y.useState(!1),[f,d]=y.useState(t?.title||""),[m,g]=y.useState(!1),h=async()=>{if(!t?.remoteId||!f||f===t.title){l(!1);return}try{g(!0),await r.rename(f)}catch{}finally{g(!1),l(!1)}},w=async x=>{x.stopPropagation();try{await r.delete(),s&&await a.switchToNewThread()}catch(b){console.error("[CuadraChat] Failed to delete thread:",b)}};return y.useEffect(()=>{t?.title&&!o&&d(t.title)},[t?.title,o]),t?u.jsxs(T.ThreadListItemPrimitive.Root,{className:`cuadra-relative cuadra-flex cuadra-items-center cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer ${s?"cuadra-bg-muted":"hover:cuadra-bg-muted/60"}`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[o?u.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:u.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=>d(x.target.value),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&h(),x.key==="Escape"&&(l(!1),d(t.title||""))},onBlur:()=>void h(),disabled:m,autoFocus:!0})}):u.jsx(T.ThreadListItemPrimitive.Trigger,{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:u.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground cuadra-truncate cuadra-block cuadra-text-left font-brand",children:t.title||"Chat"})}),(i||s)&&!o&&u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-0.5 cuadra-mr-1.5 cuadra-flex-shrink-0",children:[u.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/60 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),l(!0),d(t.title||"Chat")},title:"Rename",children:u.jsx(Wr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})}),u.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-destructive/10 cuadra-transition-colors",onClick:w,title:"Delete",children:u.jsx(Qr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-destructive"})})]})]}):null}const Oe=({children:e,className:t="",paddingX:r="px-0",paddingY:a="py-0",borderSizePx:n=2,style:s,contentStyle:i})=>u.jsx("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-lg cuadra-overflow-hidden cuadra-flex cuadra-flex-col ${r} ${a} ${t}`,style:{border:n>0?`${n}px solid var(--cuadra-primary)`:"none",...s,...i},children:e}),ks=y.createContext(void 0),Be=({children:e,value:t})=>u.jsx(ks.Provider,{value:t,children:e});function Cs(){y.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const t=document.createElement("div");t.className="cuadra-flex",document.body.appendChild(t);const r=window.getComputedStyle(t).display==="flex";if(document.body.removeChild(t),r)return;const a=document.createElement("link");a.setAttribute("data-cuadra-uikit","true"),a.rel="stylesheet",a.type="text/css";const n=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:fe&&fe.tagName.toUpperCase()==="SCRIPT"&&fe.src||new URL("index.cjs",document.baseURI).href).href];let s=!1;for(const i of n)if(a.href=i,a.onload=()=>{s=!0},a.onerror=()=>{},document.head.appendChild(a),s)break},[])}const vs=y.forwardRef(function({config:t},r){Cs();const a=y.useRef(null),n=y.useRef(!1),{baseUrl:s,proxyUrl:i,sessionToken:c,mode:o="multiChat",modelMode:l="fixed",modelId:f,onModelChange:d,ephemeral:m=!1,systemPrompt:g,enableReasoning:h=!1,initialThreadId:w,welcomeTitle:x,welcomeSubtitle:b,extraTopPadding:C,suggestions:v,inputPlaceholder:P,preMadeResponseDelay:N=1e3,streamingSpeed:I=50,initialMessage:q,initialPreMadeQA:M,theme:U="system",onError:p,onChatCreated:L,onUserMessage:W,onThreadIdUpdate:H,enableAttachments:K=!1,supportsVision:A,onBeforeRequest:R,mockResponseOnBlocked:k}=t;y.useImperativeHandle(r,()=>({sendMessage:E=>{a.current?.sendMessage(E)},sendPreMadeQA:(E,Z,ie)=>{a.current?.sendPreMadeQA(E,Z,ie)},clearChat:()=>{a.current?.clearChat()}}),[]),y.useEffect(()=>{if(n.current)return;const E=setTimeout(()=>{M?(n.current=!0,a.current?.sendPreMadeQA(M.question,M.answer,{delay:N,streamingSpeed:I})):q&&(n.current=!0,a.current?.sendMessage(q))},500);return()=>clearTimeout(E)},[q,M,N,I]);const j=i||s||"",_=!!i,F=y.useMemo(()=>new Et(j,c||void 0,_),[j,c,_]),[D,S]=y.useState(null),[O,Y]=y.useState(!1),[J,ge]=y.useState(null),[Ee,X]=y.useState(!1);y.useEffect(()=>{o==="multiChat"&&X(!0)},[o]);const ne=y.useCallback(async()=>{if(l==="selector"){Y(!0),ge(null);try{const E=await F.listModels();S(E)}catch(E){ge(E instanceof Error?E:new Error("Failed to load models"))}finally{Y(!1)}}},[F,l]);y.useEffect(()=>{l==="selector"&&ne()},[l,ne]),y.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=ne),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[ne]);const[Q,rt]=y.useState(l==="fixed"&&f||null),at=y.useRef(Q),ke=y.useCallback(E=>{const Z=at.current;rt(E),at.current=E,d?.(E),Z!==null&&Z!==E&&o==="multiChat"&&setTimeout(()=>{const ie=window.__cuadraThreadListRuntime;if(ie?.threads?.switchToNewThread)try{ie.threads.switchToNewThread()}catch{}else if(ie?.threads?.createThread)try{ie.threads.createThread()}catch{}else if(ie?.switchToNewThread)try{ie.switchToNewThread()}catch{}},100)},[d,o]);y.useEffect(()=>{if(l==="selector"&&D?.items&&D.items.length>0&&!Q){const E=D.items[0];if(E?.id){const Z=E.id;rt(Z),d?.(Z)}}},[l,D?.items,Q,d]);const xr=l==="fixed"?!!f:!!Q,yr=y.useMemo(()=>A!==void 0?A:l==="selector"&&Q&&D?.items?D.items.find(Z=>Z.id===Q)?.supportsVision??!0:!0,[A,l,Q,D?.items]),Re=y.useMemo(()=>(D?.items||[]).filter(E=>E?.id&&E?.displayName).map(E=>({id:E.id,name:E.displayName,supportsVision:E.supportsVision??!1,supportsReasoning:E.supportsReasoning??!1})),[D]),Le=y.useMemo(()=>({currentModelId:Q||"",models:Re,modelsLoading:O,modelsError:J,onModelChange:ke,refetchModels:ne}),[Q,Re,O,J,ke,ne]);return l==="selector"&&O||o==="multiChat"&&Ee?u.jsx(Be,{value:Le,children:u.jsx(Oe,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",borderSizePx:t.borderless?0:2,children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx(At,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):l==="selector"&&!xr&&J?u.jsx(Be,{value:Le,children:u.jsx(Oe,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:u.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):u.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:u.jsx(Be,{value:Le,children:u.jsx(Sa,{baseUrl:_?j:s||j,sessionToken:c,isProxyMode:_,mode:o,modelMode:l,modelId:Q||f||void 0,onModelChange:ke,ephemeral:m,systemPrompt:g,enableReasoning:h,initialThreadId:w,enableAttachments:K,supportsVision:yr,onError:p,onChatCreated:L,onUserMessage:W,onThreadIdUpdate:H,onBeforeRequest:R,mockResponseOnBlocked:k,onChatsLoaded:()=>{o==="multiChat"&&X(!1)},children:u.jsx(Oe,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${t.containerClass||""}`,borderSizePx:t.borderless?0:2,style:{height:"100%"},children:u.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:u.jsx("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:u.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0",children:u.jsx(us,{ref:a,welcomeTitle:x,welcomeSubtitle:b,extraTopPadding:C,suggestions:v,inputPlaceholder:P,enableAttachments:K,preMadeResponseDelay:N,streamingSpeed:I,safeArea:t.safeArea,showChatHeader:o==="multiChat",models:l==="selector"?Re:void 0,selectedModelId:Q||void 0,onModelChange:l==="selector"?ke:void 0,theme:U})})})})})})})})});function fr(e,t=":root"){if(typeof document>"u")return;const r=document.documentElement,a=[];if(e.light){js(e.light,r);const n=jt(e.light);n&&a.push(`.cuadra-uikit { ${n} }`)}if(e.dark){const n=jt(e.dark);n&&(a.push(`.dark { ${n} }`),a.push(`.dark .cuadra-uikit { ${n} }`))}if(a.length>0){let n=document.getElementById("cuadra-theme-custom");n||(n=document.createElement("style"),n.id="cuadra-theme-custom",document.head.appendChild(n)),n.textContent=a.join(`
20
+ `))}function o(g,h,w,x){const b=w.enter("tableCell"),C=w.enter("phrasing"),v=w.containerPhrasing(g,{...x,before:s,after:s});return C(),b(),v}function l(g,h){return kn(g,{align:h,alignDelimiters:a,padding:r,stringLength:n})}function f(g,h,w){const x=g.children;let b=-1;const C=[],v=h.enter("table");for(;++b<x.length;)C[b]=d(x[b],h,w);return v(),C}function d(g,h,w){const x=g.children;let b=-1;const C=[],v=h.enter("tableRow");for(;++b<x.length;)C[b]=o(x[b],g,h,w);return v(),C}function m(g,h,w){let x=ar.inlineCode(g,h,w);return w.stack.includes("tableCell")&&(x=x.replace(/\|/g,"\\$&")),x}}function di(){return{exit:{taskListCheckValueChecked:Ct,taskListCheckValueUnchecked:Ct,paragraph:fi}}}function hi(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:mi}}}function Ct(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function fi(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const r=this.stack[this.stack.length-1];r.type;const a=r.children[0];if(a&&a.type==="text"){const n=t.children;let s=-1,i;for(;++s<n.length;){const c=n[s];if(c.type==="paragraph"){i=c;break}}i===r&&(a.value=a.value.slice(1),a.value.length===0?r.children.shift():r.position&&a.position&&typeof a.position.start.offset=="number"&&(a.position.start.column++,a.position.start.offset++,r.position.start=Object.assign({},a.position.start)))}}this.exit(e)}function mi(e,t,r,a){const n=e.children[0],s=typeof e.checked=="boolean"&&n&&n.type==="paragraph",i="["+(e.checked?"x":" ")+"] ",c=r.createTracker(a);s&&c.move(i);let o=ar.listItem(e,t,r,{...a,...c.current()});return s&&(o=o.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),o;function l(f){return f+i}}function pi(){return[qa(),dn(),pn(),ni(),di()]}function gi(e){return{extensions:[Va(),hn(e),gn(),ui(e),hi()]}}function je(e,t,r,a){const n=e.length;let s=0,i;if(t<0?t=-t>n?0:n+t:t=t>n?n:t,r=r>0?r:0,a.length<1e4)i=Array.from(a),i.unshift(t,r),e.splice(...i);else for(r&&e.splice(t,r);s<a.length;)i=a.slice(s,s+1e4),i.unshift(t,0),e.splice(...i),s+=1e4,t+=1e4}const vt={}.hasOwnProperty;function xi(e){const t={};let r=-1;for(;++r<e.length;)yi(t,e[r]);return t}function yi(e,t){let r;for(r in t){const n=(vt.call(e,r)?e[r]:void 0)||(e[r]={}),s=t[r];let i;if(s)for(i in s){vt.call(n,i)||(n[i]=[]);const c=s[i];bi(n[i],Array.isArray(c)?c:c?[c]:[])}}}function bi(e,t){let r=-1;const a=[];for(;++r<t.length;)(t[r].add==="after"?e:a).push(t[r]);je(e,0,0,a)}const wi={tokenize:Si,partial:!0},nr={tokenize:Ii,partial:!0},ir={tokenize:Mi,partial:!0},sr={tokenize:Ai,partial:!0},ki={tokenize:Ni,partial:!0},or={name:"wwwAutolink",tokenize:Ti,previous:lr},cr={name:"protocolAutolink",tokenize:ji,previous:ur},ae={name:"emailAutolink",tokenize:vi,previous:dr},G={};function Ci(){return{text:G}}let se=48;for(;se<123;)G[se]=ae,se++,se===58?se=65:se===91&&(se=97);G[43]=ae;G[45]=ae;G[46]=ae;G[95]=ae;G[72]=[ae,cr];G[104]=[ae,cr];G[87]=[ae,or];G[119]=[ae,or];function vi(e,t,r){const a=this;let n,s;return i;function i(d){return!He(d)||!dr.call(a,a.previous)||Xe(a.events)?r(d):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),c(d))}function c(d){return He(d)?(e.consume(d),c):d===64?(e.consume(d),o):r(d)}function o(d){return d===46?e.check(ki,f,l)(d):d===45||d===95||Ge(d)?(s=!0,e.consume(d),o):f(d)}function l(d){return e.consume(d),n=!0,o}function f(d){return s&&n&&ye(a.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(d)):r(d)}}function Ti(e,t,r){const a=this;return n;function n(i){return i!==87&&i!==119||!lr.call(a,a.previous)||Xe(a.events)?r(i):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(wi,e.attempt(nr,e.attempt(ir,s),r),r)(i))}function s(i){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(i)}}function ji(e,t,r){const a=this;let n="",s=!1;return i;function i(d){return(d===72||d===104)&&ur.call(a,a.previous)&&!Xe(a.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),n+=String.fromCodePoint(d),e.consume(d),c):r(d)}function c(d){if(ye(d)&&n.length<5)return n+=String.fromCodePoint(d),e.consume(d),c;if(d===58){const m=n.toLowerCase();if(m==="http"||m==="https")return e.consume(d),o}return r(d)}function o(d){return d===47?(e.consume(d),s?l:(s=!0,o)):r(d)}function l(d){return d===null||Aa(d)||V(d)||oe(d)||Ae(d)?r(d):e.attempt(nr,e.attempt(ir,f),r)(d)}function f(d){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(d)}}function Si(e,t,r){let a=0;return n;function n(i){return(i===87||i===119)&&a<3?(a++,e.consume(i),n):i===46&&a===3?(e.consume(i),s):r(i)}function s(i){return i===null?r(i):t(i)}}function Ii(e,t,r){let a,n,s;return i;function i(l){return l===46||l===95?e.check(sr,o,c)(l):l===null||V(l)||oe(l)||l!==45&&Ae(l)?o(l):(s=!0,e.consume(l),i)}function c(l){return l===95?a=!0:(n=a,a=void 0),e.consume(l),i}function o(l){return n||a||!s?r(l):t(l)}}function Mi(e,t){let r=0,a=0;return n;function n(i){return i===40?(r++,e.consume(i),n):i===41&&a<r?s(i):i===33||i===34||i===38||i===39||i===41||i===42||i===44||i===46||i===58||i===59||i===60||i===63||i===93||i===95||i===126?e.check(sr,t,s)(i):i===null||V(i)||oe(i)?t(i):(e.consume(i),n)}function s(i){return i===41&&a++,e.consume(i),n}}function Ai(e,t,r){return a;function a(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),a):c===38?(e.consume(c),s):c===93?(e.consume(c),n):c===60||c===null||V(c)||oe(c)?t(c):r(c)}function n(c){return c===null||c===40||c===91||V(c)||oe(c)?t(c):a(c)}function s(c){return ye(c)?i(c):r(c)}function i(c){return c===59?(e.consume(c),a):ye(c)?(e.consume(c),i):r(c)}}function Ni(e,t,r){return a;function a(s){return e.consume(s),n}function n(s){return Ge(s)?r(s):t(s)}}function lr(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||V(e)}function ur(e){return!ye(e)}function dr(e){return!(e===47||He(e))}function He(e){return e===43||e===45||e===46||e===95||Ge(e)}function Xe(e){let t=e.length,r=!1;for(;t--;){const a=e[t][1];if((a.type==="labelLink"||a.type==="labelImage")&&!a._balanced){r=!0;break}if(a._gfmAutolinkLiteralWalkedInto){r=!1;break}}return e.length>0&&!r&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),r}function _i(e,t,r){const a=[];let n=-1;for(;++n<e.length;){const s=e[n].resolveAll;s&&!a.includes(s)&&(t=s(t,r),a.push(s))}return t}function re(e,t,r,a){const n=a?a-1:Number.POSITIVE_INFINITY;let s=0;return i;function i(o){return te(o)?(e.enter(r),c(o)):t(o)}function c(o){return te(o)&&s++<n?(e.consume(o),c):(e.exit(r),t(o))}}const Pi={partial:!0,tokenize:Ei};function Ei(e,t,r){return a;function a(s){return te(s)?re(e,n,"linePrefix")(s):n(s)}function n(s){return s===null||he(s)?t(s):r(s)}}const Ri={tokenize:Bi,partial:!0};function Li(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:zi,continuation:{tokenize:$i},exit:Oi}},text:{91:{name:"gfmFootnoteCall",tokenize:Ui},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Di,resolveTo:Fi}}}}function Di(e,t,r){const a=this;let n=a.events.length;const s=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let i;for(;n--;){const o=a.events[n][1];if(o.type==="labelImage"){i=o;break}if(o.type==="gfmFootnoteCall"||o.type==="labelLink"||o.type==="label"||o.type==="image"||o.type==="link")break}return c;function c(o){if(!i||!i._balanced)return r(o);const l=we(a.sliceSerialize({start:i.end,end:a.now()}));return l.codePointAt(0)!==94||!s.includes(l.slice(1))?r(o):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(o),e.exit("gfmFootnoteCallLabelMarker"),t(o))}}function Fi(e,t){let r=e.length;for(;r--;)if(e[r][1].type==="labelImage"&&e[r][0]==="enter"){e[r][1];break}e[r+1][1].type="data",e[r+3][1].type="gfmFootnoteCallLabelMarker";const a={type:"gfmFootnoteCall",start:Object.assign({},e[r+3][1].start),end:Object.assign({},e[e.length-1][1].end)},n={type:"gfmFootnoteCallMarker",start:Object.assign({},e[r+3][1].end),end:Object.assign({},e[r+3][1].end)};n.end.column++,n.end.offset++,n.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},n.end),end:Object.assign({},e[e.length-1][1].start)},i={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},c=[e[r+1],e[r+2],["enter",a,t],e[r+3],e[r+4],["enter",n,t],["exit",n,t],["enter",s,t],["enter",i,t],["exit",i,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",a,t]];return e.splice(r,e.length-r+1,...c),e}function Ui(e,t,r){const a=this,n=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let s=0,i;return c;function c(d){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),o}function o(d){return d!==94?r(d):(e.enter("gfmFootnoteCallMarker"),e.consume(d),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",l)}function l(d){if(s>999||d===93&&!i||d===null||d===91||V(d))return r(d);if(d===93){e.exit("chunkString");const m=e.exit("gfmFootnoteCallString");return n.includes(we(a.sliceSerialize(m)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):r(d)}return V(d)||(i=!0),s++,e.consume(d),d===92?f:l}function f(d){return d===91||d===92||d===93?(e.consume(d),s++,l):l(d)}}function zi(e,t,r){const a=this,n=a.parser.gfmFootnotes||(a.parser.gfmFootnotes=[]);let s,i=0,c;return o;function o(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):r(h)}function f(h){if(i>999||h===93&&!c||h===null||h===91||V(h))return r(h);if(h===93){e.exit("chunkString");const w=e.exit("gfmFootnoteDefinitionLabelString");return s=we(a.sliceSerialize(w)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(h),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),m}return V(h)||(c=!0),i++,e.consume(h),h===92?d:f}function d(h){return h===91||h===92||h===93?(e.consume(h),i++,f):f(h)}function m(h){return h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),n.includes(s)||n.push(s),re(e,g,"gfmFootnoteDefinitionWhitespace")):r(h)}function g(h){return t(h)}}function $i(e,t,r){return e.check(Pi,t,e.attempt(Ri,t,r))}function Oi(e){e.exit("gfmFootnoteDefinition")}function Bi(e,t,r){const a=this;return re(e,n,"gfmFootnoteDefinitionIndent",5);function n(s){const i=a.events[a.events.length-1];return i&&i[1].type==="gfmFootnoteDefinitionIndent"&&i[2].sliceSerialize(i[1],!0).length===4?t(s):r(s)}}function qi(e){let r=(e||{}).singleTilde;const a={name:"strikethrough",tokenize:s,resolveAll:n};return r==null&&(r=!0),{text:{126:a},insideSpan:{null:[a]},attentionMarkers:{null:[126]}};function n(i,c){let o=-1;for(;++o<i.length;)if(i[o][0]==="enter"&&i[o][1].type==="strikethroughSequenceTemporary"&&i[o][1]._close){let l=o;for(;l--;)if(i[l][0]==="exit"&&i[l][1].type==="strikethroughSequenceTemporary"&&i[l][1]._open&&i[o][1].end.offset-i[o][1].start.offset===i[l][1].end.offset-i[l][1].start.offset){i[o][1].type="strikethroughSequence",i[l][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},i[l][1].start),end:Object.assign({},i[o][1].end)},d={type:"strikethroughText",start:Object.assign({},i[l][1].end),end:Object.assign({},i[o][1].start)},m=[["enter",f,c],["enter",i[l][1],c],["exit",i[l][1],c],["enter",d,c]],g=c.parser.constructs.insideSpan.null;g&&je(m,m.length,0,_i(g,i.slice(l+1,o),c)),je(m,m.length,0,[["exit",d,c],["enter",i[o][1],c],["exit",i[o][1],c],["exit",f,c]]),je(i,l-1,o-l+3,m),o=l+m.length-2;break}}for(o=-1;++o<i.length;)i[o][1].type==="strikethroughSequenceTemporary"&&(i[o][1].type="data");return i}function s(i,c,o){const l=this.previous,f=this.events;let d=0;return m;function m(h){return l===126&&f[f.length-1][1].type!=="characterEscape"?o(h):(i.enter("strikethroughSequenceTemporary"),g(h))}function g(h){const w=Ie(l);if(h===126)return d>1?o(h):(i.consume(h),d++,g);if(d<2&&!r)return o(h);const x=i.exit("strikethroughSequenceTemporary"),b=Ie(h);return x._open=!b||b===2&&!!w,x._close=!w||w===2&&!!b,c(h)}}}class Vi{constructor(){this.map=[]}add(t,r,a){Wi(this,t,r,a)}consume(t){if(this.map.sort(function(s,i){return s[0]-i[0]}),this.map.length===0)return;let r=this.map.length;const a=[];for(;r>0;)r-=1,a.push(t.slice(this.map[r][0]+this.map[r][1]),this.map[r][2]),t.length=this.map[r][0];a.push(t.slice()),t.length=0;let n=a.pop();for(;n;){for(const s of n)t.push(s);n=a.pop()}this.map.length=0}}function Wi(e,t,r,a){let n=0;if(!(r===0&&a.length===0)){for(;n<e.map.length;){if(e.map[n][0]===t){e.map[n][1]+=r,e.map[n][2].push(...a);return}n+=1}e.map.push([t,r,a])}}function Hi(e,t){let r=!1;const a=[];for(;t<e.length;){const n=e[t];if(r){if(n[0]==="enter")n[1].type==="tableContent"&&a.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(n[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=a.length-1;a[s]=a[s]==="left"?"center":"right"}}else if(n[1].type==="tableDelimiterRow")break}else n[0]==="enter"&&n[1].type==="tableDelimiterRow"&&(r=!0);t+=1}return a}function Ki(){return{flow:{null:{name:"table",tokenize:Qi,resolveAll:Gi}}}}function Qi(e,t,r){const a=this;let n=0,s=0,i;return c;function c(p){let L=a.events.length-1;for(;L>-1;){const K=a.events[L][1].type;if(K==="lineEnding"||K==="linePrefix")L--;else break}const W=L>-1?a.events[L][1].type:null,H=W==="tableHead"||W==="tableRow"?I:o;return H===I&&a.parser.lazy[a.now().line]?r(p):H(p)}function o(p){return e.enter("tableHead"),e.enter("tableRow"),l(p)}function l(p){return p===124||(i=!0,s+=1),f(p)}function f(p){return p===null?r(p):he(p)?s>1?(s=0,a.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),g):r(p):te(p)?re(e,f,"whitespace")(p):(s+=1,i&&(i=!1,n+=1),p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),i=!0,f):(e.enter("data"),d(p)))}function d(p){return p===null||p===124||V(p)?(e.exit("data"),f(p)):(e.consume(p),p===92?m:d)}function m(p){return p===92||p===124?(e.consume(p),d):d(p)}function g(p){return a.interrupt=!1,a.parser.lazy[a.now().line]?r(p):(e.enter("tableDelimiterRow"),i=!1,te(p)?re(e,h,"linePrefix",a.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(p):h(p))}function h(p){return p===45||p===58?x(p):p===124?(i=!0,e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),w):N(p)}function w(p){return te(p)?re(e,x,"whitespace")(p):x(p)}function x(p){return p===58?(s+=1,i=!0,e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),b):p===45?(s+=1,b(p)):p===null||he(p)?P(p):N(p)}function b(p){return p===45?(e.enter("tableDelimiterFiller"),C(p)):N(p)}function C(p){return p===45?(e.consume(p),C):p===58?(i=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(p),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(p))}function v(p){return te(p)?re(e,P,"whitespace")(p):P(p)}function P(p){return p===124?h(p):p===null||he(p)?!i||n!==s?N(p):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(p)):N(p)}function N(p){return r(p)}function I(p){return e.enter("tableRow"),q(p)}function q(p){return p===124?(e.enter("tableCellDivider"),e.consume(p),e.exit("tableCellDivider"),q):p===null||he(p)?(e.exit("tableRow"),t(p)):te(p)?re(e,q,"whitespace")(p):(e.enter("data"),M(p))}function M(p){return p===null||p===124||V(p)?(e.exit("data"),q(p)):(e.consume(p),p===92?U:M)}function U(p){return p===92||p===124?(e.consume(p),M):M(p)}}function Gi(e,t){let r=-1,a=!0,n=0,s=[0,0,0,0],i=[0,0,0,0],c=!1,o=0,l,f,d;const m=new Vi;for(;++r<e.length;){const g=e[r],h=g[1];g[0]==="enter"?h.type==="tableHead"?(c=!1,o!==0&&(Tt(m,t,o,l,f),f=void 0,o=0),l={type:"table",start:Object.assign({},h.start),end:Object.assign({},h.end)},m.add(r,0,[["enter",l,t]])):h.type==="tableRow"||h.type==="tableDelimiterRow"?(a=!0,d=void 0,s=[0,0,0,0],i=[0,r+1,0,0],c&&(c=!1,f={type:"tableBody",start:Object.assign({},h.start),end:Object.assign({},h.end)},m.add(r,0,[["enter",f,t]])),n=h.type==="tableDelimiterRow"?2:f?3:1):n&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")?(a=!1,i[2]===0&&(s[1]!==0&&(i[0]=i[1],d=ve(m,t,s,n,void 0,d),s=[0,0,0,0]),i[2]=r)):h.type==="tableCellDivider"&&(a?a=!1:(s[1]!==0&&(i[0]=i[1],d=ve(m,t,s,n,void 0,d)),s=i,i=[s[1],r,0,0])):h.type==="tableHead"?(c=!0,o=r):h.type==="tableRow"||h.type==="tableDelimiterRow"?(o=r,s[1]!==0?(i[0]=i[1],d=ve(m,t,s,n,r,d)):i[1]!==0&&(d=ve(m,t,i,n,r,d)),n=0):n&&(h.type==="data"||h.type==="tableDelimiterMarker"||h.type==="tableDelimiterFiller")&&(i[3]=r)}for(o!==0&&Tt(m,t,o,l,f),m.consume(t.events),r=-1;++r<t.events.length;){const g=t.events[r];g[0]==="enter"&&g[1].type==="table"&&(g[1]._align=Hi(t.events,r))}return e}function ve(e,t,r,a,n,s){const i=a===1?"tableHeader":a===2?"tableDelimiter":"tableData",c="tableContent";r[0]!==0&&(s.end=Object.assign({},ue(t.events,r[0])),e.add(r[0],0,[["exit",s,t]]));const o=ue(t.events,r[1]);if(s={type:i,start:Object.assign({},o),end:Object.assign({},o)},e.add(r[1],0,[["enter",s,t]]),r[2]!==0){const l=ue(t.events,r[2]),f=ue(t.events,r[3]),d={type:c,start:Object.assign({},l),end:Object.assign({},f)};if(e.add(r[2],0,[["enter",d,t]]),a!==2){const m=t.events[r[2]],g=t.events[r[3]];if(m[1].end=Object.assign({},g[1].end),m[1].type="chunkText",m[1].contentType="text",r[3]>r[2]+1){const h=r[2]+1,w=r[3]-r[2]-1;e.add(h,w,[])}}e.add(r[3]+1,0,[["exit",d,t]])}return n!==void 0&&(s.end=Object.assign({},ue(t.events,n)),e.add(n,0,[["exit",s,t]]),s=void 0),s}function Tt(e,t,r,a,n){const s=[],i=ue(t.events,r);n&&(n.end=Object.assign({},i),s.push(["exit",n,t])),a.end=Object.assign({},i),s.push(["exit",a,t]),e.add(r+1,0,s)}function ue(e,t){const r=e[t],a=r[0]==="enter"?"start":"end";return r[1][a]}const Yi={name:"tasklistCheck",tokenize:Xi};function Ji(){return{text:{91:Yi}}}function Xi(e,t,r){const a=this;return n;function n(o){return a.previous!==null||!a._gfmTasklistFirstContentOfListItem?r(o):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),s)}function s(o){return V(o)?(e.enter("taskListCheckValueUnchecked"),e.consume(o),e.exit("taskListCheckValueUnchecked"),i):o===88||o===120?(e.enter("taskListCheckValueChecked"),e.consume(o),e.exit("taskListCheckValueChecked"),i):r(o)}function i(o){return o===93?(e.enter("taskListCheckMarker"),e.consume(o),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),c):r(o)}function c(o){return he(o)?t(o):te(o)?e.check({tokenize:Zi},t,r)(o):r(o)}}function Zi(e,t,r){return re(e,a,"whitespace");function a(n){return n===null?r(n):t(n)}}function es(e){return xi([Ci(),Li(),qi(e),Ki(),Ji()])}const ts={};function rs(e){const t=this,r=e||ts,a=t.data(),n=a.micromarkExtensions||(a.micromarkExtensions=[]),s=a.fromMarkdownExtensions||(a.fromMarkdownExtensions=[]),i=a.toMarkdownExtensions||(a.toMarkdownExtensions=[]);n.push(es(r)),s.push(pi()),i.push(gi(r))}function $(...e){return e.filter(Boolean).join(" ")}const as=({content:e})=>u.jsx(qe.MarkdownTextPrimitive,{remarkPlugins:[rs],className:"cuadra-aui-md",components:ss,children:e}),Ze=y.memo(as),ns=({language:e,code:t})=>{const{isCopied:r,copyToClipboard:a}=is(),n=()=>{!t||r||a(t)};return u.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:[u.jsx("span",{className:"cuadra-lowercase [&>span]:cuadra-text-xs cuadra-font-brand",children:e}),u.jsxs("button",{onClick:n,className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-muted cuadra-transition-colors","aria-label":"Copy code",children:[!r&&u.jsx(Lr,{className:"cuadra-h-4 cuadra-w-4"}),r&&u.jsx(It,{className:"cuadra-h-4 cuadra-w-4"})]})]})},is=({copiedDuration:e=3e3}={})=>{const[t,r]=y.useState(!1);return{isCopied:t,copyToClipboard:n=>{n&&navigator.clipboard.writeText(n).then(()=>{r(!0),setTimeout(()=>r(!1),e)})}}},ss=qe.unstable_memoizeMarkdownComponents({h1:({className:e,...t})=>u.jsx("h1",{className:$("cuadra-mb-6 cuadra-scroll-m-20 cuadra-text-2xl cuadra-font-normal cuadra-tracking-tight last:cuadra-mb-0 font-brand",e),...t}),h2:({className:e,...t})=>u.jsx("h2",{className:$("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),...t}),h3:({className:e,...t})=>u.jsx("h3",{className:$("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),...t}),h4:({className:e,...t})=>u.jsx("h4",{className:$("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),...t}),h5:({className:e,...t})=>u.jsx("h5",{className:$("cuadra-my-4 cuadra-text-lg cuadra-font-normal first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...t}),h6:({className:e,...t})=>u.jsx("h6",{className:$("cuadra-my-4 cuadra-font-normal first:cuadra-mb-0 font-brand",e),...t}),p:({className:e,...t})=>u.jsx("p",{className:$("cuadra-mb-5 cuadra-mt-5 cuadra-leading-7 first:cuadra-mt-0 last:cuadra-mb-0 font-brand",e),...t}),a:({className:e,...t})=>u.jsx("a",{className:$("cuadra-text-primary cuadra-font-medium cuadra-underline cuadra-underline-offset-4 font-brand",e),...t}),blockquote:({className:e,...t})=>u.jsx("blockquote",{className:$("cuadra-border-l-2 cuadra-pl-6 cuadra-italic font-brand",e),...t}),ul:({className:e,...t})=>u.jsx("ul",{className:$("cuadra-my-5 cuadra-ml-6 cuadra-list-disc [&>li]:cuadra-mt-2 font-brand",e),...t}),ol:({className:e,...t})=>u.jsx("ol",{className:$("cuadra-my-5 cuadra-ml-6 cuadra-list-decimal [&>li]:cuadra-mt-2 font-brand",e),...t}),hr:({className:e,...t})=>u.jsx("hr",{className:$("cuadra-my-5 cuadra-border-b",e),...t}),table:({className:e,...t})=>u.jsx("table",{className:$("cuadra-my-5 cuadra-w-full cuadra-border-separate cuadra-border-spacing-0 cuadra-overflow-y-auto font-brand",e),...t}),th:({className:e,...t})=>u.jsx("th",{className:$("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),...t}),td:({className:e,...t})=>u.jsx("td",{className:$("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),...t}),tr:({className:e,...t})=>u.jsx("tr",{className:$("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),...t}),sup:({className:e,...t})=>u.jsx("sup",{className:$("[&>a]:cuadra-text-xs [&>a]:cuadra-no-underline font-brand",e),...t}),pre:({className:e,...t})=>u.jsx("pre",{className:$("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),...t}),code:function({className:t,...r}){const a=qe.useIsMarkdownCodeBlock();return u.jsx("code",{className:$(!a&&"cuadra-bg-muted cuadra-rounded cuadra-border cuadra-font-normal font-brand",t),...r})},CodeHeader:ns});function et({className:e="",variant:t="default",...r}){const a="cuadra-inline-flex cuadra-items-center cuadra-rounded-md cuadra-px-3 cuadra-py-1.5 cuadra-text-xs cuadra-font-medium font-brand",n={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 u.jsx("div",{className:`${a} ${n[t]||n.default} ${e}`,...r})}function os(e){const t=new Map;for(const r of e){const a=t.get(r.filename);(!a||r.score>a.score)&&t.set(r.filename,r)}return Array.from(t.values()).sort((r,a)=>a.score-r.score)}function hr({sources:e,maxVisible:t=3}){if(!e||e.length===0)return null;const r=os(e),a=r.slice(0,t),n=r.length-t;return u.jsxs("div",{className:"cuadra-mt-4 cuadra-pt-3 cuadra-border-t cuadra-border-border",children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5 cuadra-mb-2.5",children:[u.jsx(Mt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-text-xs cuadra-font-medium cuadra-text-muted-foreground font-brand",children:"Sources"})]}),u.jsxs("div",{className:"cuadra-flex cuadra-flex-wrap cuadra-gap-2",children:[a.map((s,i)=>u.jsx(ls,{source:s},s.sourceId||i)),n>0&&u.jsxs(et,{variant:"subtle",children:["+",n," more"]})]})]})}function cs(e){switch(e.split(".").pop()?.toLowerCase()){case"csv":case"xlsx":case"xls":return Ur;case"md":case"txt":return Or;default:return Mt}}function ls({source:e}){const{filename:t,score:r}=e,a=cs(t);return u.jsxs(et,{className:"cuadra-gap-2 cuadra-cursor-default",title:r<1?`${Math.round(r*100)}% relevant`:void 0,children:[u.jsx(a,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-opacity-60"}),u.jsx("span",{className:"cuadra-truncate cuadra-max-w-[180px]",children:t}),r<1&&r>0&&u.jsxs("span",{className:"cuadra-opacity-50 cuadra-text-[10px] cuadra-tabular-nums",children:[Math.round(r*100),"%"]})]})}const us=y.forwardRef(function({welcomeTitle:t="What shall we explore today?",welcomeSubtitle:r,extraTopPadding:a,suggestions:n,inputPlaceholder:s="Reply...",enableAttachments:i=!1,preMadeResponseDelay:c=1e3,streamingSpeed:o=50,safeArea:l=!1,composerBorder:f=!1,models:d,selectedModelId:m,onModelChange:g,showChatHeader:h=!1},w){const x=T.useThreadRuntime(),b=T.useAssistantApi(),[C,v]=y.useState(!1),[P,N]=y.useState(null),[I,q]=y.useState(!1),M=y.useSyncExternalStore(de.subscribe,de.getSnapshot);y.useEffect(()=>{if(M){const A=setTimeout(()=>de.clear(),4e3);return()=>clearTimeout(A)}},[M]);const U=T.useThread(A=>{const R=A.messages;return!R||R.length===0}),p=U&&!C,L=y.useCallback((A,R,k)=>{if(!I)try{const j=k?.streamingSpeed??o,_=k?.delay??c;Ft(A,R,j,_),b.composer().setText(A),setTimeout(()=>{b.composer().send()},10)}catch{}},[I,o,c,b]),W=y.useCallback(A=>{try{b.composer().setText(A),setTimeout(()=>{b.composer().send()},10)}catch{}},[b]),H=y.useCallback(async A=>{if(!(I||!x))try{if(A.response){const R=A.responseDelay??c;await L(A.prompt,A.response,{delay:R,streamingSpeed:o})}else W(A.prompt)}catch{}},[x,I,c,o,L,W]),K=y.useCallback(async()=>{try{const R=window.__cuadraThreadListRuntime?.threadList;R?.switchToNewThread&&await R.switchToNewThread()}catch{}},[]);return y.useImperativeHandle(w,()=>({sendMessage:W,sendPreMadeQA:L,clearChat:K}),[W,L,K]),y.useEffect(()=>{if(!x){v(!1);return}try{const A=x?.store;if(!A){v(!1);return}const R=A.subscribe?.(j=>{const _=j?.threadId,F=j?.messages||[],D=j?.isLoadingHistory||!1,S=F.length;_&&_!==P&&N(_),v(D&&S===0)}),k=A.getState?.();if(k){const j=k?.threadId,_=k?.messages||[],F=k?.isLoadingHistory||!1,D=_.length;j&&j!==P&&N(j),v(F&&D===0)}return()=>{R&&R()}}catch{v(!1)}},[x,P]),u.jsxs(T.ThreadPrimitive.Root,{className:"cuadra-bg-inherit cuadra-flex cuadra-flex-col cuadra-w-full cuadra-h-full cuadra-relative",children:[h&&u.jsx(xs,{}),u.jsxs(T.ComposerPrimitive.AttachmentDropzone,{disabled:!i,className:`cuadra-flex-1 cuadra-flex cuadra-flex-col cuadra-min-h-0 cuadra-relative ${p?"cuadra-justify-center":""}`,children:[u.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:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[u.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:u.jsx(Yr,{className:"cuadra-h-6 cuadra-w-6"})}),u.jsx("p",{className:"cuadra-text-sm cuadra-font-medium cuadra-text-foreground font-brand",children:"Drop files here"})]})}),u.jsx(T.ThreadPrimitive.Viewport,{className:`cuadra-w-full cuadra-bg-inherit cuadra-relative scrollbar-thin ${p?"cuadra-flex-none":"cuadra-flex-1 cuadra-min-h-0 cuadra-overflow-y-auto"}`,style:{paddingTop:p?"0":a||(h?"0.5rem":"2rem")},children:C?u.jsx("div",{className:"cuadra-absolute cuadra-inset-0 cuadra-flex cuadra-items-center cuadra-justify-center",children:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-3",children:[u.jsx(At,{className:"cuadra-h-5 cuadra-w-5 cuadra-animate-spin cuadra-text-muted-foreground"}),u.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground font-brand",children:"Loading messages..."})]})}):u.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full cuadra-px-4",children:[u.jsx(T.ThreadPrimitive.Empty,{children:u.jsx(ds,{title:t,subtitle:r})}),u.jsx(T.ThreadPrimitive.Messages,{components:{UserMessage:hs,AssistantMessage:ps}})]})}),u.jsx("div",{className:`cuadra-w-full cuadra-px-4 cuadra-pt-2 ${p?"cuadra-pb-2":"cuadra-pb-4"}`,style:l?{paddingBottom:"calc(env(safe-area-inset-bottom) + 1rem)"}:void 0,children:u.jsxs("div",{className:"cuadra-max-w-3xl cuadra-mx-auto cuadra-w-full",children:[M&&u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2 cuadra-mb-2 cuadra-px-3 cuadra-py-2 cuadra-rounded-lg cuadra-text-xs font-brand cuadra-animate-in cuadra-fade-in cuadra-slide-in-from-bottom-2",style:{backgroundColor:"var(--cuadra-muted)",color:"var(--cuadra-foreground)",opacity:.85},children:[u.jsx(Er,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-flex-shrink-0 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-flex-1 cuadra-text-muted-foreground",children:M.message}),u.jsx("button",{type:"button",onClick:()=>de.clear(),className:"cuadra-flex-shrink-0 cuadra-p-0.5 cuadra-rounded hover:cuadra-bg-black/5 cuadra-transition-colors","aria-label":"Dismiss",children:u.jsx(ut,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})]}),i&&u.jsx(T.ComposerPrimitive.Attachments,{components:{Attachment:()=>{const A=T.useAssistantState(({attachment:R})=>R);return A?u.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:[u.jsx(Nt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground",strokeWidth:1.5}),u.jsx("span",{className:"cuadra-text-xs cuadra-text-foreground font-brand",children:A.name||"Attachment"}),u.jsx(T.AttachmentPrimitive.Remove,{asChild:!0,children:u.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:u.jsx(ut,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})})})]}):null}}}),u.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:f?"1px solid hsl(var(--cuadra-border))":"none"},children:[u.jsx(T.ComposerPrimitive.Input,{asChild:!0,children:u.jsx("textarea",{rows:1,placeholder:s,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"}})}),u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-between cuadra-px-3 cuadra-pb-2.5 cuadra-pt-1",children:[u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:i&&u.jsx(T.ComposerPrimitive.AddAttachment,{multiple:!0,asChild:!0,children:u.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:[u.jsx(_t,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground",strokeWidth:1.5}),u.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"})]})})}),u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-2",children:[d&&d.length>0&&u.jsx(gs,{models:d,selectedModelId:m,onModelChange:g,threadIsEmpty:U,onNewChat:K}),u.jsx(T.ComposerPrimitive.Send,{asChild:!0,children:u.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:u.jsx(Mr,{className:"cuadra-h-4 cuadra-w-4",strokeWidth:2})})})]})]})]})]})}),p&&n&&n.length>0&&u.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,R)=>u.jsx("button",{type:"button",onClick:()=>H(A),disabled:I,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-${R}`))})]})]})});function ds({title:e,subtitle:t}){return u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-text-center cuadra-py-6",children:[u.jsx("h2",{className:"cuadra-text-4xl cuadra-font-normal cuadra-text-foreground/80 cuadra-tracking-tight",style:{fontFamily:"var(--cuadra-font-logo), Outfit, -apple-system, sans-serif"},children:e}),t&&u.jsx("p",{className:"cuadra-text-base cuadra-text-muted-foreground cuadra-mt-3 cuadra-max-w-lg cuadra-whitespace-pre-line",children:t})]})}function hs(){return u.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-end cuadra-py-2.5",children:u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-end cuadra-gap-2 cuadra-max-w-[80%]",children:[u.jsx(T.MessagePrimitive.Attachments,{components:{Attachment:()=>{const e=T.useAssistantState(({attachment:s})=>s);if(!e)return null;const t=e.type==="image",r=e.file,a=e.content?.find(s=>s.type==="image"),n=r?URL.createObjectURL(r):a?.image;return u.jsx("div",{className:"cuadra-mb-1",children:t&&n?u.jsx("img",{src:n,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)"}}):u.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:[u.jsx(Nt,{className:"cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground"}),u.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground font-brand",children:e.name||"Attachment"})]})})}}}),u.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:u.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:e})=>u.jsx(Ze,{content:e||""})}})})]})})}function fs({text:e}){const[t,r]=y.useState(!1),a=T.useAssistantState(({message:n})=>n?.status?.type==="running");return e?a?u.jsx("div",{className:"cuadra-mb-3 cuadra-py-1",children:u.jsx("div",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand cuadra-animate-text-shimmer",children:e})}):u.jsxs("div",{className:"cuadra-mb-3",children:[u.jsxs("button",{type:"button",onClick:()=>r(!t),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:[u.jsx(Ke,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-shrink-0 cuadra-transition-transform cuadra-duration-200 ${t?"":"cuadra--rotate-90"}`}),u.jsx("span",{children:"Reasoning"})]}),u.jsx("div",{className:`cuadra-overflow-hidden cuadra-transition-all cuadra-duration-200 cuadra-ease-out ${t?"cuadra-max-h-[2000px] cuadra-opacity-100":"cuadra-max-h-0 cuadra-opacity-0"}`,children:u.jsx("div",{className:"cuadra-pl-5 cuadra-pt-2 cuadra-text-sm cuadra-text-muted-foreground cuadra-leading-relaxed font-brand",children:u.jsx(Ze,{content:e})})})]}):null}function ms(){return u.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:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1",children:[u.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}}),u.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}}),u.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}})]}),u.jsx("span",{children:"Thinking..."})]})}function ps(){const e=T.useAssistantState(({message:i})=>i?.status?.type==="running"),t=T.useAssistantState(({message:i})=>{const c=i?.content;return!c||!Array.isArray(c)?!1:c.some(o=>!!(o.type==="text"&&o.text&&o.text.length>0||o.type==="reasoning"&&o.text&&o.text.length>0))}),r=y.useRef(!1),[a,n]=y.useState(null);y.useEffect(()=>{if(e&&t&&!r.current){const i=ee.getCurrentMessageId();i&&(r.current=!0,n(i))}},[e,t]);const s=y.useSyncExternalStore(i=>ee.subscribe(i),()=>{if(a){const i=ee.getForMessage(a);return i.sources?.length?i.sources:null}if(e&&t){const i=ee.getCurrentMessageId();if(i){const c=ee.getForMessage(i);return c.sources?.length?c.sources:null}}return null},()=>null);return u.jsx(T.MessagePrimitive.Root,{className:"cuadra-flex cuadra-w-full cuadra-justify-start cuadra-py-2.5",children:u.jsxs("div",{className:"cuadra-text-foreground cuadra-max-w-full cuadra-break-words font-brand",style:{fontSize:"0.9375rem",lineHeight:"1.75"},children:[u.jsx(T.MessagePrimitive.Parts,{components:{Text:({text:i})=>u.jsx(Ze,{content:i||""}),Reasoning:({text:i})=>u.jsx(fs,{text:i||""})}}),e&&!t&&u.jsx(ms,{}),s&&s.length>0&&u.jsx(hr,{sources:s})]})})}function Te({label:e,children:t}){return u.jsxs("span",{className:"cuadra-relative cuadra-inline-flex cuadra-group/tip",children:[t,u.jsx("span",{className:"cuadra-absolute cuadra-bottom-full cuadra-left-1/2 cuadra-mb-1.5 cuadra-hidden group-hover/tip:cuadra-flex cuadra-items-center cuadra-whitespace-nowrap cuadra-rounded-md cuadra-px-2 cuadra-py-1 cuadra-text-[10px] cuadra-pointer-events-none cuadra-z-50 font-brand",style:{backgroundColor:"var(--cuadra-popover)",color:"var(--cuadra-foreground)",boxShadow:"0 2px 8px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04)",transform:"translateX(-50%)"},children:e})]})}function gs({models:e,selectedModelId:t,onModelChange:r,threadIsEmpty:a,onNewChat:n}){const[s,i]=y.useState(!1),c=e.find(l=>l.id===t)||e[0];if(!c)return null;const o=async l=>{i(!1),!a&&l!==t&&await n?.(),r?.(l)};return u.jsxs("div",{className:"cuadra-relative",children:[u.jsxs("button",{type:"button",onClick:()=>i(!s),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:[u.jsx("span",{children:c.name}),c.supportsReasoning&&u.jsx(Te,{label:"Reasoning",children:u.jsx(ct,{className:"cuadra-h-3 cuadra-w-3"})}),c.supportsVision&&u.jsx(Te,{label:"Vision",children:u.jsx(lt,{className:"cuadra-h-3 cuadra-w-3"})}),u.jsx(Ke,{className:"cuadra-h-3 cuadra-w-3"})]}),s&&u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:()=>i(!1)}),u.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-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=>u.jsxs("button",{type:"button",className:"cuadra-w-full cuadra-flex cuadra-items-center cuadra-justify-between cuadra-gap-3 cuadra-px-3 cuadra-py-2 cuadra-text-sm cuadra-text-left hover:cuadra-bg-muted/60 cuadra-transition-colors font-brand",onClick:()=>o(l.id),children:[u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-min-w-0",children:[u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-1.5",children:[u.jsx("span",{className:"cuadra-text-foreground cuadra-truncate",children:l.name}),l.supportsReasoning&&u.jsx(Te,{label:"Reasoning",children:u.jsx(ct,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground cuadra-flex-shrink-0"})}),l.supportsVision&&u.jsx(Te,{label:"Vision",children:u.jsx(lt,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground cuadra-flex-shrink-0"})})]}),l.description&&u.jsx("span",{className:"cuadra-text-xs cuadra-text-muted-foreground",children:l.description})]}),l.id===t&&u.jsx(It,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-primary cuadra-flex-shrink-0"})]},l.id))})]})]})}function xs(){const e=T.useAssistantState(({threadListItem:n})=>n?.title??null),[t,r]=y.useState(!1),a=e||"Untitled chat";return u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-px-3 cuadra-py-2 cuadra-min-h-[48px]",children:u.jsxs("div",{className:"cuadra-relative",children:[u.jsxs("button",{type:"button",onClick:()=>r(!t),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:[u.jsx("span",{className:"cuadra-font-medium cuadra-truncate cuadra-max-w-[200px]",children:a}),u.jsx(Ke,{className:`cuadra-h-3.5 cuadra-w-3.5 cuadra-text-muted-foreground cuadra-flex-shrink-0 cuadra-transition-transform cuadra-duration-200 ${t?"cuadra-rotate-180":""}`})]}),t&&u.jsx(ys,{onClose:()=>r(!1)})]})})}function ys({onClose:e}){return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-fixed cuadra-inset-0 cuadra-z-40",onClick:e}),u.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:u.jsxs(T.ThreadListPrimitive.Root,{className:"cuadra-flex cuadra-flex-col",children:[u.jsx("div",{className:"cuadra-px-2 cuadra-py-1.5",children:u.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:[u.jsx(_t,{className:"cuadra-h-4 cuadra-w-4 cuadra-text-muted-foreground"}),"New Chat"]})}),u.jsx(bs,{onSelect:e})]})})]})}function bs({onSelect:e}){const t=T.useAssistantState(({threads:n})=>n?.threadIds??[]),r=T.useAssistantState(({threads:n})=>n?.newThreadId);return t.some(n=>n!==r)?u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"cuadra-mx-3 cuadra-my-0.5",style:{borderTop:"1px solid rgba(0,0,0,0.06)"}}),u.jsx("div",{className:"cuadra-overflow-y-auto cuadra-px-2 cuadra-pb-1.5 scrollbar-thin",style:{maxHeight:"340px"},children:u.jsx(T.ThreadListPrimitive.Items,{components:{ThreadListItem:n=>u.jsx(ws,{...n,onSelect:e})}})})]}):null}function ws({onSelect:e}){const t=T.useThreadListItem(),r=T.useThreadListItemRuntime(),a=T.useAssistantRuntime(),n=T.useThread(x=>x.threadId),s=t?.id===n,[i,c]=y.useState(!1),[o,l]=y.useState(!1),[f,d]=y.useState(t?.title||""),[m,g]=y.useState(!1),h=async()=>{if(!t?.remoteId||!f||f===t.title){l(!1);return}try{g(!0),await r.rename(f)}catch{}finally{g(!1),l(!1)}},w=async x=>{x.stopPropagation();try{await r.delete(),s&&await a.switchToNewThread()}catch(b){console.error("[CuadraChat] Failed to delete thread:",b)}};return y.useEffect(()=>{t?.title&&!o&&d(t.title)},[t?.title,o]),t?u.jsxs(T.ThreadListItemPrimitive.Root,{className:`cuadra-relative cuadra-flex cuadra-items-center cuadra-rounded-lg cuadra-transition-colors cuadra-cursor-pointer ${s?"cuadra-bg-muted":"hover:cuadra-bg-muted/60"}`,onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[o?u.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:u.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=>d(x.target.value),onKeyDown:x=>{x.stopPropagation(),x.key==="Enter"&&h(),x.key==="Escape"&&(l(!1),d(t.title||""))},onBlur:()=>void h(),disabled:m,autoFocus:!0})}):u.jsx(T.ThreadListItemPrimitive.Trigger,{className:"cuadra-flex-1 cuadra-px-3 cuadra-py-2 cuadra-min-w-0 cuadra-cursor-pointer",onClick:()=>e?.(),children:u.jsx("span",{className:"cuadra-text-sm cuadra-text-foreground cuadra-truncate cuadra-block cuadra-text-left font-brand",children:t.title||"Chat"})}),(i||s)&&!o&&u.jsxs("div",{className:"cuadra-flex cuadra-items-center cuadra-gap-0.5 cuadra-mr-1.5 cuadra-flex-shrink-0",children:[u.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-background/60 cuadra-transition-colors",onClick:x=>{x.stopPropagation(),l(!0),d(t.title||"Chat")},title:"Rename",children:u.jsx(Wr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-muted-foreground"})}),u.jsx("button",{type:"button",className:"cuadra-p-1 cuadra-rounded hover:cuadra-bg-destructive/10 cuadra-transition-colors",onClick:w,title:"Delete",children:u.jsx(Qr,{className:"cuadra-h-3 cuadra-w-3 cuadra-text-destructive"})})]})]}):null}const Oe=({children:e,className:t="",paddingX:r="px-0",paddingY:a="py-0",borderSizePx:n=2,style:s,contentStyle:i})=>u.jsx("div",{className:`cuadra-relative cuadra-bg-background md:cuadra-rounded-lg cuadra-overflow-hidden cuadra-flex cuadra-flex-col ${r} ${a} ${t}`,style:{border:n>0?`${n}px solid var(--cuadra-primary)`:"none",...s,...i},children:e}),ks=y.createContext(void 0),Be=({children:e,value:t})=>u.jsx(ks.Provider,{value:t,children:e});function Cs(){y.useEffect(()=>{if(document.querySelector("style[data-cuadra-uikit]"))return;const t=document.createElement("div");t.className="cuadra-flex",document.body.appendChild(t);const r=window.getComputedStyle(t).display==="flex";if(document.body.removeChild(t),r)return;const a=document.createElement("link");a.setAttribute("data-cuadra-uikit","true"),a.rel="stylesheet",a.type="text/css";const n=["/node_modules/@cuadra-ai/uikit/dist/uikit.css",new URL("../dist/uikit.css",typeof document>"u"?require("url").pathToFileURL(__filename).href:fe&&fe.tagName.toUpperCase()==="SCRIPT"&&fe.src||new URL("index.cjs",document.baseURI).href).href];let s=!1;for(const i of n)if(a.href=i,a.onload=()=>{s=!0},a.onerror=()=>{},document.head.appendChild(a),s)break},[])}const vs=y.forwardRef(function({config:t},r){Cs();const a=y.useRef(null),n=y.useRef(!1),{baseUrl:s,proxyUrl:i,sessionToken:c,mode:o="multiChat",modelMode:l="fixed",modelId:f,onModelChange:d,ephemeral:m=!1,systemPrompt:g,enableReasoning:h=!1,initialThreadId:w,welcomeTitle:x,welcomeSubtitle:b,extraTopPadding:C,suggestions:v,inputPlaceholder:P,preMadeResponseDelay:N=1e3,streamingSpeed:I=50,initialMessage:q,initialPreMadeQA:M,theme:U="system",onError:p,onChatCreated:L,onUserMessage:W,onThreadIdUpdate:H,enableAttachments:K=!1,supportsVision:A,onBeforeRequest:R,mockResponseOnBlocked:k}=t;y.useImperativeHandle(r,()=>({sendMessage:E=>{a.current?.sendMessage(E)},sendPreMadeQA:(E,Z,ie)=>{a.current?.sendPreMadeQA(E,Z,ie)},clearChat:()=>{a.current?.clearChat()}}),[]),y.useEffect(()=>{if(n.current)return;const E=setTimeout(()=>{M?(n.current=!0,a.current?.sendPreMadeQA(M.question,M.answer,{delay:N,streamingSpeed:I})):q&&(n.current=!0,a.current?.sendMessage(q))},500);return()=>clearTimeout(E)},[q,M,N,I]);const j=i||s||"",_=!!i,F=y.useMemo(()=>new Et(j,c||void 0,_),[j,c,_]),[D,S]=y.useState(null),[O,Y]=y.useState(!1),[J,ge]=y.useState(null),[Ee,X]=y.useState(!1);y.useEffect(()=>{o==="multiChat"&&X(!0)},[o]);const ne=y.useCallback(async()=>{if(l==="selector"){Y(!0),ge(null);try{const E=await F.listModels();S(E)}catch(E){ge(E instanceof Error?E:new Error("Failed to load models"))}finally{Y(!1)}}},[F,l]);y.useEffect(()=>{l==="selector"&&ne()},[l,ne]),y.useEffect(()=>(typeof window<"u"&&(window.__cuadraUIKitRefetchModels=ne),()=>{typeof window<"u"&&delete window.__cuadraUIKitRefetchModels}),[ne]);const[Q,rt]=y.useState(l==="fixed"&&f||null),at=y.useRef(Q),ke=y.useCallback(E=>{const Z=at.current;rt(E),at.current=E,d?.(E),Z!==null&&Z!==E&&o==="multiChat"&&setTimeout(()=>{const ie=window.__cuadraThreadListRuntime;if(ie?.threads?.switchToNewThread)try{ie.threads.switchToNewThread()}catch{}else if(ie?.threads?.createThread)try{ie.threads.createThread()}catch{}else if(ie?.switchToNewThread)try{ie.switchToNewThread()}catch{}},100)},[d,o]);y.useEffect(()=>{if(l==="selector"&&D?.items&&D.items.length>0&&!Q){const E=D.items[0];if(E?.id){const Z=E.id;rt(Z),d?.(Z)}}},[l,D?.items,Q,d]);const xr=l==="fixed"?!!f:!!Q,yr=y.useMemo(()=>A!==void 0?A:l==="selector"&&Q&&D?.items?D.items.find(Z=>Z.id===Q)?.supportsVision??!0:!0,[A,l,Q,D?.items]),Re=y.useMemo(()=>(D?.items||[]).filter(E=>E?.id&&E?.displayName).map(E=>({id:E.id,name:E.displayName,supportsVision:E.supportsVision??!1,supportsReasoning:E.supportsReasoning??!1})),[D]),Le=y.useMemo(()=>({currentModelId:Q||"",models:Re,modelsLoading:O,modelsError:J,onModelChange:ke,refetchModels:ne}),[Q,Re,O,J,ke,ne]);return l==="selector"&&O||o==="multiChat"&&Ee?u.jsx(Be,{value:Le,children:u.jsx(Oe,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",borderSizePx:t.borderless?0:2,children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx(At,{className:"cuadra-h-6 cuadra-w-6 cuadra-animate-spin cuadra-text-muted-foreground"})})})}):l==="selector"&&!xr&&J?u.jsx(Be,{value:Le,children:u.jsx(Oe,{className:"cuadra-h-full",paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",children:u.jsx("div",{className:"cuadra-flex cuadra-items-center cuadra-justify-center cuadra-h-full",children:u.jsx("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-gap-2",children:u.jsx("p",{className:"cuadra-text-sm cuadra-text-destructive font-brand",children:"Failed to load models"})})})})}):u.jsx("div",{className:"cuadra-uikit cuadra-h-full cuadra-w-full",style:{height:"100%",width:"100%"},children:u.jsx(Be,{value:Le,children:u.jsx(Sa,{baseUrl:_?j:s||j,sessionToken:c,isProxyMode:_,mode:o,modelMode:l,modelId:Q||f||void 0,onModelChange:ke,ephemeral:m,systemPrompt:g,enableReasoning:h,initialThreadId:w,enableAttachments:K,supportsVision:yr,onError:p,onChatCreated:L,onUserMessage:W,onThreadIdUpdate:H,onBeforeRequest:R,mockResponseOnBlocked:k,onChatsLoaded:()=>{o==="multiChat"&&X(!1)},children:u.jsx(Oe,{paddingX:"cuadra-px-0",paddingY:"cuadra-py-0",className:`cuadra-h-full ${t.containerClass||""}`,borderSizePx:t.borderless?0:2,style:{height:"100%"},children:u.jsx("div",{className:"cuadra-h-full cuadra-flex cuadra-relative",style:{height:"100%"},children:u.jsx("div",{className:"cuadra-flex-1 cuadra-flex cuadra-flex-col",children:u.jsx("div",{className:"cuadra-flex-1 cuadra-relative cuadra-min-h-0",children:u.jsx(us,{ref:a,welcomeTitle:x,welcomeSubtitle:b,extraTopPadding:C,suggestions:v,inputPlaceholder:P,enableAttachments:K,preMadeResponseDelay:N,streamingSpeed:I,safeArea:t.safeArea,showChatHeader:o==="multiChat",models:l==="selector"?Re:void 0,selectedModelId:Q||void 0,onModelChange:l==="selector"?ke:void 0,theme:U})})})})})})})})});function fr(e,t=":root"){if(typeof document>"u")return;const r=document.documentElement,a=[];if(e.light){js(e.light,r);const n=jt(e.light);n&&a.push(`.cuadra-uikit { ${n} }`)}if(e.dark){const n=jt(e.dark);n&&(a.push(`.dark { ${n} }`),a.push(`.dark .cuadra-uikit { ${n} }`))}if(a.length>0){let n=document.getElementById("cuadra-theme-custom");n||(n=document.createElement("style"),n.id="cuadra-theme-custom",document.head.appendChild(n)),n.textContent=a.join(`
21
21
  `)}}const Ts={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 mr(e){const t=Ts[e];return t?`--cuadra-${t}`:`--cuadra-${e.replace(/([A-Z])/g,"-$1").toLowerCase()}`}function js(e,t){Object.entries(e).forEach(([r,a])=>{if(a){const n=mr(r);t.style.setProperty(n,a)}})}function jt(e){return Object.entries(e).map(([t,r])=>r?`${mr(t)}: ${r};`:"").filter(Boolean).join(" ")}function Ss(){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 r=document.getElementById("cuadra-theme-custom");r&&r.remove();const a=document.getElementById("cuadra-theme-dark");a&&a.remove()}function Is({onReset:e,error:t}){return u.jsxs("div",{className:"cuadra-flex cuadra-flex-col cuadra-items-center cuadra-justify-center cuadra-h-full cuadra-p-6 cuadra-text-center",children:[u.jsx("div",{className:"cuadra-mb-4",children:u.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:u.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"})})}),u.jsx("h3",{className:"cuadra-text-lg cuadra-font-medium cuadra-text-foreground cuadra-mb-2",children:"Something went wrong"}),u.jsx("p",{className:"cuadra-text-sm cuadra-text-muted-foreground cuadra-mb-4 cuadra-max-w-sm",children:t?.message||"An unexpected error occurred. Please try again."}),u.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 tt extends y.Component{constructor(r){super(r);z(this,"reset",()=>{this.setState({hasError:!1,error:null})});this.state={hasError:!1,error:null}}static getDerivedStateFromError(r){return{hasError:!0,error:r}}componentDidCatch(r,a){this.props.onError?.(r,a)}render(){if(this.state.hasError){const{fallback:r}=this.props,{error:a}=this.state;return typeof r=="function"?r(a,this.reset):r||u.jsx(Is,{error:a,onReset:this.reset})}return this.props.children}}function Ms(e,t){const r=a=>u.jsx(tt,{...t,children:u.jsx(e,{...a})});return r.displayName=`withErrorBoundary(${e.displayName||e.name||"Component"})`,r}const pe=y.createContext(null);pe.displayName="CuadraChatContext";function As(){const e=y.useContext(pe);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 Ns(){const e=y.useContext(pe);return e===null?null:{controls:e.controls,isReady:e.controls!==null}}function _s({children:e}){const[t,r]=y.useState(null),a=y.useCallback(i=>{r(i)},[]),n=y.useCallback(()=>{r(null)},[]),s=y.useMemo(()=>({controls:t,registerControls:a,unregisterControls:n}),[t,a,n]);return u.jsx(pe.Provider,{value:s,children:e})}function pr(e){return"connection"in e&&typeof e.connection=="object"}function gr(e){return pr(e)?Ps(e):Es(e)}function Ps(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,supportsVision:e.chat?.supportsVision,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 Es(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.
22
22
  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,supportsVision:e.supportsVision,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 Rs=y.forwardRef(function({config:t},r){const a=y.useRef(null),n=y.useContext(pe);y.useEffect(()=>{t.ui.customTheme&&fr(t.ui.customTheme)},[t.ui.customTheme]),y.useEffect(()=>{if(t.ui.primaryColor&&typeof document<"u"){const c=document.documentElement,o=l=>{const f=l.replace("#",""),d=parseInt(f.slice(0,2),16)/255,m=parseInt(f.slice(2,4),16)/255,g=parseInt(f.slice(4,6),16)/255,h=Math.max(d,m,g),w=Math.min(d,m,g);let x=0,b=0;const C=(h+w)/2;if(h!==w){const v=h-w;switch(b=C>.5?v/(2-h-w):v/(h+w),h){case d:x=((m-g)/v+(m<g?6:0))/6;break;case m:x=((g-d)/v+2)/6;break;case g:x=((d-m)/v+4)/6;break}}return`${Math.round(x*360)} ${Math.round(b*100)}% ${Math.round(C*100)}%`};try{const l=o(t.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")}}},[t.ui.primaryColor]);const s=y.useMemo(()=>({sendMessage:c=>a.current?.sendMessage(c),sendPreMadeQA:(c,o,l)=>a.current?.sendPreMadeQA(c,o,l),clearChat:()=>a.current?.clearChat()}),[]);y.useImperativeHandle(r,()=>s,[]),y.useEffect(()=>{if(n)return n.registerControls(s),()=>n.unregisterControls()},[n,s]),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=s),()=>{typeof window<"u"&&delete window.__cuadraChatControls}),[s]);const i={baseUrl:t.connection.baseUrl||void 0,proxyUrl:t.connection.proxyUrl||void 0,sessionToken:t.connection.sessionToken,mode:t.chat.mode,modelMode:t.chat.modelMode,modelId:t.chat.modelId||void 0,systemPrompt:t.chat.systemPrompt||void 0,ephemeral:t.chat.ephemeral,enableReasoning:t.chat.enableReasoning,enableAttachments:t.chat.enableAttachments,supportsVision:t.chat.supportsVision,initialThreadId:t.chat.initialThreadId,theme:t.ui.theme,showThemeToggle:t.ui.showThemeToggle,language:t.ui.language,welcomeTitle:t.ui.welcomeTitle,welcomeSubtitle:t.ui.welcomeSubtitle,suggestions:t.ui.suggestions,inputPlaceholder:t.ui.inputPlaceholder,extraTopPadding:t.ui.extraTopPadding,containerClass:t.className,borderless:t.ui.borderless,safeArea:t.ui.safeArea,orgName:t.ui.orgName,primaryColor:t.ui.primaryColor,preMadeResponseDelay:t.preMade.responseDelay,streamingSpeed:t.preMade.streamingSpeed,initialMessage:t.initial.message,initialPreMadeQA:t.initial.preMadeQA,onBeforeRequest:t.interceptors.onBeforeRequest,mockResponseOnBlocked:t.interceptors.mockResponseOnBlocked,onChatCreated:t.callbacks.onChatCreated,onError:t.callbacks.onError,onUserMessage:t.callbacks.onUserMessage,onModelChange:t.callbacks.onModelChange,onThreadIdUpdate:t.callbacks.onThreadIdUpdate,onLogout:t.callbacks.onLogout};return u.jsx(vs,{ref:a,config:i})}),Ls=y.forwardRef(function(t,r){const a=gr(t),n=a.errorFallback;return u.jsx(tt,{fallback:n,onError:(s,i)=>{a.callbacks.onError?.(s),process.env.NODE_ENV==="development"&&console.error("[CuadraChat] Error caught by boundary:",s,i)},children:u.jsx(Rs,{ref:r,config:a})})});exports.AttachmentValidationError=le;exports.Badge=et;exports.CuadraChat=Ls;exports.CuadraChatContext=pe;exports.CuadraChatProvider=_s;exports.CuadraErrorBoundary=tt;exports.SourceCitations=hr;exports.applyTheme=fr;exports.createAttachmentAdapter=Qe;exports.escapeHtml=aa;exports.generateSecureUUID=Pt;exports.isV2Props=pr;exports.isValidUrl=ea;exports.normalizeCuadraChatProps=gr;exports.removeTheme=Ss;exports.sanitizeSystemPrompt=Zr;exports.streamingMetadataStore=ee;exports.useCuadraChat=As;exports.useCuadraChatOptional=Ns;exports.validateBaseUrl=ta;exports.withErrorBoundary=Ms;
23
23
  //# sourceMappingURL=index.cjs.map