Skip to content

Commit b506d51

Browse files
Huijirocursoragent
andcommitted
feat(cursor): expose optional Max Mode as a composer boolean
When the SDK catalog has matching max and non-max variants for the same params, add a Max Mode option and honor it on send without forwarding it as a model parameter. Co-authored-by: Cursor <[email protected]>
1 parent ddcee48 commit b506d51

4 files changed

Lines changed: 197 additions & 6 deletions

File tree

‎packages/provider-cursor/src/server/sdkModel.test.ts‎

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { describe, expect, it } from "@effect/vitest";
22
import { ProviderInstanceId } from "@t3tools/contracts";
3-
import { cursorSdkMaxModeForParams, cursorSdkModelSelection } from "./sdkModel.ts";
3+
import {
4+
CURSOR_SDK_MAX_MODE_OPTION_ID,
5+
cursorSdkMaxModeForParams,
6+
cursorSdkModelOffersOptionalMaxMode,
7+
cursorSdkModelSelection,
8+
} from "./sdkModel.ts";
49

510
describe("cursorSdkModelSelection", () => {
611
const instanceId = ProviderInstanceId.make("cursor");
@@ -52,4 +57,106 @@ describe("cursorSdkModelSelection", () => {
5257
),
5358
).toBe(false);
5459
});
60+
61+
it("sets maxMode from the composer option without forwarding it as an SDK param", () => {
62+
const catalog = [
63+
{
64+
id: "composer-2",
65+
variants: [
66+
{
67+
displayName: "Composer",
68+
isDefault: true,
69+
params: [{ id: "fast", value: "false" }],
70+
},
71+
{
72+
displayName: "Composer Max",
73+
isMaxMode: true,
74+
params: [{ id: "fast", value: "false" }],
75+
},
76+
],
77+
},
78+
];
79+
expect(
80+
cursorSdkModelSelection(
81+
{
82+
instanceId,
83+
model: "composer-2",
84+
options: [
85+
{ id: "fastMode", value: false },
86+
{ id: CURSOR_SDK_MAX_MODE_OPTION_ID, value: true },
87+
],
88+
},
89+
catalog,
90+
),
91+
).toEqual({
92+
id: "composer-2",
93+
params: [{ id: "fast", value: "false" }],
94+
maxMode: true,
95+
});
96+
expect(
97+
cursorSdkModelSelection(
98+
{
99+
instanceId,
100+
model: "composer-2",
101+
options: [
102+
{ id: "fastMode", value: false },
103+
{ id: CURSOR_SDK_MAX_MODE_OPTION_ID, value: false },
104+
],
105+
},
106+
catalog,
107+
),
108+
).toEqual({
109+
id: "composer-2",
110+
params: [{ id: "fast", value: "false" }],
111+
});
112+
});
113+
});
114+
115+
describe("cursorSdkModelOffersOptionalMaxMode", () => {
116+
it("is true when the same params have both max and non-max variants", () => {
117+
expect(
118+
cursorSdkModelOffersOptionalMaxMode({
119+
variants: [
120+
{
121+
displayName: "Standard",
122+
isDefault: true,
123+
params: [{ id: "fast", value: "false" }],
124+
},
125+
{
126+
displayName: "Max",
127+
isMaxMode: true,
128+
params: [{ id: "fast", value: "false" }],
129+
},
130+
],
131+
}),
132+
).toBe(true);
133+
});
134+
135+
it("is false when max mode is forced for every matching selection", () => {
136+
expect(
137+
cursorSdkModelOffersOptionalMaxMode({
138+
variants: [
139+
{
140+
displayName: "1M",
141+
isMaxMode: true,
142+
params: [{ id: "context", value: "1m" }],
143+
},
144+
],
145+
}),
146+
).toBe(false);
147+
});
148+
149+
it("is false when no variants use max mode", () => {
150+
expect(
151+
cursorSdkModelOffersOptionalMaxMode({
152+
variants: [
153+
{
154+
displayName: "Default",
155+
isDefault: true,
156+
params: [{ id: "fast", value: "false" }],
157+
},
158+
],
159+
}),
160+
).toBe(false);
161+
});
55162
});

