|
@@ -32,6 +32,7 @@ interface ChatInterfaceProps {
|
|
|
onPreviewSource?: (source: ChatSource) => void;
|
|
onPreviewSource?: (source: ChatSource) => void;
|
|
|
onOpenFile?: (source: ChatSource) => void;
|
|
onOpenFile?: (source: ChatSource) => void;
|
|
|
onHistoryIdCreated?: (historyId: string) => void;
|
|
onHistoryIdCreated?: (historyId: string) => void;
|
|
|
|
|
+ authToken?: string; // Add authToken prop
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
|
const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
|
@@ -50,7 +51,8 @@ const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
|
|
onHistoryMessagesLoaded,
|
|
onHistoryMessagesLoaded,
|
|
|
onPreviewSource,
|
|
onPreviewSource,
|
|
|
onOpenFile,
|
|
onOpenFile,
|
|
|
- onHistoryIdCreated
|
|
|
|
|
|
|
+ onHistoryIdCreated,
|
|
|
|
|
+ authToken: propAuthToken // Use prop
|
|
|
}) => {
|
|
}) => {
|
|
|
const { t, language } = useLanguage();
|
|
const { t, language } = useLanguage();
|
|
|
const [messages, setMessages] = useState<Message[]>([]);
|
|
const [messages, setMessages] = useState<Message[]>([]);
|
|
@@ -167,8 +169,10 @@ const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
|
|
setIsLoading(true);
|
|
setIsLoading(true);
|
|
|
setMessages((prev) => [...prev, newMessage]);
|
|
setMessages((prev) => [...prev, newMessage]);
|
|
|
|
|
|
|
|
- const authToken = localStorage.getItem('authToken');
|
|
|
|
|
- if (!authToken) {
|
|
|
|
|
|
|
+ // Use token from props if available, fallback to localStorage (with correct key)
|
|
|
|
|
+ const finalToken = propAuthToken || localStorage.getItem('kb_api_key') || localStorage.getItem('authToken');
|
|
|
|
|
+
|
|
|
|
|
+ if (!finalToken) {
|
|
|
const errorMsg: Message = {
|
|
const errorMsg: Message = {
|
|
|
id: generateUUID(),
|
|
id: generateUUID(),
|
|
|
role: Role.MODEL,
|
|
role: Role.MODEL,
|
|
@@ -204,7 +208,7 @@ const ChatInterface: React.FC<ChatInterfaceProps> = ({
|
|
|
const stream = chatService.streamChat(
|
|
const stream = chatService.streamChat(
|
|
|
userText,
|
|
userText,
|
|
|
history,
|
|
history,
|
|
|
- authToken,
|
|
|
|
|
|
|
+ finalToken,
|
|
|
language,
|
|
language,
|
|
|
settings.selectedEmbeddingId,
|
|
settings.selectedEmbeddingId,
|
|
|
settings.selectedLLMId, // Pass selected LLM ID
|
|
settings.selectedLLMId, // Pass selected LLM ID
|