import { AssistantMessage, AudioContent, FileContent, ImageContent, Message, MessageContent, SystemMessage, ToolMessage, UserMessage } from "../types/message.js"; import { CompletedToolCall, ToolError, ToolResult } from "../types/tool.js"; import { PendingSubRun, RunState, RunStep } from "../types/run.js"; //#region src/utils/binary-json.d.ts /** * Base64-encoded binary payload as it appears on the wire. * * @stable */ interface EncodedBytes { readonly enc: 'base64'; readonly data: string; } /** * URL reference as it appears on the wire (`URL` instances do not * survive `JSON.stringify` as instances - they serialize to their * `href` string). * * @stable */ interface EncodedUrl { readonly enc: 'url'; readonly href: string; } /** * Wire form of a `Uint8Array | URL` binary field. * * @stable */ type EncodedBinary = EncodedBytes | EncodedUrl; /** Wire twin of {@link ImageContent}. @stable */ interface WireImageContent extends Omit { readonly image: EncodedBinary; } /** Wire twin of {@link AudioContent}. @stable */ interface WireAudioContent extends Omit { readonly audio: EncodedBinary; } /** Wire twin of {@link FileContent}. @stable */ interface WireFileContent extends Omit { readonly file: EncodedBinary; } /** * JSON-safe twin of {@link MessageContent}: binary-bearing variants * carry {@link EncodedBinary} envelopes, text/reasoning variants pass * through untouched. * * @stable */ type WireMessageContent = Exclude | WireImageContent | WireAudioContent | WireFileContent; /** Wire twin of {@link UserMessage}. @stable */ interface WireUserMessage extends Omit { readonly content: string | readonly WireMessageContent[]; } /** Wire twin of {@link AssistantMessage}. @stable */ interface WireAssistantMessage extends Omit { readonly content: string | readonly WireMessageContent[]; } /** Wire twin of {@link ToolMessage}. @stable */ interface WireToolMessage extends Omit { readonly content: string | readonly WireMessageContent[]; } /** * JSON-safe twin of {@link Message}. System messages are plain strings * and pass through unchanged. * * @stable */ type WireMessage = SystemMessage | WireUserMessage | WireAssistantMessage | WireToolMessage; /** Wire twin of {@link ToolResult}: `contentParts` are encoded. @stable */ type WireToolResult = Omit, 'contentParts'> & { readonly contentParts?: readonly WireMessageContent[]; }; /** Wire twin of `ToolOutcome`. @stable */ type WireToolOutcome = WireToolResult | ToolError; /** Wire twin of {@link CompletedToolCall}. @stable */ type WireCompletedToolCall = Omit, 'outcome'> & { readonly outcome: WireToolOutcome; }; /** Wire twin of {@link RunStep}. @stable */ type WireRunStep = Omit & { readonly toolCalls: readonly WireCompletedToolCall[]; }; /** Wire twin of {@link PendingSubRun}: the child state recurses. @stable */ type WirePendingSubRun = Omit & { readonly state: WireRunState; }; /** * JSON-safe twin of {@link RunState}: `messages`, every * `steps[].toolCalls[].outcome.contentParts`, and each parked * `pendingSubRuns[].state` (recursively) are projected through * the binary codec. Everything else is structurally identical. * * `pendingApprovals[].args` and `ToolResult.output` are model-produced * JSON and are assumed JSON-safe already - the projection does not * walk them. * * @stable */ type WireRunState = Omit & { readonly messages: readonly WireMessage[]; readonly steps: readonly WireRunStep[]; readonly pendingSubRuns?: readonly WirePendingSubRun[]; }; /** * Encode bytes as standard (padded) base64 without relying on `Buffer` * or `btoa`. * * @stable */ declare function bytesToBase64(bytes: Uint8Array): string; /** * Decode standard base64 (padding optional). Throws on characters * outside the base64 alphabet. * * @stable */ declare function base64ToBytes(data: string): Uint8Array; /** * Project multimodal content parts into their JSON-safe wire form. * Text and reasoning parts pass through untouched. * * @stable */ declare function toJsonSafeContentParts(parts: readonly MessageContent[]): readonly WireMessageContent[]; /** * Inverse of {@link toJsonSafeContentParts}. Accepts legacy corrupted * payloads (numeric-key byte objects) and repairs them best-effort. * * @stable */ declare function fromJsonSafeContentParts(parts: readonly WireMessageContent[]): readonly MessageContent[]; /** * Project a {@link Message} into its JSON-safe wire form. Idempotent: * projecting an already-wire message returns an equivalent value. * * @stable */ declare function toJsonSafeMessage(message: Message | WireMessage): WireMessage; /** * Inverse of {@link toJsonSafeMessage}. * * @stable */ declare function fromJsonSafeMessage(message: WireMessage | Message): Message; /** * Project a full {@link RunState} into its JSON-safe {@link WireRunState} * twin: `messages` and `steps[].toolCalls[].outcome.contentParts` go * through the binary codec, everything else is copied structurally. * * @stable */ declare function toJsonSafeRunState(state: RunState | WireRunState): WireRunState; /** * Inverse of {@link toJsonSafeRunState}. Best-effort: legacy corrupted * binary fields (numeric-key byte objects from schema <= 1.1 payloads) * are repaired to `Uint8Array`; unrecoverable shapes are left as-is. * * @stable */ declare function fromJsonSafeRunState(state: WireRunState): RunState; //#endregion export { EncodedBinary, EncodedBytes, EncodedUrl, WireAssistantMessage, WireAudioContent, WireCompletedToolCall, WireFileContent, WireImageContent, WireMessage, WireMessageContent, WirePendingSubRun, WireRunState, WireRunStep, WireToolMessage, WireToolOutcome, WireToolResult, WireUserMessage, base64ToBytes, bytesToBase64, fromJsonSafeContentParts, fromJsonSafeMessage, fromJsonSafeRunState, toJsonSafeContentParts, toJsonSafeMessage, toJsonSafeRunState }; //# sourceMappingURL=binary-json.d.ts.map