Node SDK

The Airplane Node SDK provides useful utilities to interact with the Airplane platform.

Installation

The Airplane Node SDK is available as an NPM package airplane.
bash
Copied
1
$ npm install 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:
javascript
Copied
1
export default async function () {
2
const rows = await queryDB("...");
3
4
return { rows, count: rows.length };
5
}
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:
javascript
Copied
1
import airplane from "airplane";
2
3
export default async function () {
4
const rows = await queryDB("...");
5
6
for (let row of rows) {
7
airplane.appendOutput(row, "rows");
8
}
9
10
airplane.setOutput(rows.length, "count");
11
}
Both tasks produce the same output:
json
Copied
1
{
2
"rows": [
3
{ "name": "...", "age": 42 }
4
// ...
5
],
6
"count": 10
7
}

[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.
You can execute subtasks using the task execution API. To execute a subtask, use the execute function. The execute function takes in the slug of the task to execute and an optional map of param slugs to their values. You can find the task slug in the triple-dot dropdown in the task's page and in the Library:
javascript
Copied
1
import airplane from "airplane";
2
3
export default async function (params) {
4
// ℹ️ This will execute `domains.length` runs in parallel and wait until
5
// all complete:
6
const runs = await Promise.all(
7
params.domains.map((domain) => {
8
// ℹ️ Execute your coworker's "Fetch Users" task to fetch
9
// a list of users by email domain:
10
return airplane.execute("fetch_users", {
11
email_suffix: "@" + domain,
12
});
13
})
14
);
15
16
return runs.map((run) => run.output).flat();
17
}
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:
typescript
Copied
1
export type Run = {
2
id: string;
3
taskID: string;
4
paramValues: any;
5
status: RunStatus;
6
output: any;
7
};
8
9
export enum RunStatus {
10
NotStarted = "NotStarted",
11
Queued = "Queued",
12
Active = "Active",
13
Succeeded = "Succeeded",
14
Failed = "Failed",
15
Cancelled = "Cancelled",
16
}
You can also view the subtasks that were run from a task by looking at the task run details and clicking on the Runs tab. You can also inspect the subtask's run details by clicking on it in the Runs tab: