Skip to content

🌊 is a simple, lightweight event-based workflow for JS

Notifications You must be signed in to change notification settings

run-llama/fluere

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a1067ef Β· Mar 25, 2025

History

42 Commits
Mar 17, 2025
Mar 17, 2025
Mar 25, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025
Mar 17, 2025

Repository files navigation

fluere

fluere 🌊 is a simple, lightweight workflow engine, inspired by LlamaIndex Workflow

Bundle Size Bundle Size

  • Minimal core API (<=2kb)
  • 100% Type safe
  • Event-driven execution engine
  • Support multiple JS runtime/framework

Usage

npm i fluere

First, define events

import { workflowEvent } from "fluere";

const startEvent = workflowEvent<string>();
const stopEvent = workflowEvent<1 | -1>();

Connect events with workflow

import { createWorkflow } from "fluere";

const convertEvent = workflowEvent();

const workflow = createWorkflow({
  startEvent,
  stopEvent,
});

workflow.handle([startEvent], (start) => {
  return convertEvent(Number.parseInt(start.data, 10));
});
workflow.handle([convertEvent], (convert) => {
  return stopEvent(convert.data > 0 ? 1 : -1);
});

Run workflow in multiple JS runtime/framework

Node.js/Bun/Deno

// One shot execution
import { promiseHandler } from "fluere/interrupter/promise";

await promiseHandler(() => workflow.run("100"));

Hono.js

import { Hono } from "hono";
import { createHonoHandler } from "fluere/interrupter/hono";

const app = new Hono();

app.post(
  "/workflow",
  createHonoHandler(async (ctx) => workflow.run(await ctx.req.text())),
);

Todo list

  • minimal API
    • basic logic: if, else if, loop case
  • context API
    • sendEvent, requireEvent
    • detect cycle dependency
    • @fluere/ui for visualizing workflow
    • ...
  • concept API
    • interrupter/* for interrupting the workflow
      • promise
      • timeout
      • next.js
      • hono.js
      • ...
    • middleware/* for processing the workflow
      • log
      • zod schema validation
      • ...
  • third party integration
    • hono.js
    • cloudflare worker
    • ...

Why not...

Event Emitter

Node.js Event Emitter is a great tool for handling events, however:

  1. It's hard to maintain the event flow; for the typesafety, it's hard to maintain the string name of the event. Also, it's hard to control the event flow, like prohibit event a calling event b. In fluere, event is checked by object reference, and the event flow is checked by the internal graph algorithm.

  2. It's hard to handle the async event, you have to handle the async event by yourself.

    import { EventEmitter } from "node:events";
    
    const ee = new EventEmitter();
    ee.on("start", (start) => {
      ee.emit("convert:stop"); // <-- how to get the data from `convert:stop` event with correct one?
    });
    ee.once("convert", async (data) => {
      const result = fetch("...").then((res) => res.json()); // <-- async fetch
      ee.emit("convert:stop", result);
    });
    ee.on("stop", (stop) => {});

RxJS

It's too heavy, few people can understand the concept of RxJS, and maintaining the RxJS code is hard.

LICENSE

MIT

About

🌊 is a simple, lightweight event-based workflow for JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published