import { Schema, Effect, Context, Layer } from 'effect'; import * as effect_Cause from 'effect/Cause'; import * as effect_Types from 'effect/Types'; /** * Minimum shape a published event must satisfy: a discriminant `_tag` * field plus arbitrary additional payload. Mirrors the * `@reactive-agents/core` `AgentEvent` taxonomy structurally without * forcing a hard import. */ type TaggedEventLike = Readonly<{ _tag: string; }> & Readonly>; /** * Structural type for optional EventBus dependency injection. * Avoids a hard dependency on `@reactive-agents/core` while enabling * observability. HS-05 (2026-05-20 sweep) replaced the prior `(event: * any)` signature so consumers can no longer accidentally publish * un-tagged payloads through the gateway boundary. */ type EventBusLike = { readonly publish: (event: TaggedEventLike) => Effect.Effect; }; declare const GatewayEventSourceSchema: Schema.Literal<["heartbeat", "cron", "webhook", "channel", "a2a", "state-change"]>; type GatewayEventSource = typeof GatewayEventSourceSchema.Type; declare const EventPrioritySchema: Schema.Literal<["low", "normal", "high", "critical"]>; type EventPriority = typeof EventPrioritySchema.Type; declare const HeartbeatPolicySchema: Schema.Literal<["always", "adaptive", "conservative"]>; type HeartbeatPolicy = typeof HeartbeatPolicySchema.Type; interface GatewayEvent { readonly id: string; readonly source: GatewayEventSource; readonly timestamp: Date; readonly agentId?: string; readonly payload: unknown; readonly priority: EventPriority; readonly metadata: Record; readonly traceId?: string; } type PolicyDecision = { readonly action: "execute"; readonly taskDescription: string; } | { readonly action: "queue"; readonly reason: string; } | { readonly action: "skip"; readonly reason: string; } | { readonly action: "merge"; readonly mergeKey: string; } | { readonly action: "escalate"; readonly reason: string; }; declare const HeartbeatConfigSchema: Schema.Struct<{ intervalMs: typeof Schema.Number; policy: Schema.optionalWith, { default: () => "adaptive"; }>; instruction: Schema.optional; maxConsecutiveSkips: Schema.optionalWith number; }>; }>; type HeartbeatConfig = typeof HeartbeatConfigSchema.Type; declare const CronEntrySchema: Schema.Struct<{ schedule: typeof Schema.String; instruction: typeof Schema.String; agentId: Schema.optional; priority: Schema.optionalWith, { default: () => "normal"; }>; timezone: Schema.optional; enabled: Schema.optionalWith true; }>; }>; type CronEntry = typeof CronEntrySchema.Type; declare const WebhookConfigSchema: Schema.Struct<{ path: typeof Schema.String; adapter: typeof Schema.String; secret: Schema.optional; events: Schema.optional>; /** When true (default), a route with no secret is refused (fail-closed, F11). */ requireSignature: Schema.optional; }>; type WebhookConfig = typeof WebhookConfigSchema.Type; declare const PolicyConfigSchema: Schema.Struct<{ dailyTokenBudget: Schema.optionalWith number; }>; maxActionsPerHour: Schema.optionalWith number; }>; heartbeatPolicy: Schema.optionalWith, { default: () => "adaptive"; }>; mergeWindowMs: Schema.optionalWith number; }>; requireApprovalFor: Schema.optional>; }>; type PolicyConfig = typeof PolicyConfigSchema.Type; interface ChannelAccessConfig { readonly policy: "allowlist" | "blocklist" | "open"; readonly allowedSenders?: readonly string[]; readonly blockedSenders?: readonly string[]; readonly unknownSenderAction?: "skip" | "escalate"; readonly replyToUnknown?: string; } declare const GatewayConfigSchema: Schema.Struct<{ timezone: Schema.optionalWith string; }>; heartbeat: Schema.optional, { default: () => "adaptive"; }>; instruction: Schema.optional; maxConsecutiveSkips: Schema.optionalWith number; }>; }>>; crons: Schema.optional; priority: Schema.optionalWith, { default: () => "normal"; }>; timezone: Schema.optional; enabled: Schema.optionalWith true; }>; }>>>; webhooks: Schema.optional; events: Schema.optional>; /** When true (default), a route with no secret is refused (fail-closed, F11). */ requireSignature: Schema.optional; }>>>; policies: Schema.optional number; }>; maxActionsPerHour: Schema.optionalWith number; }>; heartbeatPolicy: Schema.optionalWith, { default: () => "adaptive"; }>; mergeWindowMs: Schema.optionalWith number; }>; requireApprovalFor: Schema.optional>; }>>; port: Schema.optionalWith number; }>; accessControl: Schema.optional, { default: () => "allowlist"; }>; allowedSenders: Schema.optional>; blockedSenders: Schema.optional>; unknownSenderAction: Schema.optionalWith, { default: () => "skip"; }>; replyToUnknown: Schema.optional; /** How incoming channel messages are handled. Default: 'chat'. */ mode: Schema.optionalWith, { default: () => "chat"; }>; /** Days of inactivity before a persisted chat session is pruned. Default: 30. */ sessionTtlDays: Schema.optionalWith number; }>; }>>; }>; type GatewayConfig = typeof GatewayConfigSchema.Type; interface GatewayState { readonly isRunning: boolean; readonly lastExecutionAt: Date | null; readonly consecutiveHeartbeatSkips: number; readonly tokensUsedToday: number; readonly actionsThisHour: number; readonly hourWindowStart: Date; readonly dayWindowStart: Date; readonly pendingEvents: readonly GatewayEvent[]; } declare const initialGatewayState: () => GatewayState; interface GatewayStats { readonly heartbeatsFired: number; readonly heartbeatsSkipped: number; readonly webhooksReceived: number; readonly webhooksProcessed: number; readonly webhooksMerged: number; readonly cronsExecuted: number; readonly channelMessages: number; readonly totalTokensUsed: number; readonly actionsSuppressed: number; readonly actionsEscalated: number; } declare const GatewayError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "GatewayError"; } & Readonly; declare class GatewayError extends GatewayError_base<{ readonly message: string; readonly cause?: unknown; }> { } declare const GatewayConfigError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "GatewayConfigError"; } & Readonly; declare class GatewayConfigError extends GatewayConfigError_base<{ readonly message: string; readonly field?: string; }> { } declare const WebhookValidationError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "WebhookValidationError"; } & Readonly; declare class WebhookValidationError extends WebhookValidationError_base<{ readonly message: string; readonly source: string; readonly statusCode?: number; }> { } declare const WebhookTransformError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "WebhookTransformError"; } & Readonly; declare class WebhookTransformError extends WebhookTransformError_base<{ readonly message: string; readonly source: string; readonly payload?: unknown; }> { } declare const PolicyViolationError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "PolicyViolationError"; } & Readonly; declare class PolicyViolationError extends PolicyViolationError_base<{ readonly message: string; readonly policy: string; readonly eventId: string; }> { } declare const SchedulerError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "SchedulerError"; } & Readonly; declare class SchedulerError extends SchedulerError_base<{ readonly message: string; readonly schedule?: string; }> { } declare const ChannelConnectionError_base: new = {}>(args: effect_Types.Equals extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => effect_Cause.YieldableError & { readonly _tag: "ChannelConnectionError"; } & Readonly; declare class ChannelConnectionError extends ChannelConnectionError_base<{ readonly message: string; readonly platform: string; }> { } interface SchedulingPolicy { readonly _tag: string; readonly priority: number; readonly evaluate: (event: GatewayEvent, state: GatewayState) => Effect.Effect; } /** * Evaluate all policies in priority order (lower = earlier). * First non-null decision wins. Default: execute. */ declare const evaluatePolicies: (policies: readonly SchedulingPolicy[], event: GatewayEvent, state: GatewayState) => Effect.Effect; declare const PolicyEngine_base: Context.TagClass Effect.Effect; readonly addPolicy: (policy: SchedulingPolicy) => Effect.Effect; readonly getPolicies: () => Effect.Effect; }>; declare class PolicyEngine extends PolicyEngine_base { } declare const PolicyEngineLive: (initialPolicies?: SchedulingPolicy[]) => Layer.Layer; /** * Create a heartbeat GatewayEvent. */ declare const createHeartbeatEvent: (agentId: string, instruction?: string) => GatewayEvent; /** * Create a cron-triggered GatewayEvent. */ declare const createCronEvent: (agentId: string, entry: CronEntry) => GatewayEvent; interface SchedulerConfig { readonly agentId?: string; readonly timezone?: string; readonly heartbeat?: HeartbeatConfig; readonly crons?: readonly CronEntry[]; } declare const SchedulerService_base: Context.TagClass Effect.Effect; /** Check all enabled cron entries against `now` and return any that fire. */ readonly checkCrons: (now: Date) => Effect.Effect; /** Emit a single heartbeat event using the configured instruction. */ readonly emitHeartbeat: () => Effect.Effect; }>; declare class SchedulerService extends SchedulerService_base { } declare const SchedulerServiceLive: (config: SchedulerConfig, bus?: EventBusLike) => Layer.Layer; interface CronExpression { readonly minutes: readonly number[]; readonly hours: readonly number[]; readonly daysOfMonth: readonly number[]; readonly months: readonly number[]; readonly daysOfWeek: readonly number[]; } /** * Parse a 5-field cron expression string. * Returns null if the expression is invalid. * * Fields: minute(0-59) hour(0-23) day-of-month(1-31) month(1-12) day-of-week(0-6) */ declare const parseCron: (expression: string) => CronExpression | null; /** * Check if a cron expression should fire at a given date. * Optional timezone parameter converts to local time before checking. */ declare const shouldFireAt: (cron: CronExpression, date: Date, timezone?: string) => boolean; /** * Adaptive heartbeat policy — skip heartbeat ticks when agent state hasn't changed. * * Only applies to events with source === "heartbeat". Three modes: * - "always" — never skip heartbeats * - "adaptive" — skip when idle (no pending events, has executed before) * - "conservative" — only fire when pending events exist * * Force execution after maxConsecutiveSkips regardless of mode. */ declare const createAdaptiveHeartbeatPolicy: (options?: { mode?: HeartbeatPolicy; maxConsecutiveSkips?: number; }) => SchedulingPolicy; /** * Cost budget policy — block events when daily token budget is exhausted. * * Critical priority events bypass the budget check entirely. * When budget is exhausted, the configurable `onExhausted` action determines * whether events are queued, skipped, or escalated. */ declare const createCostBudgetPolicy: (options: { dailyTokenBudget: number; onExhausted?: "queue" | "skip" | "escalate"; }) => SchedulingPolicy; /** * Rate limit policy — cap autonomous executions per hour. * * Critical priority events bypass the rate limit. * When the limit is exceeded, events are queued. */ declare const createRateLimitPolicy: (options: { maxPerHour: number; }) => SchedulingPolicy; /** * Event merging policy — batch events of the same category. * * If pending events share the same merge key as the incoming event, * return a merge decision so they can be batched together. * Default merge key: `${event.source}:${event.metadata.category ?? "default"}` */ declare const createEventMergingPolicy: (options?: { mergeKey?: (event: GatewayEvent) => string; }) => SchedulingPolicy; /** * Access control policy — gate channel messages based on sender identity. * * Priority 5 (evaluated before all other policies). * Only applies to events with source === "channel". * * Modes: * - "allowlist" — only listed senders pass through * - "blocklist" — listed senders are blocked, all others pass * - "open" — all senders pass (existing guardrails still apply) */ declare const createAccessControlPolicy: (config: ChannelAccessConfig) => SchedulingPolicy; interface WebhookRequest { readonly body: string; readonly headers: Record; } interface WebhookAdapter { readonly source: string; readonly validateSignature: (req: WebhookRequest, secret: string) => Effect.Effect; readonly transform: (req: WebhookRequest) => Effect.Effect; readonly classify: (event: GatewayEvent) => string; } interface RegisterAdapterOptions { /** * Require a verified signature. Defaults to true: a route registered without a * secret is refused, so an unauthenticated webhook cannot impersonate a sender. * Set false to explicitly allow a secretless route. */ readonly requireSignature?: boolean; } declare const WebhookService_base: Context.TagClass Effect.Effect; readonly registerAdapter: (path: string, adapter: WebhookAdapter, secret?: string, options?: RegisterAdapterOptions) => Effect.Effect; }>; declare class WebhookService extends WebhookService_base { } declare const WebhookServiceLive: (configs?: readonly WebhookConfig[]) => Layer.Layer; declare const createGitHubAdapter: () => WebhookAdapter; interface GenericAdapterOptions { /** Header name that carries the signature (default: "x-webhook-signature") */ readonly signatureHeader?: string; /** HMAC algorithm (default: "sha256") */ readonly algorithm?: string; /** Source name for metadata (default: "generic") */ readonly sourceName?: string; } declare const createGenericAdapter: (options?: GenericAdapterOptions) => WebhookAdapter; /** * Route a gateway event through the policy chain and return the decision. * Pure function — no side effects, no EventBus publishing. */ declare const routeEvent: (event: GatewayEvent, policies: readonly SchedulingPolicy[]) => Effect.Effect; /** * Route a gateway event through the policy chain, publishing EventBus events * for observability: * - `GatewayEventReceived` on receipt * - `ProactiveActionSuppressed` when policy decides to skip */ declare const routeEventWithBus: (event: GatewayEvent, policies: readonly SchedulingPolicy[], bus: EventBusLike) => Effect.Effect; interface GatewayStatus { readonly isRunning: boolean; readonly stats: GatewayStats; readonly uptime: number; readonly state: GatewayState; } declare const GatewayService_base: Context.TagClass Effect.Effect; readonly status: () => Effect.Effect; readonly updateTokensUsed: (tokens: number) => Effect.Effect; }>; declare class GatewayService extends GatewayService_base { } declare const GatewayServiceLive: (config: Partial, bus?: EventBusLike) => Layer.Layer; export { type ChannelAccessConfig, ChannelConnectionError, type CronEntry, CronEntrySchema, type CronExpression, type EventBusLike, type EventPriority, EventPrioritySchema, type GatewayConfig, GatewayConfigError, GatewayConfigSchema, GatewayError, type GatewayEvent, type GatewayEventSource, GatewayEventSourceSchema, GatewayService, GatewayServiceLive, type GatewayState, type GatewayStats, type GatewayStatus, type HeartbeatConfig, HeartbeatConfigSchema, type HeartbeatPolicy, HeartbeatPolicySchema, type PolicyConfig, PolicyConfigSchema, type PolicyDecision, PolicyEngine, PolicyEngineLive, PolicyViolationError, SchedulerError, SchedulerService, SchedulerServiceLive, type SchedulingPolicy, type TaggedEventLike, type WebhookAdapter, type WebhookConfig, WebhookConfigSchema, type WebhookRequest, WebhookService, WebhookServiceLive, WebhookTransformError, WebhookValidationError, createAccessControlPolicy, createAdaptiveHeartbeatPolicy, createCostBudgetPolicy, createCronEvent, createEventMergingPolicy, createGenericAdapter, createGitHubAdapter, createHeartbeatEvent, createRateLimitPolicy, evaluatePolicies, initialGatewayState, parseCron, routeEvent, routeEventWithBus, shouldFireAt };