/** * Balanced-bracket JSON extraction from LLM output. * * Handles prose-wrapped and code-fenced JSON (```json ... ```). * Shared utility imported by both pi-ai-runtime-adapter.ts and * structured-output-repair.ts — kept in adapter/ to avoid a new * top-level directory for one small function. */ /** * Extract JSON object from text (handles prose-wrapped and code-fenced JSON). * Returns the parsed object, or null if no valid JSON found. */ export declare function extractJsonObject(text: string): Record | null; /** * Collect every top-level balanced JSON object in the text (fenced content * first, then all brace-scanned candidates in order). PRI-621 RC3: a single * free-form LLM answer can contain several complete objects — e.g. an * outer truncated answer plus an inner lineage fragment that happens to * parse. First-object extraction kept validating the wrong fragment. */ export declare function extractJsonObjects(text: string): Record[]; /** * Pick the candidate most likely to be the intended structured output, * scored by how many of the schema's required top-level keys it carries. * PRI-621 RC3: lineage fragments like {"scribeArtifactId":...} score 0 * against a schema requiring taskId/implementationCode/etc., so the real * (later, larger) object wins even when a smaller fragment appears first. * Ties break toward more own keys, then larger serialized size. Without * requiredKeys (or when nothing scores), behavior degrades to the first * candidate — identical to legacy extractJsonObject semantics. */ export declare function selectBestJsonObject(candidates: readonly Record[], requiredKeys?: readonly string[]): Record | null; /** * Schema-aware extraction (PRI-621 RC3): collect all object candidates and * return the one that best matches the schema's required top-level keys. * Falls back to legacy first-object behavior when no keys are known. */ export declare function extractJsonObjectForSchema(text: string, requiredKeys?: readonly string[]): Record | null; /** * Attempt syntactic repair of malformed JSON where string values contain * unescaped double quotes (a common LLM output error). * * Strategy: find the outermost `{...}` via balanced-bracket scan, then * try to fix unescaped quotes by escaping inner double-quote characters * that appear between key-value separators (`: `) and field separators (`,`). * * This is a BEST-EFFORT heuristic — it handles the most common LLM mistake * (unescaped quotes in string values) but is not a general JSON repair. * Returns the parsed object, or null if repair fails. */ export declare function repairMalformedJson(text: string): Record | null; //# sourceMappingURL=json-extractor.d.ts.map