// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../resource'; import { isRequestOptions } from '../../core'; import * as Core from '../../core'; import * as AutomationsAPI from './automations'; import * as OwnedByAPI from './owned-by'; import * as RelatedToAPI from './related-to'; import * as TemplatesAPI from './templates'; export class Automations extends APIResource { ownedBy: OwnedByAPI.OwnedBy = new OwnedByAPI.OwnedBy(this._client); relatedTo: RelatedToAPI.RelatedTo = new RelatedToAPI.RelatedTo(this._client); templates: TemplatesAPI.Templates = new TemplatesAPI.Templates(this._client); /** * Update Automation */ create(id: string, params: AutomationCreateParams, options?: Core.RequestOptions): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.put(`/api/automations/${id}`, { body, ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Read Automation */ retrieve( id: string, params?: AutomationRetrieveParams, options?: Core.RequestOptions, ): Core.APIPromise; retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise; retrieve( id: string, params: AutomationRetrieveParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.retrieve(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.get(`/api/automations/${id}`, { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Patch Automation */ update(id: string, params: AutomationUpdateParams, options?: Core.RequestOptions): Core.APIPromise { const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.patch(`/api/automations/${id}`, { body, ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Delete Automation */ delete(id: string, params?: AutomationDeleteParams, options?: Core.RequestOptions): Core.APIPromise; delete(id: string, options?: Core.RequestOptions): Core.APIPromise; delete( id: string, params: AutomationDeleteParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.delete(id, {}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.delete(`/api/automations/${id}`, { ...options, headers: { Accept: '*/*', ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Count Automations */ count( params?: AutomationCountParams, options?: Core.RequestOptions, ): Core.APIPromise; count(options?: Core.RequestOptions): Core.APIPromise; count( params: AutomationCountParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.count({}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion } = params; return this._client.post('/api/automations/count', { ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } /** * Read Automations */ filter( params?: AutomationFilterParams, options?: Core.RequestOptions, ): Core.APIPromise; filter(options?: Core.RequestOptions): Core.APIPromise; filter( params: AutomationFilterParams | Core.RequestOptions = {}, options?: Core.RequestOptions, ): Core.APIPromise { if (isRequestOptions(params)) { return this.filter({}, params); } const { 'x-prefect-api-version': xPrefectAPIVersion, ...body } = params; return this._client.post('/api/automations/filter', { body, ...options, headers: { ...(xPrefectAPIVersion != null ? { 'x-prefect-api-version': xPrefectAPIVersion } : undefined), ...options?.headers, }, }); } } export interface Automation { /** * The actions to perform when this Automation triggers */ actions: Array< | Automation.DoNothing | Automation.RunDeployment | Automation.PauseDeployment | Automation.ResumeDeployment | Automation.CancelFlowRun | Automation.ChangeFlowRunState | Automation.PauseWorkQueue | Automation.ResumeWorkQueue | Automation.SendNotification | Automation.CallWebhook | Automation.PauseAutomation | Automation.ResumeAutomation | Automation.SuspendFlowRun | Automation.PauseWorkPool | Automation.ResumeWorkPool >; /** * The name of this automation */ name: string; /** * The criteria for which events this Automation covers and how it will respond to * the presence or absence of those events */ trigger: Automation.EventTrigger | Automation.CompoundTriggerOutput | Automation.SequenceTriggerOutput; id?: string; /** * The actions to perform when an Automation goes into a resolving state */ actions_on_resolve?: Array< | Automation.DoNothing | Automation.RunDeployment | Automation.PauseDeployment | Automation.ResumeDeployment | Automation.CancelFlowRun | Automation.ChangeFlowRunState | Automation.PauseWorkQueue | Automation.ResumeWorkQueue | Automation.SendNotification | Automation.CallWebhook | Automation.PauseAutomation | Automation.ResumeAutomation | Automation.SuspendFlowRun | Automation.PauseWorkPool | Automation.ResumeWorkPool >; /** * The actions to perform when an Automation goes into a triggered state */ actions_on_trigger?: Array< | Automation.DoNothing | Automation.RunDeployment | Automation.PauseDeployment | Automation.ResumeDeployment | Automation.CancelFlowRun | Automation.ChangeFlowRunState | Automation.PauseWorkQueue | Automation.ResumeWorkQueue | Automation.SendNotification | Automation.CallWebhook | Automation.PauseAutomation | Automation.ResumeAutomation | Automation.SuspendFlowRun | Automation.PauseWorkPool | Automation.ResumeWorkPool >; created?: string | null; /** * A longer description of this automation */ description?: string; /** * Whether this automation will be evaluated */ enabled?: boolean; updated?: string | null; } export namespace Automation { /** * Do nothing when an Automation is triggered */ export interface DoNothing { type?: 'do-nothing'; } /** * Runs the given deployment with the given parameters */ export interface RunDeployment { /** * The identifier of the deployment */ deployment_id?: string | null; /** * The job variables to pass to the created flow run, or None to use the * deployment's default job variables */ job_variables?: unknown | null; /** * The parameters to pass to the deployment, or None to use the deployment's * default parameters */ parameters?: unknown | null; /** * Whether this Action applies to a specific selected deployment (given by * `deployment_id`), or to a deployment that is inferred from the triggering event. * If the source is 'inferred', the `deployment_id` may not be set. If the source * is 'selected', the `deployment_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'run-deployment'; } /** * Pauses the given Deployment */ export interface PauseDeployment { /** * The identifier of the deployment */ deployment_id?: string | null; /** * Whether this Action applies to a specific selected deployment (given by * `deployment_id`), or to a deployment that is inferred from the triggering event. * If the source is 'inferred', the `deployment_id` may not be set. If the source * is 'selected', the `deployment_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'pause-deployment'; } /** * Resumes the given Deployment */ export interface ResumeDeployment { /** * The identifier of the deployment */ deployment_id?: string | null; /** * Whether this Action applies to a specific selected deployment (given by * `deployment_id`), or to a deployment that is inferred from the triggering event. * If the source is 'inferred', the `deployment_id` may not be set. If the source * is 'selected', the `deployment_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'resume-deployment'; } /** * Cancels a flow run associated with the trigger */ export interface CancelFlowRun { type?: 'cancel-flow-run'; } /** * Changes the state of a flow run associated with the trigger */ export interface ChangeFlowRunState { /** * The type of the state to change the flow run to */ state: | 'SCHEDULED' | 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'CRASHED' | 'PAUSED' | 'CANCELLING'; /** * An optional message to associate with the state change */ message?: string | null; /** * The name of the state to change the flow run to */ name?: string | null; type?: 'change-flow-run-state'; } /** * Pauses a Work Queue */ export interface PauseWorkQueue { /** * Whether this Action applies to a specific selected work queue (given by * `work_queue_id`), or to a work queue that is inferred from the triggering event. * If the source is 'inferred', the `work_queue_id` may not be set. If the source * is 'selected', the `work_queue_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'pause-work-queue'; /** * The identifier of the work queue to pause */ work_queue_id?: string | null; } /** * Resumes a Work Queue */ export interface ResumeWorkQueue { /** * Whether this Action applies to a specific selected work queue (given by * `work_queue_id`), or to a work queue that is inferred from the triggering event. * If the source is 'inferred', the `work_queue_id` may not be set. If the source * is 'selected', the `work_queue_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'resume-work-queue'; /** * The identifier of the work queue to pause */ work_queue_id?: string | null; } /** * Send a notification when an Automation is triggered */ export interface SendNotification { /** * The identifier of the notification block to use */ block_document_id: string; /** * The text of the notification to send */ body: string; subject?: string; type?: 'send-notification'; } /** * Call a webhook when an Automation is triggered. */ export interface CallWebhook { /** * The identifier of the webhook block to use */ block_document_id: string; /** * An optional templatable payload to send when calling the webhook. */ payload?: string; type?: 'call-webhook'; } /** * Pauses a Work Queue */ export interface PauseAutomation { /** * The identifier of the automation to act on */ automation_id?: string | null; /** * Whether this Action applies to a specific selected automation (given by * `automation_id`), or to an automation that is inferred from the triggering * event. If the source is 'inferred', the `automation_id` may not be set. If the * source is 'selected', the `automation_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'pause-automation'; } /** * Resumes a Work Queue */ export interface ResumeAutomation { /** * The identifier of the automation to act on */ automation_id?: string | null; /** * Whether this Action applies to a specific selected automation (given by * `automation_id`), or to an automation that is inferred from the triggering * event. If the source is 'inferred', the `automation_id` may not be set. If the * source is 'selected', the `automation_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'resume-automation'; } /** * Suspends a flow run associated with the trigger */ export interface SuspendFlowRun { type?: 'suspend-flow-run'; } /** * Pauses a Work Pool */ export interface PauseWorkPool { /** * Whether this Action applies to a specific selected work pool (given by * `work_pool_id`), or to a work pool that is inferred from the triggering event. * If the source is 'inferred', the `work_pool_id` may not be set. If the source is * 'selected', the `work_pool_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'pause-work-pool'; /** * The identifier of the work pool to pause */ work_pool_id?: string | null; } /** * Resumes a Work Pool */ export interface ResumeWorkPool { /** * Whether this Action applies to a specific selected work pool (given by * `work_pool_id`), or to a work pool that is inferred from the triggering event. * If the source is 'inferred', the `work_pool_id` may not be set. If the source is * 'selected', the `work_pool_id` must be set. */ source?: 'selected' | 'inferred'; type?: 'resume-work-pool'; /** * The identifier of the work pool to pause */ work_pool_id?: string | null; } /** * A trigger that fires based on the presence or absence of events within a given * period of time. */ export interface EventTrigger { /** * The posture of this trigger, either Reactive or Proactive. Reactive triggers * respond to the _presence_ of the expected events, while Proactive triggers * respond to the _absence_ of those expected events. */ posture: 'Reactive' | 'Proactive'; /** * The unique ID of this trigger */ id?: string; /** * The event(s) which must first been seen to fire this trigger. If empty, then * fire this trigger immediately. Events may include trailing wildcards, like * `prefect.flow-run.*` */ after?: Array; /** * The event(s) this trigger is expecting to see. If empty, this trigger will match * any event. Events may include trailing wildcards, like `prefect.flow-run.*` */ expect?: Array; /** * Evaluate the trigger separately for each distinct value of these labels on the * resource. By default, labels refer to the primary resource of the triggering * event. You may also refer to labels from related resources by specifying * `related::