import { type ActionAutomationContext, type ActionCaller } from "../action.js"; import type { AgentEngine } from "../agent/engine/types.js"; import { type ActionEntry } from "../agent/production-agent.js"; import { type AutomationExecutionIdentity } from "../automations/service.js"; import { type Resource } from "../resources/store.js"; import { type RequestContext } from "../server/request-context.js"; import { CONFIG_INVALID_ERROR_CODE, OWNER_MISSING_ERROR_CODE, type AutomationFailure } from "./automation-outcome.js"; import { type AutomationResume } from "./automation-recovery.js"; import { type AutomationTerminalEvent } from "./automation-terminal-error.js"; import { type JobFrontmatter } from "./frontmatter.js"; import { type StartAutomationRunOptions } from "./run-history.js"; export declare const BACKGROUND_RUN_HARD_TIMEOUT_MS: number; export declare class BackgroundAutomationRunError extends Error { readonly errorCode: string; readonly deliveryNote?: string; constructor(message: string, errorCode: string, deliveryNote?: string); } export interface BackgroundAutomationContext { name: string; meta: JobFrontmatter; body: string; resource: Resource; } export interface BackgroundAutomationDeps { getActions: (automation?: BackgroundAutomationContext) => Record | Promise>; getSystemPrompt: (owner: string) => Promise; getWorkspaceAppContext?: (input: { request: string; ownerEmail: string; orgId?: string; appId?: string; workspaceAppsEnabled: boolean; }) => Promise; getInitialToolNames?: (automation?: BackgroundAutomationContext) => string[] | undefined; engine?: AgentEngine; apiKey?: string; model?: string; appId?: string; } export interface BackgroundAutomationRunOptions { resume?: AutomationResume; automation: BackgroundAutomationContext; ownerEmail: string; orgId?: string; prompt: string; threadTitle: string; runIdPrefix: string; usageLabel: string; usageRefId?: string; requestContext?: Omit; actionCaller?: ActionCaller; actionAutomation?: ActionAutomationContext; historyId?: string; assertCanStart?: () => Promise; hardTimeoutMs?: number; hardDeadlineAt?: number; noProgressTimeoutMs?: number; backgroundNoProgressTimeoutMs?: number; /** A run the owner asked for: it records its cause but never pauses the automation. */ manual?: boolean; /** The event this run handles; retries of one event move the streak once. */ eventId?: string; } interface BackgroundAutomationRunOutput { responseText: string; runId: string; } export type BackgroundAutomationRunResult = BackgroundAutomationRunOutput & ({ status: "success"; } | { status: "skipped"; reason: string; }); /** * `owner_missing` is permanent (the user or membership is gone); * `owner_unverifiable` means the lookup itself failed and must be retried, not * recorded as the owner being gone. */ export type AutomationIdentityFailureCode = typeof OWNER_MISSING_ERROR_CODE | "owner_unverifiable" | typeof CONFIG_INVALID_ERROR_CODE; export type AutomationIdentityValidation = { ok: true; } | { ok: false; reason: string; code: AutomationIdentityFailureCode; }; export type BackgroundAutomationIdentityResult = { ok: true; identity: AutomationExecutionIdentity; } | { ok: false; reason: string; code?: AutomationIdentityFailureCode; }; export declare function validateAutomationRunIdentity(ownerEmail: string, orgId?: string): Promise; export declare function resolveBackgroundAutomationIdentity(automation: BackgroundAutomationContext): Promise; export declare function isBackgroundAutomationRunActive(meta: Pick, now?: Date): boolean; export declare function backgroundRunCutOffReason(run: { events?: readonly { event: { type: string; reason?: string; }; }[]; }): string | null; /** * The cause a failed run recorded for itself. Without this, a run that ended * on `missing_credentials` surfaced as the generic "ended with status: * errored" and the owner never learned why. * * A run that yielded to a connection request is a failed run even though it * ended on a clean `done`: nobody is there to answer the request. */ export declare function backgroundRunTerminalError(run: { events?: readonly { event: AutomationTerminalEvent; }[]; }): { message: string; errorCode?: string; } | null; export declare function startBackgroundAutomationHistory(automation: BackgroundAutomationContext, ownerEmail: string, orgId?: string, appId?: string, options?: StartAutomationRunOptions): Promise; export declare function runBackgroundAutomation(options: BackgroundAutomationRunOptions, deps: BackgroundAutomationDeps): Promise; interface JobRunnerRunOptions { runnerId: string; automation: BackgroundAutomationContext; ownerEmail: string; orgId?: string; historyId?: string; requestContext?: Omit; assertCanStart?: () => Promise; resume?: AutomationResume; manual?: boolean; } /** * Runs a job's registered runner in place of the agent loop and settles its * history row exactly once, with the same failure alert and pause message an * agent run gets. */ export declare function runJobRunner(options: JobRunnerRunOptions): Promise; /** * Whether the automation's run identity has a usable LLM credential right now, * without starting a run. The scheduler asks this to resume an automation it * paused for `missing_credentials` as soon as the credential exists. */ export declare function checkBackgroundAutomationCredentials(identity: { ownerEmail: string; orgId?: string; orgScope?: "personal"; defaultAgentEngineScope?: "deployment"; }, deps: BackgroundAutomationDeps, automationModel?: string): Promise<{ ok: true; engine: AgentEngine; model: string; } | { ok: false; failure: AutomationFailure; }>; export {};