()
| 34 | import './FloatingMiniChat.scss'; |
| 35 | |
| 36 | export const FloatingMiniChat: React.FC = () => { |
| 37 | const { t } = useTranslation('flow-chat'); |
| 38 | const { toolbarState } = useToolbarModeContext(); |
| 39 | const activeTabId = useSceneStore((state) => state.activeTabId); |
| 40 | const customizingAppIds = useMiniAppStore((state) => state.customizingAppIds); |
| 41 | |
| 42 | const [isOpen, setIsOpen] = useState(false); |
| 43 | const [inputValue, setInputValue] = useState(''); |
| 44 | const [showSessionPicker, setShowSessionPicker] = useState(false); |
| 45 | const [flowChatState, setFlowChatState] = useState<FlowChatState>(() => |
| 46 | flowChatStore.getState() |
| 47 | ); |
| 48 | const { isImeEnter, handleCompositionStart, handleCompositionEnd } = useImeEnterGuard(); |
| 49 | const panelRef = useRef<HTMLDivElement>(null); |
| 50 | const sessionPickerRef = useRef<HTMLDivElement>(null); |
| 51 | |
| 52 | useEffect(() => { |
| 53 | const unsubscribe = flowChatStore.subscribe((state) => { |
| 54 | setFlowChatState(state); |
| 55 | }); |
| 56 | return () => unsubscribe(); |
| 57 | }, []); |
| 58 | |
| 59 | const sessionTitle = useMemo(() => { |
| 60 | const activeSession = flowChatState.activeSessionId |
| 61 | ? flowChatState.sessions.get(flowChatState.activeSessionId) |
| 62 | : undefined; |
| 63 | return resolveSessionTitle(activeSession, (key, options) => i18nService.t(key, options)); |
| 64 | }, [flowChatState]); |
| 65 | |
| 66 | const sessions = useMemo(() => { |
| 67 | return Array.from(flowChatState.sessions.values()) |
| 68 | .sort(compareSessionsForDisplay) |
| 69 | .slice(0, 10); |
| 70 | }, [flowChatState]); |
| 71 | |
| 72 | const currentStreamState = useMemo(() => { |
| 73 | const activeSession = flowChatState.activeSessionId |
| 74 | ? flowChatState.sessions.get(flowChatState.activeSessionId) |
| 75 | : undefined; |
| 76 | |
| 77 | if (!activeSession || !activeSession.dialogTurns || activeSession.dialogTurns.length === 0) { |
| 78 | return { isStreaming: false }; |
| 79 | } |
| 80 | |
| 81 | const lastTurn = activeSession.dialogTurns[activeSession.dialogTurns.length - 1]; |
| 82 | const isStreaming = |
| 83 | lastTurn.status === 'processing' || |
| 84 | lastTurn.status === 'finishing' || |
| 85 | lastTurn.status === 'image_analyzing'; |
| 86 | return { isStreaming }; |
| 87 | }, [flowChatState]); |
| 88 | |
| 89 | const activeMiniAppId = useMemo( |
| 90 | () => (typeof activeTabId === 'string' && activeTabId.startsWith('miniapp:') |
| 91 | ? activeTabId.slice('miniapp:'.length) |
| 92 | : null), |
| 93 | [activeTabId] |
nothing calls this directly
no test coverage detected