@swarm.ing/pieui 2.0.19 → 2.0.21
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/README.md +6 -2
- package/dist/cli.js +402 -28
- package/dist/code/args.d.ts.map +1 -1
- package/dist/code/commands/cardRemote/cardRef.d.ts +3 -0
- package/dist/code/commands/cardRemote/cardRef.d.ts.map +1 -1
- package/dist/code/commands/cardRemote/history.d.ts +9 -0
- package/dist/code/commands/cardRemote/history.d.ts.map +1 -0
- package/dist/code/commands/cardRemote/private.d.ts +2 -0
- package/dist/code/commands/cardRemote/private.d.ts.map +1 -0
- package/dist/code/commands/cardRemote/public.d.ts +2 -0
- package/dist/code/commands/cardRemote/public.d.ts.map +1 -0
- package/dist/code/commands/cardRemote/pull.d.ts.map +1 -1
- package/dist/code/commands/cardRemote/push.d.ts.map +1 -1
- package/dist/code/services/models.d.ts +37 -0
- package/dist/code/services/models.d.ts.map +1 -1
- package/dist/code/services/storage.d.ts +40 -1
- package/dist/code/services/storage.d.ts.map +1 -1
- package/dist/code/types.d.ts +5 -1
- package/dist/code/types.d.ts.map +1 -1
- package/dist/components/PieBaseRoot/index.d.ts.map +1 -1
- package/dist/components/PieMaxRoot/index.d.ts.map +1 -1
- package/dist/components/PieRoot/index.d.ts.map +1 -1
- package/dist/components/PieRoot/types/index.d.ts +7 -0
- package/dist/components/PieRoot/types/index.d.ts.map +1 -1
- package/dist/components/PieTelegramRoot/index.d.ts.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.js +2 -2
- package/dist/tests/ajaxCommonUtils.test.d.ts +15 -0
- package/dist/tests/ajaxCommonUtils.test.d.ts.map +1 -0
- package/dist/tests/lazy.test.d.ts +14 -0
- package/dist/tests/lazy.test.d.ts.map +1 -0
- package/dist/tests/pieName.test.d.ts +12 -0
- package/dist/tests/pieName.test.d.ts.map +1 -0
- package/dist/tests/waitForSidAvailable.test.d.ts +20 -0
- package/dist/tests/waitForSidAvailable.test.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var oH=Object.create;var{getPrototypeOf:EH,defineProperty:Pf,getOwnPropertyNames:PU,getOwnPropertyDescriptor:mH}=Object,VU=Object.prototype.hasOwnProperty;var IU=(f,U,Z)=>{Z=f!=null?oH(EH(f)):{};let H=U||!f||!f.__esModule?Pf(Z,"default",{value:f,enumerable:!0}):Z;for(let z of PU(f))if(!VU.call(H,z))Pf(H,z,{get:()=>f[z],enumerable:!0});return H},GU=new WeakMap,kH=(f)=>{var U=GU.get(f),Z;if(U)return U;if(U=Pf({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")PU(f).map((H)=>!VU.call(U,H)&&Pf(U,H,{get:()=>f[H],enumerable:!(Z=mH(f,H))||Z.enumerable}));return GU.set(f,U),U};var jH=(f,U)=>{for(var Z in U)Pf(f,Z,{get:U[Z],enumerable:!0,configurable:!0,set:(H)=>U[Z]=()=>H})};var CZ={};jH(CZ,{useWebApp:()=>uf,usePieMittAgentTools:()=>RH,usePieEmit:()=>_U,useOpenAIWebRTC:()=>If,useMaxWebApp:()=>vf,useAjaxSubmit:()=>CH,unregisterComponent:()=>KU,submitGlobalForm:()=>SH,registry:()=>g,registerPieComponent:()=>C,registerMultipleComponents:()=>FU,pieName:()=>LH,hasComponent:()=>SU,getRegistrySize:()=>AU,getRegistryEntry:()=>t,getMittAgentTools:()=>$U,getComponentMeta:()=>LU,getAllRegisteredComponents:()=>MU,cn:()=>KH,UnionCard:()=>dU,UIRendererContext:()=>x,UILoading:()=>Kf,UI:()=>F,SessionStorageCard:()=>tU,SequenceCard:()=>kU,SecureStorageCard:()=>ZH,PieTelegramRoot:()=>XH,PieRoot:()=>JH,PieMaxRoot:()=>WH,PieCard:()=>_,PieBaseRoot:()=>qH,PIEBREAK:()=>_f,IOEventsCard:()=>sU,HiddenCard:()=>cU,HTMLEmbedCard:()=>vU,DeviceStorageCard:()=>eU,CloudStorageCard:()=>UH,BoxCard:()=>TH,AutoRedirectCard:()=>rU,AjaxGroupCard:()=>DH});module.exports=kH(CZ);var d=require("react");var Cf=require("react"),u=Cf.createContext(null),s=()=>{let f=Cf.useContext(u);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},b=()=>{let{apiServer:f}=s();return f},Of=b,v=()=>{let{centrifugeServer:f}=s();return f};var o=()=>{let{enableRenderingLog:f}=s();return f},JU=o,YU=()=>{let{pageProcessor:f}=s();return f};var _f="__piedemo__";var qU=require("react"),lf=require("centrifuge"),XU=new Map,p=(f,U)=>{if(!U)return null;let Z=`${f}::${U}`,H=XU.get(Z);if(H)return H;async function z(){let $=await fetch(f+"api/centrifuge/gen_token");if(!$.ok){if($.status===403)throw new lf.Centrifuge.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${$.status}`)}return(await $.json()).token}let D=new lf.Centrifuge(U,{getToken:z});return XU.set(Z,D),D},xH=qU.createContext(null),m=xH;var WU=require("socket.io-client"),QU=require("react"),BU=new Map,c=(f)=>{let U=BU.get(f);if(U)return U;let Z=WU.io(f,{autoConnect:!1,transports:["websocket"]});return BU.set(f,Z),Z},dH=QU.createContext(null),k=dH;var CU=IU(require("mitt")),i=require("react"),rf=null;function j(){if(!rf)rf=CU.default();return rf}var OU=i.createContext(null);function _U(f){let U=i.useContext(OU);return i.useCallback((Z,H)=>{(U??j()).emit(`pie${Z}_${f}`,H)},[f,U])}var N=OU;var uH=({card:f,data:U,children:Z,useSocketioSupport:H=!1,useCentrifugeSupport:z=!1,useMittSupport:D=!1,centrifugeChannel:$=void 0,methods:G=void 0})=>{let T=JU(),P=d.useRef(G);if(P.current=G,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:z,mitt:D,centrifugeChannel:$}),console.log("[PieCard] Methods:",G?Object.keys(G):"none"),console.log("[PieCard] Has children:",!!Z);let X=d.useContext(k),B=d.useContext(m),q=d.useContext(N);if(d.useEffect(()=>{if(!X||!H||!P.current||!U.name){if(T&&H)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!X,useSocketioSupport:H,hasMethods:!!P.current,hasDataName:!!U?.name});return}let I=Object.keys(P.current??{}).map((V)=>{let J=`pie${V}_${U.name}`;if(T)console.log(`[PieCard] Socket.IO registering event: ${J}`);let W=(Q)=>{P.current?.[V]?.(Q)};return X.on(J,W),[J,W]});return()=>{I.forEach(([V,J])=>{if(T)console.log(`[PieCard] Socket.IO unregistering event: ${V}`);X.off(V,J)})}},[X,U.name,H]),d.useEffect(()=>{if(!B||!z||!$||!U.name){if(T&&z)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!B,useCentrifugeSupport:z,hasCentrifugeChannel:!!$,hasMethods:!!P.current,hasDataName:!!U?.name});return}let I=Object.keys(P.current??{}).map((V)=>{let J=`pie${V}_${U.name}_${$}`;if(T)console.log(`[PieCard] Centrifuge subscribing to channel: ${J}`);let W=B.newSubscription(J);return W.on("publication",(Q)=>{if(T)console.log(`[PieCard] Centrifuge received data on ${J}:`,Q.data);P.current?.[V]?.(Q.data)}),W.subscribe(),W});return()=>{I.forEach((V)=>{if(T)console.log("[PieCard] Centrifuge unsubscribing from channel");V.unsubscribe(),B.removeSubscription(V)})}},[B,$,U.name,z]),d.useEffect(()=>{if(!q||!D||!U.name){if(T&&D)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!q,useMittSupport:D,hasMethods:!!P.current,hasDataName:!!U?.name});return}let Y=Object.keys(P.current??{}),I={};return Y.forEach((V)=>{let J=`pie${V}_${U.name}`,W=(Q)=>{if(T)console.log(`[PieCard] Mitt registering event: ${J}`);P.current?.[V]?.(Q)};I[J]=W,q.on(J,W)}),()=>{Object.entries(I).forEach(([V,J])=>{if(T)console.log(`[PieCard] Mitt unregistering event: ${V}`);q.off(V,J)})}},[q,U.name,D]),T)console.log("[PieCard] Rendering complete, returning children");return Z},_=uH;var RU=require("react"),nf=new Map;function wU(f,U){return RU.lazy(()=>{if(nf.has(U))return nf.get(U);let Z=f().then((H)=>H);return nf.set(U,Z),Z})}var g=new Map,bH=(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=wU(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function C(f){let U=bH(f);return g.set(U.name,U),U.component}var FU=(f)=>{f.forEach((U)=>C(U))},KU=(f)=>{g.delete(f)},SU=(f)=>{return g.has(f)},LU=(f)=>{return g.get(f)?.metadata},t=(f)=>{return g.get(f)},MU=()=>{return Array.from(g.keys())},AU=()=>{return g.size};var a=require("react");var NU=require("react"),Rf=require("react/jsx-runtime"),gH=NU.createContext(Rf.jsx(Rf.Fragment,{})),w=gH;var wf=require("react/jsx-runtime");function vH({uiConfig:f,setUiAjaxConfiguration:U}){let Z=a.useContext(w),H=o();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 z=t(f.card);if(!z?.component){if(H)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return Z}if(H)console.log("[UI] Found component in registry:",{name:z.name,isLazy:z.isLazy,hasMetadata:!!z.metadata});let D=z.component,$=wf.jsx(D,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(z.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",z.name);return wf.jsx(a.Suspense,{fallback:z.fallback?wf.jsx(z.fallback,{}):Z,children:$},`${z.name}`)}if(H)console.log("[UI] Rendering component directly:",z.name);return $}var F=a.memo(vH);var Ff=require("react");var yU=require("react"),pH=yU.createContext(null),x=pH;var Vf=require("react/jsx-runtime");function oU({uiConfig:f,setUiAjaxConfiguration:U}){let Z=Ff.useContext(w),H=o();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 z=t(f.card);if(!z?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return Z}if(H)console.log("[UILoading] Found component in registry:",{name:z.name,isLazy:z.isLazy,hasMetadata:!!z.metadata,hasFallback:!!z.fallback});if(z.fallback){if(H)console.log("[UILoading] Rendering fallback for:",z.name);let G=z.fallback;return Vf.jsx(G,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",z.name);let D=z.component,$=Vf.jsx(x.Provider,{value:oU,children:Vf.jsx(D,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(z.isLazy)return Vf.jsx(Ff.Suspense,{fallback:Z,children:$},`${z.name}`);return $}var Kf=oU;var EU=require("react");var Sf=require("react/jsx-runtime"),cH=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H,sx:z}=f,D=EU.useContext(x)??F;return Sf.jsx(_,{card:H,data:f,children:Sf.jsx("div",{style:z,id:H,children:U.map(($,G)=>{return Sf.jsx(D,{uiConfig:$,setUiAjaxConfiguration:Z},`children-${G}`)})})})},mU=cH;var kU=C({name:"SequenceCard",component:mU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var jU=require("react");var sf=require("react/jsx-runtime"),hH=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H}=f,z=jU.useContext(x)??F;return sf.jsx(_,{card:H,data:f,children:U.map((D,$)=>{return sf.jsx(z,{uiConfig:D,setUiAjaxConfiguration:Z},`children-${$}`)})})},xU=hH;var dU=C({name:"UnionCard",component:xU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var Lf=require("react"),uU=IU(require("html-react-parser"));var E=require("react");function lH(){let f=new AudioContext,U=f.createOscillator(),Z=U.connect(f.createMediaStreamDestination());U.start();let H=Z.stream.getAudioTracks()[0];return H.enabled=!1,H}function If(f=null,U){let[Z,H]=E.useState(!1),z=E.useRef(null),D=E.useRef(null),$=E.useRef(null),G=E.useCallback(async(B,q=!0)=>{if(z.current)T();let Y=new RTCPeerConnection;if(Y.onconnectionstatechange=()=>{if(Y.connectionState==="connected")H(!0);else if(["disconnected","failed","closed"].includes(Y.connectionState))H(!1)},Y.ontrack=(R)=>{if(f)f.srcObject=R.streams[0]},q){let R=await navigator.mediaDevices.getUserMedia({audio:!0});Y.addTrack(R.getTracks()[0],R)}else{let R=lH();Y.addTrack(R)}let I=Y.createDataChannel("oai-events");D.current=I,$.current=new Promise((R)=>{I.addEventListener("open",()=>{R()})});let V=await Y.createOffer();await Y.setLocalDescription(V);let O=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:V.sdp,headers:{Authorization:`Bearer ${B}`,"Content-Type":"application/sdp"}})).text();await Y.setRemoteDescription({type:"answer",sdp:O}),z.current=Y,await $.current},[f]),T=E.useCallback(()=>{let B=D.current;if(B)B.close();z.current?.getSenders()?.forEach((q)=>q.track?.stop()),z.current?.close(),H(!1),z.current=null,D.current=null,$.current=null},[f]),P=E.useCallback((B)=>{let q=D.current;if(!q){console.error("Data channel is not ready",B);return}let Y=new Date().toLocaleTimeString();if(B.event_id=B.event_id||crypto.randomUUID(),q.send(JSON.stringify(B)),!B.timestamp)B.timestamp=Y;U?.(B)},[U,f]),X=E.useCallback((B)=>{if(!D.current){console.error("Data channel is not ready");return}let Y=()=>{P({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:B}]}}),P({type:"response.create"})};if($.current)$.current.then(Y);else Y()},[U,f]);return E.useEffect(()=>{let B=D.current;if(!B)return;let q=(Y)=>{let I=JSON.parse(Y.data);if(!I.timestamp)I.timestamp=new Date().toLocaleTimeString();U?.(I)};return B.addEventListener("message",q),()=>{B.removeEventListener("message",q)}},[U,f]),{isSessionActive:Z,startSession:G,stopSession:T,sendTextMessage:X}}var gU=require("react/jsx-runtime"),rH=({data:f})=>{let{html:U,useSocketioSupport:Z,useCentrifugeSupport:H,useMittSupport:z,centrifugeChannel:D}=f,[$,G]=Lf.useState(U),{isSessionActive:T,startSession:P,sendTextMessage:X}=If(null,(I)=>{if(console.log(I.type,I.type==="response.output_text.delta"&&I.delta),I.type==="response.output_text.delta"&&I.delta)G((V)=>V+I.delta)});return Lf.useEffect(()=>{G(U)},[U]),gU.jsx(_,{card:"HTMLEmbedCard",data:f,methods:{update:(I)=>{G(I.value)},generateUsingAI:async(I)=>{try{if(!T&&I.token)await P(I.token,!1);X(I.prompt)}catch(V){console.error("Failed to generate using AI",V)}},initializeAI:async(I)=>{if(!T&&I.token)await P(I.token,!1)}},useCentrifugeSupport:H,useSocketioSupport:Z,useMittSupport:z,centrifugeChannel:D,children:uU.default($)})},bU=rH;var vU=C({name:"HTMLEmbedCard",component:bU,metadata:{author:"Swarm.ing"}});var Mf=require("react");var tf=require("react/jsx-runtime"),nH=({data:f})=>{let{name:U,value:Z,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:D,centrifugeChannel:$}=f,[G,T]=Mf.useState(Z);return Mf.useEffect(()=>{T(Z)},[Z]),tf.jsx(_,{card:"HiddenCard",data:f,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:D,centrifugeChannel:$,methods:{update:({value:P})=>{T(P)}},children:tf.jsx("input",{type:"hidden",id:U,name:U,value:G})})},pU=nH;var cU=C({name:"HiddenCard",component:pU,metadata:{author:"Swarm.ing"}});var Jf=require("react");var hU=require("react"),sH=hU.createContext(void 0),y=sH;var Af=require("react/jsx-runtime"),iH=({data:f})=>{let{url:U}=f,Z=Jf.useContext(y),H=Jf.useContext(w);return Jf.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else Z?.(U)},[U,Z]),Af.jsx(Af.Fragment,{children:H})},lU=iH;var rU=C({name:"AutoRedirectCard",component:lU,metadata:{author:"Swarm.ing"}});var h=require("react-toastify"),Nf=require("react-toastify");var ff=require("react");var e=require("react/jsx-runtime"),tH={bounce:h.Bounce,slide:h.Slide,zoom:h.Zoom,flip:h.Flip},aH=(f)=>{let U={...f,type:f.alertType,transition:f.transition?tH[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};Nf.toast(f.message,U)},eH=(f)=>{console.log("Log event",f)},fZ=(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)}},Z=window.Notification.permission;if(Z==="granted"){U();return}if(Z==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((H)=>{if(H==="granted")U()})},UZ=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:Z,useMittSupport:H,centrifugeChannel:z}=f,D=ff.useContext(y),$=ff.useRef(D);$.current=D;let G=ff.useMemo(()=>({alert:aH,log:eH,push:fZ,redirect:(T)=>{if(T.to){let P=T.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(P))window.location.href=P;else $.current?.(P)}else window.location.reload()},reload:(T)=>{if(T.to){let P=T.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(P))window.location.href=P;else $.current?.(P)}else window.location.reload()}}),[]);return e.jsx(e.Fragment,{children:e.jsx(_,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:Z,useMittSupport:H,centrifugeChannel:z,methods:G,children:e.jsx(Nf.ToastContainer,{})})})},nU=UZ;var sU=C({name:"IOEventsCard",component:nU,metadata:{author:"Swarm.ing"}});var Yf=require("react");var af=require("react/jsx-runtime"),HZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=Yf.useState(H);return Yf.useEffect(()=>{P(H)},[H]),Yf.useEffect(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(Z,T)},[Z,T]),af.jsx(_,{card:"SessionStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{sessionStorage.removeItem(Z),P("")}},children:af.jsx("input",{type:"hidden",id:U,name:U,value:T})})},iU=HZ;var tU=C({name:"SessionStorageCard",component:iU,metadata:{author:"PieData"}});var Xf=require("react");var ef=require("react/jsx-runtime"),ZZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=Xf.useState(H);return Xf.useEffect(()=>{P(H)},[H]),Xf.useEffect(()=>{if(typeof window==="undefined")return;localStorage.setItem(Z,T)},[Z,T]),ef.jsx(_,{card:"DeviceStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{localStorage.removeItem(Z),P("")}},children:ef.jsx("input",{type:"hidden",id:U,name:U,value:T})})},aU=ZZ;var eU=C({name:"DeviceStorageCard",component:aU,metadata:{author:"PieData"}});var qf=require("react");var fU=require("react/jsx-runtime"),zZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=qf.useState(H);return qf.useEffect(()=>{P(H)},[H]),qf.useEffect(()=>{if(typeof window==="undefined")return;let X=window.Telegram?.WebApp?.CloudStorage;if(!X)return;X.setItem(Z,T)},[Z,T]),fU.jsx(_,{card:"CloudStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{let X=window.Telegram?.WebApp?.CloudStorage;if(X)X.removeItem(Z);P("")}},children:fU.jsx("input",{type:"hidden",id:U,name:U,value:T})})},fH=zZ;var UH=C({name:"CloudStorageCard",component:fH,metadata:{author:"PieData"}});var Bf=require("react");var UU=require("react/jsx-runtime"),DZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=Bf.useState(H);return Bf.useEffect(()=>{P(H)},[H]),Bf.useEffect(()=>{if(typeof window==="undefined")return;let X=window.Telegram?.WebApp?.SecureStorage;if(!X)return;X.setItem(Z,T)},[Z,T]),UU.jsx(_,{card:"SecureStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:D,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{let X=window.Telegram?.WebApp?.SecureStorage;if(X)X.removeItem(Z);P("")}},children:UU.jsx("input",{type:"hidden",id:U,name:U,value:T})})},HH=DZ;var ZH=C({name:"SecureStorageCard",component:HH,metadata:{author:"PieData"}});var M=require("react");var HU=require("react/jsx-runtime"),$Z=({data:f,content:U})=>{let{useLoader:Z,noReturn:H,returnType:z,useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:G,centrifugeChannel:T}=f,P=M.useContext(w),X=M.useContext(x)??F,[B,q]=M.useState(!1),[Y,I]=M.useState(null),V=M.useRef(U),J=M.useContext(N),W=M.useCallback((R)=>{if(R===null)q(!0);else if(q(!1),!H)V.current=R;if(!H)I(R)},[H]),Q=M.useCallback((R)=>{V.current=R.content,I(R.content)},[]),O=M.useCallback((R)=>{if(R===null)q(!0);else if(q(!1),!H)for(let Wf of R)J?.emit(Wf.name,Wf.data)},[H,J]);if(M.useEffect(()=>{I(U),q(!1)},[U]),!Y&&Z)return P;return HU.jsx(_,{card:"AjaxGroupCard",data:f,methods:{changeContent:Q},useSocketioSupport:D,useCentrifugeSupport:$,useMittSupport:G,centrifugeChannel:T,children:HU.jsx(X,{uiConfig:Y??V.current,setUiAjaxConfiguration:z==="events"?O:W})})},zH=$Z;var DH=C({name:"AjaxGroupCard",component:zH,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var ZU=require("react");var yf=require("react/jsx-runtime"),TZ=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H,url:z,sx:D}=f,$=ZU.useContext(y),G=ZU.useContext(x)??F;return yf.jsx(_,{card:H,data:f,children:yf.jsx("div",{style:D,id:H,onClick:(P)=>{if(z)if(P.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(z))window.location.href=z;else $?.(z)},children:yf.jsx(G,{setUiAjaxConfiguration:Z,uiConfig:U})})})},$H=TZ;var TH=C({name:"BoxCard",component:$H,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var Hf=require("react"),Zf=require("@tanstack/react-query");var jf=require("react");var mf=require("react"),of=new Map,Ef=new Map;function kf(f,U){let Z=`${f}::${U}`,H=f?of.get(Z):void 0,[z,D]=mf.useState(H??null);return mf.useEffect(()=>{if(!f)return;if(of.has(Z)){D(of.get(Z));return}let $=Ef.get(Z);if(!$)$=fetch(f+`api/support/${U}`,{method:"GET"}).then((T)=>T.json()).then((T)=>{return of.set(Z,T),Ef.delete(Z),T}).catch((T)=>{throw Ef.delete(Z),T}),Ef.set(Z,$);let G=!1;return $.then((T)=>{if(!G)D(T)}).catch(()=>{}),()=>{G=!0}},[f,U,Z]),z}var zU=null,GH=null;function PH(){GH?.()}function DU(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!zU)zU=new Promise((f)=>{GH=()=>{f()}});return zU}var GZ=({children:f})=>{let U=jf.useContext(k),Z=Of(),H=kf(Z,"socketIO"),z=(D)=>{if(typeof window!=="undefined")window.sid=D.sid,PH(),console.log(`SocketIO initialized: ${window.sid}`)};return jf.useEffect(()=>{if(!U)return;let D=()=>{console.log("SocketIO connected")},$=(G)=>{console.log(`SocketIO disconnected: ${G}`),U.connect()};if(H)U.on("pieinit",z),U.on("connect",D),U.on("disconnect",$),U.connect();return()=>{if(H)U.off("pieinit",z),U.off("connect",D),U.off("disconnect",$),U.disconnect()}},[U,H]),f},l=GZ;var xf=require("react");var PZ=({children:f})=>{let U=xf.useContext(m),Z=Of(),H=kf(Z,"centrifuge");return xf.useEffect(()=>{if(!U)return;let z=()=>{console.log("Centrifuge connected")},D=($)=>{console.log("Centrifuge disconnected:",$)};if(H)U.on("connected",z),U.on("disconnected",D),U.connect();return()=>{if(H)U.disconnect()}},[U,H]),f},r=PZ;var IH=require("axios-date-transformer");var VH=require("react/jsx-runtime");function Uf(f,U,Z){if(!U)return Z;let H=f.replace(/^\//,""),z=U[H];if(!z)return Z;return VH.jsx(Kf,{uiConfig:z})}var K=require("react/jsx-runtime"),VZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z})=>{let D=b(),$=v(),G=o(),T=Hf.useMemo(()=>IH.createAxiosDateTransformer({baseURL:D||""}),[D]),P=Hf.useMemo(()=>j(),[]),X=Hf.useMemo(()=>D?c(D):null,[D]),B=Hf.useMemo(()=>D?p(D,$):null,[D,$]),{data:q,isLoading:Y,error:I}=Zf.useQuery({queryKey:["uiConfig",f.pathname+f.search,D],enabled:!!D,queryFn:async()=>{let J=new URLSearchParams(f.search);J.set("__pieroot","web");let W="/api/content"+f.pathname+"?"+J.toString();if(G)console.log("[PieRoot] Fetching UI configuration from:",W);let Q=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(G)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:(J)=>Math.min(1000*2**J,30000),...z}),V=Uf(f.pathname,Z,U);if(!D)return V??null;if(G)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",D),console.log("[PieRoot] CENTRIFUGE_SERVER:",$),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!Z);if(I){if(G)console.error("[PieRoot] Error fetching UI configuration:",I),console.error("[PieRoot] Error details:",{message:I.message,status:I.response?.status,data:I.response?.data});return H?.(),V}if(Y||!q){if(G)console.log("[PieRoot] Loading state:",{isLoading:Y,hasUiConfiguration:!!q});return V}if(G)console.log("[PieRoot] UI configuration loaded successfully:",q),console.log("[PieRoot] Rendering UI with configuration");return K.jsx(N.Provider,{value:P,children:K.jsx(k.Provider,{value:X,children:K.jsx(m.Provider,{value:B,children:K.jsx(w.Provider,{value:U??K.jsx(K.Fragment,{}),children:K.jsx(l,{children:K.jsx(r,{children:K.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:K.jsx(F,{uiConfig:q})})})})})})})})},IZ=(f)=>{let U=Hf.useMemo(()=>new Zf.QueryClient,[]);return K.jsx(y.Provider,{value:f.onNavigate,children:K.jsx(u.Provider,{value:f.config,children:K.jsx(Zf.QueryClientProvider,{client:U,children:K.jsx(VZ,{...f})})})})},JH=IZ;var zf=require("react"),Df=require("@tanstack/react-query");var YH=require("axios-date-transformer");var df=require("react");var uf=({onError:f}={})=>{let[U,Z]=df.useState(null),H=YU();return df.useEffect(()=>{if(typeof window==="undefined")return;let z=window.Telegram?.WebApp;if(!z)return;try{z.ready?.()}catch(D){f?.()}if(H==="telegram_expanded"&&(z.platform==="ios"||z.platform==="android"))z.expand();Z(z)},[]),U};var S=require("react/jsx-runtime"),JZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z})=>{let D=b(),$=v(),G=o(),T=zf.useMemo(()=>YH.createAxiosDateTransformer({baseURL:D}),[D]),P=zf.useMemo(()=>j(),[]),X=zf.useMemo(()=>D?c(D):null,[D]),B=zf.useMemo(()=>D?p(D,$):null,[D,$]),q=uf({onError:H}),{data:Y,isLoading:I,error:V}=Df.useQuery({queryKey:["uiConfig",f.pathname+f.search,q?.initData],enabled:!!q?.initData,queryFn:async()=>{let W=new URLSearchParams(f.search);if(W.set("__pieroot","telegram"),q?.initData)W.set("initData",q.initData);let Q="/api/content"+f.pathname+"?"+W.toString();if(G)console.log("[PieRoot] Fetching UI configuration from:",Q);let O=await T.get(Q,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(G)console.log("[PieRoot] Received UI configuration:",O.data);return O.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000),...z}),J=Uf(f.pathname,Z,U);if(!D)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(V&&G)return console.error("[PieRoot] Error fetching UI configuration:",V),console.error("[PieRoot] Error details:",{message:V.message,status:V.response?.status,data:V.response?.data}),H?.(),J;if(I||!Y){if(G)console.log("[PieRoot] Loading state:",{isLoading:I,hasUiConfiguration:!!Y});return J}if(G)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return S.jsx(N.Provider,{value:P,children:S.jsx(k.Provider,{value:X,children:S.jsx(m.Provider,{value:B,children:S.jsx(w.Provider,{value:U??S.jsx(S.Fragment,{}),children:S.jsx(l,{children:S.jsx(r,{children:S.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:S.jsx(F,{uiConfig:Y})})})})})})})})},YZ=(f)=>{let U=zf.useMemo(()=>new Df.QueryClient,[]);return S.jsx(y.Provider,{value:f.onNavigate,children:S.jsx(u.Provider,{value:f.config,children:S.jsx(Df.QueryClientProvider,{client:U,children:S.jsx(JZ,{...f})})})})},XH=YZ;var $f=require("react"),bf=require("@tanstack/react-query");var A=require("react/jsx-runtime"),XZ=({location:f,fallback:U,children:Z})=>{let H=b(),z=v(),D=o(),$=$f.useMemo(()=>j(),[]),G=$f.useMemo(()=>H?c(H):null,[H]),T=$f.useMemo(()=>H?p(H,z):null,[H,z]);if(D)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!U);return A.jsx(N.Provider,{value:$,children:A.jsx(k.Provider,{value:G,children:A.jsx(m.Provider,{value:T,children:A.jsx(w.Provider,{value:U??A.jsx(A.Fragment,{}),children:A.jsx(l,{children:A.jsx(r,{children:A.jsx("form",{id:"piedata_global_form",action:H+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:Z})})})})})})})},qZ=(f)=>{let[U]=$f.useState(()=>new bf.QueryClient);return A.jsx(y.Provider,{value:f.onNavigate,children:A.jsx(u.Provider,{value:f.config,children:A.jsx(bf.QueryClientProvider,{client:U,children:A.jsx(XZ,{...f})})})})},qH=qZ;var Tf=require("react"),Gf=require("@tanstack/react-query");var BH=require("axios-date-transformer");var gf=require("react"),vf=()=>{let[f,U]=gf.useState(null);return gf.useEffect(()=>{if(typeof window==="undefined")return;let Z=window.WebApp;if(!Z)return;Z.ready(),U(Z)},[]),f};var L=require("react/jsx-runtime"),BZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z})=>{let D=b(),$=v(),G=o(),T=Tf.useMemo(()=>BH.createAxiosDateTransformer({baseURL:D}),[D]),P=Tf.useMemo(()=>j(),[]),X=Tf.useMemo(()=>D?c(D):null,[D]),B=Tf.useMemo(()=>D?p(D,$):null,[D,$]),q=vf(),{data:Y,isLoading:I,error:V}=Gf.useQuery({queryKey:["uiConfig",f.pathname+f.search,q?.initData],queryFn:async()=>{let W=new URLSearchParams(f.search);if(W.set("__pieroot","max"),q?.initData)W.set("initData",q.initData);let Q="/api/content"+f.pathname+"?"+W.toString();if(G)console.log("[PieRoot] Fetching UI configuration from:",Q);let O=await T.get(Q,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(G)console.log("[PieRoot] Received UI configuration:",O.data);return O.data},enabled:!!q?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000),...z}),J=Uf(f.pathname,Z,U);if(!D)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(V&&G)return console.error("[PieRoot] Error fetching UI configuration:",V),console.error("[PieRoot] Error details:",{message:V.message,status:V.response?.status,data:V.response?.data}),H?.(),J;if(I||!Y){if(G)console.log("[PieRoot] Loading state:",{isLoading:I,hasUiConfiguration:!!Y});return J}if(G)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return L.jsx(N.Provider,{value:P,children:L.jsx(k.Provider,{value:X,children:L.jsx(m.Provider,{value:B,children:L.jsx(w.Provider,{value:U??L.jsx(L.Fragment,{}),children:L.jsx(l,{children:L.jsx(r,{children:L.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:L.jsx(F,{uiConfig:Y})})})})})})})})},WZ=(f)=>{let U=Tf.useMemo(()=>new Gf.QueryClient,[]);return L.jsx(y.Provider,{value:f.onNavigate,children:L.jsx(u.Provider,{value:f.config,children:L.jsx(Gf.QueryClientProvider,{client:U,children:L.jsx(BZ,{...f})})})})},WH=WZ;var QH=require("react"),QZ=(f,U={},Z=[],H,z)=>{let D=z?.renderingLogEnabled??!1,$=z?.timeout,G=z?.retryPolicy,T=G?.maxRetries??0,P=G?.baseDelay??1000,X=G?.retryOn??[502,503,504];if(D)console.log("Registering AJAX: ",H,U,Z);return async(B={})=>{if(typeof window==="undefined"||typeof document==="undefined"){if(D)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let q=z?.apiServer;if(!q){if(D)console.warn("AJAX skipped: apiServer is missing");return}if(!H||!f){if(D)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(Z.includes("sid"))await DU();let Y=new FormData;for(let[J,W]of Object.entries({...U,...B}))Y.append(J,W);for(let J of Z)if(J==="sid"){if(!window.sid)throw new Error("SocketIO isn't initialized properly");Y.append("sid",window.sid)}else{let W=document.getElementsByName(J);if(!W.length){if(D)console.warn(`No input found with name ${J}`);continue}let Q=W[0];if(Q instanceof HTMLInputElement)if(Q.type==="file"&&Q.files)Array.from(Q.files).forEach((O)=>Y.append(J,O));else Y.append(J,Q.value);else if(Q instanceof HTMLTextAreaElement)Y.append(J,Q.value)}let I=q+"api/ajax_content"+H;f(null);let V;for(let J=0;J<=T;J++){if(J>0){let O=P*2**(J-1);if(D)console.log(`AJAX retry ${J}/${T} after ${O}ms`);await new Promise((R)=>setTimeout(R,O))}let W=$!=null?new AbortController:null,Q=W&&setTimeout(()=>W.abort(),$);try{let O=await fetch(I,{method:"POST",body:Y,signal:W?.signal});if(Q)clearTimeout(Q);if(!O.ok&&X.includes(O.status)&&J<T){V=new Error(`HTTP ${O.status}`);continue}let Wf=(O.headers.get("content-type")||"").includes("application/json");if(!!O.body?.getReader&&!Wf){let Qf=O.body.getReader(),MH=new TextDecoder,n="";while(!0){let{done:cf,value:AH}=await Qf.read();if(cf)break;n+=MH.decode(AH,{stream:!0});let TU=n.split(`
|
|
3
|
-
`);n=TU.pop()??"";for(let NH of TU){let hf=NH.trim();if(!hf)continue;try{let yH=JSON.parse(hf);f([yH])}catch{if(
|
|
2
|
+
var EH=Object.create;var{getPrototypeOf:oH,defineProperty:Vf,getOwnPropertyNames:VU,getOwnPropertyDescriptor:mH}=Object,JU=Object.prototype.hasOwnProperty;var YU=(f,U,Z)=>{Z=f!=null?EH(oH(f)):{};let H=U||!f||!f.__esModule?Vf(Z,"default",{value:f,enumerable:!0}):Z;for(let z of VU(f))if(!JU.call(H,z))Vf(H,z,{get:()=>f[z],enumerable:!0});return H},PU=new WeakMap,kH=(f)=>{var U=PU.get(f),Z;if(U)return U;if(U=Vf({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function")VU(f).map((H)=>!JU.call(U,H)&&Vf(U,H,{get:()=>f[H],enumerable:!(Z=mH(f,H))||Z.enumerable}));return PU.set(f,U),U};var jH=(f,U)=>{for(var Z in U)Vf(f,Z,{get:U[Z],enumerable:!0,configurable:!0,set:(H)=>U[Z]=()=>H})};var OZ={};jH(OZ,{useWebApp:()=>df,usePieMittAgentTools:()=>RH,usePieEmit:()=>CU,useOpenAIWebRTC:()=>Yf,useMaxWebApp:()=>vf,useAjaxSubmit:()=>OH,unregisterComponent:()=>FU,submitGlobalForm:()=>SH,registry:()=>g,registerPieComponent:()=>C,registerMultipleComponents:()=>KU,pieName:()=>LH,hasComponent:()=>SU,getRegistrySize:()=>AU,getRegistryEntry:()=>t,getMittAgentTools:()=>$U,getComponentMeta:()=>LU,getAllRegisteredComponents:()=>MU,cn:()=>FH,UnionCard:()=>uU,UIRendererContext:()=>x,UILoading:()=>Ff,UI:()=>w,SessionStorageCard:()=>tU,SequenceCard:()=>kU,SecureStorageCard:()=>ZH,PieTelegramRoot:()=>GH,PieRoot:()=>XH,PieMaxRoot:()=>WH,PieCard:()=>R,PieBaseRoot:()=>qH,PIEBREAK:()=>Cf,IOEventsCard:()=>sU,HiddenCard:()=>cU,HTMLEmbedCard:()=>vU,DeviceStorageCard:()=>eU,CloudStorageCard:()=>UH,BoxCard:()=>TH,AutoRedirectCard:()=>rU,AjaxGroupCard:()=>DH});module.exports=kH(OZ);var u=require("react");var Of=require("react"),d=Of.createContext(null),s=()=>{let f=Of.useContext(d);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},b=()=>{let{apiServer:f}=s();return f},_f=b,v=()=>{let{centrifugeServer:f}=s();return f};var E=()=>{let{enableRenderingLog:f}=s();return f},XU=E,IU=()=>{let{pageProcessor:f}=s();return f};var Cf="__piedemo__";var qU=require("react"),lf=require("centrifuge"),GU=new Map,p=(f,U)=>{if(!U)return null;let Z=`${f}::${U}`,H=GU.get(Z);if(H)return H;async function z(){let D=await fetch(f+"api/centrifuge/gen_token");if(!D.ok){if(D.status===403)throw new lf.Centrifuge.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${D.status}`)}return(await D.json()).token}let T=new lf.Centrifuge(U,{getToken:z});return GU.set(Z,T),T},xH=qU.createContext(null),m=xH;var WU=require("socket.io-client"),QU=require("react"),BU=new Map,c=(f)=>{let U=BU.get(f);if(U)return U;let Z=WU.io(f,{autoConnect:!1,transports:["websocket"]});return BU.set(f,Z),Z},uH=QU.createContext(null),k=uH;var OU=YU(require("mitt")),i=require("react"),rf=null;function j(){if(!rf)rf=OU.default();return rf}var _U=i.createContext(null);function CU(f){let U=i.useContext(_U);return i.useCallback((Z,H)=>{(U??j()).emit(`pie${Z}_${f}`,H)},[f,U])}var N=_U;var dH=({card:f,data:U,children:Z,useSocketioSupport:H=!1,useCentrifugeSupport:z=!1,useMittSupport:T=!1,centrifugeChannel:D=void 0,methods:V=void 0})=>{let $=XU(),P=u.useRef(V);if(P.current=V,$)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:z,mitt:T,centrifugeChannel:D}),console.log("[PieCard] Methods:",V?Object.keys(V):"none"),console.log("[PieCard] Has children:",!!Z);let G=u.useContext(k),B=u.useContext(m),W=u.useContext(N);if(u.useEffect(()=>{if(!G||!H||!P.current||!U.name){if($&&H)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!G,useSocketioSupport:H,hasMethods:!!P.current,hasDataName:!!U?.name});return}let Y=Object.keys(P.current??{}).map((I)=>{let J=`pie${I}_${U.name}`;if($)console.log(`[PieCard] Socket.IO registering event: ${J}`);let Q=(q)=>{P.current?.[I]?.(q)};return G.on(J,Q),[J,Q]});return()=>{Y.forEach(([I,J])=>{if($)console.log(`[PieCard] Socket.IO unregistering event: ${I}`);G.off(I,J)})}},[G,U.name,H]),u.useEffect(()=>{if(!B||!z||!D||!U.name){if($&&z)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!B,useCentrifugeSupport:z,hasCentrifugeChannel:!!D,hasMethods:!!P.current,hasDataName:!!U?.name});return}let Y=Object.keys(P.current??{}).map((I)=>{let J=`pie${I}_${U.name}_${D}`;if($)console.log(`[PieCard] Centrifuge subscribing to channel: ${J}`);let Q=B.newSubscription(J);return Q.on("publication",(q)=>{if($)console.log(`[PieCard] Centrifuge received data on ${J}:`,q.data);P.current?.[I]?.(q.data)}),Q.subscribe(),Q});return()=>{Y.forEach((I)=>{if($)console.log("[PieCard] Centrifuge unsubscribing from channel");I.unsubscribe(),B.removeSubscription(I)})}},[B,D,U.name,z]),u.useEffect(()=>{if(!W||!T||!U.name){if($&&T)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!W,useMittSupport:T,hasMethods:!!P.current,hasDataName:!!U?.name});return}let X=Object.keys(P.current??{}),Y={};return X.forEach((I)=>{let J=`pie${I}_${U.name}`,Q=(q)=>{if($)console.log(`[PieCard] Mitt registering event: ${J}`);P.current?.[I]?.(q)};Y[J]=Q,W.on(J,Q)}),()=>{Object.entries(Y).forEach(([I,J])=>{if($)console.log(`[PieCard] Mitt unregistering event: ${I}`);W.off(I,J)})}},[W,U.name,T]),$)console.log("[PieCard] Rendering complete, returning children");return Z},R=dH;var RU=require("react"),nf=new Map;function wU(f,U){return RU.lazy(()=>{if(nf.has(U))return nf.get(U);let Z=f().then((H)=>H);return nf.set(U,Z),Z})}var g=new Map,bH=(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=wU(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function C(f){let U=bH(f);return g.set(U.name,U),U.component}var KU=(f)=>{f.forEach((U)=>C(U))},FU=(f)=>{g.delete(f)},SU=(f)=>{return g.has(f)},LU=(f)=>{return g.get(f)?.metadata},t=(f)=>{return g.get(f)},MU=()=>{return Array.from(g.keys())},AU=()=>{return g.size};var a=require("react");var NU=require("react"),Rf=require("react/jsx-runtime"),gH=NU.createContext(Rf.jsx(Rf.Fragment,{})),L=gH;var wf=require("react/jsx-runtime");function vH({uiConfig:f,setUiAjaxConfiguration:U}){let Z=a.useContext(L),H=E();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 z=t(f.card);if(!z?.component){if(H)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return Z}if(H)console.log("[UI] Found component in registry:",{name:z.name,isLazy:z.isLazy,hasMetadata:!!z.metadata});let T=z.component,D=wf.jsx(T,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(z.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",z.name);return wf.jsx(a.Suspense,{fallback:z.fallback?wf.jsx(z.fallback,{}):Z,children:D},`${z.name}`)}if(H)console.log("[UI] Rendering component directly:",z.name);return D}var w=a.memo(vH);var Kf=require("react");var yU=require("react"),pH=yU.createContext(null),x=pH;var Jf=require("react/jsx-runtime");function EU({uiConfig:f,setUiAjaxConfiguration:U}){let Z=Kf.useContext(L),H=E();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 z=t(f.card);if(!z?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return Z}if(H)console.log("[UILoading] Found component in registry:",{name:z.name,isLazy:z.isLazy,hasMetadata:!!z.metadata,hasFallback:!!z.fallback});if(z.fallback){if(H)console.log("[UILoading] Rendering fallback for:",z.name);let V=z.fallback;return Jf.jsx(V,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",z.name);let T=z.component,D=Jf.jsx(x.Provider,{value:EU,children:Jf.jsx(T,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(z.isLazy)return Jf.jsx(Kf.Suspense,{fallback:Z,children:D},`${z.name}`);return D}var Ff=EU;var oU=require("react");var Sf=require("react/jsx-runtime"),cH=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H,sx:z}=f,T=oU.useContext(x)??w;return Sf.jsx(R,{card:H,data:f,children:Sf.jsx("div",{style:z,id:H,children:U.map((D,V)=>{return Sf.jsx(T,{uiConfig:D,setUiAjaxConfiguration:Z},`children-${V}`)})})})},mU=cH;var kU=C({name:"SequenceCard",component:mU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var jU=require("react");var sf=require("react/jsx-runtime"),hH=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H}=f,z=jU.useContext(x)??w;return sf.jsx(R,{card:H,data:f,children:U.map((T,D)=>{return sf.jsx(z,{uiConfig:T,setUiAjaxConfiguration:Z},`children-${D}`)})})},xU=hH;var uU=C({name:"UnionCard",component:xU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var Lf=require("react"),dU=YU(require("html-react-parser"));var o=require("react");function lH(){let f=new AudioContext,U=f.createOscillator(),Z=U.connect(f.createMediaStreamDestination());U.start();let H=Z.stream.getAudioTracks()[0];return H.enabled=!1,H}function Yf(f=null,U){let[Z,H]=o.useState(!1),z=o.useRef(null),T=o.useRef(null),D=o.useRef(null),V=o.useCallback(async(B,W=!0)=>{if(z.current)$();let X=new RTCPeerConnection;if(X.onconnectionstatechange=()=>{if(X.connectionState==="connected")H(!0);else if(["disconnected","failed","closed"].includes(X.connectionState))H(!1)},X.ontrack=(_)=>{if(f)f.srcObject=_.streams[0]},W){let _=await navigator.mediaDevices.getUserMedia({audio:!0});X.addTrack(_.getTracks()[0],_)}else{let _=lH();X.addTrack(_)}let Y=X.createDataChannel("oai-events");T.current=Y,D.current=new Promise((_)=>{Y.addEventListener("open",()=>{_()})});let I=await X.createOffer();await X.setLocalDescription(I);let O=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:I.sdp,headers:{Authorization:`Bearer ${B}`,"Content-Type":"application/sdp"}})).text();await X.setRemoteDescription({type:"answer",sdp:O}),z.current=X,await D.current},[f]),$=o.useCallback(()=>{let B=T.current;if(B)B.close();z.current?.getSenders()?.forEach((W)=>W.track?.stop()),z.current?.close(),H(!1),z.current=null,T.current=null,D.current=null},[f]),P=o.useCallback((B)=>{let W=T.current;if(!W){console.error("Data channel is not ready",B);return}let X=new Date().toLocaleTimeString();if(B.event_id=B.event_id||crypto.randomUUID(),W.send(JSON.stringify(B)),!B.timestamp)B.timestamp=X;U?.(B)},[U,f]),G=o.useCallback((B)=>{if(!T.current){console.error("Data channel is not ready");return}let X=()=>{P({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:B}]}}),P({type:"response.create"})};if(D.current)D.current.then(X);else X()},[U,f]);return o.useEffect(()=>{let B=T.current;if(!B)return;let W=(X)=>{let Y=JSON.parse(X.data);if(!Y.timestamp)Y.timestamp=new Date().toLocaleTimeString();U?.(Y)};return B.addEventListener("message",W),()=>{B.removeEventListener("message",W)}},[U,f]),{isSessionActive:Z,startSession:V,stopSession:$,sendTextMessage:G}}var gU=require("react/jsx-runtime"),rH=({data:f})=>{let{html:U,useSocketioSupport:Z,useCentrifugeSupport:H,useMittSupport:z,centrifugeChannel:T}=f,[D,V]=Lf.useState(U),{isSessionActive:$,startSession:P,sendTextMessage:G}=Yf(null,(Y)=>{if(console.log(Y.type,Y.type==="response.output_text.delta"&&Y.delta),Y.type==="response.output_text.delta"&&Y.delta)V((I)=>I+Y.delta)});return Lf.useEffect(()=>{V(U)},[U]),gU.jsx(R,{card:"HTMLEmbedCard",data:f,methods:{update:(Y)=>{V(Y.value)},generateUsingAI:async(Y)=>{try{if(!$&&Y.token)await P(Y.token,!1);G(Y.prompt)}catch(I){console.error("Failed to generate using AI",I)}},initializeAI:async(Y)=>{if(!$&&Y.token)await P(Y.token,!1)}},useCentrifugeSupport:H,useSocketioSupport:Z,useMittSupport:z,centrifugeChannel:T,children:dU.default(D)})},bU=rH;var vU=C({name:"HTMLEmbedCard",component:bU,metadata:{author:"Swarm.ing"}});var Mf=require("react");var tf=require("react/jsx-runtime"),nH=({data:f})=>{let{name:U,value:Z,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:T,centrifugeChannel:D}=f,[V,$]=Mf.useState(Z);return Mf.useEffect(()=>{$(Z)},[Z]),tf.jsx(R,{card:"HiddenCard",data:f,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:T,centrifugeChannel:D,methods:{update:({value:P})=>{$(P)}},children:tf.jsx("input",{type:"hidden",id:U,name:U,value:V})})},pU=nH;var cU=C({name:"HiddenCard",component:pU,metadata:{author:"Swarm.ing"}});var Xf=require("react");var hU=require("react"),sH=hU.createContext(void 0),y=sH;var Af=require("react/jsx-runtime"),iH=({data:f})=>{let{url:U}=f,Z=Xf.useContext(y),H=Xf.useContext(L);return Xf.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else Z?.(U)},[U,Z]),Af.jsx(Af.Fragment,{children:H})},lU=iH;var rU=C({name:"AutoRedirectCard",component:lU,metadata:{author:"Swarm.ing"}});var h=require("react-toastify"),Nf=require("react-toastify");var ff=require("react");var e=require("react/jsx-runtime"),tH={bounce:h.Bounce,slide:h.Slide,zoom:h.Zoom,flip:h.Flip},aH=(f)=>{let U={...f,type:f.alertType,transition:f.transition?tH[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};Nf.toast(f.message,U)},eH=(f)=>{console.log("Log event",f)},fZ=(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)}},Z=window.Notification.permission;if(Z==="granted"){U();return}if(Z==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((H)=>{if(H==="granted")U()})},UZ=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:Z,useMittSupport:H,centrifugeChannel:z}=f,T=ff.useContext(y),D=ff.useRef(T);D.current=T;let V=ff.useMemo(()=>({alert:aH,log:eH,push:fZ,redirect:($)=>{if($.to){let P=$.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(P))window.location.href=P;else D.current?.(P)}else window.location.reload()},reload:($)=>{if($.to){let P=$.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(P))window.location.href=P;else D.current?.(P)}else window.location.reload()}}),[]);return e.jsx(e.Fragment,{children:e.jsx(R,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:Z,useMittSupport:H,centrifugeChannel:z,methods:V,children:e.jsx(Nf.ToastContainer,{})})})},nU=UZ;var sU=C({name:"IOEventsCard",component:nU,metadata:{author:"Swarm.ing"}});var If=require("react");var af=require("react/jsx-runtime"),HZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=If.useState(H);return If.useEffect(()=>{P(H)},[H]),If.useEffect(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(Z,$)},[Z,$]),af.jsx(R,{card:"SessionStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{sessionStorage.removeItem(Z),P("")}},children:af.jsx("input",{type:"hidden",id:U,name:U,value:$})})},iU=HZ;var tU=C({name:"SessionStorageCard",component:iU,metadata:{author:"PieData"}});var Gf=require("react");var ef=require("react/jsx-runtime"),ZZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=Gf.useState(H);return Gf.useEffect(()=>{P(H)},[H]),Gf.useEffect(()=>{if(typeof window==="undefined")return;localStorage.setItem(Z,$)},[Z,$]),ef.jsx(R,{card:"DeviceStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{localStorage.removeItem(Z),P("")}},children:ef.jsx("input",{type:"hidden",id:U,name:U,value:$})})},aU=ZZ;var eU=C({name:"DeviceStorageCard",component:aU,metadata:{author:"PieData"}});var qf=require("react");var fU=require("react/jsx-runtime"),zZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=qf.useState(H);return qf.useEffect(()=>{P(H)},[H]),qf.useEffect(()=>{if(typeof window==="undefined")return;let G=window.Telegram?.WebApp?.CloudStorage;if(!G)return;G.setItem(Z,$)},[Z,$]),fU.jsx(R,{card:"CloudStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{let G=window.Telegram?.WebApp?.CloudStorage;if(G)G.removeItem(Z);P("")}},children:fU.jsx("input",{type:"hidden",id:U,name:U,value:$})})},fH=zZ;var UH=C({name:"CloudStorageCard",component:fH,metadata:{author:"PieData"}});var Bf=require("react");var UU=require("react/jsx-runtime"),DZ=({data:f})=>{let{name:U,key:Z,value:H,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=Bf.useState(H);return Bf.useEffect(()=>{P(H)},[H]),Bf.useEffect(()=>{if(typeof window==="undefined")return;let G=window.Telegram?.WebApp?.SecureStorage;if(!G)return;G.setItem(Z,$)},[Z,$]),UU.jsx(R,{card:"SecureStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{let G=window.Telegram?.WebApp?.SecureStorage;if(G)G.removeItem(Z);P("")}},children:UU.jsx("input",{type:"hidden",id:U,name:U,value:$})})},HH=DZ;var ZH=C({name:"SecureStorageCard",component:HH,metadata:{author:"PieData"}});var M=require("react");var HU=require("react/jsx-runtime"),$Z=({data:f,content:U})=>{let{useLoader:Z,noReturn:H,returnType:z,useSocketioSupport:T,useCentrifugeSupport:D,useMittSupport:V,centrifugeChannel:$}=f,P=M.useContext(L),G=M.useContext(x)??w,[B,W]=M.useState(!1),[X,Y]=M.useState(null),I=M.useRef(U),J=M.useContext(N),Q=M.useCallback((_)=>{if(_===null)W(!0);else if(W(!1),!H)I.current=_;if(!H)Y(_)},[H]),q=M.useCallback((_)=>{I.current=_.content,Y(_.content)},[]),O=M.useCallback((_)=>{if(_===null)W(!0);else if(W(!1),!H)for(let Wf of _)J?.emit(Wf.name,Wf.data)},[H,J]);if(M.useEffect(()=>{Y(U),W(!1)},[U]),!X&&Z)return P;return HU.jsx(R,{card:"AjaxGroupCard",data:f,methods:{changeContent:q},useSocketioSupport:T,useCentrifugeSupport:D,useMittSupport:V,centrifugeChannel:$,children:HU.jsx(G,{uiConfig:X??I.current,setUiAjaxConfiguration:z==="events"?O:Q})})},zH=$Z;var DH=C({name:"AjaxGroupCard",component:zH,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var ZU=require("react");var yf=require("react/jsx-runtime"),TZ=({data:f,content:U,setUiAjaxConfiguration:Z})=>{let{name:H,url:z,sx:T}=f,D=ZU.useContext(y),V=ZU.useContext(x)??w;return yf.jsx(R,{card:H,data:f,children:yf.jsx("div",{style:T,id:H,onClick:(P)=>{if(z)if(P.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(z))window.location.href=z;else D?.(z)},children:yf.jsx(V,{setUiAjaxConfiguration:Z,uiConfig:U})})})},$H=TZ;var TH=C({name:"BoxCard",component:$H,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var Hf=require("react"),Zf=require("@tanstack/react-query");var jf=require("react");var mf=require("react"),Ef=new Map,of=new Map;function kf(f,U){let Z=`${f}::${U}`,H=f?Ef.get(Z):void 0,[z,T]=mf.useState(H??null);return mf.useEffect(()=>{if(!f)return;if(Ef.has(Z)){T(Ef.get(Z));return}let D=of.get(Z);if(!D)D=fetch(f+`api/support/${U}`,{method:"GET"}).then(($)=>$.json()).then(($)=>{return Ef.set(Z,$),of.delete(Z),$}).catch(($)=>{throw of.delete(Z),$}),of.set(Z,D);let V=!1;return D.then(($)=>{if(!V)T($)}).catch(()=>{}),()=>{V=!0}},[f,U,Z]),z}var zU=null,PH=null;function VH(){PH?.()}function DU(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!zU)zU=new Promise((f)=>{PH=()=>{f()}});return zU}var PZ=({children:f})=>{let U=jf.useContext(k),Z=_f(),H=kf(Z,"socketIO"),z=(T)=>{if(typeof window!=="undefined")window.sid=T.sid,VH(),console.log(`SocketIO initialized: ${window.sid}`)};return jf.useEffect(()=>{if(!U)return;let T=()=>{console.log("SocketIO connected")},D=(V)=>{console.log(`SocketIO disconnected: ${V}`),U.connect()};if(H)U.on("pieinit",z),U.on("connect",T),U.on("disconnect",D),U.connect();return()=>{if(H)U.off("pieinit",z),U.off("connect",T),U.off("disconnect",D),U.disconnect()}},[U,H]),f},l=PZ;var xf=require("react");var VZ=({children:f})=>{let U=xf.useContext(m),Z=_f(),H=kf(Z,"centrifuge");return xf.useEffect(()=>{if(!U)return;let z=()=>{console.log("Centrifuge connected")},T=(D)=>{console.log("Centrifuge disconnected:",D)};if(H)U.on("connected",z),U.on("disconnected",T),U.connect();return()=>{if(H)U.disconnect()}},[U,H]),f},r=VZ;var YH=require("axios-date-transformer");var JH=require("react/jsx-runtime");function Uf(f,U,Z){if(!U)return Z;let H=f.replace(/^\//,""),z=U[H];if(!z)return Z;return JH.jsx(Ff,{uiConfig:z})}var K=require("react/jsx-runtime"),JZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z,disableGlobalForm:T})=>{let D=b(),V=v(),$=E(),P=Hf.useMemo(()=>YH.createAxiosDateTransformer({baseURL:D||""}),[D]),G=Hf.useMemo(()=>j(),[]),B=Hf.useMemo(()=>D?c(D):null,[D]),W=Hf.useMemo(()=>D?p(D,V):null,[D,V]),{data:X,isLoading:Y,error:I}=Zf.useQuery({queryKey:["uiConfig",f.pathname+f.search,D],enabled:!!D,queryFn:async()=>{let Q=new URLSearchParams(f.search);Q.set("__pieroot","web");let q="/api/content"+f.pathname+"?"+Q.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",q);let O=await P.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:",O.data);return O.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(Q)=>Math.min(1000*2**Q,30000),...z}),J=Uf(f.pathname,Z,U);if(!D)return J??null;if($)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",D),console.log("[PieRoot] CENTRIFUGE_SERVER:",V),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!Z);if(I){if($)console.error("[PieRoot] Error fetching UI configuration:",I),console.error("[PieRoot] Error details:",{message:I.message,status:I.response?.status,data:I.response?.data});return H?.(),J}if(Y||!X){if($)console.log("[PieRoot] Loading state:",{isLoading:Y,hasUiConfiguration:!!X});return J}if($)console.log("[PieRoot] UI configuration loaded successfully:",X),console.log("[PieRoot] Rendering UI with configuration");return K.jsx(N.Provider,{value:G,children:K.jsx(k.Provider,{value:B,children:K.jsx(m.Provider,{value:W,children:K.jsx(L.Provider,{value:U??K.jsx(K.Fragment,{}),children:K.jsx(l,{children:K.jsx(r,{children:T?K.jsx(w,{uiConfig:X}):K.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:K.jsx(w,{uiConfig:X})})})})})})})})},YZ=(f)=>{let U=Hf.useMemo(()=>new Zf.QueryClient,[]);return K.jsx(y.Provider,{value:f.onNavigate,children:K.jsx(d.Provider,{value:f.config,children:K.jsx(Zf.QueryClientProvider,{client:U,children:K.jsx(JZ,{...f})})})})},XH=YZ;var zf=require("react"),Df=require("@tanstack/react-query");var IH=require("axios-date-transformer");var uf=require("react");var df=({onError:f}={})=>{let[U,Z]=uf.useState(null),H=IU();return uf.useEffect(()=>{if(typeof window==="undefined")return;let z=window.Telegram?.WebApp;if(!z)return;try{z.ready?.()}catch(T){f?.()}if(H==="telegram_expanded"&&(z.platform==="ios"||z.platform==="android"))z.expand();Z(z)},[]),U};var F=require("react/jsx-runtime"),XZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z,disableGlobalForm:T})=>{let D=b(),V=v(),$=E(),P=zf.useMemo(()=>IH.createAxiosDateTransformer({baseURL:D}),[D]),G=zf.useMemo(()=>j(),[]),B=zf.useMemo(()=>D?c(D):null,[D]),W=zf.useMemo(()=>D?p(D,V):null,[D,V]),X=df({onError:H}),{data:Y,isLoading:I,error:J}=Df.useQuery({queryKey:["uiConfig",f.pathname+f.search,X?.initData],enabled:!!X?.initData,queryFn:async()=>{let q=new URLSearchParams(f.search);if(q.set("__pieroot","telegram"),X?.initData)q.set("initData",X.initData);let O="/api/content"+f.pathname+"?"+q.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",O);let _=await P.get(O,{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:",_.data);return _.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(q)=>Math.min(1000*2**q,30000),...z}),Q=Uf(f.pathname,Z,U);if(!D)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(J&&$)return console.error("[PieRoot] Error fetching UI configuration:",J),console.error("[PieRoot] Error details:",{message:J.message,status:J.response?.status,data:J.response?.data}),H?.(),Q;if(I||!Y){if($)console.log("[PieRoot] Loading state:",{isLoading:I,hasUiConfiguration:!!Y});return Q}if($)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return F.jsx(N.Provider,{value:G,children:F.jsx(k.Provider,{value:B,children:F.jsx(m.Provider,{value:W,children:F.jsx(L.Provider,{value:U??F.jsx(F.Fragment,{}),children:F.jsx(l,{children:F.jsx(r,{children:T?F.jsx(w,{uiConfig:Y}):F.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:F.jsx(w,{uiConfig:Y})})})})})})})})},IZ=(f)=>{let U=zf.useMemo(()=>new Df.QueryClient,[]);return F.jsx(y.Provider,{value:f.onNavigate,children:F.jsx(d.Provider,{value:f.config,children:F.jsx(Df.QueryClientProvider,{client:U,children:F.jsx(XZ,{...f})})})})},GH=IZ;var $f=require("react"),bf=require("@tanstack/react-query");var A=require("react/jsx-runtime"),GZ=({location:f,fallback:U,children:Z,disableGlobalForm:H})=>{let z=b(),T=v(),D=E(),V=$f.useMemo(()=>j(),[]),$=$f.useMemo(()=>z?c(z):null,[z]),P=$f.useMemo(()=>z?p(z,T):null,[z,T]);if(D)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);return A.jsx(N.Provider,{value:V,children:A.jsx(k.Provider,{value:$,children:A.jsx(m.Provider,{value:P,children:A.jsx(L.Provider,{value:U??A.jsx(A.Fragment,{}),children:A.jsx(l,{children:A.jsx(r,{children:H?Z:A.jsx("form",{id:"piedata_global_form",action:z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:Z})})})})})})})},qZ=(f)=>{let[U]=$f.useState(()=>new bf.QueryClient);return A.jsx(y.Provider,{value:f.onNavigate,children:A.jsx(d.Provider,{value:f.config,children:A.jsx(bf.QueryClientProvider,{client:U,children:A.jsx(GZ,{...f})})})})},qH=qZ;var Tf=require("react"),Pf=require("@tanstack/react-query");var BH=require("axios-date-transformer");var gf=require("react"),vf=()=>{let[f,U]=gf.useState(null);return gf.useEffect(()=>{if(typeof window==="undefined")return;let Z=window.WebApp;if(!Z)return;Z.ready(),U(Z)},[]),f};var S=require("react/jsx-runtime"),BZ=({location:f,fallback:U,piecache:Z,onError:H,queryOptions:z,disableGlobalForm:T})=>{let D=b(),V=v(),$=E(),P=Tf.useMemo(()=>BH.createAxiosDateTransformer({baseURL:D}),[D]),G=Tf.useMemo(()=>j(),[]),B=Tf.useMemo(()=>D?c(D):null,[D]),W=Tf.useMemo(()=>D?p(D,V):null,[D,V]),X=vf(),{data:Y,isLoading:I,error:J}=Pf.useQuery({queryKey:["uiConfig",f.pathname+f.search,X?.initData],queryFn:async()=>{let q=new URLSearchParams(f.search);if(q.set("__pieroot","max"),X?.initData)q.set("initData",X.initData);let O="/api/content"+f.pathname+"?"+q.toString();if($)console.log("[PieRoot] Fetching UI configuration from:",O);let _=await P.get(O,{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:",_.data);return _.data},enabled:!!X?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(q)=>Math.min(1000*2**q,30000),...z}),Q=Uf(f.pathname,Z,U);if(!D)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(J&&$)return console.error("[PieRoot] Error fetching UI configuration:",J),console.error("[PieRoot] Error details:",{message:J.message,status:J.response?.status,data:J.response?.data}),H?.(),Q;if(I||!Y){if($)console.log("[PieRoot] Loading state:",{isLoading:I,hasUiConfiguration:!!Y});return Q}if($)console.log("[PieRoot] UI configuration loaded successfully:",Y),console.log("[PieRoot] Rendering UI with configuration");return S.jsx(N.Provider,{value:G,children:S.jsx(k.Provider,{value:B,children:S.jsx(m.Provider,{value:W,children:S.jsx(L.Provider,{value:U??S.jsx(S.Fragment,{}),children:S.jsx(l,{children:S.jsx(r,{children:T?S.jsx(w,{uiConfig:Y}):S.jsx("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:S.jsx(w,{uiConfig:Y})})})})})})})})},WZ=(f)=>{let U=Tf.useMemo(()=>new Pf.QueryClient,[]);return S.jsx(y.Provider,{value:f.onNavigate,children:S.jsx(d.Provider,{value:f.config,children:S.jsx(Pf.QueryClientProvider,{client:U,children:S.jsx(BZ,{...f})})})})},WH=WZ;var QH=require("react"),QZ=(f,U={},Z=[],H,z)=>{let T=z?.renderingLogEnabled??!1,D=z?.timeout,V=z?.retryPolicy,$=V?.maxRetries??0,P=V?.baseDelay??1000,G=V?.retryOn??[502,503,504];if(T)console.log("Registering AJAX: ",H,U,Z);return async(B={})=>{if(typeof window==="undefined"||typeof document==="undefined"){if(T)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let W=z?.apiServer;if(!W){if(T)console.warn("AJAX skipped: apiServer is missing");return}if(!H||!f){if(T)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(Z.includes("sid"))await DU();let X=new FormData;for(let[J,Q]of Object.entries({...U,...B}))X.append(J,Q);for(let J of Z)if(J==="sid"){if(!window.sid)throw new Error("SocketIO isn't initialized properly");X.append("sid",window.sid)}else{let Q=document.getElementsByName(J);if(!Q.length){if(T)console.warn(`No input found with name ${J}`);continue}let q=Q[0];if(q instanceof HTMLInputElement)if(q.type==="file"&&q.files)Array.from(q.files).forEach((O)=>X.append(J,O));else X.append(J,q.value);else if(q instanceof HTMLTextAreaElement)X.append(J,q.value)}let Y=W+"api/ajax_content"+H;f(null);let I;for(let J=0;J<=$;J++){if(J>0){let O=P*2**(J-1);if(T)console.log(`AJAX retry ${J}/${$} after ${O}ms`);await new Promise((_)=>setTimeout(_,O))}let Q=D!=null?new AbortController:null,q=Q&&setTimeout(()=>Q.abort(),D);try{let O=await fetch(Y,{method:"POST",body:X,signal:Q?.signal});if(q)clearTimeout(q);if(!O.ok&&G.includes(O.status)&&J<$){I=new Error(`HTTP ${O.status}`);continue}let Wf=(O.headers.get("content-type")||"").includes("application/json");if(!!O.body?.getReader&&!Wf){let Qf=O.body.getReader(),MH=new TextDecoder,n="";while(!0){let{done:cf,value:AH}=await Qf.read();if(cf)break;n+=MH.decode(AH,{stream:!0});let TU=n.split(`
|
|
3
|
+
`);n=TU.pop()??"";for(let NH of TU){let hf=NH.trim();if(!hf)continue;try{let yH=JSON.parse(hf);f([yH])}catch{if(T)console.warn("Failed to parse streamed line:",hf)}}}if(n.trim())try{let cf=JSON.parse(n);f([cf])}catch{if(T)console.warn("Failed to parse final streamed line:",n)}return{}}else{let Qf=await O.json();return f(Qf),Qf}}catch(O){if(q)clearTimeout(q);if(I=O,J<$)continue;if(T)console.error("AJAX request failed:",O);return f(null),O}}if(T)console.error("AJAX request failed after retries:",I);return f(null),I}},OH=(f,U={},Z=[],H,z)=>{let{apiServer:T,enableRenderingLog:D}=s(),V=JSON.stringify(U),$=JSON.stringify(Z),P=JSON.stringify(z);return QH.useMemo(()=>QZ(f,U,Z,H,{apiServer:T,renderingLogEnabled:D,timeout:z?.timeout,retryPolicy:z?.retryPolicy}),[f,V,$,H,T,D,P])};var _H=require("@openai/agents"),pf=require("react");var CH=/^pie(.+?)_(.+)$/;function $U(f=j(),U={}){let Z=[],H=new Set;for(let z of f.all.keys()){if(typeof z!=="string")continue;let T=z.match(CH);if(!T)continue;let[,D,V]=T,$={methodName:D,cardName:V,eventName:z};if(U.filter&&!U.filter($))continue;let P=U.nameFor?.($)??`${V}_${D}`;if(H.has(P))continue;H.add(P);let G=U.describe?.($)??`Invokes the "${D}" method on the PieCard "${V}" by emitting the in-process mitt event "${z}". The optional "payload" argument is forwarded verbatim to the card's handler.`;Z.push(_H.tool({name:P,description:G,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(B)=>{let W=B?.payload;return f.emit(z,W),`Emitted "${z}"`}}))}return Z}function RH(f={}){let Z=pf.useContext(N)??j(),H=[];for(let $ of Z.all.keys())if(typeof $==="string"&&CH.test($))H.push($);H.sort();let z=H.join("|"),{filter:T,describe:D,nameFor:V}=f;return pf.useMemo(()=>$U(Z,{filter:T,describe:D,nameFor:V}),[Z,z,T,D,V])}var wH=require("clsx"),KH=require("tailwind-merge");function FH(...f){return KH.twMerge(wH.clsx(f))}var SH=()=>{if(typeof document==="undefined")return;let f=document.getElementById("piedata_global_form");f&&f.submit()};var LH=(f,U)=>`${f}${Cf}${U}`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for `getAjaxSubmit` from `util/ajaxCommonUtils.ts`.
|
|
3
|
+
*
|
|
4
|
+
* `getAjaxSubmit` is a plain factory function (no React hooks) that builds
|
|
5
|
+
* the async submit callback used by `AjaxGroupCard` and similar containers.
|
|
6
|
+
* It contains several guard clauses that short-circuit execution when required
|
|
7
|
+
* arguments are absent — each of those is tested here so regressions in the
|
|
8
|
+
* guard logic surface immediately without needing a full render tree.
|
|
9
|
+
*
|
|
10
|
+
* Tests that require actual HTTP calls or DOM form collection belong in an
|
|
11
|
+
* integration layer; this file focuses on the observable API surface of the
|
|
12
|
+
* factory itself.
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=ajaxCommonUtils.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ajaxCommonUtils.test.d.ts","sourceRoot":"","sources":["../../src/tests/ajaxCommonUtils.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for `trackLazy` and `preloadComponent` from `util/lazy.ts`.
|
|
3
|
+
*
|
|
4
|
+
* These utilities wrap React.lazy with a shared module-promise cache keyed by
|
|
5
|
+
* component name. The cache prevents redundant network requests when the same
|
|
6
|
+
* lazy component mounts, unmounts, and remounts — or when a manual preload
|
|
7
|
+
* races an initial render.
|
|
8
|
+
*
|
|
9
|
+
* Note: React.lazy components can only be *rendered* inside a Suspense
|
|
10
|
+
* boundary, so these tests verify the caching contract and API shape rather
|
|
11
|
+
* than the rendered output.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=lazy.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.test.d.ts","sourceRoot":"","sources":["../../src/tests/lazy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the `pieName` utility.
|
|
3
|
+
*
|
|
4
|
+
* `pieName(name, child)` builds a composite component identifier using the
|
|
5
|
+
* PieUI-internal separator constant (PIEBREAK = '__piedemo__'). This naming
|
|
6
|
+
* convention is shared between the runtime renderer and server-side UI-config
|
|
7
|
+
* generators, so any drift in the output format would cause silent mismatches
|
|
8
|
+
* in production. These tests pin the exact output so regressions surface
|
|
9
|
+
* immediately.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=pieName.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pieName.test.d.ts","sourceRoot":"","sources":["../../src/tests/pieName.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for `waitForSidAvailable` and `markSidAvailable` from
|
|
3
|
+
* `util/waitForSidAvailable.ts`.
|
|
4
|
+
*
|
|
5
|
+
* These utilities coordinate the moment when a Socket.IO session ID (`sid`)
|
|
6
|
+
* becomes available on `window.sid` after the WebSocket handshake completes.
|
|
7
|
+
* Instead of polling, the module exposes a Promise singleton that resolves
|
|
8
|
+
* exactly once when `markSidAvailable()` is called by `SocketIOInitProvider`.
|
|
9
|
+
*
|
|
10
|
+
* Testing strategy:
|
|
11
|
+
* - When `window.sid` is already defined the function must resolve immediately.
|
|
12
|
+
* - `markSidAvailable` must resolve any in-flight promise.
|
|
13
|
+
* - The function must return a Promise (not throw synchronously).
|
|
14
|
+
* - Both exports must be callable without crashing.
|
|
15
|
+
*
|
|
16
|
+
* Important: the module stores its promise singleton at module scope, so tests
|
|
17
|
+
* that set `window.sid` clean up after themselves to avoid leaking state.
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=waitForSidAvailable.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForSidAvailable.test.d.ts","sourceRoot":"","sources":["../../src/tests/waitForSidAvailable.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
|