UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

79 lines (78 loc) • 5.28 kB
import { type OwnerIdentity } from "../../core/owner-identity.js"; import { type ArtifactAction, type ArtifactCallBinding, type ArtifactHost, type ArtifactHostCapabilities, type ArtifactHostOwnership, type ArtifactRef } from "../../core/artifact-host.js"; /** The kit's five synthetic identities (see the module header). */ export type ArtifactConformanceWho = "a" | "a2" | "b" | "c" | "z"; export interface ArtifactConformanceHooks { /** Make the host's NEXT write fail BEFORE its commit point (`arm`), then restore it (`disarm`). The atomicity vector * runs only with this hook: the kit cannot reach inside an arbitrary host. */ precommitFault?: { arm: () => void | Promise<void>; disarm: () => void | Promise<void>; }; /** Save a new version of `ref`'s page from INSIDE the page — the version a plain `force` must not discard * (`force_refused`). The force-refusal vector runs only with this hook. */ pageSavedVersion?: (ref: ArtifactRef) => void | Promise<void>; /** The binding the kit acts under for one of its identities in one of its two conversations, when the host needs real ones * (an identity its directory knows, a root conversation that exists). The kit checks what comes back: five identities that * are pairwise different, `a` / `a2` one person, `a` / `b` one scope name, `z` anonymous, two conversations apart. Names * should be distinctive strings: the refusal vector looks for `a`'s as substrings of refusal texts. Absent ⇒ the kit's own. */ binding?: (who: ArtifactConformanceWho, conversation: 0 | 1) => ArtifactCallBinding | Promise<ArtifactCallBinding>; /** A host declaring `ownership.unrecorded: "possible"`: put one page whose owner record names NO identity (a page from before * owner records were kept) and answer its url. The vector that needs it fails, naming this hook, when it is absent. */ seedUnrecordedPage?: () => string | Promise<string>; /** A host declaring `ownership.sharing: "marked"`: grant identity `to` the page at `url` that identity `from` owns, through the * host's own grant table. The vector that needs it fails, naming this hook, when it is absent. */ share?: (url: string, from: OwnerIdentity, to: OwnerIdentity) => void | Promise<void>; /** A url of the host's own form at which no page exists — the "no page" the identity vectors pair another identity's page * with. Absent ⇒ the kit appends a suffix to a url the host minted; a host whose urls carry a checked form (a UUID, a * signature) supplies this instead. */ absentUrl?: () => string | Promise<string>; } export interface ArtifactConformanceOptions { hooks?: ArtifactConformanceHooks; /** Run the at-limit POSITIVE arms of the byte-limit vector: they allocate and publish payloads of the declared * sizes. Default `false` — reported `skipped`, named. The over-limit refusal arms always run. */ largePayloads?: boolean; /** The run id identity `a`'s first conversation mounts (`onMount`) and calls under; default a fresh uuid. Every other * identity × conversation is a run of its own with a fresh id. */ runId?: string; } export type ArtifactConformanceStatus = "pass" | "fail" | "not_applicable" | "skipped"; export interface ArtifactConformanceVector { /** Stable id: a host's own conformance test keys on it. */ id: string; describe: string; /** Every listed action must be declared for the vector to apply. */ requiresActions: readonly ArtifactAction[]; requiresMultiFile?: true; /** The arm of a declared `ownership` word this vector is: it applies only when the declaration names these words. */ requiresOwnership?: Partial<ArtifactHostOwnership>; requiresHook?: keyof ArtifactConformanceHooks; requiresLargePayloads?: true; } export interface ArtifactConformanceResult { id: string; status: ArtifactConformanceStatus; /** What passed, what failed (the first violated expectation), or why the vector did not run. */ detail: string; } export interface ArtifactConformanceReport { capabilities: ArtifactHostCapabilities; runId: string; results: readonly ArtifactConformanceResult[]; passed: number; failed: number; notApplicable: number; skipped: number; } /** The full vector matrix (data; ids are stable). */ export declare const ARTIFACT_CONFORMANCE_VECTORS: readonly ArtifactConformanceVector[]; /** The vectors a host's DECLARATION covers (hook- and payload-gated vectors included: their gating is reported at run time). */ export declare function artifactConformanceVectors(host: ArtifactHost): ArtifactConformanceVector[]; /** * Drive `host` through every vector its declaration covers, sequentially. Identity `a`'s first conversation runs under * `opts.runId` (or a fresh uuid); every other identity × conversation is a run of its own; the host's `onMount` is called once * for each run first. Throws only when the declaration itself is invalid — every vector outcome, a thrown host method or a * failing `binding` hook included, is a row of the report. */ export declare function runArtifactConformance(host: ArtifactHost, opts?: ArtifactConformanceOptions): Promise<ArtifactConformanceReport>;