mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
Materialize the active provider runtime for empty-session first prompts before the WebSocket prewarm and user message are sent. This keeps a clean install that adds a MiniMax provider from starting the first turn without the selected provider runtime. Tested: bun test src/server/__tests__/conversations.test.ts -t "MiniMax provider turn" Tested: bun test src/server/__tests__/websocket-handler.test.ts src/server/__tests__/conversations.test.ts -t "prewarm|active provider id|MiniMax provider turn|first-turn runtime synchronization" Tested: cd desktop && bun run test -- --run src/pages/EmptySession.test.tsx -t "draft runtime|active provider runtime|creates a new session" Tested: cd desktop && bun run test -- --run src/components/controls/ModelSelector.test.tsx -t "defaults blank provider-scoped runtime selections|selects provider-scoped runtime models" Tested: cd desktop && bun run lint Tested: cd desktop && bun run build Not-tested: bun run check:desktop, unrelated full-suite failures in MessageList timestamp formatting and TabBar AbortSignal cleanup blocked the gate. Confidence: medium Scope-risk: narrow
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { OFFICIAL_DEFAULT_MODEL_ID } from '../constants/modelCatalog'
|
|
import {
|
|
OPENAI_OFFICIAL_DEFAULT_MODEL_ID,
|
|
OPENAI_OFFICIAL_PROVIDER_ID,
|
|
} from '../constants/openaiOfficialProvider'
|
|
import type { SavedProvider } from '../types/provider'
|
|
import type { RuntimeSelection } from '../types/runtime'
|
|
|
|
export function resolveActiveProviderRuntimeSelection(
|
|
activeId: string | null,
|
|
activeProviderName: string | null,
|
|
providers: SavedProvider[],
|
|
currentModelId: string | undefined,
|
|
): RuntimeSelection | null {
|
|
const activeProvider = activeId
|
|
? providers.find((provider) => provider.id === activeId)
|
|
: activeProviderName
|
|
? providers.find((provider) => provider.name === activeProviderName)
|
|
: undefined
|
|
const inferredProviderId = activeId ?? activeProvider?.id ?? null
|
|
if (!inferredProviderId) return null
|
|
|
|
const providerMainModelId = activeProvider?.models.main.trim()
|
|
|
|
return {
|
|
providerId: inferredProviderId,
|
|
modelId: providerMainModelId || currentModelId || (
|
|
inferredProviderId === OPENAI_OFFICIAL_PROVIDER_ID
|
|
? OPENAI_OFFICIAL_DEFAULT_MODEL_ID
|
|
: OFFICIAL_DEFAULT_MODEL_ID
|
|
),
|
|
}
|
|
}
|
|
|
|
export function resolveDefaultRuntimeSelection(
|
|
activeId: string | null,
|
|
activeProviderName: string | null,
|
|
providers: SavedProvider[],
|
|
currentModelId: string | undefined,
|
|
): RuntimeSelection {
|
|
return resolveActiveProviderRuntimeSelection(
|
|
activeId,
|
|
activeProviderName,
|
|
providers,
|
|
currentModelId,
|
|
) ?? {
|
|
providerId: null,
|
|
modelId: currentModelId || OFFICIAL_DEFAULT_MODEL_ID,
|
|
}
|
|
}
|