import type { AccountState } from "./accounts.js"; import type { SkillsSyncReport } from "./cloud/managed.js"; import type { DeliveryRecord } from "./delivery-log.js"; import type { HealthChange, HealthReport } from "./health.js"; import type { JobRecord } from "./jobs.js"; import type { Logger } from "./logger.js"; import type { JobAnswer, JobQuestion, ProgressEntry } from "./progress.js"; import type { RunnerReadiness } from "./readiness.js"; import type { Config, RunnerName } from "./config.js"; import type { SkipReason } from "./scheduler.js"; import type { ServerState } from "./server.js"; import type { SkillSource } from "./skills.js"; export interface EventMap { "server.started": { state: ServerState; }; "server.stopping": { reason: string; running: number; }; /** Every request to `/hooks/`, whatever became of it (see `DeliveryRecord.outcome`). */ "delivery.received": { delivery: DeliveryRecord; }; "job.queued": { job: JobRecord; }; "job.started": { job: JobRecord; }; /** A field was captured while the job runs (`pid`, `session_id`, `resume_command`). */ "job.updated": { job: JobRecord; fields: (keyof JobRecord)[]; }; /** A cancel request was accepted; `job.finished` follows once the process is gone. */ "job.cancelled": { job: JobRecord; state: "queued" | "running"; }; "job.finished": { job: JobRecord; }; /** The agent reported progress or a note (`progress.jsonl` grew). */ "job.progress": { job: JobRecord; entry: ProgressEntry; }; /** The agent asked a person something and is waiting (or finished saying a person must act). */ "job.waiting_human": { job: JobRecord; question: JobQuestion; }; /** A person answered: `live` reached the waiting agent, `resumed` started a new job continuing the session, `recorded` was only stored. */ "job.answered": { job: JobRecord; answer: JobAnswer; delivered: "live" | "resumed" | "recorded"; resume_job_id?: string; }; "schedule.registered": { skill: string; cron: string; timezone: string; next_due: string | null; }; "schedule.fired": { skill: string; slot: string; job: JobRecord; caught_up: boolean; }; "schedule.skipped": { skill: string; slot: string; reason: SkipReason; }; /** Noticed by the registry on `get()` / `list()` once it has been primed by a first `list()`. `definition_sha256` is the content hash of the skill as it now is (null when it was removed or has no definition), so the cloud knows whether it already holds the text. */ "skill.changed": { name: string; action: "added" | "changed" | "removed"; source: SkillSource; definition_sha256: string | null; }; /** The cloud-managed skills of this machine were reconciled with what Skillhook Cloud assigns to it (on connect, every snapshot interval, or on `skills.sync`). */ "skills.synced": SkillsSyncReport; /** A fresh health report whose checks differ from the previous one (or the first report of that flavour). */ "health.changed": { report: HealthReport; changed: HealthChange[]; }; /** A runner became usable or stopped being so (installed, logged in), as the readiness check before jobs sees it. */ "runners.changed": { runner: RunnerName; readiness: RunnerReadiness; previous?: RunnerReadiness; }; /** An account (`skillhook accounts`) became usable or stopped being so (logged in, logged out, expired, token missing), as the check before jobs sees it. */ "account.changed": { account: string; runner: "claude" | "codex"; readiness: RunnerReadiness; previous?: RunnerReadiness; }; /** What runs taught about an account changed: it hit a usage limit (`limited`), is usable again (`recovered`), failed to authenticate (`auth_failed`) or its usage was read (`usage`). */ "account.updated": { account: string; reason: "limited" | "recovered" | "auth_failed" | "usage"; state: AccountState; }; /** `skillhook.json` changed and the server re-read it: `applied` took effect now, `restart_required` at the next start. */ "config.changed": { changed: (keyof Config)[]; applied: (keyof Config)[]; restart_required: (keyof Config)[]; pending_restart: (keyof Config)[]; config: Config; }; } export type EventType = keyof EventMap; export declare const EVENT_TYPES: EventType[]; export interface SkillhookEvent { /** Increases by one per event in this process; `GET /events` sends it as the SSE id. */ seq: number; type: K; at: string; data: EventMap[K]; } export type EventListener = (event: SkillhookEvent) => void; type AnyListener = (event: SkillhookEvent) => void; export declare class Events { private logger?; private readonly byType; private readonly any; private counter; constructor(logger?: Logger | undefined); setLogger(logger: Logger): void; emit(type: K, data: EventMap[K]): SkillhookEvent; /** Subscribes to one event type; returns the unsubscribe function. */ on(type: K, fn: EventListener): () => void; once(type: K, fn: EventListener): () => void; /** Subscribes to every event (what `GET /events` and the cloud link use). */ onAny(fn: AnyListener): () => void; listenerCount(type?: EventType): number; /** The seq of the last event emitted (0 before the first). */ seq(): number; private call; } export {};