pxengine 0.1.48 → 0.1.49

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.d.cts CHANGED
@@ -2124,8 +2124,13 @@ declare const MCQCard: React__default.NamedExoticComponent<MCQCardProps & {
2124
2124
 
2125
2125
  /**
2126
2126
  * Default fetchers for MCQCard self-contained mode.
2127
- * These hit relative API URLs via the agents-proxy, matching the
2128
- * endpoints in server/api/custom_agents/state.py.
2127
+ *
2128
+ * Uses localStorage as an instant cache layer:
2129
+ * - persist: writes to localStorage (sync) + backend (async) in parallel
2130
+ * - fetch: reads localStorage instantly, then backfills from backend
2131
+ *
2132
+ * This eliminates the delay where the component remounts after an agent
2133
+ * response and has to wait for the GET API before showing the selection.
2129
2134
  */
2130
2135
  declare function defaultFetchSelections(sessionId: string): Promise<Record<string, string>>;
2131
2136
  declare function defaultPersistSelection(sessionId: string, questionKey: string, value: string): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -2124,8 +2124,13 @@ declare const MCQCard: React__default.NamedExoticComponent<MCQCardProps & {
2124
2124
 
2125
2125
  /**
2126
2126
  * Default fetchers for MCQCard self-contained mode.
2127
- * These hit relative API URLs via the agents-proxy, matching the
2128
- * endpoints in server/api/custom_agents/state.py.
2127
+ *
2128
+ * Uses localStorage as an instant cache layer:
2129
+ * - persist: writes to localStorage (sync) + backend (async) in parallel
2130
+ * - fetch: reads localStorage instantly, then backfills from backend
2131
+ *
2132
+ * This eliminates the delay where the component remounts after an agent
2133
+ * response and has to wait for the GET API before showing the selection.
2129
2134
  */
2130
2135
  declare function defaultFetchSelections(sessionId: string): Promise<Record<string, string>>;
2131
2136
  declare function defaultPersistSelection(sessionId: string, questionKey: string, value: string): Promise<void>;
package/dist/index.mjs CHANGED
@@ -35629,7 +35629,26 @@ SearchSpecCard.displayName = "SearchSpecCard";
35629
35629
  import React92 from "react";
35630
35630
 
35631
35631
  // src/molecules/creator-discovery/MCQCard/defaultFetchers.ts
35632
+ var STORAGE_KEY = (sessionId) => `mcq_selections_${sessionId}`;
35633
+ function getLocalSelections(sessionId) {
35634
+ try {
35635
+ const raw = localStorage.getItem(STORAGE_KEY(sessionId));
35636
+ return raw ? JSON.parse(raw) : {};
35637
+ } catch {
35638
+ return {};
35639
+ }
35640
+ }
35641
+ function setLocalSelection(sessionId, questionKey, value) {
35642
+ try {
35643
+ const existing = getLocalSelections(sessionId);
35644
+ existing[questionKey] = value;
35645
+ localStorage.setItem(STORAGE_KEY(sessionId), JSON.stringify(existing));
35646
+ } catch {
35647
+ }
35648
+ }
35632
35649
  async function defaultFetchSelections(sessionId) {
35650
+ const local = getLocalSelections(sessionId);
35651
+ if (Object.keys(local).length > 0) return local;
35633
35652
  try {
35634
35653
  const res = await fetch(
35635
35654
  `/api/agents-proxy/custom-agents/sessions/${sessionId}/mcq-selections/get`,
@@ -35641,12 +35660,20 @@ async function defaultFetchSelections(sessionId) {
35641
35660
  );
35642
35661
  if (!res.ok) return {};
35643
35662
  const data = await res.json();
35644
- return data.selections || {};
35663
+ const selections = data.selections || {};
35664
+ if (Object.keys(selections).length > 0) {
35665
+ try {
35666
+ localStorage.setItem(STORAGE_KEY(sessionId), JSON.stringify(selections));
35667
+ } catch {
35668
+ }
35669
+ }
35670
+ return selections;
35645
35671
  } catch {
35646
35672
  return {};
35647
35673
  }
35648
35674
  }
35649
35675
  async function defaultPersistSelection(sessionId, questionKey, value) {
35676
+ setLocalSelection(sessionId, questionKey, value);
35650
35677
  try {
35651
35678
  await fetch(
35652
35679
  `/api/agents-proxy/custom-agents/sessions/${sessionId}/mcq-selections`,
@@ -35683,9 +35710,7 @@ var MCQCard = React92.memo(
35683
35710
  fetchSelections = defaultFetchSelections,
35684
35711
  persistSelection = defaultPersistSelection
35685
35712
  }) => {
35686
- const [selectedOption, setSelectedOption] = React92.useState(
35687
- propsSelectedOption
35688
- );
35713
+ const [selectedOption, setSelectedOption] = React92.useState(propsSelectedOption);
35689
35714
  const [isProceeded, setIsProceeded] = React92.useState(false);
35690
35715
  const fetchedSessionRef = React92.useRef("");
35691
35716
  React92.useEffect(() => {
@@ -35716,7 +35741,7 @@ var MCQCard = React92.memo(
35716
35741
  onSelect?.(key);
35717
35742
  }
35718
35743
  };
35719
- const handleProceed = (e) => {
35744
+ const handleProceed = async (e) => {
35720
35745
  e.preventDefault();
35721
35746
  e.stopPropagation();
35722
35747
  if ((selectedOption || recommended) && !disabled && !isProceeded) {
@@ -35725,7 +35750,7 @@ var MCQCard = React92.memo(
35725
35750
  setIsProceeded(true);
35726
35751
  if (sessionId) {
35727
35752
  const questionKey = question || "unknown";
35728
- persistSelection(sessionId, questionKey, result);
35753
+ await persistSelection(sessionId, questionKey, result);
35729
35754
  }
35730
35755
  if (sendMessage) {
35731
35756
  sendMessage(`Selected: ${label}`);