‎packages/provider-cursor/src/server/sdkModel.ts‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import type {
77
import type { ModelSelection, ServerProviderModel } from "@t3tools/contracts";
88
import { getProviderOptionCurrentValue } from "@t3tools/shared/model";
99

10+
/** Composer option id for optional Cursor max mode; not an SDK model parameter. */
11+
export const CURSOR_SDK_MAX_MODE_OPTION_ID = "maxMode";
12+
1013
const CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION: Readonly<Record<string, string>> = {
1114
context: "contextWindow",
1215
fast: "fastMode",
@@ -72,7 +75,6 @@ function variantMatchesParams(
7275
);
7376
}
7477

75-
/** True when every catalog variant consistent with `params` requires max mode. */
7678
export function cursorSdkMaxModeForParams(
7779
model: Pick<SDKModel, "variants">,
7880
params: ReadonlyArray<ModelParameterValue> | undefined,
@@ -82,21 +84,53 @@ export function cursorSdkMaxModeForParams(
8284
return matching.length > 0 && matching.every((variant) => variant.isMaxMode === true);
8385
}
8486

87+
export function cursorSdkModelOffersOptionalMaxMode(model: Pick<SDKModel, "variants">): boolean {
88+
const variants = model.variants ?? [];
89+
if (
90+
!variants.some((variant) => variant.isMaxMode === true) ||
91+
!variants.some((variant) => variant.isMaxMode !== true)
92+
) {
93+
return false;
94+
}
95+
96+
const candidateParams: Array<ReadonlyArray<ModelParameterValue> | undefined> = [undefined];
97+
for (const variant of variants) {
98+
candidateParams.push(variant.params);
99+
}
100+
101+
for (const params of candidateParams) {
102+
const matching = variants.filter((variant) => variantMatchesParams(variant, params));
103+
if (
104+
matching.some((variant) => variant.isMaxMode === true) &&
105+
matching.some((variant) => variant.isMaxMode !== true)
106+
) {
107+
return true;
108+
}
109+
}
110+
return false;
111+
}
112+
85113
export function cursorSdkModelSelection(
86114
modelSelection: ModelSelection,
87115
sdkModels?: ReadonlyArray<Pick<SDKModel, "id" | "variants">>,
88116
): CursorSdkModelSelection {
89117
const id = modelSelection.model === "auto" ? "default" : modelSelection.model;
118+
const options = modelSelection.options ?? [];
119+
const userRequestedMaxMode = options.some(
120+
(option) => option.id === CURSOR_SDK_MAX_MODE_OPTION_ID && option.value === true,
121+
);
122+
const sdkOptions = options.filter((option) => option.id !== CURSOR_SDK_MAX_MODE_OPTION_ID);
90123
const params =
91-
modelSelection.options === undefined || modelSelection.options.length === 0
124+
sdkOptions.length === 0
92125
? undefined
93-
: modelSelection.options.map((option): ModelParameterValue => ({
126+
: sdkOptions.map((option): ModelParameterValue => ({
94127
id: cursorSdkParameterId(option.id),
95128
value: String(option.value),
96129
}));
97130
const catalogModel = sdkModels?.find((model) => model.id === id);
98131
const maxMode =
99-
catalogModel === undefined ? false : cursorSdkMaxModeForParams(catalogModel, params);
132+
userRequestedMaxMode ||
133+
(catalogModel !== undefined && cursorSdkMaxModeForParams(catalogModel, params));
100134
return {
101135
id,
102136
...(params === undefined ? {} : { params }),

‎packages/provider-cursor/src/server/status.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,30 @@ const sdkParameterizedModel = {
9292
],
9393
} satisfies SDKModel;
9494

95+
const sdkOptionalMaxModeModel = {
96+
id: "composer-2",
97+
displayName: "Composer 2",
98+
parameters: [
99+
{
100+
id: "fast",
101+
displayName: "Fast",
102+
values: [{ value: "false" }, { value: "true", displayName: "Fast" }],
103+
},
104+
],
105+
variants: [
106+
{
107+
displayName: "Composer 2",
108+
isDefault: true,
109+
params: [{ id: "fast", value: "false" }],
110+
},
111+
{
112+
displayName: "Composer 2 Max",
113+
isMaxMode: true,
114+
params: [{ id: "fast", value: "false" }],
115+
},
116+
],
117+
} satisfies SDKModel;
118+
95119
describe("buildCursorProviderSnapshot", () => {
96120
it("downgrades ready status to warning when SDK model discovery returns no models", () => {
97121
expect(
@@ -134,6 +158,17 @@ describe("Cursor SDK model discovery", () => {
134158
);
135159
});
136160

161+
it("adds a Max Mode boolean when the catalog offers optional max mode", () => {
162+
expect(buildCursorCapabilitiesFromSdkModel(sdkOptionalMaxModeModel)).toEqual(
163+
createModelCapabilities({
164+
optionDescriptors: [
165+
booleanDescriptor("fastMode", "Fast", false),
166+
booleanDescriptor("maxMode", "Max Mode", false),
167+
],
168+
}),
169+
);
170+
});
171+
137172
it("filters invalid and duplicate SDK model entries", () => {
138173
expect(
139174
buildCursorDiscoveredModelsFromSdk([

‎packages/provider-cursor/src/server/status.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import * as Effect from "effect/Effect";
1313
import * as Option from "effect/Option";
1414
import * as Result from "effect/Result";
1515

16-
import { cursorSdkParameterPriority, cursorSdkProviderOptionId } from "./sdkModel.ts";
16+
import {
17+
CURSOR_SDK_MAX_MODE_OPTION_ID,
18+
cursorSdkModelOffersOptionalMaxMode,
19+
cursorSdkParameterPriority,
20+
cursorSdkProviderOptionId,
21+
} from "./sdkModel.ts";
1722
import {
1823
buildBooleanOptionDescriptor,
1924
buildSelectOptionDescriptor,
@@ -162,6 +167,16 @@ export function buildCursorCapabilitiesFromSdkModel(model: SDKModel): ModelCapab
162167
);
163168
}
164169

170+
if (cursorSdkModelOffersOptionalMaxMode(model)) {
171+
optionDescriptors.push(
172+
buildBooleanOptionDescriptor({
173+
id: CURSOR_SDK_MAX_MODE_OPTION_ID,
174+
label: "Max Mode",
175+
currentValue: false,
176+
}),
177+
);
178+
}
179+
165180
return createModelCapabilities({ optionDescriptors });
166181
}
167182

0 commit comments

Comments
 (0)