/**
* Runtime-agnostic reasoning/thinking text parsers for text-only LLM batteries.
*
* @remarks
* **Why this exists.** Text-only on-device runtimes (transformers.js, LiteRT-LM v0.13.1) emit a
* reasoning model's chain-of-thought as **raw text inside the assistant message**, delimited in a
* format specific to the model family — not as a structured `reasoning` field the way OpenAI-style
* providers do (those are handled by `extractReasoningFields`). To surface that thinking as ADK
* {@link @nhtio/adk!Thought}s rather than leaking `…` markup into the visible answer,
* the battery must parse it out of the text.
*
* Same shape as the tool-call parser layer: one parser per family, anchored on a literal marker, run
* post-hoc. The bundled defaults cover the dominant conventions; `'auto'` tries them in order and a
* custom {@link ReasoningParserFn} is the escape hatch.
*
* NOT `@module`-tagged: private to the bundled LLM batteries, re-exported through their public
* surfaces.
*/
/**
* The result of running a {@link ReasoningParserFn} over assistant text.
*
* @remarks
* `reasoning` holds each extracted thinking trace in document order; `cleanedText` is the prose with
* every consumed reasoning span removed and trimmed. On no-match a parser MUST return
* `{ reasoning: [], cleanedText: rawText }` verbatim.
*/
export interface ReasoningParseResult {
/** Each extracted thinking trace, in document order. Empty when no reasoning was found. */
reasoning: string[];
/** The prose with every consumed reasoning span removed; equals the input on no-match. */
cleanedText: string;
}
/** A synchronous reasoning text parser. */
export type ReasoningParserFn = (rawText: string) => ReasoningParseResult;
/** The bundled reasoning parser names, plus `'auto'` (try-all) and `'none'` (disable). */
export type ReasoningParserName = 'auto' | 'think_tag' | 'harmony_analysis' | 'gemma_channel' | 'none';
/**
* Options shared by the bundled reasoning parsers.
*
* @remarks
* `orphanRecovery` (default `true`) controls whether an **unpaired** reasoning marker is recovered by
* inferring the missing half from the pseudo-streaming order, rather than being left to leak into the
* visible answer. A real-world gemma-4-E4B WebGPU quant "randomly emits ``" with no matching
* open; because generation is start→end, a lone close implies the block opened at the previous close
* (or start-of-output), and a lone open with no close implies reasoning ran to end-of-stream. Turn this
* off for strict pair-only behaviour (markers without a matching partner are left verbatim).
*/
export interface ReasoningParserOptions {
/** Recover unpaired markers by inferring the missing half (default `true`). */
orphanRecovery?: boolean;
}
/**
* Parse `…` (and the `…` variant) reasoning blocks — the dominant
* convention, used by Qwen3, DeepSeek-R1, and most distilled reasoning models. Unpaired markers (a lone
* `` or a truncated ``) are recovered by default — see {@link ReasoningParserOptions}.
*/
export declare const makeThinkTagReasoningParser: (opts?: ReasoningParserOptions) => ReasoningParserFn;
/** Default {@link makeThinkTagReasoningParser} (orphan recovery on). */
export declare const thinkTagReasoningParser: ReasoningParserFn;
/** Default {@link thinkTagReasoningParser}. */
export declare const defaultThinkTagReasoningParser: ReasoningParserFn;
/**
* Parse gpt-oss Harmony chain-of-thought on the `analysis` channel:
* `<|channel|>analysis<|message|>…<|end|>`. (The user-visible answer is the separate `final` channel;
* tool calls are `commentary` — handled by the tool-call parser.) Unpaired markers are recovered by
* default — see {@link ReasoningParserOptions}.
*/
export declare const makeHarmonyAnalysisReasoningParser: (opts?: ReasoningParserOptions) => ReasoningParserFn;
/** Default {@link makeHarmonyAnalysisReasoningParser} (orphan recovery on). */
export declare const harmonyAnalysisReasoningParser: ReasoningParserFn;
/** Default {@link harmonyAnalysisReasoningParser}. */
export declare const defaultHarmonyAnalysisReasoningParser: ReasoningParserFn;
/**
* Parse Gemma E2B/E4B reasoning emitted on the thought channel:
* `<|channel>thought\n…`. Targets the E2B/E4B delimited form (the transformers.js-runnable
* one). Reasoning is only emitted when `<|think|>` is injected into the system prompt. Unpaired markers
* are recovered by default — see {@link ReasoningParserOptions}.
*/
export declare const makeGemmaChannelReasoningParser: (opts?: ReasoningParserOptions) => ReasoningParserFn;
/** Default {@link makeGemmaChannelReasoningParser} (orphan recovery on). */
export declare const gemmaChannelReasoningParser: ReasoningParserFn;
/** Default {@link gemmaChannelReasoningParser}. */
export declare const defaultGemmaChannelReasoningParser: ReasoningParserFn;
/** A parser that never extracts anything — disables reasoning parsing entirely. */
export declare const noneReasoningParser: ReasoningParserFn;
/** Default {@link noneReasoningParser}. */
export declare const defaultNoneReasoningParser: ReasoningParserFn;
/** The bundled reasoning parsers keyed by name (excluding `'auto'`/`'none'`), orphan recovery ON. */
export declare const BUNDLED_REASONING_PARSERS: Readonly, ReasoningParserFn>>;
/** Build the bundled family parsers honouring {@link ReasoningParserOptions} (e.g. orphan recovery). */
export declare const buildBundledReasoningParsers: (opts?: ReasoningParserOptions) => Record, ReasoningParserFn>;
/** The default `'auto'` precedence. All three are literal-marker-anchored, so order is collision-free. */
export declare const DEFAULT_REASONING_PARSER_ORDER: ReadonlyArray>;
/**
* Compose an `'auto'` reasoning parser: run each parser in `order` until one returns a non-empty
* `reasoning` array; that result wins. Returns no-match if none claim the text.
*/
export declare const createAutoReasoningParser: (parsers?: Partial, ReasoningParserFn>>, order?: ReadonlyArray>) => ReasoningParserFn;
/** Default {@link createAutoReasoningParser}. */
export declare const defaultCreateAutoReasoningParser: (parsers?: Partial, ReasoningParserFn>>, order?: ReadonlyArray>) => ReasoningParserFn;
/**
* Resolve a `reasoningParser` option (a name, `'auto'`, `'none'`, or a custom fn) to a concrete
* {@link ReasoningParserFn}.
*
* @param option - The option value. Defaults to `'auto'` when undefined.
* @param parsers - Override the bundled parsers. Ignored when `opts.orphanRecovery` is set (the bundled
* family parsers are rebuilt with that setting); pass a custom `option` fn for full control.
* @param opts - {@link ReasoningParserOptions}; `orphanRecovery` defaults to `true`. When `false`, the
* named/auto bundled parsers are rebuilt in strict pair-only mode.
*/
export declare const resolveReasoningParser: (option: ReasoningParserName | ReasoningParserFn | undefined, parsers?: Partial, ReasoningParserFn>>, opts?: ReasoningParserOptions) => ReasoningParserFn;
/** Default {@link resolveReasoningParser}. */
export declare const defaultResolveReasoningParser: (option: ReasoningParserName | ReasoningParserFn | undefined, parsers?: Partial, ReasoningParserFn>>, opts?: ReasoningParserOptions) => ReasoningParserFn;