feat(ai-providers): 优化 OpenAI 编辑页 UI 交互与对齐

This commit is contained in:
moxi
2026-02-11 23:31:43 +08:00
parent 027ab483d4
commit c726fbc379
15 changed files with 869 additions and 238 deletions

View File

@@ -15,12 +15,18 @@ import { buildApiKeyEntry } from '@/components/providers/utils';
export type OpenAITestStatus = 'idle' | 'loading' | 'success' | 'error';
export type KeyTestStatus = {
status: OpenAITestStatus;
message: string;
};
export type OpenAIEditDraft = {
initialized: boolean;
form: OpenAIFormState;
testModel: string;
testStatus: OpenAITestStatus;
testMessage: string;
keyTestStatuses: KeyTestStatus[];
};
interface OpenAIEditDraftState {
@@ -31,6 +37,8 @@ interface OpenAIEditDraftState {
setDraftTestModel: (key: string, action: SetStateAction<string>) => void;
setDraftTestStatus: (key: string, action: SetStateAction<OpenAITestStatus>) => void;
setDraftTestMessage: (key: string, action: SetStateAction<string>) => void;
setDraftKeyTestStatus: (draftKey: string, keyIndex: number, status: KeyTestStatus) => void;
resetDraftKeyTestStatuses: (draftKey: string, count: number) => void;
clearDraft: (key: string) => void;
}
@@ -53,6 +61,7 @@ const buildEmptyDraft = (): OpenAIEditDraft => ({
testModel: '',
testStatus: 'idle',
testMessage: '',
keyTestStatuses: [],
});
export const useOpenAIEditDraftStore = create<OpenAIEditDraftState>((set, get) => ({
@@ -135,6 +144,38 @@ export const useOpenAIEditDraftStore = create<OpenAIEditDraftState>((set, get) =
});
},
setDraftKeyTestStatus: (draftKey, keyIndex, status) => {
if (!draftKey) return;
set((state) => {
const existing = state.drafts[draftKey] ?? buildEmptyDraft();
const nextStatuses = [...existing.keyTestStatuses];
nextStatuses[keyIndex] = status;
return {
drafts: {
...state.drafts,
[draftKey]: { ...existing, initialized: true, keyTestStatuses: nextStatuses },
},
};
});
},
resetDraftKeyTestStatuses: (draftKey, count) => {
if (!draftKey) return;
set((state) => {
const existing = state.drafts[draftKey] ?? buildEmptyDraft();
return {
drafts: {
...state.drafts,
[draftKey]: {
...existing,
initialized: true,
keyTestStatuses: Array.from({ length: count }, () => ({ status: 'idle', message: '' })),
},
},
};
});
},
clearDraft: (key) => {
if (!key) return;
set((state) => {