UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

42 lines (41 loc) • 2.59 kB
/** * The `tool_end` output/structured projection, verbatim from * `runtask.ts`'s runLocked R4 phase. Pure functions over the harness `AgentToolResult`: zero closure * state, zero runtask coupling — the module-level inputs are the text cap below and the shared media budget reading * (`requestMediaBudget`); the leg hands in its own `mediaBudgetBase64Chars`. */ import { type CardOnFrame } from "../tool-card-bound.js"; /** A block's own size in characters — the ONE counter `tool_end.totalChars` adds up over a tool result's blocks (a * consumer that re-renders a result sums the same function): a text block its text plus whatever else it carries at * its serialized length (the contract's text block carries nothing else), a media block its payload, any other block * its serialization — counted in UTF-16 units (a string's `.length`). */ export declare const toolOutputBlockChars: (b: unknown) => number; type ToolOutput = { output: unknown; truncated: boolean; totalChars?: number; }; export declare const toolOutputFrom: (result: unknown, mediaBudgetBase64Chars: number | undefined) => ToolOutput | undefined; /** The `tool_end.structured` projection over a harness tool result: the CC card when `details.type` names a card * the leg admits and the frame can carry it, else undefined. */ export type StructuredProjector = (result: unknown) => unknown; /** The leg's card port: where a harness tool result's card goes on its `tool_end` ({@link cardOnFrame}), or undefined when * the leg admits no card. Minted per leg by {@link createCardProjector}; every body projection takes it as a parameter — * there is no module-level card set to fall back to. */ export type CardProjector = (result: unknown) => CardOnFrame | undefined; /** {@link createCardProjector}'s `structured` alone: the card a frame carries whole, nothing for one over the bound. */ export declare function createStructuredProjector(opts?: { declaredCards?: Iterable<string>; onUndeclared?: (type: string) => void; }): StructuredProjector; /** * L4's run-time half: a per-leg projector — the engine card set plus the leg's declared * caller cards — that DROPS an undeclared `details.type` and announces it ONCE per leg * (`config.tool_card_undeclared`, audience operator). With no options it is the engine set alone, unannounced — * the shape a caller outside a leg (a test, a fixture) uses. */ export declare function createCardProjector(opts?: { declaredCards?: Iterable<string>; onUndeclared?: (type: string) => void; }): CardProjector; export {};