Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

fix(combos): preserve legacy string combo refs during normalization

diegosouzapwb65caf82b485
diff --git a/src/app/api/combos/[id]/route.ts b/src/app/api/combos/[id]/route.ts
index 1074f26a49..c8f34a6e0c 100644
--- a/src/app/api/combos/[id]/route.ts
+++ b/src/app/api/combos/[id]/route.ts
@@ -59,6 +59,7 @@ export async function PUT(request, { params }) {
if (!currentCombo) {
return NextResponse.json({ error: "Combo not found" }, { status: 404 });
}
+ const allCombos = await getCombos();
const comboName = validation.data.name || currentCombo.name;
const body = validation.data.models
@@ -66,6 +67,7 @@ export async function PUT(request, { params }) {
...validation.data,
models: normalizeComboModels(validation.data.models, {
comboName,
+ allCombos,
}),
}
: validation.data;
@@ -89,7 +91,6 @@ export async function PUT(request, { params }) {
// Validate nested combo DAG (no circular references, max depth)
if (body.models) {
- const allCombos = await getCombos();
// Update the combo in the list temporarily for validation
const updatedCombos = allCombos.map((c) => (c.id === id ? { ...c, ...body } : c));
if (comboName) {
diff --git a/src/app/api/combos/route.ts b/src/app/api/combos/route.ts
index 938d4c8b09..bc71ea2d70 100644
--- a/src/app/api/combos/route.ts
+++ b/src/app/api/combos/route.ts
@@ -29,8 +29,10 @@ export async function POST(request) {
if (isValidationFailure(validation)) {
return NextResponse.json({ error: validation.error }, { status: 400 });
}
+ const allCombos = await getCombos();
const normalizedModels = normalizeComboModels(validation.data.models, {
comboName: validation.data.name,
+ allCombos,
});
const comboInput = {
...validation.data,
@@ -49,7 +51,6 @@ export async function POST(request) {
}
// Validate nested combo DAG (no circular references, max depth)
- const allCombos = await getCombos();
// Temporarily add the new combo to validate its graph
const tempCombo = {
...comboInput,
diff --git a/tests/unit/combo-routes-composite-tiers.test.mjs b/tests/unit/combo-routes-composite-tiers.test.mjs
index 2245ad1892..b0c3f1be9a 100644
--- a/tests/unit/combo-routes-composite-tiers.test.mjs
+++ b/tests/unit/combo-routes-composite-tiers.test.mjs
@@ -123,6 +123,30 @@ test("POST /api/combos persists valid composite tiers", async () => {
assert.equal(stored.models[0].id, "step-primary");
});
+test("POST /api/combos preserves legacy string combo refs during normalization", async () => {
+ await combosDb.createCombo({
+ name: "child-ref",
+ strategy: "priority",
+ models: ["openai/gpt-4o-mini"],
+ });
+
+ const response = await createRoute.POST(
+ makeCreateRequest({
+ name: "parent-ref",
+ strategy: "priority",
+ models: ["child-ref"],
+ })
+ );
+ const body = await response.json();
+ const stored = await combosDb.getComboByName("parent-ref");
+
+ assert.equal(response.status, 201);
+ assert.equal(body.models[0].kind, "combo-ref");
+ assert.equal(body.models[0].comboName, "child-ref");
+ assert.equal(stored.models[0].kind, "combo-ref");
+ assert.equal(stored.models[0].comboName, "child-ref");
+});
+
test("PUT /api/combos rejects updates that orphan an existing composite tier step reference", async () => {
const combo = await combosDb.createCombo(createTieredComboInput());
@@ -155,3 +179,31 @@ test("PUT /api/combos rejects updates that orphan an existing composite tier ste
},
});
});
+
+test("PUT /api/combos preserves legacy string combo refs during normalization", async () => {
+ await combosDb.createCombo({
+ name: "child-ref",
+ strategy: "priority",
+ models: ["openai/gpt-4o-mini"],
+ });
+ const combo = await combosDb.createCombo({
+ name: "parent-ref",
+ strategy: "priority",
+ models: ["openai/gpt-4o"],
+ });
+
+ const response = await comboRoute.PUT(
+ makeUpdateRequest({
+ models: ["child-ref"],
+ }),
+ { params: Promise.resolve({ id: combo.id }) }
+ );
+ const body = await response.json();
+ const stored = await combosDb.getComboById(combo.id);
+
+ assert.equal(response.status, 200);
+ assert.equal(body.models[0].kind, "combo-ref");
+ assert.equal(body.models[0].comboName, "child-ref");
+ assert.equal(stored.models[0].kind, "combo-ref");
+ assert.equal(stored.models[0].comboName, "child-ref");
+});