@waniwani/sdk 0.1.9 → 0.1.11

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.
@@ -113,6 +113,7 @@ type ChatWidgetProps = ChatBarProps;
113
113
 
114
114
  declare const ChatBar: react.ForwardRefExoticComponent<ChatBarProps & react.RefAttributes<ChatHandle>>;
115
115
 
116
+ type McpAppDisplayMode = "inline" | "pip" | "fullscreen";
116
117
  interface McpAppFrameProps {
117
118
  resourceUri: string;
118
119
  toolInput: Record<string, unknown>;
@@ -138,8 +139,10 @@ interface McpAppFrameProps {
138
139
  text?: string;
139
140
  }>;
140
141
  }) => void;
142
+ /** Called when the widget requests a display mode change (e.g. "fullscreen" for expand) */
143
+ onDisplayModeChange?: (mode: McpAppDisplayMode) => void;
141
144
  }
142
- declare function McpAppFrame({ resourceUri, toolInput, toolResult, resourceEndpoint, isDark, className, autoHeight, onOpenLink, onFollowUp, }: McpAppFrameProps): react_jsx_runtime.JSX.Element;
145
+ declare function McpAppFrame({ resourceUri, toolInput, toolResult, resourceEndpoint, isDark, className, autoHeight, onOpenLink, onFollowUp, onDisplayModeChange, }: McpAppFrameProps): react_jsx_runtime.JSX.Element;
143
146
 
144
147
  declare const ChatCard: react.ForwardRefExoticComponent<ChatCardProps & react.RefAttributes<ChatHandle>>;
145
148
 
@@ -148,4 +151,4 @@ declare const DARK_THEME: ChatTheme;
148
151
  declare function mergeTheme(userTheme?: ChatTheme): Required<ChatTheme>;
149
152
  declare function themeToCSSProperties(theme: Required<ChatTheme>): Record<string, string>;
150
153
 
