import type { ActionCaller, ActionRunContext } from "../action.js"; import { type JobFrontmatter } from "../jobs/frontmatter.js"; import { type Resource } from "../resources/store.js"; import { type ReasoningEffort } from "../shared/reasoning-effort.js"; import { type AccessibleAutomation } from "./access.js"; import { type CompleteAutomationSharingState } from "./sharing-store.js"; export type AutomationScope = "personal" | "organization"; export declare const DEFAULT_AUTOMATION_SCHEDULE = "0 * * * *"; export interface AutomationActor { userEmail: string; caller?: ActionCaller; networkProtocol?: ActionRunContext["networkProtocol"]; automation?: ActionRunContext["automation"]; orgId?: string | null; appId?: string | null; } export interface AutomationDefinition { resource: Resource; name: string; scope: AutomationScope; meta: JobFrontmatter & { triggerType: "schedule" | "event" | "manual" | "webhook"; mode: "agentic" | "deterministic"; }; body: string; canUpdate: boolean; webhookPath?: string; } /** The updated definition plus what the write changed, for change cards. */ export interface AutomationUpdateResult extends AutomationDefinition { /** Whether the persisted automation differs from the pre-update file. */ changed: boolean; /** The enabled value the file had before the update. */ previouslyEnabled: boolean; /** The enabled value the caller asked for, when it asked for one. */ requestedEnabled?: boolean; } export interface AccessibleAutomationDefinition extends AccessibleAutomation { scope: AutomationScope; /** Compatibility alias for callers not yet migrated to capabilities.canEdit. */ canUpdate: boolean; webhookPath?: string; } export interface AutomationDelivery { originScopeId?: string; platform?: string; destination?: string; threadRef?: string; tenantId?: string; } export interface DefineAutomationInput { name: string; scope: AutomationScope; triggerType: "schedule" | "event" | "manual" | "webhook"; body: string; enabled?: boolean; schedule?: string; timezone?: string; event?: string; condition?: string; domain?: string; delegatedPolicyId?: string; model?: string; reasoningEffort?: ReasoningEffort; executionHostId?: string; executionEngine?: string; executionCwd?: string; mcpTools?: unknown; delivery?: AutomationDelivery; sharing?: CompleteAutomationSharingState; acknowledgeExternalCollaborators?: boolean; } export type DefinedAutomation = Omit & { resourceId: string; }; export interface UpdateAutomationInput { resourceId?: string; name?: string; scope?: AutomationScope; triggerType?: "schedule" | "event" | "manual" | "webhook"; enabled?: boolean; body?: string; event?: string; condition?: string | null; delegatedPolicyId?: string | null; schedule?: string; timezone?: string; model?: string | null; reasoningEffort?: ReasoningEffort | null; executionHostId?: string | null; executionEngine?: string | null; executionCwd?: string | null; mcpTools?: unknown; sharing?: CompleteAutomationSharingState; acknowledgeExternalCollaborators?: boolean; } export declare function canUpdateAutomationResource(actorInput: AutomationActor, resource: Resource): Promise; export declare function canQueueAutomationRunNow(actorInput: AutomationActor, resource: Resource, scope: AutomationScope, additionalJobAppIds?: readonly string[]): Promise; export declare function listAccessibleAutomationDefinitions(actorInput: AutomationActor): Promise; /** * Scoped explicit-only compatibility wrapper. New list consumers should use * listAccessibleAutomationDefinitions so shared and legacy rows are not split * into parallel authorization paths. */ export declare function listAutomationDefinitions(actorInput: AutomationActor, scope: AutomationScope): Promise; export declare function defineAutomation(actorInput: AutomationActor, input: DefineAutomationInput): Promise; export declare function updateAutomation(actorInput: AutomationActor, input: UpdateAutomationInput): Promise; export type DeleteAutomationInput = { resourceId: string; } | { scope: AutomationScope; name: string; }; export declare function deleteAutomation(actorInput: AutomationActor, scopeOrInput: AutomationScope | DeleteAutomationInput, compatibilityName?: string): Promise; export interface AutomationExecutionIdentity { userEmail: string; orgId?: string; orgScope?: "personal"; defaultAgentEngineScope?: "deployment"; eventOwner: string; } /** * `code` says whether the failure is permanent: `owner_missing` (the creator * or their membership is gone) and `config_invalid` (the stored identity can * never resolve) will not heal on their own, so callers disable the * automation instead of re-checking forever. */ export type AutomationExecutionIdentityResult = { ok: true; identity: AutomationExecutionIdentity; } | { ok: false; reason: string; code?: "owner_missing" | "owner_unverifiable" | "config_invalid"; }; /** * What the built-in `"user"` table says about an account. Deployments whose * sessions come from a custom `getSession` have the table but none of their * users in it, so a miss there is `untracked`, never proof of deletion. */ export declare function lookupOwnerAccount(email: string): Promise<"exists" | "missing" | "untracked">; export declare function resolveAutomationExecutionIdentity(resourceOwner: string, meta: JobFrontmatter): Promise; export declare function automationMatchesEventOwner(identity: AutomationExecutionIdentity, eventOwner: string | undefined): boolean;