import { type Database } from "./database.js"; export type ScheduledTaskBlockerState = "clear" | "notified" | "paused"; export type ScheduledTaskBlockerRun = { id: string; status: string; error: string | null; admissionRefusal: { reason: string; retryable: boolean; } | null; /** Present when a pinned connector account could not be selected. */ admissionDiagnostic: unknown; sessionId: string | null; createdAt: Date; }; export type ScheduledTaskBlockerReview = { reviewedRunId: string | null; state: ScheduledTaskBlockerState; reason: string | null; message: string | null; blockedRunId: string | null; blockedSince: Date | null; noticeSessionId: string | null; noticeKey: string | null; noticePending: "post" | "withdraw" | null; }; export type ScheduledTaskBlockerFacts = { task: { id: string; accountId: string; workspaceId: string; name: string; status: string; deleted: boolean; runMode: string; reusableSessionId: string | null; updatedAt: Date; /** The stored schedule spec, unvalidated: its cadence decides when to tell the owner. */ schedule: unknown; /** * The automation's event run policy, or null without event triggers. * Repeating triggers keep running after the schedule's last run; a * run-once automation has none left once it completed. */ events: { once: boolean; completed: boolean; } | null; }; review: ScheduledTaskBlockerReview | null; /** Newest first: scheduled and event (not manual) agent-turn runs only. */ runs: ScheduledTaskBlockerRun[]; }; export type ScheduledTaskBlockerNotice = { sessionId: string; key: string; /** A validated `session.notification.posted` payload. */ payload: Record; }; export type ScheduledTaskBlockerDecision = /** Nothing to report; remember the run so it is not reviewed again. */ { kind: "none"; reviewedRunId: string | null; } | { kind: "block"; state: "notified" | "paused"; reason: string; message: string; blockedRunId: string; blockedSince: Date; reviewedRunId: string; notice: ScheduledTaskBlockerNotice | null; } /** The blocker is gone or a person acted: withdraw any notice. */ | { kind: "clear"; reviewedRunId: string | null; }; export declare const SCHEDULED_TASK_BLOCKER_REVIEW_RUNS = 20; /** Identity-only system inventory; every mutation is tenant-scoped and rechecked. */ export declare function listScheduledTaskBlockerReviews(db: Database, limit?: number): Promise<{ id: string; workspace_id: string; }[]>; /** * Review one schedule under its task lock (the lock run admission also takes), * so a decision never races a freshly accepted run or a concurrent edit. * Returns whether the schedule was paused and whether a notice awaits delivery. */ export declare function reviewScheduledTaskBlockers(db: Database, workspaceId: string, taskId: string, decide: (facts: ScheduledTaskBlockerFacts) => ScheduledTaskBlockerDecision): Promise<{ paused: boolean; noticePending: boolean; }>; export type PendingScheduledTaskBlockerNotice = { sessionId: string; key: string; pending: "post" | "withdraw"; payload: Record | null; }; export declare function getPendingScheduledTaskBlockerNotice(db: Database, workspaceId: string, taskId: string): Promise; /** * Record that exactly this pending notice was delivered. A post keeps its * session and key so the notice can be withdrawn later; a withdrawal forgets them. * A review that changed meanwhile is left for its own delivery. */ export declare function settleScheduledTaskBlockerNotice(db: Database, workspaceId: string, taskId: string, delivered: Pick): Promise; export type ScheduledTaskBlockerSummary = { state: "notified" | "paused"; reason: string; message: string; runId: string; since: string; }; /** * The current blocker of each task, for display. A recorded self-pause shows * only while the task is still paused, and a notice only while it is active. */ export declare function getScheduledTaskBlockers(db: Database, workspaceId: string, taskIds: readonly string[]): Promise>;