@waniwani/sdk 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/index.d.ts +6 -2
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/react.d.ts +28 -18
- package/dist/mcp/react.js +7 -7
- package/dist/mcp/react.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/react.d.ts
CHANGED
|
@@ -9,18 +9,7 @@ import React$1, { ReactNode, SetStateAction } from 'react';
|
|
|
9
9
|
* future host that renders the widget on a domain other than its own
|
|
10
10
|
* `baseUrl`.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* - `history.pushState` / `history.replaceState` — prevents full-origin
|
|
14
|
-
* URLs from ending up in the iframe's history (browsers reject cross-
|
|
15
|
-
* origin pushes in sandboxed iframes).
|
|
16
|
-
* - `window.fetch` — rewrites same-origin requests to the widget's real
|
|
17
|
-
* `baseUrl`. Without this, relative `/api/...` calls from the widget
|
|
18
|
-
* hit the host's origin (ChatGPT sandbox, WaniWani embed proxy, etc.)
|
|
19
|
-
* and 404. `passthroughOrigins` opts specific origins out of the
|
|
20
|
-
* rewrite (see prop doc).
|
|
21
|
-
* - `<html>` attribute observer — strips attributes the host injects
|
|
22
|
-
* after hydration (ChatGPT mutates `<html>` for theming), while
|
|
23
|
-
* preserving `class` / `style` / `lang`.
|
|
12
|
+
* See `applyIframePatches` for the patch behavior.
|
|
24
13
|
*
|
|
25
14
|
* More background on the ChatGPT case:
|
|
26
15
|
* https://vercel.com/blog/running-next-js-inside-chatgpt-a-deep-dive-into-native-app-integration
|
|
@@ -28,12 +17,10 @@ import React$1, { ReactNode, SetStateAction } from 'react';
|
|
|
28
17
|
declare function InitializeNextJsInIframe({ baseUrl, passthroughOrigins, }: {
|
|
29
18
|
baseUrl: string;
|
|
30
19
|
/**
|
|
31
|
-
* Origins whose fetches should skip the same-origin → baseUrl
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* widget tracking calls to the WaniWani API get rewritten to the
|
|
36
|
-
* widget's own host and 404.
|
|
20
|
+
* Origins whose fetches should skip the relative same-origin → baseUrl
|
|
21
|
+
* rewrite. Only needed for relative-URL calls that resolve to an
|
|
22
|
+
* origin you do not want forwarded to `baseUrl` — absolute URLs are
|
|
23
|
+
* never rewritten regardless of this list.
|
|
37
24
|
*/
|
|
38
25
|
passthroughOrigins?: string[];
|
|
39
26
|
}): react_jsx_runtime.JSX.Element;
|
|
@@ -414,6 +401,20 @@ declare function useToolResponseMetadata(): UnknownObject | null;
|
|
|
414
401
|
*/
|
|
415
402
|
declare function useUpdateModelContext(): (context: ModelContextUpdate) => Promise<void>;
|
|
416
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Opt-in toggles for the noisy auto-capture event types. Each defaults to
|
|
406
|
+
* `false` so widget owners declare intent before the SDK starts emitting
|
|
407
|
+
* coarse, high-volume events. Always-on capture covers widget_render,
|
|
408
|
+
* widget_error, widget_link_click, and the labelled `data-ww-step` /
|
|
409
|
+
* `data-ww-conversion` clicks.
|
|
410
|
+
*/
|
|
411
|
+
interface AutoCaptureToggles {
|
|
412
|
+
click?: boolean;
|
|
413
|
+
scroll?: boolean;
|
|
414
|
+
formField?: boolean;
|
|
415
|
+
formSubmit?: boolean;
|
|
416
|
+
}
|
|
417
|
+
|
|
417
418
|
/**
|
|
418
419
|
* Options for the useWaniwani hook.
|
|
419
420
|
*/
|
|
@@ -440,6 +441,15 @@ interface UseWaniwaniOptions {
|
|
|
440
441
|
* Additional metadata to include with every tracked event.
|
|
441
442
|
*/
|
|
442
443
|
metadata?: Record<string, unknown>;
|
|
444
|
+
/**
|
|
445
|
+
* Opt-in toggles for noisy auto-capture event types. Default: all off.
|
|
446
|
+
* Always-on capture: widget_render, widget_error, widget_link_click,
|
|
447
|
+
* `data-ww-step` / `data-ww-conversion` clicks.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* useWaniwani({ capture: { click: true, scroll: true } });
|
|
451
|
+
*/
|
|
452
|
+
capture?: AutoCaptureToggles;
|
|
443
453
|
}
|
|
444
454
|
/**
|
|
445
455
|
* The tracking API returned by `useWaniwani()`.
|
package/dist/mcp/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{a as
|
|
2
|
+
import{a as re}from"../chunk-DGSC74SV.js";import{b as L,c as ie}from"../chunk-5OQXAEHG.js";import{Fragment as Ye,jsx as U,jsxs as $e}from"react/jsx-runtime";function ze(){let e=window.innerBaseUrl,t=window.__wwPassthroughOrigins??[],n=document.documentElement;new MutationObserver(p=>{p.forEach(m=>{if(m.type==="attributes"&&m.target===n){let u=m.attributeName;u&&u!=="suppresshydrationwarning"&&u!=="lang"&&u!=="class"&&u!=="style"&&n.removeAttribute(u)}})}).observe(n,{attributes:!0,attributeOldValue:!0});let r=history.replaceState.bind(history);history.replaceState=(p,m,u)=>{try{let i=new URL(String(u??""),window.location.href);r(null,m,i.pathname+i.search+i.hash)}catch{}};let c=history.pushState.bind(history);history.pushState=(p,m,u)=>{try{let i=new URL(String(u??""),window.location.href);c(null,m,i.pathname+i.search+i.hash)}catch{}};let h=new URL(e).origin,x=window.self!==window.top;if(window.addEventListener("click",p=>{let m=p?.target?.closest("a");if(!m||!m.href)return;let u=new URL(m.href,window.location.href);if(u.origin!==window.location.origin&&u.origin!==h)try{window.openai&&(window.openai?.openExternal({href:m.href}),p.preventDefault())}catch{console.warn("openExternal failed, likely not in OpenAI client")}},!0),x&&window.location.origin!==h){let p=window.fetch;window.fetch=((o,d)=>{let g=typeof o=="string"&&!/^[a-z][a-z0-9+.-]*:/i.test(o)&&!o.startsWith("//"),l;if(typeof o=="string"||o instanceof URL?l=new URL(o,window.location.href):l=new URL(o.url,window.location.href),l.origin===h)return typeof o=="string"||o instanceof URL?o=l.toString():o=new Request(l.toString(),o),p.call(window,o,{...d,mode:"cors"});if(t.indexOf(l.origin)!==-1)return p.call(window,o,d);if(g&&l.origin===window.location.origin){let y=new URL(e);return y.pathname=l.pathname,y.search=l.search,y.hash=l.hash,l=y,o=l.toString(),p.call(window,o,{...d,mode:"cors"})}return p.call(window,o,d)});let m=h.replace(/^http/,"ws"),u=window.WebSocket,i=function(o,d){let g=new URL(String(o),window.location.href);if(g.origin===window.location.origin||g.origin===window.location.origin.replace(/^http/,"ws")){let l=new URL(m);return l.pathname=g.pathname,l.search=g.search,l.hash=g.hash,new u(l.toString(),d)}return new u(o,d)};i.prototype=u.prototype,Object.assign(i,{CONNECTING:u.CONNECTING,OPEN:u.OPEN,CLOSING:u.CLOSING,CLOSED:u.CLOSED}),window.WebSocket=i}}var Ge=`(${ze.toString()})()`;function Ve({baseUrl:e,passthroughOrigins:t}){return $e(Ye,{children:[U("base",{href:e}),U("script",{children:`window.innerBaseUrl = ${JSON.stringify(e)}`}),U("script",{children:`window.__wwPassthroughOrigins = ${JSON.stringify(t??[])}`}),U("script",{children:'window.__isChatGptApp = typeof window.openai !== "undefined";'}),U("script",{children:Ge})]})}import{useCallback as T,useEffect as N,useRef as q,useState as C}from"react";var se={theme:"dark",userAgent:{device:{type:"desktop"},capabilities:{hover:!0,touch:!1}},locale:"en",maxHeight:800,displayMode:"inline",safeArea:{insets:{top:0,bottom:0,left:0,right:0}},toolInput:{},toolOutput:null,toolResponseMetadata:null,widgetState:null},D={...se};function F(e){typeof window>"u"||window.openai||(D={...se,toolOutput:e??null},window.openai={...D,requestDisplayMode:async({mode:t})=>(R("displayMode",t),{mode:t}),callTool:async(t,n)=>(console.log(`[DevMode] callTool: ${t}`,n),{result:JSON.stringify({mock:!0,tool:t,args:n})}),sendFollowUpMessage:async({prompt:t})=>{console.log(`[DevMode] sendFollowUpMessage: ${t}`)},openExternal:({href:t})=>{console.log(`[DevMode] openExternal: ${t}`),window.open(t,"_blank")},setWidgetState:async t=>{R("widgetState",t)}},window.dispatchEvent(new L({globals:D})))}function R(e,t){typeof window>"u"||!window.openai||(D[e]=t,window.openai[e]=t,window.dispatchEvent(new L({globals:{[e]:t}})))}function z(){return{...D}}function P(e){R("toolOutput",e)}function H(e){R("displayMode",e)}function B(e){R("theme",e)}import{Fragment as Z,jsx as a,jsxs as v}from"react/jsx-runtime";var G=150;function ae({className:e}){return v("svg",{className:e,viewBox:"0 0 24 24",fill:"none",role:"img","aria-label":"Dev Controls",children:[a("rect",{x:"4",y:"4",width:"10",height:"10",rx:"2",stroke:"currentColor",strokeWidth:"1.5"}),a("rect",{x:"10",y:"10",width:"10",height:"10",rx:"2",stroke:"currentColor",strokeWidth:"1.5",fill:"currentColor",fillOpacity:"0.15"})]})}function Xe({className:e}){return a("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:a("path",{d:"M18 6L6 18M6 6l12 12"})})}function Je({className:e}){return a("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:a("rect",{x:"2",y:"4",width:"12",height:"8",rx:"1.5",stroke:"currentColor",strokeWidth:"1.25"})})}function qe({className:e}){return v("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[a("rect",{x:"1.5",y:"3",width:"13",height:"10",rx:"1.5",stroke:"currentColor",strokeWidth:"1.25"}),a("rect",{x:"8.5",y:"7",width:"5",height:"4",rx:"0.75",fill:"currentColor"})]})}function Ze({className:e}){return a("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:a("path",{d:"M2 5.5V3.5C2 2.95 2.45 2.5 3 2.5H5.5M10.5 2.5H13C13.55 2.5 14 2.95 14 3.5V5.5M14 10.5V12.5C14 13.05 13.55 13.5 13 13.5H10.5M5.5 13.5H3C2.45 13.5 2 13.05 2 12.5V10.5",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})}function Qe({className:e}){return v("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[a("circle",{cx:"8",cy:"8",r:"2.5",stroke:"currentColor",strokeWidth:"1.25"}),a("path",{d:"M8 2v1.5M8 12.5V14M2 8h1.5M12.5 8H14M4.11 4.11l1.06 1.06M10.83 10.83l1.06 1.06M4.11 11.89l1.06-1.06M10.83 5.17l1.06-1.06",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"})]})}function et({className:e}){return a("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:a("path",{d:"M13.5 9.5a5.5 5.5 0 01-7-7 5.5 5.5 0 107 7z",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})})}function tt({className:e}){return v("svg",{"aria-hidden":"true",className:e,viewBox:"0 0 16 16",fill:"none",children:[a("path",{d:"M2.5 8a5.5 5.5 0 019.37-3.9M13.5 8a5.5 5.5 0 01-9.37 3.9",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round"}),a("path",{d:"M12.5 2v3h-3M3.5 14v-3h3",stroke:"currentColor",strokeWidth:"1.25",strokeLinecap:"round",strokeLinejoin:"round"})]})}var nt=`
|
|
3
3
|
@keyframes devPanelSlideIn {
|
|
4
4
|
0% {
|
|
5
5
|
opacity: 0;
|
|
@@ -47,22 +47,22 @@ import{a as ae}from"../chunk-DGSC74SV.js";import{b as H,c as le}from"../chunk-5O
|
|
|
47
47
|
.dev-json-editor::-webkit-scrollbar-thumb:hover {
|
|
48
48
|
background: rgba(255, 255, 255, 0.15);
|
|
49
49
|
}
|
|
50
|
-
`;function
|
|
50
|
+
`;function de({defaultProps:e,widgetPaths:t,children:n}){let[s,r]=C(!1),[c,h]=C(!1);return N(()=>{if(new URLSearchParams(window.location.search).get("platform")==="mcp-apps"){r(!0);return}if(t&&t.length>0){let p=window.location.pathname,m=t.some(u=>p===u||p.startsWith(`${u}/`));h(m),m&&F(e)}else F(e),h(!0);r(!0)},[e,t]),s?c?v(Z,{children:[a(ot,{children:n}),a(rt,{defaultProps:e})]}):a(Z,{children:n}):null}function ot({children:e}){return a("div",{className:"min-h-screen bg-[#212121] flex items-center justify-center p-8",children:a("div",{className:"relative w-full max-w-md overflow-hidden rounded-2xl sm:rounded-3xl border border-[#414141]",style:{boxShadow:"0px 0px 0px 1px #414141, 0px 4px 14px rgba(0,0,0,0.24)"},children:e})})}function le({options:e,value:t,onChange:n}){let s=e.findIndex(r=>r.value===t);return v("div",{className:"relative flex p-0.5 rounded-lg",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},children:[a("div",{className:"absolute top-0.5 bottom-0.5 rounded-md transition-transform duration-150 ease-out",style:{width:`calc(${100/e.length}% - 2px)`,left:"2px",transform:`translateX(calc(${s*100}% + ${s*2}px))`,background:"rgba(255, 255, 255, 0.1)"}}),e.map(r=>v("button",{type:"button",onClick:()=>n(r.value),className:`
|
|
51
51
|
relative z-10 flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5
|
|
52
52
|
text-xs font-medium rounded-md transition-colors duration-150
|
|
53
|
-
${t===
|
|
54
|
-
`,children:[
|
|
53
|
+
${t===r.value?"text-white":"text-gray-400 hover:text-gray-300"}
|
|
54
|
+
`,children:[r.icon,a("span",{className:"capitalize",children:r.label})]},r.value))]})}function rt({defaultProps:e}){let[t,n]=C(()=>typeof window>"u"?!1:localStorage.getItem("dev-controls-open")==="true"),[s,r]=C(!1),[c,h]=C(t),[x,p]=C("inline"),[m,u]=C("dark"),[i,o]=C(!1),[d,g]=C(()=>JSON.stringify(e??{},null,2)),[l,y]=C(null),b=q(null),E=q(null),I=q(null);N(()=>{let f=z();p(f.displayMode),u(f.theme)},[]),N(()=>{typeof window>"u"||(window.openai||(window.openai={}),window.openai.safeArea={insets:{top:0,bottom:i?G:0,left:0,right:0}},window.dispatchEvent(new L({globals:{safeArea:window.openai.safeArea}})))},[i]),N(()=>{localStorage.setItem("dev-controls-open",String(t))},[t]);let O=T(()=>{h(!0),requestAnimationFrame(()=>{n(!0)})},[]),_=T(()=>{r(!0),n(!1),setTimeout(()=>{h(!1),r(!1)},150)},[]),J=T(()=>{t?_():O()},[t,O,_]);N(()=>{let f=k=>{(k.metaKey||k.ctrlKey)&&k.shiftKey&&k.key==="d"&&(k.preventDefault(),J()),k.key==="Escape"&&t&&_()};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[t,J,_]),N(()=>{if(!t)return;let f=k=>{I.current&&!I.current.contains(k.target)&&_()};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[t,_]);let De=T(f=>{p(f),H(f)},[]),Fe=T(f=>{u(f),B(f)},[]),K=T(f=>{try{let k=JSON.parse(f);y(null),P(k)}catch{y("Invalid JSON")}},[]),Pe=T(f=>{g(f),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{K(f)},500)},[K]),He=T(()=>{b.current&&clearTimeout(b.current),K(d)},[K,d]),Be=T(()=>{let f=JSON.stringify(e??{},null,2);g(f),y(null),P(e??{}),p("inline"),H("inline"),u("dark"),B("dark")},[e]),je=[{value:"inline",label:"inline",icon:a(Je,{className:"w-3.5 h-3.5"})},{value:"pip",label:"pip",icon:a(qe,{className:"w-3.5 h-3.5"})},{value:"fullscreen",label:"full",icon:a(Ze,{className:"w-3.5 h-3.5"})}],Ke=[{value:"light",label:"light",icon:a(Qe,{className:"w-3.5 h-3.5"})},{value:"dark",label:"dark",icon:a(et,{className:"w-3.5 h-3.5"})}];return v(Z,{children:[a("style",{dangerouslySetInnerHTML:{__html:nt}}),v("div",{ref:I,className:"fixed bottom-4 right-4 z-[9999] font-['Inter',_system-ui,_sans-serif]",children:[v("button",{type:"button",onClick:J,className:"group relative flex items-center justify-center w-11 h-11 rounded-xl transition-all duration-200 ease-out hover:scale-105 active:scale-95",style:{background:"rgba(14, 14, 16, 0.95)",backdropFilter:"blur(16px)",WebkitBackdropFilter:"blur(16px)",border:"1px solid rgba(255, 255, 255, 0.08)",boxShadow:`
|
|
55
55
|
0 4px 12px rgba(0, 0, 0, 0.4),
|
|
56
56
|
0 0 0 1px rgba(255, 255, 255, 0.05),
|
|
57
57
|
inset 0 1px 0 rgba(255, 255, 255, 0.04)
|
|
58
|
-
`},"aria-label":"Toggle Dev Controls","aria-expanded":t,children:[
|
|
58
|
+
`},"aria-label":"Toggle Dev Controls","aria-expanded":t,children:[a(ae,{className:`w-5 h-5 transition-all duration-200 ${t?"text-indigo-400 scale-110":"text-gray-300 group-hover:text-white"}`}),a("div",{className:"absolute inset-0 rounded-xl opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none",style:{background:"radial-gradient(circle at center, rgba(99, 102, 241, 0.15) 0%, transparent 70%)"}})]}),c&&v("div",{ref:E,className:`absolute bottom-14 right-0 w-80 ${t&&!s?"dev-panel-enter":"dev-panel-exit"}`,style:{maxHeight:"calc(100vh - 120px)",background:"rgba(14, 14, 16, 0.92)",backdropFilter:"blur(24px)",WebkitBackdropFilter:"blur(24px)",border:"1px solid rgba(255, 255, 255, 0.06)",borderRadius:"16px",boxShadow:`
|
|
59
59
|
0 25px 50px -12px rgba(0, 0, 0, 0.6),
|
|
60
60
|
0 0 0 1px rgba(255, 255, 255, 0.05),
|
|
61
61
|
inset 0 1px 0 rgba(255, 255, 255, 0.04)
|
|
62
|
-
`},children:[v("div",{className:"flex items-center justify-between px-4 py-3",style:{borderBottom:"1px solid rgba(255, 255, 255, 0.06)"},children:[v("div",{className:"flex items-center gap-2",children:[s(ce,{className:"w-4 h-4 text-gray-400"}),s("span",{className:"text-sm font-medium text-white",children:"Dev Controls"})]}),v("div",{className:"flex items-center gap-2",children:[s("span",{className:"text-[10px] font-medium text-gray-500 px-1.5 py-0.5 rounded",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},children:typeof navigator<"u"&&navigator.platform?.includes("Mac")?"\u2318\u21E7D":"Ctrl+Shift+D"}),s("button",{type:"button",onClick:c,className:"p-1 rounded-md text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:s(Ge,{className:"w-4 h-4"})})]})]}),v("div",{className:"p-4 space-y-5 overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:[v("div",{children:[s("label",{htmlFor:"display-mode",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Display Mode"}),s(ue,{options:He,value:g,onChange:x})]}),v("div",{children:[s("label",{htmlFor:"theme",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Theme"}),s(ue,{options:Be,value:y,onChange:b})]}),v("div",{children:[s("label",{htmlFor:"safe-area",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Safe Area (Chat Input)"}),v("button",{type:"button",onClick:()=>a(!r),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-xs font-medium transition-all duration-150 ${r?"text-emerald-400":"text-gray-400"}`,style:{background:r?"rgba(34, 197, 94, 0.1)":"rgba(255, 255, 255, 0.04)",border:r?"1px solid rgba(34, 197, 94, 0.3)":"1px solid rgba(255, 255, 255, 0.06)"},children:[s("span",{children:"Mock ChatGPT Input Bar"}),s("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold ${r?"bg-emerald-500/20 text-emerald-400":"bg-gray-500/20 text-gray-500"}`,children:r?"ON":"OFF"})]}),r&&v("p",{className:"text-[10px] text-gray-500 mt-1.5",children:["bottom: ",X,"px"]})]}),v("div",{children:[s("label",{htmlFor:"widget-props",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Widget Props"}),s("textarea",{value:m,onChange:u=>ee(u.target.value),onBlur:P,className:"dev-json-editor w-full min-h-[160px] text-xs text-gray-200 p-3 rounded-lg resize-none focus:outline-none transition-colors",style:{background:"rgba(0, 0, 0, 0.3)",border:R?"1px solid rgba(239, 68, 68, 0.5)":"1px solid rgba(255, 255, 255, 0.06)",fontFamily:"'JetBrains Mono', 'SF Mono', 'Fira Code', monospace",lineHeight:1.6},onFocus:u=>{R||(u.target.style.borderColor="rgba(99, 102, 241, 0.5)")},onBlurCapture:u=>{R||(u.target.style.borderColor="rgba(255, 255, 255, 0.06)")},spellCheck:!1}),R&&v("p",{className:"text-red-400 text-[11px] mt-1.5 flex items-center gap-1",children:[s("svg",{"aria-hidden":"true","aria-label":"Error",className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:s("path",{d:"M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"})}),R]})]}),v("button",{type:"button",onClick:Pe,className:"w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium text-gray-400 transition-all duration-150 hover:text-gray-200",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},onMouseEnter:u=>{u.currentTarget.style.background="rgba(255, 255, 255, 0.08)",u.currentTarget.style.borderColor="rgba(255, 255, 255, 0.1)"},onMouseLeave:u=>{u.currentTarget.style.background="rgba(255, 255, 255, 0.04)",u.currentTarget.style.borderColor="rgba(255, 255, 255, 0.06)"},children:[s(qe,{className:"w-3.5 h-3.5"}),"Reset to Defaults"]})]})]})]}),r&&v("div",{className:"fixed bottom-0 left-0 right-0 z-[9998] flex items-center justify-center pointer-events-none",style:{height:`${X}px`,background:"linear-gradient(to top, #1a1a1a 0%, #1a1a1a 80%, transparent 100%)"},children:[v("div",{className:"w-full max-w-2xl mx-4 px-4 py-3 rounded-2xl bg-[#2f2f2f] border border-[#424242] flex items-center gap-3",children:[s("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:s("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),s("div",{className:"flex-1 text-gray-400 text-sm",children:"Ask me anything..."}),s("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:s("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"})})})]}),v("div",{className:"absolute bottom-1 text-[10px] text-gray-600 font-mono",children:["Mock SafeArea: bottom=",X,"px"]})]})]})}import{useCallback as it}from"react";import Y,{createContext as tt,useCallback as me,useContext as nt,useEffect as fe,useState as oe,useSyncExternalStore as ot}from"react";async function ge(){let{detectPlatform:e}=await import("../platform-GKYYQBCS.js");if(e()==="openai"){let{OpenAIWidgetClient:n}=await import("../openai-client-QAC3ZD5W.js");return new n}else{let{MCPAppsWidgetClient:n}=await import("../mcp-apps-client-PUL4H54S.js");return new n}}var J=tt(null);function he({children:e,loading:t=null,onError:n}){let[i,o]=oe(null),[l,h]=oe(null),[g,w]=oe(!0);return fe(()=>{let y=!0,p=null;async function r(){try{let a=await ge();await a.connect(),y?(p=a,o(a),w(!1)):a.close()}catch(a){y&&(console.error("error",a),h(a instanceof Error?a:new Error(String(a))),w(!1))}}return r(),()=>{y=!1,p?.close()}},[]),fe(()=>{if(!i)return;let y=p=>{document.documentElement.classList.toggle("dark",p==="dark"),document.documentElement.style.colorScheme=p==="dark"?"dark":"auto"};return y(i.getTheme()),i.onThemeChange(y)},[i]),l&&n?Y.createElement(Y.Fragment,null,n(l)):g||!i?Y.createElement(Y.Fragment,null,t):Y.createElement(J.Provider,{value:i},e)}function f(e){let t=nt(J);if(!t)throw new Error("useWidgetClient must be used within a WidgetProvider");let n=me(l=>e==="toolOutput"?t.onToolResult(()=>l()):e==="theme"?t.onThemeChange(()=>l()):e==="displayMode"?t.onDisplayModeChange(()=>l()):e==="safeArea"?t.onSafeAreaChange(()=>l()):e==="maxHeight"?t.onMaxHeightChange(()=>l()):e==="toolResponseMetadata"?t.onToolResponseMetadataChange(()=>l()):e==="widgetState"?t.onWidgetStateChange(()=>l()):()=>{},[t,e]),i=me(()=>e==="toolOutput"?t.getToolOutput():e==="theme"?t.getTheme():e==="displayMode"?t.getDisplayMode():e==="locale"?t.getLocale():e==="safeArea"?t.getSafeArea():e==="maxHeight"?t.getMaxHeight():e==="toolResponseMetadata"?t.getToolResponseMetadata():e==="widgetState"?t.getWidgetState():null,[t,e]),o=ot(n,i,i);return e?o:t}function we(){let e=f();return it((t,n)=>e.callTool(t,n),[e])}function ve(){return f("displayMode")}function q(){return f("toolOutput")}function xe(){return{data:q()}}import{useSyncExternalStore as rt}from"react";function ye(){return rt(()=>()=>{},()=>typeof window>"u"?!1:window.__isChatGptApp===!0,()=>!1)}function be(){return f("locale")}function ke(){return f("maxHeight")}import{useCallback as st}from"react";function Me(){let e=f();return st(t=>e.openExternal(t),[e])}import{useCallback as at}from"react";function Ce(){let e=f();return at(t=>e.requestDisplayMode(t),[e])}function Se(){return f("safeArea")}import{useCallback as lt}from"react";function Te(){let e=f();return lt((t,n)=>{(async()=>{le(n?.modelContext)&&await Promise.resolve(e.updateModelContext(n.modelContext)),await Promise.resolve(e.sendFollowUp(t))})().catch(i=>{console.error("Failed to send follow-up message:",i)})},[e])}function Ee(){return f("theme")}function _e(){return f("toolResponseMetadata")}import{useCallback as dt}from"react";function Re(){let e=f();return dt(async t=>{await Promise.resolve(e.updateModelContext(t))},[e])}import{useContext as gt,useEffect as re,useMemo as mt,useRef as ft,useState as Oe}from"react";function ct(){return crypto.randomUUID()}function T(e,t,n){return{event_id:ct(),event_type:t,timestamp:new Date().toISOString(),source:e.source??"widget",session_id:e.sessionId,trace_id:e.traceId,...n}}function We(e){let t=e.trim().split(/\s+/),n=t[0]||"",i={};for(let o=1;o<t.length;o++){let l=t[o].indexOf(":");if(l===-1)continue;let h=t[o].slice(0,l),g=t[o].slice(l+1),w=Number(g);i[h]=Number.isFinite(w)&&g!==""?w:g}return{name:n,props:i}}function Ae(e){let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function Ie(e,t){let n=[],i=typeof navigator<"u"?navigator:void 0,o=i&&"connection"in i?i.connection:void 0;t([T(e,"widget_render",{metadata:{viewport_width:window.innerWidth,viewport_height:window.innerHeight,device_pixel_ratio:window.devicePixelRatio??1,touch_support:"ontouchstart"in window?1:0,connection_type:o?.effectiveType??"unknown",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}})]);let l=c=>{t([T(e,"widget_error",{metadata:{error_message:c.message,error_stack:(c.error?.stack??"").slice(0,1024),error_source:c.filename??"unknown"}})])};window.addEventListener("error",l),n.push(()=>window.removeEventListener("error",l));let h=c=>{let d=c.reason,x=d instanceof Error?d.message:String(d),b=d instanceof Error?(d.stack??"").slice(0,1024):"";t([T(e,"widget_error",{metadata:{error_message:x,error_stack:b,error_source:"unhandledrejection"}})])};window.addEventListener("unhandledrejection",h),n.push(()=>window.removeEventListener("unhandledrejection",h));let g=c=>{let d=c.target;t([T(e,"widget_click",{metadata:{target_tag:d?.tagName?.toLowerCase()??"unknown",target_id:d?.id||void 0,target_class:d?.className||void 0,click_x:c.clientX,click_y:c.clientY}})])};document.addEventListener("click",g,{capture:!0}),n.push(()=>document.removeEventListener("click",g,{capture:!0}));let w=c=>{let x=c.target?.closest?.("[data-ww-conversion]");if(!x)return;let{name:b,props:k}=We(x.getAttribute("data-ww-conversion")||"");b&&t([T(e,"conversion",{event_name:b,metadata:Object.keys(k).length>0?k:void 0})])};document.addEventListener("click",w,{capture:!0}),n.push(()=>document.removeEventListener("click",w,{capture:!0}));let y=0,p=c=>{let x=c.target?.closest?.("[data-ww-step]");if(!x)return;let{name:b,props:k}=We(x.getAttribute("data-ww-step")||"");b&&(y++,t([T(e,"step",{event_name:b,step_sequence:y,metadata:Object.keys(k).length>0?k:void 0})]))};document.addEventListener("click",p,{capture:!0}),n.push(()=>document.removeEventListener("click",p,{capture:!0}));let r=c=>{let d=c.target?.closest?.("a");if(!d)return;let x=d.getAttribute("href")??"",b=x.startsWith("http")&&!x.startsWith(window.location.origin);t([T(e,"widget_link_click",{metadata:{href:x,link_text:(d.textContent??"").slice(0,200),is_external:b}})])};document.addEventListener("click",r,{capture:!0}),n.push(()=>document.removeEventListener("click",r,{capture:!0}));let a=null,m=window.scrollY||0,M=()=>{a||(a=setTimeout(()=>{a=null;let c=window.scrollY||document.documentElement.scrollTop,d=document.documentElement.scrollHeight-document.documentElement.clientHeight,x=d>0?Math.round(c/d*100):0,b=c>=m?"down":"up";m=c,t([T(e,"widget_scroll",{metadata:{scroll_depth_pct:x,scroll_direction:b,viewport_height:window.innerHeight}})])},250))};window.addEventListener("scroll",M,{passive:!0}),n.push(()=>{window.removeEventListener("scroll",M),a&&clearTimeout(a)});let R=new WeakMap,O=c=>{let d=c.target;!d||!Ae(d)||R.set(d,Date.now())},W=c=>{let d=c.target;if(!d||!Ae(d))return;let x=R.get(d),b=x?Date.now()-x:0,k=d;t([T(e,"widget_form_field",{metadata:{field_name:k.name||k.id||void 0,field_type:k.type||d.tagName.toLowerCase(),time_in_field_ms:b,filled:!!k.value}})])};document.addEventListener("focusin",O,{capture:!0}),document.addEventListener("focusout",W,{capture:!0}),n.push(()=>{document.removeEventListener("focusin",O,{capture:!0}),document.removeEventListener("focusout",W,{capture:!0})});let D=new WeakMap,L=c=>{let x=c.target?.closest?.("form");x&&!D.has(x)&&D.set(x,Date.now())};document.addEventListener("focusin",L,{capture:!0}),n.push(()=>document.removeEventListener("focusin",L,{capture:!0}));let F=c=>{let d=c.target,x=d?D.get(d):void 0,b=0;if(d){let k=d.querySelectorAll("input, textarea, select");for(let ee of k){let P=ee;(P.validity&&!P.validity.valid||P.getAttribute("aria-invalid")==="true")&&b++}}t([T(e,"widget_form_submit",{metadata:{form_id:d?.id||void 0,time_to_submit_ms:x?Date.now()-x:void 0,validation_errors:b}})])};return document.addEventListener("submit",F,{capture:!0}),n.push(()=>document.removeEventListener("submit",F,{capture:!0})),()=>{for(let c of n)c()}}var ut="@waniwani/sdk";function pt(e){let n=e.event_type.startsWith("widget_")?e.event_type:`widget_${e.event_type}`,i={};e.session_id&&(i.sessionId=e.session_id),e.trace_id&&(i.traceId=e.trace_id),e.user_id&&(i.externalUserId=e.user_id);let o={...e.metadata??{}};return e.event_name&&(o.event_name=e.event_name),{id:e.event_id,type:"mcp.event",name:n,source:e.source||"widget",timestamp:e.timestamp,correlation:i,properties:o,metadata:{}}}function ie(e){return JSON.stringify({sentAt:new Date().toISOString(),source:{sdk:ut,version:"0.1.0"},events:e.map(pt)})}var Z=class{buffer=[];timer=null;flushing=!1;pendingFlush=!1;stopped=!1;config;teardownVisibility=null;teardownPagehide=null;constructor(t){this.config=t,this.start(),this.registerTeardown()}send(t){if(!this.stopped){if(this.buffer.push(...t),this.buffer.length>200){let n=this.buffer.length-200;this.buffer.splice(0,n)}this.buffer.length>=20&&this.flush().catch(()=>{})}}async flush(){if(!(this.stopped||this.buffer.length===0)){if(this.flushing){this.pendingFlush=!0;return}this.flushing=!0;try{let t=this.buffer.splice(0,20);await this.sendBatch(t)}finally{this.flushing=!1,this.pendingFlush&&this.buffer.length>0&&!this.stopped&&(this.pendingFlush=!1,this.flush().catch(()=>{}))}}}stop(){this.stopped=!0,this.timer&&(clearInterval(this.timer),this.timer=null),typeof document<"u"&&this.teardownVisibility&&(document.removeEventListener("visibilitychange",this.teardownVisibility),this.teardownVisibility=null),typeof window<"u"&&this.teardownPagehide&&(window.removeEventListener("pagehide",this.teardownPagehide),this.teardownPagehide=null)}beaconFlush(){if(this.buffer.length===0)return;let t=[...this.buffer];this.buffer.length=0;let n={"Content-Type":"application/json"};if(this.config.token&&(n.Authorization=`Bearer ${this.config.token}`),typeof fetch<"u"){this.sendKeepAliveChunked(this.config.endpoint,t,n);return}typeof navigator<"u"&&typeof navigator.sendBeacon=="function"&&this.sendBeaconChunked(this.config.endpoint,t)}sendKeepAliveChunked(t,n,i){let o=ie(n);if(o.length<=6e4){fetch(t,{method:"POST",headers:i,body:o,keepalive:!0}).catch(()=>{});return}if(n.length<=1)return;let l=Math.ceil(n.length/2);this.sendKeepAliveChunked(t,n.slice(0,l),i),this.sendKeepAliveChunked(t,n.slice(l),i)}sendBeaconChunked(t,n){let i=ie(n);if(i.length<=6e4){navigator.sendBeacon(t,new Blob([i],{type:"application/json"}));return}if(n.length<=1)return;let o=Math.ceil(n.length/2);this.sendBeaconChunked(t,n.slice(0,o)),this.sendBeaconChunked(t,n.slice(o))}start(){this.timer||(this.timer=setInterval(()=>{this.flush().catch(()=>{})},5e3))}registerTeardown(){typeof document>"u"||(this.teardownVisibility=()=>{document.visibilityState==="hidden"&&this.beaconFlush()},this.teardownPagehide=()=>{this.beaconFlush()},document.addEventListener("visibilitychange",this.teardownVisibility),window.addEventListener("pagehide",this.teardownPagehide))}async sendBatch(t){let n=ie(t),i={"Content-Type":"application/json"};this.config.token&&(i.Authorization=`Bearer ${this.config.token}`);for(let o=0;o<=3;o++)try{let l=await fetch(this.config.endpoint,{method:"POST",headers:i,body:n});if(l.status===200||l.status===207)return;if(l.status===401){this.stopped=!0;return}if(l.status>=500&&o<3){await this.delay(1e3*2**o);continue}if(l.status===429&&o<3){let h=l.headers.get("Retry-After"),g=h?Number(h):NaN,w=Number.isFinite(g)?g*1e3:1e3*2**o;await this.delay(w);continue}return}catch{if(o<3){await this.delay(1e3*2**o);continue}return}}delay(t){return new Promise(n=>setTimeout(n,t))}};var se={identify(){},step(){},track(){},conversion(){}},_=null,Q=0;function ht(){return crypto.randomUUID()}function I(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function wt(){return{widget:se,cleanup:()=>{},config:null}}function Ne(e){if(!e)return null;let t=e.getToolResponseMetadata();if(!t)return null;let n=t._meta,i=t.waniwani??n?.waniwani,o=I(i?.endpoint);return o?{endpoint:o,token:I(i?.token),sessionId:I(i?.sessionId),source:I(i?.source)}:null}function Le(e,t){return e?.endpoint===t?.endpoint&&e?.token===t?.token&&e?.sessionId===t?.sessionId&&e?.source===t?.source}function vt(e){let[t,n]=Oe(()=>Ne(e));return re(()=>{if(!e){n(o=>o===null?o:null);return}let i=()=>{let o=Ne(e);n(l=>Le(l,o)?l:o)};return i(),e.onToolResponseMetadataChange(()=>{i()})},[e]),t}function xt(e,t){let n=e.sessionId??crypto.randomUUID(),i=crypto.randomUUID(),o=new Z({endpoint:e.endpoint,token:e.token,metadata:t}),l,h=0,g=r=>{o.send(r)},w=e.source??"widget",y=Ie({sessionId:n,traceId:i,metadata:t,source:w},g);function p(r,a){return{event_id:ht(),event_type:r,timestamp:new Date().toISOString(),source:w,session_id:n,trace_id:i,user_id:l,...a}}return{widget:{identify(r,a){l=r,g([p("identify",{user_id:r,user_traits:a})])},step(r,a){h++,g([p("step",{event_name:r,step_sequence:h,metadata:a})])},track(r,a){g([p("track",{event_name:r,metadata:a})])},conversion(r,a){g([p("conversion",{event_name:r,metadata:a})])}},cleanup:()=>{y(),o.stop()},config:e}}function Ue(e={}){let t=gt(J),n=vt(t),i=I(e.endpoint),o=I(e.token),l=I(e.sessionId),h=mt(()=>i?{endpoint:i,token:o??n?.token,sessionId:l??n?.sessionId,source:n?.source}:n,[i,o,l,n]),[g,w]=Oe(se),y=ft(e.metadata);return y.current=e.metadata,re(()=>(Q++,()=>{Q=Math.max(Q-1,0),Q===0&&(_?.cleanup(),_=null)}),[]),re(()=>{if(!(typeof window>"u")){if(!h){_?.config&&(_.cleanup(),_=wt(),w(se));return}Le(_?.config,h)||(_?.cleanup(),_=xt(h,y.current),w(_.widget))}},[h]),g}import{useCallback as yt,useEffect as bt,useState as kt}from"react";function De(e){let t=f("widgetState"),[n,i]=kt(()=>t??(typeof e=="function"?e():e??null));bt(()=>{i(t)},[t]);let o=yt(l=>{i(h=>{let g=typeof l=="function"?l(h):l;return ae()==="openai"&&g!=null&&window.openai?.setWidgetState(g),g})},[]);return[n,o]}import{jsx as N,jsxs as Fe}from"react/jsx-runtime";var Mt=()=>Fe("div",{className:"flex flex-col items-center justify-center h-full min-h-[120px] gap-4",children:[Fe("div",{className:"flex gap-2",children:[N("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-blue-400 to-cyan-400 animate-bounce [animation-delay:-0.3s]"}),N("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-cyan-400 to-teal-400 animate-bounce [animation-delay:-0.15s]"}),N("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-teal-400 to-emerald-400 animate-bounce"})]}),N("p",{className:"text-sm font-medium text-transparent bg-clip-text bg-gradient-to-r from-slate-400 via-slate-200 to-slate-400 bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",children:"Loading widget..."}),N("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:N("div",{className:"w-16 h-16 rounded-full border-2 border-blue-400/20 animate-ping"})}),N("style",{children:`
|
|
62
|
+
`},children:[v("div",{className:"flex items-center justify-between px-4 py-3",style:{borderBottom:"1px solid rgba(255, 255, 255, 0.06)"},children:[v("div",{className:"flex items-center gap-2",children:[a(ae,{className:"w-4 h-4 text-gray-400"}),a("span",{className:"text-sm font-medium text-white",children:"Dev Controls"})]}),v("div",{className:"flex items-center gap-2",children:[a("span",{className:"text-[10px] font-medium text-gray-500 px-1.5 py-0.5 rounded",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},children:typeof navigator<"u"&&navigator.platform?.includes("Mac")?"\u2318\u21E7D":"Ctrl+Shift+D"}),a("button",{type:"button",onClick:_,className:"p-1 rounded-md text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:a(Xe,{className:"w-4 h-4"})})]})]}),v("div",{className:"p-4 space-y-5 overflow-y-auto",style:{maxHeight:"calc(100vh - 200px)"},children:[v("div",{children:[a("label",{htmlFor:"display-mode",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Display Mode"}),a(le,{options:je,value:x,onChange:De})]}),v("div",{children:[a("label",{htmlFor:"theme",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Theme"}),a(le,{options:Ke,value:m,onChange:Fe})]}),v("div",{children:[a("label",{htmlFor:"safe-area",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Safe Area (Chat Input)"}),v("button",{type:"button",onClick:()=>o(!i),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-xs font-medium transition-all duration-150 ${i?"text-emerald-400":"text-gray-400"}`,style:{background:i?"rgba(34, 197, 94, 0.1)":"rgba(255, 255, 255, 0.04)",border:i?"1px solid rgba(34, 197, 94, 0.3)":"1px solid rgba(255, 255, 255, 0.06)"},children:[a("span",{children:"Mock ChatGPT Input Bar"}),a("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold ${i?"bg-emerald-500/20 text-emerald-400":"bg-gray-500/20 text-gray-500"}`,children:i?"ON":"OFF"})]}),i&&v("p",{className:"text-[10px] text-gray-500 mt-1.5",children:["bottom: ",G,"px"]})]}),v("div",{children:[a("label",{htmlFor:"widget-props",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Widget Props"}),a("textarea",{value:d,onChange:f=>Pe(f.target.value),onBlur:He,className:"dev-json-editor w-full min-h-[160px] text-xs text-gray-200 p-3 rounded-lg resize-none focus:outline-none transition-colors",style:{background:"rgba(0, 0, 0, 0.3)",border:l?"1px solid rgba(239, 68, 68, 0.5)":"1px solid rgba(255, 255, 255, 0.06)",fontFamily:"'JetBrains Mono', 'SF Mono', 'Fira Code', monospace",lineHeight:1.6},onFocus:f=>{l||(f.target.style.borderColor="rgba(99, 102, 241, 0.5)")},onBlurCapture:f=>{l||(f.target.style.borderColor="rgba(255, 255, 255, 0.06)")},spellCheck:!1}),l&&v("p",{className:"text-red-400 text-[11px] mt-1.5 flex items-center gap-1",children:[a("svg",{"aria-hidden":"true","aria-label":"Error",className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:a("path",{d:"M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"})}),l]})]}),v("button",{type:"button",onClick:Be,className:"w-full flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-xs font-medium text-gray-400 transition-all duration-150 hover:text-gray-200",style:{background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.06)"},onMouseEnter:f=>{f.currentTarget.style.background="rgba(255, 255, 255, 0.08)",f.currentTarget.style.borderColor="rgba(255, 255, 255, 0.1)"},onMouseLeave:f=>{f.currentTarget.style.background="rgba(255, 255, 255, 0.04)",f.currentTarget.style.borderColor="rgba(255, 255, 255, 0.06)"},children:[a(tt,{className:"w-3.5 h-3.5"}),"Reset to Defaults"]})]})]})]}),i&&v("div",{className:"fixed bottom-0 left-0 right-0 z-[9998] flex items-center justify-center pointer-events-none",style:{height:`${G}px`,background:"linear-gradient(to top, #1a1a1a 0%, #1a1a1a 80%, transparent 100%)"},children:[v("div",{className:"w-full max-w-2xl mx-4 px-4 py-3 rounded-2xl bg-[#2f2f2f] border border-[#424242] flex items-center gap-3",children:[a("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:a("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:a("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),a("div",{className:"flex-1 text-gray-400 text-sm",children:"Ask me anything..."}),a("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:a("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:a("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"})})})]}),v("div",{className:"absolute bottom-1 text-[10px] text-gray-600 font-mono",children:["Mock SafeArea: bottom=",G,"px"]})]})]})}import{useCallback as lt}from"react";import j,{createContext as it,useCallback as ue,useContext as st,useEffect as pe,useState as Q,useSyncExternalStore as at}from"react";async function ce(){let{detectPlatform:e}=await import("../platform-GKYYQBCS.js");if(e()==="openai"){let{OpenAIWidgetClient:n}=await import("../openai-client-QAC3ZD5W.js");return new n}else{let{MCPAppsWidgetClient:n}=await import("../mcp-apps-client-PUL4H54S.js");return new n}}var V=it(null);function ge({children:e,loading:t=null,onError:n}){let[s,r]=Q(null),[c,h]=Q(null),[x,p]=Q(!0);return pe(()=>{let m=!0,u=null;async function i(){try{let o=await ce();await o.connect(),m?(u=o,r(o),p(!1)):o.close()}catch(o){m&&(console.error("error",o),h(o instanceof Error?o:new Error(String(o))),p(!1))}}return i(),()=>{m=!1,u?.close()}},[]),pe(()=>{if(!s)return;let m=u=>{document.documentElement.classList.toggle("dark",u==="dark"),document.documentElement.style.colorScheme=u==="dark"?"dark":"auto"};return m(s.getTheme()),s.onThemeChange(m)},[s]),c&&n?j.createElement(j.Fragment,null,n(c)):x||!s?j.createElement(j.Fragment,null,t):j.createElement(V.Provider,{value:s},e)}function w(e){let t=st(V);if(!t)throw new Error("useWidgetClient must be used within a WidgetProvider");let n=ue(c=>e==="toolOutput"?t.onToolResult(()=>c()):e==="theme"?t.onThemeChange(()=>c()):e==="displayMode"?t.onDisplayModeChange(()=>c()):e==="safeArea"?t.onSafeAreaChange(()=>c()):e==="maxHeight"?t.onMaxHeightChange(()=>c()):e==="toolResponseMetadata"?t.onToolResponseMetadataChange(()=>c()):e==="widgetState"?t.onWidgetStateChange(()=>c()):()=>{},[t,e]),s=ue(()=>e==="toolOutput"?t.getToolOutput():e==="theme"?t.getTheme():e==="displayMode"?t.getDisplayMode():e==="locale"?t.getLocale():e==="safeArea"?t.getSafeArea():e==="maxHeight"?t.getMaxHeight():e==="toolResponseMetadata"?t.getToolResponseMetadata():e==="widgetState"?t.getWidgetState():null,[t,e]),r=at(n,s,s);return e?r:t}function me(){let e=w();return lt((t,n)=>e.callTool(t,n),[e])}function fe(){return w("displayMode")}function Y(){return w("toolOutput")}function he(){return{data:Y()}}import{useSyncExternalStore as dt}from"react";function we(){return dt(()=>()=>{},()=>typeof window>"u"?!1:window.__isChatGptApp===!0,()=>!1)}function ve(){return w("locale")}function xe(){return w("maxHeight")}import{useCallback as ct}from"react";function ye(){let e=w();return ct(t=>e.openExternal(t),[e])}import{useCallback as ut}from"react";function be(){let e=w();return ut(t=>e.requestDisplayMode(t),[e])}function ke(){return w("safeArea")}import{useCallback as pt}from"react";function Ce(){let e=w();return pt((t,n)=>{(async()=>{ie(n?.modelContext)&&await Promise.resolve(e.updateModelContext(n.modelContext)),await Promise.resolve(e.sendFollowUp(t))})().catch(s=>{console.error("Failed to send follow-up message:",s)})},[e])}function Me(){return w("theme")}function Se(){return w("toolResponseMetadata")}import{useCallback as gt}from"react";function Te(){let e=w();return gt(async t=>{await Promise.resolve(e.updateModelContext(t))},[e])}import{useContext as wt,useEffect as ne,useMemo as vt,useRef as Re,useState as Ae}from"react";function mt(){return crypto.randomUUID()}function M(e,t,n){return{event_id:mt(),event_type:t,timestamp:new Date().toISOString(),source:e.source??"widget",session_id:e.sessionId,trace_id:e.traceId,...n}}function ee(e){let t=e.trim().split(/\s+/),n=t[0]||"",s={};for(let r=1;r<t.length;r++){let c=t[r].indexOf(":");if(c===-1)continue;let h=t[r].slice(0,c),x=t[r].slice(c+1),p=Number(x);s[h]=Number.isFinite(p)&&x!==""?p:x}return{name:n,props:s}}function Ee(e){let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function _e(e,t){let n=[],s=typeof navigator<"u"?navigator:void 0,r=s&&"connection"in s?s.connection:void 0;t([M(e,"widget_render",{metadata:{viewport_width:window.innerWidth,viewport_height:window.innerHeight,device_pixel_ratio:window.devicePixelRatio??1,touch_support:"ontouchstart"in window?1:0,connection_type:r?.effectiveType??"unknown",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}})]);let c=i=>{t([M(e,"widget_error",{metadata:{error_message:i.message,error_stack:(i.error?.stack??"").slice(0,1024),error_source:i.filename??"unknown"}})])};window.addEventListener("error",c),n.push(()=>window.removeEventListener("error",c));let h=i=>{let o=i.reason,d=o instanceof Error?o.message:String(o),g=o instanceof Error?(o.stack??"").slice(0,1024):"";t([M(e,"widget_error",{metadata:{error_message:d,error_stack:g,error_source:"unhandledrejection"}})])};if(window.addEventListener("unhandledrejection",h),n.push(()=>window.removeEventListener("unhandledrejection",h)),e.capture?.click){let i=o=>{let d=o.target,g=d?.closest?.("[data-ww-conversion],[data-ww-step]");if(g){let l=g.getAttribute("data-ww-conversion")??g.getAttribute("data-ww-step")??"";if(ee(l).name)return}t([M(e,"widget_click",{metadata:{target_tag:d?.tagName?.toLowerCase()??"unknown",target_id:d?.id||void 0,target_class:d?.className||void 0,click_x:o.clientX,click_y:o.clientY}})])};document.addEventListener("click",i,{capture:!0}),n.push(()=>document.removeEventListener("click",i,{capture:!0}))}let x=i=>{let d=i.target?.closest?.("[data-ww-conversion]");if(!d)return;let{name:g,props:l}=ee(d.getAttribute("data-ww-conversion")||"");g&&t([M(e,"conversion",{event_name:g,metadata:Object.keys(l).length>0?l:void 0})])};document.addEventListener("click",x,{capture:!0}),n.push(()=>document.removeEventListener("click",x,{capture:!0}));let p=0,m=i=>{let d=i.target?.closest?.("[data-ww-step]");if(!d)return;let{name:g,props:l}=ee(d.getAttribute("data-ww-step")||"");g&&(p++,t([M(e,"step",{event_name:g,step_sequence:p,metadata:Object.keys(l).length>0?l:void 0})]))};document.addEventListener("click",m,{capture:!0}),n.push(()=>document.removeEventListener("click",m,{capture:!0}));let u=i=>{let o=i.target?.closest?.("a");if(!o)return;let d=o.getAttribute("href")??"",g=d.startsWith("http")&&!d.startsWith(window.location.origin);t([M(e,"widget_link_click",{metadata:{href:d,link_text:(o.textContent??"").slice(0,200),is_external:g}})])};if(document.addEventListener("click",u,{capture:!0}),n.push(()=>document.removeEventListener("click",u,{capture:!0})),e.capture?.scroll){let i=null,o=window.scrollY||0,d=()=>{i||(i=setTimeout(()=>{i=null;let g=window.scrollY||document.documentElement.scrollTop,l=document.documentElement.scrollHeight-document.documentElement.clientHeight,y=l>0?Math.round(g/l*100):0,b=g>=o?"down":"up";o=g,t([M(e,"widget_scroll",{metadata:{scroll_depth_pct:y,scroll_direction:b,viewport_height:window.innerHeight}})])},250))};window.addEventListener("scroll",d,{passive:!0}),n.push(()=>{window.removeEventListener("scroll",d),i&&clearTimeout(i)})}if(e.capture?.formField){let i=new WeakMap,o=g=>{let l=g.target;!l||!Ee(l)||i.set(l,Date.now())},d=g=>{let l=g.target;if(!l||!Ee(l))return;let y=i.get(l),b=y?Date.now()-y:0,E=l;t([M(e,"widget_form_field",{metadata:{field_name:E.name||E.id||void 0,field_type:E.type||l.tagName.toLowerCase(),time_in_field_ms:b,filled:!!E.value}})])};document.addEventListener("focusin",o,{capture:!0}),document.addEventListener("focusout",d,{capture:!0}),n.push(()=>{document.removeEventListener("focusin",o,{capture:!0}),document.removeEventListener("focusout",d,{capture:!0})})}if(e.capture?.formSubmit){let i=new WeakMap,o=g=>{let y=g.target?.closest?.("form");y&&!i.has(y)&&i.set(y,Date.now())};document.addEventListener("focusin",o,{capture:!0}),n.push(()=>document.removeEventListener("focusin",o,{capture:!0}));let d=g=>{let l=g.target,y=l?i.get(l):void 0,b=0;if(l){let E=l.querySelectorAll("input, textarea, select");for(let I of E){let O=I;(O.validity&&!O.validity.valid||O.getAttribute("aria-invalid")==="true")&&b++}}t([M(e,"widget_form_submit",{metadata:{form_id:l?.id||void 0,time_to_submit_ms:y?Date.now()-y:void 0,validation_errors:b}})])};document.addEventListener("submit",d,{capture:!0}),n.push(()=>document.removeEventListener("submit",d,{capture:!0}))}return()=>{for(let i of n)i()}}var ft="@waniwani/sdk";function ht(e){let n=e.event_type.startsWith("widget_")?e.event_type:`widget_${e.event_type}`,s={};e.session_id&&(s.sessionId=e.session_id),e.trace_id&&(s.traceId=e.trace_id),e.user_id&&(s.externalUserId=e.user_id);let r={...e.metadata??{}};return e.event_name&&(r.event_name=e.event_name),{id:e.event_id,type:"mcp.event",name:n,source:e.source||"widget",timestamp:e.timestamp,correlation:s,properties:r,metadata:{}}}function te(e){return JSON.stringify({sentAt:new Date().toISOString(),source:{sdk:ft,version:"0.1.0"},events:e.map(ht)})}var $=class{buffer=[];timer=null;flushing=!1;pendingFlush=!1;stopped=!1;config;teardownVisibility=null;teardownPagehide=null;constructor(t){this.config=t,this.start(),this.registerTeardown()}send(t){if(!this.stopped){if(this.buffer.push(...t),this.buffer.length>200){let n=this.buffer.length-200;this.buffer.splice(0,n)}this.buffer.length>=20&&this.flush().catch(()=>{})}}async flush(){if(!(this.stopped||this.buffer.length===0)){if(this.flushing){this.pendingFlush=!0;return}this.flushing=!0;try{let t=this.buffer.splice(0,20);await this.sendBatch(t)}finally{this.flushing=!1,this.pendingFlush&&this.buffer.length>0&&!this.stopped&&(this.pendingFlush=!1,this.flush().catch(()=>{}))}}}stop(){this.stopped=!0,this.timer&&(clearInterval(this.timer),this.timer=null),typeof document<"u"&&this.teardownVisibility&&(document.removeEventListener("visibilitychange",this.teardownVisibility),this.teardownVisibility=null),typeof window<"u"&&this.teardownPagehide&&(window.removeEventListener("pagehide",this.teardownPagehide),this.teardownPagehide=null)}beaconFlush(){if(this.buffer.length===0)return;let t=[...this.buffer];this.buffer.length=0;let n={"Content-Type":"application/json"};if(this.config.token&&(n.Authorization=`Bearer ${this.config.token}`),typeof fetch<"u"){this.sendKeepAliveChunked(this.config.endpoint,t,n);return}typeof navigator<"u"&&typeof navigator.sendBeacon=="function"&&this.sendBeaconChunked(this.config.endpoint,t)}sendKeepAliveChunked(t,n,s){let r=te(n);if(r.length<=6e4){fetch(t,{method:"POST",headers:s,body:r,keepalive:!0}).catch(()=>{});return}if(n.length<=1)return;let c=Math.ceil(n.length/2);this.sendKeepAliveChunked(t,n.slice(0,c),s),this.sendKeepAliveChunked(t,n.slice(c),s)}sendBeaconChunked(t,n){let s=te(n);if(s.length<=6e4){navigator.sendBeacon(t,new Blob([s],{type:"application/json"}));return}if(n.length<=1)return;let r=Math.ceil(n.length/2);this.sendBeaconChunked(t,n.slice(0,r)),this.sendBeaconChunked(t,n.slice(r))}start(){this.timer||(this.timer=setInterval(()=>{this.flush().catch(()=>{})},5e3))}registerTeardown(){typeof document>"u"||(this.teardownVisibility=()=>{document.visibilityState==="hidden"&&this.beaconFlush()},this.teardownPagehide=()=>{this.beaconFlush()},document.addEventListener("visibilitychange",this.teardownVisibility),window.addEventListener("pagehide",this.teardownPagehide))}async sendBatch(t){let n=te(t),s={"Content-Type":"application/json"};this.config.token&&(s.Authorization=`Bearer ${this.config.token}`);for(let r=0;r<=3;r++)try{let c=await fetch(this.config.endpoint,{method:"POST",headers:s,body:n});if(c.status===200||c.status===207)return;if(c.status===401){this.stopped=!0;return}if(c.status>=500&&r<3){await this.delay(1e3*2**r);continue}if(c.status===429&&r<3){let h=c.headers.get("Retry-After"),x=h?Number(h):NaN,p=Number.isFinite(x)?x*1e3:1e3*2**r;await this.delay(p);continue}return}catch{if(r<3){await this.delay(1e3*2**r);continue}return}}delay(t){return new Promise(n=>setTimeout(n,t))}};var oe={identify(){},step(){},track(){},conversion(){}},S=null,X=0;function xt(){return crypto.randomUUID()}function W(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function yt(){return{widget:oe,cleanup:()=>{},config:null,captureKey:""}}function Oe(e){return e?[e.click?"1":"0",e.scroll?"1":"0",e.formField?"1":"0",e.formSubmit?"1":"0"].join(""):""}function We(e){if(!e)return null;let t=e.getToolResponseMetadata();if(!t)return null;let n=t._meta,s=t.waniwani??n?.waniwani,r=W(s?.endpoint);return r?{endpoint:r,token:W(s?.token),sessionId:W(s?.sessionId),source:W(s?.source)}:null}function Ne(e,t){return e?.endpoint===t?.endpoint&&e?.token===t?.token&&e?.sessionId===t?.sessionId&&e?.source===t?.source}function bt(e){let[t,n]=Ae(()=>We(e));return ne(()=>{if(!e){n(r=>r===null?r:null);return}let s=()=>{let r=We(e);n(c=>Ne(c,r)?c:r)};return s(),e.onToolResponseMetadataChange(()=>{s()})},[e]),t}function kt(e,t,n){let s=e.sessionId??crypto.randomUUID(),r=crypto.randomUUID(),c=new $({endpoint:e.endpoint,token:e.token,metadata:t}),h,x=0,p=o=>{c.send(o)},m=e.source??"widget",u=_e({sessionId:s,traceId:r,metadata:t,source:m,capture:n},p);function i(o,d){return{event_id:xt(),event_type:o,timestamp:new Date().toISOString(),source:m,session_id:s,trace_id:r,user_id:h,...d}}return{captureKey:Oe(n),widget:{identify(o,d){h=o,p([i("identify",{user_id:o,user_traits:d})])},step(o,d){x++,p([i("step",{event_name:o,step_sequence:x,metadata:d})])},track(o,d){p([i("track",{event_name:o,metadata:d})])},conversion(o,d){p([i("conversion",{event_name:o,metadata:d})])}},cleanup:()=>{u(),c.stop()},config:e}}function Ie(e={}){let t=wt(V),n=bt(t),s=W(e.endpoint),r=W(e.token),c=W(e.sessionId),h=vt(()=>s?{endpoint:s,token:r??n?.token,sessionId:c??n?.sessionId,source:n?.source}:n,[s,r,c,n]),[x,p]=Ae(oe),m=Re(e.metadata);m.current=e.metadata;let u=Re(e.capture);u.current=e.capture;let i=Oe(e.capture);return ne(()=>(X++,()=>{X=Math.max(X-1,0),X===0&&(S?.cleanup(),S=null)}),[]),ne(()=>{if(!(typeof window>"u")){if(!h){S?.config&&(S.cleanup(),S=yt(),p(oe));return}(!Ne(S?.config,h)||S?.captureKey!==i)&&(S?.cleanup(),S=kt(h,m.current,u.current),p(S.widget))}},[h,i]),x}import{useCallback as Ct,useEffect as Mt,useState as St}from"react";function Le(e){let t=w("widgetState"),[n,s]=St(()=>t??(typeof e=="function"?e():e??null));Mt(()=>{s(t)},[t]);let r=Ct(c=>{s(h=>{let x=typeof c=="function"?c(h):c;return re()==="openai"&&x!=null&&window.openai?.setWidgetState(x),x})},[]);return[n,r]}import{jsx as A,jsxs as Ue}from"react/jsx-runtime";var Tt=()=>Ue("div",{className:"flex flex-col items-center justify-center h-full min-h-[120px] gap-4",children:[Ue("div",{className:"flex gap-2",children:[A("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-blue-400 to-cyan-400 animate-bounce [animation-delay:-0.3s]"}),A("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-cyan-400 to-teal-400 animate-bounce [animation-delay:-0.15s]"}),A("div",{className:"w-3 h-3 rounded-full bg-gradient-to-r from-teal-400 to-emerald-400 animate-bounce"})]}),A("p",{className:"text-sm font-medium text-transparent bg-clip-text bg-gradient-to-r from-slate-400 via-slate-200 to-slate-400 bg-[length:200%_100%] animate-[shimmer_1.5s_ease-in-out_infinite]",children:"Loading widget..."}),A("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",children:A("div",{className:"w-16 h-16 rounded-full border-2 border-blue-400/20 animate-ping"})}),A("style",{children:`
|
|
63
63
|
@keyframes shimmer {
|
|
64
64
|
0% { background-position: 200% 0; }
|
|
65
65
|
100% { background-position: -200% 0; }
|
|
66
66
|
}
|
|
67
|
-
`})]});export{
|
|
67
|
+
`})]});export{de as DevModeProvider,Ve as InitializeNextJsInIframe,Tt as LoadingWidget,ge as WidgetProvider,z as getMockState,F as initializeMockOpenAI,H as updateMockDisplayMode,R as updateMockGlobal,B as updateMockTheme,P as updateMockToolOutput,me as useCallTool,fe as useDisplayMode,he as useFlowAction,we as useIsChatGptApp,ve as useLocale,xe as useMaxHeight,ye as useOpenExternal,be as useRequestDisplayMode,ke as useSafeArea,Ce as useSendFollowUp,Me as useTheme,Y as useToolOutput,Se as useToolResponseMetadata,Te as useUpdateModelContext,Ie as useWaniwani,w as useWidgetClient,Le as useWidgetState};
|
|
68
68
|
//# sourceMappingURL=react.js.map
|