supallm
v1.7.1
Published
Build AI agents with no code and control them in real-time using Supallm.
Downloads
1,055
Readme
Quick Start
Before you start, make sure you have a Supallm instance running and a flow created.
Install the SDK
npm install supallm
Server VS Browser
Our SDK package contains both a browser and a server version.
The main difference between the two is how you will authenticate your requests and what information you will have access to.
For instance, the browser version is designed to be exposed to the client side, it will not have access to the secretKey
.
The backend version is imported by default when you use the import { initSupallm } from "supallm"
statement.
To import the frontend version, you can use import { initSupallm } from "supallm/browser"
statement.
Server Version
import { initSupallm } from "supallm/server";
const supallm = initSupallm({
projectId: "<your-project-id>",
secretKey: "<your-secret-key>",
});
Browser Version
import { initSupallm } from "supallm/browser";
const supallm = initSupallm({
projectId: "<your-project-id>",
});
// Set the user token to authenticate your requests
// Note: this requires to configure the Supallm authentication feature from your dashboard.
supallm.setUserToken("<your-user-token>");
Trigger a flow and listen for events
const sub = supallm
.run({
flowId: "<your-flow-id>",
inputs: {
name: "John Doe",
},
})
.subscribe();
sub.on("flowResultStream", (event) => {
console.log("Partial result receieved", event);
});
result.on("flowEnd", (event) => {
console.log("Final concatenated result:", event.result);
});
result.on("flowFail", (event) => {
console.error("An error occurred while running the flow:", event.message);
});
result.on("nodeStart", (event) => {
console.log("Node started:", event);
});
result.on("nodeFail", (event) => {
console.error("An error occurred while running the node:", event);
});
result.on("nodeLog", (event) => {
console.log("Node log:", event);
});
result.on("nodeEnd", (event) => {
console.log("Node ended:", event);
});
Trigger a flow and wait for the result
const response = await supallm
.run({
flowId: "<your-flow-id>",
inputs: {
name: "John Doe",
},
})
.wait();
if (response.isSuccess) {
console.log("result:", response.result);
} else {
console.error(
"An error occurred while running the flow:",
response.result.message,
);
}
console.log("result:", result);