UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

48 lines (47 loc) • 2.72 kB
import type { AgentMessage } from "../internal/harness-types.js"; import { type DocumentContent, type ImageContent } from "../internal/llm.js"; import { type RequestMediaLimits } from "./image-admission.js"; /** A media block: an image or a document whose payload is a base64 string. */ export type MediaBlock = ImageContent | DocumentContent; /** Whether a value is a media block: its `type` is a media type and its `data` a string. A block of a media type with no * string `data` is not one — a {@link MediaDescriptor} is such a block. */ export declare function isMediaBlock(block: unknown): block is MediaBlock; /** What media becomes where its bytes do not ride: one block's identity (its type, its media type when it can be one, its * decoded size), or one summary of every block from there on. Never a string, never the bytes. */ export type MediaDescriptor = { type: MediaBlock["type"]; mimeType?: string; bytes: number; truncated: true; } | { type: "omitted"; blocks: number; bytes: number; truncated: true; }; /** A media block's descriptor. The media type is echoed only when it can be one (RFC 6838: type and subtype are at most * 127 characters each); `bytes` is {@link imageBytes}. */ export declare function mediaBlockDescriptor(block: MediaBlock): MediaDescriptor; /** The one summary of media blocks that leave together: how many, and their decoded size. */ export declare function omittedMediaDescriptor(blocks: readonly MediaBlock[]): MediaDescriptor; /** Decoded byte size of a base64 media payload (4 base64 chars ≈ 3 bytes) — what a descriptor states of the block. */ export declare function imageBytes(b: ImageContent | DocumentContent): number; /** One block the trim took out: the input's own block object, and its type and base64 as the trim read them (once). */ export interface RemovedMedia { block: object; type: MediaBlock["type"]; data: string; } /** What one request's trim did: the request's messages (the input array itself when nothing went), the blocks that went * (oldest first) and their base64 characters, and the request's media as it came — how many blocks, how many base64 * characters. */ export interface RequestMediaTrim { messages: AgentMessage[]; removed: RemovedMedia[]; removedBase64Chars: number; items: number; base64Chars: number; } /** Trim the media of `messages` to `limits` (see the module head). A block's size is its base64 length (CC `Pkn`), `0` for * one that carries no base64 string — such a block counts toward `maxItems` and is never cut for the budget. */ export declare function trimRequestMedia(messages: AgentMessage[], limits: RequestMediaLimits): RequestMediaTrim;