import { type JsonValue } from "../kernel/json.js"; import { type Database } from "../data/database.js"; import { type AgentHistoryEvent } from "./events.js"; import type { AgentMemberConfig, AgentPromptSnapshot } from "./types.js"; import { type AgentInstance } from "./instance.js"; export interface PreparedRuntimeInput { prompt: string; source?: "room_mention" | "private_instruction" | "system"; trigger: string; replySources?: string[]; } export interface AgentAdmission { memberId: string; sourceRef: string; idempotencyKey: string; input: PreparedRuntimeInput; replyExpected: boolean; } export interface AgentAdmissionReceipt { enqueued: boolean; inputId: number; interrupt: boolean; } export interface AgentWakeReceipt { inputId: number; interrupt: boolean; } export type QueuedInputStatus = "pending" | "dispatched" | "settled" | "interrupted" | "uncertain"; export interface QueuedInput { id: number; memberId: string; idempotencyKey: string; sourceRef: string | null; payload: JsonValue; trigger: string; replyExpected: boolean; placement: "front" | "tail"; status: QueuedInputStatus; createdAt: number; dispatchedAt: number | null; endedAt: number | null; dispatchToken: string | null; executionAttemptId: string | null; outcome: "completed" | "failed" | "cancelled" | null; result: JsonValue; diagnosis: string | null; } export declare function readQueuedInput(db: Database, id: number, memberId: string): QueuedInput | undefined; /** Agent-owned half of chat admission. Caller owns the outer synchronous transaction. */ export declare function acceptAgentAdmission(db: Database, admission: AgentAdmission): AgentAdmissionReceipt; /** Internal control/continuation input; chat facts are never invented. */ export declare function acceptControlInput(sourceRef: string | null, memberId: string, input: PreparedRuntimeInput, replyExpected: boolean, placement?: "front" | "tail", onAccepted?: () => void): { input: QueuedInput; accepted: boolean; }; export declare function runtimeInputPayload(input: QueuedInput): PreparedRuntimeInput; export declare function runtimeReplySources(inputs: readonly QueuedInput[]): string[]; export declare function pendingRuntimeInputSources(memberId: string): Array; export declare const pendingRuntimeInputOwners: typeof pendingRuntimeInputSources; export declare function memberPendingInputCount(memberId: string): number; export declare function queueDepth(instance: AgentInstance): number; export declare function claimRuntimeInputs(inputs: readonly QueuedInput[], attemptId: string, dispatchToken: string): void; export declare function finishRuntimeInputs(inputs: readonly QueuedInput[], token: string, outcome: "completed" | "failed" | "cancelled", diagnosis: string): void; export declare function cancelPendingRuntimeInputs(memberId: string, diagnosis: string, sourceRef?: string | null): number; export declare function recoverRuntimeInputState(): void; export declare function hasInputPumps(): boolean; export declare function invalidateInputScope(memberId: string): void; export declare function waitForInputSettlement(input: QueuedInput, operation: Promise): Promise; export interface SchedulerServices { buildSession(memberId: string): Promise; memberConfig(memberId: string): AgentMemberConfig | null; authorizeExecution(memberId: string, sourceRef: string | null): boolean; postSystemNotice(sourceRef: string, text: string): void; emitEvent(sourceRef: string | null, memberId: string, event: AgentHistoryEvent): void; loadProfileSources(memberId: string): { agentName: string; compiled: AgentPromptSnapshot; }; applyPendingControls(instance: AgentInstance, trigger: string): void; interruptAccepted(instance: AgentInstance, sourceRef: string): void; flushPendingReload(instance: AgentInstance): void; hasPendingReply(db: Database, memberId: string, sourceRef: string, replySources: string[]): boolean; dismissReplies(db: Database, memberId: string, sourceRef: string | null | undefined, diagnosis: string, disposition: "failed" | "cancelled" | "silent" | "continuation-exhausted"): void; } export declare function configureScheduler(next: SchedulerServices): void; export declare function wakeAgent(memberId: string, receipt: AgentWakeReceipt): Promise; export declare function resumePendingRuntimeInputs(): void; export declare function drainQueuedInputsAsPrompt(instance: AgentInstance, trigger: string): boolean; export declare function pumpRuntimeInputs(memberId: string): Promise; export interface ExecutionAttempt { id: string; memberId: string; sourceRef: string | null; operation: "input" | "session-create" | "session-fork" | "external"; externalReference: string | null; status: "prepared" | "dispatched" | "acknowledged" | "interrupted"; startedAt: number; dispatchedAt: number | null; endedAt: number | null; diagnosis: string | null; } export declare class SdkExecutionAttempt { readonly id: string; private readonly memberId; private readonly db; private uncertainty; private interrupted; constructor(id: string, memberId: string, db: Database); noteUncertain(reason: string): void; interrupt(reason: string): void; settle(): void; fail(error: unknown): never; run(call: () => Promise): Promise; } export declare function dispatchSdkExecution(memberId: string, sourceRef: string | null, operation: ExecutionAttempt["operation"], externalReference: string, beforeDispatch?: (attemptId: string) => void): SdkExecutionAttempt; /** * THE one instance event subscription. Room and DM instances share this wiring; * the only scope difference is the notification address: `sourceRef` is the bare * room id for room scope and "dm:" for DM scope, and postMessage * routes by that prefix (room store vs member-owned DM store). Failure notices * therefore reach the user in both UIs (G1), and lifecycle handling (length * continuation, compaction, unexpected exit, queued-input draining) cannot * drift between scopes. */ export declare function recordMemberRuntimeEvent(sourceRef: string | null, memberId: string, event: AgentHistoryEvent): void; export declare function wireInstanceEvents(instance: AgentInstance): void; /** Destructive member cleanup must outlive the final dispatcher settlement. */ export declare function settleMemberInputPump(memberId: string): Promise; //# sourceMappingURL=scheduler.d.ts.map