UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

49 lines (48 loc) • 2.97 kB
import { type MaybeCompactOptions, type maybeCompact } from "../auto-compaction.js"; import type { HookInvocationIdentity } from "../hooks.js"; import type { CompactOutcome, ExtensionRequester } from "../task-event.js"; import { type ModBottomContext, type ModCallEntry } from "./kernel/index.js"; import { type LegModBus } from "./stations.js"; type CompactResult = Awaited<ReturnType<typeof maybeCompact>>; /** What a pass hands the station: the instructions its manual request named, and — for `$.session.compact` — the call's * context (the pass is raised under the caller's frames and origin, so the caller's own handlers stay out of it). */ export interface CompactPass { readonly instructions?: string; readonly call?: ModBottomContext; } /** The boundary's in-place pass, as `$.session.compact` reaches it: run one manual pass now, asked for by `requestedBy`. */ export type CompactWindowPass = (request: { readonly instructions?: string; readonly requestedBy: ExtensionRequester; readonly call: ModBottomContext; }) => Promise<CompactOutcome>; /** What the leg binds the station to once its bus is admitted. */ export interface CompactStationBinding { readonly bus: LegModBus; readonly identity: HookInvocationIdentity | undefined; readonly report: (err: Error) => void; } /** The leg's `session.compact` station (see the module header). */ export interface CompactStation { bind(binding: CompactStationBinding): void; /** One compaction pass through the station: `run` is the lane's `maybeCompact`, handed the options with the station's * seats in place (no handler ⇒ the options as they came). */ compact(opts: MaybeCompactOptions, run: (opts: MaybeCompactOptions) => Promise<CompactResult>, pass?: CompactPass): Promise<CompactResult>; /** Run `raise` (the boundary's `turn.complete`) with `$.session.compact` open: a direct call from one of its handlers runs * `pass` in place, and `window` answers once that pass has ended too. */ window<T>(pass: CompactWindowPass, raise: () => Promise<T>): Promise<T>; /** `$.session.compact`'s seat: the in-place pass, or the refusal. */ call(instructions: string | undefined, ctx: ModBottomContext): Promise<CompactOutcome>; } /** The leg's `session.compact` station. */ export declare function createCompactStation(): CompactStation; /** The extension the last `$.session.compact` request among `waiters` came from (requests coalesce onto one pass), as the * member the pass's ending frame spreads; empty when no extension asked. */ export declare function requesterOf(waiters: ReadonlyArray<{ readonly requestedBy?: ExtensionRequester; }>): { readonly requestedBy?: ExtensionRequester; }; /** `$.session.compact`'s host entry: `{ instructions? }`, a manual pass at the turn boundary in place (the module header). */ export declare function createSessionCompactEntry(station: Pick<CompactStation, "call">): ModCallEntry; export {};