/** * @license * Copyright 2026 Steven Roussey * SPDX-License-Identifier: Apache-2.0 */ import type { AiProviderRunFn, AiSessionContext, CacheCheckpointTaskInput, CacheCheckpointTaskOutput, ChatMessage, ToolDefinition } from "@workglow/ai"; import type { OpenAiModelConfig } from "./OpenAI_ModelSchema"; /** * Merges a checkpoint prefix into the unified generation input: the prefix's * messages come first, the caller's tail follows (its `messages`, or its * `prompt` lifted into a user message — the shared message builders only fall * back to `prompt` when the message list is empty), the prefix system prompt * applies when the call carries none (an explicit `""` falls through too — * suppressing the warmed instructions would diverge the replayed prefix), and * the effective `tools` are the caller's when it declares any, else the * prefix's — tools precede the conversation in the serialized request, so a * tools-warmed prefix consumed without them never shares the warm-up's cached * prefix. Returns undefined when the session has no prefix so plain calls * take the unmodified path. * * OpenAI's prompt caching is automatic and keyed on the request's literal * token prefix, so replaying identical prefix content is both the correctness * path and the cache-hit path — no per-request cache annotations exist. */ export declare function mergeOpenAICheckpointPrefix(session: AiSessionContext | undefined, input: { readonly messages?: readonly unknown[] | undefined; readonly systemPrompt?: string | undefined; readonly prompt?: unknown; readonly tools?: readonly ToolDefinition[] | undefined; }): { messages: readonly ChatMessage[]; systemPrompt: string | undefined; tools: readonly ToolDefinition[] | undefined; } | undefined; /** * Warm-up run-fn for `["cache.checkpoint"]` on OpenAI. Sends the prefix once * (minimal `max_output_tokens` — the Responses API floor is 16) so the * server-side automatic prompt cache is populated before consumers arrive. * * The warm-up is advisory: OpenAI caches long prompt prefixes on its own and * may evict at any time, so consumption never depends on this call having * succeeded — consumers always replay the full prefix content. * {@link finalizeResponsesRequest} derives the `prompt_cache_key` from the * request's model + instructions + tools, so this warm-up and every consumer * replaying the same prefix converge on the same key without coordination. */ export declare const OpenAI_CacheCheckpoint_Stream: AiProviderRunFn;