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.cjs CHANGED
@@ -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;