Skip to content

Commit d5f79e7

Browse files
committed
fix(cursor): normalize fallback session models
1 parent c45e7fd commit d5f79e7

3 files changed

Lines changed: 43 additions & 17 deletions

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,17 @@ const grokAcpModels: ReadonlyArray<AcpSchema.ModelInfo> = [
350350
];
351351

352352
function modelState(): AcpSchema.SessionModelState {
353+
if (process.env.T3_ACP_CURSOR_MODELS_ERROR === "missing") {
354+
return {
355+
currentModelId: " grok-4.6 ",
356+
availableModels: [
357+
{ modelId: " grok-4.6 ", name: " Grok 4.6 " },
358+
{ modelId: "grok-mock-alt", name: " Grok Mock Alt " },
359+
{ modelId: "blank-name", name: " " },
360+
{ modelId: " ", name: "Invalid" },
361+
],
362+
};
363+
}
353364
if (antigravityProfile) {
354365
return { currentModelId, availableModels: antigravityModels };
355366
}

‎apps/server/src/provider/Layers/CursorProvider.test.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ describe("discoverCursorModelsViaAcp", () => {
650650
customModels: [],
651651
}),
652652
);
653-
expect(models.map((model) => model.slug)).toEqual(["grok-4.6", "grok-mock-alt"]);
653+
expect(models.map((model) => [model.slug, model.name])).toEqual([
654+
["grok-4.6", "Grok 4.6"],
655+
["grok-mock-alt", "Grok Mock Alt"],
656+
]);
654657
expect(models.find((model) => model.isDefault)?.slug).toBe("grok-4.6");
655658
expect(models.every((model) => model.capabilities?.optionDescriptors?.length === 0)).toBe(true);
656659
});

‎apps/server/src/provider/Layers/CursorProvider.ts‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -563,22 +563,34 @@ const discoverCursorModelsViaListAvailableModels = (
563563
return yield* acp.request("cursor/list_available_models", {}).pipe(
564564
Effect.flatMap(decodeCursorListAvailableModelsResponse),
565565
Effect.map(buildCursorDiscoveredModelsFromAvailableModelsResponse),
566-
Effect.catchTag("AcpRequestError", (error) => {
567-
const models = started.sessionSetupResult.models;
568-
if (error.code !== -32601 || !models?.availableModels.length) {
569-
return Effect.fail(error);
570-
}
571-
return Effect.succeed(
572-
buildCursorDiscoveredModels(
573-
models.availableModels.map((model) => ({
574-
slug: model.modelId,
575-
name: model.name,
576-
capabilities: EMPTY_CAPABILITIES,
577-
})),
578-
).map((model) =>
579-
model.slug === models.currentModelId ? { ...model, isDefault: true } : model,
580-
),
581-
);
566+
Effect.catchTags({
567+
AcpRequestError: (error) => {
568+
const models = started.sessionSetupResult.models;
569+
if (error.code !== -32601 || !models?.availableModels.length) {
570+
return Effect.fail(error);
571+
}
572+
return Effect.succeed(
573+
buildCursorDiscoveredModels(
574+
models.availableModels.flatMap((model) => {
575+
const slug = model.modelId.trim();
576+
const name = model.name.trim();
577+
return slug && name
578+
? [
579+
{
580+
slug,
581+
name,
582+
capabilities: EMPTY_CAPABILITIES,
583+
},
584+
]
585+
: [];
586+
}),
587+
).map((model) =>
588+
model.slug === models.currentModelId.trim()
589+
? { ...model, isDefault: true }
590+
: model,
591+
),
592+
);
593+
},
582594
}),
583595
);
584596
}),

0 commit comments

Comments
 (0)