Enhance credential management and testing functionality

- Introduce new fields for voice, speed, and language in the AssistantConfig and ProviderCredential models to support TTS and ASR configurations.
- Update the database schema and seeding script to accommodate the new fields, ensuring backward compatibility.
- Implement credential testing endpoints and logic to validate OpenAI-compatible credentials, enhancing user experience and reliability.
- Modify frontend components to include new fields in the credential forms and improve connection testing feedback.
- Refactor related services and API interactions to support the new credential testing feature.
This commit is contained in:
Xin Wang
2026-06-09 14:42:25 +08:00
parent 3661dab81c
commit c64b7dcf99
12 changed files with 443 additions and 28 deletions

View File

@@ -20,6 +20,9 @@ export type Credential = {
interfaceType: InterfaceType;
apiUrl: string;
apiKey: string;
voice: string;
speed: number;
language: string;
isDefault: boolean;
};
@@ -34,6 +37,25 @@ export type CredentialUpsert = {
isDefault: boolean;
};
export type CredentialTestRequest = Pick<
CredentialUpsert,
| "modelId"
| "type"
| "interfaceType"
| "apiUrl"
| "apiKey"
| "voice"
| "speed"
| "language"
>;
export type CredentialTestResult = {
ok: boolean;
latencyMs: number | null;
message: string;
detail: string;
};
async function request<T>(path: string, init?: RequestInit): Promise<T> {
const res = await fetch(`${API_BASE}${path}`, {
headers: { "Content-Type": "application/json" },
@@ -66,6 +88,14 @@ export const credentialsApi = {
method: "PUT",
body: JSON.stringify(body),
}),
test: (body: CredentialTestRequest, id?: string) =>
request<CredentialTestResult>(
id ? `/api/credentials/${id}/test` : "/api/credentials/test",
{
method: "POST",
body: JSON.stringify(body),
},
),
// 服务端整行复制(含真 key,密钥不经浏览器)
duplicate: (id: string) =>
request<Credential>(`/api/credentials/${id}/duplicate`, { method: "POST" }),