1import type { ModelSelection as CursorSdkModelSelection, ModelParameterValue } from "@cursor/sdk";
2import type { ModelSelection } from "@t3tools/contracts";
3
4const CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION: Readonly<Record<string, string>> = {
5 context: "contextWindow",
6 fast: "fastMode",
7};
8
9const PROVIDER_OPTION_TO_CURSOR_SDK_PARAMETER: Readonly<Record<string, string>> = {
10 contextWindow: "context",
11 fastMode: "fast",
12};
13
14export function cursorSdkProviderOptionId(parameterId: string): string {
15 return CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION[parameterId] ?? parameterId;
16}
17
18function cursorSdkParameterId(providerOptionId: string): string {
19 return PROVIDER_OPTION_TO_CURSOR_SDK_PARAMETER[providerOptionId] ?? providerOptionId;
20}
21
22export function cursorSdkParameterPriority(parameterId: string): number {
23 switch (parameterId) {
24 case "effort":
25 case "reasoning":
26 return 0;
27 case "context":
28 return 1;
29 case "fast":
30 return 2;
31 case "thinking":
32 return 3;
33 default:
34 return 4;
35 }
36}
37
38export function cursorSdkModelSelection(modelSelection: ModelSelection): CursorSdkModelSelection {
39 return {
40 id: modelSelection.model === "auto" ? "default" : modelSelection.model,
41 ...(modelSelection.options === undefined || modelSelection.options.length === 0
42 ? {}
43 : {
44 params: modelSelection.options.map((option): ModelParameterValue => ({
45 id: cursorSdkParameterId(option.id),
46 value: String(option.value),
47 })),
48 }),
49 };
50}