feat(ai-config): validate bindings before save

This commit is contained in:
2026-04-08 00:09:36 +08:00
parent 929b838e0f
commit e5948cd346
6 changed files with 381 additions and 15 deletions
+34
View File
@@ -47,6 +47,23 @@ export type UpsertWebAiBindingInput = {
isEnabled?: boolean;
};
export type TestWebAiBindingResponse =
| {
success: true;
channel: Exclude<WebAiChannel, "PUBLIC_POOL">;
providerName: string;
model: string | null;
contentPreview: string;
}
| {
success: false;
channel: Exclude<WebAiChannel, "PUBLIC_POOL">;
providerName: string;
model: string | null;
code: string;
message: string;
};
export type WebAiChatResponse = {
channel: WebAiChannel;
providerName: string;
@@ -141,6 +158,23 @@ export async function upsertAiBinding(
return (await response.json()) as WebAiBindingSummary;
}
export async function testAiBinding(
session: WebSession,
payload: UpsertWebAiBindingInput
): Promise<TestWebAiBindingResponse> {
const response = await fetch(`${resolveApiBaseUrl()}/ai/bindings/test`, {
method: "POST",
headers: createHeaders(session),
body: JSON.stringify(payload)
});
if (!response.ok) {
throw await createApiError(response);
}
return (await response.json()) as TestWebAiBindingResponse;
}
export async function chatWithAi(
session: WebSession,
payload: {