fix(room): load model list inside fetchRoomAiConfigs so AI names are always resolved
Some checks are pending
CI / Rust Lint & Check (push) Waiting to run
CI / Rust Tests (push) Waiting to run
CI / Frontend Lint & Type Check (push) Waiting to run
CI / Frontend Build (push) Blocked by required conditions

Previously availableModels was fetched in parallel with roomAiConfigs, so
the first call to fetchRoomAiConfigs had empty availableModels and all AI
configs showed model IDs instead of names.

Now fetchRoomAiConfigs loads the model list itself when called, guaranteeing
that model names are always available.
This commit is contained in:
ZhenYi 2026-04-18 00:55:18 +08:00
parent 7be2f4eb61
commit 3a24022972

View File

@ -1146,12 +1146,16 @@ export function RoomProvider({
}
setAiConfigsLoading(true);
try {
// Load model list fresh so we have names even if availableModels is empty
const { modelList } = await import('@/client');
const modelsResp = await modelList({});
const models = (modelsResp.data as { data?: { data?: { id: string; name: string }[] } } | undefined)
?.data?.data ?? [];
const configs = await client.aiList(activeRoomId);
// Look up model names from the available models list
setRoomAiConfigs(
configs.map((cfg) => ({
model: cfg.model,
modelName: availableModels.find((m) => m.id === cfg.model)?.name,
modelName: models.find((m) => m.id === cfg.model)?.name,
})),
);
} catch {
@ -1159,7 +1163,7 @@ export function RoomProvider({
} finally {
setAiConfigsLoading(false);
}
}, [activeRoomId, availableModels]);
}, [activeRoomId]);
// Fetch available models (for AI model name lookup)
const fetchAvailableModels = useCallback(async () => {
@ -1176,14 +1180,14 @@ export function RoomProvider({
fetchProjectRepos();
}, [fetchProjectRepos]);
useEffect(() => {
fetchRoomAiConfigs();
}, [fetchRoomAiConfigs]);
useEffect(() => {
fetchAvailableModels();
}, [fetchAvailableModels]);
useEffect(() => {
fetchRoomAiConfigs();
}, [fetchRoomAiConfigs]);
const createRoom = useCallback(
async (name: string, isPublic: boolean, categoryId?: string) => {
const client = wsClientRef.current;