Fix sandbox inference route provider duplication

This commit is contained in:
Codex
2026-04-27 17:24:23 +00:00
parent 5858ac4f93
commit 9603835db0
4 changed files with 24 additions and 9 deletions
@@ -25,9 +25,7 @@ function parseRoutes(value: unknown): SandboxInferenceRoute[] {
return value.map((item) => {
const provider = typeof item?.provider === "string" ? item.provider.trim() : ""
const model = typeof item?.model === "string" ? item.model.trim() : ""
const id = typeof item?.id === "string" && item.id.trim()
? item.id.trim()
: `${provider}::${model}`
const id = `${provider}::${model}`
return {
id,
provider,
+15 -2
View File
@@ -59,7 +59,10 @@ function routeKey(route: Pick<SandboxInferenceRoute, "provider" | "model">) {
function dedupeRoutes(routes: SandboxInferenceRoute[]) {
return Array.from(new Map(routes
.filter((route) => route.provider.trim() && route.model.trim())
.map((route) => [route.id || routeKey(route), { ...route, id: route.id || routeKey(route) }])).values())
.map((route) => {
const id = routeKey(route)
return [id, { ...route, id }]
})).values())
}
export default function SandboxInferencePanel({
@@ -183,7 +186,17 @@ export default function SandboxInferencePanel({
}
function updateRoute(id: string, updates: Partial<SandboxInferenceRoute>) {
setRoutes((current) => current.map((route) => route.id === id ? { ...route, ...updates } : route))
setRoutes((current) => {
let replacementId = id
const next = current.map((route) => {
if (route.id !== id) return route
const updated = { ...route, ...updates }
replacementId = routeKey(updated)
return { ...updated, id: replacementId }
})
if (primaryRouteId === id) setPrimaryRouteId(replacementId)
return dedupeRoutes(next)
})
}
function removeRoute(id: string) {
+3 -4
View File
@@ -50,20 +50,19 @@ async function writeStore(store: StoreShape) {
export function normalizeSandboxInferenceConfig(sandboxId: string, input?: Partial<SandboxInferenceConfig> | null): SandboxInferenceConfig {
const legacyProvider = typeof input?.provider === "string" ? input.provider.trim() : ""
const hasExplicitRoutes = Array.isArray(input?.routes) && input.routes.length > 0
const legacyModels = Array.from(new Set([
input?.primaryModel,
...(Array.isArray(input?.models) ? input.models : []),
].map((item) => typeof item === "string" ? item.trim() : "").filter(Boolean)))
const rawRoutes: any[] = [
...(Array.isArray(input?.routes) ? input.routes : []),
...legacyModels.map((model) => ({ provider: legacyProvider, model, enabled: true, label: "" })),
...(hasExplicitRoutes ? [] : legacyModels.map((model) => ({ provider: legacyProvider, model, enabled: true, label: "" }))),
]
const routeEntries: Array<[string, SandboxInferenceRoute]> = rawRoutes.map((route) => {
const provider = typeof route?.provider === "string" ? route.provider.trim() : ""
const model = typeof route?.model === "string" ? route.model.trim() : ""
const id = typeof route?.id === "string" && route.id.trim()
? route.id.trim()
: `${provider}::${model}`
const id = `${provider}::${model}`
return [id, {
id,
provider,
+5
View File
@@ -12,6 +12,7 @@ const ollamaModelsRoutePath = path.join(root, 'app/api/ollama/models/route.ts')
const sandboxInferenceRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/route.ts')
const sandboxInferenceApplyRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/inference/apply/route.ts')
const sandboxInferenceApplyLibPath = path.join(root, 'app/lib/sandboxInferenceApply.ts')
const sandboxInferenceStorePath = path.join(root, 'app/lib/sandboxInferenceStore.ts')
const sandboxRestartRoutePath = path.join(root, 'app/api/sandbox/[sandboxId]/restart/route.ts')
const hookPath = path.join(root, 'app/hooks/useSandboxInventory.ts')
const pagePath = path.join(root, 'app/page.tsx')
@@ -30,6 +31,7 @@ const ollamaModelsRouteSource = await readFile(ollamaModelsRoutePath, 'utf8')
const sandboxInferenceRouteSource = await readFile(sandboxInferenceRoutePath, 'utf8')
const sandboxInferenceApplyRouteSource = await readFile(sandboxInferenceApplyRoutePath, 'utf8')
const sandboxInferenceApplyLibSource = await readFile(sandboxInferenceApplyLibPath, 'utf8')
const sandboxInferenceStoreSource = await readFile(sandboxInferenceStorePath, 'utf8')
const sandboxRestartRouteSource = await readFile(sandboxRestartRoutePath, 'utf8')
const hookSource = await readFile(hookPath, 'utf8')
const pageSource = await readFile(pagePath, 'utf8')
@@ -83,6 +85,9 @@ assert.match(ollamaModelsRouteSource, /OLLAMA_BASE_URL/, 'Ollama models route mu
assert.match(sandboxInferenceRouteSource, /parseRoutes/, 'sandbox inference route must accept multiple provider/model routes')
assert.match(sandboxInferenceRouteSource, /primaryRouteId/, 'sandbox inference route must preserve the primary route selection')
assert.match(sandboxInferenceRouteSource, /saveSandboxInferenceConfig/, 'sandbox inference route must persist per-sandbox inference profiles')
assert.match(sandboxInferenceRouteSource, /const id = `\$\{provider\}::\$\{model\}`/, 'sandbox inference route must canonicalize route ids from provider/model pairs')
assert.match(sandboxInferenceStoreSource, /hasExplicitRoutes \? \[\] : legacyModels\.map/, 'sandbox inference store must not re-expand legacy provider/models when explicit routes are present')
assert.match(sandboxInferenceStoreSource, /const id = `\$\{provider\}::\$\{model\}`/, 'sandbox inference store must canonicalize route ids from provider/model pairs')
assert.match(sandboxInferencePanelSource, /Save Sandbox Routes/, 'selected sandbox UI must expose multi-route inference saving')
assert.match(sandboxInferencePanelSource, /Apply to Running Container/, 'selected sandbox UI must expose live apply for running containers')
assert.match(sandboxInferencePanelSource, /Verified Working Routes/, 'selected sandbox UI must list verified active inference routes')