import type { ReactNode } from "react"; import { ClientOptions } from "./api/client"; import { Run } from "./api/types"; import { InputParams, InputParamValues, InputToOutputParamValues, InputToSerializedParamValues } from "./params/params_input"; import { SerializedParamValues } from "./params/params_serialized"; import { TaskRuntime } from "./runtime"; import { Resolve } from "./type_helpers"; /** * The configuration for a Schedule. To learn more, see the * [Schedules documentation](https://docs.airplane.dev/tasks/schedules). */ export type Schedule = { /** * Specifies the frequency for often the schedule runs. * * Expressed using CRON syntax, generally in the form of * "MINUTE HOUR DAY_OF_MONTH MONTH DAY_OF_WEEK". For a full reference, see our * [CRON syntax docs](https://docs.airplane.dev/tasks/schedules#cron-syntax). * @example Run every second. * "* * * * *" * @example Daily at 12:00 UTC. * "0 12 * * *" * @example Every Friday at 17:00 UTC. * "0 17 * * 5" * @example First Wednesday of the month at 12:00 UTC. * "0 12 * * 3#1" * @example Every half hour between 12:00 UTC and 16:59 UTC on weekdays. * "*\/30 12-17 * * MON-FRI" * @example Every 15th of the month at 12:00 UTC, every two months (starting in January). * "0 12 15 *\/2 *" */ cron: string; /** * An optional user-facing name for this schedule. * * Defaults to a human-readable description of the recurrence (e.g. "Every Friday at 12PM UTC"). */ name?: string; /** * An optional user-facing description for this schedule. * * Supports markdown. See the [CommonMark docs](https://commonmark.org/help/) for * an introduction to markdown formatting. */ description?: string; } & (Record extends TParamValues ? { /** * The parameter values to provide when the schedule executes this task. */ paramValues?: Resolve; } : { /** * The parameter values to provide when the schedule executes this task. */ paramValues: Resolve; }); /** * The configuration for task permissions. Permissions can either be set to "team_access" to allow full * access to everyone on the team or can be defined explicitly. */ export type TaskPermissions = ExplicitPermissions | "team_access"; export type ExplicitPermissions = { /** * Groups and users who can see task information, but can't request or execute tasks. */ viewers?: PermissionAssignees; /** * Groups and users who have all the permission of viewers, and can also request tasks. */ requesters?: PermissionAssignees; /** * Groups and users who have all the permissions of requesters, and can also execute tasks and other's requests. */ executers?: PermissionAssignees; /** * Groups and users who have full access to the task, and can change task configurations and permissions. */ admins?: PermissionAssignees; }; export type PermissionAssignees = { /** Users to assign the permission to. Users are referenced via their emails. */ users?: string[]; /** Groups to assign the permission to. Groups are referenced via their slugs. */ groups?: string[]; }; export type TaskCaller = "task" | "view"; export type DefaultRunPermission = "task-viewers" | "task-participants"; export type RunnerConfig = { k8sPodSpecPatch?: K8SPodSpecPatch; }; export type K8SPodSpecPatch = { /** * Strategic merge patch to apply to Kubernetes runner pod specs. Only applies * if running self-hosted agents in Kubernetes. */ patch: Record; }; type ActionBase = { /** * Label of the action. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. * * If not set, the label will default to the entity being previewed. */ label?: string; }; type HrefAction = ActionBase & { /** * A string URL to navigate to when the action is clicked. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. */ href: string; }; type ActionAs = "side_peek" | "center_peek" | "full_page"; type EntityActionBase = ActionBase & { /** * The parameter values when previewing the entity. * * Keys and values can be a JST that can reference the output of the task and * the row of the output if using a row action. */ paramValues?: InputParamValues; /** * Method of previewing the entitiy. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. * @default "side_peek" */ as?: ActionAs; }; type TaskAction = EntityActionBase & { /** * Slug of the task to preview. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. */ task: string; }; type PageAction = EntityActionBase & { /** * Path of the page to preview. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. */ page: string; }; type ViewAction = EntityActionBase & { /** * Slug of the view to preview. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. */ view: string; }; type RunbookAction = EntityActionBase & { /** * Slug of the runbook to preview. * * Can be a JST that can reference the output of the task and * the row of the output if using a row action. */ runbook: string; }; type Action = HrefAction | TaskAction | PageAction | ViewAction | RunbookAction; type OutputDisplayBase = { /** * Buttons to display alongside the output display. Can be used to open a link or * to open a task, page, view, or runbook. * * If more than 3 actions are provided, only the first 3 will be shown. */ actions?: Action[]; }; type StatisticOutputDisplay = OutputDisplayBase & { type: "statistic"; /** * Value of the display. * * The value can be a JST that can reference the output of the task. * * If not set, the value will be the output of the task. * @example "100%" * @example "{{output * 10}} ms" */ value?: string; /** * Label of the display. * * The label can be a JST that can reference the output of the task. */ label?: string; /** * Sublabel of the display. * * The sublabel can be a JST that can reference the output of the task. */ sublabel?: string; }; type TextOutputDisplay = OutputDisplayBase & { type: "text"; /** * Value of the display. * * The value can be a JST that can reference the output of the task. * * If not set, the value will be the output of the task. * @example "Hello, world" * @example "{{output.toUpperCase()}}" */ value?: string; }; type DescriptionListOutputDisplay = OutputDisplayBase & { type: "descriptionList"; /** * Value of the display. * * The value should be a JST that evaluates to the expected format of a description list, which * is a list of objects with `term` and `description` fields. The JST can reference the output * of the task. * @example "{{[{ term: 'Name', description: 'John Doe' }]}}" * @example "{{ output.map((o) => ({ term: o.name, description: o.address })) }}" */ value?: string; }; type JSONOutputDisplay = OutputDisplayBase & { type: "json"; }; type CodeOutputDisplay = OutputDisplayBase & { type: "code"; /** * Language of the code. */ language?: string; }; type FileOutputDisplay = OutputDisplayBase & { type: "file"; }; type TableOutputDisplay = OutputDisplayBase & { type: "table"; /** * Columns of the table. * * `label` is what's displayed as the column header. `accessor` indicates which field of the * table value should be used for this column. * * If not set, the columns will be inferred from the output of the task. * @example [{ label: "Name", accessor: "name" }, { label: "Address", accessor: "address" }] */ columns?: { label: string; accessor: string; }[]; /** * Value of the display. * * The value should be a JST that evaluates to the expected format of a table, which is a list * of objects with fields corresponding to the columns. The JST can reference the output of the * task. * * If not set, the value will be the output of the task. * @example "{{[{ name: 'John Doe', address: '123 Main St' }]}}" * @example "{{ output.map((o) => ({ name: o.name, address: o.address })) }}" */ value?: string; /** * Buttons to display for each row of the table output display. Can be used to open a link or * to open a task, page, view, or runbook. * * If more than 1 row action is provided, they will be shown in a dropdown menu. */ rowActions?: Action[]; }; type OutputDisplay = StatisticOutputDisplay | TextOutputDisplay | DescriptionListOutputDisplay | JSONOutputDisplay | CodeOutputDisplay | FileOutputDisplay | TableOutputDisplay; /** * The configuration for a task. To learn more, see the * [Task definition reference](https://docs.airplane.dev/tasks/task-definition). */ export type TaskConfig = { /** * A unique identifier that ties this declaration to a task in Airplane. * * This should generally not be changed. If changed and re-deployed, Airplane will * create a brand new task. If you wish to change a slug, first rename the slug in * the UI before renaming in code. * * Slugs must: * - Be less than 50 characters long * - Use only lowercase letters, numbers, and underscores * - Start with a lowercase letter */ slug: string; /** * An optional user-facing name for this task. * * If not set, defaults to the task's slug. */ name?: string; /** * An optional user-facing description for the task. * * Supports markdown. See the [CommonMark docs](https://commonmark.org/help/) for * an introduction to markdown formatting. */ description?: string; /** * Tasks can be configured with parameters that will be requested from users * before they execute this task. * * Parameters are expressed as a mapping of slug to parameter. The values will be * passed to your function as an object that maps the parameter slug to the corresponding value. * * By default, tasks do not have parameters. * * To learn more about parameters, see the * [Parameter documentation](https://docs.airplane.dev/platform/parameters). * @example A required text parameter for an email address. * { * "email": "shorttext", * } * @example An optional multi-line text parameter for a reason. * { * "reason": { * "type": "longtext", * "required": false, * }, * } */ parameters?: TParams; /** * Determines if a task execution must be requested. This disables direct execution, including schedules. * @default false */ requireRequests?: boolean; /** * Determines if an execution request can be approved by the requestor. * @default true */ allowSelfApprovals?: boolean; /** * Restrict task execution to specific callers. This disables direct execution and hides the task in the UI. * @default [] */ restrictCallers?: TaskCaller[]; /** * Manage who can view new runs of this task. * * `task-viewers`: Anyone who can view the task can also view the run. * * `task-participants`: Can only be viewed by those who execute, request, or approve the run. * @default "task-viewers" */ defaultRunPermissions?: DefaultRunPermission; /** * Restricts runs with the same concurrency key from executing at the same time. * @default "" */ concurrencyKey?: string; /** * If concurrency key is set, only allows this task's runs to start if the number of other active runs with the * same key is below this limit. * @default 1 */ concurrencyLimit?: number; /** * Limits how long (in seconds) a task can run before it is automatically cancelled. * * Defaults to 1 hour (3600), but can be raised up to 12 hours (43200). * * To learn more, see the [Timeouts documentation](https://docs.airplane.dev/tasks/timeouts). * @default 3600 */ timeout?: number; /** * If set, runs with identical inputs within the configured age (in seconds) may * get cached results. */ allowCachedMaxAge?: number; /** * Restricts this task to run only on agents with matching labels. * * To learn more, see the * [Run constraints documentation](https://docs.airplane.dev/platform/execute-rules#run-constraints). * @example Run only on agents in the us-west-2 region. Requires the agent to have a corresponding label. * { * "aws-region": "us-west-2" * } */ constraints?: Record; /** * An optional list of schedules. Each schedule defines a unique recurrence for how often Airplane * should run this task, along with a set of parameter values to supply upon each execution. * * In order to associate each schedule in code with a schedule in Airplane, each schedule must * have an identifier (which only needs to be unique to this task). Schedules are supplied * here as a map of this identifier to the schedule's configuration. * @example * { every_minute: { cron: "* * * * *" } } */ schedules?: Record>>; /** * An optional list of webhooks. Each webhook will map to a unique URL that can be used to trigger this task. * * In order to associate each webhook in code with a webhook in Airplane, each webhook must * have an identifier (which only needs to be unique to this task). Webhooks are supplied * here as a list of slugs. * @example Adds a webhook with slug "test_webhook". By default, requireAirplaneToken is false. * ["test_webhook"] * @example Creates a webhook with slug "test_webhook" with the setting requireAirplaneToken set to true. * { test_webhook: {requireAirplaneToken: true} } */ webhooks?: string[] | Record; /** * An optional list of permissions to apply to this task. * * Setting permissions to be "team_access" allows full access to anyone on your team. * * Permissions can also be set explicitly. For explicit permissions, there are four roles that any user or group can be * assigned for a task: viewer, requester, executer, and admin. * * Once permissions are set in code for a task, they will no longer be configurable in the Airplane UI. * @example { executers: { users: [ "support@airplane.dev" ], groups: [ "support_team" ] } } */ permissions?: TaskPermissions; /** * Determines how the output of this task should be displayed in the UI. * * To learn more, see https://docs.airplane.dev/tasks/output#output-displays. * @default { type: "table" } */ outputDisplay?: OutputDisplay; /** * A list of resources to attach to this task. Resources are identified by their slug. * Once attached, a resource can be used to call [built-ins](https://docs.airplane.dev/resources/builtins). * The resource's fields can also be accessed via the `AIRPLANE_RESOURCES` environment * variable. For the exact list of fields attached per resource, see the * [Resources documentation](https://docs.airplane.dev/resources/overview). * * Within a task, resources are referenced by their slug. In some cases, it can help to give * resources an alias so that you can swap the resource without having to change your code. * Resources can be aliased by using a map of alias to slug instead of a list of slugs. * @example Attaches a resource with slug "db". * ["db"] * @example Attaches a resource with slug "demo_db" aliased as "db". * { db: "demo_db" } */ resources?: Record | string[]; /** * Environment variables that will be passed into the task. * * For secrets or values that are shared across multiple tasks, environment variables can load their value * from a config variable. To learn more, see the * [config variables documentation](https://docs.airplane.dev/platform/configs). * @example Attaches an environment variable, `PORT`, with a literal value. * { "PORT": "8000" } * @example Attaches an environment variable, `API_KEY`, from a config variable. * { "API_KEY": { "config": "api_key" } } */ envVars?: Record; /** * Configures which runtime to use for the task. Defaults to the "standard" runtime. * * A runtime determines how your task's code is executed. By default, Airplane executes tasks on * the standard runtime in which code is executed on a server, similar to how you would execute a script locally. * For long-running tasks, Airplane supports the workflow runtime which enables developers to write * orchestration logic as code. To learn more, see the [Runtime reference](https://docs.airplane.dev/tasks/runtimes). * @default "standard" */ runtime?: TaskRuntime; /** * Configuration for runners for instances of the task. * * NOTE: This is an advanced feature that only applies for self-hosted agents. */ runnerConfig?: RunnerConfig; }; export type WebhookConfig = { /** * Configures whether an Airplane API Key is required to trigger this webhook. * To learn more, see [Webhooks](https://docs.airplane.dev/tasks/webhooks). * @default false */ requireAirplaneToken: boolean; }; export type RunFunc = (paramValues: Resolve) => Awaited | Promise>; export type WrappedRunFunc = undefined extends InputParamValues ? (paramValues?: Resolve>, executeOptions?: ClientOptions) => Promise>, Awaited>> : (paramValues: Resolve>, executeOptions?: ClientOptions) => Promise>, Awaited>>; /** * DefaultEmpty is a helper that defaults `TParams` to an empty object when unset. * * If parameters are not set, we want to default TParams to an empty object rather than * `Record` to indicate the lack of parameter values. * * We could achieve this behavior by defaulting the generic directly: * * > * * However, this breaks intellisense when setting a parameter: * * parameters: { * "myparam": { * "type": "shorttext", * // The other parameter fields will not show up in intellisense here. * } * } * * Therefore, we let `TParams` default to `InputParams` for the task config and then * override it to `Record` wherever we use TParams to generate parameter values. */ type DefaultEmpty = InputParams extends TParams ? Record : TParams; /** * Airplane Tasks are functions that anyone on your team can execute via a simple Airplane-generated UI. * * A call to this method will declare a new task and register a function to call * whenever this task is executed. You can configure * [parameters](https://docs.airplane.dev/platform/parameters) for your task and the values will * be passed as the first argument to your function. Your function can return * [output](https://docs.airplane.dev/tasks/output) that will be rendered in the Airplane UI. * * If the function throws an error, that error will be automatically caught and serialized as * an error output. * * This method returns a wrapped version of your task's function. This can be called from * within other tasks to trigger an execution of your task. It will return the execution's * output. To learn more, see [executing other tasks](https://docs.airplane.dev/workflows/js-tasks). * @param config The configuration for this task, including its parameters. * @param f The function to execute whenever this task is executed. * @returns A function that can be called to execute this task. */ export declare const task: (config: TaskConfig, f: RunFunc>, TOutput>) => WrappedRunFunc, TOutput>; /** * Airplane Workflows are currently in beta. To learn more, see * [the Workflow documentation](https://docs.airplane.dev/workflows/overview). * @deprecated since v0.2.23, use `task()` instead and set `runtime: "workflow"` * @param config The configuration for this workflow, including its parameters. * @param f The function to execute whenever this workflow is executed. * @returns A function that can be called to execute this workflow. */ export declare const workflow: (config: TaskConfig, f: RunFunc>, TOutput>) => WrappedRunFunc, TOutput>; /** * The configuration for view permissions. Permissions can either be set to "team_access" to allow full * access to everyone on the team or can be defined explicitly. */ export type ViewPermissions = ViewExplicitPermissions | "team_access"; export type ViewExplicitPermissions = { /** * Groups and users who can see and interact with the view. */ viewers?: PermissionAssignees; /** * Groups and users who have full access to the view, and can change view permissions. */ admins?: PermissionAssignees; }; export type ViewConfig = { /** * A unique identifier that ties this declaration to a view in Airplane. * * This should generally not be changed. If changed and re-deployed, Airplane will * create a brand new view. If you wish to change a slug, first rename the slug in * the UI before renaming in code. * * Slugs must: * - Be less than 50 characters long * - Use only lowercase letters, numbers, and underscores * - Start with a lowercase letter */ slug: string; /** * A user-facing name for this view. */ name?: string; /** * An optional user-facing description for the view. * * Supports markdown. See the [CommonMark docs](https://commonmark.org/help/) for * an introduction to markdown formatting. */ description?: string; /** * Environment variables that will be passed into the view. * * For secrets or values that are shared across multiple tasks, environment variables can load their value * from a config variable. To learn more, see the * [config variables documentation](https://docs.airplane.dev/platform/configs). * * Note that environment variables can be seen in the View source code in the browser, so anybody * with access to the view can see the value of the environment variable. If you need to use a secret * in a view, we recommend pulling business logic that requires the secret into a task and passing it * in as a task environment variable. * @example Attaches an environment variable, `THEME`, with a literal value. * { "THEME": "light" } * @example Attaches an environment variable, `API_URL`, from a config variable. * { "API_URL": { "config": "api_url" } } */ envVars?: Record; /** * An optional list of permissions to apply to this view. * * Setting permissions to be "team_access" allows full access to anyone on your team. * * Permissions can also be set explicitly. For explicit permissions, there are two roles that any user or group can be * assigned for a view: viewer and admin. * * Once permissions are set in code for a view, they will no longer be configurable in the Airplane UI. * @example { viewers: { users: [ "support@airplane.dev" ], groups: [ "support_team" ] } } */ permissions?: ViewPermissions; }; type ViewProps = { params: Record; }; export type View = (props: ViewProps) => ReactNode; /** * Airplane Views make it incredibly easy to build UIs that you and your teammates can use. * * To learn more, see the [Getting started with Views guide](https://docs.airplane.dev/views/getting-started). * @param config The configuration for this view. * @param view The React component to render whenever this view is opened. * @returns A representation of the view. */ export declare const view: (config: ViewConfig, view: View) => View; export {};