import { type InferencePressureCoordinator } from "../_types/orchestrator/inference-pressure.js"; export declare const TELEGRAM_COGNITION_AUTHORITY: "internal_cognition_only"; export type TelegramCognitionJobKind = "social_state" | "memory" | "reflection" | "cognition_batch"; export type TelegramCognitionQueueState = "open" | "closing" | "closed"; export type TelegramCognitionAdmissionStatus = "accepted" | "deduplicated" | "rejected_capacity" | "rejected_pressure" | "rejected_closed"; export type TelegramCognitionJobStatus = "succeeded" | "failed" | "timed_out" | "cancelled" | "preempted" | "rejected_capacity" | "rejected_pressure" | "rejected_closed"; export type TelegramCognitionFailureKind = "timeout" | "capacity_refusal" | "provider_refusal"; /** * Content-free failure evidence passed between inference transport, the * bounded cognition queue, and the room sweep. Decisions use fixed transport * contracts and exception types. They never inspect user or model text. */ export interface TelegramCognitionFailureReceipt { readonly schema: "omnius.telegram-cognition-failure.v1"; readonly kind: TelegramCognitionFailureKind; readonly retryable: boolean; readonly status?: number; readonly reasonCode: string; readonly retryAfterMs?: number; } export declare class TelegramCognitionTerminalFailure extends Error { readonly receipt: TelegramCognitionFailureReceipt; constructor(receipt: TelegramCognitionFailureReceipt); } export declare function telegramCognitionFailureFromInferenceError(error: unknown): TelegramCognitionFailureReceipt | null; export interface TelegramCognitionJobContext { /** This queue has no Telegram send/reply authority. */ readonly authority: typeof TELEGRAM_COGNITION_AUTHORITY; readonly jobId: string; readonly scopeKey: string; readonly kind: TelegramCognitionJobKind; readonly signal: AbortSignal; readonly deadlineAtMs: number; } export interface TelegramCognitionJob { jobId?: string; /** Jobs with the same scope never start concurrently. */ scopeKey: string; /** Deduplication is scoped: one active key per scope. */ dedupeKey: string; kind: TelegramCognitionJobKind; /** Overrides the queue default for this job. */ timeBudgetMs?: number; execute: (context: TelegramCognitionJobContext) => void | Promise; } export interface TelegramCognitionJobOutcome { jobId: string; scopeKey: string; dedupeKey: string; kind: TelegramCognitionJobKind; status: TelegramCognitionJobStatus; enqueuedAtMs: number; startedAtMs?: number; finishedAtMs: number; queueWaitMs?: number; runDurationMs?: number; errorMessage?: string; failure?: TelegramCognitionFailureReceipt; } export interface TelegramCognitionEnqueueReceipt { admission: TelegramCognitionAdmissionStatus; jobId: string; scopeKey: string; dedupeKey: string; completion: Promise; } export interface TelegramCognitionQueueOptions { /** Maximum jobs that may execute concurrently across distinct scopes. */ maxConcurrentScopes: number; /** Maximum jobs waiting to start. Running jobs do not consume this bound. */ maxQueuedJobs: number; defaultTimeBudgetMs: number; /** Process-wide model pressure authority. Defaults to the shared authority. */ inferencePressureCoordinator?: InferencePressureCoordinator; } export interface TelegramCognitionQueueTotals { accepted: number; deduplicated: number; rejectedCapacity: number; rejectedPressure: number; rejectedClosed: number; started: number; succeeded: number; failed: number; timedOut: number; cancelled: number; preempted: number; } export interface TelegramCognitionQueueSnapshot { state: TelegramCognitionQueueState; maxConcurrentScopes: number; maxQueuedJobs: number; defaultTimeBudgetMs: number; queuedJobs: number; runningJobs: number; activeScopes: string[]; queuedByScope: Record; oldestQueuedAgeMs: number; totals: TelegramCognitionQueueTotals; } export interface TelegramCognitionCloseOptions { /** Cancel work that has not started. Default false: drain accepted work. */ cancelQueued?: boolean; /** Abort running work. Default false: let accepted work drain. */ cancelRunning?: boolean; reason?: string; } export declare class TelegramCognitionQueueValidationError extends Error { constructor(message: string); } /** * Bounded scheduler for post-delivery Telegram cognition. It serializes each * scope, admits multiple scopes up to a global cap, and contains every job * failure in a resolved outcome. The execution context intentionally carries * no visible-message delivery capability. * * Cancellation and time budgets use AbortSignal. An execute function must stop * external work when its signal aborts; JavaScript cannot forcibly terminate * an arbitrary closure that ignores cancellation. */ export declare class TelegramCognitionQueue { private readonly maxConcurrentScopes; private readonly maxQueuedJobs; private readonly defaultTimeBudgetMs; private readonly pressure; private readonly unsubscribePressure; private readonly pending; private readonly running; private readonly activeScopes; private readonly dedupe; private readonly jobsById; private readonly idleWaiters; private readonly totals; private state; private pumpScheduled; private nextJobSequence; private readonly scopeOrdinals; private nextScopeOrdinal; private lastStartedScopeOrdinal; constructor(options: TelegramCognitionQueueOptions); enqueue(job: TelegramCognitionJob): TelegramCognitionEnqueueReceipt; cancel(jobId: string, reason?: string): boolean; cancelScope(scopeKey: string, reason?: string): number; snapshot(): TelegramCognitionQueueSnapshot; waitForIdle(): Promise; close(options?: TelegramCognitionCloseOptions): Promise; private rejectedReceipt; private schedulePump; private pump; private nextPendingIndex; private start; private finish; private maybeResolveIdle; }