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
16 buildPrContentPrompt,16 buildPrContentPrompt,
17 buildThreadTitlePrompt,17 buildThreadTitlePrompt,
18} from "../Prompts.ts";18} from "../Prompts.ts";
19import { sanitizeCommitSubject, sanitizePrTitle, sanitizeThreadTitle } from "../Utils.ts";19import {
20 extractJsonObject,
21 sanitizeCommitSubject,
22 sanitizePrTitle,
23 sanitizeThreadTitle,
24} from "../Utils.ts";
20import {25import {
21 applyCursorAcpModelSelection,26 applyCursorAcpModelSelection,
22 makeCursorAcpRuntime,27 makeCursorAcpRuntime,
@@ -25,54 +30,6 @@ import { ServerSettingsService } from "../../serverSettings.ts"; · 2 unmodified lines
25 30
26const CURSOR_TIMEOUT_MS = 180_000;31const CURSOR_TIMEOUT_MS = 180_000;
27 32
28function 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
76function mapCursorAcpError(33function mapCursorAcpError(
77 operation:34 operation:
78 | "generateCommitMessage"35 | "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