({ selectedAgentName, selectedNamespace, selectedSession, sessionId, shareToken }: ChatInterfaceProps)
| 51 | } |
| 52 | |
| 53 | export default function ChatInterface({ selectedAgentName, selectedNamespace, selectedSession, sessionId, shareToken }: ChatInterfaceProps) { |
| 54 | const runInSandbox = useChatRunInSandbox(); |
| 55 | const substrateSandbox = useChatSubstrateSandbox(); |
| 56 | const router = useRouter(); |
| 57 | const containerRef = useRef<HTMLDivElement>(null); |
| 58 | const [currentInputMessage, setCurrentInputMessage] = useState(""); |
| 59 | |
| 60 | const [chatStatus, setChatStatus] = useState<ChatStatus>("ready"); |
| 61 | |
| 62 | const [session, setSession] = useState<Session | null>(selectedSession || null); |
| 63 | const [shareReadOnly, setShareReadOnly] = useState<boolean>(false); |
| 64 | const [storedMessages, setStoredMessages] = useState<Message[]>([]); |
| 65 | const [streamingMessages, setStreamingMessages] = useState<Message[]>([]); |
| 66 | const [streamingContent, setStreamingContent] = useState<string>(""); |
| 67 | const [isStreaming, setIsStreaming] = useState<boolean>(false); |
| 68 | const abortControllerRef = useRef<AbortController | null>(null); |
| 69 | const isFirstAssistantChunkRef = useRef(true); |
| 70 | const [isLoading, setIsLoading] = useState<boolean>(false); |
| 71 | const [sessionNotFound, setSessionNotFound] = useState<boolean>(false); |
| 72 | const isCreatingSessionRef = useRef<boolean>(false); |
| 73 | const [isFirstMessage, setIsFirstMessage] = useState<boolean>(!sessionId); |
| 74 | const [sessionStats, setSessionStats] = useState<TokenStats>({ total: 0, prompt: 0, completion: 0 }); |
| 75 | // Mutable ref so pendingTurnStats survives re-renders between A2A stream events |
| 76 | const pendingTurnStatsRef = useRef<TokenStats | undefined>(undefined); |
| 77 | const [pendingDecisions, setPendingDecisions] = useState<Record<string, ToolDecision>>({}); |
| 78 | const pendingDecisionsRef = useRef<Record<string, ToolDecision>>({}); |
| 79 | /** Per-tool rejection reasons collected as the user rejects individual tools. */ |
| 80 | const pendingRejectionReasonsRef = useRef<Record<string, string>>({}); |
| 81 | // Stream inactivity timeout (ms), configurable via Helm (ui.streamTimeoutSeconds). |
| 82 | const streamTimeoutMsRef = useRef<number>(DEFAULT_STREAM_TIMEOUT_MS); |
| 83 | |
| 84 | useEffect(() => { |
| 85 | let cancelled = false; |
| 86 | getUiRuntimeConfig() |
| 87 | .then((config) => { |
| 88 | if (!cancelled) streamTimeoutMsRef.current = config.streamTimeoutMs; |
| 89 | }) |
| 90 | .catch(() => { |
| 91 | /* keep default on failure */ |
| 92 | }); |
| 93 | return () => { |
| 94 | cancelled = true; |
| 95 | }; |
| 96 | }, []); |
| 97 | |
| 98 | const { |
| 99 | isListening, |
| 100 | isSupported: isVoiceSupported, |
| 101 | startListening, |
| 102 | stopListening, |
| 103 | error: voiceError, |
| 104 | } = useSpeechRecognition({ |
| 105 | onResult(transcriptText) { |
| 106 | setCurrentInputMessage(transcriptText); |
| 107 | }, |
| 108 | onError(msg) { |
| 109 | toast.error(msg); |
| 110 | }, |
nothing calls this directly
no test coverage detected