jevtools.Documentation

Guides

Flows from scratch

Define and run a greeting flow, then inspect its steps.

Build a flow that returns a name, then add a task that turns the name into a greeting. Both runs use ordinary server code and make no network requests. You can follow this tutorial without an API key or the inspector drawer.

To explore complete flows before writing code, open the Cookbook Playground. Its source, diagrams, and step-by-step guides need no local setup or API key.

Use an ESM TypeScript project on Node 22.12+ with jev-devtools installed. See the Quick start prerequisites if you need to install it. Run the files with your project's TypeScript runner, or compile them to JavaScript before running them with Node.

Your first flow#

Create first-flow.ts on your server:

ts · API help
import { defineJevFlow } from "jev-devtools/flow";

// 1. Define the steps. No application work runs here.
export const greet = <{ name: string }>("greet", (flow) => {
  return flow.("greeted", flow..("name"));
});

// This flow has no Jev steps: no API key or network access is needed.
const noInference = {
  systemOne() { throw new Error("This example does not call Jev"); },
};

// 2. Call tryGreeting() from Node to execute the flow.
export async function tryGreeting() {
  const result = await greet.({ name: "Ada" }, { : noInference });
  console.log(result.outcome); // "greeted"
  console.log(result.value); // "Ada"
  return result;
}

API reference: defineJevFlow() · flow.output() · flow.input · expression.get() · program.run()

The defineJevFlow() callback describes the steps synchronously. The call to greet.run() executes them. Importing the file alone does not run the flow.

Call await tryGreeting() from your Node code. For example, if your project uses tsx, run this from the directory containing the file:

sh
node --import tsx --input-type=module -e 'import { tryGreeting } from "./first-flow.ts"; await tryGreeting();'

The console prints:

text
greeted
Ada

Every flow run requires a client. This example supplies noInference, which throws if a Jev request is attempted. The flow has no Jev steps, so it never calls that client.

Change the input#

In tryGreeting(), change { name: "Ada" } to { name: "Grace" }. Run the function again. The console now prints:

text
greeted
Grace

flow.input.get("name") selects the name supplied to greet.run(). flow.output("greeted", ...) gives the result its outcome name and value. The outcome stays "greeted" because you changed only the input.

Add a greeting task#

Now format the name into a greeting. Create flow-task.ts beside the first file:

ts · API help
import { defineJevFlow } from "jev-devtools/flow";

// 1. Define the steps. No application work runs here.
export const greeting = <{ name: string }>("greeting", (flow) => {
  const message = flow.("make-message", {
    : flow..("name"),
    : (name) => `Hello, ${name}!`,
  });
  return flow.("greeted", message);
});

// This flow has no Jev steps: no API key or network access is needed.
const noInference = {
  systemOne() { throw new Error("This example does not call Jev"); },
};

// 2. Call tryTask() from Node to execute the flow.
export async function tryTask() {
  const result = await greeting.({ name: "Ada" }, { : noInference });
  console.log(result.outcome); // "greeted"
  console.log(result.value); // "Hello, Ada!"
  return result;
}

API reference: defineJevFlow() · flow.task() · flow.input · expression.get() · flow.output() · program.run()

Call await tryTask() from your Node code. With tsx, use:

sh
node --import tsx --input-type=module -e 'import { tryTask } from "./flow-task.ts"; await tryTask();'

The console prints:

text
greeted
Hello, Ada!

During definition, flow.input.get("name") is a reference to a future string. The task resolves that reference before calling its run callback, so name inside the callback is an ordinary string. The callback builds the greeting, and flow.output() returns it as the flow's value.

Change the input to { name: "Grace" } and run the function again. You should see Hello, Grace!. Put string operations and other application work inside task callbacks; builder references are neither strings nor promises.

Use the result in your application#

Inside tryTask(), after the awaited greeting.run() call, narrow result.value before using it as a string:

ts
if (typeof result.value !== "string") {
  throw new Error("Expected a greeting string");
}
console.log(result.value.toUpperCase());

For the original { name: "Ada" } input, this adds HELLO, ADA! to the console output. The public value type is unknown, even though this task produces a string.

Inspect the greeting flow#

If you have connected the drawer through Quick start, import the shared inspector into flow-task.ts. Replace the greeting.run() call inside tryTask() with this fragment:

ts
const result = await greeting.run(
  { name: "Ada" },
  { client: noInference, devtools: inspector },
);

Here greeting and noInference come from the complete example above. Use your server module's path for the inspector import.

Call tryTask() from a handler in the same Node process as that adapter. Open the drawer and select the flow run. You should see the make-message task and the greeted output. This flow makes no SDK request, so it adds no request trace.

The task ID make-message identifies the step; greeted names the output. Keep these names unique throughout the definition. See the naming and execution limits when adding more steps.

Where to go next#

You have defined a flow, run it with different inputs, and used a task's result. Continue with the operation your application needs. The linked reference sections contain complete examples, input and return tables, and limits.

Build a flow combines a Jev question, a terminal branch, and inspector capture in one example.

Jev DevTools is an independent, open-source community project. It is not affiliated with TypeSafe AI.