@sema-agent/core
Version:
Stateless, task-oriented AI agent core
96 lines (95 loc) • 4.17 kB
TypeScript
/**
* The one typing of the engine's classic stations: each `classic.*` event a station raises, paired with its `e` and its
* answer form. Every raise site constructs its `e` against it (`dispatchClassic` / `observeClassic`), and the engine's
* registration form types a handler by it. Its keys are the event table's `classic.*` rows that carry a station — the key
* set is held to that table.
*/
import type { MessageDisplayEvent, MessageDisplayResult, PermissionDeniedPayload, PostCompactEvent, PostToolBatchEvent, PostToolBatchResult, PostToolUseEvent, PostToolUseFailureEvent, PostToolUseFailureResult, PostToolUseResult, PreCompactEvent, PreCompactResult, PreToolUseEvent, PreToolUseResult, SessionEndEvent, SessionStartEvent, StopEvent, StopFailureEvent, StopHookResult, SubagentStartEvent, SubagentStartResult, TaskHookEvent, TeammateIdleEvent, UserPromptSubmitEvent, UserPromptSubmitResult } from "../hooks.js";
import type { MappedOn, ModRegistration } from "./kernel/index.js";
import type { EngineDollar } from "./dollar.js";
/** The answer of an event whose station reads none (an observation event): a chain handler passes `next(e)`'s on. */
export type ObservedAnswer = Readonly<Record<string, never>>;
/** Each `classic.*` event a station raises, with its `e` and its answer form. */
export type ClassicEventMap = {
readonly "classic.PreToolUse": {
readonly e: PreToolUseEvent;
readonly answer: PreToolUseResult | null | false;
};
readonly "classic.PostToolUse": {
readonly e: PostToolUseEvent;
readonly answer: PostToolUseResult;
};
readonly "classic.PostToolUseFailure": {
readonly e: PostToolUseFailureEvent;
readonly answer: PostToolUseFailureResult;
};
readonly "classic.PostToolBatch": {
readonly e: PostToolBatchEvent;
readonly answer: PostToolBatchResult;
};
readonly "classic.UserPromptSubmit": {
readonly e: UserPromptSubmitEvent;
readonly answer: UserPromptSubmitResult;
};
readonly "classic.SessionStart": {
readonly e: SessionStartEvent;
readonly answer: ObservedAnswer;
};
readonly "classic.SessionEnd": {
readonly e: SessionEndEvent;
readonly answer: ObservedAnswer;
};
readonly "classic.SubagentStart": {
readonly e: SubagentStartEvent;
readonly answer: SubagentStartResult;
};
readonly "classic.Stop": {
readonly e: StopEvent;
readonly answer: StopHookResult;
};
readonly "classic.SubagentStop": {
readonly e: StopEvent;
readonly answer: StopHookResult;
};
readonly "classic.TaskCreated": {
readonly e: TaskHookEvent;
readonly answer: StopHookResult;
};
readonly "classic.TaskCompleted": {
readonly e: TaskHookEvent;
readonly answer: StopHookResult;
};
readonly "classic.TeammateIdle": {
readonly e: TeammateIdleEvent;
readonly answer: StopHookResult;
};
readonly "classic.StopFailure": {
readonly e: StopFailureEvent;
readonly answer: ObservedAnswer;
};
readonly "classic.PreCompact": {
readonly e: PreCompactEvent;
readonly answer: PreCompactResult;
};
readonly "classic.PostCompact": {
readonly e: PostCompactEvent;
readonly answer: ObservedAnswer;
};
readonly "classic.PermissionDenied": {
readonly e: PermissionDeniedPayload;
readonly answer: ObservedAnswer;
};
readonly "classic.MessageDisplay": {
readonly e: MessageDisplayEvent;
readonly answer: MessageDisplayResult;
};
};
/** A `classic.*` event a station raises. */
export type ClassicEventName = keyof ClassicEventMap;
/**
* A registration on the engine's bus (`RunnerDeps.mods`, `TaskSpec.mods`): the kernel's registration form whose `on`
* types a handler of a `classic.*` event by {@link ClassicEventMap} — its `e`, its `next`, its answer.
*/
export interface EngineModRegistration extends Omit<ModRegistration<EngineDollar>, "register"> {
register(on: MappedOn<EngineDollar, ClassicEventMap>, options: unknown): void;
}