fix: refresh does refresh on all byok (#931)

This commit is contained in:
Ari Webb
2026-02-12 12:21:27 -08:00
committed by GitHub
parent 1a302cfcc0
commit e1274a6dc3
3 changed files with 61 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
import { debugWarn } from "../utils/debug";
import { getClient } from "./client";
const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
@@ -42,6 +43,59 @@ export function getAvailableModelsCacheInfo(): {
};
}
/**
* Provider response from /v1/providers/ endpoint
*/
type Provider = {
id: string;
name: string;
provider_type: string;
provider_category?: "base" | "byok" | null;
};
/**
* Refresh BYOK providers to get the latest models from their APIs.
* This calls PATCH /v1/providers/{provider_id}/refresh for each BYOK provider.
* Errors are logged but don't fail the overall refresh (best-effort).
*/
async function refreshByokProviders(): Promise<void> {
const client = await getClient();
try {
// List all providers
const providers = await client.get<Provider[]>("/v1/providers/");
// Filter to BYOK providers only
const byokProviders = providers.filter(
(p) => p.provider_category === "byok",
);
// Refresh each BYOK provider in parallel (best-effort, don't fail on errors)
await Promise.allSettled(
byokProviders.map(async (provider) => {
try {
await client.patch<Provider>(`/v1/providers/${provider.id}/refresh`);
} catch (error) {
// Log but don't throw - refresh is best-effort
debugWarn(
"available-models",
`Failed to refresh provider ${provider.name} (${provider.id}):`,
error,
);
}
}),
);
} catch (error) {
// If we can't list providers, just log and continue
// This might happen on self-hosted servers without the providers endpoint
debugWarn(
"available-models",
"Failed to list providers for refresh:",
error,
);
}
}
async function fetchFromNetwork(): Promise<CacheEntry> {
const client = await getClient();
const modelsList = await client.models.list();
@@ -81,6 +135,12 @@ export async function getAvailableModelHandles(options?: {
};
}
// When forceRefresh is true, first refresh BYOK providers to get latest models
// This matches the behavior in ADE (letta-cloud) where refresh is called before listing models
if (forceRefresh) {
await refreshByokProviders();
}
inflight = fetchFromNetwork()
.then((entry) => {
cache = entry;

View File

@@ -1265,7 +1265,7 @@ export default function App({
}, [llmConfig]);
const [currentModelId, setCurrentModelId] = useState<string | null>(null);
// Full model handle for API calls (e.g., "anthropic/claude-sonnet-4-5-20251101")
const [currentModelHandle, setCurrentModelHandle] = useState<string | null>(
const [_currentModelHandle, setCurrentModelHandle] = useState<string | null>(
null,
);
// Derive agentName from agentState (single source of truth)

View File

@@ -8,7 +8,6 @@ import {
isStatusLineDisabled,
MAX_STATUS_LINE_TIMEOUT_MS,
MIN_STATUS_LINE_DEBOUNCE_MS,
MIN_STATUS_LINE_INTERVAL_MS,
normalizeStatusLineConfig,
resolveStatusLineConfig,
} from "../../cli/helpers/statusLineConfig";