@waniwani/sdk 0.12.15 → 0.12.16

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.
@@ -381,6 +381,8 @@ interface ChatHandle {
381
381
  focus: () => void;
382
382
  /** Current chat messages */
383
383
  messages: ai.UIMessage[];
384
+ /** Session ID used for event correlation. Available after the first message. */
385
+ sessionId: string | undefined;
384
386
  }
385
387
 
386
388
  /** @deprecated Use `WaniwaniChat` (hosted, React) or the `<script>` embed for new code. `ChatCard` is preserved for back-compat only and lives under `@waniwani/sdk/legacy`. */
@@ -13,7 +13,7 @@ import{a as Br,b as Dr,c as Er,d as it,e as lt,f as ea,g as _r,h as Nr,i as Or,j
13
13
  `}));let x={type:"element",tagName:"span",properties:{class:"line"},children:[]},g=0;for(let h of C){let L={type:"element",tagName:"span",properties:{...h.htmlAttrs},children:[{type:"text",value:h.content}]},y=qo(h.htmlStyle||Ra(h));y&&(L.properties.style=y);for(let k of r)L=k?.span?.call(c,L,w+1,g,x,h)||L;i==="inline"?n.children.push(L):i==="classic"&&x.children.push(L),g+=h.content.length}if(i==="classic"){for(let h of r)x=h?.line?.call(c,x,w+1)||x;p.push(x),s.push(x)}else i==="inline"&&p.push(x)}),i==="classic"){for(let C of r)d=C?.code?.call(c,d)||d;f.children.push(d);for(let C of r)f=C?.pre?.call(c,f)||f;n.children.push(f)}else if(i==="inline"){let C=[],w={type:"element",tagName:"span",properties:{class:"line"},children:[]};for(let h of n.children)h.type==="element"&&h.tagName==="br"?(C.push(w),w={type:"element",tagName:"span",properties:{class:"line"},children:[]}):(h.type==="element"||h.type==="text")&&w.children.push(h);C.push(w);let g={type:"element",tagName:"code",properties:{},children:C};for(let h of r)g=h?.code?.call(c,g)||g;n.children=[];for(let h=0;h<g.children.length;h++){h>0&&n.children.push({type:"element",tagName:"br",properties:{},children:[]});let L=g.children[h];L.type==="element"&&n.children.push(...L.children)}}let m=n;for(let C of r)m=C?.root?.call(c,m)||m;return o&&_a(m,o),m}function Df(e){return e.map(t=>{let a=[],o="",r;return t.forEach((s,n)=>{let l=!(s.fontStyle&&(s.fontStyle&de.Underline||s.fontStyle&de.Strikethrough));l&&s.content.match(/^\s+$/)&&t[n+1]?(r===void 0&&(r=s.offset),o+=s.content):o?(l?a.push({...s,offset:r,content:o+s.content}):a.push({content:o,offset:r},s),r=void 0,o=""):a.push(s)}),a})}function Ef(e){return e.map(t=>t.flatMap(a=>{if(a.content.match(/^\s+$/))return a;let o=a.content.match(/^(\s*)(.*?)(\s*)$/);if(!o)return a;let[,r,s,n]=o;if(!r&&!n)return a;let i=[{...a,offset:a.offset+r.length,content:s}];return r&&i.unshift({content:r,offset:a.offset}),n&&i.push({content:n,offset:a.offset+r.length+s.length}),i}))}function _f(e){return e.map(t=>{let a=[];for(let o of t){if(a.length===0){a.push({...o});continue}let r=a[a.length-1],s=qo(r.htmlStyle||Ra(r)),n=qo(o.htmlStyle||Ra(o)),i=r.fontStyle&&(r.fontStyle&de.Underline||r.fontStyle&de.Strikethrough),l=o.fontStyle&&(o.fontStyle&de.Underline||o.fontStyle&de.Strikethrough);!i&&!l&&s===n?r.content+=o.content:a.push({...o})}return a})}var Nf=Oo;function Of(e,t,a){let o={meta:{},options:a,codeToHast:(s,n)=>Da(e,s,n),codeToTokens:(s,n)=>Ba(e,s,n)},r=Nf(Da(e,t,a,o));for(let s of Fa(a))r=s.postprocess?.call(o,r,a)||r;return r}var Rn={light:"#333333",dark:"#bbbbbb"},Fn={light:"#fffffe",dark:"#1e1e1e"},Bn="__shiki_resolved";function Qo(e){if(e?.[Bn])return e;let t={...e};t.tokenColors&&!t.settings&&(t.settings=t.tokenColors,delete t.tokenColors),t.type||="dark",t.colorReplacements={...t.colorReplacements},t.settings||=[];let{bg:a,fg:o}=t;if(!a||!o){let i=t.settings?t.settings.find(l=>!l.name&&!l.scope):void 0;i?.settings?.foreground&&(o=i.settings.foreground),i?.settings?.background&&(a=i.settings.background),!o&&t?.colors?.["editor.foreground"]&&(o=t.colors["editor.foreground"]),!a&&t?.colors?.["editor.background"]&&(a=t.colors["editor.background"]),o||(o=t.type==="light"?Rn.light:Rn.dark),a||(a=t.type==="light"?Fn.light:Fn.dark),t.fg=o,t.bg=a}t.settings[0]&&t.settings[0].settings&&!t.settings[0].scope||t.settings.unshift({settings:{foreground:t.fg,background:t.bg}});let r=0,s=new Map;function n(i){if(s.has(i))return s.get(i);r+=1;let l=`#${r.toString(16).padStart(8,"0").toLowerCase()}`;return t.colorReplacements?.[`#${l}`]?n(i):(s.set(i,l),l)}t.settings=t.settings.map(i=>{let l=i.settings?.foreground&&!i.settings.foreground.startsWith("#"),u=i.settings?.background&&!i.settings.background.startsWith("#");if(!l&&!u)return i;let f={...i,settings:{...i.settings}};if(l){let d=n(i.settings.foreground);t.colorReplacements[d]=i.settings.foreground,f.settings.foreground=d}if(u){let d=n(i.settings.background);t.colorReplacements[d]=i.settings.background,f.settings.background=d}return f});for(let i of Object.keys(t.colors||{}))if((i==="editor.foreground"||i==="editor.background"||i.startsWith("terminal.ansi"))&&!t.colors[i]?.startsWith("#")){let l=n(t.colors[i]);t.colorReplacements[l]=t.colors[i],t.colors[i]=l}return Object.defineProperty(t,Bn,{enumerable:!1,writable:!1,value:!0}),t}async function Gn(e){return Array.from(new Set((await Promise.all(e.filter(t=>!En(t)).map(async t=>await Dn(t).then(a=>Array.isArray(a)?a:[a])))).flat()))}async function Wn(e){return(await Promise.all(e.map(async a=>_n(a)?null:Qo(await Dn(a))))).filter(a=>!!a)}var Ho=3,Uf=!1;function Hf(e,t=3){if(Ho&&!(typeof Ho=="number"&&t>Ho)){if(Uf)throw new Error(`[SHIKI DEPRECATE]: ${e}`);console.trace(`[SHIKI DEPRECATE]: ${e}`)}}var Ve=class extends Error{constructor(t){super(t),this.name="ShikiError"}};function zn(e,t){if(!t)return e;if(t[e]){let a=new Set([e]);for(;t[e];){if(e=t[e],a.has(e))throw new Ve(`Circular alias \`${Array.from(a).join(" -> ")} -> ${e}\``);a.add(e)}}return e}var Go=class extends ln{constructor(t,a,o,r={}){super(t),this._resolver=t,this._themes=a,this._langs=o,this._alias=r,this._themes.map(s=>this.loadTheme(s)),this.loadLanguages(this._langs)}_resolvedThemes=new Map;_resolvedGrammars=new Map;_langMap=new Map;_langGraph=new Map;_textmateThemeCache=new WeakMap;_loadedThemesCache=null;_loadedLanguagesCache=null;getTheme(t){return typeof t=="string"?this._resolvedThemes.get(t):this.loadTheme(t)}loadTheme(t){let a=Qo(t);return a.name&&(this._resolvedThemes.set(a.name,a),this._loadedThemesCache=null),a}getLoadedThemes(){return this._loadedThemesCache||(this._loadedThemesCache=[...this._resolvedThemes.keys()]),this._loadedThemesCache}setTheme(t){let a=this._textmateThemeCache.get(t);a||(a=Nt.createFromRawTheme(t),this._textmateThemeCache.set(t,a)),this._syncRegistry.setTheme(a)}getGrammar(t){return t=zn(t,this._alias),this._resolvedGrammars.get(t)}loadLanguage(t){if(this.getGrammar(t.name))return;let a=new Set([...this._langMap.values()].filter(s=>s.embeddedLangsLazy?.includes(t.name)));this._resolver.addLanguage(t);let o={balancedBracketSelectors:t.balancedBracketSelectors||["*"],unbalancedBracketSelectors:t.unbalancedBracketSelectors||[]};this._syncRegistry._rawGrammars.set(t.scopeName,t);let r=this.loadGrammarWithConfiguration(t.scopeName,1,o);if(r.name=t.name,this._resolvedGrammars.set(t.name,r),t.aliases&&t.aliases.forEach(s=>{this._alias[s]=t.name}),this._loadedLanguagesCache=null,a.size)for(let s of a)this._resolvedGrammars.delete(s.name),this._loadedLanguagesCache=null,this._syncRegistry?._injectionGrammars?.delete(s.scopeName),this._syncRegistry?._grammars?.delete(s.scopeName),this.loadLanguage(this._langMap.get(s.name))}dispose(){super.dispose(),this._resolvedThemes.clear(),this._resolvedGrammars.clear(),this._langMap.clear(),this._langGraph.clear(),this._loadedThemesCache=null}loadLanguages(t){for(let r of t)this.resolveEmbeddedLanguages(r);let a=Array.from(this._langGraph.entries()),o=a.filter(([r,s])=>!s);if(o.length){let r=a.filter(([s,n])=>n?(n.embeddedLanguages||n.embeddedLangs)?.some(l=>o.map(([u])=>u).includes(l)):!1).filter(s=>!o.includes(s));throw new Ve(`Missing languages ${o.map(([s])=>`\`${s}\``).join(", ")}, required by ${r.map(([s])=>`\`${s}\``).join(", ")}`)}for(let[r,s]of a)this._resolver.addLanguage(s);for(let[r,s]of a)this.loadLanguage(s)}getLoadedLanguages(){return this._loadedLanguagesCache||(this._loadedLanguagesCache=[...new Set([...this._resolvedGrammars.keys(),...Object.keys(this._alias)])]),this._loadedLanguagesCache}resolveEmbeddedLanguages(t){this._langMap.set(t.name,t),this._langGraph.set(t.name,t);let a=t.embeddedLanguages??t.embeddedLangs;if(a)for(let o of a)this._langGraph.set(o,this._langMap.get(o))}},Wo=class{_langs=new Map;_scopeToLang=new Map;_injections=new Map;_onigLib;constructor(t,a){this._onigLib={createOnigScanner:o=>t.createScanner(o),createOnigString:o=>t.createString(o)},a.forEach(o=>this.addLanguage(o))}get onigLib(){return this._onigLib}getLangRegistration(t){return this._langs.get(t)}loadGrammar(t){return this._scopeToLang.get(t)}addLanguage(t){this._langs.set(t.name,t),t.aliases&&t.aliases.forEach(a=>{this._langs.set(a,t)}),this._scopeToLang.set(t.scopeName,t),t.injectTo&&t.injectTo.forEach(a=>{this._injections.get(a)||this._injections.set(a,[]),this._injections.get(a).push(t.scopeName)})}getInjections(t){let a=t.split("."),o=[];for(let r=1;r<=a.length;r++){let s=a.slice(0,r).join(".");o=[...o,...this._injections.get(s)||[]]}return o}},Wt=0;function qf(e){Wt+=1,e.warnings!==!1&&Wt>=10&&Wt%10===0&&console.warn(`[Shiki] ${Wt} instances have been created. Shiki is supposed to be used as a singleton, consider refactoring your code to cache your highlighter instance; Or call \`highlighter.dispose()\` to release unused instances.`);let t=!1;if(!e.engine)throw new Ve("`engine` option is required for synchronous mode");let a=(e.langs||[]).flat(1),o=(e.themes||[]).flat(1).map(Qo),r=new Wo(e.engine,a),s=new Go(r,o,a,e.langAlias),n;function i(h){return zn(h,e.langAlias)}function l(h){x();let L=s.getGrammar(typeof h=="string"?h:h.name);if(!L)throw new Ve(`Language \`${h}\` not found, you may need to load it first`);return L}function u(h){if(h==="none")return{bg:"",fg:"",name:"none",settings:[],type:"dark"};x();let L=s.getTheme(h);if(!L)throw new Ve(`Theme \`${h}\` not found, you may need to load it first`);return L}function f(h){x();let L=u(h);n!==h&&(s.setTheme(L),n=h);let y=s.getColorMap();return{theme:L,colorMap:y}}function d(){return x(),s.getLoadedThemes()}function p(){return x(),s.getLoadedLanguages()}function c(...h){x(),s.loadLanguages(h.flat(1))}async function m(...h){return c(await Gn(h))}function C(...h){x();for(let L of h.flat(1))s.loadTheme(L)}async function w(...h){return x(),C(await Wn(h))}function x(){if(t)throw new Ve("Shiki instance has been disposed")}function g(){t||(t=!0,s.dispose(),Wt-=1)}return{setTheme:f,getTheme:u,getLanguage:l,getLoadedThemes:d,getLoadedLanguages:p,resolveLangAlias:i,loadLanguage:m,loadLanguageSync:c,loadTheme:w,loadThemeSync:C,dispose:g,[Symbol.dispose]:g}}async function Gf(e){e.engine||Hf("`engine` option is required. Use `createOnigurumaEngine` or `createJavaScriptRegexEngine` to create an engine.");let[t,a,o]=await Promise.all([Wn(e.themes||[]),Gn(e.langs||[]),e.engine]);return qf({...e,themes:t,langs:a,engine:o})}async function Wf(e){let t=await Gf(e);return{getLastGrammarState:(...a)=>Tf(t,...a),codeToTokensBase:(a,o)=>$o(t,a,o),codeToTokensWithThemes:(a,o)=>qn(t,a,o),codeToTokens:(a,o)=>Ba(t,a,o),codeToHast:(a,o)=>Da(t,a,o),codeToHtml:(a,o)=>Of(t,a,o),getBundledLanguages:()=>({}),getBundledThemes:()=>({}),...t,getInternalContext:()=>t}}function Vn(e){let t=e.langs,a=e.themes,o=e.engine;async function r(s){function n(d){if(typeof d=="string"){if(d=s.langAlias?.[d]||d,En(d))return[];let p=t[d];if(!p)throw new K(`Language \`${d}\` is not included in this bundle. You may want to load it from external source.`);return p}return d}function i(d){if(_n(d))return"none";if(typeof d=="string"){let p=a[d];if(!p)throw new K(`Theme \`${d}\` is not included in this bundle. You may want to load it from external source.`);return p}return d}let l=(s.themes??[]).map(d=>i(d)),u=(s.langs??[]).map(d=>n(d)),f=await Wf({engine:s.engine??o(),...s,themes:l,langs:u});return{...f,loadLanguage(...d){return f.loadLanguage(...d.map(n))},loadTheme(...d){return f.loadTheme(...d.map(i))},getBundledLanguages(){return t},getBundledThemes(){return a}}}return r}function zf(e){let t;async function a(o={}){if(t){let r=await t;return await Promise.all([r.loadTheme(...o.themes||[]),r.loadLanguage(...o.langs||[])]),r}else{t=e({...o,themes:[],langs:[]});let r=await t;return await Promise.all([r.loadTheme(...o.themes||[]),r.loadLanguage(...o.langs||[])]),r}}return a}function jn(e,t){let a=zf(e);async function o(r,s){let n=await a({langs:[s.lang],themes:"theme"in s?[s.theme]:Object.values(s.themes)}),i=await t?.guessEmbeddedLanguages?.(r,s.lang,n);return i&&await n.loadLanguage(...i),n}return{getSingletonHighlighter(r){return a(r)},async codeToHtml(r,s){return(await o(r,s)).codeToHtml(r,s)},async codeToHast(r,s){return(await o(r,s)).codeToHast(r,s)},async codeToTokens(r,s){return(await o(r,s)).codeToTokens(r,s)},async codeToTokensBase(r,s){return(await o(r,s)).codeToTokensBase(r,s)},async codeToTokensWithThemes(r,s){return(await o(r,s)).codeToTokensWithThemes(r,s)},async getLastGrammarState(r,s){return(await a({langs:[s.lang],themes:[s.theme]})).getLastGrammarState(r,s)}}}var Ko=[{id:"abap",name:"ABAP",import:(()=>import("../abap-KGVIZMDC.js"))},{id:"actionscript-3",name:"ActionScript",import:(()=>import("../actionscript-3-2UHK5QYP.js"))},{id:"ada",name:"Ada",import:(()=>import("../ada-JKTWR5BV.js"))},{id:"angular-html",name:"Angular HTML",import:(()=>import("../angular-html-EOIKHM3D.js"))},{id:"angular-ts",name:"Angular TypeScript",import:(()=>import("../angular-ts-A7ZNTSV6.js"))},{id:"apache",name:"Apache Conf",import:(()=>import("../apache-MPGFGQFB.js"))},{id:"apex",name:"Apex",import:(()=>import("../apex-BOAZL66Z.js"))},{id:"apl",name:"APL",import:(()=>import("../apl-QBN4KIYA.js"))},{id:"applescript",name:"AppleScript",import:(()=>import("../applescript-C4CJ3STL.js"))},{id:"ara",name:"Ara",import:(()=>import("../ara-FSFFBRSD.js"))},{id:"asciidoc",name:"AsciiDoc",aliases:["adoc"],import:(()=>import("../asciidoc-QQK2LANG.js"))},{id:"asm",name:"Assembly",import:(()=>import("../asm-X43A2VYW.js"))},{id:"astro",name:"Astro",import:(()=>import("../astro-OQUOYMBE.js"))},{id:"awk",name:"AWK",import:(()=>import("../awk-4Z3PRTF7.js"))},{id:"ballerina",name:"Ballerina",import:(()=>import("../ballerina-JCXSJ2QD.js"))},{id:"bat",name:"Batch File",aliases:["batch"],import:(()=>import("../bat-XFWR7RMZ.js"))},{id:"beancount",name:"Beancount",import:(()=>import("../beancount-7BBDB4BH.js"))},{id:"berry",name:"Berry",aliases:["be"],import:(()=>import("../berry-PQ2BEJIZ.js"))},{id:"bibtex",name:"BibTeX",import:(()=>import("../bibtex-J2PAB23I.js"))},{id:"bicep",name:"Bicep",import:(()=>import("../bicep-TNKT6R3W.js"))},{id:"blade",name:"Blade",import:(()=>import("../blade-QBDEYXMB.js"))},{id:"bsl",name:"1C (Enterprise)",aliases:["1c"],import:(()=>import("../bsl-PQW6E45S.js"))},{id:"c",name:"C",import:(()=>import("../c-PZBJFNXE.js"))},{id:"c3",name:"C3",import:(()=>import("../c3-GP7XYHE6.js"))},{id:"cadence",name:"Cadence",aliases:["cdc"],import:(()=>import("../cadence-NABGDHKY.js"))},{id:"cairo",name:"Cairo",import:(()=>import("../cairo-WQSC2GLN.js"))},{id:"clarity",name:"Clarity",import:(()=>import("../clarity-NXNSINKX.js"))},{id:"clojure",name:"Clojure",aliases:["clj"],import:(()=>import("../clojure-Y57BKRMA.js"))},{id:"cmake",name:"CMake",import:(()=>import("../cmake-LVMEA3JZ.js"))},{id:"cobol",name:"COBOL",import:(()=>import("../cobol-6DNJTKH3.js"))},{id:"codeowners",name:"CODEOWNERS",import:(()=>import("../codeowners-JYHOTXQS.js"))},{id:"codeql",name:"CodeQL",aliases:["ql"],import:(()=>import("../codeql-IWWSYR3L.js"))},{id:"coffee",name:"CoffeeScript",aliases:["coffeescript"],import:(()=>import("../coffee-NNDQ5QXC.js"))},{id:"common-lisp",name:"Common Lisp",aliases:["lisp"],import:(()=>import("../common-lisp-JKXCDYH3.js"))},{id:"coq",name:"Coq",import:(()=>import("../coq-BEHPNP64.js"))},{id:"cpp",name:"C++",aliases:["c++"],import:(()=>import("../cpp-IALOHSZA.js"))},{id:"crystal",name:"Crystal",import:(()=>import("../crystal-ZDP3FIUI.js"))},{id:"csharp",name:"C#",aliases:["c#","cs"],import:(()=>import("../csharp-ODFBXRGA.js"))},{id:"css",name:"CSS",import:(()=>import("../css-CJGL5AVH.js"))},{id:"csv",name:"CSV",import:(()=>import("../csv-LIK4TU3Z.js"))},{id:"cue",name:"CUE",import:(()=>import("../cue-UAAEAKHI.js"))},{id:"cypher",name:"Cypher",aliases:["cql"],import:(()=>import("../cypher-SZPVUQZJ.js"))},{id:"d",name:"D",import:(()=>import("../d-VSCA3XHG.js"))},{id:"dart",name:"Dart",import:(()=>import("../dart-A4PE6FIS.js"))},{id:"dax",name:"DAX",import:(()=>import("../dax-TILIKSFB.js"))},{id:"desktop",name:"Desktop",import:(()=>import("../desktop-75KK3D55.js"))},{id:"diff",name:"Diff",import:(()=>import("../diff-HOT6P45M.js"))},{id:"docker",name:"Dockerfile",aliases:["dockerfile"],import:(()=>import("../docker-FF35TY6T.js"))},{id:"dotenv",name:"dotEnv",import:(()=>import("../dotenv-FVPPHJI3.js"))},{id:"dream-maker",name:"Dream Maker",import:(()=>import("../dream-maker-SYE3ZPSJ.js"))},{id:"edge",name:"Edge",import:(()=>import("../edge-CCLQ2CKA.js"))},{id:"elixir",name:"Elixir",import:(()=>import("../elixir-F6DQGRKA.js"))},{id:"elm",name:"Elm",import:(()=>import("../elm-5QRQXDZ6.js"))},{id:"emacs-lisp",name:"Emacs Lisp",aliases:["elisp"],import:(()=>import("../emacs-lisp-NJ4S4OHV.js"))},{id:"erb",name:"ERB",import:(()=>import("../erb-HGSLHT5Y.js"))},{id:"erlang",name:"Erlang",aliases:["erl"],import:(()=>import("../erlang-APEONNZ6.js"))},{id:"fennel",name:"Fennel",import:(()=>import("../fennel-7OCMFVPS.js"))},{id:"fish",name:"Fish",import:(()=>import("../fish-BC46ME2N.js"))},{id:"fluent",name:"Fluent",aliases:["ftl"],import:(()=>import("../fluent-MXZS6EX3.js"))},{id:"fortran-fixed-form",name:"Fortran (Fixed Form)",aliases:["f","for","f77"],import:(()=>import("../fortran-fixed-form-35BC2KX6.js"))},{id:"fortran-free-form",name:"Fortran (Free Form)",aliases:["f90","f95","f03","f08","f18"],import:(()=>import("../fortran-free-form-AXRAI2HH.js"))},{id:"fsharp",name:"F#",aliases:["f#","fs"],import:(()=>import("../fsharp-JKNSQXHD.js"))},{id:"gdresource",name:"GDResource",aliases:["tscn","tres"],import:(()=>import("../gdresource-ZMKZGPZV.js"))},{id:"gdscript",name:"GDScript",aliases:["gd"],import:(()=>import("../gdscript-HNCVXEYB.js"))},{id:"gdshader",name:"GDShader",import:(()=>import("../gdshader-XAJ4QRYP.js"))},{id:"genie",name:"Genie",import:(()=>import("../genie-HEFVQZAP.js"))},{id:"gherkin",name:"Gherkin",import:(()=>import("../gherkin-OFBRDPXX.js"))},{id:"git-commit",name:"Git Commit Message",import:(()=>import("../git-commit-ZE2M3Q5H.js"))},{id:"git-rebase",name:"Git Rebase Message",import:(()=>import("../git-rebase-3N3INGLU.js"))},{id:"gleam",name:"Gleam",import:(()=>import("../gleam-NFFQFQLP.js"))},{id:"glimmer-js",name:"Glimmer JS",aliases:["gjs"],import:(()=>import("../glimmer-js-RSUW6JYN.js"))},{id:"glimmer-ts",name:"Glimmer TS",aliases:["gts"],import:(()=>import("../glimmer-ts-EZGWLX5T.js"))},{id:"glsl",name:"GLSL",import:(()=>import("../glsl-VJLRYEVJ.js"))},{id:"gn",name:"GN",import:(()=>import("../gn-UH2XQWLG.js"))},{id:"gnuplot",name:"Gnuplot",import:(()=>import("../gnuplot-K6IV6NNR.js"))},{id:"go",name:"Go",import:(()=>import("../go-BDV7RR5G.js"))},{id:"graphql",name:"GraphQL",aliases:["gql"],import:(()=>import("../graphql-YEJQLMOO.js"))},{id:"groovy",name:"Groovy",import:(()=>import("../groovy-SX7K3XGL.js"))},{id:"hack",name:"Hack",import:(()=>import("../hack-3TGPQNR2.js"))},{id:"haml",name:"Ruby Haml",import:(()=>import("../haml-335RVEQR.js"))},{id:"handlebars",name:"Handlebars",aliases:["hbs"],import:(()=>import("../handlebars-73IS6B2J.js"))},{id:"haskell",name:"Haskell",aliases:["hs"],import:(()=>import("../haskell-P5PTJARU.js"))},{id:"haxe",name:"Haxe",import:(()=>import("../haxe-RCPSSA3N.js"))},{id:"hcl",name:"HashiCorp HCL",import:(()=>import("../hcl-AKKZAVC2.js"))},{id:"hjson",name:"Hjson",import:(()=>import("../hjson-REXV6F6N.js"))},{id:"hlsl",name:"HLSL",import:(()=>import("../hlsl-AJ7VWOVL.js"))},{id:"html",name:"HTML",import:(()=>import("../html-654LNGWF.js"))},{id:"html-derivative",name:"HTML (Derivative)",import:(()=>import("../html-derivative-CMQ7BFDQ.js"))},{id:"http",name:"HTTP",import:(()=>import("../http-NEPTRAQZ.js"))},{id:"hurl",name:"Hurl",import:(()=>import("../hurl-V6ZX2Q3F.js"))},{id:"hxml",name:"HXML",import:(()=>import("../hxml-5BXJCAAU.js"))},{id:"hy",name:"Hy",import:(()=>import("../hy-SB4TMFE7.js"))},{id:"imba",name:"Imba",import:(()=>import("../imba-Y64MHYWP.js"))},{id:"ini",name:"INI",aliases:["properties"],import:(()=>import("../ini-J2OP4CNW.js"))},{id:"java",name:"Java",import:(()=>import("../java-MJKJ5GPP.js"))},{id:"javascript",name:"JavaScript",aliases:["js","cjs","mjs"],import:(()=>import("../javascript-IYAGHPR6.js"))},{id:"jinja",name:"Jinja",import:(()=>import("../jinja-WPD26JJ6.js"))},{id:"jison",name:"Jison",import:(()=>import("../jison-UYDZQBN5.js"))},{id:"json",name:"JSON",import:(()=>import("../json-5V4JESJO.js"))},{id:"json5",name:"JSON5",import:(()=>import("../json5-7SHUZD3R.js"))},{id:"jsonc",name:"JSON with Comments",import:(()=>import("../jsonc-X3Z34FN3.js"))},{id:"jsonl",name:"JSON Lines",import:(()=>import("../jsonl-6I3D2HM6.js"))},{id:"jsonnet",name:"Jsonnet",import:(()=>import("../jsonnet-PZEQIBYV.js"))},{id:"jssm",name:"JSSM",aliases:["fsl"],import:(()=>import("../jssm-GJJ25IKR.js"))},{id:"jsx",name:"JSX",import:(()=>import("../jsx-NI2J427C.js"))},{id:"julia",name:"Julia",aliases:["jl"],import:(()=>import("../julia-QPZ7EOS6.js"))},{id:"kdl",name:"KDL",import:(()=>import("../kdl-IA7HA2TL.js"))},{id:"kotlin",name:"Kotlin",aliases:["kt","kts"],import:(()=>import("../kotlin-CCRMGYMI.js"))},{id:"kusto",name:"Kusto",aliases:["kql"],import:(()=>import("../kusto-7DW25GYH.js"))},{id:"latex",name:"LaTeX",import:(()=>import("../latex-F2CTDTFG.js"))},{id:"lean",name:"Lean 4",aliases:["lean4"],import:(()=>import("../lean-MGJJWBTR.js"))},{id:"less",name:"Less",import:(()=>import("../less-WFSIMX5G.js"))},{id:"liquid",name:"Liquid",import:(()=>import("../liquid-7CFNUD3V.js"))},{id:"llvm",name:"LLVM IR",import:(()=>import("../llvm-CFQSEDXB.js"))},{id:"log",name:"Log file",import:(()=>import("../log-YQNML6LA.js"))},{id:"logo",name:"Logo",import:(()=>import("../logo-2PPKBL2M.js"))},{id:"lua",name:"Lua",import:(()=>import("../lua-RPAMRKNG.js"))},{id:"luau",name:"Luau",import:(()=>import("../luau-GR2DOH6N.js"))},{id:"make",name:"Makefile",aliases:["makefile"],import:(()=>import("../make-DQQEEPI4.js"))},{id:"markdown",name:"Markdown",aliases:["md"],import:(()=>import("../markdown-OC5ILZSY.js"))},{id:"marko",name:"Marko",import:(()=>import("../marko-XSB3CTWQ.js"))},{id:"matlab",name:"MATLAB",import:(()=>import("../matlab-YQY6FS4U.js"))},{id:"mdc",name:"MDC",import:(()=>import("../mdc-TEVTGSC7.js"))},{id:"mdx",name:"MDX",import:(()=>import("../mdx-ZIH2JLVR.js"))},{id:"mermaid",name:"Mermaid",aliases:["mmd"],import:(()=>import("../mermaid-WPX56SBB.js"))},{id:"mipsasm",name:"MIPS Assembly",aliases:["mips"],import:(()=>import("../mipsasm-IDXQRZ2B.js"))},{id:"mojo",name:"Mojo",import:(()=>import("../mojo-MH7EQVOK.js"))},{id:"moonbit",name:"MoonBit",aliases:["mbt","mbti"],import:(()=>import("../moonbit-5JDFTWKE.js"))},{id:"move",name:"Move",import:(()=>import("../move-RWSXKYDY.js"))},{id:"narrat",name:"Narrat Language",aliases:["nar"],import:(()=>import("../narrat-QJUEXMVV.js"))},{id:"nextflow",name:"Nextflow",aliases:["nf"],import:(()=>import("../nextflow-2EICNZA3.js"))},{id:"nginx",name:"Nginx",import:(()=>import("../nginx-RIWAEC5Z.js"))},{id:"nim",name:"Nim",import:(()=>import("../nim-JPSYX5KC.js"))},{id:"nix",name:"Nix",import:(()=>import("../nix-XCKQVWCN.js"))},{id:"nushell",name:"nushell",aliases:["nu"],import:(()=>import("../nushell-QGW7HANA.js"))},{id:"objective-c",name:"Objective-C",aliases:["objc"],import:(()=>import("../objective-c-V7KYXFHL.js"))},{id:"objective-cpp",name:"Objective-C++",import:(()=>import("../objective-cpp-NKUEWVGU.js"))},{id:"ocaml",name:"OCaml",import:(()=>import("../ocaml-QT2CZJZN.js"))},{id:"odin",name:"Odin",import:(()=>import("../odin-MVMIXBHP.js"))},{id:"openscad",name:"OpenSCAD",aliases:["scad"],import:(()=>import("../openscad-BJDUXUUZ.js"))},{id:"pascal",name:"Pascal",import:(()=>import("../pascal-HGWEFD6L.js"))},{id:"perl",name:"Perl",import:(()=>import("../perl-X4IFZB22.js"))},{id:"php",name:"PHP",import:(()=>import("../php-3V7EPUAN.js"))},{id:"pkl",name:"Pkl",import:(()=>import("../pkl-VA5ZK5DW.js"))},{id:"plsql",name:"PL/SQL",import:(()=>import("../plsql-J7A7YWFH.js"))},{id:"po",name:"Gettext PO",aliases:["pot","potx"],import:(()=>import("../po-5RDI65JX.js"))},{id:"polar",name:"Polar",import:(()=>import("../polar-VUJL2E7F.js"))},{id:"postcss",name:"PostCSS",import:(()=>import("../postcss-ESTB5G7N.js"))},{id:"powerquery",name:"PowerQuery",import:(()=>import("../powerquery-ODTEKQCW.js"))},{id:"powershell",name:"PowerShell",aliases:["ps","ps1"],import:(()=>import("../powershell-ZOYRAWBJ.js"))},{id:"prisma",name:"Prisma",import:(()=>import("../prisma-QHG2W5GE.js"))},{id:"prolog",name:"Prolog",import:(()=>import("../prolog-CSAPG5PH.js"))},{id:"proto",name:"Protocol Buffer 3",aliases:["protobuf"],import:(()=>import("../proto-WDNJBTSW.js"))},{id:"pug",name:"Pug",aliases:["jade"],import:(()=>import("../pug-P7LS6DER.js"))},{id:"puppet",name:"Puppet",import:(()=>import("../puppet-LHFWHTY3.js"))},{id:"purescript",name:"PureScript",import:(()=>import("../purescript-DUFJP4FY.js"))},{id:"python",name:"Python",aliases:["py"],import:(()=>import("../python-5ZNZSNQ2.js"))},{id:"qml",name:"QML",import:(()=>import("../qml-LTAXB6W5.js"))},{id:"qmldir",name:"QML Directory",import:(()=>import("../qmldir-7Z2ODQLM.js"))},{id:"qss",name:"Qt Style Sheets",import:(()=>import("../qss-FDFD3HQD.js"))},{id:"r",name:"R",import:(()=>import("../r-6ZOS53WN.js"))},{id:"racket",name:"Racket",import:(()=>import("../racket-7AYZPEUI.js"))},{id:"raku",name:"Raku",aliases:["perl6"],import:(()=>import("../raku-A4F6VHVG.js"))},{id:"razor",name:"ASP.NET Razor",import:(()=>import("../razor-4QOCK4UD.js"))},{id:"reg",name:"Windows Registry Script",import:(()=>import("../reg-FAPHGG66.js"))},{id:"regexp",name:"RegExp",aliases:["regex"],import:(()=>import("../regexp-5BYLYA2R.js"))},{id:"rel",name:"Rel",import:(()=>import("../rel-7DJ7HHU4.js"))},{id:"riscv",name:"RISC-V",import:(()=>import("../riscv-YIYJATFG.js"))},{id:"ron",name:"RON",import:(()=>import("../ron-HYYMCHTX.js"))},{id:"rosmsg",name:"ROS Interface",import:(()=>import("../rosmsg-FDNH6QF7.js"))},{id:"rst",name:"reStructuredText",import:(()=>import("../rst-WIWCR2KQ.js"))},{id:"ruby",name:"Ruby",aliases:["rb"],import:(()=>import("../ruby-LXZJUMFB.js"))},{id:"rust",name:"Rust",aliases:["rs"],import:(()=>import("../rust-V3GMJA2K.js"))},{id:"sas",name:"SAS",import:(()=>import("../sas-D3G4GB3X.js"))},{id:"sass",name:"Sass",import:(()=>import("../sass-JTO65AGR.js"))},{id:"scala",name:"Scala",import:(()=>import("../scala-4XQGFSVM.js"))},{id:"scheme",name:"Scheme",import:(()=>import("../scheme-CB7AC7IL.js"))},{id:"scss",name:"SCSS",import:(()=>import("../scss-6SKV4OGI.js"))},{id:"sdbl",name:"1C (Query)",aliases:["1c-query"],import:(()=>import("../sdbl-LKGZFJ46.js"))},{id:"shaderlab",name:"ShaderLab",aliases:["shader"],import:(()=>import("../shaderlab-K536DHEB.js"))},{id:"shellscript",name:"Shell",aliases:["bash","sh","shell","zsh"],import:(()=>import("../shellscript-LRNUKUSZ.js"))},{id:"shellsession",name:"Shell Session",aliases:["console"],import:(()=>import("../shellsession-IBQK7VWQ.js"))},{id:"smalltalk",name:"Smalltalk",import:(()=>import("../smalltalk-DQOSWAW7.js"))},{id:"solidity",name:"Solidity",import:(()=>import("../solidity-V2FMZEG4.js"))},{id:"soy",name:"Closure Templates",aliases:["closure-templates"],import:(()=>import("../soy-VW3CKXWF.js"))},{id:"sparql",name:"SPARQL",import:(()=>import("../sparql-L2VKP7YP.js"))},{id:"splunk",name:"Splunk Query Language",aliases:["spl"],import:(()=>import("../splunk-KDKHP7GC.js"))},{id:"sql",name:"SQL",import:(()=>import("../sql-UF27CALT.js"))},{id:"ssh-config",name:"SSH Config",import:(()=>import("../ssh-config-JC2DQ6ED.js"))},{id:"stata",name:"Stata",import:(()=>import("../stata-7PXCUY24.js"))},{id:"stylus",name:"Stylus",aliases:["styl"],import:(()=>import("../stylus-2L7N3EZD.js"))},{id:"surrealql",name:"SurrealQL",aliases:["surql"],import:(()=>import("../surrealql-ZY3E6XEL.js"))},{id:"svelte",name:"Svelte",import:(()=>import("../svelte-Q45XIK2A.js"))},{id:"swift",name:"Swift",import:(()=>import("../swift-XBH5HZSC.js"))},{id:"system-verilog",name:"SystemVerilog",import:(()=>import("../system-verilog-VRAUSZY3.js"))},{id:"systemd",name:"Systemd Units",import:(()=>import("../systemd-JOTSGJD4.js"))},{id:"talonscript",name:"TalonScript",aliases:["talon"],import:(()=>import("../talonscript-NNZRZKOU.js"))},{id:"tasl",name:"Tasl",import:(()=>import("../tasl-MBFZ4QNC.js"))},{id:"tcl",name:"Tcl",import:(()=>import("../tcl-4GEDCBVE.js"))},{id:"templ",name:"Templ",import:(()=>import("../templ-3XM7DLQ3.js"))},{id:"terraform",name:"Terraform",aliases:["tf","tfvars"],import:(()=>import("../terraform-XTHOS4UK.js"))},{id:"tex",name:"TeX",import:(()=>import("../tex-UXMN2CV7.js"))},{id:"toml",name:"TOML",import:(()=>import("../toml-J6K55ZSV.js"))},{id:"ts-tags",name:"TypeScript with Tags",aliases:["lit"],import:(()=>import("../ts-tags-7WGDLEKX.js"))},{id:"tsv",name:"TSV",import:(()=>import("../tsv-DOUJHQDQ.js"))},{id:"tsx",name:"TSX",import:(()=>import("../tsx-G5BMVRHK.js"))},{id:"turtle",name:"Turtle",import:(()=>import("../turtle-JHJ7W6U5.js"))},{id:"twig",name:"Twig",import:(()=>import("../twig-C6YWFFZU.js"))},{id:"typescript",name:"TypeScript",aliases:["ts","cts","mts"],import:(()=>import("../typescript-LMKEAHFC.js"))},{id:"typespec",name:"TypeSpec",aliases:["tsp"],import:(()=>import("../typespec-5CLTIJYY.js"))},{id:"typst",name:"Typst",aliases:["typ"],import:(()=>import("../typst-4W4Z436Z.js"))},{id:"v",name:"V",import:(()=>import("../v-Y4SBDBN7.js"))},{id:"vala",name:"Vala",import:(()=>import("../vala-UMKT2MFA.js"))},{id:"vb",name:"Visual Basic",aliases:["cmd"],import:(()=>import("../vb-DQ7A5WJU.js"))},{id:"verilog",name:"Verilog",import:(()=>import("../verilog-N6ZF7GQD.js"))},{id:"vhdl",name:"VHDL",import:(()=>import("../vhdl-BNYDT37G.js"))},{id:"viml",name:"Vim Script",aliases:["vim","vimscript"],import:(()=>import("../viml-37RMDCBC.js"))},{id:"vue",name:"Vue",import:(()=>import("../vue-O6SLORWU.js"))},{id:"vue-html",name:"Vue HTML",import:(()=>import("../vue-html-ZLTZN573.js"))},{id:"vue-vine",name:"Vue Vine",import:(()=>import("../vue-vine-6JKAZ54I.js"))},{id:"vyper",name:"Vyper",aliases:["vy"],import:(()=>import("../vyper-GVXF46KD.js"))},{id:"wasm",name:"WebAssembly",import:(()=>import("../wasm-NTB4O7GL.js"))},{id:"wenyan",name:"Wenyan",aliases:["\u6587\u8A00"],import:(()=>import("../wenyan-W7WB3BC7.js"))},{id:"wgsl",name:"WGSL",import:(()=>import("../wgsl-7GTDVXHG.js"))},{id:"wikitext",name:"Wikitext",aliases:["mediawiki","wiki"],import:(()=>import("../wikitext-ASAFPAIL.js"))},{id:"wit",name:"WebAssembly Interface Types",import:(()=>import("../wit-ZBCR6544.js"))},{id:"wolfram",name:"Wolfram",aliases:["wl"],import:(()=>import("../wolfram-SZRZOETJ.js"))},{id:"xml",name:"XML",import:(()=>import("../xml-EBTJCOTU.js"))},{id:"xsl",name:"XSL",import:(()=>import("../xsl-IBYEXWDX.js"))},{id:"yaml",name:"YAML",aliases:["yml"],import:(()=>import("../yaml-GMVQNECR.js"))},{id:"zenscript",name:"ZenScript",import:(()=>import("../zenscript-O2TZFP4A.js"))},{id:"zig",name:"Zig",import:(()=>import("../zig-ZLGM7IMN.js"))}],$n=Object.fromEntries(Ko.map(e=>[e.id,e.import])),Xn=Object.fromEntries(Ko.flatMap(e=>e.aliases?.map(t=>[t,e.import])||[])),Vt={...$n,...Xn};var Vf=[{id:"andromeeda",displayName:"Andromeeda",type:"dark",import:(()=>import("../andromeeda-HAPOYWX3.js"))},{id:"aurora-x",displayName:"Aurora X",type:"dark",import:(()=>import("../aurora-x-R6WAWEBC.js"))},{id:"ayu-dark",displayName:"Ayu Dark",type:"dark",import:(()=>import("../ayu-dark-KMD4YO7F.js"))},{id:"ayu-light",displayName:"Ayu Light",type:"light",import:(()=>import("../ayu-light-2ATPDILG.js"))},{id:"ayu-mirage",displayName:"Ayu Mirage",type:"dark",import:(()=>import("../ayu-mirage-LJ7PG5AM.js"))},{id:"catppuccin-frappe",displayName:"Catppuccin Frapp\xE9",type:"dark",import:(()=>import("../catppuccin-frappe-Z4Y2POK6.js"))},{id:"catppuccin-latte",displayName:"Catppuccin Latte",type:"light",import:(()=>import("../catppuccin-latte-4TQUIKX4.js"))},{id:"catppuccin-macchiato",displayName:"Catppuccin Macchiato",type:"dark",import:(()=>import("../catppuccin-macchiato-B7YYPERT.js"))},{id:"catppuccin-mocha",displayName:"Catppuccin Mocha",type:"dark",import:(()=>import("../catppuccin-mocha-KX33VXKA.js"))},{id:"dark-plus",displayName:"Dark Plus",type:"dark",import:(()=>import("../dark-plus-LNHXUR7U.js"))},{id:"dracula",displayName:"Dracula Theme",type:"dark",import:(()=>import("../dracula-T2CMBBQ5.js"))},{id:"dracula-soft",displayName:"Dracula Theme Soft",type:"dark",import:(()=>import("../dracula-soft-SMFRNKX2.js"))},{id:"everforest-dark",displayName:"Everforest Dark",type:"dark",import:(()=>import("../everforest-dark-DBZHIUAO.js"))},{id:"everforest-light",displayName:"Everforest Light",type:"light",import:(()=>import("../everforest-light-TDAGYJUK.js"))},{id:"github-dark",displayName:"GitHub Dark",type:"dark",import:(()=>import("../github-dark-3E25TTAN.js"))},{id:"github-dark-default",displayName:"GitHub Dark Default",type:"dark",import:(()=>import("../github-dark-default-KCBFVSS5.js"))},{id:"github-dark-dimmed",displayName:"GitHub Dark Dimmed",type:"dark",import:(()=>import("../github-dark-dimmed-WRCBXEVS.js"))},{id:"github-dark-high-contrast",displayName:"GitHub Dark High Contrast",type:"dark",import:(()=>import("../github-dark-high-contrast-ET7SAHAV.js"))},{id:"github-light",displayName:"GitHub Light",type:"light",import:(()=>import("../github-light-6FNTZH5H.js"))},{id:"github-light-default",displayName:"GitHub Light Default",type:"light",import:(()=>import("../github-light-default-GGTAKNM7.js"))},{id:"github-light-high-contrast",displayName:"GitHub Light High Contrast",type:"light",import:(()=>import("../github-light-high-contrast-LHYKPR5E.js"))},{id:"gruvbox-dark-hard",displayName:"Gruvbox Dark Hard",type:"dark",import:(()=>import("../gruvbox-dark-hard-IQWZCHF7.js"))},{id:"gruvbox-dark-medium",displayName:"Gruvbox Dark Medium",type:"dark",import:(()=>import("../gruvbox-dark-medium-ARPWF4FS.js"))},{id:"gruvbox-dark-soft",displayName:"Gruvbox Dark Soft",type:"dark",import:(()=>import("../gruvbox-dark-soft-ODS6FPID.js"))},{id:"gruvbox-light-hard",displayName:"Gruvbox Light Hard",type:"light",import:(()=>import("../gruvbox-light-hard-KFA5YFDW.js"))},{id:"gruvbox-light-medium",displayName:"Gruvbox Light Medium",type:"light",import:(()=>import("../gruvbox-light-medium-MMET4L3Y.js"))},{id:"gruvbox-light-soft",displayName:"Gruvbox Light Soft",type:"light",import:(()=>import("../gruvbox-light-soft-DBZDERMK.js"))},{id:"horizon",displayName:"Horizon",type:"dark",import:(()=>import("../horizon-FSOMPXNP.js"))},{id:"houston",displayName:"Houston",type:"dark",import:(()=>import("../houston-FAQBCORN.js"))},{id:"kanagawa-dragon",displayName:"Kanagawa Dragon",type:"dark",import:(()=>import("../kanagawa-dragon-JNDVF5RJ.js"))},{id:"kanagawa-lotus",displayName:"Kanagawa Lotus",type:"light",import:(()=>import("../kanagawa-lotus-S7JK6TQ6.js"))},{id:"kanagawa-wave",displayName:"Kanagawa Wave",type:"dark",import:(()=>import("../kanagawa-wave-QJJIMVEV.js"))},{id:"laserwave",displayName:"LaserWave",type:"dark",import:(()=>import("../laserwave-YFP3EJVX.js"))},{id:"light-plus",displayName:"Light Plus",type:"light",import:(()=>import("../light-plus-NGDHCPUZ.js"))},{id:"material-theme",displayName:"Material Theme",type:"dark",import:(()=>import("../material-theme-H2BHKUKX.js"))},{id:"material-theme-darker",displayName:"Material Theme Darker",type:"dark",import:(()=>import("../material-theme-darker-VENCGWTB.js"))},{id:"material-theme-lighter",displayName:"Material Theme Lighter",type:"light",import:(()=>import("../material-theme-lighter-SDMLS22W.js"))},{id:"material-theme-ocean",displayName:"Material Theme Ocean",type:"dark",import:(()=>import("../material-theme-ocean-UHDBRLVF.js"))},{id:"material-theme-palenight",displayName:"Material Theme Palenight",type:"dark",import:(()=>import("../material-theme-palenight-3TB2BEET.js"))},{id:"min-dark",displayName:"Min Dark",type:"dark",import:(()=>import("../min-dark-CQ5WKNT7.js"))},{id:"min-light",displayName:"Min Light",type:"light",import:(()=>import("../min-light-LZRD4NPR.js"))},{id:"monokai",displayName:"Monokai",type:"dark",import:(()=>import("../monokai-WHRY6275.js"))},{id:"night-owl",displayName:"Night Owl",type:"dark",import:(()=>import("../night-owl-7PNEW2JB.js"))},{id:"night-owl-light",displayName:"Night Owl Light",type:"light",import:(()=>import("../night-owl-light-GJUYOOJR.js"))},{id:"nord",displayName:"Nord",type:"dark",import:(()=>import("../nord-EVGUMUX2.js"))},{id:"one-dark-pro",displayName:"One Dark Pro",type:"dark",import:(()=>import("../one-dark-pro-PMTR3SA7.js"))},{id:"one-light",displayName:"One Light",type:"light",import:(()=>import("../one-light-O7WH4N5X.js"))},{id:"plastic",displayName:"Plastic",type:"dark",import:(()=>import("../plastic-FBVUW6NJ.js"))},{id:"poimandres",displayName:"Poimandres",type:"dark",import:(()=>import("../poimandres-WBB7GZAD.js"))},{id:"red",displayName:"Red",type:"dark",import:(()=>import("../red-7KAMONOP.js"))},{id:"rose-pine",displayName:"Ros\xE9 Pine",type:"dark",import:(()=>import("../rose-pine-F2G5IHZD.js"))},{id:"rose-pine-dawn",displayName:"Ros\xE9 Pine Dawn",type:"light",import:(()=>import("../rose-pine-dawn-ALZ7XGH2.js"))},{id:"rose-pine-moon",displayName:"Ros\xE9 Pine Moon",type:"dark",import:(()=>import("../rose-pine-moon-D3K4SWUL.js"))},{id:"slack-dark",displayName:"Slack Dark",type:"dark",import:(()=>import("../slack-dark-YFPJODWS.js"))},{id:"slack-ochin",displayName:"Slack Ochin",type:"light",import:(()=>import("../slack-ochin-H67AWZOI.js"))},{id:"snazzy-light",displayName:"Snazzy Light",type:"light",import:(()=>import("../snazzy-light-OUVS63VK.js"))},{id:"solarized-dark",displayName:"Solarized Dark",type:"dark",import:(()=>import("../solarized-dark-2RCAVEXJ.js"))},{id:"solarized-light",displayName:"Solarized Light",type:"light",import:(()=>import("../solarized-light-XFSENHTC.js"))},{id:"synthwave-84",displayName:"Synthwave '84",type:"dark",import:(()=>import("../synthwave-84-5XXB3K6S.js"))},{id:"tokyo-night",displayName:"Tokyo Night",type:"dark",import:(()=>import("../tokyo-night-CHJCCBJH.js"))},{id:"vesper",displayName:"Vesper",type:"dark",import:(()=>import("../vesper-Y5GIEAN4.js"))},{id:"vitesse-black",displayName:"Vitesse Black",type:"dark",import:(()=>import("../vitesse-black-7TI33KHX.js"))},{id:"vitesse-dark",displayName:"Vitesse Dark",type:"dark",import:(()=>import("../vitesse-dark-FOB25MRB.js"))},{id:"vitesse-light",displayName:"Vitesse Light",type:"light",import:(()=>import("../vitesse-light-4WCNCTCO.js"))}],Qn=Object.fromEntries(Vf.map(e=>[e.id,e.import]));var jt=class extends Error{constructor(t){super(t),this.name="ShikiError"}};function jf(){return 2147483648}function $f(){return typeof performance<"u"?performance.now():Date.now()}var Xf=(e,t)=>e+(t-e%t)%t;async function Qf(e){let t,a,o={};function r(c){a=c,o.HEAPU8=new Uint8Array(c),o.HEAPU32=new Uint32Array(c)}function s(c,m,C){o.HEAPU8.copyWithin(c,m,m+C)}function n(c){try{return t.grow(c-a.byteLength+65535>>>16),r(t.buffer),1}catch{}}function i(c){let m=o.HEAPU8.length;c=c>>>0;let C=jf();if(c>C)return!1;for(let w=1;w<=4;w*=2){let x=m*(1+.2/w);x=Math.min(x,c+100663296);let g=Math.min(C,Xf(Math.max(c,x),65536));if(n(g))return!0}return!1}let l=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function u(c,m,C=1024){let w=m+C,x=m;for(;c[x]&&!(x>=w);)++x;if(x-m>16&&c.buffer&&l)return l.decode(c.subarray(m,x));let g="";for(;m<x;){let h=c[m++];if(!(h&128)){g+=String.fromCharCode(h);continue}let L=c[m++]&63;if((h&224)===192){g+=String.fromCharCode((h&31)<<6|L);continue}let y=c[m++]&63;if((h&240)===224?h=(h&15)<<12|L<<6|y:h=(h&7)<<18|L<<12|y<<6|c[m++]&63,h<65536)g+=String.fromCharCode(h);else{let k=h-65536;g+=String.fromCharCode(55296|k>>10,56320|k&1023)}}return g}function f(c,m){return c?u(o.HEAPU8,c,m):""}let d={emscripten_get_now:$f,emscripten_memcpy_big:s,emscripten_resize_heap:i,fd_write:()=>0};async function p(){let m=await e({env:d,wasi_snapshot_preview1:d});t=m.memory,r(t.buffer),Object.assign(o,m),o.UTF8ToString=f}return await p(),o}var Kf=Object.defineProperty,Jf=(e,t,a)=>t in e?Kf(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,ae=(e,t,a)=>Jf(e,typeof t!="symbol"?t+"":t,a),ie=null;function Zf(e){throw new jt(e.UTF8ToString(e.getLastOnigError()))}var Oa=class e{constructor(t){ae(this,"utf16Length"),ae(this,"utf8Length"),ae(this,"utf16Value"),ae(this,"utf8Value"),ae(this,"utf16OffsetToUtf8"),ae(this,"utf8OffsetToUtf16");let a=t.length,o=e._utf8ByteLength(t),r=o!==a,s=r?new Uint32Array(a+1):null;r&&(s[a]=o);let n=r?new Uint32Array(o+1):null;r&&(n[o]=a);let i=new Uint8Array(o),l=0;for(let u=0;u<a;u++){let f=t.charCodeAt(u),d=f,p=!1;if(f>=55296&&f<=56319&&u+1<a){let c=t.charCodeAt(u+1);c>=56320&&c<=57343&&(d=(f-55296<<10)+65536|c-56320,p=!0)}r&&(s[u]=l,p&&(s[u+1]=l),d<=127?n[l+0]=u:d<=2047?(n[l+0]=u,n[l+1]=u):d<=65535?(n[l+0]=u,n[l+1]=u,n[l+2]=u):(n[l+0]=u,n[l+1]=u,n[l+2]=u,n[l+3]=u)),d<=127?i[l++]=d:d<=2047?(i[l++]=192|(d&1984)>>>6,i[l++]=128|(d&63)>>>0):d<=65535?(i[l++]=224|(d&61440)>>>12,i[l++]=128|(d&4032)>>>6,i[l++]=128|(d&63)>>>0):(i[l++]=240|(d&1835008)>>>18,i[l++]=128|(d&258048)>>>12,i[l++]=128|(d&4032)>>>6,i[l++]=128|(d&63)>>>0),p&&u++}this.utf16Length=a,this.utf8Length=o,this.utf16Value=t,this.utf8Value=i,this.utf16OffsetToUtf8=s,this.utf8OffsetToUtf16=n}static _utf8ByteLength(t){let a=0;for(let o=0,r=t.length;o<r;o++){let s=t.charCodeAt(o),n=s,i=!1;if(s>=55296&&s<=56319&&o+1<r){let l=t.charCodeAt(o+1);l>=56320&&l<=57343&&(n=(s-55296<<10)+65536|l-56320,i=!0)}n<=127?a+=1:n<=2047?a+=2:n<=65535?a+=3:a+=4,i&&o++}return a}createString(t){let a=t.omalloc(this.utf8Length);return t.HEAPU8.set(this.utf8Value,a),a}},Ua=class Ee{constructor(t){if(ae(this,"id",++Ee.LAST_ID),ae(this,"_onigBinding"),ae(this,"content"),ae(this,"utf16Length"),ae(this,"utf8Length"),ae(this,"utf16OffsetToUtf8"),ae(this,"utf8OffsetToUtf16"),ae(this,"ptr"),!ie)throw new jt("Must invoke loadWasm first.");this._onigBinding=ie,this.content=t;let a=new Oa(t);this.utf16Length=a.utf16Length,this.utf8Length=a.utf8Length,this.utf16OffsetToUtf8=a.utf16OffsetToUtf8,this.utf8OffsetToUtf16=a.utf8OffsetToUtf16,this.utf8Length<1e4&&!Ee._sharedPtrInUse?(Ee._sharedPtr||(Ee._sharedPtr=ie.omalloc(1e4)),Ee._sharedPtrInUse=!0,ie.HEAPU8.set(a.utf8Value,Ee._sharedPtr),this.ptr=Ee._sharedPtr):this.ptr=a.createString(ie)}convertUtf8OffsetToUtf16(t){return this.utf8OffsetToUtf16?t<0?0:t>this.utf8Length?this.utf16Length:this.utf8OffsetToUtf16[t]:t}convertUtf16OffsetToUtf8(t){return this.utf16OffsetToUtf8?t<0?0:t>this.utf16Length?this.utf8Length:this.utf16OffsetToUtf8[t]:t}dispose(){this.ptr===Ee._sharedPtr?Ee._sharedPtrInUse=!1:this._onigBinding.ofree(this.ptr)}};ae(Ua,"LAST_ID",0);ae(Ua,"_sharedPtr",0);ae(Ua,"_sharedPtrInUse",!1);var Kn=Ua,Zo=class{constructor(t){if(ae(this,"_onigBinding"),ae(this,"_ptr"),!ie)throw new jt("Must invoke loadWasm first.");let a=[],o=[];for(let i=0,l=t.length;i<l;i++){let u=new Oa(t[i]);a[i]=u.createString(ie),o[i]=u.utf8Length}let r=ie.omalloc(4*t.length);ie.HEAPU32.set(a,r/4);let s=ie.omalloc(4*t.length);ie.HEAPU32.set(o,s/4);let n=ie.createOnigScanner(r,s,t.length);for(let i=0,l=t.length;i<l;i++)ie.ofree(a[i]);ie.ofree(s),ie.ofree(r),n===0&&Zf(ie),this._onigBinding=ie,this._ptr=n}dispose(){this._onigBinding.freeOnigScanner(this._ptr)}findNextMatchSync(t,a,o){let r=0;if(typeof o=="number"&&(r=o),typeof t=="string"){t=new Kn(t);let s=this._findNextMatchSync(t,a,!1,r);return t.dispose(),s}return this._findNextMatchSync(t,a,!1,r)}_findNextMatchSync(t,a,o,r){let s=this._onigBinding,n=s.findNextOnigScannerMatch(this._ptr,t.id,t.ptr,t.utf8Length,t.convertUtf16OffsetToUtf8(a),r);if(n===0)return null;let i=s.HEAPU32,l=n/4,u=i[l++],f=i[l++],d=[];for(let p=0;p<f;p++){let c=t.convertUtf8OffsetToUtf16(i[l++]),m=t.convertUtf8OffsetToUtf16(i[l++]);d[p]={start:c,end:m,length:m-c}}return{index:u,captureIndices:d}}};function Yf(e){return typeof e.instantiator=="function"}function ec(e){return typeof e.default=="function"}function tc(e){return typeof e.data<"u"}function ac(e){return typeof Response<"u"&&e instanceof Response}function oc(e){return typeof ArrayBuffer<"u"&&(e instanceof ArrayBuffer||ArrayBuffer.isView(e))||typeof Buffer<"u"&&Buffer.isBuffer?.(e)||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer||typeof Uint32Array<"u"&&e instanceof Uint32Array}var Na;function rc(e){if(Na)return Na;async function t(){ie=await Qf(async a=>{let o=e;return o=await o,typeof o=="function"&&(o=await o(a)),typeof o=="function"&&(o=await o(a)),Yf(o)?o=await o.instantiator(a):ec(o)?o=await o.default(a):(tc(o)&&(o=o.data),ac(o)?typeof WebAssembly.instantiateStreaming=="function"?o=await sc(o)(a):o=await nc(o)(a):oc(o)?o=await Jo(o)(a):o instanceof WebAssembly.Module?o=await Jo(o)(a):"default"in o&&o.default instanceof WebAssembly.Module&&(o=await Jo(o.default)(a))),"instance"in o&&(o=o.instance),"exports"in o&&(o=o.exports),o})}return Na=t(),Na}function Jo(e){return t=>WebAssembly.instantiate(e,t)}function sc(e){return t=>WebAssembly.instantiateStreaming(e,t)}function nc(e){return async t=>{let a=await e.arrayBuffer();return WebAssembly.instantiate(a,t)}}async function Jn(e){return e&&await rc(e),{createScanner(t){return new Zo(t.map(a=>typeof a=="string"?a:a.source))},createString(t){return new Kn(t)}}}var Ha=Vn({langs:Vt,themes:Qn,engine:()=>Jn(import("../wasm-EOPKAILK.js"))}),{codeToHtml:ic,codeToHast:lc,codeToTokens:uc,codeToTokensBase:dc,codeToTokensWithThemes:fc,getSingletonHighlighter:cc,getLastGrammarState:pc}=jn(Ha,{guessEmbeddedLanguages:On});var Zn=new Set(Object.keys(Vt)),Yo=new Map,er=new Map,gt=new Map,mc=(e,t)=>`${e}-${t[0]}-${t[1]}`,hc=(e,t,a)=>{let o=e.slice(0,100),r=e.length>100?e.slice(-100):"";return`${t}:${a[0]}:${a[1]}:${e.length}:${o}:${r}`},gc=(e,t)=>{let a=mc(e,t);if(Yo.has(a))return Yo.get(a);let o=Ha({themes:t,langs:[e]});return Yo.set(a,o),o};function wc(e={}){var t;let a=(t=e.themes)!=null?t:["github-light","github-dark"];return{name:"shiki",type:"code-highlighter",supportsLanguage(o){return Zn.has(o)},getSupportedLanguages(){return Array.from(Zn)},getThemes(){return a},highlight({code:o,language:r,themes:s},n){let i=hc(o,r,s);return er.has(i)?er.get(i):(n&&(gt.has(i)||gt.set(i,new Set),gt.get(i).add(n)),gc(r,s).then(l=>{let u=l.getLoadedLanguages().includes(r)?r:"text",f=l.codeToTokens(o,{lang:u,themes:{light:s[0],dark:s[1]}});er.set(i,f);let d=gt.get(i);if(d){for(let p of d)p(f);gt.delete(i)}}).catch(l=>{console.error("[Streamdown Code] Failed to highlight code:",l),gt.delete(i)}),null)}}}var Yn=wc();import{memo as Ic}from"react";import{useEffect as xc,useRef as qa,useState as Lc}from"react";var Cc=5,ei=400;function ti(e,t,a={}){let{msPerChar:o=Cc}=a,[r,s]=Lc(t?"":e),n=qa(e),i=qa(t?0:e.length),l=qa(0),u=qa(null);return(e.length<i.current||!e.startsWith(r.slice(0,i.current)))&&(i.current=t?0:e.length),n.current=e,xc(()=>{if(!t){u.current!==null&&(cancelAnimationFrame(u.current),u.current=null),i.current=e.length,s(e);return}if(n.current.length-i.current>ei&&(i.current=n.current.length-ei),u.current!==null)return;let d=p=>{let c=n.current;if(i.current>=c.length){u.current=null;return}l.current===0&&(l.current=p);let m=p-l.current;if(m>=o){let C=Math.min(Math.floor(m/o),c.length-i.current);i.current+=C,s(c.slice(0,i.current)),l.current=p}u.current=requestAnimationFrame(d)};return u.current=requestAnimationFrame(d),()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[e,t,o]),r}import{jsx as Ga}from"react/jsx-runtime";var tr=({className:e,from:t,children:a,...o})=>Ga("div",{className:A("ww:group ww:flex ww:w-full",t==="user"?"is-user ww:ml-auto ww:max-w-[80%] ww:flex-col ww:items-end":"is-assistant ww:flex-col",e),...o,children:Ga("div",{className:A("ww:flex ww:min-w-0 ww:flex-col ww:gap-2","ww:w-full"),children:a})}),ar=({children:e,className:t,...a})=>Ga("div",{className:A("ww:flex ww:w-fit ww:min-w-0 ww:max-w-full ww:flex-col ww:gap-2 ww:overflow-hidden ww:text-base","ww:group-[.is-user]:ml-auto ww:group-[.is-user]:rounded-lg ww:group-[.is-user]:bg-user-bubble ww:group-[.is-user]:px-4 ww:group-[.is-user]:py-3 ww:group-[.is-user]:text-primary-foreground","ww:group-[.is-assistant]:text-foreground",t),...a,children:e}),Sc={cjk:ko,code:Yn},yc={cjk:ko},kc={enabled:!1};function bc({className:e,linkSafety:t,isStreaming:a,children:o,...r}){let n=ti(typeof o=="string"?o:"",!!a),i=typeof o=="string"?n:o;return Ga(Lt,{className:A("ww:size-full ww:[&>*:first-child]:mt-0 ww:[&>*:last-child]:mb-0",e),linkSafety:t??kc,plugins:a?yc:Sc,...r,children:i})}var Wa=Ic(bc,(e,t)=>e.children===t.children&&e.isStreaming===t.isStreaming);Wa.displayName="MessageResponse";import{createContext as vc,memo as sr,useCallback as Mc,useContext as Rc,useEffect as or,useMemo as Fc,useRef as ai,useState as rr}from"react";import{memo as Tc}from"react";import{jsx as Ac}from"react/jsx-runtime";var Pc=({as:e="span",className:t,duration:a=2,style:o,children:r,...s})=>{let n={backgroundImage:"linear-gradient(90deg, var(--ww-color-muted-foreground) 0%, var(--ww-color-muted-foreground) 40%, var(--ww-color-foreground) 50%, var(--ww-color-muted-foreground) 60%, var(--ww-color-muted-foreground) 100%)",backgroundSize:"250% 100%",WebkitBackgroundClip:"text",backgroundClip:"text",color:"transparent",animation:`ww-shimmer ${a}s linear infinite`,...o};return Ac(e,{"data-waniwani-shimmer":"",className:A("ww:inline-block",t),style:n,...s,children:r})},$e=Tc(Pc);$e.displayName="Shimmer";import{Fragment as Ec,jsx as Me,jsxs as _c}from"react/jsx-runtime";var oi=vc(null);function ri(){let e=Rc(oi);if(!e)throw new Error("Reasoning components must be used within <Reasoning>");return e}var Bc=1e3,Dc=1e3,nr=sr(({className:e,isStreaming:t=!1,open:a,defaultOpen:o,onOpenChange:r,duration:s,children:n,...i})=>{let l=o??t,u=o===!1,f=a!==void 0,[d,p]=rr(l),c=f?a:d,m=Mc(v=>{f||p(v),r?.(v)},[f,r]),[C,w]=rr(void 0),x=s??C,g=ai(t),[h,L]=rr(!1),y=ai(null);or(()=>{t?(g.current=!0,y.current===null&&(y.current=Date.now())):y.current!==null&&(w(Math.ceil((Date.now()-y.current)/Dc)),y.current=null)},[t]),or(()=>{t&&!c&&!u&&m(!0)},[t,c,u,m]),or(()=>{if(g.current&&!t&&c&&!h){let v=setTimeout(()=>{m(!1),L(!0)},Bc);return()=>clearTimeout(v)}},[t,c,h,m]);let k=Fc(()=>({isStreaming:t,isOpen:c,setIsOpen:m,duration:x}),[t,c,m,x]);return Me(oi.Provider,{value:k,children:Me("div",{className:A("ww:mb-4 ww:flex ww:flex-col ww:gap-2",e),"data-state":c?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...i,children:n})})});nr.displayName="Reasoning";var ir=sr(({className:e,children:t,getThinkingMessage:a,onClick:o,...r})=>{let{t:s}=U(),{isStreaming:n,isOpen:i,duration:l,setIsOpen:u}=ri(),d=a??((p,c)=>p||c===0?Me($e,{duration:1.6,children:s.reasoning.thinking}):c===void 0?Me("span",{children:s.reasoning.thoughtBrief}):Me("span",{children:s.reasoning.thoughtForSeconds(c)}));return Me("button",{type:"button","aria-expanded":i,onClick:p=>{u(!i),o?.(p)},className:A("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),...r,children:t??_c(Ec,{children:[Me(It,{className:"ww:size-4 ww:shrink-0"}),d(n,l)]})})});ir.displayName="ReasoningTrigger";var lr=sr(({className:e,children:t,...a})=>{let{isOpen:o}=ri();return Me("div",{className:A("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",o?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:Me("div",{className:"ww:min-h-0 ww:overflow-hidden",children:Me("div",{className:A("ww:text-sm ww:text-muted-foreground",e),...a,children:Me(Lt,{children:t})})})})});lr.displayName="ReasoningContent";import{createContext as Nc,useCallback as Oc,useContext as li,useEffect as Uc,useMemo as dr,useRef as Hc,useState as fr}from"react";import{Fragment as ii,jsx as j,jsxs as Xe}from"react/jsx-runtime";function qc(e,t=80){if(e==null)return String(e);if(typeof e!="object")return String(e).slice(0,t);if(Array.isArray(e))return`Array(${e.length})`;let a=JSON.stringify(e);if(a.length<=t)return a;let o=Object.entries(e),r=[],s=t-2;for(let[n,i]of o){if(s<=8)break;let l=n.length>4?`${n.slice(0,4)}\u2026`:n,u;typeof i=="string"?u=i.length>2?`'${i.slice(0,1)}\u2026`:`'${i}'`:Array.isArray(i)?u=`Array(${i.length})`:typeof i=="object"&&i!==null?u="{\u2026}":u=String(i);let f=`${l}\u2009${u}`;r.push(f),s-=f.length+3}return`{${r.join(", ")}}`}function Gc({text:e,className:t}){let{t:a}=U(),[o,r]=fr(!1),s=Hc(null);Uc(()=>()=>{s.current&&clearTimeout(s.current)},[]);let n=Oc(async i=>{i.stopPropagation();try{await navigator.clipboard.writeText(e),r(!0),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>r(!1),2e3)}catch{}},[e]);return j(be,{variant:"ghost",size:"sm",onClick:n,className:A("ww:h-auto ww:gap-1 ww:px-1.5 ww:py-0.5 ww:text-xs ww:text-muted-foreground ww:hover:text-foreground",t),children:o?Xe(ii,{children:[j(St,{className:"ww:size-3.5"}),j("span",{children:a.tool.copied})]}):Xe(ii,{children:[j(bt,{className:"ww:size-3.5"}),j("span",{children:a.tool.copy})]})})}function ui({data:e,label:t,className:a,...o}){let[r,s]=fr(!1),n=dr(()=>JSON.stringify(e,null,2),[e]),i=qc(e);return Xe("div",{className:A("ww:rounded-lg ww:bg-tool-card",a),...o,children:[Xe("div",{className:"ww:flex ww:items-center ww:justify-between ww:px-3 ww:pt-2.5 ww:pb-1.5",children:[j("span",{className:"ww:text-xs ww:font-medium ww:text-muted-foreground",children:t}),j(Gc,{text:n})]}),Xe("button",{type:"button",onClick:()=>s(l=>!l),className:"ww:flex ww:w-full ww:items-start ww:gap-2 ww:px-3 ww:pb-3 ww:text-left",children:[j(kt,{className:A("ww:mt-0.5 ww:size-3.5 ww:shrink-0 ww:text-muted-foreground ww:transition-transform ww:duration-150",r&&"ww:rotate-90")}),r?j("pre",{className:"ww:overflow-x-auto ww:text-xs ww:font-mono ww:text-foreground ww:whitespace-pre-wrap ww:break-all",children:j("code",{children:n})}):j("span",{className:"ww:truncate ww:text-xs ww:font-mono ww:text-foreground/80",children:i})]})]})}var cr=Nc({open:!1,toggle:()=>{}});function di({className:e,defaultOpen:t=!1,children:a,...o}){let[r,s]=fr(t);return j(cr.Provider,{value:{open:r,toggle:()=>s(n=>!n)},children:j("div",{className:A("ww:mb-4 ww:w-full",e),"data-state":r?"open":"closed",style:{animation:"ww-fade-in 0.2s ease-out"},...o,children:a})})}function fi({className:e,title:t,state:a,...o}){let{open:r,toggle:s}=li(cr),n=a==="input-available"||a==="input-streaming",i=t??"";return Xe("button",{type:"button",onClick:s,className:A("ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground ww:transition-colors ww:hover:text-foreground",e),"aria-expanded":r,...o,children:[j(Ne,{className:"ww:size-4 ww:shrink-0"}),j("span",{className:"ww:truncate",children:n?j($e,{duration:1.6,children:i}):i}),j(yt,{className:A("ww:size-4 ww:shrink-0 ww:transition-transform ww:duration-200",r&&"ww:rotate-180")})]})}function ci({className:e,title:t,state:a,...o}){let r=a==="input-available"||a==="input-streaming",s=t??"";return Xe("div",{className:A("ww:mb-4 ww:flex ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...o,children:[j(Ne,{className:"ww:size-4 ww:shrink-0"}),j("span",{className:"ww:truncate",children:r?j($e,{duration:1.6,children:s}):s})]})}function pi({className:e,children:t,...a}){let{open:o}=li(cr);return j("div",{className:A("ww:grid ww:transition-[grid-template-rows,opacity] ww:duration-200 ww:ease-out",o?"ww:grid-rows-[1fr] ww:opacity-100":"ww:grid-rows-[0fr] ww:opacity-0"),children:j("div",{className:"ww:min-h-0 ww:overflow-hidden",children:j("div",{className:A("ww:mt-2 ww:space-y-3 ww:rounded-lg ww:border ww:border-border ww:bg-background ww:p-3",e),...a,children:t})})})}function mi({className:e,input:t,debug:a,...o}){let{t:r}=U(),s=dr(()=>{if(!a&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:n,...i}=t;return i}return t},[t,a]);return j(ui,{data:s,label:r.tool.request,className:e,...o})}function ur(e){if(!(typeof e!="object"||e===null))return e}function hi(e){return ur(e?.ui)}function gi(e){return ur(ur(e)?._meta)}function si(e){if(!e)return;let t=hi(e)?.resourceUri;if(typeof t=="string"&&t.length>0)return t;let a=e["ui/resourceUri"];if(typeof a=="string"&&a.length>0)return a;let o=e["openai/outputTemplate"];if(typeof o=="string"&&o.length>0)return o}function ni(e){return hi(e)?.autoHeight===!0}function za(e,t,a){if(e){let o=si(a?.[e]?._meta);if(o)return o}return si(gi(t))}function wi(e,t,a){return e&&ni(a?.[e]?._meta)?!0:ni(gi(t))}function xi({className:e,output:t,errorText:a,debug:o,...r}){let{t:s}=U(),n=dr(()=>{if(!o&&typeof t=="object"&&t!==null&&!Array.isArray(t)){let{_meta:i,...l}=t;return l}return t},[t,o]);return t||a?a?Xe("div",{className:A("ww:space-y-2",e),...r,children:[j("h4",{className:"ww:text-xs ww:font-medium ww:uppercase ww:tracking-wide ww:text-muted-foreground",children:s.tool.error}),j("div",{className:"ww:rounded-lg ww:bg-destructive/10 ww:p-3 ww:text-xs ww:text-destructive",children:a})]}):j(ui,{data:n,label:s.tool.response,className:e,...r}):null}import{jsx as Li,jsxs as zc}from"react/jsx-runtime";function Wc(e){return e.type==="text"||e.type==="reasoning"||e.type==="file"||"toolCallId"in e}function pr(e){return e.parts.some(Wc)}function Ci(e,t){if(t!=="submitted"&&t!=="streaming")return!1;let a=e[e.length-1];return!a||a.role!=="assistant"?!0:!pr(a)}function Ii({className:e,...t}){let{t:a}=U();return zc("div",{"aria-live":"polite",className:A("ww:mb-4 ww:flex ww:w-full ww:items-center ww:gap-2 ww:text-sm ww:text-muted-foreground",e),style:{animation:"ww-fade-in 0.2s ease-out"},...t,children:[Li(Mt,{className:"ww:size-4 ww:shrink-0"}),Li($e,{duration:1.6,children:a.workingIndicator.default})]})}import{useCallback as Vc,useEffect as yi,useMemo as jc,useRef as Le,useState as ki}from"react";function wt(e){if(!e)return!1;let t=Array.isArray(e.content)&&e.content.length>0,a=typeof e.structuredContent=="object"&&e.structuredContent!==null&&Object.keys(e.structuredContent).length>0;return t||a}function Si(e,t){return!wt(e)&&!wt(t)?null:wt(e)?wt(t)?{...e.content||t.content?{content:[...e.content??[],...t.content??[]]}:{},...e.structuredContent||t.structuredContent?{structuredContent:{...e.structuredContent??{},...t.structuredContent??{}}}:{}}:{...e.content?{content:[...e.content]}:{},...e.structuredContent?{structuredContent:{...e.structuredContent}}:{}}:{...t?.content?{content:[...t.content]}:{},...t?.structuredContent?{structuredContent:{...t.structuredContent}}:{}}}import{jsx as op}from"react/jsx-runtime";var $c="/api/mcp/resource",Xc=500,Qc=0,Kc=16,Jc="2026-01-26",Zc=300,Yc=3e3,ep=3;function tp(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function ap(e,t,a){return za(e,t,a)?!1:t._meta?.["waniwani/autoInjectResultText"]!==!1}function mr({resourceUri:e,toolInput:t,toolResult:a,resourceEndpoint:o=$c,chatSessionId:r,isDark:s=!1,className:n,autoHeight:i=!1,onOpenLink:l,onFollowUp:u,onCallTool:f,onDisplayModeChange:d,isFullscreen:p=!1,toolDefinitions:c}){let m=Le(null),C=Le(t),w=Le(a),x=Le({width:0,height:0}),g=Le(null),h=Le(!1),L=Le(0),y=Le("inline"),[k,v]=ki(Qc),[M,E]=ki(void 0),F=Le(l),T=Le(u),S=Le(f),P=Le(d),$=Le(r),V=Le(c);C.current=t,w.current=a,F.current=l,T.current=u,S.current=f,P.current=d,$.current=r,V.current=c;let we=Vc(X=>i?Math.max(X+Kc,0):Math.min(Math.max(X,50),Xc),[i]),pe=jc(()=>{let X=o.includes("?")?"&":"?";return`${o}${X}uri=${encodeURIComponent(e)}`},[o,e]),me=Le(s);return me.current=s,yi(()=>{if(!h.current)return;let X=m.current;X?.contentWindow&&X.contentWindow.postMessage({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{theme:s?"dark":"light"}},"*")},[s]),yi(()=>{let X=m.current;if(!X)return;let Z=!1,he=!1,se=null,ne=null,Fe=setTimeout(()=>{if(Z||he||L.current>=ep)return;L.current+=1;let q=new URL(X.src);q.searchParams.set("_retry",String(L.current)),X.src=q.toString()},Yc),B=q=>{X.contentWindow?.postMessage(q,"*")},Q=q=>{if(Z||q.source!==X.contentWindow)return;let H=q.data;if(!H||typeof H!="object"||H.jsonrpc!=="2.0")return;let Y=H.method,_=H.id;if(Y==="ui/initialize"&&_!=null){he=!0,clearTimeout(Fe),B({jsonrpc:"2.0",id:_,result:{protocolVersion:H.params?.protocolVersion??Jc,hostInfo:{name:"WaniWani Chat",version:"1.0.0"},hostCapabilities:{openLinks:{},message:{text:{}},tools:{},updateModelContext:{text:{},structuredContent:{}}},hostContext:{theme:me.current?"dark":"light",displayMode:y.current}}});return}if(Y==="ui/notifications/initialized"){h.current=!0;let G=C.current,W=w.current,b=W._meta&&typeof W._meta=="object"?W._meta:null,R=tp($.current),O=b&&typeof b.waniwani=="object"&&b.waniwani!==null?b.waniwani:null,te=O||R?{...O??{},...R?{sessionId:R}:{}}:void 0,ye=b||te?{...b??{},...te?{waniwani:te}:{}}:void 0;B({jsonrpc:"2.0",method:"ui/notifications/tool-input",params:{arguments:G}});let Pe=W.content??[{type:"text",text:JSON.stringify(W)}];B({jsonrpc:"2.0",method:"ui/notifications/tool-result",params:{content:Pe,structuredContent:W.structuredContent,_meta:ye,meta:ye}});return}if(Y==="ui/notifications/size-changed"){let G=H.params,W=typeof G?.height=="number"?G.height:void 0,b=typeof G?.width=="number"?G.width:void 0,R=x.current,O=W!==void 0&&W!==R.height,te=b!==void 0&&b!==R.width;if(!O&&!te)return;if(O&&W!==void 0){R.height=W;let ye=we(W),Pe=X.getBoundingClientRect().height;if(g.current&&(g.current.cancel(),g.current=null),v(ye),X.animate&&Math.abs(Pe-ye)>2){let He=X.animate([{height:`${Pe}px`},{height:`${ye}px`}],{duration:Zc,easing:"ease-out",fill:"forwards"});g.current=He,He.onfinish=()=>{g.current===He&&(He.cancel(),g.current=null)}}}te&&i&&b!==void 0&&(R.width=b,E(b));return}if(Y==="ui/open-link"&&_!=null){let G=H.params?.url;typeof G=="string"&&(F.current?F.current(G):window.open(G,"_blank","noopener,noreferrer")),B({jsonrpc:"2.0",id:_,result:{}});return}if(Y==="ui/message"&&_!=null){if(T.current&&H.params){let G=H.params,W=se;if(se=null,ne){clearTimeout(ne.timer);let b=ne.text;ne=null;let R=(G.content??[]).map(O=>O.text??"").join("").trim();G={...G,content:[{type:"text",text:`${R}
14
14
 
15
15
  ${b}`}]}}T.current({...G,...W?{modelContext:W}:{}})}B({jsonrpc:"2.0",id:_,result:{}});return}if(Y==="ui/update-model-context"&&_!=null){se=Si(se,H.params),B({jsonrpc:"2.0",id:_,result:{}});return}if(Y==="tools/call"&&_!=null){let G=S.current;if(!G){B({jsonrpc:"2.0",id:_,error:{code:-32601,message:"tools/call not supported"}});return}let W=H.params?.name;G({name:W,arguments:H.params?.arguments??{}}).then(b=>{B({jsonrpc:"2.0",id:_,result:b});let R=b.content?.map(O=>O.text??"").join("").trim();R&&ap(W,b,V.current)&&(ne&&clearTimeout(ne.timer),ne={text:R,timer:setTimeout(()=>{if(Z)return;let O=se;se=null,ne=null,T.current?.({role:"user",content:[{type:"text",text:R}],...O?{modelContext:O}:{}})},500)})}).catch(b=>{let R=b instanceof Error?b.message:"Tool call failed";B({jsonrpc:"2.0",id:_,error:{code:-32e3,message:R}})});return}if(Y==="ui/request-display-mode"&&_!=null){let G=H.params?.mode,W=G==="fullscreen"||G==="inline"||G==="pip"?G:"inline";y.current=W,B({jsonrpc:"2.0",id:_,result:{mode:W}}),B({jsonrpc:"2.0",method:"ui/notifications/host-context-changed",params:{displayMode:W}}),P.current?.(W);return}if(Y==="ui/resource-teardown"&&_!=null){B({jsonrpc:"2.0",id:_,result:{}});return}Y==="ping"&&_!=null&&B({jsonrpc:"2.0",id:_,result:{}})};return window.addEventListener("message",Q),()=>{Z=!0,clearTimeout(Fe),ne&&clearTimeout(ne.timer),window.removeEventListener("message",Q)}},[i,we]),op("iframe",{ref:m,src:pe,sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox",className:A(!p&&"ww:rounded-md ww:border ww:border-border",n),style:{height:p?"100%":k,minWidth:p||!M?void 0:`min(${M}px, 100%)`,width:"100%",border:"none",colorScheme:s?"dark":"auto"},title:"MCP App"})}import{jsx as $t,jsxs as rp}from"react/jsx-runtime";function bi({icon:e,title:t,description:a,suggestions:o,onSuggestionSelect:r}){return rp("div",{className:"ww:flex ww:flex-col ww:items-center ww:justify-center ww:py-12 ww:px-6 ww:text-center ww:min-h-full",children:[e&&$t("div",{className:"ww:mb-4 ww:flex ww:items-center ww:justify-center ww:size-12 ww:rounded-xl ww:bg-foreground ww:text-background",children:e}),$t("h2",{className:"ww:text-lg ww:font-semibold ww:text-foreground",children:t}),a&&$t("p",{className:"ww:mt-1 ww:text-sm ww:text-muted-foreground ww:max-w-sm",children:a}),o&&o.length>0&&$t("div",{className:"ww:mt-6 ww:w-full ww:max-w-md ww:flex ww:flex-col ww:gap-2",children:o.map((s,n)=>$t("button",{type:"button",onClick:()=>r?.(s),className:A("ww:w-full ww:text-left ww:rounded-xl ww:border ww:border-border ww:bg-background ww:px-4 ww:py-3 ww:text-sm","ww:text-foreground ww:hover:bg-accent ww:hover:border-primary/30","ww:transition-all ww:duration-200 ww:ease-out ww:cursor-pointer","ww:animate-[ww-fade-in_0.2s_ease-out_both]"),style:{animationDelay:`${n*50}ms`},children:s},s))})]})}import{Component as sp}from"react";import{jsx as hr,jsxs as ip}from"react/jsx-runtime";function np({onRetry:e}){let{t}=U();return ip("div",{className:"ww:flex ww:items-center ww:justify-between ww:rounded-md ww:border ww:border-border ww:bg-muted/50 ww:px-4 ww:py-3 ww:text-sm ww:text-muted-foreground",children:[hr("span",{children:t.widgetErrorBoundary.failedToLoad}),hr("button",{type:"button",onClick:e,className:"ww:text-xs ww:font-medium ww:text-primary ww:hover:underline",children:t.widgetErrorBoundary.retry})]})}var Va=class extends sp{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.warn("[WaniWani] Widget failed to render:",t.message)}render(){return this.state.hasError?hr(np,{onRetry:()=>this.setState({hasError:!1})}):this.props.children}};import{Fragment as lp,jsx as oe,jsxs as rt}from"react/jsx-runtime";function Ti(e){return e?e.replace(/[-_]/g," ").replace(/^\w/,t=>t.toUpperCase()):"Tool"}function ja({messages:e,status:t,welcomeMessage:a,welcome:o,onSuggestionSelect:r,resourceEndpoint:s,chatSessionId:n,isDark:i,onFollowUp:l,onCallTool:u,onWidgetDisplayModeChange:f,fullscreenToolCallId:d,debug:p,showToolCalls:c=!0,toolDefinitions:m}){let C=e[e.length-1],w=e.length>0,x=d!=null,g=!x&&Ci(e,t);return rt(lp,{children:[!x&&(!w&&o?oe(bi,{...o,onSuggestionSelect:r}):a&&oe(tr,{from:"assistant",children:oe(ar,{children:oe(Wa,{children:a})})})),e.map(h=>{let L=h.parts.filter(T=>T.type==="text"),y=h.parts.filter(T=>T.type==="reasoning"),k=h.parts.filter(T=>T.type==="file"),v=h.parts.filter(T=>"toolCallId"in T),M=h===C&&h.role==="assistant",E=L.length>0,F=x?v.some(T=>T.toolCallId===d):!1;return x&&!F?oe("div",{style:{display:"none"}},h.id):h.role==="assistant"&&!pr(h)?oe("div",{style:{display:"none"}},h.id):rt(tr,{from:h.role,children:[!F&&y.map((T,S)=>rt(nr,{isStreaming:T.state==="streaming",children:[oe(ir,{}),oe(lr,{children:T.text})]},`reasoning-${h.id}-${S}`)),v.map(T=>{let S="output"in T?T.output:void 0,P=za(T.toolName,S,m),$=wi(T.toolName,S,m),V=T.toolCallId===d;return rt("div",{style:V?{position:"absolute",inset:0,zIndex:10,display:"flex",flexDirection:"column",overflow:"hidden",background:"var(--ww-color-background)"}:void 0,children:[oe("div",{style:V?{display:"none"}:void 0,children:c?rt(di,{children:[oe(fi,{title:T.title??Ti(T.toolName),state:T.state}),rt(pi,{children:[oe(mi,{input:T.input,debug:p}),S!==void 0&&oe(xi,{output:S,errorText:"errorText"in T?T.errorText:void 0,debug:p})]})]}):oe(ci,{title:T.title??Ti(T.toolName),state:T.state})}),P&&s&&S!==void 0&&oe(Va,{children:oe(mr,{isFullscreen:V,resourceUri:P,toolInput:T.input??{},toolResult:{content:S.content,structuredContent:S.structuredContent,_meta:S._meta},resourceEndpoint:s,chatSessionId:n,isDark:i,autoHeight:$,toolDefinitions:m,onFollowUp:l,onCallTool:u,onDisplayModeChange:f?we=>f(we,{toolCallId:T.toolCallId,resourceUri:P,toolInput:T.input??{},toolResult:{content:S.content,structuredContent:S.structuredContent,_meta:S._meta},autoHeight:$}):void 0})})]},T.toolCallId)}),!F&&oe("div",{children:rt(ar,{children:[k.length>0&&oe(Ss,{files:k}),E?L.map((T,S)=>{let P=M&&t==="streaming"&&S===L.length-1;return oe(Wa,{isStreaming:P,children:T.type==="text"?T.text:""},`${h.id}-${S}`)}):null]})})]},h.id)}),g&&oe(Ii,{})]})}import{jsx as Pi,jsxs as fp}from"react/jsx-runtime";var up="https://app.waniwani.ai/assets/waniwani-logo.svg",dp="https://waniwani.ai";function $a(){let{t:e}=U();return fp("a",{href:dp,target:"_blank",rel:"noopener noreferrer",className:"ww:flex ww:items-center ww:gap-1.5 ww:text-[11px] ww:text-muted-foreground ww:opacity-70 hover:ww:opacity-100 ww:transition-opacity",children:[Pi("span",{children:e.poweredBy.label}),Pi("img",{src:up,alt:"WaniWani",width:72,height:10,"data-waniwani-logo":"",className:"ww:h-2.5 ww:w-auto"})]})}import{jsx as Xa}from"react/jsx-runtime";function Qa({suggestions:e,isLoading:t,onSelect:a,className:o,...r}){return e.length===0&&!t?null:Xa("div",{className:A("ww:px-4 ww:py-2",o),...r,children:Xa("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl ww:flex ww:flex-wrap ww:gap-2",children:t?[0,1,2].map(s=>Xa("div",{className:"ww:h-7 ww:rounded-full ww:bg-accent ww:animate-pulse",style:{width:`${60+s*20}px`}},s)):e.map((s,n)=>Xa("button",{type:"button",onClick:()=>a(s),className:A("ww:rounded-full ww:border ww:border-border ww:bg-background ww:px-3 ww:py-1 ww:text-xs","ww:text-foreground ww:hover:bg-accent ww:hover:border-primary/30","ww:transition-all ww:duration-200 ww:ease-out ww:cursor-pointer","ww:animate-[ww-fade-in_0.2s_ease-out_both]"),style:{animationDelay:`${n*50}ms`},children:s},s))})})}import{useEffect as cp,useRef as pp,useState as mp}from"react";import{jsx as J,jsxs as st}from"react/jsx-runtime";var Ai=20;function hp({label:e}){return st("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[J("title",{children:e}),J("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),J("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function gp({label:e}){return st("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[J("title",{children:e}),J("path",{d:"M3 12a9 9 0 1 0 3-6.7"}),J("polyline",{points:"3 4 3 9 8 9"}),J("line",{x1:"12",y1:"7",x2:"12",y2:"12"}),J("line",{x1:"12",y1:"12",x2:"15",y2:"14"})]})}function wp({label:e}){return st("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",role:"img","aria-label":e,children:[J("title",{children:e}),J("polyline",{points:"3 6 5 6 21 6"}),J("path",{d:"M19 6l-2 14a2 2 0 0 1-2 2H9a2 2 0 0 1-2-2L5 6"}),J("path",{d:"M10 11v6"}),J("path",{d:"M14 11v6"})]})}function Ka({threads:e,activeThreadId:t,onNewThread:a,onSelectThread:o,onDeleteThread:r}){let{locale:s,t:n}=U(),[i,l]=mp(!1),u=pp(null);cp(()=>{if(!i)return;let p=c=>{let m=u.current;m&&(c.composedPath().includes(m)||l(!1))};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[i]);let f=e.slice(0,Ai),d=Math.max(0,e.length-Ai);return st("div",{ref:u,className:"ww:relative ww:flex ww:items-center ww:gap-1",children:[J("button",{type:"button",onClick:a,title:n.threadMenu.newChat,"aria-label":n.threadMenu.newChat,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:J(hp,{label:n.threadMenu.newChat})}),J("button",{type:"button",onClick:()=>l(p=>!p),title:n.threadMenu.threadHistory,"aria-label":n.threadMenu.threadHistory,"aria-expanded":i,className:"ww:p-1.5 ww:rounded-md ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/5 ww:transition-colors ww:cursor-pointer",children:J(gp,{label:n.threadMenu.threadHistory})}),i&&st("div",{role:"menu",className:"ww:absolute ww:right-0 ww:top-full ww:mt-1 ww:w-72 ww:max-h-80 ww:overflow-y-auto ww:rounded-lg ww:border ww:border-border ww:bg-background ww:shadow-lg ww:z-50",children:[f.length===0&&J("div",{className:"ww:px-3 ww:py-3 ww:text-xs ww:text-muted-foreground",children:n.threadMenu.noPreviousChats}),f.map(p=>{let c=p.threadId===t,m=Date.parse(p.updatedAt);return st("div",{className:`ww:flex ww:items-center ww:gap-2 ww:px-3 ww:py-2 ww:text-xs hover:ww:bg-foreground/5 ${c?"ww:bg-foreground/5":""}`,children:[st("button",{type:"button",onClick:()=>{o(p.threadId),l(!1)},className:"ww:flex-1 ww:min-w-0 ww:text-left ww:cursor-pointer",children:[J("div",{className:"ww:truncate ww:text-foreground ww:font-medium",children:p.title}),J("div",{className:"ww:text-[10px] ww:text-muted-foreground",children:Number.isNaN(m)?"":Lo(m,s)})]}),J("button",{type:"button",onClick:C=>{C.stopPropagation(),r(p.threadId)},title:n.threadMenu.deleteThread,"aria-label":n.threadMenu.deleteThread,className:"ww:p-1 ww:rounded ww:text-muted-foreground hover:ww:text-foreground hover:ww:bg-foreground/10 ww:transition-colors ww:cursor-pointer",children:J(wp,{label:n.threadMenu.deleteThread})})]},p.threadId)}),d>0&&J("div",{className:"ww:px-3 ww:py-2 ww:text-[10px] ww:text-muted-foreground ww:border-t ww:border-border",children:n.threadMenu.hiddenThreads(d)})]})]})}import{useCallback as xp,useRef as Lp}from"react";function Ja(e){let t=Lp(e);return t.current=e,xp(async a=>{let{api:o,headers:r,onCallTool:s,sessionId:n}=t.current;if(s)return s(a);let i=`${o??"/api/waniwani"}/tool`,l=typeof n=="string"&&n.trim().length>0?n.trim():void 0,u=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",...l?{"X-Session-Id":l}:{},...r},body:JSON.stringify(a)});if(!u.ok)throw new Error(`Tool call failed: ${u.status} ${u.statusText}`);return u.json()},[])}import{useChat as _p}from"@ai-sdk/react";import{useCallback as fe,useEffect as Re,useRef as le,useState as nt}from"react";import{DefaultChatTransport as Cp,uiMessageChunkSchema as Ip}from"ai";function Sp(e){let t=e?.cause,a=t?.issues??t?.errors;if(!Array.isArray(a))return null;let o=a.find(r=>r.code==="invalid_union");if(!o?.errors)return null;for(let r of o.errors){if(!Array.isArray(r)||r.some(i=>(i.code==="invalid_value"||i.code==="invalid_literal")&&i.path?.[0]==="type"))continue;let n=r.filter(i=>i.code==="unrecognized_keys").flatMap(i=>i.keys??[]);if(n.length>0)return n}return null}var Za=class extends Cp{processResponseStream(t){let a="",o=Ip(),r=o.validate?.bind(o);return t.pipeThrough(new TextDecoderStream).pipeThrough(new TransformStream({async transform(s,n){a+=s;let i=a.split(`
16
- `);a=i.pop()??"";for(let l of i){let u=l.trim();if(!u.startsWith("data:"))continue;let f=u.slice(5).trim();if(f!=="[DONE]")try{let d=JSON.parse(f);if(!r){n.enqueue(d);continue}let p=await r(d);if(p.success){n.enqueue(p.value);continue}let c=Sp(p.error);if(c?.length){let m={...d};for(let w of c)delete m[w];let C=await r(m);C.success&&n.enqueue(C.value)}}catch{}}}}))}};var yp="waniwani-memory";var Se="threads",Ya="by_memoryUserId",kp="by_updatedAt";var Mi="memoryUserId",vi="waniwani-memory-user-id",gr=null;function wr(){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 bp(e,t){if(t<1&&(e.objectStoreNames.contains("ids")||e.createObjectStore("ids")),t<2&&!e.objectStoreNames.contains(Se)){let a=e.createObjectStore(Se,{keyPath:"threadId"});a.createIndex(Ya,"memoryUserId",{unique:!1}),a.createIndex(kp,"updatedAt",{unique:!1})}}async function xr(){return new Promise((e,t)=>{let a=indexedDB.open(yp,2);a.onupgradeneeded=o=>{bp(a.result,o.oldVersion)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}async function Tp(){return xr()}async function Pp(e){return new Promise((t,a)=>{let s=e.transaction("ids","readonly").objectStore("ids").get(Mi);s.onsuccess=()=>t(typeof s.result=="string"?s.result:null),s.onerror=()=>a(s.error)})}async function Ap(e,t){return new Promise((a,o)=>{let n=e.transaction("ids","readwrite").objectStore("ids").put(t,Mi);n.onsuccess=()=>a(),n.onerror=()=>o(n.error)})}async function vp(){if(typeof indexedDB>"u")return null;try{let e=await Tp();try{let t=await Pp(e);if(t)return t;let a=wr();return await Ap(e,a),a}finally{e.close()}}catch{return null}}function Mp(){try{let e=localStorage.getItem(vi);if(e)return e;let t=wr();return localStorage.setItem(vi,t),t}catch{return null}}async function Ri(){let e=await vp();if(e)return e;let t=Mp();return t||(gr||(gr=wr()),gr)}var Fi=50,Bi=1e3;function eo(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.threadId=="string"&&typeof t.memoryUserId=="string"&&typeof t.title=="string"&&Array.isArray(t.messages)&&typeof t.createdAt=="string"&&typeof t.updatedAt=="string"}async function to(e){if(typeof indexedDB>"u")return null;let t=null;try{return t=await xr(),await e(t)}catch{return null}finally{try{t?.close()}catch{}}}function Lr(e){return new Promise((t,a)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>a(e.error)})}async function Cr(e){return await to(async a=>{let s=a.transaction(Se,"readonly").objectStore(Se).index(Ya),i=(await Lr(s.getAll(e))??[]).filter(eo);return i.sort((l,u)=>l.updatedAt<u.updatedAt?1:-1),i})??[]}async function Ir(e){return await to(async a=>{let r=a.transaction(Se,"readonly").objectStore(Se),s=await Lr(r.get(e));return eo(s)?s:null})??null}async function Sr(e){if(!eo(e))return;let t=e.messages.length>Bi?{...e,messages:e.messages.slice(e.messages.length-Bi)}:e;await to(async a=>{await new Promise((l,u)=>{let f=a.transaction(Se,"readwrite");f.oncomplete=()=>l(),f.onerror=()=>u(f.error),f.onabort=()=>u(f.error),f.objectStore(Se).put(t)});let o=a.transaction(Se,"readwrite"),r=o.objectStore(Se),s=r.index(Ya),i=(await Lr(s.getAll(t.memoryUserId))??[]).filter(eo);if(i.length>Fi){i.sort((u,f)=>u.updatedAt<f.updatedAt?-1:1);let l=i.slice(0,i.length-Fi);for(let u of l)r.delete(u.threadId)}return await new Promise((l,u)=>{o.oncomplete=()=>l(),o.onerror=()=>u(o.error),o.onabort=()=>u(o.error)}),null})}async function Di(e){await to(async t=>(await new Promise((a,o)=>{let r=t.transaction(Se,"readwrite");r.oncomplete=()=>a(),r.onerror=()=>o(r.error),r.onabort=()=>o(r.error),r.objectStore(Se).delete(e)}),null))}async function Ei(e){return(await Cr(e))[0]?.threadId??null}function _i(e){let t=e.trim();if(!t)return`Conversation on ${new Date().toISOString().slice(0,10)}`;let a=t.split(/\r?\n/,1)[0]??t;return a.length<=60?a:`${a.slice(0,60).trimEnd()}\u2026`}var Ni="waniwani-visitor-id";function Oi(e,t){return e.match(t)?.[1]??null}function Rp(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,o]of t){let r=Oi(e,o);if(r)return{name:a,version:r}}return null}function Fp(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,o]of t){let r=Oi(e,o);if(r)return{name:a,version:r.replace(/_/g,".")};if(a==="Linux"&&o.test(e))return{name:a,version:""}}return null}function Bp(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 Dp(e){let t=new TextEncoder().encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function Ep(){try{let a=localStorage.getItem(Ni);if(a)return a}catch{}let e=[navigator.userAgent,screen.width,screen.height,screen.colorDepth,Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.language,navigator.hardwareConcurrency??"",navigator.platform??""].join("|"),t=await Dp(e);try{localStorage.setItem(Ni,t)}catch{}return t}async function Ui(){let e=navigator.userAgent,[t,a]=await Promise.all([Ep(),Ri()]);return{userAgent:e,browser:Rp(e),os:Fp(e),deviceType:Bp(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 Np="x-session-id",Op=250;function Hi(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Ft()}function ao(){return new Date().toISOString()}function qi(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}async function Up(e,t){let a=`${e.replace(/\/$/,"")}/tools`,o=await fetch(a,{method:"GET",headers:t?{...t}:void 0});if(!o.ok)throw new Error(`[WaniWani] Failed to fetch /tools: ${o.status} ${o.statusText}`);let r=await o.json();if(!r||!Array.isArray(r.tools))return{};let s={};for(let n of r.tools)n&&typeof n.name=="string"&&(s[n.name]=n);return s}function oo(e){let{api:t="/api/waniwani",headers:a,body:o,onMessageSent:r,onResponseReceived:s,enableThreadHistory:n=!1,activeThreadId:i,onThreadChange:l}=e,u=le(a),f=le(o),d=le(n);Re(()=>{d.current=n},[n]);let p=le(void 0),c=le(null),[m,C]=nt(void 0),w=le(m),[x,g]=nt(i),h=le(x),[L,y]=nt([]),[k,v]=nt(!n),M=le(void 0),E=le(void 0),F=le(void 0),T=le(void 0),S=le(0),P=le(l);Re(()=>{P.current=l},[l]);let $=fe(I=>{h.current=I,g(I),I&&P.current?.(I)},[]),V=fe(async()=>{if(!n)return;let I=c.current?.memoryUserId;if(!I)return;let D=await Cr(I);y(D)},[n]),we=fe(()=>w.current,[]),pe=fe(I=>{let D=qi(I);D&&w.current!==D&&(w.current=D,C(D))},[]),me=fe(()=>{w.current=void 0,C(void 0)},[]);Re(()=>{u.current=a},[a]),Re(()=>{f.current=o},[o]),Re(()=>{let I=!1,D=S.current;return(async()=>{try{let ke=await Ui();if(I)return;c.current=ke}catch{}if(!n)return;let N=c.current?.memoryUserId;if(!N){v(!0);return}try{let ke=i??await Ei(N);if(I||D!==S.current)return;if(ke){let xe=await Ir(ke);if(I||D!==S.current)return;xe&&xe.memoryUserId===N&&(h.current=xe.threadId,g(xe.threadId),M.current=xe.createdAt,E.current=xe.title,xe.sessionId&&(w.current=xe.sessionId,C(xe.sessionId)),Y(xe.messages))}await V()}finally{I||v(!0)}})(),()=>{I=!0}},[]);let X=le(new Za({api:t,headers:()=>({...u.current}),body:()=>{let I={...f.current??{}},D=Object.hasOwn(I,"sessionId"),N=qi(I.sessionId);if(N)pe(N),I.sessionId=N;else if(D)me(),delete I.sessionId;else{let Ae=we();Ae&&(I.sessionId=Ae)}if(wt(p.current)&&(I.modelContext=p.current),c.current){let Ae=c.current;I.visitorContext={timezone:Ae.timezone,language:Ae.language,languages:Ae.languages,deviceType:Ae.deviceType,referrer:Ae.referrer,visitorId:Ae.visitorId};let _e=typeof I.visitor=="object"&&I.visitor!==null?I.visitor:{},fl=typeof _e.client=="object"&&_e.client!==null?_e.client:{};I.visitor={..._e,client:{...fl,memoryUserId:Ae.memoryUserId}}}let ke=typeof I.extra=="object"&&I.extra!==null&&!Array.isArray(I.extra)?I.extra:void 0,xe=c.current?.memoryUserId,qe=c.current?.language,Yt={};if(xe&&(Yt.memoryUserId=xe),qe&&(Yt.locale=qe),(Object.keys(Yt).length>0||ke)&&(I.extra={...Yt,...ke??{}}),d.current)if(Object.hasOwn(I,"threadId"))typeof I.threadId=="string"&&(h.current=I.threadId);else{let _e=h.current;_e||(_e=Hi(),M.current=ao(),E.current=void 0,$(_e)),I.threadId=_e}return I},fetch:(async(I,D)=>{let N=await fetch(I,D);return p.current=void 0,pe(N.headers.get(Np)),N})})),Z=le(null),he=le(null),se=le({}),[ne,Fe]=nt(0),B=e.skipRemoteConfig===!0,Q=fe(async()=>{if(!B)try{let I=await Up(t,u.current);se.current=I,Fe(D=>D+1)}catch(I){console.warn("[WaniWani] Failed to fetch tool definitions:",I instanceof Error?I.message:I)}},[t,B]);Re(()=>{Q()},[Q]);let{messages:q,sendMessage:H,setMessages:Y,status:_}=_p({messages:e.initialMessages,transport:X.current,onFinish({message:I}){s?.(),Z.current&&(he.current=I)},onError(I){console.warn("[WaniWani] Chat error:",I.message),Z.current&&(Z.current.reject(I),Z.current=null)}}),G=le(q);Re(()=>{G.current=q},[q]),Re(()=>{if(_==="ready"&&Z.current&&he.current){let I=Z.current,D=he.current;Z.current=null,he.current=null,I.resolve(D)}},[_]);let[W,b]=nt(""),[R,O]=nt([]),te=_==="submitted"||_==="streaming",ye=fe(I=>{O(D=>D.filter(N=>N.id!==I))},[]),Pe=te&&R.length>0,He=fe(I=>{let D=!!I.text?.trim(),N=!!I.files?.length;if(D||N){if(te){if(R.length>0)return;O(ke=>[...ke,{id:Ft(),text:I.text||"",files:I.files??[],modelContext:I.modelContext}]),b("");return}p.current=I.modelContext,H({text:I.text||"",files:I.files}),r?.(I.text||""),b("")}},[H,r,te,R.length]),rl=fe(I=>new Promise((D,N)=>{Z.current={resolve:D,reject:N},H({text:I}),r?.(I)}),[H,r]);Re(()=>{if(_!=="ready"||R.length===0)return;let[I,...D]=R;O(D),p.current=I.modelContext,H({text:I.text,files:I.files.length>0?I.files:void 0}),r?.(I.text)},[_,H,r,R]);let sl=fe(()=>{Y([]),O([]),me(),b(""),se.current={},Fe(I=>I+1),Q()},[Y,me,Q]),Jt=fe(()=>{if(!d.current)return;let I=c.current?.memoryUserId,D=h.current,N=G.current;if(!(!I||!D||N.length===0)){if(M.current||(M.current=ao()),!E.current){let ke=N.find(qe=>qe.role==="user"),xe=ke?ke.parts.map(qe=>"text"in qe&&typeof qe.text=="string"?qe.text:"").join(" "):"";E.current=_i(xe)}return{threadId:D,memoryUserId:I,title:E.current,messages:N,sessionId:w.current,createdAt:M.current,updatedAt:ao()}}},[]),Mr=fe(async()=>{let I=Jt();I&&(await Sr(I),await V())},[Jt,V]);Re(()=>{if(n&&k&&!(_==="submitted"||_==="streaming")&&q.length!==0)return F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{F.current=void 0;let I=Mr().finally(()=>{T.current===I&&(T.current=void 0)});T.current=I},Op),()=>{F.current&&clearTimeout(F.current)}},[n,k,q,_,Mr]);let Zt=fe(()=>{let I=T.current,D=F.current,N=D?Jt():void 0;return D&&(clearTimeout(D),F.current=void 0),(async()=>{I&&await I,N&&(await Sr(N),await V())})()},[Jt,V]),nl=fe(()=>{S.current+=1,Zt(),Y([]),O([]),me(),b("");let I=Hi();return M.current=ao(),E.current=void 0,$(I),V(),I},[Y,me,$,V,Zt]),lo=fe(async I=>{S.current+=1;let D=S.current;if(await Zt(),D!==S.current)return;let N=await Ir(I);D===S.current&&N&&($(N.threadId),M.current=N.createdAt,E.current=N.title,N.sessionId?(w.current=N.sessionId,C(N.sessionId)):me(),Y(N.messages),O([]),b(""))},[Y,me,$,Zt]),il=fe(async I=>{if(h.current===I){S.current+=1,F.current&&(clearTimeout(F.current),F.current=void 0);let D=T.current;D&&await D}await Di(I),await V(),h.current===I&&(Y([]),O([]),me(),b(""),h.current=void 0,g(void 0),M.current=void 0,E.current=void 0)},[Y,me,V]);Re(()=>{n&&k&&i!==void 0&&i!==h.current&&lo(i)},[i,n,k,lo]);let ll=fe(I=>{b(I.target.value)},[]),Rr=q[q.length-1],Fr=q.length>0,ul=te&&(!Fr||Rr.role==="user"),dl=se.current;return{messages:q,status:_,text:W,setText:b,handleSubmit:He,handleTextChange:ll,isLoading:te,showLoaderBubble:ul,lastMessage:Rr,hasMessages:Fr,sendMessage:H,sendMessageAndWait:rl,reset:sl,queuedMessages:R,queueFull:Pe,removeQueuedMessage:ye,sessionId:m,toolDefinitions:dl,refreshToolDefinitions:Q,threads:L,activeThreadId:x,isThreadHistoryReady:k,startNewThread:nl,switchThread:lo,deleteThread:il}}import{useEffect as Gi,useRef as Hp,useState as qp}from"react";var Gp={debug:!1,eval:!1};function Wi(e="/api/waniwani",t,a=!1){let[o,r]=qp(Gp),s=Hp(t);return Gi(()=>{s.current=t},[t]),Gi(()=>{a||(async()=>{try{let n=s.current,l=await(await fetch(`${e}/config`,{headers:n?{...n}:void 0})).json();r({debug:l.debug===!0,eval:l.eval===!0})}catch{}})()},[e,a]),o}import{useCallback as Wp,useEffect as yr,useRef as zp,useState as Vp}from"react";function jp(e){for(let t of e.parts){let a=t;if(a.type==="data"||a.type==="data-suggestions"){let o=a.data;if(o&&Array.isArray(o.suggestions))return o.suggestions}}return null}function zi(e){return typeof e=="object"&&e!==null&&"initial"in e}function ro(e){let{messages:t,status:a,config:o}=e,r=zi(o)&&o.initial?o.initial:void 0,[s,n]=Vp(r??[]),i=zp(a),l=o===!0||zi(o)&&o.dynamic!==!1,u=Wp(()=>{n([])},[]),f=t.length>0;yr(()=>{!f&&r&&r.length>0&&n(r)},[r,f]);let d=t[t.length-1];return yr(()=>{d?.role==="user"&&u()},[d,u]),yr(()=>{let p=i.current;if(i.current=a,p==="streaming"&&a==="ready"&&l){let c=[...t].reverse().find(C=>C.role==="assistant");if(!c)return;let m=jp(c);m&&n(m)}},[a,l,t]),{suggestions:s,isLoading:!1,clear:u}}import{useEffect as $p,useRef as Xp,useState as Qp}from"react";var Kp=50,Jp=30,Zp=2e3,Vi=500;function so(e,t=!0){let[a,o]=Qp(""),r=Xp(void 0);return $p(()=>{if(!t){o("");return}let s=0,n=!1,i=!1,l=()=>{i||(n?(s--,o(e.slice(0,s)),s<=0?(n=!1,r.current=setTimeout(l,Vi)):r.current=setTimeout(l,Jp)):(s++,o(e.slice(0,s)),s>=e.length?(n=!0,r.current=setTimeout(l,Zp)):r.current=setTimeout(l,Kp)))};return r.current=setTimeout(l,Vi),()=>{i=!0,clearTimeout(r.current)}},[e,t]),a}function no(e,t){let a=t?.Authorization,o=typeof a=="string"&&a.startsWith("Bearer ")?a.slice(7):null;return o?`${e}/resource?token=${encodeURIComponent(o)}`:`${e}/resource`}var ji={primaryColor:"#6366f1",primaryForeground:"#1f2937",backgroundColor:"#ffffff",textColor:"#1f2937",mutedColor:"#6b7280",borderColor:"#e5e7eb",borderWidth:0,boxShadow:"none",assistantBubbleColor:"#f3f4f6",userBubbleColor:"#f4f4f4",inputBackgroundColor:"#f9fafb",borderRadius:16,messageBorderRadius:12,fontFamily:"system-ui, -apple-system, 'Segoe UI', sans-serif",headerBackgroundColor:"#ffffff",headerTextColor:"#1f2937",statusColor:"#22c55e",toolCardColor:"#f4f4f5"},Yp={backgroundColor:"#212121",headerBackgroundColor:"#1e1e1e",headerTextColor:"#ececec",textColor:"#ececec",primaryForeground:"#ffffff",mutedColor:"#8e8ea0",borderColor:"#444444",assistantBubbleColor:"#2f2f2f",userBubbleColor:"#303030",inputBackgroundColor:"#2f2f2f",primaryColor:"#6366f1",statusColor:"#22c55e",toolCardColor:"#262626"},em={primaryColor:["--ww-primary","--ww-color-primary"],primaryForeground:["--ww-primary-fg","--ww-color-primary-foreground"],backgroundColor:["--ww-bg","--ww-color-background"],textColor:["--ww-text","--ww-color-foreground","--ww-color-accent-foreground"],mutedColor:["--ww-muted","--ww-color-muted-foreground"],borderColor:["--ww-border","--ww-color-border"],borderWidth:["--ww-border-width"],boxShadow:["--ww-shadow"],assistantBubbleColor:["--ww-assistant-bubble","--ww-color-accent"],userBubbleColor:["--ww-user-bubble"],inputBackgroundColor:["--ww-input-bg","--ww-color-input"],borderRadius:["--ww-radius"],messageBorderRadius:["--ww-msg-radius"],fontFamily:["--ww-font"],headerBackgroundColor:["--ww-header-bg"],headerTextColor:["--ww-header-text"],statusColor:["--ww-status"],toolCardColor:["--ww-tool-card","--ww-color-tool-card"]};function kr(e){return{...ji,...e}}function Xt(e){let t={};for(let[a,o]of Object.entries(em)){let r=e[a];if(r===void 0)continue;let s=typeof r=="number"?`${r}px`:String(r);for(let n of o)t[n]=s}return t}import{jsx as ce,jsxs as Qt}from"react/jsx-runtime";var rm=tm(function(t,a){let{theme:o,title:r="Assistant",width:s,height:n,className:i,allowAttachments:l=!1,welcomeMessage:u,welcome:f,placeholder:d="Ask me anything...",triggerEvent:p="triggerDemoRequest",api:c,debug:m,enableThreadHistory:C=!1,showToolCalls:w=!0}=t,x=c??"/api/waniwani",g=no(x,t.headers),h=kr(o),L=Xt(h),y=h.backgroundColor.replace("#",""),k=parseInt(y.substring(0,2),16),v=parseInt(y.substring(2,4),16),M=parseInt(y.substring(4,6),16),E=(k*299+v*587+M*114)/1e3<128,F=Wi(x,t.headers,t.skipRemoteConfig),T=m??F.debug,S=oo({...t,api:x}),P=Ja({...t,api:x,sessionId:S.sessionId}),$=so(d,!S.text),[V,we]=Xi(!1),[pe,me]=Xi(null),X=$i(null),Z=$i(void 0),he=br(()=>{let B=X.current;if(!B)return;B.scrollIntoView({behavior:"smooth",block:"center"});let Q=B.querySelector("textarea");Q&&setTimeout(()=>Q.focus(),300),we(!0),clearTimeout(Z.current),Z.current=setTimeout(()=>we(!1),2e3)},[]),se=ro({messages:S.messages,status:S.status,config:t.suggestions}),ne=br(B=>{let Q=B.content.map(q=>q.text??"").join("").trim();Q&&S.handleSubmit({text:Q,files:[],modelContext:B.modelContext})},[S.handleSubmit]),Fe=br(B=>{se.clear(),S.handleSubmit({text:B,files:[]})},[se.clear,S.handleSubmit]);return om(a,()=>({sendMessage:B=>{S.handleSubmit({text:B,files:[]}),he()},sendMessageAndWait:B=>S.sendMessageAndWait(B),reset:S.reset,focus:he,get messages(){return S.messages}}),[S.handleSubmit,S.sendMessageAndWait,S.reset,S.messages,he]),am(()=>{if(!p)return;let B=Q=>{let q=Q.detail,H=typeof q?.message=="string"?q.message:void 0;H&&S.handleSubmit({text:H,files:[]}),he()};return window.addEventListener(p,B),()=>window.removeEventListener(p,B)},[p,S.handleSubmit,he]),Qt("div",{ref:X,style:{...L,width:s,height:n},"data-waniwani-chat":"","data-waniwani-layout":"card",...E?{"data-waniwani-dark":""}:{},className:A("ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground ww:bg-background ww:rounded-[var(--ww-radius)] ww:overflow-hidden",V&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background",i),children:[Qt("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-2 ww:px-6 ww:py-3",style:{backgroundColor:h.headerBackgroundColor,color:h.headerTextColor},children:[ce("div",{className:"ww:text-sm ww:font-semibold ww:truncate ww:flex-1 ww:min-w-0",children:r}),ce(Is,{messages:S.messages,evalEnabled:F.eval,api:x}),C&&ce(Ka,{threads:S.threads,activeThreadId:S.activeThreadId,onNewThread:S.startNewThread,onSelectThread:B=>{S.switchThread(B)},onDeleteThread:B=>{S.deleteThread(B)}})]}),Qt(Zr,{className:"ww:flex-1 ww:min-h-0 ww:bg-background",children:[ce(Yr,{scrollClassName:pe?"ww:!relative ww:!overflow-hidden":void 0,children:ce(ja,{messages:S.messages,status:S.status,welcomeMessage:u,welcome:f,onSuggestionSelect:Fe,resourceEndpoint:g,chatSessionId:S.sessionId,isDark:E,onFollowUp:ne,onCallTool:P,fullscreenToolCallId:pe,debug:T,showToolCalls:w,toolDefinitions:S.toolDefinitions,onWidgetDisplayModeChange:(B,Q)=>{me(B==="fullscreen"?Q.toolCallId:null)}})}),ce(es,{})]}),ce("div",{style:pe?{display:"none"}:void 0,children:ce(Qa,{suggestions:se.suggestions,isLoading:se.isLoading,onSelect:Fe})}),ce("div",{style:pe?{display:"none"}:void 0,children:ce(da,{queuedMessages:S.queuedMessages,onRemove:S.removeQueuedMessage})}),ce("div",{style:pe?{display:"none"}:void 0,children:ce("div",{className:"ww:shrink-0 ww:px-4 ww:pb-8 ww:pt-2 ww:bg-background",children:Qt("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl",children:[ce(na,{onSubmit:S.handleSubmit,globalDrop:l,multiple:l,className:"ww:rounded-2xl ww:border-border ww:bg-input",children:Qt("div",{className:"ww:flex ww:items-center ww:gap-1 ww:pl-4 ww:pr-3 ww:py-2.5",children:[l&&ce(ua,{}),ce(ia,{onChange:S.handleTextChange,value:S.text,placeholder:$,className:"ww:min-h-0 ww:py-1 ww:px-0"}),ce(la,{status:S.status,disabled:S.queueFull})]})}),ce($a,{})]})})})]})});import{forwardRef as Ki,useCallback as io,useEffect as xt,useImperativeHandle as nm,useRef as Kt,useState as Tr}from"react";import{jsx as sm}from"react/jsx-runtime";function Qi({text:e}){let{t}=U();return e===!1?null:sm("span",{className:"ww:text-[11px] ww:text-muted-foreground ww:opacity-70",children:e||t.aiDisclaimer.default})}import{jsx as re,jsxs as Qe}from"react/jsx-runtime";var Pr=Ki(function(t,a){let{locale:o,messages:r}=t;return re(xo,{locale:o,messages:r,children:re(im,{...t,ref:a})})}),im=Ki(function(t,a){let{t:o,ready:r}=U(),{appearance:s,className:n,allowAttachments:i=!1,welcomeMessage:l,welcome:u,placeholder:f=o.promptInput.placeholder,triggerEvent:d="triggerDemoRequest",api:p,mcp:c,debug:m=!1,readOnly:C=!1,title:w,headerActions:x,hideHeader:g=!1,enableThreadHistory:h=!1,showToolCalls:L=!0,initializing:y=!1,disclaimer:k}=t,v=s?.theme,M=s?.variables,E=M?Xt(M):{},[F,T]=Tr(!1);xt(()=>{if(v!=="auto"||typeof window>"u")return;let b=window.matchMedia("(prefers-color-scheme: dark)");T(b.matches);let R=()=>T(b.matches);return b.addEventListener("change",R),()=>b.removeEventListener("change",R)},[v]);let S=v==="dark"||v==="auto"&&F,P=oo({...t,api:p}),$=Ja({...t,api:p,sessionId:P.sessionId,onCallTool:c?.onCallTool}),V=c?.resourceEndpoint??no(p,t.headers),we=so(f,!P.text),[pe,me]=Tr(null),X=Kt(null),Z=Kt(null),he=Kt(null),se=Kt(null),[ne,Fe]=Tr(!0),B=Kt(ne);B.current=ne;let Q=io(()=>{let b=X.current;if(!b)return;let R=b.querySelector("textarea");R&&R.focus()},[]),q=io((b="smooth")=>{let R=Z.current;R&&R.scrollTo({top:R.scrollHeight,behavior:b})},[]);xt(()=>{let b=se.current,R=Z.current;if(!b||!R)return;let O=new IntersectionObserver(([te])=>Fe(te.isIntersecting),{root:R,rootMargin:"0px 0px 200px 0px",threshold:0});return O.observe(b),()=>O.disconnect()},[]),xt(()=>{(P.messages[P.messages.length-1]?.role==="user"||B.current)&&q("smooth")},[P.messages.length,P.messages[P.messages.length-1]]),xt(()=>{q("auto")},[q]),xt(()=>{if(typeof ResizeObserver>"u")return;let b=Z.current,R=he.current;if(!b&&!R)return;let O=b?.scrollHeight??0,te=b?.clientHeight??0,ye=new ResizeObserver(()=>{let Pe=Z.current;if(!Pe)return;let He=Pe.scrollTop+te>=O-5;O=Pe.scrollHeight,te=Pe.clientHeight,He&&q("auto")});return b&&ye.observe(b),R&&ye.observe(R),()=>ye.disconnect()},[q]);let H=ro({messages:P.messages,status:P.status,config:t.suggestions}),Y=io(b=>{let R=b.content.map(O=>O.text??"").join("").trim();R&&P.handleSubmit({text:R,files:[],modelContext:b.modelContext})},[P.handleSubmit]),_=io(b=>{H.clear(),P.handleSubmit({text:b,files:[]})},[H.clear,P.handleSubmit]);nm(a,()=>({sendMessage:b=>{P.handleSubmit({text:b,files:[]}),Q()},sendMessageAndWait:b=>P.sendMessageAndWait(b),reset:P.reset,focus:Q,get messages(){return P.messages}}),[P.handleSubmit,P.sendMessageAndWait,P.reset,P.messages,Q]),xt(()=>{if(!d)return;let b=R=>{let O=R.detail,te=typeof O?.message=="string"?O.message:void 0;te&&P.handleSubmit({text:te,files:[]}),Q()};return window.addEventListener(d,b),()=>window.removeEventListener(d,b)},[d,P.handleSubmit,Q]);let G=!g&&!!(w||h||x),W=y||!r;return Qe("div",{ref:X,style:{...E,maxHeight:"inherit",opacity:W?0:1,transition:"opacity 220ms ease-out"},"data-waniwani-chat":"","data-waniwani-layout":"embed","data-color-scheme":v==="auto"?"auto":void 0,...W?{"data-waniwani-initializing":""}:{},...S?{"data-waniwani-dark":""}:{},className:A("ww:relative ww:w-full ww:h-full ww:flex ww:flex-col ww:bg-background ww:text-foreground ww:font-[family-name:var(--ww-font)] ww:overflow-hidden",v==="dark"&&"dark",n),children:[G&&Qe("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-2 ww:px-6 ww:py-3 ww:border-b ww:border-border",style:{backgroundColor:"var(--ww-color-card-header)",color:"var(--ww-color-card-header-foreground)"},children:[w&&re("div",{className:"ww:text-sm ww:font-semibold ww:truncate ww:flex-1 ww:min-w-0",children:w}),!w&&re("div",{className:"ww:flex-1"}),x,h&&re(Ka,{threads:P.threads,activeThreadId:P.activeThreadId,onNewThread:P.startNewThread,onSelectThread:b=>{P.switchThread(b)},onDeleteThread:b=>{P.deleteThread(b)}})]}),Qe("div",{ref:Z,className:A("ww:relative ww:flex-1 ww:min-h-0",pe?"ww:overflow-hidden":"ww:overflow-y-auto"),children:[Qe("div",{ref:he,className:A("ww:mx-auto ww:w-full ww:max-w-3xl ww:px-4 ww:py-6 ww:flex ww:flex-col ww:gap-6",pe&&"ww:!py-0"),children:[re(ja,{messages:P.messages,status:P.status,welcomeMessage:l,welcome:u,onSuggestionSelect:_,resourceEndpoint:V,chatSessionId:P.sessionId,isDark:S,onFollowUp:Y,onCallTool:$,fullscreenToolCallId:pe,debug:m,showToolCalls:L,toolDefinitions:P.toolDefinitions,onWidgetDisplayModeChange:(b,R)=>{me(b==="fullscreen"?R.toolCallId:null)}}),re("div",{ref:se,"aria-hidden":!0,style:{height:1}})]}),!ne&&!pe&&re("div",{className:"ww:sticky ww:bottom-2 ww:flex ww:justify-center ww:pointer-events-none",children:re(be,{type:"button",onClick:()=>q("smooth"),size:"icon",variant:"outline",className:"ww:rounded-full ww:shadow ww:pointer-events-auto","aria-label":"Scroll to latest",children:re(Ke,{className:"ww:size-4"})})})]}),!C&&Qe("div",{className:"ww:shrink-0 ww:bg-background",style:pe?{display:"none"}:void 0,children:[re(Qa,{suggestions:H.suggestions,isLoading:H.isLoading,onSelect:_}),re(da,{queuedMessages:P.queuedMessages,onRemove:P.removeQueuedMessage}),re("div",{className:"ww:px-4 ww:pb-2 ww:pt-2",children:Qe("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl",children:[re(na,{onSubmit:P.handleSubmit,globalDrop:i,multiple:i,className:"ww:rounded-2xl ww:border-border ww:bg-input",children:Qe("div",{className:"ww:flex ww:items-center ww:gap-1 ww:pl-4 ww:pr-3 ww:py-2.5",children:[i&&re(ua,{}),re(ia,{onChange:P.handleTextChange,value:P.text,placeholder:we,className:"ww:min-h-0 ww:py-1 ww:px-0"}),re(la,{status:P.status,disabled:P.queueFull})]})}),Qe("div",{className:"ww:pt-2 ww:pb-1 ww:flex ww:justify-center ww:items-center ww:gap-1.5",children:[re($a,{}),re(Qi,{text:k})]})]})})]})]})});import{forwardRef as hm,useEffect as gm,useMemo as tl,useState as al}from"react";var lm="https://app.waniwani.ai/api/mcp/chat",um={api:lm};function dm(){if(typeof document>"u")return null;if(document.currentScript instanceof HTMLScriptElement)return document.currentScript;let e=document.querySelectorAll("script[src]");for(let t of e)if(t instanceof HTMLScriptElement&&/embed/i.test(t.src))return t;return null}function fm(){let e=dm();if(!e)return{};let t=h=>e.getAttribute(h)??void 0,a=h=>{let L=e.getAttribute(h);if(L==null)return;let y=L.trim().toLowerCase();if(y==="true"||y==="1"||y==="")return!0;if(y==="false"||y==="0")return!1},o={},r=t("data-api");r&&(o.api=r);let s=t("data-token");s&&(o.token=s);let n=t("data-title");n&&(o.title=n);let i=t("data-welcome-message");i&&(o.welcomeMessage=i);let l=t("data-placeholder");l&&(o.placeholder=l);let u=t("data-mcp-server-url");u&&(o.mcpServerUrl=u);let f=t("data-channel-id");f&&(o.channelId=f);let d=a("data-show-tool-calls");d!==void 0&&(o.showToolCalls=d);let p=t("data-css");p&&(o.css=p);let c=t("data-suggestions");c&&(o.suggestions=c.split(",").map(h=>h.trim()).filter(Boolean));let m=a("data-enable-thread-history");m!==void 0&&(o.enableThreadHistory=m);let C=a("data-hide-header");C!==void 0&&(o.hideHeader=C);let w=t("data-theme");(w==="light"||w==="dark"||w==="auto")&&(o.appearance={theme:w});let x=t("data-locale");(x==="en"||x==="fr"||x==="es")&&(o.locale=x);let g=t("data-disclaimer");if(g!==void 0){let h=g.trim(),L=h.toLowerCase();L==="false"||L==="0"?o.disclaimer=!1:h&&(o.disclaimer=h)}return o}function Ar(e){if(!e)return{};let t={};for(let a in e)e[a]!==void 0&&(t[a]=e[a]);return t}function vr(e,t,a){let o=a??fm(),r=cm(t,o,e),s={token:"",...um,...Ar(t),...Ar(o),...Ar(e),...r?{appearance:r}:{}};if(!s.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return s}function cm(e,t,a){let o=a?.appearance?.theme??t.appearance?.theme??e?.appearance?.theme,r={...e?.appearance?.variables??{},...t.appearance?.variables??{},...a?.appearance?.variables??{}},s=Object.keys(r).length>0;if(!o&&!s)return;let n={};return o&&(n.theme=o),s&&(n.variables=r),n}import{useEffect as xS,useState as LS}from"react";var pm="waniwani:config:";function Ji(e,t,a){return`${pm}${e}|${t}|${a??""}`}function Zi(e,t,a){if(typeof window>"u")return null;try{let o=window.sessionStorage.getItem(Ji(e,t,a));if(!o)return null;let r=JSON.parse(o);return r&&typeof r=="object"?r:null}catch{return null}}function Yi(e,t,a,o){if(!(typeof window>"u"))try{window.sessionStorage.setItem(Ji(e,t,a),JSON.stringify(o))}catch{}}async function el(e,t,a,o){try{let r=`${e.replace(/\/$/,"")}/config`,s=o?`${r}?channel=${encodeURIComponent(o)}`:r,n=await fetch(s,{method:"GET",headers:{Authorization:`Bearer ${t}`},signal:a});if(!n.ok)return{};let i=await n.json(),l=i&&typeof i=="object"&&"data"in i&&i.data?i.data:i;return l?mm(l):{}}catch{return{}}}function mm(e){let t={};return e.title!=null&&(t.title=e.title),e.welcomeMessage!=null&&(t.welcomeMessage=e.welcomeMessage),e.placeholder!=null&&(t.placeholder=e.placeholder),e.suggestions!=null&&e.suggestions.length>0&&(t.suggestions=e.suggestions),typeof e.enableThreadHistory=="boolean"&&(t.enableThreadHistory=e.enableThreadHistory),t}import{jsx as Lm}from"react/jsx-runtime";var wm=600,ol="https://app.waniwani.ai/api/mcp/chat",xm=hm(function(t,a){let{token:o,channelId:r,className:s,overrides:n}=t,i=tl(()=>({token:o,channelId:r,api:n?.api,mcpServerUrl:n?.mcpServerUrl,title:n?.title,hideHeader:n?.hideHeader,welcomeMessage:n?.welcomeMessage,placeholder:n?.placeholder,suggestions:n?.suggestions,enableThreadHistory:n?.enableThreadHistory,showToolCalls:n?.showToolCalls,appearance:n?.appearance,disclaimer:n?.disclaimer,locale:n?.locale}),[o,r,n?.api,n?.mcpServerUrl,n?.title,n?.hideHeader,n?.welcomeMessage,n?.placeholder,n?.suggestions,n?.enableThreadHistory,n?.showToolCalls,n?.appearance,n?.disclaimer,n?.locale]),l=n?.api??ol,[u,f]=al({}),[d,p]=al(!1);gm(()=>{if(!o){p(!0);return}let C=Zi(l,o,r);C&&(f(C),p(!0));let w=new AbortController,x=setTimeout(()=>p(!0),wm);return el(l,o,w.signal,r).then(g=>{w.signal.aborted||(Object.keys(g).length>0&&(Yi(l,o,r,g),f(g)),p(!0))}).catch(g=>{console.error("[WaniWani] Remote config fetch failed:",g),p(!0)}).finally(()=>clearTimeout(x)),()=>{w.abort(),clearTimeout(x)}},[l,o,r]);let c=tl(()=>vr(i,u,void 0),[i,u]),m={};return c.mcpServerUrl&&(m.mcpServerUrl=c.mcpServerUrl),c.channelId&&(m.channelId=c.channelId),Lm(Pr,{ref:a,api:c.api??ol,headers:{Authorization:`Bearer ${c.token}`},skipRemoteConfig:!0,body:Object.keys(m).length>0?m:void 0,appearance:c.appearance,title:c.title,hideHeader:c.hideHeader,welcomeMessage:c.welcomeMessage,welcome:n?.welcome,placeholder:c.placeholder,suggestions:c.suggestions?{initial:c.suggestions}:void 0,enableThreadHistory:c.enableThreadHistory,showToolCalls:c.showToolCalls,disclaimer:c.disclaimer,allowAttachments:n?.allowAttachments,locale:c.locale,messages:n?.messages,className:s,initializing:!d})});export{rm as ChatCard,Pr as ChatEmbed,Yp as DARK_THEME,ji as DEFAULT_THEME,mr as McpAppFrame,xm as WaniwaniChat,kr as mergeTheme,Xt as themeToCSSProperties};
16
+ `);a=i.pop()??"";for(let l of i){let u=l.trim();if(!u.startsWith("data:"))continue;let f=u.slice(5).trim();if(f!=="[DONE]")try{let d=JSON.parse(f);if(!r){n.enqueue(d);continue}let p=await r(d);if(p.success){n.enqueue(p.value);continue}let c=Sp(p.error);if(c?.length){let m={...d};for(let w of c)delete m[w];let C=await r(m);C.success&&n.enqueue(C.value)}}catch{}}}}))}};var yp="waniwani-memory";var Se="threads",Ya="by_memoryUserId",kp="by_updatedAt";var Mi="memoryUserId",vi="waniwani-memory-user-id",gr=null;function wr(){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 bp(e,t){if(t<1&&(e.objectStoreNames.contains("ids")||e.createObjectStore("ids")),t<2&&!e.objectStoreNames.contains(Se)){let a=e.createObjectStore(Se,{keyPath:"threadId"});a.createIndex(Ya,"memoryUserId",{unique:!1}),a.createIndex(kp,"updatedAt",{unique:!1})}}async function xr(){return new Promise((e,t)=>{let a=indexedDB.open(yp,2);a.onupgradeneeded=o=>{bp(a.result,o.oldVersion)},a.onsuccess=()=>e(a.result),a.onerror=()=>t(a.error)})}async function Tp(){return xr()}async function Pp(e){return new Promise((t,a)=>{let s=e.transaction("ids","readonly").objectStore("ids").get(Mi);s.onsuccess=()=>t(typeof s.result=="string"?s.result:null),s.onerror=()=>a(s.error)})}async function Ap(e,t){return new Promise((a,o)=>{let n=e.transaction("ids","readwrite").objectStore("ids").put(t,Mi);n.onsuccess=()=>a(),n.onerror=()=>o(n.error)})}async function vp(){if(typeof indexedDB>"u")return null;try{let e=await Tp();try{let t=await Pp(e);if(t)return t;let a=wr();return await Ap(e,a),a}finally{e.close()}}catch{return null}}function Mp(){try{let e=localStorage.getItem(vi);if(e)return e;let t=wr();return localStorage.setItem(vi,t),t}catch{return null}}async function Ri(){let e=await vp();if(e)return e;let t=Mp();return t||(gr||(gr=wr()),gr)}var Fi=50,Bi=1e3;function eo(e){if(!e||typeof e!="object")return!1;let t=e;return typeof t.threadId=="string"&&typeof t.memoryUserId=="string"&&typeof t.title=="string"&&Array.isArray(t.messages)&&typeof t.createdAt=="string"&&typeof t.updatedAt=="string"}async function to(e){if(typeof indexedDB>"u")return null;let t=null;try{return t=await xr(),await e(t)}catch{return null}finally{try{t?.close()}catch{}}}function Lr(e){return new Promise((t,a)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>a(e.error)})}async function Cr(e){return await to(async a=>{let s=a.transaction(Se,"readonly").objectStore(Se).index(Ya),i=(await Lr(s.getAll(e))??[]).filter(eo);return i.sort((l,u)=>l.updatedAt<u.updatedAt?1:-1),i})??[]}async function Ir(e){return await to(async a=>{let r=a.transaction(Se,"readonly").objectStore(Se),s=await Lr(r.get(e));return eo(s)?s:null})??null}async function Sr(e){if(!eo(e))return;let t=e.messages.length>Bi?{...e,messages:e.messages.slice(e.messages.length-Bi)}:e;await to(async a=>{await new Promise((l,u)=>{let f=a.transaction(Se,"readwrite");f.oncomplete=()=>l(),f.onerror=()=>u(f.error),f.onabort=()=>u(f.error),f.objectStore(Se).put(t)});let o=a.transaction(Se,"readwrite"),r=o.objectStore(Se),s=r.index(Ya),i=(await Lr(s.getAll(t.memoryUserId))??[]).filter(eo);if(i.length>Fi){i.sort((u,f)=>u.updatedAt<f.updatedAt?-1:1);let l=i.slice(0,i.length-Fi);for(let u of l)r.delete(u.threadId)}return await new Promise((l,u)=>{o.oncomplete=()=>l(),o.onerror=()=>u(o.error),o.onabort=()=>u(o.error)}),null})}async function Di(e){await to(async t=>(await new Promise((a,o)=>{let r=t.transaction(Se,"readwrite");r.oncomplete=()=>a(),r.onerror=()=>o(r.error),r.onabort=()=>o(r.error),r.objectStore(Se).delete(e)}),null))}async function Ei(e){return(await Cr(e))[0]?.threadId??null}function _i(e){let t=e.trim();if(!t)return`Conversation on ${new Date().toISOString().slice(0,10)}`;let a=t.split(/\r?\n/,1)[0]??t;return a.length<=60?a:`${a.slice(0,60).trimEnd()}\u2026`}var Ni="waniwani-visitor-id";function Oi(e,t){return e.match(t)?.[1]??null}function Rp(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,o]of t){let r=Oi(e,o);if(r)return{name:a,version:r}}return null}function Fp(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,o]of t){let r=Oi(e,o);if(r)return{name:a,version:r.replace(/_/g,".")};if(a==="Linux"&&o.test(e))return{name:a,version:""}}return null}function Bp(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 Dp(e){let t=new TextEncoder().encode(e),a=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(a)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function Ep(){try{let a=localStorage.getItem(Ni);if(a)return a}catch{}let e=[navigator.userAgent,screen.width,screen.height,screen.colorDepth,Intl.DateTimeFormat().resolvedOptions().timeZone,navigator.language,navigator.hardwareConcurrency??"",navigator.platform??""].join("|"),t=await Dp(e);try{localStorage.setItem(Ni,t)}catch{}return t}async function Ui(){let e=navigator.userAgent,[t,a]=await Promise.all([Ep(),Ri()]);return{userAgent:e,browser:Rp(e),os:Fp(e),deviceType:Bp(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 Np="x-session-id",Op=250;function Hi(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():Ft()}function ao(){return new Date().toISOString()}function qi(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}async function Up(e,t){let a=`${e.replace(/\/$/,"")}/tools`,o=await fetch(a,{method:"GET",headers:t?{...t}:void 0});if(!o.ok)throw new Error(`[WaniWani] Failed to fetch /tools: ${o.status} ${o.statusText}`);let r=await o.json();if(!r||!Array.isArray(r.tools))return{};let s={};for(let n of r.tools)n&&typeof n.name=="string"&&(s[n.name]=n);return s}function oo(e){let{api:t="/api/waniwani",headers:a,body:o,onMessageSent:r,onResponseReceived:s,enableThreadHistory:n=!1,activeThreadId:i,onThreadChange:l}=e,u=le(a),f=le(o),d=le(n);Re(()=>{d.current=n},[n]);let p=le(void 0),c=le(null),[m,C]=nt(void 0),w=le(m),[x,g]=nt(i),h=le(x),[L,y]=nt([]),[k,v]=nt(!n),M=le(void 0),E=le(void 0),F=le(void 0),T=le(void 0),S=le(0),P=le(l);Re(()=>{P.current=l},[l]);let $=fe(I=>{h.current=I,g(I),I&&P.current?.(I)},[]),V=fe(async()=>{if(!n)return;let I=c.current?.memoryUserId;if(!I)return;let D=await Cr(I);y(D)},[n]),we=fe(()=>w.current,[]),pe=fe(I=>{let D=qi(I);D&&w.current!==D&&(w.current=D,C(D))},[]),me=fe(()=>{w.current=void 0,C(void 0)},[]);Re(()=>{u.current=a},[a]),Re(()=>{f.current=o},[o]),Re(()=>{let I=!1,D=S.current;return(async()=>{try{let ke=await Ui();if(I)return;c.current=ke}catch{}if(!n)return;let N=c.current?.memoryUserId;if(!N){v(!0);return}try{let ke=i??await Ei(N);if(I||D!==S.current)return;if(ke){let xe=await Ir(ke);if(I||D!==S.current)return;xe&&xe.memoryUserId===N&&(h.current=xe.threadId,g(xe.threadId),M.current=xe.createdAt,E.current=xe.title,xe.sessionId&&(w.current=xe.sessionId,C(xe.sessionId)),Y(xe.messages))}await V()}finally{I||v(!0)}})(),()=>{I=!0}},[]);let X=le(new Za({api:t,headers:()=>({...u.current}),body:()=>{let I={...f.current??{}},D=Object.hasOwn(I,"sessionId"),N=qi(I.sessionId);if(N)pe(N),I.sessionId=N;else if(D)me(),delete I.sessionId;else{let Ae=we();Ae&&(I.sessionId=Ae)}if(wt(p.current)&&(I.modelContext=p.current),c.current){let Ae=c.current;I.visitorContext={timezone:Ae.timezone,language:Ae.language,languages:Ae.languages,deviceType:Ae.deviceType,referrer:Ae.referrer,visitorId:Ae.visitorId};let _e=typeof I.visitor=="object"&&I.visitor!==null?I.visitor:{},fl=typeof _e.client=="object"&&_e.client!==null?_e.client:{};I.visitor={..._e,client:{...fl,memoryUserId:Ae.memoryUserId}}}let ke=typeof I.extra=="object"&&I.extra!==null&&!Array.isArray(I.extra)?I.extra:void 0,xe=c.current?.memoryUserId,qe=c.current?.language,Yt={};if(xe&&(Yt.memoryUserId=xe),qe&&(Yt.locale=qe),(Object.keys(Yt).length>0||ke)&&(I.extra={...Yt,...ke??{}}),d.current)if(Object.hasOwn(I,"threadId"))typeof I.threadId=="string"&&(h.current=I.threadId);else{let _e=h.current;_e||(_e=Hi(),M.current=ao(),E.current=void 0,$(_e)),I.threadId=_e}return I},fetch:(async(I,D)=>{let N=await fetch(I,D);return p.current=void 0,pe(N.headers.get(Np)),N})})),Z=le(null),he=le(null),se=le({}),[ne,Fe]=nt(0),B=e.skipRemoteConfig===!0,Q=fe(async()=>{if(!B)try{let I=await Up(t,u.current);se.current=I,Fe(D=>D+1)}catch(I){console.warn("[WaniWani] Failed to fetch tool definitions:",I instanceof Error?I.message:I)}},[t,B]);Re(()=>{Q()},[Q]);let{messages:q,sendMessage:H,setMessages:Y,status:_}=_p({messages:e.initialMessages,transport:X.current,onFinish({message:I}){s?.(),Z.current&&(he.current=I)},onError(I){console.warn("[WaniWani] Chat error:",I.message),Z.current&&(Z.current.reject(I),Z.current=null)}}),G=le(q);Re(()=>{G.current=q},[q]),Re(()=>{if(_==="ready"&&Z.current&&he.current){let I=Z.current,D=he.current;Z.current=null,he.current=null,I.resolve(D)}},[_]);let[W,b]=nt(""),[R,O]=nt([]),te=_==="submitted"||_==="streaming",ye=fe(I=>{O(D=>D.filter(N=>N.id!==I))},[]),Pe=te&&R.length>0,He=fe(I=>{let D=!!I.text?.trim(),N=!!I.files?.length;if(D||N){if(te){if(R.length>0)return;O(ke=>[...ke,{id:Ft(),text:I.text||"",files:I.files??[],modelContext:I.modelContext}]),b("");return}p.current=I.modelContext,H({text:I.text||"",files:I.files}),r?.(I.text||""),b("")}},[H,r,te,R.length]),rl=fe(I=>new Promise((D,N)=>{Z.current={resolve:D,reject:N},H({text:I}),r?.(I)}),[H,r]);Re(()=>{if(_!=="ready"||R.length===0)return;let[I,...D]=R;O(D),p.current=I.modelContext,H({text:I.text,files:I.files.length>0?I.files:void 0}),r?.(I.text)},[_,H,r,R]);let sl=fe(()=>{Y([]),O([]),me(),b(""),se.current={},Fe(I=>I+1),Q()},[Y,me,Q]),Jt=fe(()=>{if(!d.current)return;let I=c.current?.memoryUserId,D=h.current,N=G.current;if(!(!I||!D||N.length===0)){if(M.current||(M.current=ao()),!E.current){let ke=N.find(qe=>qe.role==="user"),xe=ke?ke.parts.map(qe=>"text"in qe&&typeof qe.text=="string"?qe.text:"").join(" "):"";E.current=_i(xe)}return{threadId:D,memoryUserId:I,title:E.current,messages:N,sessionId:w.current,createdAt:M.current,updatedAt:ao()}}},[]),Mr=fe(async()=>{let I=Jt();I&&(await Sr(I),await V())},[Jt,V]);Re(()=>{if(n&&k&&!(_==="submitted"||_==="streaming")&&q.length!==0)return F.current&&clearTimeout(F.current),F.current=setTimeout(()=>{F.current=void 0;let I=Mr().finally(()=>{T.current===I&&(T.current=void 0)});T.current=I},Op),()=>{F.current&&clearTimeout(F.current)}},[n,k,q,_,Mr]);let Zt=fe(()=>{let I=T.current,D=F.current,N=D?Jt():void 0;return D&&(clearTimeout(D),F.current=void 0),(async()=>{I&&await I,N&&(await Sr(N),await V())})()},[Jt,V]),nl=fe(()=>{S.current+=1,Zt(),Y([]),O([]),me(),b("");let I=Hi();return M.current=ao(),E.current=void 0,$(I),V(),I},[Y,me,$,V,Zt]),lo=fe(async I=>{S.current+=1;let D=S.current;if(await Zt(),D!==S.current)return;let N=await Ir(I);D===S.current&&N&&($(N.threadId),M.current=N.createdAt,E.current=N.title,N.sessionId?(w.current=N.sessionId,C(N.sessionId)):me(),Y(N.messages),O([]),b(""))},[Y,me,$,Zt]),il=fe(async I=>{if(h.current===I){S.current+=1,F.current&&(clearTimeout(F.current),F.current=void 0);let D=T.current;D&&await D}await Di(I),await V(),h.current===I&&(Y([]),O([]),me(),b(""),h.current=void 0,g(void 0),M.current=void 0,E.current=void 0)},[Y,me,V]);Re(()=>{n&&k&&i!==void 0&&i!==h.current&&lo(i)},[i,n,k,lo]);let ll=fe(I=>{b(I.target.value)},[]),Rr=q[q.length-1],Fr=q.length>0,ul=te&&(!Fr||Rr.role==="user"),dl=se.current;return{messages:q,status:_,text:W,setText:b,handleSubmit:He,handleTextChange:ll,isLoading:te,showLoaderBubble:ul,lastMessage:Rr,hasMessages:Fr,sendMessage:H,sendMessageAndWait:rl,reset:sl,queuedMessages:R,queueFull:Pe,removeQueuedMessage:ye,sessionId:m,toolDefinitions:dl,refreshToolDefinitions:Q,threads:L,activeThreadId:x,isThreadHistoryReady:k,startNewThread:nl,switchThread:lo,deleteThread:il}}import{useEffect as Gi,useRef as Hp,useState as qp}from"react";var Gp={debug:!1,eval:!1};function Wi(e="/api/waniwani",t,a=!1){let[o,r]=qp(Gp),s=Hp(t);return Gi(()=>{s.current=t},[t]),Gi(()=>{a||(async()=>{try{let n=s.current,l=await(await fetch(`${e}/config`,{headers:n?{...n}:void 0})).json();r({debug:l.debug===!0,eval:l.eval===!0})}catch{}})()},[e,a]),o}import{useCallback as Wp,useEffect as yr,useRef as zp,useState as Vp}from"react";function jp(e){for(let t of e.parts){let a=t;if(a.type==="data"||a.type==="data-suggestions"){let o=a.data;if(o&&Array.isArray(o.suggestions))return o.suggestions}}return null}function zi(e){return typeof e=="object"&&e!==null&&"initial"in e}function ro(e){let{messages:t,status:a,config:o}=e,r=zi(o)&&o.initial?o.initial:void 0,[s,n]=Vp(r??[]),i=zp(a),l=o===!0||zi(o)&&o.dynamic!==!1,u=Wp(()=>{n([])},[]),f=t.length>0;yr(()=>{!f&&r&&r.length>0&&n(r)},[r,f]);let d=t[t.length-1];return yr(()=>{d?.role==="user"&&u()},[d,u]),yr(()=>{let p=i.current;if(i.current=a,p==="streaming"&&a==="ready"&&l){let c=[...t].reverse().find(C=>C.role==="assistant");if(!c)return;let m=jp(c);m&&n(m)}},[a,l,t]),{suggestions:s,isLoading:!1,clear:u}}import{useEffect as $p,useRef as Xp,useState as Qp}from"react";var Kp=50,Jp=30,Zp=2e3,Vi=500;function so(e,t=!0){let[a,o]=Qp(""),r=Xp(void 0);return $p(()=>{if(!t){o("");return}let s=0,n=!1,i=!1,l=()=>{i||(n?(s--,o(e.slice(0,s)),s<=0?(n=!1,r.current=setTimeout(l,Vi)):r.current=setTimeout(l,Jp)):(s++,o(e.slice(0,s)),s>=e.length?(n=!0,r.current=setTimeout(l,Zp)):r.current=setTimeout(l,Kp)))};return r.current=setTimeout(l,Vi),()=>{i=!0,clearTimeout(r.current)}},[e,t]),a}function no(e,t){let a=t?.Authorization,o=typeof a=="string"&&a.startsWith("Bearer ")?a.slice(7):null;return o?`${e}/resource?token=${encodeURIComponent(o)}`:`${e}/resource`}var ji={primaryColor:"#6366f1",primaryForeground:"#1f2937",backgroundColor:"#ffffff",textColor:"#1f2937",mutedColor:"#6b7280",borderColor:"#e5e7eb",borderWidth:0,boxShadow:"none",assistantBubbleColor:"#f3f4f6",userBubbleColor:"#f4f4f4",inputBackgroundColor:"#f9fafb",borderRadius:16,messageBorderRadius:12,fontFamily:"system-ui, -apple-system, 'Segoe UI', sans-serif",headerBackgroundColor:"#ffffff",headerTextColor:"#1f2937",statusColor:"#22c55e",toolCardColor:"#f4f4f5"},Yp={backgroundColor:"#212121",headerBackgroundColor:"#1e1e1e",headerTextColor:"#ececec",textColor:"#ececec",primaryForeground:"#ffffff",mutedColor:"#8e8ea0",borderColor:"#444444",assistantBubbleColor:"#2f2f2f",userBubbleColor:"#303030",inputBackgroundColor:"#2f2f2f",primaryColor:"#6366f1",statusColor:"#22c55e",toolCardColor:"#262626"},em={primaryColor:["--ww-primary","--ww-color-primary"],primaryForeground:["--ww-primary-fg","--ww-color-primary-foreground"],backgroundColor:["--ww-bg","--ww-color-background"],textColor:["--ww-text","--ww-color-foreground","--ww-color-accent-foreground"],mutedColor:["--ww-muted","--ww-color-muted-foreground"],borderColor:["--ww-border","--ww-color-border"],borderWidth:["--ww-border-width"],boxShadow:["--ww-shadow"],assistantBubbleColor:["--ww-assistant-bubble","--ww-color-accent"],userBubbleColor:["--ww-user-bubble"],inputBackgroundColor:["--ww-input-bg","--ww-color-input"],borderRadius:["--ww-radius"],messageBorderRadius:["--ww-msg-radius"],fontFamily:["--ww-font"],headerBackgroundColor:["--ww-header-bg"],headerTextColor:["--ww-header-text"],statusColor:["--ww-status"],toolCardColor:["--ww-tool-card","--ww-color-tool-card"]};function kr(e){return{...ji,...e}}function Xt(e){let t={};for(let[a,o]of Object.entries(em)){let r=e[a];if(r===void 0)continue;let s=typeof r=="number"?`${r}px`:String(r);for(let n of o)t[n]=s}return t}import{jsx as ce,jsxs as Qt}from"react/jsx-runtime";var rm=tm(function(t,a){let{theme:o,title:r="Assistant",width:s,height:n,className:i,allowAttachments:l=!1,welcomeMessage:u,welcome:f,placeholder:d="Ask me anything...",triggerEvent:p="triggerDemoRequest",api:c,debug:m,enableThreadHistory:C=!1,showToolCalls:w=!0}=t,x=c??"/api/waniwani",g=no(x,t.headers),h=kr(o),L=Xt(h),y=h.backgroundColor.replace("#",""),k=parseInt(y.substring(0,2),16),v=parseInt(y.substring(2,4),16),M=parseInt(y.substring(4,6),16),E=(k*299+v*587+M*114)/1e3<128,F=Wi(x,t.headers,t.skipRemoteConfig),T=m??F.debug,S=oo({...t,api:x}),P=Ja({...t,api:x,sessionId:S.sessionId}),$=so(d,!S.text),[V,we]=Xi(!1),[pe,me]=Xi(null),X=$i(null),Z=$i(void 0),he=br(()=>{let B=X.current;if(!B)return;B.scrollIntoView({behavior:"smooth",block:"center"});let Q=B.querySelector("textarea");Q&&setTimeout(()=>Q.focus(),300),we(!0),clearTimeout(Z.current),Z.current=setTimeout(()=>we(!1),2e3)},[]),se=ro({messages:S.messages,status:S.status,config:t.suggestions}),ne=br(B=>{let Q=B.content.map(q=>q.text??"").join("").trim();Q&&S.handleSubmit({text:Q,files:[],modelContext:B.modelContext})},[S.handleSubmit]),Fe=br(B=>{se.clear(),S.handleSubmit({text:B,files:[]})},[se.clear,S.handleSubmit]);return om(a,()=>({sendMessage:B=>{S.handleSubmit({text:B,files:[]}),he()},sendMessageAndWait:B=>S.sendMessageAndWait(B),reset:S.reset,focus:he,get messages(){return S.messages},get sessionId(){return S.sessionId}}),[S.handleSubmit,S.sendMessageAndWait,S.reset,S.messages,S.sessionId,he]),am(()=>{if(!p)return;let B=Q=>{let q=Q.detail,H=typeof q?.message=="string"?q.message:void 0;H&&S.handleSubmit({text:H,files:[]}),he()};return window.addEventListener(p,B),()=>window.removeEventListener(p,B)},[p,S.handleSubmit,he]),Qt("div",{ref:X,style:{...L,width:s,height:n},"data-waniwani-chat":"","data-waniwani-layout":"card",...E?{"data-waniwani-dark":""}:{},className:A("ww:flex ww:flex-col ww:font-[family-name:var(--ww-font)] ww:text-foreground ww:bg-background ww:rounded-[var(--ww-radius)] ww:overflow-hidden",V&&"ww:ring-2 ww:ring-blue-400/70 ww:ring-offset-2 ww:ring-offset-background",i),children:[Qt("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-2 ww:px-6 ww:py-3",style:{backgroundColor:h.headerBackgroundColor,color:h.headerTextColor},children:[ce("div",{className:"ww:text-sm ww:font-semibold ww:truncate ww:flex-1 ww:min-w-0",children:r}),ce(Is,{messages:S.messages,evalEnabled:F.eval,api:x}),C&&ce(Ka,{threads:S.threads,activeThreadId:S.activeThreadId,onNewThread:S.startNewThread,onSelectThread:B=>{S.switchThread(B)},onDeleteThread:B=>{S.deleteThread(B)}})]}),Qt(Zr,{className:"ww:flex-1 ww:min-h-0 ww:bg-background",children:[ce(Yr,{scrollClassName:pe?"ww:!relative ww:!overflow-hidden":void 0,children:ce(ja,{messages:S.messages,status:S.status,welcomeMessage:u,welcome:f,onSuggestionSelect:Fe,resourceEndpoint:g,chatSessionId:S.sessionId,isDark:E,onFollowUp:ne,onCallTool:P,fullscreenToolCallId:pe,debug:T,showToolCalls:w,toolDefinitions:S.toolDefinitions,onWidgetDisplayModeChange:(B,Q)=>{me(B==="fullscreen"?Q.toolCallId:null)}})}),ce(es,{})]}),ce("div",{style:pe?{display:"none"}:void 0,children:ce(Qa,{suggestions:se.suggestions,isLoading:se.isLoading,onSelect:Fe})}),ce("div",{style:pe?{display:"none"}:void 0,children:ce(da,{queuedMessages:S.queuedMessages,onRemove:S.removeQueuedMessage})}),ce("div",{style:pe?{display:"none"}:void 0,children:ce("div",{className:"ww:shrink-0 ww:px-4 ww:pb-8 ww:pt-2 ww:bg-background",children:Qt("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl",children:[ce(na,{onSubmit:S.handleSubmit,globalDrop:l,multiple:l,className:"ww:rounded-2xl ww:border-border ww:bg-input",children:Qt("div",{className:"ww:flex ww:items-center ww:gap-1 ww:pl-4 ww:pr-3 ww:py-2.5",children:[l&&ce(ua,{}),ce(ia,{onChange:S.handleTextChange,value:S.text,placeholder:$,className:"ww:min-h-0 ww:py-1 ww:px-0"}),ce(la,{status:S.status,disabled:S.queueFull})]})}),ce($a,{})]})})})]})});import{forwardRef as Ki,useCallback as io,useEffect as xt,useImperativeHandle as nm,useRef as Kt,useState as Tr}from"react";import{jsx as sm}from"react/jsx-runtime";function Qi({text:e}){let{t}=U();return e===!1?null:sm("span",{className:"ww:text-[11px] ww:text-muted-foreground ww:opacity-70",children:e||t.aiDisclaimer.default})}import{jsx as re,jsxs as Qe}from"react/jsx-runtime";var Pr=Ki(function(t,a){let{locale:o,messages:r}=t;return re(xo,{locale:o,messages:r,children:re(im,{...t,ref:a})})}),im=Ki(function(t,a){let{t:o,ready:r}=U(),{appearance:s,className:n,allowAttachments:i=!1,welcomeMessage:l,welcome:u,placeholder:f=o.promptInput.placeholder,triggerEvent:d="triggerDemoRequest",api:p,mcp:c,debug:m=!1,readOnly:C=!1,title:w,headerActions:x,hideHeader:g=!1,enableThreadHistory:h=!1,showToolCalls:L=!0,initializing:y=!1,disclaimer:k}=t,v=s?.theme,M=s?.variables,E=M?Xt(M):{},[F,T]=Tr(!1);xt(()=>{if(v!=="auto"||typeof window>"u")return;let b=window.matchMedia("(prefers-color-scheme: dark)");T(b.matches);let R=()=>T(b.matches);return b.addEventListener("change",R),()=>b.removeEventListener("change",R)},[v]);let S=v==="dark"||v==="auto"&&F,P=oo({...t,api:p}),$=Ja({...t,api:p,sessionId:P.sessionId,onCallTool:c?.onCallTool}),V=c?.resourceEndpoint??no(p,t.headers),we=so(f,!P.text),[pe,me]=Tr(null),X=Kt(null),Z=Kt(null),he=Kt(null),se=Kt(null),[ne,Fe]=Tr(!0),B=Kt(ne);B.current=ne;let Q=io(()=>{let b=X.current;if(!b)return;let R=b.querySelector("textarea");R&&R.focus()},[]),q=io((b="smooth")=>{let R=Z.current;R&&R.scrollTo({top:R.scrollHeight,behavior:b})},[]);xt(()=>{let b=se.current,R=Z.current;if(!b||!R)return;let O=new IntersectionObserver(([te])=>Fe(te.isIntersecting),{root:R,rootMargin:"0px 0px 200px 0px",threshold:0});return O.observe(b),()=>O.disconnect()},[]),xt(()=>{(P.messages[P.messages.length-1]?.role==="user"||B.current)&&q("smooth")},[P.messages.length,P.messages[P.messages.length-1]]),xt(()=>{q("auto")},[q]),xt(()=>{if(typeof ResizeObserver>"u")return;let b=Z.current,R=he.current;if(!b&&!R)return;let O=b?.scrollHeight??0,te=b?.clientHeight??0,ye=new ResizeObserver(()=>{let Pe=Z.current;if(!Pe)return;let He=Pe.scrollTop+te>=O-5;O=Pe.scrollHeight,te=Pe.clientHeight,He&&q("auto")});return b&&ye.observe(b),R&&ye.observe(R),()=>ye.disconnect()},[q]);let H=ro({messages:P.messages,status:P.status,config:t.suggestions}),Y=io(b=>{let R=b.content.map(O=>O.text??"").join("").trim();R&&P.handleSubmit({text:R,files:[],modelContext:b.modelContext})},[P.handleSubmit]),_=io(b=>{H.clear(),P.handleSubmit({text:b,files:[]})},[H.clear,P.handleSubmit]);nm(a,()=>({sendMessage:b=>{P.handleSubmit({text:b,files:[]}),Q()},sendMessageAndWait:b=>P.sendMessageAndWait(b),reset:P.reset,focus:Q,get messages(){return P.messages},get sessionId(){return P.sessionId}}),[P.handleSubmit,P.sendMessageAndWait,P.reset,P.messages,P.sessionId,Q]),xt(()=>{if(!d)return;let b=R=>{let O=R.detail,te=typeof O?.message=="string"?O.message:void 0;te&&P.handleSubmit({text:te,files:[]}),Q()};return window.addEventListener(d,b),()=>window.removeEventListener(d,b)},[d,P.handleSubmit,Q]);let G=!g&&!!(w||h||x),W=y||!r;return Qe("div",{ref:X,style:{...E,maxHeight:"inherit",opacity:W?0:1,transition:"opacity 220ms ease-out"},"data-waniwani-chat":"","data-waniwani-layout":"embed","data-color-scheme":v==="auto"?"auto":void 0,...W?{"data-waniwani-initializing":""}:{},...S?{"data-waniwani-dark":""}:{},className:A("ww:relative ww:w-full ww:h-full ww:flex ww:flex-col ww:bg-background ww:text-foreground ww:font-[family-name:var(--ww-font)] ww:overflow-hidden",v==="dark"&&"dark",n),children:[G&&Qe("div",{className:"ww:shrink-0 ww:flex ww:items-center ww:gap-2 ww:px-6 ww:py-3 ww:border-b ww:border-border",style:{backgroundColor:"var(--ww-color-card-header)",color:"var(--ww-color-card-header-foreground)"},children:[w&&re("div",{className:"ww:text-sm ww:font-semibold ww:truncate ww:flex-1 ww:min-w-0",children:w}),!w&&re("div",{className:"ww:flex-1"}),x,h&&re(Ka,{threads:P.threads,activeThreadId:P.activeThreadId,onNewThread:P.startNewThread,onSelectThread:b=>{P.switchThread(b)},onDeleteThread:b=>{P.deleteThread(b)}})]}),Qe("div",{ref:Z,className:A("ww:relative ww:flex-1 ww:min-h-0",pe?"ww:overflow-hidden":"ww:overflow-y-auto"),children:[Qe("div",{ref:he,className:A("ww:mx-auto ww:w-full ww:max-w-3xl ww:px-4 ww:py-6 ww:flex ww:flex-col ww:gap-6",pe&&"ww:!py-0"),children:[re(ja,{messages:P.messages,status:P.status,welcomeMessage:l,welcome:u,onSuggestionSelect:_,resourceEndpoint:V,chatSessionId:P.sessionId,isDark:S,onFollowUp:Y,onCallTool:$,fullscreenToolCallId:pe,debug:m,showToolCalls:L,toolDefinitions:P.toolDefinitions,onWidgetDisplayModeChange:(b,R)=>{me(b==="fullscreen"?R.toolCallId:null)}}),re("div",{ref:se,"aria-hidden":!0,style:{height:1}})]}),!ne&&!pe&&re("div",{className:"ww:sticky ww:bottom-2 ww:flex ww:justify-center ww:pointer-events-none",children:re(be,{type:"button",onClick:()=>q("smooth"),size:"icon",variant:"outline",className:"ww:rounded-full ww:shadow ww:pointer-events-auto","aria-label":"Scroll to latest",children:re(Ke,{className:"ww:size-4"})})})]}),!C&&Qe("div",{className:"ww:shrink-0 ww:bg-background",style:pe?{display:"none"}:void 0,children:[re(Qa,{suggestions:H.suggestions,isLoading:H.isLoading,onSelect:_}),re(da,{queuedMessages:P.queuedMessages,onRemove:P.removeQueuedMessage}),re("div",{className:"ww:px-4 ww:pb-2 ww:pt-2",children:Qe("div",{className:"ww:mx-auto ww:w-full ww:max-w-3xl",children:[re(na,{onSubmit:P.handleSubmit,globalDrop:i,multiple:i,className:"ww:rounded-2xl ww:border-border ww:bg-input",children:Qe("div",{className:"ww:flex ww:items-center ww:gap-1 ww:pl-4 ww:pr-3 ww:py-2.5",children:[i&&re(ua,{}),re(ia,{onChange:P.handleTextChange,value:P.text,placeholder:we,className:"ww:min-h-0 ww:py-1 ww:px-0"}),re(la,{status:P.status,disabled:P.queueFull})]})}),Qe("div",{className:"ww:pt-2 ww:pb-1 ww:flex ww:justify-center ww:items-center ww:gap-1.5",children:[re($a,{}),re(Qi,{text:k})]})]})})]})]})});import{forwardRef as hm,useEffect as gm,useMemo as tl,useState as al}from"react";var lm="https://app.waniwani.ai/api/mcp/chat",um={api:lm};function dm(){if(typeof document>"u")return null;if(document.currentScript instanceof HTMLScriptElement)return document.currentScript;let e=document.querySelectorAll("script[src]");for(let t of e)if(t instanceof HTMLScriptElement&&/embed/i.test(t.src))return t;return null}function fm(){let e=dm();if(!e)return{};let t=h=>e.getAttribute(h)??void 0,a=h=>{let L=e.getAttribute(h);if(L==null)return;let y=L.trim().toLowerCase();if(y==="true"||y==="1"||y==="")return!0;if(y==="false"||y==="0")return!1},o={},r=t("data-api");r&&(o.api=r);let s=t("data-token");s&&(o.token=s);let n=t("data-title");n&&(o.title=n);let i=t("data-welcome-message");i&&(o.welcomeMessage=i);let l=t("data-placeholder");l&&(o.placeholder=l);let u=t("data-mcp-server-url");u&&(o.mcpServerUrl=u);let f=t("data-channel-id");f&&(o.channelId=f);let d=a("data-show-tool-calls");d!==void 0&&(o.showToolCalls=d);let p=t("data-css");p&&(o.css=p);let c=t("data-suggestions");c&&(o.suggestions=c.split(",").map(h=>h.trim()).filter(Boolean));let m=a("data-enable-thread-history");m!==void 0&&(o.enableThreadHistory=m);let C=a("data-hide-header");C!==void 0&&(o.hideHeader=C);let w=t("data-theme");(w==="light"||w==="dark"||w==="auto")&&(o.appearance={theme:w});let x=t("data-locale");(x==="en"||x==="fr"||x==="es")&&(o.locale=x);let g=t("data-disclaimer");if(g!==void 0){let h=g.trim(),L=h.toLowerCase();L==="false"||L==="0"?o.disclaimer=!1:h&&(o.disclaimer=h)}return o}function Ar(e){if(!e)return{};let t={};for(let a in e)e[a]!==void 0&&(t[a]=e[a]);return t}function vr(e,t,a){let o=a??fm(),r=cm(t,o,e),s={token:"",...um,...Ar(t),...Ar(o),...Ar(e),...r?{appearance:r}:{}};if(!s.token)throw new Error("[WaniWani] Missing required config: `token`. Set data-token on the script tag or pass it to WaniWani.chat.init().");return s}function cm(e,t,a){let o=a?.appearance?.theme??t.appearance?.theme??e?.appearance?.theme,r={...e?.appearance?.variables??{},...t.appearance?.variables??{},...a?.appearance?.variables??{}},s=Object.keys(r).length>0;if(!o&&!s)return;let n={};return o&&(n.theme=o),s&&(n.variables=r),n}import{useEffect as xS,useState as LS}from"react";var pm="waniwani:config:";function Ji(e,t,a){return`${pm}${e}|${t}|${a??""}`}function Zi(e,t,a){if(typeof window>"u")return null;try{let o=window.sessionStorage.getItem(Ji(e,t,a));if(!o)return null;let r=JSON.parse(o);return r&&typeof r=="object"?r:null}catch{return null}}function Yi(e,t,a,o){if(!(typeof window>"u"))try{window.sessionStorage.setItem(Ji(e,t,a),JSON.stringify(o))}catch{}}async function el(e,t,a,o){try{let r=`${e.replace(/\/$/,"")}/config`,s=o?`${r}?channel=${encodeURIComponent(o)}`:r,n=await fetch(s,{method:"GET",headers:{Authorization:`Bearer ${t}`},signal:a});if(!n.ok)return{};let i=await n.json(),l=i&&typeof i=="object"&&"data"in i&&i.data?i.data:i;return l?mm(l):{}}catch{return{}}}function mm(e){let t={};return e.title!=null&&(t.title=e.title),e.welcomeMessage!=null&&(t.welcomeMessage=e.welcomeMessage),e.placeholder!=null&&(t.placeholder=e.placeholder),e.suggestions!=null&&e.suggestions.length>0&&(t.suggestions=e.suggestions),typeof e.enableThreadHistory=="boolean"&&(t.enableThreadHistory=e.enableThreadHistory),t}import{jsx as Lm}from"react/jsx-runtime";var wm=600,ol="https://app.waniwani.ai/api/mcp/chat",xm=hm(function(t,a){let{token:o,channelId:r,className:s,overrides:n}=t,i=tl(()=>({token:o,channelId:r,api:n?.api,mcpServerUrl:n?.mcpServerUrl,title:n?.title,hideHeader:n?.hideHeader,welcomeMessage:n?.welcomeMessage,placeholder:n?.placeholder,suggestions:n?.suggestions,enableThreadHistory:n?.enableThreadHistory,showToolCalls:n?.showToolCalls,appearance:n?.appearance,disclaimer:n?.disclaimer,locale:n?.locale}),[o,r,n?.api,n?.mcpServerUrl,n?.title,n?.hideHeader,n?.welcomeMessage,n?.placeholder,n?.suggestions,n?.enableThreadHistory,n?.showToolCalls,n?.appearance,n?.disclaimer,n?.locale]),l=n?.api??ol,[u,f]=al({}),[d,p]=al(!1);gm(()=>{if(!o){p(!0);return}let C=Zi(l,o,r);C&&(f(C),p(!0));let w=new AbortController,x=setTimeout(()=>p(!0),wm);return el(l,o,w.signal,r).then(g=>{w.signal.aborted||(Object.keys(g).length>0&&(Yi(l,o,r,g),f(g)),p(!0))}).catch(g=>{console.error("[WaniWani] Remote config fetch failed:",g),p(!0)}).finally(()=>clearTimeout(x)),()=>{w.abort(),clearTimeout(x)}},[l,o,r]);let c=tl(()=>vr(i,u,void 0),[i,u]),m={};return c.mcpServerUrl&&(m.mcpServerUrl=c.mcpServerUrl),c.channelId&&(m.channelId=c.channelId),Lm(Pr,{ref:a,api:c.api??ol,headers:{Authorization:`Bearer ${c.token}`},skipRemoteConfig:!0,body:Object.keys(m).length>0?m:void 0,appearance:c.appearance,title:c.title,hideHeader:c.hideHeader,welcomeMessage:c.welcomeMessage,welcome:n?.welcome,placeholder:c.placeholder,suggestions:c.suggestions?{initial:c.suggestions}:void 0,enableThreadHistory:c.enableThreadHistory,showToolCalls:c.showToolCalls,disclaimer:c.disclaimer,allowAttachments:n?.allowAttachments,locale:c.locale,messages:n?.messages,className:s,initializing:!d})});export{rm as ChatCard,Pr as ChatEmbed,Yp as DARK_THEME,ji as DEFAULT_THEME,mr as McpAppFrame,xm as WaniwaniChat,kr as mergeTheme,Xt as themeToCSSProperties};
17
17
  /*! Bundled license information:
18
18
 
19
19
  lucide-react/dist/esm/shared/src/utils/mergeClasses.js: