@sema-agent/core
Version:
Stateless, task-oriented AI agent core
61 lines (60 loc) • 3.15 kB
TypeScript
/**
* Prepare-side assembly adapter — the SINGLE entry that drives the Composer over the bundled catalog. Prepare
* hands it the run's facts and tails and the overlays of each source class (the task class: the request-body
* sugar's, then the task seat's mods; the center class; the deploy class: the deployment seat's mods); it
* orders the classes `task < center < deploy`, composes, and reports every overlay a later one superseded.
*
* There is no "provider" here: no source owns the whole prompt, the locked bands have no writer, and a role
* text that carries locked text never reaches this point (the sugar refuses it, a mods handler's answer is
* skipped).
*/
import type { AgentTool } from "../internal/harness-types.js";
import type { HostForm, HostRole } from "./catalog/schema.js";
import { type SourcedOverlay, type SupersededOverlay } from "./overlay.js";
import type { CompiledSection, CompiledSystemBlock, PromptRuntimeFacts } from "./types.js";
export interface AssembleInputs {
/** The task class, in application order: the request-body sugar's overlays, then the task seat's mods. */
taskOverlays: readonly SourcedOverlay[];
/** The center class (the adopted center layer's overlays). */
centerOverlays: readonly SourcedOverlay[];
/** The deploy class: the deployment seat's mods, in chain order. */
deployOverlays: readonly SourcedOverlay[];
/** The host selector values (`TaskSpec.promptRole` / `TaskSpec.promptForm`). */
host?: {
role?: HostRole;
form?: HostForm;
};
/** The run's binding (`TaskSpec.promptBinding`), read by every overlay's `when.binding`. */
binding?: string;
tools: readonly AgentTool[];
facts: PromptRuntimeFacts;
/** The task's working directory (the Cowork role base's `{{workspaceFolder}}`). */
workspaceFolder?: string;
mcpInstructionsBlock?: string;
memoryBlock?: string;
/** Renders the environment tail for a given date (leg-frozen; date_change re-render seam). */
buildEnvBlock: (date: string) => string | undefined;
/** The leg's frozen date — the initial render input. */
date: string;
modelGuidance?: string;
/** Structured warning channel (maps to deps.onError with a phase). */
onWarn?: (message: string, phase: "prompt-constitution") => void;
}
export interface AssembledPrompt {
/** Re-render the full prompt for a date. */
renderWithDate: (date: string) => string;
/** The initially-rendered system prompt. */
systemPrompt: string;
/** The `prompt.assembled` block view (the id wordlist is a downstream contract). */
blocks: Array<{
id: string;
text: string;
}>;
/** Compiled IR of the last render — the manifest's section source. */
sections: CompiledSection[];
/** Physical system blocks of the last render (one block, text === systemPrompt). */
systemBlocks: CompiledSystemBlock[];
/** The composition's {@link ComposedWithOverlays.superseded}, from the first render. */
superseded: readonly SupersededOverlay[];
}
export declare function assemblePrompt(inputs: AssembleInputs): AssembledPrompt;