feat(fetch): add Ollama Cloud web fetch provider

This commit is contained in:
Sami Basra
2026-09-03 10:12:41 +07:00
committed by decolua
parent 6ab9ca9eb1
commit e0ffc7e2a1
6 changed files with 255 additions and 8 deletions

View File

@@ -159,8 +159,13 @@ async function handleSingleProviderFetch(body, providerInput, request, apiKey, s
let lastError = null;
let lastStatus = null;
// Keep web-fetch failures scoped to this capability. Providers such as
// Ollama use the same connection for chat and fetch, so an upstream fetch
// failure must not take the account offline for LLM requests.
const fetchLockKey = `webfetch:${providerId}`;
while (true) {
const credentials = await getProviderCredentials(providerId, excludeConnectionIds);
const credentials = await getProviderCredentials(providerId, excludeConnectionIds, fetchLockKey);
if (!credentials || credentials.allRateLimited) {
if (credentials?.allRateLimited) {
@@ -200,13 +205,19 @@ async function handleSingleProviderFetch(body, providerInput, request, apiKey, s
});
if (result.success) {
await clearAccountError(credentials.connectionId, credentials);
await clearAccountError(credentials.connectionId, credentials, fetchLockKey);
return new Response(JSON.stringify(result.data), {
headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" }
});
}
const { shouldFallback } = await markAccountUnavailable(credentials.connectionId, result.status, result.error, providerId);
const { shouldFallback } = await markAccountUnavailable(
credentials.connectionId,
result.status,
result.error,
providerId,
fetchLockKey,
);
if (shouldFallback) {
log.warn("AUTH", `Account ${credentials.connectionName} unavailable (${result.status}), trying fallback`);