Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/components/DocsAssistant.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useCallback, useEffect, useMemo } from "react";
import { useCallback, useEffect, useMemo, useRef } from "react";

Check warning on line 3 in app/components/DocsAssistant.tsx

View workflow job for this annotation

GitHub Actions / build

'useRef' is defined but never used

Check warning on line 3 in app/components/DocsAssistant.tsx

View workflow job for this annotation

GitHub Actions / build

'useRef' is defined but never used. Allowed unused vars must match /^_/u

import { AssistantRuntimeProvider } from "@assistant-ui/react";
import { useAISDKRuntime } from "@assistant-ui/react-ai-sdk";
Expand Down Expand Up @@ -49,13 +49,13 @@
return { pageContext, provider, apiKey };
},
}),
[geminiApiKey, openaiApiKey, pageContext, provider],
[pageContext, provider, openaiApiKey, geminiApiKey],
);

const chat = useChat({
transport,
onFinish: () => {
// 当对话结束时(流式传输完成),记录一次查询行为
// Track AI query when chat finishes (streaming completes)
if (window.umami) {
window.umami.track("ai_assistant_query");
}
Expand All @@ -68,6 +68,11 @@
clearError: clearChatError,
} = chat;

// Clear previous error when Provider changes
useEffect(() => {
clearChatError();
}, [provider, clearChatError]);

useEffect(() => {
if (chatStatus === "submitted" || chatStatus === "streaming") {
clearChatError();
Expand Down
8 changes: 4 additions & 4 deletions app/hooks/useAssistantSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface AssistantSettingsState {
provider: Provider;
openaiApiKey: string;
geminiApiKey: string;
saveToLocalStorage: boolean; // 是否将API Key保存到localStorage
saveToLocalStorage: boolean; // Whether to save API keys to localStorage
}

interface AssistantSettingsContextValue extends AssistantSettingsState {
Expand All @@ -30,7 +30,7 @@ interface AssistantSettingsContextValue extends AssistantSettingsState {
const SETTINGS_KEY = "assistant-settings-storage";

const defaultSettings: AssistantSettingsState = {
provider: "openai",
provider: "intern",
openaiApiKey: "",
geminiApiKey: "",
saveToLocalStorage: false,
Expand All @@ -56,7 +56,7 @@ const parseStoredSettings = (raw: string | null): AssistantSettingsState => {
: parsed.provider === "intern"
? "intern"
: "openai",
// 只有在saveToLocalStorage为true时才使用存储的key
// Use only stored key if saveToLocalStorage is true
openaiApiKey:
saveToLocalStorage && typeof parsed.openaiApiKey === "string"
? parsed.openaiApiKey
Expand Down Expand Up @@ -100,7 +100,7 @@ export const AssistantSettingsProvider = ({
}

try {
// 根据saveToLocalStorage决定是否保存API key
// Decide whether to save API keys based on saveToLocalStorage
const dataToSave = settings.saveToLocalStorage
? settings
: {
Expand Down
Loading