Manage and extend BHuman's Task Engine with JavaScript or TypeScript.
The type documentation can be found here.
npm i task-engine-sdk
You may also need to install
fetch
andws
depending on your environment.
import { Config } from "task-engine-sdk";
export const config: Config = {
clientId: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
engineSecret: "ENGINE_SECRET",
};
Adding fetch and WebSocket if not globally defined.
import { Config } from "task-engine-sdk";
import fetch from "node-fetch";
import WebSocket from "ws";
export const config: Config = {
clientId: "CLIENT_ID",
clientSecret: "CLIENT_SECRET",
engineSecret: "ENGINE_SECRET",
fetch,
WebSocket,
};
import { Task } from "task-engine-sdk";
const task = new Task(config, "What time is it in NYC?");
const result = await task.run(); // It is 12:00 PM in NYC.
import { FunctionsPlugin } from "task-engine-sdk";
// create the task...
const functions = new FunctionsPlugin();
task.use(functions);
functions.add({
name: "multiply",
args: ["number a", "number b"],
description: "Multiply two numbers together",
run: (a: string, b: string) => [`Answer: ${+a * +b}`],
});
// run the task...
Please refer to the examples directory for more.
examples/add-function.ts
: To add a custom function.examples/open-page.ts
: To open a page in the browser.examples/page-evaluate.ts
: To run a script in the browser.