diff --git a/app/api/sandbox/[sandboxId]/inference/route.ts b/app/api/sandbox/[sandboxId]/inference/route.ts index ccf7894..02876d0 100644 --- a/app/api/sandbox/[sandboxId]/inference/route.ts +++ b/app/api/sandbox/[sandboxId]/inference/route.ts @@ -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, diff --git a/app/components/SandboxInferencePanel.tsx b/app/components/SandboxInferencePanel.tsx index cb1bd65..378c145 100644 --- a/app/components/SandboxInferencePanel.tsx +++ b/app/components/SandboxInferencePanel.tsx @@ -59,7 +59,10 @@ function routeKey(route: Pick) { 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) { - 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) { diff --git a/app/lib/sandboxInferenceStore.ts b/app/lib/sandboxInferenceStore.ts index e254d66..3ce8780 100644 --- a/app/lib/sandboxInferenceStore.ts +++ b/app/lib/sandboxInferenceStore.ts @@ -50,20 +50,19 @@ async function writeStore(store: StoreShape) { export function normalizeSandboxInferenceConfig(sandboxId: string, input?: Partial | 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, diff --git a/tests/sandbox-lifecycle-check.mjs b/tests/sandbox-lifecycle-check.mjs index 36d1e56..916d111 100644 --- a/tests/sandbox-lifecycle-check.mjs +++ b/tests/sandbox-lifecycle-check.mjs @@ -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')