@sema-agent/core
Version:
Stateless, task-oriented AI agent core
49 lines (48 loc) • 3.61 kB
TypeScript
/**
* The terminal's accounts — `terminal.detail` and its members — each read off the ONE seat its fact was minted on, and
* admitted as a value this engine did not necessarily build (a host Brain mints the final message too; a host throws
* the error): every member read once, words admitted only from their closed sets, a malformed member absent rather than
* repaired. Nothing here re-derives a fact from a sentence. The arbitration of WHICH account a terminal carries is
* `assemble-result.ts`'s (`terminalCauseOf`); this module only reads.
*/
import { type AssistantMessage, type ModelOutputInvalid } from "../../internal/llm.js";
import { type RequestRoute } from "../../brain/request-route.js";
import type { TerminalCause } from "../types.js";
import type { TerminalFailureDetail } from "../terminal-cause.js";
type ProviderRejected = Extract<TerminalFailureDetail, {
kind: "provider_rejected";
}>;
/** The terminal message's provider-condition verdict, as the refusal account carries it: each member read once and
* admitted only as a word of its closed set (a host Brain mints this message too); the reset instant only beside a
* condition. Absent members stay absent. */
export declare function providerVerdictOf(final: AssistantMessage): Pick<ProviderRejected, "providerCondition" | "providerConditionSource" | "providerResetAtMs">;
/** The terminal message's request route (`apiErrorRoute`), admitted as a shape some request carries
* (`ROUTE_CREDENTIAL_PAIRING`); anything else is no route. */
export declare function requestRouteOfMessage(final: AssistantMessage): RequestRoute | undefined;
/** The terminal message's dropped-calls account (`modelOutputInvalid`): `cause` admitted from its closed set (else no
* account); `outputLimit` only beside `truncated`, only with a boolean `capStop`, its counts only as non-negative
* integers — an unreadable limit leaves the cause standing without it. */
export declare function modelOutputInvalidOfMessage(final: AssistantMessage): ModelOutputInvalid | undefined;
/**
* Extract a machine-readable code from a thrown error (e.g. `SessionError.code`, a Node error code).
* Walks the `cause` chain because the harness wraps lower-level errors (e.g. a `SessionError("conflict")`
* append failure surfaces as an `AgentHarnessError("unknown")` whose cause is the real one) — so we
* prefer the first specific code over a generic `"unknown"` wrapper.
*/
export declare function errorCodeOf(err: unknown): string | undefined;
/** A thrown failure's terminal account — its code ({@link errorCodeOf}), its sentence (the seat's own describing of the
* thrown value, `text`, through the secret word list: a throw's message is the thrower's text, and a credential in it
* must not reach the result any more than one in its `detail`), and, when the coded link's throw site stated a
* structured `detail`, the `coded` account of it. One reading for every seat that turns a throw into a `failed`
* terminal (the run's arbitration in `assemble-result.ts` and the stream lane's settle backstop). */
export declare function thrownFailureOf(err: unknown, text: string): {
code?: string;
message: string;
detail?: TerminalFailureDetail;
};
/** The completion's one account: the final turn ended on a provider word the brain does not read (the turn was kept
* and the run announced the word) — stated beside the completion, in the echo shape the brain carried it in. */
export declare function completedTerminalOf(final: AssistantMessage | undefined): Extract<TerminalCause, {
kind: "completed";
}>;
export {};