Skip to content

Commit 9eee645

Browse files
saphidclaude
andcommitted
fix(cursor): Cursor text generation names usage-limit failures
Map the Cursor SDK RunError code to fixed detail text instead of copying the raw SDK message, and keep the RunError as the cause. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4193fc3 commit 9eee645

2 files changed

Lines changed: 25 additions & 14 deletions

File tree

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,28 @@ describe("CursorTextGeneration", () => {
194194
}).pipe(Effect.provide(layerTest)),
195195
);
196196

197-
it.effect.each(["error", "cancelled"] as const)(
198-
"rejects a %s Cursor SDK run that includes valid title JSON",
199-
(status) =>
197+
it.effect.each([
198+
{
199+
status: "error",
200+
error: { message: "Raw Cursor usage text", code: "PRO_USER_USAGE_LIMIT" },
201+
detail:
202+
"Cursor usage limit reached. Try again later or choose another text-generation provider.",
203+
},
204+
{
205+
status: "error",
206+
error: { message: "Raw Cursor backend text", code: "internal" },
207+
detail: "Cursor SDK request finished with an error.",
208+
},
209+
{ status: "cancelled", error: undefined, detail: "Cursor SDK request was cancelled." },
210+
] as const)(
211+
"rejects a $status Cursor SDK run ($error.code) that includes valid title JSON",
212+
({ status, error, detail }) =>
200213
Effect.gen(function* () {
201214
const promptResult = {
202215
id: "run-cursor-partial-title-test",
203216
status,
204217
result: '{"title":"Partial title from a failed run."}',
205-
...(status === "error" ? { error: { message: "Usage limit reached." } } : {}),
218+
...(error ? { error } : {}),
206219
} satisfies RunResult;
207220
cursorSdkMock.prompt.mockResolvedValueOnce(promptResult);
208221
const generation = yield* makeCursorTextGeneration(cursorSettings, {
@@ -220,11 +233,9 @@ describe("CursorTextGeneration", () => {
220233
);
221234
expect(failure).toBeInstanceOf(TextGenerationError);
222235
expect(failure.operation).toBe("generateThreadTitle");
223-
expect(failure.detail).toBe(
224-
status === "cancelled"
225-
? "Cursor SDK request was cancelled."
226-
: "Cursor SDK request finished with an error: Usage limit reached.",
227-
);
236+
expect(failure.detail).toBe(detail);
237+
expect(failure.message).not.toContain("Raw Cursor");
238+
expect(failure.cause).toBe(error);
228239
expect(cursorSdkMock.close).toHaveBeenCalledOnce();
229240
}).pipe(Effect.provide(layerTest)),
230241
);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { CursorSettings } from "../settings.ts";
1111
import * as TextGenerationOperations from "@t3tools/provider-core/server/textGenerationOperations";
1212
import { cursorSdkModelSelection } from "./sdkModel.ts";
1313
import type { CursorAuth } from "./auth.ts";
14+
import * as CursorAgentSdk from "./CursorAgentSdk.ts";
1415
import * as CursorSdk from "./CursorSdk.ts";
1516
import * as HostProcess from "@t3tools/shared/HostProcess";
1617

@@ -22,12 +23,10 @@ function cursorSdkResultDetail(result: RunResult): string {
2223
switch (result.status) {
2324
case "cancelled":
2425
return "Cursor SDK request was cancelled.";
25-
case "error": {
26-
const message = result.error?.message.trim();
27-
return message
28-
? `Cursor SDK request finished with an error: ${message}`
26+
case "error":
27+
return CursorAgentSdk.isCursorUsageLimitError(result.error)
28+
? "Cursor usage limit reached. Try again later or choose another text-generation provider."
2929
: "Cursor SDK request finished with an error.";
30-
}
3130
case "finished":
3231
return "Cursor SDK returned empty output.";
3332
}
@@ -186,6 +185,7 @@ export const makeCursorTextGeneration = Effect.fn("makeCursorTextGeneration")(fu
186185
return yield* new TextGenerationError({
187186
operation,
188187
detail: cursorSdkResultDetail(promptResult),
188+
...(promptResult.error ? { cause: promptResult.error } : {}),
189189
});
190190
}
191191

0 commit comments

Comments
 (0)