mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(walkthrough): plan-then-explain generation with selectable diff sources
This commit is contained in:
1 parent
aeea96b466
commit
88b3543dc1
35 files changed
+2583
-609
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user