UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

72 lines (71 loc) • 5.96 kB
/** * 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 { LoopTerminalReason } from "../../internal/harness-types.js"; import { type RequestRoute } from "../../brain/request-route.js"; import type { TaskResult, TerminalCause } from "../types.js"; import { type TerminalFailureDetail } from "../terminal-cause.js"; type ProviderRejected = Extract<TerminalFailureDetail, { kind: "provider_rejected"; }>; /** The failure a loop exit word names ({@link LOOP_EXIT_FAILURE}), by own-row membership; `undefined` for every other word and for no word. */ export declare function loopExitFailureOf(reason: LoopTerminalReason | undefined): { readonly code: string; readonly message: string; } | undefined; /** 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 provider sentence, admitted through the one pass over a remote's words (a host Brain mints this message too); absent when it states none. */ export declare function providerSentenceOf(final: AssistantMessage): Pick<ProviderRejected, "providerMessage">; /** The part of the request the terminal message's refusal named, from the message's `errorKind` and `refusedTool` as the * terminal read them (each once): the kind admitted only as a word of `REFUSED_REQUEST_PARTS`, a tool-schema refusal only * with its tool (a non-empty string), else no account; an output-cap refusal with its two numbers when `refusedOutputCap` is * such a pair (`outputCapReportOf`, copied), else the word alone. */ export declare function refusedPartOf(errorKind: unknown, refusedTool: unknown, refusedOutputCap?: unknown): Pick<ProviderRejected, "errorKind" | "tool" | "outputCap">; /** 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; /** Admit one string value for a `coded` failure detail (and any wire mirror of its string members, e.g. * `WiringManifest.projectMarkerUnreadable.markerPath`): drops strings over {@link CODED_DETAIL_STRING} (`undefined`) * and replaces any string that {@link carriesCredential} with {@link CREDENTIAL_LEAF}; otherwise returns `text` verbatim. */ export declare function codedDetailStringOf(text: string): string | 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; }; /** A `failed` TaskResult for a throw that occurred before a Runner leg could start (e.g. the one-shot `runTask(spec, deps)` * when `new Runner(deps)` refuses deployment deps): carries the same coded terminal account (`thrownFailureOf`), * intake (`{ committed: false }`), unsettled continuation, and zero/usageMissing stats as the stream settle backstop, * without invoking any throwing getter on `spec`. */ export declare function failedPreRunResult(err: unknown, spec: unknown): TaskResult; /** The completion's one account, read off the final message: it ended on a provider word the brain does not read (the * turn was kept and the run announced the word — stated in the echo shape the brain carried it in), or its answer stopped * arriving before the provider ended it and what arrived was kept. A cut stream has no ending word, so the two never meet. */ export declare function completedTerminalOf(final: AssistantMessage | undefined): Extract<TerminalCause, { kind: "completed"; }>; export {};