pxengine 0.1.107 → 0.1.109

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -345,7 +345,11 @@ __export(index_exports, {
345
345
  formatQAMessage: () => formatQAMessage,
346
346
  generateFieldsFromData: () => generateFieldsFromData,
347
347
  generateFieldsFromPropDefinitions: () => generateFieldsFromPropDefinitions,
348
+ getPxAuthToken: () => getPxAuthToken,
348
349
  isInputAtom: () => isInputAtom,
350
+ notifyPxUnauthorized: () => notifyPxUnauthorized,
351
+ setPxAuthTokenProvider: () => setPxAuthTokenProvider,
352
+ setPxUnauthorizedHandler: () => setPxUnauthorizedHandler,
349
353
  submitWidgetToAgent: () => submitWidgetToAgent,
350
354
  th: () => th,
351
355
  useCreatorWidgetPolling: () => useCreatorWidgetPolling,
@@ -355,7 +359,7 @@ __export(index_exports, {
355
359
  module.exports = __toCommonJS(index_exports);
356
360
 
357
361
  // src/render/PXEngineRenderer.tsx
358
- var import_react96 = __toESM(require("react"), 1);
362
+ var import_react97 = __toESM(require("react"), 1);
359
363
 
360
364
  // src/atoms/index.ts
361
365
  var atoms_exports = {};
@@ -3480,7 +3484,7 @@ __export(lucide_react_exports, {
3480
3484
  LucideMailX: () => MailX,
3481
3485
  LucideMailbox: () => Mailbox,
3482
3486
  LucideMails: () => Mails,
3483
- LucideMap: () => Map,
3487
+ LucideMap: () => Map2,
3484
3488
  LucideMapPin: () => MapPin,
3485
3489
  LucideMapPinCheck: () => MapPinCheck,
3486
3490
  LucideMapPinCheckInside: () => MapPinCheckInside,
@@ -4272,8 +4276,8 @@ __export(lucide_react_exports, {
4272
4276
  MailboxIcon: () => Mailbox,
4273
4277
  Mails: () => Mails,
4274
4278
  MailsIcon: () => Mails,
4275
- Map: () => Map,
4276
- MapIcon: () => Map,
4279
+ Map: () => Map2,
4280
+ MapIcon: () => Map2,
4277
4281
  MapPin: () => MapPin,
4278
4282
  MapPinCheck: () => MapPinCheck,
4279
4283
  MapPinCheckIcon: () => MapPinCheck,
@@ -6684,7 +6688,7 @@ __export(icons_exports, {
6684
6688
  MailX: () => MailX,
6685
6689
  Mailbox: () => Mailbox,
6686
6690
  Mails: () => Mails,
6687
- Map: () => Map,
6691
+ Map: () => Map2,
6688
6692
  MapPin: () => MapPin,
6689
6693
  MapPinCheck: () => MapPinCheck,
6690
6694
  MapPinCheckInside: () => MapPinCheckInside,
@@ -17499,7 +17503,7 @@ var __iconNode891 = [
17499
17503
  ["path", { d: "M15 5.764v15", key: "1pn4in" }],
17500
17504
  ["path", { d: "M9 3.236v15", key: "1uimfh" }]
17501
17505
  ];
17502
- var Map = createLucideIcon("Map", __iconNode891);
17506
+ var Map2 = createLucideIcon("Map", __iconNode891);
17503
17507
 
17504
17508
  // node_modules/lucide-react/dist/esm/icons/mars-stroke.js
17505
17509
  var __iconNode892 = [
@@ -33510,7 +33514,7 @@ var ChartTooltipContent = React80.forwardRef(
33510
33514
  )
33511
33515
  ] })
33512
33516
  },
33513
- item.dataKey
33517
+ `${item.dataKey ?? index}`
33514
33518
  );
33515
33519
  }) })
33516
33520
  ]
@@ -39181,7 +39185,128 @@ var NextStepCard = ({
39181
39185
  };
39182
39186
 
39183
39187
  // src/molecules/generic/PresentationJobCard/PresentationJobCard.tsx
39188
+ var import_react78 = require("react");
39189
+
39190
+ // src/lib/shared-poll.ts
39184
39191
  var import_react77 = require("react");
39192
+ var entries = /* @__PURE__ */ new Map();
39193
+ function clearTimer(entry) {
39194
+ if (entry.timer !== null) {
39195
+ clearInterval(entry.timer);
39196
+ entry.timer = null;
39197
+ }
39198
+ entry.controller?.abort();
39199
+ entry.controller = null;
39200
+ }
39201
+ async function runPoll(key) {
39202
+ const entry = entries.get(key);
39203
+ if (!entry || entry.inFlight || entry.stopped) return;
39204
+ entry.inFlight = true;
39205
+ const controller = new AbortController();
39206
+ entry.controller = controller;
39207
+ try {
39208
+ const data = await entry.fetcher(controller.signal);
39209
+ if (entries.get(key) !== entry) return;
39210
+ entry.lastData = data;
39211
+ entry.hasData = true;
39212
+ for (const listener of Array.from(entry.dataListeners)) {
39213
+ try {
39214
+ listener(data);
39215
+ } catch {
39216
+ }
39217
+ }
39218
+ if (!entry.shouldContinue(data)) {
39219
+ entry.stopped = true;
39220
+ clearTimer(entry);
39221
+ }
39222
+ } catch (error) {
39223
+ if (entries.get(key) !== entry) return;
39224
+ for (const listener of Array.from(entry.errorListeners)) {
39225
+ try {
39226
+ listener(error);
39227
+ } catch {
39228
+ }
39229
+ }
39230
+ } finally {
39231
+ entry.inFlight = false;
39232
+ }
39233
+ }
39234
+ function subscribeSharedPoll(config, onData, onError) {
39235
+ const { key, intervalMs, fetcher, shouldContinue } = config;
39236
+ if (!key) return () => {
39237
+ };
39238
+ let entry = entries.get(key);
39239
+ if (!entry) {
39240
+ entry = {
39241
+ intervalMs,
39242
+ fetcher,
39243
+ shouldContinue: shouldContinue ?? (() => true),
39244
+ dataListeners: /* @__PURE__ */ new Set(),
39245
+ errorListeners: /* @__PURE__ */ new Set(),
39246
+ timer: null,
39247
+ controller: null,
39248
+ lastData: void 0,
39249
+ hasData: false,
39250
+ stopped: false,
39251
+ inFlight: false
39252
+ };
39253
+ entries.set(key, entry);
39254
+ }
39255
+ const activeEntry = entry;
39256
+ activeEntry.dataListeners.add(onData);
39257
+ if (onError) activeEntry.errorListeners.add(onError);
39258
+ if (activeEntry.hasData && activeEntry.lastData !== void 0) {
39259
+ try {
39260
+ onData(activeEntry.lastData);
39261
+ } catch {
39262
+ }
39263
+ }
39264
+ if (!activeEntry.stopped && activeEntry.timer === null) {
39265
+ void runPoll(key);
39266
+ activeEntry.timer = setInterval(() => void runPoll(key), activeEntry.intervalMs);
39267
+ }
39268
+ return () => {
39269
+ activeEntry.dataListeners.delete(onData);
39270
+ if (onError) activeEntry.errorListeners.delete(onError);
39271
+ if (activeEntry.dataListeners.size === 0 && activeEntry.errorListeners.size === 0) {
39272
+ clearTimer(activeEntry);
39273
+ entries.delete(key);
39274
+ }
39275
+ };
39276
+ }
39277
+ function stopSharedPoll(key) {
39278
+ const entry = entries.get(key);
39279
+ if (!entry) return;
39280
+ entry.stopped = true;
39281
+ clearTimer(entry);
39282
+ }
39283
+ function useSharedPoll(config, onData, onError) {
39284
+ const fetcherRef = (0, import_react77.useRef)(config.fetcher);
39285
+ fetcherRef.current = config.fetcher;
39286
+ const shouldContinueRef = (0, import_react77.useRef)(config.shouldContinue);
39287
+ shouldContinueRef.current = config.shouldContinue;
39288
+ const onDataRef = (0, import_react77.useRef)(onData);
39289
+ onDataRef.current = onData;
39290
+ const onErrorRef = (0, import_react77.useRef)(onError);
39291
+ onErrorRef.current = onError;
39292
+ const { key, intervalMs } = config;
39293
+ (0, import_react77.useEffect)(() => {
39294
+ if (!key) return;
39295
+ const unsubscribe = subscribeSharedPoll(
39296
+ {
39297
+ key,
39298
+ intervalMs,
39299
+ fetcher: (signal) => fetcherRef.current(signal),
39300
+ shouldContinue: (data) => shouldContinueRef.current ? shouldContinueRef.current(data) : true
39301
+ },
39302
+ (data) => onDataRef.current(data),
39303
+ (error) => onErrorRef.current?.(error)
39304
+ );
39305
+ return unsubscribe;
39306
+ }, [key, intervalMs]);
39307
+ }
39308
+
39309
+ // src/molecules/generic/PresentationJobCard/PresentationJobCard.tsx
39185
39310
  var import_jsx_runtime147 = require("react/jsx-runtime");
39186
39311
  var DownloadIcon = () => /* @__PURE__ */ (0, import_jsx_runtime147.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", children: [
39187
39312
  /* @__PURE__ */ (0, import_jsx_runtime147.jsx)("path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }),
@@ -39238,7 +39363,7 @@ var FORMATS = [
39238
39363
  var ExportModal = ({ formats, title, onClose }) => {
39239
39364
  const available = FORMATS.filter((f) => (formats ?? {})[f.key]);
39240
39365
  const filename = (title ?? "").replace(/[^a-z0-9]/gi, "-").toLowerCase();
39241
- const [downloadingKey, setDownloadingKey] = (0, import_react77.useState)(null);
39366
+ const [downloadingKey, setDownloadingKey] = (0, import_react78.useState)(null);
39242
39367
  const handleDownload = async (fmtKey, url, ext) => {
39243
39368
  if (downloadingKey) return;
39244
39369
  const downloadName = `${filename}${ext}`;
@@ -39306,10 +39431,10 @@ var ExportModal = ({ formats, title, onClose }) => {
39306
39431
  ] });
39307
39432
  };
39308
39433
  var FullscreenModal = ({ url, title, slideCount, initialSlide = 1, onClose }) => {
39309
- const [currentSlide, setCurrentSlide] = (0, import_react77.useState)(initialSlide);
39310
- const [iframeReady, setIframeReady] = (0, import_react77.useState)(false);
39311
- const iframeRef = (0, import_react77.useRef)(null);
39312
- (0, import_react77.useEffect)(() => {
39434
+ const [currentSlide, setCurrentSlide] = (0, import_react78.useState)(initialSlide);
39435
+ const [iframeReady, setIframeReady] = (0, import_react78.useState)(false);
39436
+ const iframeRef = (0, import_react78.useRef)(null);
39437
+ (0, import_react78.useEffect)(() => {
39313
39438
  const onKey = (e) => {
39314
39439
  if (e.key === "Escape") onClose();
39315
39440
  };
@@ -39327,7 +39452,7 @@ var FullscreenModal = ({ url, title, slideCount, initialSlide = 1, onClose }) =>
39327
39452
  window.removeEventListener("message", onMsg);
39328
39453
  };
39329
39454
  }, [onClose, iframeReady]);
39330
- (0, import_react77.useEffect)(() => {
39455
+ (0, import_react78.useEffect)(() => {
39331
39456
  document.body.style.overflow = "hidden";
39332
39457
  return () => {
39333
39458
  document.body.style.overflow = "";
@@ -39426,46 +39551,45 @@ var PresentationJobCard = ({
39426
39551
  }) => {
39427
39552
  const t = th(theme);
39428
39553
  const accentGradient = theme?.gradient;
39429
- const [status, setStatus] = (0, import_react77.useState)(initialStatus);
39430
- const [title, setTitle] = (0, import_react77.useState)(initialTitle);
39431
- const [slideCount, setSlideCount] = (0, import_react77.useState)(initialSlideCount ?? 0);
39432
- const [formats, setFormats] = (0, import_react77.useState)(initialFormats);
39433
- const [error, setError] = (0, import_react77.useState)(initialError);
39434
- const [progress, setProgress] = (0, import_react77.useState)(initialProgress);
39435
- const [showExport, setShowExport] = (0, import_react77.useState)(false);
39436
- const [showFullscreen, setShowFullscreen] = (0, import_react77.useState)(false);
39437
- const [copied, setCopied] = (0, import_react77.useState)(false);
39438
- const [currentSlide, setCurrentSlide] = (0, import_react77.useState)(1);
39439
- const [previewScale, setPreviewScale] = (0, import_react77.useState)(1);
39440
- const [iframeReady, setIframeReady] = (0, import_react77.useState)(false);
39441
- const intervalRef = (0, import_react77.useRef)(null);
39442
- const previewRef = (0, import_react77.useRef)(null);
39443
- const iframeRef = (0, import_react77.useRef)(null);
39444
- (0, import_react77.useEffect)(() => {
39554
+ const [status, setStatus] = (0, import_react78.useState)(initialStatus);
39555
+ const [title, setTitle] = (0, import_react78.useState)(initialTitle);
39556
+ const [slideCount, setSlideCount] = (0, import_react78.useState)(initialSlideCount ?? 0);
39557
+ const [formats, setFormats] = (0, import_react78.useState)(initialFormats);
39558
+ const [error, setError] = (0, import_react78.useState)(initialError);
39559
+ const [progress, setProgress] = (0, import_react78.useState)(initialProgress);
39560
+ const [showExport, setShowExport] = (0, import_react78.useState)(false);
39561
+ const [showFullscreen, setShowFullscreen] = (0, import_react78.useState)(false);
39562
+ const [copied, setCopied] = (0, import_react78.useState)(false);
39563
+ const [currentSlide, setCurrentSlide] = (0, import_react78.useState)(1);
39564
+ const [previewScale, setPreviewScale] = (0, import_react78.useState)(1);
39565
+ const [iframeReady, setIframeReady] = (0, import_react78.useState)(false);
39566
+ const previewRef = (0, import_react78.useRef)(null);
39567
+ const iframeRef = (0, import_react78.useRef)(null);
39568
+ (0, import_react78.useEffect)(() => {
39445
39569
  setStatus(initialStatus);
39446
39570
  }, [initialStatus]);
39447
39571
  const progressPct = initialProgress?.percentage;
39448
39572
  const progressStep = initialProgress?.current_step;
39449
- (0, import_react77.useEffect)(() => {
39573
+ (0, import_react78.useEffect)(() => {
39450
39574
  if (initialProgress) setProgress(initialProgress);
39451
39575
  }, [progressPct, progressStep]);
39452
- (0, import_react77.useEffect)(() => {
39576
+ (0, import_react78.useEffect)(() => {
39453
39577
  if (initialError) setError(initialError);
39454
39578
  }, [initialError]);
39455
- (0, import_react77.useEffect)(() => {
39579
+ (0, import_react78.useEffect)(() => {
39456
39580
  if (initialSlideCount !== void 0) setSlideCount(initialSlideCount);
39457
39581
  }, [initialSlideCount]);
39458
39582
  const htmlUrl = initialFormats?.html_url;
39459
- (0, import_react77.useEffect)(() => {
39583
+ (0, import_react78.useEffect)(() => {
39460
39584
  if (initialFormats) setFormats(initialFormats);
39461
39585
  }, [htmlUrl]);
39462
- (0, import_react77.useEffect)(() => {
39586
+ (0, import_react78.useEffect)(() => {
39463
39587
  if (initialTitle) setTitle(initialTitle);
39464
39588
  }, [initialTitle]);
39465
- const updateScale = (0, import_react77.useCallback)(() => {
39589
+ const updateScale = (0, import_react78.useCallback)(() => {
39466
39590
  if (previewRef.current) setPreviewScale(previewRef.current.offsetWidth / 1280);
39467
39591
  }, []);
39468
- (0, import_react77.useEffect)(() => {
39592
+ (0, import_react78.useEffect)(() => {
39469
39593
  updateScale();
39470
39594
  setIframeReady(false);
39471
39595
  if (typeof ResizeObserver === "undefined") return;
@@ -39473,7 +39597,7 @@ var PresentationJobCard = ({
39473
39597
  if (previewRef.current) ro.observe(previewRef.current);
39474
39598
  return () => ro.disconnect();
39475
39599
  }, [updateScale, formats.html_url]);
39476
- (0, import_react77.useEffect)(() => {
39600
+ (0, import_react78.useEffect)(() => {
39477
39601
  const handler = (e) => {
39478
39602
  if (e.data?.type === "slideChanged") {
39479
39603
  setCurrentSlide(e.data.slide);
@@ -39498,66 +39622,59 @@ var PresentationJobCard = ({
39498
39622
  iframe.contentWindow.postMessage({ type: command }, "*");
39499
39623
  };
39500
39624
  const isTerminal = status === "complete" || status === "failed";
39501
- const onCompleteRef = (0, import_react77.useRef)(onComplete);
39502
- const onFailedRef = (0, import_react77.useRef)(onFailed);
39503
- const hasNotifiedRef = (0, import_react77.useRef)(false);
39625
+ const onCompleteRef = (0, import_react78.useRef)(onComplete);
39626
+ const onFailedRef = (0, import_react78.useRef)(onFailed);
39627
+ const hasNotifiedRef = (0, import_react78.useRef)(false);
39504
39628
  onCompleteRef.current = onComplete;
39505
39629
  onFailedRef.current = onFailed;
39506
- (0, import_react77.useEffect)(() => {
39507
- if (isTerminal || !pollUrl) return;
39508
- const poll = async () => {
39509
- try {
39630
+ useSharedPoll(
39631
+ {
39632
+ key: !isTerminal && pollUrl ? pollUrl : null,
39633
+ intervalMs: 3e3,
39634
+ fetcher: async () => {
39510
39635
  const headers = {};
39511
39636
  if (authToken) {
39512
39637
  headers["Authorization"] = `Bearer ${authToken}`;
39513
39638
  }
39514
39639
  const res = await fetch(pollUrl, { headers });
39515
- if (!res.ok) return;
39516
- const data = await res.json();
39517
- const newStatus = data.status;
39518
- setStatus(newStatus);
39519
- if (data.progress) {
39520
- setProgress(data.progress);
39521
- }
39522
- if (newStatus === "complete" && data.output) {
39523
- const newTitle = data.output.title || initialTitle;
39524
- const newSlideCount = data.output.slide_count || 0;
39525
- const newFormats = data.output.formats || {};
39526
- setTitle(newTitle);
39527
- setSlideCount(newSlideCount);
39528
- setFormats(newFormats);
39529
- if (!hasNotifiedRef.current && onCompleteRef.current) {
39530
- hasNotifiedRef.current = true;
39531
- onCompleteRef.current({
39532
- title: newTitle,
39533
- slide_count: newSlideCount,
39534
- formats: newFormats
39535
- });
39536
- }
39640
+ if (!res.ok) throw new Error(`poll ${res.status}`);
39641
+ return res.json();
39642
+ },
39643
+ shouldContinue: (data) => data.status !== "complete" && data.status !== "failed"
39644
+ },
39645
+ (data) => {
39646
+ const newStatus = data.status;
39647
+ setStatus(newStatus);
39648
+ if (data.progress) {
39649
+ setProgress(data.progress);
39650
+ }
39651
+ if (newStatus === "complete" && data.output) {
39652
+ const newTitle = data.output.title || initialTitle;
39653
+ const newSlideCount = data.output.slide_count || 0;
39654
+ const newFormats = data.output.formats || {};
39655
+ setTitle(newTitle);
39656
+ setSlideCount(newSlideCount);
39657
+ setFormats(newFormats);
39658
+ if (!hasNotifiedRef.current && onCompleteRef.current) {
39659
+ hasNotifiedRef.current = true;
39660
+ onCompleteRef.current({
39661
+ title: newTitle,
39662
+ slide_count: newSlideCount,
39663
+ formats: newFormats
39664
+ });
39537
39665
  }
39538
- if (newStatus === "failed") {
39539
- const errorMsg = data.error || "Job failed";
39540
- setError(errorMsg);
39541
- if (!hasNotifiedRef.current && onFailedRef.current) {
39542
- hasNotifiedRef.current = true;
39543
- onFailedRef.current(errorMsg);
39544
- }
39666
+ }
39667
+ if (newStatus === "failed") {
39668
+ const errorMsg = data.error || "Job failed";
39669
+ setError(errorMsg);
39670
+ if (!hasNotifiedRef.current && onFailedRef.current) {
39671
+ hasNotifiedRef.current = true;
39672
+ onFailedRef.current(errorMsg);
39545
39673
  }
39546
- } catch {
39547
39674
  }
39548
- };
39549
- poll();
39550
- intervalRef.current = setInterval(poll, 3e3);
39551
- return () => {
39552
- if (intervalRef.current) clearInterval(intervalRef.current);
39553
- };
39554
- }, [isTerminal, pollUrl, authToken, initialTitle]);
39555
- (0, import_react77.useEffect)(() => {
39556
- if (isTerminal && intervalRef.current) {
39557
- clearInterval(intervalRef.current);
39558
- intervalRef.current = null;
39559
39675
  }
39560
- }, [isTerminal]);
39676
+ // Transient fetch errors are ignored — the shared loop retries next tick.
39677
+ );
39561
39678
  const handleShare = async () => {
39562
39679
  const link = shareUrl ?? (typeof window !== "undefined" && _job_id ? `${window.location.origin}/p/${_job_id}` : formats.html_url);
39563
39680
  if (!link) return;
@@ -39829,7 +39946,7 @@ var PresentationJobCard = ({
39829
39946
  };
39830
39947
 
39831
39948
  // src/molecules/generic/ResearchReportJobCard/ResearchReportJobCard.tsx
39832
- var import_react78 = require("react");
39949
+ var import_react79 = require("react");
39833
39950
  var import_jsx_runtime148 = require("react/jsx-runtime");
39834
39951
  var DEFAULT_THEME = {
39835
39952
  primary: "#8b5cf6",
@@ -39885,14 +40002,14 @@ function formatTemplateLabel(templateId) {
39885
40002
  return templateId.split("-").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
39886
40003
  }
39887
40004
  var FullscreenPreviewModal = ({ url, title, onClose }) => {
39888
- (0, import_react78.useEffect)(() => {
40005
+ (0, import_react79.useEffect)(() => {
39889
40006
  const onKey = (e) => {
39890
40007
  if (e.key === "Escape") onClose();
39891
40008
  };
39892
40009
  document.addEventListener("keydown", onKey);
39893
40010
  return () => document.removeEventListener("keydown", onKey);
39894
40011
  }, [onClose]);
39895
- (0, import_react78.useEffect)(() => {
40012
+ (0, import_react79.useEffect)(() => {
39896
40013
  document.body.style.overflow = "hidden";
39897
40014
  return () => {
39898
40015
  document.body.style.overflow = "";
@@ -39958,162 +40075,154 @@ var ResearchReportJobCard = (props) => {
39958
40075
  compact = false
39959
40076
  } = props;
39960
40077
  const inferredStatus = initialStatus ?? (initialHtmlUrl ? "complete" : void 0);
39961
- const [status, setStatus] = (0, import_react78.useState)(inferredStatus);
39962
- const [title, setTitle] = (0, import_react78.useState)(initialTitle);
39963
- const [depth, setDepth] = (0, import_react78.useState)(initialDepth || "");
39964
- const [sectionCount, setSectionCount] = (0, import_react78.useState)(initialSectionCount ?? 0);
39965
- const [sourceCount, setSourceCount] = (0, import_react78.useState)(initialSourceCount ?? 0);
39966
- const [wordCount, setWordCount] = (0, import_react78.useState)(initialWordCount ?? 0);
39967
- const [summary, setSummary] = (0, import_react78.useState)(initialSummary || "");
39968
- const [htmlUrl, setHtmlUrl] = (0, import_react78.useState)(initialHtmlUrl || "");
39969
- const [generationMode, setGenerationMode] = (0, import_react78.useState)(
40078
+ const [status, setStatus] = (0, import_react79.useState)(inferredStatus);
40079
+ const [title, setTitle] = (0, import_react79.useState)(initialTitle);
40080
+ const [depth, setDepth] = (0, import_react79.useState)(initialDepth || "");
40081
+ const [sectionCount, setSectionCount] = (0, import_react79.useState)(initialSectionCount ?? 0);
40082
+ const [sourceCount, setSourceCount] = (0, import_react79.useState)(initialSourceCount ?? 0);
40083
+ const [wordCount, setWordCount] = (0, import_react79.useState)(initialWordCount ?? 0);
40084
+ const [summary, setSummary] = (0, import_react79.useState)(initialSummary || "");
40085
+ const [htmlUrl, setHtmlUrl] = (0, import_react79.useState)(initialHtmlUrl || "");
40086
+ const [generationMode, setGenerationMode] = (0, import_react79.useState)(
39970
40087
  initialGenerationMode || (initialHtmlUrl ? "template" : "")
39971
40088
  );
39972
- const [templateId, setTemplateId] = (0, import_react78.useState)(initialTemplateId || "");
39973
- const [templateVersionId, setTemplateVersionId] = (0, import_react78.useState)(initialTemplateVersionId || "");
39974
- const [reviewStatus, setReviewStatus] = (0, import_react78.useState)(
40089
+ const [templateId, setTemplateId] = (0, import_react79.useState)(initialTemplateId || "");
40090
+ const [templateVersionId, setTemplateVersionId] = (0, import_react79.useState)(initialTemplateVersionId || "");
40091
+ const [reviewStatus, setReviewStatus] = (0, import_react79.useState)(
39975
40092
  initialReviewStatus || (initialHtmlUrl ? "pending_review" : "")
39976
40093
  );
39977
- const [theme, setTheme] = (0, import_react78.useState)(initialTheme || DEFAULT_THEME);
39978
- const [error, setError] = (0, import_react78.useState)(initialError);
39979
- const [progress, setProgress] = (0, import_react78.useState)(initialProgress);
39980
- const [showPreview, setShowPreview] = (0, import_react78.useState)(false);
39981
- const [previewScale, setPreviewScale] = (0, import_react78.useState)(1);
39982
- const [copied, setCopied] = (0, import_react78.useState)(false);
39983
- const [approving, setApproving] = (0, import_react78.useState)(false);
39984
- const [regenerating, setRegenerating] = (0, import_react78.useState)(false);
39985
- const [approveError, setApproveError] = (0, import_react78.useState)(null);
39986
- const previewRef = (0, import_react78.useRef)(null);
39987
- const intervalRef = (0, import_react78.useRef)(null);
39988
- const onCompleteRef = (0, import_react78.useRef)(onComplete);
39989
- const onFailedRef = (0, import_react78.useRef)(onFailed);
39990
- const hasNotifiedRef = (0, import_react78.useRef)(false);
40094
+ const [theme, setTheme] = (0, import_react79.useState)(initialTheme || DEFAULT_THEME);
40095
+ const [error, setError] = (0, import_react79.useState)(initialError);
40096
+ const [progress, setProgress] = (0, import_react79.useState)(initialProgress);
40097
+ const [showPreview, setShowPreview] = (0, import_react79.useState)(false);
40098
+ const [previewScale, setPreviewScale] = (0, import_react79.useState)(1);
40099
+ const [copied, setCopied] = (0, import_react79.useState)(false);
40100
+ const [approving, setApproving] = (0, import_react79.useState)(false);
40101
+ const [regenerating, setRegenerating] = (0, import_react79.useState)(false);
40102
+ const [approveError, setApproveError] = (0, import_react79.useState)(null);
40103
+ const previewRef = (0, import_react79.useRef)(null);
40104
+ const onCompleteRef = (0, import_react79.useRef)(onComplete);
40105
+ const onFailedRef = (0, import_react79.useRef)(onFailed);
40106
+ const hasNotifiedRef = (0, import_react79.useRef)(false);
39991
40107
  onCompleteRef.current = onComplete;
39992
40108
  onFailedRef.current = onFailed;
39993
- (0, import_react78.useEffect)(() => {
40109
+ (0, import_react79.useEffect)(() => {
39994
40110
  const newStatus = initialStatus ?? (initialHtmlUrl ? "complete" : void 0);
39995
40111
  setStatus(newStatus);
39996
40112
  }, [initialStatus, initialHtmlUrl]);
39997
- (0, import_react78.useEffect)(() => {
40113
+ (0, import_react79.useEffect)(() => {
39998
40114
  if (initialTitle) setTitle(initialTitle);
39999
40115
  }, [initialTitle]);
40000
- (0, import_react78.useEffect)(() => {
40116
+ (0, import_react79.useEffect)(() => {
40001
40117
  if (initialHtmlUrl) setHtmlUrl(initialHtmlUrl);
40002
40118
  }, [initialHtmlUrl]);
40003
- (0, import_react78.useEffect)(() => {
40119
+ (0, import_react79.useEffect)(() => {
40004
40120
  if (initialGenerationMode) setGenerationMode(initialGenerationMode);
40005
40121
  }, [initialGenerationMode]);
40006
- (0, import_react78.useEffect)(() => {
40122
+ (0, import_react79.useEffect)(() => {
40007
40123
  if (initialTemplateId) setTemplateId(initialTemplateId);
40008
40124
  }, [initialTemplateId]);
40009
- (0, import_react78.useEffect)(() => {
40125
+ (0, import_react79.useEffect)(() => {
40010
40126
  if (initialTemplateVersionId) setTemplateVersionId(initialTemplateVersionId);
40011
40127
  }, [initialTemplateVersionId]);
40012
- (0, import_react78.useEffect)(() => {
40128
+ (0, import_react79.useEffect)(() => {
40013
40129
  if (initialReviewStatus) setReviewStatus(initialReviewStatus);
40014
40130
  }, [initialReviewStatus]);
40015
- (0, import_react78.useEffect)(() => {
40131
+ (0, import_react79.useEffect)(() => {
40016
40132
  if (initialDepth) setDepth(initialDepth);
40017
40133
  }, [initialDepth]);
40018
- (0, import_react78.useEffect)(() => {
40134
+ (0, import_react79.useEffect)(() => {
40019
40135
  if (initialSectionCount !== void 0) setSectionCount(initialSectionCount);
40020
40136
  }, [initialSectionCount]);
40021
- (0, import_react78.useEffect)(() => {
40137
+ (0, import_react79.useEffect)(() => {
40022
40138
  if (initialSourceCount !== void 0) setSourceCount(initialSourceCount);
40023
40139
  }, [initialSourceCount]);
40024
- (0, import_react78.useEffect)(() => {
40140
+ (0, import_react79.useEffect)(() => {
40025
40141
  if (initialWordCount !== void 0) setWordCount(initialWordCount);
40026
40142
  }, [initialWordCount]);
40027
- (0, import_react78.useEffect)(() => {
40143
+ (0, import_react79.useEffect)(() => {
40028
40144
  if (initialSummary) setSummary(initialSummary);
40029
40145
  }, [initialSummary]);
40030
40146
  const themePrimary = initialTheme?.primary;
40031
- (0, import_react78.useEffect)(() => {
40147
+ (0, import_react79.useEffect)(() => {
40032
40148
  if (initialTheme) setTheme(initialTheme);
40033
40149
  }, [themePrimary]);
40034
- (0, import_react78.useEffect)(() => {
40150
+ (0, import_react79.useEffect)(() => {
40035
40151
  if (initialError) setError(initialError);
40036
40152
  }, [initialError]);
40037
40153
  const progressPct = initialProgress?.percentage;
40038
40154
  const progressStep = initialProgress?.current_step;
40039
- (0, import_react78.useEffect)(() => {
40155
+ (0, import_react79.useEffect)(() => {
40040
40156
  if (initialProgress) setProgress(initialProgress);
40041
40157
  }, [progressPct, progressStep]);
40042
40158
  const isTerminal = status === "complete" || status === "failed";
40043
40159
  const primaryColor = theme?.primary || DEFAULT_THEME.primary;
40044
40160
  const hasHTML = Boolean(htmlUrl);
40045
- const updateScale = (0, import_react78.useCallback)(() => {
40161
+ const updateScale = (0, import_react79.useCallback)(() => {
40046
40162
  if (previewRef.current) {
40047
40163
  setPreviewScale(previewRef.current.offsetWidth / 800);
40048
40164
  }
40049
40165
  }, []);
40050
- (0, import_react78.useEffect)(() => {
40166
+ (0, import_react79.useEffect)(() => {
40051
40167
  updateScale();
40052
40168
  if (typeof ResizeObserver === "undefined") return;
40053
40169
  const ro = new ResizeObserver(updateScale);
40054
40170
  if (previewRef.current) ro.observe(previewRef.current);
40055
40171
  return () => ro.disconnect();
40056
40172
  }, [updateScale, htmlUrl]);
40057
- (0, import_react78.useEffect)(() => {
40058
- if (isTerminal || !pollUrl) return;
40059
- const poll = async () => {
40060
- try {
40173
+ useSharedPoll(
40174
+ {
40175
+ key: !isTerminal && pollUrl ? pollUrl : null,
40176
+ intervalMs: 3e3,
40177
+ fetcher: async () => {
40061
40178
  const headers = {};
40062
40179
  if (authToken) {
40063
40180
  headers["Authorization"] = `Bearer ${authToken}`;
40064
40181
  }
40065
40182
  const res = await fetch(pollUrl, { headers });
40066
- if (!res.ok) return;
40067
- const data = await res.json();
40068
- const newStatus = data.status;
40069
- setStatus(newStatus);
40070
- if (data.progress) {
40071
- setProgress(data.progress);
40183
+ if (!res.ok) throw new Error(`poll ${res.status}`);
40184
+ return res.json();
40185
+ },
40186
+ shouldContinue: (data) => data.status !== "complete" && data.status !== "failed"
40187
+ },
40188
+ (data) => {
40189
+ const newStatus = data.status;
40190
+ setStatus(newStatus);
40191
+ if (data.progress) {
40192
+ setProgress(data.progress);
40193
+ }
40194
+ if (newStatus === "complete" && data.output) {
40195
+ const output = data.output;
40196
+ setTitle(output.title || initialTitle);
40197
+ setDepth(output.depth || "");
40198
+ setSectionCount(output.section_count || 0);
40199
+ setSourceCount(output.source_count || 0);
40200
+ setWordCount(output.word_count || 0);
40201
+ setSummary(output.executive_summary || "");
40202
+ setHtmlUrl(output.html_url || "");
40203
+ if (output.generation_mode) setGenerationMode(output.generation_mode);
40204
+ if (output.template_id) setTemplateId(output.template_id);
40205
+ if (output.template_version_id) setTemplateVersionId(output.template_version_id);
40206
+ if (output.review_status) setReviewStatus(output.review_status);
40207
+ if (output.theme) {
40208
+ setTheme(output.theme);
40072
40209
  }
40073
- if (newStatus === "complete" && data.output) {
40074
- const output = data.output;
40075
- setTitle(output.title || initialTitle);
40076
- setDepth(output.depth || "");
40077
- setSectionCount(output.section_count || 0);
40078
- setSourceCount(output.source_count || 0);
40079
- setWordCount(output.word_count || 0);
40080
- setSummary(output.executive_summary || "");
40081
- setHtmlUrl(output.html_url || "");
40082
- if (output.generation_mode) setGenerationMode(output.generation_mode);
40083
- if (output.template_id) setTemplateId(output.template_id);
40084
- if (output.template_version_id) setTemplateVersionId(output.template_version_id);
40085
- if (output.review_status) setReviewStatus(output.review_status);
40086
- if (output.theme) {
40087
- setTheme(output.theme);
40088
- }
40089
- if (!hasNotifiedRef.current && onCompleteRef.current) {
40090
- hasNotifiedRef.current = true;
40091
- onCompleteRef.current(output);
40092
- }
40210
+ if (!hasNotifiedRef.current && onCompleteRef.current) {
40211
+ hasNotifiedRef.current = true;
40212
+ onCompleteRef.current(output);
40093
40213
  }
40094
- if (newStatus === "failed") {
40095
- const errorMsg = data.error || "Job failed";
40096
- setError(errorMsg);
40097
- if (!hasNotifiedRef.current && onFailedRef.current) {
40098
- hasNotifiedRef.current = true;
40099
- onFailedRef.current(errorMsg);
40100
- }
40214
+ }
40215
+ if (newStatus === "failed") {
40216
+ const errorMsg = data.error || "Job failed";
40217
+ setError(errorMsg);
40218
+ if (!hasNotifiedRef.current && onFailedRef.current) {
40219
+ hasNotifiedRef.current = true;
40220
+ onFailedRef.current(errorMsg);
40101
40221
  }
40102
- } catch {
40103
40222
  }
40104
- };
40105
- poll();
40106
- intervalRef.current = setInterval(poll, 3e3);
40107
- return () => {
40108
- if (intervalRef.current) clearInterval(intervalRef.current);
40109
- };
40110
- }, [isTerminal, pollUrl, authToken, initialTitle]);
40111
- (0, import_react78.useEffect)(() => {
40112
- if (isTerminal && intervalRef.current) {
40113
- clearInterval(intervalRef.current);
40114
- intervalRef.current = null;
40115
40223
  }
40116
- }, [isTerminal]);
40224
+ // Transient fetch errors are ignored — the shared loop retries next tick.
40225
+ );
40117
40226
  const formatWordCount = (count) => {
40118
40227
  if (count >= 1e3) return `${(count / 1e3).toFixed(1)}k`;
40119
40228
  return count.toString();
@@ -40537,7 +40646,7 @@ var ResearchReportJobCard = (props) => {
40537
40646
  };
40538
40647
 
40539
40648
  // src/molecules/generic/WebSearchJobCard/WebSearchJobCard.tsx
40540
- var import_react79 = require("react");
40649
+ var import_react80 = require("react");
40541
40650
  var import_jsx_runtime149 = require("react/jsx-runtime");
40542
40651
  var SearchIcon = () => /* @__PURE__ */ (0, import_jsx_runtime149.jsxs)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
40543
40652
  /* @__PURE__ */ (0, import_jsx_runtime149.jsx)("circle", { cx: "11", cy: "11", r: "8" }),
@@ -40566,99 +40675,91 @@ var WebSearchJobCard = ({
40566
40675
  onFailed,
40567
40676
  compact = false
40568
40677
  }) => {
40569
- const [status, setStatus] = (0, import_react79.useState)(initialStatus);
40570
- const [query, setQuery] = (0, import_react79.useState)(initialQuery || initialTitle || "");
40571
- const [resultCount, setResultCount] = (0, import_react79.useState)(initialResultCount ?? 0);
40572
- const [searchCount, setSearchCount] = (0, import_react79.useState)(initialSearchCount ?? 0);
40573
- const [summary, setSummary] = (0, import_react79.useState)(initialSummary || "");
40574
- const [results, setResults] = (0, import_react79.useState)(initialResults || []);
40575
- const [error, setError] = (0, import_react79.useState)(initialError);
40576
- const [progress, setProgress] = (0, import_react79.useState)(initialProgress);
40577
- const intervalRef = (0, import_react79.useRef)(null);
40578
- const onCompleteRef = (0, import_react79.useRef)(onComplete);
40579
- const onFailedRef = (0, import_react79.useRef)(onFailed);
40580
- const hasNotifiedRef = (0, import_react79.useRef)(false);
40678
+ const [status, setStatus] = (0, import_react80.useState)(initialStatus);
40679
+ const [query, setQuery] = (0, import_react80.useState)(initialQuery || initialTitle || "");
40680
+ const [resultCount, setResultCount] = (0, import_react80.useState)(initialResultCount ?? 0);
40681
+ const [searchCount, setSearchCount] = (0, import_react80.useState)(initialSearchCount ?? 0);
40682
+ const [summary, setSummary] = (0, import_react80.useState)(initialSummary || "");
40683
+ const [results, setResults] = (0, import_react80.useState)(initialResults || []);
40684
+ const [error, setError] = (0, import_react80.useState)(initialError);
40685
+ const [progress, setProgress] = (0, import_react80.useState)(initialProgress);
40686
+ const onCompleteRef = (0, import_react80.useRef)(onComplete);
40687
+ const onFailedRef = (0, import_react80.useRef)(onFailed);
40688
+ const hasNotifiedRef = (0, import_react80.useRef)(false);
40581
40689
  onCompleteRef.current = onComplete;
40582
40690
  onFailedRef.current = onFailed;
40583
- (0, import_react79.useEffect)(() => {
40691
+ (0, import_react80.useEffect)(() => {
40584
40692
  setStatus(initialStatus);
40585
40693
  }, [initialStatus]);
40586
- (0, import_react79.useEffect)(() => {
40694
+ (0, import_react80.useEffect)(() => {
40587
40695
  if (initialQuery) setQuery(initialQuery);
40588
40696
  }, [initialQuery]);
40589
- (0, import_react79.useEffect)(() => {
40697
+ (0, import_react80.useEffect)(() => {
40590
40698
  if (initialTitle && !initialQuery) setQuery(initialTitle);
40591
40699
  }, [initialTitle, initialQuery]);
40592
- (0, import_react79.useEffect)(() => {
40700
+ (0, import_react80.useEffect)(() => {
40593
40701
  if (initialResultCount !== void 0) setResultCount(initialResultCount);
40594
40702
  }, [initialResultCount]);
40595
- (0, import_react79.useEffect)(() => {
40703
+ (0, import_react80.useEffect)(() => {
40596
40704
  if (initialSearchCount !== void 0) setSearchCount(initialSearchCount);
40597
40705
  }, [initialSearchCount]);
40598
- (0, import_react79.useEffect)(() => {
40706
+ (0, import_react80.useEffect)(() => {
40599
40707
  if (initialSummary) setSummary(initialSummary);
40600
40708
  }, [initialSummary]);
40601
- (0, import_react79.useEffect)(() => {
40709
+ (0, import_react80.useEffect)(() => {
40602
40710
  if (initialResults) setResults(initialResults);
40603
40711
  }, [initialResults]);
40604
- (0, import_react79.useEffect)(() => {
40712
+ (0, import_react80.useEffect)(() => {
40605
40713
  if (initialError) setError(initialError);
40606
40714
  }, [initialError]);
40607
40715
  const progressPct = initialProgress?.percentage;
40608
40716
  const progressStep = initialProgress?.current_step;
40609
- (0, import_react79.useEffect)(() => {
40717
+ (0, import_react80.useEffect)(() => {
40610
40718
  if (initialProgress) setProgress(initialProgress);
40611
40719
  }, [progressPct, progressStep]);
40612
40720
  const isTerminal = status === "complete" || status === "failed";
40613
- (0, import_react79.useEffect)(() => {
40614
- if (isTerminal || !pollUrl) return;
40615
- const poll = async () => {
40616
- try {
40721
+ useSharedPoll(
40722
+ {
40723
+ key: !isTerminal && pollUrl ? pollUrl : null,
40724
+ intervalMs: 3e3,
40725
+ fetcher: async () => {
40617
40726
  const headers = {};
40618
40727
  if (authToken) headers["Authorization"] = `Bearer ${authToken}`;
40619
40728
  const res = await fetch(pollUrl, { headers });
40620
- if (!res.ok) return;
40621
- const data = await res.json();
40622
- const newStatus = data.status;
40623
- setStatus(newStatus);
40624
- if (data.progress) {
40625
- setProgress(data.progress);
40626
- }
40627
- if (newStatus === "complete" && data.output) {
40628
- const output = data.output;
40629
- setQuery(output.query || "");
40630
- setResultCount(output.result_count ?? 0);
40631
- setSearchCount(output.search_count ?? 0);
40632
- setSummary(output.summary || "");
40633
- setResults(output.results || []);
40634
- if (!hasNotifiedRef.current && onCompleteRef.current) {
40635
- hasNotifiedRef.current = true;
40636
- onCompleteRef.current(output);
40637
- }
40729
+ if (!res.ok) throw new Error(`poll ${res.status}`);
40730
+ return res.json();
40731
+ },
40732
+ shouldContinue: (data) => data.status !== "complete" && data.status !== "failed"
40733
+ },
40734
+ (data) => {
40735
+ const newStatus = data.status;
40736
+ setStatus(newStatus);
40737
+ if (data.progress) {
40738
+ setProgress(data.progress);
40739
+ }
40740
+ if (newStatus === "complete" && data.output) {
40741
+ const output = data.output;
40742
+ setQuery(output.query || "");
40743
+ setResultCount(output.result_count ?? 0);
40744
+ setSearchCount(output.search_count ?? 0);
40745
+ setSummary(output.summary || "");
40746
+ setResults(output.results || []);
40747
+ if (!hasNotifiedRef.current && onCompleteRef.current) {
40748
+ hasNotifiedRef.current = true;
40749
+ onCompleteRef.current(output);
40638
40750
  }
40639
- if (newStatus === "failed") {
40640
- const errorMsg = data.error || "Job failed";
40641
- setError(errorMsg);
40642
- if (!hasNotifiedRef.current && onFailedRef.current) {
40643
- hasNotifiedRef.current = true;
40644
- onFailedRef.current(errorMsg);
40645
- }
40751
+ }
40752
+ if (newStatus === "failed") {
40753
+ const errorMsg = data.error || "Job failed";
40754
+ setError(errorMsg);
40755
+ if (!hasNotifiedRef.current && onFailedRef.current) {
40756
+ hasNotifiedRef.current = true;
40757
+ onFailedRef.current(errorMsg);
40646
40758
  }
40647
- } catch {
40648
40759
  }
40649
- };
40650
- poll();
40651
- intervalRef.current = setInterval(poll, 3e3);
40652
- return () => {
40653
- if (intervalRef.current) clearInterval(intervalRef.current);
40654
- };
40655
- }, [isTerminal, pollUrl, authToken]);
40656
- (0, import_react79.useEffect)(() => {
40657
- if (isTerminal && intervalRef.current) {
40658
- clearInterval(intervalRef.current);
40659
- intervalRef.current = null;
40660
40760
  }
40661
- }, [isTerminal]);
40761
+ // Transient fetch errors are ignored — the shared loop retries next tick.
40762
+ );
40662
40763
  if (status === "pending" || status === "running") {
40663
40764
  const pct = progress?.percentage ?? 0;
40664
40765
  const step = progress?.current_step ?? "Starting web search...";
@@ -40798,10 +40899,10 @@ var WebSearchJobCard = ({
40798
40899
  };
40799
40900
 
40800
40901
  // src/molecules/creator-discovery/CampaignSeedCard/CampaignSeedCard.tsx
40801
- var import_react81 = __toESM(require("react"), 1);
40902
+ var import_react82 = __toESM(require("react"), 1);
40802
40903
 
40803
40904
  // src/molecules/creator-discovery/SearchSpecCard/CustomFieldRenderers.tsx
40804
- var import_react80 = require("react");
40905
+ var import_react81 = require("react");
40805
40906
 
40806
40907
  // src/lib/countries.ts
40807
40908
  var countries = [
@@ -41013,10 +41114,10 @@ var CountrySelectEdit = ({
41013
41114
  value,
41014
41115
  onChange
41015
41116
  }) => {
41016
- const [isDropdownOpen, setIsDropdownOpen] = (0, import_react80.useState)(false);
41017
- const [searchTerm, setSearchTerm] = (0, import_react80.useState)("");
41018
- const dropdownRef = (0, import_react80.useRef)(null);
41019
- (0, import_react80.useEffect)(() => {
41117
+ const [isDropdownOpen, setIsDropdownOpen] = (0, import_react81.useState)(false);
41118
+ const [searchTerm, setSearchTerm] = (0, import_react81.useState)("");
41119
+ const dropdownRef = (0, import_react81.useRef)(null);
41120
+ (0, import_react81.useEffect)(() => {
41020
41121
  const handleClickOutside = (event) => {
41021
41122
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
41022
41123
  setIsDropdownOpen(false);
@@ -41025,7 +41126,7 @@ var CountrySelectEdit = ({
41025
41126
  document.addEventListener("mousedown", handleClickOutside);
41026
41127
  return () => document.removeEventListener("mousedown", handleClickOutside);
41027
41128
  }, []);
41028
- const inputValue = (0, import_react80.useMemo)(() => {
41129
+ const inputValue = (0, import_react81.useMemo)(() => {
41029
41130
  if (Array.isArray(value)) return value;
41030
41131
  if (typeof value === "string" && value.trim() !== "") {
41031
41132
  const foundCountry = countries.find(
@@ -41126,7 +41227,7 @@ var CountrySelectEdit = ({
41126
41227
  ] });
41127
41228
  };
41128
41229
  var CountrySelectDisplay = ({ value }) => {
41129
- const displayValues = (0, import_react80.useMemo)(() => {
41230
+ const displayValues = (0, import_react81.useMemo)(() => {
41130
41231
  if (Array.isArray(value)) return value;
41131
41232
  if (typeof value === "string" && value.trim() !== "") return [value];
41132
41233
  return [];
@@ -41302,7 +41403,7 @@ var PlatformSelectEdit = ({
41302
41403
  value,
41303
41404
  onChange
41304
41405
  }) => {
41305
- const selectedPlatforms = (0, import_react80.useMemo)(() => {
41406
+ const selectedPlatforms = (0, import_react81.useMemo)(() => {
41306
41407
  if (Array.isArray(value)) return value;
41307
41408
  if (typeof value === "string" && value.trim() !== "") {
41308
41409
  return value.split(",").map((s) => s.trim()).filter(Boolean);
@@ -41321,7 +41422,7 @@ var PlatformSelectEdit = ({
41321
41422
  onChange([...selectedPlatforms, platform]);
41322
41423
  }
41323
41424
  };
41324
- const options = (0, import_react80.useMemo)(() => {
41425
+ const options = (0, import_react81.useMemo)(() => {
41325
41426
  return DEFAULT_PLATFORMS;
41326
41427
  }, []);
41327
41428
  return /* @__PURE__ */ (0, import_jsx_runtime150.jsx)("div", { className: "flex flex-wrap gap-4 py-2", children: options.map((platform) => /* @__PURE__ */ (0, import_jsx_runtime150.jsxs)(
@@ -41347,7 +41448,7 @@ var PlatformSelectEdit = ({
41347
41448
  )) });
41348
41449
  };
41349
41450
  var PlatformSelectDisplay = ({ value }) => {
41350
- const displayValues = (0, import_react80.useMemo)(() => {
41451
+ const displayValues = (0, import_react81.useMemo)(() => {
41351
41452
  if (Array.isArray(value)) return value;
41352
41453
  if (typeof value === "string" && value.trim() !== "") {
41353
41454
  return value.split(",").map((s) => s.trim()).filter(Boolean);
@@ -41507,7 +41608,7 @@ function buildCampaignSeedFields(data) {
41507
41608
  return generated;
41508
41609
  });
41509
41610
  }
41510
- var CampaignSeedCard = import_react81.default.memo(
41611
+ var CampaignSeedCard = import_react82.default.memo(
41511
41612
  ({
41512
41613
  selectionStatus,
41513
41614
  isLatestMessage = true,
@@ -41519,7 +41620,7 @@ var CampaignSeedCard = import_react81.default.memo(
41519
41620
  sendMessage,
41520
41621
  ...formCardProps
41521
41622
  }) => {
41522
- const fields = (0, import_react81.useMemo)(() => {
41623
+ const fields = (0, import_react82.useMemo)(() => {
41523
41624
  return providedFields || buildCampaignSeedFields(data);
41524
41625
  }, [providedFields, data]);
41525
41626
  const handleProceed = () => {
@@ -41553,7 +41654,7 @@ var CampaignSeedCard = import_react81.default.memo(
41553
41654
  CampaignSeedCard.displayName = "CampaignSeedCard";
41554
41655
 
41555
41656
  // src/molecules/creator-discovery/SearchSpecCard/SearchSpecCard.tsx
41556
- var import_react82 = __toESM(require("react"), 1);
41657
+ var import_react83 = __toESM(require("react"), 1);
41557
41658
  var import_jsx_runtime152 = require("react/jsx-runtime");
41558
41659
  var ObjectDisplay2 = ({ value }) => {
41559
41660
  if (!value || typeof value !== "object") return null;
@@ -41669,7 +41770,7 @@ function buildSearchSpecFields(data) {
41669
41770
  return generated;
41670
41771
  });
41671
41772
  }
41672
- var SearchSpecCard = import_react82.default.memo(
41773
+ var SearchSpecCard = import_react83.default.memo(
41673
41774
  ({
41674
41775
  selectionStatus,
41675
41776
  isLatestMessage = true,
@@ -41683,7 +41784,7 @@ var SearchSpecCard = import_react82.default.memo(
41683
41784
  ...formCardProps
41684
41785
  }) => {
41685
41786
  const resolvedData = data || specData;
41686
- const fields = (0, import_react82.useMemo)(() => {
41787
+ const fields = (0, import_react83.useMemo)(() => {
41687
41788
  return providedFields || buildSearchSpecFields(resolvedData ?? {});
41688
41789
  }, [providedFields, resolvedData]);
41689
41790
  const handleProceed = () => {
@@ -41719,7 +41820,43 @@ var SearchSpecCard = import_react82.default.memo(
41719
41820
  SearchSpecCard.displayName = "SearchSpecCard";
41720
41821
 
41721
41822
  // src/molecules/creator-discovery/MCQCard/MCQCard.tsx
41722
- var import_react83 = __toESM(require("react"), 1);
41823
+ var import_react84 = __toESM(require("react"), 1);
41824
+
41825
+ // src/lib/auth-provider.ts
41826
+ var _provider = null;
41827
+ var _onUnauthorized = null;
41828
+ function setPxAuthTokenProvider(provider) {
41829
+ _provider = provider;
41830
+ }
41831
+ function setPxUnauthorizedHandler(handler) {
41832
+ _onUnauthorized = handler;
41833
+ }
41834
+ function notifyPxUnauthorized(status) {
41835
+ if (status !== 401) return false;
41836
+ if (_onUnauthorized) {
41837
+ try {
41838
+ _onUnauthorized();
41839
+ } catch {
41840
+ }
41841
+ }
41842
+ return true;
41843
+ }
41844
+ function getPxAuthToken() {
41845
+ if (_provider) {
41846
+ try {
41847
+ const t = _provider();
41848
+ if (t) return t;
41849
+ } catch {
41850
+ }
41851
+ }
41852
+ if (typeof document !== "undefined") {
41853
+ for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
41854
+ const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
41855
+ if (match2?.[1]) return match2[1];
41856
+ }
41857
+ }
41858
+ return null;
41859
+ }
41723
41860
 
41724
41861
  // src/molecules/creator-discovery/MCQCard/defaultFetchers.ts
41725
41862
  function getBackendOrigin() {
@@ -41736,25 +41873,10 @@ function getBaseUrl() {
41736
41873
  if (backend) return `${backend}/api/custom-agents`;
41737
41874
  return "/api/agents-proxy/custom-agents";
41738
41875
  }
41739
- function getAuthToken() {
41740
- if (typeof window === "undefined") return null;
41741
- try {
41742
- const ls = localStorage.getItem("px_auth_token");
41743
- if (ls) return ls;
41744
- } catch {
41745
- }
41746
- if (typeof document !== "undefined") {
41747
- for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
41748
- const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
41749
- if (match2?.[1]) return match2[1];
41750
- }
41751
- }
41752
- return null;
41753
- }
41754
41876
  function buildHeaders() {
41755
41877
  const headers = { "Content-Type": "application/json" };
41756
41878
  if (getBackendOrigin()) {
41757
- const token = getAuthToken();
41879
+ const token = getPxAuthToken();
41758
41880
  if (token) headers["Authorization"] = `Bearer ${token}`;
41759
41881
  }
41760
41882
  return headers;
@@ -41788,6 +41910,7 @@ async function defaultFetchSelections(sessionId) {
41788
41910
  body: "{}"
41789
41911
  }
41790
41912
  );
41913
+ if (res.status === 401) notifyPxUnauthorized(res.status);
41791
41914
  if (!res.ok) return {};
41792
41915
  const data = await res.json();
41793
41916
  const selections = data.selections || {};
@@ -41805,7 +41928,7 @@ async function defaultFetchSelections(sessionId) {
41805
41928
  async function defaultPersistSelection(sessionId, questionKey, value) {
41806
41929
  setLocalSelection(sessionId, questionKey, value);
41807
41930
  try {
41808
- await fetch(
41931
+ const res = await fetch(
41809
41932
  `${getBaseUrl()}/sessions/${sessionId}/mcq-selections`,
41810
41933
  {
41811
41934
  method: "PATCH",
@@ -41813,6 +41936,7 @@ async function defaultPersistSelection(sessionId, questionKey, value) {
41813
41936
  body: JSON.stringify({ question_key: questionKey, value })
41814
41937
  }
41815
41938
  );
41939
+ if (res.status === 401) notifyPxUnauthorized(res.status);
41816
41940
  } catch (err) {
41817
41941
  console.warn("[MCQ persist failed]", err);
41818
41942
  }
@@ -41866,7 +41990,7 @@ function inferSelectionLimits(text, optionCount) {
41866
41990
  }
41867
41991
  return null;
41868
41992
  }
41869
- var MCQCard = import_react83.default.memo(
41993
+ var MCQCard = import_react84.default.memo(
41870
41994
  ({
41871
41995
  question,
41872
41996
  options,
@@ -41924,12 +42048,12 @@ var MCQCard = import_react83.default.memo(
41924
42048
  if (propsSelectedOption) return [propsSelectedOption];
41925
42049
  return [];
41926
42050
  };
41927
- const [selectedKeys, setSelectedKeys] = import_react83.default.useState(seedSelection);
41928
- const [isProceeded, setIsProceeded] = import_react83.default.useState(
42051
+ const [selectedKeys, setSelectedKeys] = import_react84.default.useState(seedSelection);
42052
+ const [isProceeded, setIsProceeded] = import_react84.default.useState(
41929
42053
  Boolean(propsSelectedOption || propsSelectedOptions && propsSelectedOptions.length)
41930
42054
  );
41931
- const fetchedSessionRef = import_react83.default.useRef("");
41932
- import_react83.default.useEffect(() => {
42055
+ const fetchedSessionRef = import_react84.default.useRef("");
42056
+ import_react84.default.useEffect(() => {
41933
42057
  if (propsSelectedOption) {
41934
42058
  setSelectedKeys([propsSelectedOption]);
41935
42059
  setIsProceeded(true);
@@ -41938,7 +42062,7 @@ var MCQCard = import_react83.default.memo(
41938
42062
  setIsProceeded(true);
41939
42063
  }
41940
42064
  }, [propsSelectedOption, propsSelectedOptions]);
41941
- const buildQuestionKey = import_react83.default.useCallback((sid, q) => {
42065
+ const buildQuestionKey = import_react84.default.useCallback((sid, q) => {
41942
42066
  let hash = 2166136261;
41943
42067
  for (let i = 0; i < q.length; i++) {
41944
42068
  hash ^= q.charCodeAt(i);
@@ -41946,7 +42070,7 @@ var MCQCard = import_react83.default.memo(
41946
42070
  }
41947
42071
  return `mcq_${sid}_${hash.toString(36)}`;
41948
42072
  }, []);
41949
- import_react83.default.useEffect(() => {
42073
+ import_react84.default.useEffect(() => {
41950
42074
  if (!sessionId || !resolvedQuestion) return;
41951
42075
  const fetchKey = `${sessionId}::${resolvedQuestion}`;
41952
42076
  if (fetchedSessionRef.current === fetchKey) return;
@@ -42618,9 +42742,9 @@ var CreatorActionHeader = ({
42618
42742
  };
42619
42743
 
42620
42744
  // src/molecules/creator-discovery/CreatorSearchBox/CreatorSearch.tsx
42621
- var import_react84 = __toESM(require("react"), 1);
42745
+ var import_react85 = __toESM(require("react"), 1);
42622
42746
  var import_jsx_runtime164 = require("react/jsx-runtime");
42623
- var CreatorSearch = import_react84.default.memo(
42747
+ var CreatorSearch = import_react85.default.memo(
42624
42748
  ({
42625
42749
  selectionStatus,
42626
42750
  isLatestMessage = true,
@@ -42629,7 +42753,7 @@ var CreatorSearch = import_react84.default.memo(
42629
42753
  data,
42630
42754
  ...formCardProps
42631
42755
  }) => {
42632
- const fields = (0, import_react84.useMemo)(() => {
42756
+ const fields = (0, import_react85.useMemo)(() => {
42633
42757
  const baseFields = providedFields || generateFieldsFromData(data);
42634
42758
  return baseFields.map((field) => {
42635
42759
  if (field.key === "platforms") {
@@ -42709,10 +42833,10 @@ var CreatorSearch = import_react84.default.memo(
42709
42833
  CreatorSearch.displayName = "CreatorSearch";
42710
42834
 
42711
42835
  // src/molecules/creator-discovery/CampaignConceptCard/CampaignConceptCard.tsx
42712
- var import_react85 = __toESM(require("react"), 1);
42836
+ var import_react86 = __toESM(require("react"), 1);
42713
42837
  var import_framer_motion = require("framer-motion");
42714
42838
  var import_jsx_runtime165 = require("react/jsx-runtime");
42715
- var CampaignConceptCard = import_react85.default.memo(
42839
+ var CampaignConceptCard = import_react86.default.memo(
42716
42840
  ({
42717
42841
  index,
42718
42842
  isRecommended,
@@ -42728,7 +42852,7 @@ var CampaignConceptCard = import_react85.default.memo(
42728
42852
  onAction,
42729
42853
  ...formCardProps
42730
42854
  }) => {
42731
- const [internalIsOpen, setInternalIsOpen] = (0, import_react85.useState)(false);
42855
+ const [internalIsOpen, setInternalIsOpen] = (0, import_react86.useState)(false);
42732
42856
  const isOpen = controlledIsOpen !== void 0 ? controlledIsOpen : internalIsOpen;
42733
42857
  const handleToggle = () => {
42734
42858
  if (onToggle) {
@@ -42747,7 +42871,7 @@ var CampaignConceptCard = import_react85.default.memo(
42747
42871
  });
42748
42872
  };
42749
42873
  const effectiveIsLatest = isLatestMessage && !hasUserResponded;
42750
- const fields = (0, import_react85.useMemo)(() => {
42874
+ const fields = (0, import_react86.useMemo)(() => {
42751
42875
  const baseFields = providedFields || generateFieldsFromData(data);
42752
42876
  const FIELD_ORDER = [
42753
42877
  "description",
@@ -42801,10 +42925,10 @@ var CampaignConceptCard = import_react85.default.memo(
42801
42925
  }) });
42802
42926
  }
42803
42927
  if (typeof val === "object") {
42804
- const entries = Object.entries(val);
42805
- if (entries.length === 0)
42928
+ const entries2 = Object.entries(val);
42929
+ if (entries2.length === 0)
42806
42930
  return /* @__PURE__ */ (0, import_jsx_runtime165.jsx)("span", { className: "text-muted-foreground text-sm", children: "-" });
42807
- return /* @__PURE__ */ (0, import_jsx_runtime165.jsx)("div", { className: "space-y-2", children: entries.map(([k, v], idx) => /* @__PURE__ */ (0, import_jsx_runtime165.jsxs)("div", { className: "flex items-center gap-2", children: [
42931
+ return /* @__PURE__ */ (0, import_jsx_runtime165.jsx)("div", { className: "space-y-2", children: entries2.map(([k, v], idx) => /* @__PURE__ */ (0, import_jsx_runtime165.jsxs)("div", { className: "flex items-center gap-2", children: [
42808
42932
  /* @__PURE__ */ (0, import_jsx_runtime165.jsxs)("span", { className: "text-muted-foreground font-medium", children: [
42809
42933
  idx + 1,
42810
42934
  "."
@@ -43059,14 +43183,14 @@ var CampaignConceptCard = import_react85.default.memo(
43059
43183
  CampaignConceptCard.displayName = "CampaignConceptCard";
43060
43184
 
43061
43185
  // src/molecules/creator-discovery/CreatorWidget/CreatorWidget.tsx
43062
- var import_react93 = require("react");
43186
+ var import_react94 = require("react");
43063
43187
 
43064
43188
  // src/molecules/creator-discovery/CreatorWidget/CreatorImageList.tsx
43065
- var import_react86 = require("react");
43189
+ var import_react87 = require("react");
43066
43190
  var import_jsx_runtime166 = require("react/jsx-runtime");
43067
43191
  function useMediaQuery(query) {
43068
- const [matches, setMatches] = (0, import_react86.useState)(false);
43069
- (0, import_react86.useEffect)(() => {
43192
+ const [matches, setMatches] = (0, import_react87.useState)(false);
43193
+ (0, import_react87.useEffect)(() => {
43070
43194
  const media = window.matchMedia(query);
43071
43195
  const listener = () => setMatches(media.matches);
43072
43196
  listener();
@@ -43149,7 +43273,7 @@ function CreatorImageList({
43149
43273
  }
43150
43274
 
43151
43275
  // src/molecules/creator-discovery/CreatorWidget/CreatorProgressBar.tsx
43152
- var import_react87 = require("react");
43276
+ var import_react88 = require("react");
43153
43277
  var import_framer_motion2 = require("framer-motion");
43154
43278
  var import_jsx_runtime167 = require("react/jsx-runtime");
43155
43279
  function truncateName(name, maxLength) {
@@ -43157,8 +43281,8 @@ function truncateName(name, maxLength) {
43157
43281
  return name.substring(0, maxLength) + "...";
43158
43282
  }
43159
43283
  function ProgressBar({ overallPercentage }) {
43160
- const [showTooltip, setShowTooltip] = (0, import_react87.useState)(true);
43161
- (0, import_react87.useEffect)(() => {
43284
+ const [showTooltip, setShowTooltip] = (0, import_react88.useState)(true);
43285
+ (0, import_react88.useEffect)(() => {
43162
43286
  if (overallPercentage && overallPercentage >= 100) {
43163
43287
  setShowTooltip(false);
43164
43288
  }
@@ -43319,7 +43443,7 @@ function CreatorCompactView({
43319
43443
  }
43320
43444
 
43321
43445
  // src/molecules/creator-discovery/CreatorWidget/CreatorExpandedPanel.tsx
43322
- var import_react91 = require("react");
43446
+ var import_react92 = require("react");
43323
43447
  var import_react_dom2 = __toESM(require("react-dom"), 1);
43324
43448
  var import_framer_motion5 = require("framer-motion");
43325
43449
 
@@ -43333,26 +43457,11 @@ function getBackendOrigin2() {
43333
43457
  }
43334
43458
  return raw;
43335
43459
  }
43336
- function getAuthToken2() {
43337
- if (typeof window === "undefined") return null;
43338
- try {
43339
- const ls = localStorage.getItem("px_auth_token");
43340
- if (ls) return ls;
43341
- } catch {
43342
- }
43343
- if (typeof document !== "undefined") {
43344
- for (const name of ["adminTokenBuilder", "adminToken", "token"]) {
43345
- const match2 = document.cookie.match(new RegExp(`(?:^|;\\s*)${name}=([^;]*)`));
43346
- if (match2?.[1]) return match2[1];
43347
- }
43348
- }
43349
- return null;
43350
- }
43351
43460
  function buildHeaders2(includeJson = false) {
43352
43461
  const headers = {};
43353
43462
  if (includeJson) headers["Content-Type"] = "application/json";
43354
43463
  if (getBackendOrigin2()) {
43355
- const token = getAuthToken2();
43464
+ const token = getPxAuthToken();
43356
43465
  if (token) headers["Authorization"] = `Bearer ${token}`;
43357
43466
  }
43358
43467
  return headers;
@@ -43362,6 +43471,7 @@ async function defaultFetchVersions(params) {
43362
43471
  const versionParam = params.version ? `&version=${params.version}` : "";
43363
43472
  const url = backend ? `${backend}/api/creators/versions?sessionId=${params.sessionId}${versionParam}&validated=${params.validated}` : `/api/get-creator-versions?sessionId=${params.sessionId}${versionParam}&validated=${params.validated}`;
43364
43473
  const res = await fetch(url, { headers: buildHeaders2() });
43474
+ if (res.status === 401) notifyPxUnauthorized(res.status);
43365
43475
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
43366
43476
  return res.json();
43367
43477
  }
@@ -43369,6 +43479,7 @@ async function defaultFetchStatus(params) {
43369
43479
  const backend = getBackendOrigin2();
43370
43480
  const url = backend ? `${backend}/api/creators/version-status?session_id=${params.sessionId}&version_no=${params.versionNo}` : `/api/get-creator-detail-status?session_id=${params.sessionId}&version_no=${params.versionNo}`;
43371
43481
  const res = await fetch(url, { headers: buildHeaders2() });
43482
+ if (res.status === 401) notifyPxUnauthorized(res.status);
43372
43483
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
43373
43484
  return res.json();
43374
43485
  }
@@ -43384,6 +43495,7 @@ async function defaultFetchCreatorDetails(params) {
43384
43495
  version_no: params.versionNo
43385
43496
  })
43386
43497
  });
43498
+ if (res.status === 401) notifyPxUnauthorized(res.status);
43387
43499
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
43388
43500
  return res.json();
43389
43501
  }
@@ -43805,7 +43917,7 @@ function getPlatformIconColor(platform) {
43805
43917
  }
43806
43918
 
43807
43919
  // src/molecules/creator-discovery/CreatorWidget/PostCard.tsx
43808
- var import_react88 = require("react");
43920
+ var import_react89 = require("react");
43809
43921
  var import_jsx_runtime172 = require("react/jsx-runtime");
43810
43922
  var formatFollowerCount = (count) => {
43811
43923
  if (count >= 1e6) {
@@ -43819,8 +43931,8 @@ var formatFollowerCount = (count) => {
43819
43931
  return Math.floor(count).toString();
43820
43932
  };
43821
43933
  function PostCard({ post, platformUsername }) {
43822
- const [expanded, setExpanded] = (0, import_react88.useState)(false);
43823
- const [errored, setErrored] = (0, import_react88.useState)(false);
43934
+ const [expanded, setExpanded] = (0, import_react89.useState)(false);
43935
+ const [errored, setErrored] = (0, import_react89.useState)(false);
43824
43936
  const thumbnail = post.thumbnail_url || post.thumbnail || post.image || "";
43825
43937
  const likes = post.engagement?.likes ?? post.likes ?? null;
43826
43938
  const comments = post.engagement?.comments ?? post.comments ?? null;
@@ -44030,7 +44142,7 @@ function PlatformPostsSection({
44030
44142
  }
44031
44143
 
44032
44144
  // src/molecules/creator-discovery/CreatorWidget/BrandCollaborationsList.tsx
44033
- var import_react89 = require("react");
44145
+ var import_react90 = require("react");
44034
44146
  var import_react_dom = __toESM(require("react-dom"), 1);
44035
44147
  var import_framer_motion3 = require("framer-motion");
44036
44148
  var import_jsx_runtime174 = require("react/jsx-runtime");
@@ -44232,8 +44344,8 @@ function BrandMentionDetails({
44232
44344
  function BrandCollaborationsList({
44233
44345
  brandBreakdown
44234
44346
  }) {
44235
- const [openDetails, setOpenDetails] = (0, import_react89.useState)(false);
44236
- const [selectedBrand, setSelectedBrand] = (0, import_react89.useState)("");
44347
+ const [openDetails, setOpenDetails] = (0, import_react90.useState)(false);
44348
+ const [selectedBrand, setSelectedBrand] = (0, import_react90.useState)("");
44237
44349
  if (!brandBreakdown?.insights?.brandBreakdown || brandBreakdown.insights.brandBreakdown.length === 0) {
44238
44350
  return null;
44239
44351
  }
@@ -44292,7 +44404,7 @@ function BrandCollaborationsList({
44292
44404
  }
44293
44405
 
44294
44406
  // src/molecules/creator-discovery/CreatorWidget/CreatorGridView.tsx
44295
- var import_react90 = require("react");
44407
+ var import_react91 = require("react");
44296
44408
  var import_framer_motion4 = require("framer-motion");
44297
44409
  var import_jsx_runtime175 = require("react/jsx-runtime");
44298
44410
  var formatFollowerCount3 = (count) => {
@@ -44341,25 +44453,25 @@ var itemsExplanation = [
44341
44453
  { key: "brandSafety", label: "Brand Safety" }
44342
44454
  ];
44343
44455
  function CreatorGridViewCard({ creator }) {
44344
- const [isExpanded, setIsExpanded] = (0, import_react90.useState)(false);
44345
- const [showFullDescription, setShowFullDescription] = (0, import_react90.useState)(false);
44346
- const [isDescriptionOverflowing, setIsDescriptionOverflowing] = (0, import_react90.useState)(false);
44347
- const descriptionRef = (0, import_react90.useRef)(null);
44348
- const cardRef = (0, import_react90.useRef)(null);
44349
- const checkDescriptionOverflow = (0, import_react90.useCallback)(() => {
44456
+ const [isExpanded, setIsExpanded] = (0, import_react91.useState)(false);
44457
+ const [showFullDescription, setShowFullDescription] = (0, import_react91.useState)(false);
44458
+ const [isDescriptionOverflowing, setIsDescriptionOverflowing] = (0, import_react91.useState)(false);
44459
+ const descriptionRef = (0, import_react91.useRef)(null);
44460
+ const cardRef = (0, import_react91.useRef)(null);
44461
+ const checkDescriptionOverflow = (0, import_react91.useCallback)(() => {
44350
44462
  const el = descriptionRef.current;
44351
44463
  if (!el) return;
44352
44464
  setIsDescriptionOverflowing(el.scrollHeight > el.clientHeight + 1);
44353
44465
  }, []);
44354
- (0, import_react90.useEffect)(() => {
44466
+ (0, import_react91.useEffect)(() => {
44355
44467
  checkDescriptionOverflow();
44356
44468
  }, [checkDescriptionOverflow, isExpanded, showFullDescription]);
44357
- (0, import_react90.useEffect)(() => {
44469
+ (0, import_react91.useEffect)(() => {
44358
44470
  const onResize = () => checkDescriptionOverflow();
44359
44471
  window.addEventListener("resize", onResize);
44360
44472
  return () => window.removeEventListener("resize", onResize);
44361
44473
  }, [checkDescriptionOverflow]);
44362
- const platformStats = (0, import_react90.useMemo)(() => {
44474
+ const platformStats = (0, import_react91.useMemo)(() => {
44363
44475
  return [
44364
44476
  {
44365
44477
  platform: "instagram",
@@ -44777,7 +44889,7 @@ function BrandMentionPerformance({ creator }) {
44777
44889
  ] });
44778
44890
  }
44779
44891
  function CreatorFitSummary({ creator, showBrandPerformance }) {
44780
- const [contentExpanded, setContentExpanded] = (0, import_react91.useState)(false);
44892
+ const [contentExpanded, setContentExpanded] = (0, import_react92.useState)(false);
44781
44893
  const hasDeepAnalysis = creator?.sentiment?.deepAnalysis?.deepAnalysis;
44782
44894
  const title = hasDeepAnalysis ? "CREATOR DEEP ANALYSIS" : "CREATOR FIT SUMMARY";
44783
44895
  const content = hasDeepAnalysis ? creator.sentiment.deepAnalysis.deepAnalysis : creator?.sentiment?.aiReasoning || "No data available.";
@@ -44797,7 +44909,7 @@ function CreatorFitSummary({ creator, showBrandPerformance }) {
44797
44909
  ] });
44798
44910
  }
44799
44911
  function ProfileSection({ creator, isValidationComplete }) {
44800
- const [descriptionExpanded, setDescriptionExpanded] = (0, import_react91.useState)(false);
44912
+ const [descriptionExpanded, setDescriptionExpanded] = (0, import_react92.useState)(false);
44801
44913
  const username = creator.platformMetrics?.instagramMetrics?.username ? `@${creator.platformMetrics.instagramMetrics.username}` : creator.platformMetrics?.youtubeMetrics?.channelName ? `@${creator.platformMetrics.youtubeMetrics.channelName}` : creator.platformMetrics?.tiktokMetrics?.username ? `@${creator.platformMetrics.tiktokMetrics.username}` : "";
44802
44914
  const iso2 = normalizeToIso2(creator.country);
44803
44915
  const meta = codeToMeta[iso2];
@@ -44887,7 +44999,7 @@ function CreatorCard({
44887
44999
  creator,
44888
45000
  isValidationComplete
44889
45001
  }) {
44890
- const [detailsExpanded, setDetailsExpanded] = (0, import_react91.useState)(false);
45002
+ const [detailsExpanded, setDetailsExpanded] = (0, import_react92.useState)(false);
44891
45003
  const hasValidBrandMention = (() => {
44892
45004
  const insights = creator?.brandCollaborations?.insights;
44893
45005
  if (!insights) return false;
@@ -44929,7 +45041,7 @@ function CreatorDisplay({
44929
45041
  creators,
44930
45042
  isValidationComplete
44931
45043
  }) {
44932
- const [viewMode, setViewMode] = (0, import_react91.useState)("list");
45044
+ const [viewMode, setViewMode] = (0, import_react92.useState)("list");
44933
45045
  return /* @__PURE__ */ (0, import_jsx_runtime176.jsxs)("div", { className: "px-4", children: [
44934
45046
  /* @__PURE__ */ (0, import_jsx_runtime176.jsxs)("div", { className: "flex justify-end items-center my-3 gap-1", children: [
44935
45047
  /* @__PURE__ */ (0, import_jsx_runtime176.jsxs)("span", { className: "text-xs text-gray600 mr-2", children: [
@@ -45010,10 +45122,10 @@ function CreatorExpandedPanel({
45010
45122
  searchSpec,
45011
45123
  fetchCreatorDetails
45012
45124
  }) {
45013
- const [creators, setCreators] = (0, import_react91.useState)([]);
45014
- const [loading, setLoading] = (0, import_react91.useState)(false);
45125
+ const [creators, setCreators] = (0, import_react92.useState)([]);
45126
+ const [loading, setLoading] = (0, import_react92.useState)(false);
45015
45127
  const fetcher = fetchCreatorDetails ?? defaultFetchCreatorDetails;
45016
- const loadCreators = (0, import_react91.useCallback)(async () => {
45128
+ const loadCreators = (0, import_react92.useCallback)(async () => {
45017
45129
  if (!creatorIds.length) return;
45018
45130
  setLoading(true);
45019
45131
  try {
@@ -45025,7 +45137,7 @@ function CreatorExpandedPanel({
45025
45137
  setLoading(false);
45026
45138
  }
45027
45139
  }, [creatorIds, sessionId, version, fetcher]);
45028
- (0, import_react91.useEffect)(() => {
45140
+ (0, import_react92.useEffect)(() => {
45029
45141
  if (isOpen && creatorIds.length > 0) {
45030
45142
  loadCreators();
45031
45143
  }
@@ -45079,13 +45191,18 @@ function CreatorExpandedPanel({
45079
45191
  }
45080
45192
 
45081
45193
  // src/molecules/creator-discovery/CreatorWidget/useCreatorWidgetPolling.ts
45082
- var import_react92 = require("react");
45194
+ var import_react93 = require("react");
45083
45195
  var DEFAULT_POLLING_CONFIG = {
45084
45196
  pollInterval: 5e3,
45085
45197
  maxDuration: 15 * 60 * 1e3,
45086
45198
  maxErrors: 10,
45087
45199
  secondsPerCreator: 13
45088
45200
  };
45201
+ var formatTime = (seconds) => {
45202
+ if (seconds <= 0) return "to complete";
45203
+ const minutes = Math.floor(seconds / 60);
45204
+ return minutes >= 1 ? `${minutes} min remaining...` : `${seconds} sec remaining...`;
45205
+ };
45089
45206
  function useCreatorWidgetPolling({
45090
45207
  sessionId,
45091
45208
  currentVersion,
@@ -45096,136 +45213,137 @@ function useCreatorWidgetPolling({
45096
45213
  }) {
45097
45214
  const fetchVersions = fetchVersionsProp ?? defaultFetchVersions;
45098
45215
  const fetchStatus = fetchStatusProp ?? defaultFetchStatus;
45099
- const config = (0, import_react92.useMemo)(
45216
+ const config = (0, import_react93.useMemo)(
45100
45217
  () => ({ ...DEFAULT_POLLING_CONFIG, ...pollingConfig }),
45101
45218
  [pollingConfig]
45102
45219
  );
45103
- const [versionData, setVersionData] = (0, import_react92.useState)(null);
45104
- const [totalVersions, setTotalVersions] = (0, import_react92.useState)(0);
45105
- const [selectedVersion, setSelectedVersion] = (0, import_react92.useState)();
45106
- const [isLoadingVersion, setIsLoadingVersion] = (0, import_react92.useState)(false);
45107
- const [isValidationComplete, setIsValidationComplete] = (0, import_react92.useState)(false);
45108
- const [versionStatus, setVersionStatus] = (0, import_react92.useState)("checking");
45109
- const [statusDetails, setStatusDetails] = (0, import_react92.useState)();
45110
- const [timeDisplay, setTimeDisplay] = (0, import_react92.useState)("");
45111
- const [loadingStatus, setLoadingStatus] = (0, import_react92.useState)(true);
45112
- const remainingTimeRef = (0, import_react92.useRef)(0);
45220
+ const [versionData, setVersionData] = (0, import_react93.useState)(null);
45221
+ const [totalVersions, setTotalVersions] = (0, import_react93.useState)(0);
45222
+ const [selectedVersion, setSelectedVersion] = (0, import_react93.useState)();
45223
+ const [isLoadingVersion, setIsLoadingVersion] = (0, import_react93.useState)(false);
45224
+ const [isValidationComplete, setIsValidationComplete] = (0, import_react93.useState)(false);
45225
+ const [versionStatus, setVersionStatus] = (0, import_react93.useState)("checking");
45226
+ const [statusDetails, setStatusDetails] = (0, import_react93.useState)();
45227
+ const [timeDisplay, setTimeDisplay] = (0, import_react93.useState)("");
45228
+ const [loadingStatus, setLoadingStatus] = (0, import_react93.useState)(true);
45229
+ const remainingTimeRef = (0, import_react93.useRef)(0);
45230
+ const countdownRef = (0, import_react93.useRef)(null);
45113
45231
  const requestedVersion = selectedVersion ?? currentVersion ?? versionData?.currentVersion;
45114
- const fetchVersionData = (0, import_react92.useCallback)(async () => {
45115
- if (!sessionId) return;
45116
- if (!versionData) setIsLoadingVersion(true);
45117
- try {
45118
- const data = await fetchVersions({
45119
- sessionId,
45120
- version: requestedVersion,
45121
- validated: isValidationComplete
45122
- });
45123
- if (data.success !== false) {
45232
+ const updateStatus = (0, import_react93.useCallback)(
45233
+ (status) => {
45234
+ setVersionStatus(status);
45235
+ onStatusChange?.(status);
45236
+ },
45237
+ [onStatusChange]
45238
+ );
45239
+ const versionKey = sessionId ? `creator:versions:${sessionId}:${requestedVersion ?? "latest"}:${isValidationComplete ? 1 : 0}` : null;
45240
+ useSharedPoll(
45241
+ {
45242
+ key: versionKey,
45243
+ intervalMs: config.pollInterval,
45244
+ fetcher: async () => {
45245
+ if (!versionData) setIsLoadingVersion(true);
45246
+ return fetchVersions({
45247
+ sessionId,
45248
+ version: requestedVersion,
45249
+ validated: isValidationComplete
45250
+ });
45251
+ },
45252
+ shouldContinue: (data) => !((data?.totalVersions || 0) > 0)
45253
+ },
45254
+ (data) => {
45255
+ if (data && data.success !== false) {
45124
45256
  setVersionData(data);
45125
45257
  setTotalVersions(data.totalVersions || 0);
45126
45258
  }
45127
- } catch (err) {
45128
- if (err.name !== "AbortError") {
45259
+ setIsLoadingVersion(false);
45260
+ },
45261
+ (err) => {
45262
+ if (err?.name !== "AbortError") {
45129
45263
  console.error("Error fetching creator version:", err);
45130
45264
  }
45131
- } finally {
45132
45265
  setIsLoadingVersion(false);
45133
45266
  }
45134
- }, [sessionId, requestedVersion, isValidationComplete, fetchVersions, versionData]);
45135
- (0, import_react92.useEffect)(() => {
45136
- fetchVersionData();
45137
- }, [sessionId, requestedVersion, isValidationComplete]);
45138
- (0, import_react92.useEffect)(() => {
45139
- if (totalVersions > 0 || !sessionId) return;
45140
- const interval = setInterval(() => {
45141
- if (totalVersions === 0) fetchVersionData();
45142
- }, config.pollInterval);
45143
- return () => clearInterval(interval);
45144
- }, [totalVersions, sessionId, fetchVersionData, config.pollInterval]);
45145
- (0, import_react92.useEffect)(() => {
45146
- if (!selectedVersion && !requestedVersion) return;
45147
- const activeVersion = selectedVersion ?? requestedVersion;
45148
- let isMounted = true;
45149
- let intervalId = null;
45150
- let timerIntervalId = null;
45151
- let elapsed = 0;
45152
- let errorCount = 0;
45267
+ );
45268
+ const activeVersion = selectedVersion ?? requestedVersion;
45269
+ const statusKey = sessionId && activeVersion != null ? `creator:status:${sessionId}:${activeVersion}` : null;
45270
+ const errorCountRef = (0, import_react93.useRef)(0);
45271
+ const deadlineRef = (0, import_react93.useRef)(0);
45272
+ const doneRef = (0, import_react93.useRef)(false);
45273
+ const stopCountdown = (0, import_react93.useCallback)(() => {
45274
+ if (countdownRef.current) {
45275
+ clearInterval(countdownRef.current);
45276
+ countdownRef.current = null;
45277
+ }
45278
+ setTimeDisplay("");
45279
+ }, []);
45280
+ (0, import_react93.useEffect)(() => {
45281
+ if (statusKey == null) return;
45153
45282
  setLoadingStatus(true);
45154
45283
  setStatusDetails(void 0);
45155
45284
  setVersionStatus("checking");
45285
+ errorCountRef.current = 0;
45286
+ doneRef.current = false;
45287
+ deadlineRef.current = Date.now() + config.maxDuration;
45156
45288
  const creatorLength2 = versionData?.length || 0;
45157
45289
  remainingTimeRef.current = creatorLength2 > 0 ? creatorLength2 * config.secondsPerCreator : 60;
45158
- const formatTime = (seconds) => {
45159
- if (seconds <= 0) return "to complete";
45160
- const minutes = Math.floor(seconds / 60);
45161
- return minutes >= 1 ? `${minutes} min remaining...` : `${seconds} sec remaining...`;
45162
- };
45163
45290
  setTimeDisplay(formatTime(remainingTimeRef.current));
45164
- timerIntervalId = setInterval(() => {
45291
+ countdownRef.current = setInterval(() => {
45165
45292
  if (remainingTimeRef.current > 0) remainingTimeRef.current -= 1;
45166
45293
  setTimeDisplay(formatTime(remainingTimeRef.current));
45167
45294
  }, 1e3);
45168
- const updateStatus = (status) => {
45169
- setVersionStatus(status);
45170
- onStatusChange?.(status);
45171
- };
45172
- const stopPolling = () => {
45173
- if (intervalId) clearInterval(intervalId);
45174
- if (timerIntervalId) clearInterval(timerIntervalId);
45175
- setTimeDisplay("");
45295
+ return () => {
45296
+ if (countdownRef.current) {
45297
+ clearInterval(countdownRef.current);
45298
+ countdownRef.current = null;
45299
+ }
45176
45300
  };
45177
- const pollStatus = async () => {
45178
- try {
45179
- const data = await fetchStatus({
45180
- sessionId,
45181
- versionNo: activeVersion
45182
- });
45183
- if (!isMounted) return;
45184
- if (data?.status) setStatusDetails(data.status);
45301
+ }, [statusKey]);
45302
+ useSharedPoll(
45303
+ {
45304
+ key: statusKey,
45305
+ intervalMs: config.pollInterval,
45306
+ fetcher: async () => fetchStatus({ sessionId, versionNo: activeVersion }),
45307
+ shouldContinue: (data) => {
45308
+ if (Date.now() >= deadlineRef.current) return false;
45185
45309
  const s = data?.status?.status;
45186
- if (s === "completed" || s === "complete") {
45187
- updateStatus(s);
45188
- setIsValidationComplete(true);
45189
- stopPolling();
45190
- return;
45191
- }
45192
- if (s === "failed") {
45193
- updateStatus("failed");
45194
- stopPolling();
45195
- return;
45196
- }
45197
- errorCount = 0;
45198
- updateStatus(s || "in-progress");
45199
- } catch (err) {
45200
- console.error("Error fetching status:", err);
45201
- errorCount++;
45202
- if (errorCount >= config.maxErrors) {
45203
- console.error(`Polling failed after ${config.maxErrors} consecutive errors`);
45204
- updateStatus("failed");
45205
- setLoadingStatus(false);
45206
- stopPolling();
45207
- return;
45208
- }
45209
- } finally {
45210
- setLoadingStatus(false);
45310
+ return !(s === "completed" || s === "complete" || s === "failed");
45211
45311
  }
45212
- };
45213
- pollStatus();
45214
- intervalId = setInterval(() => {
45215
- elapsed += config.pollInterval;
45216
- if (elapsed >= config.maxDuration) {
45217
- console.warn("Stopped polling after max duration");
45218
- stopPolling();
45312
+ },
45313
+ (data) => {
45314
+ if (data?.status) setStatusDetails(data.status);
45315
+ const s = data?.status?.status;
45316
+ if (s === "completed" || s === "complete") {
45317
+ updateStatus(s);
45318
+ setIsValidationComplete(true);
45319
+ doneRef.current = true;
45320
+ stopCountdown();
45321
+ } else if (s === "failed") {
45322
+ updateStatus("failed");
45323
+ doneRef.current = true;
45324
+ stopCountdown();
45219
45325
  } else {
45220
- pollStatus();
45326
+ errorCountRef.current = 0;
45327
+ updateStatus(s || "in-progress");
45221
45328
  }
45222
- }, config.pollInterval);
45223
- return () => {
45224
- isMounted = false;
45225
- stopPolling();
45226
- };
45227
- }, [selectedVersion, requestedVersion, sessionId]);
45228
- const versionNumbers = (0, import_react92.useMemo)(() => {
45329
+ setLoadingStatus(false);
45330
+ },
45331
+ (err) => {
45332
+ console.error("Error fetching status:", err);
45333
+ errorCountRef.current++;
45334
+ if (errorCountRef.current >= config.maxErrors) {
45335
+ console.error(
45336
+ `Polling failed after ${config.maxErrors} consecutive errors`
45337
+ );
45338
+ updateStatus("failed");
45339
+ doneRef.current = true;
45340
+ stopCountdown();
45341
+ if (statusKey) stopSharedPoll(statusKey);
45342
+ }
45343
+ setLoadingStatus(false);
45344
+ }
45345
+ );
45346
+ const versionNumbers = (0, import_react93.useMemo)(() => {
45229
45347
  if (!totalVersions) return [];
45230
45348
  return Array.from({ length: totalVersions }, (_, i) => i + 1);
45231
45349
  }, [totalVersions]);
@@ -45265,7 +45383,7 @@ function CreatorWidgetInner({
45265
45383
  onAction,
45266
45384
  className
45267
45385
  }) {
45268
- const [isExpanded, setIsExpanded] = (0, import_react93.useState)(false);
45386
+ const [isExpanded, setIsExpanded] = (0, import_react94.useState)(false);
45269
45387
  const {
45270
45388
  versionNumbers,
45271
45389
  selectedVersion,
@@ -45286,11 +45404,11 @@ function CreatorWidgetInner({
45286
45404
  pollingConfig,
45287
45405
  onStatusChange
45288
45406
  });
45289
- const handleVersionSelect = (0, import_react93.useCallback)(
45407
+ const handleVersionSelect = (0, import_react94.useCallback)(
45290
45408
  (version) => setSelectedVersion(version),
45291
45409
  [setSelectedVersion]
45292
45410
  );
45293
- const handleViewCreators = (0, import_react93.useCallback)(() => {
45411
+ const handleViewCreators = (0, import_react94.useCallback)(() => {
45294
45412
  setIsExpanded(true);
45295
45413
  onAction?.({
45296
45414
  type: "view-creators",
@@ -45331,10 +45449,10 @@ function CreatorWidgetInner({
45331
45449
  )
45332
45450
  ] });
45333
45451
  }
45334
- var CreatorWidget = (0, import_react93.memo)(CreatorWidgetInner);
45452
+ var CreatorWidget = (0, import_react94.memo)(CreatorWidgetInner);
45335
45453
 
45336
45454
  // src/molecules/analytics/AnalyticsChart.tsx
45337
- var import_react94 = require("react");
45455
+ var import_react95 = require("react");
45338
45456
  var import_jsx_runtime178 = require("react/jsx-runtime");
45339
45457
  function getCSSVar(name) {
45340
45458
  if (typeof document === "undefined") return "";
@@ -45447,16 +45565,16 @@ function AnalyticsChart({
45447
45565
  loading: loadingProp,
45448
45566
  error: errorProp
45449
45567
  }) {
45450
- const [mounted, setMounted] = (0, import_react94.useState)(false);
45451
- const [fetchedConfig, setFetchedConfig] = (0, import_react94.useState)(null);
45452
- const [fetching, setFetching] = (0, import_react94.useState)(false);
45453
- const [fetchError, setFetchError] = (0, import_react94.useState)(null);
45454
- const containerRef = (0, import_react94.useRef)(null);
45455
- const chartRef = (0, import_react94.useRef)(null);
45456
- (0, import_react94.useEffect)(() => {
45568
+ const [mounted, setMounted] = (0, import_react95.useState)(false);
45569
+ const [fetchedConfig, setFetchedConfig] = (0, import_react95.useState)(null);
45570
+ const [fetching, setFetching] = (0, import_react95.useState)(false);
45571
+ const [fetchError, setFetchError] = (0, import_react95.useState)(null);
45572
+ const containerRef = (0, import_react95.useRef)(null);
45573
+ const chartRef = (0, import_react95.useRef)(null);
45574
+ (0, import_react95.useEffect)(() => {
45457
45575
  setMounted(true);
45458
45576
  }, []);
45459
- (0, import_react94.useEffect)(() => {
45577
+ (0, import_react95.useEffect)(() => {
45460
45578
  if (!chartId || configProp) return;
45461
45579
  let cancelled = false;
45462
45580
  setFetching(true);
@@ -45478,7 +45596,7 @@ function AnalyticsChart({
45478
45596
  };
45479
45597
  }, [chartId, apiBase, authToken, configProp]);
45480
45598
  const activeConfig = configProp ?? fetchedConfig;
45481
- (0, import_react94.useEffect)(() => {
45599
+ (0, import_react95.useEffect)(() => {
45482
45600
  if (!mounted || !activeConfig || !containerRef.current) return;
45483
45601
  const container = containerRef.current;
45484
45602
  let cancelled = false;
@@ -45498,7 +45616,7 @@ function AnalyticsChart({
45498
45616
  cancelled = true;
45499
45617
  };
45500
45618
  }, [mounted, activeConfig]);
45501
- (0, import_react94.useEffect)(() => {
45619
+ (0, import_react95.useEffect)(() => {
45502
45620
  return () => {
45503
45621
  if (chartRef.current) {
45504
45622
  try {
@@ -45509,7 +45627,7 @@ function AnalyticsChart({
45509
45627
  }
45510
45628
  };
45511
45629
  }, []);
45512
- (0, import_react94.useEffect)(() => {
45630
+ (0, import_react95.useEffect)(() => {
45513
45631
  if (!mounted || !containerRef.current) return;
45514
45632
  const obs = new ResizeObserver(() => {
45515
45633
  try {
@@ -45991,7 +46109,7 @@ function EmptyContent({ className, ...props }) {
45991
46109
  }
45992
46110
 
45993
46111
  // src/components/ui/field.tsx
45994
- var import_react95 = require("react");
46112
+ var import_react96 = require("react");
45995
46113
  var import_class_variance_authority10 = require("class-variance-authority");
45996
46114
  var import_jsx_runtime181 = require("react/jsx-runtime");
45997
46115
  function FieldSet({ className, ...props }) {
@@ -46174,7 +46292,7 @@ function FieldError({
46174
46292
  errors,
46175
46293
  ...props
46176
46294
  }) {
46177
- const content = (0, import_react95.useMemo)(() => {
46295
+ const content = (0, import_react96.useMemo)(() => {
46178
46296
  if (children) {
46179
46297
  return children;
46180
46298
  }
@@ -47212,6 +47330,37 @@ ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
47212
47330
  // src/render/PXEngineRenderer.tsx
47213
47331
  var import_jsx_runtime188 = require("react/jsx-runtime");
47214
47332
  var MOLECULE_REFS = new Set(Object.values(molecules_exports));
47333
+ var ATOMS_WITH_RENDER = /* @__PURE__ */ new Set([
47334
+ "LayoutAtom",
47335
+ "CardAtom",
47336
+ "TabsAtom",
47337
+ "AccordionAtom",
47338
+ "ScrollAreaAtom",
47339
+ "CarouselAtom",
47340
+ "AspectRatioAtom",
47341
+ "CollapsibleAtom",
47342
+ "TooltipAtom",
47343
+ "PopoverAtom",
47344
+ "DialogAtom",
47345
+ "SheetAtom",
47346
+ "ResizableAtom"
47347
+ ]);
47348
+ var COMPONENT_LOOKUP_CACHE = /* @__PURE__ */ new Map();
47349
+ var resolveComponent = (identifier) => {
47350
+ const cached = COMPONENT_LOOKUP_CACHE.get(identifier);
47351
+ if (cached !== void 0) return cached;
47352
+ const normalized = identifier.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
47353
+ const atomName = normalized.endsWith("Atom") ? normalized : `${normalized}Atom`;
47354
+ let Comp = atoms_exports[atomName] || atoms_exports[normalized] || atoms_exports[identifier] || null;
47355
+ if (!Comp) {
47356
+ Comp = molecules_exports[normalized] || molecules_exports[identifier] || null;
47357
+ }
47358
+ if (!Comp && !CONTEXT_DEPENDENT_COMPONENTS.has(normalized)) {
47359
+ Comp = ui_exports[normalized] || ui_exports[identifier] || null;
47360
+ }
47361
+ COMPONENT_LOOKUP_CACHE.set(identifier, Comp);
47362
+ return Comp;
47363
+ };
47215
47364
  var CONTEXT_DEPENDENT_COMPONENTS = /* @__PURE__ */ new Set([
47216
47365
  // Form components - require FormField + FormItem context
47217
47366
  "FormLabel",
@@ -47340,7 +47489,10 @@ var renderContextDependentError = (componentName, normalizedName, key) => {
47340
47489
  key
47341
47490
  );
47342
47491
  };
47492
+ var NORMALIZE_PROPS_CACHE = /* @__PURE__ */ new WeakMap();
47343
47493
  var normalizeProps = (props) => {
47494
+ const cached = NORMALIZE_PROPS_CACHE.get(props);
47495
+ if (cached) return cached;
47344
47496
  const normalized = {};
47345
47497
  const dynamicStyle = {};
47346
47498
  Object.entries(props).forEach(([key, value]) => {
@@ -47400,7 +47552,9 @@ var normalizeProps = (props) => {
47400
47552
  }
47401
47553
  normalized[key] = value;
47402
47554
  });
47403
- return { normalized, dynamicStyle };
47555
+ const result = { normalized, dynamicStyle };
47556
+ NORMALIZE_PROPS_CACHE.set(props, result);
47557
+ return result;
47404
47558
  };
47405
47559
  var FORM_INPUT_ATOM_NAMES = /* @__PURE__ */ new Set([
47406
47560
  "InputAtom",
@@ -47419,18 +47573,18 @@ var FORM_INPUT_ATOM_NAMES = /* @__PURE__ */ new Set([
47419
47573
  "InputOTPAtom",
47420
47574
  "ToggleAtom"
47421
47575
  ]);
47422
- var PXEngineRenderer = ({
47576
+ var PXEngineRenderer = import_react97.default.memo(function PXEngineRenderer2({
47423
47577
  schema,
47424
47578
  onAction,
47425
47579
  disabled,
47426
47580
  theme,
47427
47581
  onFormSubmit
47428
- }) => {
47429
- const contextTheme = import_react96.default.useContext(WidgetThemeContext);
47582
+ }) {
47583
+ const contextTheme = import_react97.default.useContext(WidgetThemeContext);
47430
47584
  const effectiveTheme = theme ?? contextTheme;
47431
- const formValuesRef = import_react96.default.useRef({});
47432
- const [, forceUpdate] = import_react96.default.useReducer((x) => x + 1, 0);
47433
- const handleInputValueChange = import_react96.default.useCallback((key, value) => {
47585
+ const formValuesRef = import_react97.default.useRef({});
47586
+ const [, forceUpdate] = import_react97.default.useReducer((x) => x + 1, 0);
47587
+ const handleInputValueChange = import_react97.default.useCallback((key, value) => {
47434
47588
  formValuesRef.current[key] = value;
47435
47589
  forceUpdate();
47436
47590
  }, []);
@@ -47438,12 +47592,12 @@ var PXEngineRenderer = ({
47438
47592
  const root = schema.root || schema;
47439
47593
  const renderRecursive = (component, index) => {
47440
47594
  if (Array.isArray(component)) {
47441
- return /* @__PURE__ */ (0, import_jsx_runtime188.jsx)(import_react96.default.Fragment, { children: component.map((child, idx) => renderRecursive(child, idx)) }, index !== void 0 ? `array-${index}` : "array-root");
47595
+ return /* @__PURE__ */ (0, import_jsx_runtime188.jsx)(import_react97.default.Fragment, { children: component.map((child, idx) => renderRecursive(child, idx)) }, index !== void 0 ? `array-${index}` : "array-root");
47442
47596
  }
47443
47597
  if (typeof component === "string" || typeof component === "number") {
47444
47598
  return component;
47445
47599
  }
47446
- if (import_react96.default.isValidElement(component)) {
47600
+ if (import_react97.default.isValidElement(component)) {
47447
47601
  return component;
47448
47602
  }
47449
47603
  if (!component || typeof component !== "object") return null;
@@ -47460,28 +47614,34 @@ var PXEngineRenderer = ({
47460
47614
  } = component;
47461
47615
  const componentName = name || type || componentType;
47462
47616
  if (!componentName || typeof componentName !== "string") return null;
47463
- const rawProps = { ...remainingProps, ...props };
47464
- delete rawProps.key;
47465
- if (disabled !== void 0 && rawProps.disabled === void 0) {
47466
- rawProps.disabled = disabled;
47617
+ const hasRemaining = Object.keys(remainingProps).length > 0;
47618
+ let baseProps = hasRemaining ? { ...remainingProps, ...props } : props;
47619
+ if (baseProps && baseProps.key !== void 0) {
47620
+ const { key: _k, ...rest } = baseProps;
47621
+ baseProps = rest;
47622
+ }
47623
+ const { normalized, dynamicStyle } = normalizeProps(baseProps || {});
47624
+ const finalProps = { ...normalized };
47625
+ if (disabled !== void 0 && finalProps.disabled === void 0) {
47626
+ finalProps.disabled = disabled;
47467
47627
  }
47468
47628
  const normalizedName = componentName.charAt(0).toUpperCase() + componentName.slice(1);
47469
47629
  const earlyAtomName = normalizedName.endsWith("Atom") ? normalizedName : `${normalizedName}Atom`;
47470
47630
  if (onFormSubmit && FORM_INPUT_ATOM_NAMES.has(earlyAtomName)) {
47471
- const fieldKey = rawProps.fieldKey || rawProps.id || id || rawProps.label || componentName;
47631
+ const fieldKey = finalProps.fieldKey || finalProps.id || id || finalProps.label || componentName;
47472
47632
  const storedValue = formValuesRef.current[fieldKey];
47473
47633
  if (storedValue !== void 0) {
47474
- rawProps.defaultValue = storedValue;
47634
+ finalProps.defaultValue = storedValue;
47475
47635
  }
47476
- rawProps.onValueChange = handleInputValueChange;
47477
- rawProps.fieldKey = fieldKey;
47478
- if (id) rawProps.id = id;
47636
+ finalProps.onValueChange = handleInputValueChange;
47637
+ finalProps.fieldKey = fieldKey;
47638
+ if (id) finalProps.id = id;
47479
47639
  }
47480
47640
  if (onFormSubmit && earlyAtomName === "ButtonAtom") {
47481
- const action = rawProps.action || rawProps.buttonAction;
47641
+ const action = finalProps.action || finalProps.buttonAction;
47482
47642
  if (action === "submit") {
47483
- const originalOnAction = rawProps.onAction;
47484
- rawProps.onAction = (evt) => {
47643
+ const originalOnAction = finalProps.onAction;
47644
+ finalProps.onAction = (evt) => {
47485
47645
  const elements = Object.entries(formValuesRef.current).map(
47486
47646
  ([key, value]) => ({
47487
47647
  id: key,
@@ -47497,23 +47657,10 @@ var PXEngineRenderer = ({
47497
47657
  };
47498
47658
  }
47499
47659
  }
47500
- const { normalized: finalProps, dynamicStyle } = normalizeProps(rawProps);
47501
47660
  if (id && !finalProps.id) {
47502
47661
  finalProps.id = id;
47503
47662
  }
47504
47663
  const uniqueKey = id || (index !== void 0 ? `${componentName}-${index}` : `${componentName}-root`);
47505
- const resolveComponent = (identifier) => {
47506
- const normalized = identifier.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
47507
- const atomName2 = normalized.endsWith("Atom") ? normalized : `${normalized}Atom`;
47508
- let Comp = atoms_exports[atomName2] || atoms_exports[normalized] || atoms_exports[identifier];
47509
- if (!Comp) {
47510
- Comp = molecules_exports[normalized] || molecules_exports[identifier];
47511
- }
47512
- if (!Comp && !CONTEXT_DEPENDENT_COMPONENTS.has(normalized)) {
47513
- Comp = ui_exports[normalized] || ui_exports[identifier];
47514
- }
47515
- return Comp;
47516
- };
47517
47664
  let TargetComponent = resolveComponent(componentName);
47518
47665
  let resolvedIdentifier = componentName;
47519
47666
  if (!TargetComponent && type && type !== componentName) {
@@ -47538,21 +47685,6 @@ var PXEngineRenderer = ({
47538
47685
  }
47539
47686
  const resolvedNormalized = resolvedIdentifier.charAt(0).toUpperCase() + resolvedIdentifier.slice(1);
47540
47687
  const atomName = resolvedNormalized.endsWith("Atom") ? resolvedNormalized : `${resolvedNormalized}Atom`;
47541
- const ATOMS_WITH_RENDER = /* @__PURE__ */ new Set([
47542
- "LayoutAtom",
47543
- "CardAtom",
47544
- "TabsAtom",
47545
- "AccordionAtom",
47546
- "ScrollAreaAtom",
47547
- "CarouselAtom",
47548
- "AspectRatioAtom",
47549
- "CollapsibleAtom",
47550
- "TooltipAtom",
47551
- "PopoverAtom",
47552
- "DialogAtom",
47553
- "SheetAtom",
47554
- "ResizableAtom"
47555
- ]);
47556
47688
  const isAtomWithRenderProp = ATOMS_WITH_RENDER.has(atomName);
47557
47689
  if (effectiveTheme && finalProps.theme === void 0 && MOLECULE_REFS.has(TargetComponent)) {
47558
47690
  finalProps.theme = effectiveTheme;
@@ -47586,7 +47718,8 @@ var PXEngineRenderer = ({
47586
47718
  }
47587
47719
  };
47588
47720
  return /* @__PURE__ */ (0, import_jsx_runtime188.jsx)(WidgetThemeContext.Provider, { value: effectiveTheme, children: /* @__PURE__ */ (0, import_jsx_runtime188.jsx)("div", { className: "px-engine-root relative w-full h-full", children: renderRecursive(root) }) });
47589
- };
47721
+ });
47722
+ PXEngineRenderer.displayName = "PXEngineRenderer";
47590
47723
  // Annotate the CommonJS export names for ESM import in node:
47591
47724
  0 && (module.exports = {
47592
47725
  Accordion,
@@ -47904,7 +48037,11 @@ var PXEngineRenderer = ({
47904
48037
  formatQAMessage,
47905
48038
  generateFieldsFromData,
47906
48039
  generateFieldsFromPropDefinitions,
48040
+ getPxAuthToken,
47907
48041
  isInputAtom,
48042
+ notifyPxUnauthorized,
48043
+ setPxAuthTokenProvider,
48044
+ setPxUnauthorizedHandler,
47908
48045
  submitWidgetToAgent,
47909
48046
  th,
47910
48047
  useCreatorWidgetPolling,