Node.js SDK

The Airplane Node.js SDK is available as an NPM package, airplane. To install it, run:

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 {
5
rows,
6
count: 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:

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.

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:

bash
Copied
1
$ npm install airplane@next

Once installed, you can execute tasks with airplane.execute():

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
emailSuffix: "@" + domain,
12
});
13
})
14
);
15
16
const users = runs.map((run) => run.output).flat();
17
return 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:

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
}

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: