Node.js SDK
The Airplane Node.js SDK is available as an NPM package,
airplane
. To install it, run:
bashCopied1$ npm install airplane
bashCopied1$ yarn add airplane
Output
Tasks have Output that is rendered in the UI when executed. The simplest way to produce output is by returning it from the entrypoint of your task:
javascriptCopied1export default async function () {2const rows = await queryDB("...");34return {5rows,6count: rows.length,7};8}
This requires your task to buffer output in-memory before returning. Alternatively, output can be streamed while the task is executing using the Airplane SDK:
javascriptCopied1import airplane from "airplane";23export default async function () {4const rows = await queryDB("...");56for (let row of rows) {7airplane.appendOutput(row, "rows");8}910airplane.setOutput(rows.length, "count");11}
Both tasks produce the same output:
jsonCopied1{2"rows": [3{ "name": "...", "age": 42 }4// ...5],6"count": 107}
[Beta] Subtasks
The SDK can be used to execute other tasks within your Airplane team. This is used to compose tasks and fan-out work across multiple runs or multiple agents.
SDK-based task execution is in beta and requires version >=0.2
of the Node SDK.
Install airplane@next
to get the latest version
of the beta SDK:
bashCopied1$ npm install airplane@next
bashCopied1$ yarn add airplane@next
Once installed, you can execute tasks with airplane.execute()
:
javascriptCopied1import airplane from "airplane";23export default async function (params) {4// ℹ️ This will execute `domains.length` runs in parallel and wait until5// all complete:6const runs = await Promise.all(7params.domains.map((domain) => {8// ℹ️ Execute your coworker's "Fetch Users" task to fetch9// a list of users by email domain:10return airplane.execute("fetch_users", {11emailSuffix: "@" + domain,12});13})14);1516const users = runs.map((run) => run.output).flat();17return users;18}
The SDK handles executing the task, waiting for the run to complete, and finally fetching its
output. It returns a Run
with the following fields:
typescriptCopied1export type Run = {2id: string;3taskID: string;4paramValues: any;5status: RunStatus;6output: any;7};89export enum RunStatus {10NotStarted = "NotStarted",11Queued = "Queued",12Active = "Active",13Succeeded = "Succeeded",14Failed = "Failed",15Cancelled = "Cancelled",16}
To identify which task to execute, pass the task's slug as the first parameter to
airplane.execute
. You can find the slug in the triple-dot dropdown in the task's page and in the
Library:
