@sema-agent/core
Version:
Stateless, task-oriented AI agent core
93 lines (92 loc) • 4.09 kB
TypeScript
import type { PromptTextDeclaration } from "../prompts/default.js";
/** v1 overlay slots — the same reserved rank bands the stableBlocks lane mounts into. */
export type CenterOverlaySlot = "identity" | "scenario" | "behavior";
export interface CenterOverlaySection {
/** Same grammar as stableBlocks ids (manifest/trace/explain-safe, never `core/`). */
id: string;
slot: CenterOverlaySlot;
/** Immutable rendered text (v1: fixed text, no renderer — center compiles before publishing). */
text: string;
/** REQUIRED on the center lane (unlike caller stableBlocks): sha256 of `text`. The center
* publish path always mints it — it is the reconciliation anchor (digest tiering). */
contentHash: string;
}
export interface PromptCatalogSnapshot {
/** Center pack identity, e.g. "center:acme@3". Logical name only — history identity is digests. */
packId: string;
sections: ReadonlyArray<CenterOverlaySection>;
}
export interface PromptDependencyClosure {
/** v1: only the bundled base is a legal foundation (exact-archive multi-base = later slice). */
basePackId: string;
promptCatalog: PromptCatalogSnapshot;
}
/** Dependency-free core-compat range: dotted-triple compares, absent bound = unbounded. */
export interface CoreCompatRange {
minCore?: string;
maxCoreExclusive?: string;
}
export interface PromptEpochArtifactPayload {
schemaVersion: 1;
assemblyApi: 1;
catalogDigest: string;
compatibleCore?: CoreCompatRange;
closure: PromptDependencyClosure;
}
export interface PromptEpochArtifact {
payload: PromptEpochArtifactPayload;
artifactDigest: string;
}
/** The publish envelope (§9.2): artifact + opaque source provenance. Attestation = later slice
* (protocol: first phase does not require full PKI for internal artifacts). */
export interface PublishedPromptArtifactEnvelope {
artifact: PromptEpochArtifact;
/** Opaque ETag-like revision. State transitions key off "last successfully verified response";
* NEVER ordered or compared for recency. */
sourceRevision: string;
}
/** Validator hard limits (§9.2: sections/bytes caps so a untrusted or runaway publish cannot wedge
* the composer). Deliberately generous — these bound abuse, not legitimate catalogs. */
export declare const ARTIFACT_LIMITS: {
readonly maxSections: 64;
readonly maxSectionBytes: 32000;
readonly maxTotalBytes: 131072;
readonly maxIdLength: 128;
readonly maxPackIdLength: 200;
};
export declare function sha256Hex(text: string): string;
export declare function computeCatalogDigest(catalog: PromptCatalogSnapshot): string;
export declare function computeArtifactDigest(payload: PromptEpochArtifactPayload): string;
export type ArtifactVerifyResult = {
ok: true;
artifact: PromptEpochArtifact;
} | {
ok: false;
code: string;
reason: string;
};
/**
* Full §9.2 verify pipeline over an UNTRUSTED envelope (network body or disk bytes — the store
* re-verifies on read; nothing on disk is trusted by location). Every arm is a distinct coded
* rejection so the source-state machine can log honestly. Verification is pure — no IO.
*/
export declare function verifyPromptArtifact(raw: unknown, opts: {
engineVersion: string;
}): ArtifactVerifyResult;
/**
* Compile a VERIFIED artifact into the declaration lane (v1 adoption channel — see file header).
* Deterministic order: catalog order preserved (it entered the digest, so it is stable).
*/
export declare function artifactDeclarations(artifact: PromptEpochArtifact): PromptTextDeclaration[];
/** Test/fixture helper: build a correctly-digested envelope from plain sections (the shape a
* center's publish pipeline produces). Exported for tests and the fixture-center harness. */
export declare function buildPromptArtifactEnvelope(opts: {
packId: string;
sections: ReadonlyArray<{
id: string;
slot: CenterOverlaySlot;
text: string;
}>;
sourceRevision: string;
compatibleCore?: CoreCompatRange;
}): PublishedPromptArtifactEnvelope;