feat: add OpenAI model support and harden OSS security defaults

This commit is contained in:
willchen96 2026-05-09 14:55:51 +08:00
parent adc2cf2370
commit bef75b082d
24 changed files with 1301 additions and 364 deletions

View file

@ -37,6 +37,7 @@ import {
isModelAvailable,
type ModelProvider,
} from "@/app/lib/modelAvailability";
import type { ApiKeyState } from "@/app/lib/mikeApi";
// ---------------------------------------------------------------------------
// Types
@ -454,7 +455,7 @@ function TRChatInput({
onCancel: () => void;
model: string;
onModelChange: (id: string) => void;
apiKeys: { claudeApiKey: string | null; geminiApiKey: string | null };
apiKeys?: ApiKeyState;
onHeightChange: (height: number) => void;
}) {
const [value, setValue] = useState("");
@ -642,10 +643,7 @@ export function TRChatPanel({
onChatIdChange,
}: Props) {
const { profile, updateModelPreference } = useUserProfile();
const apiKeys = {
claudeApiKey: profile?.claudeApiKey ?? null,
geminiApiKey: profile?.geminiApiKey ?? null,
};
const apiKeys = profile?.apiKeys;
const currentModel = profile?.tabularModel ?? "gemini-3-flash-preview";
const [apiKeyModalProvider, setApiKeyModalProvider] =
useState<ModelProvider | null>(null);
@ -993,7 +991,7 @@ export function TRChatPanel({
async function handleSubmit(trimmed: string) {
if (!trimmed || isLoading) return;
if (!isModelAvailable(currentModel, apiKeys)) {
if (apiKeys && !isModelAvailable(currentModel, apiKeys)) {
setApiKeyModalProvider(getModelProvider(currentModel));
return;
}

View file

@ -87,10 +87,7 @@ export function TRView({ reviewId, projectId }: Props) {
const tableRef = useRef<TRTableHandle>(null);
const router = useRouter();
const { profile } = useUserProfile();
const apiKeys = {
claudeApiKey: profile?.claudeApiKey ?? null,
geminiApiKey: profile?.geminiApiKey ?? null,
};
const apiKeys = profile?.apiKeys;
const tabularModel = profile?.tabularModel ?? "gemini-3-flash-preview";
useEffect(() => {
@ -243,7 +240,7 @@ export function TRView({ reviewId, projectId }: Props) {
// If columns changed since last save, update the review first
if (columns.length === 0) return;
if (!isModelAvailable(tabularModel, apiKeys)) {
if (apiKeys && !isModelAvailable(tabularModel, apiKeys)) {
setApiKeyModalProvider(getModelProvider(tabularModel));
return;
}