@sema-agent/core
Version:
Stateless, task-oriented AI agent core
58 lines (57 loc) • 3.29 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 SourcedOverlay, type SupersededOverlay } from "./overlay.js";
import type { PromptSelectors } from "./select.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 run's selectors, minted once by prepare (`selectorsOf`): traits, host, facts, binding and locale. Every render
* of this run — the first, a date re-render, a compaction-boundary re-assembly — reads this one object. */
selectors: PromptSelectors;
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;
/** 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[];
/** The event templates the overlays replaced ({@link ComposedWithOverlays.eventCopy}) — the run's engine text reading reads them. */
eventCopy: ReadonlyMap<string, string>;
}
export declare function assemblePrompt(inputs: AssembleInputs): AssembledPrompt;