@waniwani/sdk 0.12.14-beta.0 → 0.12.14-beta.1

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.
@@ -118,7 +118,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error
118
118
  `)},My=e=>{let t=!1;for(let r of e)if(r==="\\"||r==="|"){t=!0;break}if(!t)return e;let a=[];for(let r of e)r==="\\"?a.push("\\\\"):r==="|"?a.push("\\|"):a.push(r);return a.join("")},Oq=e=>{let{headers:t,rows:a}=e;if(t.length===0)return"";let r=new Array(a.length+2),n=0,o=t.map(i=>My(i));r[n]=`| ${o.join(" | ")} |`,n+=1;let l=new Array(t.length);for(let i=0;i<t.length;i+=1)l[i]="---";r[n]=`| ${l.join(" | ")} |`,n+=1;for(let i of a)if(i.length<t.length){let s=new Array(t.length);for(let u=0;u<t.length;u+=1)s[u]=u<i.length?My(i[u]):"";r[n]=`| ${s.join(" | ")} |`,n+=1}else{let s=i.map(u=>My(u));r[n]=`| ${s.join(" | ")} |`,n+=1}return r.join(`
119
119
  `)},Pq=({children:e,className:t,onCopy:a,onError:r,timeout:n=2e3})=>{let[o,l]=(0,R.useState)(!1),[i,s]=(0,R.useState)(!1),u=(0,R.useRef)(null),c=(0,R.useRef)(0),{isAnimating:d}=(0,R.useContext)(Yt),f=async g=>{var v,C;if(typeof window>"u"||!((v=navigator?.clipboard)!=null&&v.write)){r?.(new Error("Clipboard API not available"));return}try{let y=(C=u.current)==null?void 0:C.closest('[data-streamdown="table-wrapper"]'),x=y?.querySelector("table");if(!x){r?.(new Error("Table not found"));return}let h=VM(x),w=g==="csv"?GM(h):_q(h),M=new ClipboardItem({"text/plain":new Blob([w],{type:"text/plain"}),"text/html":new Blob([x.outerHTML],{type:"text/html"})});await navigator.clipboard.write([M]),s(!0),l(!1),a?.(g),c.current=window.setTimeout(()=>s(!1),n)}catch(y){r?.(y)}};(0,R.useEffect)(()=>{let g=v=>{let C=v.composedPath();u.current&&!C.includes(u.current)&&l(!1)};return document.addEventListener("mousedown",g),()=>{document.removeEventListener("mousedown",g),window.clearTimeout(c.current)}},[]);let p=i?_y:Oy;return(0,T.jsxs)("div",{className:"relative",ref:u,children:[(0,T.jsx)("button",{className:J("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>l(!o),title:"Copy table",type:"button",children:e??(0,T.jsx)(p,{size:14})}),o?(0,T.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>f("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>f("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})},Nq=({children:e,className:t,onDownload:a,onError:r})=>{let[n,o]=(0,R.useState)(!1),l=(0,R.useRef)(null),{isAnimating:i}=(0,R.useContext)(Yt),s=u=>{var c;try{let d=(c=l.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),f=d?.querySelector("table");if(!f){r?.(new Error("Table not found"));return}let p=VM(f),g=u==="csv"?GM(p):Oq(p);Bl(`table.${u==="csv"?"csv":"md"}`,g,u==="csv"?"text/csv":"text/markdown"),o(!1),a?.(u)}catch(d){r?.(d)}};return(0,R.useEffect)(()=>{let u=c=>{let d=c.composedPath();l.current&&!d.includes(l.current)&&o(!1)};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u)}},[]),(0,T.jsxs)("div",{className:"relative",ref:l,children:[(0,T.jsx)("button",{className:J("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>o(!n),title:"Download table",type:"button",children:e??(0,T.jsx)(jd,{size:14})}),n?(0,T.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>s("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>s("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})},Bq=({children:e,className:t,showControls:a,...r})=>(0,T.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[a?(0,T.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,T.jsx)(Pq,{}),(0,T.jsx)(Nq,{})]}):null,(0,T.jsx)("div",{className:"overflow-x-auto",children:(0,T.jsx)("table",{className:J("w-full border-collapse border border-border",t),"data-streamdown":"table",...r,children:e})})]}),Uq=(0,R.lazy)(()=>Promise.resolve().then(()=>(EM(),AM)).then(e=>({default:e.CodeBlock}))),qq=(0,R.lazy)(()=>Promise.resolve().then(()=>(_M(),DM)).then(e=>({default:e.Mermaid}))),zq=/language-([^\s]+)/;Dy=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,Fd=(e,t)=>{if(typeof e=="boolean")return e;let a=e.mermaid;return a===!1?!1:a===!0||a===void 0?!0:a[t]!==!1},Ny=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("ol",{className:J("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...r,children:e}),(e,t)=>ht(e,t));Ny.displayName="MarkdownOl";$M=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("li",{className:J("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...r,children:e}),(e,t)=>e.className===t.className&&Vd(e.node,t.node));$M.displayName="MarkdownLi";WM=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("ul",{className:J("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...r,children:e}),(e,t)=>ht(e,t));WM.displayName="MarkdownUl";XM=(0,R.memo)(({className:e,node:t,...a})=>(0,T.jsx)("hr",{className:J("my-6 border-border",e),"data-streamdown":"horizontal-rule",...a}),(e,t)=>ht(e,t));XM.displayName="MarkdownHr";ZM=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("span",{className:J("font-semibold",t),"data-streamdown":"strong",...r,children:e}),(e,t)=>ht(e,t));ZM.displayName="MarkdownStrong";Fq=({children:e,className:t,href:a,node:r,...n})=>{let{linkSafety:o}=(0,R.useContext)(Yt),[l,i]=(0,R.useState)(!1),s=a==="streamdown:incomplete-link",u=(0,R.useCallback)(async p=>{if(!(!(o!=null&&o.enabled&&a)||s)){if(p.preventDefault(),o.onLinkCheck&&await o.onLinkCheck(a)){window.open(a,"_blank","noreferrer");return}i(!0)}},[o,a,s]),c=(0,R.useCallback)(()=>{a&&window.open(a,"_blank","noreferrer")},[a]),d=(0,R.useCallback)(()=>{i(!1)},[]),f={url:a??"",isOpen:l,onClose:d,onConfirm:c};return o!=null&&o.enabled&&a?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("button",{className:J("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",onClick:u,type:"button",children:e}),o.renderModal?o.renderModal(f):(0,T.jsx)(Tq,{...f})]}):(0,T.jsx)("a",{className:J("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:a,rel:"noreferrer",target:"_blank",...n,children:e})},QM=(0,R.memo)(Fq,(e,t)=>ht(e,t)&&e.href===t.href);QM.displayName="MarkdownA";KM=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h1",{className:J("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...r,children:e}),(e,t)=>ht(e,t));KM.displayName="MarkdownH1";YM=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h2",{className:J("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...r,children:e}),(e,t)=>ht(e,t));YM.displayName="MarkdownH2";JM=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h3",{className:J("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...r,children:e}),(e,t)=>ht(e,t));JM.displayName="MarkdownH3";eA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h4",{className:J("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...r,children:e}),(e,t)=>ht(e,t));eA.displayName="MarkdownH4";tA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h5",{className:J("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...r,children:e}),(e,t)=>ht(e,t));tA.displayName="MarkdownH5";aA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("h6",{className:J("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...r,children:e}),(e,t)=>ht(e,t));aA.displayName="MarkdownH6";rA=(0,R.memo)(({children:e,className:t,node:a,...r})=>{let{controls:n}=(0,R.useContext)(Yt),o=Dy(n,"table");return(0,T.jsx)(Bq,{className:t,showControls:o,...r,children:e})},(e,t)=>ht(e,t));rA.displayName="MarkdownTable";nA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("thead",{className:J("bg-muted/80",t),"data-streamdown":"table-header",...r,children:e}),(e,t)=>ht(e,t));nA.displayName="MarkdownThead";oA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("tbody",{className:J("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...r,children:e}),(e,t)=>ht(e,t));oA.displayName="MarkdownTbody";lA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("tr",{className:J("border-border border-b",t),"data-streamdown":"table-row",...r,children:e}),(e,t)=>ht(e,t));lA.displayName="MarkdownTr";iA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("th",{className:J("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...r,children:e}),(e,t)=>ht(e,t));iA.displayName="MarkdownTh";sA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("td",{className:J("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...r,children:e}),(e,t)=>ht(e,t));sA.displayName="MarkdownTd";uA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("blockquote",{className:J("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...r,children:e}),(e,t)=>ht(e,t));uA.displayName="MarkdownBlockquote";cA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("sup",{className:J("text-sm",t),"data-streamdown":"superscript",...r,children:e}),(e,t)=>ht(e,t));cA.displayName="MarkdownSup";dA=(0,R.memo)(({children:e,className:t,node:a,...r})=>(0,T.jsx)("sub",{className:J("text-sm",t),"data-streamdown":"subscript",...r,children:e}),(e,t)=>ht(e,t));dA.displayName="MarkdownSub";fA=(0,R.memo)(({children:e,className:t,node:a,...r})=>{if("data-footnotes"in r){let n=l=>{var i,s;if(!(0,R.isValidElement)(l))return!1;let u=Array.isArray(l.props.children)?l.props.children:[l.props.children],c=!1,d=!1;for(let f of u)if(f){if(typeof f=="string")f.trim()!==""&&(c=!0);else if((0,R.isValidElement)(f))if(((i=f.props)==null?void 0:i["data-footnote-backref"])!==void 0)d=!0;else{let p=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let g of p){if(typeof g=="string"&&g.trim()!==""){c=!0;break}if((0,R.isValidElement)(g)&&((s=g.props)==null?void 0:s["data-footnote-backref"])===void 0){c=!0;break}}}}return d&&!c},o=Array.isArray(e)?e.map(l=>{if(!(0,R.isValidElement)(l))return l;if(l.type===Ny){let i=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(s=>!n(s));return i.length===0?null:{...l,props:{...l.props,children:i}}}return l}):e;return(Array.isArray(o)?o.some(l=>l!==null):o!==null)?(0,T.jsx)("section",{className:t,...r,children:o}):null}return(0,T.jsx)("section",{className:t,...r,children:e})},(e,t)=>ht(e,t));fA.displayName="MarkdownSection";Hq=({node:e,className:t,children:a,...r})=>{var n,o,l;let i=((n=e?.position)==null?void 0:n.start.line)===((o=e?.position)==null?void 0:o.end.line),{mermaid:s,controls:u}=(0,R.useContext)(Yt),c=Py();if(i)return(0,T.jsx)("code",{className:J("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...r,children:a});let d=t?.match(zq),f=(l=d?.at(1))!=null?l:"",p="";if((0,R.isValidElement)(a)&&a.props&&typeof a.props=="object"&&"children"in a.props&&typeof a.props.children=="string"?p=a.props.children:typeof a=="string"&&(p=a),f==="mermaid"&&c){let v=Dy(u,"mermaid"),C=Fd(u,"download"),y=Fd(u,"copy"),x=Fd(u,"fullscreen"),h=Fd(u,"panZoom"),w=v&&(C||y||x);return(0,T.jsx)(R.Suspense,{fallback:(0,T.jsx)(BM,{}),children:(0,T.jsxs)("div",{className:J("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[w?(0,T.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[C?(0,T.jsx)(Aq,{chart:p,config:s?.config}):null,y?(0,T.jsx)(PM,{code:p}):null,x?(0,T.jsx)(Dq,{chart:p,config:s?.config}):null]}):null,(0,T.jsx)(qq,{chart:p,config:s?.config,showControls:h})]})})}let g=Dy(u,"code");return(0,T.jsx)(R.Suspense,{fallback:(0,T.jsx)(BM,{}),children:(0,T.jsx)(Uq,{className:J("overflow-x-auto border-border border-t",t),code:p,language:f,children:g?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(Sq,{code:p,language:f}),(0,T.jsx)(PM,{})]}):null})})},pA=(0,R.memo)(Hq,(e,t)=>e.className===t.className&&Vd(e.node,t.node));pA.displayName="MarkdownCode";mA=(0,R.memo)(Iq,(e,t)=>e.className===t.className&&Vd(e.node,t.node));mA.displayName="MarkdownImg";hA=(0,R.memo)(({children:e,className:t,node:a,...r})=>{var n,o;let l=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");if(l.length===1&&(0,R.isValidElement)(l[0])){let i=l[0].props.node,s=i?.tagName;if(s==="img")return(0,T.jsx)(T.Fragment,{children:e});if(s==="code"&&((n=i?.position)==null?void 0:n.start.line)!==((o=i?.position)==null?void 0:o.end.line))return(0,T.jsx)(T.Fragment,{children:e})}return(0,T.jsx)("p",{className:t,...r,children:e})},(e,t)=>ht(e,t));hA.displayName="MarkdownParagraph";jq={ol:Ny,li:$M,ul:WM,hr:XM,strong:ZM,a:QM,h1:KM,h2:YM,h3:JM,h4:eA,h5:tA,h6:aA,table:rA,thead:nA,tbody:oA,tr:lA,th:iA,td:sA,blockquote:uA,code:pA,img:mA,pre:({children:e})=>e,sup:cA,sub:dA,p:hA,section:fA},UM=[],qM={allowDangerousHtml:!0},Hd=new WeakMap,Vq=class{constructor(){this.cache=new Map,this.keyCache=new WeakMap,this.maxSize=100}generateCacheKey(e){let t=this.keyCache.get(e);if(t)return t;let a=e.rehypePlugins,r=e.remarkPlugins,n=e.remarkRehypeOptions;if(!(a||r||n)){let c="default";return this.keyCache.set(e,c),c}let o=c=>{if(!c||c.length===0)return"";let d="";for(let f=0;f<c.length;f+=1){let p=c[f];if(f>0&&(d+=","),Array.isArray(p)){let[g,v]=p;if(typeof g=="function"){let C=Hd.get(g);C||(C=g.name,Hd.set(g,C)),d+=C}else d+=String(g);d+=":",d+=JSON.stringify(v)}else if(typeof p=="function"){let g=Hd.get(p);g||(g=p.name,Hd.set(p,g)),d+=g}else d+=String(p)}return d},l=o(a),i=o(r),s=n?JSON.stringify(n):"",u=`${i}::${l}::${s}`;return this.keyCache.set(e,u),u}get(e){let t=this.generateCacheKey(e),a=this.cache.get(t);return a&&(this.cache.delete(t),this.cache.set(t,a)),a}set(e,t){let a=this.generateCacheKey(e);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r)}this.cache.set(a,t)}clear(){this.cache.clear()}},zM=new Vq,gA=e=>{let t=Gq(e),a=e.children||"";return Wq(t.runSync(t.parse(a),a),e)},Gq=e=>{let t=zM.get(e);if(t)return t;let a=$q(e);return zM.set(e,a),a},$q=e=>{let t=e.rehypePlugins||UM,a=e.remarkPlugins||UM,r=e.remarkRehypeOptions?{...qM,...e.remarkRehypeOptions}:qM;return py().use(Ld).use(a).use(Ad,r).use(t)},Wq=(e,t)=>$g(e,{Fragment:T.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:T.jsx,jsxs:T.jsxs,passKeys:!0,passNode:!0}),Xq=/\[\^[^\]\s]{1,200}\](?!:)/,Zq=/\[\^[^\]\s]{1,200}\]:/,Qq=/<\/(\w+)>/,Kq=/<(\w+)[\s>]/,Ay=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
120
120
  `||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},Yq=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
