import type { ResolvedOpenAICompat } from "@oh-my-pi-zen/pi-catalog/types"; import type { Api, AssistantMessage, Message, Model } from "../types.js"; /** * Maximum tool-call id length the strictest replay provider accepts. * * Anthropic requires `^[a-zA-Z0-9_-]+$` with a 64-char cap; Google and Codex * `normalizeToolCallId` implementations cap individual id segments to the same * 64-char ceiling. Replacement ids minted here flow back through * `convertAnthropicMessages` (and friends) unchanged, so the `_dupN` suffix * MUST not push a normalized id past this bound. */ export declare const MAX_TOOL_CALL_ID_LENGTH = 64; /** Replace unsupported tool-call ID characters and cap the result for strict replay providers. */ export declare function normalizeToolCallId(id: string, maxLength?: number): string; /** Whether `id` already satisfies the strict 1–64 `[a-zA-Z0-9_-]` tool-call ID contract. */ export declare function isValidToolCallId(id: string): boolean; /** * OpenAI Responses-family APIs mint composite tool ids (`call_id|item_id`); * opaque Chat Completions ids do not (openai-completions preserves same-model * ids verbatim as provider correlation tokens), so ONLY these origins may be * canonicalized to their `call_` component for pairing. */ export declare function isResponsesFamilyApi(api: Api | undefined): boolean; /** * The wire `call_id` component of a (possibly composite) Responses id: the * FIRST segment before `|`. A degenerate `|itemId` (empty call half, pipe at * index 0) keeps its full id so unrelated empty-half ids never collapse onto * one empty-string bucket. */ export declare function responsesCallComponent(id: string): string; export declare function appendDuplicateSuffix(originalId: string, suffix: string, maxLength: number): string; /** * Whether a tool-call name cannot be replayed to the target: missing, empty, * longer than its declaration limit, or containing a character outside its * declaration charset. Models emit such names when the name slot carries * invocation text (whitespace, NULs) or an invented internal URL (`proc://*`). * * Without a target, use the OpenAI Responses native-history constraints. */ export declare function isMalformedToolCallName(name: unknown, allowedName?: RegExp, maxLength?: number): boolean; /** * Whether {@link transformMessages} drops `msg` from every replay: a turn cut * off by `length` / `error` / `aborted` that carries no text and no tool call. */ export declare function shouldDropTruncatedThinkingOnlyAssistant(msg: AssistantMessage): boolean; /** * Whether `msg` reaches a replay as an assistant turn, so it can be the latest * surviving one: {@link sanitizeMalformedToolCalls} drops its malformed tool * calls, then {@link shouldDropTruncatedThinkingOnlyAssistant} a truncated * turn left with no text and no tool call. On an already sanitized list this * is `!shouldDropTruncatedThinkingOnlyAssistant(msg)`. Pass the target `model` * to apply its tool-name limits; without one, any provider-declarable name survives. */ export declare function isSurvivingAssistant(msg: AssistantMessage, model?: Model): boolean; /** Whether `msg` carries mid-conversation Anthropic request controls (`clearAt`, `effort`, `toolChanges`). */ export declare function hasAnthropicMessageControls(msg: Message): boolean; /** * Whether a `user` or `developer` message emits a non-tool-result wire turn * that ends an assistant tool loop instead of being dropped as empty. */ export declare function isReplayTurnBoundary(msg: Message): boolean; export declare function isAnthropicMessagesModel(model: Model): model is Model<"anthropic-messages">; /** Whether `turn` came from `model` itself: its own turns replay their native reasoning unchanged. */ export declare function isSameModelTurn(turn: Pick, model: Pick): boolean; /** * Whether {@link transformMessages} certainly drops `turn`'s opaque reasoning * payload (thinking signatures, redacted thinking) on its way to `model`: * another model's turn on a directly encoded wire keeps neither, except * Anthropic-messages to Anthropic-messages, where deployment and signing * rules may keep them. `false` when the payload may survive. */ export declare function dropsForeignReasoningPayload(turn: Pick, model: Pick): boolean; /** * Whether chat completions (`convertMessages`) writes the model's own past * thinking under `compat`: as Mistral content parts, demoted text, or a * reasoning field. Otherwise it drops it. */ export declare function completionsSendsOwnThinking(model: { reasoning?: boolean; }, compat: Pick): boolean; /** * Normalize tool call ID for cross-provider compatibility. * OpenAI Responses API generates IDs that are 450+ chars with special characters like `|`. * Anthropic APIs require IDs matching ^[a-zA-Z0-9_-]+$ (max 64 chars). * * For aborted/errored turns, this function: * - Preserves tool call structure (unlike converting to text summaries) * - Injects synthetic "aborted" tool results */ /** * Credential-shaped token patterns scrubbed from outbound provider traffic when * credential redaction is enabled. Exported so hosts can route the same shapes * through reversible obfuscation (keyed placeholders restored before local tool * execution) instead of the irreversible `[*_token_redacted]` rewrite below — * an irreversible placeholder echoed back in edit-tool `old_string` can never * match the real bytes on disk. */ export declare const SENSITIVE_TOKEN_RE: RegExp; /** * Toggle process-wide outbound credential-pattern redaction (requests outside * any {@link withCredentialRedaction} scope). When disabled (the default), * {@link redactSensitiveCredentials} and {@link redactSensitiveInObject} are * pass-throughs and outbound messages/system prompts leave the process * unmodified. */ export declare function configureCredentialRedaction(enabled: boolean): void; /** * Runs `fn` with outbound credential-pattern redaction forced on or off for * every request it starts (including the async work those requests spawn), * overriding {@link configureCredentialRedaction}. Lets concurrent sessions in * one process each apply their own policy. */ export declare function withCredentialRedaction(enabled: boolean, fn: () => T): T; export declare function redactSensitiveCredentials(text: string): string; export declare function redactSensitiveInObject(val: unknown): { result: unknown; changed: boolean; }; export declare function transformMessages(messages: Message[], model: Model, normalizeToolCallId?: (id: string, model: Model, source: AssistantMessage) => string, maxNormalizedToolCallIdLength?: number, duplicateToolCallIdSuffixPrefix?: string, targetCompat?: Model["compat"], targetCredentialId?: number): Message[];