@waniwani/sdk 0.7.5-beta.0 → 0.7.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp/react.js
CHANGED
|
@@ -59,7 +59,7 @@ import{a as ae}from"../chunk-DGSC74SV.js";import{b as H,c as le}from"../chunk-5O
|
|
|
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:[r(ce,{className:"w-4 h-4 text-gray-400"}),r("span",{className:"text-sm font-medium text-white",children:"Dev Controls"})]}),v("div",{className:"flex items-center gap-2",children:[r("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"}),r("button",{type:"button",onClick:u,className:"p-1 rounded-md text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:r(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:[r("label",{htmlFor:"display-mode",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Display Mode"}),r(ue,{options:He,value:h,onChange:x})]}),v("div",{children:[r("label",{htmlFor:"theme",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Theme"}),r(ue,{options:Be,value:s,onChange:y})]}),v("div",{children:[r("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:()=>g(!a),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-xs font-medium transition-all duration-150 ${a?"text-emerald-400":"text-gray-400"}`,style:{background:a?"rgba(34, 197, 94, 0.1)":"rgba(255, 255, 255, 0.04)",border:a?"1px solid rgba(34, 197, 94, 0.3)":"1px solid rgba(255, 255, 255, 0.06)"},children:[r("span",{children:"Mock ChatGPT Input Bar"}),r("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold ${a?"bg-emerald-500/20 text-emerald-400":"bg-gray-500/20 text-gray-500"}`,children:a?"ON":"OFF"})]}),a&&v("p",{className:"text-[10px] text-gray-500 mt-1.5",children:["bottom: ",X,"px"]})]}),v("div",{children:[r("label",{htmlFor:"widget-props",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Widget Props"}),r("textarea",{value:N,onChange:m=>ee(m.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:E?"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:m=>{E||(m.target.style.borderColor="rgba(99, 102, 241, 0.5)")},onBlurCapture:m=>{E||(m.target.style.borderColor="rgba(255, 255, 255, 0.06)")},spellCheck:!1}),E&&v("p",{className:"text-red-400 text-[11px] mt-1.5 flex items-center gap-1",children:[r("svg",{"aria-hidden":"true","aria-label":"Error",className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:r("path",{d:"M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"})}),E]})]}),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:m=>{m.currentTarget.style.background="rgba(255, 255, 255, 0.08)",m.currentTarget.style.borderColor="rgba(255, 255, 255, 0.1)"},onMouseLeave:m=>{m.currentTarget.style.background="rgba(255, 255, 255, 0.04)",m.currentTarget.style.borderColor="rgba(255, 255, 255, 0.06)"},children:[r(qe,{className:"w-3.5 h-3.5"}),"Reset to Defaults"]})]})]})]}),a&&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:[r("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:r("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),r("div",{className:"flex-1 text-gray-400 text-sm",children:"Ask me anything..."}),r("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:r("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r("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 V,{createContext as tt,useCallback as ge,useContext as nt,useEffect as fe,useState as oe,useSyncExternalStore as ot}from"react";async function me(){let{detectPlatform:e}=await import("../platform-GKYYQBCS.js");if(e()==="openai"){let{OpenAIWidgetClient:n}=await import("../openai-client-VPL3Z3ZD.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,f]=oe(null),[h,p]=oe(!0);return fe(()=>{let s=!0,c=null;async function a(){try{let g=await me();await g.connect(),s?(c=g,o(g),p(!1)):g.close()}catch(g){s&&(console.error("error",g),f(g instanceof Error?g:new Error(String(g))),p(!1))}}return a(),()=>{s=!1,c?.close()}},[]),fe(()=>{if(!i)return;let s=c=>{document.documentElement.classList.toggle("dark",c==="dark"),document.documentElement.style.colorScheme=c==="dark"?"dark":"auto"};return s(i.getTheme()),i.onThemeChange(s)},[i]),l&&n?V.createElement(V.Fragment,null,n(l)):h||!i?V.createElement(V.Fragment,null,t):V.createElement(J.Provider,{value:i},e)}function w(e){let t=nt(J);if(!t)throw new Error("useWidgetClient must be used within a WidgetProvider");let n=ge(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=ge(()=>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=w();return it((t,n)=>e.callTool(t,n),[e])}function ve(){return w("displayMode")}function q(){return w("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 w("locale")}function ke(){return w("maxHeight")}import{useCallback as st}from"react";function Ce(){let e=w();return st(t=>e.openExternal(t),[e])}import{useCallback as at}from"react";function Me(){let e=w();return at(t=>e.requestDisplayMode(t),[e])}function Se(){return w("safeArea")}import{useCallback as lt}from"react";function Te(){let e=w();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 w("theme")}function Re(){return w("toolResponseMetadata")}import{useCallback as dt}from"react";function _e(){let e=w();return dt(async t=>{await Promise.resolve(e.updateModelContext(t))},[e])}import{useContext as mt,useEffect as re,useMemo as gt,useRef as ft,useState as Le}from"react";function ct(){return crypto.randomUUID()}function M(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 f=t[o].slice(0,l),h=t[o].slice(l+1),p=Number(h);i[f]=Number.isFinite(p)&&h!==""?p:h}return{name:n,props:i}}function Ae(e){let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function Ne(e,t){let n=[],i=typeof navigator<"u"?navigator:void 0,o=i&&"connection"in i?i.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:o?.effectiveType??"unknown",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}})]);let l=u=>{t([M(e,"widget_error",{metadata:{error_message:u.message,error_stack:(u.error?.stack??"").slice(0,1024),error_source:u.filename??"unknown"}})])};window.addEventListener("error",l),n.push(()=>window.removeEventListener("error",l));let f=u=>{let d=u.reason,x=d instanceof Error?d.message:String(d),y=d instanceof Error?(d.stack??"").slice(0,1024):"";t([M(e,"widget_error",{metadata:{error_message:x,error_stack:y,error_source:"unhandledrejection"}})])};window.addEventListener("unhandledrejection",f),n.push(()=>window.removeEventListener("unhandledrejection",f));let h=u=>{let d=u.target;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:u.clientX,click_y:u.clientY}})])};document.addEventListener("click",h,{capture:!0}),n.push(()=>document.removeEventListener("click",h,{capture:!0}));let p=u=>{let x=u.target?.closest?.("[data-ww-conversion]");if(!x)return;let{name:y,props:b}=We(x.getAttribute("data-ww-conversion")||"");y&&t([M(e,"conversion",{event_name:y,metadata:Object.keys(b).length>0?b:void 0})])};document.addEventListener("click",p,{capture:!0}),n.push(()=>document.removeEventListener("click",p,{capture:!0}));let s=0,c=u=>{let x=u.target?.closest?.("[data-ww-step]");if(!x)return;let{name:y,props:b}=We(x.getAttribute("data-ww-step")||"");y&&(s++,t([M(e,"step",{event_name:y,step_sequence:s,metadata:Object.keys(b).length>0?b:void 0})]))};document.addEventListener("click",c,{capture:!0}),n.push(()=>document.removeEventListener("click",c,{capture:!0}));let a=u=>{let d=u.target?.closest?.("a");if(!d)return;let x=d.getAttribute("href")??"",y=x.startsWith("http")&&!x.startsWith(window.location.origin);t([M(e,"widget_link_click",{metadata:{href:x,link_text:(d.textContent??"").slice(0,200),is_external:y}})])};document.addEventListener("click",a,{capture:!0}),n.push(()=>document.removeEventListener("click",a,{capture:!0}));let g=null,N=window.scrollY||0,U=()=>{g||(g=setTimeout(()=>{g=null;let u=window.scrollY||document.documentElement.scrollTop,d=document.documentElement.scrollHeight-document.documentElement.clientHeight,x=d>0?Math.round(u/d*100):0,y=u>=N?"down":"up";N=u,t([M(e,"widget_scroll",{metadata:{scroll_depth_pct:x,scroll_direction:y,viewport_height:window.innerHeight}})])},250))};window.addEventListener("scroll",U,{passive:!0}),n.push(()=>{window.removeEventListener("scroll",U),g&&clearTimeout(g)});let E=new WeakMap,I=u=>{let d=u.target;!d||!Ae(d)||E.set(d,Date.now())},R=u=>{let d=u.target;if(!d||!Ae(d))return;let x=E.get(d),y=x?Date.now()-x:0,b=d;t([M(e,"widget_form_field",{metadata:{field_name:b.name||b.id||void 0,field_type:b.type||d.tagName.toLowerCase(),time_in_field_ms:y,filled:!!b.value}})])};document.addEventListener("focusin",I,{capture:!0}),document.addEventListener("focusout",R,{capture:!0}),n.push(()=>{document.removeEventListener("focusin",I,{capture:!0}),document.removeEventListener("focusout",R,{capture:!0})});let D=new WeakMap,L=u=>{let x=u.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=u=>{let d=u.target,x=d?D.get(d):void 0,y=0;if(d){let b=d.querySelectorAll("input, textarea, select");for(let ee of b){let P=ee;(P.validity&&!P.validity.valid||P.getAttribute("aria-invalid")==="true")&&y++}}t([M(e,"widget_form_submit",{metadata:{form_id:d?.id||void 0,time_to_submit_ms:x?Date.now()-x:void 0,validation_errors:y}})])};return document.addEventListener("submit",F,{capture:!0}),n.push(()=>document.removeEventListener("submit",F,{capture:!0})),()=>{for(let u of n)u()}}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 f=l.headers.get("Retry-After"),h=f?Number(f):NaN,p=Number.isFinite(h)?h*1e3:1e3*2**o;await this.delay(p);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(){}},T=null,Q=0;function ht(){return crypto.randomUUID()}function W(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 Ie(e){if(!e)return null;let t=e.getToolResponseMetadata();if(!t)return null;let n=t._meta,i=t.waniwani??n?.waniwani,o=W(i?.endpoint);return o?{endpoint:o,token:W(i?.token),sessionId:W(i?.sessionId),source:W(i?.source)}:null}function Oe(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]=Le(()=>Ie(e));return re(()=>{if(!e){n(o=>o===null?o:null);return}let i=()=>{let o=Ie(e);n(l=>Oe(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,f=0,h=a=>{o.send(a)},p=e.source??"widget",s=Ne({sessionId:n,traceId:i,metadata:t,source:p},h);function c(a,g){return{event_id:ht(),event_type:a,timestamp:new Date().toISOString(),source:p,session_id:n,trace_id:i,user_id:l,...g}}return{widget:{identify(a,g){l=a,h([c("identify",{user_id:a,user_traits:g})])},step(a,g){f++,h([c("step",{event_name:a,step_sequence:f,metadata:g})])},track(a,g){h([c("track",{event_name:a,metadata:g})])},conversion(a,g){h([c("conversion",{event_name:a,metadata:g})])}},cleanup:()=>{s(),o.stop()},config:e}}function Ue(e={}){let t=mt(J),n=vt(t),i=W(e.endpoint),o=W(e.token),l=W(e.sessionId),f=gt(()=>i?{endpoint:i,token:o??n?.token,sessionId:l??n?.sessionId,source:n?.source}:n,[i,o,l,n]),[h,p]=Le(se),s=ft(e.metadata);return s.current=e.metadata,re(()=>(Q++,()=>{Q=Math.max(Q-1,0),Q===0&&(T?.cleanup(),T=null)}),[]),re(()=>{if(!(typeof window>"u")){if(!f){T?.config&&(T.cleanup(),T=wt(),p(se));return}Oe(T?.config,f)||(T?.cleanup(),T=xt(f,s.current),p(T.widget))}},[f]),h}import{useCallback as yt,useEffect as bt,useState as kt}from"react";function De(e){let t=w("widgetState"),[n,i]=kt(()=>t??(typeof e=="function"?e():e??null));bt(()=>{i(t)},[t]);let o=yt(l=>{i(f=>{let h=typeof l=="function"?l(f):l;return ae()==="openai"&&h!=null&&window.openai?.setWidgetState(h),h})},[]);return[n,o]}import{jsx as A,jsxs as Fe}from"react/jsx-runtime";var Ct=()=>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:[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:`
|
|
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:[r(ce,{className:"w-4 h-4 text-gray-400"}),r("span",{className:"text-sm font-medium text-white",children:"Dev Controls"})]}),v("div",{className:"flex items-center gap-2",children:[r("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"}),r("button",{type:"button",onClick:u,className:"p-1 rounded-md text-gray-500 hover:text-gray-300 hover:bg-white/5 transition-colors",children:r(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:[r("label",{htmlFor:"display-mode",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Display Mode"}),r(ue,{options:He,value:h,onChange:x})]}),v("div",{children:[r("label",{htmlFor:"theme",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Theme"}),r(ue,{options:Be,value:s,onChange:y})]}),v("div",{children:[r("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:()=>g(!a),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-xs font-medium transition-all duration-150 ${a?"text-emerald-400":"text-gray-400"}`,style:{background:a?"rgba(34, 197, 94, 0.1)":"rgba(255, 255, 255, 0.04)",border:a?"1px solid rgba(34, 197, 94, 0.3)":"1px solid rgba(255, 255, 255, 0.06)"},children:[r("span",{children:"Mock ChatGPT Input Bar"}),r("span",{className:`px-2 py-0.5 rounded text-[10px] font-semibold ${a?"bg-emerald-500/20 text-emerald-400":"bg-gray-500/20 text-gray-500"}`,children:a?"ON":"OFF"})]}),a&&v("p",{className:"text-[10px] text-gray-500 mt-1.5",children:["bottom: ",X,"px"]})]}),v("div",{children:[r("label",{htmlFor:"widget-props",className:"text-[11px] font-medium uppercase tracking-wider text-gray-500 block mb-2",children:"Widget Props"}),r("textarea",{value:N,onChange:m=>ee(m.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:E?"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:m=>{E||(m.target.style.borderColor="rgba(99, 102, 241, 0.5)")},onBlurCapture:m=>{E||(m.target.style.borderColor="rgba(255, 255, 255, 0.06)")},spellCheck:!1}),E&&v("p",{className:"text-red-400 text-[11px] mt-1.5 flex items-center gap-1",children:[r("svg",{"aria-hidden":"true","aria-label":"Error",className:"w-3 h-3",viewBox:"0 0 16 16",fill:"currentColor",children:r("path",{d:"M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM7 4.5h2v4H7v-4zm0 5h2v2H7v-2z"})}),E]})]}),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:m=>{m.currentTarget.style.background="rgba(255, 255, 255, 0.08)",m.currentTarget.style.borderColor="rgba(255, 255, 255, 0.1)"},onMouseLeave:m=>{m.currentTarget.style.background="rgba(255, 255, 255, 0.04)",m.currentTarget.style.borderColor="rgba(255, 255, 255, 0.06)"},children:[r(qe,{className:"w-3.5 h-3.5"}),"Reset to Defaults"]})]})]})]}),a&&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:[r("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:r("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}),r("div",{className:"flex-1 text-gray-400 text-sm",children:"Ask me anything..."}),r("div",{className:"w-8 h-8 rounded-full bg-[#424242] flex items-center justify-center",children:r("svg",{"aria-hidden":"true",className:"w-4 h-4 text-gray-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r("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 V,{createContext as tt,useCallback as ge,useContext as nt,useEffect as fe,useState as oe,useSyncExternalStore as ot}from"react";async function me(){let{detectPlatform:e}=await import("../platform-GKYYQBCS.js");if(e()==="openai"){let{OpenAIWidgetClient:n}=await import("../openai-client-WEB5BLC4.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,f]=oe(null),[h,p]=oe(!0);return fe(()=>{let s=!0,c=null;async function a(){try{let g=await me();await g.connect(),s?(c=g,o(g),p(!1)):g.close()}catch(g){s&&(console.error("error",g),f(g instanceof Error?g:new Error(String(g))),p(!1))}}return a(),()=>{s=!1,c?.close()}},[]),fe(()=>{if(!i)return;let s=c=>{document.documentElement.classList.toggle("dark",c==="dark"),document.documentElement.style.colorScheme=c==="dark"?"dark":"auto"};return s(i.getTheme()),i.onThemeChange(s)},[i]),l&&n?V.createElement(V.Fragment,null,n(l)):h||!i?V.createElement(V.Fragment,null,t):V.createElement(J.Provider,{value:i},e)}function w(e){let t=nt(J);if(!t)throw new Error("useWidgetClient must be used within a WidgetProvider");let n=ge(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=ge(()=>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=w();return it((t,n)=>e.callTool(t,n),[e])}function ve(){return w("displayMode")}function q(){return w("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 w("locale")}function ke(){return w("maxHeight")}import{useCallback as st}from"react";function Ce(){let e=w();return st(t=>e.openExternal(t),[e])}import{useCallback as at}from"react";function Me(){let e=w();return at(t=>e.requestDisplayMode(t),[e])}function Se(){return w("safeArea")}import{useCallback as lt}from"react";function Te(){let e=w();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 w("theme")}function Re(){return w("toolResponseMetadata")}import{useCallback as dt}from"react";function _e(){let e=w();return dt(async t=>{await Promise.resolve(e.updateModelContext(t))},[e])}import{useContext as mt,useEffect as re,useMemo as gt,useRef as ft,useState as Le}from"react";function ct(){return crypto.randomUUID()}function M(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 f=t[o].slice(0,l),h=t[o].slice(l+1),p=Number(h);i[f]=Number.isFinite(p)&&h!==""?p:h}return{name:n,props:i}}function Ae(e){let t=e.tagName.toLowerCase();return t==="input"||t==="textarea"||t==="select"}function Ne(e,t){let n=[],i=typeof navigator<"u"?navigator:void 0,o=i&&"connection"in i?i.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:o?.effectiveType??"unknown",timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}})]);let l=u=>{t([M(e,"widget_error",{metadata:{error_message:u.message,error_stack:(u.error?.stack??"").slice(0,1024),error_source:u.filename??"unknown"}})])};window.addEventListener("error",l),n.push(()=>window.removeEventListener("error",l));let f=u=>{let d=u.reason,x=d instanceof Error?d.message:String(d),y=d instanceof Error?(d.stack??"").slice(0,1024):"";t([M(e,"widget_error",{metadata:{error_message:x,error_stack:y,error_source:"unhandledrejection"}})])};window.addEventListener("unhandledrejection",f),n.push(()=>window.removeEventListener("unhandledrejection",f));let h=u=>{let d=u.target;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:u.clientX,click_y:u.clientY}})])};document.addEventListener("click",h,{capture:!0}),n.push(()=>document.removeEventListener("click",h,{capture:!0}));let p=u=>{let x=u.target?.closest?.("[data-ww-conversion]");if(!x)return;let{name:y,props:b}=We(x.getAttribute("data-ww-conversion")||"");y&&t([M(e,"conversion",{event_name:y,metadata:Object.keys(b).length>0?b:void 0})])};document.addEventListener("click",p,{capture:!0}),n.push(()=>document.removeEventListener("click",p,{capture:!0}));let s=0,c=u=>{let x=u.target?.closest?.("[data-ww-step]");if(!x)return;let{name:y,props:b}=We(x.getAttribute("data-ww-step")||"");y&&(s++,t([M(e,"step",{event_name:y,step_sequence:s,metadata:Object.keys(b).length>0?b:void 0})]))};document.addEventListener("click",c,{capture:!0}),n.push(()=>document.removeEventListener("click",c,{capture:!0}));let a=u=>{let d=u.target?.closest?.("a");if(!d)return;let x=d.getAttribute("href")??"",y=x.startsWith("http")&&!x.startsWith(window.location.origin);t([M(e,"widget_link_click",{metadata:{href:x,link_text:(d.textContent??"").slice(0,200),is_external:y}})])};document.addEventListener("click",a,{capture:!0}),n.push(()=>document.removeEventListener("click",a,{capture:!0}));let g=null,N=window.scrollY||0,U=()=>{g||(g=setTimeout(()=>{g=null;let u=window.scrollY||document.documentElement.scrollTop,d=document.documentElement.scrollHeight-document.documentElement.clientHeight,x=d>0?Math.round(u/d*100):0,y=u>=N?"down":"up";N=u,t([M(e,"widget_scroll",{metadata:{scroll_depth_pct:x,scroll_direction:y,viewport_height:window.innerHeight}})])},250))};window.addEventListener("scroll",U,{passive:!0}),n.push(()=>{window.removeEventListener("scroll",U),g&&clearTimeout(g)});let E=new WeakMap,I=u=>{let d=u.target;!d||!Ae(d)||E.set(d,Date.now())},R=u=>{let d=u.target;if(!d||!Ae(d))return;let x=E.get(d),y=x?Date.now()-x:0,b=d;t([M(e,"widget_form_field",{metadata:{field_name:b.name||b.id||void 0,field_type:b.type||d.tagName.toLowerCase(),time_in_field_ms:y,filled:!!b.value}})])};document.addEventListener("focusin",I,{capture:!0}),document.addEventListener("focusout",R,{capture:!0}),n.push(()=>{document.removeEventListener("focusin",I,{capture:!0}),document.removeEventListener("focusout",R,{capture:!0})});let D=new WeakMap,L=u=>{let x=u.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=u=>{let d=u.target,x=d?D.get(d):void 0,y=0;if(d){let b=d.querySelectorAll("input, textarea, select");for(let ee of b){let P=ee;(P.validity&&!P.validity.valid||P.getAttribute("aria-invalid")==="true")&&y++}}t([M(e,"widget_form_submit",{metadata:{form_id:d?.id||void 0,time_to_submit_ms:x?Date.now()-x:void 0,validation_errors:y}})])};return document.addEventListener("submit",F,{capture:!0}),n.push(()=>document.removeEventListener("submit",F,{capture:!0})),()=>{for(let u of n)u()}}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 f=l.headers.get("Retry-After"),h=f?Number(f):NaN,p=Number.isFinite(h)?h*1e3:1e3*2**o;await this.delay(p);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(){}},T=null,Q=0;function ht(){return crypto.randomUUID()}function W(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 Ie(e){if(!e)return null;let t=e.getToolResponseMetadata();if(!t)return null;let n=t._meta,i=t.waniwani??n?.waniwani,o=W(i?.endpoint);return o?{endpoint:o,token:W(i?.token),sessionId:W(i?.sessionId),source:W(i?.source)}:null}function Oe(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]=Le(()=>Ie(e));return re(()=>{if(!e){n(o=>o===null?o:null);return}let i=()=>{let o=Ie(e);n(l=>Oe(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,f=0,h=a=>{o.send(a)},p=e.source??"widget",s=Ne({sessionId:n,traceId:i,metadata:t,source:p},h);function c(a,g){return{event_id:ht(),event_type:a,timestamp:new Date().toISOString(),source:p,session_id:n,trace_id:i,user_id:l,...g}}return{widget:{identify(a,g){l=a,h([c("identify",{user_id:a,user_traits:g})])},step(a,g){f++,h([c("step",{event_name:a,step_sequence:f,metadata:g})])},track(a,g){h([c("track",{event_name:a,metadata:g})])},conversion(a,g){h([c("conversion",{event_name:a,metadata:g})])}},cleanup:()=>{s(),o.stop()},config:e}}function Ue(e={}){let t=mt(J),n=vt(t),i=W(e.endpoint),o=W(e.token),l=W(e.sessionId),f=gt(()=>i?{endpoint:i,token:o??n?.token,sessionId:l??n?.sessionId,source:n?.source}:n,[i,o,l,n]),[h,p]=Le(se),s=ft(e.metadata);return s.current=e.metadata,re(()=>(Q++,()=>{Q=Math.max(Q-1,0),Q===0&&(T?.cleanup(),T=null)}),[]),re(()=>{if(!(typeof window>"u")){if(!f){T?.config&&(T.cleanup(),T=wt(),p(se));return}Oe(T?.config,f)||(T?.cleanup(),T=xt(f,s.current),p(T.widget))}},[f]),h}import{useCallback as yt,useEffect as bt,useState as kt}from"react";function De(e){let t=w("widgetState"),[n,i]=kt(()=>t??(typeof e=="function"?e():e??null));bt(()=>{i(t)},[t]);let o=yt(l=>{i(f=>{let h=typeof l=="function"?l(f):l;return ae()==="openai"&&h!=null&&window.openai?.setWidgetState(h),h})},[]);return[n,o]}import{jsx as A,jsxs as Fe}from"react/jsx-runtime";var Ct=()=>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:[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; }
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{a,d as i,e as s}from"./chunk-5OQXAEHG.js";import{App as
|
|
2
|
+
import{a,d as i,e as s}from"./chunk-5OQXAEHG.js";import{App as p,PostMessageTransport as u}from"@modelcontextprotocol/ext-apps";var r=class{pendingModelContext=null;app;getGlobal(e,n){return typeof window>"u"?n:window.openai?.[e]??n}onGlobalChange(e,n,t){if(typeof window>"u")return()=>{};let o=d=>{let l=d.detail.globals[e];l!==void 0&&n(t?t(l):l)};return window.addEventListener(a,o,{passive:!0}),()=>window.removeEventListener(a,o)}constructor(){this.app=new p({name:"WaniWani Widget",version:"1.0.0"},{},{autoResize:!1})}async connect(){if(typeof window>"u"||!("openai"in window))throw new Error("OpenAI global not found. Are you running in ChatGPT?");await this.app.connect(new u(window.parent,window.parent))}async close(){await this.app.close()}getToolOutput(){return this.getGlobal("toolOutput",null)}onToolResult(e){return this.onGlobalChange("toolOutput",e,n=>({content:[],structuredContent:n??{}}))}async callTool(e,n){if(typeof window>"u"||!window.openai?.callTool)throw new Error("OpenAI callTool not available");return{content:[{type:"text",text:(await window.openai.callTool(e,n)).result}]}}openExternal(e){typeof window<"u"&&window.openai?.openExternal&&window.openai.openExternal({href:e})}sendFollowUp(e){let n=s(this.pendingModelContext);this.pendingModelContext=null;let t=n?`${e}
|
|
3
3
|
|
|
4
|
-
${n}`:e;this.app.sendMessage({role:"user",content:[{type:"text",text:t}]}).
|
|
5
|
-
//# sourceMappingURL=openai-client-
|
|
4
|
+
${n}`:e;this.app.sendMessage({role:"user",content:[{type:"text",text:t}]}).then(o=>{console.log("[sendFollowUp] ui/message result:",o),o.isError&&console.warn("[sendFollowUp] host rejected message:",o)}).catch(o=>{console.error("[sendFollowUp] ui/message error:",o)})}updateModelContext(e){this.pendingModelContext=i(this.pendingModelContext,e)}getTheme(){return this.getGlobal("theme","light")}onThemeChange(e){return this.onGlobalChange("theme",e)}getLocale(){return this.getGlobal("locale","en")}getDisplayMode(){return this.getGlobal("displayMode","inline")}async requestDisplayMode(e){return typeof window>"u"||!window.openai?.requestDisplayMode?"inline":(await window.openai.requestDisplayMode({mode:e})).mode}onDisplayModeChange(e){return this.onGlobalChange("displayMode",e)}getSafeArea(){return this.getGlobal("safeArea",null)}onSafeAreaChange(e){return this.onGlobalChange("safeArea",e,n=>n??null)}getMaxHeight(){return this.getGlobal("maxHeight",null)}onMaxHeightChange(e){return this.onGlobalChange("maxHeight",e,n=>n??null)}getToolResponseMetadata(){return this.getGlobal("toolResponseMetadata",null)}onToolResponseMetadataChange(e){return this.onGlobalChange("toolResponseMetadata",e,n=>n??null)}getWidgetState(){return this.getGlobal("widgetState",null)}onWidgetStateChange(e){return this.onGlobalChange("widgetState",e,n=>n??null)}};export{r as OpenAIWidgetClient};
|
|
5
|
+
//# sourceMappingURL=openai-client-WEB5BLC4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mcp/react/widgets/openai-client.ts"],"sourcesContent":["import { App, PostMessageTransport } from \"@modelcontextprotocol/ext-apps\";\nimport {\n\tformatModelContextForPrompt,\n\ttype ModelContextUpdate,\n\tmergeModelContext,\n} from \"../../../shared/model-context\";\nimport type {\n\tDisplayMode,\n\tSafeArea,\n\tTheme,\n\tUnknownObject,\n} from \"../hooks/@types\";\nimport { SET_GLOBALS_EVENT_TYPE, type SetGlobalsEvent } from \"../hooks/@types\";\nimport type {\n\tToolCallResult,\n\tToolResult,\n\tUnifiedWidgetClient,\n} from \"./widget-client\";\n\ntype GlobalsKey = keyof SetGlobalsEvent[\"detail\"][\"globals\"];\n\n/**\n * OpenAI widget client implementation.\n * Uses window.openai global object injected by ChatGPT.\n */\nexport class OpenAIWidgetClient implements UnifiedWidgetClient {\n\tprivate pendingModelContext: ModelContextUpdate | null = null;\n\tprivate app: App;\n\n\tprivate getGlobal<T>(\n\t\tkey: keyof NonNullable<typeof window.openai>,\n\t\tfallback: T,\n\t): T {\n\t\tif (typeof window === \"undefined\") {\n\t\t\treturn fallback;\n\t\t}\n\t\treturn (window.openai?.[key] as T) ?? fallback;\n\t}\n\n\tprivate onGlobalChange<\n\t\tK extends GlobalsKey,\n\t\tT = SetGlobalsEvent[\"detail\"][\"globals\"][K],\n\t>(\n\t\tkey: K,\n\t\tcallback: (value: T) => void,\n\t\ttransform?: (value: SetGlobalsEvent[\"detail\"][\"globals\"][K]) => T,\n\t): () => void {\n\t\tif (typeof window === \"undefined\") {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst handler = (event: SetGlobalsEvent) => {\n\t\t\tconst value = event.detail.globals[key];\n\t\t\tif (value !== undefined) {\n\t\t\t\tcallback(transform ? transform(value) : (value as T));\n\t\t\t}\n\t\t};\n\n\t\twindow.addEventListener(SET_GLOBALS_EVENT_TYPE, handler, { passive: true });\n\t\treturn () => window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handler);\n\t}\n\n\tconstructor() {\n\t\tthis.app = new App(\n\t\t\t{ name: \"WaniWani Widget\", version: \"1.0.0\" },\n\t\t\t{},\n\t\t\t{ autoResize: false },\n\t\t);\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (typeof window === \"undefined\" || !(\"openai\" in window)) {\n\t\t\tthrow new Error(\"OpenAI global not found. Are you running in ChatGPT?\");\n\t\t}\n\t\tawait this.app.connect(\n\t\t\tnew PostMessageTransport(window.parent, window.parent),\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tawait this.app.close();\n\t}\n\n\tgetToolOutput<T = Record<string, unknown>>(): T | null {\n\t\treturn this.getGlobal<T | null>(\"toolOutput\", null);\n\t}\n\n\tonToolResult(callback: (result: ToolResult) => void): () => void {\n\t\treturn this.onGlobalChange(\"toolOutput\", callback, (v) => ({\n\t\t\tcontent: [],\n\t\t\tstructuredContent: v ?? {},\n\t\t}));\n\t}\n\n\tasync callTool(\n\t\tname: string,\n\t\targs: Record<string, unknown>,\n\t): Promise<ToolCallResult> {\n\t\tif (typeof window === \"undefined\" || !window.openai?.callTool) {\n\t\t\tthrow new Error(\"OpenAI callTool not available\");\n\t\t}\n\t\tconst response = await window.openai.callTool(name, args);\n\t\treturn { content: [{ type: \"text\", text: response.result }] };\n\t}\n\n\topenExternal(url: string): void {\n\t\tif (typeof window !== \"undefined\" && window.openai?.openExternal) {\n\t\t\twindow.openai.openExternal({ href: url });\n\t\t}\n\t}\n\n\tsendFollowUp(prompt: string): void {\n\t\tconst hiddenContext = formatModelContextForPrompt(this.pendingModelContext);\n\t\tthis.pendingModelContext = null;\n\t\tconst message = hiddenContext ? `${prompt}\\n\\n${hiddenContext}` : prompt;\n\t\tthis.app\n\t\t\t.sendMessage({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: [{ type: \"text\", text: message }],\n\t\t\t})\n\t\t\t.then((result) => {\n\t\t\t\tconsole.log(\"[sendFollowUp] ui/message result:\", result);\n\t\t\t\tif (result.isError) {\n\t\t\t\t\tconsole.warn(\"[sendFollowUp] host rejected message:\", result);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((err: unknown) => {\n\t\t\t\tconsole.error(\"[sendFollowUp] ui/message error:\", err);\n\t\t\t});\n\t}\n\n\tupdateModelContext(context: ModelContextUpdate): void {\n\t\tthis.pendingModelContext = mergeModelContext(\n\t\t\tthis.pendingModelContext,\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tgetTheme(): Theme {\n\t\treturn this.getGlobal(\"theme\", \"light\" as Theme);\n\t}\n\n\tonThemeChange(callback: (theme: Theme) => void): () => void {\n\t\treturn this.onGlobalChange(\"theme\", callback);\n\t}\n\n\tgetLocale(): string {\n\t\treturn this.getGlobal(\"locale\", \"en\");\n\t}\n\n\tgetDisplayMode(): DisplayMode {\n\t\treturn this.getGlobal(\"displayMode\", \"inline\" as DisplayMode);\n\t}\n\n\tasync requestDisplayMode(mode: DisplayMode): Promise<DisplayMode> {\n\t\tif (typeof window === \"undefined\" || !window.openai?.requestDisplayMode) {\n\t\t\treturn \"inline\";\n\t\t}\n\t\tconst result = await window.openai.requestDisplayMode({ mode });\n\t\treturn result.mode;\n\t}\n\n\tonDisplayModeChange(callback: (mode: DisplayMode) => void): () => void {\n\t\treturn this.onGlobalChange(\"displayMode\", callback);\n\t}\n\n\tgetSafeArea(): SafeArea | null {\n\t\treturn this.getGlobal(\"safeArea\", null);\n\t}\n\n\tonSafeAreaChange(callback: (safeArea: SafeArea | null) => void): () => void {\n\t\treturn this.onGlobalChange(\"safeArea\", callback, (v) => v ?? null);\n\t}\n\n\tgetMaxHeight(): number | null {\n\t\treturn this.getGlobal(\"maxHeight\", null);\n\t}\n\n\tonMaxHeightChange(callback: (maxHeight: number | null) => void): () => void {\n\t\treturn this.onGlobalChange(\"maxHeight\", callback, (v) => v ?? null);\n\t}\n\n\tgetToolResponseMetadata(): UnknownObject | null {\n\t\treturn this.getGlobal(\"toolResponseMetadata\", null);\n\t}\n\n\tonToolResponseMetadataChange(\n\t\tcallback: (metadata: UnknownObject | null) => void,\n\t): () => void {\n\t\treturn this.onGlobalChange(\n\t\t\t\"toolResponseMetadata\",\n\t\t\tcallback,\n\t\t\t(v) => v ?? null,\n\t\t);\n\t}\n\n\tgetWidgetState(): UnknownObject | null {\n\t\treturn this.getGlobal<UnknownObject | null>(\"widgetState\", null);\n\t}\n\n\tonWidgetStateChange(\n\t\tcallback: (state: UnknownObject | null) => void,\n\t): () => void {\n\t\treturn this.onGlobalChange(\"widgetState\", callback, (v) => v ?? null);\n\t}\n}\n"],"mappings":"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","names":["App","PostMessageTransport","OpenAIWidgetClient","key","fallback","callback","transform","handler","event","value","SET_GLOBALS_EVENT_TYPE","App","PostMessageTransport","v","name","args","url","prompt","hiddenContext","formatModelContextForPrompt","message","result","err","context","mergeModelContext","mode"]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mcp/react/widgets/openai-client.ts"],"sourcesContent":["import { App, PostMessageTransport } from \"@modelcontextprotocol/ext-apps\";\nimport {\n\tformatModelContextForPrompt,\n\ttype ModelContextUpdate,\n\tmergeModelContext,\n} from \"../../../shared/model-context\";\nimport type {\n\tDisplayMode,\n\tSafeArea,\n\tTheme,\n\tUnknownObject,\n} from \"../hooks/@types\";\nimport { SET_GLOBALS_EVENT_TYPE, type SetGlobalsEvent } from \"../hooks/@types\";\nimport type {\n\tToolCallResult,\n\tToolResult,\n\tUnifiedWidgetClient,\n} from \"./widget-client\";\n\ntype GlobalsKey = keyof SetGlobalsEvent[\"detail\"][\"globals\"];\n\n/**\n * OpenAI widget client implementation.\n * Uses window.openai global object injected by ChatGPT.\n */\nexport class OpenAIWidgetClient implements UnifiedWidgetClient {\n\tprivate pendingModelContext: ModelContextUpdate | null = null;\n\tprivate app: App;\n\n\tprivate getGlobal<T>(\n\t\tkey: keyof NonNullable<typeof window.openai>,\n\t\tfallback: T,\n\t): T {\n\t\tif (typeof window === \"undefined\") {\n\t\t\treturn fallback;\n\t\t}\n\t\treturn (window.openai?.[key] as T) ?? fallback;\n\t}\n\n\tprivate onGlobalChange<\n\t\tK extends GlobalsKey,\n\t\tT = SetGlobalsEvent[\"detail\"][\"globals\"][K],\n\t>(\n\t\tkey: K,\n\t\tcallback: (value: T) => void,\n\t\ttransform?: (value: SetGlobalsEvent[\"detail\"][\"globals\"][K]) => T,\n\t): () => void {\n\t\tif (typeof window === \"undefined\") {\n\t\t\treturn () => {};\n\t\t}\n\n\t\tconst handler = (event: SetGlobalsEvent) => {\n\t\t\tconst value = event.detail.globals[key];\n\t\t\tif (value !== undefined) {\n\t\t\t\tcallback(transform ? transform(value) : (value as T));\n\t\t\t}\n\t\t};\n\n\t\twindow.addEventListener(SET_GLOBALS_EVENT_TYPE, handler, { passive: true });\n\t\treturn () => window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handler);\n\t}\n\n\tconstructor() {\n\t\tthis.app = new App(\n\t\t\t{ name: \"WaniWani Widget\", version: \"1.0.0\" },\n\t\t\t{},\n\t\t\t{ autoResize: false },\n\t\t);\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (typeof window === \"undefined\" || !(\"openai\" in window)) {\n\t\t\tthrow new Error(\"OpenAI global not found. Are you running in ChatGPT?\");\n\t\t}\n\t\tawait this.app.connect(\n\t\t\tnew PostMessageTransport(window.parent, window.parent),\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tawait this.app.close();\n\t}\n\n\tgetToolOutput<T = Record<string, unknown>>(): T | null {\n\t\treturn this.getGlobal<T | null>(\"toolOutput\", null);\n\t}\n\n\tonToolResult(callback: (result: ToolResult) => void): () => void {\n\t\treturn this.onGlobalChange(\"toolOutput\", callback, (v) => ({\n\t\t\tcontent: [],\n\t\t\tstructuredContent: v ?? {},\n\t\t}));\n\t}\n\n\tasync callTool(\n\t\tname: string,\n\t\targs: Record<string, unknown>,\n\t): Promise<ToolCallResult> {\n\t\tif (typeof window === \"undefined\" || !window.openai?.callTool) {\n\t\t\tthrow new Error(\"OpenAI callTool not available\");\n\t\t}\n\t\tconst response = await window.openai.callTool(name, args);\n\t\treturn { content: [{ type: \"text\", text: response.result }] };\n\t}\n\n\topenExternal(url: string): void {\n\t\tif (typeof window !== \"undefined\" && window.openai?.openExternal) {\n\t\t\twindow.openai.openExternal({ href: url });\n\t\t}\n\t}\n\n\tsendFollowUp(prompt: string): void {\n\t\tconst hiddenContext = formatModelContextForPrompt(this.pendingModelContext);\n\t\tthis.pendingModelContext = null;\n\t\tconst message = hiddenContext ? `${prompt}\\n\\n${hiddenContext}` : prompt;\n\t\tthis.app\n\t\t\t.sendMessage({\n\t\t\t\trole: \"user\",\n\t\t\t\tcontent: [{ type: \"text\", text: message }],\n\t\t\t})\n\t\t\t.catch((err: unknown) => {\n\t\t\t\tconsole.error(\"Failed to send follow-up message:\", err);\n\t\t\t});\n\t}\n\n\tupdateModelContext(context: ModelContextUpdate): void {\n\t\tthis.pendingModelContext = mergeModelContext(\n\t\t\tthis.pendingModelContext,\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tgetTheme(): Theme {\n\t\treturn this.getGlobal(\"theme\", \"light\" as Theme);\n\t}\n\n\tonThemeChange(callback: (theme: Theme) => void): () => void {\n\t\treturn this.onGlobalChange(\"theme\", callback);\n\t}\n\n\tgetLocale(): string {\n\t\treturn this.getGlobal(\"locale\", \"en\");\n\t}\n\n\tgetDisplayMode(): DisplayMode {\n\t\treturn this.getGlobal(\"displayMode\", \"inline\" as DisplayMode);\n\t}\n\n\tasync requestDisplayMode(mode: DisplayMode): Promise<DisplayMode> {\n\t\tif (typeof window === \"undefined\" || !window.openai?.requestDisplayMode) {\n\t\t\treturn \"inline\";\n\t\t}\n\t\tconst result = await window.openai.requestDisplayMode({ mode });\n\t\treturn result.mode;\n\t}\n\n\tonDisplayModeChange(callback: (mode: DisplayMode) => void): () => void {\n\t\treturn this.onGlobalChange(\"displayMode\", callback);\n\t}\n\n\tgetSafeArea(): SafeArea | null {\n\t\treturn this.getGlobal(\"safeArea\", null);\n\t}\n\n\tonSafeAreaChange(callback: (safeArea: SafeArea | null) => void): () => void {\n\t\treturn this.onGlobalChange(\"safeArea\", callback, (v) => v ?? null);\n\t}\n\n\tgetMaxHeight(): number | null {\n\t\treturn this.getGlobal(\"maxHeight\", null);\n\t}\n\n\tonMaxHeightChange(callback: (maxHeight: number | null) => void): () => void {\n\t\treturn this.onGlobalChange(\"maxHeight\", callback, (v) => v ?? null);\n\t}\n\n\tgetToolResponseMetadata(): UnknownObject | null {\n\t\treturn this.getGlobal(\"toolResponseMetadata\", null);\n\t}\n\n\tonToolResponseMetadataChange(\n\t\tcallback: (metadata: UnknownObject | null) => void,\n\t): () => void {\n\t\treturn this.onGlobalChange(\n\t\t\t\"toolResponseMetadata\",\n\t\t\tcallback,\n\t\t\t(v) => v ?? null,\n\t\t);\n\t}\n\n\tgetWidgetState(): UnknownObject | null {\n\t\treturn this.getGlobal<UnknownObject | null>(\"widgetState\", null);\n\t}\n\n\tonWidgetStateChange(\n\t\tcallback: (state: UnknownObject | null) => void,\n\t): () => void {\n\t\treturn this.onGlobalChange(\"widgetState\", callback, (v) => v ?? null);\n\t}\n}\n"],"mappings":";iDAAA,OAAS,OAAAA,EAAK,wBAAAC,MAA4B,iCAyBnC,IAAMC,EAAN,KAAwD,CACtD,oBAAiD,KACjD,IAEA,UACPC,EACAC,EACI,CACJ,OAAI,OAAO,OAAW,IACdA,EAEA,OAAO,SAASD,CAAG,GAAWC,CACvC,CAEQ,eAIPD,EACAE,EACAC,EACa,CACb,GAAI,OAAO,OAAW,IACrB,MAAO,IAAM,CAAC,EAGf,IAAMC,EAAWC,GAA2B,CAC3C,IAAMC,EAAQD,EAAM,OAAO,QAAQL,CAAG,EAClCM,IAAU,QACbJ,EAASC,EAAYA,EAAUG,CAAK,EAAKA,CAAW,CAEtD,EAEA,cAAO,iBAAiBC,EAAwBH,EAAS,CAAE,QAAS,EAAK,CAAC,EACnE,IAAM,OAAO,oBAAoBG,EAAwBH,CAAO,CACxE,CAEA,aAAc,CACb,KAAK,IAAM,IAAII,EACd,CAAE,KAAM,kBAAmB,QAAS,OAAQ,EAC5C,CAAC,EACD,CAAE,WAAY,EAAM,CACrB,CACD,CAEA,MAAM,SAAyB,CAC9B,GAAI,OAAO,OAAW,KAAe,EAAE,WAAY,QAClD,MAAM,IAAI,MAAM,sDAAsD,EAEvE,MAAM,KAAK,IAAI,QACd,IAAIC,EAAqB,OAAO,OAAQ,OAAO,MAAM,CACtD,CACD,CAEA,MAAM,OAAuB,CAC5B,MAAM,KAAK,IAAI,MAAM,CACtB,CAEA,eAAuD,CACtD,OAAO,KAAK,UAAoB,aAAc,IAAI,CACnD,CAEA,aAAaP,EAAoD,CAChE,OAAO,KAAK,eAAe,aAAcA,EAAWQ,IAAO,CAC1D,QAAS,CAAC,EACV,kBAAmBA,GAAK,CAAC,CAC1B,EAAE,CACH,CAEA,MAAM,SACLC,EACAC,EAC0B,CAC1B,GAAI,OAAO,OAAW,KAAe,CAAC,OAAO,QAAQ,SACpD,MAAM,IAAI,MAAM,+BAA+B,EAGhD,MAAO,CAAE,QAAS,CAAC,CAAE,KAAM,OAAQ,MADlB,MAAM,OAAO,OAAO,SAASD,EAAMC,CAAI,GACN,MAAO,CAAC,CAAE,CAC7D,CAEA,aAAaC,EAAmB,CAC3B,OAAO,OAAW,KAAe,OAAO,QAAQ,cACnD,OAAO,OAAO,aAAa,CAAE,KAAMA,CAAI,CAAC,CAE1C,CAEA,aAAaC,EAAsB,CAClC,IAAMC,EAAgBC,EAA4B,KAAK,mBAAmB,EAC1E,KAAK,oBAAsB,KAC3B,IAAMC,EAAUF,EAAgB,GAAGD,CAAM;AAAA;AAAA,EAAOC,CAAa,GAAKD,EAClE,KAAK,IACH,YAAY,CACZ,KAAM,OACN,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAMG,CAAQ,CAAC,CAC1C,CAAC,EACA,MAAOC,GAAiB,CACxB,QAAQ,MAAM,oCAAqCA,CAAG,CACvD,CAAC,CACH,CAEA,mBAAmBC,EAAmC,CACrD,KAAK,oBAAsBC,EAC1B,KAAK,oBACLD,CACD,CACD,CAEA,UAAkB,CACjB,OAAO,KAAK,UAAU,QAAS,OAAgB,CAChD,CAEA,cAAcjB,EAA8C,CAC3D,OAAO,KAAK,eAAe,QAASA,CAAQ,CAC7C,CAEA,WAAoB,CACnB,OAAO,KAAK,UAAU,SAAU,IAAI,CACrC,CAEA,gBAA8B,CAC7B,OAAO,KAAK,UAAU,cAAe,QAAuB,CAC7D,CAEA,MAAM,mBAAmBmB,EAAyC,CACjE,OAAI,OAAO,OAAW,KAAe,CAAC,OAAO,QAAQ,mBAC7C,UAEO,MAAM,OAAO,OAAO,mBAAmB,CAAE,KAAAA,CAAK,CAAC,GAChD,IACf,CAEA,oBAAoBnB,EAAmD,CACtE,OAAO,KAAK,eAAe,cAAeA,CAAQ,CACnD,CAEA,aAA+B,CAC9B,OAAO,KAAK,UAAU,WAAY,IAAI,CACvC,CAEA,iBAAiBA,EAA2D,CAC3E,OAAO,KAAK,eAAe,WAAYA,EAAWQ,GAAMA,GAAK,IAAI,CAClE,CAEA,cAA8B,CAC7B,OAAO,KAAK,UAAU,YAAa,IAAI,CACxC,CAEA,kBAAkBR,EAA0D,CAC3E,OAAO,KAAK,eAAe,YAAaA,EAAWQ,GAAMA,GAAK,IAAI,CACnE,CAEA,yBAAgD,CAC/C,OAAO,KAAK,UAAU,uBAAwB,IAAI,CACnD,CAEA,6BACCR,EACa,CACb,OAAO,KAAK,eACX,uBACAA,EACCQ,GAAMA,GAAK,IACb,CACD,CAEA,gBAAuC,CACtC,OAAO,KAAK,UAAgC,cAAe,IAAI,CAChE,CAEA,oBACCR,EACa,CACb,OAAO,KAAK,eAAe,cAAeA,EAAWQ,GAAMA,GAAK,IAAI,CACrE,CACD","names":["App","PostMessageTransport","OpenAIWidgetClient","key","fallback","callback","transform","handler","event","value","SET_GLOBALS_EVENT_TYPE","App","PostMessageTransport","v","name","args","url","prompt","hiddenContext","formatModelContextForPrompt","message","err","context","mergeModelContext","mode"]}
|