pxengine 0.1.63 → 0.1.65

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
@@ -37731,7 +37731,7 @@ var import_react66 = __toESM(require("react"), 1);
37731
37731
  // src/molecules/creator-discovery/MCQCard/defaultFetchers.ts
37732
37732
  function getBackendOrigin() {
37733
37733
  if (typeof window === "undefined") return null;
37734
- return window.__NEXT_DATA__?.runtimeConfig?.NEXT_PUBLIC_AGENT_BACKEND ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_AGENT_BACKEND : void 0) ?? window.__NEXT_DATA__?.runtimeConfig?.NEXT_PUBLIC_BACKEND_URL ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_BACKEND_URL : void 0) ?? null;
37734
+ return window.__NEXT_DATA__?.runtimeConfig?.NEXT_PUBLIC_AGENT_BACKEND ?? (typeof process !== "undefined" ? process.env?.NEXT_PUBLIC_AGENT_BACKEND : void 0) ?? null;
37735
37735
  }
37736
37736
  function getBaseUrl() {
37737
37737
  const backend = getBackendOrigin();
@@ -37833,8 +37833,13 @@ var MCQCard = import_react66.default.memo(
37833
37833
  sessionId,
37834
37834
  sendMessage,
37835
37835
  fetchSelections = defaultFetchSelections,
37836
- persistSelection = defaultPersistSelection
37836
+ persistSelection = defaultPersistSelection,
37837
+ ...allProps
37837
37838
  }) => {
37839
+ const resolvedQuestion = question || allProps.Question || allProps.q || "";
37840
+ const resolvedOptions = options || allProps.Options || allProps.opts || {};
37841
+ const resolvedRecommended = recommended || allProps.Recommended || allProps.rec;
37842
+ console.log("[MCQCard] FULL PROPS:", { allProps, resolvedQuestion, resolvedOptions: Object.keys(resolvedOptions || {}), resolvedRecommended });
37838
37843
  const [selectedOption, setSelectedOption] = import_react66.default.useState(propsSelectedOption);
37839
37844
  const [isProceeded, setIsProceeded] = import_react66.default.useState(false);
37840
37845
  const fetchedSessionRef = import_react66.default.useRef("");
@@ -37844,24 +37849,39 @@ var MCQCard = import_react66.default.memo(
37844
37849
  setIsProceeded(true);
37845
37850
  }
37846
37851
  }, [propsSelectedOption]);
37852
+ const buildQuestionKey = import_react66.default.useCallback((sid, question2) => {
37853
+ let hash = 2166136261;
37854
+ for (let i = 0; i < question2.length; i++) {
37855
+ hash ^= question2.charCodeAt(i);
37856
+ hash = hash * 16777619 >>> 0;
37857
+ }
37858
+ return `mcq_${sid}_${hash.toString(36)}`;
37859
+ }, []);
37847
37860
  import_react66.default.useEffect(() => {
37848
- if (!sessionId || fetchedSessionRef.current === sessionId) return;
37861
+ if (!sessionId || !resolvedQuestion) return;
37862
+ const fetchKey = `${sessionId}::${resolvedQuestion}`;
37863
+ if (fetchedSessionRef.current === fetchKey) return;
37849
37864
  if (propsSelectedOption) return;
37850
- fetchedSessionRef.current = sessionId;
37851
- const questionKey = question || "unknown";
37865
+ fetchedSessionRef.current = fetchKey;
37866
+ const questionKey = buildQuestionKey(sessionId, resolvedQuestion);
37867
+ console.log("[MCQCard] Fetching with key:", questionKey, "(question:", resolvedQuestion, ")");
37852
37868
  fetchSelections(sessionId).then((selections) => {
37853
- const stored = selections[questionKey];
37869
+ console.log("[MCQCard] Got selections:", selections);
37870
+ const stored = selections[questionKey] || selections[resolvedQuestion] || selections[`mcq_${sessionId}`];
37854
37871
  if (stored) {
37872
+ console.log("[MCQCard] Setting selected:", stored);
37855
37873
  setSelectedOption(stored);
37856
37874
  setIsProceeded(true);
37857
37875
  }
37858
- });
37859
- }, [sessionId, question, propsSelectedOption, fetchSelections]);
37876
+ }).catch((err) => console.error("[MCQCard] Fetch error:", err));
37877
+ }, [sessionId, propsSelectedOption, resolvedQuestion, buildQuestionKey]);
37860
37878
  const isDiscovery = disableContinueInDiscovery !== void 0 ? disableContinueInDiscovery : typeof window !== "undefined" && window.location.pathname.includes("creator-discovery");
