@waniwani/sdk 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chat/embed.js +1 -1
- package/dist/chat/index.js +1 -1
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.js +4 -4
- package/dist/mcp/index.js.map +1 -1
- package/package.json +1 -1
package/dist/chat/embed.js
CHANGED
|
@@ -118,7 +118,7 @@ Please report this to https://github.com/markedjs/marked.`,e){let n="<p>An error
|
|
|
118
118
|
`)},PS=e=>{let t=!1;for(let n of e)if(n==="\\"||n==="|"){t=!0;break}if(!t)return e;let a=[];for(let n of e)n==="\\"?a.push("\\\\"):n==="|"?a.push("\\|"):a.push(n);return a.join("")},uK=e=>{let{headers:t,rows:a}=e;if(t.length===0)return"";let n=new Array(a.length+2),r=0,o=t.map(s=>PS(s));n[r]=`| ${o.join(" | ")} |`,r+=1;let i=new Array(t.length);for(let s=0;s<t.length;s+=1)i[s]="---";n[r]=`| ${i.join(" | ")} |`,r+=1;for(let s of a)if(s.length<t.length){let l=new Array(t.length);for(let u=0;u<t.length;u+=1)l[u]=u<s.length?PS(s[u]):"";n[r]=`| ${l.join(" | ")} |`,r+=1}else{let l=s.map(u=>PS(u));n[r]=`| ${l.join(" | ")} |`,r+=1}return n.join(`
|
|
119
119
|
`)},cK=({children:e,className:t,onCopy:a,onError:n,timeout:r=2e3})=>{let[o,i]=(0,N.useState)(!1),[s,l]=(0,N.useState)(!1),u=(0,N.useRef)(null),c=(0,N.useRef)(0),{isAnimating:d}=(0,N.useContext)(qa),p=async h=>{var v,I;if(typeof window>"u"||!((v=navigator?.clipboard)!=null&&v.write)){n?.(new Error("Clipboard API not available"));return}try{let y=(I=u.current)==null?void 0:I.closest('[data-streamdown="table-wrapper"]'),w=y?.querySelector("table");if(!w){n?.(new Error("Table not found"));return}let g=VN(w),S=h==="csv"?$N(g):lK(g),E=new ClipboardItem({"text/plain":new Blob([S],{type:"text/plain"}),"text/html":new Blob([w.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),l(!0),i(!1),a?.(h),c.current=window.setTimeout(()=>l(!1),r)}catch(y){n?.(y)}};(0,N.useEffect)(()=>{let h=v=>{let I=v.composedPath();u.current&&!I.includes(u.current)&&i(!1)};return document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h),window.clearTimeout(c.current)}},[]);let m=s?zS:FS;return(0,M.jsxs)("div",{className:"relative",ref:u,children:[(0,M.jsx)("button",{className:Ce("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>i(!o),title:"Copy table",type:"button",children:e??(0,M.jsx)(m,{size:14})}),o?(0,M.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,M.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),(0,M.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})},dK=({children:e,className:t,onDownload:a,onError:n})=>{let[r,o]=(0,N.useState)(!1),i=(0,N.useRef)(null),{isAnimating:s}=(0,N.useContext)(qa),l=u=>{var c;try{let d=(c=i.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),p=d?.querySelector("table");if(!p){n?.(new Error("Table not found"));return}let m=VN(p),h=u==="csv"?$N(m):uK(m);tu(`table.${u==="csv"?"csv":"md"}`,h,u==="csv"?"text/csv":"text/markdown"),o(!1),a?.(u)}catch(d){n?.(d)}};return(0,N.useEffect)(()=>{let u=c=>{let d=c.composedPath();i.current&&!d.includes(i.current)&&o(!1)};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u)}},[]),(0,M.jsxs)("div",{className:"relative",ref:i,children:[(0,M.jsx)("button",{className:Ce("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:s,onClick:()=>o(!r),title:"Download table",type:"button",children:e??(0,M.jsx)(Lh,{size:14})}),r?(0,M.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,M.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),(0,M.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})},fK=({children:e,className:t,showControls:a,...n})=>(0,M.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[a?(0,M.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,M.jsx)(cK,{}),(0,M.jsx)(dK,{})]}):null,(0,M.jsx)("div",{className:"overflow-x-auto",children:(0,M.jsx)("table",{className:Ce("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]}),pK=(0,N.lazy)(()=>Promise.resolve().then(()=>(MN(),AN)).then(e=>({default:e.CodeBlock}))),mK=(0,N.lazy)(()=>Promise.resolve().then(()=>(_N(),DN)).then(e=>({default:e.Mermaid}))),hK=/language-([^\s]+)/;BS=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,kh=(e,t)=>{if(typeof e=="boolean")return e;let a=e.mermaid;return a===!1?!1:a===!0||a===void 0?!0:a[t]!==!1},HS=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("ol",{className:Ce("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>Wt(e,t));HS.displayName="MarkdownOl";WN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("li",{className:Ce("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&Eh(e.node,t.node));WN.displayName="MarkdownLi";GN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("ul",{className:Ce("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>Wt(e,t));GN.displayName="MarkdownUl";XN=(0,N.memo)(({className:e,node:t,...a})=>(0,M.jsx)("hr",{className:Ce("my-6 border-border",e),"data-streamdown":"horizontal-rule",...a}),(e,t)=>Wt(e,t));XN.displayName="MarkdownHr";KN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("span",{className:Ce("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>Wt(e,t));KN.displayName="MarkdownStrong";gK=({children:e,className:t,href:a,node:n,...r})=>{let{linkSafety:o}=(0,N.useContext)(qa),[i,s]=(0,N.useState)(!1),l=a==="streamdown:incomplete-link",u=(0,N.useCallback)(async m=>{if(!(!(o!=null&&o.enabled&&a)||l)){if(m.preventDefault(),o.onLinkCheck&&await o.onLinkCheck(a)){window.open(a,"_blank","noreferrer");return}s(!0)}},[o,a,l]),c=(0,N.useCallback)(()=>{a&&window.open(a,"_blank","noreferrer")},[a]),d=(0,N.useCallback)(()=>{s(!1)},[]),p={url:a??"",isOpen:i,onClose:d,onConfirm:c};return o!=null&&o.enabled&&a?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("button",{className:Ce("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":l,"data-streamdown":"link",onClick:u,type:"button",children:e}),o.renderModal?o.renderModal(p):(0,M.jsx)(aK,{...p})]}):(0,M.jsx)("a",{className:Ce("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":l,"data-streamdown":"link",href:a,rel:"noreferrer",target:"_blank",...r,children:e})},YN=(0,N.memo)(gK,(e,t)=>Wt(e,t)&&e.href===t.href);YN.displayName="MarkdownA";ZN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h1",{className:Ce("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>Wt(e,t));ZN.displayName="MarkdownH1";JN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h2",{className:Ce("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>Wt(e,t));JN.displayName="MarkdownH2";QN=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h3",{className:Ce("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>Wt(e,t));QN.displayName="MarkdownH3";eU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h4",{className:Ce("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>Wt(e,t));eU.displayName="MarkdownH4";tU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h5",{className:Ce("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>Wt(e,t));tU.displayName="MarkdownH5";aU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("h6",{className:Ce("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>Wt(e,t));aU.displayName="MarkdownH6";nU=(0,N.memo)(({children:e,className:t,node:a,...n})=>{let{controls:r}=(0,N.useContext)(qa),o=BS(r,"table");return(0,M.jsx)(fK,{className:t,showControls:o,...n,children:e})},(e,t)=>Wt(e,t));nU.displayName="MarkdownTable";rU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("thead",{className:Ce("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>Wt(e,t));rU.displayName="MarkdownThead";oU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("tbody",{className:Ce("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>Wt(e,t));oU.displayName="MarkdownTbody";iU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("tr",{className:Ce("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>Wt(e,t));iU.displayName="MarkdownTr";sU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("th",{className:Ce("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>Wt(e,t));sU.displayName="MarkdownTh";lU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("td",{className:Ce("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>Wt(e,t));lU.displayName="MarkdownTd";uU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("blockquote",{className:Ce("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>Wt(e,t));uU.displayName="MarkdownBlockquote";cU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("sup",{className:Ce("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>Wt(e,t));cU.displayName="MarkdownSup";dU=(0,N.memo)(({children:e,className:t,node:a,...n})=>(0,M.jsx)("sub",{className:Ce("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>Wt(e,t));dU.displayName="MarkdownSub";fU=(0,N.memo)(({children:e,className:t,node:a,...n})=>{if("data-footnotes"in n){let r=i=>{var s,l;if(!(0,N.isValidElement)(i))return!1;let u=Array.isArray(i.props.children)?i.props.children:[i.props.children],c=!1,d=!1;for(let p of u)if(p){if(typeof p=="string")p.trim()!==""&&(c=!0);else if((0,N.isValidElement)(p))if(((s=p.props)==null?void 0:s["data-footnote-backref"])!==void 0)d=!0;else{let m=Array.isArray(p.props.children)?p.props.children:[p.props.children];for(let h of m){if(typeof h=="string"&&h.trim()!==""){c=!0;break}if((0,N.isValidElement)(h)&&((l=h.props)==null?void 0:l["data-footnote-backref"])===void 0){c=!0;break}}}}return d&&!c},o=Array.isArray(e)?e.map(i=>{if(!(0,N.isValidElement)(i))return i;if(i.type===HS){let s=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(l=>!r(l));return s.length===0?null:{...i,props:{...i.props,children:s}}}return i}):e;return(Array.isArray(o)?o.some(i=>i!==null):o!==null)?(0,M.jsx)("section",{className:t,...n,children:o}):null}return(0,M.jsx)("section",{className:t,...n,children:e})},(e,t)=>Wt(e,t));fU.displayName="MarkdownSection";yK=({node:e,className:t,children:a,...n})=>{var r,o,i;let s=((r=e?.position)==null?void 0:r.start.line)===((o=e?.position)==null?void 0:o.end.line),{mermaid:l,controls:u}=(0,N.useContext)(qa),c=qS();if(s)return(0,M.jsx)("code",{className:Ce("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:a});let d=t?.match(hK),p=(i=d?.at(1))!=null?i:"",m="";if((0,N.isValidElement)(a)&&a.props&&typeof a.props=="object"&&"children"in a.props&&typeof a.props.children=="string"?m=a.props.children:typeof a=="string"&&(m=a),p==="mermaid"&&c){let v=BS(u,"mermaid"),I=kh(u,"download"),y=kh(u,"copy"),w=kh(u,"fullscreen"),g=kh(u,"panZoom"),S=v&&(I||y||w);return(0,M.jsx)(N.Suspense,{fallback:(0,M.jsx)(UN,{}),children:(0,M.jsxs)("div",{className:Ce("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[S?(0,M.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[I?(0,M.jsx)(rK,{chart:m,config:l?.config}):null,y?(0,M.jsx)(ON,{code:m}):null,w?(0,M.jsx)(sK,{chart:m,config:l?.config}):null]}):null,(0,M.jsx)(mK,{chart:m,config:l?.config,showControls:g})]})})}let h=BS(u,"code");return(0,M.jsx)(N.Suspense,{fallback:(0,M.jsx)(UN,{}),children:(0,M.jsx)(pK,{className:Ce("overflow-x-auto border-border border-t",t),code:m,language:p,children:h?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(ZX,{code:m,language:p}),(0,M.jsx)(ON,{})]}):null})})},pU=(0,N.memo)(yK,(e,t)=>e.className===t.className&&Eh(e.node,t.node));pU.displayName="MarkdownCode";mU=(0,N.memo)(QX,(e,t)=>e.className===t.className&&Eh(e.node,t.node));mU.displayName="MarkdownImg";hU=(0,N.memo)(({children:e,className:t,node:a,...n})=>{var r,o;let i=(Array.isArray(e)?e:[e]).filter(s=>s!=null&&s!=="");if(i.length===1&&(0,N.isValidElement)(i[0])){let s=i[0].props.node,l=s?.tagName;if(l==="img")return(0,M.jsx)(M.Fragment,{children:e});if(l==="code"&&((r=s?.position)==null?void 0:r.start.line)!==((o=s?.position)==null?void 0:o.end.line))return(0,M.jsx)(M.Fragment,{children:e})}return(0,M.jsx)("p",{className:t,...n,children:e})},(e,t)=>Wt(e,t));hU.displayName="MarkdownParagraph";wK={ol:HS,li:WN,ul:GN,hr:XN,strong:KN,a:YN,h1:ZN,h2:JN,h3:QN,h4:eU,h5:tU,h6:aU,table:nU,thead:rU,tbody:oU,tr:iU,th:sU,td:lU,blockquote:uU,code:pU,img:mU,pre:({children:e})=>e,sup:cU,sub:dU,p:hU,section:fU},BN=[],zN={allowDangerousHtml:!0},Th=new WeakMap,vK=class{constructor(){this.cache=new Map,this.keyCache=new WeakMap,this.maxSize=100}generateCacheKey(e){let t=this.keyCache.get(e);if(t)return t;let a=e.rehypePlugins,n=e.remarkPlugins,r=e.remarkRehypeOptions;if(!(a||n||r)){let c="default";return this.keyCache.set(e,c),c}let o=c=>{if(!c||c.length===0)return"";let d="";for(let p=0;p<c.length;p+=1){let m=c[p];if(p>0&&(d+=","),Array.isArray(m)){let[h,v]=m;if(typeof h=="function"){let I=Th.get(h);I||(I=h.name,Th.set(h,I)),d+=I}else d+=String(h);d+=":",d+=JSON.stringify(v)}else if(typeof m=="function"){let h=Th.get(m);h||(h=m.name,Th.set(m,h)),d+=h}else d+=String(m)}return d},i=o(a),s=o(n),l=r?JSON.stringify(r):"",u=`${s}::${i}::${l}`;return this.keyCache.set(e,u),u}get(e){let t=this.generateCacheKey(e),a=this.cache.get(t);return a&&(this.cache.delete(t),this.cache.set(t,a)),a}set(e,t){let a=this.generateCacheKey(e);if(this.cache.size>=this.maxSize){let n=this.cache.keys().next().value;n&&this.cache.delete(n)}this.cache.set(a,t)}clear(){this.cache.clear()}},FN=new vK,gU=e=>{let t=xK(e),a=e.children||"";return SK(t.runSync(t.parse(a),a),e)},xK=e=>{let t=FN.get(e);if(t)return t;let a=bK(e);return FN.set(e,a),a},bK=e=>{let t=e.rehypePlugins||BN,a=e.remarkPlugins||BN,n=e.remarkRehypeOptions?{...zN,...e.remarkRehypeOptions}:zN;return vS().use(uh).use(a).use(ph,n).use(t)},SK=(e,t)=>Jb(e,{Fragment:M.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:M.jsx,jsxs:M.jsxs,passKeys:!0,passNode:!0}),IK=/\[\^[^\]\s]{1,200}\](?!:)/,CK=/\[\^[^\]\s]{1,200}\]:/,kK=/<\/(\w+)>/,TK=/<(\w+)[\s>]/,OS=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
120
120
|
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},LK=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
121
|
-
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},NS=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},yU=e=>{let t=IK.test(e),a=CK.test(e);if(t||a)return[e];let n=Sn.lex(e,{gfm:!0}),r=[],o=[];for(let i of n){let s=i.raw,l=r.length;if(o.length>0){if(r[l-1]+=s,i.type==="html"){let u=s.match(kK);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(i.type==="html"&&i.block){let u=s.match(TK);if(u){let c=u[1];s.includes(`</${c}>`)||o.push(c)}}if(s.trim()==="$$"&&l>0){let u=r[l-1],c=OS(u),d=NS(u);if(c&&d%2===1){r[l-1]=u+s;continue}}if(l>0&&LK(s)){let u=r[l-1],c=OS(u),d=NS(u),p=NS(s);if(c&&d%2===1&&!OS(s)&&p===1){r[l-1]=u+s;continue}}r.push(s)}return r},wU={raw:ZM,sanitize:[Am,{}],harden:[KM,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},vU={gfm:[eh,{}]},EK=Object.values(wU),AK=Object.values(vU),MK={block:" \u258B",circle:" \u25CF"},RK={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},qa=(0,N.createContext)(RK),jS=(0,N.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...n})=>(0,M.jsx)(gU,{...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,i;return((o=e.components)==null?void 0:o[r])!==((i=t.components)==null?void 0:i[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});jS.displayName="Block";DK=["github-light","github-dark"],au=(0,N.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:n,rehypePlugins:r=EK,remarkPlugins:o=AK,className:i,shikiTheme:s=DK,mermaid:l,controls:u=!0,isAnimating:c=!1,BlockComponent:d=jS,parseMarkdownIntoBlocksFn:p=yU,caret:m,plugins:h,remend:v,linkSafety:I={enabled:!0},...y})=>{let w=(0,N.useId)(),[g,S]=(0,N.useTransition)(),E=(0,N.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?u_(e,v):e,[e,t,a,v]),T=(0,N.useMemo)(()=>p(E),[E,p]),[R,O]=(0,N.useState)(T);(0,N.useEffect)(()=>{t==="streaming"?S(()=>{O(T)}):O(T)},[T,t]);let U=t==="streaming"?R:T,A=(0,N.useMemo)(()=>U.map((B,P)=>`${w}-${P}`),[U.length,w]),Q=(0,N.useMemo)(()=>{var B,P;return{shikiTheme:(P=(B=h?.code)==null?void 0:B.getThemes())!=null?P:s,controls:u,isAnimating:c,mode:t,mermaid:l,linkSafety:I}},[s,u,c,t,l,I,h?.code]),$=(0,N.useMemo)(()=>({...wK,...n}),[n]),H=(0,N.useMemo)(()=>{let B=[];return h!=null&&h.cjk&&(B=[...B,...h.cjk.remarkPluginsBefore]),B=[...B,...o],h!=null&&h.cjk&&(B=[...B,...h.cjk.remarkPluginsAfter]),h!=null&&h.math&&(B=[...B,h.math.remarkPlugin]),B},[o,h?.math,h?.cjk]),Z=(0,N.useMemo)(()=>h!=null&&h.math?[...r,h.math.rehypePlugin]:r,[r,h?.math]),X=(0,N.useMemo)(()=>m&&c?{"--streamdown-caret":`"${MK[m]}"`}:void 0,[m,c]);return t==="static"?(0,M.jsx)(US.Provider,{value:h??null,children:(0,M.jsx)(qa.Provider,{value:Q,children:(0,M.jsx)("div",{className:Ce("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",i),children:(0,M.jsx)(gU,{components:$,rehypePlugins:Z,remarkPlugins:H,...y,children:e})})})}):(0,M.jsx)(US.Provider,{value:h??null,children:(0,M.jsx)(qa.Provider,{value:Q,children:(0,M.jsxs)("div",{className:Ce("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,i),style:X,children:[U.length===0&&m&&c&&(0,M.jsx)("span",{}),U.map((B,P)=>(0,M.jsx)(d,{components:$,content:B,index:P,rehypePlugins:Z,remarkPlugins:H,shouldParseIncompleteMarkdown:a,...y},A[P]))]})})})},(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);au.displayName="Streamdown";_K=({children:e,className:t,minZoom:a=.5,maxZoom:n=3,zoomStep:r=.1,showControls:o=!0,initialZoom:i=1,fullscreen:s=!1})=>{let l=(0,N.useRef)(null),u=(0,N.useRef)(null),[c,d]=(0,N.useState)(i),[p,m]=(0,N.useState)({x:0,y:0}),[h,v]=(0,N.useState)(!1),[I,y]=(0,N.useState)({x:0,y:0}),[w,g]=(0,N.useState)({x:0,y:0}),S=(0,N.useCallback)($=>{d(H=>Math.max(a,Math.min(n,H+$)))},[a,n]),E=(0,N.useCallback)(()=>{S(r)},[S,r]),T=(0,N.useCallback)(()=>{S(-r)},[S,r]),R=(0,N.useCallback)(()=>{d(i),m({x:0,y:0})},[i]),O=(0,N.useCallback)($=>{$.preventDefault();let H=$.deltaY>0?-r:r;S(H)},[S,r]),U=(0,N.useCallback)($=>{if($.button!==0||$.isPrimary===!1)return;v(!0),y({x:$.clientX,y:$.clientY}),g(p);let H=$.currentTarget;H instanceof HTMLElement&&H.setPointerCapture($.pointerId)},[p]),A=(0,N.useCallback)($=>{if(!h)return;$.preventDefault();let H=$.clientX-I.x,Z=$.clientY-I.y;m({x:w.x+H,y:w.y+Z})},[h,I,w]),Q=(0,N.useCallback)($=>{v(!1);let H=$.currentTarget;H instanceof HTMLElement&&H.releasePointerCapture($.pointerId)},[]);return(0,N.useEffect)(()=>{let $=l.current;if($)return $.addEventListener("wheel",O,{passive:!1}),()=>{$.removeEventListener("wheel",O)}},[O]),(0,N.useEffect)(()=>{let $=u.current;if($&&h)return document.body.style.userSelect="none",$.addEventListener("pointermove",A,{passive:!1}),$.addEventListener("pointerup",Q),$.addEventListener("pointercancel",Q),()=>{document.body.style.userSelect="",$.removeEventListener("pointermove",A),$.removeEventListener("pointerup",Q),$.removeEventListener("pointercancel",Q)}},[h,A,Q]),(0,M.jsxs)("div",{className:Ce("relative flex flex-col",s?"h-full w-full":"min-h-28 w-full",t),ref:l,style:{cursor:h?"grabbing":"grab"},children:[o?(0,M.jsxs)("div",{className:Ce("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",s?"bottom-4 left-4":"bottom-2 left-2"),children:[(0,M.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:E,title:"Zoom in",type:"button",children:(0,M.jsx)(KX,{size:16})}),(0,M.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:T,title:"Zoom out",type:"button",children:(0,M.jsx)(YX,{size:16})}),(0,M.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:R,title:"Reset zoom and pan",type:"button",children:(0,M.jsx)(XX,{size:16})})]}):null,(0,M.jsx)("div",{className:Ce("flex-1 origin-center transition-transform duration-150 ease-out",s?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:U,ref:u,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},_S=({chart:e,className:t,config:a,fullscreen:n=!1,showControls:r=!0})=>{let[o,i]=(0,N.useState)(null),[s,l]=(0,N.useState)(!1),[u,c]=(0,N.useState)(""),[d,p]=(0,N.useState)(""),[m,h]=(0,N.useState)(0),{mermaid:v}=(0,N.useContext)(qa),I=qS(),y=v?.errorComponent,{shouldRender:w,containerRef:g}=$X({immediate:n});if((0,N.useEffect)(()=>{if(w){if(!I){i("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{i(null),l(!0);let E=I.getMermaid(a),T=e.split("").reduce((U,A)=>(U<<5)-U+A.charCodeAt(0)|0,0),R=`mermaid-${Math.abs(T)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:O}=await E.render(R,e);c(O),p(O)}catch(E){if(!(d||u)){let T=E instanceof Error?E.message:"Failed to render Mermaid chart";i(T)}}finally{l(!1)}})()}},[e,a,m,w,I]),!(w||u||d))return(0,M.jsx)("div",{className:Ce("my-4 min-h-[200px]",t),ref:g});if(s&&!u&&!d)return(0,M.jsx)("div",{className:Ce("my-4 flex justify-center p-4",t),ref:g,children:(0,M.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,M.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,M.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return y?(0,M.jsx)("div",{ref:g,children:(0,M.jsx)(y,{chart:e,error:o,retry:()=>h(T=>T+1)})}):(0,M.jsxs)("div",{className:Ce("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:g,children:[(0,M.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,M.jsxs)("details",{className:"mt-2",children:[(0,M.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,M.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let S=u||d;return(0,M.jsx)("div",{className:Ce("size-full",t),"data-streamdown":"mermaid",ref:g,children:(0,M.jsx)(_K,{className:Ce(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:(0,M.jsx)("div",{"aria-label":"Mermaid chart",className:Ce("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:S},role:"img"})})})}});var lB=Ca((Xve,sB)=>{"use strict";function cY(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 i=Date.now(),s=i-n,l=t-s;l<=0?(n=i,e.apply(this,o)):a=setTimeout(()=>{n=Date.now(),e.apply(this,o)},l)}}sB.exports=cY});var xI=typeof performance>"u"?0:performance.now(),bI=typeof window<"u"&&!!window.WaniWani?.chat;var Cs=j(Ee(),1),Zh=j(qw(),1);var Hw="waniwani/suggestions";function yl(e,t){for(let a of t){let n=e[a];if(typeof n=="string"&&n.length>0)return n}}var hq=["waniwani/sessionId","openai/sessionId","openai/session","sessionId","conversationId","mcp-session-id"],gq=["waniwani/requestId","openai/requestId","requestId","mcp/requestId"],yq=["waniwani/traceId","openai/traceId","traceId","mcp/traceId","openai/requestId","requestId"],wq=["waniwani/userId","openai/userId","externalUserId","userId","actorId"],vq=["waniwani/visitorId","visitorId"],xq=["correlationId","openai/requestId"];function c1(e){return e?yl(e,hq):void 0}function d1(e){return e?yl(e,gq):void 0}function f1(e){return e?yl(e,yq):void 0}function p1(e){return e?yl(e,wq):void 0}function m1(e){return e?yl(e,vq):void 0}function h1(e){return e?yl(e,xq):void 0}var bq=[{key:"openai/sessionId",source:"chatgpt"},{key:"openai/session",source:"chatgpt"}],Sq=[{needle:"claude",source:"claude"},{needle:"chatgpt",source:"chatgpt"},{needle:"openai",source:"chatgpt"},{needle:"gemini",source:"gemini"}];function g1(e,t){if(e){let n=e["waniwani/source"];if(typeof n=="string"&&n.length>0)return n;for(let{key:r,source:o}of bq){let i=e[r];if(typeof i=="string"&&i.length>0)return o}}let a=t?.name;if(typeof a=="string"&&a.length>0){let n=a.toLowerCase();for(let{needle:r,source:o}of Sq)if(n.includes(r))return o}}var Iq="@waniwani/sdk";function y1(e,t={}){let a=t.now??(()=>new Date),n=t.generateId??Cq,r=Lq(e),o=zp(e.meta),i=zp(e.metadata),s=Eq(e,o),l=Xn(e.eventId)??n(),u=Aq(e.timestamp,a),c=Xn(e.source)??g1(o)??t.source??Iq,d=jw(e)?{...e}:void 0,p={...i};return Object.keys(o).length>0&&(p.meta=o),d&&(p.rawLegacy=d),{id:l,type:"mcp.event",name:r,source:c,timestamp:u,correlation:s,properties:kq(e,r),metadata:p,rawLegacy:d}}function Cq(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`evt_${crypto.randomUUID()}`:`evt_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function kq(e,t){if(!jw(e))return zp(e.properties);let a=Tq(e,t),n=zp(e.properties);return{...a,...n}}function Tq(e,t){switch(t){case"tool.called":{let a={};return Xn(e.toolName)&&(a.name=e.toolName),Xn(e.toolType)&&(a.type=e.toolType),a}case"link.clicked":{let a={};return Xn(e.linkUrl)&&(a.url=e.linkUrl),a}default:return{}}}function Lq(e){return jw(e)?e.eventType:e.event}function Eq(e,t){let a=Xn(e.requestId)??d1(t),n=Xn(e.sessionId)??c1(t),r=Xn(e.traceId)??f1(t),o=Xn(e.externalUserId)??p1(t),i=Xn(e.visitorId)??m1(t),s=Xn(e.correlationId)??h1(t)??a,l={};return n&&(l.sessionId=n),r&&(l.traceId=r),a&&(l.requestId=a),s&&(l.correlationId=s),o&&(l.externalUserId=o),i&&(l.visitorId=i),l}function Aq(e,t){if(e instanceof Date)return e.toISOString();if(typeof e=="string"){let a=new Date(e);if(!Number.isNaN(a.getTime()))return a.toISOString()}return t().toISOString()}function zp(e){return!e||typeof e!="object"||Array.isArray(e)?{}:e}function Xn(e){if(typeof e=="string"&&e.trim().length!==0)return e}function jw(e){return"eventType"in e}function w1(e){return{priceShown:({amount:t,currency:a,itemId:n,label:r,...o})=>e({event:"price_shown",properties:{amount:t,currency:a,itemId:n,label:r},...o}),pricesCompared:({options:t,...a})=>e({event:"prices_compared",properties:{options:t},...a}),optionSelected:({id:t,amount:a,currency:n,...r})=>e({event:"option_selected",properties:{id:t,amount:a,currency:n},...r}),leadQualified:t=>{let{externalId:a,email:n,name:r,...o}=t??{};return e({event:"lead_qualified",properties:{externalId:a,email:n,name:r},...o})},converted:({amount:t,currency:a,occurredAt:n,...r})=>e({event:"converted",properties:{amount:t,currency:a,occurredAt:n},...r})}}var Mq="/api/mcp/events/v2/batch";var v1="@waniwani/sdk";var Rq=new Set([401,403]),Dq=new Set([408,425,429,500,502,503,504]),_q=(e,t)=>globalThis.fetch(e,t);function x1(e){return new Vw(e)}var Vw=class{constructor(t){K(this,"endpointUrl");K(this,"flushIntervalMs");K(this,"maxBatchSize");K(this,"maxBufferSize");K(this,"maxRetries");K(this,"retryBaseDelayMs");K(this,"retryMaxDelayMs");K(this,"shutdownTimeoutMs");K(this,"sdkVersion");K(this,"fetchFn");K(this,"logger");K(this,"now");K(this,"sleep");K(this,"apiKey");K(this,"buffer",[]);K(this,"flushTimer");K(this,"flushScheduled",!1);K(this,"flushScheduledTimer");K(this,"flushInFlight");K(this,"inFlightCount",0);K(this,"isStopped",!1);K(this,"isShuttingDown",!1);this.endpointUrl=Nq(t.apiUrl,t.endpointPath??Mq),this.flushIntervalMs=t.flushIntervalMs??1e3,this.maxBatchSize=t.maxBatchSize??20,this.maxBufferSize=t.maxBufferSize??1e3,this.maxRetries=t.maxRetries??3,this.retryBaseDelayMs=t.retryBaseDelayMs??200,this.retryMaxDelayMs=t.retryMaxDelayMs??2e3,this.shutdownTimeoutMs=t.shutdownTimeoutMs??2e3,this.fetchFn=t.fetchFn??_q,this.logger=t.logger??console,this.now=t.now??(()=>new Date),this.sleep=t.sleep??(a=>new Promise(n=>setTimeout(n,a))),this.apiKey=t.apiKey,this.sdkVersion=t.sdkVersion,this.flushIntervalMs>0&&(this.flushTimer=setInterval(()=>{this.flush()},this.flushIntervalMs)),this.registerBrowserTeardown()}enqueue(t){if(this.isStopped||this.isShuttingDown){this.logger.warn("[Waniwani] Tracking transport is stopped, dropping event %s",t.id);return}if(this.buffer.length>=this.maxBufferSize){let a=this.buffer.length-this.maxBufferSize+1;this.buffer.splice(0,a),this.logger.warn("[Waniwani] Tracking buffer overflow, dropped %d oldest event(s)",a)}if(this.buffer.push(t),this.buffer.length>=this.maxBatchSize){this.flush();return}this.scheduleMicroFlush()}pendingEvents(){return this.buffer.length+this.inFlightCount}async flush(){return this.flushInFlight?this.flushInFlight:(this.flushInFlight=this.flushLoop().finally(()=>{this.flushInFlight=void 0}),this.flushInFlight)}async shutdown(t){this.isShuttingDown=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=void 0),this.flushScheduledTimer&&(clearTimeout(this.flushScheduledTimer),this.flushScheduledTimer=void 0,this.flushScheduled=!1);let a=t?.timeoutMs??this.shutdownTimeoutMs,n=this.flush();if(!Number.isFinite(a)||a<=0)return await n,this.isStopped=!0,{timedOut:!1,pendingEvents:this.pendingEvents()};let r=Symbol("shutdown-timeout");return await Promise.race([n.then(()=>"flushed"),this.sleep(a).then(()=>r)])===r?(this.isStopped=!0,{timedOut:!0,pendingEvents:this.pendingEvents()}):(this.isStopped=!0,{timedOut:!1,pendingEvents:this.pendingEvents()})}registerBrowserTeardown(){if(typeof document>"u"||typeof window>"u")return;let t=()=>{document.visibilityState==="hidden"&&this.keepaliveFlush()};document.addEventListener("visibilitychange",t),window.addEventListener("pagehide",()=>this.keepaliveFlush())}keepaliveFlush(){if(this.isStopped||this.buffer.length===0)return;let t=this.buffer.splice(0,this.buffer.length);this.sendKeepaliveChunk(t)}sendKeepaliveChunk(t){let a=JSON.stringify(this.makeBatchRequest(t));if(a.length>6e4&&t.length>1){let n=Math.ceil(t.length/2);this.sendKeepaliveChunk(t.slice(0,n)),this.sendKeepaliveChunk(t.slice(n));return}try{this.fetchFn(this.endpointUrl,{method:"POST",headers:this.requestHeaders(),body:a,keepalive:!0}).catch(()=>{})}catch{}}requestHeaders(){let t={"Content-Type":"application/json","X-WaniWani-SDK":v1};return this.apiKey&&(t.Authorization=`Bearer ${this.apiKey}`),t}scheduleMicroFlush(){this.flushScheduled||(this.flushScheduled=!0,this.flushScheduledTimer=setTimeout(()=>{this.flushScheduledTimer=void 0,this.flushScheduled=!1,this.flush()},0))}async flushLoop(){for(;this.buffer.length>0&&!this.isStopped;){let t=this.buffer.splice(0,this.maxBatchSize);await this.sendBatchWithRetry(t)}}async sendBatchWithRetry(t){let a=0,n=t;for(;n.length>0&&!this.isStopped;){this.inFlightCount=n.length;let r=await this.sendBatchOnce(n);switch(this.inFlightCount=0,r.kind){case"success":return;case"auth":this.stopTransportForAuthFailure(r.status,n.length);return;case"permanent":this.logger.error("[Waniwani] Dropping %d event(s) after permanent failure: %s",n.length,r.reason);return;case"retryable":if(a>=this.maxRetries){this.logger.error("[Waniwani] Dropping %d event(s) after retry exhaustion: %s",n.length,r.reason);return}await this.sleep(this.backoffDelayMs(a)),a+=1;continue;case"partial":if(r.permanent.length>0&&this.logger.error("[Waniwani] Dropping %d event(s) rejected as permanent",r.permanent.length),r.retryable.length===0)return;if(a>=this.maxRetries){this.logger.error("[Waniwani] Dropping %d retryable event(s) after retry exhaustion",r.retryable.length);return}n=r.retryable,await this.sleep(this.backoffDelayMs(a)),a+=1;continue}}}async sendBatchOnce(t){let a;try{a=await this.fetchFn(this.endpointUrl,{method:"POST",headers:this.requestHeaders(),body:JSON.stringify(this.makeBatchRequest(t))})}catch(o){return{kind:"retryable",reason:Uq(o)}}if(Rq.has(a.status))return{kind:"auth",status:a.status};if(Dq.has(a.status))return{kind:"retryable",reason:`HTTP ${a.status}`};if(!a.ok)return{kind:"permanent",reason:`HTTP ${a.status}`};let n=await Oq(a);if(!n?.rejected||n.rejected.length===0)return{kind:"success"};let r=this.classifyRejectedEvents(t,n.rejected);return r.retryable.length===0&&r.permanent.length===0?{kind:"success"}:{kind:"partial",retryable:r.retryable,permanent:r.permanent}}makeBatchRequest(t){return{sentAt:this.now().toISOString(),source:{sdk:v1,version:this.sdkVersion??"0.0.0"},events:t}}classifyRejectedEvents(t,a){let n=new Map(t.map(i=>[i.id,i])),r=[],o=[];for(let i of a){let s=n.get(i.eventId);if(s){if(Pq(i)){r.push(s);continue}o.push(s)}}return{retryable:r,permanent:o}}backoffDelayMs(t){let a=this.retryBaseDelayMs*2**t;return Math.min(a,this.retryMaxDelayMs)}stopTransportForAuthFailure(t,a){this.isStopped=!0;let n=this.buffer.length;this.buffer.splice(0,n),this.logger.error("[Waniwani] Auth failure (HTTP %d). Stopping tracking transport and dropping %d queued event(s)",t,a+n)}};function Pq(e){if(e.retryable===!0)return!0;let t=e.code.toLowerCase();return t.includes("timeout")||t.includes("temporary")||t.includes("unavailable")||t.includes("rate_limit")||t.includes("transient")||t.includes("server")}async function Oq(e){let t=await e.text();if(t)try{return JSON.parse(t)}catch{return}}function Nq(e,t){let a=e.endsWith("/")?e:`${e}/`,n=t.startsWith("/")?t.slice(1):t;return`${a}${n}`}function Uq(e){return e instanceof Error?e.message:String(e)}function b1(e){let{apiUrl:t,endpointPath:a}=Bq(e.endpoint),n=x1({apiUrl:t,apiKey:e.token,endpointPath:a,flushIntervalMs:e.flushIntervalMs}),r,o=s=>typeof s=="function"?s():s,i=async s=>{let l=e.identity?.()??{},u=o(e.channelId),c=u===void 0?s.properties:{channelId:u,...s.properties},d=y1({sessionId:l.sessionId,visitorId:l.visitorId,externalUserId:l.externalUserId??r,traceId:l.traceId,...s,properties:c,metadata:{...e.metadata,...s.metadata}},{source:o(e.source)});return n.enqueue(d),{eventId:d.id}};return{track:Object.assign(i,w1(i)),identify(s,l){return r=s,i({event:"user.identified",externalUserId:s,properties:l})},flush:()=>n.flush(),shutdown:s=>n.shutdown(s)}}function Bq(e){let t=new URL(e);return{apiUrl:t.origin,endpointPath:`${t.pathname}${t.search}`}}function Na(e,t,a){let[n,r=""]=e.split("?"),o=n.replace(/\/$/,""),i=new URLSearchParams(r);if(a)for(let[l,u]of Object.entries(a))i.set(l,u);let s=i.toString();return`${o}${t}${s?`?${s}`:""}`}var zq="/api/mcp/";function Fp(e,t){let[a=""]=e.split("?"),n="",r=a;try{let o=new URL(a);n=o.origin,r=o.pathname}catch{if(!a.startsWith("/"))return null}return r.startsWith(zq)?`${n}${t}`:null}function Fq(){if(typeof window>"u")return!1;try{return window.WANIWANI_DEBUG?!0:!!window.localStorage?.getItem("WANIWANI_DEBUG")}catch{return!1}}function Ua(...e){Fq()&&console.log("[Waniwani]",...e)}var $w="waniwani-visitor-id";function qq(){try{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,a=>a.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}}}catch{}return`v-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ma(){try{let t=localStorage.getItem($w);if(t)return t}catch{}let e=qq();try{localStorage.setItem($w,e)}catch{}return e}function wl(e){let t=typeof e=="string"?e.trim():"";if(!t)return ma();try{localStorage.setItem($w,t)}catch{}return t}function Hq(e){return e!=null&&typeof e.then=="function"}function Sc(e){let t=!1,a=()=>{t=!0};if(e==null)return a;let n;try{n=typeof e=="function"?e():e}catch{return a}return Hq(n)?n.then(r=>{t||wl(r??"")},()=>{}):wl(n??""),a}var jq="waniwani-memory";var yn="threads",qp="by_memoryUserId",Vq="by_updatedAt";var I1="memoryUserId",S1="waniwani-memory-user-id",Ww=null;function Gw(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function $q(e,t){if(t<1&&(e.objectStoreNames.contains("ids")||e.createObjectStore("ids")),t<2&&!e.objectStoreNames.contains(yn)){let a=e.createObjectStore(yn,{keyPath:"threadId"});a.createIndex(qp,"memoryUserId",{unique:!1}),a.createIndex(Vq,"updatedAt",{unique:!1})}}async function Xw(){return new Promise((e,t)=>{let a=indexedDB.open(jq,2);a.onupgradeneeded=n=>{$q(a.result,n.oldVersion)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}async function Wq(){return Xw()}async function Gq(e){return new Promise((t,a)=>{let o=e.transaction("ids","readonly").objectStore("ids").get(I1);o.onsuccess=()=>t(typeof o.result=="string"?o.result:null),o.onerror=()=>a(o.error)})}async function Xq(e,t){return new Promise((a,n)=>{let i=e.transaction("ids","readwrite").objectStore("ids").put(t,I1);i.onsuccess=()=>a(),i.onerror=()=>n(i.error)})}async function Kq(){if(typeof indexedDB>"u")return null;try{let e=await Wq();try{let t=await Gq(e);if(t)return t;let a=Gw();return await Xq(e,a),a}finally{e.close()}}catch{return null}}function Yq(){try{let e=localStorage.getItem(S1);if(e)return e;let t=Gw();return localStorage.setItem(S1,t),t}catch{return null}}async function C1(){let e=await Kq();if(e)return e;let t=Yq();return t||(Ww||(Ww=Gw()),Ww)}function k1(e,t){return e.match(t)?.[1]??null}function Zq(e){let t=[["Edge",/Edg(?:e|A|iOS)?\/(\S+)/],["Opera",/(?:OPR|Opera)\/(\S+)/],["Samsung Internet",/SamsungBrowser\/(\S+)/],["Firefox",/Firefox\/(\S+)/],["Chrome",/Chrome\/(\S+)/],["Safari",/Version\/(\S+).*Safari/]];for(let[a,n]of t){let r=k1(e,n);if(r)return{name:a,version:r}}return null}function Jq(e){let t=[["iOS",/(?:iPhone|iPad|iPod).+?OS (\d+[_.\d]*)/],["Android",/Android (\d+[.\d]*)/],["macOS",/Mac OS X (\d+[_.\d]*)/],["Windows",/Windows NT (\d+[.\d]*)/],["ChromeOS",/CrOS \S+ (\d+[.\d]*)/],["Linux",/Linux/]];for(let[a,n]of t){let r=k1(e,n);if(r)return{name:a,version:r.replace(/_/g,".")};if(a==="Linux"&&n.test(e))return{name:a,version:""}}return null}function Qq(e){return typeof navigator<"u"&&"userAgentData"in navigator&&navigator.userAgentData?.mobile?"mobile":/iPad|tablet|PlayBook/i.test(e)?"tablet":/Mobi|Android.*Mobile|iPhone|iPod/i.test(e)?"mobile":"desktop"}async function Ic(){let e=navigator.userAgent,t=ma(),a=await C1();return{userAgent:e,browser:Zq(e),os:Jq(e),deviceType:Qq(e),language:navigator.language,languages:[...navigator.languages],timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,screenWidth:screen.width,screenHeight:screen.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,colorDepth:screen.colorDepth,devicePixelRatio:window.devicePixelRatio??1,touchSupport:"ontouchstart"in window||navigator.maxTouchPoints>0,connectionType:navigator.connection?.effectiveType??"unknown",referrer:document.referrer,visitorId:t,memoryUserId:a}}var e4="0.22.0",t4=40,a4=10,n4=6e5;function Yw(){return typeof performance>"u"?0:performance.now()}function Zw(e,t){let a={};return{metrics:a,has:n=>n in a,set(n,r){a[n]=r},mark(n,r=Yw()){if(!(n in a)){a[n]=r-t;try{performance.mark(`waniwani:${e}:${n}`,{startTime:r})}catch{}}}}}function r4(e){let t={};for(let[a,n]of Object.entries(e)){if(Object.keys(t).length>=t4)break;if(!Number.isFinite(n))continue;let r=Math.round(n);r<0||r>n4||(t[a]=r)}return t}function o4(e){let t={};for(let[a,n]of Object.entries(e)){if(Object.keys(t).length>=a4)break;(typeof n=="string"||typeof n=="boolean")&&(t[a]=n)}return t}function i4(){let e=navigator.connection;if(e)return{effectiveType:e.effectiveType,rtt:e.rtt,downlink:e.downlink,saveData:e.saveData}}function jp(e){let t=e?.Authorization;return typeof t=="string"&&t.startsWith("Bearer ")?t.slice(7):void 0}function s4(e,t,a,n){return{kind:e,sdkVersion:e4,channelId:t.channelId||void 0,sessionId:e==="boot"?void 0:t.sessionId||void 0,visitorId:ma(),pageHost:window.location.hostname,connection:i4(),tags:o4(a),metrics:r4(n)}}var Kw,Hp=[];function Jw(e){let t=String(e?.chatTimingLogs).trim().toLowerCase()==="true";Kw=t;let a=Hp;if(Hp=[],t)for(let n of a)n()}function Vp(e,t,a,n){let{api:r,token:o}=t;if(!(typeof window>"u"||!r||!o||Kw===!1))try{let i=s4(e,t,a,n),s=()=>{Ua("timing",i),fetch(Na(r,"/timing"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(i),keepalive:!0}).catch(()=>{})};Kw?s():Hp.length<20&&Hp.push(s)}catch{}}var Wr=Zw("boot",0),T1;function Di(e,t){Wr.mark(e,t)}function $p(e){T1??(T1=e)}var l4=/cdn\.jsdelivr\.net\/npm\/@waniwani\/sdk@[^/]+\/dist\/chat\/embed\.js/,u4=/\/embed\.js(\?|$)/;function c4(){if(typeof performance>"u")return;let e=performance.getEntriesByType("navigation")[0];e?.responseStart&&Wr.mark("navTtfb",e.responseStart),e?.domContentLoadedEventEnd&&Wr.mark("navDomContentLoaded",e.domContentLoadedEventEnd);let t=performance.getEntriesByType("resource");for(let a of t)l4.test(a.name)?(Wr.mark("bundleStart",a.startTime),Wr.mark("bundleEnd",a.responseEnd)):u4.test(a.name)&&(Wr.mark("loaderStart",a.startTime),Wr.mark("loaderEnd",a.responseEnd))}function d4(){if(bI)return!0;try{return document.querySelectorAll('script[src*="@waniwani/sdk"]').length>1}catch{return!1}}function L1(e){c4(),Wr.mark("bundleExecuted",xI),Vp("boot",e,{configSource:T1,mode:e.mode,secondSdk:d4()},Wr.metrics)}var f4=[["text-delta","firstText"],["tool-input-start","firstToolInput"],["tool-output-available","firstToolOutput"]];function E1(e){let t=Zw("turn",Yw());t.set("turnIndex",e);let a=!1;return{mark:n=>t.mark(n),instrument(n){if(!n.ok||!n.body||typeof TransformStream>"u")return n;try{let r=new TextDecoder,o=n.body.pipeThrough(new TransformStream({transform(i,s){t.mark("firstChunk");let l=r.decode(i,{stream:!0});for(let[u,c]of f4)!t.has(c)&&l.includes(u)&&t.mark(c);s.enqueue(i)}}));return new Response(o,{status:n.status,statusText:n.statusText,headers:n.headers})}catch{return n}},report(n,r){a||(a=!0,Vp("turn",n,r,t.metrics))}}}function p4(e){let t=e.indexOf("?");return t===-1?e:e.slice(0,t)}function A1(e,t){let a=Zw("widget",Yw()),n=!1;return{mark:r=>a.mark(r),has:r=>a.has(r),report(r,o){n||(n=!0,a.set("retries",o),t({widget:p4(e),outcome:r,metrics:a.metrics}))}}}var m4="/api/mcp/events/v2/batch",Qw=new Set;function h4(e,t,a){return`${e}|${t}|${a??""}`}function Cc(e){return Fp(e,m4)}async function M1(e){let{api:t,token:a,channelId:n,mode:r,source:o}=e;if(typeof window>"u"||!t||!a)return;let i=Cc(t);if(!i){Ua("page.viewed skipped: the chat api is not a Waniwani endpoint");return}if(!n&&!o){Ua("page.viewed skipped: no channelId or source to attribute it");return}let s=h4(t,a,n);if(!Qw.has(s)){Qw.add(s);try{let l=await Ic(),u=new Date().toISOString(),c=JSON.stringify({sentAt:u,source:{sdk:"@waniwani/sdk",version:"0.1.0"},events:[{id:crypto.randomUUID(),type:"mcp.event",name:"page.viewed",source:o,timestamp:u,correlation:{visitorId:l.visitorId},properties:{channelId:n,mode:r,url:window.location.href,referrer:l.referrer,deviceType:l.deviceType,language:l.language,timezone:l.timezone},metadata:{}}]}),d=fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:c,keepalive:!0});Di("pageViewSent"),await d}catch{Qw.delete(s)}}}function R1(e){let t=Cc(e.api);return t?b1({endpoint:t,token:e.token,channelId:e.channelId,source:e.getSource,identity:()=>({sessionId:e.getSessionId(),visitorId:ma()})}):Wp("the chat api does not point at a Waniwani event ingest")}function Wp(e){let t=!1,a=async()=>(t||(t=!0,console.warn(`[Waniwani] track() is disabled: ${e}`)),{eventId:""});return{track:Object.assign(a,{priceShown:a,pricesCompared:a,optionSelected:a,leadQualified:a,converted:a}),identify:a,flush:async()=>{},shutdown:async()=>({timedOut:!1,pendingEvents:0})}}var Xp=j(Ee());var Gp=(...e)=>e.filter((t,a,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===a).join(" ").trim();var D1=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var _1=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,n)=>n?n.toUpperCase():a.toLowerCase());var ev=e=>{let t=_1(e);return t.charAt(0).toUpperCase()+t.slice(1)};var kc=j(Ee());var P1={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 O1=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var N1=(0,kc.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:n,className:r="",children:o,iconNode:i,...s},l)=>(0,kc.createElement)("svg",{ref:l,...P1,width:t,height:t,stroke:e,strokeWidth:n?Number(a)*24/Number(t):a,className:Gp("lucide",r),...!o&&!O1(s)&&{"aria-hidden":"true"},...s},[...i.map(([u,c])=>(0,kc.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var tt=(e,t)=>{let a=(0,Xp.forwardRef)(({className:n,...r},o)=>(0,Xp.createElement)(N1,{ref:o,iconNode:t,className:Gp(`lucide-${D1(ev(e))}`,`lucide-${e}`,n),...r}));return a.displayName=ev(e),a};var g4=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Tc=tt("arrow-down",g4);var y4=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],pr=tt("arrow-up",y4);var w4=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Lc=tt("check",w4);var v4=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],zo=tt("chevron-down",v4);var x4=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ec=tt("chevron-right",x4);var b4=[["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"}]],Ac=tt("clipboard-copy",b4);var S4=[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Gr=tt("clock",S4);var I4=[["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"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Mc=tt("file-text",I4);var C4=[["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"}]],vl=tt("file",C4);var k4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Rc=tt("globe",k4);var T4=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Dc=tt("image",T4);var L4=[["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"}]],_c=tt("loader",L4);var E4=[["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"}]],xl=tt("paperclip",E4);var A4=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Pc=tt("square",A4);var M4=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],_i=tt("wrench",M4);var R4=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],wn=tt("x",R4);var D4=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Oc=tt("zap",D4);var rt=j(Ee(),1),qB=j(gg(),1);var bl=j(Ee(),1),Nc=j(me(),1);function O4(e){return 1-(1-e)**3}function N4({start:e=0,end:t=100,duration:a=1e3,delay:n=0,ease:r=O4,onUpdate:o,onEnd:i}){let s=performance.now()+n;function l(){let u=performance.now()-s,c=Math.min(u/a,1);o(e+(t-e)*r(c)),c<1?requestAnimationFrame(l):i&&i()}setTimeout(()=>requestAnimationFrame(l),n)}var U4=["80% 55%","69% 34%","8% 6%","41% 38%","86% 85%","82% 18%","51% 4%"],B4=[0,1,2,0,1,2,1];function z4(e){let t=[];for(let a=0;a<7;a++){let n=e[Math.min(B4[a],e.length-1)];t.push(`radial-gradient(at ${U4[a]}, ${n} 0px, transparent 50%)`)}return t.push(`linear-gradient(${e[0]} 0 100%)`),t}var F4=({children:e,className:t="",style:a,edgeSensitivity:n=30,backgroundColor:r="#120F17",borderRadius:o=28,coneSpread:i=25,animated:s=!1,colors:l=["#c084fc","#f472b6","#38bdf8"]})=>{let[u,c]=(0,bl.useState)(110),[d,p]=(0,bl.useState)(0),[m,h]=(0,bl.useState)(!1);(0,bl.useEffect)(()=>{if(!s)return;let E=110;h(!0),c(E),N4({ease:T=>T,duration:2e3,onUpdate:T=>{let R=T/100;c(E+360*R);let O=Math.min(R/.1,1),U=R>.85?(1-R)/.15:1;p(Math.min(O,U))},onEnd:()=>h(!1)})},[s]);let v=n+20,I=m?Math.max(0,(d*100-v)/(100-v)):0,w=z4(l).map(E=>`${E} border-box`),S=`conic-gradient(from ${`${u.toFixed(3)}deg`} at center, black ${i}%, transparent ${i+15}%, transparent ${100-i-15}%, black ${100-i}%)`;return(0,Nc.jsxs)("div",{className:`ww:relative ww:grid ww:isolate ww:border ${t}`,style:{background:r,borderRadius:typeof o=="number"?`${o}px`:o,transform:"translate3d(0, 0, 0.01px)",...a},children:[(0,Nc.jsx)("div",{className:"ww:absolute ww:inset-0 ww:rounded-[inherit] ww:-z-[1]",style:{border:"1px solid transparent",background:[`linear-gradient(${r} 0 100%) padding-box`,"linear-gradient(rgb(255 255 255 / 0%) 0% 100%) border-box",...w].join(", "),opacity:I,maskImage:S,WebkitMaskImage:S,transition:m?"opacity 0.25s ease-out":"opacity 0.75s ease-in-out"}}),(0,Nc.jsx)("div",{className:"ww:flex ww:flex-col ww:relative ww:overflow-auto ww:z-[1]",children:e})]})},Yp=F4;tv();nv();var q4=q1({prefix:"ww"});function V(...e){return q4(Zp(e))}var Uc=j(me(),1);function Sl({suggestions:e,isLoading:t,onSelect:a,align:n="start",className:r,...o}){return e.length===0&&!t?null:(0,Uc.jsx)("div",{className:V("ww:px-4 ww:py-2",r),...o,children:(0,Uc.jsx)("div",{className:V("ww:mx-auto ww:w-full ww:max-w-3xl ww:flex ww:flex-wrap ww:gap-2",n==="center"&&"ww:justify-center"),children:t?[0,1,2].map(i=>(0,Uc.jsx)("div",{className:"ww:h-8 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+i*20}px`}},i)):e.map((i,s)=>(0,Uc.jsx)("button",{type:"button",onClick:()=>a(i),className:V("ww:rounded-full ww:border ww:border-border ww:bg-accent ww:px-3.5 ww:py-1.5 ww:text-sm","ww:text-foreground ww:hover:bg-border 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:`${s*50}ms`},children:i},i))})})}var gm=j(Ee(),1);var gL="vercel.ai.error",H4=Symbol.for(gL),H1,j1,Je=class yL extends(j1=Error,H1=H4,j1){constructor({name:t,message:a,cause:n}){super(a),this[H1]=!0,this.name=t,this.cause=n}static isInstance(t){return yL.hasMarker(t,gL)}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}},wL="AI_APICallError",vL=`vercel.ai.error.${wL}`,j4=Symbol.for(vL),V1,$1,GQ=class extends($1=Je,V1=j4,$1){constructor({message:e,url:t,requestBodyValues:a,statusCode:n,responseHeaders:r,responseBody:o,cause:i,isRetryable:s=n!=null&&(n===408||n===409||n===429||n>=500),data:l}){super({name:wL,message:e,cause:i}),this[V1]=!0,this.url=t,this.requestBodyValues=a,this.statusCode=n,this.responseHeaders=r,this.responseBody=o,this.isRetryable=s,this.data=l}static isInstance(e){return Je.hasMarker(e,vL)}},xL="AI_EmptyResponseBodyError",bL=`vercel.ai.error.${xL}`,V4=Symbol.for(bL),W1,G1,XQ=class extends(G1=Je,W1=V4,G1){constructor({message:e="Empty response body"}={}){super({name:xL,message:e}),this[W1]=!0}static isInstance(e){return Je.hasMarker(e,bL)}};function SL(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var IL="AI_InvalidArgumentError",CL=`vercel.ai.error.${IL}`,$4=Symbol.for(CL),X1,K1,kL=class extends(K1=Je,X1=$4,K1){constructor({message:e,cause:t,argument:a}){super({name:IL,message:e,cause:t}),this[X1]=!0,this.argument=a}static isInstance(e){return Je.hasMarker(e,CL)}},TL="AI_InvalidPromptError",LL=`vercel.ai.error.${TL}`,W4=Symbol.for(LL),Y1,Z1,KQ=class extends(Z1=Je,Y1=W4,Z1){constructor({prompt:e,message:t,cause:a}){super({name:TL,message:`Invalid prompt: ${t}`,cause:a}),this[Y1]=!0,this.prompt=e}static isInstance(e){return Je.hasMarker(e,LL)}},EL="AI_InvalidResponseDataError",AL=`vercel.ai.error.${EL}`,G4=Symbol.for(AL),J1,Q1,YQ=class extends(Q1=Je,J1=G4,Q1){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:EL,message:t}),this[J1]=!0,this.data=e}static isInstance(e){return Je.hasMarker(e,AL)}},ML="AI_JSONParseError",RL=`vercel.ai.error.${ML}`,X4=Symbol.for(RL),eL,tL,ov=class extends(tL=Je,eL=X4,tL){constructor({text:e,cause:t}){super({name:ML,message:`JSON parsing failed: Text: ${e}.
|
|
121
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},NS=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},yU=e=>{let t=IK.test(e),a=CK.test(e);if(t||a)return[e];let n=Sn.lex(e,{gfm:!0}),r=[],o=[];for(let i of n){let s=i.raw,l=r.length;if(o.length>0){if(r[l-1]+=s,i.type==="html"){let u=s.match(kK);if(u){let c=u[1];o.at(-1)===c&&o.pop()}}continue}if(i.type==="html"&&i.block){let u=s.match(TK);if(u){let c=u[1];s.includes(`</${c}>`)||o.push(c)}}if(s.trim()==="$$"&&l>0){let u=r[l-1],c=OS(u),d=NS(u);if(c&&d%2===1){r[l-1]=u+s;continue}}if(l>0&&LK(s)){let u=r[l-1],c=OS(u),d=NS(u),p=NS(s);if(c&&d%2===1&&!OS(s)&&p===1){r[l-1]=u+s;continue}}r.push(s)}return r},wU={raw:ZM,sanitize:[Am,{}],harden:[KM,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:!0}]},vU={gfm:[eh,{}]},EK=Object.values(wU),AK=Object.values(vU),MK={block:" \u258B",circle:" \u25CF"},RK={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0,linkSafety:{enabled:!0}},qa=(0,N.createContext)(RK),jS=(0,N.memo)(({content:e,shouldParseIncompleteMarkdown:t,index:a,...n})=>(0,M.jsx)(gU,{...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,i;return((o=e.components)==null?void 0:o[r])!==((i=t.components)==null?void 0:i[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});jS.displayName="Block";DK=["github-light","github-dark"],au=(0,N.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:a=!0,components:n,rehypePlugins:r=EK,remarkPlugins:o=AK,className:i,shikiTheme:s=DK,mermaid:l,controls:u=!0,isAnimating:c=!1,BlockComponent:d=jS,parseMarkdownIntoBlocksFn:p=yU,caret:m,plugins:h,remend:v,linkSafety:I={enabled:!0},...y})=>{let w=(0,N.useId)(),[g,S]=(0,N.useTransition)(),E=(0,N.useMemo)(()=>typeof e!="string"?"":t==="streaming"&&a?u_(e,v):e,[e,t,a,v]),T=(0,N.useMemo)(()=>p(E),[E,p]),[R,O]=(0,N.useState)(T);(0,N.useEffect)(()=>{t==="streaming"?S(()=>{O(T)}):O(T)},[T,t]);let U=t==="streaming"?R:T,A=(0,N.useMemo)(()=>U.map((B,P)=>`${w}-${P}`),[U.length,w]),Q=(0,N.useMemo)(()=>{var B,P;return{shikiTheme:(P=(B=h?.code)==null?void 0:B.getThemes())!=null?P:s,controls:u,isAnimating:c,mode:t,mermaid:l,linkSafety:I}},[s,u,c,t,l,I,h?.code]),$=(0,N.useMemo)(()=>({...wK,...n}),[n]),H=(0,N.useMemo)(()=>{let B=[];return h!=null&&h.cjk&&(B=[...B,...h.cjk.remarkPluginsBefore]),B=[...B,...o],h!=null&&h.cjk&&(B=[...B,...h.cjk.remarkPluginsAfter]),h!=null&&h.math&&(B=[...B,h.math.remarkPlugin]),B},[o,h?.math,h?.cjk]),Z=(0,N.useMemo)(()=>h!=null&&h.math?[...r,h.math.rehypePlugin]:r,[r,h?.math]),X=(0,N.useMemo)(()=>m&&c?{"--streamdown-caret":`"${MK[m]}"`}:void 0,[m,c]);return t==="static"?(0,M.jsx)(US.Provider,{value:h??null,children:(0,M.jsx)(qa.Provider,{value:Q,children:(0,M.jsx)("div",{className:Ce("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",i),children:(0,M.jsx)(gU,{components:$,rehypePlugins:Z,remarkPlugins:H,...y,children:e})})})}):(0,M.jsx)(US.Provider,{value:h??null,children:(0,M.jsx)(qa.Provider,{value:Q,children:(0,M.jsxs)("div",{className:Ce("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,i),style:X,children:[U.length===0&&m&&c&&(0,M.jsx)("span",{}),U.map((B,P)=>(0,M.jsx)(d,{components:$,content:B,index:P,rehypePlugins:Z,remarkPlugins:H,shouldParseIncompleteMarkdown:a,...y},A[P]))]})})})},(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);au.displayName="Streamdown";_K=({children:e,className:t,minZoom:a=.5,maxZoom:n=3,zoomStep:r=.1,showControls:o=!0,initialZoom:i=1,fullscreen:s=!1})=>{let l=(0,N.useRef)(null),u=(0,N.useRef)(null),[c,d]=(0,N.useState)(i),[p,m]=(0,N.useState)({x:0,y:0}),[h,v]=(0,N.useState)(!1),[I,y]=(0,N.useState)({x:0,y:0}),[w,g]=(0,N.useState)({x:0,y:0}),S=(0,N.useCallback)($=>{d(H=>Math.max(a,Math.min(n,H+$)))},[a,n]),E=(0,N.useCallback)(()=>{S(r)},[S,r]),T=(0,N.useCallback)(()=>{S(-r)},[S,r]),R=(0,N.useCallback)(()=>{d(i),m({x:0,y:0})},[i]),O=(0,N.useCallback)($=>{$.preventDefault();let H=$.deltaY>0?-r:r;S(H)},[S,r]),U=(0,N.useCallback)($=>{if($.button!==0||$.isPrimary===!1)return;v(!0),y({x:$.clientX,y:$.clientY}),g(p);let H=$.currentTarget;H instanceof HTMLElement&&H.setPointerCapture($.pointerId)},[p]),A=(0,N.useCallback)($=>{if(!h)return;$.preventDefault();let H=$.clientX-I.x,Z=$.clientY-I.y;m({x:w.x+H,y:w.y+Z})},[h,I,w]),Q=(0,N.useCallback)($=>{v(!1);let H=$.currentTarget;H instanceof HTMLElement&&H.releasePointerCapture($.pointerId)},[]);return(0,N.useEffect)(()=>{let $=l.current;if($)return $.addEventListener("wheel",O,{passive:!1}),()=>{$.removeEventListener("wheel",O)}},[O]),(0,N.useEffect)(()=>{let $=u.current;if($&&h)return document.body.style.userSelect="none",$.addEventListener("pointermove",A,{passive:!1}),$.addEventListener("pointerup",Q),$.addEventListener("pointercancel",Q),()=>{document.body.style.userSelect="",$.removeEventListener("pointermove",A),$.removeEventListener("pointerup",Q),$.removeEventListener("pointercancel",Q)}},[h,A,Q]),(0,M.jsxs)("div",{className:Ce("relative flex flex-col",s?"h-full w-full":"min-h-28 w-full",t),ref:l,style:{cursor:h?"grabbing":"grab"},children:[o?(0,M.jsxs)("div",{className:Ce("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",s?"bottom-4 left-4":"bottom-2 left-2"),children:[(0,M.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:E,title:"Zoom in",type:"button",children:(0,M.jsx)(KX,{size:16})}),(0,M.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:T,title:"Zoom out",type:"button",children:(0,M.jsx)(YX,{size:16})}),(0,M.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:R,title:"Reset zoom and pan",type:"button",children:(0,M.jsx)(XX,{size:16})})]}):null,(0,M.jsx)("div",{className:Ce("flex-1 origin-center transition-transform duration-150 ease-out",s?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:U,ref:u,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})},_S=({chart:e,className:t,config:a,fullscreen:n=!1,showControls:r=!0})=>{let[o,i]=(0,N.useState)(null),[s,l]=(0,N.useState)(!1),[u,c]=(0,N.useState)(""),[d,p]=(0,N.useState)(""),[m,h]=(0,N.useState)(0),{mermaid:v}=(0,N.useContext)(qa),I=qS(),y=v?.errorComponent,{shouldRender:w,containerRef:g}=$X({immediate:n});if((0,N.useEffect)(()=>{if(w){if(!I){i("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{i(null),l(!0);let E=I.getMermaid(a),T=e.split("").reduce((U,A)=>(U<<5)-U+A.charCodeAt(0)|0,0),R=`mermaid-${Math.abs(T)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:O}=await E.render(R,e);c(O),p(O)}catch(E){if(!(d||u)){let T=E instanceof Error?E.message:"Failed to render Mermaid chart";i(T)}}finally{l(!1)}})()}},[e,a,m,w,I]),!(w||u||d))return(0,M.jsx)("div",{className:Ce("my-4 min-h-[200px]",t),ref:g});if(s&&!u&&!d)return(0,M.jsx)("div",{className:Ce("my-4 flex justify-center p-4",t),ref:g,children:(0,M.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,M.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,M.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(o&&!u&&!d)return y?(0,M.jsx)("div",{ref:g,children:(0,M.jsx)(y,{chart:e,error:o,retry:()=>h(T=>T+1)})}):(0,M.jsxs)("div",{className:Ce("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:g,children:[(0,M.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",o]}),(0,M.jsxs)("details",{className:"mt-2",children:[(0,M.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,M.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let S=u||d;return(0,M.jsx)("div",{className:Ce("size-full",t),"data-streamdown":"mermaid",ref:g,children:(0,M.jsx)(_K,{className:Ce(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:(0,M.jsx)("div",{"aria-label":"Mermaid chart",className:Ce("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:S},role:"img"})})})}});var lB=Ca((Xve,sB)=>{"use strict";function cY(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 i=Date.now(),s=i-n,l=t-s;l<=0?(n=i,e.apply(this,o)):a=setTimeout(()=>{n=Date.now(),e.apply(this,o)},l)}}sB.exports=cY});var xI=typeof performance>"u"?0:performance.now(),bI=typeof window<"u"&&!!window.WaniWani?.chat;var Cs=j(Ee(),1),Zh=j(qw(),1);var Hw="waniwani/suggestions";function yl(e,t){for(let a of t){let n=e[a];if(typeof n=="string"&&n.length>0)return n}}var hq=["waniwani/sessionId","openai/sessionId","openai/session","sessionId","conversationId","mcp-session-id"],gq=["waniwani/requestId","openai/requestId","requestId","mcp/requestId"],yq=["waniwani/traceId","openai/traceId","traceId","mcp/traceId","openai/requestId","requestId"],wq=["waniwani/userId","openai/userId","externalUserId","userId","actorId"],vq=["waniwani/visitorId","visitorId"],xq=["correlationId","openai/requestId"];function c1(e){return e?yl(e,hq):void 0}function d1(e){return e?yl(e,gq):void 0}function f1(e){return e?yl(e,yq):void 0}function p1(e){return e?yl(e,wq):void 0}function m1(e){return e?yl(e,vq):void 0}function h1(e){return e?yl(e,xq):void 0}var bq=[{key:"openai/sessionId",source:"chatgpt"},{key:"openai/session",source:"chatgpt"}],Sq=[{needle:"claude",source:"claude"},{needle:"chatgpt",source:"chatgpt"},{needle:"openai",source:"chatgpt"},{needle:"gemini",source:"gemini"}];function g1(e,t){if(e){let n=e["waniwani/source"];if(typeof n=="string"&&n.length>0)return n;for(let{key:r,source:o}of bq){let i=e[r];if(typeof i=="string"&&i.length>0)return o}}let a=t?.name;if(typeof a=="string"&&a.length>0){let n=a.toLowerCase();for(let{needle:r,source:o}of Sq)if(n.includes(r))return o}}var Iq="@waniwani/sdk";function y1(e,t={}){let a=t.now??(()=>new Date),n=t.generateId??Cq,r=Lq(e),o=zp(e.meta),i=zp(e.metadata),s=Eq(e,o),l=Xn(e.eventId)??n(),u=Aq(e.timestamp,a),c=Xn(e.source)??g1(o)??t.source??Iq,d=jw(e)?{...e}:void 0,p={...i};return Object.keys(o).length>0&&(p.meta=o),d&&(p.rawLegacy=d),{id:l,type:"mcp.event",name:r,source:c,timestamp:u,correlation:s,properties:kq(e,r),metadata:p,rawLegacy:d}}function Cq(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`evt_${crypto.randomUUID()}`:`evt_${Math.random().toString(36).slice(2,10)}_${Date.now().toString(36)}`}function kq(e,t){if(!jw(e))return zp(e.properties);let a=Tq(e,t),n=zp(e.properties);return{...a,...n}}function Tq(e,t){switch(t){case"tool.called":{let a={};return Xn(e.toolName)&&(a.name=e.toolName),Xn(e.toolType)&&(a.type=e.toolType),a}case"link.clicked":{let a={};return Xn(e.linkUrl)&&(a.url=e.linkUrl),a}default:return{}}}function Lq(e){return jw(e)?e.eventType:e.event}function Eq(e,t){let a=Xn(e.requestId)??d1(t),n=Xn(e.sessionId)??c1(t),r=Xn(e.traceId)??f1(t),o=Xn(e.externalUserId)??p1(t),i=Xn(e.visitorId)??m1(t),s=Xn(e.correlationId)??h1(t)??a,l={};return n&&(l.sessionId=n),r&&(l.traceId=r),a&&(l.requestId=a),s&&(l.correlationId=s),o&&(l.externalUserId=o),i&&(l.visitorId=i),l}function Aq(e,t){if(e instanceof Date)return e.toISOString();if(typeof e=="string"){let a=new Date(e);if(!Number.isNaN(a.getTime()))return a.toISOString()}return t().toISOString()}function zp(e){return!e||typeof e!="object"||Array.isArray(e)?{}:e}function Xn(e){if(typeof e=="string"&&e.trim().length!==0)return e}function jw(e){return"eventType"in e}function w1(e){return{priceShown:({amount:t,currency:a,itemId:n,label:r,...o})=>e({event:"price_shown",properties:{amount:t,currency:a,itemId:n,label:r},...o}),pricesCompared:({options:t,...a})=>e({event:"prices_compared",properties:{options:t},...a}),optionSelected:({id:t,amount:a,currency:n,...r})=>e({event:"option_selected",properties:{id:t,amount:a,currency:n},...r}),leadQualified:t=>{let{externalId:a,email:n,name:r,...o}=t??{};return e({event:"lead_qualified",properties:{externalId:a,email:n,name:r},...o})},converted:({amount:t,currency:a,occurredAt:n,...r})=>e({event:"converted",properties:{amount:t,currency:a,occurredAt:n},...r})}}var Mq="/api/mcp/events/v2/batch";var v1="@waniwani/sdk";var Rq=new Set([401,403]),Dq=new Set([408,425,429,500,502,503,504]),_q=(e,t)=>globalThis.fetch(e,t);function x1(e){return new Vw(e)}var Vw=class{constructor(t){K(this,"endpointUrl");K(this,"flushIntervalMs");K(this,"maxBatchSize");K(this,"maxBufferSize");K(this,"maxRetries");K(this,"retryBaseDelayMs");K(this,"retryMaxDelayMs");K(this,"shutdownTimeoutMs");K(this,"sdkVersion");K(this,"fetchFn");K(this,"logger");K(this,"now");K(this,"sleep");K(this,"apiKey");K(this,"buffer",[]);K(this,"flushTimer");K(this,"flushScheduled",!1);K(this,"flushScheduledTimer");K(this,"flushInFlight");K(this,"inFlightCount",0);K(this,"isStopped",!1);K(this,"isShuttingDown",!1);this.endpointUrl=Nq(t.apiUrl,t.endpointPath??Mq),this.flushIntervalMs=t.flushIntervalMs??1e3,this.maxBatchSize=t.maxBatchSize??20,this.maxBufferSize=t.maxBufferSize??1e3,this.maxRetries=t.maxRetries??3,this.retryBaseDelayMs=t.retryBaseDelayMs??200,this.retryMaxDelayMs=t.retryMaxDelayMs??2e3,this.shutdownTimeoutMs=t.shutdownTimeoutMs??2e3,this.fetchFn=t.fetchFn??_q,this.logger=t.logger??console,this.now=t.now??(()=>new Date),this.sleep=t.sleep??(a=>new Promise(n=>setTimeout(n,a))),this.apiKey=t.apiKey,this.sdkVersion=t.sdkVersion,this.flushIntervalMs>0&&(this.flushTimer=setInterval(()=>{this.flush()},this.flushIntervalMs)),this.registerBrowserTeardown()}enqueue(t){if(this.isStopped||this.isShuttingDown){this.logger.warn("[Waniwani] Tracking transport is stopped, dropping event %s",t.id);return}if(this.buffer.length>=this.maxBufferSize){let a=this.buffer.length-this.maxBufferSize+1;this.buffer.splice(0,a),this.logger.warn("[Waniwani] Tracking buffer overflow, dropped %d oldest event(s)",a)}if(this.buffer.push(t),this.buffer.length>=this.maxBatchSize){this.flush();return}this.scheduleMicroFlush()}pendingEvents(){return this.buffer.length+this.inFlightCount}async flush(){return this.flushInFlight?this.flushInFlight:(this.flushInFlight=this.flushLoop().finally(()=>{this.flushInFlight=void 0}),this.flushInFlight)}async shutdown(t){this.isShuttingDown=!0,this.flushTimer&&(clearInterval(this.flushTimer),this.flushTimer=void 0),this.flushScheduledTimer&&(clearTimeout(this.flushScheduledTimer),this.flushScheduledTimer=void 0,this.flushScheduled=!1);let a=t?.timeoutMs??this.shutdownTimeoutMs,n=this.flush();if(!Number.isFinite(a)||a<=0)return await n,this.isStopped=!0,{timedOut:!1,pendingEvents:this.pendingEvents()};let r=Symbol("shutdown-timeout");return await Promise.race([n.then(()=>"flushed"),this.sleep(a).then(()=>r)])===r?(this.isStopped=!0,{timedOut:!0,pendingEvents:this.pendingEvents()}):(this.isStopped=!0,{timedOut:!1,pendingEvents:this.pendingEvents()})}registerBrowserTeardown(){if(typeof document>"u"||typeof window>"u")return;let t=()=>{document.visibilityState==="hidden"&&this.keepaliveFlush()};document.addEventListener("visibilitychange",t),window.addEventListener("pagehide",()=>this.keepaliveFlush())}keepaliveFlush(){if(this.isStopped||this.buffer.length===0)return;let t=this.buffer.splice(0,this.buffer.length);this.sendKeepaliveChunk(t)}sendKeepaliveChunk(t){let a=JSON.stringify(this.makeBatchRequest(t));if(a.length>6e4&&t.length>1){let n=Math.ceil(t.length/2);this.sendKeepaliveChunk(t.slice(0,n)),this.sendKeepaliveChunk(t.slice(n));return}try{this.fetchFn(this.endpointUrl,{method:"POST",headers:this.requestHeaders(),body:a,keepalive:!0}).catch(()=>{})}catch{}}requestHeaders(){let t={"Content-Type":"application/json","X-WaniWani-SDK":v1};return this.apiKey&&(t.Authorization=`Bearer ${this.apiKey}`),t}scheduleMicroFlush(){this.flushScheduled||(this.flushScheduled=!0,this.flushScheduledTimer=setTimeout(()=>{this.flushScheduledTimer=void 0,this.flushScheduled=!1,this.flush()},0))}async flushLoop(){for(;this.buffer.length>0&&!this.isStopped;){let t=this.buffer.splice(0,this.maxBatchSize);await this.sendBatchWithRetry(t)}}async sendBatchWithRetry(t){let a=0,n=t;for(;n.length>0&&!this.isStopped;){this.inFlightCount=n.length;let r=await this.sendBatchOnce(n);switch(this.inFlightCount=0,r.kind){case"success":return;case"auth":this.stopTransportForAuthFailure(r.status,n.length);return;case"permanent":this.logger.error("[Waniwani] Dropping %d event(s) after permanent failure: %s",n.length,r.reason);return;case"retryable":if(a>=this.maxRetries){this.logger.error("[Waniwani] Dropping %d event(s) after retry exhaustion: %s",n.length,r.reason);return}await this.sleep(this.backoffDelayMs(a)),a+=1;continue;case"partial":if(r.permanent.length>0&&this.logger.error("[Waniwani] Dropping %d event(s) rejected as permanent",r.permanent.length),r.retryable.length===0)return;if(a>=this.maxRetries){this.logger.error("[Waniwani] Dropping %d retryable event(s) after retry exhaustion",r.retryable.length);return}n=r.retryable,await this.sleep(this.backoffDelayMs(a)),a+=1;continue}}}async sendBatchOnce(t){let a;try{a=await this.fetchFn(this.endpointUrl,{method:"POST",headers:this.requestHeaders(),body:JSON.stringify(this.makeBatchRequest(t))})}catch(o){return{kind:"retryable",reason:Uq(o)}}if(Rq.has(a.status))return{kind:"auth",status:a.status};if(Dq.has(a.status))return{kind:"retryable",reason:`HTTP ${a.status}`};if(!a.ok)return{kind:"permanent",reason:`HTTP ${a.status}`};let n=await Oq(a);if(!n?.rejected||n.rejected.length===0)return{kind:"success"};let r=this.classifyRejectedEvents(t,n.rejected);return r.retryable.length===0&&r.permanent.length===0?{kind:"success"}:{kind:"partial",retryable:r.retryable,permanent:r.permanent}}makeBatchRequest(t){return{sentAt:this.now().toISOString(),source:{sdk:v1,version:this.sdkVersion??"0.0.0"},events:t}}classifyRejectedEvents(t,a){let n=new Map(t.map(i=>[i.id,i])),r=[],o=[];for(let i of a){let s=n.get(i.eventId);if(s){if(Pq(i)){r.push(s);continue}o.push(s)}}return{retryable:r,permanent:o}}backoffDelayMs(t){let a=this.retryBaseDelayMs*2**t;return Math.min(a,this.retryMaxDelayMs)}stopTransportForAuthFailure(t,a){this.isStopped=!0;let n=this.buffer.length;this.buffer.splice(0,n),this.logger.error("[Waniwani] Auth failure (HTTP %d). Stopping tracking transport and dropping %d queued event(s)",t,a+n)}};function Pq(e){if(e.retryable===!0)return!0;let t=e.code.toLowerCase();return t.includes("timeout")||t.includes("temporary")||t.includes("unavailable")||t.includes("rate_limit")||t.includes("transient")||t.includes("server")}async function Oq(e){let t=await e.text();if(t)try{return JSON.parse(t)}catch{return}}function Nq(e,t){let a=e.endsWith("/")?e:`${e}/`,n=t.startsWith("/")?t.slice(1):t;return`${a}${n}`}function Uq(e){return e instanceof Error?e.message:String(e)}function b1(e){let{apiUrl:t,endpointPath:a}=Bq(e.endpoint),n=x1({apiUrl:t,apiKey:e.token,endpointPath:a,flushIntervalMs:e.flushIntervalMs}),r,o=s=>typeof s=="function"?s():s,i=async s=>{let l=e.identity?.()??{},u=o(e.channelId),c=u===void 0?s.properties:{channelId:u,...s.properties},d=y1({sessionId:l.sessionId,visitorId:l.visitorId,externalUserId:l.externalUserId??r,traceId:l.traceId,...s,properties:c,metadata:{...e.metadata,...s.metadata}},{source:o(e.source)});return n.enqueue(d),{eventId:d.id}};return{track:Object.assign(i,w1(i)),identify(s,l){return r=s,i({event:"user.identified",externalUserId:s,properties:l})},flush:()=>n.flush(),shutdown:s=>n.shutdown(s)}}function Bq(e){let t=new URL(e);return{apiUrl:t.origin,endpointPath:`${t.pathname}${t.search}`}}function Na(e,t,a){let[n,r=""]=e.split("?"),o=n.replace(/\/$/,""),i=new URLSearchParams(r);if(a)for(let[l,u]of Object.entries(a))i.set(l,u);let s=i.toString();return`${o}${t}${s?`?${s}`:""}`}var zq="/api/mcp/";function Fp(e,t){let[a=""]=e.split("?"),n="",r=a;try{let o=new URL(a);n=o.origin,r=o.pathname}catch{if(!a.startsWith("/"))return null}return r.startsWith(zq)?`${n}${t}`:null}function Fq(){if(typeof window>"u")return!1;try{return window.WANIWANI_DEBUG?!0:!!window.localStorage?.getItem("WANIWANI_DEBUG")}catch{return!1}}function Ua(...e){Fq()&&console.log("[Waniwani]",...e)}var $w="waniwani-visitor-id";function qq(){try{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,a=>a.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}}}catch{}return`v-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function ma(){try{let t=localStorage.getItem($w);if(t)return t}catch{}let e=qq();try{localStorage.setItem($w,e)}catch{}return e}function wl(e){let t=typeof e=="string"?e.trim():"";if(!t)return ma();try{localStorage.setItem($w,t)}catch{}return t}function Hq(e){return e!=null&&typeof e.then=="function"}function Sc(e){let t=!1,a=()=>{t=!0};if(e==null)return a;let n;try{n=typeof e=="function"?e():e}catch{return a}return Hq(n)?n.then(r=>{t||wl(r??"")},()=>{}):wl(n??""),a}var jq="waniwani-memory";var yn="threads",qp="by_memoryUserId",Vq="by_updatedAt";var I1="memoryUserId",S1="waniwani-memory-user-id",Ww=null;function Gw(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function $q(e,t){if(t<1&&(e.objectStoreNames.contains("ids")||e.createObjectStore("ids")),t<2&&!e.objectStoreNames.contains(yn)){let a=e.createObjectStore(yn,{keyPath:"threadId"});a.createIndex(qp,"memoryUserId",{unique:!1}),a.createIndex(Vq,"updatedAt",{unique:!1})}}async function Xw(){return new Promise((e,t)=>{let a=indexedDB.open(jq,2);a.onupgradeneeded=n=>{$q(a.result,n.oldVersion)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}async function Wq(){return Xw()}async function Gq(e){return new Promise((t,a)=>{let o=e.transaction("ids","readonly").objectStore("ids").get(I1);o.onsuccess=()=>t(typeof o.result=="string"?o.result:null),o.onerror=()=>a(o.error)})}async function Xq(e,t){return new Promise((a,n)=>{let i=e.transaction("ids","readwrite").objectStore("ids").put(t,I1);i.onsuccess=()=>a(),i.onerror=()=>n(i.error)})}async function Kq(){if(typeof indexedDB>"u")return null;try{let e=await Wq();try{let t=await Gq(e);if(t)return t;let a=Gw();return await Xq(e,a),a}finally{e.close()}}catch{return null}}function Yq(){try{let e=localStorage.getItem(S1);if(e)return e;let t=Gw();return localStorage.setItem(S1,t),t}catch{return null}}async function C1(){let e=await Kq();if(e)return e;let t=Yq();return t||(Ww||(Ww=Gw()),Ww)}function k1(e,t){return e.match(t)?.[1]??null}function Zq(e){let t=[["Edge",/Edg(?:e|A|iOS)?\/(\S+)/],["Opera",/(?:OPR|Opera)\/(\S+)/],["Samsung Internet",/SamsungBrowser\/(\S+)/],["Firefox",/Firefox\/(\S+)/],["Chrome",/Chrome\/(\S+)/],["Safari",/Version\/(\S+).*Safari/]];for(let[a,n]of t){let r=k1(e,n);if(r)return{name:a,version:r}}return null}function Jq(e){let t=[["iOS",/(?:iPhone|iPad|iPod).+?OS (\d+[_.\d]*)/],["Android",/Android (\d+[.\d]*)/],["macOS",/Mac OS X (\d+[_.\d]*)/],["Windows",/Windows NT (\d+[.\d]*)/],["ChromeOS",/CrOS \S+ (\d+[.\d]*)/],["Linux",/Linux/]];for(let[a,n]of t){let r=k1(e,n);if(r)return{name:a,version:r.replace(/_/g,".")};if(a==="Linux"&&n.test(e))return{name:a,version:""}}return null}function Qq(e){return typeof navigator<"u"&&"userAgentData"in navigator&&navigator.userAgentData?.mobile?"mobile":/iPad|tablet|PlayBook/i.test(e)?"tablet":/Mobi|Android.*Mobile|iPhone|iPod/i.test(e)?"mobile":"desktop"}async function Ic(){let e=navigator.userAgent,t=ma(),a=await C1();return{userAgent:e,browser:Zq(e),os:Jq(e),deviceType:Qq(e),language:navigator.language,languages:[...navigator.languages],timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,screenWidth:screen.width,screenHeight:screen.height,viewportWidth:window.innerWidth,viewportHeight:window.innerHeight,colorDepth:screen.colorDepth,devicePixelRatio:window.devicePixelRatio??1,touchSupport:"ontouchstart"in window||navigator.maxTouchPoints>0,connectionType:navigator.connection?.effectiveType??"unknown",referrer:document.referrer,visitorId:t,memoryUserId:a}}var e4="0.22.1",t4=40,a4=10,n4=6e5;function Yw(){return typeof performance>"u"?0:performance.now()}function Zw(e,t){let a={};return{metrics:a,has:n=>n in a,set(n,r){a[n]=r},mark(n,r=Yw()){if(!(n in a)){a[n]=r-t;try{performance.mark(`waniwani:${e}:${n}`,{startTime:r})}catch{}}}}}function r4(e){let t={};for(let[a,n]of Object.entries(e)){if(Object.keys(t).length>=t4)break;if(!Number.isFinite(n))continue;let r=Math.round(n);r<0||r>n4||(t[a]=r)}return t}function o4(e){let t={};for(let[a,n]of Object.entries(e)){if(Object.keys(t).length>=a4)break;(typeof n=="string"||typeof n=="boolean")&&(t[a]=n)}return t}function i4(){let e=navigator.connection;if(e)return{effectiveType:e.effectiveType,rtt:e.rtt,downlink:e.downlink,saveData:e.saveData}}function jp(e){let t=e?.Authorization;return typeof t=="string"&&t.startsWith("Bearer ")?t.slice(7):void 0}function s4(e,t,a,n){return{kind:e,sdkVersion:e4,channelId:t.channelId||void 0,sessionId:e==="boot"?void 0:t.sessionId||void 0,visitorId:ma(),pageHost:window.location.hostname,connection:i4(),tags:o4(a),metrics:r4(n)}}var Kw,Hp=[];function Jw(e){let t=String(e?.chatTimingLogs).trim().toLowerCase()==="true";Kw=t;let a=Hp;if(Hp=[],t)for(let n of a)n()}function Vp(e,t,a,n){let{api:r,token:o}=t;if(!(typeof window>"u"||!r||!o||Kw===!1))try{let i=s4(e,t,a,n),s=()=>{Ua("timing",i),fetch(Na(r,"/timing"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(i),keepalive:!0}).catch(()=>{})};Kw?s():Hp.length<20&&Hp.push(s)}catch{}}var Wr=Zw("boot",0),T1;function Di(e,t){Wr.mark(e,t)}function $p(e){T1??(T1=e)}var l4=/cdn\.jsdelivr\.net\/npm\/@waniwani\/sdk@[^/]+\/dist\/chat\/embed\.js/,u4=/\/embed\.js(\?|$)/;function c4(){if(typeof performance>"u")return;let e=performance.getEntriesByType("navigation")[0];e?.responseStart&&Wr.mark("navTtfb",e.responseStart),e?.domContentLoadedEventEnd&&Wr.mark("navDomContentLoaded",e.domContentLoadedEventEnd);let t=performance.getEntriesByType("resource");for(let a of t)l4.test(a.name)?(Wr.mark("bundleStart",a.startTime),Wr.mark("bundleEnd",a.responseEnd)):u4.test(a.name)&&(Wr.mark("loaderStart",a.startTime),Wr.mark("loaderEnd",a.responseEnd))}function d4(){if(bI)return!0;try{return document.querySelectorAll('script[src*="@waniwani/sdk"]').length>1}catch{return!1}}function L1(e){c4(),Wr.mark("bundleExecuted",xI),Vp("boot",e,{configSource:T1,mode:e.mode,secondSdk:d4()},Wr.metrics)}var f4=[["text-delta","firstText"],["tool-input-start","firstToolInput"],["tool-output-available","firstToolOutput"]];function E1(e){let t=Zw("turn",Yw());t.set("turnIndex",e);let a=!1;return{mark:n=>t.mark(n),instrument(n){if(!n.ok||!n.body||typeof TransformStream>"u")return n;try{let r=new TextDecoder,o=n.body.pipeThrough(new TransformStream({transform(i,s){t.mark("firstChunk");let l=r.decode(i,{stream:!0});for(let[u,c]of f4)!t.has(c)&&l.includes(u)&&t.mark(c);s.enqueue(i)}}));return new Response(o,{status:n.status,statusText:n.statusText,headers:n.headers})}catch{return n}},report(n,r){a||(a=!0,Vp("turn",n,r,t.metrics))}}}function p4(e){let t=e.indexOf("?");return t===-1?e:e.slice(0,t)}function A1(e,t){let a=Zw("widget",Yw()),n=!1;return{mark:r=>a.mark(r),has:r=>a.has(r),report(r,o){n||(n=!0,a.set("retries",o),t({widget:p4(e),outcome:r,metrics:a.metrics}))}}}var m4="/api/mcp/events/v2/batch",Qw=new Set;function h4(e,t,a){return`${e}|${t}|${a??""}`}function Cc(e){return Fp(e,m4)}async function M1(e){let{api:t,token:a,channelId:n,mode:r,source:o}=e;if(typeof window>"u"||!t||!a)return;let i=Cc(t);if(!i){Ua("page.viewed skipped: the chat api is not a Waniwani endpoint");return}if(!n&&!o){Ua("page.viewed skipped: no channelId or source to attribute it");return}let s=h4(t,a,n);if(!Qw.has(s)){Qw.add(s);try{let l=await Ic(),u=new Date().toISOString(),c=JSON.stringify({sentAt:u,source:{sdk:"@waniwani/sdk",version:"0.1.0"},events:[{id:crypto.randomUUID(),type:"mcp.event",name:"page.viewed",source:o,timestamp:u,correlation:{visitorId:l.visitorId},properties:{channelId:n,mode:r,url:window.location.href,referrer:l.referrer,deviceType:l.deviceType,language:l.language,timezone:l.timezone},metadata:{}}]}),d=fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:c,keepalive:!0});Di("pageViewSent"),await d}catch{Qw.delete(s)}}}function R1(e){let t=Cc(e.api);return t?b1({endpoint:t,token:e.token,channelId:e.channelId,source:e.getSource,identity:()=>({sessionId:e.getSessionId(),visitorId:ma()})}):Wp("the chat api does not point at a Waniwani event ingest")}function Wp(e){let t=!1,a=async()=>(t||(t=!0,console.warn(`[Waniwani] track() is disabled: ${e}`)),{eventId:""});return{track:Object.assign(a,{priceShown:a,pricesCompared:a,optionSelected:a,leadQualified:a,converted:a}),identify:a,flush:async()=>{},shutdown:async()=>({timedOut:!1,pendingEvents:0})}}var Xp=j(Ee());var Gp=(...e)=>e.filter((t,a,n)=>!!t&&t.trim()!==""&&n.indexOf(t)===a).join(" ").trim();var D1=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var _1=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,a,n)=>n?n.toUpperCase():a.toLowerCase());var ev=e=>{let t=_1(e);return t.charAt(0).toUpperCase()+t.slice(1)};var kc=j(Ee());var P1={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 O1=e=>{for(let t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1};var N1=(0,kc.forwardRef)(({color:e="currentColor",size:t=24,strokeWidth:a=2,absoluteStrokeWidth:n,className:r="",children:o,iconNode:i,...s},l)=>(0,kc.createElement)("svg",{ref:l,...P1,width:t,height:t,stroke:e,strokeWidth:n?Number(a)*24/Number(t):a,className:Gp("lucide",r),...!o&&!O1(s)&&{"aria-hidden":"true"},...s},[...i.map(([u,c])=>(0,kc.createElement)(u,c)),...Array.isArray(o)?o:[o]]));var tt=(e,t)=>{let a=(0,Xp.forwardRef)(({className:n,...r},o)=>(0,Xp.createElement)(N1,{ref:o,iconNode:t,className:Gp(`lucide-${D1(ev(e))}`,`lucide-${e}`,n),...r}));return a.displayName=ev(e),a};var g4=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Tc=tt("arrow-down",g4);var y4=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],pr=tt("arrow-up",y4);var w4=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],Lc=tt("check",w4);var v4=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],zo=tt("chevron-down",v4);var x4=[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]],Ec=tt("chevron-right",x4);var b4=[["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"}]],Ac=tt("clipboard-copy",b4);var S4=[["path",{d:"M12 6v6l4 2",key:"mmk7yg"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],Gr=tt("clock",S4);var I4=[["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"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],Mc=tt("file-text",I4);var C4=[["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"}]],vl=tt("file",C4);var k4=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]],Rc=tt("globe",k4);var T4=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Dc=tt("image",T4);var L4=[["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"}]],_c=tt("loader",L4);var E4=[["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"}]],xl=tt("paperclip",E4);var A4=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Pc=tt("square",A4);var M4=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],_i=tt("wrench",M4);var R4=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],wn=tt("x",R4);var D4=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Oc=tt("zap",D4);var rt=j(Ee(),1),qB=j(gg(),1);var bl=j(Ee(),1),Nc=j(me(),1);function O4(e){return 1-(1-e)**3}function N4({start:e=0,end:t=100,duration:a=1e3,delay:n=0,ease:r=O4,onUpdate:o,onEnd:i}){let s=performance.now()+n;function l(){let u=performance.now()-s,c=Math.min(u/a,1);o(e+(t-e)*r(c)),c<1?requestAnimationFrame(l):i&&i()}setTimeout(()=>requestAnimationFrame(l),n)}var U4=["80% 55%","69% 34%","8% 6%","41% 38%","86% 85%","82% 18%","51% 4%"],B4=[0,1,2,0,1,2,1];function z4(e){let t=[];for(let a=0;a<7;a++){let n=e[Math.min(B4[a],e.length-1)];t.push(`radial-gradient(at ${U4[a]}, ${n} 0px, transparent 50%)`)}return t.push(`linear-gradient(${e[0]} 0 100%)`),t}var F4=({children:e,className:t="",style:a,edgeSensitivity:n=30,backgroundColor:r="#120F17",borderRadius:o=28,coneSpread:i=25,animated:s=!1,colors:l=["#c084fc","#f472b6","#38bdf8"]})=>{let[u,c]=(0,bl.useState)(110),[d,p]=(0,bl.useState)(0),[m,h]=(0,bl.useState)(!1);(0,bl.useEffect)(()=>{if(!s)return;let E=110;h(!0),c(E),N4({ease:T=>T,duration:2e3,onUpdate:T=>{let R=T/100;c(E+360*R);let O=Math.min(R/.1,1),U=R>.85?(1-R)/.15:1;p(Math.min(O,U))},onEnd:()=>h(!1)})},[s]);let v=n+20,I=m?Math.max(0,(d*100-v)/(100-v)):0,w=z4(l).map(E=>`${E} border-box`),S=`conic-gradient(from ${`${u.toFixed(3)}deg`} at center, black ${i}%, transparent ${i+15}%, transparent ${100-i-15}%, black ${100-i}%)`;return(0,Nc.jsxs)("div",{className:`ww:relative ww:grid ww:isolate ww:border ${t}`,style:{background:r,borderRadius:typeof o=="number"?`${o}px`:o,transform:"translate3d(0, 0, 0.01px)",...a},children:[(0,Nc.jsx)("div",{className:"ww:absolute ww:inset-0 ww:rounded-[inherit] ww:-z-[1]",style:{border:"1px solid transparent",background:[`linear-gradient(${r} 0 100%) padding-box`,"linear-gradient(rgb(255 255 255 / 0%) 0% 100%) border-box",...w].join(", "),opacity:I,maskImage:S,WebkitMaskImage:S,transition:m?"opacity 0.25s ease-out":"opacity 0.75s ease-in-out"}}),(0,Nc.jsx)("div",{className:"ww:flex ww:flex-col ww:relative ww:overflow-auto ww:z-[1]",children:e})]})},Yp=F4;tv();nv();var q4=q1({prefix:"ww"});function V(...e){return q4(Zp(e))}var Uc=j(me(),1);function Sl({suggestions:e,isLoading:t,onSelect:a,align:n="start",className:r,...o}){return e.length===0&&!t?null:(0,Uc.jsx)("div",{className:V("ww:px-4 ww:py-2",r),...o,children:(0,Uc.jsx)("div",{className:V("ww:mx-auto ww:w-full ww:max-w-3xl ww:flex ww:flex-wrap ww:gap-2",n==="center"&&"ww:justify-center"),children:t?[0,1,2].map(i=>(0,Uc.jsx)("div",{className:"ww:h-8 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+i*20}px`}},i)):e.map((i,s)=>(0,Uc.jsx)("button",{type:"button",onClick:()=>a(i),className:V("ww:rounded-full ww:border ww:border-border ww:bg-accent ww:px-3.5 ww:py-1.5 ww:text-sm","ww:text-foreground ww:hover:bg-border 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:`${s*50}ms`},children:i},i))})})}var gm=j(Ee(),1);var gL="vercel.ai.error",H4=Symbol.for(gL),H1,j1,Je=class yL extends(j1=Error,H1=H4,j1){constructor({name:t,message:a,cause:n}){super(a),this[H1]=!0,this.name=t,this.cause=n}static isInstance(t){return yL.hasMarker(t,gL)}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}},wL="AI_APICallError",vL=`vercel.ai.error.${wL}`,j4=Symbol.for(vL),V1,$1,GQ=class extends($1=Je,V1=j4,$1){constructor({message:e,url:t,requestBodyValues:a,statusCode:n,responseHeaders:r,responseBody:o,cause:i,isRetryable:s=n!=null&&(n===408||n===409||n===429||n>=500),data:l}){super({name:wL,message:e,cause:i}),this[V1]=!0,this.url=t,this.requestBodyValues=a,this.statusCode=n,this.responseHeaders=r,this.responseBody=o,this.isRetryable=s,this.data=l}static isInstance(e){return Je.hasMarker(e,vL)}},xL="AI_EmptyResponseBodyError",bL=`vercel.ai.error.${xL}`,V4=Symbol.for(bL),W1,G1,XQ=class extends(G1=Je,W1=V4,G1){constructor({message:e="Empty response body"}={}){super({name:xL,message:e}),this[W1]=!0}static isInstance(e){return Je.hasMarker(e,bL)}};function SL(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var IL="AI_InvalidArgumentError",CL=`vercel.ai.error.${IL}`,$4=Symbol.for(CL),X1,K1,kL=class extends(K1=Je,X1=$4,K1){constructor({message:e,cause:t,argument:a}){super({name:IL,message:e,cause:t}),this[X1]=!0,this.argument=a}static isInstance(e){return Je.hasMarker(e,CL)}},TL="AI_InvalidPromptError",LL=`vercel.ai.error.${TL}`,W4=Symbol.for(LL),Y1,Z1,KQ=class extends(Z1=Je,Y1=W4,Z1){constructor({prompt:e,message:t,cause:a}){super({name:TL,message:`Invalid prompt: ${t}`,cause:a}),this[Y1]=!0,this.prompt=e}static isInstance(e){return Je.hasMarker(e,LL)}},EL="AI_InvalidResponseDataError",AL=`vercel.ai.error.${EL}`,G4=Symbol.for(AL),J1,Q1,YQ=class extends(Q1=Je,J1=G4,Q1){constructor({data:e,message:t=`Invalid response data: ${JSON.stringify(e)}.`}){super({name:EL,message:t}),this[J1]=!0,this.data=e}static isInstance(e){return Je.hasMarker(e,AL)}},ML="AI_JSONParseError",RL=`vercel.ai.error.${ML}`,X4=Symbol.for(RL),eL,tL,ov=class extends(tL=Je,eL=X4,tL){constructor({text:e,cause:t}){super({name:ML,message:`JSON parsing failed: Text: ${e}.
|
|
122
122
|
Error message: ${SL(t)}`,cause:t}),this[eL]=!0,this.text=e}static isInstance(e){return Je.hasMarker(e,RL)}},DL="AI_LoadAPIKeyError",_L=`vercel.ai.error.${DL}`,K4=Symbol.for(_L),aL,nL,ZQ=class extends(nL=Je,aL=K4,nL){constructor({message:e}){super({name:DL,message:e}),this[aL]=!0}static isInstance(e){return Je.hasMarker(e,_L)}},PL="AI_LoadSettingError",OL=`vercel.ai.error.${PL}`,Y4=Symbol.for(OL),rL,oL,JQ=class extends(oL=Je,rL=Y4,oL){constructor({message:e}){super({name:PL,message:e}),this[rL]=!0}static isInstance(e){return Je.hasMarker(e,OL)}},NL="AI_NoContentGeneratedError",UL=`vercel.ai.error.${NL}`,Z4=Symbol.for(UL),iL,sL,QQ=class extends(sL=Je,iL=Z4,sL){constructor({message:e="No content generated."}={}){super({name:NL,message:e}),this[iL]=!0}static isInstance(e){return Je.hasMarker(e,UL)}},BL="AI_NoSuchModelError",zL=`vercel.ai.error.${BL}`,J4=Symbol.for(zL),lL,uL,eee=class extends(uL=Je,lL=J4,uL){constructor({errorName:e=BL,modelId:t,modelType:a,message:n=`No such ${a}: ${t}`}){super({name:e,message:n}),this[lL]=!0,this.modelId=t,this.modelType=a}static isInstance(e){return Je.hasMarker(e,zL)}},FL="AI_TooManyEmbeddingValuesForCallError",qL=`vercel.ai.error.${FL}`,Q4=Symbol.for(qL),cL,dL,tee=class extends(dL=Je,cL=Q4,dL){constructor(e){super({name:FL,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[cL]=!0,this.provider=e.provider,this.modelId=e.modelId,this.maxEmbeddingsPerCall=e.maxEmbeddingsPerCall,this.values=e.values}static isInstance(e){return Je.hasMarker(e,qL)}},HL="AI_TypeValidationError",jL=`vercel.ai.error.${HL}`,e5=Symbol.for(jL),fL,pL,Kn=class rv extends(pL=Je,fL=e5,pL){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:HL,message:`${r}: Value: ${JSON.stringify(t)}.
|
|
123
123
|
Error message: ${SL(a)}`,cause:a}),this[fL]=!0,this.value=t,this.context=n}static isInstance(t){return Je.hasMarker(t,jL)}static wrap({value:t,cause:a,context:n}){var r,o,i;return rv.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&&((i=a.context)==null?void 0:i.entityId)===n?.entityId?a:new rv({value:t,cause:a,context:n})}},VL="AI_UnsupportedFunctionalityError",$L=`vercel.ai.error.${VL}`,t5=Symbol.for($L),mL,hL,aee=class extends(hL=Je,mL=t5,hL){constructor({functionality:e,message:t=`'${e}' functionality not supported.`}){super({name:VL,message:t}),this[mL]=!0,this.functionality=e}static isInstance(e){return Je.hasMarker(e,$L)}};var Jp=()=>sv,sv=new Proxy(Jp,{get(e,t){return t==="parse"||t==="parseAsync"?a=>a:t==="safeParse"||t==="safeParseAsync"?a=>({success:!0,data:a}):t==="_def"?{}:t==="jsonSchema"?{}:Jp},apply(){return sv}}),iv=class extends Error{constructor(){super(...arguments);K(this,"issues",[])}},f=new Proxy(Jp,{get(e,t){return t==="ZodError"?iv:t==="NEVER"?Symbol("NEVER"):Jp},apply(){return sv}});var Me={};var Qp=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 lv(e){}function WL(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=lv,onError:a=lv,onRetry:n=lv,onComment:r}=e,o="",i=!0,s,l="",u="";function c(v){let I=i?v.replace(/^\xEF\xBB\xBF/,""):v,[y,w]=a5(`${o}${I}`);for(let g of y)d(g);o=w,i=!1}function d(v){if(v===""){m();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),w=v[I+1]===" "?2:1,g=v.slice(I+w);p(y,g,v);return}p(v,"",v)}function p(v,I,y){switch(v){case"event":u=I;break;case"data":l=`${l}${I}
|
|
124
124
|
`;break;case"id":s=I.includes("\0")?void 0:I;break;case"retry":/^\d+$/.test(I)?n(parseInt(I,10)):a(new Qp(`Invalid \`retry\` value: "${I}"`,{type:"invalid-retry",value:I,line:y}));break;default:a(new Qp(`Unknown field "${v.length>20?`${v.slice(0,20)}\u2026`:v}"`,{type:"unknown-field",field:v,value:I,line:y}));break}}function m(){l.length>0&&t({id:s,event:u||void 0,data:l.endsWith(`
|