feat(walkthrough): plan-then-explain generation with selectable diff sources

This commit is contained in:
Chris Scott committed 2026-10-08 15:53:49 -04:00
1 parent aeea96b466
commit 88b3543dc1
35 files changed
+2583 -609

No files matched your search

+23
View File
@@ -1,3 +1,5 @@
import type { ZodType } from 'zod'
export function extractFirstJsonObject(text: string): string | null {
const start = text.indexOf('{')
if (start === -1) {
@@ -39,3 +41,24 @@ export function extractFirstJsonObject(text: string): string | null {
return null
}
export function parseFirstJsonObject<T>(text: string, schema: ZodType<T>): T | null {
const extracted = extractFirstJsonObject(text)
if (!extracted) {
return null
}
let raw: unknown
try {
raw = JSON.parse(extracted)
} catch {
return null
}
const parsed = schema.safeParse(raw)
if (!parsed.success) {
return null
}
return parsed.data
}