@unctad-ai/voice-agent-ui 1.0.4 → 1.0.6

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.ts CHANGED
@@ -46,14 +46,15 @@ declare function VoiceSettingsProvider({ children }: {
46
46
  declare function useVoiceSettings(): VoiceSettingsContextType;
47
47
 
48
48
  interface GlassCopilotPanelProps {
49
- isOpen: boolean;
49
+ /** Controlled open state. When omitted, the panel manages its own open/close state. */
50
+ isOpen?: boolean;
50
51
  onOpen?: () => void;
51
- onClose: () => void;
52
+ onClose?: () => void;
52
53
  onStateChange?: (orbState: OrbState) => void;
53
54
  /** URL for the avatar portrait image */
54
55
  portraitSrc?: string;
55
56
  }
56
- declare function GlassCopilotPanel({ isOpen, onOpen, onClose, onStateChange, portraitSrc }: GlassCopilotPanelProps): react.ReactPortal;
57
+ declare function GlassCopilotPanel({ isOpen: isOpenProp, onOpen: onOpenProp, onClose: onCloseProp, onStateChange, portraitSrc }: GlassCopilotPanelProps): react.ReactPortal;
57
58
 
58
59
  interface AgentAvatarProps {
59
60
  state: OrbState;
package/dist/index.js CHANGED
@@ -2524,15 +2524,23 @@ function WiredPanelInner({
2524
2524
  /* @__PURE__ */ jsx9(AnimatePresence5, { children: showSettings && /* @__PURE__ */ jsx9(Suspense, { fallback: null, children: /* @__PURE__ */ jsx9(VoiceSettingsView2, { onBack: toggleSettings, onVolumeChange: applyVolume }) }) })
2525
2525
  ] });
2526
2526
  }
2527
- function GlassCopilotPanel({ isOpen, onOpen, onClose, onStateChange, portraitSrc }) {
2527
+ function GlassCopilotPanel({ isOpen: isOpenProp, onOpen: onOpenProp, onClose: onCloseProp, onStateChange, portraitSrc }) {
2528
2528
  injectAgentFabCSS();
2529
2529
  const config = useSiteConfig4();
2530
2530
  const resolvedPortrait = portraitSrc ?? config.avatarUrl;
2531
+ const [internalOpen, setInternalOpen] = useState5(false);
2532
+ const isControlled = isOpenProp !== void 0;
2533
+ const isOpen = isControlled ? isOpenProp : internalOpen;
2534
+ const handleOpen = useCallback3(() => {
2535
+ onOpenProp?.();
2536
+ if (!isControlled) setInternalOpen(true);
2537
+ }, [onOpenProp, isControlled]);
2531
2538
  const [internalState, setInternalState] = useState5("collapsed");
2532
2539
  const panelState = isOpen ? internalState : "hidden";
2533
2540
  const handleClose = useCallback3(() => {
2534
- onClose();
2535
- }, [onClose]);
2541
+ onCloseProp?.();
2542
+ if (!isControlled) setInternalOpen(false);
2543
+ }, [onCloseProp, isControlled]);
2536
2544
  const handleCollapse = useCallback3(() => {
2537
2545
  setInternalState("collapsed");
2538
2546
  }, []);
@@ -2570,7 +2578,7 @@ function GlassCopilotPanel({ isOpen, onOpen, onClose, onStateChange, portraitSrc
2570
2578
  ] }) }) }),
2571
2579
  /* @__PURE__ */ jsx9("span", { "aria-live": "polite", "aria-atomic": "true", style: { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0,0,0,0)", whiteSpace: "nowrap", borderWidth: 0 }, children: ariaAnnouncement }),
2572
2580
  /* @__PURE__ */ jsxs8(AnimatePresence5, { children: [
2573
- !isVisible && /* @__PURE__ */ jsx9(motion5.div, { ref: fabRef, initial: { scale: 0, opacity: 0 }, animate: { scale: 1, opacity: 1 }, exit: { scale: 0, opacity: 0 }, transition: { duration: 0.25, ease: "easeOut" }, className: "fixed", style: { bottom: PANEL_BOTTOM, right: PANEL_RIGHT, zIndex: PANEL_Z_INDEX }, children: /* @__PURE__ */ jsx9(CopilotFAB, { onClick: () => onOpen?.(), portraitSrc: resolvedPortrait }) }, "copilot-fab"),
2581
+ !isVisible && /* @__PURE__ */ jsx9(motion5.div, { ref: fabRef, initial: { scale: 0, opacity: 0 }, animate: { scale: 1, opacity: 1 }, exit: { scale: 0, opacity: 0 }, transition: { duration: 0.25, ease: "easeOut" }, className: "fixed", style: { bottom: PANEL_BOTTOM, right: PANEL_RIGHT, zIndex: PANEL_Z_INDEX }, children: /* @__PURE__ */ jsx9(CopilotFAB, { onClick: handleOpen, portraitSrc: resolvedPortrait }) }, "copilot-fab"),
2574
2582
  isVisible && /* @__PURE__ */ jsxs8(
2575
2583
  motion5.div,
2576
2584
  {