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:
import { defineJevFlow } from "jev-devtools/flow";
// 1. Define the steps. No application work runs here.
export const greet = defineJevFlow<{ name: string }>("greet", (flow) => {
return flow.output("greeted", flow.input.get("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.run({ name: "Ada" }, { client: noInference });
console.log(result.outcome); // "greeted"
console.log(result.value); // "Ada"
return result;
}Describe a flow once, then run it with different inputs. Defining it does not send requests.
defineJevFlow<Input>(name, build)- name
- The flow name shown in DevTools.
- build
- Receives a builder. Return an output or a terminal branch.
Finish this path with a named outcome and, optionally, a value for your application.
flow.output(name, value?, display?)- name
- The outcome string returned by run().
- value?
- Optional result data. Narrow its type in your application before using it.
- display?
- Optional labels and display metadata for DevTools.
A reference to the data passed to run(). Inside map/loop programs, it refers to the item or iteration input instead.
flow.input: FlowExpression<Input>Select a field owned by an object, an array index, or array length. TypeScript rejects array methods. Missing fields and array bounds remain execution checks; use a task for string operations.
expression.get(key)Start the flow with new input and await its steps, including SDK requests. Use await to read { runId, outcome, value? }.
program.run(input, { client, devtools?, signal? })- input
- Data matching the input type declared in defineJevFlow.
- client
- The TypeSafe-compatible client that executes Jev requests.
- devtools?
- An optional observer, such as the shared server adapter, that records execution.
- signal?
- An optional AbortSignal to cancel the run.
The TypeSafe-compatible client that executes Jev requests.
clientAPI 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:
node --import tsx --input-type=module -e 'import { tryGreeting } from "./first-flow.ts"; await tryGreeting();'The console prints:
greeted
AdaEvery 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:
greeted
Graceflow.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:
import { defineJevFlow } from "jev-devtools/flow";
// 1. Define the steps. No application work runs here.
export const greeting = defineJevFlow<{ name: string }>("greeting", (flow) => {
const message = flow.task("make-message", {
input: flow.input.get("name"),
run: (name) => `Hello, ${name}!`,
});
return flow.output("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.run({ name: "Ada" }, { client: noInference });
console.log(result.outcome); // "greeted"
console.log(result.value); // "Hello, Ada!"
return result;
}Resolve input references, run application code, and return a reference to its result. Tasks do not retry automatically.
flow.task(id, { input, run, timeoutMs? }, display?)- input
- Values and nested flow references resolved before run is called.
- run
- Your callback receives the resolved input and task context, including a cancellation signal.
- timeoutMs?
- Optional time limit. The callback must cooperate with cancellation; a timeout cannot undo side effects.
Values and nested flow references resolved before run is called.
inputYour callback receives the resolved input and task context, including a cancellation signal.
runAPI reference: defineJevFlow() · flow.task() · flow.input · expression.get() · flow.output() · program.run()
Call await tryTask() from your Node code. With tsx, use:
node --import tsx --input-type=module -e 'import { tryTask } from "./flow-task.ts"; await tryTask();'The console prints:
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:
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:
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.
Ask a Jev question to add a model request.
flow.jev()creates future-answer references; the runner sends and awaits the SDK request. Use a server-side client and API key for these live examples.Choose a value with
if()when two paths rejoin before the flow finishes.Choose an outcome with
branch()when each path ends the flow.Run independent work with
parallel()when one step does not need another's result.Process a collection with
map()to apply the same steps to each item.Repeat with
loop()when each iteration needs the previous result.
Build a flow combines a Jev question, a terminal branch, and inspector capture in one example.