/** * Tolerant parsers for raw model output: unwrap code fences, extract every * top-level `{...}` object from noisy text, repair invalid JSON string escapes, * and strip leaked tool-call markup / punctuation-only replies. Used wherever * the runtime must salvage structure from a weak model's not-quite-valid JSON. */ export declare function parseJsonObject(raw: string): T | null; /** * Extract every top-level `{...}` JSON object substring from `raw`, in order. * Brace-depth scan that respects string literals and escapes, so braces inside * string values never confuse the boundaries. Weak models routinely narrate * multiple intents as concatenated objects (`{...}\n{...}`) rather than one * array — callers that took only the first silently dropped the rest. */ export declare function extractJsonObjects(raw: string): string[]; /** * Spans of the outermost complete `{...}` objects embedded in prose, in order. * Unlike {@link extractJsonObjects}, text before a `{` never changes how that * object is read: a `"` outside every object is prose (`5" wide`), and a `{` * that never closes (`{ 5"`) is dropped instead of hiding the objects after it. * Linear: the end of each `{` and of each string is resolved once and reused. */ export declare function extractJsonObjectSpans(raw: string): Array<{ start: number; end: number; }>; export declare function stringifyForModel(value: unknown): string; /** Serialize diagnostic context without allowing hostile or cyclic values to mask the original event. */ export declare function stringifyForDiagnostics(value: unknown): string; /** * Detects tool-call-shaped markup a model emitted as reply text instead of a * structured call: the native `` serialization or an invented * `` pseudo-tag. Text matching this is a tool INTENT, never a * user-facing answer — deliverers must either recover and dispatch the call * or decline the text entirely; stripping the markup and shipping the * surviving prose fabricates an effect claim ("saving note." with no note). */ export declare function containsToolCallShapedMarkup(text: string): boolean; /** * Recover the tool invocations a weak model serialized as * `{json args}` pseudo-tags (live: * `{"title":…}` beside "saving note." prose, * tj-9129a432454364 stage 7 — stripped and never executed). Deliberately * conservative: only `_`-bearing tag names with a parseable JSON-object body * qualify, so an all-caps tag quoted in prose or wrapping non-JSON text never * fabricates a call. */ export declare function parsePseudoTagToolInvocations(text: string | undefined): Array<{ name: string; params: Record; }>; /** * Clean a model-produced reply field before it reaches the user. Removes * structural junk that weak models emit as plain text but which is never * user-facing content: * 1. the model's NATIVE tool-call serialization emitted as text instead of a * structured call, e.g. * `WEB_FETCHurl...` * (observed on cerebras gpt-oss / zai; eliza routes real tool calls * structurally, and this markup never appears in eliza's own format), and * 2. a reply that is ONLY JSON punctuation (braces/brackets/quotes/commas). * * Structural artifact removal - the sibling of the existing `[tool output:]` * markup stripping - not semantic-content matching. The truncated-open branch is * deliberately conservative: it only swallows to end-of-string when the markup is * unmistakably a serialized call (an uppercase ACTION token or the native * ``/`` markup follows), so a reply that merely *mentions* * `` in prose is preserved. */ export declare function stripJsonStructuralJunkReply(value: string): string;