@waniwani/sdk 0.11.26 → 0.11.27

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.
@@ -120,7 +120,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
120
120
  `||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},xz=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
121
121
  `||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},yy=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},WA=e=>{let t=mz.test(e),a=hz.test(e);if(t||a)return[e];let n=xa.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(gz);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(l.type==="html"&&l.block){let u=i.match(yz);if(u){let c=u[1];i.includes(`</${c}>`)||o.push(c)}}if(i.trim()==="$$"&&s>0){let u=r[s-1],c=gy(u),d=yy(u);if(c&&d%2===1){r[s-1]=u+i;continue}}if(s>0&&xz(i)){let u=r[s-1],c=gy(u),d=yy(u),f=yy(i);if(c&&d%2===1&&!gy(i)&&f===1){r[s-1]=u+i;continue}}r.push(i)}return r},XA={raw:T0,sanitize:[Rc,{}],harden:[L0,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},ZA={gfm:[ad,{}]},vz=Object.values(XA),wz=Object.values(ZA),bz={block:" \u258B",circle:" \u25CF"},Sz={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},Zt=(0,E.createContext)(Sz),Iy=(0,E.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...n})=>(0,T.jsx)($A,{...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)});Iy.displayName="Block";Cz=["github-light","github-dark"],Rd=(0,E.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:n,rehypePlugins:r=vz,remarkPlugins:o=wz,className:l,shikiTheme:i=Cz,mermaid:s,controls:u=!0,isAnimating:c=!1,BlockComponent:d=Iy,parseMarkdownIntoBlocksFn:f=WA,caret:p,plugins:g,remend:v,linkSafety:I={enabled:!0},...y})=>{let x=(0,E.useId)(),[h,b]=(0,E.useTransition)(),A=(0,E.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?z1(e,v):e,[e,t,a,v]),w=(0,E.useMemo)(()=>f(A),[A,f]),[M,_]=(0,E.useState)(w);(0,E.useEffect)(()=>{t==="streaming"?b(()=>{_(w)}):_(w)},[w,t]);let P=t==="streaming"?M:w,k=(0,E.useMemo)(()=>P.map((Q,he)=>`${x}-${he}`),[P.length,x]),H=(0,E.useMemo)(()=>{var Q,he;return{shikiTheme:(he=(Q=g?.code)==null?void 0:Q.getThemes())!=null?he:i,controls:u,isAnimating:c,mode:t,mermaid:s,linkSafety:I}},[i,u,c,t,s,I,g?.code]),R=(0,E.useMemo)(()=>({...uz,...n}),[n]),B=(0,E.useMemo)(()=>{let Q=[];return g!=null&&g.cjk&&(Q=[...Q,...g.cjk.remarkPluginsBefore]),Q=[...Q,...o],g!=null&&g.cjk&&(Q=[...Q,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(Q=[...Q,g.math.remarkPlugin]),Q},[o,g?.math,g?.cjk]),j=(0,E.useMemo)(()=>g!=null&&g.math?[...r,g.math.rehypePlugin]:r,[r,g?.math]),V=(0,E.useMemo)(()=>p&&c?{"--streamdown-caret":`"${bz[p]}"`}:void 0,[p,c]);return t==="static"?(0,T.jsx)(xy.Provider,{value:g??null,children:(0,T.jsx)(Zt.Provider,{value:H,children:(0,T.jsx)("div",{className:Y("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:(0,T.jsx)($A,{components:R,rehypePlugins:j,remarkPlugins:B,...y,children:e})})})}):(0,T.jsx)(xy.Provider,{value:g??null,children:(0,T.jsx)(Zt.Provider,{value:H,children:(0,T.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:[P.length===0&&p&&c&&(0,T.jsx)("span",{}),P.map((Q,he)=>(0,T.jsx)(d,{components:R,content:Q,index:he,rehypePlugins:j,remarkPlugins:B,shouldParseIncompleteMarkdown:a,...y},k[he]))]})})})},(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);Rd.displayName="Streamdown";Iz=({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}),[g,v]=(0,E.useState)(!1),[I,y]=(0,E.useState)({x:0,y:0}),[x,h]=(0,E.useState)({x:0,y:0}),b=(0,E.useCallback)(R=>{d(B=>Math.max(a,Math.min(n,B+R)))},[a,n]),A=(0,E.useCallback)(()=>{b(r)},[b,r]),w=(0,E.useCallback)(()=>{b(-r)},[b,r]),M=(0,E.useCallback)(()=>{d(l),p({x:0,y:0})},[l]),_=(0,E.useCallback)(R=>{R.preventDefault();let B=R.deltaY>0?-r:r;b(B)},[b,r]),P=(0,E.useCallback)(R=>{if(R.button!==0||R.isPrimary===!1)return;v(!0),y({x:R.clientX,y:R.clientY}),h(f);let B=R.currentTarget;B instanceof HTMLElement&&B.setPointerCapture(R.pointerId)},[f]),k=(0,E.useCallback)(R=>{if(!g)return;R.preventDefault();let B=R.clientX-I.x,j=R.clientY-I.y;p({x:x.x+B,y:x.y+j})},[g,I,x]),H=(0,E.useCallback)(R=>{v(!1);let B=R.currentTarget;B instanceof HTMLElement&&B.releasePointerCapture(R.pointerId)},[]);return(0,E.useEffect)(()=>{let R=s.current;if(R)return R.addEventListener("wheel",_,{passive:!1}),()=>{R.removeEventListener("wheel",_)}},[_]),(0,E.useEffect)(()=>{let R=u.current;if(R&&g)return document.body.style.userSelect="none",R.addEventListener("pointermove",k,{passive:!1}),R.addEventListener("pointerup",H),R.addEventListener("pointercancel",H),()=>{document.body.style.userSelect="",R.removeEventListener("pointermove",k),R.removeEventListener("pointerup",H),R.removeEventListener("pointercancel",H)}},[g,k,H]),(0,T.jsxs)("div",{className:Y("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:g?"grabbing":"grab"},children:[o?(0,T.jsxs)("div",{className: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,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c>=n,onClick:A,title:"Zoom in",type:"button",children:(0,T.jsx)(q4,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c<=a,onClick:w,title:"Zoom out",type:"button",children:(0,T.jsx)(F4,{size:16})}),(0,T.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:M,title:"Reset zoom and pan",type:"button",children:(0,T.jsx)(z4,{size:16})})]}):null,(0,T.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:P,ref:u,role:"application",style:{transform:`translate(${f.x}px, ${f.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},my=({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,g]=(0,E.useState)(0),{mermaid:v}=(0,E.useContext)(Zt),I=Sy(),y=v?.errorComponent,{shouldRender:x,containerRef:h}=N4({immediate:n});if((0,E.useEffect)(()=>{if(x){if(!I){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),s(!0);let A=I.getMermaid(a),w=e.split("").reduce((P,k)=>(P<<5)-P+k.charCodeAt(0)|0,0),M=`mermaid-${Math.abs(w)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:_}=await A.render(M,e);c(_),f(_)}catch(A){if(!(d||u)){let w=A instanceof Error?A.message:"Failed to render Mermaid chart";l(w)}}finally{s(!1)}})()}},[e,a,p,x,I]),!(x||u||d))return(0,T.jsx)("div",{className:Y("my-4 min-h-[200px]",t),ref:h});if(i&&!u&&!d)return(0,T.jsx)("div",{className:Y("my-4 flex justify-center p-4",t),ref:h,children:(0,T.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,T.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,T.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return y?(0,T.jsx)("div",{ref:h,children:(0,T.jsx)(y,{chart:e,error:o,retry:()=>g(w=>w+1)})}):(0,T.jsxs)("div",{className:Y("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:h,children:[(0,T.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,T.jsxs)("details",{className:"mt-2",children:[(0,T.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,T.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let b=u||d;return(0,T.jsx)("div",{className:Y("size-full",t),"data-streamdown":"mermaid",ref:h,children:(0,T.jsx)(Iz,{className:Y(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:(0,T.jsx)("div",{"aria-label":"Mermaid chart",className:Y("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:b},role:"img"})})})}});var o2=Ut(($J,r2)=>{"use strict";function JF(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)}}r2.exports=JF});var Jy=F(Qe(),1),z2=F(jS(),1);var q_="https://app.waniwani.ai/api/mcp/chat",F_={api:q_};function H_(){if(typeof document>"u")return null;if(document.currentScript instanceof HTMLScriptElement)return document.currentScript;let e=document.querySelectorAll("script[src]");for(let t of e)if(t instanceof HTMLScriptElement&&/embed/i.test(t.src))return t;return null}function yc(){let e=H_();if(!e)return{};let t=h=>e.getAttribute(h)??void 0,a=h=>{let b=e.getAttribute(h);if(b==null)return;let A=b.trim().toLowerCase();if(A==="true"||A==="1"||A==="")return!0;if(A==="false"||A==="0")return!1},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-channel-id");c&&(n.channelId=c);let d=a("data-show-tool-calls");d!==void 0&&(n.showToolCalls=d);let f=t("data-css");f&&(n.css=f);let p=t("data-suggestions");p&&(n.suggestions=p.split(",").map(h=>h.trim()).filter(Boolean));let g=a("data-enable-thread-history");g!==void 0&&(n.enableThreadHistory=g);let v=t("data-primary-color"),I=t("data-background-color"),y=t("data-text-color"),x=t("data-font-family");return(v||I||y||x)&&(n.theme={},v&&(n.theme.primaryColor=v),I&&(n.theme.backgroundColor=I),y&&(n.theme.textColor=y),x&&(n.theme.fontFamily=x)),n}function Gm(e){if(!e)return{};let t={};for(let a in e)e[a]!==void 0&&(t[a]=e[a]);return t}function Ui(e,t,a){let n=a??yc(),r={token:"",...F_,...Gm(t),...Gm(n),...Gm(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}function VS(e){if(!(!e.theme||Object.keys(e.theme).length===0))return e.theme}var Or=F(Qe(),1);var vc=F(Qe());var xc=(...e)=>e.filter((t,a,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===a).join(" ").trim();var GS=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var $S=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,n)=>n?n.toUpperCase():a.toLowerCase());var $m=e=>{let t=$S(e);return t.charAt(0).toUpperCase()+t.slice(1)};var zi=F(Qe());var WS={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 XS=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var ZS=(0,zi.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:n,className:r="",children:o,iconNode:l,...i},s)=>(0,zi.createElement)("svg",{ref:s,...WS,width:t,height:t,stroke:e,strokeWidth:n?Number(a)*24/Number(t):a,className:xc("lucide",r),...!o&&!XS(i)&&{"aria-hidden":"true"},...i},[...l.map(([u,c])=>(0,zi.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var rt=(e,t)=>{let a=(0,vc.forwardRef)(({className:n,...r},o)=>(0,vc.createElement)(ZS,{ref:o,iconNode:t,className:xc(`lucide-${GS($m(e))}`,`lucide-${e}`,n),...r}));return a.displayName=$m(e),a};var j_=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],qi=rt("arrow-down",j_);var V_=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Fi=rt("arrow-up",V_);var G_=[["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"}]],xr=rt("braces",G_);var $_=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Hi=rt("check",$_);var W_=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],ji=rt("chevron-down",W_);var X_=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Vi=rt("chevron-right",X_);var Z_=[["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"}]],Gi=rt("clipboard-copy",Z_);var Q_=[["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"}]],$i=rt("file",Q_);var K_=[["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"}]],Wi=rt("loader",K_);var Y_=[["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"}]],Xi=rt("paperclip",Y_);var J_=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Zi=rt("square",J_);var eO=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],ao=rt("x",eO);var ot=F(Qe(),1);var Qi=(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 je=F(Qe(),1);Wm();Zm();var tO=KS({prefix:"ww"});function K(...e){return tO(wc(e))}var t0=F(ue(),1),an=({className:e,variant:t="default",size:a="default",type:n="button",...r})=>(0,t0.jsx)("button",{type:n,className:K("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 $t=F(ue(),1),rO=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}},a0=(0,je.createContext)(null),n0=()=>{let e=(0,je.useContext)(a0);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},r0=({className:e,accept:t,multiple:a,globalDrop:n,maxFiles:r,maxFileSize:o,onSubmit:l,children:i,...s})=>{let u=(0,je.useRef)(null),c=(0,je.useRef)(null),[d,f]=(0,je.useState)([]),p=(0,je.useRef)(d);(0,je.useEffect)(()=>{p.current=d},[d]);let g=(0,je.useCallback)(()=>{u.current?.click()},[]),v=(0,je.useCallback)(A=>{let w=[...A];if(w.length===0)return;let M=P=>o?P.size<=o:!0,_=w.filter(M);f(P=>{let k=typeof r=="number"?Math.max(0,r-P.length):void 0,H=typeof k=="number"?_.slice(0,k):_;return[...P,...H.map(R=>({filename:R.name,id:Qi(),mediaType:R.type,type:"file",url:URL.createObjectURL(R)}))]})},[r,o]),I=(0,je.useCallback)(A=>{f(w=>{let M=w.find(_=>_.id===A);return M?.url&&URL.revokeObjectURL(M.url),w.filter(_=>_.id!==A)})},[]),y=(0,je.useCallback)(()=>{f(A=>{for(let w of A)w.url&&URL.revokeObjectURL(w.url);return[]})},[]);(0,je.useEffect)(()=>()=>{for(let A of p.current)A.url&&URL.revokeObjectURL(A.url)},[]);let x=(0,je.useCallback)(A=>{A.currentTarget.files&&v(A.currentTarget.files),A.currentTarget.value=""},[v]);(0,je.useEffect)(()=>{if(!n)return;let A=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault()},w=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault(),M.dataTransfer?.files&&M.dataTransfer.files.length>0&&v(M.dataTransfer.files)};return document.addEventListener("dragover",A),document.addEventListener("drop",w),()=>{document.removeEventListener("dragover",A),document.removeEventListener("drop",w)}},[v,n]);let h=(0,je.useCallback)(async A=>{A.preventDefault();let w=A.currentTarget,_=new FormData(w).get("message")||"";w.reset();let P=await Promise.all(d.map(async({id:k,...H})=>{if(H.url?.startsWith("blob:")){let R=await rO(H.url);return{...H,url:R??H.url}}return H}));try{let k=l({files:P,text:_},A);k instanceof Promise&&await k,y()}catch{}},[d,l,y]),b=(0,je.useMemo)(()=>({add:v,clear:y,files:d,openFileDialog:g,remove:I}),[d,v,I,y,g]);return(0,$t.jsxs)(a0.Provider,{value:b,children:[(0,$t.jsx)("input",{accept:t,"aria-label":"Upload files",className:"ww:hidden",multiple:a,onChange:x,ref:u,title:"Upload files",type:"file"}),(0,$t.jsx)("form",{className:K("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:h,ref:c,...s,children:i})]})};var o0=({onChange:e,onKeyDown:t,className:a,placeholder:n="What would you like to know?",...r})=>{let o=n0(),[l,i]=(0,je.useState)(!1),s=(0,je.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,je.useCallback)(c=>{let d=c.clipboardData?.items;if(!d)return;let f=[];for(let p of d)if(p.kind==="file"){let g=p.getAsFile();g&&f.push(g)}f.length>0&&(c.preventDefault(),o.add(f))},[o]);return(0,$t.jsx)("textarea",{className:K("ww:field-sizing-content ww:max-h-48 ww:min-h-0 ww:w-full ww:resize-none ww:border-0 ww:bg-transparent ww:px-3 ww:py-2 ww:text-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})},l0=({className:e,status:t,onStop:a,onClick:n,children:r,...o})=>{let l=t==="submitted"||t==="streaming",i=(0,$t.jsx)(Fi,{className:"ww:size-4"});t==="submitted"?i=(0,$t.jsx)(Wi,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(i=(0,$t.jsx)(Zi,{className:"ww:size-4"}));let s=(0,je.useCallback)(u=>{if(l&&a){u.preventDefault(),a();return}n?.(u)},[l,a,n]);return(0,$t.jsx)(an,{"aria-label":l?"Stop":"Submit",className:K("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})},i0=({className:e,children:t,...a})=>{let n=n0();return n.files.length>0?(0,$t.jsxs)(an,{className:K("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":"Remove all attachments",...a,children:[(0,$t.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,$t.jsx)(ao,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):(0,$t.jsx)(an,{className:K(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...a,children:t??(0,$t.jsx)(Xi,{className:"ww:size-4"})})};var Sc=F(Qe(),1);var no=F(ue(),1),s0=({className:e,...t})=>(0,no.jsx)("div",{className:K("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),u0=({className:e,...t})=>(0,no.jsx)("li",{className:K("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}),c0=({className:e,...t})=>(0,no.jsx)("span",{className:K("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),d0=({className:e,...t})=>(0,no.jsx)("span",{className:K("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),f0=({className:e,...t})=>(0,no.jsx)("div",{className:K("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),p0=({className:e,...t})=>(0,no.jsx)(an,{className:K("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 _a=F(ue(),1),m0=(0,Sc.memo)(({message:e,onRemove:t})=>{let a=(0,Sc.useCallback)(()=>t(e.id),[t,e.id]);return(0,_a.jsxs)(u0,{children:[(0,_a.jsx)(c0,{}),(0,_a.jsx)(d0,{children:e.text||"(attachment)"}),(0,_a.jsx)(f0,{children:(0,_a.jsx)(p0,{"aria-label":"Remove from queue",onClick:a,children:(0,_a.jsx)(ao,{className:"ww:size-3"})})})]})});m0.displayName="ChatQueueItem";function h0({queuedMessages:e,onRemove:t,className:a}){return e.length===0?null:(0,_a.jsxs)(s0,{className:K("ww:border-t ww:border-border",a),children:[(0,_a.jsxs)("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:[e.length," queued"]}),(0,_a.jsx)("ul",{children:e.map(n=>(0,_a.jsx)(m0,{message:n,onRemove:t},n.id))})]})}var vr=F(ue(),1),g0=({files:e,className:t,...a})=>e.length===0?null:(0,vr.jsx)("div",{className:K("ww:flex ww:flex-wrap ww:gap-1.5",t),...a,children:e.map((n,r)=>(0,vr.jsx)(oO,{file:n},r))});function oO({file:e}){return e.mediaType?.startsWith("image/")&&e.url?(0,vr.jsx)("img",{src:e.url,alt:e.filename??"attachment",className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):(0,vr.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,vr.jsx)($i,{className:"ww:size-3 ww:shrink-0"}),(0,vr.jsx)("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??"file"})]})}var Qm=F(ue(),1),Km=({className:e,size:t=5,...a})=>(0,Qm.jsx)("div",{className:K("ww:flex ww:items-center ww:gap-1",e),...a,children:[0,1,2].map(n=>(0,Qm.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 y0={name:"cjk-noop",type:"cjk",remarkPluginsBefore:[],remarkPluginsAfter:[],remarkPlugins:[]};var x0={name:"shiki-noop",type:"code-highlighter",supportsLanguage:()=>!1,getSupportedLanguages:()=>[],getThemes:()=>["github-light","github-dark"],highlight:()=>null};var QA=F(Qe(),1);kd();var Is=F(ue(),1),Dd=({className:e,from:t,children:a,...n})=>(0,Is.jsx)("div",{className:K("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,Is.jsx)("div",{className:K("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),_d=({children:e,className:t,...a})=>(0,Is.jsx)("div",{className:K("ww:flex ww:w-fit ww:min-w-0 ww:max-w-full ww:flex-col ww:gap-2 ww:overflow-hidden ww:text-base","ww:group-[.is-user]:ml-auto ww:group-[.is-user]:rounded-lg ww:group-[.is-user]:bg-user-bubble ww:group-[.is-user]:px-4 ww:group-[.is-user]:py-3 ww:group-[.is-user]:text-primary-foreground","ww:group-[.is-assistant]:text-foreground",t),...a,children:e}),Lz={cjk:y0,code:x0},kz={enabled:!1},Od=(0,QA.memo)(({className:e,linkSafety:t,...a})=>(0,Is.jsx)(Rd,{className:K("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),linkSafety:t??kz,plugins:Lz,...a}),(e,t)=>e.children===t.children);Od.displayName="MessageResponse";var YA=F(ue(),1);function KA({className:e,text:t,...a}){return t?(0,YA.jsx)("pre",{className:K("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 Tt=F(Qe(),1);var se=F(ue(),1);function Tz(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 Az({text:e,className:t}){let[a,n]=(0,Tt.useState)(!1),r=(0,Tt.useRef)(null);(0,Tt.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]);let o=(0,Tt.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,se.jsx)(an,{variant:"ghost",size:"sm",onClick:o,className:K("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,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Hi,{className:"ww:size-3.5"}),(0,se.jsx)("span",{children:"Copied"})]}):(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)(Gi,{className:"ww:size-3.5"}),(0,se.jsx)("span",{children:"Copy"})]})})}function tM({data:e,label:t,className:a,...n}){let[r,o]=(0,Tt.useState)(!1),l=(0,Tt.useMemo)(()=>JSON.stringify(e,null,2),[e]),i=Tz(e);return(0,se.jsxs)("div",{className:K("ww:rounded-lg ww:bg-tool-card",a),...n,children:[(0,se.jsxs)("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[(0,se.jsx)("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),(0,se.jsx)(Az,{text:l})]}),(0,se.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,se.jsx)(Vi,{className:K("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,se.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,se.jsx)("code",{children:l})}):(0,se.jsx)("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var ky=(0,Tt.createContext)({open:!1,toggle:()=>{}});function aM({className:e,defaultOpen:t=!1,children:a,...n}){let[r,o]=(0,Tt.useState)(t);return(0,se.jsx)(ky.Provider,{value:{open:r,toggle:()=>o(l=>!l)},children:(0,se.jsx)("div",{className:K("ww:mb-4 ww:w-full",e),"data-state":r?"open":"closed",...n,children:a})})}function nM({className:e,title:t,state:a,...n}){let{open:r,toggle:o}=(0,Tt.useContext)(ky),l=a==="input-available"||a==="input-streaming";return(0,se.jsxs)("button",{type:"button",onClick:o,className:K("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,se.jsxs)("div",{className:"ww:flex ww:min-w-0 ww:items-center ww:gap-2",children:[(0,se.jsx)(xr,{className:"ww:size-4 ww:shrink-0 ww:text-muted-foreground"}),(0,se.jsx)("span",{className:"ww:truncate ww:text-sm ww:font-medium",children:t}),l&&(0,se.jsx)("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]}),(0,se.jsx)(ji,{className:K("ww:size-4 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-200",r&&"ww:rotate-180")})]})}function rM({className:e,title:t,state:a,...n}){let r=a==="input-available"||a==="input-streaming";return(0,se.jsxs)("div",{className:K("ww:mb-4 ww:flex ww:items-center ww:gap-2 ww:py-1.5 ww:text-sm ww:text-muted-foreground ww:italic",e),...n,children:[(0,se.jsx)("span",{className:"ww:truncate",children:t}),r&&(0,se.jsx)("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]})}function oM({className:e,children:t,...a}){let{open:n}=(0,Tt.useContext)(ky);return(0,se.jsx)("div",{className:K("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,se.jsx)("div",{className:"ww:min-h-0 ww:overflow-hidden",children:(0,se.jsx)("div",{className:K("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 lM({className:e,input:t,debug:a,...n}){let r=(0,Tt.useMemo)(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:o,...l}=t;return l}return t},[t,a]);return(0,se.jsx)(tM,{data:r,label:"Request",className:e,...n})}function Ly(e){if(!(typeof e!="object"||e===null))return e}function iM(e){return Ly(e?.ui)}function sM(e){return Ly(Ly(e)?._meta)}function JA(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 eM(e){return iM(e)?.autoHeight===!0}function Pd(e,t,a){if(e){let n=JA(a?.[e]?._meta);if(n)return n}return JA(sM(t))}function uM(e,t,a){return e&&eM(a?.[e]?._meta)?!0:eM(sM(t))}function cM({className:e,output:t,errorText:a,debug:n,...r}){let o=(0,Tt.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,se.jsxs)("div",{className:K("ww:space-y-2",e),...r,children:[(0,se.jsx)("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:"Error"}),(0,se.jsx)("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):(0,se.jsx)(tM,{data:o,label:"Response",className:e,...r}):null}var We=F(Qe(),1);function Ml(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 dM(e,t){return!Ml(e)&&!Ml(t)?null:Ml(e)?Ml(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 pM=F(ue(),1),Mz="/api/mcp/resource",Ez=500,Rz=0,Dz=16,_z="2026-01-26",Oz=300,Pz=3e3,Nz=3;function Bz(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function Uz(e,t,a){return Pd(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function fM({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:n=Mz,chatSessionId:r,isDark:o=!1,className:l,autoHeight:i=!1,onOpenLink:s,onFollowUp:u,onCallTool:c,onDisplayModeChange:d,isFullscreen:f=!1,toolDefinitions:p}){let g=(0,We.useRef)(null),v=(0,We.useRef)(t),I=(0,We.useRef)(a),y=(0,We.useRef)({width:0,height:0}),x=(0,We.useRef)(null),h=(0,We.useRef)(!1),b=(0,We.useRef)(0),A=(0,We.useRef)("inline"),[w,M]=(0,We.useState)(Rz),[_,P]=(0,We.useState)(void 0),k=(0,We.useRef)(s),H=(0,We.useRef)(u),R=(0,We.useRef)(c),B=(0,We.useRef)(d),j=(0,We.useRef)(r),V=(0,We.useRef)(p);v.current=t,I.current=a,k.current=s,H.current=u,R.current=c,B.current=d,j.current=r,V.current=p;let Q=(0,We.useCallback)(xe=>i?Math.max(xe+Dz,0):Math.min(Math.max(xe,50),Ez),[i]),he=(0,We.useMemo)(()=>{let xe=n.includes("?")?"&":"?";return`${n}${xe}uri=${encodeURIComponent(e)}`},[n,e]),Fe=(0,We.useRef)(o);return Fe.current=o,(0,We.useEffect)(()=>{if(!h.current)return;let xe=g.current;xe?.contentWindow&&xe.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:o?"dark":"light"}},"*")},[o]),(0,We.useEffect)(()=>{let xe=g.current;if(!xe)return;let C=!1,Xe=!1,it=null,L=null,mt=setTimeout(()=>{if(C||Xe||b.current>=Nz)return;b.current+=1;let Ie=new URL(xe.src);Ie.searchParams.set("_retry",String(b.current)),xe.src=Ie.toString()},Pz),$=Ie=>{xe.contentWindow?.postMessage(Ie,"*")},Ce=Ie=>{if(C||Ie.source!==xe.contentWindow)return;let J=Ie.data;if(!J||typeof J!="object"||J.jsonrpc!=="2.0")return;let Re=J.method,ae=J.id;if(Re==="ui/initialize"&&ae!=null){Xe=!0,clearTimeout(mt),$({jsonrpc:"2.0",id:ae,result:{protocolVersion:J.params?.protocolVersion??_z,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:Fe.current?"dark":"light",displayMode:A.current}}});return}if(Re==="ui/notifications/initialized"){h.current=!0;let ge=v.current,Le=I.current,be=Le._meta&&typeof Le._meta=="object"?Le._meta:null,Ve=Bz(j.current),lt=be&&typeof be.waniwani=="object"&&be.waniwani!==null?be.waniwani:null,Ht=lt||Ve?{...lt??{},...Ve?{sessionId:Ve}:{}}:void 0,za=be||Ht?{...be??{},...Ht?{waniwani:Ht}:{}}:void 0;$({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:ge}});let jn=Le.content??[{type:"text",text:JSON.stringify(Le)}];$({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:jn,structuredContent:Le.structuredContent,_meta:za,meta:za}});return}if(Re==="ui/notifications/size-changed"){let ge=J.params,Le=typeof ge?.height=="number"?ge.height:void 0,be=typeof ge?.width=="number"?ge.width:void 0,Ve=y.current,lt=Le!==void 0&&Le!==Ve.height,Ht=be!==void 0&&be!==Ve.width;if(!lt&&!Ht)return;if(lt&&Le!==void 0){Ve.height=Le;let za=Q(Le),jn=xe.getBoundingClientRect().height;if(x.current&&(x.current.cancel(),x.current=null),M(za),xe.animate&&Math.abs(jn-za)>2){let dn=xe.animate([{height:`${jn}px`},{height:`${za}px`}],{duration:Oz,easing:"ease-out",fill:"forwards"});x.current=dn,dn.onfinish=()=>{x.current===dn&&(dn.cancel(),x.current=null)}}}Ht&&i&&be!==void 0&&(Ve.width=be,P(be));return}if(Re==="ui/open-link"&&ae!=null){let ge=J.params?.url;typeof ge=="string"&&(k.current?k.current(ge):window.open(ge,"_blank","noopener,noreferrer")),$({jsonrpc:"2.0",id:ae,result:{}});return}if(Re==="ui/message"&&ae!=null){if(H.current&&J.params){let ge=J.params,Le=it;if(it=null,L){clearTimeout(L.timer);let be=L.text;L=null;let Ve=(ge.content??[]).map(lt=>lt.text??"").join("").trim();ge={...ge,content:[{type:"text",text:`${Ve}
122
122
 
123
- ${be}`}]}}H.current({...ge,...Le?{modelContext:Le}:{}})}$({jsonrpc:"2.0",id:ae,result:{}});return}if(Re==="ui/update-model-context"&&ae!=null){it=dM(it,J.params),$({jsonrpc:"2.0",id:ae,result:{}});return}if(Re==="tools/call"&&ae!=null){let ge=R.current;if(!ge){$({jsonrpc:"2.0",id:ae,error:{code:-32601,message:"tools/call not supported"}});return}let Le=J.params?.name;ge({name:Le,arguments:J.params?.arguments??{}}).then(be=>{$({jsonrpc:"2.0",id:ae,result:be});let Ve=be.content?.map(lt=>lt.text??"").join("").trim();Ve&&Uz(Le,be,V.current)&&(L&&clearTimeout(L.timer),L={text:Ve,timer:setTimeout(()=>{if(C)return;let lt=it;it=null,L=null,H.current?.({role:"user",content:[{type:"text",text:Ve}],...lt?{modelContext:lt}:{}})},500)})}).catch(be=>{let Ve=be instanceof Error?be.message:"Tool call failed";$({jsonrpc:"2.0",id:ae,error:{code:-32e3,message:Ve}})});return}if(Re==="ui/request-display-mode"&&ae!=null){let ge=J.params?.mode,Le=ge==="fullscreen"||ge==="inline"||ge==="pip"?ge:"inline";A.current=Le,$({jsonrpc:"2.0",id:ae,result:{mode:Le}}),$({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:Le}}),B.current?.(Le);return}if(Re==="ui/resource-teardown"&&ae!=null){$({jsonrpc:"2.0",id:ae,result:{}});return}Re==="ping"&&ae!=null&&$({jsonrpc:"2.0",id:ae,result:{}})};return window.addEventListener("message",Ce),()=>{C=!0,clearTimeout(mt),L&&clearTimeout(L.timer),window.removeEventListener("message",Ce)}},[i,Q]),(0,pM.jsx)("iframe",{ref:g,src:he,sandbox:"allow-scripts allow-forms allow-same-origin",className:K(!f&&"ww:rounded-md ww:border ww:border-border",l),style:{height:f?"100%":w,minWidth:f||!_?void 0:`min(${_}px, 100%)`,width:"100%",border:"none",colorScheme:o?"dark":"auto"},title:"MCP App"})}var Er=F(ue(),1);function mM({icon:e,title:t,description:a,suggestions:n,onSuggestionSelect:r}){return(0,Er.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,Er.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,Er.jsx)("h2",{className:"ww:text-lg ww:font-semibold ww:text-foreground",children:t}),a&&(0,Er.jsx)("p",{className:"ww:mt-1 ww:text-sm ww:text-muted-foreground ww:max-w-sm",children:a}),n&&n.length>0&&(0,Er.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,Er.jsx)("button",{type:"button",onClick:()=>r?.(o),className:K("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 hM=F(Qe(),1);var Ls=F(ue(),1),Nd=class extends hM.Component{constructor(){super(...arguments);ke(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,Ls.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,Ls.jsx)("span",{children:"Widget failed to load"}),(0,Ls.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 _e=F(ue(),1);function gM(e){return e?e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase()):"Tool"}function yM({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,showToolCalls:p=!0,toolDefinitions:g}){let v=t==="submitted"||t==="streaming",I=e[e.length-1],y=e.length>0,x=v&&(!y||I.role==="user"),h=d!=null;return(0,_e.jsxs)(_e.Fragment,{children:[!h&&(!y&&n?(0,_e.jsx)(mM,{...n,onSuggestionSelect:r}):a&&(0,_e.jsx)(Dd,{from:"assistant",children:(0,_e.jsx)(_d,{children:(0,_e.jsx)(Od,{children:a})})})),e.map(b=>{let A=b.parts.filter(R=>R.type==="text"),w=b.parts.filter(R=>R.type==="reasoning"),M=b.parts.filter(R=>R.type==="file"),_=b.parts.filter(R=>"toolCallId"in R),P=b===I&&b.role==="assistant",k=A.length>0,H=h?_.some(R=>R.toolCallId===d):!1;return h&&!H?(0,_e.jsx)("div",{style:{display:"none"}},b.id):(0,_e.jsxs)(Dd,{from:b.role,children:[!H&&w.map((R,B)=>(0,_e.jsx)(KA,{text:R.text},`reasoning-${b.id}-${B}`)),_.map(R=>{let B="output"in R?R.output:void 0,j=Pd(R.toolName,B,g),V=uM(R.toolName,B,g),Q=R.toolCallId===d;return(0,_e.jsxs)("div",{style:Q?{position:"absolute",inset:0,zIndex:10,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--ww-color-background)"}:void 0,children:[(0,_e.jsx)("div",{style:Q?{display:"none"}:void 0,children:p?(0,_e.jsxs)(aM,{children:[(0,_e.jsx)(nM,{title:R.title??gM(R.toolName),state:R.state}),(0,_e.jsxs)(oM,{children:[(0,_e.jsx)(lM,{input:R.input,debug:f}),B!==void 0&&(0,_e.jsx)(cM,{output:B,errorText:"errorText"in R?R.errorText:void 0,debug:f})]})]}):(0,_e.jsx)(rM,{title:R.title??gM(R.toolName),state:R.state})}),j&&o&&B!==void 0&&(0,_e.jsx)(Nd,{children:(0,_e.jsx)(fM,{isFullscreen:Q,resourceUri:j,toolInput:R.input??{},toolResult:{content:B.content,structuredContent:B.structuredContent,_meta:B._meta},resourceEndpoint:o,chatSessionId:l,isDark:i,autoHeight:V,toolDefinitions:g,onFollowUp:s,onCallTool:u,onDisplayModeChange:c?he=>c(he,{toolCallId:R.toolCallId,resourceUri:j,toolInput:R.input??{},toolResult:{content:B.content,structuredContent:B.structuredContent,_meta:B._meta},autoHeight:V}):void 0})})]},R.toolCallId)}),!H&&(0,_e.jsx)("div",{children:(0,_e.jsxs)(_d,{children:[M.length>0&&(0,_e.jsx)(g0,{files:M}),k?A.map((R,B)=>(0,_e.jsx)(Od,{children:R.type==="text"?R.text:""},`${b.id}-${B}`)):P&&v&&(0,_e.jsx)(Km,{})]})})]},b.id)}),!h&&x&&(0,_e.jsx)(Dd,{from:"assistant",children:(0,_e.jsx)(_d,{children:(0,_e.jsx)(Km,{})})})]})}var El=F(ue(),1),zz="https://app.waniwani.ai/assets/waniwani-logo.svg",qz="https://waniwani.ai";function xM(){return(0,El.jsx)("div",{className:"ww:pt-2 ww:pb-1 ww:flex ww:justify-center",children:(0,El.jsxs)("a",{href:qz,target:"_blank",rel:"noopener noreferrer",className:"ww:flex ww:items-center ww:gap-1.5 ww:text-[11px] ww:text-muted-foreground ww:opacity-70 hover:ww:opacity-100 ww:transition-opacity",children:[(0,El.jsx)("span",{children:"powered by"}),(0,El.jsx)("img",{src:zz,alt:"WaniWani",width:72,height:10,className:"ww:h-2.5 ww:w-auto"})]})})}var ks=F(ue(),1);function vM({suggestions:e,isLoading:t,onSelect:a,className:n,...r}){return e.length===0&&!t?null:(0,ks.jsx)("div",{className:K("ww:px-4 ww:py-2",n),...r,children:(0,ks.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,ks.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,ks.jsx)("button",{type:"button",onClick:()=>a(o),className:K("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 Rl=F(Qe(),1),Ae=F(ue(),1),wM=20;function Fz(e){let t=Date.parse(e);if(Number.isNaN(t))return"";let a=Date.now()-t;return a<6e4?"just now":a<60*6e4?`${Math.floor(a/6e4)}m ago`:a<1440*6e4?`${Math.floor(a/(60*6e4))}h ago`:`${Math.floor(a/(1440*6e4))}d ago`}function Hz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"New chat",children:[(0,Ae.jsx)("title",{children:"New chat"}),(0,Ae.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,Ae.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function jz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"Thread history",children:[(0,Ae.jsx)("title",{children:"Thread history"}),(0,Ae.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,Ae.jsx)("polyline",{points:"3 4 3 9 8 9"}),(0,Ae.jsx)("line",{x1:"12",y1:"7",x2:"12",y2:"12"}),(0,Ae.jsx)("line",{x1:"12",y1:"12",x2:"15",y2:"14"})]})}function Vz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"Delete thread",children:[(0,Ae.jsx)("title",{children:"Delete thread"}),(0,Ae.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,Ae.jsx)("path",{d:"M19 6l-2 14a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2L5 6"}),(0,Ae.jsx)("path",{d:"M10 11v6"}),(0,Ae.jsx)("path",{d:"M14 11v6"})]})}function bM({threads:e,activeThreadId:t,onNewThread:a,onSelectThread:n,onDeleteThread:r}){let[o,l]=(0,Rl.useState)(!1),i=(0,Rl.useRef)(null);(0,Rl.useEffect)(()=>{if(!o)return;let c=d=>{let f=i.current;f&&(d.composedPath().includes(f)||l(!1))};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[o]);let s=e.slice(0,wM),u=Math.max(0,e.length-wM);return(0,Ae.jsxs)("div",{ref:i,className:"ww:relative ww:flex ww:items-center ww:gap-1",children:[(0,Ae.jsx)("button",{type:"button",onClick:a,title:"New chat","aria-label":"New chat",className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(Hz,{})}),(0,Ae.jsx)("button",{type:"button",onClick:()=>l(c=>!c),title:"Thread history","aria-label":"Thread history","aria-expanded":o,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(jz,{})}),o&&(0,Ae.jsxs)("div",{role:"menu",className:"ww:absolute ww:right-0 ww:top-full ww:mt-1 ww:w-72 ww:max-h-80 ww:overflow-y-auto ww:rounded-lg ww:border ww:border-border ww:bg-background ww:shadow-lg ww:z-50",children:[s.length===0&&(0,Ae.jsx)("div",{className:"ww:px-3 ww:py-3 ww:text-xs ww:text-muted-foreground",children:"No previous chats yet."}),s.map(c=>{let d=c.threadId===t;return(0,Ae.jsxs)("div",{className:`ww:flex ww:items-center ww:gap-2 ww:px-3 ww:py-2 ww:text-xs hover:ww:bg-foreground/5 ${d?"ww:bg-foreground/5":""}`,children:[(0,Ae.jsxs)("button",{type:"button",onClick:()=>{n(c.threadId),l(!1)},className:"ww:flex-1 ww:min-w-0 ww:text-left ww:cursor-pointer",children:[(0,Ae.jsx)("div",{className:"ww:truncate ww:text-foreground ww:font-medium",children:c.title}),(0,Ae.jsx)("div",{className:"ww:text-[10px] ww:text-muted-foreground",children:Fz(c.updatedAt)})]}),(0,Ae.jsx)("button",{type:"button",onClick:f=>{f.stopPropagation(),r(c.threadId)},title:"Delete thread","aria-label":"Delete thread",className:"ww:p-1 ww:rounded ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/10 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(Vz,{})})]},c.threadId)}),u>0&&(0,Ae.jsxs)("div",{className:"ww:px-3 ww:py-2 ww:text-[10px] ww:text-muted-foreground ww:border-t ww:border-border",children:[u," older thread",u===1?"":"s"," hidden"]})]})]})}var Bd=F(Qe(),1);function SM(e){let t=(0,Bd.useRef)(e);return t.current=e,(0,Bd.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 Ua=F(Qe(),1);var KM="vercel.ai.error",Gz=Symbol.for(KM),CM,IM,we=class YM extends(IM=Error,CM=Gz,IM){constructor({name:t,message:a,cause:n}){super(a),this[CM]=!0,this.name=t,this.cause=n}static isInstance(t){return YM.hasMarker(t,KM)}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}},JM="AI_APICallError",eE=`vercel.ai.error.${JM}`,$z=Symbol.for(eE),LM,kM,gY=class extends(kM=we,LM=$z,kM){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:JM,message:e,cause:l}),this[LM]=!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 we.hasMarker(e,eE)}},tE="AI_EmptyResponseBodyError",aE=`vercel.ai.error.${tE}`,Wz=Symbol.for(aE),TM,AM,yY=class extends(AM=we,TM=Wz,AM){constructor({message:e="Empty response body"}={}){super({name:tE,message:e}),this[TM]=!0}static isInstance(e){return we.hasMarker(e,aE)}};function nE(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var rE="AI_InvalidArgumentError",oE=`vercel.ai.error.${rE}`,Xz=Symbol.for(oE),MM,EM,lE=class extends(EM=we,MM=Xz,EM){constructor({message:e,cause:t,argument:a}){super({name:rE,message:e,cause:t}),this[MM]=!0,this.argument=a}static isInstance(e){return we.hasMarker(e,oE)}},iE="AI_InvalidPromptError",sE=`vercel.ai.error.${iE}`,Zz=Symbol.for(sE),RM,DM,xY=class extends(DM=we,RM=Zz,DM){constructor({prompt:e,message:t,cause:a}){super({name:iE,message:`Invalid prompt: ${t}`,cause:a}),this[RM]=!0,this.prompt=e}static isInstance(e){return we.hasMarker(e,sE)}},uE="AI_InvalidResponseDataError",cE=`vercel.ai.error.${uE}`,Qz=Symbol.for(cE),_M,OM,vY=class extends(OM=we,_M=Qz,OM){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:uE,message:t}),this[_M]=!0,this.data=e}static isInstance(e){return we.hasMarker(e,cE)}},dE="AI_JSONParseError",fE=`vercel.ai.error.${dE}`,Kz=Symbol.for(fE),PM,NM,Ay=class extends(NM=we,PM=Kz,NM){constructor({text:e,cause:t}){super({name:dE,message:`JSON parsing failed: Text: ${e}.
123
+ ${be}`}]}}H.current({...ge,...Le?{modelContext:Le}:{}})}$({jsonrpc:"2.0",id:ae,result:{}});return}if(Re==="ui/update-model-context"&&ae!=null){it=dM(it,J.params),$({jsonrpc:"2.0",id:ae,result:{}});return}if(Re==="tools/call"&&ae!=null){let ge=R.current;if(!ge){$({jsonrpc:"2.0",id:ae,error:{code:-32601,message:"tools/call not supported"}});return}let Le=J.params?.name;ge({name:Le,arguments:J.params?.arguments??{}}).then(be=>{$({jsonrpc:"2.0",id:ae,result:be});let Ve=be.content?.map(lt=>lt.text??"").join("").trim();Ve&&Uz(Le,be,V.current)&&(L&&clearTimeout(L.timer),L={text:Ve,timer:setTimeout(()=>{if(C)return;let lt=it;it=null,L=null,H.current?.({role:"user",content:[{type:"text",text:Ve}],...lt?{modelContext:lt}:{}})},500)})}).catch(be=>{let Ve=be instanceof Error?be.message:"Tool call failed";$({jsonrpc:"2.0",id:ae,error:{code:-32e3,message:Ve}})});return}if(Re==="ui/request-display-mode"&&ae!=null){let ge=J.params?.mode,Le=ge==="fullscreen"||ge==="inline"||ge==="pip"?ge:"inline";A.current=Le,$({jsonrpc:"2.0",id:ae,result:{mode:Le}}),$({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:Le}}),B.current?.(Le);return}if(Re==="ui/resource-teardown"&&ae!=null){$({jsonrpc:"2.0",id:ae,result:{}});return}Re==="ping"&&ae!=null&&$({jsonrpc:"2.0",id:ae,result:{}})};return window.addEventListener("message",Ce),()=>{C=!0,clearTimeout(mt),L&&clearTimeout(L.timer),window.removeEventListener("message",Ce)}},[i,Q]),(0,pM.jsx)("iframe",{ref:g,src:he,sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox",className:K(!f&&"ww:rounded-md ww:border ww:border-border",l),style:{height:f?"100%":w,minWidth:f||!_?void 0:`min(${_}px, 100%)`,width:"100%",border:"none",colorScheme:o?"dark":"auto"},title:"MCP App"})}var Er=F(ue(),1);function mM({icon:e,title:t,description:a,suggestions:n,onSuggestionSelect:r}){return(0,Er.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,Er.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,Er.jsx)("h2",{className:"ww:text-lg ww:font-semibold ww:text-foreground",children:t}),a&&(0,Er.jsx)("p",{className:"ww:mt-1 ww:text-sm ww:text-muted-foreground ww:max-w-sm",children:a}),n&&n.length>0&&(0,Er.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,Er.jsx)("button",{type:"button",onClick:()=>r?.(o),className:K("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 hM=F(Qe(),1);var Ls=F(ue(),1),Nd=class extends hM.Component{constructor(){super(...arguments);ke(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,Ls.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,Ls.jsx)("span",{children:"Widget failed to load"}),(0,Ls.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 _e=F(ue(),1);function gM(e){return e?e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase()):"Tool"}function yM({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,showToolCalls:p=!0,toolDefinitions:g}){let v=t==="submitted"||t==="streaming",I=e[e.length-1],y=e.length>0,x=v&&(!y||I.role==="user"),h=d!=null;return(0,_e.jsxs)(_e.Fragment,{children:[!h&&(!y&&n?(0,_e.jsx)(mM,{...n,onSuggestionSelect:r}):a&&(0,_e.jsx)(Dd,{from:"assistant",children:(0,_e.jsx)(_d,{children:(0,_e.jsx)(Od,{children:a})})})),e.map(b=>{let A=b.parts.filter(R=>R.type==="text"),w=b.parts.filter(R=>R.type==="reasoning"),M=b.parts.filter(R=>R.type==="file"),_=b.parts.filter(R=>"toolCallId"in R),P=b===I&&b.role==="assistant",k=A.length>0,H=h?_.some(R=>R.toolCallId===d):!1;return h&&!H?(0,_e.jsx)("div",{style:{display:"none"}},b.id):(0,_e.jsxs)(Dd,{from:b.role,children:[!H&&w.map((R,B)=>(0,_e.jsx)(KA,{text:R.text},`reasoning-${b.id}-${B}`)),_.map(R=>{let B="output"in R?R.output:void 0,j=Pd(R.toolName,B,g),V=uM(R.toolName,B,g),Q=R.toolCallId===d;return(0,_e.jsxs)("div",{style:Q?{position:"absolute",inset:0,zIndex:10,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--ww-color-background)"}:void 0,children:[(0,_e.jsx)("div",{style:Q?{display:"none"}:void 0,children:p?(0,_e.jsxs)(aM,{children:[(0,_e.jsx)(nM,{title:R.title??gM(R.toolName),state:R.state}),(0,_e.jsxs)(oM,{children:[(0,_e.jsx)(lM,{input:R.input,debug:f}),B!==void 0&&(0,_e.jsx)(cM,{output:B,errorText:"errorText"in R?R.errorText:void 0,debug:f})]})]}):(0,_e.jsx)(rM,{title:R.title??gM(R.toolName),state:R.state})}),j&&o&&B!==void 0&&(0,_e.jsx)(Nd,{children:(0,_e.jsx)(fM,{isFullscreen:Q,resourceUri:j,toolInput:R.input??{},toolResult:{content:B.content,structuredContent:B.structuredContent,_meta:B._meta},resourceEndpoint:o,chatSessionId:l,isDark:i,autoHeight:V,toolDefinitions:g,onFollowUp:s,onCallTool:u,onDisplayModeChange:c?he=>c(he,{toolCallId:R.toolCallId,resourceUri:j,toolInput:R.input??{},toolResult:{content:B.content,structuredContent:B.structuredContent,_meta:B._meta},autoHeight:V}):void 0})})]},R.toolCallId)}),!H&&(0,_e.jsx)("div",{children:(0,_e.jsxs)(_d,{children:[M.length>0&&(0,_e.jsx)(g0,{files:M}),k?A.map((R,B)=>(0,_e.jsx)(Od,{children:R.type==="text"?R.text:""},`${b.id}-${B}`)):P&&v&&(0,_e.jsx)(Km,{})]})})]},b.id)}),!h&&x&&(0,_e.jsx)(Dd,{from:"assistant",children:(0,_e.jsx)(_d,{children:(0,_e.jsx)(Km,{})})})]})}var El=F(ue(),1),zz="https://app.waniwani.ai/assets/waniwani-logo.svg",qz="https://waniwani.ai";function xM(){return(0,El.jsx)("div",{className:"ww:pt-2 ww:pb-1 ww:flex ww:justify-center",children:(0,El.jsxs)("a",{href:qz,target:"_blank",rel:"noopener noreferrer",className:"ww:flex ww:items-center ww:gap-1.5 ww:text-[11px] ww:text-muted-foreground ww:opacity-70 hover:ww:opacity-100 ww:transition-opacity",children:[(0,El.jsx)("span",{children:"powered by"}),(0,El.jsx)("img",{src:zz,alt:"WaniWani",width:72,height:10,className:"ww:h-2.5 ww:w-auto"})]})})}var ks=F(ue(),1);function vM({suggestions:e,isLoading:t,onSelect:a,className:n,...r}){return e.length===0&&!t?null:(0,ks.jsx)("div",{className:K("ww:px-4 ww:py-2",n),...r,children:(0,ks.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,ks.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,ks.jsx)("button",{type:"button",onClick:()=>a(o),className:K("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 Rl=F(Qe(),1),Ae=F(ue(),1),wM=20;function Fz(e){let t=Date.parse(e);if(Number.isNaN(t))return"";let a=Date.now()-t;return a<6e4?"just now":a<60*6e4?`${Math.floor(a/6e4)}m ago`:a<1440*6e4?`${Math.floor(a/(60*6e4))}h ago`:`${Math.floor(a/(1440*6e4))}d ago`}function Hz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"New chat",children:[(0,Ae.jsx)("title",{children:"New chat"}),(0,Ae.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,Ae.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function jz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"Thread history",children:[(0,Ae.jsx)("title",{children:"Thread history"}),(0,Ae.jsx)("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),(0,Ae.jsx)("polyline",{points:"3 4 3 9 8 9"}),(0,Ae.jsx)("line",{x1:"12",y1:"7",x2:"12",y2:"12"}),(0,Ae.jsx)("line",{x1:"12",y1:"12",x2:"15",y2:"14"})]})}function Vz(){return(0,Ae.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":"Delete thread",children:[(0,Ae.jsx)("title",{children:"Delete thread"}),(0,Ae.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,Ae.jsx)("path",{d:"M19 6l-2 14a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2L5 6"}),(0,Ae.jsx)("path",{d:"M10 11v6"}),(0,Ae.jsx)("path",{d:"M14 11v6"})]})}function bM({threads:e,activeThreadId:t,onNewThread:a,onSelectThread:n,onDeleteThread:r}){let[o,l]=(0,Rl.useState)(!1),i=(0,Rl.useRef)(null);(0,Rl.useEffect)(()=>{if(!o)return;let c=d=>{let f=i.current;f&&(d.composedPath().includes(f)||l(!1))};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[o]);let s=e.slice(0,wM),u=Math.max(0,e.length-wM);return(0,Ae.jsxs)("div",{ref:i,className:"ww:relative ww:flex ww:items-center ww:gap-1",children:[(0,Ae.jsx)("button",{type:"button",onClick:a,title:"New chat","aria-label":"New chat",className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(Hz,{})}),(0,Ae.jsx)("button",{type:"button",onClick:()=>l(c=>!c),title:"Thread history","aria-label":"Thread history","aria-expanded":o,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(jz,{})}),o&&(0,Ae.jsxs)("div",{role:"menu",className:"ww:absolute ww:right-0 ww:top-full ww:mt-1 ww:w-72 ww:max-h-80 ww:overflow-y-auto ww:rounded-lg ww:border ww:border-border ww:bg-background ww:shadow-lg ww:z-50",children:[s.length===0&&(0,Ae.jsx)("div",{className:"ww:px-3 ww:py-3 ww:text-xs ww:text-muted-foreground",children:"No previous chats yet."}),s.map(c=>{let d=c.threadId===t;return(0,Ae.jsxs)("div",{className:`ww:flex ww:items-center ww:gap-2 ww:px-3 ww:py-2 ww:text-xs hover:ww:bg-foreground/5 ${d?"ww:bg-foreground/5":""}`,children:[(0,Ae.jsxs)("button",{type:"button",onClick:()=>{n(c.threadId),l(!1)},className:"ww:flex-1 ww:min-w-0 ww:text-left ww:cursor-pointer",children:[(0,Ae.jsx)("div",{className:"ww:truncate ww:text-foreground ww:font-medium",children:c.title}),(0,Ae.jsx)("div",{className:"ww:text-[10px] ww:text-muted-foreground",children:Fz(c.updatedAt)})]}),(0,Ae.jsx)("button",{type:"button",onClick:f=>{f.stopPropagation(),r(c.threadId)},title:"Delete thread","aria-label":"Delete thread",className:"ww:p-1 ww:rounded ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/10 ww:transition-colors ww:cursor-pointer",children:(0,Ae.jsx)(Vz,{})})]},c.threadId)}),u>0&&(0,Ae.jsxs)("div",{className:"ww:px-3 ww:py-2 ww:text-[10px] ww:text-muted-foreground ww:border-t ww:border-border",children:[u," older thread",u===1?"":"s"," hidden"]})]})]})}var Bd=F(Qe(),1);function SM(e){let t=(0,Bd.useRef)(e);return t.current=e,(0,Bd.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 Ua=F(Qe(),1);var KM="vercel.ai.error",Gz=Symbol.for(KM),CM,IM,we=class YM extends(IM=Error,CM=Gz,IM){constructor({name:t,message:a,cause:n}){super(a),this[CM]=!0,this.name=t,this.cause=n}static isInstance(t){return YM.hasMarker(t,KM)}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}},JM="AI_APICallError",eE=`vercel.ai.error.${JM}`,$z=Symbol.for(eE),LM,kM,gY=class extends(kM=we,LM=$z,kM){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:JM,message:e,cause:l}),this[LM]=!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 we.hasMarker(e,eE)}},tE="AI_EmptyResponseBodyError",aE=`vercel.ai.error.${tE}`,Wz=Symbol.for(aE),TM,AM,yY=class extends(AM=we,TM=Wz,AM){constructor({message:e="Empty response body"}={}){super({name:tE,message:e}),this[TM]=!0}static isInstance(e){return we.hasMarker(e,aE)}};function nE(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var rE="AI_InvalidArgumentError",oE=`vercel.ai.error.${rE}`,Xz=Symbol.for(oE),MM,EM,lE=class extends(EM=we,MM=Xz,EM){constructor({message:e,cause:t,argument:a}){super({name:rE,message:e,cause:t}),this[MM]=!0,this.argument=a}static isInstance(e){return we.hasMarker(e,oE)}},iE="AI_InvalidPromptError",sE=`vercel.ai.error.${iE}`,Zz=Symbol.for(sE),RM,DM,xY=class extends(DM=we,RM=Zz,DM){constructor({prompt:e,message:t,cause:a}){super({name:iE,message:`Invalid prompt: ${t}`,cause:a}),this[RM]=!0,this.prompt=e}static isInstance(e){return we.hasMarker(e,sE)}},uE="AI_InvalidResponseDataError",cE=`vercel.ai.error.${uE}`,Qz=Symbol.for(cE),_M,OM,vY=class extends(OM=we,_M=Qz,OM){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:uE,message:t}),this[_M]=!0,this.data=e}static isInstance(e){return we.hasMarker(e,cE)}},dE="AI_JSONParseError",fE=`vercel.ai.error.${dE}`,Kz=Symbol.for(fE),PM,NM,Ay=class extends(NM=we,PM=Kz,NM){constructor({text:e,cause:t}){super({name:dE,message:`JSON parsing failed: Text: ${e}.
124
124
  Error message: ${nE(t)}`,cause:t}),this[PM]=!0,this.text=e}static isInstance(e){return we.hasMarker(e,fE)}},pE="AI_LoadAPIKeyError",mE=`vercel.ai.error.${pE}`,Yz=Symbol.for(mE),BM,UM,wY=class extends(UM=we,BM=Yz,UM){constructor({message:e}){super({name:pE,message:e}),this[BM]=!0}static isInstance(e){return we.hasMarker(e,mE)}},hE="AI_LoadSettingError",gE=`vercel.ai.error.${hE}`,Jz=Symbol.for(gE),zM,qM,bY=class extends(qM=we,zM=Jz,qM){constructor({message:e}){super({name:hE,message:e}),this[zM]=!0}static isInstance(e){return we.hasMarker(e,gE)}},yE="AI_NoContentGeneratedError",xE=`vercel.ai.error.${yE}`,eq=Symbol.for(xE),FM,HM,SY=class extends(HM=we,FM=eq,HM){constructor({message:e="No content generated."}={}){super({name:yE,message:e}),this[FM]=!0}static isInstance(e){return we.hasMarker(e,xE)}},vE="AI_NoSuchModelError",wE=`vercel.ai.error.${vE}`,tq=Symbol.for(wE),jM,VM,CY=class extends(VM=we,jM=tq,VM){constructor({errorName:e=vE,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 we.hasMarker(e,wE)}},bE="AI_TooManyEmbeddingValuesForCallError",SE=`vercel.ai.error.${bE}`,aq=Symbol.for(SE),GM,$M,IY=class extends($M=we,GM=aq,$M){constructor(e){super({name:bE,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[GM]=!0,this.provider=e.provider,this.modelId=e.modelId,this.maxEmbeddingsPerCall=e.maxEmbeddingsPerCall,this.values=e.values}static isInstance(e){return we.hasMarker(e,SE)}},CE="AI_TypeValidationError",IE=`vercel.ai.error.${CE}`,nq=Symbol.for(IE),WM,XM,ln=class Ty extends(XM=we,WM=nq,XM){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:CE,message:`${r}: Value: ${JSON.stringify(t)}.
125
125
  Error message: ${nE(a)}`,cause:a}),this[WM]=!0,this.value=t,this.context=n}static isInstance(t){return we.hasMarker(t,IE)}static wrap({value:t,cause:a,context:n}){var r,o,l;return Ty.isInstance(a)&&a.value===t&&((r=a.context)==null?void 0:r.field)===n?.field&&((o=a.context)==null?void 0:o.entityName)===n?.entityName&&((l=a.context)==null?void 0:l.entityId)===n?.entityId?a:new Ty({value:t,cause:a,context:n})}},LE="AI_UnsupportedFunctionalityError",kE=`vercel.ai.error.${LE}`,rq=Symbol.for(kE),ZM,QM,LY=class extends(QM=we,ZM=rq,QM){constructor({functionality:e,message:t=`'${e}' functionality not supported.`}){super({name:LE,message:t}),this[ZM]=!0,this.functionality=e}static isInstance(e){return we.hasMarker(e,kE)}};var Ud=()=>Ey,Ey=new Proxy(Ud,{get(e,t){return t==="parse"||t==="parseAsync"?a=>a:t==="safeParse"||t==="safeParseAsync"?a=>({success:!0,data:a}):t==="_def"?{}:t==="jsonSchema"?{}:Ud},apply(){return Ey}}),My=class extends Error{constructor(){super(...arguments);ke(this,"issues",[])}},m=new Proxy(Ud,{get(e,t){return t==="ZodError"?My:t==="NEVER"?Symbol("NEVER"):Ud},apply(){return Ey}});var re={};var zd=class extends Error{constructor(t,a){super(t),this.name="ParseError",this.type=a.type,this.field=a.field,this.value=a.value,this.line=a.line}};function Ry(e){}function TE(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");let{onEvent:t=Ry,onError:a=Ry,onRetry:n=Ry,onComment:r}=e,o="",l=!0,i,s="",u="";function c(v){let I=l?v.replace(/^\xEF\xBB\xBF/,""):v,[y,x]=oq(`${o}${I}`);for(let h of y)d(h);o=x,l=!1}function d(v){if(v===""){p();return}if(v.startsWith(":")){r&&r(v.slice(v.startsWith(": ")?2:1));return}let I=v.indexOf(":");if(I!==-1){let y=v.slice(0,I),x=v[I+1]===" "?2:1,h=v.slice(I+x);f(y,h,v);return}f(v,"",v)}function f(v,I,y){switch(v){case"event":u=I;break;case"data":s=`${s}${I}
126
126
  `;break;case"id":i=I.includes("\0")?void 0:I;break;case"retry":/^\d+$/.test(I)?n(parseInt(I,10)):a(new zd(`Invalid \`retry\` value: "${I}"`,{type:"invalid-retry",value:I,line:y}));break;default:a(new zd(`Unknown field "${v.length>20?`${v.slice(0,20)}\u2026`:v}"`,{type:"unknown-field",field:v,value:I,line:y}));break}}function p(){s.length>0&&t({id:i,event:u||void 0,data:s.endsWith(`