Add Cursor SDK orchestration replay support
- Wire Cursor adapter and provider session handling into orchestration v2 - Add replay fixtures, recording script, and coverage for Cursor turn flows - Update docs and debug timeline mapping for Cursor events
This commit is contained in:
1 parent
4fae73ee08
commit
ce64e37094
50 files changed
+7163
-201
No files matched your search
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* CursorDriver — `ProviderDriver` for the Cursor Agent (`cursor-agent`) runtime.
|
||||
*
|
||||
* Cursor exposes an ACP-based CLI. Model catalog and capability refreshes
|
||||
* happen during the managed provider status check via Cursor's
|
||||
* `list_available_models` extension method.
|
||||
* Provider status and model discovery use the official Cursor SDK when an API
|
||||
* key is configured. The ACP CLI remains the compatibility fallback for
|
||||
* installations that authenticate through the local Cursor binary.
|
||||
*
|
||||
* Text generation is supported via the ACP runtime — `makeCursorTextGeneration`
|
||||
* drives `runtime.prompt` with a structured-output schema and collects the
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
checkCursorProviderStatus,
|
||||
enrichCursorSnapshot,
|
||||
} from "../Layers/CursorProvider.ts";
|
||||
import { CursorSdkCatalogLive } from "../Layers/CursorSdkCatalog.ts";
|
||||
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
|
||||
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
|
||||
import {
|
||||
@@ -134,7 +135,7 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
|
||||
|
||||
const checkProvider = checkCursorProviderStatus(effectiveConfig, processEnv).pipe(
|
||||
Effect.map(stampIdentity),
|
||||
Effect.provideService(Crypto.Crypto, crypto),
|
||||
Effect.provide(CursorSdkCatalogLive),
|
||||
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
|
||||
Effect.provideService(FileSystem.FileSystem, fileSystem),
|
||||
Effect.provideService(Path.Path, path),
|
||||
|
||||
@@ -3,17 +3,22 @@ import * as os from "node:os";
|
||||
import { chmod, mkdtemp, readFile, writeFile } from "node:fs/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import type { SDKModel } from "@cursor/sdk";
|
||||
import { describe, expect, it } from "@effect/vitest";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { Effect } from "effect";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import type * as EffectAcpSchema from "effect-acp/schema";
|
||||
import type { CursorSettings, ServerProviderModel } from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
buildCursorProviderSnapshot,
|
||||
buildCursorCapabilitiesFromConfigOptions,
|
||||
buildCursorDiscoveredModelsFromConfigOptions,
|
||||
discoverCursorModelCapabilitiesViaAcp,
|
||||
buildCursorCapabilitiesFromSdkModel,
|
||||
buildCursorDiscoveredModelsFromSdk,
|
||||
checkCursorProviderStatus,
|
||||
discoverCursorModelsViaAcp,
|
||||
getCursorFallbackModels,
|
||||
getCursorParameterizedModelPickerUnsupportedMessage,
|
||||
@@ -23,6 +28,7 @@ import {
|
||||
resolveCursorAcpBaseModelId,
|
||||
resolveCursorAcpConfigUpdates,
|
||||
} from "./CursorProvider.ts";
|
||||
import { CursorSdkCatalogError, makeCursorSdkCatalogTestLayer } from "./CursorSdkCatalog.ts";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const mockAgentPath = path.join(__dirname, "../../../scripts/acp-mock-agent.ts");
|
||||
@@ -239,13 +245,50 @@ const baseCursorSettings: CursorSettings = {
|
||||
customModels: [],
|
||||
};
|
||||
|
||||
const emptyCapabilities = {
|
||||
reasoningEffortLevels: [],
|
||||
supportsFastMode: false,
|
||||
supportsThinkingToggle: false,
|
||||
contextWindowOptions: [],
|
||||
promptInjectedEffortLevels: [],
|
||||
} as const;
|
||||
const sdkParameterizedModel = {
|
||||
id: "claude-opus-4-8",
|
||||
displayName: "Opus 4.8",
|
||||
parameters: [
|
||||
{
|
||||
id: "thinking",
|
||||
displayName: "Thinking",
|
||||
values: [{ value: "false" }, { value: "true" }],
|
||||
},
|
||||
{
|
||||
id: "context",
|
||||
displayName: "Context",
|
||||
values: [
|
||||
{ value: "300k", displayName: "300K" },
|
||||
{ value: "1m", displayName: "1M" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "effort",
|
||||
displayName: "Effort",
|
||||
values: [
|
||||
{ value: "low", displayName: "Low" },
|
||||
{ value: "high", displayName: "High" },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "fast",
|
||||
displayName: "Fast",
|
||||
values: [{ value: "false" }, { value: "true", displayName: "Fast" }],
|
||||
},
|
||||
],
|
||||
variants: [
|
||||
{
|
||||
displayName: "Opus 4.8",
|
||||
isDefault: true,
|
||||
params: [
|
||||
{ id: "thinking", value: "true" },
|
||||
{ id: "context", value: "1m" },
|
||||
{ id: "effort", value: "high" },
|
||||
{ id: "fast", value: "false" },
|
||||
],
|
||||
},
|
||||
],
|
||||
} satisfies SDKModel;
|
||||
|
||||
describe("getCursorFallbackModels", () => {
|
||||
it("does not publish any built-in cursor models before ACP discovery", () => {
|
||||
@@ -361,22 +404,114 @@ describe("buildCursorCapabilitiesFromConfigOptions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkCursorProviderStatus", () => {
|
||||
it("reports the install docs when the Cursor CLI command is missing", async () => {
|
||||
const provider = await runNode(
|
||||
checkCursorProviderStatus({
|
||||
enabled: true,
|
||||
binaryPath: missingCursorBinaryPath,
|
||||
apiEndpoint: "",
|
||||
customModels: [],
|
||||
describe("Cursor SDK model discovery", () => {
|
||||
it("maps native SDK parameter ids and default variant values to model capabilities", () => {
|
||||
expect(buildCursorCapabilitiesFromSdkModel(sdkParameterizedModel)).toEqual(
|
||||
createModelCapabilities({
|
||||
optionDescriptors: [
|
||||
selectDescriptor("effort", "Effort", [
|
||||
{ id: "low", label: "Low" },
|
||||
{ id: "high", label: "High", isDefault: true },
|
||||
]),
|
||||
selectDescriptor("contextWindow", "Context", [
|
||||
{ id: "300k", label: "300K" },
|
||||
{ id: "1m", label: "1M", isDefault: true },
|
||||
]),
|
||||
booleanDescriptor("fastMode", "Fast", false),
|
||||
booleanDescriptor("thinking", "Thinking", true),
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("filters invalid and duplicate SDK model entries", () => {
|
||||
expect(
|
||||
buildCursorDiscoveredModelsFromSdk([
|
||||
sdkParameterizedModel,
|
||||
{ ...sdkParameterizedModel, displayName: "Duplicate" },
|
||||
{ id: "", displayName: "Invalid" },
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
slug: "claude-opus-4-8",
|
||||
name: "Opus 4.8",
|
||||
isCustom: false,
|
||||
capabilities: buildCursorCapabilitiesFromSdkModel(sdkParameterizedModel),
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("checkCursorProviderStatus", () => {
|
||||
it("uses the SDK catalog when CURSOR_API_KEY is configured", async () => {
|
||||
const provider = await Effect.runPromise(
|
||||
checkCursorProviderStatus(
|
||||
{
|
||||
...baseCursorSettings,
|
||||
binaryPath: "cursor-cli-must-not-be-invoked",
|
||||
customModels: ["internal/cursor-model"],
|
||||
},
|
||||
{ CURSOR_API_KEY: "test-cursor-key" },
|
||||
).pipe(
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
makeCursorSdkCatalogTestLayer((apiKey) => {
|
||||
expect(apiKey).toBe("test-cursor-key");
|
||||
return Effect.succeed({
|
||||
user: {
|
||||
apiKeyName: "test-key",
|
||||
userEmail: "[email protected]",
|
||||
createdAt: "2026-01-01T00:00:00.000Z",
|
||||
},
|
||||
models: [sdkParameterizedModel],
|
||||
});
|
||||
}),
|
||||
NodeServices.layer,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(provider).toMatchObject({
|
||||
status: "ready",
|
||||
auth: {
|
||||
status: "authenticated",
|
||||
type: "api-key",
|
||||
label: "Cursor API key (test-key)",
|
||||
email: "[email protected]",
|
||||
},
|
||||
models: [
|
||||
{ slug: "claude-opus-4-8", isCustom: false },
|
||||
{ slug: "internal/cursor-model", isCustom: true },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("surfaces SDK authentication failures without invoking the CLI", async () => {
|
||||
const provider = await Effect.runPromise(
|
||||
checkCursorProviderStatus(baseCursorSettings, {
|
||||
CURSOR_API_KEY: "invalid-test-key",
|
||||
}).pipe(
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
makeCursorSdkCatalogTestLayer(() =>
|
||||
Effect.fail(
|
||||
new CursorSdkCatalogError({
|
||||
authenticationFailure: true,
|
||||
cause: new Error("unauthorized"),
|
||||
}),
|
||||
),
|
||||
),
|
||||
NodeServices.layer,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(provider).toMatchObject({
|
||||
installed: false,
|
||||
status: "error",
|
||||
auth: { status: "unknown" },
|
||||
message: cursorCliCommandMissingMessage,
|
||||
auth: { status: "unauthenticated" },
|
||||
message: "Cursor SDK authentication failed. Check CURSOR_API_KEY.",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -393,8 +528,18 @@ describe("checkCursorProviderStatus", () => {
|
||||
},
|
||||
{
|
||||
...process.env,
|
||||
CURSOR_API_KEY: "",
|
||||
T3_ACP_REQUEST_LOG_PATH: requestLogPath,
|
||||
},
|
||||
).pipe(
|
||||
Effect.provide(
|
||||
Layer.mergeAll(
|
||||
makeCursorSdkCatalogTestLayer(() =>
|
||||
Effect.die("SDK catalog must not be used without CURSOR_API_KEY"),
|
||||
),
|
||||
NodeServices.layer,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -409,45 +554,40 @@ describe("checkCursorProviderStatus", () => {
|
||||
});
|
||||
|
||||
describe("discoverCursorModelsViaAcp", () => {
|
||||
it("keeps the ACP probe runtime alive long enough to discover models", async () => {
|
||||
const wrapperPath = await makeMockAgentWrapper();
|
||||
|
||||
const models = await Effect.runPromise(
|
||||
discoverCursorModelsViaAcp({
|
||||
it.effect("keeps the ACP probe runtime alive long enough to discover models", () =>
|
||||
Effect.gen(function* () {
|
||||
const wrapperPath = yield* makeMockAgentWrapper();
|
||||
const models = yield* discoverCursorModelsViaAcp({
|
||||
enabled: true,
|
||||
binaryPath: wrapperPath,
|
||||
apiEndpoint: "",
|
||||
customModels: [],
|
||||
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
|
||||
);
|
||||
});
|
||||
|
||||
expect(models.map((model) => model.slug)).toEqual([
|
||||
"default",
|
||||
"composer-2",
|
||||
"gpt-5.4",
|
||||
"claude-opus-4-6",
|
||||
]);
|
||||
});
|
||||
expect(models.map((model) => model.slug)).toEqual([
|
||||
"default",
|
||||
"composer-2",
|
||||
"gpt-5.4",
|
||||
"claude-opus-4-6",
|
||||
]);
|
||||
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
|
||||
);
|
||||
|
||||
it("closes the ACP probe runtime after discovery completes", async () => {
|
||||
const tempDir = await mkdtemp(path.join(os.tmpdir(), "cursor-provider-exit-log-"));
|
||||
const exitLogPath = path.join(tempDir, "exit.log");
|
||||
const wrapperPath = await makeMockAgentWrapper({
|
||||
T3_ACP_EXIT_LOG_PATH: exitLogPath,
|
||||
});
|
||||
it.effect("closes the ACP probe runtime after discovery completes", () =>
|
||||
Effect.gen(function* () {
|
||||
const { exitLogPath, wrapperPath } = yield* makeExitLogFixture("cursor-provider-exit-log-");
|
||||
|
||||
await Effect.runPromise(
|
||||
discoverCursorModelsViaAcp({
|
||||
yield* discoverCursorModelsViaAcp({
|
||||
enabled: true,
|
||||
binaryPath: wrapperPath,
|
||||
apiEndpoint: "",
|
||||
customModels: [],
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
});
|
||||
|
||||
const exitLog = await waitForFileContent(exitLogPath);
|
||||
expect(exitLog).toContain("SIGTERM");
|
||||
});
|
||||
const exitLog = yield* waitForFileContent(exitLogPath);
|
||||
expect(exitLog).toContain("SIGTERM");
|
||||
}).pipe(Effect.provide(NodeServices.layer)),
|
||||
);
|
||||
});
|
||||
|
||||
describe("discoverCursorModelCapabilitiesViaAcp", () => {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import * as NodeOS from "node:os";
|
||||
import * as NodeOs from "node:os";
|
||||
import type { SDKModel, SDKUser } from "@cursor/sdk";
|
||||
import type {
|
||||
CursorSettings,
|
||||
ModelCapabilities,
|
||||
ProviderOptionDescriptor,
|
||||
ProviderOptionSelection,
|
||||
ServerProvider,
|
||||
ServerProviderAuth,
|
||||
@@ -44,8 +46,10 @@ import {
|
||||
enrichProviderSnapshotWithVersionAdvisory,
|
||||
type ProviderMaintenanceCapabilities,
|
||||
} from "../providerMaintenance.ts";
|
||||
import * as AcpSessionRuntime from "../acp/AcpSessionRuntime.ts";
|
||||
import { cursorSdkParameterPriority, cursorSdkProviderOptionId } from "../cursorSdkModel.ts";
|
||||
import { AcpSessionRuntime } from "../acp/AcpSessionRuntime.ts";
|
||||
import { CursorListAvailableModelsResponse } from "../acp/CursorAcpExtension.ts";
|
||||
import { CursorSdkCatalog } from "./CursorSdkCatalog.ts";
|
||||
|
||||
const decodeCursorListAvailableModelsResponse = Schema.decodeUnknownEffect(
|
||||
CursorListAvailableModelsResponse,
|
||||
@@ -60,6 +64,7 @@ const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({
|
||||
});
|
||||
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_TIMEOUT_MS = 15_000;
|
||||
const CURSOR_SDK_CATALOG_TIMEOUT_MS = 15_000;
|
||||
const CURSOR_PARAMETERIZED_MODEL_PICKER_MIN_VERSION_DATE = 2026_04_08;
|
||||
const CURSOR_CLI_INSTALLATION_DOCS_URL = "https://cursor.com/docs/cli/installation";
|
||||
const CURSOR_ACP_MODEL_DISCOVERY_FAILED_MESSAGE = [
|
||||
@@ -378,6 +383,112 @@ function buildCursorDiscoveredModels(
|
||||
});
|
||||
}
|
||||
|
||||
function cursorSdkDefaultParameterValue(model: SDKModel, parameterId: string): string | undefined {
|
||||
return model.variants
|
||||
?.find((variant) => variant.isDefault)
|
||||
?.params.find((parameter) => parameter.id === parameterId)?.value;
|
||||
}
|
||||
|
||||
export function buildCursorCapabilitiesFromSdkModel(model: SDKModel): ModelCapabilities {
|
||||
const seen = new Set<string>();
|
||||
const optionDescriptors: Array<ProviderOptionDescriptor> = [];
|
||||
const parameters = (model.parameters ?? [])
|
||||
.map((parameter, index) => ({ parameter, index }))
|
||||
.toSorted(
|
||||
(left, right) =>
|
||||
cursorSdkParameterPriority(left.parameter.id) -
|
||||
cursorSdkParameterPriority(right.parameter.id) || left.index - right.index,
|
||||
);
|
||||
for (const { parameter } of parameters) {
|
||||
const nativeId = parameter.id.trim();
|
||||
const id = cursorSdkProviderOptionId(nativeId);
|
||||
if (!nativeId || !id || seen.has(id)) {
|
||||
continue;
|
||||
}
|
||||
seen.add(id);
|
||||
|
||||
const values = parameter.values.flatMap((entry) => {
|
||||
const value = entry.value.trim();
|
||||
if (!value) {
|
||||
return [];
|
||||
}
|
||||
return [
|
||||
{
|
||||
value,
|
||||
label: entry.displayName?.trim() || value,
|
||||
},
|
||||
];
|
||||
});
|
||||
if (values.length === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const label = parameter.displayName?.trim() || toTitleCaseWords(id);
|
||||
const defaultValue = cursorSdkDefaultParameterValue(model, nativeId);
|
||||
const normalizedValues = new Set(values.map((entry) => entry.value.toLowerCase()));
|
||||
if (values.length === 2 && normalizedValues.has("true") && normalizedValues.has("false")) {
|
||||
if (defaultValue === "true" || defaultValue === "false") {
|
||||
optionDescriptors.push(
|
||||
buildBooleanOptionDescriptor({
|
||||
id,
|
||||
label,
|
||||
currentValue: defaultValue === "true",
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
optionDescriptors.push(buildBooleanOptionDescriptor({ id, label }));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
optionDescriptors.push(
|
||||
buildSelectOptionDescriptor({
|
||||
id,
|
||||
label,
|
||||
options: values.map((entry) => ({
|
||||
...entry,
|
||||
...(entry.value === defaultValue ? { isDefault: true } : {}),
|
||||
})),
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return createModelCapabilities({ optionDescriptors });
|
||||
}
|
||||
|
||||
export function buildCursorDiscoveredModelsFromSdk(
|
||||
models: ReadonlyArray<SDKModel>,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
const seen = new Set<string>();
|
||||
return models.flatMap((model) => {
|
||||
const slug = model.id.trim();
|
||||
const name = model.displayName.trim();
|
||||
if (!slug || !name || seen.has(slug)) {
|
||||
return [];
|
||||
}
|
||||
seen.add(slug);
|
||||
return [
|
||||
{
|
||||
slug,
|
||||
name,
|
||||
isCustom: false,
|
||||
capabilities: buildCursorCapabilitiesFromSdkModel(model),
|
||||
} satisfies ServerProviderModel,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
function cursorSdkAuth(user: SDKUser): ServerProviderAuth {
|
||||
const email = user.userEmail?.trim();
|
||||
const apiKeyName = user.apiKeyName.trim();
|
||||
return {
|
||||
status: "authenticated",
|
||||
type: "api-key",
|
||||
label: apiKeyName ? `Cursor API key (${apiKeyName})` : "Cursor API key",
|
||||
...(email ? { email } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function buildCursorDiscoveredModelsFromAvailableModelsResponse(
|
||||
response: typeof CursorListAvailableModelsResponse.Type,
|
||||
): ReadonlyArray<ServerProviderModel> {
|
||||
@@ -990,7 +1101,7 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
): Effect.fn.Return<
|
||||
ServerProviderDraft,
|
||||
never,
|
||||
ChildProcessSpawner.ChildProcessSpawner | Crypto.Crypto | FileSystem.FileSystem | Path.Path
|
||||
ChildProcessSpawner.ChildProcessSpawner | CursorSdkCatalog | FileSystem.FileSystem | Path.Path
|
||||
> {
|
||||
const checkedAt = DateTime.formatIso(yield* DateTime.now);
|
||||
const fallbackModels = getCursorFallbackModels(cursorSettings);
|
||||
@@ -1011,6 +1122,68 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
});
|
||||
}
|
||||
|
||||
const sdkApiKey = environment?.CURSOR_API_KEY?.trim();
|
||||
if (sdkApiKey) {
|
||||
const sdkCatalog = yield* CursorSdkCatalog;
|
||||
const catalogResult = yield* sdkCatalog
|
||||
.read(sdkApiKey)
|
||||
.pipe(Effect.timeoutOption(CURSOR_SDK_CATALOG_TIMEOUT_MS), Effect.result);
|
||||
|
||||
if (Result.isFailure(catalogResult)) {
|
||||
yield* Effect.logWarning("Cursor SDK catalog probe failed", {
|
||||
cause: catalogResult.failure.cause,
|
||||
});
|
||||
const authenticationFailure = catalogResult.failure.authenticationFailure;
|
||||
return buildServerProvider({
|
||||
presentation: CURSOR_PRESENTATION,
|
||||
enabled: cursorSettings.enabled,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: true,
|
||||
version: null,
|
||||
status: "error",
|
||||
auth: { status: authenticationFailure ? "unauthenticated" : "unknown" },
|
||||
message: authenticationFailure
|
||||
? "Cursor SDK authentication failed. Check CURSOR_API_KEY."
|
||||
: "Cursor SDK catalog request failed. Check server logs for details.",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (Option.isNone(catalogResult.success)) {
|
||||
return buildServerProvider({
|
||||
presentation: CURSOR_PRESENTATION,
|
||||
enabled: cursorSettings.enabled,
|
||||
checkedAt,
|
||||
models: fallbackModels,
|
||||
probe: {
|
||||
installed: true,
|
||||
version: null,
|
||||
status: "error",
|
||||
auth: { status: "unknown" },
|
||||
message: `Cursor SDK catalog request timed out after ${CURSOR_SDK_CATALOG_TIMEOUT_MS}ms.`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const snapshot = catalogResult.success.value;
|
||||
const discoveredModels = buildCursorDiscoveredModelsFromSdk(snapshot.models);
|
||||
return buildCursorProviderSnapshot({
|
||||
checkedAt,
|
||||
cursorSettings,
|
||||
parsed: {
|
||||
version: null,
|
||||
status: "ready",
|
||||
auth: cursorSdkAuth(snapshot.user),
|
||||
},
|
||||
discoveredModels,
|
||||
...(discoveredModels.length === 0
|
||||
? { discoveryWarning: "Cursor SDK model discovery returned no built-in models." }
|
||||
: {}),
|
||||
});
|
||||
}
|
||||
|
||||
// Single `agent about` probe: returns version + auth status in one call.
|
||||
const aboutProbe = yield* runCursorAboutCommand(cursorSettings, environment).pipe(
|
||||
Effect.timeoutOption(ABOUT_TIMEOUT_MS),
|
||||
@@ -1118,8 +1291,9 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(
|
||||
*
|
||||
* Used by `CursorDriver` as the `makeManagedServerProvider.enrichSnapshot`
|
||||
* hook: republishes update/version advisory metadata without performing any
|
||||
* model or capability discovery. Cursor model data comes exclusively from
|
||||
* `cursor/list_available_models` during provider status checks.
|
||||
* model or capability discovery. Provider status checks source Cursor model
|
||||
* data from the SDK when an API key is configured, with ACP discovery as the
|
||||
* compatibility fallback.
|
||||
*/
|
||||
export const enrichCursorSnapshot = (input: {
|
||||
readonly settings: CursorSettings;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import {
|
||||
AuthenticationError,
|
||||
Cursor,
|
||||
CursorSdkError,
|
||||
type SDKModel,
|
||||
type SDKUser,
|
||||
} from "@cursor/sdk";
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Schema from "effect/Schema";
|
||||
|
||||
export interface CursorSdkCatalogSnapshot {
|
||||
readonly user: SDKUser;
|
||||
readonly models: ReadonlyArray<SDKModel>;
|
||||
}
|
||||
|
||||
export class CursorSdkCatalogError extends Schema.TaggedErrorClass<CursorSdkCatalogError>()(
|
||||
"CursorSdkCatalogError",
|
||||
{
|
||||
authenticationFailure: Schema.Boolean,
|
||||
cause: Schema.Defect(),
|
||||
},
|
||||
) {
|
||||
override get message(): string {
|
||||
return this.authenticationFailure
|
||||
? "Cursor SDK authentication failed."
|
||||
: "Cursor SDK catalog request failed.";
|
||||
}
|
||||
}
|
||||
|
||||
export interface CursorSdkCatalogShape {
|
||||
readonly read: (apiKey: string) => Effect.Effect<CursorSdkCatalogSnapshot, CursorSdkCatalogError>;
|
||||
}
|
||||
|
||||
export class CursorSdkCatalog extends Context.Service<CursorSdkCatalog, CursorSdkCatalogShape>()(
|
||||
"t3/provider/Layers/CursorSdkCatalog",
|
||||
) {}
|
||||
|
||||
function isAuthenticationFailure(cause: unknown): boolean {
|
||||
return (
|
||||
cause instanceof AuthenticationError ||
|
||||
(cause instanceof CursorSdkError && cause.status === 401)
|
||||
);
|
||||
}
|
||||
|
||||
const readCursorSdkCatalog = Effect.fn("CursorSdkCatalog.read")(function* (apiKey: string) {
|
||||
return yield* Effect.tryPromise({
|
||||
try: async () => {
|
||||
const [user, models] = await Promise.all([
|
||||
Cursor.me({ apiKey }),
|
||||
Cursor.models.list({ apiKey }),
|
||||
]);
|
||||
return { user, models } satisfies CursorSdkCatalogSnapshot;
|
||||
},
|
||||
catch: (cause) =>
|
||||
new CursorSdkCatalogError({
|
||||
authenticationFailure: isAuthenticationFailure(cause),
|
||||
cause,
|
||||
}),
|
||||
});
|
||||
});
|
||||
|
||||
export const CursorSdkCatalogLive = Layer.succeed(
|
||||
CursorSdkCatalog,
|
||||
CursorSdkCatalog.of({ read: readCursorSdkCatalog }),
|
||||
);
|
||||
|
||||
export function makeCursorSdkCatalogTestLayer(
|
||||
read: CursorSdkCatalogShape["read"],
|
||||
): Layer.Layer<CursorSdkCatalog> {
|
||||
return Layer.succeed(CursorSdkCatalog, CursorSdkCatalog.of({ read }));
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
const CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION: Readonly<Record<string, string>> = {
|
||||
context: "contextWindow",
|
||||
fast: "fastMode",
|
||||
};
|
||||
|
||||
const PROVIDER_OPTION_TO_CURSOR_SDK_PARAMETER: Readonly<Record<string, string>> = {
|
||||
contextWindow: "context",
|
||||
fastMode: "fast",
|
||||
};
|
||||
|
||||
export function cursorSdkProviderOptionId(parameterId: string): string {
|
||||
return CURSOR_SDK_PARAMETER_TO_PROVIDER_OPTION[parameterId] ?? parameterId;
|
||||
}
|
||||
|
||||
export function cursorSdkParameterId(providerOptionId: string): string {
|
||||
return PROVIDER_OPTION_TO_CURSOR_SDK_PARAMETER[providerOptionId] ?? providerOptionId;
|
||||
}
|
||||
|
||||
export function cursorSdkParameterPriority(parameterId: string): number {
|
||||
switch (parameterId) {
|
||||
case "effort":
|
||||
case "reasoning":
|
||||
return 0;
|
||||
case "context":
|
||||
return 1;
|
||||
case "fast":
|
||||
return 2;
|
||||
case "thinking":
|
||||
return 3;
|
||||
default:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user