@swarm.ing/pieui 2.0.22 → 2.0.24

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.
Files changed (33) hide show
  1. package/dist/cli.js +992 -400
  2. package/dist/code/args.d.ts +3 -1
  3. package/dist/code/args.d.ts.map +1 -1
  4. package/dist/code/commands/add.d.ts.map +1 -1
  5. package/dist/code/commands/addEvent.d.ts.map +1 -1
  6. package/dist/code/commands/cardPull.d.ts +2 -0
  7. package/dist/code/commands/cardPull.d.ts.map +1 -0
  8. package/dist/code/commands/cardView.d.ts +2 -0
  9. package/dist/code/commands/cardView.d.ts.map +1 -0
  10. package/dist/code/commands/create.d.ts +1 -1
  11. package/dist/code/commands/create.d.ts.map +1 -1
  12. package/dist/code/commands/init.d.ts +1 -1
  13. package/dist/code/commands/init.d.ts.map +1 -1
  14. package/dist/code/commands/list.d.ts.map +1 -1
  15. package/dist/code/commands/pageAdd.d.ts.map +1 -1
  16. package/dist/code/commands/pageAjax.d.ts +3 -0
  17. package/dist/code/commands/pageAjax.d.ts.map +1 -0
  18. package/dist/code/commands/pageView.d.ts +2 -0
  19. package/dist/code/commands/pageView.d.ts.map +1 -0
  20. package/dist/code/commands/selfUpgrade.d.ts +2 -0
  21. package/dist/code/commands/selfUpgrade.d.ts.map +1 -0
  22. package/dist/code/scan.d.ts.map +1 -1
  23. package/dist/code/types.d.ts +8 -3
  24. package/dist/code/types.d.ts.map +1 -1
  25. package/dist/components/PieCard/index.d.ts +1 -1
  26. package/dist/components/PieCard/index.d.ts.map +1 -1
  27. package/dist/components/PieCard/types/index.d.ts +6 -0
  28. package/dist/components/PieCard/types/index.d.ts.map +1 -1
  29. package/dist/components/index.esm.js +1 -1
  30. package/dist/components/index.js +1 -1
  31. package/dist/index.esm.js +2 -2
  32. package/dist/index.js +2 -2
  33. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- var xH=Object.create;var{getPrototypeOf:dH,defineProperty:Vf,getOwnPropertyNames:CU,getOwnPropertyDescriptor:uH}=Object,JU=Object.prototype.hasOwnProperty;var YU=(f,U,P)=>{P=f!=null?xH(dH(f)):{};let H=U||!f||!f.__esModule?Vf(P,"default",{value:f,enumerable:!0}):P;for(let D of CU(f))if(!JU.call(H,D))Vf(H,D,{get:()=>f[D],enumerable:!0});return H},IU=new WeakMap,bH=(f)=>{var U=IU.get(f),P;if(U)return U;if(U=Vf({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")CU(f).map((H)=>!JU.call(U,H)&&Vf(U,H,{get:()=>f[H],enumerable:!(P=uH(f,H))||P.enumerable}));return IU.set(f,U),U};var gH=(f,U)=>{for(var P in U)Vf(f,P,{get:U[P],enumerable:!0,configurable:!0,set:(H)=>U[P]=()=>H})};var SP={};gH(SP,{useWebApp:()=>bf,usePieMittAgentTools:()=>MH,usePieEmit:()=>wU,useOpenAIWebRTC:()=>Cf,useMaxWebApp:()=>pf,useAjaxSubmit:()=>KH,unregisterComponent:()=>MU,submitGlobalForm:()=>oH,registry:()=>g,registerPieComponent:()=>W,registerMultipleComponents:()=>FU,readAjaxKey:()=>zU,pieName:()=>yH,hasComponent:()=>LU,getRegistrySize:()=>oU,getRegistryEntry:()=>s,getMittAgentTools:()=>TU,getComponentMeta:()=>AU,getAllRegisteredComponents:()=>NU,cn:()=>NH,UnionCard:()=>bU,UIRendererContext:()=>o,UILoading:()=>Sf,UI:()=>w,SessionStorageCard:()=>eU,SequenceCard:()=>xU,SecureStorageCard:()=>ZH,PieTelegramRoot:()=>WH,PieRoot:()=>qH,PieMaxRoot:()=>_H,PieCard:()=>_,PieBaseRoot:()=>QH,PIEBREAK:()=>Rf,OneOfCard:()=>JH,IOEventsCard:()=>sU,HiddenCard:()=>lU,HTMLEmbedCard:()=>cU,DeviceStorageCard:()=>UH,CloudStorageCard:()=>PH,BoxCard:()=>VH,AutoRedirectCard:()=>iU,AjaxGroupCard:()=>zH});module.exports=bH(SP);var d=require("react");var Wf=require("react"),u=Wf.createContext(null),i=()=>{let f=Wf.useContext(u);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},b=()=>{let{apiServer:f}=i();return f},Qf=b,v=()=>{let{centrifugeServer:f}=i();return f};var m=()=>{let{enableRenderingLog:f}=i();return f},OU=m,XU=()=>{let{pageProcessor:f}=i();return f};var Rf="__piedemo__";var qU=require("react"),rf=require("centrifuge"),GU=new Map,p=(f,U)=>{if(!U)return null;let P=`${f}::${U}`,H=GU.get(P);if(H)return H;async function D(){let Z=await fetch(f+"api/centrifuge/gen_token");if(!Z.ok){if(Z.status===403)throw new rf.Centrifuge.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${Z.status}`)}return(await Z.json()).token}let z=new rf.Centrifuge(U,{getToken:D});return GU.set(P,z),z},vH=qU.createContext(null),k=vH;var WU=require("socket.io-client"),QU=require("react"),BU=new Map,c=(f)=>{let U=BU.get(f);if(U)return U;let P=WU.io(f,{autoConnect:!1,transports:["websocket"]});return BU.set(f,P),P},pH=QU.createContext(null),j=pH;var RU=YU(require("mitt")),t=require("react"),nf=null;function x(){if(!nf)nf=RU.default();return nf}var _U=t.createContext(null);function wU(f){let U=t.useContext(_U);return t.useCallback((P,H)=>{(U??x()).emit(`pie${P}_${f}`,H)},[f,U])}var N=_U;var cH=({card:f,data:U,children:P,useSocketioSupport:H=!1,useCentrifugeSupport:D=!1,useMittSupport:z=!1,centrifugeChannel:Z=void 0,methods:T=void 0})=>{let $=OU(),V=d.useRef(T);if(V.current=T,$)console.log("[PieCard] Rendering card:",f),console.log("[PieCard] Card data:",U),console.log("[PieCard] Component name:",U?.name),console.log("[PieCard] Real-time support:",{socketio:H,centrifuge:D,mitt:z,centrifugeChannel:Z}),console.log("[PieCard] Methods:",T?Object.keys(T):"none"),console.log("[PieCard] Has children:",!!P);let O=d.useContext(j),X=d.useContext(k),G=d.useContext(N);if(d.useEffect(()=>{if(!O||!H||!V.current||!U.name){if($&&H)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!O,useSocketioSupport:H,hasMethods:!!V.current,hasDataName:!!U?.name});return}let I=Object.keys(V.current??{}).map((Y)=>{let C=`pie${Y}_${U.name}`;if($)console.log(`[PieCard] Socket.IO registering event: ${C}`);let q=(B)=>{V.current?.[Y]?.(B)};return O.on(C,q),[C,q]});return()=>{I.forEach(([Y,C])=>{if($)console.log(`[PieCard] Socket.IO unregistering event: ${Y}`);O.off(Y,C)})}},[O,U.name,H]),d.useEffect(()=>{if(!X||!D||!Z||!U.name){if($&&D)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!X,useCentrifugeSupport:D,hasCentrifugeChannel:!!Z,hasMethods:!!V.current,hasDataName:!!U?.name});return}let I=Object.keys(V.current??{}).map((Y)=>{let C=`pie${Y}_${U.name}_${Z}`;if($)console.log(`[PieCard] Centrifuge subscribing to channel: ${C}`);let q=X.newSubscription(C);return q.on("publication",(B)=>{if($)console.log(`[PieCard] Centrifuge received data on ${C}:`,B.data);V.current?.[Y]?.(B.data)}),q.subscribe(),q});return()=>{I.forEach((Y)=>{if($)console.log("[PieCard] Centrifuge unsubscribing from channel");Y.unsubscribe(),X.removeSubscription(Y)})}},[X,Z,U.name,D]),d.useEffect(()=>{if(!G||!z||!U.name){if($&&z)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!G,useMittSupport:z,hasMethods:!!V.current,hasDataName:!!U?.name});return}let J=Object.keys(V.current??{}),I={};return J.forEach((Y)=>{let C=`pie${Y}_${U.name}`,q=(B)=>{if($)console.log(`[PieCard] Mitt registering event: ${C}`);V.current?.[Y]?.(B)};I[C]=q,G.on(C,q)}),()=>{Object.entries(I).forEach(([Y,C])=>{if($)console.log(`[PieCard] Mitt unregistering event: ${Y}`);G.off(Y,C)})}},[G,U.name,z]),$)console.log("[PieCard] Rendering complete, returning children");return P},_=cH;var KU=require("react"),tf=new Map;function SU(f,U){return KU.lazy(()=>{if(tf.has(U))return tf.get(U);let P=f().then((H)=>H);return tf.set(U,P),P})}var g=new Map,hH=(f)=>{if(!f.name)throw new Error("Component registration requires a name");if(!f.component&&!f.loader)throw new Error(`Component "${f.name}" requires component or loader`);let U={name:f.name,component:f.component,loader:f.loader,metadata:f.metadata,fallback:f.fallback,isLazy:!1};if(!U.component&&U.loader)U.component=SU(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function W(f){let U=hH(f);return g.set(U.name,U),U.component}var FU=(f)=>{f.forEach((U)=>W(U))},MU=(f)=>{g.delete(f)},LU=(f)=>{return g.has(f)},AU=(f)=>{return g.get(f)?.metadata},s=(f)=>{return g.get(f)},NU=()=>{return Array.from(g.keys())},oU=()=>{return g.size};var a=require("react");var yU=require("react"),_f=require("react/jsx-runtime"),lH=yU.createContext(_f.jsx(_f.Fragment,{})),M=lH;var wf=require("react/jsx-runtime");function rH({uiConfig:f,setUiAjaxConfiguration:U}){let P=a.useContext(M),H=m();if(H)console.log("[UI] Rendering component:",f.card),console.log("[UI] Component data:",f.data),console.log("[UI] Component content:",f.content),console.log("[UI] Has setUiAjaxConfiguration:",!!U);let D=s(f.card);if(!D?.component){if(H)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return P}if(H)console.log("[UI] Found component in registry:",{name:D.name,isLazy:D.isLazy,hasMetadata:!!D.metadata});let z=D.component,Z=wf.jsx(z,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(D.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",D.name);return wf.jsx(a.Suspense,{fallback:D.fallback?wf.jsx(D.fallback,{}):P,children:Z},`${D.name}`)}if(H)console.log("[UI] Rendering component directly:",D.name);return Z}var w=a.memo(rH);var Kf=require("react");var mU=require("react"),nH=mU.createContext(null),o=nH;var If=require("react/jsx-runtime");function EU({uiConfig:f,setUiAjaxConfiguration:U}){let P=Kf.useContext(M),H=m();if(H)console.log("[UILoading] Rendering fallback for:",f.card),console.log("[UILoading] Component data:",f.data),console.log("[UILoading] Component content:",f.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!U);let D=s(f.card);if(!D?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return P}if(H)console.log("[UILoading] Found component in registry:",{name:D.name,isLazy:D.isLazy,hasMetadata:!!D.metadata,hasFallback:!!D.fallback});if(D.fallback){if(H)console.log("[UILoading] Rendering fallback for:",D.name);let T=D.fallback;return If.jsx(T,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",D.name);let z=D.component,Z=If.jsx(o.Provider,{value:EU,children:If.jsx(z,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(D.isLazy)return If.jsx(Kf.Suspense,{fallback:P,children:Z},`${D.name}`);return Z}var Sf=EU;var kU=require("react");var Ff=require("react/jsx-runtime"),iH=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,sx:D}=f,z=kU.useContext(o)??w;return Ff.jsx(_,{card:H,data:f,children:Ff.jsx("div",{style:D,id:H,children:U.map((Z,T)=>{return Ff.jsx(z,{uiConfig:Z,setUiAjaxConfiguration:P},`children-${T}`)})})})},jU=iH;var xU=W({name:"SequenceCard",component:jU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var dU=require("react");var sf=require("react/jsx-runtime"),tH=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H}=f,D=dU.useContext(o)??w;return sf.jsx(_,{card:H,data:f,children:U.map((z,Z)=>{return sf.jsx(D,{uiConfig:z,setUiAjaxConfiguration:P},`children-${Z}`)})})},uU=tH;var bU=W({name:"UnionCard",component:uU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var Mf=require("react"),gU=YU(require("html-react-parser"));var E=require("react");function sH(){let f=new AudioContext,U=f.createOscillator(),P=U.connect(f.createMediaStreamDestination());U.start();let H=P.stream.getAudioTracks()[0];return H.enabled=!1,H}function Cf(f=null,U){let[P,H]=E.useState(!1),D=E.useRef(null),z=E.useRef(null),Z=E.useRef(null),T=E.useCallback(async(X,G=!0)=>{if(D.current)$();let J=new RTCPeerConnection;if(J.onconnectionstatechange=()=>{if(J.connectionState==="connected")H(!0);else if(["disconnected","failed","closed"].includes(J.connectionState))H(!1)},J.ontrack=(R)=>{if(f)f.srcObject=R.streams[0]},G){let R=await navigator.mediaDevices.getUserMedia({audio:!0});J.addTrack(R.getTracks()[0],R)}else{let R=sH();J.addTrack(R)}let I=J.createDataChannel("oai-events");z.current=I,Z.current=new Promise((R)=>{I.addEventListener("open",()=>{R()})});let Y=await J.createOffer();await J.setLocalDescription(Y);let Q=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:Y.sdp,headers:{Authorization:`Bearer ${X}`,"Content-Type":"application/sdp"}})).text();await J.setRemoteDescription({type:"answer",sdp:Q}),D.current=J,await Z.current},[f]),$=E.useCallback(()=>{let X=z.current;if(X)X.close();D.current?.getSenders()?.forEach((G)=>G.track?.stop()),D.current?.close(),H(!1),D.current=null,z.current=null,Z.current=null},[f]),V=E.useCallback((X)=>{let G=z.current;if(!G){console.error("Data channel is not ready",X);return}let J=new Date().toLocaleTimeString();if(X.event_id=X.event_id||crypto.randomUUID(),G.send(JSON.stringify(X)),!X.timestamp)X.timestamp=J;U?.(X)},[U,f]),O=E.useCallback((X)=>{if(!z.current){console.error("Data channel is not ready");return}let J=()=>{V({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:X}]}}),V({type:"response.create"})};if(Z.current)Z.current.then(J);else J()},[U,f]);return E.useEffect(()=>{let X=z.current;if(!X)return;let G=(J)=>{let I=JSON.parse(J.data);if(!I.timestamp)I.timestamp=new Date().toLocaleTimeString();U?.(I)};return X.addEventListener("message",G),()=>{X.removeEventListener("message",G)}},[U,f]),{isSessionActive:P,startSession:T,stopSession:$,sendTextMessage:O}}var pU=require("react/jsx-runtime"),aH=({data:f})=>{let{html:U,useSocketioSupport:P,useCentrifugeSupport:H,useMittSupport:D,centrifugeChannel:z}=f,[Z,T]=Mf.useState(U),{isSessionActive:$,startSession:V,sendTextMessage:O}=Cf(null,(I)=>{if(console.log(I.type,I.type==="response.output_text.delta"&&I.delta),I.type==="response.output_text.delta"&&I.delta)T((Y)=>Y+I.delta)});return Mf.useEffect(()=>{T(U)},[U]),pU.jsx(_,{card:"HTMLEmbedCard",data:f,methods:{update:(I)=>{T(I.value)},generateUsingAI:async(I)=>{try{if(!$&&I.token)await V(I.token,!1);O(I.prompt)}catch(Y){console.error("Failed to generate using AI",Y)}},initializeAI:async(I)=>{if(!$&&I.token)await V(I.token,!1)}},useCentrifugeSupport:H,useSocketioSupport:P,useMittSupport:D,centrifugeChannel:z,children:gU.default(Z)})},vU=aH;var cU=W({name:"HTMLEmbedCard",component:vU,metadata:{author:"Swarm.ing"}});var Lf=require("react");var af=require("react/jsx-runtime"),eH=({data:f})=>{let{name:U,value:P,useSocketioSupport:H,useCentrifugeSupport:D,useMittSupport:z,centrifugeChannel:Z}=f,[T,$]=Lf.useState(P);return Lf.useEffect(()=>{$(P)},[P]),af.jsx(_,{card:"HiddenCard",data:f,useSocketioSupport:H,useCentrifugeSupport:D,useMittSupport:z,centrifugeChannel:Z,methods:{update:({value:V})=>{$(V)}},children:af.jsx("input",{type:"hidden",id:U,name:U,value:T})})},hU=eH;var lU=W({name:"HiddenCard",component:hU,metadata:{author:"Swarm.ing"}});var Jf=require("react");var rU=require("react"),fP=rU.createContext(void 0),y=fP;var Af=require("react/jsx-runtime"),UP=({data:f})=>{let{url:U}=f,P=Jf.useContext(y),H=Jf.useContext(M);return Jf.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else P?.(U)},[U,P]),Af.jsx(Af.Fragment,{children:H})},nU=UP;var iU=W({name:"AutoRedirectCard",component:nU,metadata:{author:"Swarm.ing"}});var h=require("react-toastify"),Nf=require("react-toastify");var ff=require("react");var e=require("react/jsx-runtime"),HP={bounce:h.Bounce,slide:h.Slide,zoom:h.Zoom,flip:h.Flip},PP=(f)=>{let U={...f,type:f.alertType,transition:f.transition?HP[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};Nf.toast(f.message,U)},DP=(f)=>{console.log("Log event",f)},ZP=(f)=>{if(typeof window==="undefined"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let U=()=>{try{new window.Notification(f.title,{body:f.message??f.subtitle,icon:f.icon,silent:f.silent})}catch(H){console.error("[IOEventsCard] Failed to show notification",H)}},P=window.Notification.permission;if(P==="granted"){U();return}if(P==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((H)=>{if(H==="granted")U()})},$P=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:P,useMittSupport:H,centrifugeChannel:D}=f,z=ff.useContext(y),Z=ff.useRef(z);Z.current=z;let T=ff.useMemo(()=>({alert:PP,log:DP,push:ZP,redirect:($)=>{if($.to){let V=$.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(V))window.location.href=V;else Z.current?.(V)}else window.location.reload()},reload:($)=>{if($.to){let V=$.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(V))window.location.href=V;else Z.current?.(V)}else window.location.reload()}}),[]);return e.jsx(e.Fragment,{children:e.jsx(_,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:P,useMittSupport:H,centrifugeChannel:D,methods:T,children:e.jsx(Nf.ToastContainer,{})})})},tU=$P;var sU=W({name:"IOEventsCard",component:tU,metadata:{author:"Swarm.ing"}});var Yf=require("react");var ef=require("react/jsx-runtime"),zP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T}=f,[$,V]=Yf.useState(H);return Yf.useEffect(()=>{V(H)},[H]),Yf.useEffect(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(P,$)},[P,$]),ef.jsx(_,{card:"SessionStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T,methods:{update:({value:O})=>{V(O)},remove:()=>{sessionStorage.removeItem(P),V("")}},children:ef.jsx("input",{type:"hidden",id:U,name:U,value:$})})},aU=zP;var eU=W({name:"SessionStorageCard",component:aU,metadata:{author:"PieData"}});var Of=require("react");var fU=require("react/jsx-runtime"),TP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T}=f,[$,V]=Of.useState(H);return Of.useEffect(()=>{V(H)},[H]),Of.useEffect(()=>{if(typeof window==="undefined")return;localStorage.setItem(P,$)},[P,$]),fU.jsx(_,{card:"DeviceStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T,methods:{update:({value:O})=>{V(O)},remove:()=>{localStorage.removeItem(P),V("")}},children:fU.jsx("input",{type:"hidden",id:U,name:U,value:$})})},fH=TP;var UH=W({name:"DeviceStorageCard",component:fH,metadata:{author:"PieData"}});var Xf=require("react");var UU=require("react/jsx-runtime"),VP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T}=f,[$,V]=Xf.useState(H);return Xf.useEffect(()=>{V(H)},[H]),Xf.useEffect(()=>{if(typeof window==="undefined")return;let O=window.Telegram?.WebApp?.CloudStorage;if(!O)return;O.setItem(P,$)},[P,$]),UU.jsx(_,{card:"CloudStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T,methods:{update:({value:O})=>{V(O)},remove:()=>{let O=window.Telegram?.WebApp?.CloudStorage;if(O)O.removeItem(P);V("")}},children:UU.jsx("input",{type:"hidden",id:U,name:U,value:$})})},HH=VP;var PH=W({name:"CloudStorageCard",component:HH,metadata:{author:"PieData"}});var Gf=require("react");var HU=require("react/jsx-runtime"),IP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T}=f,[$,V]=Gf.useState(H);return Gf.useEffect(()=>{V(H)},[H]),Gf.useEffect(()=>{if(typeof window==="undefined")return;let O=window.Telegram?.WebApp?.SecureStorage;if(!O)return;O.setItem(P,$)},[P,$]),HU.jsx(_,{card:"SecureStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:T,methods:{update:({value:O})=>{V(O)},remove:()=>{let O=window.Telegram?.WebApp?.SecureStorage;if(O)O.removeItem(P);V("")}},children:HU.jsx("input",{type:"hidden",id:U,name:U,value:$})})},DH=IP;var ZH=W({name:"SecureStorageCard",component:DH,metadata:{author:"PieData"}});var L=require("react");var PU=require("react/jsx-runtime"),CP=({data:f,content:U})=>{let{useLoader:P,noReturn:H,returnType:D,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:T,centrifugeChannel:$}=f,V=L.useContext(M),O=L.useContext(o)??w,[X,G]=L.useState(!1),[J,I]=L.useState(null),Y=L.useRef(U),C=L.useContext(N),q=L.useCallback((R)=>{if(R===null)G(!0);else if(G(!1),!H)Y.current=R;if(!H)I(R)},[H]),B=L.useCallback((R)=>{Y.current=R.content,I(R.content)},[]),Q=L.useCallback((R)=>{if(R===null)G(!0);else if(G(!1),!H)for(let qf of R)C?.emit(qf.name,qf.data)},[H,C]);if(L.useEffect(()=>{I(U),G(!1)},[U]),!J&&P)return V;return PU.jsx(_,{card:"AjaxGroupCard",data:f,methods:{changeContent:B},useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:T,centrifugeChannel:$,children:PU.jsx(O,{uiConfig:J??Y.current,setUiAjaxConfiguration:D==="events"?Q:q})})},$H=CP;var zH=W({name:"AjaxGroupCard",component:$H,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var DU=require("react");var of=require("react/jsx-runtime"),JP=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,url:D,sx:z}=f,Z=DU.useContext(y),T=DU.useContext(o)??w;return of.jsx(_,{card:H,data:f,children:of.jsx("div",{style:z,id:H,onClick:(V)=>{if(D)if(V.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(D))window.location.href=D;else Z?.(D)},children:of.jsx(T,{setUiAjaxConfiguration:P,uiConfig:U})})})},TH=JP;var VH=W({name:"BoxCard",component:TH,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var IH=require("react");var yf=require("react/jsx-runtime"),YP=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,sx:D}=f,z=IH.useContext(o)??w;return yf.jsx(_,{card:H,data:f,children:yf.jsx("div",{style:D,id:H,children:U.map((Z,T)=>{return yf.jsx(z,{uiConfig:Z,setUiAjaxConfiguration:P},`children-${T}`)})})})},CH=YP;var JH=W({name:"OneOfCard",component:CH,metadata:{author:"Swarm.ing",description:"Different variants"}});var Hf=require("react"),Pf=require("@tanstack/react-query");var xf=require("react");var kf=require("react"),mf=new Map,Ef=new Map;function jf(f,U){let P=`${f}::${U}`,H=f?mf.get(P):void 0,[D,z]=kf.useState(H??null);return kf.useEffect(()=>{if(!f)return;if(mf.has(P)){z(mf.get(P));return}let Z=Ef.get(P);if(!Z)Z=fetch(f+`api/support/${U}`,{method:"GET"}).then(($)=>$.json()).then(($)=>{return mf.set(P,$),Ef.delete(P),$}).catch(($)=>{throw Ef.delete(P),$}),Ef.set(P,Z);let T=!1;return Z.then(($)=>{if(!T)z($)}).catch(()=>{}),()=>{T=!0}},[f,U,P]),D}var ZU=null,YH=null;function OH(){YH?.()}function $U(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!ZU)ZU=new Promise((f)=>{YH=()=>{f()}});return ZU}var OP=({children:f})=>{let U=xf.useContext(j),P=Qf(),H=jf(P,"socketIO"),D=(z)=>{if(typeof window!=="undefined")window.sid=z.sid,OH(),console.log(`SocketIO initialized: ${window.sid}`)};return xf.useEffect(()=>{if(!U)return;let z=()=>{console.log("SocketIO connected")},Z=(T)=>{console.log(`SocketIO disconnected: ${T}`),U.connect()};if(H)U.on("pieinit",D),U.on("connect",z),U.on("disconnect",Z),U.connect();return()=>{if(H)U.off("pieinit",D),U.off("connect",z),U.off("disconnect",Z),U.disconnect()}},[U,H]),f},l=OP;var df=require("react");var XP=({children:f})=>{let U=df.useContext(k),P=Qf(),H=jf(P,"centrifuge");return df.useEffect(()=>{if(!U)return;let D=()=>{console.log("Centrifuge connected")},z=(Z)=>{console.log("Centrifuge disconnected:",Z)};if(H)U.on("connected",D),U.on("disconnected",z),U.connect();return()=>{if(H)U.disconnect()}},[U,H]),f},r=XP;var GH=require("axios-date-transformer");var XH=require("react/jsx-runtime");function Uf(f,U,P){if(!U)return P;let H=f.replace(/^\//,""),D=U[H];if(!D)return P;return XH.jsx(Sf,{uiConfig:D})}var K=require("react/jsx-runtime"),GP=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:z})=>{let Z=b(),T=v(),$=m(),V=Hf.useMemo(()=>GH.createAxiosDateTransformer({baseURL:Z||""}),[Z]),O=Hf.useMemo(()=>x(),[]),X=Hf.useMemo(()=>Z?c(Z):null,[Z]),G=Hf.useMemo(()=>Z?p(Z,T):null,[Z,T]),{data:J,isLoading:I,error:Y}=Pf.useQuery({queryKey:["uiConfig",f.pathname+f.search,Z],enabled:!!Z,queryFn:async()=>{let q=new URLSearchParams(f.search);q.set("__pieroot","web");let B="/api/content"+f.pathname+"?"+q.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",B);let Q=await V.get(B,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if($)console.log("[PieRoot] Received UI configuration:",Q.data);return Q.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(q)=>Math.min(1000*2**q,30000),...D}),C=Uf(f.pathname,P,U);if(!Z)return C??null;if($)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",Z),console.log("[PieRoot] CENTRIFUGE_SERVER:",T),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!P);if(Y){if($)console.error("[PieRoot] Error fetching UI configuration:",Y),console.error("[PieRoot] Error details:",{message:Y.message,status:Y.response?.status,data:Y.response?.data});return H?.(),C}if(I||!J){if($)console.log("[PieRoot] Loading state:",{isLoading:I,hasUiConfiguration:!!J});return C}if($)console.log("[PieRoot] UI configuration loaded successfully:",J),console.log("[PieRoot] Rendering UI with configuration");return K.jsx(N.Provider,{value:O,children:K.jsx(j.Provider,{value:X,children:K.jsx(k.Provider,{value:G,children:K.jsx(M.Provider,{value:U??K.jsx(K.Fragment,{}),children:K.jsx(l,{children:K.jsx(r,{children:z?K.jsx(w,{uiConfig:J}):K.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:K.jsx(w,{uiConfig:J})})})})})})})})},qP=(f)=>{let U=Hf.useMemo(()=>new Pf.QueryClient,[]);return K.jsx(y.Provider,{value:f.onNavigate,children:K.jsx(u.Provider,{value:f.config,children:K.jsx(Pf.QueryClientProvider,{client:U,children:K.jsx(GP,{...f})})})})},qH=qP;var Df=require("react"),Zf=require("@tanstack/react-query");var BH=require("axios-date-transformer");var uf=require("react");var bf=({onError:f}={})=>{let[U,P]=uf.useState(null),H=XU();return uf.useEffect(()=>{if(typeof window==="undefined")return;let D=window.Telegram?.WebApp;if(!D)return;try{D.ready?.()}catch(z){f?.()}if(H==="telegram_expanded"&&(D.platform==="ios"||D.platform==="android"))D.expand();P(D)},[]),U};var S=require("react/jsx-runtime"),BP=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:z})=>{let Z=b(),T=v(),$=m(),V=Df.useMemo(()=>BH.createAxiosDateTransformer({baseURL:Z}),[Z]),O=Df.useMemo(()=>x(),[]),X=Df.useMemo(()=>Z?c(Z):null,[Z]),G=Df.useMemo(()=>Z?p(Z,T):null,[Z,T]),J=bf({onError:H}),{data:I,isLoading:Y,error:C}=Zf.useQuery({queryKey:["uiConfig",f.pathname+f.search,J?.initData],enabled:!!J?.initData,queryFn:async()=>{let B=new URLSearchParams(f.search);if(B.set("__pieroot","telegram"),J?.initData)B.set("initData",J.initData);let Q="/api/content"+f.pathname+"?"+B.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",Q);let R=await V.get(Q,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if($)console.log("[PieRoot] Received UI configuration:",R.data);return R.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(B)=>Math.min(1000*2**B,30000),...D}),q=Uf(f.pathname,P,U);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(C&&$)return console.error("[PieRoot] Error fetching UI configuration:",C),console.error("[PieRoot] Error details:",{message:C.message,status:C.response?.status,data:C.response?.data}),H?.(),q;if(Y||!I){if($)console.log("[PieRoot] Loading state:",{isLoading:Y,hasUiConfiguration:!!I});return q}if($)console.log("[PieRoot] UI configuration loaded successfully:",I),console.log("[PieRoot] Rendering UI with configuration");return S.jsx(N.Provider,{value:O,children:S.jsx(j.Provider,{value:X,children:S.jsx(k.Provider,{value:G,children:S.jsx(M.Provider,{value:U??S.jsx(S.Fragment,{}),children:S.jsx(l,{children:S.jsx(r,{children:z?S.jsx(w,{uiConfig:I}):S.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:S.jsx(w,{uiConfig:I})})})})})})})})},WP=(f)=>{let U=Df.useMemo(()=>new Zf.QueryClient,[]);return S.jsx(y.Provider,{value:f.onNavigate,children:S.jsx(u.Provider,{value:f.config,children:S.jsx(Zf.QueryClientProvider,{client:U,children:S.jsx(BP,{...f})})})})},WH=WP;var $f=require("react"),gf=require("@tanstack/react-query");var A=require("react/jsx-runtime"),QP=({location:f,fallback:U,children:P,disableGlobalForm:H})=>{let D=b(),z=v(),Z=m(),T=$f.useMemo(()=>x(),[]),$=$f.useMemo(()=>D?c(D):null,[D]),V=$f.useMemo(()=>D?p(D,z):null,[D,z]);if(Z)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",D),console.log("[PieRoot] CENTRIFUGE_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!U);return A.jsx(N.Provider,{value:T,children:A.jsx(j.Provider,{value:$,children:A.jsx(k.Provider,{value:V,children:A.jsx(M.Provider,{value:U??A.jsx(A.Fragment,{}),children:A.jsx(l,{children:A.jsx(r,{children:H?P:A.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:P})})})})})})})},RP=(f)=>{let[U]=$f.useState(()=>new gf.QueryClient);return A.jsx(y.Provider,{value:f.onNavigate,children:A.jsx(u.Provider,{value:f.config,children:A.jsx(gf.QueryClientProvider,{client:U,children:A.jsx(QP,{...f})})})})},QH=RP;var zf=require("react"),Tf=require("@tanstack/react-query");var RH=require("axios-date-transformer");var vf=require("react"),pf=()=>{let[f,U]=vf.useState(null);return vf.useEffect(()=>{if(typeof window==="undefined")return;let P=window.WebApp;if(!P)return;P.ready(),U(P)},[]),f};var F=require("react/jsx-runtime"),_P=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:z})=>{let Z=b(),T=v(),$=m(),V=zf.useMemo(()=>RH.createAxiosDateTransformer({baseURL:Z}),[Z]),O=zf.useMemo(()=>x(),[]),X=zf.useMemo(()=>Z?c(Z):null,[Z]),G=zf.useMemo(()=>Z?p(Z,T):null,[Z,T]),J=pf(),{data:I,isLoading:Y,error:C}=Tf.useQuery({queryKey:["uiConfig",f.pathname+f.search,J?.initData],queryFn:async()=>{let B=new URLSearchParams(f.search);if(B.set("__pieroot","max"),J?.initData)B.set("initData",J.initData);let Q="/api/content"+f.pathname+"?"+B.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",Q);let R=await V.get(Q,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if($)console.log("[PieRoot] Received UI configuration:",R.data);return R.data},enabled:!!J?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(B)=>Math.min(1000*2**B,30000),...D}),q=Uf(f.pathname,P,U);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(C&&$)return console.error("[PieRoot] Error fetching UI configuration:",C),console.error("[PieRoot] Error details:",{message:C.message,status:C.response?.status,data:C.response?.data}),H?.(),q;if(Y||!I){if($)console.log("[PieRoot] Loading state:",{isLoading:Y,hasUiConfiguration:!!I});return q}if($)console.log("[PieRoot] UI configuration loaded successfully:",I),console.log("[PieRoot] Rendering UI with configuration");return F.jsx(N.Provider,{value:O,children:F.jsx(j.Provider,{value:X,children:F.jsx(k.Provider,{value:G,children:F.jsx(M.Provider,{value:U??F.jsx(F.Fragment,{}),children:F.jsx(l,{children:F.jsx(r,{children:z?F.jsx(w,{uiConfig:I}):F.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:F.jsx(w,{uiConfig:I})})})})})})})})},wP=(f)=>{let U=zf.useMemo(()=>new Tf.QueryClient,[]);return F.jsx(y.Provider,{value:f.onNavigate,children:F.jsx(u.Provider,{value:f.config,children:F.jsx(Tf.QueryClientProvider,{client:U,children:F.jsx(_P,{...f})})})})},_H=wP;var wH=require("react"),zU=(f,U=!1)=>{if(f==="sid"){if(!window.sid)throw new Error("SocketIO isn't initialized properly");return[window.sid]}let P=document.getElementsByName(f);if(!P.length){if(U)console.warn(`No input found with name ${f}`);return[]}let H=P[0];if(H instanceof HTMLInputElement){if(H.type==="file"&&H.files)return Array.from(H.files);return[H.value]}if(H instanceof HTMLTextAreaElement)return[H.value];return[]},KP=(f,U={},P=[],H,D)=>{let z=D?.renderingLogEnabled??!1,Z=D?.timeout,T=D?.retryPolicy,$=T?.maxRetries??0,V=T?.baseDelay??1000,O=T?.retryOn??[502,503,504];if(z)console.log("Registering AJAX: ",H,U,P);return async(X={})=>{if(typeof window==="undefined"||typeof document==="undefined"){if(z)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let G=D?.apiServer;if(!G){if(z)console.warn("AJAX skipped: apiServer is missing");return}if(!H||!f){if(z)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(P.includes("sid"))await $U();let J=new FormData;for(let[C,q]of Object.entries({...U,...X}))J.append(C,q);for(let C of P)for(let q of zU(C,z))J.append(C,q);let I=G+"api/ajax_content"+H;f(null);let Y;for(let C=0;C<=$;C++){if(C>0){let Q=V*2**(C-1);if(z)console.log(`AJAX retry ${C}/${$} after ${Q}ms`);await new Promise((R)=>setTimeout(R,Q))}let q=Z!=null?new AbortController:null,B=q&&setTimeout(()=>q.abort(),Z);try{let Q=await fetch(I,{method:"POST",body:J,signal:q?.signal});if(B)clearTimeout(B);if(!Q.ok&&O.includes(Q.status)&&C<$){Y=new Error(`HTTP ${Q.status}`);continue}let qf=(Q.headers.get("content-type")||"").includes("application/json");if(!!Q.body?.getReader&&!qf){let Bf=Q.body.getReader(),mH=new TextDecoder,n="";while(!0){let{done:hf,value:EH}=await Bf.read();if(hf)break;n+=mH.decode(EH,{stream:!0});let VU=n.split(`
3
- `);n=VU.pop()??"";for(let kH of VU){let lf=kH.trim();if(!lf)continue;try{let jH=JSON.parse(lf);f([jH])}catch{if(z)console.warn("Failed to parse streamed line:",lf)}}}if(n.trim())try{let hf=JSON.parse(n);f([hf])}catch{if(z)console.warn("Failed to parse final streamed line:",n)}return{}}else{let Bf=await Q.json();return f(Bf),Bf}}catch(Q){if(B)clearTimeout(B);if(Y=Q,C<$)continue;if(z)console.error("AJAX request failed:",Q);return f(null),Q}}if(z)console.error("AJAX request failed after retries:",Y);return f(null),Y}},KH=(f,U={},P=[],H,D)=>{let{apiServer:z,enableRenderingLog:Z}=i(),T=JSON.stringify(U),$=JSON.stringify(P),V=JSON.stringify(D);return wH.useMemo(()=>KP(f,U,P,H,{apiServer:z,renderingLogEnabled:Z,timeout:D?.timeout,retryPolicy:D?.retryPolicy}),[f,T,$,H,z,Z,V])};var SH=require("@openai/agents"),cf=require("react");var FH=/^pie(.+?)_(.+)$/;function TU(f=x(),U={}){let P=[],H=new Set;for(let D of f.all.keys()){if(typeof D!=="string")continue;let z=D.match(FH);if(!z)continue;let[,Z,T]=z,$={methodName:Z,cardName:T,eventName:D};if(U.filter&&!U.filter($))continue;let V=U.nameFor?.($)??`${T}_${Z}`;if(H.has(V))continue;H.add(V);let O=U.describe?.($)??`Invokes the "${Z}" method on the PieCard "${T}" by emitting the in-process mitt event "${D}". The optional "payload" argument is forwarded verbatim to the card's handler.`;P.push(SH.tool({name:V,description:O,strict:!1,parameters:{type:"object",properties:{payload:{description:"Arbitrary JSON payload forwarded to the PieCard method handler. Omit for fire-and-forget calls."}},required:[],additionalProperties:!0},execute:async(X)=>{let G=X?.payload;return f.emit(D,G),`Emitted "${D}"`}}))}return P}function MH(f={}){let P=cf.useContext(N)??x(),H=[];for(let $ of P.all.keys())if(typeof $==="string"&&FH.test($))H.push($);H.sort();let D=H.join("|"),{filter:z,describe:Z,nameFor:T}=f;return cf.useMemo(()=>TU(P,{filter:z,describe:Z,nameFor:T}),[P,D,z,Z,T])}var LH=require("clsx"),AH=require("tailwind-merge");function NH(...f){return AH.twMerge(LH.clsx(f))}var oH=()=>{if(typeof document==="undefined")return;let f=document.getElementById("piedata_global_form");f&&f.submit()};var yH=(f,U)=>`${f}${Rf}${U}`;
2
+ var uH=Object.create;var{getPrototypeOf:dH,defineProperty:If,getOwnPropertyNames:JU,getOwnPropertyDescriptor:bH}=Object,YU=Object.prototype.hasOwnProperty;var OU=(f,U,P)=>{P=f!=null?uH(dH(f)):{};let H=U||!f||!f.__esModule?If(P,"default",{value:f,enumerable:!0}):P;for(let D of JU(f))if(!YU.call(H,D))If(H,D,{get:()=>f[D],enumerable:!0});return H},CU=new WeakMap,gH=(f)=>{var U=CU.get(f),P;if(U)return U;if(U=If({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")JU(f).map((H)=>!YU.call(U,H)&&If(U,H,{get:()=>f[H],enumerable:!(P=bH(f,H))||P.enumerable}));return CU.set(f,U),U};var vH=(f,U)=>{for(var P in U)If(f,P,{get:U[P],enumerable:!0,configurable:!0,set:(H)=>U[P]=()=>H})};var FP={};vH(FP,{useWebApp:()=>gf,usePieMittAgentTools:()=>LH,usePieEmit:()=>KU,useOpenAIWebRTC:()=>Jf,useMaxWebApp:()=>cf,useAjaxSubmit:()=>SH,unregisterComponent:()=>LU,submitGlobalForm:()=>oH,registry:()=>g,registerPieComponent:()=>Q,registerMultipleComponents:()=>MU,readAjaxKey:()=>TU,pieName:()=>mH,hasComponent:()=>AU,getRegistrySize:()=>oU,getRegistryEntry:()=>a,getMittAgentTools:()=>VU,getComponentMeta:()=>NU,getAllRegisteredComponents:()=>yU,cn:()=>yH,UnionCard:()=>gU,UIRendererContext:()=>y,UILoading:()=>Ff,UI:()=>w,SessionStorageCard:()=>fH,SequenceCard:()=>uU,SecureStorageCard:()=>$H,PieTelegramRoot:()=>QH,PieRoot:()=>BH,PieMaxRoot:()=>wH,PieCard:()=>_,PieBaseRoot:()=>RH,PIEBREAK:()=>_f,OneOfCard:()=>YH,IOEventsCard:()=>aU,HiddenCard:()=>rU,HTMLEmbedCard:()=>hU,DeviceStorageCard:()=>HH,CloudStorageCard:()=>DH,BoxCard:()=>IH,AutoRedirectCard:()=>tU,AjaxGroupCard:()=>TH});module.exports=gH(FP);var u=require("react");var Qf=require("react"),d=Qf.createContext(null),i=()=>{let f=Qf.useContext(d);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},b=()=>{let{apiServer:f}=i();return f},Rf=b,v=()=>{let{centrifugeServer:f}=i();return f};var m=()=>{let{enableRenderingLog:f}=i();return f},XU=m,GU=()=>{let{pageProcessor:f}=i();return f};var _f="__piedemo__";var BU=require("react"),nf=require("centrifuge"),qU=new Map,p=(f,U)=>{if(!U)return null;let P=`${f}::${U}`,H=qU.get(P);if(H)return H;async function D(){let Z=await fetch(f+"api/centrifuge/gen_token");if(!Z.ok){if(Z.status===403)throw new nf.Centrifuge.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${Z.status}`)}return(await Z.json()).token}let $=new nf.Centrifuge(U,{getToken:D});return qU.set(P,$),$},pH=BU.createContext(null),k=pH;var QU=require("socket.io-client"),RU=require("react"),WU=new Map,c=(f)=>{let U=WU.get(f);if(U)return U;let P=QU.io(f,{autoConnect:!1,transports:["websocket"]});return WU.set(f,P),P},cH=RU.createContext(null),j=cH;var _U=OU(require("mitt")),t=require("react"),tf=null;function x(){if(!tf)tf=_U.default();return tf}var wU=t.createContext(null);function KU(f){let U=t.useContext(wU);return t.useCallback((P,H)=>{(U??x()).emit(`pie${P}_${f}`,H)},[f,U])}var N=wU;var s=require("react/jsx-runtime"),hH=({card:f,data:U,children:P,useSocketioSupport:H=!1,useCentrifugeSupport:D=!1,useMittSupport:$=!1,centrifugeChannel:Z=void 0,methods:V=void 0,stored:z=void 0})=>{let T=XU(),I=u.useRef(V);if(I.current=V,T)console.log("[PieCard] Rendering card:",f),console.log("[PieCard] Card data:",U),console.log("[PieCard] Component name:",U?.name),console.log("[PieCard] Real-time support:",{socketio:H,centrifuge:D,mitt:$,centrifugeChannel:Z}),console.log("[PieCard] Methods:",V?Object.keys(V):"none"),console.log("[PieCard] Has children:",!!P);let X=u.useContext(j),G=u.useContext(k),J=u.useContext(N);if(u.useEffect(()=>{if(!X||!H||!I.current||!U.name){if(T&&H)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!X,useSocketioSupport:H,hasMethods:!!I.current,hasDataName:!!U?.name});return}let q=Object.keys(I.current??{}).map((C)=>{let O=`pie${C}_${U.name}`;if(T)console.log(`[PieCard] Socket.IO registering event: ${O}`);let W=(B)=>{I.current?.[C]?.(B)};return X.on(O,W),[O,W]});return()=>{q.forEach(([C,O])=>{if(T)console.log(`[PieCard] Socket.IO unregistering event: ${C}`);X.off(C,O)})}},[X,U.name,H]),u.useEffect(()=>{if(!G||!D||!Z||!U.name){if(T&&D)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!G,useCentrifugeSupport:D,hasCentrifugeChannel:!!Z,hasMethods:!!I.current,hasDataName:!!U?.name});return}let q=Object.keys(I.current??{}).map((C)=>{let O=`pie${C}_${U.name}_${Z}`;if(T)console.log(`[PieCard] Centrifuge subscribing to channel: ${O}`);let W=G.newSubscription(O);return W.on("publication",(B)=>{if(T)console.log(`[PieCard] Centrifuge received data on ${O}:`,B.data);I.current?.[C]?.(B.data)}),W.subscribe(),W});return()=>{q.forEach((C)=>{if(T)console.log("[PieCard] Centrifuge unsubscribing from channel");C.unsubscribe(),G.removeSubscription(C)})}},[G,Z,U.name,D]),u.useEffect(()=>{if(!J||!$||!U.name){if(T&&$)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!J,useMittSupport:$,hasMethods:!!I.current,hasDataName:!!U?.name});return}let Y=Object.keys(I.current??{}),q={};return Y.forEach((C)=>{let O=`pie${C}_${U.name}`,W=(B)=>{if(T)console.log(`[PieCard] Mitt registering event: ${O}`);I.current?.[C]?.(B)};q[O]=W,J.on(O,W)}),()=>{Object.entries(q).forEach(([C,O])=>{if(T)console.log(`[PieCard] Mitt unregistering event: ${C}`);J.off(C,O)})}},[J,U.name,$]),T)console.log("[PieCard] Rendering complete, returning children");if(z!==void 0)return s.jsxs(s.Fragment,{children:[s.jsx("input",{type:"hidden",name:U.name,value:JSON.stringify(z)}),P]});return P},_=hH;var SU=require("react"),sf=new Map;function FU(f,U){return SU.lazy(()=>{if(sf.has(U))return sf.get(U);let P=f().then((H)=>H);return sf.set(U,P),P})}var g=new Map,lH=(f)=>{if(!f.name)throw new Error("Component registration requires a name");if(!f.component&&!f.loader)throw new Error(`Component "${f.name}" requires component or loader`);let U={name:f.name,component:f.component,loader:f.loader,metadata:f.metadata,fallback:f.fallback,isLazy:!1};if(!U.component&&U.loader)U.component=FU(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function Q(f){let U=lH(f);return g.set(U.name,U),U.component}var MU=(f)=>{f.forEach((U)=>Q(U))},LU=(f)=>{g.delete(f)},AU=(f)=>{return g.has(f)},NU=(f)=>{return g.get(f)?.metadata},a=(f)=>{return g.get(f)},yU=()=>{return Array.from(g.keys())},oU=()=>{return g.size};var e=require("react");var mU=require("react"),wf=require("react/jsx-runtime"),rH=mU.createContext(wf.jsx(wf.Fragment,{})),M=rH;var Kf=require("react/jsx-runtime");function nH({uiConfig:f,setUiAjaxConfiguration:U}){let P=e.useContext(M),H=m();if(H)console.log("[UI] Rendering component:",f.card),console.log("[UI] Component data:",f.data),console.log("[UI] Component content:",f.content),console.log("[UI] Has setUiAjaxConfiguration:",!!U);let D=a(f.card);if(!D?.component){if(H)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return P}if(H)console.log("[UI] Found component in registry:",{name:D.name,isLazy:D.isLazy,hasMetadata:!!D.metadata});let $=D.component,Z=Kf.jsx($,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(D.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",D.name);return Kf.jsx(e.Suspense,{fallback:D.fallback?Kf.jsx(D.fallback,{}):P,children:Z},`${D.name}`)}if(H)console.log("[UI] Rendering component directly:",D.name);return Z}var w=e.memo(nH);var Sf=require("react");var EU=require("react"),iH=EU.createContext(null),y=iH;var Cf=require("react/jsx-runtime");function kU({uiConfig:f,setUiAjaxConfiguration:U}){let P=Sf.useContext(M),H=m();if(H)console.log("[UILoading] Rendering fallback for:",f.card),console.log("[UILoading] Component data:",f.data),console.log("[UILoading] Component content:",f.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!U);let D=a(f.card);if(!D?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return P}if(H)console.log("[UILoading] Found component in registry:",{name:D.name,isLazy:D.isLazy,hasMetadata:!!D.metadata,hasFallback:!!D.fallback});if(D.fallback){if(H)console.log("[UILoading] Rendering fallback for:",D.name);let V=D.fallback;return Cf.jsx(V,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",D.name);let $=D.component,Z=Cf.jsx(y.Provider,{value:kU,children:Cf.jsx($,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(D.isLazy)return Cf.jsx(Sf.Suspense,{fallback:P,children:Z},`${D.name}`);return Z}var Ff=kU;var jU=require("react");var Mf=require("react/jsx-runtime"),tH=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,sx:D}=f,$=jU.useContext(y)??w;return Mf.jsx(_,{card:H,data:f,children:Mf.jsx("div",{style:D,id:H,children:U.map((Z,V)=>{return Mf.jsx($,{uiConfig:Z,setUiAjaxConfiguration:P},`children-${V}`)})})})},xU=tH;var uU=Q({name:"SequenceCard",component:xU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var dU=require("react");var af=require("react/jsx-runtime"),sH=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H}=f,D=dU.useContext(y)??w;return af.jsx(_,{card:H,data:f,children:U.map(($,Z)=>{return af.jsx(D,{uiConfig:$,setUiAjaxConfiguration:P},`children-${Z}`)})})},bU=sH;var gU=Q({name:"UnionCard",component:bU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var Lf=require("react"),vU=OU(require("html-react-parser"));var E=require("react");function aH(){let f=new AudioContext,U=f.createOscillator(),P=U.connect(f.createMediaStreamDestination());U.start();let H=P.stream.getAudioTracks()[0];return H.enabled=!1,H}function Jf(f=null,U){let[P,H]=E.useState(!1),D=E.useRef(null),$=E.useRef(null),Z=E.useRef(null),V=E.useCallback(async(X,G=!0)=>{if(D.current)z();let J=new RTCPeerConnection;if(J.onconnectionstatechange=()=>{if(J.connectionState==="connected")H(!0);else if(["disconnected","failed","closed"].includes(J.connectionState))H(!1)},J.ontrack=(R)=>{if(f)f.srcObject=R.streams[0]},G){let R=await navigator.mediaDevices.getUserMedia({audio:!0});J.addTrack(R.getTracks()[0],R)}else{let R=aH();J.addTrack(R)}let Y=J.createDataChannel("oai-events");$.current=Y,Z.current=new Promise((R)=>{Y.addEventListener("open",()=>{R()})});let q=await J.createOffer();await J.setLocalDescription(q);let B=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:q.sdp,headers:{Authorization:`Bearer ${X}`,"Content-Type":"application/sdp"}})).text();await J.setRemoteDescription({type:"answer",sdp:B}),D.current=J,await Z.current},[f]),z=E.useCallback(()=>{let X=$.current;if(X)X.close();D.current?.getSenders()?.forEach((G)=>G.track?.stop()),D.current?.close(),H(!1),D.current=null,$.current=null,Z.current=null},[f]),T=E.useCallback((X)=>{let G=$.current;if(!G){console.error("Data channel is not ready",X);return}let J=new Date().toLocaleTimeString();if(X.event_id=X.event_id||crypto.randomUUID(),G.send(JSON.stringify(X)),!X.timestamp)X.timestamp=J;U?.(X)},[U,f]),I=E.useCallback((X)=>{if(!$.current){console.error("Data channel is not ready");return}let J=()=>{T({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:X}]}}),T({type:"response.create"})};if(Z.current)Z.current.then(J);else J()},[U,f]);return E.useEffect(()=>{let X=$.current;if(!X)return;let G=(J)=>{let Y=JSON.parse(J.data);if(!Y.timestamp)Y.timestamp=new Date().toLocaleTimeString();U?.(Y)};return X.addEventListener("message",G),()=>{X.removeEventListener("message",G)}},[U,f]),{isSessionActive:P,startSession:V,stopSession:z,sendTextMessage:I}}var cU=require("react/jsx-runtime"),eH=({data:f})=>{let{html:U,useSocketioSupport:P,useCentrifugeSupport:H,useMittSupport:D,centrifugeChannel:$}=f,[Z,V]=Lf.useState(U),{isSessionActive:z,startSession:T,sendTextMessage:I}=Jf(null,(Y)=>{if(console.log(Y.type,Y.type==="response.output_text.delta"&&Y.delta),Y.type==="response.output_text.delta"&&Y.delta)V((q)=>q+Y.delta)});return Lf.useEffect(()=>{V(U)},[U]),cU.jsx(_,{card:"HTMLEmbedCard",data:f,methods:{update:(Y)=>{V(Y.value)},generateUsingAI:async(Y)=>{try{if(!z&&Y.token)await T(Y.token,!1);I(Y.prompt)}catch(q){console.error("Failed to generate using AI",q)}},initializeAI:async(Y)=>{if(!z&&Y.token)await T(Y.token,!1)}},useCentrifugeSupport:H,useSocketioSupport:P,useMittSupport:D,centrifugeChannel:$,children:vU.default(Z)})},pU=eH;var hU=Q({name:"HTMLEmbedCard",component:pU,metadata:{author:"Swarm.ing"}});var Af=require("react");var ef=require("react/jsx-runtime"),fP=({data:f})=>{let{name:U,value:P,useSocketioSupport:H,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:Z}=f,[V,z]=Af.useState(P);return Af.useEffect(()=>{z(P)},[P]),ef.jsx(_,{card:"HiddenCard",data:f,useSocketioSupport:H,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:Z,methods:{update:({value:T})=>{z(T)}},children:ef.jsx("input",{type:"hidden",id:U,name:U,value:V})})},lU=fP;var rU=Q({name:"HiddenCard",component:lU,metadata:{author:"Swarm.ing"}});var Yf=require("react");var nU=require("react"),UP=nU.createContext(void 0),o=UP;var Nf=require("react/jsx-runtime"),HP=({data:f})=>{let{url:U}=f,P=Yf.useContext(o),H=Yf.useContext(M);return Yf.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else P?.(U)},[U,P]),Nf.jsx(Nf.Fragment,{children:H})},iU=HP;var tU=Q({name:"AutoRedirectCard",component:iU,metadata:{author:"Swarm.ing"}});var h=require("react-toastify"),yf=require("react-toastify");var Uf=require("react");var ff=require("react/jsx-runtime"),PP={bounce:h.Bounce,slide:h.Slide,zoom:h.Zoom,flip:h.Flip},DP=(f)=>{let U={...f,type:f.alertType,transition:f.transition?PP[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};yf.toast(f.message,U)},ZP=(f)=>{console.log("Log event",f)},$P=(f)=>{if(typeof window==="undefined"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let U=()=>{try{new window.Notification(f.title,{body:f.message??f.subtitle,icon:f.icon,silent:f.silent})}catch(H){console.error("[IOEventsCard] Failed to show notification",H)}},P=window.Notification.permission;if(P==="granted"){U();return}if(P==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((H)=>{if(H==="granted")U()})},zP=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:P,useMittSupport:H,centrifugeChannel:D}=f,$=Uf.useContext(o),Z=Uf.useRef($);Z.current=$;let V=Uf.useMemo(()=>({alert:DP,log:ZP,push:$P,redirect:(z)=>{if(z.to){let T=z.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(T))window.location.href=T;else Z.current?.(T)}else window.location.reload()},reload:(z)=>{if(z.to){let T=z.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(T))window.location.href=T;else Z.current?.(T)}else window.location.reload()}}),[]);return ff.jsx(ff.Fragment,{children:ff.jsx(_,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:P,useMittSupport:H,centrifugeChannel:D,methods:V,children:ff.jsx(yf.ToastContainer,{})})})},sU=zP;var aU=Q({name:"IOEventsCard",component:sU,metadata:{author:"Swarm.ing"}});var Of=require("react");var fU=require("react/jsx-runtime"),TP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V}=f,[z,T]=Of.useState(H);return Of.useEffect(()=>{T(H)},[H]),Of.useEffect(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(P,z)},[P,z]),fU.jsx(_,{card:"SessionStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V,methods:{update:({value:I})=>{T(I)},remove:()=>{sessionStorage.removeItem(P),T("")}},children:fU.jsx("input",{type:"hidden",id:U,name:U,value:z})})},eU=TP;var fH=Q({name:"SessionStorageCard",component:eU,metadata:{author:"PieData"}});var Xf=require("react");var UU=require("react/jsx-runtime"),VP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V}=f,[z,T]=Xf.useState(H);return Xf.useEffect(()=>{T(H)},[H]),Xf.useEffect(()=>{if(typeof window==="undefined")return;localStorage.setItem(P,z)},[P,z]),UU.jsx(_,{card:"DeviceStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V,methods:{update:({value:I})=>{T(I)},remove:()=>{localStorage.removeItem(P),T("")}},children:UU.jsx("input",{type:"hidden",id:U,name:U,value:z})})},UH=VP;var HH=Q({name:"DeviceStorageCard",component:UH,metadata:{author:"PieData"}});var Gf=require("react");var HU=require("react/jsx-runtime"),IP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V}=f,[z,T]=Gf.useState(H);return Gf.useEffect(()=>{T(H)},[H]),Gf.useEffect(()=>{if(typeof window==="undefined")return;let I=window.Telegram?.WebApp?.CloudStorage;if(!I)return;I.setItem(P,z)},[P,z]),HU.jsx(_,{card:"CloudStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V,methods:{update:({value:I})=>{T(I)},remove:()=>{let I=window.Telegram?.WebApp?.CloudStorage;if(I)I.removeItem(P);T("")}},children:HU.jsx("input",{type:"hidden",id:U,name:U,value:z})})},PH=IP;var DH=Q({name:"CloudStorageCard",component:PH,metadata:{author:"PieData"}});var qf=require("react");var PU=require("react/jsx-runtime"),CP=({data:f})=>{let{name:U,key:P,value:H,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V}=f,[z,T]=qf.useState(H);return qf.useEffect(()=>{T(H)},[H]),qf.useEffect(()=>{if(typeof window==="undefined")return;let I=window.Telegram?.WebApp?.SecureStorage;if(!I)return;I.setItem(P,z)},[P,z]),PU.jsx(_,{card:"SecureStorageCard",data:f,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:Z,centrifugeChannel:V,methods:{update:({value:I})=>{T(I)},remove:()=>{let I=window.Telegram?.WebApp?.SecureStorage;if(I)I.removeItem(P);T("")}},children:PU.jsx("input",{type:"hidden",id:U,name:U,value:z})})},ZH=CP;var $H=Q({name:"SecureStorageCard",component:ZH,metadata:{author:"PieData"}});var L=require("react");var DU=require("react/jsx-runtime"),JP=({data:f,content:U})=>{let{useLoader:P,noReturn:H,returnType:D,useSocketioSupport:$,useCentrifugeSupport:Z,useMittSupport:V,centrifugeChannel:z}=f,T=L.useContext(M),I=L.useContext(y)??w,[X,G]=L.useState(!1),[J,Y]=L.useState(null),q=L.useRef(U),C=L.useContext(N),O=L.useCallback((R)=>{if(R===null)G(!0);else if(G(!1),!H)q.current=R;if(!H)Y(R)},[H]),W=L.useCallback((R)=>{q.current=R.content,Y(R.content)},[]),B=L.useCallback((R)=>{if(R===null)G(!0);else if(G(!1),!H)for(let Bf of R)C?.emit(Bf.name,Bf.data)},[H,C]);if(L.useEffect(()=>{Y(U),G(!1)},[U]),!J&&P)return T;return DU.jsx(_,{card:"AjaxGroupCard",data:f,methods:{changeContent:W},useSocketioSupport:$,useCentrifugeSupport:Z,useMittSupport:V,centrifugeChannel:z,children:DU.jsx(I,{uiConfig:J??q.current,setUiAjaxConfiguration:D==="events"?B:O})})},zH=JP;var TH=Q({name:"AjaxGroupCard",component:zH,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var ZU=require("react");var of=require("react/jsx-runtime"),YP=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,url:D,sx:$}=f,Z=ZU.useContext(o),V=ZU.useContext(y)??w;return of.jsx(_,{card:H,data:f,children:of.jsx("div",{style:$,id:H,onClick:(T)=>{if(D)if(T.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(D))window.location.href=D;else Z?.(D)},children:of.jsx(V,{setUiAjaxConfiguration:P,uiConfig:U})})})},VH=YP;var IH=Q({name:"BoxCard",component:VH,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var CH=require("react");var mf=require("react/jsx-runtime"),OP=({data:f,content:U,setUiAjaxConfiguration:P})=>{let{name:H,sx:D}=f,$=CH.useContext(y)??w;return mf.jsx(_,{card:H,data:f,children:mf.jsx("div",{style:D,id:H,children:U.map((Z,V)=>{return mf.jsx($,{uiConfig:Z,setUiAjaxConfiguration:P},`children-${V}`)})})})},JH=OP;var YH=Q({name:"OneOfCard",component:JH,metadata:{author:"Swarm.ing",description:"Different variants"}});var Pf=require("react"),Df=require("@tanstack/react-query");var uf=require("react");var jf=require("react"),Ef=new Map,kf=new Map;function xf(f,U){let P=`${f}::${U}`,H=f?Ef.get(P):void 0,[D,$]=jf.useState(H??null);return jf.useEffect(()=>{if(!f)return;if(Ef.has(P)){$(Ef.get(P));return}let Z=kf.get(P);if(!Z)Z=fetch(f+`api/support/${U}`,{method:"GET"}).then((z)=>z.json()).then((z)=>{return Ef.set(P,z),kf.delete(P),z}).catch((z)=>{throw kf.delete(P),z}),kf.set(P,Z);let V=!1;return Z.then((z)=>{if(!V)$(z)}).catch(()=>{}),()=>{V=!0}},[f,U,P]),D}var $U=null,OH=null;function XH(){OH?.()}function zU(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!$U)$U=new Promise((f)=>{OH=()=>{f()}});return $U}var XP=({children:f})=>{let U=uf.useContext(j),P=Rf(),H=xf(P,"socketIO"),D=($)=>{if(typeof window!=="undefined")window.sid=$.sid,XH(),console.log(`SocketIO initialized: ${window.sid}`)};return uf.useEffect(()=>{if(!U)return;let $=()=>{console.log("SocketIO connected")},Z=(V)=>{console.log(`SocketIO disconnected: ${V}`),U.connect()};if(H)U.on("pieinit",D),U.on("connect",$),U.on("disconnect",Z),U.connect();return()=>{if(H)U.off("pieinit",D),U.off("connect",$),U.off("disconnect",Z),U.disconnect()}},[U,H]),f},l=XP;var df=require("react");var GP=({children:f})=>{let U=df.useContext(k),P=Rf(),H=xf(P,"centrifuge");return df.useEffect(()=>{if(!U)return;let D=()=>{console.log("Centrifuge connected")},$=(Z)=>{console.log("Centrifuge disconnected:",Z)};if(H)U.on("connected",D),U.on("disconnected",$),U.connect();return()=>{if(H)U.disconnect()}},[U,H]),f},r=GP;var qH=require("axios-date-transformer");var GH=require("react/jsx-runtime");function Hf(f,U,P){if(!U)return P;let H=f.replace(/^\//,""),D=U[H];if(!D)return P;return GH.jsx(Ff,{uiConfig:D})}var K=require("react/jsx-runtime"),qP=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:$})=>{let Z=b(),V=v(),z=m(),T=Pf.useMemo(()=>qH.createAxiosDateTransformer({baseURL:Z||""}),[Z]),I=Pf.useMemo(()=>x(),[]),X=Pf.useMemo(()=>Z?c(Z):null,[Z]),G=Pf.useMemo(()=>Z?p(Z,V):null,[Z,V]),{data:J,isLoading:Y,error:q}=Df.useQuery({queryKey:["uiConfig",f.pathname+f.search,Z],enabled:!!Z,queryFn:async()=>{let O=new URLSearchParams(f.search);O.set("__pieroot","web");let W="/api/content"+f.pathname+"?"+O.toString();if(z)console.log("[PieRoot] Fetching UI configuration from:",W);let B=await T.get(W,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(z)console.log("[PieRoot] Received UI configuration:",B.data);return B.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(O)=>Math.min(1000*2**O,30000),...D}),C=Hf(f.pathname,P,U);if(!Z)return C??null;if(z)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",Z),console.log("[PieRoot] CENTRIFUGE_SERVER:",V),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!P);if(q){if(z)console.error("[PieRoot] Error fetching UI configuration:",q),console.error("[PieRoot] Error details:",{message:q.message,status:q.response?.status,data:q.response?.data});return H?.(),C}if(Y||!J){if(z)console.log("[PieRoot] Loading state:",{isLoading:Y,hasUiConfiguration:!!J});return C}if(z)console.log("[PieRoot] UI configuration loaded successfully:",J),console.log("[PieRoot] Rendering UI with configuration");return K.jsx(N.Provider,{value:I,children:K.jsx(j.Provider,{value:X,children:K.jsx(k.Provider,{value:G,children:K.jsx(M.Provider,{value:U??K.jsx(K.Fragment,{}),children:K.jsx(l,{children:K.jsx(r,{children:$?K.jsx(w,{uiConfig:J}):K.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:K.jsx(w,{uiConfig:J})})})})})})})})},BP=(f)=>{let U=Pf.useMemo(()=>new Df.QueryClient,[]);return K.jsx(o.Provider,{value:f.onNavigate,children:K.jsx(d.Provider,{value:f.config,children:K.jsx(Df.QueryClientProvider,{client:U,children:K.jsx(qP,{...f})})})})},BH=BP;var Zf=require("react"),$f=require("@tanstack/react-query");var WH=require("axios-date-transformer");var bf=require("react");var gf=({onError:f}={})=>{let[U,P]=bf.useState(null),H=GU();return bf.useEffect(()=>{if(typeof window==="undefined")return;let D=window.Telegram?.WebApp;if(!D)return;try{D.ready?.()}catch($){f?.()}if(H==="telegram_expanded"&&(D.platform==="ios"||D.platform==="android"))D.expand();P(D)},[]),U};var S=require("react/jsx-runtime"),WP=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:$})=>{let Z=b(),V=v(),z=m(),T=Zf.useMemo(()=>WH.createAxiosDateTransformer({baseURL:Z}),[Z]),I=Zf.useMemo(()=>x(),[]),X=Zf.useMemo(()=>Z?c(Z):null,[Z]),G=Zf.useMemo(()=>Z?p(Z,V):null,[Z,V]),J=gf({onError:H}),{data:Y,isLoading:q,error:C}=$f.useQuery({queryKey:["uiConfig",f.pathname+f.search,J?.initData],enabled:!!J?.initData,queryFn:async()=>{let W=new URLSearchParams(f.search);if(W.set("__pieroot","telegram"),J?.initData)W.set("initData",J.initData);let B="/api/content"+f.pathname+"?"+W.toString();if(z)console.log("[PieRoot] Fetching UI configuration from:",B);let R=await T.get(B,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(z)console.log("[PieRoot] Received UI configuration:",R.data);return R.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000),...D}),O=Hf(f.pathname,P,U);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(C&&z)return console.error("[PieRoot] Error fetching UI configuration:",C),console.error("[PieRoot] Error details:",{message:C.message,status:C.response?.status,data:C.response?.data}),H?.(),O;if(q||!Y){if(z)console.log("[PieRoot] Loading state:",{isLoading:q,hasUiConfiguration:!!Y});return O}if(z)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return S.jsx(N.Provider,{value:I,children:S.jsx(j.Provider,{value:X,children:S.jsx(k.Provider,{value:G,children:S.jsx(M.Provider,{value:U??S.jsx(S.Fragment,{}),children:S.jsx(l,{children:S.jsx(r,{children:$?S.jsx(w,{uiConfig:Y}):S.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:S.jsx(w,{uiConfig:Y})})})})})})})})},QP=(f)=>{let U=Zf.useMemo(()=>new $f.QueryClient,[]);return S.jsx(o.Provider,{value:f.onNavigate,children:S.jsx(d.Provider,{value:f.config,children:S.jsx($f.QueryClientProvider,{client:U,children:S.jsx(WP,{...f})})})})},QH=QP;var zf=require("react"),vf=require("@tanstack/react-query");var A=require("react/jsx-runtime"),RP=({location:f,fallback:U,children:P,disableGlobalForm:H})=>{let D=b(),$=v(),Z=m(),V=zf.useMemo(()=>x(),[]),z=zf.useMemo(()=>D?c(D):null,[D]),T=zf.useMemo(()=>D?p(D,$):null,[D,$]);if(Z)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",D),console.log("[PieRoot] CENTRIFUGE_SERVER:",$),console.log("[PieRoot] Fallback provided:",!!U);return A.jsx(N.Provider,{value:V,children:A.jsx(j.Provider,{value:z,children:A.jsx(k.Provider,{value:T,children:A.jsx(M.Provider,{value:U??A.jsx(A.Fragment,{}),children:A.jsx(l,{children:A.jsx(r,{children:H?P:A.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:P})})})})})})})},_P=(f)=>{let[U]=zf.useState(()=>new vf.QueryClient);return A.jsx(o.Provider,{value:f.onNavigate,children:A.jsx(d.Provider,{value:f.config,children:A.jsx(vf.QueryClientProvider,{client:U,children:A.jsx(RP,{...f})})})})},RH=_P;var Tf=require("react"),Vf=require("@tanstack/react-query");var _H=require("axios-date-transformer");var pf=require("react"),cf=()=>{let[f,U]=pf.useState(null);return pf.useEffect(()=>{if(typeof window==="undefined")return;let P=window.WebApp;if(!P)return;P.ready(),U(P)},[]),f};var F=require("react/jsx-runtime"),wP=({location:f,fallback:U,piecache:P,onError:H,queryOptions:D,disableGlobalForm:$})=>{let Z=b(),V=v(),z=m(),T=Tf.useMemo(()=>_H.createAxiosDateTransformer({baseURL:Z}),[Z]),I=Tf.useMemo(()=>x(),[]),X=Tf.useMemo(()=>Z?c(Z):null,[Z]),G=Tf.useMemo(()=>Z?p(Z,V):null,[Z,V]),J=cf(),{data:Y,isLoading:q,error:C}=Vf.useQuery({queryKey:["uiConfig",f.pathname+f.search,J?.initData],queryFn:async()=>{let W=new URLSearchParams(f.search);if(W.set("__pieroot","max"),J?.initData)W.set("initData",J.initData);let B="/api/content"+f.pathname+"?"+W.toString();if(z)console.log("[PieRoot] Fetching UI configuration from:",B);let R=await T.get(B,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(z)console.log("[PieRoot] Received UI configuration:",R.data);return R.data},enabled:!!J?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000),...D}),O=Hf(f.pathname,P,U);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(C&&z)return console.error("[PieRoot] Error fetching UI configuration:",C),console.error("[PieRoot] Error details:",{message:C.message,status:C.response?.status,data:C.response?.data}),H?.(),O;if(q||!Y){if(z)console.log("[PieRoot] Loading state:",{isLoading:q,hasUiConfiguration:!!Y});return O}if(z)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return F.jsx(N.Provider,{value:I,children:F.jsx(j.Provider,{value:X,children:F.jsx(k.Provider,{value:G,children:F.jsx(M.Provider,{value:U??F.jsx(F.Fragment,{}),children:F.jsx(l,{children:F.jsx(r,{children:$?F.jsx(w,{uiConfig:Y}):F.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:F.jsx(w,{uiConfig:Y})})})})})})})})},KP=(f)=>{let U=Tf.useMemo(()=>new Vf.QueryClient,[]);return F.jsx(o.Provider,{value:f.onNavigate,children:F.jsx(d.Provider,{value:f.config,children:F.jsx(Vf.QueryClientProvider,{client:U,children:F.jsx(wP,{...f})})})})},wH=KP;var KH=require("react"),TU=(f,U=!1)=>{if(f==="sid"){if(!window.sid)throw new Error("SocketIO isn't initialized properly");return[window.sid]}let P=document.getElementsByName(f);if(!P.length){if(U)console.warn(`No input found with name ${f}`);return[]}let H=P[0];if(H instanceof HTMLInputElement){if(H.type==="file"&&H.files)return Array.from(H.files);return[H.value]}if(H instanceof HTMLTextAreaElement)return[H.value];return[]},SP=(f,U={},P=[],H,D)=>{let $=D?.renderingLogEnabled??!1,Z=D?.timeout,V=D?.retryPolicy,z=V?.maxRetries??0,T=V?.baseDelay??1000,I=V?.retryOn??[502,503,504];if($)console.log("Registering AJAX: ",H,U,P);return async(X={})=>{if(typeof window==="undefined"||typeof document==="undefined"){if($)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let G=D?.apiServer;if(!G){if($)console.warn("AJAX skipped: apiServer is missing");return}if(!H||!f){if($)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(P.includes("sid"))await zU();let J=new FormData;for(let[C,O]of Object.entries({...U,...X}))J.append(C,O);for(let C of P)for(let O of TU(C,$))J.append(C,O);let Y=G+"api/ajax_content"+H;f(null);let q;for(let C=0;C<=z;C++){if(C>0){let B=T*2**(C-1);if($)console.log(`AJAX retry ${C}/${z} after ${B}ms`);await new Promise((R)=>setTimeout(R,B))}let O=Z!=null?new AbortController:null,W=O&&setTimeout(()=>O.abort(),Z);try{let B=await fetch(Y,{method:"POST",body:J,signal:O?.signal});if(W)clearTimeout(W);if(!B.ok&&I.includes(B.status)&&C<z){q=new Error(`HTTP ${B.status}`);continue}let Bf=(B.headers.get("content-type")||"").includes("application/json");if(!!B.body?.getReader&&!Bf){let Wf=B.body.getReader(),EH=new TextDecoder,n="";while(!0){let{done:lf,value:kH}=await Wf.read();if(lf)break;n+=EH.decode(kH,{stream:!0});let IU=n.split(`
3
+ `);n=IU.pop()??"";for(let jH of IU){let rf=jH.trim();if(!rf)continue;try{let xH=JSON.parse(rf);f([xH])}catch{if($)console.warn("Failed to parse streamed line:",rf)}}}if(n.trim())try{let lf=JSON.parse(n);f([lf])}catch{if($)console.warn("Failed to parse final streamed line:",n)}return{}}else{let Wf=await B.json();return f(Wf),Wf}}catch(B){if(W)clearTimeout(W);if(q=B,C<z)continue;if($)console.error("AJAX request failed:",B);return f(null),B}}if($)console.error("AJAX request failed after retries:",q);return f(null),q}},SH=(f,U={},P=[],H,D)=>{let{apiServer:$,enableRenderingLog:Z}=i(),V=JSON.stringify(U),z=JSON.stringify(P),T=JSON.stringify(D);return KH.useMemo(()=>SP(f,U,P,H,{apiServer:$,renderingLogEnabled:Z,timeout:D?.timeout,retryPolicy:D?.retryPolicy}),[f,V,z,H,$,Z,T])};var FH=require("@openai/agents"),hf=require("react");var MH=/^pie(.+?)_(.+)$/;function VU(f=x(),U={}){let P=[],H=new Set;for(let D of f.all.keys()){if(typeof D!=="string")continue;let $=D.match(MH);if(!$)continue;let[,Z,V]=$,z={methodName:Z,cardName:V,eventName:D};if(U.filter&&!U.filter(z))continue;let T=U.nameFor?.(z)??`${V}_${Z}`;if(H.has(T))continue;H.add(T);let I=U.describe?.(z)??`Invokes the "${Z}" method on the PieCard "${V}" by emitting the in-process mitt event "${D}". The optional "payload" argument is forwarded verbatim to the card's handler.`;P.push(FH.tool({name:T,description:I,strict:!1,parameters:{type:"object",properties:{payload:{description:"Arbitrary JSON payload forwarded to the PieCard method handler. Omit for fire-and-forget calls."}},required:[],additionalProperties:!0},execute:async(X)=>{let G=X?.payload;return f.emit(D,G),`Emitted "${D}"`}}))}return P}function LH(f={}){let P=hf.useContext(N)??x(),H=[];for(let z of P.all.keys())if(typeof z==="string"&&MH.test(z))H.push(z);H.sort();let D=H.join("|"),{filter:$,describe:Z,nameFor:V}=f;return hf.useMemo(()=>VU(P,{filter:$,describe:Z,nameFor:V}),[P,D,$,Z,V])}var AH=require("clsx"),NH=require("tailwind-merge");function yH(...f){return NH.twMerge(AH.clsx(f))}var oH=()=>{if(typeof document==="undefined")return;let f=document.getElementById("piedata_global_form");f&&f.submit()};var mH=(f,U)=>`${f}${_f}${U}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarm.ing/pieui",
3
- "version": "2.0.22",
3
+ "version": "2.0.24",
4
4
  "description": "A React component library featuring PieCard component",
5
5
  "repository": {
6
6
  "type": "git",