pxengine 0.1.62 → 0.1.64

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.mjs CHANGED
@@ -37542,8 +37542,13 @@ var MCQCard = React96.memo(
37542
37542
  sessionId,
37543
37543
  sendMessage,
37544
37544
  fetchSelections = defaultFetchSelections,
37545
- persistSelection = defaultPersistSelection
37545
+ persistSelection = defaultPersistSelection,
37546
+ ...allProps
37546
37547
  }) => {
37548
+ const resolvedQuestion = question || allProps.Question || allProps.q || "";
37549
+ const resolvedOptions = options || allProps.Options || allProps.opts || {};
37550
+ const resolvedRecommended = recommended || allProps.Recommended || allProps.rec;
37551
+ console.log("[MCQCard] FULL PROPS:", { allProps, resolvedQuestion, resolvedOptions: Object.keys(resolvedOptions || {}), resolvedRecommended });
37547
37552
  const [selectedOption, setSelectedOption] = React96.useState(propsSelectedOption);
37548
37553
  const [isProceeded, setIsProceeded] = React96.useState(false);
37549
37554
  const fetchedSessionRef = React96.useRef("");
@@ -37553,24 +37558,39 @@ var MCQCard = React96.memo(
37553
37558
  setIsProceeded(true);
37554
37559
  }
37555
37560
  }, [propsSelectedOption]);
37561
+ const buildQuestionKey = React96.useCallback((sid, question2) => {
37562
+ let hash = 2166136261;
37563
+ for (let i = 0; i < question2.length; i++) {
37564
+ hash ^= question2.charCodeAt(i);
37565
+ hash = hash * 16777619 >>> 0;
37566
+ }
37567
+ return `mcq_${sid}_${hash.toString(36)}`;
37568
+ }, []);
37556
37569
  React96.useEffect(() => {
37557
- if (!sessionId || fetchedSessionRef.current === sessionId) return;
37570
+ if (!sessionId || !resolvedQuestion) return;
37571
+ const fetchKey = `${sessionId}::${resolvedQuestion}`;
37572
+ if (fetchedSessionRef.current === fetchKey) return;
37558
37573
  if (propsSelectedOption) return;
37559
- fetchedSessionRef.current = sessionId;
37560
- const questionKey = question || "unknown";
37574
+ fetchedSessionRef.current = fetchKey;
37575
+ const questionKey = buildQuestionKey(sessionId, resolvedQuestion);
37576
+ console.log("[MCQCard] Fetching with key:", questionKey, "(question:", resolvedQuestion, ")");
37561
37577
  fetchSelections(sessionId).then((selections) => {
37562
- const stored = selections[questionKey];
37578
+ console.log("[MCQCard] Got selections:", selections);
37579
+ const stored = selections[questionKey] || selections[resolvedQuestion] || selections[`mcq_${sessionId}`];
37563
37580
  if (stored) {
37581
+ console.log("[MCQCard] Setting selected:", stored);
37564
37582
  setSelectedOption(stored);
37565
37583
  setIsProceeded(true);
37566
37584
  }
37567
- });
37568
- }, [sessionId, question, propsSelectedOption, fetchSelections]);
37585
+ }).catch((err) => console.error("[MCQCard] Fetch error:", err));
37586
+ }, [sessionId, propsSelectedOption, resolvedQuestion, buildQuestionKey]);
37569
37587
  const isDiscovery = disableContinueInDiscovery !== void 0 ? disableContinueInDiscovery : typeof window !== "undefined" && window.location.pathname.includes("creator-discovery");
37570
37588
  const handleOptionClick = (key, e) => {
37571
37589
  e.preventDefault();
37572
37590
  e.stopPropagation();
37591
+ console.log("[MCQCard] Option clicked:", key, "Can select:", isLatestMessage && !isLoading && !disabled && !isProceeded);
37573
37592
  if (isLatestMessage && !isLoading && !disabled && !isProceeded) {
37593
+ console.log("[MCQCard] Setting selected to:", key);
37574
37594
  setSelectedOption(key);
37575
37595
  onSelect?.(key);
37576
37596
  }
@@ -37583,8 +37603,9 @@ var MCQCard = React96.memo(
37583
37603
  const rawLabel = options && options[result];
37584
37604
  const label = typeof rawLabel === "string" ? rawLabel : typeof rawLabel === "object" && rawLabel !== null ? rawLabel.label || rawLabel.description || result : result;
37585
37605
  setIsProceeded(true);
37586
- if (sessionId) {
37587
- const questionKey = question || "unknown";
37606
+ if (sessionId && resolvedQuestion) {
37607
+ const questionKey = buildQuestionKey(sessionId, resolvedQuestion);
37608
+ console.log("[MCQCard] Persisting:", questionKey, result);
37588
37609
  await persistSelection(sessionId, questionKey, result);
37589
37610
  }
37590
37611
  if (sendMessage) {
@@ -37600,7 +37621,7 @@ var MCQCard = React96.memo(
37600
37621
  };
37601
37622
  const isOptionsDisabled = disabled || !isLatestMessage || isProceeded && !disableContinueInDiscovery;
37602
37623
  const isContinueDisabled = disabled || !isLatestMessage || isProceeded || isDiscovery;
37603
- const optionsEntries = options ? Object.entries(options).map(([key, val]) => [
37624
+ const optionsEntries = resolvedOptions && Object.keys(resolvedOptions).length > 0 ? Object.entries(resolvedOptions).map(([key, val]) => [
37604
37625
  key,
37605
37626
  typeof val === "string" ? val : typeof val === "object" && val !== null ? val.label || val.description || val.id || JSON.stringify(val) : String(val ?? "")
37606
37627
  ]) : [];
@@ -37612,7 +37633,7 @@ var MCQCard = React96.memo(
37612
37633
  className
37613
37634
  ),
37614
37635
  children: [
37615
- /* @__PURE__ */ jsx125("div", { className: "mb-4", children: /* @__PURE__ */ jsx125("p", { className: "text-sm text-cardText", children: question }) }),
37636
+ /* @__PURE__ */ jsx125("div", { className: "mb-4", children: /* @__PURE__ */ jsx125("p", { className: "text-sm text-cardText", children: resolvedQuestion || "Select an option:" }) }),
37616
37637
  /* @__PURE__ */ jsx125("div", { className: "space-y-2.5 mb-4", children: optionsEntries.map(([key, label]) => {
37617
37638
  const isSelected = selectedOption === key;
37618
37639
  const isRecommended = key === recommended;