@waniwani/sdk 0.10.7-beta.2 → 0.10.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -118,7 +118,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
118
118
  `)},Uy=e=>{let t=!1;for(let n of e)if(n==="\\"||n==="|"){t=!0;break}if(!t)return e;let a=[];for(let n of e)n==="\\"?a.push("\\\\"):n==="|"?a.push("\\|"):a.push(n);return a.join("")},nz=e=>{let{headers:t,rows:a}=e;if(t.length===0)return"";let n=new Array(a.length+2),r=0,o=t.map(i=>Uy(i));n[r]=`| ${o.join(" | ")} |`,r+=1;let l=new Array(t.length);for(let i=0;i<t.length;i+=1)l[i]="---";n[r]=`| ${l.join(" | ")} |`,r+=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?Uy(i[u]):"";n[r]=`| ${s.join(" | ")} |`,r+=1}else{let s=i.map(u=>Uy(u));n[r]=`| ${s.join(" | ")} |`,r+=1}return n.join(`
119
119
  `)},rz=({children:e,className:t,onCopy:a,onError:n,timeout:r=2e3})=>{let[o,l]=(0,E.useState)(!1),[i,s]=(0,E.useState)(!1),u=(0,E.useRef)(null),c=(0,E.useRef)(0),{isAnimating:d}=(0,E.useContext)(Wt),f=async y=>{var v,S;if(typeof window>"u"||!((v=navigator?.clipboard)!=null&&v.write)){n?.(new Error("Clipboard API not available"));return}try{let g=(S=u.current)==null?void 0:S.closest('[data-streamdown="table-wrapper"]'),x=g?.querySelector("table");if(!x){n?.(new Error("Table not found"));return}let m=UA(x),w=y==="csv"?zA(m):az(m),L=new ClipboardItem({"text/plain":new Blob([w],{type:"text/plain"}),"text/html":new Blob([x.outerHTML],{type:"text/html"})});await navigator.clipboard.write([L]),s(!0),l(!1),a?.(y),c.current=window.setTimeout(()=>s(!1),r)}catch(g){n?.(g)}};(0,E.useEffect)(()=>{let y=v=>{let S=v.composedPath();u.current&&!S.includes(u.current)&&l(!1)};return document.addEventListener("mousedown",y),()=>{document.removeEventListener("mousedown",y),window.clearTimeout(c.current)}},[]);let p=i?jy:Vy;return(0,A.jsxs)("div",{className:"relative",ref:u,children:[(0,A.jsx)("button",{className:Y("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,A.jsx)(p,{size:14})}),o?(0,A.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,A.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,A.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]})},oz=({children:e,className:t,onDownload:a,onError:n})=>{let[r,o]=(0,E.useState)(!1),l=(0,E.useRef)(null),{isAnimating:i}=(0,E.useContext)(Wt),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){n?.(new Error("Table not found"));return}let p=UA(f),y=u==="csv"?zA(p):nz(p);zl(`table.${u==="csv"?"csv":"md"}`,y,u==="csv"?"text/csv":"text/markdown"),o(!1),a?.(u)}catch(d){n?.(d)}};return(0,E.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,A.jsxs)("div",{className:"relative",ref:l,children:[(0,A.jsx)("button",{className:Y("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>o(!r),title:"Download table",type:"button",children:e??(0,A.jsx)(Qd,{size:14})}),r?(0,A.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,A.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,A.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]})},lz=({children:e,className:t,showControls:a,...n})=>(0,A.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[a?(0,A.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,A.jsx)(rz,{}),(0,A.jsx)(oz,{})]}):null,(0,A.jsx)("div",{className:"overflow-x-auto",children:(0,A.jsx)("table",{className:Y("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]}),iz=(0,E.lazy)(()=>Promise.resolve().then(()=>(IA(),CA)).then(e=>({default:e.CodeBlock}))),sz=(0,E.lazy)(()=>Promise.resolve().then(()=>(TA(),kA)).then(e=>({default:e.Mermaid}))),uz=/language-([^\s]+)/;Hy=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,Xd=(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},Wy=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("ol",{className:Y("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>nt(e,t));Wy.displayName="MarkdownOl";qA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("li",{className:Y("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&Kd(e.node,t.node));qA.displayName="MarkdownLi";FA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("ul",{className:Y("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>nt(e,t));FA.displayName="MarkdownUl";HA=(0,E.memo)(({className:e,node:t,...a})=>(0,A.jsx)("hr",{className:Y("my-6 border-border",e),"data-streamdown":"horizontal-rule",...a}),(e,t)=>nt(e,t));HA.displayName="MarkdownHr";jA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("span",{className:Y("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>nt(e,t));jA.displayName="MarkdownStrong";cz=({children:e,className:t,href:a,node:n,...r})=>{let{linkSafety:o}=(0,E.useContext)(Wt),[l,i]=(0,E.useState)(!1),s=a==="streamdown:incomplete-link",u=(0,E.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,E.useCallback)(()=>{a&&window.open(a,"_blank","noreferrer")},[a]),d=(0,E.useCallback)(()=>{i(!1)},[]),f={url:a??"",isOpen:l,onClose:d,onConfirm:c};return o!=null&&o.enabled&&a?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("button",{className:Y("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,A.jsx)(QU,{...f})]}):(0,A.jsx)("a",{className:Y("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:a,rel:"noreferrer",target:"_blank",...r,children:e})},VA=(0,E.memo)(cz,(e,t)=>nt(e,t)&&e.href===t.href);VA.displayName="MarkdownA";GA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h1",{className:Y("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>nt(e,t));GA.displayName="MarkdownH1";WA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h2",{className:Y("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>nt(e,t));WA.displayName="MarkdownH2";$A=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h3",{className:Y("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>nt(e,t));$A.displayName="MarkdownH3";XA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h4",{className:Y("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>nt(e,t));XA.displayName="MarkdownH4";ZA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h5",{className:Y("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>nt(e,t));ZA.displayName="MarkdownH5";QA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("h6",{className:Y("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>nt(e,t));QA.displayName="MarkdownH6";KA=(0,E.memo)(({children:e,className:t,node:a,...n})=>{let{controls:r}=(0,E.useContext)(Wt),o=Hy(r,"table");return(0,A.jsx)(lz,{className:t,showControls:o,...n,children:e})},(e,t)=>nt(e,t));KA.displayName="MarkdownTable";YA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("thead",{className:Y("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>nt(e,t));YA.displayName="MarkdownThead";JA=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("tbody",{className:Y("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>nt(e,t));JA.displayName="MarkdownTbody";eM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("tr",{className:Y("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>nt(e,t));eM.displayName="MarkdownTr";tM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("th",{className:Y("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>nt(e,t));tM.displayName="MarkdownTh";aM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("td",{className:Y("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>nt(e,t));aM.displayName="MarkdownTd";nM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("blockquote",{className:Y("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>nt(e,t));nM.displayName="MarkdownBlockquote";rM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("sup",{className:Y("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>nt(e,t));rM.displayName="MarkdownSup";oM=(0,E.memo)(({children:e,className:t,node:a,...n})=>(0,A.jsx)("sub",{className:Y("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>nt(e,t));oM.displayName="MarkdownSub";lM=(0,E.memo)(({children:e,className:t,node:a,...n})=>{if("data-footnotes"in n){let r=l=>{var i,s;if(!(0,E.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,E.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 y of p){if(typeof y=="string"&&y.trim()!==""){c=!0;break}if((0,E.isValidElement)(y)&&((s=y.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,E.isValidElement)(l))return l;if(l.type===Wy){let i=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(s=>!r(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,A.jsx)("section",{className:t,...n,children:o}):null}return(0,A.jsx)("section",{className:t,...n,children:e})},(e,t)=>nt(e,t));lM.displayName="MarkdownSection";dz=({node:e,className:t,children:a,...n})=>{var r,o,l;let i=((r=e?.position)==null?void 0:r.start.line)===((o=e?.position)==null?void 0:o.end.line),{mermaid:s,controls:u}=(0,E.useContext)(Wt),c=Gy();if(i)return(0,A.jsx)("code",{className:Y("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:a});let d=t?.match(uz),f=(l=d?.at(1))!=null?l:"",p="";if((0,E.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=Hy(u,"mermaid"),S=Xd(u,"download"),g=Xd(u,"copy"),x=Xd(u,"fullscreen"),m=Xd(u,"panZoom"),w=v&&(S||g||x);return(0,A.jsx)(E.Suspense,{fallback:(0,A.jsx)(RA,{}),children:(0,A.jsxs)("div",{className:Y("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[w?(0,A.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[S?(0,A.jsx)(YU,{chart:p,config:s?.config}):null,g?(0,A.jsx)(MA,{code:p}):null,x?(0,A.jsx)(tz,{chart:p,config:s?.config}):null]}):null,(0,A.jsx)(sz,{chart:p,config:s?.config,showControls:m})]})})}let y=Hy(u,"code");return(0,A.jsx)(E.Suspense,{fallback:(0,A.jsx)(RA,{}),children:(0,A.jsx)(iz,{className:Y("overflow-x-auto border-border border-t",t),code:p,language:f,children:y?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(GU,{code:p,language:f}),(0,A.jsx)(MA,{})]}):null})})},iM=(0,E.memo)(dz,(e,t)=>e.className===t.className&&Kd(e.node,t.node));iM.displayName="MarkdownCode";sM=(0,E.memo)($U,(e,t)=>e.className===t.className&&Kd(e.node,t.node));sM.displayName="MarkdownImg";uM=(0,E.memo)(({children:e,className:t,node:a,...n})=>{var r,o;let l=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");if(l.length===1&&(0,E.isValidElement)(l[0])){let i=l[0].props.node,s=i?.tagName;if(s==="img")return(0,A.jsx)(A.Fragment,{children:e});if(s==="code"&&((r=i?.position)==null?void 0:r.start.line)!==((o=i?.position)==null?void 0:o.end.line))return(0,A.jsx)(A.Fragment,{children:e})}return(0,A.jsx)("p",{className:t,...n,children:e})},(e,t)=>nt(e,t));uM.displayName="MarkdownParagraph";fz={ol:Wy,li:qA,ul:FA,hr:HA,strong:jA,a:VA,h1:GA,h2:WA,h3:$A,h4:XA,h5:ZA,h6:QA,table:KA,thead:YA,tbody:JA,tr:eM,th:tM,td:aM,blockquote:nM,code:iM,img:sM,pre:({children:e})=>e,sup:rM,sub:oM,p:uM,section:lM},DA=[],_A={allowDangerousHtml:!0},Zd=new WeakMap,pz=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,n=e.remarkPlugins,r=e.remarkRehypeOptions;if(!(a||n||r)){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[y,v]=p;if(typeof y=="function"){let S=Zd.get(y);S||(S=y.name,Zd.set(y,S)),d+=S}else d+=String(y);d+=":",d+=JSON.stringify(v)}else if(typeof p=="function"){let y=Zd.get(p);y||(y=p.name,Zd.set(p,y)),d+=y}else d+=String(p)}return d},l=o(a),i=o(n),s=r?JSON.stringify(r):"",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 n=this.cache.keys().next().value;n&&this.cache.delete(n)}this.cache.set(a,t)}clear(){this.cache.clear()}},OA=new pz,cM=e=>{let t=mz(e),a=e.children||"";return gz(t.runSync(t.parse(a),a),e)},mz=e=>{let t=OA.get(e);if(t)return t;let a=hz(e);return OA.set(e,a),a},hz=e=>{let t=e.rehypePlugins||DA,a=e.remarkPlugins||DA,n=e.remarkRehypeOptions?{..._A,...e.remarkRehypeOptions}:_A;return Cy().use(Dd).use(a).use(Nd,n).use(t)},gz=(e,t)=>ay(e,{Fragment:A.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:A.jsx,jsxs:A.jsxs,passKeys:!0,passNode:!0}),yz=/\[\^[^\]\s]{1,200}\](?!:)/,xz=/\[\^[^\]\s]{1,200}\]:/,vz=/<\/(\w+)>/,wz=/<(\w+)[\s>]/,zy=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]==="$"},bz=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]==="$"},qy=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},dM=e=>{let t=yz.test(e),a=xz.test(e);if(t||a)return[e];let n=ya.lex(e,{gfm:!0}),r=[],o=[];for(let l of n){let i=l.raw,s=r.length;if(o.length>0){if(r[s-1]+=i,l.type==="html"){let u=i.match(vz);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(l.type==="html"&&l.block){let u=i.match(wz);if(u){let c=u[1];i.includes(`</${c}>`)||o.push(c)}}if(i.trim()==="$$"&&s>0){let u=r[s-1],c=zy(u),d=qy(u);if(c&&d%2===1){r[s-1]=u+i;continue}}if(s>0&&bz(i)){let u=r[s-1],c=zy(u),d=qy(u),f=qy(i);if(c&&d%2===1&&!zy(i)&&f===1){r[s-1]=u+i;continue}}r.push(i)}return r},fM={raw:GC,sanitize:[Yc,{}],harden:[jC,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},pM={gfm:[Cd,{}]},Sz=Object.values(fM),Cz=Object.values(pM),Iz={block:" \u258B",circle:" \u25CF"},Lz={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},Wt=(0,E.createContext)(Lz),$y=(0,E.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...n})=>(0,A.jsx)(cM,{...n,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||{}),n=Object.keys(t.components||{});if(a.length!==n.length||a.some(r=>{var o,l;return((o=e.components)==null?void 0:o[r])!==((l=t.components)==null?void 0:l[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});$y.displayName="Block";kz=["github-light","github-dark"],Yd=(0,E.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:n,rehypePlugins:r=Sz,remarkPlugins:o=Cz,className:l,shikiTheme:i=kz,mermaid:s,controls:u=!0,isAnimating:c=!1,BlockComponent:d=$y,parseMarkdownIntoBlocksFn:f=dM,caret:p,plugins:y,remend:v,linkSafety:S={enabled:!0},...g})=>{let x=(0,E.useId)(),[m,w]=(0,E.useTransition)(),L=(0,E.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?n1(e,v):e,[e,t,a,v]),b=(0,E.useMemo)(()=>f(L),[L,f]),[M,R]=(0,E.useState)(b);(0,E.useEffect)(()=>{t==="streaming"?w(()=>{R(b)}):R(b)},[b,t]);let _=t==="streaming"?M:b,T=(0,E.useMemo)(()=>_.map((F,te)=>`${x}-${te}`),[_.length,x]),D=(0,E.useMemo)(()=>{var F,te;return{shikiTheme:(te=(F=y?.code)==null?void 0:F.getThemes())!=null?te:i,controls:u,isAnimating:c,mode:t,mermaid:s,linkSafety:S}},[i,u,c,t,s,S,y?.code]),N=(0,E.useMemo)(()=>({...fz,...n}),[n]),B=(0,E.useMemo)(()=>{let F=[];return y!=null&&y.cjk&&(F=[...F,...y.cjk.remarkPluginsBefore]),F=[...F,...o],y!=null&&y.cjk&&(F=[...F,...y.cjk.remarkPluginsAfter]),y!=null&&y.math&&(F=[...F,y.math.remarkPlugin]),F},[o,y?.math,y?.cjk]),j=(0,E.useMemo)(()=>y!=null&&y.math?[...r,y.math.rehypePlugin]:r,[r,y?.math]),V=(0,E.useMemo)(()=>p&&c?{"--streamdown-caret":`"${Iz[p]}"`}:void 0,[p,c]);return t==="static"?(0,A.jsx)(Fy.Provider,{value:y??null,children:(0,A.jsx)(Wt.Provider,{value:D,children:(0,A.jsx)("div",{className:Y("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:(0,A.jsx)(cM,{components:N,rehypePlugins:j,remarkPlugins:B,...g,children:e})})})}):(0,A.jsx)(Fy.Provider,{value:y??null,children:(0,A.jsx)(Wt.Provider,{value:D,children:(0,A.jsxs)("div",{className:Y("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:[_.length===0&&p&&c&&(0,A.jsx)("span",{}),_.map((F,te)=>(0,A.jsx)(d,{components:N,content:F,index:te,rehypePlugins:j,remarkPlugins:B,shouldParseIncompleteMarkdown:a,...g},T[te]))]})})})},(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);Yd.displayName="Streamdown";Tz=({children:e,className:t,minZoom:a=.5,maxZoom:n=3,zoomStep:r=.1,showControls:o=!0,initialZoom:l=1,fullscreen:i=!1})=>{let s=(0,E.useRef)(null),u=(0,E.useRef)(null),[c,d]=(0,E.useState)(l),[f,p]=(0,E.useState)({x:0,y:0}),[y,v]=(0,E.useState)(!1),[S,g]=(0,E.useState)({x:0,y:0}),[x,m]=(0,E.useState)({x:0,y:0}),w=(0,E.useCallback)(N=>{d(B=>Math.max(a,Math.min(n,B+N)))},[a,n]),L=(0,E.useCallback)(()=>{w(r)},[w,r]),b=(0,E.useCallback)(()=>{w(-r)},[w,r]),M=(0,E.useCallback)(()=>{d(l),p({x:0,y:0})},[l]),R=(0,E.useCallback)(N=>{N.preventDefault();let B=N.deltaY>0?-r:r;w(B)},[w,r]),_=(0,E.useCallback)(N=>{if(N.button!==0||N.isPrimary===!1)return;v(!0),g({x:N.clientX,y:N.clientY}),m(f);let B=N.currentTarget;B instanceof HTMLElement&&B.setPointerCapture(N.pointerId)},[f]),T=(0,E.useCallback)(N=>{if(!y)return;N.preventDefault();let B=N.clientX-S.x,j=N.clientY-S.y;p({x:x.x+B,y:x.y+j})},[y,S,x]),D=(0,E.useCallback)(N=>{v(!1);let B=N.currentTarget;B instanceof HTMLElement&&B.releasePointerCapture(N.pointerId)},[]);return(0,E.useEffect)(()=>{let N=s.current;if(N)return N.addEventListener("wheel",R,{passive:!1}),()=>{N.removeEventListener("wheel",R)}},[R]),(0,E.useEffect)(()=>{let N=u.current;if(N&&y)return document.body.style.userSelect="none",N.addEventListener("pointermove",T,{passive:!1}),N.addEventListener("pointerup",D),N.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",N.removeEventListener("pointermove",T),N.removeEventListener("pointerup",D),N.removeEventListener("pointercancel",D)}},[y,T,D]),(0,A.jsxs)("div",{className:Y("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:y?"grabbing":"grab"},children:[o?(0,A.jsxs)("div",{className:Y("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,A.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>=n,onClick:L,title:"Zoom in",type:"button",children:(0,A.jsx)(jU,{size:16})}),(0,A.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,A.jsx)(VU,{size:16})}),(0,A.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:M,title:"Reset zoom and pan",type:"button",children:(0,A.jsx)(HU,{size:16})})]}):null,(0,A.jsx)("div",{className:Y("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:_,ref:u,role:"application",style:{transform:`translate(${f.x}px, ${f.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},By=({chart:e,className:t,config:a,fullscreen:n=!1,showControls:r=!0})=>{let[o,l]=(0,E.useState)(null),[i,s]=(0,E.useState)(!1),[u,c]=(0,E.useState)(""),[d,f]=(0,E.useState)(""),[p,y]=(0,E.useState)(0),{mermaid:v}=(0,E.useContext)(Wt),S=Gy(),g=v?.errorComponent,{shouldRender:x,containerRef:m}=zU({immediate:n});if((0,E.useEffect)(()=>{if(x){if(!S){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),s(!0);let L=S.getMermaid(a),b=e.split("").reduce((_,T)=>(_<<5)-_+T.charCodeAt(0)|0,0),M=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:R}=await L.render(M,e);c(R),f(R)}catch(L){if(!(d||u)){let b=L instanceof Error?L.message:"Failed to render Mermaid chart";l(b)}}finally{s(!1)}})()}},[e,a,p,x,S]),!(x||u||d))return(0,A.jsx)("div",{className:Y("my-4 min-h-[200px]",t),ref:m});if(i&&!u&&!d)return(0,A.jsx)("div",{className:Y("my-4 flex justify-center p-4",t),ref:m,children:(0,A.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,A.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,A.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return g?(0,A.jsx)("div",{ref:m,children:(0,A.jsx)(g,{chart:e,error:o,retry:()=>y(b=>b+1)})}):(0,A.jsxs)("div",{className:Y("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:m,children:[(0,A.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,A.jsxs)("details",{className:"mt-2",children:[(0,A.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,A.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,A.jsx)("div",{className:Y("size-full",t),"data-streamdown":"mermaid",ref:m,children:(0,A.jsx)(Tz,{className:Y(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:(0,A.jsx)("div",{"aria-label":"Mermaid chart",className:Y("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:w},role:"img"})})})}});var h2=Ot((HJ,m2)=>{"use strict";function QF(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let a,n=0;return function(...o){clearTimeout(a);let l=Date.now(),i=l-n,s=t-i;s<=0?(n=l,e.apply(this,o)):a=setTimeout(()=>{n=Date.now(),e.apply(this,o)},s)}}m2.exports=QF});var Lf=q(xe(),1),yx=q(sC(),1);var U_="https://app.waniwani.ai/api/mcp/chat",z_={api:U_,title:"Assistant",position:"bottom-right",width:400,height:600};function q_(){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 _c(){let e=q_();if(!e)return{};let t=L=>e.getAttribute(L)??void 0,a=L=>{let b=e.getAttribute(L);if(b==null)return;let M=Number(b);return Number.isFinite(M)?M:void 0},n={},r=t("data-api");r&&(n.api=r);let o=t("data-token");o&&(n.token=o);let l=t("data-title");l&&(n.title=l);let i=t("data-welcome-message");i&&(n.welcomeMessage=i);let s=t("data-placeholder");s&&(n.placeholder=s);let u=t("data-mcp-server-url");u&&(n.mcpServerUrl=u);let c=t("data-css");c&&(n.css=c);let d=t("data-suggestions");d&&(n.suggestions=d.split(",").map(L=>L.trim()).filter(Boolean));let f=t("data-position");(f==="bottom-right"||f==="bottom-left")&&(n.position=f);let p=t("data-mode");(p==="floating"||p==="custom"||p==="inline")&&(n.mode=p);let y=t("data-layout");(y==="card"||y==="bar"||y==="embed")&&(n.layout=y);let v=a("data-width");v&&(n.width=v);let S=a("data-height");S&&(n.height=S);let g=t("data-primary-color"),x=t("data-background-color"),m=t("data-text-color"),w=t("data-font-family");return(g||x||m||w)&&(n.theme={},g&&(n.theme.primaryColor=g),x&&(n.theme.backgroundColor=x),m&&(n.theme.textColor=m),w&&(n.theme.fontFamily=w)),n}function Oc(e,t,a){let n=a??_c(),r={token:"",...z_,...t??{},...n,...e,theme:{...t?.theme??{},...n.theme,...e?.theme}};if(!r.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return r.mode||(r.mode="floating"),r}function Pc(e){if(!e.theme)return;let t=e.theme;return{...t.primaryColor?{primaryColor:t.primaryColor}:{},...t.backgroundColor?{backgroundColor:t.backgroundColor}:{},...t.textColor?{textColor:t.textColor}:{},...t.fontFamily?{fontFamily:t.fontFamily}:{}}}var ct=q(xe(),1);var Ut=q(xe(),1);var Bc=q(xe());var Nc=(...e)=>e.filter((t,a,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===a).join(" ").trim();var uC=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var cC=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,n)=>n?n.toUpperCase():a.toLowerCase());var dh=e=>{let t=cC(e);return t.charAt(0).toUpperCase()+t.slice(1)};var rs=q(xe());var dC={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 fC=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var pC=(0,rs.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:n,className:r="",children:o,iconNode:l,...i},s)=>(0,rs.createElement)("svg",{ref:s,...dC,width:t,height:t,stroke:e,strokeWidth:n?Number(a)*24/Number(t):a,className:Nc("lucide",r),...!o&&!fC(i)&&{"aria-hidden":"true"},...i},[...l.map(([u,c])=>(0,rs.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var Ye=(e,t)=>{let a=(0,Bc.forwardRef)(({className:n,...r},o)=>(0,Bc.createElement)(pC,{ref:o,iconNode:t,className:Nc(`lucide-${uC(dh(e))}`,`lucide-${e}`,n),...r}));return a.displayName=dh(e),a};var F_=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],os=Ye("arrow-down",F_);var H_=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],ls=Ye("arrow-up",H_);var j_=[["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"}]],yr=Ye("braces",j_);var V_=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],is=Ye("check",V_);var G_=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ss=Ye("chevron-down",G_);var W_=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],us=Ye("chevron-right",W_);var $_=[["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"}]],cs=Ye("clipboard-copy",$_);var X_=[["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"}]],ds=Ye("file",X_);var Z_=[["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"}]],fs=Ye("loader",Z_);var Q_=[["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"}]],ps=Ye("paperclip",Q_);var K_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],ms=Ye("square",K_);var Y_=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],ao=Ye("x",Y_);var CC=q(xe(),1);var _t=q(xe(),1);var J_={damping:.7,stiffness:.05,mass:1.25},eO=70,tO=1e3/60,aO=350,Uc=!1;globalThis.document?.addEventListener("mousedown",()=>{Uc=!0});globalThis.document?.addEventListener("mouseup",()=>{Uc=!1});globalThis.document?.addEventListener("click",()=>{Uc=!1});var hC=(e={})=>{let[t,a]=(0,_t.useState)(!1),[n,r]=(0,_t.useState)(e.initial!==!1),[o,l]=(0,_t.useState)(!1),i=(0,_t.useRef)(null);i.current=e;let s=(0,_t.useCallback)(()=>{if(!Uc)return!1;let x=window.getSelection();if(!x||!x.rangeCount)return!1;let m=x.getRangeAt(0);return m.commonAncestorContainer.contains(S.current)||S.current?.contains(m.commonAncestorContainer)},[]),u=(0,_t.useCallback)(x=>{d.isAtBottom=x,r(x)},[]),c=(0,_t.useCallback)(x=>{d.escapedFromLock=x,a(x)},[]),d=(0,_t.useMemo)(()=>{let x;return{escapedFromLock:t,isAtBottom:n,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return S.current?.scrollTop??0},set scrollTop(m){S.current&&(S.current.scrollTop=m,d.ignoreScrollToTop=S.current.scrollTop)},get targetScrollTop(){return!S.current||!g.current?0:S.current.scrollHeight-1-S.current.clientHeight},get calculatedTargetScrollTop(){if(!S.current||!g.current)return 0;let{targetScrollTop:m}=this;if(!e.targetScrollTop)return m;if(x?.targetScrollTop===m)return x.calculatedScrollTop;let w=Math.max(Math.min(e.targetScrollTop(m,{scrollElement:S.current,contentElement:g.current}),m),0);return x={targetScrollTop:m,calculatedScrollTop:w},requestAnimationFrame(()=>{x=void 0}),w},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=eO}}},[]),f=(0,_t.useCallback)((x={})=>{typeof x=="string"&&(x={animation:x}),x.preserveScrollPosition||u(!0);let m=Date.now()+(Number(x.wait)||0),w=ph(i.current,x.animation),{ignoreEscapes:L=!1}=x,b,M=d.calculatedTargetScrollTop;x.duration instanceof Promise?x.duration.finally(()=>{b=Date.now()}):b=m+(x.duration??0);let R=async()=>{let _=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:T}=d,D=performance.now(),N=(D-(d.lastTick??D))/tO;if(d.animation||(d.animation={behavior:w,promise:_,ignoreEscapes:L}),d.animation.behavior===w&&(d.lastTick=D),s()||m>Date.now())return R();if(T<Math.min(M,d.calculatedTargetScrollTop)){if(d.animation?.behavior===w){if(w==="instant")return d.scrollTop=d.calculatedTargetScrollTop,R();d.velocity=(w.damping*d.velocity+w.stiffness*d.scrollDifference)/w.mass,d.accumulated+=d.velocity*N,d.scrollTop+=d.accumulated,d.scrollTop!==T&&(d.accumulated=0)}return R()}return b>Date.now()?(M=d.calculatedTargetScrollTop,R()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:ph(i.current,i.current.resize),ignoreEscapes:L,duration:Math.max(0,b-Date.now())||void 0}):d.isAtBottom)});return _.then(T=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),T))};return x.wait!==!0&&(d.animation=void 0),d.animation?.behavior===w?d.animation.promise:R()},[u,s,d]),p=(0,_t.useCallback)(()=>{c(!0),u(!1)},[c,u]),y=(0,_t.useCallback)(({target:x})=>{if(x!==S.current)return;let{scrollTop:m,ignoreScrollToTop:w}=d,{lastScrollTop:L=m}=d;d.lastScrollTop=m,d.ignoreScrollToTop=void 0,w&&w>m&&(L=w),l(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||m===w)return;if(s()){c(!0),u(!1);return}let b=m>L,M=m<L;if(d.animation?.ignoreEscapes){d.scrollTop=L;return}M&&(c(!0),u(!1)),b&&c(!1),!d.escapedFromLock&&d.isNearBottom&&u(!0)},1)},[c,u,s,d]),v=(0,_t.useCallback)(({target:x,deltaY:m})=>{let w=x;for(;!["scroll","auto"].includes(getComputedStyle(w).overflow);){if(!w.parentElement)return;w=w.parentElement}w===S.current&&m<0&&S.current.scrollHeight>S.current.clientHeight&&!d.animation?.ignoreEscapes&&(c(!0),u(!1))},[c,u,d]),S=mC(x=>{S.current?.removeEventListener("scroll",y),S.current?.removeEventListener("wheel",v),x?.addEventListener("scroll",y,{passive:!0}),x?.addEventListener("wheel",v,{passive:!0})},[]),g=mC(x=>{if(d.resizeObserver?.disconnect(),!x)return;let m;d.resizeObserver=new ResizeObserver(([w])=>{let{height:L}=w.contentRect,b=L-(m??L);if(d.resizeDifference=b,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),l(d.isNearBottom),b>=0){let M=ph(i.current,m?i.current.resize:i.current.initial);f({animation:M,wait:!0,preserveScrollPosition:!0,duration:M==="instant"?void 0:aO})}else d.isNearBottom&&(c(!1),u(!0));m=L,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===b&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(x)},[]);return{contentRef:g,scrollRef:S,scrollToBottom:f,stopScroll:p,isAtBottom:n||o,isNearBottom:o,escapedFromLock:t,state:d}};function mC(e,t){let a=(0,_t.useCallback)(n=>(a.current=n,e(n)),t);return a}var fh=new Map;function ph(...e){let t={...J_},a=!1;for(let r of e){if(r==="instant"){a=!0;continue}typeof r=="object"&&(a=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let n=JSON.stringify(t);return fh.has(n)||fh.set(n,Object.freeze(t)),a?"instant":fh.get(n)}var no=q(xe(),1),ta=q(xe(),1);var gC=(0,ta.createContext)(null),nO=typeof window<"u"?ta.useLayoutEffect:ta.useEffect;function hs({instance:e,children:t,resize:a,initial:n,mass:r,damping:o,stiffness:l,targetScrollTop:i,contextRef:s,...u}){let c=(0,ta.useRef)(null),d=no.useCallback((L,b)=>(w?.targetScrollTop??i)?.(L,b)??L,[i]),f=hC({mass:r,damping:o,stiffness:l,resize:a,initial:n,targetScrollTop:d}),{scrollRef:p,contentRef:y,scrollToBottom:v,stopScroll:S,isAtBottom:g,escapedFromLock:x,state:m}=e??f,w=(0,ta.useMemo)(()=>({scrollToBottom:v,stopScroll:S,scrollRef:p,isAtBottom:g,escapedFromLock:x,contentRef:y,state:m,get targetScrollTop(){return c.current},set targetScrollTop(L){c.current=L}}),[v,g,y,p,S,x,m]);return(0,ta.useImperativeHandle)(s,()=>w,[w]),nO(()=>{p.current&&getComputedStyle(p.current).overflow==="visible"&&(p.current.style.overflow="auto")},[]),no.createElement(gC.Provider,{value:w},no.createElement("div",{...u},typeof t=="function"?t(w):t))}(function(e){function t({children:a,scrollClassName:n,...r}){let o=mh();return no.createElement("div",{ref:o.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:n},no.createElement("div",{...r,ref:o.contentRef},typeof a=="function"?a(o):a))}e.Content=t})(hs||(hs={}));function mh(){let e=(0,ta.useContext)(gC);if(!e)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return e}hh();yh();var rO=xC({prefix:"ww"});function $(...e){return rO(zc(e))}var SC=q(ee(),1),en=({className:e,variant:t="default",size:a="default",type:n="button",...r})=>(0,SC.jsx)("button",{type:n,className:$("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),...r});var gs=q(ee(),1),bl=({className:e,...t})=>(0,gs.jsx)(hs,{className:$("ww:relative ww:flex-1 ww:overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),Sl=({className:e,...t})=>(0,gs.jsx)(hs.Content,{className:$("ww:flex ww:flex-col ww:gap-6 ww:px-4 ww:py-6 ww:mx-auto ww:w-full ww:max-w-3xl",e),...t}),Cl=({className:e,...t})=>{let{isAtBottom:a,scrollToBottom:n}=mh(),r=(0,CC.useCallback)(()=>{n()},[n]);return!a&&(0,gs.jsx)(en,{className:$("ww:absolute ww:bottom-4 ww:left-[50%] ww:translate-x-[-50%] ww:rounded-full",e),onClick:r,size:"icon",variant:"outline",...t,children:(0,gs.jsx)(os,{className:"ww:size-4"})})};var Fc=(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 Be=q(xe(),1);var jt=q(ee(),1),iO=async e=>{try{let a=await(await fetch(e)).blob();return new Promise(n=>{let r=new FileReader;r.onloadend=()=>n(r.result),r.onerror=()=>n(null),r.readAsDataURL(a)})}catch{return null}},IC=(0,Be.createContext)(null),LC=()=>{let e=(0,Be.useContext)(IC);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},Il=({className:e,accept:t,multiple:a,globalDrop:n,maxFiles:r,maxFileSize:o,onSubmit:l,children:i,...s})=>{let u=(0,Be.useRef)(null),c=(0,Be.useRef)(null),[d,f]=(0,Be.useState)([]),p=(0,Be.useRef)(d);(0,Be.useEffect)(()=>{p.current=d},[d]);let y=(0,Be.useCallback)(()=>{u.current?.click()},[]),v=(0,Be.useCallback)(L=>{let b=[...L];if(b.length===0)return;let M=_=>o?_.size<=o:!0,R=b.filter(M);f(_=>{let T=typeof r=="number"?Math.max(0,r-_.length):void 0,D=typeof T=="number"?R.slice(0,T):R;return[..._,...D.map(N=>({filename:N.name,id:Fc(),mediaType:N.type,type:"file",url:URL.createObjectURL(N)}))]})},[r,o]),S=(0,Be.useCallback)(L=>{f(b=>{let M=b.find(R=>R.id===L);return M?.url&&URL.revokeObjectURL(M.url),b.filter(R=>R.id!==L)})},[]),g=(0,Be.useCallback)(()=>{f(L=>{for(let b of L)b.url&&URL.revokeObjectURL(b.url);return[]})},[]);(0,Be.useEffect)(()=>()=>{for(let L of p.current)L.url&&URL.revokeObjectURL(L.url)},[]);let x=(0,Be.useCallback)(L=>{L.currentTarget.files&&v(L.currentTarget.files),L.currentTarget.value=""},[v]);(0,Be.useEffect)(()=>{if(!n)return;let L=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault()},b=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault(),M.dataTransfer?.files&&M.dataTransfer.files.length>0&&v(M.dataTransfer.files)};return document.addEventListener("dragover",L),document.addEventListener("drop",b),()=>{document.removeEventListener("dragover",L),document.removeEventListener("drop",b)}},[v,n]);let m=(0,Be.useCallback)(async L=>{L.preventDefault();let b=L.currentTarget,R=new FormData(b).get("message")||"";b.reset();let _=await Promise.all(d.map(async({id:T,...D})=>{if(D.url?.startsWith("blob:")){let N=await iO(D.url);return{...D,url:N??D.url}}return D}));try{let T=l({files:_,text:R},L);T instanceof Promise&&await T,g()}catch{}},[d,l,g]),w=(0,Be.useMemo)(()=>({add:v,clear:g,files:d,openFileDialog:y,remove:S}),[d,v,S,g,y]);return(0,jt.jsxs)(IC.Provider,{value:w,children:[(0,jt.jsx)("input",{accept:t,"aria-label":"Upload files",className:"ww:hidden",multiple:a,onChange:x,ref:u,title:"Upload files",type:"file"}),(0,jt.jsx)("form",{className:$("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:m,ref:c,...s,children:i})]})};var Ll=({onChange:e,onKeyDown:t,className:a,placeholder:n="What would you like to know?",...r})=>{let o=LC(),[l,i]=(0,Be.useState)(!1),s=(0,Be.useCallback)(c=>{if(t?.(c),!c.defaultPrevented){if(c.key==="Enter"){if(l||c.nativeEvent.isComposing||c.shiftKey)return;c.preventDefault();let{form:d}=c.currentTarget;if(d?.querySelector('button[type="submit"]')?.disabled)return;d?.requestSubmit()}if(c.key==="Backspace"&&c.currentTarget.value===""&&o.files.length>0){c.preventDefault();let d=o.files.at(-1);d&&o.remove(d.id)}}},[t,l,o]),u=(0,Be.useCallback)(c=>{let d=c.clipboardData?.items;if(!d)return;let f=[];for(let p of d)if(p.kind==="file"){let y=p.getAsFile();y&&f.push(y)}f.length>0&&(c.preventDefault(),o.add(f))},[o]);return(0,jt.jsx)("textarea",{className:$("ww:field-sizing-content ww:max-h-48 ww:min-h-16 ww:w-full ww:resize-none ww:border-0 ww:bg-transparent ww:px-3 ww:py-3 ww:text-sm ww:outline-none ww:placeholder:text-muted-foreground",a),name:"message",onCompositionEnd:()=>i(!1),onCompositionStart:()=>i(!0),onKeyDown:s,onPaste:u,placeholder:n,onChange:e,...r})},kl=({className:e,status:t,onStop:a,onClick:n,children:r,...o})=>{let l=t==="submitted"||t==="streaming",i=(0,jt.jsx)(ls,{className:"ww:size-4"});t==="submitted"?i=(0,jt.jsx)(fs,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(i=(0,jt.jsx)(ms,{className:"ww:size-4"}));let s=(0,Be.useCallback)(u=>{if(l&&a){u.preventDefault(),a();return}n?.(u)},[l,a,n]);return(0,jt.jsx)(en,{"aria-label":l?"Stop":"Submit",className:$("ww:bg-foreground ww:text-background ww:hover:bg-foreground ww:rounded-full",e),onClick:s,size:"icon-sm",type:l&&a?"button":"submit",variant:"ghost",...o,children:r??i})},Tl=({className:e,children:t,...a})=>{let n=LC();return n.files.length>0?(0,jt.jsxs)(en,{className:$("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":"Remove all attachments",...a,children:[(0,jt.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,jt.jsx)(ao,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):(0,jt.jsx)(en,{className:$(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...a,children:t??(0,jt.jsx)(ps,{className:"ww:size-4"})})};var Hc=q(xe(),1);var ro=q(ee(),1),kC=({className:e,...t})=>(0,ro.jsx)("div",{className:$("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),TC=({className:e,...t})=>(0,ro.jsx)("li",{className:$("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}),AC=({className:e,...t})=>(0,ro.jsx)("span",{className:$("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),MC=({className:e,...t})=>(0,ro.jsx)("span",{className:$("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),EC=({className:e,...t})=>(0,ro.jsx)("div",{className:$("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),RC=({className:e,...t})=>(0,ro.jsx)(en,{className:$("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 Ea=q(ee(),1),DC=(0,Hc.memo)(({message:e,onRemove:t})=>{let a=(0,Hc.useCallback)(()=>t(e.id),[t,e.id]);return(0,Ea.jsxs)(TC,{children:[(0,Ea.jsx)(AC,{}),(0,Ea.jsx)(MC,{children:e.text||"(attachment)"}),(0,Ea.jsx)(EC,{children:(0,Ea.jsx)(RC,{"aria-label":"Remove from queue",onClick:a,children:(0,Ea.jsx)(ao,{className:"ww:size-3"})})})]})});DC.displayName="ChatQueueItem";function Al({queuedMessages:e,onRemove:t,className:a}){return e.length===0?null:(0,Ea.jsxs)(kC,{className:$("ww:border-t ww:border-border",a),children:[(0,Ea.jsxs)("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:[e.length," queued"]}),(0,Ea.jsx)("ul",{children:e.map(n=>(0,Ea.jsx)(DC,{message:n,onRemove:t},n.id))})]})}var xh=q(xe(),1),_C=q(ee(),1);function jc({messages:e,evalEnabled:t,api:a="/api/waniwani"}){let[n,r]=(0,xh.useState)(!1),[o,l]=(0,xh.useState)(null),i=async()=>{let u={name:`session-${new Date().toISOString().slice(0,19)}`,type:"functional",messages:e,mode:"manual"};r(!0),l(null);try{let c=await fetch(`${a}/scenarios`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!c.ok)throw new Error(`${c.status}`);l("saved")}catch{l("error")}finally{r(!1),setTimeout(()=>l(null),2e3)}};return!t||e.length===0?null:(0,_C.jsx)("button",{type:"button",onClick:i,disabled:n,title:"Save scenario to WaniWani",className:"ww:ml-auto ww:text-[10px] ww:font-mono ww:uppercase ww:tracking-wider ww:text-muted-foreground hover:ww:text-foreground ww:cursor-pointer ww:transition-colors ww:disabled:opacity-40",children:n?"saving...":o==="saved"?"saved":o==="error"?"error":"export"})}var xr=q(ee(),1),OC=({files:e,className:t,...a})=>e.length===0?null:(0,xr.jsx)("div",{className:$("ww:flex ww:flex-wrap ww:gap-1.5",t),...a,children:e.map((n,r)=>(0,xr.jsx)(sO,{file:n},r))});function sO({file:e}){return e.mediaType?.startsWith("image/")&&e.url?(0,xr.jsx)("img",{src:e.url,alt:e.filename??"attachment",className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):(0,xr.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,xr.jsx)(ds,{className:"ww:size-3 ww:shrink-0"}),(0,xr.jsx)("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??"file"})]})}var vh=q(ee(),1),wh=({className:e,size:t=5,...a})=>(0,vh.jsx)("div",{className:$("ww:flex ww:items-center ww:gap-1",e),...a,children:[0,1,2].map(n=>(0,vh.jsx)("div",{className:"ww:rounded-full ww:bg-muted-foreground/60",style:{width:t,height:t,animation:"ww-pulse 1.4s ease-in-out infinite",animationDelay:`${n*.2}s`}},n))});var PC={name:"cjk-noop",type:"cjk",remarkPluginsBefore:[],remarkPluginsAfter:[],remarkPlugins:[]};var NC={name:"shiki-noop",type:"code-highlighter",supportsLanguage:()=>!1,getSupportedLanguages:()=>[],getThemes:()=>["github-light","github-dark"],highlight:()=>null};var mM=q(xe(),1);$d();var Vs=q(ee(),1),Jd=({className:e,from:t,children:a,...n})=>(0,Vs.jsx)("div",{className:$("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),...n,children:(0,Vs.jsx)("div",{className:$("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),ef=({children:e,className:t,...a})=>(0,Vs.jsx)("div",{className:$("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}),Az={cjk:PC,code:NC},tf=(0,mM.memo)(({className:e,...t})=>(0,Vs.jsx)(Yd,{className:$("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),plugins:Az,...t}),(e,t)=>e.children===t.children);tf.displayName="MessageResponse";var gM=q(ee(),1);function hM({className:e,text:t,...a}){return t?(0,gM.jsx)("pre",{className:$("ww:mb-2 ww:overflow-x-auto ww:whitespace-pre-wrap ww:break-words ww:text-xs ww:font-mono ww:text-muted-foreground",e),...a,children:t}):null}var vt=q(xe(),1);var fe=q(ee(),1);function Mz(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 n=Object.entries(e),r=[],o=t-2;for(let[l,i]of n){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}`;r.push(c),o-=c.length+3}return`{${r.join(", ")}}`}function Ez({text:e,className:t}){let[a,n]=(0,vt.useState)(!1),r=(0,vt.useRef)(null);(0,vt.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]);let o=(0,vt.useCallback)(async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(e),n(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>n(!1),2e3)}catch{}},[e]);return(0,fe.jsx)(en,{variant:"ghost",size:"sm",onClick:o,className:$("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:a?(0,fe.jsxs)(fe.Fragment,{children:[(0,fe.jsx)(is,{className:"ww:size-3.5"}),(0,fe.jsx)("span",{children:"Copied"})]}):(0,fe.jsxs)(fe.Fragment,{children:[(0,fe.jsx)(cs,{className:"ww:size-3.5"}),(0,fe.jsx)("span",{children:"Copy"})]})})}function vM({data:e,label:t,className:a,...n}){let[r,o]=(0,vt.useState)(!1),l=(0,vt.useMemo)(()=>JSON.stringify(e,null,2),[e]),i=Mz(e);return(0,fe.jsxs)("div",{className:$("ww:rounded-lg ww:bg-tool-card",a),...n,children:[(0,fe.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[(0,fe.jsx)("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),(0,fe.jsx)(Ez,{text:l})]}),(0,fe.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,fe.jsx)(us,{className:$("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",r&&"ww:rotate-90")}),r?(0,fe.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,fe.jsx)("code",{children:l})}):(0,fe.jsx)("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var Zy=(0,vt.createContext)({open:!1,toggle:()=>{}});function wM({className:e,defaultOpen:t=!1,children:a,...n}){let[r,o]=(0,vt.useState)(t);return(0,fe.jsx)(Zy.Provider,{value:{open:r,toggle:()=>o(l=>!l)},children:(0,fe.jsx)("div",{className:$("ww:mb-4 ww:w-full",e),"data-state":r?"open":"closed",...n,children:a})})}function bM({className:e,title:t,state:a,...n}){let{open:r,toggle:o}=(0,vt.useContext)(Zy),l=a==="input-available"||a==="input-streaming";return(0,fe.jsxs)("button",{type:"button",onClick:o,className:$("ww:flex ww:w-full ww:items-center ww:justify-between ww:gap-3 ww:py-1.5",e),"aria-expanded":r,...n,children:[(0,fe.jsxs)("div",{className:"ww:flex ww:min-w-0 ww:items-center ww:gap-2",children:[(0,fe.jsx)(yr,{className:"ww:size-4 ww:shrink-0 ww:text-muted-foreground"}),(0,fe.jsx)("span",{className:"ww:truncate ww:text-sm ww:font-medium",children:t}),l&&(0,fe.jsx)("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]}),(0,fe.jsx)(ss,{className:$("ww:size-4 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-200",r&&"ww:rotate-180")})]})}function SM({className:e,children:t,...a}){let{open:n}=(0,vt.useContext)(Zy);return(0,fe.jsx)("div",{className:$("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",n?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,fe.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,fe.jsx)("div",{className:$("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 CM({className:e,input:t,debug:a,...n}){let r=(0,vt.useMemo)(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:o,...l}=t;return l}return t},[t,a]);return(0,fe.jsx)(vM,{data:r,label:"Request",className:e,...n})}function Xy(e){if(!(typeof e!="object"||e===null))return e}function IM(e){return Xy(e?.ui)}function LM(e){return Xy(Xy(e)?._meta)}function yM(e){if(!e)return;let t=IM(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 n=e["openai/outputTemplate"];if(typeof n=="string"&&n.length>0)return n}function xM(e){return IM(e)?.autoHeight===!0}function af(e,t,a){if(e){let n=yM(a?.[e]?._meta);if(n)return n}return yM(LM(t))}function kM(e,t,a){return e&&xM(a?.[e]?._meta)?!0:xM(LM(t))}function TM({className:e,output:t,errorText:a,debug:n,...r}){let o=(0,vt.useMemo)(()=>{if(!n&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:l,...i}=t;return i}return t},[t,n]);return t||a?a?(0,fe.jsxs)("div",{className:$("ww:space-y-2",e),...r,children:[(0,fe.jsx)("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:"Error"}),(0,fe.jsx)("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):(0,fe.jsx)(vM,{data:o,label:"Response",className:e,...r}):null}var qe=q(xe(),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 AM(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 EM=q(ee(),1),Rz="/api/mcp/resource",Dz=500,_z=0,Oz=16,Pz="2026-01-26",Nz=300,Bz=3e3,Uz=3;function zz(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function qz(e,t,a){return af(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function MM({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:n=Rz,chatSessionId:r,isDark:o=!1,className:l,autoHeight:i=!1,onOpenLink:s,onFollowUp:u,onCallTool:c,onDisplayModeChange:d,isFullscreen:f=!1,toolDefinitions:p}){let y=(0,qe.useRef)(null),v=(0,qe.useRef)(t),S=(0,qe.useRef)(a),g=(0,qe.useRef)({width:0,height:0}),x=(0,qe.useRef)(null),m=(0,qe.useRef)(!1),w=(0,qe.useRef)(0),L=(0,qe.useRef)("inline"),[b,M]=(0,qe.useState)(_z),[R,_]=(0,qe.useState)(void 0),T=(0,qe.useRef)(s),D=(0,qe.useRef)(u),N=(0,qe.useRef)(c),B=(0,qe.useRef)(d),j=(0,qe.useRef)(r),V=(0,qe.useRef)(p);v.current=t,S.current=a,T.current=s,D.current=u,N.current=c,B.current=d,j.current=r,V.current=p;let F=(0,qe.useCallback)(Z=>i?Math.max(Z+Oz,0):Math.min(Math.max(Z,50),Dz),[i]),te=(0,qe.useMemo)(()=>{let Z=n.includes("?")?"&":"?";return`${n}${Z}uri=${encodeURIComponent(e)}`},[n,e]),$e=(0,qe.useRef)(o);return $e.current=o,(0,qe.useEffect)(()=>{if(!m.current)return;let Z=y.current;Z?.contentWindow&&Z.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:o?"dark":"light"}},"*")},[o]),(0,qe.useEffect)(()=>{let Z=y.current;if(!Z)return;let C=!1,Xe=!1,le=null,k=null,Ze=setTimeout(()=>{if(C||Xe||w.current>=Uz)return;w.current+=1;let G=new URL(Z.src);G.searchParams.set("_retry",String(w.current)),Z.src=G.toString()},Bz),Ue=G=>{Z.contentWindow?.postMessage(G,"*")},Hn=G=>{if(C||G.source!==Z.contentWindow)return;let Q=G.data;if(!Q||typeof Q!="object"||Q.jsonrpc!=="2.0")return;let ke=Q.method,se=Q.id;if(ke==="ui/initialize"&&se!=null){Xe=!0,clearTimeout(Ze),Ue({jsonrpc:"2.0",id:se,result:{protocolVersion:Q.params?.protocolVersion??Pz,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:$e.current?"dark":"light",displayMode:L.current}}});return}if(ke==="ui/notifications/initialized"){m.current=!0;let Se=v.current,Le=S.current,Fe=Le._meta&&typeof Le._meta=="object"?Le._meta:null,St=zz(j.current),zt=Fe&&typeof Fe.waniwani=="object"&&Fe.waniwani!==null?Fe.waniwani:null,sn=zt||St?{...zt??{},...St?{sessionId:St}:{}}:void 0,un=Fe||sn?{...Fe??{},...sn?{waniwani:sn}:{}}:void 0;Ue({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:Se}});let To=Le.content??[{type:"text",text:JSON.stringify(Le)}];Ue({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:To,structuredContent:Le.structuredContent,_meta:un,meta:un}});return}if(ke==="ui/notifications/size-changed"){let Se=Q.params,Le=typeof Se?.height=="number"?Se.height:void 0,Fe=typeof Se?.width=="number"?Se.width:void 0,St=g.current,zt=Le!==void 0&&Le!==St.height,sn=Fe!==void 0&&Fe!==St.width;if(!zt&&!sn)return;if(zt&&Le!==void 0){St.height=Le;let un=F(Le),To=Z.getBoundingClientRect().height;if(x.current&&(x.current.cancel(),x.current=null),M(un),Z.animate&&Math.abs(To-un)>2){let Or=Z.animate([{height:`${To}px`},{height:`${un}px`}],{duration:Nz,easing:"ease-out",fill:"forwards"});x.current=Or,Or.onfinish=()=>{x.current===Or&&(Or.cancel(),x.current=null)}}}sn&&i&&Fe!==void 0&&(St.width=Fe,_(Fe));return}if(ke==="ui/open-link"&&se!=null){let Se=Q.params?.url;typeof Se=="string"&&(T.current?T.current(Se):window.open(Se,"_blank","noopener,noreferrer")),Ue({jsonrpc:"2.0",id:se,result:{}});return}if(ke==="ui/message"&&se!=null){if(D.current&&Q.params){let Se=Q.params,Le=le;if(le=null,k){clearTimeout(k.timer);let Fe=k.text;k=null;let St=(Se.content??[]).map(zt=>zt.text??"").join("").trim();Se={...Se,content:[{type:"text",text:`${St}
121
+ `||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},qy=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},dM=e=>{let t=yz.test(e),a=xz.test(e);if(t||a)return[e];let n=ya.lex(e,{gfm:!0}),r=[],o=[];for(let l of n){let i=l.raw,s=r.length;if(o.length>0){if(r[s-1]+=i,l.type==="html"){let u=i.match(vz);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(l.type==="html"&&l.block){let u=i.match(wz);if(u){let c=u[1];i.includes(`</${c}>`)||o.push(c)}}if(i.trim()==="$$"&&s>0){let u=r[s-1],c=zy(u),d=qy(u);if(c&&d%2===1){r[s-1]=u+i;continue}}if(s>0&&bz(i)){let u=r[s-1],c=zy(u),d=qy(u),f=qy(i);if(c&&d%2===1&&!zy(i)&&f===1){r[s-1]=u+i;continue}}r.push(i)}return r},fM={raw:GC,sanitize:[Yc,{}],harden:[jC,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},pM={gfm:[Cd,{}]},Sz=Object.values(fM),Cz=Object.values(pM),Iz={block:" \u258B",circle:" \u25CF"},Lz={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},Wt=(0,E.createContext)(Lz),$y=(0,E.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...n})=>(0,A.jsx)(cM,{...n,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||{}),n=Object.keys(t.components||{});if(a.length!==n.length||a.some(r=>{var o,l;return((o=e.components)==null?void 0:o[r])!==((l=t.components)==null?void 0:l[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});$y.displayName="Block";kz=["github-light","github-dark"],Yd=(0,E.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:n,rehypePlugins:r=Sz,remarkPlugins:o=Cz,className:l,shikiTheme:i=kz,mermaid:s,controls:u=!0,isAnimating:c=!1,BlockComponent:d=$y,parseMarkdownIntoBlocksFn:f=dM,caret:p,plugins:y,remend:v,linkSafety:S={enabled:!0},...g})=>{let x=(0,E.useId)(),[m,w]=(0,E.useTransition)(),L=(0,E.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?n1(e,v):e,[e,t,a,v]),b=(0,E.useMemo)(()=>f(L),[L,f]),[M,R]=(0,E.useState)(b);(0,E.useEffect)(()=>{t==="streaming"?w(()=>{R(b)}):R(b)},[b,t]);let _=t==="streaming"?M:b,T=(0,E.useMemo)(()=>_.map((F,te)=>`${x}-${te}`),[_.length,x]),D=(0,E.useMemo)(()=>{var F,te;return{shikiTheme:(te=(F=y?.code)==null?void 0:F.getThemes())!=null?te:i,controls:u,isAnimating:c,mode:t,mermaid:s,linkSafety:S}},[i,u,c,t,s,S,y?.code]),N=(0,E.useMemo)(()=>({...fz,...n}),[n]),B=(0,E.useMemo)(()=>{let F=[];return y!=null&&y.cjk&&(F=[...F,...y.cjk.remarkPluginsBefore]),F=[...F,...o],y!=null&&y.cjk&&(F=[...F,...y.cjk.remarkPluginsAfter]),y!=null&&y.math&&(F=[...F,y.math.remarkPlugin]),F},[o,y?.math,y?.cjk]),j=(0,E.useMemo)(()=>y!=null&&y.math?[...r,y.math.rehypePlugin]:r,[r,y?.math]),V=(0,E.useMemo)(()=>p&&c?{"--streamdown-caret":`"${Iz[p]}"`}:void 0,[p,c]);return t==="static"?(0,A.jsx)(Fy.Provider,{value:y??null,children:(0,A.jsx)(Wt.Provider,{value:D,children:(0,A.jsx)("div",{className:Y("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:(0,A.jsx)(cM,{components:N,rehypePlugins:j,remarkPlugins:B,...g,children:e})})})}):(0,A.jsx)(Fy.Provider,{value:y??null,children:(0,A.jsx)(Wt.Provider,{value:D,children:(0,A.jsxs)("div",{className:Y("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:[_.length===0&&p&&c&&(0,A.jsx)("span",{}),_.map((F,te)=>(0,A.jsx)(d,{components:N,content:F,index:te,rehypePlugins:j,remarkPlugins:B,shouldParseIncompleteMarkdown:a,...g},T[te]))]})})})},(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);Yd.displayName="Streamdown";Tz=({children:e,className:t,minZoom:a=.5,maxZoom:n=3,zoomStep:r=.1,showControls:o=!0,initialZoom:l=1,fullscreen:i=!1})=>{let s=(0,E.useRef)(null),u=(0,E.useRef)(null),[c,d]=(0,E.useState)(l),[f,p]=(0,E.useState)({x:0,y:0}),[y,v]=(0,E.useState)(!1),[S,g]=(0,E.useState)({x:0,y:0}),[x,m]=(0,E.useState)({x:0,y:0}),w=(0,E.useCallback)(N=>{d(B=>Math.max(a,Math.min(n,B+N)))},[a,n]),L=(0,E.useCallback)(()=>{w(r)},[w,r]),b=(0,E.useCallback)(()=>{w(-r)},[w,r]),M=(0,E.useCallback)(()=>{d(l),p({x:0,y:0})},[l]),R=(0,E.useCallback)(N=>{N.preventDefault();let B=N.deltaY>0?-r:r;w(B)},[w,r]),_=(0,E.useCallback)(N=>{if(N.button!==0||N.isPrimary===!1)return;v(!0),g({x:N.clientX,y:N.clientY}),m(f);let B=N.currentTarget;B instanceof HTMLElement&&B.setPointerCapture(N.pointerId)},[f]),T=(0,E.useCallback)(N=>{if(!y)return;N.preventDefault();let B=N.clientX-S.x,j=N.clientY-S.y;p({x:x.x+B,y:x.y+j})},[y,S,x]),D=(0,E.useCallback)(N=>{v(!1);let B=N.currentTarget;B instanceof HTMLElement&&B.releasePointerCapture(N.pointerId)},[]);return(0,E.useEffect)(()=>{let N=s.current;if(N)return N.addEventListener("wheel",R,{passive:!1}),()=>{N.removeEventListener("wheel",R)}},[R]),(0,E.useEffect)(()=>{let N=u.current;if(N&&y)return document.body.style.userSelect="none",N.addEventListener("pointermove",T,{passive:!1}),N.addEventListener("pointerup",D),N.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",N.removeEventListener("pointermove",T),N.removeEventListener("pointerup",D),N.removeEventListener("pointercancel",D)}},[y,T,D]),(0,A.jsxs)("div",{className:Y("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:y?"grabbing":"grab"},children:[o?(0,A.jsxs)("div",{className:Y("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,A.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>=n,onClick:L,title:"Zoom in",type:"button",children:(0,A.jsx)(jU,{size:16})}),(0,A.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,A.jsx)(VU,{size:16})}),(0,A.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:M,title:"Reset zoom and pan",type:"button",children:(0,A.jsx)(HU,{size:16})})]}):null,(0,A.jsx)("div",{className:Y("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:_,ref:u,role:"application",style:{transform:`translate(${f.x}px, ${f.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},By=({chart:e,className:t,config:a,fullscreen:n=!1,showControls:r=!0})=>{let[o,l]=(0,E.useState)(null),[i,s]=(0,E.useState)(!1),[u,c]=(0,E.useState)(""),[d,f]=(0,E.useState)(""),[p,y]=(0,E.useState)(0),{mermaid:v}=(0,E.useContext)(Wt),S=Gy(),g=v?.errorComponent,{shouldRender:x,containerRef:m}=zU({immediate:n});if((0,E.useEffect)(()=>{if(x){if(!S){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),s(!0);let L=S.getMermaid(a),b=e.split("").reduce((_,T)=>(_<<5)-_+T.charCodeAt(0)|0,0),M=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:R}=await L.render(M,e);c(R),f(R)}catch(L){if(!(d||u)){let b=L instanceof Error?L.message:"Failed to render Mermaid chart";l(b)}}finally{s(!1)}})()}},[e,a,p,x,S]),!(x||u||d))return(0,A.jsx)("div",{className:Y("my-4 min-h-[200px]",t),ref:m});if(i&&!u&&!d)return(0,A.jsx)("div",{className:Y("my-4 flex justify-center p-4",t),ref:m,children:(0,A.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,A.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,A.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return g?(0,A.jsx)("div",{ref:m,children:(0,A.jsx)(g,{chart:e,error:o,retry:()=>y(b=>b+1)})}):(0,A.jsxs)("div",{className:Y("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:m,children:[(0,A.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,A.jsxs)("details",{className:"mt-2",children:[(0,A.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,A.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,A.jsx)("div",{className:Y("size-full",t),"data-streamdown":"mermaid",ref:m,children:(0,A.jsx)(Tz,{className:Y(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:(0,A.jsx)("div",{"aria-label":"Mermaid chart",className:Y("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:w},role:"img"})})})}});var h2=Ot((HJ,m2)=>{"use strict";function QF(e,t){if(typeof e!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof e}\`.`);let a,n=0;return function(...o){clearTimeout(a);let l=Date.now(),i=l-n,s=t-i;s<=0?(n=l,e.apply(this,o)):a=setTimeout(()=>{n=Date.now(),e.apply(this,o)},s)}}m2.exports=QF});var Lf=q(xe(),1),yx=q(sC(),1);var U_="https://app.waniwani.ai/api/mcp/chat",z_={api:U_,title:"Assistant",position:"bottom-right",width:400,height:600};function q_(){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 _c(){let e=q_();if(!e)return{};let t=L=>e.getAttribute(L)??void 0,a=L=>{let b=e.getAttribute(L);if(b==null)return;let M=Number(b);return Number.isFinite(M)?M:void 0},n={},r=t("data-api");r&&(n.api=r);let o=t("data-token");o&&(n.token=o);let l=t("data-title");l&&(n.title=l);let i=t("data-welcome-message");i&&(n.welcomeMessage=i);let s=t("data-placeholder");s&&(n.placeholder=s);let u=t("data-mcp-server-url");u&&(n.mcpServerUrl=u);let c=t("data-css");c&&(n.css=c);let d=t("data-suggestions");d&&(n.suggestions=d.split(",").map(L=>L.trim()).filter(Boolean));let f=t("data-position");(f==="bottom-right"||f==="bottom-left")&&(n.position=f);let p=t("data-mode");(p==="floating"||p==="custom"||p==="inline")&&(n.mode=p);let y=t("data-layout");(y==="card"||y==="bar"||y==="embed")&&(n.layout=y);let v=a("data-width");v&&(n.width=v);let S=a("data-height");S&&(n.height=S);let g=t("data-primary-color"),x=t("data-background-color"),m=t("data-text-color"),w=t("data-font-family");return(g||x||m||w)&&(n.theme={},g&&(n.theme.primaryColor=g),x&&(n.theme.backgroundColor=x),m&&(n.theme.textColor=m),w&&(n.theme.fontFamily=w)),n}function Oc(e,t,a){let n=a??_c(),r={token:"",...z_,...t??{},...n,...e,theme:{...t?.theme??{},...n.theme,...e?.theme}};if(!r.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return r.mode||(r.mode="inline"),r}function Pc(e){if(!e.theme)return;let t=e.theme;return{...t.primaryColor?{primaryColor:t.primaryColor}:{},...t.backgroundColor?{backgroundColor:t.backgroundColor}:{},...t.textColor?{textColor:t.textColor}:{},...t.fontFamily?{fontFamily:t.fontFamily}:{}}}var ct=q(xe(),1);var Ut=q(xe(),1);var Bc=q(xe());var Nc=(...e)=>e.filter((t,a,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===a).join(" ").trim();var uC=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var cC=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,n)=>n?n.toUpperCase():a.toLowerCase());var dh=e=>{let t=cC(e);return t.charAt(0).toUpperCase()+t.slice(1)};var rs=q(xe());var dC={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 fC=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var pC=(0,rs.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:n,className:r="",children:o,iconNode:l,...i},s)=>(0,rs.createElement)("svg",{ref:s,...dC,width:t,height:t,stroke:e,strokeWidth:n?Number(a)*24/Number(t):a,className:Nc("lucide",r),...!o&&!fC(i)&&{"aria-hidden":"true"},...i},[...l.map(([u,c])=>(0,rs.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var Ye=(e,t)=>{let a=(0,Bc.forwardRef)(({className:n,...r},o)=>(0,Bc.createElement)(pC,{ref:o,iconNode:t,className:Nc(`lucide-${uC(dh(e))}`,`lucide-${e}`,n),...r}));return a.displayName=dh(e),a};var F_=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],os=Ye("arrow-down",F_);var H_=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],ls=Ye("arrow-up",H_);var j_=[["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"}]],yr=Ye("braces",j_);var V_=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],is=Ye("check",V_);var G_=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ss=Ye("chevron-down",G_);var W_=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],us=Ye("chevron-right",W_);var $_=[["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"}]],cs=Ye("clipboard-copy",$_);var X_=[["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"}]],ds=Ye("file",X_);var Z_=[["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"}]],fs=Ye("loader",Z_);var Q_=[["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"}]],ps=Ye("paperclip",Q_);var K_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],ms=Ye("square",K_);var Y_=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],ao=Ye("x",Y_);var CC=q(xe(),1);var _t=q(xe(),1);var J_={damping:.7,stiffness:.05,mass:1.25},eO=70,tO=1e3/60,aO=350,Uc=!1;globalThis.document?.addEventListener("mousedown",()=>{Uc=!0});globalThis.document?.addEventListener("mouseup",()=>{Uc=!1});globalThis.document?.addEventListener("click",()=>{Uc=!1});var hC=(e={})=>{let[t,a]=(0,_t.useState)(!1),[n,r]=(0,_t.useState)(e.initial!==!1),[o,l]=(0,_t.useState)(!1),i=(0,_t.useRef)(null);i.current=e;let s=(0,_t.useCallback)(()=>{if(!Uc)return!1;let x=window.getSelection();if(!x||!x.rangeCount)return!1;let m=x.getRangeAt(0);return m.commonAncestorContainer.contains(S.current)||S.current?.contains(m.commonAncestorContainer)},[]),u=(0,_t.useCallback)(x=>{d.isAtBottom=x,r(x)},[]),c=(0,_t.useCallback)(x=>{d.escapedFromLock=x,a(x)},[]),d=(0,_t.useMemo)(()=>{let x;return{escapedFromLock:t,isAtBottom:n,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return S.current?.scrollTop??0},set scrollTop(m){S.current&&(S.current.scrollTop=m,d.ignoreScrollToTop=S.current.scrollTop)},get targetScrollTop(){return!S.current||!g.current?0:S.current.scrollHeight-1-S.current.clientHeight},get calculatedTargetScrollTop(){if(!S.current||!g.current)return 0;let{targetScrollTop:m}=this;if(!e.targetScrollTop)return m;if(x?.targetScrollTop===m)return x.calculatedScrollTop;let w=Math.max(Math.min(e.targetScrollTop(m,{scrollElement:S.current,contentElement:g.current}),m),0);return x={targetScrollTop:m,calculatedScrollTop:w},requestAnimationFrame(()=>{x=void 0}),w},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=eO}}},[]),f=(0,_t.useCallback)((x={})=>{typeof x=="string"&&(x={animation:x}),x.preserveScrollPosition||u(!0);let m=Date.now()+(Number(x.wait)||0),w=ph(i.current,x.animation),{ignoreEscapes:L=!1}=x,b,M=d.calculatedTargetScrollTop;x.duration instanceof Promise?x.duration.finally(()=>{b=Date.now()}):b=m+(x.duration??0);let R=async()=>{let _=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:T}=d,D=performance.now(),N=(D-(d.lastTick??D))/tO;if(d.animation||(d.animation={behavior:w,promise:_,ignoreEscapes:L}),d.animation.behavior===w&&(d.lastTick=D),s()||m>Date.now())return R();if(T<Math.min(M,d.calculatedTargetScrollTop)){if(d.animation?.behavior===w){if(w==="instant")return d.scrollTop=d.calculatedTargetScrollTop,R();d.velocity=(w.damping*d.velocity+w.stiffness*d.scrollDifference)/w.mass,d.accumulated+=d.velocity*N,d.scrollTop+=d.accumulated,d.scrollTop!==T&&(d.accumulated=0)}return R()}return b>Date.now()?(M=d.calculatedTargetScrollTop,R()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:ph(i.current,i.current.resize),ignoreEscapes:L,duration:Math.max(0,b-Date.now())||void 0}):d.isAtBottom)});return _.then(T=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),T))};return x.wait!==!0&&(d.animation=void 0),d.animation?.behavior===w?d.animation.promise:R()},[u,s,d]),p=(0,_t.useCallback)(()=>{c(!0),u(!1)},[c,u]),y=(0,_t.useCallback)(({target:x})=>{if(x!==S.current)return;let{scrollTop:m,ignoreScrollToTop:w}=d,{lastScrollTop:L=m}=d;d.lastScrollTop=m,d.ignoreScrollToTop=void 0,w&&w>m&&(L=w),l(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||m===w)return;if(s()){c(!0),u(!1);return}let b=m>L,M=m<L;if(d.animation?.ignoreEscapes){d.scrollTop=L;return}M&&(c(!0),u(!1)),b&&c(!1),!d.escapedFromLock&&d.isNearBottom&&u(!0)},1)},[c,u,s,d]),v=(0,_t.useCallback)(({target:x,deltaY:m})=>{let w=x;for(;!["scroll","auto"].includes(getComputedStyle(w).overflow);){if(!w.parentElement)return;w=w.parentElement}w===S.current&&m<0&&S.current.scrollHeight>S.current.clientHeight&&!d.animation?.ignoreEscapes&&(c(!0),u(!1))},[c,u,d]),S=mC(x=>{S.current?.removeEventListener("scroll",y),S.current?.removeEventListener("wheel",v),x?.addEventListener("scroll",y,{passive:!0}),x?.addEventListener("wheel",v,{passive:!0})},[]),g=mC(x=>{if(d.resizeObserver?.disconnect(),!x)return;let m;d.resizeObserver=new ResizeObserver(([w])=>{let{height:L}=w.contentRect,b=L-(m??L);if(d.resizeDifference=b,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),l(d.isNearBottom),b>=0){let M=ph(i.current,m?i.current.resize:i.current.initial);f({animation:M,wait:!0,preserveScrollPosition:!0,duration:M==="instant"?void 0:aO})}else d.isNearBottom&&(c(!1),u(!0));m=L,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===b&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(x)},[]);return{contentRef:g,scrollRef:S,scrollToBottom:f,stopScroll:p,isAtBottom:n||o,isNearBottom:o,escapedFromLock:t,state:d}};function mC(e,t){let a=(0,_t.useCallback)(n=>(a.current=n,e(n)),t);return a}var fh=new Map;function ph(...e){let t={...J_},a=!1;for(let r of e){if(r==="instant"){a=!0;continue}typeof r=="object"&&(a=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let n=JSON.stringify(t);return fh.has(n)||fh.set(n,Object.freeze(t)),a?"instant":fh.get(n)}var no=q(xe(),1),ta=q(xe(),1);var gC=(0,ta.createContext)(null),nO=typeof window<"u"?ta.useLayoutEffect:ta.useEffect;function hs({instance:e,children:t,resize:a,initial:n,mass:r,damping:o,stiffness:l,targetScrollTop:i,contextRef:s,...u}){let c=(0,ta.useRef)(null),d=no.useCallback((L,b)=>(w?.targetScrollTop??i)?.(L,b)??L,[i]),f=hC({mass:r,damping:o,stiffness:l,resize:a,initial:n,targetScrollTop:d}),{scrollRef:p,contentRef:y,scrollToBottom:v,stopScroll:S,isAtBottom:g,escapedFromLock:x,state:m}=e??f,w=(0,ta.useMemo)(()=>({scrollToBottom:v,stopScroll:S,scrollRef:p,isAtBottom:g,escapedFromLock:x,contentRef:y,state:m,get targetScrollTop(){return c.current},set targetScrollTop(L){c.current=L}}),[v,g,y,p,S,x,m]);return(0,ta.useImperativeHandle)(s,()=>w,[w]),nO(()=>{p.current&&getComputedStyle(p.current).overflow==="visible"&&(p.current.style.overflow="auto")},[]),no.createElement(gC.Provider,{value:w},no.createElement("div",{...u},typeof t=="function"?t(w):t))}(function(e){function t({children:a,scrollClassName:n,...r}){let o=mh();return no.createElement("div",{ref:o.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:n},no.createElement("div",{...r,ref:o.contentRef},typeof a=="function"?a(o):a))}e.Content=t})(hs||(hs={}));function mh(){let e=(0,ta.useContext)(gC);if(!e)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return e}hh();yh();var rO=xC({prefix:"ww"});function $(...e){return rO(zc(e))}var SC=q(ee(),1),en=({className:e,variant:t="default",size:a="default",type:n="button",...r})=>(0,SC.jsx)("button",{type:n,className:$("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),...r});var gs=q(ee(),1),bl=({className:e,...t})=>(0,gs.jsx)(hs,{className:$("ww:relative ww:flex-1 ww:overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),Sl=({className:e,...t})=>(0,gs.jsx)(hs.Content,{className:$("ww:flex ww:flex-col ww:gap-6 ww:px-4 ww:py-6 ww:mx-auto ww:w-full ww:max-w-3xl",e),...t}),Cl=({className:e,...t})=>{let{isAtBottom:a,scrollToBottom:n}=mh(),r=(0,CC.useCallback)(()=>{n()},[n]);return!a&&(0,gs.jsx)(en,{className:$("ww:absolute ww:bottom-4 ww:left-[50%] ww:translate-x-[-50%] ww:rounded-full",e),onClick:r,size:"icon",variant:"outline",...t,children:(0,gs.jsx)(os,{className:"ww:size-4"})})};var Fc=(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 Be=q(xe(),1);var jt=q(ee(),1),iO=async e=>{try{let a=await(await fetch(e)).blob();return new Promise(n=>{let r=new FileReader;r.onloadend=()=>n(r.result),r.onerror=()=>n(null),r.readAsDataURL(a)})}catch{return null}},IC=(0,Be.createContext)(null),LC=()=>{let e=(0,Be.useContext)(IC);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},Il=({className:e,accept:t,multiple:a,globalDrop:n,maxFiles:r,maxFileSize:o,onSubmit:l,children:i,...s})=>{let u=(0,Be.useRef)(null),c=(0,Be.useRef)(null),[d,f]=(0,Be.useState)([]),p=(0,Be.useRef)(d);(0,Be.useEffect)(()=>{p.current=d},[d]);let y=(0,Be.useCallback)(()=>{u.current?.click()},[]),v=(0,Be.useCallback)(L=>{let b=[...L];if(b.length===0)return;let M=_=>o?_.size<=o:!0,R=b.filter(M);f(_=>{let T=typeof r=="number"?Math.max(0,r-_.length):void 0,D=typeof T=="number"?R.slice(0,T):R;return[..._,...D.map(N=>({filename:N.name,id:Fc(),mediaType:N.type,type:"file",url:URL.createObjectURL(N)}))]})},[r,o]),S=(0,Be.useCallback)(L=>{f(b=>{let M=b.find(R=>R.id===L);return M?.url&&URL.revokeObjectURL(M.url),b.filter(R=>R.id!==L)})},[]),g=(0,Be.useCallback)(()=>{f(L=>{for(let b of L)b.url&&URL.revokeObjectURL(b.url);return[]})},[]);(0,Be.useEffect)(()=>()=>{for(let L of p.current)L.url&&URL.revokeObjectURL(L.url)},[]);let x=(0,Be.useCallback)(L=>{L.currentTarget.files&&v(L.currentTarget.files),L.currentTarget.value=""},[v]);(0,Be.useEffect)(()=>{if(!n)return;let L=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault()},b=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault(),M.dataTransfer?.files&&M.dataTransfer.files.length>0&&v(M.dataTransfer.files)};return document.addEventListener("dragover",L),document.addEventListener("drop",b),()=>{document.removeEventListener("dragover",L),document.removeEventListener("drop",b)}},[v,n]);let m=(0,Be.useCallback)(async L=>{L.preventDefault();let b=L.currentTarget,R=new FormData(b).get("message")||"";b.reset();let _=await Promise.all(d.map(async({id:T,...D})=>{if(D.url?.startsWith("blob:")){let N=await iO(D.url);return{...D,url:N??D.url}}return D}));try{let T=l({files:_,text:R},L);T instanceof Promise&&await T,g()}catch{}},[d,l,g]),w=(0,Be.useMemo)(()=>({add:v,clear:g,files:d,openFileDialog:y,remove:S}),[d,v,S,g,y]);return(0,jt.jsxs)(IC.Provider,{value:w,children:[(0,jt.jsx)("input",{accept:t,"aria-label":"Upload files",className:"ww:hidden",multiple:a,onChange:x,ref:u,title:"Upload files",type:"file"}),(0,jt.jsx)("form",{className:$("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:m,ref:c,...s,children:i})]})};var Ll=({onChange:e,onKeyDown:t,className:a,placeholder:n="What would you like to know?",...r})=>{let o=LC(),[l,i]=(0,Be.useState)(!1),s=(0,Be.useCallback)(c=>{if(t?.(c),!c.defaultPrevented){if(c.key==="Enter"){if(l||c.nativeEvent.isComposing||c.shiftKey)return;c.preventDefault();let{form:d}=c.currentTarget;if(d?.querySelector('button[type="submit"]')?.disabled)return;d?.requestSubmit()}if(c.key==="Backspace"&&c.currentTarget.value===""&&o.files.length>0){c.preventDefault();let d=o.files.at(-1);d&&o.remove(d.id)}}},[t,l,o]),u=(0,Be.useCallback)(c=>{let d=c.clipboardData?.items;if(!d)return;let f=[];for(let p of d)if(p.kind==="file"){let y=p.getAsFile();y&&f.push(y)}f.length>0&&(c.preventDefault(),o.add(f))},[o]);return(0,jt.jsx)("textarea",{className:$("ww:field-sizing-content ww:max-h-48 ww:min-h-16 ww:w-full ww:resize-none ww:border-0 ww:bg-transparent ww:px-3 ww:py-3 ww:text-sm ww:outline-none ww:placeholder:text-muted-foreground",a),name:"message",onCompositionEnd:()=>i(!1),onCompositionStart:()=>i(!0),onKeyDown:s,onPaste:u,placeholder:n,onChange:e,...r})},kl=({className:e,status:t,onStop:a,onClick:n,children:r,...o})=>{let l=t==="submitted"||t==="streaming",i=(0,jt.jsx)(ls,{className:"ww:size-4"});t==="submitted"?i=(0,jt.jsx)(fs,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(i=(0,jt.jsx)(ms,{className:"ww:size-4"}));let s=(0,Be.useCallback)(u=>{if(l&&a){u.preventDefault(),a();return}n?.(u)},[l,a,n]);return(0,jt.jsx)(en,{"aria-label":l?"Stop":"Submit",className:$("ww:bg-foreground ww:text-background ww:hover:bg-foreground ww:rounded-full",e),onClick:s,size:"icon-sm",type:l&&a?"button":"submit",variant:"ghost",...o,children:r??i})},Tl=({className:e,children:t,...a})=>{let n=LC();return n.files.length>0?(0,jt.jsxs)(en,{className:$("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":"Remove all attachments",...a,children:[(0,jt.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,jt.jsx)(ao,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):(0,jt.jsx)(en,{className:$(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...a,children:t??(0,jt.jsx)(ps,{className:"ww:size-4"})})};var Hc=q(xe(),1);var ro=q(ee(),1),kC=({className:e,...t})=>(0,ro.jsx)("div",{className:$("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),TC=({className:e,...t})=>(0,ro.jsx)("li",{className:$("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}),AC=({className:e,...t})=>(0,ro.jsx)("span",{className:$("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),MC=({className:e,...t})=>(0,ro.jsx)("span",{className:$("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),EC=({className:e,...t})=>(0,ro.jsx)("div",{className:$("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),RC=({className:e,...t})=>(0,ro.jsx)(en,{className:$("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 Ea=q(ee(),1),DC=(0,Hc.memo)(({message:e,onRemove:t})=>{let a=(0,Hc.useCallback)(()=>t(e.id),[t,e.id]);return(0,Ea.jsxs)(TC,{children:[(0,Ea.jsx)(AC,{}),(0,Ea.jsx)(MC,{children:e.text||"(attachment)"}),(0,Ea.jsx)(EC,{children:(0,Ea.jsx)(RC,{"aria-label":"Remove from queue",onClick:a,children:(0,Ea.jsx)(ao,{className:"ww:size-3"})})})]})});DC.displayName="ChatQueueItem";function Al({queuedMessages:e,onRemove:t,className:a}){return e.length===0?null:(0,Ea.jsxs)(kC,{className:$("ww:border-t ww:border-border",a),children:[(0,Ea.jsxs)("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:[e.length," queued"]}),(0,Ea.jsx)("ul",{children:e.map(n=>(0,Ea.jsx)(DC,{message:n,onRemove:t},n.id))})]})}var xh=q(xe(),1),_C=q(ee(),1);function jc({messages:e,evalEnabled:t,api:a="/api/waniwani"}){let[n,r]=(0,xh.useState)(!1),[o,l]=(0,xh.useState)(null),i=async()=>{let u={name:`session-${new Date().toISOString().slice(0,19)}`,type:"functional",messages:e,mode:"manual"};r(!0),l(null);try{let c=await fetch(`${a}/scenarios`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)});if(!c.ok)throw new Error(`${c.status}`);l("saved")}catch{l("error")}finally{r(!1),setTimeout(()=>l(null),2e3)}};return!t||e.length===0?null:(0,_C.jsx)("button",{type:"button",onClick:i,disabled:n,title:"Save scenario to WaniWani",className:"ww:ml-auto ww:text-[10px] ww:font-mono ww:uppercase ww:tracking-wider ww:text-muted-foreground hover:ww:text-foreground ww:cursor-pointer ww:transition-colors ww:disabled:opacity-40",children:n?"saving...":o==="saved"?"saved":o==="error"?"error":"export"})}var xr=q(ee(),1),OC=({files:e,className:t,...a})=>e.length===0?null:(0,xr.jsx)("div",{className:$("ww:flex ww:flex-wrap ww:gap-1.5",t),...a,children:e.map((n,r)=>(0,xr.jsx)(sO,{file:n},r))});function sO({file:e}){return e.mediaType?.startsWith("image/")&&e.url?(0,xr.jsx)("img",{src:e.url,alt:e.filename??"attachment",className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):(0,xr.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,xr.jsx)(ds,{className:"ww:size-3 ww:shrink-0"}),(0,xr.jsx)("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??"file"})]})}var vh=q(ee(),1),wh=({className:e,size:t=5,...a})=>(0,vh.jsx)("div",{className:$("ww:flex ww:items-center ww:gap-1",e),...a,children:[0,1,2].map(n=>(0,vh.jsx)("div",{className:"ww:rounded-full ww:bg-muted-foreground/60",style:{width:t,height:t,animation:"ww-pulse 1.4s ease-in-out infinite",animationDelay:`${n*.2}s`}},n))});var PC={name:"cjk-noop",type:"cjk",remarkPluginsBefore:[],remarkPluginsAfter:[],remarkPlugins:[]};var NC={name:"shiki-noop",type:"code-highlighter",supportsLanguage:()=>!1,getSupportedLanguages:()=>[],getThemes:()=>["github-light","github-dark"],highlight:()=>null};var mM=q(xe(),1);$d();var Vs=q(ee(),1),Jd=({className:e,from:t,children:a,...n})=>(0,Vs.jsx)("div",{className:$("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),...n,children:(0,Vs.jsx)("div",{className:$("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),ef=({children:e,className:t,...a})=>(0,Vs.jsx)("div",{className:$("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}),Az={cjk:PC,code:NC},tf=(0,mM.memo)(({className:e,...t})=>(0,Vs.jsx)(Yd,{className:$("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),plugins:Az,...t}),(e,t)=>e.children===t.children);tf.displayName="MessageResponse";var gM=q(ee(),1);function hM({className:e,text:t,...a}){return t?(0,gM.jsx)("pre",{className:$("ww:mb-2 ww:overflow-x-auto ww:whitespace-pre-wrap ww:break-words ww:text-xs ww:font-mono ww:text-muted-foreground",e),...a,children:t}):null}var vt=q(xe(),1);var fe=q(ee(),1);function Mz(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 n=Object.entries(e),r=[],o=t-2;for(let[l,i]of n){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}`;r.push(c),o-=c.length+3}return`{${r.join(", ")}}`}function Ez({text:e,className:t}){let[a,n]=(0,vt.useState)(!1),r=(0,vt.useRef)(null);(0,vt.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]);let o=(0,vt.useCallback)(async l=>{l.stopPropagation();try{await navigator.clipboard.writeText(e),n(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>n(!1),2e3)}catch{}},[e]);return(0,fe.jsx)(en,{variant:"ghost",size:"sm",onClick:o,className:$("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:a?(0,fe.jsxs)(fe.Fragment,{children:[(0,fe.jsx)(is,{className:"ww:size-3.5"}),(0,fe.jsx)("span",{children:"Copied"})]}):(0,fe.jsxs)(fe.Fragment,{children:[(0,fe.jsx)(cs,{className:"ww:size-3.5"}),(0,fe.jsx)("span",{children:"Copy"})]})})}function vM({data:e,label:t,className:a,...n}){let[r,o]=(0,vt.useState)(!1),l=(0,vt.useMemo)(()=>JSON.stringify(e,null,2),[e]),i=Mz(e);return(0,fe.jsxs)("div",{className:$("ww:rounded-lg ww:bg-tool-card",a),...n,children:[(0,fe.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[(0,fe.jsx)("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),(0,fe.jsx)(Ez,{text:l})]}),(0,fe.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,fe.jsx)(us,{className:$("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",r&&"ww:rotate-90")}),r?(0,fe.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,fe.jsx)("code",{children:l})}):(0,fe.jsx)("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var Zy=(0,vt.createContext)({open:!1,toggle:()=>{}});function wM({className:e,defaultOpen:t=!1,children:a,...n}){let[r,o]=(0,vt.useState)(t);return(0,fe.jsx)(Zy.Provider,{value:{open:r,toggle:()=>o(l=>!l)},children:(0,fe.jsx)("div",{className:$("ww:mb-4 ww:w-full",e),"data-state":r?"open":"closed",...n,children:a})})}function bM({className:e,title:t,state:a,...n}){let{open:r,toggle:o}=(0,vt.useContext)(Zy),l=a==="input-available"||a==="input-streaming";return(0,fe.jsxs)("button",{type:"button",onClick:o,className:$("ww:flex ww:w-full ww:items-center ww:justify-between ww:gap-3 ww:py-1.5",e),"aria-expanded":r,...n,children:[(0,fe.jsxs)("div",{className:"ww:flex ww:min-w-0 ww:items-center ww:gap-2",children:[(0,fe.jsx)(yr,{className:"ww:size-4 ww:shrink-0 ww:text-muted-foreground"}),(0,fe.jsx)("span",{className:"ww:truncate ww:text-sm ww:font-medium",children:t}),l&&(0,fe.jsx)("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]}),(0,fe.jsx)(ss,{className:$("ww:size-4 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-200",r&&"ww:rotate-180")})]})}function SM({className:e,children:t,...a}){let{open:n}=(0,vt.useContext)(Zy);return(0,fe.jsx)("div",{className:$("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",n?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:(0,fe.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,fe.jsx)("div",{className:$("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 CM({className:e,input:t,debug:a,...n}){let r=(0,vt.useMemo)(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:o,...l}=t;return l}return t},[t,a]);return(0,fe.jsx)(vM,{data:r,label:"Request",className:e,...n})}function Xy(e){if(!(typeof e!="object"||e===null))return e}function IM(e){return Xy(e?.ui)}function LM(e){return Xy(Xy(e)?._meta)}function yM(e){if(!e)return;let t=IM(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 n=e["openai/outputTemplate"];if(typeof n=="string"&&n.length>0)return n}function xM(e){return IM(e)?.autoHeight===!0}function af(e,t,a){if(e){let n=yM(a?.[e]?._meta);if(n)return n}return yM(LM(t))}function kM(e,t,a){return e&&xM(a?.[e]?._meta)?!0:xM(LM(t))}function TM({className:e,output:t,errorText:a,debug:n,...r}){let o=(0,vt.useMemo)(()=>{if(!n&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:l,...i}=t;return i}return t},[t,n]);return t||a?a?(0,fe.jsxs)("div",{className:$("ww:space-y-2",e),...r,children:[(0,fe.jsx)("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:"Error"}),(0,fe.jsx)("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):(0,fe.jsx)(vM,{data:o,label:"Response",className:e,...r}):null}var qe=q(xe(),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 AM(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 EM=q(ee(),1),Rz="/api/mcp/resource",Dz=500,_z=0,Oz=16,Pz="2026-01-26",Nz=300,Bz=3e3,Uz=3;function zz(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function qz(e,t,a){return af(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function MM({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:n=Rz,chatSessionId:r,isDark:o=!1,className:l,autoHeight:i=!1,onOpenLink:s,onFollowUp:u,onCallTool:c,onDisplayModeChange:d,isFullscreen:f=!1,toolDefinitions:p}){let y=(0,qe.useRef)(null),v=(0,qe.useRef)(t),S=(0,qe.useRef)(a),g=(0,qe.useRef)({width:0,height:0}),x=(0,qe.useRef)(null),m=(0,qe.useRef)(!1),w=(0,qe.useRef)(0),L=(0,qe.useRef)("inline"),[b,M]=(0,qe.useState)(_z),[R,_]=(0,qe.useState)(void 0),T=(0,qe.useRef)(s),D=(0,qe.useRef)(u),N=(0,qe.useRef)(c),B=(0,qe.useRef)(d),j=(0,qe.useRef)(r),V=(0,qe.useRef)(p);v.current=t,S.current=a,T.current=s,D.current=u,N.current=c,B.current=d,j.current=r,V.current=p;let F=(0,qe.useCallback)(Z=>i?Math.max(Z+Oz,0):Math.min(Math.max(Z,50),Dz),[i]),te=(0,qe.useMemo)(()=>{let Z=n.includes("?")?"&":"?";return`${n}${Z}uri=${encodeURIComponent(e)}`},[n,e]),$e=(0,qe.useRef)(o);return $e.current=o,(0,qe.useEffect)(()=>{if(!m.current)return;let Z=y.current;Z?.contentWindow&&Z.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:o?"dark":"light"}},"*")},[o]),(0,qe.useEffect)(()=>{let Z=y.current;if(!Z)return;let C=!1,Xe=!1,le=null,k=null,Ze=setTimeout(()=>{if(C||Xe||w.current>=Uz)return;w.current+=1;let G=new URL(Z.src);G.searchParams.set("_retry",String(w.current)),Z.src=G.toString()},Bz),Ue=G=>{Z.contentWindow?.postMessage(G,"*")},Hn=G=>{if(C||G.source!==Z.contentWindow)return;let Q=G.data;if(!Q||typeof Q!="object"||Q.jsonrpc!=="2.0")return;let ke=Q.method,se=Q.id;if(ke==="ui/initialize"&&se!=null){Xe=!0,clearTimeout(Ze),Ue({jsonrpc:"2.0",id:se,result:{protocolVersion:Q.params?.protocolVersion??Pz,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:$e.current?"dark":"light",displayMode:L.current}}});return}if(ke==="ui/notifications/initialized"){m.current=!0;let Se=v.current,Le=S.current,Fe=Le._meta&&typeof Le._meta=="object"?Le._meta:null,St=zz(j.current),zt=Fe&&typeof Fe.waniwani=="object"&&Fe.waniwani!==null?Fe.waniwani:null,sn=zt||St?{...zt??{},...St?{sessionId:St}:{}}:void 0,un=Fe||sn?{...Fe??{},...sn?{waniwani:sn}:{}}:void 0;Ue({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:Se}});let To=Le.content??[{type:"text",text:JSON.stringify(Le)}];Ue({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:To,structuredContent:Le.structuredContent,_meta:un,meta:un}});return}if(ke==="ui/notifications/size-changed"){let Se=Q.params,Le=typeof Se?.height=="number"?Se.height:void 0,Fe=typeof Se?.width=="number"?Se.width:void 0,St=g.current,zt=Le!==void 0&&Le!==St.height,sn=Fe!==void 0&&Fe!==St.width;if(!zt&&!sn)return;if(zt&&Le!==void 0){St.height=Le;let un=F(Le),To=Z.getBoundingClientRect().height;if(x.current&&(x.current.cancel(),x.current=null),M(un),Z.animate&&Math.abs(To-un)>2){let Or=Z.animate([{height:`${To}px`},{height:`${un}px`}],{duration:Nz,easing:"ease-out",fill:"forwards"});x.current=Or,Or.onfinish=()=>{x.current===Or&&(Or.cancel(),x.current=null)}}}sn&&i&&Fe!==void 0&&(St.width=Fe,_(Fe));return}if(ke==="ui/open-link"&&se!=null){let Se=Q.params?.url;typeof Se=="string"&&(T.current?T.current(Se):window.open(Se,"_blank","noopener,noreferrer")),Ue({jsonrpc:"2.0",id:se,result:{}});return}if(ke==="ui/message"&&se!=null){if(D.current&&Q.params){let Se=Q.params,Le=le;if(le=null,k){clearTimeout(k.timer);let Fe=k.text;k=null;let St=(Se.content??[]).map(zt=>zt.text??"").join("").trim();Se={...Se,content:[{type:"text",text:`${St}
122
122
 
123
123
  ${Fe}`}]}}D.current({...Se,...Le?{modelContext:Le}:{}})}Ue({jsonrpc:"2.0",id:se,result:{}});return}if(ke==="ui/update-model-context"&&se!=null){le=AM(le,Q.params),Ue({jsonrpc:"2.0",id:se,result:{}});return}if(ke==="tools/call"&&se!=null){let Se=N.current;if(!Se){Ue({jsonrpc:"2.0",id:se,error:{code:-32601,message:"tools/call not supported"}});return}let Le=Q.params?.name;Se({name:Le,arguments:Q.params?.arguments??{}}).then(Fe=>{Ue({jsonrpc:"2.0",id:se,result:Fe});let St=Fe.content?.map(zt=>zt.text??"").join("").trim();St&&qz(Le,Fe,V.current)&&(k&&clearTimeout(k.timer),k={text:St,timer:setTimeout(()=>{if(C)return;let zt=le;le=null,k=null,D.current?.({role:"user",content:[{type:"text",text:St}],...zt?{modelContext:zt}:{}})},500)})}).catch(Fe=>{let St=Fe instanceof Error?Fe.message:"Tool call failed";Ue({jsonrpc:"2.0",id:se,error:{code:-32e3,message:St}})});return}if(ke==="ui/request-display-mode"&&se!=null){let Se=Q.params?.mode,Le=Se==="fullscreen"||Se==="inline"||Se==="pip"?Se:"inline";L.current=Le,Ue({jsonrpc:"2.0",id:se,result:{mode:Le}}),Ue({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:Le}}),B.current?.(Le);return}if(ke==="ui/resource-teardown"&&se!=null){Ue({jsonrpc:"2.0",id:se,result:{}});return}ke==="ping"&&se!=null&&Ue({jsonrpc:"2.0",id:se,result:{}})};return window.addEventListener("message",Hn),()=>{C=!0,clearTimeout(Ze),k&&clearTimeout(k.timer),window.removeEventListener("message",Hn)}},[i,F]),(0,EM.jsx)("iframe",{ref:y,src:te,sandbox:"allow-scripts allow-forms allow-same-origin",className:$(!f&&"ww:rounded-md ww:border ww:border-border",l),style:{height:f?"100%":b,minWidth:f||!R?void 0:`min(${R}px, 100%)`,width:"100%",border:"none",colorScheme:o?"dark":"auto"},title:"MCP App"})}var Mr=q(ee(),1);function RM({icon:e,title:t,description:a,suggestions:n,onSuggestionSelect:r}){return(0,Mr.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,Mr.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,Mr.jsx)("h2",{className:"ww:text-lg ww:font-semibold ww:text-foreground",children:t}),a&&(0,Mr.jsx)("p",{className:"ww:mt-1 ww:text-sm ww:text-muted-foreground ww:max-w-sm",children:a}),n&&n.length>0&&(0,Mr.jsx)("div",{className:"ww:mt-6 ww:w-full ww:max-w-md ww:flex ww:flex-col ww:gap-2",children:n.map((o,l)=>(0,Mr.jsx)("button",{type:"button",onClick:()=>r?.(o),className:$("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 DM=q(xe(),1);var Gs=q(ee(),1),nf=class extends DM.Component{constructor(){super(...arguments);ve(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,Gs.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,Gs.jsx)("span",{children:"Widget failed to load"}),(0,Gs.jsx)("button",{type:"button",onClick:()=>this.setState({hasError:!1}),className:"ww:text-xs ww:font-medium ww:text-primary ww:hover:underline",children:"Retry"})]}):this.props.children}};var Ee=q(ee(),1);function Fz(e){return e?e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase()):"Tool"}function Fl({messages:e,status:t,welcomeMessage:a,welcome:n,onSuggestionSelect:r,resourceEndpoint:o,chatSessionId:l,isDark:i,onFollowUp:s,onCallTool:u,onWidgetDisplayModeChange:c,fullscreenToolCallId:d,debug:f,toolDefinitions:p}){let y=t==="submitted"||t==="streaming",v=e[e.length-1],S=e.length>0,g=y&&(!S||v.role==="user"),x=d!=null;return(0,Ee.jsxs)(Ee.Fragment,{children:[!x&&(!S&&n?(0,Ee.jsx)(RM,{...n,onSuggestionSelect:r}):a&&(0,Ee.jsx)(Jd,{from:"assistant",children:(0,Ee.jsx)(ef,{children:(0,Ee.jsx)(tf,{children:a})})})),e.map(m=>{let w=m.parts.filter(D=>D.type==="text"),L=m.parts.filter(D=>D.type==="reasoning"),b=m.parts.filter(D=>D.type==="file"),M=m.parts.filter(D=>"toolCallId"in D),R=m===v&&m.role==="assistant",_=w.length>0,T=x?M.some(D=>D.toolCallId===d):!1;return x&&!T?(0,Ee.jsx)("div",{style:{display:"none"}},m.id):(0,Ee.jsxs)(Jd,{from:m.role,children:[!T&&L.map((D,N)=>(0,Ee.jsx)(hM,{text:D.text},`reasoning-${m.id}-${N}`)),M.map(D=>{let N="output"in D?D.output:void 0,B=af(D.toolName,N,p),j=kM(D.toolName,N,p),V=D.toolCallId===d;return(0,Ee.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,Ee.jsx)("div",{style:V?{display:"none"}:void 0,children:(0,Ee.jsxs)(wM,{children:[(0,Ee.jsx)(bM,{title:D.title??Fz(D.toolName),state:D.state}),(0,Ee.jsxs)(SM,{children:[(0,Ee.jsx)(CM,{input:D.input,debug:f}),N!==void 0&&(0,Ee.jsx)(TM,{output:N,errorText:"errorText"in D?D.errorText:void 0,debug:f})]})]})}),B&&o&&N!==void 0&&(0,Ee.jsx)(nf,{children:(0,Ee.jsx)(MM,{isFullscreen:V,resourceUri:B,toolInput:D.input??{},toolResult:{content:N.content,structuredContent:N.structuredContent,_meta:N._meta},resourceEndpoint:o,chatSessionId:l,isDark:i,autoHeight:j,toolDefinitions:p,onFollowUp:s,onCallTool:u,onDisplayModeChange:c?F=>c(F,{toolCallId:D.toolCallId,resourceUri:B,toolInput:D.input??{},toolResult:{content:N.content,structuredContent:N.structuredContent,_meta:N._meta},autoHeight:j}):void 0})})]},D.toolCallId)}),!T&&(0,Ee.jsx)("div",{children:(0,Ee.jsxs)(ef,{children:[b.length>0&&(0,Ee.jsx)(OC,{files:b}),_?w.map((D,N)=>(0,Ee.jsx)(tf,{children:D.type==="text"?D.text:""},`${m.id}-${N}`)):R&&y&&(0,Ee.jsx)(wh,{})]})})]},m.id)}),!x&&g&&(0,Ee.jsx)(Jd,{from:"assistant",children:(0,Ee.jsx)(ef,{children:(0,Ee.jsx)(wh,{})})})]})}var Ws=q(ee(),1);function Hl({suggestions:e,isLoading:t,onSelect:a,className:n,...r}){return e.length===0&&!t?null:(0,Ws.jsx)("div",{className:$("ww:px-4 ww:py-2",n),...r,children:(0,Ws.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,Ws.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,Ws.jsx)("button",{type:"button",onClick:()=>a(o),className:$("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 rf=q(xe(),1);function jl(e){let t=(0,rf.useRef)(e);return t.current=e,(0,rf.useCallback)(async a=>{let{api:n,headers:r,onCallTool:o,sessionId:l}=t.current;if(o)return o(a);let i=`${n??"/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}:{},...r},body:JSON.stringify(a)});if(!u.ok)throw new Error(`Tool call failed: ${u.status} ${u.statusText}`);return u.json()},[])}var Pa=q(xe(),1);var iE="vercel.ai.error",Hz=Symbol.for(iE),_M,OM,ge=class sE extends(OM=Error,_M=Hz,OM){constructor({name:t,message:a,cause:n}){super(a),this[_M]=!0,this.name=t,this.cause=n}static isInstance(t){return sE.hasMarker(t,iE)}static hasMarker(t,a){let n=Symbol.for(a);return t!=null&&typeof t=="object"&&n in t&&typeof t[n]=="boolean"&&t[n]===!0}},uE="AI_APICallError",cE=`vercel.ai.error.${uE}`,jz=Symbol.for(cE),PM,NM,fY=class extends(NM=ge,PM=jz,NM){constructor({message:e,url:t,requestBodyValues:a,statusCode:n,responseHeaders:r,responseBody:o,cause:l,isRetryable:i=n!=null&&(n===408||n===409||n===429||n>=500),data:s}){super({name:uE,message:e,cause:l}),this[PM]=!0,this.url=t,this.requestBodyValues=a,this.statusCode=n,this.responseHeaders=r,this.responseBody=o,this.isRetryable=i,this.data=s}static isInstance(e){return ge.hasMarker(e,cE)}},dE="AI_EmptyResponseBodyError",fE=`vercel.ai.error.${dE}`,Vz=Symbol.for(fE),BM,UM,pY=class extends(UM=ge,BM=Vz,UM){constructor({message:e="Empty response body"}={}){super({name:dE,message:e}),this[BM]=!0}static isInstance(e){return ge.hasMarker(e,fE)}};function pE(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var mE="AI_InvalidArgumentError",hE=`vercel.ai.error.${mE}`,Gz=Symbol.for(hE),zM,qM,gE=class extends(qM=ge,zM=Gz,qM){constructor({message:e,cause:t,argument:a}){super({name:mE,message:e,cause:t}),this[zM]=!0,this.argument=a}static isInstance(e){return ge.hasMarker(e,hE)}},yE="AI_InvalidPromptError",xE=`vercel.ai.error.${yE}`,Wz=Symbol.for(xE),FM,HM,mY=class extends(HM=ge,FM=Wz,HM){constructor({prompt:e,message:t,cause:a}){super({name:yE,message:`Invalid prompt: ${t}`,cause:a}),this[FM]=!0,this.prompt=e}static isInstance(e){return ge.hasMarker(e,xE)}},vE="AI_InvalidResponseDataError",wE=`vercel.ai.error.${vE}`,$z=Symbol.for(wE),jM,VM,hY=class extends(VM=ge,jM=$z,VM){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:vE,message:t}),this[jM]=!0,this.data=e}static isInstance(e){return ge.hasMarker(e,wE)}},bE="AI_JSONParseError",SE=`vercel.ai.error.${bE}`,Xz=Symbol.for(SE),GM,WM,Ky=class extends(WM=ge,GM=Xz,WM){constructor({text:e,cause:t}){super({name:bE,message:`JSON parsing failed: Text: ${e}.
124
124
  Error message: ${pE(t)}`,cause:t}),this[GM]=!0,this.text=e}static isInstance(e){return ge.hasMarker(e,SE)}},CE="AI_LoadAPIKeyError",IE=`vercel.ai.error.${CE}`,Zz=Symbol.for(IE),$M,XM,gY=class extends(XM=ge,$M=Zz,XM){constructor({message:e}){super({name:CE,message:e}),this[$M]=!0}static isInstance(e){return ge.hasMarker(e,IE)}},LE="AI_LoadSettingError",kE=`vercel.ai.error.${LE}`,Qz=Symbol.for(kE),ZM,QM,yY=class extends(QM=ge,ZM=Qz,QM){constructor({message:e}){super({name:LE,message:e}),this[ZM]=!0}static isInstance(e){return ge.hasMarker(e,kE)}},TE="AI_NoContentGeneratedError",AE=`vercel.ai.error.${TE}`,Kz=Symbol.for(AE),KM,YM,xY=class extends(YM=ge,KM=Kz,YM){constructor({message:e="No content generated."}={}){super({name:TE,message:e}),this[KM]=!0}static isInstance(e){return ge.hasMarker(e,AE)}},ME="AI_NoSuchModelError",EE=`vercel.ai.error.${ME}`,Yz=Symbol.for(EE),JM,eE,vY=class extends(eE=ge,JM=Yz,eE){constructor({errorName:e=ME,modelId:t,modelType:a,message:n=`No such ${a}: ${t}`}){super({name:e,message:n}),this[JM]=!0,this.modelId=t,this.modelType=a}static isInstance(e){return ge.hasMarker(e,EE)}},RE="AI_TooManyEmbeddingValuesForCallError",DE=`vercel.ai.error.${RE}`,Jz=Symbol.for(DE),tE,aE,wY=class extends(aE=ge,tE=Jz,aE){constructor(e){super({name:RE,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[tE]=!0,this.provider=e.provider,this.modelId=e.modelId,this.maxEmbeddingsPerCall=e.maxEmbeddingsPerCall,this.values=e.values}static isInstance(e){return ge.hasMarker(e,DE)}},_E="AI_TypeValidationError",OE=`vercel.ai.error.${_E}`,eq=Symbol.for(OE),nE,rE,rn=class Qy extends(rE=ge,nE=eq,rE){constructor({value:t,cause:a,context:n}){let r="Type validation failed";if(n?.field&&(r+=` for ${n.field}`),n?.entityName||n?.entityId){r+=" (";let o=[];n.entityName&&o.push(n.entityName),n.entityId&&o.push(`id: "${n.entityId}"`),r+=o.join(", "),r+=")"}super({name:_E,message:`${r}: Value: ${JSON.stringify(t)}.