Add Cloudflare AI provider support and enhance connection management

- Introduced Cloudflare AI as a new provider with specific configurations in providerModels.js and providers.js.
- Updated DefaultExecutor to handle account ID resolution for Cloudflare AI connections.
- Enhanced AddApiKeyModal and EditConnectionModal to include account ID input for Cloudflare AI.
- Implemented validation for Cloudflare AI API key connections in testUtils.js and route.js.
- Updated UI components to reflect changes in provider management and connection handling.
This commit is contained in:
decolua
2026-04-28 11:07:39 +07:00
parent 111e78940a
commit 1bb621317d
18 changed files with 325 additions and 71 deletions

View File

@@ -367,6 +367,19 @@ async function testApiKeyConnection(connection, effectiveProxy = null) {
try {
switch (connection.provider) {
case "cloudflare-ai": {
const psd = connection.providerSpecificData || {};
const accountId = psd.accountId;
if (!accountId) return { valid: false, error: "Missing Account ID" };
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/chat/completions`;
const res = await fetchWithConnectionProxy(url, {
method: "POST",
headers: { "Authorization": `Bearer ${connection.apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({ model: getDefaultModel("cloudflare-ai"), messages: [{ role: "user", content: "test" }], max_tokens: 1 }),
}, effectiveProxy);
const valid = res.status !== 401 && res.status !== 403 && res.status !== 404;
return { valid, error: valid ? null : "Invalid API token or Account ID" };
}
case "azure": {
const psd = connection.providerSpecificData || {};
const endpoint = (psd.azureEndpoint || "").replace(/\/$/, "");

View File

@@ -95,6 +95,29 @@ export async function POST(request) {
});
}
if (provider === "cloudflare-ai") {
const { providerSpecificData } = body;
const accountId = providerSpecificData?.accountId;
if (!accountId) {
return NextResponse.json({ valid: false, error: "Missing Account ID" });
}
const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/chat/completions`;
const cfRes = await fetch(url, {
method: "POST",
headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: getDefaultModel("cloudflare-ai"),
messages: [{ role: "user", content: "test" }],
max_tokens: 1,
}),
});
isValid = cfRes.status !== 401 && cfRes.status !== 403 && cfRes.status !== 404;
return NextResponse.json({
valid: isValid,
error: isValid ? null : "Invalid API token or Account ID",
});
}
if (provider === "azure") {
const { providerSpecificData } = body;
const endpoint = (providerSpecificData?.azureEndpoint || "").replace(/\/$/, "");