@swarm.ing/pieui 2.0.20 → 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 CHANGED
@@ -107,16 +107,20 @@ Create a blank Next.js web app template with PieUI CLI:
107
107
 
108
108
  ```sh
109
109
  bunx pieui create-pie-app my-pie-app
110
+ # or alias:
111
+ bunx pieui create-pieui my-pie-app
110
112
  ```
111
113
 
112
114
  This command:
113
115
 
114
116
  - runs `bun create next-app@latest my-pie-app --yes`
115
- - copies a standard `_shared` folder into the new app (sourced from `ai-exchange-bot`)
117
+ - copies a standard `_shared` folder into the new app (sourced from `ai-exchange-bot` when found)
116
118
  - rewrites `dev/build/start` scripts to `bun --bun next ...`
117
119
  - appends a TODO marker in `app/page.tsx` for future backend (Python Unicorn) linking
118
120
 
119
- If the `_shared` source cannot be found automatically, set:
121
+ If the `_shared` source cannot be found automatically, PieUI now creates a fallback `_shared/simple.tsx` scaffold and continues.
122
+
123
+ To force a specific shared source, set:
120
124
 
121
125
  ```sh
122
126
  PIEUI_SHARED_TEMPLATE_DIR=/absolute/path/to/_shared bunx pieui create-pie-app my-pie-app
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieBaseRoot/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAwD1C;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CAY3C,CAAA;AAED,eAAe,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieBaseRoot/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AA6D1C;;;;;;;;;;GAUG;AACH,QAAA,MAAM,WAAW,GAAI,OAAO,gBAAgB,4CAY3C,CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieMaxRoot/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA8K/C;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAYtC,CAAA;AAED,eAAe,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieMaxRoot/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAmL/C;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAYtC,CAAA;AAED,eAAe,UAAU,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieRoot/index.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AA8KtC;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,OAAO,GAAI,OAAO,YAAY,4CAYnC,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieRoot/index.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAmLtC;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,OAAO,GAAI,OAAO,YAAY,4CAYnC,CAAA;AAED,eAAe,OAAO,CAAA"}
@@ -45,5 +45,12 @@ export interface PieRootProps {
45
45
  config: PieConfig;
46
46
  /** Optional react-query overrides; see {@link PieQueryOptions}. */
47
47
  queryOptions?: PieQueryOptions;
48
+ /**
49
+ * When `true`, the implicit `<form id="piedata_global_form">` wrapper is
50
+ * not rendered. Use this when the host application owns its own form
51
+ * element or when PieUI is embedded inside another form and a nested
52
+ * `<form>` would be invalid HTML.
53
+ */
54
+ disableGlobalForm?: boolean;
48
55
  }
49
56
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/PieRoot/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAElC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAC9B,eAAe,CAAC,YAAY,EAAE,UAAU,CAAC,EACzC,UAAU,GAAG,SAAS,GAAG,SAAS,CACrC,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;;;;OAKG;IACH,QAAQ,EAAE;QACN,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;KACjB,CAAA;IACD;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACvC,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,oEAAoE;IACpE,MAAM,EAAE,SAAS,CAAA;IACjB,mEAAmE;IACnE,YAAY,CAAC,EAAE,eAAe,CAAA;CACjC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/PieRoot/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAElC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,IAAI,CAC9B,eAAe,CAAC,YAAY,EAAE,UAAU,CAAC,EACzC,UAAU,GAAG,SAAS,GAAG,SAAS,CACrC,CAAA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB;;;;;OAKG;IACH,QAAQ,EAAE;QACN,QAAQ,EAAE,MAAM,CAAA;QAChB,MAAM,EAAE,MAAM,CAAA;KACjB,CAAA;IACD;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACvC,wDAAwD;IACxD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,oEAAoE;IACpE,MAAM,EAAE,SAAS,CAAA;IACjB,mEAAmE;IACnE,YAAY,CAAC,EAAE,eAAe,CAAA;IAC9B;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieTelegramRoot/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAgL/C;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAY3C,CAAA;AAED,eAAe,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PieTelegramRoot/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAOtC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAqL/C;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAY3C,CAAA;AAED,eAAe,eAAe,CAAA"}
package/dist/index.esm.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use client";
2
- import{useContext as Vf,useEffect as If,useRef as MU}from"react";import{createContext as BU,useContext as WU}from"react";var j=BU(null),h=()=>{let f=WU(j);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},x=()=>{let{apiServer:f}=h();return f},e=x,d=()=>{let{centrifugeServer:f}=h();return f};var L=()=>{let{enableRenderingLog:f}=h();return f},Lf=L,Mf=()=>{let{pageProcessor:f}=h();return f};var Gf="__piedemo__";import{createContext as QU}from"react";import{Centrifuge as Af}from"centrifuge";var Nf=new Map,u=(f,U)=>{if(!U)return null;let D=`${f}::${U}`,H=Nf.get(D);if(H)return H;async function z(){let $=await fetch(f+"api/centrifuge/gen_token");if(!$.ok){if($.status===403)throw new Af.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${$.status}`)}return(await $.json()).token}let Z=new Af(U,{getToken:z});return Nf.set(D,Z),Z},CU=QU(null),y=CU;import{io as OU}from"socket.io-client";import{createContext as _U}from"react";var yf=new Map,b=(f)=>{let U=yf.get(f);if(U)return U;let D=OU(f,{autoConnect:!1,transports:["websocket"]});return yf.set(f,D),D},RU=_U(null),o=RU;import wU from"mitt";import{createContext as FU,useCallback as KU,useContext as SU}from"react";var Pf=null;function E(){if(!Pf)Pf=wU();return Pf}var of=FU(null);function LU(f){let U=SU(of);return KU((D,H)=>{(U??E()).emit(`pie${D}_${f}`,H)},[f,U])}var K=of;var AU=({card:f,data:U,children:D,useSocketioSupport:H=!1,useCentrifugeSupport:z=!1,useMittSupport:Z=!1,centrifugeChannel:$=void 0,methods:G=void 0})=>{let T=Lf(),P=MU(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:Z,centrifugeChannel:$}),console.log("[PieCard] Methods:",G?Object.keys(G):"none"),console.log("[PieCard] Has children:",!!D);let X=Vf(o),B=Vf(y),q=Vf(K);if(If(()=>{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]),If(()=>{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]),If(()=>{if(!q||!Z||!U.name){if(T&&Z)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!q,useMittSupport:Z,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,Z]),T)console.log("[PieCard] Rendering complete, returning children");return D},_=AU;import{lazy as NU}from"react";var Jf=new Map;function Ef(f,U){return NU(()=>{if(Jf.has(U))return Jf.get(U);let D=f().then((H)=>H);return Jf.set(U,D),D})}var g=new Map,yU=(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=Ef(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function O(f){let U=yU(f);return g.set(U.name,U),U.component}var oU=(f)=>{f.forEach((U)=>O(U))},EU=(f)=>{g.delete(f)},mU=(f)=>{return g.has(f)},kU=(f)=>{return g.get(f)?.metadata},r=(f)=>{return g.get(f)},jU=()=>{return Array.from(g.keys())},xU=()=>{return g.size};import{Suspense as vU,useContext as pU,memo as cU}from"react";import{createContext as dU}from"react";import{jsx as gU,Fragment as bU}from"react/jsx-runtime";var uU=dU(gU(bU,{})),w=uU;import{jsx as Yf}from"react/jsx-runtime";function hU({uiConfig:f,setUiAjaxConfiguration:U}){let D=pU(w),H=L();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=r(f.card);if(!z?.component){if(H)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return D}if(H)console.log("[UI] Found component in registry:",{name:z.name,isLazy:z.isLazy,hasMetadata:!!z.metadata});let Z=z.component,$=Yf(Z,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(z.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",z.name);return Yf(vU,{fallback:z.fallback?Yf(z.fallback,{}):D,children:$},`${z.name}`)}if(H)console.log("[UI] Rendering component directly:",z.name);return $}var F=cU(hU);import{Suspense as nU,useContext as sU}from"react";import{createContext as lU}from"react";var rU=lU(null),k=rU;import{jsx as ff}from"react/jsx-runtime";function mf({uiConfig:f,setUiAjaxConfiguration:U}){let D=sU(w),H=L();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=r(f.card);if(!z?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return D}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 ff(G,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",z.name);let Z=z.component,$=ff(k.Provider,{value:mf,children:ff(Z,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(z.isLazy)return ff(nU,{fallback:D,children:$},`${z.name}`);return $}var Xf=mf;import{useContext as iU}from"react";import{jsx as qf}from"react/jsx-runtime";var tU=({data:f,content:U,setUiAjaxConfiguration:D})=>{let{name:H,sx:z}=f,Z=iU(k)??F;return qf(_,{card:H,data:f,children:qf("div",{style:z,id:H,children:U.map(($,G)=>{return qf(Z,{uiConfig:$,setUiAjaxConfiguration:D},`children-${G}`)})})})},kf=tU;var aU=O({name:"SequenceCard",component:kf,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as eU}from"react";import{jsx as jf}from"react/jsx-runtime";var fH=({data:f,content:U,setUiAjaxConfiguration:D})=>{let{name:H}=f,z=eU(k)??F;return jf(_,{card:H,data:f,children:U.map((Z,$)=>{return jf(z,{uiConfig:Z,setUiAjaxConfiguration:D},`children-${$}`)})})},xf=fH;var UH=O({name:"UnionCard",component:xf,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});import{useEffect as DH,useState as $H}from"react";import TH from"html-react-parser";import{useCallback as Uf,useEffect as HH,useRef as Bf,useState as ZH}from"react";function zH(){let f=new AudioContext,U=f.createOscillator(),D=U.connect(f.createMediaStreamDestination());U.start();let H=D.stream.getAudioTracks()[0];return H.enabled=!1,H}function Hf(f=null,U){let[D,H]=ZH(!1),z=Bf(null),Z=Bf(null),$=Bf(null),G=Uf(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=zH();Y.addTrack(R)}let I=Y.createDataChannel("oai-events");Z.current=I,$.current=new Promise((R)=>{I.addEventListener("open",()=>{R()})});let V=await Y.createOffer();await Y.setLocalDescription(V);let C=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:C}),z.current=Y,await $.current},[f]),T=Uf(()=>{let B=Z.current;if(B)B.close();z.current?.getSenders()?.forEach((q)=>q.track?.stop()),z.current?.close(),H(!1),z.current=null,Z.current=null,$.current=null},[f]),P=Uf((B)=>{let q=Z.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=Uf((B)=>{if(!Z.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 HH(()=>{let B=Z.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:D,startSession:G,stopSession:T,sendTextMessage:X}}import{jsx as PH}from"react/jsx-runtime";var GH=({data:f})=>{let{html:U,useSocketioSupport:D,useCentrifugeSupport:H,useMittSupport:z,centrifugeChannel:Z}=f,[$,G]=$H(U),{isSessionActive:T,startSession:P,sendTextMessage:X}=Hf(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 DH(()=>{G(U)},[U]),PH(_,{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:D,useMittSupport:z,centrifugeChannel:Z,children:TH($)})},df=GH;var VH=O({name:"HTMLEmbedCard",component:df,metadata:{author:"Swarm.ing"}});import{useEffect as IH,useState as JH}from"react";import{jsx as uf}from"react/jsx-runtime";var YH=({data:f})=>{let{name:U,value:D,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:$}=f,[G,T]=JH(D);return IH(()=>{T(D)},[D]),uf(_,{card:"HiddenCard",data:f,useSocketioSupport:H,useCentrifugeSupport:z,useMittSupport:Z,centrifugeChannel:$,methods:{update:({value:P})=>{T(P)}},children:uf("input",{type:"hidden",id:U,name:U,value:G})})},bf=YH;var XH=O({name:"HiddenCard",component:bf,metadata:{author:"Swarm.ing"}});import{useContext as gf,useEffect as WH}from"react";import{createContext as qH}from"react";var BH=qH(void 0),S=BH;import{jsx as OH,Fragment as CH}from"react/jsx-runtime";var QH=({data:f})=>{let{url:U}=f,D=gf(S),H=gf(w);return WH(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else D?.(U)},[U,D]),OH(CH,{children:H})},vf=QH;var _H=O({name:"AutoRedirectCard",component:vf,metadata:{author:"Swarm.ing"}});import{Bounce as RH,Slide as wH,Zoom as FH,Flip as KH}from"react-toastify";import{toast as SH,ToastContainer as LH}from"react-toastify";import{useContext as MH,useMemo as AH,useRef as NH}from"react";import{jsx as Wf,Fragment as jH}from"react/jsx-runtime";var yH={bounce:RH,slide:wH,zoom:FH,flip:KH},oH=(f)=>{let U={...f,type:f.alertType,transition:f.transition?yH[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};SH(f.message,U)},EH=(f)=>{console.log("Log event",f)},mH=(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)}},D=window.Notification.permission;if(D==="granted"){U();return}if(D==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((H)=>{if(H==="granted")U()})},kH=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:D,useMittSupport:H,centrifugeChannel:z}=f,Z=MH(S),$=NH(Z);$.current=Z;let G=AH(()=>({alert:oH,log:EH,push:mH,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 Wf(jH,{children:Wf(_,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:D,useMittSupport:H,centrifugeChannel:z,methods:G,children:Wf(LH,{})})})},pf=kH;var xH=O({name:"IOEventsCard",component:pf,metadata:{author:"Swarm.ing"}});import{useEffect as cf,useState as dH}from"react";import{jsx as hf}from"react/jsx-runtime";var uH=({data:f})=>{let{name:U,key:D,value:H,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=dH(H);return cf(()=>{P(H)},[H]),cf(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(D,T)},[D,T]),hf(_,{card:"SessionStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{sessionStorage.removeItem(D),P("")}},children:hf("input",{type:"hidden",id:U,name:U,value:T})})},lf=uH;var bH=O({name:"SessionStorageCard",component:lf,metadata:{author:"PieData"}});import{useEffect as rf,useState as gH}from"react";import{jsx as nf}from"react/jsx-runtime";var vH=({data:f})=>{let{name:U,key:D,value:H,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=gH(H);return rf(()=>{P(H)},[H]),rf(()=>{if(typeof window==="undefined")return;localStorage.setItem(D,T)},[D,T]),nf(_,{card:"DeviceStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{localStorage.removeItem(D),P("")}},children:nf("input",{type:"hidden",id:U,name:U,value:T})})},sf=vH;var pH=O({name:"DeviceStorageCard",component:sf,metadata:{author:"PieData"}});import{useEffect as tf,useState as cH}from"react";import{jsx as af}from"react/jsx-runtime";var hH=({data:f})=>{let{name:U,key:D,value:H,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=cH(H);return tf(()=>{P(H)},[H]),tf(()=>{if(typeof window==="undefined")return;let X=window.Telegram?.WebApp?.CloudStorage;if(!X)return;X.setItem(D,T)},[D,T]),af(_,{card:"CloudStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{let X=window.Telegram?.WebApp?.CloudStorage;if(X)X.removeItem(D);P("")}},children:af("input",{type:"hidden",id:U,name:U,value:T})})},ef=hH;var lH=O({name:"CloudStorageCard",component:ef,metadata:{author:"PieData"}});import{useEffect as fU,useState as rH}from"react";import{jsx as UU}from"react/jsx-runtime";var nH=({data:f})=>{let{name:U,key:D,value:H,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G}=f,[T,P]=rH(H);return fU(()=>{P(H)},[H]),fU(()=>{if(typeof window==="undefined")return;let X=window.Telegram?.WebApp?.SecureStorage;if(!X)return;X.setItem(D,T)},[D,T]),UU(_,{card:"SecureStorageCard",data:f,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:$,centrifugeChannel:G,methods:{update:({value:X})=>{P(X)},remove:()=>{let X=window.Telegram?.WebApp?.SecureStorage;if(X)X.removeItem(D);P("")}},children:UU("input",{type:"hidden",id:U,name:U,value:T})})},HU=nH;var sH=O({name:"SecureStorageCard",component:HU,metadata:{author:"PieData"}});import{useCallback as Qf,useContext as Cf,useEffect as iH,useRef as tH,useState as ZU}from"react";import{jsx as zU}from"react/jsx-runtime";var aH=({data:f,content:U})=>{let{useLoader:D,noReturn:H,returnType:z,useSocketioSupport:Z,useCentrifugeSupport:$,useMittSupport:G,centrifugeChannel:T}=f,P=Cf(w),X=Cf(k)??F,[B,q]=ZU(!1),[Y,I]=ZU(null),V=tH(U),J=Cf(K),W=Qf((R)=>{if(R===null)q(!0);else if(q(!1),!H)V.current=R;if(!H)I(R)},[H]),Q=Qf((R)=>{V.current=R.content,I(R.content)},[]),C=Qf((R)=>{if(R===null)q(!0);else if(q(!1),!H)for(let t of R)J?.emit(t.name,t.data)},[H,J]);if(iH(()=>{I(U),q(!1)},[U]),!Y&&D)return P;return zU(_,{card:"AjaxGroupCard",data:f,methods:{changeContent:Q},useSocketioSupport:Z,useCentrifugeSupport:$,useMittSupport:G,centrifugeChannel:T,children:zU(X,{uiConfig:Y??V.current,setUiAjaxConfiguration:z==="events"?C:W})})},DU=aH;var eH=O({name:"AjaxGroupCard",component:DU,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});import{useContext as $U}from"react";import{jsx as Of}from"react/jsx-runtime";var fZ=({data:f,content:U,setUiAjaxConfiguration:D})=>{let{name:H,url:z,sx:Z}=f,$=$U(S),G=$U(k)??F;return Of(_,{card:H,data:f,children:Of("div",{style:Z,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:Of(G,{setUiAjaxConfiguration:D,uiConfig:U})})})},TU=fZ;var UZ=O({name:"BoxCard",component:TU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useMemo as n}from"react";import{QueryClient as IZ,QueryClientProvider as JZ,useQuery as YZ}from"@tanstack/react-query";import{useContext as zZ,useEffect as DZ}from"react";import{useEffect as HZ,useState as ZZ}from"react";var Zf=new Map,zf=new Map;function Df(f,U){let D=`${f}::${U}`,H=f?Zf.get(D):void 0,[z,Z]=ZZ(H??null);return HZ(()=>{if(!f)return;if(Zf.has(D)){Z(Zf.get(D));return}let $=zf.get(D);if(!$)$=fetch(f+`api/support/${U}`,{method:"GET"}).then((T)=>T.json()).then((T)=>{return Zf.set(D,T),zf.delete(D),T}).catch((T)=>{throw zf.delete(D),T}),zf.set(D,$);let G=!1;return $.then((T)=>{if(!G)Z(T)}).catch(()=>{}),()=>{G=!0}},[f,U,D]),z}var _f=null,GU=null;function PU(){GU?.()}function Rf(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!_f)_f=new Promise((f)=>{GU=()=>{f()}});return _f}var $Z=({children:f})=>{let U=zZ(o),D=e(),H=Df(D,"socketIO"),z=(Z)=>{if(typeof window!=="undefined")window.sid=Z.sid,PU(),console.log(`SocketIO initialized: ${window.sid}`)};return DZ(()=>{if(!U)return;let Z=()=>{console.log("SocketIO connected")},$=(G)=>{console.log(`SocketIO disconnected: ${G}`),U.connect()};if(H)U.on("pieinit",z),U.on("connect",Z),U.on("disconnect",$),U.connect();return()=>{if(H)U.off("pieinit",z),U.off("connect",Z),U.off("disconnect",$),U.disconnect()}},[U,H]),f},v=$Z;import{useContext as TZ,useEffect as GZ}from"react";var PZ=({children:f})=>{let U=TZ(y),D=e(),H=Df(D,"centrifuge");return GZ(()=>{if(!U)return;let z=()=>{console.log("Centrifuge connected")},Z=($)=>{console.log("Centrifuge disconnected:",$)};if(H)U.on("connected",z),U.on("disconnected",Z),U.connect();return()=>{if(H)U.disconnect()}},[U,H]),f},p=PZ;import{createAxiosDateTransformer as XZ}from"axios-date-transformer";import{jsx as VZ}from"react/jsx-runtime";function l(f,U,D){if(!U)return D;let H=f.replace(/^\//,""),z=U[H];if(!z)return D;return VZ(Xf,{uiConfig:z})}import{jsx as M,Fragment as WZ}from"react/jsx-runtime";var qZ=({location:f,fallback:U,piecache:D,onError:H,queryOptions:z})=>{let Z=x(),$=d(),G=L(),T=n(()=>XZ({baseURL:Z||""}),[Z]),P=n(()=>E(),[]),X=n(()=>Z?b(Z):null,[Z]),B=n(()=>Z?u(Z,$):null,[Z,$]),{data:q,isLoading:Y,error:I}=YZ({queryKey:["uiConfig",f.pathname+f.search,Z],enabled:!!Z,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=l(f.pathname,D,U);if(!Z)return V??null;if(G)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",Z),console.log("[PieRoot] CENTRIFUGE_SERVER:",$),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!D);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 M(K.Provider,{value:P,children:M(o.Provider,{value:X,children:M(y.Provider,{value:B,children:M(w.Provider,{value:U??M(WZ,{}),children:M(v,{children:M(p,{children:M("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:M(F,{uiConfig:q})})})})})})})})},BZ=(f)=>{let U=n(()=>new IZ,[]);return M(S.Provider,{value:f.onNavigate,children:M(j.Provider,{value:f.config,children:M(JZ,{client:U,children:M(qZ,{...f})})})})},QZ=BZ;import{useMemo as s}from"react";import{QueryClient as _Z,QueryClientProvider as RZ,useQuery as wZ}from"@tanstack/react-query";import{createAxiosDateTransformer as FZ}from"axios-date-transformer";import{useEffect as CZ,useState as OZ}from"react";var wf=({onError:f}={})=>{let[U,D]=OZ(null),H=Mf();return CZ(()=>{if(typeof window==="undefined")return;let z=window.Telegram?.WebApp;if(!z)return;try{z.ready?.()}catch(Z){f?.()}if(H==="telegram_expanded"&&(z.platform==="ios"||z.platform==="android"))z.expand();D(z)},[]),U};import{jsx as A,Fragment as LZ}from"react/jsx-runtime";var KZ=({location:f,fallback:U,piecache:D,onError:H,queryOptions:z})=>{let Z=x(),$=d(),G=L(),T=s(()=>FZ({baseURL:Z}),[Z]),P=s(()=>E(),[]),X=s(()=>Z?b(Z):null,[Z]),B=s(()=>Z?u(Z,$):null,[Z,$]),q=wf({onError:H}),{data:Y,isLoading:I,error:V}=wZ({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 C=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:",C.data);return C.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=l(f.pathname,D,U);if(!Z)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 A(K.Provider,{value:P,children:A(o.Provider,{value:X,children:A(y.Provider,{value:B,children:A(w.Provider,{value:U??A(LZ,{}),children:A(v,{children:A(p,{children:A("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:A(F,{uiConfig:Y})})})})})})})})},SZ=(f)=>{let U=s(()=>new _Z,[]);return A(S.Provider,{value:f.onNavigate,children:A(j.Provider,{value:f.config,children:A(RZ,{client:U,children:A(KZ,{...f})})})})},MZ=SZ;import{useMemo as Ff,useState as AZ}from"react";import{QueryClient as NZ,QueryClientProvider as yZ}from"@tanstack/react-query";import{jsx as m,Fragment as mZ}from"react/jsx-runtime";var oZ=({location:f,fallback:U,children:D})=>{let H=x(),z=d(),Z=L(),$=Ff(()=>E(),[]),G=Ff(()=>H?b(H):null,[H]),T=Ff(()=>H?u(H,z):null,[H,z]);if(Z)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 m(K.Provider,{value:$,children:m(o.Provider,{value:G,children:m(y.Provider,{value:T,children:m(w.Provider,{value:U??m(mZ,{}),children:m(v,{children:m(p,{children:m("form",{id:"piedata_global_form",action:H+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:D})})})})})})})},EZ=(f)=>{let[U]=AZ(()=>new NZ);return m(S.Provider,{value:f.onNavigate,children:m(j.Provider,{value:f.config,children:m(yZ,{client:U,children:m(oZ,{...f})})})})},kZ=EZ;import{useMemo as i}from"react";import{QueryClient as dZ,QueryClientProvider as uZ,useQuery as bZ}from"@tanstack/react-query";import{createAxiosDateTransformer as gZ}from"axios-date-transformer";import{useEffect as jZ,useState as xZ}from"react";var Kf=()=>{let[f,U]=xZ(null);return jZ(()=>{if(typeof window==="undefined")return;let D=window.WebApp;if(!D)return;D.ready(),U(D)},[]),f};import{jsx as N,Fragment as cZ}from"react/jsx-runtime";var vZ=({location:f,fallback:U,piecache:D,onError:H,queryOptions:z})=>{let Z=x(),$=d(),G=L(),T=i(()=>gZ({baseURL:Z}),[Z]),P=i(()=>E(),[]),X=i(()=>Z?b(Z):null,[Z]),B=i(()=>Z?u(Z,$):null,[Z,$]),q=Kf(),{data:Y,isLoading:I,error:V}=bZ({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 C=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:",C.data);return C.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=l(f.pathname,D,U);if(!Z)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 N(K.Provider,{value:P,children:N(o.Provider,{value:X,children:N(y.Provider,{value:B,children:N(w.Provider,{value:U??N(cZ,{}),children:N(v,{children:N(p,{children:N("form",{id:"piedata_global_form",action:Z+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:N(F,{uiConfig:Y})})})})})})})})},pZ=(f)=>{let U=i(()=>new dZ,[]);return N(S.Provider,{value:f.onNavigate,children:N(j.Provider,{value:f.config,children:N(uZ,{client:U,children:N(vZ,{...f})})})})},hZ=pZ;import{useMemo as lZ}from"react";var rZ=(f,U={},D=[],H,z)=>{let Z=z?.renderingLogEnabled??!1,$=z?.timeout,G=z?.retryPolicy,T=G?.maxRetries??0,P=G?.baseDelay??1000,X=G?.retryOn??[502,503,504];if(Z)console.log("Registering AJAX: ",H,U,D);return async(B={})=>{if(typeof window==="undefined"||typeof document==="undefined"){if(Z)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let q=z?.apiServer;if(!q){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(D.includes("sid"))await Rf();let Y=new FormData;for(let[J,W]of Object.entries({...U,...B}))Y.append(J,W);for(let J of D)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(Z)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((C)=>Y.append(J,C));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 C=P*2**(J-1);if(Z)console.log(`AJAX retry ${J}/${T} after ${C}ms`);await new Promise((R)=>setTimeout(R,C))}let W=$!=null?new AbortController:null,Q=W&&setTimeout(()=>W.abort(),$);try{let C=await fetch(I,{method:"POST",body:Y,signal:W?.signal});if(Q)clearTimeout(Q);if(!C.ok&&X.includes(C.status)&&J<T){V=new Error(`HTTP ${C.status}`);continue}let t=(C.headers.get("content-type")||"").includes("application/json");if(!!C.body?.getReader&&!t){let a=C.body.getReader(),JU=new TextDecoder,c="";while(!0){let{done:$f,value:YU}=await a.read();if($f)break;c+=JU.decode(YU,{stream:!0});let Sf=c.split(`
3
- `);c=Sf.pop()??"";for(let XU of Sf){let Tf=XU.trim();if(!Tf)continue;try{let qU=JSON.parse(Tf);f([qU])}catch{if(Z)console.warn("Failed to parse streamed line:",Tf)}}}if(c.trim())try{let $f=JSON.parse(c);f([$f])}catch{if(Z)console.warn("Failed to parse final streamed line:",c)}return{}}else{let a=await C.json();return f(a),a}}catch(C){if(Q)clearTimeout(Q);if(V=C,J<T)continue;if(Z)console.error("AJAX request failed:",C);return f(null),C}}if(Z)console.error("AJAX request failed after retries:",V);return f(null),V}},nZ=(f,U={},D=[],H,z)=>{let{apiServer:Z,enableRenderingLog:$}=h(),G=JSON.stringify(U),T=JSON.stringify(D),P=JSON.stringify(z);return lZ(()=>rZ(f,U,D,H,{apiServer:Z,renderingLogEnabled:$,timeout:z?.timeout,retryPolicy:z?.retryPolicy}),[f,G,T,H,Z,$,P])};import{tool as sZ}from"@openai/agents";import{useContext as iZ,useMemo as tZ}from"react";var VU=/^pie(.+?)_(.+)$/;function IU(f=E(),U={}){let D=[],H=new Set;for(let z of f.all.keys()){if(typeof z!=="string")continue;let Z=z.match(VU);if(!Z)continue;let[,$,G]=Z,T={methodName:$,cardName:G,eventName:z};if(U.filter&&!U.filter(T))continue;let P=U.nameFor?.(T)??`${G}_${$}`;if(H.has(P))continue;H.add(P);let X=U.describe?.(T)??`Invokes the "${$}" method on the PieCard "${G}" by emitting the in-process mitt event "${z}". The optional "payload" argument is forwarded verbatim to the card's handler.`;D.push(sZ({name:P,description:X,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 q=B?.payload;return f.emit(z,q),`Emitted "${z}"`}}))}return D}function aZ(f={}){let D=iZ(K)??E(),H=[];for(let T of D.all.keys())if(typeof T==="string"&&VU.test(T))H.push(T);H.sort();let z=H.join("|"),{filter:Z,describe:$,nameFor:G}=f;return tZ(()=>IU(D,{filter:Z,describe:$,nameFor:G}),[D,z,Z,$,G])}import{clsx as eZ}from"clsx";import{twMerge as fz}from"tailwind-merge";function Uz(...f){return fz(eZ(f))}var Hz=()=>{if(typeof document==="undefined")return;let f=document.getElementById("piedata_global_form");f&&f.submit()};var Zz=(f,U)=>`${f}${Gf}${U}`;export{wf as useWebApp,aZ as usePieMittAgentTools,LU as usePieEmit,Hf as useOpenAIWebRTC,Kf as useMaxWebApp,nZ as useAjaxSubmit,EU as unregisterComponent,Hz as submitGlobalForm,g as registry,O as registerPieComponent,oU as registerMultipleComponents,Zz as pieName,mU as hasComponent,xU as getRegistrySize,r as getRegistryEntry,IU as getMittAgentTools,kU as getComponentMeta,jU as getAllRegisteredComponents,Uz as cn,UH as UnionCard,k as UIRendererContext,Xf as UILoading,F as UI,bH as SessionStorageCard,aU as SequenceCard,sH as SecureStorageCard,MZ as PieTelegramRoot,QZ as PieRoot,hZ as PieMaxRoot,_ as PieCard,kZ as PieBaseRoot,Gf as PIEBREAK,xH as IOEventsCard,XH as HiddenCard,VH as HTMLEmbedCard,pH as DeviceStorageCard,lH as CloudStorageCard,UZ as BoxCard,_H as AutoRedirectCard,eH as AjaxGroupCard};
2
+ import{useContext as Jf,useEffect as Yf,useRef as MU}from"react";import{createContext as BU,useContext as WU}from"react";var j=BU(null),h=()=>{let f=WU(j);if(!f)throw new Error("usePieConfig must be used within PieConfigProvider");return f},x=()=>{let{apiServer:f}=h();return f},e=x,u=()=>{let{centrifugeServer:f}=h();return f};var N=()=>{let{enableRenderingLog:f}=h();return f},Lf=N,Mf=()=>{let{pageProcessor:f}=h();return f};var Pf="__piedemo__";import{createContext as QU}from"react";import{Centrifuge as Af}from"centrifuge";var Nf=new Map,d=(f,U)=>{if(!U)return null;let z=`${f}::${U}`,Z=Nf.get(z);if(Z)return Z;async function H(){let D=await fetch(f+"api/centrifuge/gen_token");if(!D.ok){if(D.status===403)throw new Af.UnauthorizedError("Backend is not answering");throw new Error(`Unexpected status code ${D.status}`)}return(await D.json()).token}let T=new Af(U,{getToken:H});return Nf.set(z,T),T},OU=QU(null),y=OU;import{io as _U}from"socket.io-client";import{createContext as CU}from"react";var yf=new Map,b=(f)=>{let U=yf.get(f);if(U)return U;let z=_U(f,{autoConnect:!1,transports:["websocket"]});return yf.set(f,z),z},RU=CU(null),E=RU;import wU from"mitt";import{createContext as KU,useCallback as FU,useContext as SU}from"react";var Vf=null;function o(){if(!Vf)Vf=wU();return Vf}var Ef=KU(null);function LU(f){let U=SU(Ef);return FU((z,Z)=>{(U??o()).emit(`pie${z}_${f}`,Z)},[f,U])}var F=Ef;var AU=({card:f,data:U,children:z,useSocketioSupport:Z=!1,useCentrifugeSupport:H=!1,useMittSupport:T=!1,centrifugeChannel:D=void 0,methods:V=void 0})=>{let $=Lf(),P=MU(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:Z,centrifuge:H,mitt:T,centrifugeChannel:D}),console.log("[PieCard] Methods:",V?Object.keys(V):"none"),console.log("[PieCard] Has children:",!!z);let G=Jf(E),B=Jf(y),W=Jf(F);if(Yf(()=>{if(!G||!Z||!P.current||!U.name){if($&&Z)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!G,useSocketioSupport:Z,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,Z]),Yf(()=>{if(!B||!H||!D||!U.name){if($&&H)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!B,useCentrifugeSupport:H,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,H]),Yf(()=>{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=AU;import{lazy as NU}from"react";var Xf=new Map;function of(f,U){return NU(()=>{if(Xf.has(U))return Xf.get(U);let z=f().then((Z)=>Z);return Xf.set(U,z),z})}var g=new Map,yU=(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=of(U.loader,f.name),U.loader=void 0,U.isLazy=!0;return U};function C(f){let U=yU(f);return g.set(U.name,U),U.component}var EU=(f)=>{f.forEach((U)=>C(U))},oU=(f)=>{g.delete(f)},mU=(f)=>{return g.has(f)},kU=(f)=>{return g.get(f)?.metadata},r=(f)=>{return g.get(f)},jU=()=>{return Array.from(g.keys())},xU=()=>{return g.size};import{Suspense as vU,useContext as pU,memo as cU}from"react";import{createContext as uU}from"react";import{jsx as gU,Fragment as bU}from"react/jsx-runtime";var dU=uU(gU(bU,{})),K=dU;import{jsx as If}from"react/jsx-runtime";function hU({uiConfig:f,setUiAjaxConfiguration:U}){let z=pU(K),Z=N();if(Z)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 H=r(f.card);if(!H?.component){if(Z)console.warn(`[UI] Component not found in registry: ${f.card}`),console.log("[UI] Returning fallback component");return z}if(Z)console.log("[UI] Found component in registry:",{name:H.name,isLazy:H.isLazy,hasMetadata:!!H.metadata});let T=H.component,D=If(T,{data:f.data,content:f.content,setUiAjaxConfiguration:U});if(H.isLazy){if(Z)console.log("[UI] Rendering lazy component with Suspense:",H.name);return If(vU,{fallback:H.fallback?If(H.fallback,{}):z,children:D},`${H.name}`)}if(Z)console.log("[UI] Rendering component directly:",H.name);return D}var w=cU(hU);import{Suspense as nU,useContext as sU}from"react";import{createContext as lU}from"react";var rU=lU(null),k=rU;import{jsx as ff}from"react/jsx-runtime";function mf({uiConfig:f,setUiAjaxConfiguration:U}){let z=sU(K),Z=N();if(Z)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 H=r(f.card);if(!H?.component){if(Z)console.warn(`[UILoading] Component not found in registry: ${f.card}`),console.log("[UILoading] Returning fallback component");return z}if(Z)console.log("[UILoading] Found component in registry:",{name:H.name,isLazy:H.isLazy,hasMetadata:!!H.metadata,hasFallback:!!H.fallback});if(H.fallback){if(Z)console.log("[UILoading] Rendering fallback for:",H.name);let V=H.fallback;return ff(V,{})}if(Z)console.log("[UILoading] No fallback, rendering full component:",H.name);let T=H.component,D=ff(k.Provider,{value:mf,children:ff(T,{data:f.data,content:f.content,setUiAjaxConfiguration:U})});if(H.isLazy)return ff(nU,{fallback:z,children:D},`${H.name}`);return D}var Gf=mf;import{useContext as iU}from"react";import{jsx as qf}from"react/jsx-runtime";var tU=({data:f,content:U,setUiAjaxConfiguration:z})=>{let{name:Z,sx:H}=f,T=iU(k)??w;return qf(R,{card:Z,data:f,children:qf("div",{style:H,id:Z,children:U.map((D,V)=>{return qf(T,{uiConfig:D,setUiAjaxConfiguration:z},`children-${V}`)})})})},kf=tU;var aU=C({name:"SequenceCard",component:kf,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as eU}from"react";import{jsx as jf}from"react/jsx-runtime";var fH=({data:f,content:U,setUiAjaxConfiguration:z})=>{let{name:Z}=f,H=eU(k)??w;return jf(R,{card:Z,data:f,children:U.map((T,D)=>{return jf(H,{uiConfig:T,setUiAjaxConfiguration:z},`children-${D}`)})})},xf=fH;var UH=C({name:"UnionCard",component:xf,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});import{useEffect as DH,useState as $H}from"react";import TH from"html-react-parser";import{useCallback as Uf,useEffect as HH,useRef as Bf,useState as ZH}from"react";function zH(){let f=new AudioContext,U=f.createOscillator(),z=U.connect(f.createMediaStreamDestination());U.start();let Z=z.stream.getAudioTracks()[0];return Z.enabled=!1,Z}function Hf(f=null,U){let[z,Z]=ZH(!1),H=Bf(null),T=Bf(null),D=Bf(null),V=Uf(async(B,W=!0)=>{if(H.current)$();let X=new RTCPeerConnection;if(X.onconnectionstatechange=()=>{if(X.connectionState==="connected")Z(!0);else if(["disconnected","failed","closed"].includes(X.connectionState))Z(!1)},X.ontrack=(_)=>{if(f)f.srcObject=_.streams[0]},W){let _=await navigator.mediaDevices.getUserMedia({audio:!0});X.addTrack(_.getTracks()[0],_)}else{let _=zH();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}),H.current=X,await D.current},[f]),$=Uf(()=>{let B=T.current;if(B)B.close();H.current?.getSenders()?.forEach((W)=>W.track?.stop()),H.current?.close(),Z(!1),H.current=null,T.current=null,D.current=null},[f]),P=Uf((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=Uf((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 HH(()=>{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}}import{jsx as VH}from"react/jsx-runtime";var PH=({data:f})=>{let{html:U,useSocketioSupport:z,useCentrifugeSupport:Z,useMittSupport:H,centrifugeChannel:T}=f,[D,V]=$H(U),{isSessionActive:$,startSession:P,sendTextMessage:G}=Hf(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 DH(()=>{V(U)},[U]),VH(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:Z,useSocketioSupport:z,useMittSupport:H,centrifugeChannel:T,children:TH(D)})},uf=PH;var JH=C({name:"HTMLEmbedCard",component:uf,metadata:{author:"Swarm.ing"}});import{useEffect as YH,useState as XH}from"react";import{jsx as df}from"react/jsx-runtime";var IH=({data:f})=>{let{name:U,value:z,useSocketioSupport:Z,useCentrifugeSupport:H,useMittSupport:T,centrifugeChannel:D}=f,[V,$]=XH(z);return YH(()=>{$(z)},[z]),df(R,{card:"HiddenCard",data:f,useSocketioSupport:Z,useCentrifugeSupport:H,useMittSupport:T,centrifugeChannel:D,methods:{update:({value:P})=>{$(P)}},children:df("input",{type:"hidden",id:U,name:U,value:V})})},bf=IH;var GH=C({name:"HiddenCard",component:bf,metadata:{author:"Swarm.ing"}});import{useContext as gf,useEffect as WH}from"react";import{createContext as qH}from"react";var BH=qH(void 0),S=BH;import{jsx as _H,Fragment as OH}from"react/jsx-runtime";var QH=({data:f})=>{let{url:U}=f,z=gf(S),Z=gf(K);return WH(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else z?.(U)},[U,z]),_H(OH,{children:Z})},vf=QH;var CH=C({name:"AutoRedirectCard",component:vf,metadata:{author:"Swarm.ing"}});import{Bounce as RH,Slide as wH,Zoom as KH,Flip as FH}from"react-toastify";import{toast as SH,ToastContainer as LH}from"react-toastify";import{useContext as MH,useMemo as AH,useRef as NH}from"react";import{jsx as Wf,Fragment as jH}from"react/jsx-runtime";var yH={bounce:RH,slide:wH,zoom:KH,flip:FH},EH=(f)=>{let U={...f,type:f.alertType,transition:f.transition?yH[f.transition]:void 0,position:f.position??"bottom-right",autoClose:f.autoClose??3000,style:{backgroundColor:"black",...f.sx}};SH(f.message,U)},oH=(f)=>{console.log("Log event",f)},mH=(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(Z){console.error("[IOEventsCard] Failed to show notification",Z)}},z=window.Notification.permission;if(z==="granted"){U();return}if(z==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((Z)=>{if(Z==="granted")U()})},kH=({data:f})=>{let{useCentrifugeSupport:U,useSocketioSupport:z,useMittSupport:Z,centrifugeChannel:H}=f,T=MH(S),D=NH(T);D.current=T;let V=AH(()=>({alert:EH,log:oH,push:mH,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 Wf(jH,{children:Wf(R,{card:"IOEventsCard",data:f,useCentrifugeSupport:U,useSocketioSupport:z,useMittSupport:Z,centrifugeChannel:H,methods:V,children:Wf(LH,{})})})},pf=kH;var xH=C({name:"IOEventsCard",component:pf,metadata:{author:"Swarm.ing"}});import{useEffect as cf,useState as uH}from"react";import{jsx as hf}from"react/jsx-runtime";var dH=({data:f})=>{let{name:U,key:z,value:Z,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=uH(Z);return cf(()=>{P(Z)},[Z]),cf(()=>{if(typeof window==="undefined")return;sessionStorage.setItem(z,$)},[z,$]),hf(R,{card:"SessionStorageCard",data:f,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{sessionStorage.removeItem(z),P("")}},children:hf("input",{type:"hidden",id:U,name:U,value:$})})},lf=dH;var bH=C({name:"SessionStorageCard",component:lf,metadata:{author:"PieData"}});import{useEffect as rf,useState as gH}from"react";import{jsx as nf}from"react/jsx-runtime";var vH=({data:f})=>{let{name:U,key:z,value:Z,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=gH(Z);return rf(()=>{P(Z)},[Z]),rf(()=>{if(typeof window==="undefined")return;localStorage.setItem(z,$)},[z,$]),nf(R,{card:"DeviceStorageCard",data:f,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V,methods:{update:({value:G})=>{P(G)},remove:()=>{localStorage.removeItem(z),P("")}},children:nf("input",{type:"hidden",id:U,name:U,value:$})})},sf=vH;var pH=C({name:"DeviceStorageCard",component:sf,metadata:{author:"PieData"}});import{useEffect as tf,useState as cH}from"react";import{jsx as af}from"react/jsx-runtime";var hH=({data:f})=>{let{name:U,key:z,value:Z,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=cH(Z);return tf(()=>{P(Z)},[Z]),tf(()=>{if(typeof window==="undefined")return;let G=window.Telegram?.WebApp?.CloudStorage;if(!G)return;G.setItem(z,$)},[z,$]),af(R,{card:"CloudStorageCard",data:f,useSocketioSupport:H,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:af("input",{type:"hidden",id:U,name:U,value:$})})},ef=hH;var lH=C({name:"CloudStorageCard",component:ef,metadata:{author:"PieData"}});import{useEffect as fU,useState as rH}from"react";import{jsx as UU}from"react/jsx-runtime";var nH=({data:f})=>{let{name:U,key:z,value:Z,useSocketioSupport:H,useCentrifugeSupport:T,useMittSupport:D,centrifugeChannel:V}=f,[$,P]=rH(Z);return fU(()=>{P(Z)},[Z]),fU(()=>{if(typeof window==="undefined")return;let G=window.Telegram?.WebApp?.SecureStorage;if(!G)return;G.setItem(z,$)},[z,$]),UU(R,{card:"SecureStorageCard",data:f,useSocketioSupport:H,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("input",{type:"hidden",id:U,name:U,value:$})})},HU=nH;var sH=C({name:"SecureStorageCard",component:HU,metadata:{author:"PieData"}});import{useCallback as Qf,useContext as Of,useEffect as iH,useRef as tH,useState as ZU}from"react";import{jsx as zU}from"react/jsx-runtime";var aH=({data:f,content:U})=>{let{useLoader:z,noReturn:Z,returnType:H,useSocketioSupport:T,useCentrifugeSupport:D,useMittSupport:V,centrifugeChannel:$}=f,P=Of(K),G=Of(k)??w,[B,W]=ZU(!1),[X,Y]=ZU(null),I=tH(U),J=Of(F),Q=Qf((_)=>{if(_===null)W(!0);else if(W(!1),!Z)I.current=_;if(!Z)Y(_)},[Z]),q=Qf((_)=>{I.current=_.content,Y(_.content)},[]),O=Qf((_)=>{if(_===null)W(!0);else if(W(!1),!Z)for(let t of _)J?.emit(t.name,t.data)},[Z,J]);if(iH(()=>{Y(U),W(!1)},[U]),!X&&z)return P;return zU(R,{card:"AjaxGroupCard",data:f,methods:{changeContent:q},useSocketioSupport:T,useCentrifugeSupport:D,useMittSupport:V,centrifugeChannel:$,children:zU(G,{uiConfig:X??I.current,setUiAjaxConfiguration:H==="events"?O:Q})})},DU=aH;var eH=C({name:"AjaxGroupCard",component:DU,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});import{useContext as $U}from"react";import{jsx as _f}from"react/jsx-runtime";var fZ=({data:f,content:U,setUiAjaxConfiguration:z})=>{let{name:Z,url:H,sx:T}=f,D=$U(S),V=$U(k)??w;return _f(R,{card:Z,data:f,children:_f("div",{style:T,id:Z,onClick:(P)=>{if(H)if(P.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(H))window.location.href=H;else D?.(H)},children:_f(V,{setUiAjaxConfiguration:z,uiConfig:U})})})},TU=fZ;var UZ=C({name:"BoxCard",component:TU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useMemo as n}from"react";import{QueryClient as YZ,QueryClientProvider as XZ,useQuery as IZ}from"@tanstack/react-query";import{useContext as zZ,useEffect as DZ}from"react";import{useEffect as HZ,useState as ZZ}from"react";var Zf=new Map,zf=new Map;function Df(f,U){let z=`${f}::${U}`,Z=f?Zf.get(z):void 0,[H,T]=ZZ(Z??null);return HZ(()=>{if(!f)return;if(Zf.has(z)){T(Zf.get(z));return}let D=zf.get(z);if(!D)D=fetch(f+`api/support/${U}`,{method:"GET"}).then(($)=>$.json()).then(($)=>{return Zf.set(z,$),zf.delete(z),$}).catch(($)=>{throw zf.delete(z),$}),zf.set(z,D);let V=!1;return D.then(($)=>{if(!V)T($)}).catch(()=>{}),()=>{V=!0}},[f,U,z]),H}var Cf=null,PU=null;function VU(){PU?.()}function Rf(){if(typeof window==="undefined")return Promise.resolve();if(typeof window.sid!=="undefined")return Promise.resolve();if(!Cf)Cf=new Promise((f)=>{PU=()=>{f()}});return Cf}var $Z=({children:f})=>{let U=zZ(E),z=e(),Z=Df(z,"socketIO"),H=(T)=>{if(typeof window!=="undefined")window.sid=T.sid,VU(),console.log(`SocketIO initialized: ${window.sid}`)};return DZ(()=>{if(!U)return;let T=()=>{console.log("SocketIO connected")},D=(V)=>{console.log(`SocketIO disconnected: ${V}`),U.connect()};if(Z)U.on("pieinit",H),U.on("connect",T),U.on("disconnect",D),U.connect();return()=>{if(Z)U.off("pieinit",H),U.off("connect",T),U.off("disconnect",D),U.disconnect()}},[U,Z]),f},v=$Z;import{useContext as TZ,useEffect as PZ}from"react";var VZ=({children:f})=>{let U=TZ(y),z=e(),Z=Df(z,"centrifuge");return PZ(()=>{if(!U)return;let H=()=>{console.log("Centrifuge connected")},T=(D)=>{console.log("Centrifuge disconnected:",D)};if(Z)U.on("connected",H),U.on("disconnected",T),U.connect();return()=>{if(Z)U.disconnect()}},[U,Z]),f},p=VZ;import{createAxiosDateTransformer as GZ}from"axios-date-transformer";import{jsx as JZ}from"react/jsx-runtime";function l(f,U,z){if(!U)return z;let Z=f.replace(/^\//,""),H=U[Z];if(!H)return z;return JZ(Gf,{uiConfig:H})}import{jsx as L,Fragment as WZ}from"react/jsx-runtime";var qZ=({location:f,fallback:U,piecache:z,onError:Z,queryOptions:H,disableGlobalForm:T})=>{let D=x(),V=u(),$=N(),P=n(()=>GZ({baseURL:D||""}),[D]),G=n(()=>o(),[]),B=n(()=>D?b(D):null,[D]),W=n(()=>D?d(D,V):null,[D,V]),{data:X,isLoading:Y,error:I}=IZ({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),...H}),J=l(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 Z?.(),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 L(F.Provider,{value:G,children:L(E.Provider,{value:B,children:L(y.Provider,{value:W,children:L(K.Provider,{value:U??L(WZ,{}),children:L(v,{children:L(p,{children:T?L(w,{uiConfig:X}):L("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:L(w,{uiConfig:X})})})})})})})})},BZ=(f)=>{let U=n(()=>new YZ,[]);return L(S.Provider,{value:f.onNavigate,children:L(j.Provider,{value:f.config,children:L(XZ,{client:U,children:L(qZ,{...f})})})})},QZ=BZ;import{useMemo as s}from"react";import{QueryClient as CZ,QueryClientProvider as RZ,useQuery as wZ}from"@tanstack/react-query";import{createAxiosDateTransformer as KZ}from"axios-date-transformer";import{useEffect as OZ,useState as _Z}from"react";var wf=({onError:f}={})=>{let[U,z]=_Z(null),Z=Mf();return OZ(()=>{if(typeof window==="undefined")return;let H=window.Telegram?.WebApp;if(!H)return;try{H.ready?.()}catch(T){f?.()}if(Z==="telegram_expanded"&&(H.platform==="ios"||H.platform==="android"))H.expand();z(H)},[]),U};import{jsx as M,Fragment as LZ}from"react/jsx-runtime";var FZ=({location:f,fallback:U,piecache:z,onError:Z,queryOptions:H,disableGlobalForm:T})=>{let D=x(),V=u(),$=N(),P=s(()=>KZ({baseURL:D}),[D]),G=s(()=>o(),[]),B=s(()=>D?b(D):null,[D]),W=s(()=>D?d(D,V):null,[D,V]),X=wf({onError:Z}),{data:Y,isLoading:I,error:J}=wZ({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),...H}),Q=l(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}),Z?.(),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 M(F.Provider,{value:G,children:M(E.Provider,{value:B,children:M(y.Provider,{value:W,children:M(K.Provider,{value:U??M(LZ,{}),children:M(v,{children:M(p,{children:T?M(w,{uiConfig:Y}):M("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:M(w,{uiConfig:Y})})})})})})})})},SZ=(f)=>{let U=s(()=>new CZ,[]);return M(S.Provider,{value:f.onNavigate,children:M(j.Provider,{value:f.config,children:M(RZ,{client:U,children:M(FZ,{...f})})})})},MZ=SZ;import{useMemo as Kf,useState as AZ}from"react";import{QueryClient as NZ,QueryClientProvider as yZ}from"@tanstack/react-query";import{jsx as m,Fragment as mZ}from"react/jsx-runtime";var EZ=({location:f,fallback:U,children:z,disableGlobalForm:Z})=>{let H=x(),T=u(),D=N(),V=Kf(()=>o(),[]),$=Kf(()=>H?b(H):null,[H]),P=Kf(()=>H?d(H,T):null,[H,T]);if(D)console.log("[PieRoot] Rendering with location:",f),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",T),console.log("[PieRoot] Fallback provided:",!!U);return m(F.Provider,{value:V,children:m(E.Provider,{value:$,children:m(y.Provider,{value:P,children:m(K.Provider,{value:U??m(mZ,{}),children:m(v,{children:m(p,{children:Z?z:m("form",{id:"piedata_global_form",action:H+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:z})})})})})})})},oZ=(f)=>{let[U]=AZ(()=>new NZ);return m(S.Provider,{value:f.onNavigate,children:m(j.Provider,{value:f.config,children:m(yZ,{client:U,children:m(EZ,{...f})})})})},kZ=oZ;import{useMemo as i}from"react";import{QueryClient as uZ,QueryClientProvider as dZ,useQuery as bZ}from"@tanstack/react-query";import{createAxiosDateTransformer as gZ}from"axios-date-transformer";import{useEffect as jZ,useState as xZ}from"react";var Ff=()=>{let[f,U]=xZ(null);return jZ(()=>{if(typeof window==="undefined")return;let z=window.WebApp;if(!z)return;z.ready(),U(z)},[]),f};import{jsx as A,Fragment as cZ}from"react/jsx-runtime";var vZ=({location:f,fallback:U,piecache:z,onError:Z,queryOptions:H,disableGlobalForm:T})=>{let D=x(),V=u(),$=N(),P=i(()=>gZ({baseURL:D}),[D]),G=i(()=>o(),[]),B=i(()=>D?b(D):null,[D]),W=i(()=>D?d(D,V):null,[D,V]),X=Ff(),{data:Y,isLoading:I,error:J}=bZ({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),...H}),Q=l(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}),Z?.(),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 A(F.Provider,{value:G,children:A(E.Provider,{value:B,children:A(y.Provider,{value:W,children:A(K.Provider,{value:U??A(cZ,{}),children:A(v,{children:A(p,{children:T?A(w,{uiConfig:Y}):A("form",{id:"piedata_global_form",action:D+"api/process"+f.pathname,method:"post",encType:"multipart/form-data",children:A(w,{uiConfig:Y})})})})})})})})},pZ=(f)=>{let U=i(()=>new uZ,[]);return A(S.Provider,{value:f.onNavigate,children:A(j.Provider,{value:f.config,children:A(dZ,{client:U,children:A(vZ,{...f})})})})},hZ=pZ;import{useMemo as lZ}from"react";var rZ=(f,U={},z=[],Z,H)=>{let T=H?.renderingLogEnabled??!1,D=H?.timeout,V=H?.retryPolicy,$=V?.maxRetries??0,P=V?.baseDelay??1000,G=V?.retryOn??[502,503,504];if(T)console.log("Registering AJAX: ",Z,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=H?.apiServer;if(!W){if(T)console.warn("AJAX skipped: apiServer is missing");return}if(!Z||!f){if(T)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(z.includes("sid"))await Rf();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"+Z;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 t=(O.headers.get("content-type")||"").includes("application/json");if(!!O.body?.getReader&&!t){let a=O.body.getReader(),XU=new TextDecoder,c="";while(!0){let{done:$f,value:IU}=await a.read();if($f)break;c+=XU.decode(IU,{stream:!0});let Sf=c.split(`
3
+ `);c=Sf.pop()??"";for(let GU of Sf){let Tf=GU.trim();if(!Tf)continue;try{let qU=JSON.parse(Tf);f([qU])}catch{if(T)console.warn("Failed to parse streamed line:",Tf)}}}if(c.trim())try{let $f=JSON.parse(c);f([$f])}catch{if(T)console.warn("Failed to parse final streamed line:",c)}return{}}else{let a=await O.json();return f(a),a}}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}},nZ=(f,U={},z=[],Z,H)=>{let{apiServer:T,enableRenderingLog:D}=h(),V=JSON.stringify(U),$=JSON.stringify(z),P=JSON.stringify(H);return lZ(()=>rZ(f,U,z,Z,{apiServer:T,renderingLogEnabled:D,timeout:H?.timeout,retryPolicy:H?.retryPolicy}),[f,V,$,Z,T,D,P])};import{tool as sZ}from"@openai/agents";import{useContext as iZ,useMemo as tZ}from"react";var JU=/^pie(.+?)_(.+)$/;function YU(f=o(),U={}){let z=[],Z=new Set;for(let H of f.all.keys()){if(typeof H!=="string")continue;let T=H.match(JU);if(!T)continue;let[,D,V]=T,$={methodName:D,cardName:V,eventName:H};if(U.filter&&!U.filter($))continue;let P=U.nameFor?.($)??`${V}_${D}`;if(Z.has(P))continue;Z.add(P);let G=U.describe?.($)??`Invokes the "${D}" method on the PieCard "${V}" by emitting the in-process mitt event "${H}". The optional "payload" argument is forwarded verbatim to the card's handler.`;z.push(sZ({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(H,W),`Emitted "${H}"`}}))}return z}function aZ(f={}){let z=iZ(F)??o(),Z=[];for(let $ of z.all.keys())if(typeof $==="string"&&JU.test($))Z.push($);Z.sort();let H=Z.join("|"),{filter:T,describe:D,nameFor:V}=f;return tZ(()=>YU(z,{filter:T,describe:D,nameFor:V}),[z,H,T,D,V])}import{clsx as eZ}from"clsx";import{twMerge as fz}from"tailwind-merge";function Uz(...f){return fz(eZ(f))}var Hz=()=>{if(typeof document==="undefined")return;let f=document.getElementById("piedata_global_form");f&&f.submit()};var Zz=(f,U)=>`${f}${Pf}${U}`;export{wf as useWebApp,aZ as usePieMittAgentTools,LU as usePieEmit,Hf as useOpenAIWebRTC,Ff as useMaxWebApp,nZ as useAjaxSubmit,oU as unregisterComponent,Hz as submitGlobalForm,g as registry,C as registerPieComponent,EU as registerMultipleComponents,Zz as pieName,mU as hasComponent,xU as getRegistrySize,r as getRegistryEntry,YU as getMittAgentTools,kU as getComponentMeta,jU as getAllRegisteredComponents,Uz as cn,UH as UnionCard,k as UIRendererContext,Gf as UILoading,w as UI,bH as SessionStorageCard,aU as SequenceCard,sH as SecureStorageCard,MZ as PieTelegramRoot,QZ as PieRoot,hZ as PieMaxRoot,R as PieCard,kZ as PieBaseRoot,Pf as PIEBREAK,xH as IOEventsCard,GH as HiddenCard,JH as HTMLEmbedCard,pH as DeviceStorageCard,lH as CloudStorageCard,UZ as BoxCard,CH as AutoRedirectCard,eH as AjaxGroupCard};
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(D)console.warn("Failed to parse streamed line:",hf)}}}if(n.trim())try{let cf=JSON.parse(n);f([cf])}catch{if(D)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(V=O,J<T)continue;if(D)console.error("AJAX request failed:",O);return f(null),O}}if(D)console.error("AJAX request failed after retries:",V);return f(null),V}},CH=(f,U={},Z=[],H,z)=>{let{apiServer:D,enableRenderingLog:$}=s(),G=JSON.stringify(U),T=JSON.stringify(Z),P=JSON.stringify(z);return QH.useMemo(()=>QZ(f,U,Z,H,{apiServer:D,renderingLogEnabled:$,timeout:z?.timeout,retryPolicy:z?.retryPolicy}),[f,G,T,H,D,$,P])};var OH=require("@openai/agents"),pf=require("react");var _H=/^pie(.+?)_(.+)$/;function $U(f=j(),U={}){let Z=[],H=new Set;for(let z of f.all.keys()){if(typeof z!=="string")continue;let D=z.match(_H);if(!D)continue;let[,$,G]=D,T={methodName:$,cardName:G,eventName:z};if(U.filter&&!U.filter(T))continue;let P=U.nameFor?.(T)??`${G}_${$}`;if(H.has(P))continue;H.add(P);let X=U.describe?.(T)??`Invokes the "${$}" method on the PieCard "${G}" by emitting the in-process mitt event "${z}". The optional "payload" argument is forwarded verbatim to the card's handler.`;Z.push(OH.tool({name:P,description:X,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 q=B?.payload;return f.emit(z,q),`Emitted "${z}"`}}))}return Z}function RH(f={}){let Z=pf.useContext(N)??j(),H=[];for(let T of Z.all.keys())if(typeof T==="string"&&_H.test(T))H.push(T);H.sort();let z=H.join("|"),{filter:D,describe:$,nameFor:G}=f;return pf.useMemo(()=>$U(Z,{filter:D,describe:$,nameFor:G}),[Z,z,D,$,G])}var wH=require("clsx"),FH=require("tailwind-merge");function KH(...f){return FH.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}${_f}${U}`;
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarm.ing/pieui",
3
- "version": "2.0.20",
3
+ "version": "2.0.21",
4
4
  "description": "A React component library featuring PieCard component",
5
5
  "repository": {
6
6
  "type": "git",