Showing the changes to apps/server/src/git/Layers/CursorTextGeneration.ts (1 of 4 files). Show all
Unified · Split
| @@ -16,7 +16,12 @@ import { · 15 unmodified lines | ||
| 16 | 16 | buildPrContentPrompt, |
| 17 | 17 | buildThreadTitlePrompt, |
| 18 | 18 | } 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"; | |
| 20 | 25 | import { |
| 21 | 26 | applyCursorAcpModelSelection, |
| 22 | 27 | makeCursorAcpRuntime, |
| @@ -25,54 +30,6 @@ import { ServerSettingsService } from "../../serverSettings.ts"; · 2 unmodified lines | ||
| 25 | 30 | |
| 26 | 31 | const CURSOR_TIMEOUT_MS = 180_000; |
| 27 | 32 | |
| 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 | − | |
| 76 | 33 | function mapCursorAcpError( |
| 77 | 34 | operation: |
| 78 | 35 | | "generateCommitMessage" |