import * as smoltalk from "smoltalk"; import type { PromptResult, ToolCallJSON } from "smoltalk"; import { type LogLevel, type LogSink } from "../logger.js"; import { GlobalStore } from "./state/globalStore.js"; import { ThreadStore } from "./index.js"; import { RunNodeCoreResult } from "./types.js"; import { ResultValue } from "./result.js"; export declare function deepClone(obj: T): T; /** Keep a value only when it round-trips through the given schema. The reply * message's usage, cost, thinking, and logprobs are validated by smoltalk's fromJSON * on restore (checkpoint resume, rewind, subthread clone), which throws on a * bad shape, so a value that would not pass is dropped here instead — the * same as before the reply carried these fields. Pass smoltalk's own schema * for the field, so a value this accepts is one fromJSON accepts. `onInvalid` * is called with the parse error when a value is dropped, so the caller can * say which client returned a shape it could not keep. */ export declare function serializableExtra(value: T | undefined, schema: { safeParse(input: unknown): { success: boolean; error?: unknown; }; }, onInvalid?: (error: unknown) => void): T | undefined; /** The assistant message `runPrompt` appends for a completion. Everything the * completion carried beyond its text rides on it, where `lastReply()` in * std::thread reads it back: thinking, usage, cost, and a provider's extras * such as a decision model's answers. Each of thinking, logprobs, usage, and * cost goes through {@link serializableExtra} so a shape that would not survive smoltalk's * fromJSON on restore is dropped rather than left to break a checkpoint. An * unset `toolCalls` serializes exactly as an omitted one. */ export declare function buildReplyMessage(completion: PromptResult, toolCalls: ToolCallJSON[], logLevel: LogLevel, sink: LogSink): smoltalk.AssistantMessage; export declare function deepFreeze(obj: T, seen?: WeakSet): T; /** Strict structured-output extraction: unwrap the provider's response * shape and validate against the schema. Returns success(value) with the * validated value, or failure(schemaError) — never the raw content. The * unwrap heuristics mirror the shapes providers actually return: the * { response: ... } wrapper for primitive schemas, single-key wrappers, * stringified JSON, and single-element arrays. */ export declare function extractStructuredResponse(rawValue: any, schema: any): ResultValue; export declare function extractResponse(rawValue: any, schema: any): any; export declare function createReturnObject({ result, globals, }: { result: { data: T; messages?: ThreadStore; }; globals: GlobalStore; }): RunNodeCoreResult; export type ModelUsage = { model: string; inputTokens: number; outputTokens: number; /** Tokens read back from an existing cache entry. */ cachedInputTokens: number; /** Tokens written to a new cache entry. */ cacheCreationInputTokens: number; cost: number; }; /** * Normalize the raw `__tokenStats.models` map into a typed, defensively * narrowed array sorted by cost descending (model name as the tiebreak). * Single source of truth for reading the per-model breakdown — shared by * std::thread's `getModelCosts` and the REPL footer's token snapshot so * the field narrowing and ordering live in one place. */ export declare function normalizeModelUsage(rawModels: unknown): ModelUsage[]; /** The token-usage fields `updateTokenStats` reads (all optional — providers * vary, and a free/local model has no cost). */ type StatUsage = { inputTokens?: number; outputTokens?: number; cachedInputTokens?: number; cacheCreationInputTokens?: number; totalTokens?: number; }; type StatCost = { inputCost?: number; outputCost?: number; cachedInputCost?: number; cacheCreationInputCost?: number; totalCost?: number; }; export declare function updateTokenStats(args: { globals: GlobalStore; usage: StatUsage | null | undefined; cost?: StatCost | null; model?: string; }): void; export {};