TypeScript
fix(provider-cursor): say when Cursor rejects a free-plan account (#19771)
Ali Younes8046e1d8cdaa
diff --git a/docs/user/cursor.md b/docs/user/cursor.mdindex ad1a69ef956..5fc20811da6 100644--- a/docs/user/cursor.md+++ b/docs/user/cursor.md@@ -8,6 +8,7 @@ TypeScript package. It does not use Cursor's ACP transport for V2 execution.- Node.js 22.13 or newer. The repository's supported Node version satisfies this requirement.- Sign in with Cursor in **Settings > Providers > Cursor**, or provide a Cursor API key in`CURSOR_API_KEY`.+- A paid Cursor plan on the account used for browser sign-in or `CURSOR_API_KEY`.- A model accepted by the Cursor SDK. `auto` is sent to the SDK as its `default` model selection.The adapter currently uses the SDK's local-agent runtime so runs operate in the selected T3 Codediff --git a/packages/provider-cursor/src/server/CursorSdkCatalog.ts b/packages/provider-cursor/src/server/CursorSdkCatalog.tsindex 7f317cc0978..fae053fe535 100644--- a/packages/provider-cursor/src/server/CursorSdkCatalog.ts+++ b/packages/provider-cursor/src/server/CursorSdkCatalog.ts@@ -26,6 +26,10 @@ export class CursorSdkCatalogError extends Schema.TaggedError<CursorSdkCatalogEr? "Cursor SDK authentication failed.": "Cursor SDK catalog request failed.";}++ get planRequired(): boolean {+ return this.cause instanceof CursorSdkError && this.cause.code === "plan_required";+ }}export class CursorSdkCatalog extends Context.Service<diff --git a/packages/provider-cursor/src/server/auth.test.ts b/packages/provider-cursor/src/server/auth.test.tsindex 3d31211ac5a..8219f1aa202 100644--- a/packages/provider-cursor/src/server/auth.test.ts+++ b/packages/provider-cursor/src/server/auth.test.ts@@ -234,6 +234,8 @@ it.layer(NodeServices.layer)("CursorAuth", (it) => {it.effect("discards a credential rejected by verification and permits a fresh login", () =>Effect.gen(function* () {+ const rejectionMessage =+ "Cursor needs a paid plan to run in T3 Code. Upgrade this account or sign in with a different one.";let rejected = true;const harness = yield* makeHarness({onChanged: (signedIn) =>@@ -242,7 +244,7 @@ it.layer(NodeServices.layer)("CursorAuth", (it) => {new ProviderSetupError({instanceId,operation: "start",- detail: "Could not verify the Cursor sign-in.",+ detail: rejectionMessage,}),): Effect.void,@@ -250,7 +252,8 @@ it.layer(NodeServices.layer)("CursorAuth", (it) => {yield* harness.auth.controller.start(owner);yield* phase(harness.auth, "waiting");yield* Effect.sync(() => harness.complete.resolve());- yield* phase(harness.auth, "failed");+ const failed = yield* phase(harness.auth, "failed");+ expect(failed.message).toBe(rejectionMessage);expect(yield* Effect.promise(() => harness.store.load())).toBeUndefined();expect(yield* harness.auth.readApiKey).toBeUndefined();expect(Exit.isFailure(yield* Effect.exit(harness.auth.requireApiKey))).toBe(true);diff --git a/packages/provider-cursor/src/server/auth.ts b/packages/provider-cursor/src/server/auth.tsindex 2122731a9d7..6b7d43fd38c 100644--- a/packages/provider-cursor/src/server/auth.ts+++ b/packages/provider-cursor/src/server/auth.ts@@ -4,12 +4,14 @@ import {type ProviderAuthState,type ProviderInstanceId,} from "@t3tools/contracts";+import * as Cause from "effect/Cause";import * as Clock from "effect/Clock";import * as Crypto from "effect/Crypto";import * as DateTime from "effect/DateTime";import * as Effect from "effect/Effect";import * as Exit from "effect/Exit";import * as Fiber from "effect/Fiber";+import * as Option from "effect/Option";import * as Queue from "effect/Queue";import * as Scope from "effect/Scope";import * as Semaphore from "effect/Semaphore";@@ -271,7 +273,10 @@ export const makeCursorAuth = Effect.fn("makeCursorAuth")(function* (options: CuexpiresAt: null,message: Exit.isSuccess(result)? "Signed in with Cursor."- : "Cursor sign-in failed or expired. Start sign-in again.",+ : Option.match(Cause.findErrorOption(result.cause), {+ onNone: () => "Cursor sign-in failed or expired. Start sign-in again.",+ onSome: (error) => error.detail,+ }),});}),),diff --git a/packages/provider-cursor/src/server/status.test.ts b/packages/provider-cursor/src/server/status.test.tsindex 32eedf9e3a9..1aed62d5354 100644--- a/packages/provider-cursor/src/server/status.test.ts+++ b/packages/provider-cursor/src/server/status.test.ts@@ -14,6 +14,7 @@ import {checkCursorProviderStatus,} from "./status.ts";import * as CursorSdkCatalog from "./CursorSdkCatalog.ts";+import { CursorSdkError } from "./sdk.ts";const decodeCursorSettings = Schema.decodeSync(CursorSettingsSchema);@@ -231,6 +232,49 @@ describe("checkCursorProviderStatus", () => {}),);+ it.effect.each([+ {+ authenticationType: "browser" as const,+ message:+ "Cursor needs a paid plan to run in T3 Code. Upgrade this account or sign in with a different one.",+ },+ {+ authenticationType: "api-key" as const,+ message:+ "Cursor needs a paid plan to run in T3 Code. Upgrade the account that owns CURSOR_API_KEY or use a key from a paid account.",+ },+ ])(+ "explains a rejected plan for $authenticationType authentication",+ ({ authenticationType, message }) =>+ Effect.gen(function* () {+ const provider = yield* checkCursorProviderStatus(+ baseCursorSettings,+ { CURSOR_API_KEY: "free-plan-key" },+ authenticationType,+ ).pipe(+ Effect.provide(+ CursorSdkCatalog.layerTest(() =>+ Effect.fail(+ new CursorSdkCatalog.CursorSdkCatalogError({+ authenticationFailure: false,+ cause: new CursorSdkError(+ "[plan_required] Cloud Agent is not available for free users. Please upgrade to Pro.",+ { code: "plan_required", status: 403 },+ ),+ }),+ ),+ ),+ ),+ );++ expect(provider).toMatchObject({+ status: "error",+ auth: { status: "unknown" },+ message,+ });+ }),+ );+it.effect("requires a Cursor API key without probing any external Cursor binary", () =>Effect.gen(function* () {const provider = yield* checkCursorProviderStatus(baseCursorSettings).pipe(diff --git a/packages/provider-cursor/src/server/status.ts b/packages/provider-cursor/src/server/status.tsindex 2c21a01459b..9722ddbcfd2 100644--- a/packages/provider-cursor/src/server/status.ts+++ b/packages/provider-cursor/src/server/status.ts@@ -294,7 +294,19 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(yield* Effect.logWarning("Cursor SDK catalog probe failed", {cause: catalogResult.failure.cause,});- const authenticationFailure = catalogResult.failure.authenticationFailure;+ const failure = catalogResult.failure;+ let message = "Cursor SDK catalog request failed. Check server logs for details.";+ if (failure.authenticationFailure) {+ message =+ authenticationType === "browser"+ ? "Cursor sign-in expired or was rejected. Sign in again in provider settings."+ : "Cursor SDK authentication failed. Check CURSOR_API_KEY.";+ } else if (failure.planRequired) {+ message =+ authenticationType === "browser"+ ? "Cursor needs a paid plan to run in T3 Code. Upgrade this account or sign in with a different one."+ : "Cursor needs a paid plan to run in T3 Code. Upgrade the account that owns CURSOR_API_KEY or use a key from a paid account.";+ }return buildServerProvider({presentation: CURSOR_PRESENTATION,enabled: cursorSettings.enabled,@@ -304,12 +316,8 @@ export const checkCursorProviderStatus = Effect.fn("checkCursorProviderStatus")(installed: true,version: null,status: "error",- auth: { status: authenticationFailure ? "unauthenticated" : "unknown" },- message: authenticationFailure- ? authenticationType === "browser"- ? "Cursor sign-in expired or was rejected. Sign in again in provider settings."- : "Cursor SDK authentication failed. Check CURSOR_API_KEY."- : "Cursor SDK catalog request failed. Check server logs for details.",+ auth: { status: failure.authenticationFailure ? "unauthenticated" : "unknown" },+ message,},});}