Skip to content
TypeScript

fix(cursor): Cursor text generation names usage-limit failures (#29748)

Alex Southwell47057a3cac9d
diff --git a/packages/provider-cursor/src/server/textGeneration.test.ts b/packages/provider-cursor/src/server/textGeneration.test.ts
index 1085a956417..bfb02df390d 100644
--- a/packages/provider-cursor/src/server/textGeneration.test.ts
+++ b/packages/provider-cursor/src/server/textGeneration.test.ts
@@ -194,14 +194,28 @@ describe("CursorTextGeneration", () => {
}).pipe(Effect.provide(layerTest)),
);
- it.effect.each(["error", "cancelled"] as const)(
- "rejects a %s Cursor SDK run that includes valid title JSON",
- (status) =>
+ it.effect.each([
+ {
+ status: "error",
+ error: { message: "Raw Cursor usage text", code: "PRO_USER_USAGE_LIMIT" },
+ detail:
+ "Cursor usage limit reached. Try again later or choose another text-generation provider.",
+ },
+ {
+ status: "error",
+ error: { message: "Raw Cursor backend text", code: "internal" },
+ detail: "Cursor SDK request finished with an error.",
+ },
+ { status: "cancelled", error: undefined, detail: "Cursor SDK request was cancelled." },
+ ] as const)(
+ "rejects a $status Cursor SDK run ($error.code) that includes valid title JSON",
+ ({ status, error, detail }) =>
Effect.gen(function* () {
const promptResult = {
id: "run-cursor-partial-title-test",
status,
result: '{"title":"Partial title from a failed run."}',
+ ...(error ? { error } : {}),
} satisfies RunResult;
cursorSdkMock.prompt.mockResolvedValueOnce(promptResult);
const generation = yield* makeCursorTextGeneration(cursorSettings, {
@@ -219,11 +233,9 @@ describe("CursorTextGeneration", () => {
);
expect(failure).toBeInstanceOf(TextGenerationError);
expect(failure.operation).toBe("generateThreadTitle");
- expect(failure.detail).toBe(
- status === "cancelled"
- ? "Cursor SDK request was cancelled."
- : "Cursor SDK request finished with an error.",
- );
+ expect(failure.detail).toBe(detail);
+ expect(failure.message).not.toContain("Raw Cursor");
+ expect(failure.cause).toBe(error);
expect(cursorSdkMock.close).toHaveBeenCalledOnce();
}).pipe(Effect.provide(layerTest)),
);
diff --git a/packages/provider-cursor/src/server/textGeneration.ts b/packages/provider-cursor/src/server/textGeneration.ts
index fc62b779c49..fa8228d0ba0 100644
--- a/packages/provider-cursor/src/server/textGeneration.ts
+++ b/packages/provider-cursor/src/server/textGeneration.ts
@@ -11,6 +11,7 @@ import type { CursorSettings } from "../settings.ts";
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
import { cursorSdkModelSelection } from "./sdkModel.ts";
import type { CursorAuth } from "./auth.ts";
+import * as CursorAgentSdk from "./CursorAgentSdk.ts";
import * as CursorSdk from "./CursorSdk.ts";
import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -23,7 +24,9 @@ function cursorSdkResultDetail(result: RunResult): string {
case "cancelled":
return "Cursor SDK request was cancelled.";
case "error":
- return "Cursor SDK request finished with an error.";
+ return CursorAgentSdk.isCursorUsageLimitError(result.error)
+ ? "Cursor usage limit reached. Try again later or choose another text-generation provider."
+ : "Cursor SDK request finished with an error.";
case "finished":
return "Cursor SDK returned empty output.";
}
@@ -182,6 +185,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
return yield* new TextGenerationError({
operation,
detail: cursorSdkResultDetail(promptResult),
+ ...(promptResult.error ? { cause: promptResult.error } : {}),
});
}