UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

74 lines (73 loc) • 5.07 kB
/** * Media degradation shared by the two message assemblers (anthropic.ts / openai.ts). * * Both lanes answer the same two questions on every request — "may this model see images?" and * "what do I say when a media block cannot ride along?" — from ONE construction point: a capability * rule that drifts between lanes is a silent per-provider behavior difference, and a placeholder * sentence that drifts is a string consumers grep for. */ import type { Model } from "../internal/llm.js"; import type { RenderedLocale } from "../prompt-assembly/catalog/schema.js"; import { type CapabilityDeclaration } from "./model-capability.js"; /** Why a request's images are withheld from the SERVING model: the entry's image declaration, when it is not held * (the withheld-capability report's `cause`, `status-sink.ts`). */ export type ImageWithholdCause = Exclude<CapabilityDeclaration, "declared_on">; /** A request whose images are withheld: which model, and why. */ export interface ImageWithhold { readonly modelId: string; readonly cause: ImageWithholdCause; } /** * The image row of the capability table for one request: `undefined` = images ride as images; otherwise the model and * the declaration that withholds them. Read off the one capability reading (`capabilityHeld` / `capabilityOf`), so an * entry that never declared `input` gets its images exactly as the table says, and an entry that declares a list without * `"image"` gets the placeholder path — the case a text-only API rejects with a hard 400 on an image part. No model = * images ride. */ export declare function imageWithholdOf(model?: Model): ImageWithhold | undefined; /** Report `count` images of one request replaced by placeholders — the one emit for every lane: the operator trace frame * (telemetry, per request) and the leg's withheld-capability account (the person's notice, once per conversation). */ export declare function reportImagesWithheld(withhold: ImageWithhold, count: number): void; /** Placeholder for an image block dropped because the serving model declares no image input. */ export declare const IMAGE_OMITTED_NO_VISION = "[image omitted: the serving model does not support image input]"; /** Placeholder for a document block the request cannot carry: a wire with no document part (OpenAI-compatible, Responses), or an * Anthropic model without image input. It says only what is true whatever produced the block — the Read tool forks on the * serving model before it makes one, an MCP result keeps an unreadable pdf by ref — so it names no file and no step to re-run: * what still reaches it is a block from an earlier model of the conversation, or one a caller put there. */ export declare const DOCUMENT_OMITTED = "[PDF document omitted: the serving model does not support PDF (document) input]"; /** {@link IMAGE_OMITTED_NO_VISION}, counted — a batch of dropped images states how many were lost. */ export declare function imagesOmittedNoVisionNote(count: number): string; /** The provenance line before a tool's images where a lane carries them in a synthetic user message (the endpoint * takes images only on a user message): the catalog's image-prefix message for one image or several, naming the * tool calls (`ids`) they came from — in the request's locale (`Context.promptLocale`; absent ⇒ canonical). */ export declare function toolImagesPrefix(count: number, ids: string, locale?: RenderedLocale): string; /** An image content block carrying both wire fields — the only shape any lane can actually send. */ export interface SendableImage { type: "image"; data: string; mimeType: string; } /** * The blocks that would ride as REAL image media: `type:"image"` with both wire fields present. * * One predicate for both lanes and for both of its uses — deciding what to SEND and counting what was * DROPPED. A block missing `data`/`mimeType` is discarded by every assembler on every path, error or * not, so an omission note that counted it would blame the error for a loss it did not cause. */ export declare function sendableImages(blocks: readonly unknown[]): SendableImage[]; /** * Disclosure for media blocks stripped out of an ERROR tool result. * * The stripping itself is mandatory on both lanes and is NOT a choice this note softens: the * Anthropic API rejects an image inside an `is_error` tool_result outright (CC messages.ts, image-in-error rejection — * a passthrough attempt 400s the request forever, not once), and the OpenAI-compatible `tool` role * carries text only, with the synthetic image-carrier user message deliberately not built for error * results. What the note fixes is the SILENCE: an error whose attached evidence simply vanished * reads to the model as an error that never had any, so it cannot ask for the evidence another way. * * @returns the note, or `undefined` when there is nothing to disclose (no media was dropped). */ export declare function errorResultMediaNote(counts: { images: number; documents: number; }): string | undefined;