History

fix(server): handle OpenCode text response format in commit message g… (#2202)

Abdul Azeez committed 6 months ago

Commit 37965da1 parent 57b59b54 files · +184 −68Browse files

Showing the changes to apps/server/src/git/Layers/CursorTextGeneration.ts (1 of 4 files). Show all

Unified · Split

apps/server/src/git/Layers/CursorTextGeneration.ts+6−49
@@ -16,7 +16,12 @@ import { · 15 unmodified lines
1616 buildPrContentPrompt,
1717 buildThreadTitlePrompt,
1818 } from "../Prompts.ts";
19−import { sanitizeCommitSubject, sanitizePrTitle, sanitizeThreadTitle } from "../Utils.ts";
19+import {
20+ extractJsonObject,
21+ sanitizeCommitSubject,
22+ sanitizePrTitle,
23+ sanitizeThreadTitle,
24+} from "../Utils.ts";
2025 import {
2126 applyCursorAcpModelSelection,
2227 makeCursorAcpRuntime,
@@ -25,54 +30,6 @@ import { ServerSettingsService } from "../../serverSettings.ts"; · 2 unmodified lines
2530
2631 const CURSOR_TIMEOUT_MS = 180_000;
2732
28−function extractJsonObject(raw: string): string {
29− const trimmed = raw.trim();
30− if (trimmed.length === 0) {
31− return trimmed;
32− }
33−
34− const start = trimmed.indexOf("{");
35− if (start < 0) {
36− return trimmed;
37− }
38−
39− let depth = 0;
40− let inString = false;
41− let escaping = false;
42− for (let index = start; index < trimmed.length; index += 1) {
43− const char = trimmed[index];
44− if (inString) {
45− if (escaping) {
46− escaping = false;
47− } else if (char === "\\") {
48− escaping = true;
49− } else if (char === '"') {
50− inString = false;
51− }
52− continue;
53− }
54−
55− if (char === '"') {
56− inString = true;
57− continue;
58− }
59−
60− if (char === "{") {
61− depth += 1;
62− continue;
63− }
64−
65− if (char === "}") {
66− depth -= 1;
67− if (depth === 0) {
68− return trimmed.slice(start, index + 1);
69− }
70− }
71− }
72−
73− return trimmed.slice(start);
74−}
75−
7633 function mapCursorAcpError(
7734 operation:
7835 | "generateCommitMessage"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t