diff --git a/packages/provider-cursor/src/server/adapter.ts b/packages/provider-cursor/src/server/adapter.ts index 1e160be188f08..6b3be72833b97 100644 --- a/packages/provider-cursor/src/server/adapter.ts +++ b/packages/provider-cursor/src/server/adapter.ts @@ -307,6 +307,7 @@ const CURSOR_AGENT_SETTING_SOURCES = [ export function makeCursorAgentOptions(input: { readonly apiKey?: string; readonly modelSelection: ModelSelection; + readonly models?: ReadonlyArray; readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy; readonly threadId: ThreadId; readonly mcpSession: McpProviderSession.McpProviderSessionConfig | undefined; @@ -315,7 +316,7 @@ export function makeCursorAgentOptions(input: { const policy = cursorRuntimeAgentPolicy(input.runtimePolicy, input.platform); const mcpServers = cursorMcpServers(input.mcpSession); return { - model: cursorSdkModelSelection(input.modelSelection), + model: cursorSdkModelSelection(input.modelSelection, input.models), name: `T3 Code ${input.threadId}`, mode: input.runtimePolicy.interactionMode === "plan" ? "plan" : "agent", ...(input.apiKey === undefined ? {} : { apiKey: input.apiKey }), @@ -2296,6 +2297,7 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* ( const options = makeCursorAgentOptions({ ...(apiKey === undefined ? {} : { apiKey }), modelSelection: openInput.modelSelection, + models: adapterOptions.getModels?.() ?? [], runtimePolicy: openInput.runtimePolicy, platform, threadId: openInput.threadId, @@ -2486,7 +2488,10 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* ( message, summarize: compacted, options: { - model: cursorSdkModelSelection(turnInput.modelSelection), + model: cursorSdkModelSelection( + turnInput.modelSelection, + adapterOptions.getModels?.() ?? [], + ), mode: turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : "agent", ...(Object.keys(turnMcpServers).length === 0 ? {} diff --git a/packages/provider-cursor/src/server/driver.test.ts b/packages/provider-cursor/src/server/driver.test.ts index 6ff8bd7685648..213d413b6dee2 100644 --- a/packages/provider-cursor/src/server/driver.test.ts +++ b/packages/provider-cursor/src/server/driver.test.ts @@ -389,7 +389,7 @@ it.layer(layerTest)("CursorDriver", (it) => { allowance: DEFAULT_HANDOFF_TOKEN_CAP, }, catalogDefault: { - model: { id: "claude-opus-5-5" }, + model: { id: "claude-opus-5-5", params: [{ id: "context", value: "1m" }] }, window: 1_000_000, allowance: DEFAULT_HANDOFF_TOKEN_CAP, }, diff --git a/packages/provider-cursor/src/server/driver.ts b/packages/provider-cursor/src/server/driver.ts index ef50abb0a93b4..85ab45b107d71 100644 --- a/packages/provider-cursor/src/server/driver.ts +++ b/packages/provider-cursor/src/server/driver.ts @@ -208,6 +208,7 @@ export const CursorDriver: ProviderDriver< processEnv, auth.requireApiKey, auth.withAccess, + () => catalogModels, ); const checkProvider = auth.readApiKey.pipe( diff --git a/packages/provider-cursor/src/server/sdkModel.test.ts b/packages/provider-cursor/src/server/sdkModel.test.ts new file mode 100644 index 0000000000000..4ad129e1ae239 --- /dev/null +++ b/packages/provider-cursor/src/server/sdkModel.test.ts @@ -0,0 +1,73 @@ +import { ProviderInstanceId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { cursorSdkModelSelection } from "./sdkModel.ts"; +import { buildCursorDiscoveredModelsFromSdk } from "./status.ts"; + +const instanceId = ProviderInstanceId.make("cursor"); +const models = buildCursorDiscoveredModelsFromSdk([ + { + id: "grok-4.5", + displayName: "Grok 4.5", + parameters: [ + { + id: "effort", + displayName: "Effort", + values: [{ value: "low" }, { value: "medium" }, { value: "high" }], + }, + { id: "fast", displayName: "Fast", values: [{ value: "false" }, { value: "true" }] }, + ], + variants: [ + { + displayName: "Grok 4.5 High Fast", + isDefault: true, + params: [ + { id: "effort", value: "high" }, + { id: "fast", value: "true" }, + ], + }, + ], + }, +]); + +describe("cursorSdkModelSelection", () => { + it.each([ + { + name: "fills unset catalog parameters and keeps Fast off", + options: undefined, + params: [ + { id: "effort", value: "high" }, + { id: "fast", value: "false" }, + ], + }, + { + name: "keeps explicit options", + options: [ + { id: "effort", value: "low" }, + { id: "fastMode", value: true }, + ], + params: [ + { id: "effort", value: "low" }, + { id: "fast", value: "true" }, + ], + }, + ])("$name", ({ options, params }) => { + const selection = cursorSdkModelSelection( + { instanceId, model: "grok-4.5", ...(options === undefined ? {} : { options }) }, + models, + ); + expect({ + ...selection, + params: selection.params?.toSorted((a, b) => a.id.localeCompare(b.id)), + }).toEqual({ + id: "grok-4.5", + params, + }); + }); + + it("sends no parameters for a model missing from the catalog", () => { + expect(cursorSdkModelSelection({ instanceId, model: "auto" }, models)).toEqual({ + id: "default", + }); + }); +}); diff --git a/packages/provider-cursor/src/server/sdkModel.ts b/packages/provider-cursor/src/server/sdkModel.ts index fec0bafc45eee..ec2a53b6aea71 100644 --- a/packages/provider-cursor/src/server/sdkModel.ts +++ b/packages/provider-cursor/src/server/sdkModel.ts @@ -55,13 +55,27 @@ export function cursorContextWindowTokens( return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined; } -export function cursorSdkModelSelection(modelSelection: ModelSelection): CursorSdkModelSelection { +export function cursorSdkModelSelection( + modelSelection: ModelSelection, + models: ReadonlyArray = [], +): CursorSdkModelSelection { + const explicit = modelSelection.options ?? []; + const descriptors = + models.find((model) => model.slug === modelSelection.model)?.capabilities?.optionDescriptors ?? + []; + // Some Cursor plans reject runs that leave a catalog parameter unset; T3 keeps Fast off until picked. + const defaults = descriptors.flatMap((descriptor) => { + if (explicit.some((option) => option.id === descriptor.id)) return []; + const value = descriptor.id === "fastMode" ? false : getProviderOptionCurrentValue(descriptor); + return value === undefined ? [] : [{ id: descriptor.id, value }]; + }); + const options = [...explicit, ...defaults]; return { id: modelSelection.model === "auto" ? "default" : modelSelection.model, - ...(modelSelection.options === undefined || modelSelection.options.length === 0 + ...(options.length === 0 ? {} : { - params: modelSelection.options.map((option): ModelParameterValue => ({ + params: options.map((option): ModelParameterValue => ({ id: cursorSdkParameterId(option.id), value: String(option.value), })), diff --git a/packages/provider-cursor/src/server/textGeneration.ts b/packages/provider-cursor/src/server/textGeneration.ts index 278839558ee92..82982dfabbb5f 100644 --- a/packages/provider-cursor/src/server/textGeneration.ts +++ b/packages/provider-cursor/src/server/textGeneration.ts @@ -5,7 +5,11 @@ import * as Effect from "effect/Effect"; import * as Option from "effect/Option"; import * as Schema from "effect/Schema"; -import { type ProviderSetupError, TextGenerationError } from "@t3tools/contracts"; +import { + type ProviderSetupError, + type ServerProviderModel, + TextGenerationError, +} from "@t3tools/contracts"; import type { CursorSettings } from "../settings.ts"; import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations"; @@ -51,6 +55,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu environment?: NodeJS.ProcessEnv, resolveApiKey?: Effect.Effect, withAccess?: CursorAuth["withAccess"], + getModels?: () => ReadonlyArray, ) { const fs = yield* FileSystem.FileSystem; const sdk = yield* CursorSdk.CursorSdk; @@ -117,7 +122,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu const agentOptions = { apiKey, mode: "plan", - model: cursorSdkModelSelection(modelSelection), + model: cursorSdkModelSelection(modelSelection, getModels?.() ?? []), local: { cwd, store,