npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

useflowcanvas

v0.1.0

Published

SDK for building and executing AI-powered visual workflows programmatically

Readme

useflowcanvas

enter image description here

FlowCanvas SDK — Build and execute AI-powered visual workflows programmatically.

Design directed acyclic graphs (DAGs) of nodes, wire them together, and run them. Supports OpenAI-powered AI nodes, HTTP requests, conditional branching, data transforms, and more.


Quick Start


import  "dotenv/config";

import  { FlowCanvas }  from  "useflowcanvas";

  

const  canvas = new  FlowCanvas("My First Workflow", {

openaiApiKey: process.env.OPENAI_API_KEY,

});

  

const  input = canvas.addInput("Input");

const  ai = canvas.addAI("Summarize", {

systemPrompt:  "You are a concise assistant.",

userPrompt:  "Summarize: {{text}}",

responseField:  "summary",

});

const  output = canvas.addOutput("Output");

  

canvas.pipe(input, ai).pipe(ai, output);

  

const  result = await  canvas.run({ text:  "Long article text goes here..."  });

console.log(result.outputs.summary);

Environment Variables

Copy .env.example to .env and fill in your values:


OPENAI_API_KEY=sk-...

OPENAI_DEFAULT_MODEL=gpt-4o-mini # optional

Node Types

| Node | Class | Purpose |

|------|-------|---------|

| input | InputNode | Entry point — passes initial data into the workflow |

| output | OutputNode | Terminal node — collects final results |

| ai | AINode | Calls OpenAI chat completions |

| transform | TransformNode | Maps, templates, or evaluates expressions |

| condition | ConditionNode | Evaluates a boolean expression and routes branches |

| http | HTTPNode | Makes HTTP requests to external APIs |

| delay | DelayNode | Pauses execution for a given duration |

| merge | MergeNode | Merges outputs from multiple upstream nodes |


API Reference

new FlowCanvas(name, options?)

| Option | Type | Description |

|--------|------|-------------|

| openaiApiKey | string | OpenAI API key (falls back to OPENAI_API_KEY env var) |

| openaiBaseUrl | string | Custom OpenAI-compatible base URL |

| defaultModel | string | Default chat model (e.g. "gpt-4o") |

| maxConcurrency | number | Max parallel node executions (reserved) |

| timeout | number | Execution timeout in ms (reserved) |

| onNodeStart | (nodeId, nodeType) => void | Fires before a node runs |

| onNodeComplete | (result) => void | Fires after a node succeeds |

| onNodeError | (nodeId, error) => void | Fires when a node throws |

Adding Nodes


canvas.addInput(label?)

canvas.addOutput(label?, fields?)

canvas.addAI(label?, config?)

canvas.addTransform(label?, config?)

canvas.addCondition(label?, config?)

canvas.addHTTP(label?, config?)

canvas.addDelay(label?, config?)

canvas.addMerge(label?)

Connecting Nodes


// Fluent chaining

canvas.pipe(nodeA, nodeB).pipe(nodeB, nodeC);

  

// With a conditional edge

canvas.connect(condNode.id, branchNode.id, {

label:  "true",

condition: (data) => data._conditionResult ===  true,

});

Running a Workflow


const  result = await  canvas.run(inputs, globals?);

WorkflowResult:


{

workflowId: string;

status: "success"  |  "error"  |  "partial";

results: ExecutionResult[]; // per-node results

outputs: NodeData; // merged outputs from terminal nodes

durationMs: number;

startedAt: Date;

finishedAt: Date;

}

Node Configs

AI Node


canvas.addAI("My AI Step", {

model:  "gpt-4o", // overrides defaultModel

systemPrompt:  "You are helpful.",

userPrompt:  "Analyze {{text}}", // {{variable}} interpolation

temperature:  0.7,

maxTokens:  500,

responseField:  "analysis", // key in output data (default: "result")

});

Transform Node


// Template interpolation

canvas.addTransform("Greeting", {

template:  "Hello, {{name}}! You scored {{score}}.",

});

  

// Key mapping with JS expressions

canvas.addTransform("Remap", {

mapping: {

fullName:  "firstName + ' ' + lastName",

scorePercent:  "score / 100",

},

});

  

// Arbitrary expression

canvas.addTransform("Compute", {

expression:  "score * 2 + bonus",

});

Condition Node


const  cond = canvas.addCondition("Is Premium?", {

condition:  "plan === 'premium' && score >= 80",

});

  

// Connect both branches explicitly

canvas.connect(cond.id, premiumNode.id, {

label:  "true",

condition: (d) => d._conditionResult ===  true,

});

canvas.connect(cond.id, freeNode.id, {

label:  "false",

condition: (d) => d._conditionResult ===  false,

});

Output includes _conditionResult: boolean and _branch: string.

HTTP Node


canvas.addHTTP("Fetch User", {

url:  "https://api.example.com/users/{{userId}}",

method:  "GET",

headers: { Authorization:  "Bearer {{token}}" },

responseField:  "user",

});

Delay Node


canvas.addDelay("Wait 2s", { delayMs:  2000  });

Template Interpolation

Any node config that accepts a string supports {{variable}} syntax. Variables are resolved from the merged output of all upstream nodes plus any globals passed to run().


canvas.addAI("Personalize", {

userPrompt:  "Write a message for {{name}} who likes {{hobby}}.",

});

  

await  canvas.run({ name:  "Alice", hobby:  "photography"  });

Serialization

Workflows can be serialized to JSON and restored:


// Save

const  json = canvas.toJSON();

await  fs.writeFile("workflow.json", JSON.stringify(json));

  

// Restore

const  data = JSON.parse(await  fs.readFile("workflow.json", "utf8"));

const  restored = FlowCanvas.fromJSON(data, { openaiApiKey: process.env.OPENAI_API_KEY  });

const  result = await  restored.run({ text:  "..."  });

Extending with Custom Nodes


import  { BaseNode }  from  "useflowcanvas";

  

class  UpperCaseNode  extends  BaseNode {

constructor(id, label = "UpperCase") {

super(id, "transform", label, {});

}

  

async  execute(context) {

const { text } = context.inputs;

return { ...context.inputs, text: text?.toUpperCase() ??  "" };

}

}

  

const  node = new  UpperCaseNode("upper_1");

canvas.addNode(node);

canvas.pipe(inputNode, node).pipe(node, outputNode);

Examples

| File | Description |

|------|-------------|

| examples/basic-workflow.js | Linear transform pipeline, no AI required |

| examples/ai-workflow.js | Multi-step summarize + translate pipeline |

| examples/conditional-workflow.js | Branching based on score threshold |

| examples/serialization.js | Save and restore workflows from JSON |


node examples/basic-workflow.js

node examples/ai-workflow.js # requires OPENAI_API_KEY

node examples/conditional-workflow.js

node examples/serialization.js

License

MIT