37861
37879
  const handleOptionClick = (key, e) => {
37862
37880
  e.preventDefault();
37863
37881
  e.stopPropagation();
37882
+ console.log("[MCQCard] Option clicked:", key, "Can select:", isLatestMessage && !isLoading && !disabled && !isProceeded);
37864
37883
  if (isLatestMessage && !isLoading && !disabled && !isProceeded) {
37884
+ console.log("[MCQCard] Setting selected to:", key);
37865
37885
  setSelectedOption(key);
37866
37886
  onSelect?.(key);
37867
37887
  }
@@ -37874,8 +37894,9 @@ var MCQCard = import_react66.default.memo(
37874
37894
  const rawLabel = options && options[result];
37875
37895
  const label = typeof rawLabel === "string" ? rawLabel : typeof rawLabel === "object" && rawLabel !== null ? rawLabel.label || rawLabel.description || result : result;
37876
37896
  setIsProceeded(true);
37877
- if (sessionId) {
37878
- const questionKey = question || "unknown";
37897
+ if (sessionId && resolvedQuestion) {
37898
+ const questionKey = buildQuestionKey(sessionId, resolvedQuestion);
37899
+ console.log("[MCQCard] Persisting:", questionKey, result);
37879
37900
  await persistSelection(sessionId, questionKey, result);
37880
37901
  }
37881
37902
  if (sendMessage) {
@@ -37891,7 +37912,7 @@ var MCQCard = import_react66.default.memo(
37891
37912
  };
37892
37913
  const isOptionsDisabled = disabled || !isLatestMessage || isProceeded && !disableContinueInDiscovery;
37893
37914
  const isContinueDisabled = disabled || !isLatestMessage || isProceeded || isDiscovery;
37894
- const optionsEntries = options ? Object.entries(options).map(([key, val]) => [
37915
+ const optionsEntries = resolvedOptions && Object.keys(resolvedOptions).length > 0 ? Object.entries(resolvedOptions).map(([key, val]) => [
37895
37916
  key,
37896
37917
  typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || JSON.stringify(val) : String(val ?? "")
37897
37918
  ]) : [];
@@ -37903,7 +37924,7 @@ var MCQCard = import_react66.default.memo(
37903
37924
  className
37904
37925
  ),
37905
37926
  children: [
37906
- /* @__PURE__ */ (0, import_jsx_runtime125.jsx)("div", { className: "mb-4", children: /* @__PURE__ */ (0, import_jsx_runtime125.jsx)("p", { className: "text-sm text-cardText", children: question }) }),
37927
+ /* @__PURE__ */ (0, import_jsx_runtime125.jsx)("div", { className: "mb-4", children: /* @__PURE__ */ (0, import_jsx_runtime125.jsx)("p", { className: "text-sm text-cardText", children: resolvedQuestion || "Select an option:" }) }),
37907
37928
  /* @__PURE__ */ (0, import_jsx_runtime125.jsx)("div", { className: "space-y-2.5 mb-4", children: optionsEntries.map(([key, label]) => {
37908
37929
  const isSelected = selectedOption === key;
37909
37930
  const isRecommended = key === recommended;
@@ -40728,6 +40749,37 @@ function CreatorDisplay({
40728
40749
  ] })
40729
40750
  ] });
40730
40751
  }
40752
+ function CreatorCardSkeleton() {
40753
+ return /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "bg-paperBackground rounded-[25px] py-5 pl-7 pr-7 border-2 border-gray300 shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "flex flex-col gap-4 sm:grid sm:grid-cols-[1.3fr_1fr_2fr_120px] gap-8 items-start w-full", children: [
40754
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "flex items-start gap-1 md:gap-6", children: [
40755
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "w-[5rem] h-[5rem] rounded-[10px] bg-gray200 animate-pulse" }),
40756
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "flex flex-col gap-3", children: [
40757
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-5 w-36 rounded bg-gray200 animate-pulse" }),
40758
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-24 rounded bg-gray200 animate-pulse" }),
40759
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-32 rounded bg-gray200 animate-pulse" }),
40760
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-44 rounded bg-gray200 animate-pulse" })
40761
+ ] })
40762
+ ] }),
40763
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "space-y-3 w-full", children: [
40764
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-4 w-32 rounded bg-gray200 animate-pulse" }),
40765
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-4 w-28 rounded bg-gray200 animate-pulse" }),
40766
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-4 w-24 rounded bg-gray200 animate-pulse" })
40767
+ ] }),
40768
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "space-y-3 w-full", children: [
40769
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-4 w-40 rounded bg-gray200 animate-pulse" }),
40770
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-full rounded bg-gray200 animate-pulse" }),
40771
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-[90%] rounded bg-gray200 animate-pulse" }),
40772
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-3 w-[75%] rounded bg-gray200 animate-pulse" })
40773
+ ] }),
40774
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "hidden md:flex flex-col items-center justify-center gap-3", children: [
40775
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-6 w-16 rounded bg-gray200 animate-pulse" }),
40776
+ /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "h-4 w-20 rounded bg-gray200 animate-pulse" })
40777
+ ] })
40778
+ ] }) });
40779
+ }
40780
+ function CreatorDisplaySkeleton() {
40781
+ return /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "px-4 py-4 space-y-4", children: Array.from({ length: 3 }).map((_, idx) => /* @__PURE__ */ (0, import_jsx_runtime148.jsx)(CreatorCardSkeleton, {}, idx)) });
40782
+ }
40731
40783
  function CreatorExpandedPanel({
40732
40784
  isOpen,
40733
40785
  onClose,
@@ -40795,10 +40847,7 @@ function CreatorExpandedPanel({
40795
40847
  ] })
40796
40848
  ] }),
40797
40849
  /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "border-b border-gray300" }),
40798
- loading ? /* @__PURE__ */ (0, import_jsx_runtime148.jsxs)("div", { className: "flex flex-col items-center justify-center py-16 gap-3", children: [
40799
- /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("div", { className: "w-8 h-8 border-3 border-purple100 border-t-transparent rounded-full animate-spin" }),
40800
- /* @__PURE__ */ (0, import_jsx_runtime148.jsx)("p", { className: "text-sm text-gray600", children: "Fetching Creators" })
40801
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime148.jsx)(CreatorDisplay, { creators, isValidationComplete: version !== void 0 })
40850
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime148.jsx)(CreatorDisplaySkeleton, {}) : /* @__PURE__ */ (0, import_jsx_runtime148.jsx)(CreatorDisplay, { creators, isValidationComplete: version !== void 0 })
40802
40851
  ] })
40803
40852
  },
40804
40853
  "creator-panel"