import type { GameEvent, GameState, ObservationFrame } from '../module-input/index.js'; import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js'; import type { ClawclawResourceLocalizations } from '../resource-metadata.js'; /** A fixed dependency, resolved against this account's equipped, loadable Behaviors. */ export interface ReactionBehaviorBinding { readonly name: string; /** Preferred Hub identity. A missing match falls back to name and its duplicate aliases. */ readonly resourceId?: string; readonly layer?: 'reflex'; readonly input?: Readonly>; readonly reflexPriority?: number; readonly cooldownMs?: number; readonly rearm?: 'after_clear' | 'after_cooldown'; readonly maxRuntimeMs?: number; } export interface ClawclawReactionManifest { readonly apiVersion: 2; readonly kind: 'reaction'; readonly id: string; readonly name?: string; readonly description: string; readonly localizations?: ClawclawResourceLocalizations; /** Backend, derived and visual Events. Reaction outputs cannot feed reactions. */ readonly consumes: readonly string[]; /** Own Agent-visible notices, named reaction.. */ readonly produces: readonly string[]; readonly behaviors?: Readonly>; readonly inputs?: readonly BehaviorInputFieldSpec[]; readonly config?: Readonly>; } export interface ReactionFact extends GameEvent { readonly wakeAgent?: boolean; readonly replayed: boolean; } export interface ReactionInput { readonly moduleId: string; readonly scope: Readonly<{ sessionId: string; segmentId: string }>; readonly gameState: Readonly | null; readonly frame: Readonly | null; readonly events: readonly ReactionFact[]; readonly nowMs: number; /** JSON data returned by the previous evaluate; do not keep state in class fields. */ readonly state: unknown; readonly config: Readonly>; readonly availableBehaviors: readonly string[]; } export interface ReactionEvent { readonly type: string; /** Stable identity for this occurrence, not a new key on every frame. */ readonly key: string; readonly wakeAgent?: boolean; readonly payload: Readonly> & { readonly text: string }; } export interface ReactionActivation { /** Key in manifest.behaviors; never an arbitrary executable command. */ readonly behavior: string; readonly input?: Readonly>; readonly reason?: string; } export interface ReactionResult { readonly state?: unknown; readonly events?: readonly ReactionEvent[]; /** Return while the condition holds. Omitting a binding clears its after_clear latch. */ readonly activations?: readonly ReactionActivation[]; } /** A perception resource that can notify the Agent and request fixed Behaviors. */ /** @deprecated API v2 compatibility; future support may end. New scripts use ClawclawPerception API v3. */ export abstract class ClawclawReaction { static readonly manifest?: ClawclawReactionManifest; abstract evaluate(input: Readonly): ReactionResult | Promise; }