Skip to content

bhuman-ai/task-engine-sdk

Repository files navigation

Task Engine SDK

Manage and extend BHuman's Task Engine with JavaScript or TypeScript.

The type documentation can be found here.

Installation

npm i task-engine-sdk

You may also need to install fetch and ws depending on your environment.

Getting Started

Step 1: Define the configuration

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,
};

Step 2: Create a task

import { Task } from "task-engine-sdk";

const task = new Task(config, "What time is it in NYC?");

Step 3: Run the task

const result = await task.run(); // It is 12:00 PM in NYC.

Advanced Usage

Adding a custom function

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.

Releases

No releases published

Packages

No packages published