151
- export { ChatBar, type ChatBarProps, type ChatBaseProps, ChatCard, type ChatCardProps, type ChatHandle, type ChatTheme, ChatBar as ChatWidget, type ChatWidgetProps, DARK_THEME, DEFAULT_THEME, McpAppFrame, type McpAppFrameProps, type SuggestionsConfig, mergeTheme, themeToCSSProperties };
154
+ export { ChatBar, type ChatBarProps, type ChatBaseProps, ChatCard, type ChatCardProps, type ChatHandle, type ChatTheme, ChatBar as ChatWidget, type ChatWidgetProps, DARK_THEME, DEFAULT_THEME, type McpAppDisplayMode, McpAppFrame, type McpAppFrameProps, type SuggestionsConfig, mergeTheme, themeToCSSProperties };
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import{forwardRef as Eo,useCallback as ye,useEffect as ut,useImperativeHandle as Io,useRef as ct,useState as pt}from"react";import{ArrowDownIcon as bt}from"lucide-react";import{useCallback as xt}from"react";import{StickToBottom as Fe,useStickToBottomContext as yt}from"use-stick-to-bottom";import{clsx as mt}from"clsx";import{extendTailwindMerge as ft}from"tailwind-merge";var gt=ft({prefix:"ww"});function i(...e){return gt(mt(e))}import{jsx as ht}from"react/jsx-runtime";var J=({className:e,variant:t="default",size:o="default",type:r="button",...n})=>ht("button",{type:r,className:i("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",o==="default"&&"ww:h-9 ww:px-4 ww:py-2 ww:text-sm",o==="sm"&&"ww:h-8 ww:px-3 ww:text-xs",o==="icon"&&"ww:size-9",o==="icon-sm"&&"ww:size-7",e),...n});import{jsx as oe}from"react/jsx-runtime";var re=({className:e,...t})=>oe(Fe,{className:i("ww:relative ww:flex-1 ww:overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),ne=({className:e,...t})=>oe(Fe.Content,{className:i("ww:flex ww:flex-col ww:gap-8 ww:p-4",e),...t}),se=({className:e,...t})=>{let{isAtBottom:o,scrollToBottom:r}=yt(),n=xt(()=>{r()},[r]);return!o&&oe(J,{className:i("ww:absolute ww:bottom-4 ww:left-[50%] ww:translate-x-[-50%] ww:rounded-full",e),onClick:n,size:"icon",variant:"outline",...t,children:oe(bt,{className:"ww:size-4"})})};import{ArrowUpIcon as Ct,LoaderIcon as vt,PaperclipIcon as Tt,SquareIcon as Pt,XIcon as Mt}from"lucide-react";import{nanoid as kt}from"nanoid";import{createContext as St,useCallback as q,useContext as Et,useEffect as Pe,useMemo as It,useRef as Me,useState as Ue}from"react";import{jsx as O,jsxs as _e}from"react/jsx-runtime";var Rt=async e=>{try{let o=await(await fetch(e)).blob();return new Promise(r=>{let n=new FileReader;n.onloadend=()=>r(n.result),n.onerror=()=>r(null),n.readAsDataURL(o)})}catch{return null}},Oe=St(null),ze=()=>{let e=Et(Oe);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},ae=({className:e,accept:t,multiple:o,globalDrop:r,maxFiles:n,maxFileSize:s,onSubmit:a,children:w,...m})=>{let c=Me(null),l=Me(null),[p,y]=Ue([]),C=Me(p);Pe(()=>{C.current=p},[p]);let E=q(()=>{c.current?.click()},[]),P=q(b=>{let v=[...b];if(v.length===0)return;let M=g=>s?g.size<=s:!0,N=v.filter(M);y(g=>{let I=typeof n=="number"?Math.max(0,n-g.length):void 0,R=typeof I=="number"?N.slice(0,I):N;return[...g,...R.map(k=>({filename:k.name,id:kt(),mediaType:k.type,type:"file",url:URL.createObjectURL(k)}))]})},[n,s]),f=q(b=>{y(v=>{let M=v.find(N=>N.id===b);return M?.url&&URL.revokeObjectURL(M.url),v.filter(N=>N.id!==b)})},[]),u=q(()=>{y(b=>{for(let v of b)v.url&&URL.revokeObjectURL(v.url);return[]})},[]);Pe(()=>()=>{for(let b of C.current)b.url&&URL.revokeObjectURL(b.url)},[]);let d=q(b=>{b.currentTarget.files&&P(b.currentTarget.files),b.currentTarget.value=""},[P]);Pe(()=>{if(!r)return;let b=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault()},v=M=>{M.dataTransfer?.types?.includes("Files")&&M.preventDefault(),M.dataTransfer?.files&&M.dataTransfer.files.length>0&&P(M.dataTransfer.files)};return document.addEventListener("dragover",b),document.addEventListener("drop",v),()=>{document.removeEventListener("dragover",b),document.removeEventListener("drop",v)}},[P,r]);let x=q(async b=>{b.preventDefault();let v=b.currentTarget,N=new FormData(v).get("message")||"";v.reset();let g=await Promise.all(p.map(async({id:I,...R})=>{if(R.url?.startsWith("blob:")){let k=await Rt(R.url);return{...R,url:k??R.url}}return R}));try{let I=a({files:g,text:N},b);I instanceof Promise&&await I,u()}catch{}},[p,a,u]),D=It(()=>({add:P,clear:u,files:p,openFileDialog:E,remove:f}),[p,P,f,u,E]);return _e(Oe.Provider,{value:D,children:[O("input",{accept:t,"aria-label":"Upload files",className:"ww:hidden",multiple:o,onChange:d,ref:c,title:"Upload files",type:"file"}),O("form",{className:i("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:x,ref:l,...m,children:w})]})};var ie=({onChange:e,onKeyDown:t,className:o,placeholder:r="What would you like to know?",...n})=>{let s=ze(),[a,w]=Ue(!1),m=q(l=>{if(t?.(l),!l.defaultPrevented){if(l.key==="Enter"){if(a||l.nativeEvent.isComposing||l.shiftKey)return;l.preventDefault();let{form:p}=l.currentTarget;if(p?.querySelector('button[type="submit"]')?.disabled)return;p?.requestSubmit()}if(l.key==="Backspace"&&l.currentTarget.value===""&&s.files.length>0){l.preventDefault();let p=s.files.at(-1);p&&s.remove(p.id)}}},[t,a,s]),c=q(l=>{let p=l.clipboardData?.items;if(!p)return;let y=[];for(let C of p)if(C.kind==="file"){let E=C.getAsFile();E&&y.push(E)}y.length>0&&(l.preventDefault(),s.add(y))},[s]);return O("textarea",{className:i("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",o),name:"message",onCompositionEnd:()=>w(!1),onCompositionStart:()=>w(!0),onKeyDown:m,onPaste:c,placeholder:r,onChange:e,...n})},we=({className:e,status:t,onStop:o,onClick:r,children:n,...s})=>{let a=t==="submitted"||t==="streaming",w=O(Ct,{className:"ww:size-4"});t==="submitted"?w=O(vt,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(w=O(Pt,{className:"ww:size-4"}));let m=q(c=>{if(a&&o){c.preventDefault(),o();return}r?.(c)},[a,o,r]);return O(J,{"aria-label":a?"Stop":"Submit",className:i("ww:bg-foreground ww:text-background ww:hover:bg-foreground",e),onClick:m,size:"icon-sm",type:a&&o?"button":"submit",variant:"ghost",...s,children:n??w})},le=({className:e,children:t,...o})=>{let r=ze();return r.files.length>0?_e(J,{className:i("ww:group ww:relative",e),onClick:()=>r.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":"Remove all attachments",...o,children:[O("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:r.files.length}),O(Mt,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):O(J,{className:i(e),onClick:()=>r.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...o,children:t??O(Tt,{className:"ww:size-4"})})};import{FileIcon as Nt}from"lucide-react";import{jsx as Y,jsxs as At}from"react/jsx-runtime";var We=({files:e,className:t,...o})=>e.length===0?null:Y("div",{className:i("ww:flex ww:flex-wrap ww:gap-1.5",t),...o,children:e.map((r,n)=>Y(Lt,{file:r},n))});function Lt({file:e}){return e.mediaType?.startsWith("image/")&&e.url?Y("img",{src:e.url,alt:e.filename??"attachment",className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):At("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:[Y(Nt,{className:"ww:size-3 ww:shrink-0"}),Y("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??"file"})]})}import{jsx as $e}from"react/jsx-runtime";var ke=({className:e,size:t=5,...o})=>$e("div",{className:i("ww:flex ww:items-center ww:gap-1",e),...o,children:[0,1,2].map(r=>$e("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:`${r*.2}s`}},r))});import{cjk as Ht}from"@streamdown/cjk";import{code as Bt}from"@streamdown/code";import{memo as Dt}from"react";import{Streamdown as Ft}from"streamdown";import{jsx as Se}from"react/jsx-runtime";var ue=({className:e,from:t,...o})=>Se("div",{className:i("ww:group ww:flex ww:w-full ww:max-w-[95%] ww:flex-col ww:gap-2",t==="user"?"is-user ww:ml-auto ww:justify-end":"is-assistant",e),...o}),ce=({children:e,className:t,...o})=>Se("div",{className:i("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),...o,children:e}),Ut={cjk:Ht,code:Bt},pe=Dt(({className:e,...t})=>Se(Ft,{className:i("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),plugins:Ut,...t}),(e,t)=>e.children===t.children);pe.displayName="MessageResponse";import{jsx as Ot}from"react/jsx-runtime";function je({className:e,text:t,...o}){return t?Ot("pre",{className:i("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),...o,children:t}):null}import{BracesIcon as zt,CheckIcon as _t,ChevronDownIcon as Wt,ChevronRightIcon as $t,ClipboardCopyIcon as jt,ServerIcon as xr}from"lucide-react";import{createContext as qt,useCallback as Vt,useContext as Ve,useEffect as Jt,useMemo as Kt,useRef as Gt,useState as Ee}from"react";import{Fragment as qe,jsx as T,jsxs as K}from"react/jsx-runtime";function Xt(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 o=JSON.stringify(e);if(o.length<=t)return o;let r=Object.entries(e),n=[],s=t-2;for(let[a,w]of r){if(s<=8)break;let m=a.length>4?`${a.slice(0,4)}\u2026`:a,c;typeof w=="string"?c=w.length>2?`'${w.slice(0,1)}\u2026`:`'${w}'`:Array.isArray(w)?c=`Array(${w.length})`:typeof w=="object"&&w!==null?c="{\u2026}":c=String(w);let l=`${m}\u2009${c}`;n.push(l),s-=l.length+3}return`{${n.join(", ")}}`}function Yt({text:e,className:t}){let[o,r]=Ee(!1),n=Gt(null);Jt(()=>()=>{n.current&&clearTimeout(n.current)},[]);let s=Vt(async a=>{a.stopPropagation();try{await navigator.clipboard.writeText(e),r(!0),n.current&&clearTimeout(n.current),n.current=setTimeout(()=>r(!1),2e3)}catch{}},[e]);return T(J,{variant:"ghost",size:"sm",onClick:s,className:i("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:o?K(qe,{children:[T(_t,{className:"ww:size-3.5"}),T("span",{children:"Copied"})]}):K(qe,{children:[T(jt,{className:"ww:size-3.5"}),T("span",{children:"Copy"})]})})}function Je({data:e,label:t,className:o,...r}){let[n,s]=Ee(!1),a=Kt(()=>JSON.stringify(e,null,2),[e]),w=Xt(e);return K("div",{className:i("ww:rounded-lg ww:bg-tool-card",o),...r,children:[K("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[T("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),T(Yt,{text:a})]}),K("button",{type:"button",onClick:()=>s(m=>!m),className:"ww:flex ww:w-full ww:items-start ww:gap-2 ww:px-3 ww:pb-3 ww:text-left",children:[T($t,{className:i("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",n&&"ww:rotate-90")}),n?T("pre",{className:"ww:overflow-x-auto ww:text-xs ww:font-mono ww:text-foreground ww:whitespace-pre-wrap ww:break-all",children:T("code",{children:a})}):T("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:w})]})]})}var Ie=qt({open:!1,toggle:()=>{}});function Ke({className:e,defaultOpen:t=!1,children:o,...r}){let[n,s]=Ee(t);return T(Ie.Provider,{value:{open:n,toggle:()=>s(a=>!a)},children:T("div",{className:i("ww:mb-4 ww:w-full",e),"data-state":n?"open":"closed",...r,children:o})})}function Ge({className:e,title:t,state:o,...r}){let{open:n,toggle:s}=Ve(Ie),a=o==="input-available"||o==="input-streaming";return K("button",{type:"button",onClick:s,className:i("ww:flex ww:w-full ww:items-center ww:justify-between ww:gap-3 ww:py-1.5",e),"aria-expanded":n,...r,children:[K("div",{className:"ww:flex ww:min-w-0 ww:items-center ww:gap-2",children:[T(zt,{className:"ww:size-4 ww:shrink-0 ww:text-muted-foreground"}),T("span",{className:"ww:truncate ww:text-sm ww:font-medium",children:t}),a&&T("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]}),T(Wt,{className:i("ww:size-4 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-200",n&&"ww:rotate-180")})]})}function Xe({className:e,children:t,...o}){let{open:r}=Ve(Ie);return T("div",{className:i("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",r?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:T("div",{className:"ww:min-h-0 ww:overflow-hidden",children:T("div",{className:i("ww:mt-2 ww:space-y-3 ww:rounded-lg ww:border ww:border-border ww:bg-background ww:p-3",e),...o,children:t})})})}function Ye({className:e,input:t,...o}){return T(Je,{data:t,label:"Request",className:e,...o})}function Ze(e){if(typeof e!="object"||e===null)return;let t=e._meta;if(typeof t!="object"||t===null)return;let o=t.ui;if(!(typeof o!="object"||o===null))return o}function Qe(e){let t=Ze(e)?.resourceUri;return typeof t=="string"?t:void 0}function et(e){return Ze(e)?.autoHeight===!0}function tt({className:e,output:t,errorText:o,...r}){return t||o?o?K("div",{className:i("ww:space-y-2",e),...r,children:[T("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:"Error"}),T("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:o})]}):T(Je,{data:t,label:"Response",className:e,...r}):null}import{useCallback as Zt,useEffect as ot,useMemo as Qt,useRef as W,useState as rt}from"react";import{jsx as ao}from"react/jsx-runtime";var eo="/api/mcp/resource",to=500,oo=0,ro="2026-01-26",no=300,so=3e3,Re=3;function Ne({resourceUri:e,toolInput:t,toolResult:o,resourceEndpoint:r=eo,isDark:n=!1,className:s,autoHeight:a=!0,onOpenLink:w,onFollowUp:m}){let c=W(null),l=W(t),p=W(o),y=W({width:0,height:0}),C=W(null),E=W(!1),P=W(0),[f,u]=rt(oo),[d,x]=rt(void 0),D=W(w),b=W(m);l.current=t,p.current=o,D.current=w,b.current=m;let v=Zt(g=>a?Math.max(g,0):Math.min(Math.max(g,50),to),[a]),M=Qt(()=>`${r}?uri=${encodeURIComponent(e)}`,[r,e]),N=W(n);return N.current=n,ot(()=>{if(!E.current)return;let g=c.current;g?.contentWindow&&g.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:n?"dark":"light"}},"*")},[n]),ot(()=>{let g=c.current;if(!g)return;let I=!1,R=!1,k=(...S)=>console.debug("[McpAppFrame]",...S);k("effect mounted, waiting for handshake");let L=setTimeout(()=>{if(I||R)return;if(P.current>=Re){k("handshake failed after",Re,"retries, giving up");return}P.current+=1,k("handshake timeout, reloading iframe (retry",P.current,"of",Re,")");let S=new URL(g.src);S.searchParams.set("_retry",String(P.current)),g.src=S.toString()},so),h=S=>{k("\u2192 send",S.method??`response:${S.id}`,S),g.contentWindow?.postMessage(S,"*")},A=S=>{if(I||S.source!==g.contentWindow)return;let B=S.data;if(!B||typeof B!="object"||B.jsonrpc!=="2.0")return;let j=B.method,F=B.id;if(k("\u2190 recv",j??`response:${F}`,B),j==="ui/initialize"&&F!=null){R=!0,clearTimeout(L),k("handshake started"),h({jsonrpc:"2.0",id:F,result:{protocolVersion:B.params?.protocolVersion??ro,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{}},hostContext:{theme:N.current?"dark":"light",displayMode:"inline"}}});return}if(j==="ui/notifications/initialized"){k("handshake complete, sending tool data"),E.current=!0;let z=l.current,_=p.current;h({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:z}});let V=_.content??[{type:"text",text:JSON.stringify(_)}];h({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:V,structuredContent:_.structuredContent}});return}if(j==="ui/notifications/size-changed"){let z=B.params,_=typeof z?.height=="number"?z.height:void 0,V=typeof z?.width=="number"?z.width:void 0,G=y.current,Ce=_!==void 0&&_!==G.height,ve=V!==void 0&&V!==G.width;if(k("size-changed",{newHeight:_,newWidth:V,lastHeight:G.height,lastWidth:G.width,heightChanged:Ce,widthChanged:ve}),!Ce&&!ve)return;if(Ce&&_!==void 0){G.height=_;let Te=v(_),De=g.getBoundingClientRect().height;if(C.current&&(C.current.cancel(),C.current=null),u(Te),g.animate&&Math.abs(De-Te)>2){let te=g.animate([{height:`${De}px`},{height:`${Te}px`}],{duration:no,easing:"ease-out",fill:"forwards"});C.current=te,te.onfinish=()=>{C.current===te&&(te.cancel(),C.current=null)}}}ve&&a&&V!==void 0&&(G.width=V,x(V));return}if(j==="ui/open-link"&&F!=null){let z=B.params?.url;typeof z=="string"&&(D.current?D.current(z):window.open(z,"_blank","noopener,noreferrer")),h({jsonrpc:"2.0",id:F,result:{}});return}if(j==="ui/message"&&F!=null){b.current&&B.params&&b.current(B.params),h({jsonrpc:"2.0",id:F,result:{}});return}if(j==="ui/request-display-mode"&&F!=null){h({jsonrpc:"2.0",id:F,result:{}});return}if(j==="ui/resource-teardown"&&F!=null){h({jsonrpc:"2.0",id:F,result:{}});return}j==="ping"&&F!=null&&h({jsonrpc:"2.0",id:F,result:{}})};return window.addEventListener("message",A),()=>{k("effect cleanup (disposed)"),I=!0,clearTimeout(L),window.removeEventListener("message",A)}},[a,v]),ao("iframe",{ref:c,src:M,sandbox:"allow-scripts allow-forms allow-same-origin",className:i("ww:rounded-md ww:border ww:border-border",s),style:{height:f,minWidth:d?`min(${d}px, 100%)`:void 0,width:"100%",border:"none",colorScheme:"auto"},title:"MCP App"})}import{Component as io}from"react";import{jsx as nt,jsxs as wo}from"react/jsx-runtime";var de=class extends io{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.warn("[WaniWani] Widget failed to render:",t.message)}render(){return this.state.hasError?wo("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:[nt("span",{children:"Widget failed to load"}),nt("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}};import{Fragment as uo,jsx as H,jsxs as X}from"react/jsx-runtime";function lo(e){return e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase())}function me({messages:e,status:t,welcomeMessage:o,resourceEndpoint:r,isDark:n,onFollowUp:s}){let a=t==="submitted"||t==="streaming",w=e[e.length-1],m=e.length>0,c=a&&(!m||w.role==="user");return X(uo,{children:[o&&H(ue,{from:"assistant",children:H(ce,{children:H(pe,{children:o})})}),e.map(l=>{let p=l.parts.filter(u=>u.type==="text"),y=l.parts.filter(u=>u.type==="reasoning"),C=l.parts.filter(u=>u.type==="file"),E=l.parts.filter(u=>"toolCallId"in u),P=l===w&&l.role==="assistant",f=p.length>0;return X(ue,{from:l.role,children:[y.map((u,d)=>H(je,{text:u.text},`reasoning-${l.id}-${d}`)),E.map(u=>{let d="output"in u?u.output:void 0,x=d!==void 0?Qe(d):void 0,D=d!==void 0?et(d):!1;return X("div",{children:[X(Ke,{defaultOpen:u.state==="output-available",children:[H(Ge,{title:u.title??lo(u.toolName),state:u.state}),X(Xe,{children:[H(Ye,{input:u.input}),d!==void 0&&H(tt,{output:d,errorText:"errorText"in u?u.errorText:void 0})]})]}),x&&d!==void 0&&H(de,{children:H(Ne,{resourceUri:x,toolInput:u.input??{},toolResult:{content:d.content,structuredContent:d.structuredContent},resourceEndpoint:r,isDark:n,autoHeight:D,onFollowUp:s})})]},u.toolCallId)}),X(ce,{children:[C.length>0&&H(We,{files:C}),f?p.map((u,d)=>H(pe,{children:u.type==="text"?u.text:""},`${l.id}-${d}`)):P&&a&&H(ke,{})]})]},l.id)}),c&&H(ue,{from:"assistant",children:H(ce,{children:H(ke,{})})})]})}import{jsx as Le}from"react/jsx-runtime";function fe({suggestions:e,isLoading:t,onSelect:o,className:r,...n}){return e.length===0&&!t?null:Le("div",{className:i("ww:flex ww:flex-wrap ww:gap-2 ww:px-3 ww:py-2",r),...n,children:t?[0,1,2].map(s=>Le("div",{className:"ww:h-7 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+s*20}px`}},s)):e.map((s,a)=>Le("button",{type:"button",onClick:()=>o(s),className:i("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:`${a*50}ms`},children:s},s))})}import{useChat as co}from"@ai-sdk/react";import{DefaultChatTransport as po}from"ai";import{useCallback as st,useRef as mo,useState as fo}from"react";function ge(e){let{api:t="https://app.waniwani.ai/api/chat",headers:o,body:r,onMessageSent:n,onResponseReceived:s}=e,a=mo(new po({api:t,headers:{...o},body:r})),{messages:w,sendMessage:m,status:c}=co({transport:a.current,onFinish(){s?.()},onError(d){console.warn("[WaniWani] Chat error:",d.message)}}),[l,p]=fo(""),y=st(d=>{let x=!!d.text?.trim(),D=!!d.files?.length;(x||D)&&(m({text:d.text||"",files:d.files}),n?.(d.text||""),p(""))},[m,n]),C=st(d=>{p(d.target.value)},[]),E=c==="submitted"||c==="streaming",P=w[w.length-1],f=w.length>0,u=E&&(!f||P.role==="user");return{messages:w,status:c,text:l,setText:p,handleSubmit:y,handleTextChange:C,isLoading:E,showLoaderBubble:u,lastMessage:P,hasMessages:f,sendMessage:m}}import{useCallback as go,useEffect as at,useRef as ho,useState as bo}from"react";function xo(e){for(let t of e.parts){let o=t;if(o.type==="data"||o.type==="data-suggestions"){let r=o.data;if(r&&Array.isArray(r.suggestions))return r.suggestions}}return null}function it(e){return typeof e=="object"&&e!==null&&"initial"in e}function he(e){let{messages:t,status:o,config:r}=e,[n,s]=bo((it(r)&&r.initial?r.initial:[])??[]),a=ho(o),w=r===!0||it(r)&&r.dynamic!==!1,m=go(()=>{s([])},[]),c=t[t.length-1];return at(()=>{c?.role==="user"&&m()},[c,m]),at(()=>{let l=a.current;if(a.current=o,l==="streaming"&&o==="ready"&&w){let p=[...t].reverse().find(C=>C.role==="assistant");if(!p)return;console.log("[WaniWani] Assistant parts:",p.parts);let y=xo(p);console.log("[WaniWani] Extracted suggestions:",y),y&&s(y)}},[o,w,t]),{suggestions:n,isLoading:!1,clear:m}}import{useEffect as yo,useRef as Co,useState as vo}from"react";var To=50,Po=30,Mo=2e3,wt=500;function be(e,t=!0){let[o,r]=vo(""),n=Co(void 0);return yo(()=>{if(!t){r("");return}let s=0,a=!1,w=!1,m=()=>{w||(a?(s--,r(e.slice(0,s)),s<=0?(a=!1,n.current=setTimeout(m,wt)):n.current=setTimeout(m,Po)):(s++,r(e.slice(0,s)),s>=e.length?(a=!0,n.current=setTimeout(m,Mo)):n.current=setTimeout(m,To)))};return n.current=setTimeout(m,wt),()=>{w=!0,clearTimeout(n.current)}},[e,t]),o}var lt={primaryColor:"#6366f1",primaryForeground:"#1f2937",backgroundColor:"#ffffff",textColor:"#1f2937",mutedColor:"#6b7280",borderColor:"#e5e7eb",assistantBubbleColor:"#f3f4f6",userBubbleColor:"#f4f4f4",inputBackgroundColor:"#f9fafb",borderRadius:16,messageBorderRadius:12,fontFamily:"system-ui, -apple-system, 'Segoe UI', sans-serif",headerBackgroundColor:"#ffffff",headerTextColor:"#1f2937",statusColor:"#22c55e",toolCardColor:"#f4f4f5"},ko={backgroundColor:"#212121",headerBackgroundColor:"#1e1e1e",headerTextColor:"#ececec",textColor:"#ececec",primaryForeground:"#ffffff",mutedColor:"#8e8ea0",borderColor:"#444444",assistantBubbleColor:"#2f2f2f",userBubbleColor:"#303030",inputBackgroundColor:"#2f2f2f",primaryColor:"#6366f1",statusColor:"#22c55e",toolCardColor:"#262626"},So={primaryColor:["--ww-primary","--ww-color-primary"],primaryForeground:["--ww-primary-fg","--ww-color-primary-foreground"],backgroundColor:["--ww-bg","--ww-color-background"],textColor:["--ww-text","--ww-color-foreground","--ww-color-accent-foreground"],mutedColor:["--ww-muted","--ww-color-muted-foreground"],borderColor:["--ww-border","--ww-color-border"],assistantBubbleColor:["--ww-assistant-bubble","--ww-color-accent"],userBubbleColor:["--ww-user-bubble"],inputBackgroundColor:["--ww-input-bg","--ww-color-input"],borderRadius:["--ww-radius"],messageBorderRadius:["--ww-msg-radius"],fontFamily:["--ww-font"],headerBackgroundColor:["--ww-header-bg"],headerTextColor:["--ww-header-text"],statusColor:["--ww-status"],toolCardColor:["--ww-tool-card","--ww-color-tool-card"]};function Z(e){return{...lt,...e}}function xe(e){let t=e.backgroundColor.replace("#",""),o=parseInt(t.substring(0,2),16),r=parseInt(t.substring(2,4),16),n=parseInt(t.substring(4,6),16);return(o*299+r*587+n*114)/1e3<128}function Q(e){let t={};for(let[o,r]of Object.entries(So)){let n=e[o],s=typeof n=="number"?`${n}px`:String(n);for(let a of r)t[a]=s}return t}import{jsx as $,jsxs as Ae}from"react/jsx-runtime";var He=Eo(function(t,o){let{theme:r,width:n=600,expandedHeight:s=400,allowAttachments:a=!1,welcomeMessage:w,placeholder:m="Ask me anything...",triggerEvent:c="triggerDemoRequest",resourceEndpoint:l,api:p}=t,y=l??(p?`${p}/resource`:void 0),C=Z(r),E=Q(C),P=xe(C),f=ge(t),u=he({messages:f.messages,status:f.status,config:t.suggestions}),d=ye(h=>{let A=h.content.map(S=>S.text??"").join("").trim();A&&f.handleSubmit({text:A,files:[]})},[f.handleSubmit]),x=ye(h=>{u.clear(),f.handleSubmit({text:h,files:[]})},[u.clear,f.handleSubmit]),D=be(m,!f.text),[b,v]=pt(!1),[M,N]=pt(!1),g=ct(null),I=ct(void 0),R=ye(()=>{let h=g.current;if(!h)return;h.scrollIntoView({behavior:"smooth",block:"center"});let A=h.querySelector("textarea");A&&setTimeout(()=>A.focus(),300),v(!0),N(!0),clearTimeout(I.current),I.current=setTimeout(()=>N(!1),2e3)},[]);Io(o,()=>({sendMessage:h=>{f.handleSubmit({text:h,files:[]}),R()},focus:R}),[f.handleSubmit,R]),ut(()=>{if(!c)return;let h=A=>{let S=A.detail,B=typeof S?.message=="string"?S.message:void 0;B&&f.handleSubmit({text:B,files:[]}),R()};return window.addEventListener(c,h),()=>window.removeEventListener(c,h)},[c,f.handleSubmit,R]);let k=b;ut(()=>{if(!b)return;let h=A=>{g.current&&!g.current.contains(A.target)&&v(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[b]);let L=ye(()=>{v(!0)},[]);return Ae("div",{ref:g,style:{...E,width:n},"data-waniwani-chat":"","data-waniwani-layout":"bar",...P?{"data-waniwani-dark":""}:{},className:"ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground",children:[$("div",{className:i("ww:overflow-hidden ww:bg-background/80 ww:backdrop-blur-xl ww:transition-all ww:duration-300 ww:ease-out",k?"ww:opacity-100 ww:translate-y-0":"ww:opacity-0 ww:translate-y-2 ww:pointer-events-none ww:max-h-0"),style:{...k?{maxHeight:s}:void 0,maskImage:"linear-gradient(to bottom, transparent, black 24px, black calc(100% - 16px), transparent), linear-gradient(to right, transparent, black 16px, black calc(100% - 16px), transparent)",maskComposite:"intersect",WebkitMaskImage:"linear-gradient(to bottom, transparent, black 24px, black calc(100% - 16px), transparent), linear-gradient(to right, transparent, black 16px, black calc(100% - 16px), transparent)",WebkitMaskComposite:"source-in"},children:Ae(re,{className:"ww:flex-1",style:{height:s},children:[$(ne,{children:$(me,{messages:f.messages,status:f.status,welcomeMessage:w,resourceEndpoint:y,isDark:P,onFollowUp:d})}),$(se,{})]})}),$(fe,{suggestions:u.suggestions,isLoading:u.isLoading,onSelect:x}),$("div",{className:"ww:shrink-0",children:$(ae,{onSubmit:f.handleSubmit,globalDrop:a,multiple:a,className:i("ww:rounded-[var(--ww-radius)] ww:shadow-sm ww:transition-all ww:duration-300 ww:ease-out",M&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background"),children:Ae("div",{className:"ww:flex ww:items-center ww:gap-1 ww:px-3 ww:py-2",children:[a&&$(le,{}),$(ie,{onChange:f.handleTextChange,value:f.text,placeholder:D,onFocus:L,className:"ww:min-h-0 ww:py-1.5 ww:px-2"}),$(we,{status:f.status})]})})})]})});import{forwardRef as Ro,useCallback as Be,useEffect as No,useImperativeHandle as Lo,useRef as dt,useState as Ao}from"react";import{jsx as U,jsxs as ee}from"react/jsx-runtime";var Ho=Ro(function(t,o){let{theme:r,title:n="Assistant",subtitle:s,showStatus:a=!0,width:w=500,height:m=600,allowAttachments:c=!1,welcomeMessage:l,placeholder:p="Ask me anything...",triggerEvent:y="triggerDemoRequest",resourceEndpoint:C,api:E}=t,P=C??(E?`${E}/resource`:void 0),f=Z(r),u=Q(f),d=xe(f),x=ge(t),D=be(p,!x.text),[b,v]=Ao(!1),M=dt(null),N=dt(void 0),g=Be(()=>{let L=M.current;if(!L)return;L.scrollIntoView({behavior:"smooth",block:"center"});let h=L.querySelector("textarea");h&&setTimeout(()=>h.focus(),300),v(!0),clearTimeout(N.current),N.current=setTimeout(()=>v(!1),2e3)},[]),I=he({messages:x.messages,status:x.status,config:t.suggestions}),R=Be(L=>{let h=L.content.map(A=>A.text??"").join("").trim();h&&x.handleSubmit({text:h,files:[]})},[x.handleSubmit]),k=Be(L=>{I.clear(),x.handleSubmit({text:L,files:[]})},[I.clear,x.handleSubmit]);return Lo(o,()=>({sendMessage:L=>{x.handleSubmit({text:L,files:[]}),g()},focus:g}),[x.handleSubmit,g]),No(()=>{if(!y)return;let L=h=>{let A=h.detail,S=typeof A?.message=="string"?A.message:void 0;S&&x.handleSubmit({text:S,files:[]}),g()};return window.addEventListener(y,L),()=>window.removeEventListener(y,L)},[y,x.handleSubmit,g]),ee("div",{ref:M,style:{...u,width:w,height:m},"data-waniwani-chat":"","data-waniwani-layout":"card",...d?{"data-waniwani-dark":""}:{},className:i("ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground ww:bg-background ww:rounded-[var(--ww-radius)] ww:border ww:border-border ww:shadow-md ww:overflow-hidden ww:transition-shadow ww:duration-300",b&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background"),children:[ee("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-3 ww:px-4 ww:py-2 ww:border-b ww:border-border",style:{backgroundColor:f.headerBackgroundColor,color:f.headerTextColor},children:[a&&U("span",{className:"ww:size-2.5 ww:rounded-full ww:bg-status"}),ee("div",{className:"ww:flex-1 ww:min-w-0",children:[U("div",{className:"ww:text-xs ww:font-semibold ww:truncate",children:n}),s&&U("div",{className:"ww:text-[11px] ww:text-muted-foreground ww:truncate",children:s})]})]}),ee(re,{className:"ww:flex-1 ww:min-h-0 ww:bg-background",children:[U(ne,{children:U(me,{messages:x.messages,status:x.status,welcomeMessage:l,resourceEndpoint:P,isDark:d,onFollowUp:R})}),U(se,{})]}),U(fe,{suggestions:I.suggestions,isLoading:I.isLoading,onSelect:k,className:"ww:border-t ww:border-border"}),U("div",{className:"ww:shrink-0 ww:border-t ww:border-border ww:bg-background",children:U(ae,{onSubmit:x.handleSubmit,globalDrop:c,multiple:c,className:i("ww:rounded-none ww:border-0"),children:ee("div",{className:"ww:flex ww:items-center ww:gap-1 ww:px-3 ww:py-2",children:[c&&U(le,{}),U(ie,{onChange:x.handleTextChange,value:x.text,placeholder:D,className:"ww:min-h-0 ww:py-1.5 ww:px-2"}),U(we,{status:x.status})]})})})]})});export{He as ChatBar,Ho as ChatCard,He as ChatWidget,ko as DARK_THEME,lt as DEFAULT_THEME,Ne as McpAppFrame,Z as mergeTheme,Q as themeToCSSProperties};
2
+ import{forwardRef as Jo,useCallback as Ie,useEffect as It,useImperativeHandle as Ko,useRef as kt,useState as ze}from"react";import{ArrowDownIcon as Ht}from"lucide-react";import{useCallback as Dt}from"react";import{StickToBottom as qe,useStickToBottomContext as Ft}from"use-stick-to-bottom";import{clsx as Rt}from"clsx";import{extendTailwindMerge as At}from"tailwind-merge";var Nt=At({prefix:"ww"});function a(...e){return Nt(Rt(e))}import{jsx as Lt}from"react/jsx-runtime";var q=({className:e,variant:t="default",size:o="default",type:n="button",...r})=>Lt("button",{type:n,className:a("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",o==="default"&&"ww:h-9 ww:px-4 ww:py-2 ww:text-sm",o==="sm"&&"ww:h-8 ww:px-3 ww:text-xs",o==="icon"&&"ww:size-9",o==="icon-sm"&&"ww:size-7",e),...r});import{jsx as ae}from"react/jsx-runtime";var ue=({className:e,...t})=>ae(qe,{className:a("ww:relative ww:flex-1 ww:overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),le=({className:e,...t})=>ae(qe.Content,{className:a("ww:flex ww:flex-col ww:gap-8 ww:p-4",e),...t}),we=({className:e,...t})=>{let{isAtBottom:o,scrollToBottom:n}=Ft(),r=Dt(()=>{n()},[n]);return!o&&ae(q,{className:a("ww:absolute ww:bottom-4 ww:left-[50%] ww:translate-x-[-50%] ww:rounded-full",e),onClick:r,size:"icon",variant:"outline",...t,children:ae(Ht,{className:"ww:size-4"})})};import{ArrowUpIcon as Bt,LoaderIcon as Ut,PaperclipIcon as Qt,SquareIcon as Ot,XIcon as zt}from"lucide-react";import{nanoid as Wt}from"nanoid";import{createContext as _t,useCallback as J,useContext as $t,useEffect as Re,useMemo as jt,useRef as Ae,useState as Ve}from"react";import{jsx as _,jsxs as Xe}from"react/jsx-runtime";var qt=async e=>{try{let o=await(await fetch(e)).blob();return new Promise(n=>{let r=new FileReader;r.onloadend=()=>n(r.result),r.onerror=()=>n(null),r.readAsDataURL(o)})}catch{return null}},Je=_t(null),Ke=()=>{let e=$t(Je);if(!e)throw new Error("usePromptInputAttachments must be used within a PromptInput");return e},ce=({className:e,accept:t,multiple:o,globalDrop:n,maxFiles:r,maxFileSize:i,onSubmit:u,children:l,...m})=>{let p=Ae(null),b=Ae(null),[f,g]=Ve([]),k=Ae(f);Re(()=>{k.current=f},[f]);let P=J(()=>{p.current?.click()},[]),E=J(s=>{let c=[...s];if(c.length===0)return;let h=A=>i?A.size<=i:!0,I=c.filter(h);g(A=>{let L=typeof r=="number"?Math.max(0,r-A.length):void 0,S=typeof L=="number"?I.slice(0,L):I;return[...A,...S.map(C=>({filename:C.name,id:Wt(),mediaType:C.type,type:"file",url:URL.createObjectURL(C)}))]})},[r,i]),d=J(s=>{g(c=>{let h=c.find(I=>I.id===s);return h?.url&&URL.revokeObjectURL(h.url),c.filter(I=>I.id!==s)})},[]),R=J(()=>{g(s=>{for(let c of s)c.url&&URL.revokeObjectURL(c.url);return[]})},[]);Re(()=>()=>{for(let s of k.current)s.url&&URL.revokeObjectURL(s.url)},[]);let B=J(s=>{s.currentTarget.files&&E(s.currentTarget.files),s.currentTarget.value=""},[E]);Re(()=>{if(!n)return;let s=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault()},c=h=>{h.dataTransfer?.types?.includes("Files")&&h.preventDefault(),h.dataTransfer?.files&&h.dataTransfer.files.length>0&&E(h.dataTransfer.files)};return document.addEventListener("dragover",s),document.addEventListener("drop",c),()=>{document.removeEventListener("dragover",s),document.removeEventListener("drop",c)}},[E,n]);let x=J(async s=>{s.preventDefault();let c=s.currentTarget,I=new FormData(c).get("message")||"";c.reset();let A=await Promise.all(f.map(async({id:L,...S})=>{if(S.url?.startsWith("blob:")){let C=await qt(S.url);return{...S,url:C??S.url}}return S}));try{let L=u({files:A,text:I},s);L instanceof Promise&&await L,R()}catch{}},[f,u,R]),w=jt(()=>({add:E,clear:R,files:f,openFileDialog:P,remove:d}),[f,E,d,R,P]);return Xe(Je.Provider,{value:w,children:[_("input",{accept:t,"aria-label":"Upload files",className:"ww:hidden",multiple:o,onChange:B,ref:p,title:"Upload files",type:"file"}),_("form",{className:a("ww:flex ww:w-full ww:flex-col ww:rounded-lg ww:border ww:border-border ww:bg-background",e),onSubmit:x,ref:b,...m,children:l})]})};var pe=({onChange:e,onKeyDown:t,className:o,placeholder:n="What would you like to know?",...r})=>{let i=Ke(),[u,l]=Ve(!1),m=J(b=>{if(t?.(b),!b.defaultPrevented){if(b.key==="Enter"){if(u||b.nativeEvent.isComposing||b.shiftKey)return;b.preventDefault();let{form:f}=b.currentTarget;if(f?.querySelector('button[type="submit"]')?.disabled)return;f?.requestSubmit()}if(b.key==="Backspace"&&b.currentTarget.value===""&&i.files.length>0){b.preventDefault();let f=i.files.at(-1);f&&i.remove(f.id)}}},[t,u,i]),p=J(b=>{let f=b.clipboardData?.items;if(!f)return;let g=[];for(let k of f)if(k.kind==="file"){let P=k.getAsFile();P&&g.push(P)}g.length>0&&(b.preventDefault(),i.add(g))},[i]);return _("textarea",{className:a("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",o),name:"message",onCompositionEnd:()=>l(!1),onCompositionStart:()=>l(!0),onKeyDown:m,onPaste:p,placeholder:n,onChange:e,...r})},de=({className:e,status:t,onStop:o,onClick:n,children:r,...i})=>{let u=t==="submitted"||t==="streaming",l=_(Bt,{className:"ww:size-4"});t==="submitted"?l=_(Ut,{className:"ww:size-4 ww:animate-spin"}):t==="streaming"&&(l=_(Ot,{className:"ww:size-4"}));let m=J(p=>{if(u&&o){p.preventDefault(),o();return}n?.(p)},[u,o,n]);return _(q,{"aria-label":u?"Stop":"Submit",className:a("ww:bg-foreground ww:text-background ww:hover:bg-foreground",e),onClick:m,size:"icon-sm",type:u&&o?"button":"submit",variant:"ghost",...i,children:r??l})},me=({className:e,children:t,...o})=>{let n=Ke();return n.files.length>0?Xe(q,{className:a("ww:group ww:relative",e),onClick:()=>n.clear(),size:"icon-sm",type:"button",variant:"ghost","aria-label":"Remove all attachments",...o,children:[_("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}),_(zt,{className:"ww:absolute ww:size-4 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100"})]}):_(q,{className:a(e),onClick:()=>n.openFileDialog(),size:"icon-sm",type:"button",variant:"ghost",...o,children:t??_(Qt,{className:"ww:size-4"})})};import{XIcon as Vt}from"lucide-react";import{memo as Jt,useCallback as Kt}from"react";import{jsx as ee}from"react/jsx-runtime";var Ge=({className:e,...t})=>ee("div",{className:a("ww:flex ww:flex-col ww:gap-1 ww:px-3 ww:py-2",e),...t}),Ye=({className:e,...t})=>ee("li",{className:a("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}),Ze=({className:e,...t})=>ee("span",{className:a("ww:inline-block ww:size-2 ww:shrink-0 ww:rounded-full ww:border ww:border-muted-foreground/50",e),...t}),et=({className:e,...t})=>ee("span",{className:a("ww:line-clamp-1 ww:grow ww:break-words ww:text-muted-foreground",e),...t}),tt=({className:e,...t})=>ee("div",{className:a("ww:flex ww:shrink-0 ww:gap-1 ww:opacity-0 ww:transition-opacity ww:group-hover:opacity-100",e),...t}),ot=({className:e,...t})=>ee(q,{className:a("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});import{jsx as Y,jsxs as Ne}from"react/jsx-runtime";var nt=Jt(({message:e,onRemove:t})=>{let o=Kt(()=>t(e.id),[t,e.id]);return Ne(Ye,{children:[Y(Ze,{}),Y(et,{children:e.text||"(attachment)"}),Y(tt,{children:Y(ot,{"aria-label":"Remove from queue",onClick:o,children:Y(Vt,{className:"ww:size-3"})})})]})});nt.displayName="ChatQueueItem";function fe({queuedMessages:e,onRemove:t,className:o}){return e.length===0?null:Ne(Ge,{className:a("ww:border-t ww:border-border",o),children:[Ne("div",{className:"ww:text-[11px] ww:font-medium ww:text-muted-foreground ww:px-2",children:[e.length," queued"]}),Y("ul",{children:e.map(n=>Y(nt,{message:n,onRemove:t},n.id))})]})}import{FileIcon as Xt}from"lucide-react";import{jsx as oe,jsxs as Yt}from"react/jsx-runtime";var rt=({files:e,className:t,...o})=>e.length===0?null:oe("div",{className:a("ww:flex ww:flex-wrap ww:gap-1.5",t),...o,children:e.map((n,r)=>oe(Gt,{file:n},r))});function Gt({file:e}){return e.mediaType?.startsWith("image/")&&e.url?oe("img",{src:e.url,alt:e.filename??"attachment",className:"ww:h-16 ww:max-w-32 ww:rounded ww:object-cover"}):Yt("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:[oe(Xt,{className:"ww:size-3 ww:shrink-0"}),oe("span",{className:"ww:max-w-24 ww:truncate",children:e.filename??"file"})]})}import{jsx as st}from"react/jsx-runtime";var Le=({className:e,size:t=5,...o})=>st("div",{className:a("ww:flex ww:items-center ww:gap-1",e),...o,children:[0,1,2].map(n=>st("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))});import{cjk as Zt}from"@streamdown/cjk";import{code as eo}from"@streamdown/code";import{memo as to}from"react";import{Streamdown as oo}from"streamdown";import{jsx as He}from"react/jsx-runtime";var ge=({className:e,from:t,...o})=>He("div",{className:a("ww:group ww:flex ww:w-full ww:max-w-[95%] ww:flex-col ww:gap-2",t==="user"?"is-user ww:ml-auto ww:justify-end":"is-assistant",e),...o}),he=({children:e,className:t,...o})=>He("div",{className:a("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),...o,children:e}),no={cjk:Zt,code:eo},be=to(({className:e,...t})=>He(oo,{className:a("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),plugins:no,...t}),(e,t)=>e.children===t.children);be.displayName="MessageResponse";import{jsx as ro}from"react/jsx-runtime";function it({className:e,text:t,...o}){return t?ro("pre",{className:a("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),...o,children:t}):null}import{BracesIcon as so,CheckIcon as io,ChevronDownIcon as ao,ChevronRightIcon as uo,ClipboardCopyIcon as lo,ServerIcon as Kn}from"lucide-react";import{createContext as wo,useCallback as co,useContext as ut,useEffect as po,useMemo as mo,useRef as fo,useState as De}from"react";import{Fragment as at,jsx as M,jsxs as X}from"react/jsx-runtime";function go(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 o=JSON.stringify(e);if(o.length<=t)return o;let n=Object.entries(e),r=[],i=t-2;for(let[u,l]of n){if(i<=8)break;let m=u.length>4?`${u.slice(0,4)}\u2026`:u,p;typeof l=="string"?p=l.length>2?`'${l.slice(0,1)}\u2026`:`'${l}'`:Array.isArray(l)?p=`Array(${l.length})`:typeof l=="object"&&l!==null?p="{\u2026}":p=String(l);let b=`${m}\u2009${p}`;r.push(b),i-=b.length+3}return`{${r.join(", ")}}`}function ho({text:e,className:t}){let[o,n]=De(!1),r=fo(null);po(()=>()=>{r.current&&clearTimeout(r.current)},[]);let i=co(async u=>{u.stopPropagation();try{await navigator.clipboard.writeText(e),n(!0),r.current&&clearTimeout(r.current),r.current=setTimeout(()=>n(!1),2e3)}catch{}},[e]);return M(q,{variant:"ghost",size:"sm",onClick:i,className:a("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:o?X(at,{children:[M(io,{className:"ww:size-3.5"}),M("span",{children:"Copied"})]}):X(at,{children:[M(lo,{className:"ww:size-3.5"}),M("span",{children:"Copy"})]})})}function lt({data:e,label:t,className:o,...n}){let[r,i]=De(!1),u=mo(()=>JSON.stringify(e,null,2),[e]),l=go(e);return X("div",{className:a("ww:rounded-lg ww:bg-tool-card",o),...n,children:[X("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[M("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),M(ho,{text:u})]}),X("button",{type:"button",onClick:()=>i(m=>!m),className:"ww:flex ww:w-full ww:items-start ww:gap-2 ww:px-3 ww:pb-3 ww:text-left",children:[M(uo,{className:a("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?M("pre",{className:"ww:overflow-x-auto ww:text-xs ww:font-mono ww:text-foreground ww:whitespace-pre-wrap ww:break-all",children:M("code",{children:u})}):M("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:l})]})]})}var Fe=wo({open:!1,toggle:()=>{}});function wt({className:e,defaultOpen:t=!1,children:o,...n}){let[r,i]=De(t);return M(Fe.Provider,{value:{open:r,toggle:()=>i(u=>!u)},children:M("div",{className:a("ww:mb-4 ww:w-full",e),"data-state":r?"open":"closed",...n,children:o})})}function ct({className:e,title:t,state:o,...n}){let{open:r,toggle:i}=ut(Fe),u=o==="input-available"||o==="input-streaming";return X("button",{type:"button",onClick:i,className:a("ww:flex ww:w-full ww:items-center ww:justify-between ww:gap-3 ww:py-1.5",e),"aria-expanded":r,...n,children:[X("div",{className:"ww:flex ww:min-w-0 ww:items-center ww:gap-2",children:[M(so,{className:"ww:size-4 ww:shrink-0 ww:text-muted-foreground"}),M("span",{className:"ww:truncate ww:text-sm ww:font-medium",children:t}),u&&M("span",{className:"ww:size-2 ww:shrink-0 ww:rounded-full ww:bg-primary ww:animate-pulse"})]}),M(ao,{className:a("ww:size-4 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-200",r&&"ww:rotate-180")})]})}function pt({className:e,children:t,...o}){let{open:n}=ut(Fe);return M("div",{className:a("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:M("div",{className:"ww:min-h-0 ww:overflow-hidden",children:M("div",{className:a("ww:mt-2 ww:space-y-3 ww:rounded-lg ww:border ww:border-border ww:bg-background ww:p-3",e),...o,children:t})})})}function dt({className:e,input:t,...o}){return M(lt,{data:t,label:"Request",className:e,...o})}function mt(e){if(typeof e!="object"||e===null)return;let t=e._meta;if(typeof t!="object"||t===null)return;let o=t.ui;if(!(typeof o!="object"||o===null))return o}function ft(e){let t=mt(e)?.resourceUri;return typeof t=="string"?t:void 0}function gt(e){return mt(e)?.autoHeight===!0}function ht({className:e,output:t,errorText:o,...n}){return t||o?o?X("div",{className:a("ww:space-y-2",e),...n,children:[M("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:"Error"}),M("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:o})]}):M(lt,{data:t,label:"Response",className:e,...n}):null}import{useCallback as bo,useEffect as bt,useMemo as xo,useRef as z,useState as xt}from"react";import{jsx as Io}from"react/jsx-runtime";var yo="/api/mcp/resource",Co=500,vo=0,To="2026-01-26",Po=300,Mo=3e3,Be=3;function Ue({resourceUri:e,toolInput:t,toolResult:o,resourceEndpoint:n=yo,isDark:r=!1,className:i,autoHeight:u=!0,onOpenLink:l,onFollowUp:m,onDisplayModeChange:p}){let b=z(null),f=z(t),g=z(o),k=z({width:0,height:0}),P=z(null),E=z(!1),d=z(0),R=z("inline"),[B,x]=xt(vo),[w,s]=xt(void 0),c=z(l),h=z(m),I=z(p);f.current=t,g.current=o,c.current=l,h.current=m,I.current=p;let A=bo(C=>u?Math.max(C,0):Math.min(Math.max(C,50),Co),[u]),L=xo(()=>`${n}?uri=${encodeURIComponent(e)}`,[n,e]),S=z(r);return S.current=r,bt(()=>{if(!E.current)return;let C=b.current;C?.contentWindow&&C.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:r?"dark":"light"}},"*")},[r]),bt(()=>{let C=b.current;if(!C)return;let W=!1,G=!1,v=(...H)=>console.debug("[McpAppFrame]",...H);v("effect mounted, waiting for handshake");let y=setTimeout(()=>{if(W||G)return;if(d.current>=Be){v("handshake failed after",Be,"retries, giving up");return}d.current+=1,v("handshake timeout, reloading iframe (retry",d.current,"of",Be,")");let H=new URL(C.src);H.searchParams.set("_retry",String(d.current)),C.src=H.toString()},Mo),T=H=>{v("\u2192 send",H.method??`response:${H.id}`,H),C.contentWindow?.postMessage(H,"*")},j=H=>{if(W||H.source!==C.contentWindow)return;let O=H.data;if(!O||typeof O!="object"||O.jsonrpc!=="2.0")return;let V=O.method,U=O.id;if(v("\u2190 recv",V??`response:${U}`,O),V==="ui/initialize"&&U!=null){G=!0,clearTimeout(y),v("handshake started"),T({jsonrpc:"2.0",id:U,result:{protocolVersion:O.params?.protocolVersion??To,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{}},hostContext:{theme:S.current?"dark":"light",displayMode:R.current}}});return}if(V==="ui/notifications/initialized"){v("handshake complete, sending tool data"),E.current=!0;let D=f.current,F=g.current;T({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:D}});let K=F.content??[{type:"text",text:JSON.stringify(F)}];T({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:K,structuredContent:F.structuredContent}});return}if(V==="ui/notifications/size-changed"){let D=O.params,F=typeof D?.height=="number"?D.height:void 0,K=typeof D?.width=="number"?D.width:void 0,Z=k.current,ke=F!==void 0&&F!==Z.height,Se=K!==void 0&&K!==Z.width;if(v("size-changed",{newHeight:F,newWidth:K,lastHeight:Z.height,lastWidth:Z.width,heightChanged:ke,widthChanged:Se}),!ke&&!Se)return;if(ke&&F!==void 0){Z.height=F;let Ee=A(F),je=C.getBoundingClientRect().height;if(P.current&&(P.current.cancel(),P.current=null),x(Ee),C.animate&&Math.abs(je-Ee)>2){let ie=C.animate([{height:`${je}px`},{height:`${Ee}px`}],{duration:Po,easing:"ease-out",fill:"forwards"});P.current=ie,ie.onfinish=()=>{P.current===ie&&(ie.cancel(),P.current=null)}}}Se&&u&&K!==void 0&&(Z.width=K,s(K));return}if(V==="ui/open-link"&&U!=null){let D=O.params?.url;typeof D=="string"&&(c.current?c.current(D):window.open(D,"_blank","noopener,noreferrer")),T({jsonrpc:"2.0",id:U,result:{}});return}if(V==="ui/message"&&U!=null){h.current&&O.params&&h.current(O.params),T({jsonrpc:"2.0",id:U,result:{}});return}if(V==="ui/request-display-mode"&&U!=null){let D=O.params?.mode,F=D==="fullscreen"||D==="inline"||D==="pip"?D:"inline";R.current=F,T({jsonrpc:"2.0",id:U,result:{mode:F}}),T({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:F}}),I.current?.(F);return}if(V==="ui/resource-teardown"&&U!=null){T({jsonrpc:"2.0",id:U,result:{}});return}V==="ping"&&U!=null&&T({jsonrpc:"2.0",id:U,result:{}})};return window.addEventListener("message",j),()=>{v("effect cleanup (disposed)"),W=!0,clearTimeout(y),window.removeEventListener("message",j)}},[u,A]),Io("iframe",{ref:b,src:L,sandbox:"allow-scripts allow-forms allow-same-origin",className:a("ww:rounded-md ww:border ww:border-border",i),style:{height:B,minWidth:w?`min(${w}px, 100%)`:void 0,width:"100%",border:"none",colorScheme:"auto"},title:"MCP App"})}import{Component as ko}from"react";import{jsx as yt,jsxs as So}from"react/jsx-runtime";var xe=class extends ko{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.warn("[WaniWani] Widget failed to render:",t.message)}render(){return this.state.hasError?So("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:[yt("span",{children:"Widget failed to load"}),yt("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}};import{Fragment as Ro,jsx as N,jsxs as te}from"react/jsx-runtime";function Eo(e){return e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase())}function ye({messages:e,status:t,welcomeMessage:o,resourceEndpoint:n,isDark:r,onFollowUp:i,onWidgetDisplayModeChange:u,fullscreenToolCallId:l}){let m=t==="submitted"||t==="streaming",p=e[e.length-1],b=e.length>0,f=m&&(!b||p.role==="user");return te(Ro,{children:[o&&!l&&N(ge,{from:"assistant",children:N(he,{children:N(be,{children:o})})}),e.map(g=>{let k=g.parts.filter(w=>w.type==="text"),P=g.parts.filter(w=>w.type==="reasoning"),E=g.parts.filter(w=>w.type==="file"),d=g.parts.filter(w=>"toolCallId"in w),R=g===p&&g.role==="assistant",B=k.length>0,x=l&&d.some(w=>w.toolCallId===l);return l&&!x?null:te(ge,{from:g.role,children:[P.map((w,s)=>N("div",{style:l?{display:"none"}:void 0,children:N(it,{text:w.text})},`reasoning-${g.id}-${s}`)),d.map(w=>{let s="output"in w?w.output:void 0,c=s!==void 0?ft(s):void 0,h=s!==void 0?gt(s):!1,I=w.toolCallId===l,A=l!=null&&!I;return te("div",{style:A?{display:"none"}:I?{height:"100%"}:void 0,children:[N("div",{style:I?{display:"none"}:void 0,children:te(wt,{defaultOpen:w.state==="output-available",children:[N(ct,{title:w.title??Eo(w.toolName),state:w.state}),te(pt,{children:[N(dt,{input:w.input}),s!==void 0&&N(ht,{output:s,errorText:"errorText"in w?w.errorText:void 0})]})]})}),c&&s!==void 0&&N(xe,{children:N(Ue,{resourceUri:c,toolInput:w.input??{},toolResult:{content:s.content,structuredContent:s.structuredContent},resourceEndpoint:n,isDark:r,autoHeight:h,onFollowUp:i,onDisplayModeChange:u?L=>u(L,{toolCallId:w.toolCallId,resourceUri:c,toolInput:w.input??{},toolResult:{content:s.content,structuredContent:s.structuredContent},autoHeight:h}):void 0})})]},w.toolCallId)}),N("div",{style:l?{display:"none"}:void 0,children:te(he,{children:[E.length>0&&N(rt,{files:E}),B?k.map((w,s)=>N(be,{children:w.type==="text"?w.text:""},`${g.id}-${s}`)):R&&m&&N(Le,{})]})})]},g.id)}),f&&!l&&N(ge,{from:"assistant",children:N(he,{children:N(Le,{})})})]})}import{jsx as Qe}from"react/jsx-runtime";function Ce({suggestions:e,isLoading:t,onSelect:o,className:n,...r}){return e.length===0&&!t?null:Qe("div",{className:a("ww:flex ww:flex-wrap ww:gap-2 ww:px-3 ww:py-2",n),...r,children:t?[0,1,2].map(i=>Qe("div",{className:"ww:h-7 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+i*20}px`}},i)):e.map((i,u)=>Qe("button",{type:"button",onClick:()=>o(i),className:a("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:`${u*50}ms`},children:i},i))})}import{useChat as Ao}from"@ai-sdk/react";import{DefaultChatTransport as No}from"ai";import{nanoid as Lo}from"nanoid";import{useCallback as Oe,useEffect as Ho,useRef as Do,useState as Ct}from"react";function ve(e){let{api:t="https://app.waniwani.ai/api/chat",headers:o,body:n,onMessageSent:r,onResponseReceived:i}=e,u=Do(new No({api:t,headers:{...o},body:n})),{messages:l,sendMessage:m,status:p}=Ao({transport:u.current,onFinish(){i?.()},onError(s){console.warn("[WaniWani] Chat error:",s.message)}}),[b,f]=Ct(""),[g,k]=Ct([]),P=p==="submitted"||p==="streaming",E=Oe(s=>{k(c=>c.filter(h=>h.id!==s))},[]),d=Oe(s=>{let c=!!s.text?.trim(),h=!!s.files?.length;if(c||h){if(P){k(I=>[...I,{id:Lo(),text:s.text||"",files:s.files??[]}]),f("");return}m({text:s.text||"",files:s.files}),r?.(s.text||""),f("")}},[m,r,P]);Ho(()=>{p==="ready"&&k(s=>{if(s.length===0)return s;let[c,...h]=s;return m({text:c.text,files:c.files.length>0?c.files:void 0}),r?.(c.text),h})},[p,m,r]);let R=Oe(s=>{f(s.target.value)},[]),B=l[l.length-1],x=l.length>0,w=P&&(!x||B.role==="user");return{messages:l,status:p,text:b,setText:f,handleSubmit:d,handleTextChange:R,isLoading:P,showLoaderBubble:w,lastMessage:B,hasMessages:x,sendMessage:m,queuedMessages:g,removeQueuedMessage:E}}import{useCallback as Fo,useEffect as vt,useRef as Bo,useState as Uo}from"react";function Qo(e){for(let t of e.parts){let o=t;if(o.type==="data"||o.type==="data-suggestions"){let n=o.data;if(n&&Array.isArray(n.suggestions))return n.suggestions}}return null}function Tt(e){return typeof e=="object"&&e!==null&&"initial"in e}function Te(e){let{messages:t,status:o,config:n}=e,[r,i]=Uo((Tt(n)&&n.initial?n.initial:[])??[]),u=Bo(o),l=n===!0||Tt(n)&&n.dynamic!==!1,m=Fo(()=>{i([])},[]),p=t[t.length-1];return vt(()=>{p?.role==="user"&&m()},[p,m]),vt(()=>{let b=u.current;if(u.current=o,b==="streaming"&&o==="ready"&&l){let f=[...t].reverse().find(k=>k.role==="assistant");if(!f)return;console.log("[WaniWani] Assistant parts:",f.parts);let g=Qo(f);console.log("[WaniWani] Extracted suggestions:",g),g&&i(g)}},[o,l,t]),{suggestions:r,isLoading:!1,clear:m}}import{useEffect as Oo,useRef as zo,useState as Wo}from"react";var _o=50,$o=30,jo=2e3,Pt=500;function Pe(e,t=!0){let[o,n]=Wo(""),r=zo(void 0);return Oo(()=>{if(!t){n("");return}let i=0,u=!1,l=!1,m=()=>{l||(u?(i--,n(e.slice(0,i)),i<=0?(u=!1,r.current=setTimeout(m,Pt)):r.current=setTimeout(m,$o)):(i++,n(e.slice(0,i)),i>=e.length?(u=!0,r.current=setTimeout(m,jo)):r.current=setTimeout(m,_o)))};return r.current=setTimeout(m,Pt),()=>{l=!0,clearTimeout(r.current)}},[e,t]),o}var Mt={primaryColor:"#6366f1",primaryForeground:"#1f2937",backgroundColor:"#ffffff",textColor:"#1f2937",mutedColor:"#6b7280",borderColor:"#e5e7eb",assistantBubbleColor:"#f3f4f6",userBubbleColor:"#f4f4f4",inputBackgroundColor:"#f9fafb",borderRadius:16,messageBorderRadius:12,fontFamily:"system-ui, -apple-system, 'Segoe UI', sans-serif",headerBackgroundColor:"#ffffff",headerTextColor:"#1f2937",statusColor:"#22c55e",toolCardColor:"#f4f4f5"},qo={backgroundColor:"#212121",headerBackgroundColor:"#1e1e1e",headerTextColor:"#ececec",textColor:"#ececec",primaryForeground:"#ffffff",mutedColor:"#8e8ea0",borderColor:"#444444",assistantBubbleColor:"#2f2f2f",userBubbleColor:"#303030",inputBackgroundColor:"#2f2f2f",primaryColor:"#6366f1",statusColor:"#22c55e",toolCardColor:"#262626"},Vo={primaryColor:["--ww-primary","--ww-color-primary"],primaryForeground:["--ww-primary-fg","--ww-color-primary-foreground"],backgroundColor:["--ww-bg","--ww-color-background"],textColor:["--ww-text","--ww-color-foreground","--ww-color-accent-foreground"],mutedColor:["--ww-muted","--ww-color-muted-foreground"],borderColor:["--ww-border","--ww-color-border"],assistantBubbleColor:["--ww-assistant-bubble","--ww-color-accent"],userBubbleColor:["--ww-user-bubble"],inputBackgroundColor:["--ww-input-bg","--ww-color-input"],borderRadius:["--ww-radius"],messageBorderRadius:["--ww-msg-radius"],fontFamily:["--ww-font"],headerBackgroundColor:["--ww-header-bg"],headerTextColor:["--ww-header-text"],statusColor:["--ww-status"],toolCardColor:["--ww-tool-card","--ww-color-tool-card"]};function ne(e){return{...Mt,...e}}function Me(e){let t=e.backgroundColor.replace("#",""),o=parseInt(t.substring(0,2),16),n=parseInt(t.substring(2,4),16),r=parseInt(t.substring(4,6),16);return(o*299+n*587+r*114)/1e3<128}function re(e){let t={};for(let[o,n]of Object.entries(Vo)){let r=e[o],i=typeof r=="number"?`${r}px`:String(r);for(let u of n)t[u]=i}return t}import{jsx as $,jsxs as We}from"react/jsx-runtime";var _e=Jo(function(t,o){let{theme:n,width:r=600,expandedHeight:i=400,allowAttachments:u=!1,welcomeMessage:l,placeholder:m="Ask me anything...",triggerEvent:p="triggerDemoRequest",resourceEndpoint:b,api:f}=t,g=b??(f?`${f}/resource`:void 0),k=ne(n),P=re(k),E=Me(k),d=ve(t),R=Te({messages:d.messages,status:d.status,config:t.suggestions}),B=Ie(y=>{let T=y.content.map(j=>j.text??"").join("").trim();T&&d.handleSubmit({text:T,files:[]})},[d.handleSubmit]),x=Ie(y=>{R.clear(),d.handleSubmit({text:y,files:[]})},[R.clear,d.handleSubmit]),w=Pe(m,!d.text),[s,c]=ze(!1),[h,I]=ze(!1),[A,L]=ze(null),S=kt(null),C=kt(void 0),W=Ie(()=>{let y=S.current;if(!y)return;y.scrollIntoView({behavior:"smooth",block:"center"});let T=y.querySelector("textarea");T&&setTimeout(()=>T.focus(),300),c(!0),I(!0),clearTimeout(C.current),C.current=setTimeout(()=>I(!1),2e3)},[]);Ko(o,()=>({sendMessage:y=>{d.handleSubmit({text:y,files:[]}),W()},focus:W}),[d.handleSubmit,W]),It(()=>{if(!p)return;let y=T=>{let j=T.detail,H=typeof j?.message=="string"?j.message:void 0;H&&d.handleSubmit({text:H,files:[]}),W()};return window.addEventListener(p,y),()=>window.removeEventListener(p,y)},[p,d.handleSubmit,W]);let G=s||A!==null;It(()=>{if(!s)return;let y=T=>{S.current&&!S.current.contains(T.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[s]);let v=Ie(()=>{c(!0)},[]);return We("div",{ref:S,style:{...P,width:r},"data-waniwani-chat":"","data-waniwani-layout":"bar",...E?{"data-waniwani-dark":""}:{},className:"ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground",children:[$("div",{className:a("ww:overflow-hidden ww:bg-background/80 ww:backdrop-blur-xl ww:transition-all ww:duration-300 ww:ease-out",G?"ww:opacity-100 ww:translate-y-0":"ww:opacity-0 ww:translate-y-2 ww:pointer-events-none ww:max-h-0"),style:{...G?{maxHeight:i}:void 0,maskImage:"linear-gradient(to bottom, transparent, black 24px, black calc(100% - 16px), transparent), linear-gradient(to right, transparent, black 16px, black calc(100% - 16px), transparent)",maskComposite:"intersect",WebkitMaskImage:"linear-gradient(to bottom, transparent, black 24px, black calc(100% - 16px), transparent), linear-gradient(to right, transparent, black 16px, black calc(100% - 16px), transparent)",WebkitMaskComposite:"source-in"},children:We(ue,{className:"ww:flex-1",style:{height:i},children:[$(le,{children:$(ye,{messages:d.messages,status:d.status,welcomeMessage:l,resourceEndpoint:g,isDark:E,onFollowUp:B,fullscreenToolCallId:A,onWidgetDisplayModeChange:(y,T)=>{L(y==="fullscreen"?T.toolCallId:null)}})}),!A&&$(we,{})]})}),$(Ce,{suggestions:R.suggestions,isLoading:R.isLoading,onSelect:x}),$(fe,{queuedMessages:d.queuedMessages,onRemove:d.removeQueuedMessage}),$("div",{className:"ww:shrink-0",children:$(ce,{onSubmit:d.handleSubmit,globalDrop:u,multiple:u,className:a("ww:rounded-[var(--ww-radius)] ww:shadow-sm ww:transition-all ww:duration-300 ww:ease-out",h&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background"),children:We("div",{className:"ww:flex ww:items-center ww:gap-1 ww:px-3 ww:py-2",children:[u&&$(me,{}),$(pe,{onChange:d.handleTextChange,value:d.text,placeholder:w,onFocus:v,className:"ww:min-h-0 ww:py-1.5 ww:px-2"}),$(de,{status:d.status})]})})})]})});import{forwardRef as Xo,useCallback as $e,useEffect as Go,useImperativeHandle as Yo,useRef as St,useState as Et}from"react";import{jsx as Q,jsxs as se}from"react/jsx-runtime";var Zo=Xo(function(t,o){let{theme:n,title:r="Assistant",subtitle:i,showStatus:u=!0,width:l=500,height:m=600,allowAttachments:p=!1,welcomeMessage:b,placeholder:f="Ask me anything...",triggerEvent:g="triggerDemoRequest",resourceEndpoint:k,api:P}=t,E=k??(P?`${P}/resource`:void 0),d=ne(n),R=re(d),B=Me(d),x=ve(t),w=Pe(f,!x.text),[s,c]=Et(!1),[h,I]=Et(null),A=St(null),L=St(void 0),S=$e(()=>{let v=A.current;if(!v)return;v.scrollIntoView({behavior:"smooth",block:"center"});let y=v.querySelector("textarea");y&&setTimeout(()=>y.focus(),300),c(!0),clearTimeout(L.current),L.current=setTimeout(()=>c(!1),2e3)},[]),C=Te({messages:x.messages,status:x.status,config:t.suggestions}),W=$e(v=>{let y=v.content.map(T=>T.text??"").join("").trim();y&&x.handleSubmit({text:y,files:[]})},[x.handleSubmit]),G=$e(v=>{C.clear(),x.handleSubmit({text:v,files:[]})},[C.clear,x.handleSubmit]);return Yo(o,()=>({sendMessage:v=>{x.handleSubmit({text:v,files:[]}),S()},focus:S}),[x.handleSubmit,S]),Go(()=>{if(!g)return;let v=y=>{let T=y.detail,j=typeof T?.message=="string"?T.message:void 0;j&&x.handleSubmit({text:j,files:[]}),S()};return window.addEventListener(g,v),()=>window.removeEventListener(g,v)},[g,x.handleSubmit,S]),se("div",{ref:A,style:{...R,width:l,height:m},"data-waniwani-chat":"","data-waniwani-layout":"card",...B?{"data-waniwani-dark":""}:{},className:a("ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground ww:bg-background ww:rounded-[var(--ww-radius)] ww:border ww:border-border ww:shadow-md ww:overflow-hidden ww:transition-shadow ww:duration-300",s&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background"),children:[se("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-3 ww:px-4 ww:py-2 ww:border-b ww:border-border",style:{backgroundColor:d.headerBackgroundColor,color:d.headerTextColor},children:[u&&Q("span",{className:"ww:size-2.5 ww:rounded-full ww:bg-status"}),se("div",{className:"ww:flex-1 ww:min-w-0",children:[Q("div",{className:"ww:text-xs ww:font-semibold ww:truncate",children:r}),i&&Q("div",{className:"ww:text-[11px] ww:text-muted-foreground ww:truncate",children:i})]})]}),se(ue,{className:"ww:flex-1 ww:min-h-0 ww:bg-background",children:[Q(le,{children:Q(ye,{messages:x.messages,status:x.status,welcomeMessage:b,resourceEndpoint:E,isDark:B,onFollowUp:W,fullscreenToolCallId:h,onWidgetDisplayModeChange:(v,y)=>{I(v==="fullscreen"?y.toolCallId:null)}})}),!h&&Q(we,{})]}),!h&&Q(Ce,{suggestions:C.suggestions,isLoading:C.isLoading,onSelect:G,className:"ww:border-t ww:border-border"}),!h&&Q(fe,{queuedMessages:x.queuedMessages,onRemove:x.removeQueuedMessage}),!h&&Q("div",{className:"ww:shrink-0 ww:border-t ww:border-border ww:bg-background",children:Q(ce,{onSubmit:x.handleSubmit,globalDrop:p,multiple:p,className:a("ww:rounded-none ww:border-0"),children:se("div",{className:"ww:flex ww:items-center ww:gap-1 ww:px-3 ww:py-2",children:[p&&Q(me,{}),Q(pe,{onChange:x.handleTextChange,value:x.text,placeholder:w,className:"ww:min-h-0 ww:py-1.5 ww:px-2"}),Q(de,{status:x.status})]})})})]})});export{_e as ChatBar,Zo as ChatCard,_e as ChatWidget,qo as DARK_THEME,Mt as DEFAULT_THEME,Ue as McpAppFrame,ne as mergeTheme,re as themeToCSSProperties};
3
3
  //# sourceMappingURL=index.js.map