121
- `||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Ey=e=>{let t=0;for(let a=0;a<e.length-1;a+=1)e[a]==="$"&&e[a+1]==="$"&&(t+=1,a+=1);return t},yA=e=>{let t=Xq.test(e),a=Zq.test(e);if(t||a)return[e];let r=Sa.lex(e,{gfm:!0}),n=[],o=[];for(let l of r){let i=l.raw,s=n.length;if(o.length>0){if(n[s-1]+=i,l.type==="html"){let u=i.match(Qq);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(l.type==="html"&&l.block){let u=i.match(Kq);if(u){let c=u[1];i.includes(`</${c}>`)||o.push(c)}}if(i.trim()==="$$"&&s>0){let u=n[s-1],c=Ay(u),d=Ey(u);if(c&&d%2===1){n[s-1]=u+i;continue}}if(s>0&&Yq(i)){let u=n[s-1],c=Ay(u),d=Ey(u),f=Ey(i);if(c&&d%2===1&&!Ay(i)&&f===1){n[s-1]=u+i;continue}}n.push(i)}return n},xA={raw:K0,sanitize:[Gc,{}],harden:[Z0,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},vA={gfm:[gd,{}]},Jq=Object.values(xA),ez=Object.values(vA),tz={block:" \u258B",circle:" \u25CF"},az={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},Yt=(0,R.createContext)(az),By=(0,R.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...r})=>(0,T.jsx)(gA,{...r,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return!1;if(e.components!==t.components){let a=Object.keys(e.components||{}),r=Object.keys(t.components||{});if(a.length!==r.length||a.some(n=>{var o,l;return((o=e.components)==null?void 0:o[n])!==((l=t.components)==null?void 0:l[n])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});By.displayName="Block";rz=["github-light","github-dark"],Ul=(0,R.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:r,rehypePlugins:n=Jq,remarkPlugins:o=ez,className:l,shikiTheme:i=rz,mermaid:s,controls:u=!0,isAnimating:c=!1,BlockComponent:d=By,parseMarkdownIntoBlocksFn:f=yA,caret:p,plugins:g,remend:v,linkSafety:C={enabled:!0},...y})=>{let x=(0,R.useId)(),[h,w]=(0,R.useTransition)(),M=(0,R.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?uL(e,v):e,[e,t,a,v]),b=(0,R.useMemo)(()=>f(M),[M,f]),[A,D]=(0,R.useState)(b);(0,R.useEffect)(()=>{t==="streaming"?w(()=>{D(b)}):D(b)},[b,t]);let P=t==="streaming"?A:b,k=(0,R.useMemo)(()=>P.map((Y,be)=>`${x}-${be}`),[P.length,x]),U=(0,R.useMemo)(()=>{var Y,be;return{shikiTheme:(be=(Y=g?.code)==null?void 0:Y.getThemes())!=null?be:i,controls:u,isAnimating:c,mode:t,mermaid:s,linkSafety:C}},[i,u,c,t,s,C,g?.code]),E=(0,R.useMemo)(()=>({...jq,...r}),[r]),q=(0,R.useMemo)(()=>{let Y=[];return g!=null&&g.cjk&&(Y=[...Y,...g.cjk.remarkPluginsBefore]),Y=[...Y,...o],g!=null&&g.cjk&&(Y=[...Y,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(Y=[...Y,g.math.remarkPlugin]),Y},[o,g?.math,g?.cjk]),$=(0,R.useMemo)(()=>g!=null&&g.math?[...n,g.math.rehypePlugin]:n,[n,g?.math]),V=(0,R.useMemo)(()=>p&&c?{"--streamdown-caret":`"${tz[p]}"`}:void 0,[p,c]);return t==="static"?(0,T.jsx)(Ry.Provider,{value:g??null,children:(0,T.jsx)(Yt.Provider,{value:U,children:(0,T.jsx)("div",{className:J("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:(0,T.jsx)(gA,{components:E,rehypePlugins:$,remarkPlugins:q,...y,children:e})})})}):(0,T.jsx)(Ry.Provider,{value:g??null,children:(0,T.jsx)(Yt.Provider,{value:U,children:(0,T.jsxs)("div",{className:J("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",p?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:V,children:[P.length===0&&p&&c&&(0,T.jsx)("span",{}),P.map((Y,be)=>(0,T.jsx)(d,{components:E,content:Y,index:be,rehypePlugins:$,remarkPlugins:q,shouldParseIncompleteMarkdown:a,...y},k[be]))]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety);Ul.displayName="Streamdown";nz=({children:e,className:t,minZoom:a=.5,maxZoom:r=3,zoomStep:n=.1,showControls:o=!0,initialZoom:l=1,fullscreen:i=!1})=>{let s=(0,R.useRef)(null),u=(0,R.useRef)(null),[c,d]=(0,R.useState)(l),[f,p]=(0,R.useState)({x:0,y:0}),[g,v]=(0,R.useState)(!1),[C,y]=(0,R.useState)({x:0,y:0}),[x,h]=(0,R.useState)({x:0,y:0}),w=(0,R.useCallback)(E=>{d(q=>Math.max(a,Math.min(r,q+E)))},[a,r]),M=(0,R.useCallback)(()=>{w(n)},[w,n]),b=(0,R.useCallback)(()=>{w(-n)},[w,n]),A=(0,R.useCallback)(()=>{d(l),p({x:0,y:0})},[l]),D=(0,R.useCallback)(E=>{E.preventDefault();let q=E.deltaY>0?-n:n;w(q)},[w,n]),P=(0,R.useCallback)(E=>{if(E.button!==0||E.isPrimary===!1)return;v(!0),y({x:E.clientX,y:E.clientY}),h(f);let q=E.currentTarget;q instanceof HTMLElement&&q.setPointerCapture(E.pointerId)},[f]),k=(0,R.useCallback)(E=>{if(!g)return;E.preventDefault();let q=E.clientX-C.x,$=E.clientY-C.y;p({x:x.x+q,y:x.y+$})},[g,C,x]),U=(0,R.useCallback)(E=>{v(!1);let q=E.currentTarget;q instanceof HTMLElement&&q.releasePointerCapture(E.pointerId)},[]);return(0,R.useEffect)(()=>{let E=s.current;if(E)return E.addEventListener("wheel",D,{passive:!1}),()=>{E.removeEventListener("wheel",D)}},[D]),(0,R.useEffect)(()=>{let E=u.current;if(E&&g)return document.body.style.userSelect="none",E.addEventListener("pointermove",k,{passive:!1}),E.addEventListener("pointerup",U),E.addEventListener("pointercancel",U),()=>{document.body.style.userSelect="",E.removeEventListener("pointermove",k),E.removeEventListener("pointerup",U),E.removeEventListener("pointercancel",U)}},[g,k,U]),(0,T.jsxs)("div",{className:J("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:g?"grabbing":"grab"},children:[o?(0,T.jsxs)("div",{className:J("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c>=r,onClick:M,title:"Zoom in",type:"button",children:(0,T.jsx)(wq,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c<=a,onClick:b,title:"Zoom out",type:"button",children:(0,T.jsx)(bq,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:A,title:"Reset zoom and pan",type:"button",children:(0,T.jsx)(vq,{size:16})})]}):null,(0,T.jsx)("div",{className:J("flex-1 origin-center transition-transform duration-150 ease-out",i?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:P,ref:u,role:"application",style:{transform:`translate(${f.x}px, ${f.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},Ty=({chart:e,className:t,config:a,fullscreen:r=!1,showControls:n=!0})=>{let[o,l]=(0,R.useState)(null),[i,s]=(0,R.useState)(!1),[u,c]=(0,R.useState)(""),[d,f]=(0,R.useState)(""),[p,g]=(0,R.useState)(0),{mermaid:v}=(0,R.useContext)(Yt),C=Py(),y=v?.errorComponent,{shouldRender:x,containerRef:h}=gq({immediate:r});if((0,R.useEffect)(()=>{if(x){if(!C){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),s(!0);let M=C.getMermaid(a),b=e.split("").reduce((P,k)=>(P<<5)-P+k.charCodeAt(0)|0,0),A=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:D}=await M.render(A,e);c(D),f(D)}catch(M){if(!(d||u)){let b=M instanceof Error?M.message:"Failed to render Mermaid chart";l(b)}}finally{s(!1)}})()}},[e,a,p,x,C]),!(x||u||d))return(0,T.jsx)("div",{className:J("my-4 min-h-[200px]",t),ref:h});if(i&&!u&&!d)return(0,T.jsx)("div",{className:J("my-4 flex justify-center p-4",t),ref:h,children:(0,T.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,T.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,T.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return y?(0,T.jsx)("div",{ref:h,children:(0,T.jsx)(y,{chart:e,error:o,retry:()=>g(b=>b+1)})}):(0,T.jsxs)("div",{className:J("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:h,children:[(0,T.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,T.jsxs)("details",{className:"mt-2",children:[(0,T.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,T.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let w=u||d;return(0,T.jsx)("div",{className:J("size-full",t),"data-streamdown":"mermaid",ref:h,children:(0,T.jsx)(nz,{className:J(r?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:r,maxZoom:3,minZoom:.5,showControls:n,zoomStep:.1,children:(0,T.jsx)("div",{"aria-label":"Mermaid chart",className:J("flex justify-center",r?"size-full items-center":null),dangerouslySetInnerHTML:{__html:w},role:"img"})})})}});var P2=Ht((Dte,O2)=>{"use strict";function z6(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let a,r=0;return function(...o){clearTimeout(a);let l=Date.now(),i=l-r,s=t-i;s<=0?(r=l,e.apply(this,o)):a=setTimeout(()=>{r=Date.now(),e.apply(this,o)},s)}}O2.exports=z6});var xx=F(_e(),1),mR=F(s0(),1);var hO="https://app.waniwani.ai/api/mcp/chat",gO={api:hO};function yO(){if(typeof document>"u")return null;if(document.currentScript instanceof HTMLScriptElement)return document.currentScript;let e=document.querySelectorAll("script[src]");for(let t of e)if(t instanceof HTMLScriptElement&&/embed/i.test(t.src))return t;return null}function Ac(){let e=yO();if(!e)return{};let t=h=>e.getAttribute(h)??void 0,a=h=>{let w=e.getAttribute(h);if(w==null)return;let M=w.trim().toLowerCase();if(M==="true"||M==="1"||M==="")return!0;if(M==="false"||M==="0")return!1},r={},n=t("data-api");n&&(r.api=n);let o=t("data-token");o&&(r.token=o);let l=t("data-title");l&&(r.title=l);let i=t("data-welcome-message");i&&(r.welcomeMessage=i);let s=t("data-placeholder");s&&(r.placeholder=s);let u=t("data-mcp-server-url");u&&(r.mcpServerUrl=u);let c=t("data-channel-id");c&&(r.channelId=c);let d=a("data-show-tool-calls");d!==void 0&&(r.showToolCalls=d);let f=t("data-css");f&&(r.css=f);let p=t("data-suggestions");p&&(r.suggestions=p.split(",").map(h=>h.trim()).filter(Boolean));let g=a("data-enable-thread-history");g!==void 0&&(r.enableThreadHistory=g);let v=a("data-hide-header");v!==void 0&&(r.hideHeader=v);let C=t("data-theme");(C==="light"||C==="dark"||C==="auto")&&(r.appearance={theme:C});let y=t("data-locale");(y==="en"||y==="fr"||y==="es")&&(r.locale=y);let x=t("data-disclaimer");if(x!==void 0){let h=x.trim(),w=h.toLowerCase();w==="false"||w==="0"?r.disclaimer=!1:h&&(r.disclaimer=h)}return r}function ah(e){if(!e)return{};let t={};for(let a in e)e[a]!==void 0&&(t[a]=e[a]);return t}function Xi(e,t,a){let r=a??Ac(),n=xO(t,r,e),o={token:"",...gO,...ah(t),...ah(r),...ah(e),...n?{appearance:n}:{}};if(!o.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return o}function xO(e,t,a){let r=a?.appearance?.theme??t.appearance?.theme??e?.appearance?.theme,n={...e?.appearance?.variables??{},...t.appearance?.variables??{},...a?.appearance?.variables??{}},o=Object.keys(n).length>0;if(!r&&!o)return;let l={};return r&&(l.theme=r),o&&(l.variables=n),l}var zn=F(_e(),1);var Rc=F(_e());var Ec=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim();var u0=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var c0=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase());var rh=e=>{let t=c0(e);return t.charAt(0).toUpperCase()+t.slice(1)};var Zi=F(_e());var d0={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var f0=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var p0=(0,Zi.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:r,className:n="",children:o,iconNode:l,...i},s)=>(0,Zi.createElement)("svg",{ref:s,...d0,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Ec("lucide",n),...!o&&!f0(i)&&{"aria-hidden":"true"},...i},[...l.map(([u,c])=>(0,Zi.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var He=(e,t)=>{let a=(0,Rc.forwardRef)(({className:r,...n},o)=>(0,Rc.createElement)(p0,{ref:o,iconNode:t,className:Ec(`lucide-${u0(rh(e))}`,`lucide-${e}`,r),...n}));return a.displayName=rh(e),a};var vO=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Qi=He("arrow-down",vO);var wO=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ki=He("arrow-up",wO);var bO=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Br=He("braces",bO);var SO=[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]],Yi=He("brain",SO);var CO=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Ji=He("check",CO);var IO=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],so=He("chevron-down",IO);var LO=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],es=He("chevron-right",LO);var kO=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]],ts=He("clipboard-copy",kO);var TO=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]],as=He("file",TO);var MO=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],rs=He("loader",MO);var AO=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],ns=He("paperclip",AO);var EO=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],os=He("square",EO);var RO=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],uo=He("x",RO);var DO=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],ls=He("zap",DO);var Ze=F(_e(),1);var is=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,a)=>(a&=63,a<36?t+=a.toString(36):a<62?t+=(a-26).toString(36).toUpperCase():a>62?t+="-":t+="_",t),"");var Xe=F(_e(),1);var or=F(_e(),1);var m0=["en","fr","es"];function Ll(e){return m0.includes(e)}function Dc(e){if(e&&Ll(e))return e;if(e){let a=e.split("-")[0]?.toLowerCase();if(a&&Ll(a))return a}let t=[];if(typeof document<"u"){let a=document.documentElement.getAttribute("lang");a&&t.push(a)}typeof navigator<"u"&&(navigator.language&&t.push(navigator.language),navigator.languages&&t.push(...navigator.languages));for(let a of t){let r=a.toLowerCase();if(Ll(r))return r;let n=r.split("-")[0];if(n&&Ll(n))return n}return"en"}var _c={promptInput:{placeholder:"What would you like to know?",uploadFiles:"Upload files",stop:"Stop",submit:"Submit",removeAttachments:"Remove all attachments"},workingIndicator:{default:"On it\u2026"},reasoning:{thinking:"Thinking\u2026",thoughtBrief:"Thought for a few seconds",thoughtForSeconds:e=>`Thought for ${e} second${e===1?"":"s"}`},tool:{copy:"Copy",copied:"Copied",request:"Request",response:"Response",error:"Error"},attachments:{attachmentFallback:"attachment",fileFallback:"file"},threadMenu:{newChat:"New chat",threadHistory:"Thread history",deleteThread:"Delete thread",noPreviousChats:"No previous chats yet.",hiddenThreads:e=>`${e} older thread${e===1?"":"s"} hidden`},chatQueue:{attachmentFallback:"(attachment)",removeFromQueue:"Remove from queue",queued:e=>`${e} queued`},poweredBy:{label:"AI agent powered by"},aiDisclaimer:{default:"can make mistakes"},exportSession:{saving:"saving...",saved:"saved",error:"error",export:"export",tooltip:"Save scenario to WaniWani"},widgetErrorBoundary:{failedToLoad:"Widget failed to load",retry:"Retry"}};var h0={promptInput:{placeholder:"\xBFQu\xE9 te gustar\xEDa saber?",uploadFiles:"Subir archivos",stop:"Detener",submit:"Enviar",removeAttachments:"Eliminar todos los archivos adjuntos"},workingIndicator:{default:"Un momento\u2026"},reasoning:{thinking:"Pensando\u2026",thoughtBrief:"Pens\xE9 durante unos segundos",thoughtForSeconds:e=>`Pens\xE9 durante ${e} segundo${e===1?"":"s"}`},tool:{copy:"Copiar",copied:"Copiado",request:"Solicitud",response:"Respuesta",error:"Error"},attachments:{attachmentFallback:"adjunto",fileFallback:"archivo"},threadMenu:{newChat:"Nuevo chat",threadHistory:"Historial",deleteThread:"Eliminar conversaci\xF3n",noPreviousChats:"A\xFAn no hay conversaciones anteriores.",hiddenThreads:e=>`${e} conversaci\xF3n${e===1?"":"es"} anterior${e===1?"":"es"} oculta${e===1?"":"s"}`},chatQueue:{attachmentFallback:"(adjunto)",removeFromQueue:"Quitar de la cola",queued:e=>`${e} en cola`},poweredBy:{label:"Agente IA con tecnolog\xEDa de"},aiDisclaimer:{default:"puede cometer errores"},exportSession:{saving:"guardando...",saved:"guardado",error:"error",export:"exportar",tooltip:"Guardar escenario en WaniWani"},widgetErrorBoundary:{failedToLoad:"No se pudo cargar el widget",retry:"Reintentar"}};var g0={promptInput:{placeholder:"Que souhaitez-vous savoir ?",uploadFiles:"Importer des fichiers",stop:"Arr\xEAter",submit:"Envoyer",removeAttachments:"Supprimer toutes les pi\xE8ces jointes"},workingIndicator:{default:"Un instant\u2026"},reasoning:{thinking:"R\xE9flexion\u2026",thoughtBrief:"R\xE9flexion de quelques secondes",thoughtForSeconds:e=>`R\xE9flexion de ${e} seconde${e===1?"":"s"}`},tool:{copy:"Copier",copied:"Copi\xE9",request:"Requ\xEAte",response:"R\xE9ponse",error:"Erreur"},attachments:{attachmentFallback:"pi\xE8ce jointe",fileFallback:"fichier"},threadMenu:{newChat:"Nouvelle conversation",threadHistory:"Historique",deleteThread:"Supprimer la conversation",noPreviousChats:"Aucune conversation pr\xE9c\xE9dente.",hiddenThreads:e=>`${e} conversation${e===1?"":"s"} plus ancienne${e===1?"":"s"} masqu\xE9e${e===1?"":"s"}`},chatQueue:{attachmentFallback:"(pi\xE8ce jointe)",removeFromQueue:"Retirer de la file",queued:e=>`${e} en file`},poweredBy:{label:"Agent IA propuls\xE9 par"},aiDisclaimer:{default:"peut faire des erreurs"},exportSession:{saving:"enregistrement...",saved:"enregistr\xE9",error:"erreur",export:"exporter",tooltip:"Enregistrer le sc\xE9nario dans WaniWani"},widgetErrorBoundary:{failedToLoad:"\xC9chec du chargement du widget",retry:"R\xE9essayer"}};var nh={en:_c,fr:g0,es:h0};var b0=F(re(),1),w0=(0,or.createContext)(null);function PO(e,t){if(!t)return e;let a={...e};for(let r of Object.keys(e)){let n=e[r],o=t[r];o&&typeof n=="object"&&(a[r]={...n,...o})}return a}function oh({children:e,locale:t,messages:a}){let[r,n]=(0,or.useState)(()=>typeof window>"u"?t&&NO(t)?t:"en":Dc(t));(0,or.useEffect)(()=>{n(Dc(t))},[t]);let o=(0,or.useMemo)(()=>{let l=nh[r]??nh["en"];return{locale:r,t:PO(l,a)}},[r,a]);return(0,b0.jsx)(w0.Provider,{value:o,children:e})}function NO(e){return e==="en"||e==="fr"||e==="es"}function Ne(){let e=(0,or.useContext)(w0);return e||{locale:"en",t:_c}}function lh(e,t){let a=Date.now()-e;if(a<6e4)try{return new Intl.RelativeTimeFormat(t,{numeric:"auto",style:"narrow"}).format(0,"second")}catch{return"just now"}let r,n;a<60*6e4?(r=-Math.floor(a/6e4),n="minute"):a<1440*6e4?(r=-Math.floor(a/(60*6e4)),n="hour"):(r=-Math.floor(a/(1440*6e4)),n="day");try{return new Intl.RelativeTimeFormat(t,{numeric:"auto",style:"short"}).format(r,n)}catch{return`${Math.abs(r)}${n==="minute"?"m":n==="hour"?"h":"d"} ago`}}ih();uh();var BO=C0({prefix:"ww"});function Z(...e){return BO(Pc(e))}var I0=F(re(),1),lr=({className:e,variant:t="default",size:a="default",type:r="button",...n})=>(0,I0.jsx)("button",{type:r,className:Z("ww:inline-flex ww:cursor-pointer ww:items-center ww:justify-center ww:rounded-md ww:font-medium ww:transition-colors ww:disabled:pointer-events-none ww:disabled:opacity-50",t==="default"&&"ww:bg-primary ww:text-primary-foreground ww:hover:bg-primary/90",t==="outline"&&"ww:border ww:border-border ww:bg-background ww:hover:bg-accent ww:hover:text-accent-foreground",t==="ghost"&&"ww:hover:bg-accent ww:hover:text-accent-foreground",a==="default"&&"ww:h-9 ww:px-4 ww:py-2 ww:text-sm",a==="sm"&&"ww:h-8 ww:px-3 ww:text-xs",a==="icon"&&"ww:size-9 ww:!rounded-full",a==="icon-sm"&&"ww:size-7 ww:!rounded-full",e),...n});var Zt=F(re(),1),UO=async e=>{try{let a=await(await fetch(e)).blob();return new Promise(r=>{let n=new FileReader;n.onloadend=()=>r(n.result),n.onerror=()=>r(null),n.readAsDataURL(a)})}catch{return null}},L0=(0,Xe.createContext)(null),k0=()=>{let e=(0,Xe.useContext)(L0);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},T0=({className:e,accept:t,multiple:a,globalDrop:r,maxFiles:n,maxFileSize:o,onSubmit:l,children:i,...s})=>{let{t:u}=Ne(),c=(0,Xe.useRef)(null),d=(0,Xe.useRef)(null),[f,p]=(0,Xe.useState)([]),g=(0,Xe.useRef)(f);(0,Xe.useEffect)(()=>{g.current=f},[f]);let v=(0,Xe.useCallback)(()=>{c.current?.click()},[]),C=(0,Xe.useCallback)(b=>{let A=[...b];if(A.length===0)return;let D=k=>o?k.size<=o:!0,P=A.filter(D);p(k=>{let U=typeof n=="number"?Math.max(0,n-k.length):void 0,E=typeof U=="number"?P.slice(0,U):P;return[...k,...E.map(q=>({filename:q.name,id:is(),mediaType:q.type,type:"file",url:URL.createObjectURL(q)}))]})},[n,o]),y=(0,Xe.useCallback)(b=>{p(A=>{let D=A.find(P=>P.id===b);return D?.url&&URL.revokeObjectURL(D.url),A.filter(P=>P.id!==b)})},[]),x=(0,Xe.useCallback)(()=>{p(b=>{for(let A of b)A.url&&URL.revokeObjectURL(A.url);return[]})},[]);(0,Xe.useEffect)(()=>()=>{for(let b of g.current)b.url&&URL.revokeObjectURL(b.url)},[]);let h=(0,Xe.useCallback)(b=>{b.currentTarget.files&&C(b.currentTarget.files),b.currentTarget.value=""},[C]);(0,Xe.useEffect)(()=>{if(!r)return;let b=D=>{D.dataTransfer?.types?.includes("Files")&&D.preventDefault()},A=D=>{D.dataTransfer?.types?.includes("Files")&&D.preventDefault(),D.dataTransfer?.files&&D.dataTransfer.files.length>0&&C(D.dataTransfer.files)};return document.addEventListener("dragover",b),document.addEventListener("drop",A),()=>{document.removeEventListener("dragover",b),document.removeEventListener("drop",A)}},[C,r]);let w=(0,Xe.useCallback)(async b=>{b.preventDefault();let A=b.currentTarget,P=new FormData(A).get("message")||"";A.reset();let k=await Promise.all(f.map(async({id:U,...E})=>{if(E.url?.startsWith("blob:")){let q=await UO(E.url);return{...E,url:q??E.url}}return E}));try{let U=l({files:k,text:P},b);U instanceof Promise&&await U,x()}catch{}},[f,l,x]),M=(0,Xe.useMemo)(()=>({add:C,clear:x,files:f,openFileDialog:v,remove:y}),[f,C,y,x,v]);return(0,Zt.jsxs)(L0.Provider,{value:M,children:[(0,Zt.jsx)("input",{accept:t,"aria-label":u.promptInput.uploadFiles,className:"ww:hidden",multiple:a,onChange:h,ref:c,title:u.promptInput.uploadFiles,type:"file"}),(0,Zt.jsx)("form",{className:Z("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:w,ref:d,...s,children:i})]})};var M0=({onChange:e,onKeyDown:t,className:a,placeholder:r,...n})=>{let{t:o}=Ne(),l=k0(),[i,s]=(0,Xe.useState)(!1),u=r??o.promptInput.placeholder,c=(0,Xe.useCallback)(f=>{if(t?.(f),!f.defaultPrevented){if(f.key==="Enter"){if(i||f.nativeEvent.isComposing||f.shiftKey)return;f.preventDefault();let{form:p}=f.currentTarget;if(p?.querySelector('button[type="submit"]')?.disabled)return;p?.requestSubmit()}if(f.key==="Backspace"&&f.currentTarget.value===""&&l.files.length>0){f.preventDefault();let p=l.files.at(-1);p&&l.remove(p.id)}}},[t,i,l]),d=(0,Xe.useCallback)(f=>{let p=f.clipboardData?.items;if(!p)return;let g=[];for(let v of p)if(v.kind==="file"){let C=v.getAsFile();C&&g.push(C)}g.length>0&&(f.preventDefault(),l.add(g))},[l]);return(0,Zt.jsx)("textarea",{className:Z("ww:field-sizing-content ww:max-h-48 ww:min-h-0 ww:w-full ww:resize-none ww:border-0 ww:bg-transparent ww:px-3 ww:py-2 ww:text-base ww:sm:text-sm ww:outline-none ww:placeholder:text-muted-foreground",a),name:"message",onCompositionEnd:()=>s(!1),onCompositionStart:()=>s(!0),onKeyDown:c,onPaste:d,placeholder:u,onChange:e,...n})},A0=({className:e,status:t,onStop:a,onClick:r,children:n,...o})=>{let{t:l}=Ne(),i=t==="submitted"||t==="streaming",s=(0,Zt.jsx)(Ki,{className:"ww:size-4"});t==="submitted"?s=(0,Zt.jsx)(rs,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(s=(0,Zt.jsx)(os,{className:"ww:size-4"}));let u=(0,Xe.useCallback)(c=>{if(i&&a){c.preventDefault(),a();return}r?.(c)},[i,a,r]);return(0,Zt.jsx)(lr,{"aria-label":i?l.promptInput.stop:l.promptInput.submit,className:Z("ww:bg-foreground ww:text-background ww:hover:bg-foreground ww:rounded-full",e),onClick:u,size:"icon-sm",type:i&&a?"button":"submit",variant:"ghost",...o,children:n??s})},E0=({className:e,children:t,...a})=>{let{t:r}=Ne(),n=k0();return n.files.length>0?(0,Zt.jsxs)(lr,{className:Z("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":r.promptInput.removeAttachments,...a,children:[(0,Zt.jsx)("span",{className:"ww:flex ww:size-5 ww:items-center ww:justify-center ww:rounded-full ww:bg-primary ww:text-[10px] ww:font-medium ww:text-primary-foreground ww:transition-opacity ww:group-hover:opacity-0",children:n.files.length}),(0,Zt.jsx)(uo,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):(0,Zt.jsx)(lr,{className:Z(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...a,children:t??(0,Zt.jsx)(ns,{className:"ww:size-4"})})};var D0=F(re(),1);function R0({text:e}){let{t}=Ne();return e===!1?null:(0,D0.jsx)("span",{className:"ww:text-[11px] ww:text-muted-foreground ww:opacity-70",children:e||t.aiDisclaimer.default})}var Nc=F(_e(),1);var co=F(re(),1),_0=({className:e,...t})=>(0,co.jsx)("div",{className:Z("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),O0=({className:e,...t})=>(0,co.jsx)("li",{className:Z("ww:group ww:flex ww:items-center ww:gap-2 ww:rounded-md ww:px-2 ww:py-1 ww:text-sm ww:transition-colors ww:hover:bg-muted",e),...t}),P0=({className:e,...t})=>(0,co.jsx)("span",{className:Z("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),N0=({className:e,...t})=>(0,co.jsx)("span",{className:Z("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),B0=({className:e,...t})=>(0,co.jsx)("div",{className:Z("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),U0=({className:e,...t})=>(0,co.jsx)(lr,{className:Z("ww:size-auto ww:rounded ww:p-1 ww:text-muted-foreground ww:hover:bg-muted-foreground/10 ww:hover:text-foreground",e),size:"icon",type:"button",variant:"ghost",...t});var Ba=F(re(),1),q0=(0,Nc.memo)(({message:e,onRemove:t})=>{let{t:a}=Ne(),r=(0,Nc.useCallback)(()=>t(e.id),[t,e.id]);return(0,Ba.jsxs)(O0,{children:[(0,Ba.jsx)(P0,{}),(0,Ba.jsx)(N0,{children:e.text||a.chatQueue.attachmentFallback}),(0,Ba.jsx)(B0,{children:(0,Ba.jsx)(U0,{"aria-label":a.chatQueue.removeFromQueue,onClick:r,children:(0,Ba.jsx)(uo,{className:"ww:size-3"})})})]})});q0.displayName="ChatQueueItem";function z0({queuedMessages:e,onRemove:t,className:a}){let{t:r}=Ne();return e.length===0?null:(0,Ba.jsxs)(_0,{className:Z("ww:border-t ww:border-border",a),children:[(0,Ba.jsx)("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:r.chatQueue.queued(e.length)}),(0,Ba.jsx)("ul",{children:e.map(n=>(0,Ba.jsx)(q0,{message:n,onRemove:t},n.id))})]})}var In=F(re(),1),F0=({files:e,className:t,...a})=>e.length===0?null:(0,In.jsx)("div",{className:Z("ww:flex ww:flex-wrap ww:gap-1.5",t),...a,children:e.map((r,n)=>(0,In.jsx)(qO,{file:r},n))});function qO({file:e}){let{t}=Ne();return e.mediaType?.startsWith("image/")&&e.url?(0,In.jsx)("img",{src:e.url,alt:e.filename??t.attachments.attachmentFallback,className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):(0,In.jsxs)("span",{className:"ww:inline-flex ww:items-center ww:gap-1.5 ww:rounded ww:bg-background/20 ww:px-2 ww:py-1 ww:text-xs",children:[(0,In.jsx)(as,{className:"ww:size-3 ww:shrink-0"}),(0,In.jsx)("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??t.attachments.fileFallback})]})}var ch={name:"cjk-noop",type:"cjk",remarkPluginsBefore:[],remarkPluginsAfter:[],remarkPlugins:[]};var H0={name:"shiki-noop",type:"code-highlighter",supportsLanguage:()=>!1,getSupportedLanguages:()=>[],getThemes:()=>["github-light","github-dark"],highlight:()=>null};var SA=F(_e(),1);zd();var Gr=F(_e(),1),oz=5,wA=400;function bA(e,t,a={}){let{msPerChar:r=oz}=a,[n,o]=(0,Gr.useState)(t?"":e),l=(0,Gr.useRef)(e),i=(0,Gr.useRef)(t?0:e.length),s=(0,Gr.useRef)(0),u=(0,Gr.useRef)(null);return(e.length<i.current||!e.startsWith(n.slice(0,i.current)))&&(i.current=t?0:e.length),l.current=e,(0,Gr.useEffect)(()=>{if(!t){u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),i.current=e.length,o(e);return}if(l.current.length-i.current>wA&&(i.current=l.current.length-wA),u.current!==null)return;let d=f=>{let p=l.current;if(i.current>=p.length){u.current=null;return}s.current===0&&(s.current=f);let g=f-s.current;if(g>=r){let v=Math.min(Math.floor(g/r),p.length-i.current);i.current+=v,o(p.slice(0,i.current)),s.current=f}u.current=requestAnimationFrame(d)};return u.current=requestAnimationFrame(d),()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[e,t,r]),n}var Ps=F(re(),1),Uy=({className:e,from:t,children:a,...r})=>(0,Ps.jsx)("div",{className:Z("ww:group ww:flex ww:w-full",t==="user"?"is-user ww:ml-auto ww:max-w-[80%] ww:flex-col ww:items-end":"is-assistant ww:flex-col",e),...r,children:(0,Ps.jsx)("div",{className:Z("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),qy=({children:e,className:t,...a})=>(0,Ps.jsx)("div",{className:Z("ww:flex ww:w-fit ww:min-w-0 ww:max-w-full ww:flex-col ww:gap-2 ww:overflow-hidden ww:text-base","ww:group-[.is-user]:ml-auto ww:group-[.is-user]:rounded-lg ww:group-[.is-user]:bg-user-bubble ww:group-[.is-user]:px-4 ww:group-[.is-user]:py-3 ww:group-[.is-user]:text-primary-foreground","ww:group-[.is-assistant]:text-foreground",t),...a,children:e}),lz={cjk:ch,code:H0},iz={cjk:ch},sz={enabled:!1};function uz({className:e,linkSafety:t,isStreaming:a,children:r,...n}){let l=bA(typeof r=="string"?r:"",!!a),i=typeof r=="string"?l:r;return(0,Ps.jsx)(Ul,{className:Z("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),linkSafety:t??sz,plugins:a?iz:lz,...n,children:i})}var Gd=(0,SA.memo)(uz,(e,t)=>e.children===t.children&&e.isStreaming===t.isStreaming);Gd.displayName="MessageResponse";var st=F(_e(),1);var CA=F(_e(),1);var IA=F(re(),1),cz=({as:e="span",className:t,duration:a=2,style:r,children:n,...o})=>{let l={backgroundImage:"linear-gradient(90deg, var(--ww-color-muted-foreground) 0%, var(--ww-color-muted-foreground) 40%, var(--ww-color-foreground) 50%, var(--ww-color-muted-foreground) 60%, var(--ww-color-muted-foreground) 100%)",backgroundSize:"250% 100%",WebkitBackgroundClip:"text",backgroundClip:"text",color:"transparent",animation:`ww-shimmer ${a}s linear infinite`,...r};return(0,IA.jsx)(e,{"data-waniwani-shimmer":"",className:Z("ww:inline-block",t),style:l,...o,children:n})},Pn=(0,CA.memo)(cz);Pn.displayName="Shimmer";var Ft=F(re(),1),LA=(0,st.createContext)(null);function kA(){let e=(0,st.useContext)(LA);if(!e)throw new Error("Reasoning components must be used within <Reasoning>");return e}var dz=1e3,fz=1e3,zy=(0,st.memo)(({className:e,isStreaming:t=!1,open:a,defaultOpen:r,onOpenChange:n,duration:o,children:l,...i})=>{let s=r??t,u=r===!1,c=a!==void 0,[d,f]=(0,st.useState)(s),p=c?a:d,g=(0,st.useCallback)(A=>{c||f(A),n?.(A)},[c,n]),[v,C]=(0,st.useState)(void 0),y=o??v,x=(0,st.useRef)(t),[h,w]=(0,st.useState)(!1),M=(0,st.useRef)(null);(0,st.useEffect)(()=>{t?(x.current=!0,M.current===null&&(M.current=Date.now())):M.current!==null&&(C(Math.ceil((Date.now()-M.current)/fz)),M.current=null)},[t]),(0,st.useEffect)(()=>{t&&!p&&!u&&g(!0)},[t,p,u,g]),(0,st.useEffect)(()=>{if(x.current&&!t&&p&&!h){let A=setTimeout(()=>{g(!1),w(!0)},dz);return()=>clearTimeout(A)}},[t,p,h,g]);let b=(0,st.useMemo)(()=>({isStreaming:t,isOpen:p,setIsOpen:g,duration:y}),[t,p,g,y]);return(0,Ft.jsx)(LA.Provider,{value:b,children:(0,Ft.jsx)("div",{className:Z("ww:mb-4 ww:flex ww:flex-col ww:gap-2",e),"data-state":p?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...i,children:l})})});zy.displayName="Reasoning";var Fy=(0,st.memo)(({className:e,children:t,getThinkingMessage:a,onClick:r,...n})=>{let{t:o}=Ne(),{isStreaming:l,isOpen:i,duration:s,setIsOpen:u}=kA(),d=a??((f,p)=>f||p===0?(0,Ft.jsx)(Pn,{duration:1.6,children:o.reasoning.thinking}):p===void 0?(0,Ft.jsx)("span",{children:o.reasoning.thoughtBrief}):(0,Ft.jsx)("span",{children:o.reasoning.thoughtForSeconds(p)}));return(0,Ft.jsx)("button",{type:"button","aria-expanded":i,onClick:f=>{u(!i),r?.(f)},className:Z("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),...n,children:t??(0,Ft.jsxs)(Ft.Fragment,{children:[(0,Ft.jsx)(Yi,{className:"ww:size-4 ww:shrink-0"}),d(l,s),(0,Ft.jsx)(so,{className:Z("ww:size-4 ww:shrink-0 ww:transition-transform ww:duration-200",i&&"ww:rotate-180")})]})})});Fy.displayName="ReasoningTrigger";var Hy=(0,st.memo)(({className:e,children:t,...a})=>{let{isOpen:r}=kA();return(0,Ft.jsx)("div",{className:Z("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",r?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,Ft.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,Ft.jsx)("div",{className:Z("ww:text-sm ww:text-muted-foreground",e),...a,children:(0,Ft.jsx)(Ul,{children:t})})})})});Hy.displayName="ReasoningContent";var Et=F(_e(),1);var de=F(re(),1);function pz(e,t=80){if(e==null)return String(e);if(typeof e!="object")return String(e).slice(0,t);if(Array.isArray(e))return`Array(${e.length})`;let a=JSON.stringify(e);if(a.length<=t)return a;let r=Object.entries(e),n=[],o=t-2;for(let[l,i]of r){if(o<=8)break;let s=l.length>4?`${l.slice(0,4)}\u2026`:l,u;typeof i=="string"?u=i.length>2?`'${i.slice(0,1)}\u2026`:`'${i}'`:Array.isArray(i)?u=`Array(${i.length})`:typeof i=="object"&&i!==null?u="{\u2026}":u=String(i);let c=`${s}\u2009${u}`;n.push(c),o-=c.length+3}return`{${n.join(", ")}}`}function mz({text:e,className:t}){let{t:a}=Ne(),[r,n]=(0,Et.useState)(!1),o=(0,Et.useRef)(null);(0,Et.useEffect)(()=>()=>{o.current&&clearTimeout(o.current)},[]);let l=(0,Et.useCallback)(async i=>{i.stopPropagation();try{await navigator.clipboard.writeText(e),n(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>n(!1),2e3)}catch{}},[e]);return(0,de.jsx)(lr,{variant:"ghost",size:"sm",onClick:l,className:Z("ww:h-auto ww:gap-1 ww:px-1.5 ww:py-0.5 ww:text-xs ww:text-muted-foreground ww:hover:text-foreground",t),children:r?(0,de.jsxs)(de.Fragment,{children:[(0,de.jsx)(Ji,{className:"ww:size-3.5"}),(0,de.jsx)("span",{children:a.tool.copied})]}):(0,de.jsxs)(de.Fragment,{children:[(0,de.jsx)(ts,{className:"ww:size-3.5"}),(0,de.jsx)("span",{children:a.tool.copy})]})})}function AA({data:e,label:t,className:a,...r}){let[n,o]=(0,Et.useState)(!1),l=(0,Et.useMemo)(()=>JSON.stringify(e,null,2),[e]),i=pz(e);return(0,de.jsxs)("div",{className:Z("ww:rounded-lg ww:bg-tool-card",a),...r,children:[(0,de.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[(0,de.jsx)("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),(0,de.jsx)(mz,{text:l})]}),(0,de.jsxs)("button",{type:"button",onClick:()=>o(s=>!s),className:"ww:flex ww:w-full ww:items-start ww:gap-2 ww:px-3 ww:pb-3 ww:text-left",children:[(0,de.jsx)(es,{className:Z("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",n&&"ww:rotate-90")}),n?(0,de.jsx)("pre",{className:"ww:overflow-x-auto ww:text-xs ww:font-mono ww:text-foreground ww:whitespace-pre-wrap ww:break-all",children:(0,de.jsx)("code",{children:l})}):(0,de.jsx)("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var Vy=(0,Et.createContext)({open:!1,toggle:()=>{}});function EA({className:e,defaultOpen:t=!1,children:a,...r}){let[n,o]=(0,Et.useState)(t);return(0,de.jsx)(Vy.Provider,{value:{open:n,toggle:()=>o(l=>!l)},children:(0,de.jsx)("div",{className:Z("ww:mb-4 ww:w-full",e),"data-state":n?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...r,children:a})})}function RA({className:e,title:t,state:a,...r}){let{open:n,toggle:o}=(0,Et.useContext)(Vy),l=a==="input-available"||a==="input-streaming",i=t??"";return(0,de.jsxs)("button",{type:"button",onClick:o,className:Z("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),"aria-expanded":n,...r,children:[(0,de.jsx)(Br,{className:"ww:size-4 ww:shrink-0"}),(0,de.jsx)("span",{className:"ww:truncate",children:l?(0,de.jsx)(Pn,{duration:1.6,children:i}):i}),(0,de.jsx)(so,{className:Z("ww:size-4 ww:shrink-0 ww:transition-transform ww:duration-200",n&&"ww:rotate-180")})]})}function DA({className:e,title:t,state:a,...r}){let n=a==="input-available"||a==="input-streaming",o=t??"";return(0,de.jsxs)("div",{className:Z("ww:mb-4 ww:flex ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...r,children:[(0,de.jsx)(Br,{className:"ww:size-4 ww:shrink-0"}),(0,de.jsx)("span",{className:"ww:truncate",children:n?(0,de.jsx)(Pn,{duration:1.6,children:o}):o})]})}function _A({className:e,children:t,...a}){let{open:r}=(0,Et.useContext)(Vy);return(0,de.jsx)("div",{className:Z("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",r?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,de.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,de.jsx)("div",{className:Z("ww:mt-2 ww:space-y-3 ww:rounded-lg ww:border ww:border-border ww:bg-background ww:p-3",e),...a,children:t})})})}function OA({className:e,input:t,debug:a,...r}){let{t:n}=Ne(),o=(0,Et.useMemo)(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:l,...i}=t;return i}return t},[t,a]);return(0,de.jsx)(AA,{data:o,label:n.tool.request,className:e,...r})}function jy(e){if(!(typeof e!="object"||e===null))return e}function PA(e){return jy(e?.ui)}function NA(e){return jy(jy(e)?._meta)}function TA(e){if(!e)return;let t=PA(e)?.resourceUri;if(typeof t=="string"&&t.length>0)return t;let a=e["ui/resourceUri"];if(typeof a=="string"&&a.length>0)return a;let r=e["openai/outputTemplate"];if(typeof r=="string"&&r.length>0)return r}function MA(e){return PA(e)?.autoHeight===!0}function $d(e,t,a){if(e){let r=TA(a?.[e]?._meta);if(r)return r}return TA(NA(t))}function BA(e,t,a){return e&&MA(a?.[e]?._meta)?!0:MA(NA(t))}function UA({className:e,output:t,errorText:a,debug:r,...n}){let{t:o}=Ne(),l=(0,Et.useMemo)(()=>{if(!r&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:i,...s}=t;return s}return t},[t,r]);return t||a?a?(0,de.jsxs)("div",{className:Z("ww:space-y-2",e),...n,children:[(0,de.jsx)("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:o.tool.error}),(0,de.jsx)("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):(0,de.jsx)(AA,{data:l,label:o.tool.response,className:e,...n}):null}var Ns=F(re(),1);function hz(e){return e.type==="text"||e.type==="reasoning"||e.type==="file"||"toolCallId"in e}function Gy(e){return e.parts.some(hz)}function qA(e,t){if(t!=="submitted"&&t!=="streaming")return!1;let a=e[e.length-1];return!a||a.role!=="assistant"?!0:!Gy(a)}function zA({className:e,...t}){let{t:a}=Ne();return(0,Ns.jsxs)("div",{"aria-live":"polite",className:Z("ww:mb-4 ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...t,children:[(0,Ns.jsx)(ls,{className:"ww:size-4 ww:shrink-0"}),(0,Ns.jsx)(Pn,{duration:1.6,children:a.workingIndicator.default})]})}var Ye=F(_e(),1);function ql(e){if(!e)return!1;let t=Array.isArray(e.content)&&e.content.length>0,a=typeof e.structuredContent=="object"&&e.structuredContent!==null&&Object.keys(e.structuredContent).length>0;return t||a}function FA(e,t){return!ql(e)&&!ql(t)?null:ql(e)?ql(t)?{...e.content||t.content?{content:[...e.content??[],...t.content??[]]}:{},...e.structuredContent||t.structuredContent?{structuredContent:{...e.structuredContent??{},...t.structuredContent??{}}}:{}}:{...e.content?{content:[...e.content]}:{},...e.structuredContent?{structuredContent:{...e.structuredContent}}:{}}:{...t?.content?{content:[...t.content]}:{},...t?.structuredContent?{structuredContent:{...t.structuredContent}}:{}}}var jA=F(re(),1),gz="/api/mcp/resource",yz=500,xz=0,vz=16,wz="2026-01-26",bz=300,Sz=3e3,Cz=3;function Iz(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function Lz(e,t,a){return $d(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function HA({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:r=gz,chatSessionId:n,isDark:o=!1,className:l,autoHeight:i=!1,onOpenLink:s,onFollowUp:u,onCallTool:c,onDisplayModeChange:d,isFullscreen:f=!1,toolDefinitions:p}){let g=(0,Ye.useRef)(null),v=(0,Ye.useRef)(t),C=(0,Ye.useRef)(a),y=(0,Ye.useRef)({width:0,height:0}),x=(0,Ye.useRef)(null),h=(0,Ye.useRef)(!1),w=(0,Ye.useRef)(0),M=(0,Ye.useRef)("inline"),[b,A]=(0,Ye.useState)(xz),[D,P]=(0,Ye.useState)(void 0),k=(0,Ye.useRef)(s),U=(0,Ye.useRef)(u),E=(0,Ye.useRef)(c),q=(0,Ye.useRef)(d),$=(0,Ye.useRef)(n),V=(0,Ye.useRef)(p);v.current=t,C.current=a,k.current=s,U.current=u,E.current=c,q.current=d,$.current=n,V.current=p;let Y=(0,Ye.useCallback)(xe=>i?Math.max(xe+vz,0):Math.min(Math.max(xe,50),yz),[i]),be=(0,Ye.useMemo)(()=>{let xe=r.includes("?")?"&":"?";return`${r}${xe}uri=${encodeURIComponent(e)}`},[r,e]),Ve=(0,Ye.useRef)(o);return Ve.current=o,(0,Ye.useEffect)(()=>{if(!h.current)return;let xe=g.current;xe?.contentWindow&&xe.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:o?"dark":"light"}},"*")},[o]),(0,Ye.useEffect)(()=>{let xe=g.current;if(!xe)return;let I=!1,it=!1,nt=null,L=null,ut=setTimeout(()=>{if(I||it||w.current>=Cz)return;w.current+=1;let Ge=new URL(xe.src);Ge.searchParams.set("_retry",String(w.current)),xe.src=Ge.toString()},Sz),Ae=Ge=>{xe.contentWindow?.postMessage(Ge,"*")},kt=Ge=>{if(I||Ge.source!==xe.contentWindow)return;let se=Ge.data;if(!se||typeof se!="object"||se.jsonrpc!=="2.0")return;let De=se.method,ce=se.id;if(De==="ui/initialize"&&ce!=null){it=!0,clearTimeout(ut),Ae({jsonrpc:"2.0",id:ce,result:{protocolVersion:se.params?.protocolVersion??wz,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:Ve.current?"dark":"light",displayMode:M.current}}});return}if(De==="ui/notifications/initialized"){h.current=!0;let j=v.current,X=C.current,te=X._meta&&typeof X._meta=="object"?X._meta:null,Se=Iz($.current),$e=te&&typeof te.waniwani=="object"&&te.waniwani!==null?te.waniwani:null,bt=$e||Se?{...$e??{},...Se?{sessionId:Se}:{}}:void 0,ua=te||bt?{...te??{},...bt?{waniwani:bt}:{}}:void 0;Ae({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:j}});let Xr=X.content??[{type:"text",text:JSON.stringify(X)}];Ae({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:Xr,structuredContent:X.structuredContent,_meta:ua,meta:ua}});return}if(De==="ui/notifications/size-changed"){let j=se.params,X=typeof j?.height=="number"?j.height:void 0,te=typeof j?.width=="number"?j.width:void 0,Se=y.current,$e=X!==void 0&&X!==Se.height,bt=te!==void 0&&te!==Se.width;if(!$e&&!bt)return;if($e&&X!==void 0){Se.height=X;let ua=Y(X),Xr=xe.getBoundingClientRect().height;if(x.current&&(x.current.cancel(),x.current=null),A(ua),xe.animate&&Math.abs(Xr-ua)>2){let mr=xe.animate([{height:`${Xr}px`},{height:`${ua}px`}],{duration:bz,easing:"ease-out",fill:"forwards"});x.current=mr,mr.onfinish=()=>{x.current===mr&&(mr.cancel(),x.current=null)}}}bt&&i&&te!==void 0&&(Se.width=te,P(te));return}if(De==="ui/open-link"&&ce!=null){let j=se.params?.url;typeof j=="string"&&(k.current?k.current(j):window.open(j,"_blank","noopener,noreferrer")),Ae({jsonrpc:"2.0",id:ce,result:{}});return}if(De==="ui/message"&&ce!=null){if(U.current&&se.params){let j=se.params,X=nt;if(nt=null,L){clearTimeout(L.timer);let te=L.text;L=null;let Se=(j.content??[]).map($e=>$e.text??"").join("").trim();j={...j,content:[{type:"text",text:`${Se}
121
+ `||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Ey=e=>{let t=0;for(let a=0;a<e.length-1;a+=1)e[a]==="$"&&e[a+1]==="$"&&(t+=1,a+=1);return t},yA=e=>{let t=Xq.test(e),a=Zq.test(e);if(t||a)return[e];let r=Sa.lex(e,{gfm:!0}),n=[],o=[];for(let l of r){let i=l.raw,s=n.length;if(o.length>0){if(n[s-1]+=i,l.type==="html"){let u=i.match(Qq);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(l.type==="html"&&l.block){let u=i.match(Kq);if(u){let c=u[1];i.includes(`</${c}>`)||o.push(c)}}if(i.trim()==="$$"&&s>0){let u=n[s-1],c=Ay(u),d=Ey(u);if(c&&d%2===1){n[s-1]=u+i;continue}}if(s>0&&Yq(i)){let u=n[s-1],c=Ay(u),d=Ey(u),f=Ey(i);if(c&&d%2===1&&!Ay(i)&&f===1){n[s-1]=u+i;continue}}n.push(i)}return n},xA={raw:K0,sanitize:[Gc,{}],harden:[Z0,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},vA={gfm:[gd,{}]},Jq=Object.values(xA),ez=Object.values(vA),tz={block:" \u258B",circle:" \u25CF"},az={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},Yt=(0,R.createContext)(az),By=(0,R.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...r})=>(0,T.jsx)(gA,{...r,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return!1;if(e.components!==t.components){let a=Object.keys(e.components||{}),r=Object.keys(t.components||{});if(a.length!==r.length||a.some(n=>{var o,l;return((o=e.components)==null?void 0:o[n])!==((l=t.components)==null?void 0:l[n])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});By.displayName="Block";rz=["github-light","github-dark"],Ul=(0,R.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:r,rehypePlugins:n=Jq,remarkPlugins:o=ez,className:l,shikiTheme:i=rz,mermaid:s,controls:u=!0,isAnimating:c=!1,BlockComponent:d=By,parseMarkdownIntoBlocksFn:f=yA,caret:p,plugins:g,remend:v,linkSafety:C={enabled:!0},...y})=>{let x=(0,R.useId)(),[h,w]=(0,R.useTransition)(),M=(0,R.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?uL(e,v):e,[e,t,a,v]),b=(0,R.useMemo)(()=>f(M),[M,f]),[A,D]=(0,R.useState)(b);(0,R.useEffect)(()=>{t==="streaming"?w(()=>{D(b)}):D(b)},[b,t]);let P=t==="streaming"?A:b,k=(0,R.useMemo)(()=>P.map((Y,be)=>`${x}-${be}`),[P.length,x]),U=(0,R.useMemo)(()=>{var Y,be;return{shikiTheme:(be=(Y=g?.code)==null?void 0:Y.getThemes())!=null?be:i,controls:u,isAnimating:c,mode:t,mermaid:s,linkSafety:C}},[i,u,c,t,s,C,g?.code]),E=(0,R.useMemo)(()=>({...jq,...r}),[r]),q=(0,R.useMemo)(()=>{let Y=[];return g!=null&&g.cjk&&(Y=[...Y,...g.cjk.remarkPluginsBefore]),Y=[...Y,...o],g!=null&&g.cjk&&(Y=[...Y,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(Y=[...Y,g.math.remarkPlugin]),Y},[o,g?.math,g?.cjk]),$=(0,R.useMemo)(()=>g!=null&&g.math?[...n,g.math.rehypePlugin]:n,[n,g?.math]),V=(0,R.useMemo)(()=>p&&c?{"--streamdown-caret":`"${tz[p]}"`}:void 0,[p,c]);return t==="static"?(0,T.jsx)(Ry.Provider,{value:g??null,children:(0,T.jsx)(Yt.Provider,{value:U,children:(0,T.jsx)("div",{className:J("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:(0,T.jsx)(gA,{components:E,rehypePlugins:$,remarkPlugins:q,...y,children:e})})})}):(0,T.jsx)(Ry.Provider,{value:g??null,children:(0,T.jsx)(Yt.Provider,{value:U,children:(0,T.jsxs)("div",{className:J("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",p?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:V,children:[P.length===0&&p&&c&&(0,T.jsx)("span",{}),P.map((Y,be)=>(0,T.jsx)(d,{components:E,content:Y,index:be,rehypePlugins:$,remarkPlugins:q,shouldParseIncompleteMarkdown:a,...y},k[be]))]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety);Ul.displayName="Streamdown";nz=({children:e,className:t,minZoom:a=.5,maxZoom:r=3,zoomStep:n=.1,showControls:o=!0,initialZoom:l=1,fullscreen:i=!1})=>{let s=(0,R.useRef)(null),u=(0,R.useRef)(null),[c,d]=(0,R.useState)(l),[f,p]=(0,R.useState)({x:0,y:0}),[g,v]=(0,R.useState)(!1),[C,y]=(0,R.useState)({x:0,y:0}),[x,h]=(0,R.useState)({x:0,y:0}),w=(0,R.useCallback)(E=>{d(q=>Math.max(a,Math.min(r,q+E)))},[a,r]),M=(0,R.useCallback)(()=>{w(n)},[w,n]),b=(0,R.useCallback)(()=>{w(-n)},[w,n]),A=(0,R.useCallback)(()=>{d(l),p({x:0,y:0})},[l]),D=(0,R.useCallback)(E=>{E.preventDefault();let q=E.deltaY>0?-n:n;w(q)},[w,n]),P=(0,R.useCallback)(E=>{if(E.button!==0||E.isPrimary===!1)return;v(!0),y({x:E.clientX,y:E.clientY}),h(f);let q=E.currentTarget;q instanceof HTMLElement&&q.setPointerCapture(E.pointerId)},[f]),k=(0,R.useCallback)(E=>{if(!g)return;E.preventDefault();let q=E.clientX-C.x,$=E.clientY-C.y;p({x:x.x+q,y:x.y+$})},[g,C,x]),U=(0,R.useCallback)(E=>{v(!1);let q=E.currentTarget;q instanceof HTMLElement&&q.releasePointerCapture(E.pointerId)},[]);return(0,R.useEffect)(()=>{let E=s.current;if(E)return E.addEventListener("wheel",D,{passive:!1}),()=>{E.removeEventListener("wheel",D)}},[D]),(0,R.useEffect)(()=>{let E=u.current;if(E&&g)return document.body.style.userSelect="none",E.addEventListener("pointermove",k,{passive:!1}),E.addEventListener("pointerup",U),E.addEventListener("pointercancel",U),()=>{document.body.style.userSelect="",E.removeEventListener("pointermove",k),E.removeEventListener("pointerup",U),E.removeEventListener("pointercancel",U)}},[g,k,U]),(0,T.jsxs)("div",{className:J("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:g?"grabbing":"grab"},children:[o?(0,T.jsxs)("div",{className:J("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c>=r,onClick:M,title:"Zoom in",type:"button",children:(0,T.jsx)(wq,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c<=a,onClick:b,title:"Zoom out",type:"button",children:(0,T.jsx)(bq,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:A,title:"Reset zoom and pan",type:"button",children:(0,T.jsx)(vq,{size:16})})]}):null,(0,T.jsx)("div",{className:J("flex-1 origin-center transition-transform duration-150 ease-out",i?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:P,ref:u,role:"application",style:{transform:`translate(${f.x}px, ${f.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},Ty=({chart:e,className:t,config:a,fullscreen:r=!1,showControls:n=!0})=>{let[o,l]=(0,R.useState)(null),[i,s]=(0,R.useState)(!1),[u,c]=(0,R.useState)(""),[d,f]=(0,R.useState)(""),[p,g]=(0,R.useState)(0),{mermaid:v}=(0,R.useContext)(Yt),C=Py(),y=v?.errorComponent,{shouldRender:x,containerRef:h}=gq({immediate:r});if((0,R.useEffect)(()=>{if(x){if(!C){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),s(!0);let M=C.getMermaid(a),b=e.split("").reduce((P,k)=>(P<<5)-P+k.charCodeAt(0)|0,0),A=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:D}=await M.render(A,e);c(D),f(D)}catch(M){if(!(d||u)){let b=M instanceof Error?M.message:"Failed to render Mermaid chart";l(b)}}finally{s(!1)}})()}},[e,a,p,x,C]),!(x||u||d))return(0,T.jsx)("div",{className:J("my-4 min-h-[200px]",t),ref:h});if(i&&!u&&!d)return(0,T.jsx)("div",{className:J("my-4 flex justify-center p-4",t),ref:h,children:(0,T.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,T.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,T.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return y?(0,T.jsx)("div",{ref:h,children:(0,T.jsx)(y,{chart:e,error:o,retry:()=>g(b=>b+1)})}):(0,T.jsxs)("div",{className:J("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:h,children:[(0,T.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,T.jsxs)("details",{className:"mt-2",children:[(0,T.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,T.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let w=u||d;return(0,T.jsx)("div",{className:J("size-full",t),"data-streamdown":"mermaid",ref:h,children:(0,T.jsx)(nz,{className:J(r?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:r,maxZoom:3,minZoom:.5,showControls:n,zoomStep:.1,children:(0,T.jsx)("div",{"aria-label":"Mermaid chart",className:J("flex justify-center",r?"size-full items-center":null),dangerouslySetInnerHTML:{__html:w},role:"img"})})})}});var P2=Ht((Dte,O2)=>{"use strict";function z6(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let a,r=0;return function(...o){clearTimeout(a);let l=Date.now(),i=l-r,s=t-i;s<=0?(r=l,e.apply(this,o)):a=setTimeout(()=>{r=Date.now(),e.apply(this,o)},s)}}O2.exports=z6});var xx=F(_e(),1),mR=F(s0(),1);var hO="https://app.waniwani.ai/api/mcp/chat",gO={api:hO};function yO(){if(typeof document>"u")return null;if(document.currentScript instanceof HTMLScriptElement)return document.currentScript;let e=document.querySelectorAll("script[src]");for(let t of e)if(t instanceof HTMLScriptElement&&/embed/i.test(t.src))return t;return null}function Ac(){let e=yO();if(!e)return{};let t=h=>e.getAttribute(h)??void 0,a=h=>{let w=e.getAttribute(h);if(w==null)return;let M=w.trim().toLowerCase();if(M==="true"||M==="1"||M==="")return!0;if(M==="false"||M==="0")return!1},r={},n=t("data-api");n&&(r.api=n);let o=t("data-token");o&&(r.token=o);let l=t("data-title");l&&(r.title=l);let i=t("data-welcome-message");i&&(r.welcomeMessage=i);let s=t("data-placeholder");s&&(r.placeholder=s);let u=t("data-mcp-server-url");u&&(r.mcpServerUrl=u);let c=t("data-channel-id");c&&(r.channelId=c);let d=a("data-show-tool-calls");d!==void 0&&(r.showToolCalls=d);let f=t("data-css");f&&(r.css=f);let p=t("data-suggestions");p&&(r.suggestions=p.split(",").map(h=>h.trim()).filter(Boolean));let g=a("data-enable-thread-history");g!==void 0&&(r.enableThreadHistory=g);let v=a("data-hide-header");v!==void 0&&(r.hideHeader=v);let C=t("data-theme");(C==="light"||C==="dark"||C==="auto")&&(r.appearance={theme:C});let y=t("data-locale");(y==="en"||y==="fr"||y==="es")&&(r.locale=y);let x=t("data-disclaimer");if(x!==void 0){let h=x.trim(),w=h.toLowerCase();w==="false"||w==="0"?r.disclaimer=!1:h&&(r.disclaimer=h)}return r}function ah(e){if(!e)return{};let t={};for(let a in e)e[a]!==void 0&&(t[a]=e[a]);return t}function Xi(e,t,a){let r=a??Ac(),n=xO(t,r,e),o={token:"",...gO,...ah(t),...ah(r),...ah(e),...n?{appearance:n}:{}};if(!o.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return o}function xO(e,t,a){let r=a?.appearance?.theme??t.appearance?.theme??e?.appearance?.theme,n={...e?.appearance?.variables??{},...t.appearance?.variables??{},...a?.appearance?.variables??{}},o=Object.keys(n).length>0;if(!r&&!o)return;let l={};return r&&(l.theme=r),o&&(l.variables=n),l}var zn=F(_e(),1);var Rc=F(_e());var Ec=(...e)=>e.filter((t,a,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===a).join(" ").trim();var u0=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var c0=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,r)=>r?r.toUpperCase():a.toLowerCase());var rh=e=>{let t=c0(e);return t.charAt(0).toUpperCase()+t.slice(1)};var Zi=F(_e());var d0={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var f0=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var p0=(0,Zi.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:r,className:n="",children:o,iconNode:l,...i},s)=>(0,Zi.createElement)("svg",{ref:s,...d0,width:t,height:t,stroke:e,strokeWidth:r?Number(a)*24/Number(t):a,className:Ec("lucide",n),...!o&&!f0(i)&&{"aria-hidden":"true"},...i},[...l.map(([u,c])=>(0,Zi.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var He=(e,t)=>{let a=(0,Rc.forwardRef)(({className:r,...n},o)=>(0,Rc.createElement)(p0,{ref:o,iconNode:t,className:Ec(`lucide-${u0(rh(e))}`,`lucide-${e}`,r),...n}));return a.displayName=rh(e),a};var vO=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Qi=He("arrow-down",vO);var wO=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ki=He("arrow-up",wO);var bO=[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]],Br=He("braces",bO);var SO=[["path",{d:"M12 18V5",key:"adv99a"}],["path",{d:"M15 13a4.17 4.17 0 0 1-3-4 4.17 4.17 0 0 1-3 4",key:"1e3is1"}],["path",{d:"M17.598 6.5A3 3 0 1 0 12 5a3 3 0 1 0-5.598 1.5",key:"1gqd8o"}],["path",{d:"M17.997 5.125a4 4 0 0 1 2.526 5.77",key:"iwvgf7"}],["path",{d:"M18 18a4 4 0 0 0 2-7.464",key:"efp6ie"}],["path",{d:"M19.967 17.483A4 4 0 1 1 12 18a4 4 0 1 1-7.967-.517",key:"1gq6am"}],["path",{d:"M6 18a4 4 0 0 1-2-7.464",key:"k1g0md"}],["path",{d:"M6.003 5.125a4 4 0 0 0-2.526 5.77",key:"q97ue3"}]],Yi=He("brain",SO);var CO=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Ji=He("check",CO);var IO=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],so=He("chevron-down",IO);var LO=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],es=He("chevron-right",LO);var kO=[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2",key:"4jdomd"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v4",key:"3hqy98"}],["path",{d:"M21 14H11",key:"1bme5i"}],["path",{d:"m15 10-4 4 4 4",key:"5dvupr"}]],ts=He("clipboard-copy",kO);var TO=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}]],as=He("file",TO);var MO=[["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m16.2 7.8 2.9-2.9",key:"r700ao"}],["path",{d:"M18 12h4",key:"wj9ykh"}],["path",{d:"m16.2 16.2 2.9 2.9",key:"1bxg5t"}],["path",{d:"M12 18v4",key:"jadmvz"}],["path",{d:"m4.9 19.1 2.9-2.9",key:"bwix9q"}],["path",{d:"M2 12h4",key:"j09sii"}],["path",{d:"m4.9 4.9 2.9 2.9",key:"giyufr"}]],rs=He("loader",MO);var AO=[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]],ns=He("paperclip",AO);var EO=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],os=He("square",EO);var RO=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],uo=He("x",RO);var DO=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],ls=He("zap",DO);var Ze=F(_e(),1);var is=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,a)=>(a&=63,a<36?t+=a.toString(36):a<62?t+=(a-26).toString(36).toUpperCase():a>62?t+="-":t+="_",t),"");var Xe=F(_e(),1);var or=F(_e(),1);var m0=["en","fr","es"];function Ll(e){return m0.includes(e)}function Dc(e){if(e&&Ll(e))return e;if(e){let a=e.split("-")[0]?.toLowerCase();if(a&&Ll(a))return a}let t=[];if(typeof navigator<"u"&&(navigator.language&&t.push(navigator.language),navigator.languages&&t.push(...navigator.languages)),typeof document<"u"){let a=document.documentElement.getAttribute("lang");a&&t.push(a)}for(let a of t){let r=a.toLowerCase();if(Ll(r))return r;let n=r.split("-")[0];if(n&&Ll(n))return n}return"en"}var _c={promptInput:{placeholder:"What would you like to know?",uploadFiles:"Upload files",stop:"Stop",submit:"Submit",removeAttachments:"Remove all attachments"},workingIndicator:{default:"On it\u2026"},reasoning:{thinking:"Thinking\u2026",thoughtBrief:"Thought for a few seconds",thoughtForSeconds:e=>`Thought for ${e} second${e===1?"":"s"}`},tool:{copy:"Copy",copied:"Copied",request:"Request",response:"Response",error:"Error"},attachments:{attachmentFallback:"attachment",fileFallback:"file"},threadMenu:{newChat:"New chat",threadHistory:"Thread history",deleteThread:"Delete thread",noPreviousChats:"No previous chats yet.",hiddenThreads:e=>`${e} older thread${e===1?"":"s"} hidden`},chatQueue:{attachmentFallback:"(attachment)",removeFromQueue:"Remove from queue",queued:e=>`${e} queued`},poweredBy:{label:"AI agent powered by"},aiDisclaimer:{default:"can make mistakes"},exportSession:{saving:"saving...",saved:"saved",error:"error",export:"export",tooltip:"Save scenario to WaniWani"},widgetErrorBoundary:{failedToLoad:"Widget failed to load",retry:"Retry"}};var h0={promptInput:{placeholder:"\xBFQu\xE9 te gustar\xEDa saber?",uploadFiles:"Subir archivos",stop:"Detener",submit:"Enviar",removeAttachments:"Eliminar todos los archivos adjuntos"},workingIndicator:{default:"Un momento\u2026"},reasoning:{thinking:"Pensando\u2026",thoughtBrief:"Pens\xE9 durante unos segundos",thoughtForSeconds:e=>`Pens\xE9 durante ${e} segundo${e===1?"":"s"}`},tool:{copy:"Copiar",copied:"Copiado",request:"Solicitud",response:"Respuesta",error:"Error"},attachments:{attachmentFallback:"adjunto",fileFallback:"archivo"},threadMenu:{newChat:"Nuevo chat",threadHistory:"Historial",deleteThread:"Eliminar conversaci\xF3n",noPreviousChats:"A\xFAn no hay conversaciones anteriores.",hiddenThreads:e=>`${e} conversaci\xF3n${e===1?"":"es"} anterior${e===1?"":"es"} oculta${e===1?"":"s"}`},chatQueue:{attachmentFallback:"(adjunto)",removeFromQueue:"Quitar de la cola",queued:e=>`${e} en cola`},poweredBy:{label:"Agente IA con tecnolog\xEDa de"},aiDisclaimer:{default:"puede cometer errores"},exportSession:{saving:"guardando...",saved:"guardado",error:"error",export:"exportar",tooltip:"Guardar escenario en WaniWani"},widgetErrorBoundary:{failedToLoad:"No se pudo cargar el widget",retry:"Reintentar"}};var g0={promptInput:{placeholder:"Que souhaitez-vous savoir ?",uploadFiles:"Importer des fichiers",stop:"Arr\xEAter",submit:"Envoyer",removeAttachments:"Supprimer toutes les pi\xE8ces jointes"},workingIndicator:{default:"Un instant\u2026"},reasoning:{thinking:"R\xE9flexion\u2026",thoughtBrief:"R\xE9flexion de quelques secondes",thoughtForSeconds:e=>`R\xE9flexion de ${e} seconde${e===1?"":"s"}`},tool:{copy:"Copier",copied:"Copi\xE9",request:"Requ\xEAte",response:"R\xE9ponse",error:"Erreur"},attachments:{attachmentFallback:"pi\xE8ce jointe",fileFallback:"fichier"},threadMenu:{newChat:"Nouvelle conversation",threadHistory:"Historique",deleteThread:"Supprimer la conversation",noPreviousChats:"Aucune conversation pr\xE9c\xE9dente.",hiddenThreads:e=>`${e} conversation${e===1?"":"s"} plus ancienne${e===1?"":"s"} masqu\xE9e${e===1?"":"s"}`},chatQueue:{attachmentFallback:"(pi\xE8ce jointe)",removeFromQueue:"Retirer de la file",queued:e=>`${e} en file`},poweredBy:{label:"Agent IA propuls\xE9 par"},aiDisclaimer:{default:"peut faire des erreurs"},exportSession:{saving:"enregistrement...",saved:"enregistr\xE9",error:"erreur",export:"exporter",tooltip:"Enregistrer le sc\xE9nario dans WaniWani"},widgetErrorBoundary:{failedToLoad:"\xC9chec du chargement du widget",retry:"R\xE9essayer"}};var nh={en:_c,fr:g0,es:h0};var b0=F(re(),1),w0=(0,or.createContext)(null);function PO(e,t){if(!t)return e;let a={...e};for(let r of Object.keys(e)){let n=e[r],o=t[r];o&&typeof n=="object"&&(a[r]={...n,...o})}return a}function oh({children:e,locale:t,messages:a}){let[r,n]=(0,or.useState)(()=>typeof window>"u"?t&&NO(t)?t:"en":Dc(t));(0,or.useEffect)(()=>{n(Dc(t))},[t]);let o=(0,or.useMemo)(()=>{let l=nh[r]??nh["en"];return{locale:r,t:PO(l,a)}},[r,a]);return(0,b0.jsx)(w0.Provider,{value:o,children:e})}function NO(e){return e==="en"||e==="fr"||e==="es"}function Ne(){let e=(0,or.useContext)(w0);return e||{locale:"en",t:_c}}function lh(e,t){let a=Date.now()-e;if(a<6e4)try{return new Intl.RelativeTimeFormat(t,{numeric:"auto",style:"narrow"}).format(0,"second")}catch{return"just now"}let r,n;a<60*6e4?(r=-Math.floor(a/6e4),n="minute"):a<1440*6e4?(r=-Math.floor(a/(60*6e4)),n="hour"):(r=-Math.floor(a/(1440*6e4)),n="day");try{return new Intl.RelativeTimeFormat(t,{numeric:"auto",style:"short"}).format(r,n)}catch{return`${Math.abs(r)}${n==="minute"?"m":n==="hour"?"h":"d"} ago`}}ih();uh();var BO=C0({prefix:"ww"});function Z(...e){return BO(Pc(e))}var I0=F(re(),1),lr=({className:e,variant:t="default",size:a="default",type:r="button",...n})=>(0,I0.jsx)("button",{type:r,className:Z("ww:inline-flex ww:cursor-pointer ww:items-center ww:justify-center ww:rounded-md ww:font-medium ww:transition-colors ww:disabled:pointer-events-none ww:disabled:opacity-50",t==="default"&&"ww:bg-primary ww:text-primary-foreground ww:hover:bg-primary/90",t==="outline"&&"ww:border ww:border-border ww:bg-background ww:hover:bg-accent ww:hover:text-accent-foreground",t==="ghost"&&"ww:hover:bg-accent ww:hover:text-accent-foreground",a==="default"&&"ww:h-9 ww:px-4 ww:py-2 ww:text-sm",a==="sm"&&"ww:h-8 ww:px-3 ww:text-xs",a==="icon"&&"ww:size-9 ww:!rounded-full",a==="icon-sm"&&"ww:size-7 ww:!rounded-full",e),...n});var Zt=F(re(),1),UO=async e=>{try{let a=await(await fetch(e)).blob();return new Promise(r=>{let n=new FileReader;n.onloadend=()=>r(n.result),n.onerror=()=>r(null),n.readAsDataURL(a)})}catch{return null}},L0=(0,Xe.createContext)(null),k0=()=>{let e=(0,Xe.useContext)(L0);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},T0=({className:e,accept:t,multiple:a,globalDrop:r,maxFiles:n,maxFileSize:o,onSubmit:l,children:i,...s})=>{let{t:u}=Ne(),c=(0,Xe.useRef)(null),d=(0,Xe.useRef)(null),[f,p]=(0,Xe.useState)([]),g=(0,Xe.useRef)(f);(0,Xe.useEffect)(()=>{g.current=f},[f]);let v=(0,Xe.useCallback)(()=>{c.current?.click()},[]),C=(0,Xe.useCallback)(b=>{let A=[...b];if(A.length===0)return;let D=k=>o?k.size<=o:!0,P=A.filter(D);p(k=>{let U=typeof n=="number"?Math.max(0,n-k.length):void 0,E=typeof U=="number"?P.slice(0,U):P;return[...k,...E.map(q=>({filename:q.name,id:is(),mediaType:q.type,type:"file",url:URL.createObjectURL(q)}))]})},[n,o]),y=(0,Xe.useCallback)(b=>{p(A=>{let D=A.find(P=>P.id===b);return D?.url&&URL.revokeObjectURL(D.url),A.filter(P=>P.id!==b)})},[]),x=(0,Xe.useCallback)(()=>{p(b=>{for(let A of b)A.url&&URL.revokeObjectURL(A.url);return[]})},[]);(0,Xe.useEffect)(()=>()=>{for(let b of g.current)b.url&&URL.revokeObjectURL(b.url)},[]);let h=(0,Xe.useCallback)(b=>{b.currentTarget.files&&C(b.currentTarget.files),b.currentTarget.value=""},[C]);(0,Xe.useEffect)(()=>{if(!r)return;let b=D=>{D.dataTransfer?.types?.includes("Files")&&D.preventDefault()},A=D=>{D.dataTransfer?.types?.includes("Files")&&D.preventDefault(),D.dataTransfer?.files&&D.dataTransfer.files.length>0&&C(D.dataTransfer.files)};return document.addEventListener("dragover",b),document.addEventListener("drop",A),()=>{document.removeEventListener("dragover",b),document.removeEventListener("drop",A)}},[C,r]);let w=(0,Xe.useCallback)(async b=>{b.preventDefault();let A=b.currentTarget,P=new FormData(A).get("message")||"";A.reset();let k=await Promise.all(f.map(async({id:U,...E})=>{if(E.url?.startsWith("blob:")){let q=await UO(E.url);return{...E,url:q??E.url}}return E}));try{let U=l({files:k,text:P},b);U instanceof Promise&&await U,x()}catch{}},[f,l,x]),M=(0,Xe.useMemo)(()=>({add:C,clear:x,files:f,openFileDialog:v,remove:y}),[f,C,y,x,v]);return(0,Zt.jsxs)(L0.Provider,{value:M,children:[(0,Zt.jsx)("input",{accept:t,"aria-label":u.promptInput.uploadFiles,className:"ww:hidden",multiple:a,onChange:h,ref:c,title:u.promptInput.uploadFiles,type:"file"}),(0,Zt.jsx)("form",{className:Z("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:w,ref:d,...s,children:i})]})};var M0=({onChange:e,onKeyDown:t,className:a,placeholder:r,...n})=>{let{t:o}=Ne(),l=k0(),[i,s]=(0,Xe.useState)(!1),u=r??o.promptInput.placeholder,c=(0,Xe.useCallback)(f=>{if(t?.(f),!f.defaultPrevented){if(f.key==="Enter"){if(i||f.nativeEvent.isComposing||f.shiftKey)return;f.preventDefault();let{form:p}=f.currentTarget;if(p?.querySelector('button[type="submit"]')?.disabled)return;p?.requestSubmit()}if(f.key==="Backspace"&&f.currentTarget.value===""&&l.files.length>0){f.preventDefault();let p=l.files.at(-1);p&&l.remove(p.id)}}},[t,i,l]),d=(0,Xe.useCallback)(f=>{let p=f.clipboardData?.items;if(!p)return;let g=[];for(let v of p)if(v.kind==="file"){let C=v.getAsFile();C&&g.push(C)}g.length>0&&(f.preventDefault(),l.add(g))},[l]);return(0,Zt.jsx)("textarea",{className:Z("ww:field-sizing-content ww:max-h-48 ww:min-h-0 ww:w-full ww:resize-none ww:border-0 ww:bg-transparent ww:px-3 ww:py-2 ww:text-base ww:sm:text-sm ww:outline-none ww:placeholder:text-muted-foreground",a),name:"message",onCompositionEnd:()=>s(!1),onCompositionStart:()=>s(!0),onKeyDown:c,onPaste:d,placeholder:u,onChange:e,...n})},A0=({className:e,status:t,onStop:a,onClick:r,children:n,...o})=>{let{t:l}=Ne(),i=t==="submitted"||t==="streaming",s=(0,Zt.jsx)(Ki,{className:"ww:size-4"});t==="submitted"?s=(0,Zt.jsx)(rs,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(s=(0,Zt.jsx)(os,{className:"ww:size-4"}));let u=(0,Xe.useCallback)(c=>{if(i&&a){c.preventDefault(),a();return}r?.(c)},[i,a,r]);return(0,Zt.jsx)(lr,{"aria-label":i?l.promptInput.stop:l.promptInput.submit,className:Z("ww:bg-foreground ww:text-background ww:hover:bg-foreground ww:rounded-full",e),onClick:u,size:"icon-sm",type:i&&a?"button":"submit",variant:"ghost",...o,children:n??s})},E0=({className:e,children:t,...a})=>{let{t:r}=Ne(),n=k0();return n.files.length>0?(0,Zt.jsxs)(lr,{className:Z("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":r.promptInput.removeAttachments,...a,children:[(0,Zt.jsx)("span",{className:"ww:flex ww:size-5 ww:items-center ww:justify-center ww:rounded-full ww:bg-primary ww:text-[10px] ww:font-medium ww:text-primary-foreground ww:transition-opacity ww:group-hover:opacity-0",children:n.files.length}),(0,Zt.jsx)(uo,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):(0,Zt.jsx)(lr,{className:Z(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...a,children:t??(0,Zt.jsx)(ns,{className:"ww:size-4"})})};var D0=F(re(),1);function R0({text:e}){let{t}=Ne();return e===!1?null:(0,D0.jsx)("span",{className:"ww:text-[11px] ww:text-muted-foreground ww:opacity-70",children:e||t.aiDisclaimer.default})}var Nc=F(_e(),1);var co=F(re(),1),_0=({className:e,...t})=>(0,co.jsx)("div",{className:Z("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),O0=({className:e,...t})=>(0,co.jsx)("li",{className:Z("ww:group ww:flex ww:items-center ww:gap-2 ww:rounded-md ww:px-2 ww:py-1 ww:text-sm ww:transition-colors ww:hover:bg-muted",e),...t}),P0=({className:e,...t})=>(0,co.jsx)("span",{className:Z("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),N0=({className:e,...t})=>(0,co.jsx)("span",{className:Z("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),B0=({className:e,...t})=>(0,co.jsx)("div",{className:Z("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),U0=({className:e,...t})=>(0,co.jsx)(lr,{className:Z("ww:size-auto ww:rounded ww:p-1 ww:text-muted-foreground ww:hover:bg-muted-foreground/10 ww:hover:text-foreground",e),size:"icon",type:"button",variant:"ghost",...t});var Ba=F(re(),1),q0=(0,Nc.memo)(({message:e,onRemove:t})=>{let{t:a}=Ne(),r=(0,Nc.useCallback)(()=>t(e.id),[t,e.id]);return(0,Ba.jsxs)(O0,{children:[(0,Ba.jsx)(P0,{}),(0,Ba.jsx)(N0,{children:e.text||a.chatQueue.attachmentFallback}),(0,Ba.jsx)(B0,{children:(0,Ba.jsx)(U0,{"aria-label":a.chatQueue.removeFromQueue,onClick:r,children:(0,Ba.jsx)(uo,{className:"ww:size-3"})})})]})});q0.displayName="ChatQueueItem";function z0({queuedMessages:e,onRemove:t,className:a}){let{t:r}=Ne();return e.length===0?null:(0,Ba.jsxs)(_0,{className:Z("ww:border-t ww:border-border",a),children:[(0,Ba.jsx)("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:r.chatQueue.queued(e.length)}),(0,Ba.jsx)("ul",{children:e.map(n=>(0,Ba.jsx)(q0,{message:n,onRemove:t},n.id))})]})}var In=F(re(),1),F0=({files:e,className:t,...a})=>e.length===0?null:(0,In.jsx)("div",{className:Z("ww:flex ww:flex-wrap ww:gap-1.5",t),...a,children:e.map((r,n)=>(0,In.jsx)(qO,{file:r},n))});function qO({file:e}){let{t}=Ne();return e.mediaType?.startsWith("image/")&&e.url?(0,In.jsx)("img",{src:e.url,alt:e.filename??t.attachments.attachmentFallback,className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):(0,In.jsxs)("span",{className:"ww:inline-flex ww:items-center ww:gap-1.5 ww:rounded ww:bg-background/20 ww:px-2 ww:py-1 ww:text-xs",children:[(0,In.jsx)(as,{className:"ww:size-3 ww:shrink-0"}),(0,In.jsx)("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??t.attachments.fileFallback})]})}var ch={name:"cjk-noop",type:"cjk",remarkPluginsBefore:[],remarkPluginsAfter:[],remarkPlugins:[]};var H0={name:"shiki-noop",type:"code-highlighter",supportsLanguage:()=>!1,getSupportedLanguages:()=>[],getThemes:()=>["github-light","github-dark"],highlight:()=>null};var SA=F(_e(),1);zd();var Gr=F(_e(),1),oz=5,wA=400;function bA(e,t,a={}){let{msPerChar:r=oz}=a,[n,o]=(0,Gr.useState)(t?"":e),l=(0,Gr.useRef)(e),i=(0,Gr.useRef)(t?0:e.length),s=(0,Gr.useRef)(0),u=(0,Gr.useRef)(null);return(e.length<i.current||!e.startsWith(n.slice(0,i.current)))&&(i.current=t?0:e.length),l.current=e,(0,Gr.useEffect)(()=>{if(!t){u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),i.current=e.length,o(e);return}if(l.current.length-i.current>wA&&(i.current=l.current.length-wA),u.current!==null)return;let d=f=>{let p=l.current;if(i.current>=p.length){u.current=null;return}s.current===0&&(s.current=f);let g=f-s.current;if(g>=r){let v=Math.min(Math.floor(g/r),p.length-i.current);i.current+=v,o(p.slice(0,i.current)),s.current=f}u.current=requestAnimationFrame(d)};return u.current=requestAnimationFrame(d),()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[e,t,r]),n}var Ps=F(re(),1),Uy=({className:e,from:t,children:a,...r})=>(0,Ps.jsx)("div",{className:Z("ww:group ww:flex ww:w-full",t==="user"?"is-user ww:ml-auto ww:max-w-[80%] ww:flex-col ww:items-end":"is-assistant ww:flex-col",e),...r,children:(0,Ps.jsx)("div",{className:Z("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),qy=({children:e,className:t,...a})=>(0,Ps.jsx)("div",{className:Z("ww:flex ww:w-fit ww:min-w-0 ww:max-w-full ww:flex-col ww:gap-2 ww:overflow-hidden ww:text-base","ww:group-[.is-user]:ml-auto ww:group-[.is-user]:rounded-lg ww:group-[.is-user]:bg-user-bubble ww:group-[.is-user]:px-4 ww:group-[.is-user]:py-3 ww:group-[.is-user]:text-primary-foreground","ww:group-[.is-assistant]:text-foreground",t),...a,children:e}),lz={cjk:ch,code:H0},iz={cjk:ch},sz={enabled:!1};function uz({className:e,linkSafety:t,isStreaming:a,children:r,...n}){let l=bA(typeof r=="string"?r:"",!!a),i=typeof r=="string"?l:r;return(0,Ps.jsx)(Ul,{className:Z("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),linkSafety:t??sz,plugins:a?iz:lz,...n,children:i})}var Gd=(0,SA.memo)(uz,(e,t)=>e.children===t.children&&e.isStreaming===t.isStreaming);Gd.displayName="MessageResponse";var st=F(_e(),1);var CA=F(_e(),1);var IA=F(re(),1),cz=({as:e="span",className:t,duration:a=2,style:r,children:n,...o})=>{let l={backgroundImage:"linear-gradient(90deg, var(--ww-color-muted-foreground) 0%, var(--ww-color-muted-foreground) 40%, var(--ww-color-foreground) 50%, var(--ww-color-muted-foreground) 60%, var(--ww-color-muted-foreground) 100%)",backgroundSize:"250% 100%",WebkitBackgroundClip:"text",backgroundClip:"text",color:"transparent",animation:`ww-shimmer ${a}s linear infinite`,...r};return(0,IA.jsx)(e,{"data-waniwani-shimmer":"",className:Z("ww:inline-block",t),style:l,...o,children:n})},Pn=(0,CA.memo)(cz);Pn.displayName="Shimmer";var Ft=F(re(),1),LA=(0,st.createContext)(null);function kA(){let e=(0,st.useContext)(LA);if(!e)throw new Error("Reasoning components must be used within <Reasoning>");return e}var dz=1e3,fz=1e3,zy=(0,st.memo)(({className:e,isStreaming:t=!1,open:a,defaultOpen:r,onOpenChange:n,duration:o,children:l,...i})=>{let s=r??t,u=r===!1,c=a!==void 0,[d,f]=(0,st.useState)(s),p=c?a:d,g=(0,st.useCallback)(A=>{c||f(A),n?.(A)},[c,n]),[v,C]=(0,st.useState)(void 0),y=o??v,x=(0,st.useRef)(t),[h,w]=(0,st.useState)(!1),M=(0,st.useRef)(null);(0,st.useEffect)(()=>{t?(x.current=!0,M.current===null&&(M.current=Date.now())):M.current!==null&&(C(Math.ceil((Date.now()-M.current)/fz)),M.current=null)},[t]),(0,st.useEffect)(()=>{t&&!p&&!u&&g(!0)},[t,p,u,g]),(0,st.useEffect)(()=>{if(x.current&&!t&&p&&!h){let A=setTimeout(()=>{g(!1),w(!0)},dz);return()=>clearTimeout(A)}},[t,p,h,g]);let b=(0,st.useMemo)(()=>({isStreaming:t,isOpen:p,setIsOpen:g,duration:y}),[t,p,g,y]);return(0,Ft.jsx)(LA.Provider,{value:b,children:(0,Ft.jsx)("div",{className:Z("ww:mb-4 ww:flex ww:flex-col ww:gap-2",e),"data-state":p?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...i,children:l})})});zy.displayName="Reasoning";var Fy=(0,st.memo)(({className:e,children:t,getThinkingMessage:a,onClick:r,...n})=>{let{t:o}=Ne(),{isStreaming:l,isOpen:i,duration:s,setIsOpen:u}=kA(),d=a??((f,p)=>f||p===0?(0,Ft.jsx)(Pn,{duration:1.6,children:o.reasoning.thinking}):p===void 0?(0,Ft.jsx)("span",{children:o.reasoning.thoughtBrief}):(0,Ft.jsx)("span",{children:o.reasoning.thoughtForSeconds(p)}));return(0,Ft.jsx)("button",{type:"button","aria-expanded":i,onClick:f=>{u(!i),r?.(f)},className:Z("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),...n,children:t??(0,Ft.jsxs)(Ft.Fragment,{children:[(0,Ft.jsx)(Yi,{className:"ww:size-4 ww:shrink-0"}),d(l,s),(0,Ft.jsx)(so,{className:Z("ww:size-4 ww:shrink-0 ww:transition-transform ww:duration-200",i&&"ww:rotate-180")})]})})});Fy.displayName="ReasoningTrigger";var Hy=(0,st.memo)(({className:e,children:t,...a})=>{let{isOpen:r}=kA();return(0,Ft.jsx)("div",{className:Z("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",r?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,Ft.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,Ft.jsx)("div",{className:Z("ww:text-sm ww:text-muted-foreground",e),...a,children:(0,Ft.jsx)(Ul,{children:t})})})})});Hy.displayName="ReasoningContent";var Et=F(_e(),1);var de=F(re(),1);function pz(e,t=80){if(e==null)return String(e);if(typeof e!="object")return String(e).slice(0,t);if(Array.isArray(e))return`Array(${e.length})`;let a=JSON.stringify(e);if(a.length<=t)return a;let r=Object.entries(e),n=[],o=t-2;for(let[l,i]of r){if(o<=8)break;let s=l.length>4?`${l.slice(0,4)}\u2026`:l,u;typeof i=="string"?u=i.length>2?`'${i.slice(0,1)}\u2026`:`'${i}'`:Array.isArray(i)?u=`Array(${i.length})`:typeof i=="object"&&i!==null?u="{\u2026}":u=String(i);let c=`${s}\u2009${u}`;n.push(c),o-=c.length+3}return`{${n.join(", ")}}`}function mz({text:e,className:t}){let{t:a}=Ne(),[r,n]=(0,Et.useState)(!1),o=(0,Et.useRef)(null);(0,Et.useEffect)(()=>()=>{o.current&&clearTimeout(o.current)},[]);let l=(0,Et.useCallback)(async i=>{i.stopPropagation();try{await navigator.clipboard.writeText(e),n(!0),o.current&&clearTimeout(o.current),o.current=setTimeout(()=>n(!1),2e3)}catch{}},[e]);return(0,de.jsx)(lr,{variant:"ghost",size:"sm",onClick:l,className:Z("ww:h-auto ww:gap-1 ww:px-1.5 ww:py-0.5 ww:text-xs ww:text-muted-foreground ww:hover:text-foreground",t),children:r?(0,de.jsxs)(de.Fragment,{children:[(0,de.jsx)(Ji,{className:"ww:size-3.5"}),(0,de.jsx)("span",{children:a.tool.copied})]}):(0,de.jsxs)(de.Fragment,{children:[(0,de.jsx)(ts,{className:"ww:size-3.5"}),(0,de.jsx)("span",{children:a.tool.copy})]})})}function AA({data:e,label:t,className:a,...r}){let[n,o]=(0,Et.useState)(!1),l=(0,Et.useMemo)(()=>JSON.stringify(e,null,2),[e]),i=pz(e);return(0,de.jsxs)("div",{className:Z("ww:rounded-lg ww:bg-tool-card",a),...r,children:[(0,de.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[(0,de.jsx)("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),(0,de.jsx)(mz,{text:l})]}),(0,de.jsxs)("button",{type:"button",onClick:()=>o(s=>!s),className:"ww:flex ww:w-full ww:items-start ww:gap-2 ww:px-3 ww:pb-3 ww:text-left",children:[(0,de.jsx)(es,{className:Z("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",n&&"ww:rotate-90")}),n?(0,de.jsx)("pre",{className:"ww:overflow-x-auto ww:text-xs ww:font-mono ww:text-foreground ww:whitespace-pre-wrap ww:break-all",children:(0,de.jsx)("code",{children:l})}):(0,de.jsx)("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var Vy=(0,Et.createContext)({open:!1,toggle:()=>{}});function EA({className:e,defaultOpen:t=!1,children:a,...r}){let[n,o]=(0,Et.useState)(t);return(0,de.jsx)(Vy.Provider,{value:{open:n,toggle:()=>o(l=>!l)},children:(0,de.jsx)("div",{className:Z("ww:mb-4 ww:w-full",e),"data-state":n?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...r,children:a})})}function RA({className:e,title:t,state:a,...r}){let{open:n,toggle:o}=(0,Et.useContext)(Vy),l=a==="input-available"||a==="input-streaming",i=t??"";return(0,de.jsxs)("button",{type:"button",onClick:o,className:Z("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),"aria-expanded":n,...r,children:[(0,de.jsx)(Br,{className:"ww:size-4 ww:shrink-0"}),(0,de.jsx)("span",{className:"ww:truncate",children:l?(0,de.jsx)(Pn,{duration:1.6,children:i}):i}),(0,de.jsx)(so,{className:Z("ww:size-4 ww:shrink-0 ww:transition-transform ww:duration-200",n&&"ww:rotate-180")})]})}function DA({className:e,title:t,state:a,...r}){let n=a==="input-available"||a==="input-streaming",o=t??"";return(0,de.jsxs)("div",{className:Z("ww:mb-4 ww:flex ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...r,children:[(0,de.jsx)(Br,{className:"ww:size-4 ww:shrink-0"}),(0,de.jsx)("span",{className:"ww:truncate",children:n?(0,de.jsx)(Pn,{duration:1.6,children:o}):o})]})}function _A({className:e,children:t,...a}){let{open:r}=(0,Et.useContext)(Vy);return(0,de.jsx)("div",{className:Z("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",r?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,de.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,de.jsx)("div",{className:Z("ww:mt-2 ww:space-y-3 ww:rounded-lg ww:border ww:border-border ww:bg-background ww:p-3",e),...a,children:t})})})}function OA({className:e,input:t,debug:a,...r}){let{t:n}=Ne(),o=(0,Et.useMemo)(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:l,...i}=t;return i}return t},[t,a]);return(0,de.jsx)(AA,{data:o,label:n.tool.request,className:e,...r})}function jy(e){if(!(typeof e!="object"||e===null))return e}function PA(e){return jy(e?.ui)}function NA(e){return jy(jy(e)?._meta)}function TA(e){if(!e)return;let t=PA(e)?.resourceUri;if(typeof t=="string"&&t.length>0)return t;let a=e["ui/resourceUri"];if(typeof a=="string"&&a.length>0)return a;let r=e["openai/outputTemplate"];if(typeof r=="string"&&r.length>0)return r}function MA(e){return PA(e)?.autoHeight===!0}function $d(e,t,a){if(e){let r=TA(a?.[e]?._meta);if(r)return r}return TA(NA(t))}function BA(e,t,a){return e&&MA(a?.[e]?._meta)?!0:MA(NA(t))}function UA({className:e,output:t,errorText:a,debug:r,...n}){let{t:o}=Ne(),l=(0,Et.useMemo)(()=>{if(!r&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:i,...s}=t;return s}return t},[t,r]);return t||a?a?(0,de.jsxs)("div",{className:Z("ww:space-y-2",e),...n,children:[(0,de.jsx)("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:o.tool.error}),(0,de.jsx)("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):(0,de.jsx)(AA,{data:l,label:o.tool.response,className:e,...n}):null}var Ns=F(re(),1);function hz(e){return e.type==="text"||e.type==="reasoning"||e.type==="file"||"toolCallId"in e}function Gy(e){return e.parts.some(hz)}function qA(e,t){if(t!=="submitted"&&t!=="streaming")return!1;let a=e[e.length-1];return!a||a.role!=="assistant"?!0:!Gy(a)}function zA({className:e,...t}){let{t:a}=Ne();return(0,Ns.jsxs)("div",{"aria-live":"polite",className:Z("ww:mb-4 ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...t,children:[(0,Ns.jsx)(ls,{className:"ww:size-4 ww:shrink-0"}),(0,Ns.jsx)(Pn,{duration:1.6,children:a.workingIndicator.default})]})}var Ye=F(_e(),1);function ql(e){if(!e)return!1;let t=Array.isArray(e.content)&&e.content.length>0,a=typeof e.structuredContent=="object"&&e.structuredContent!==null&&Object.keys(e.structuredContent).length>0;return t||a}function FA(e,t){return!ql(e)&&!ql(t)?null:ql(e)?ql(t)?{...e.content||t.content?{content:[...e.content??[],...t.content??[]]}:{},...e.structuredContent||t.structuredContent?{structuredContent:{...e.structuredContent??{},...t.structuredContent??{}}}:{}}:{...e.content?{content:[...e.content]}:{},...e.structuredContent?{structuredContent:{...e.structuredContent}}:{}}:{...t?.content?{content:[...t.content]}:{},...t?.structuredContent?{structuredContent:{...t.structuredContent}}:{}}}var jA=F(re(),1),gz="/api/mcp/resource",yz=500,xz=0,vz=16,wz="2026-01-26",bz=300,Sz=3e3,Cz=3;function Iz(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function Lz(e,t,a){return $d(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function HA({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:r=gz,chatSessionId:n,isDark:o=!1,className:l,autoHeight:i=!1,onOpenLink:s,onFollowUp:u,onCallTool:c,onDisplayModeChange:d,isFullscreen:f=!1,toolDefinitions:p}){let g=(0,Ye.useRef)(null),v=(0,Ye.useRef)(t),C=(0,Ye.useRef)(a),y=(0,Ye.useRef)({width:0,height:0}),x=(0,Ye.useRef)(null),h=(0,Ye.useRef)(!1),w=(0,Ye.useRef)(0),M=(0,Ye.useRef)("inline"),[b,A]=(0,Ye.useState)(xz),[D,P]=(0,Ye.useState)(void 0),k=(0,Ye.useRef)(s),U=(0,Ye.useRef)(u),E=(0,Ye.useRef)(c),q=(0,Ye.useRef)(d),$=(0,Ye.useRef)(n),V=(0,Ye.useRef)(p);v.current=t,C.current=a,k.current=s,U.current=u,E.current=c,q.current=d,$.current=n,V.current=p;let Y=(0,Ye.useCallback)(xe=>i?Math.max(xe+vz,0):Math.min(Math.max(xe,50),yz),[i]),be=(0,Ye.useMemo)(()=>{let xe=r.includes("?")?"&":"?";return`${r}${xe}uri=${encodeURIComponent(e)}`},[r,e]),Ve=(0,Ye.useRef)(o);return Ve.current=o,(0,Ye.useEffect)(()=>{if(!h.current)return;let xe=g.current;xe?.contentWindow&&xe.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:o?"dark":"light"}},"*")},[o]),(0,Ye.useEffect)(()=>{let xe=g.current;if(!xe)return;let I=!1,it=!1,nt=null,L=null,ut=setTimeout(()=>{if(I||it||w.current>=Cz)return;w.current+=1;let Ge=new URL(xe.src);Ge.searchParams.set("_retry",String(w.current)),xe.src=Ge.toString()},Sz),Ae=Ge=>{xe.contentWindow?.postMessage(Ge,"*")},kt=Ge=>{if(I||Ge.source!==xe.contentWindow)return;let se=Ge.data;if(!se||typeof se!="object"||se.jsonrpc!=="2.0")return;let De=se.method,ce=se.id;if(De==="ui/initialize"&&ce!=null){it=!0,clearTimeout(ut),Ae({jsonrpc:"2.0",id:ce,result:{protocolVersion:se.params?.protocolVersion??wz,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:Ve.current?"dark":"light",displayMode:M.current}}});return}if(De==="ui/notifications/initialized"){h.current=!0;let j=v.current,X=C.current,te=X._meta&&typeof X._meta=="object"?X._meta:null,Se=Iz($.current),$e=te&&typeof te.waniwani=="object"&&te.waniwani!==null?te.waniwani:null,bt=$e||Se?{...$e??{},...Se?{sessionId:Se}:{}}:void 0,ua=te||bt?{...te??{},...bt?{waniwani:bt}:{}}:void 0;Ae({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:j}});let Xr=X.content??[{type:"text",text:JSON.stringify(X)}];Ae({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:Xr,structuredContent:X.structuredContent,_meta:ua,meta:ua}});return}if(De==="ui/notifications/size-changed"){let j=se.params,X=typeof j?.height=="number"?j.height:void 0,te=typeof j?.width=="number"?j.width:void 0,Se=y.current,$e=X!==void 0&&X!==Se.height,bt=te!==void 0&&te!==Se.width;if(!$e&&!bt)return;if($e&&X!==void 0){Se.height=X;let ua=Y(X),Xr=xe.getBoundingClientRect().height;if(x.current&&(x.current.cancel(),x.current=null),A(ua),xe.animate&&Math.abs(Xr-ua)>2){let mr=xe.animate([{height:`${Xr}px`},{height:`${ua}px`}],{duration:bz,easing:"ease-out",fill:"forwards"});x.current=mr,mr.onfinish=()=>{x.current===mr&&(mr.cancel(),x.current=null)}}}bt&&i&&te!==void 0&&(Se.width=te,P(te));return}if(De==="ui/open-link"&&ce!=null){let j=se.params?.url;typeof j=="string"&&(k.current?k.current(j):window.open(j,"_blank","noopener,noreferrer")),Ae({jsonrpc:"2.0",id:ce,result:{}});return}if(De==="ui/message"&&ce!=null){if(U.current&&se.params){let j=se.params,X=nt;if(nt=null,L){clearTimeout(L.timer);let te=L.text;L=null;let Se=(j.content??[]).map($e=>$e.text??"").join("").trim();j={...j,content:[{type:"text",text:`${Se}
122
122
 
123
123
  ${te}`}]}}U.current({...j,...X?{modelContext:X}:{}})}Ae({jsonrpc:"2.0",id:ce,result:{}});return}if(De==="ui/update-model-context"&&ce!=null){nt=FA(nt,se.params),Ae({jsonrpc:"2.0",id:ce,result:{}});return}if(De==="tools/call"&&ce!=null){let j=E.current;if(!j){Ae({jsonrpc:"2.0",id:ce,error:{code:-32601,message:"tools/call not supported"}});return}let X=se.params?.name;j({name:X,arguments:se.params?.arguments??{}}).then(te=>{Ae({jsonrpc:"2.0",id:ce,result:te});let Se=te.content?.map($e=>$e.text??"").join("").trim();Se&&Lz(X,te,V.current)&&(L&&clearTimeout(L.timer),L={text:Se,timer:setTimeout(()=>{if(I)return;let $e=nt;nt=null,L=null,U.current?.({role:"user",content:[{type:"text",text:Se}],...$e?{modelContext:$e}:{}})},500)})}).catch(te=>{let Se=te instanceof Error?te.message:"Tool call failed";Ae({jsonrpc:"2.0",id:ce,error:{code:-32e3,message:Se}})});return}if(De==="ui/request-display-mode"&&ce!=null){let j=se.params?.mode,X=j==="fullscreen"||j==="inline"||j==="pip"?j:"inline";M.current=X,Ae({jsonrpc:"2.0",id:ce,result:{mode:X}}),Ae({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:X}}),q.current?.(X);return}if(De==="ui/resource-teardown"&&ce!=null){Ae({jsonrpc:"2.0",id:ce,result:{}});return}De==="ping"&&ce!=null&&Ae({jsonrpc:"2.0",id:ce,result:{}})};return window.addEventListener("message",kt),()=>{I=!0,clearTimeout(ut),L&&clearTimeout(L.timer),window.removeEventListener("message",kt)}},[i,Y]),(0,jA.jsx)("iframe",{ref:g,src:be,sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox",className:Z(!f&&"ww:rounded-md ww:border ww:border-border",l),style:{height:f?"100%":b,minWidth:f||!D?void 0:`min(${D}px, 100%)`,width:"100%",border:"none",colorScheme:o?"dark":"auto"},title:"MCP App"})}var Nn=F(re(),1);function VA({icon:e,title:t,description:a,suggestions:r,onSuggestionSelect:n}){return(0,Nn.jsxs)("div",{className:"ww:flex ww:flex-col ww:items-center ww:justify-center ww:py-12 ww:px-6 ww:text-center ww:min-h-full",children:[e&&(0,Nn.jsx)("div",{className:"ww:mb-4 ww:flex ww:items-center ww:justify-center ww:size-12 ww:rounded-xl ww:bg-foreground ww:text-background",children:e}),(0,Nn.jsx)("h2",{className:"ww:text-lg ww:font-semibold ww:text-foreground",children:t}),a&&(0,Nn.jsx)("p",{className:"ww:mt-1 ww:text-sm ww:text-muted-foreground ww:max-w-sm",children:a}),r&&r.length>0&&(0,Nn.jsx)("div",{className:"ww:mt-6 ww:w-full ww:max-w-md ww:flex ww:flex-col ww:gap-2",children:r.map((o,l)=>(0,Nn.jsx)("button",{type:"button",onClick:()=>n?.(o),className:Z("ww:w-full ww:text-left ww:rounded-xl ww:border ww:border-border ww:bg-background ww:px-4 ww:py-3 ww:text-sm","ww:text-foreground ww:hover:bg-accent ww:hover:border-primary/30","ww:transition-all ww:duration-200 ww:ease-out ww:cursor-pointer","ww:animate-[ww-fade-in_0.2s_ease-out_both]"),style:{animationDelay:`${l*50}ms`},children:o},o))})]})}var GA=F(_e(),1);var zl=F(re(),1);function kz({onRetry:e}){let{t}=Ne();return(0,zl.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:rounded-md ww:border ww:border-border ww:bg-muted/50 ww:px-4 ww:py-3 ww:text-sm ww:text-muted-foreground",children:[(0,zl.jsx)("span",{children:t.widgetErrorBoundary.failedToLoad}),(0,zl.jsx)("button",{type:"button",onClick:e,className:"ww:text-xs ww:font-medium ww:text-primary ww:hover:underline",children:t.widgetErrorBoundary.retry})]})}var Wd=class extends GA.Component{constructor(){super(...arguments);Ie(this,"state",{hasError:!1})}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(a){console.warn("[WaniWani] Widget failed to render:",a.message)}render(){return this.state.hasError?(0,zl.jsx)(kz,{onRetry:()=>this.setState({hasError:!1})}):this.props.children}};var Re=F(re(),1);function $A(e){return e?e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase()):"Tool"}function WA({messages:e,status:t,welcomeMessage:a,welcome:r,onSuggestionSelect:n,resourceEndpoint:o,chatSessionId:l,isDark:i,onFollowUp:s,onCallTool:u,onWidgetDisplayModeChange:c,fullscreenToolCallId:d,debug:f,showToolCalls:p=!0,toolDefinitions:g}){let v=e[e.length-1],C=e.length>0,y=d!=null,x=!y&&qA(e,t);return(0,Re.jsxs)(Re.Fragment,{children:[!y&&(!C&&r?(0,Re.jsx)(VA,{...r,onSuggestionSelect:n}):a&&(0,Re.jsx)(Uy,{from:"assistant",children:(0,Re.jsx)(qy,{children:(0,Re.jsx)(Gd,{children:a})})})),e.map(h=>{let w=h.parts.filter(U=>U.type==="text"),M=h.parts.filter(U=>U.type==="reasoning"),b=h.parts.filter(U=>U.type==="file"),A=h.parts.filter(U=>"toolCallId"in U),D=h===v&&h.role==="assistant",P=w.length>0,k=y?A.some(U=>U.toolCallId===d):!1;return y&&!k?(0,Re.jsx)("div",{style:{display:"none"}},h.id):h.role==="assistant"&&!Gy(h)?(0,Re.jsx)("div",{style:{display:"none"}},h.id):(0,Re.jsxs)(Uy,{from:h.role,children:[!k&&M.map((U,E)=>(0,Re.jsxs)(zy,{isStreaming:U.state==="streaming",children:[(0,Re.jsx)(Fy,{}),(0,Re.jsx)(Hy,{children:U.text})]},`reasoning-${h.id}-${E}`)),A.map(U=>{let E="output"in U?U.output:void 0,q=$d(U.toolName,E,g),$=BA(U.toolName,E,g),V=U.toolCallId===d;return(0,Re.jsxs)("div",{style:V?{position:"absolute",inset:0,zIndex:10,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--ww-color-background)"}:void 0,children:[(0,Re.jsx)("div",{style:V?{display:"none"}:void 0,children:p?(0,Re.jsxs)(EA,{children:[(0,Re.jsx)(RA,{title:U.title??$A(U.toolName),state:U.state}),(0,Re.jsxs)(_A,{children:[(0,Re.jsx)(OA,{input:U.input,debug:f}),E!==void 0&&(0,Re.jsx)(UA,{output:E,errorText:"errorText"in U?U.errorText:void 0,debug:f})]})]}):(0,Re.jsx)(DA,{title:U.title??$A(U.toolName),state:U.state})}),q&&o&&E!==void 0&&(0,Re.jsx)(Wd,{children:(0,Re.jsx)(HA,{isFullscreen:V,resourceUri:q,toolInput:U.input??{},toolResult:{content:E.content,structuredContent:E.structuredContent,_meta:E._meta},resourceEndpoint:o,chatSessionId:l,isDark:i,autoHeight:$,toolDefinitions:g,onFollowUp:s,onCallTool:u,onDisplayModeChange:c?Y=>c(Y,{toolCallId:U.toolCallId,resourceUri:q,toolInput:U.input??{},toolResult:{content:E.content,structuredContent:E.structuredContent,_meta:E._meta},autoHeight:$}):void 0})})]},U.toolCallId)}),!k&&(0,Re.jsx)("div",{children:(0,Re.jsxs)(qy,{children:[b.length>0&&(0,Re.jsx)(F0,{files:b}),P?w.map((U,E)=>{let q=D&&t==="streaming"&&E===w.length-1;return(0,Re.jsx)(Gd,{isStreaming:q,children:U.type==="text"?U.text:""},`${h.id}-${E}`)}):null]})})]},h.id)}),x&&(0,Re.jsx)(zA,{})]})}var Bs=F(re(),1),Tz="https://app.waniwani.ai/assets/waniwani-logo.svg",Mz="https://waniwani.ai";function XA(){let{t:e}=Ne();return(0,Bs.jsxs)("a",{href:Mz,target:"_blank",rel:"noopener noreferrer",className:"ww:flex ww:items-center ww:gap-1.5 ww:text-[11px] ww:text-muted-foreground ww:opacity-70 hover:ww:opacity-100 ww:transition-opacity",children:[(0,Bs.jsx)("span",{children:e.poweredBy.label}),(0,Bs.jsx)("img",{src:Tz,alt:"WaniWani",width:72,height:10,"data-waniwani-logo":"",className:"ww:h-2.5 ww:w-auto"})]})}var Us=F(re(),1);function ZA({suggestions:e,isLoading:t,onSelect:a,className:r,...n}){return e.length===0&&!t?null:(0,Us.jsx)("div",{className:Z("ww:px-4 ww:py-2",r),...n,children:(0,Us.jsx)("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl ww:flex ww:flex-wrap ww:gap-2",children:t?[0,1,2].map(o=>(0,Us.jsx)("div",{className:"ww:h-7 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+o*20}px`}},o)):e.map((o,l)=>(0,Us.jsx)("button",{type:"button",onClick:()=>a(o),className:Z("ww:rounded-full ww:border ww:border-border ww:bg-background ww:px-3 ww:py-1 ww:text-xs","ww:text-foreground ww:hover:bg-accent ww:hover:border-primary/30","ww:transition-all ww:duration-200 ww:ease-out ww:cursor-pointer","ww:animate-[ww-fade-in_0.2s_ease-out_both]"),style:{animationDelay:`${l*50}ms`},children:o},o))})})}var Fl=F(_e(),1);var ke=F(re(),1),QA=20;function Az({label:e}){return(0,ke.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[(0,ke.jsx)("title",{children:e}),(0,ke.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,ke.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function Ez({label:e}){return(0,ke.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[(0,ke.jsx)("title",{children:e}),(0,ke.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,ke.jsx)("polyline",{points:"3 4 3 9 8 9"}),(0,ke.jsx)("line",{x1:"12",y1:"7",x2:"12",y2:"12"}),(0,ke.jsx)("line",{x1:"12",y1:"12",x2:"15",y2:"14"})]})}function Rz({label:e}){return(0,ke.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[(0,ke.jsx)("title",{children:e}),(0,ke.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,ke.jsx)("path",{d:"M19 6l-2 14a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2L5 6"}),(0,ke.jsx)("path",{d:"M10 11v6"}),(0,ke.jsx)("path",{d:"M14 11v6"})]})}function KA({threads:e,activeThreadId:t,onNewThread:a,onSelectThread:r,onDeleteThread:n}){let{locale:o,t:l}=Ne(),[i,s]=(0,Fl.useState)(!1),u=(0,Fl.useRef)(null);(0,Fl.useEffect)(()=>{if(!i)return;let f=p=>{let g=u.current;g&&(p.composedPath().includes(g)||s(!1))};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[i]);let c=e.slice(0,QA),d=Math.max(0,e.length-QA);return(0,ke.jsxs)("div",{ref:u,className:"ww:relative ww:flex ww:items-center ww:gap-1",children:[(0,ke.jsx)("button",{type:"button",onClick:a,title:l.threadMenu.newChat,"aria-label":l.threadMenu.newChat,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,ke.jsx)(Az,{label:l.threadMenu.newChat})}),(0,ke.jsx)("button",{type:"button",onClick:()=>s(f=>!f),title:l.threadMenu.threadHistory,"aria-label":l.threadMenu.threadHistory,"aria-expanded":i,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,ke.jsx)(Ez,{label:l.threadMenu.threadHistory})}),i&&(0,ke.jsxs)("div",{role:"menu",className:"ww:absolute ww:right-0 ww:top-full ww:mt-1 ww:w-72 ww:max-h-80 ww:overflow-y-auto ww:rounded-lg ww:border ww:border-border ww:bg-background ww:shadow-lg ww:z-50",children:[c.length===0&&(0,ke.jsx)("div",{className:"ww:px-3 ww:py-3 ww:text-xs ww:text-muted-foreground",children:l.threadMenu.noPreviousChats}),c.map(f=>{let p=f.threadId===t,g=Date.parse(f.updatedAt);return(0,ke.jsxs)("div",{className:`ww:flex ww:items-center ww:gap-2 ww:px-3 ww:py-2 ww:text-xs hover:ww:bg-foreground/5 ${p?"ww:bg-foreground/5":""}`,children:[(0,ke.jsxs)("button",{type:"button",onClick:()=>{r(f.threadId),s(!1)},className:"ww:flex-1 ww:min-w-0 ww:text-left ww:cursor-pointer",children:[(0,ke.jsx)("div",{className:"ww:truncate ww:text-foreground ww:font-medium",children:f.title}),(0,ke.jsx)("div",{className:"ww:text-[10px] ww:text-muted-foreground",children:Number.isNaN(g)?"":lh(g,o)})]}),(0,ke.jsx)("button",{type:"button",onClick:v=>{v.stopPropagation(),n(f.threadId)},title:l.threadMenu.deleteThread,"aria-label":l.threadMenu.deleteThread,className:"ww:p-1 ww:rounded ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/10 ww:transition-colors ww:cursor-pointer",children:(0,ke.jsx)(Rz,{label:l.threadMenu.deleteThread})})]},f.threadId)}),d>0&&(0,ke.jsx)("div",{className:"ww:px-3 ww:py-2 ww:text-[10px] ww:text-muted-foreground ww:border-t ww:border-border",children:l.threadMenu.hiddenThreads(d)})]})]})}var Xd=F(_e(),1);function YA(e){let t=(0,Xd.useRef)(e);return t.current=e,(0,Xd.useCallback)(async a=>{let{api:r,headers:n,onCallTool:o,sessionId:l}=t.current;if(o)return o(a);let i=`${r??"/api/waniwani"}/tool`,s=typeof l=="string"&&l.trim().length>0?l.trim():void 0,u=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",...s?{"X-Session-Id":s}:{},...n},body:JSON.stringify(a)});if(!u.ok)throw new Error(`Tool call failed: ${u.status} ${u.statusText}`);return u.json()},[])}var Ha=F(_e(),1);var TE="vercel.ai.error",Dz=Symbol.for(TE),JA,eE,we=class ME extends(eE=Error,JA=Dz,eE){constructor({name:t,message:a,cause:r}){super(a),this[JA]=!0,this.name=t,this.cause=r}static isInstance(t){return ME.hasMarker(t,TE)}static hasMarker(t,a){let r=Symbol.for(a);return t!=null&&typeof t=="object"&&r in t&&typeof t[r]=="boolean"&&t[r]===!0}},AE="AI_APICallError",EE=`vercel.ai.error.${AE}`,_z=Symbol.for(EE),tE,aE,aee=class extends(aE=we,tE=_z,aE){constructor({message:e,url:t,requestBodyValues:a,statusCode:r,responseHeaders:n,responseBody:o,cause:l,isRetryable:i=r!=null&&(r===408||r===409||r===429||r>=500),data:s}){super({name:AE,message:e,cause:l}),this[tE]=!0,this.url=t,this.requestBodyValues=a,this.statusCode=r,this.responseHeaders=n,this.responseBody=o,this.isRetryable=i,this.data=s}static isInstance(e){return we.hasMarker(e,EE)}},RE="AI_EmptyResponseBodyError",DE=`vercel.ai.error.${RE}`,Oz=Symbol.for(DE),rE,nE,ree=class extends(nE=we,rE=Oz,nE){constructor({message:e="Empty response body"}={}){super({name:RE,message:e}),this[rE]=!0}static isInstance(e){return we.hasMarker(e,DE)}};function _E(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var OE="AI_InvalidArgumentError",PE=`vercel.ai.error.${OE}`,Pz=Symbol.for(PE),oE,lE,NE=class extends(lE=we,oE=Pz,lE){constructor({message:e,cause:t,argument:a}){super({name:OE,message:e,cause:t}),this[oE]=!0,this.argument=a}static isInstance(e){return we.hasMarker(e,PE)}},BE="AI_InvalidPromptError",UE=`vercel.ai.error.${BE}`,Nz=Symbol.for(UE),iE,sE,nee=class extends(sE=we,iE=Nz,sE){constructor({prompt:e,message:t,cause:a}){super({name:BE,message:`Invalid prompt: ${t}`,cause:a}),this[iE]=!0,this.prompt=e}static isInstance(e){return we.hasMarker(e,UE)}},qE="AI_InvalidResponseDataError",zE=`vercel.ai.error.${qE}`,Bz=Symbol.for(zE),uE,cE,oee=class extends(cE=we,uE=Bz,cE){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:qE,message:t}),this[uE]=!0,this.data=e}static isInstance(e){return we.hasMarker(e,zE)}},FE="AI_JSONParseError",HE=`vercel.ai.error.${FE}`,Uz=Symbol.for(HE),dE,fE,Wy=class extends(fE=we,dE=Uz,fE){constructor({text:e,cause:t}){super({name:FE,message:`JSON parsing failed: Text: ${e}.
124
124
  Error message: ${_E(t)}`,cause:t}),this[dE]=!0,this.text=e}static isInstance(e){return we.hasMarker(e,HE)}},jE="AI_LoadAPIKeyError",VE=`vercel.ai.error.${jE}`,qz=Symbol.for(VE),pE,mE,lee=class extends(mE=we,pE=qz,mE){constructor({message:e}){super({name:jE,message:e}),this[pE]=!0}static isInstance(e){return we.hasMarker(e,VE)}},GE="AI_LoadSettingError",$E=`vercel.ai.error.${GE}`,zz=Symbol.for($E),hE,gE,iee=class extends(gE=we,hE=zz,gE){constructor({message:e}){super({name:GE,message:e}),this[hE]=!0}static isInstance(e){return we.hasMarker(e,$E)}},WE="AI_NoContentGeneratedError",XE=`vercel.ai.error.${WE}`,Fz=Symbol.for(XE),yE,xE,see=class extends(xE=we,yE=Fz,xE){constructor({message:e="No content generated."}={}){super({name:WE,message:e}),this[yE]=!0}static isInstance(e){return we.hasMarker(e,XE)}},ZE="AI_NoSuchModelError",QE=`vercel.ai.error.${ZE}`,Hz=Symbol.for(QE),vE,wE,uee=class extends(wE=we,vE=Hz,wE){constructor({errorName:e=ZE,modelId:t,modelType:a,message:r=`No such ${a}: ${t}`}){super({name:e,message:r}),this[vE]=!0,this.modelId=t,this.modelType=a}static isInstance(e){return we.hasMarker(e,QE)}},KE="AI_TooManyEmbeddingValuesForCallError",YE=`vercel.ai.error.${KE}`,jz=Symbol.for(YE),bE,SE,cee=class extends(SE=we,bE=jz,SE){constructor(e){super({name:KE,message:`Too many values for a single embedding call. The ${e.provider} model "${e.modelId}" can only embed up to ${e.maxEmbeddingsPerCall} values per call, but ${e.values.length} values were provided.`}),this[bE]=!0,this.provider=e.provider,this.modelId=e.modelId,this.maxEmbeddingsPerCall=e.maxEmbeddingsPerCall,this.values=e.values}static isInstance(e){return we.hasMarker(e,YE)}},JE="AI_TypeValidationError",e2=`vercel.ai.error.${JE}`,Vz=Symbol.for(e2),CE,IE,cr=class $y extends(IE=we,CE=Vz,IE){constructor({value:t,cause:a,context:r}){let n="Type validation failed";if(r?.field&&(n+=` for ${r.field}`),r?.entityName||r?.entityId){n+=" (";let o=[];r.entityName&&o.push(r.entityName),r.entityId&&o.push(`id: "${r.entityId}"`),n+=o.join(", "),n+=")"}super({name:JE,message:`${n}: Value: ${JSON.stringify(t)}.