### Stepflow Quick Start Example Source: https://stepflow-production.up.railway.app/docs A basic example demonstrating how to set up and run a simple 'Hello, Stepflow!' workflow using Stepflow's core library and memory storage adapter. This snippet shows the installation command, workflow definition, Stepflow initialization, and starting the service. ```bash pnpm add @stepflowjs/core @stepflowjs/storage-memory ``` ```typescript import { Stepflow, createWorkflow } from "@stepflowjs/core"; import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; const workflow = createWorkflow({ id: "hello-world" }, async ({ step }) => { const result = await step.run("greet", () => "Hello, Stepflow!"); return result; }); const stepflow = new Stepflow({ storage: new MemoryStorageAdapter(), }); stepflow.register(workflow); await stepflow.start(); ``` -------------------------------- ### HTTP Trigger Installation Example Source: https://stepflow-production.up.railway.app/docs/triggers/http This code snippet demonstrates how to install the HTTP trigger. It typically involves adding a dependency to your project's configuration file. ```javascript npm install @stepflow/trigger-http # or yarn add @stepflow/trigger-http ``` -------------------------------- ### Initialize and Register Stepflow Workflow Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start Initializes the Stepflow core with memory storage and enables logging. It then registers the previously defined workflow and starts the Stepflow service. This setup is essential for running workflows. ```typescript import { Stepflow } from "@stepflowjs/core"; import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; const stepflow = new Stepflow({ storage: new MemoryStorageAdapter(), logging: true, }); stepflow.register(welcomeWorkflow); await stepflow.start(); ``` -------------------------------- ### Log Workflow Start - JavaScript Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start This snippet demonstrates how to log the start of a workflow using console.log in JavaScript. It's a common pattern for debugging and monitoring. ```javascript console.log("Workflow started:"); ``` -------------------------------- ### Create Basic Workflow with Stepflow JS Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start This JavaScript code snippet demonstrates how to import and use the `createWorkflow` function from the `@stepflowjs/core` library. It defines a sample workflow named 'welcomeWorkflow' with a specified ID, retry count, and an asynchronous event handler. This is a foundational example for building more complex workflows. ```javascript import { createWorkflow } from "@stepflowjs/core"; export const welcomeWorkflow = createWorkflow({ id: "welcome-user", retries: 3, async ({event, step}) => { // Workflow logic here } }); ``` -------------------------------- ### Basic Stepflow.js Usage Example Source: https://stepflow-production.up.railway.app/docs/storage/memory This code snippet demonstrates the basic usage of Stepflow.js. It imports the necessary components and initializes the Stepflow with a MemoryStorageAdapter. This is a foundational example for getting started with Stepflow. ```javascript import { Stepflow } from "@stepflowjs/core"; import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; // Initialize Stepflow with MemoryStorageAdapter const stepflow = new Stepflow({ storage: new MemoryStorageAdapter() }); // Further Stepflow logic would go here... ``` -------------------------------- ### Installation Source: https://stepflow-production.up.railway.app/llms-full.txt Install the @stepflowjs/client package using pnpm. ```APIDOC ## Installation ### Description Install the core SDK for interacting with Stepflow APIs. ### Method `pnpm` ### Endpoint `add @stepflowjs/client` ### Request Example ```bash pnpm add @stepflowjs/client ``` ### Response ``` Packages successfully installed. ``` ``` -------------------------------- ### Authorization Example Source: https://stepflow-production.up.railway.app/docs/adapters/nextjs An example demonstrating how to set up authorization using NextAuth.js. ```APIDOC ## Authorization Example ### Description This section provides an example of how to configure authorization using NextAuth.js, including the necessary imports and structure for `NextAuthConfig`. ### Method N/A (Configuration Example) ### Endpoint N/A (Configuration Example) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript import { createStepflowHandlers, createApiKeyAuth } from '@stepflow/nextjs'; const handlers = createStepflowHandlers({ providers: [ createApiKeyAuth({ // API key configuration }), ], // Other NextAuth.js configuration options session: { strategy: 'jwt', }, callbacks: { async jwt({ token }) { // Add custom properties to the token return token; }, async session({ session, token }) { // Add custom properties to the session session.user.id = token.sub; return session; }, }, // Custom health check function healthCheck: async () => { // Implement your health check logic here return true; }, // Callback when authorization fails onAuthFailure: async (error, request) => { console.error('Authorization failed:', error); // Handle authorization failure, e.g., return a custom error response }, }); export const { GET, POST } = handlers; ``` ### Response #### Success Response (200) N/A (Configuration Example) #### Response Example N/A (Configuration Example) ``` -------------------------------- ### Client SDK Installation Source: https://stepflow-production.up.railway.app/llms-full.txt Instructions for installing the Stepflow client SDKs for TypeScript, React, and React Native. ```APIDOC ## Client SDK Installation Choose the package that fits your project: ### TypeScript client ```bash pnpm add @stepflowjs/client ``` ### React hooks ```bash pnpm add @stepflowjs/react @stepflowjs/client ``` ### React Native hooks ```bash pnpm add @stepflowjs/react-native @stepflowjs/client ``` ``` -------------------------------- ### Register and Start a Workflow with Stepflow Source: https://stepflow-production.up.railway.app/docs This code illustrates the process of registering a workflow definition and then starting an instance of that workflow using the Stepflow library. The `register` method takes a workflow object, and the `start` method initiates its execution. Ensure the workflow object is correctly defined before registration. ```typescript stepflow.register(workflow); await stepflow.start(); ``` -------------------------------- ### Start Stepflow Workflow (TypeScript) Source: https://stepflow-production.up.railway.app/docs/triggers This code snippet shows how to initiate a Stepflow workflow using the 'start' function. It's typically used to begin a new workflow instance or resume a paused one. The function is called without any arguments in this example, suggesting a default starting point. ```typescript await stepflow.start(); ``` -------------------------------- ### Adapter Examples Source: https://stepflow-production.up.railway.app/docs/adapters Examples of specific adapters like Cloudflare Workers and Nitric. ```APIDOC ## Adapter Examples ### Cloudflare Workers ``` @stepflowjs/adapter-cloudflare ``` ### Nitric ``` @stepflowjs/adapter-nitric ``` ``` -------------------------------- ### Install Stepflow Fastify Adapter Source: https://stepflow-production.up.railway.app/docs/adapters/fastify This code snippet shows how to install the Stepflow Fastify adapter using npm. Ensure you have Node.js and npm installed. ```bash npm install @stepflow/fastify ``` -------------------------------- ### Authorization Example Source: https://stepflow-production.up.railway.app/docs/adapters/cloudflare Illustrates how to configure authorization for the Stepflow API. This section provides a conceptual example of authorization setup. ```APIDOC ## Authorization Example ### Description This section demonstrates a conceptual example of how authorization might be configured and handled within the Stepflow API. ### Method (Not applicable for configuration example) ### Endpoint (Not applicable for configuration example) ### Parameters (Refer to `createStepflowHandler` for detailed parameter options) ### Request Example (Refer to `createStepflowHandler` Request Example for configuration structure) ### Response (Refer to `createStepflowHandler` Response Example for success/error indications) #### Error Handling - **onAuthFailure** callback can be used to handle specific authorization failures. ``` -------------------------------- ### Authorization Example Source: https://stepflow-production.up.railway.app/docs/adapters/hono An example demonstrating how to configure authorization for the Stepflow API. ```APIDOC ## Authorization Example ### Description This section provides an example of how to configure authorization settings for the Stepflow API. ### Method N/A (Configuration object) ### Endpoint N/A (Configuration object) ### Parameters #### Query Parameters N/A #### Request Body N/A ### Request Example ```json { "auth": { "//": "Authorization configuration details here" } } ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Install @stepflowjs/react and @stepflowjs/client Source: https://stepflow-production.up.railway.app/llms-full.txt Installs the necessary Stepflow packages for React integration. This command uses pnpm for package management. ```bash pnpm add @stepflowjs/react @stepflowjs/client ``` -------------------------------- ### Install Stepflow TypeScript Client with pnpm Source: https://stepflow-production.up.railway.app/docs/getting-started/installation This command installs the Stepflow client library for TypeScript projects using the pnpm package manager. Ensure you have pnpm installed and configured in your project. ```bash pnpm add @stepflowjs/client ``` -------------------------------- ### Install StepflowJS Packages with pnpm Source: https://stepflow-production.up.railway.app/docs This command installs the core StepflowJS package and the memory storage adapter using the pnpm package manager. Ensure you have pnpm installed globally. ```bash pnpm add @stepflowjs/core @stepflowjs/storage-memory ``` -------------------------------- ### Install Stepflow Client SDKs (Bash) Source: https://stepflow-production.up.railway.app/llms-full.txt Commands to install Stepflow client SDKs for interacting with Stepflow from frontend applications. Includes a TypeScript client and React hooks for web and mobile apps. ```bash # TypeScript client pnpm add @stepflowjs/client ``` ```bash # React hooks pnpm add @stepflowjs/react ``` -------------------------------- ### Install Stepflow Client SDKs (Bash) Source: https://stepflow-production.up.railway.app/llms-full.txt Installs the core Stepflow TypeScript client, or includes React/React Native hooks. Requires pnpm package manager. ```bash # TypeScript client pnpm add @stepflowjs/client # React hooks pnpm add @stepflowjs/react @stepflowjs/client # React Native hooks pnpm add @stepflowjs/react-native @stepflowjs/client ``` -------------------------------- ### Install Stepflow using npm or yarn Source: https://stepflow-production.up.railway.app/docs/client This snippet shows how to install the Stepflow client using either npm or yarn. It highlights the TypeScript client as the recommended package. ```bash # TypeScript client npm install @stepflow/client # or yarn add @stepflow/client ``` -------------------------------- ### Install Stepflow Hono Adapter Source: https://stepflow-production.up.railway.app/llms-full.txt Installs the Stepflow Hono adapter package using pnpm. This is the first step to integrate Stepflow with Hono. ```bash pnpm add @stepflowjs/adapter-hono ``` -------------------------------- ### Install Stepflow Framework Adapters (Bash) Source: https://stepflow-production.up.railway.app/llms-full.txt Commands to install Stepflow framework adapters for integrating Stepflow with web frameworks like Hono, Express, and Next.js. These adapters expose Stepflow as HTTP endpoints. ```bash # Hono pnpm add @stepflowjs/adapter-hono ``` ```bash # Express pnpm add @stepflowjs/adapter-express ``` ```bash # Next.js pnpm add @stepflowjs/adapter-nextjs ``` -------------------------------- ### Install Stepflow.js PostgreSQL Storage Adapter Source: https://stepflow-production.up.railway.app/docs/getting-started/installation This command installs the PostgreSQL storage adapter for Stepflow.js, recommended for production environments. It utilizes pnpm for package management. ```bash # Production pnpm add @stepflowjs/storage-postgres ``` -------------------------------- ### Install Stepflow React Hooks with pnpm Source: https://stepflow-production.up.railway.app/docs/getting-started/installation This command installs the Stepflow React hooks library for projects using React. It allows you to integrate Stepflow's orchestration capabilities into your React components. Ensure you have pnpm installed. ```bash pnpm add @stepflowjs/react ``` -------------------------------- ### Install Fastify Adapter Source: https://stepflow-production.up.railway.app/docs/adapters/fastify Install the Fastify adapter for Stepflow using pnpm. This package provides the necessary plugin to integrate Stepflow with Fastify. ```bash pnpm add @stepflowjs/adapter-fastify ``` -------------------------------- ### Install Stepflow.js Redis Storage Adapter Source: https://stepflow-production.up.railway.app/docs/getting-started/installation This command installs the Redis storage adapter for Stepflow.js, an alternative for production environments. It uses pnpm as the package manager. ```bash # or pnpm add @stepflowjs/storage-redis ``` -------------------------------- ### Install Stepflow Client SDKs (pnpm) Source: https://stepflow-production.up.railway.app/docs/client Installs the necessary Stepflow client SDK packages using the pnpm package manager. The core client is required for all other SDKs. ```bash pnpm add @stepflowjs/client pnpm add @stepflowjs/react @stepflowjs/client pnpm add @stepflowjs/react-native @stepflowjs/client ``` -------------------------------- ### Install Stepflow Core Package Source: https://stepflow-production.up.railway.app/docs/adapters/hono This snippet shows how to install the core Stepflow.js package using npm. It is a prerequisite for using Stepflow functionalities. ```bash npm install @stepflowjs/core; ``` -------------------------------- ### Install Stepflow Framework Adapters using pnpm Source: https://stepflow-production.up.railway.app/docs/getting-started/installation This snippet shows how to install different framework adapters for Stepflow using the pnpm package manager. It covers adapters for Hono, Express, and Next.js. ```bash # Hono pnpm add @stepflowjs/adapter-hono # Express pnpm add @stepflowjs/adapter-express # Next.js pnpm add @stepflowjs/adapter-nextjs ``` -------------------------------- ### Install MSSQL Storage Adapter Source: https://stepflow-production.up.railway.app/docs/storage/mssql Installs the MSSQL storage adapter package using pnpm. This is the first step to integrate MSSQL with Stepflow. ```bash pnpm add @stepflowjs/storage-mssql ``` -------------------------------- ### Fastify-specific Context Example Source: https://stepflow-production.up.railway.app/docs/adapters/fastify This example illustrates how to access Fastify-specific context within your Stepflow workflows when using the Fastify adapter. It shows how to retrieve the request and reply objects. ```javascript import { Workflow } from '@stepflow/core'; export class MyWorkflow extends Workflow { async run(context) { const { request, reply } = context.fastify; console.log('Request URL:', request.url); reply.send('Hello from Stepflow!'); } } ``` -------------------------------- ### Install Stepflow Storage Adapters (Bash) Source: https://stepflow-production.up.railway.app/llms-full.txt Commands to install different Stepflow storage adapters for persisting workflow state. Options include memory for development, PostgreSQL for production, Redis for high throughput, and SQLite for edge deployments. ```bash # Development/Testing pnpm add @stepflowjs/storage-memory ``` ```bash # Production pnpm add @stepflowjs/storage-postgres # or pnpm add @stepflowjs/storage-redis ``` -------------------------------- ### Install HTTP Trigger - pnpm Source: https://stepflow-production.up.railway.app/docs/triggers/http Installs the HTTP Trigger package using pnpm. This is the first step to using the HTTP trigger functionality in your project. ```bash pnpm add @stepflowjs/trigger-http ``` -------------------------------- ### Install Redis Storage Adapter Source: https://stepflow-production.up.railway.app/docs/storage/redis Installs the Redis storage adapter for Stepflow. This command uses npm to add the necessary package to your project's dependencies. ```bash npm install @stepflowjs/storage-redis ``` -------------------------------- ### Install PostgreSQL Storage Adapter Source: https://stepflow-production.up.railway.app/docs/storage/postgres Installs the PostgreSQL storage adapter package using pnpm. This is the first step to integrating PostgreSQL storage with Stepflow. ```bash pnpm add @stepflowjs/storage-postgres ``` -------------------------------- ### Initialize and Start HTTP Trigger - TypeScript Source: https://stepflow-production.up.railway.app/docs/triggers/http Demonstrates how to initialize and start the HttpTrigger in TypeScript. It includes configuration for the path, method, and signature validation, and defines a callback for handling incoming events. ```typescript import { HttpTrigger } from "@stepflowjs/trigger-http"; const trigger = new HttpTrigger({ path: "/webhooks/order", method: "POST", validateSignature: { header: "x-signature", secret: process.env.WEBHOOK_SECRET, algorithm: "sha256", }, }); await trigger.start(async (event) => { console.log("Received HTTP event:", event.data); await stepflow.trigger("process-order", event.data); }); ``` -------------------------------- ### Install Redis Storage Adapter Source: https://stepflow-production.up.railway.app/docs/storage/redis Installs the Redis storage adapter for Stepflow using pnpm. This package provides the necessary components to integrate Redis as a storage backend for Stepflow workflows. ```bash pnpm add @stepflowjs/storage-redis ``` -------------------------------- ### Initialize Stepflow Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start This snippet illustrates the initialization of the Stepflow process. It includes a section for setting up the Stepflow environment and potentially configuring its parameters. The use of 'h2' and 'a' tags suggests this might be part of a documentation or UI rendering process. ```html

2. Initialize Stepflow

``` -------------------------------- ### Stepflow Core - Quick Start Source: https://stepflow-production.up.railway.app/llms-full.txt Demonstrates how to set up and run a basic workflow using Stepflow with memory storage. ```APIDOC ## Stepflow Core - Quick Start ### Description This snippet shows the basic setup for Stepflow, including creating a workflow, registering it, and starting the Stepflow instance with in-memory storage. ### Method N/A (Client-side setup) ### Endpoint N/A ### Parameters N/A ### Request Example ```typescript import { Stepflow, createWorkflow } from "@stepflowjs/core"; import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; const workflow = createWorkflow({ id: "hello-world" }, async ({ step }) => { const result = await step.run("greet", () => "Hello, Stepflow!"); return result; }); const stepflow = new Stepflow({ storage: new MemoryStorageAdapter(), }); stepflow.register(workflow); await stepflow.start(); ``` ### Response N/A ``` -------------------------------- ### Local SQLite Usage Example Source: https://stepflow-production.up.railway.app/docs/storage/sqlite Demonstrates how to interact with a local SQLite database using the Stepflow storage package. This example assumes you have a local SQLite database file. ```typescript import { SQLiteStorage } from "@stepflowjs/storage-sqlite"; async function main() { const storage = new SQLiteStorage("./my-database.sqlite"); // Example: Inserting data await storage.set("user:1", { name: "Alice", age: 30 }); // Example: Retrieving data const userData = await storage.get("user:1"); console.log(userData); // Example: Deleting data await storage.delete("user:1"); await storage.close(); } main().catch(console.error); ``` -------------------------------- ### Install and Use HTTP Trigger Source: https://stepflow-production.up.railway.app/llms-full.txt Installs the HTTP Trigger using pnpm and shows its basic usage in TypeScript, including optional HMAC signature validation. It configures the trigger to listen for POST requests on a specific path. ```bash pnpm add @stepflowjs/trigger-http ``` ```typescript import { HttpTrigger } from "@stepflowjs/trigger-http"; const trigger = new HttpTrigger({ path: "/webhooks/order", method: "POST", validateSignature: { header: "x-signature", secret: process.env.WEBHOOK_SECRET, algorithm: "sha256", }, }); await trigger.start(async (event) => { console.log("Received HTTP event:", event.data); await stepflow.trigger("process-order", event.data); }); ``` -------------------------------- ### Start Fastify Server in JavaScript Source: https://stepflow-production.up.railway.app/docs/adapters/fastify This snippet shows how to start the Fastify server to listen for incoming requests. It uses the `fastify.listen()` method, which is a standard way to initiate a web server in Fastify. The specific port and host are not detailed in this snippet, but it's the final step in making the application accessible. ```javascript fastify.listen(); ``` -------------------------------- ### MongoDB Connection URL Example Source: https://stepflow-production.up.railway.app/docs/storage/mongodb An example of a MongoDB connection URL, including authentication, host, port, database name, and replica set configuration. This format is used for the `url` option in the MongoStorageAdapter. ```env MONGODB_URL=mongodb://user:password@localhost:27017/stepflow?replicaSet=rs0 ``` -------------------------------- ### Stepflow Nitric Adapter Usage Example Source: https://stepflow-production.up.railway.app/docs/adapters/nitric Demonstrates how to import and use the `createStepflowRouter` function from the Stepflow Nitric adapter. This example shows the basic setup for integrating Stepflow with Nitric's API. ```typescript import { api } from "@nitric/sdk"; import { Stepflow } from "@stepflowjs/core"; import { createStepflowRouter } from "@stepflowjs/adapter-nitric"; const stepflow = new Stepflow(); const router = createStepflowRouter(stepflow); api.http.get("/stepflow", router); ``` -------------------------------- ### Basic Stepflow Workflow Example Source: https://stepflow-production.up.railway.app/llms-full.txt Demonstrates creating a simple 'hello-world' workflow using Stepflow core and memory storage. It defines a workflow with a single step that returns a greeting. ```typescript import { Stepflow, createWorkflow } from "@stepflowjs/core"; import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; const workflow = createWorkflow({ id: "hello-world" }, async ({ step }) => { const result = await step.run("greet", () => "Hello, Stepflow!"); return result; }); const stepflow = new Stepflow({ storage: new MemoryStorageAdapter(), }); stepflow.register(workflow); await stepflow.start(); ``` -------------------------------- ### Next.js Run Status Handler Setup Source: https://stepflow-production.up.railway.app/llms-full.txt Sets up the GET handler for the Stepflow run status endpoint in Next.js. It utilizes `createStepflowHandlers` to obtain the `runHandler`. ```typescript import { stepflow } from "@/lib/stepflow"; import { createStepflowHandlers } from "@stepflowjs/adapter-nextjs"; const { runHandler } = createStepflowHandlers(stepflow); export const GET = runHandler; ``` -------------------------------- ### Install and Use Cron Trigger Source: https://stepflow-production.up.railway.app/llms-full.txt Installs the Cron Trigger using pnpm and demonstrates its usage in TypeScript. It schedules a workflow to run every hour using a cron expression and includes a storage adapter for leader election. ```bash pnpm add @stepflowjs/trigger-cron ``` ```typescript import { CronTrigger } from "@stepflowjs/trigger-cron"; const trigger = new CronTrigger( { expression: "0 * * * *", // Every hour timezone: "America/New_York", catchUp: true, }, storage, // Storage adapter for leader election "daily-report", // Unique ID for this schedule ); await trigger.start(async (event) => { console.log("Cron fired at:", event.data.scheduledTime); await stepflow.trigger("daily-report", event.data); }); ``` -------------------------------- ### Send Welcome Email - JavaScript Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start This asynchronous JavaScript function, 'send-welcome', sends a welcome email to a specified user. It utilizes an 'await' call to the 'sendEmail' function, indicating potential I/O operations or network requests. ```javascript async () => { await sendEmail(email, "Welcome!"); }; ``` -------------------------------- ### Basic Stream Trigger Usage (JavaScript) Source: https://stepflow-production.up.railway.app/docs/triggers/stream Example demonstrating how to use the Stream Trigger with a simple async iterable in JavaScript. This showcases the basic setup and consumption of stream data. ```javascript import { StreamTrigger } from '@stepflow/stream-trigger'; async function* myAsyncIterable() { yield 'data1'; yield 'data2'; } const trigger = new StreamTrigger(myAsyncIterable()); async function processData() { for await (const data of trigger) { console.log('Received:', data); } } processData(); ``` -------------------------------- ### Kafka Trigger Usage Example Source: https://stepflow-production.up.railway.app/docs/triggers/kafka Demonstrates how to use the Kafka Trigger to start Stepflow workflows. It configures the trigger with broker details, topic, and group ID, then processes incoming Kafka messages. ```typescript import { KafkaTrigger } from "@stepflowjs/trigger-kafka"; const trigger = new KafkaTrigger({ brokers: ["localhost:9092"], topic: "orders", groupId: "stepflow-orders", fromBeginning: false, }); await trigger.start(async (event) => { console.log("Received Kafka message:", event.data); await stepflow.trigger("process-order", event.data); }); ``` -------------------------------- ### Access Run Monitoring with Public Access Token Source: https://stepflow-production.up.railway.app/docs/api-reference This example shows how to access run monitoring information using a Public Access Token (PAT). It sends a GET request to the runs endpoint, including the token as a query parameter. ```curl curl https://api.example.com/api/stepflow/runs/run_123?token=pat_xyz ``` -------------------------------- ### React Native Setup with StepflowNativeProvider Source: https://stepflow-production.up.railway.app/docs/client/react-native This snippet shows how to import and use the StepflowNativeProvider to wrap your main application component. This is essential for initializing Stepflow's context and making its features available throughout your React Native app. Ensure you have '@stepflowjs/react-native' installed. ```javascript import { StepflowNativeProvider } from "@stepflowjs/react-native"; function App() { return ( ); } export default App; ``` -------------------------------- ### Install @stepflowjs/trigger-stream using pnpm Source: https://stepflow-production.up.railway.app/docs/triggers/stream This command installs the @stepflowjs/trigger-stream package using the pnpm package manager. Ensure you have pnpm installed globally. ```bash pnpm add @stepflowjs/trigger-stream ``` -------------------------------- ### Install Stepflow Express Adapter with pnpm Source: https://stepflow-production.up.railway.app/docs/adapters/express This command installs the Stepflow Express adapter using the pnpm package manager. Ensure you have pnpm installed and configured in your project. ```bash pnpm add @stepflowjs/adapter-express ``` -------------------------------- ### Initialize Stepflow and Fastify in JavaScript Source: https://stepflow-production.up.railway.app/docs/adapters/fastify This snippet shows the initialization of Stepflow and Fastify. It declares constants for both Stepflow and Fastify, preparing them for further configuration and integration within the application. No external dependencies are explicitly mentioned, but it's assumed that 'Stepflow' and 'Fastify' are available in the scope. ```javascript const stepflow = new Stepflow(); const fastify = Fastify(); ``` -------------------------------- ### Initialize Stepflow with MemoryStorageAdapter Source: https://stepflow-production.up.railway.app/docs This snippet demonstrates how to initialize the Stepflow library using the MemoryStorageAdapter. This adapter is suitable for development and testing purposes as it stores workflow states in memory. It requires no external dependencies for basic usage. ```typescript const stepflow = new Stepflow({ storage: new MemoryStorageAdapter() }); ``` -------------------------------- ### Express Adapter - Configuration Options Source: https://stepflow-production.up.railway.app/llms-full.txt Details the available configuration options for `createStepflowRouter` and `createStepflowMiddleware`. ```APIDOC ## Express Adapter - Configuration Options ### Description This section outlines the configuration options available when using `createStepflowRouter` and `createStepflowMiddleware` from the Stepflow Express adapter. ### Method N/A ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Configuration Options: | Option | Type | Description | | :-------------- | :----------------------- | :---------------------------------------------- | | `basePath` | `string` | Prefix for all routes (e.g., `"/api/stepflow"`) | | `endpoints` | `EndpointOption` | Preset or fine-grained endpoint configuration | | `auth` | `ExpressAuthConfig` | Authorization configuration | | `healthCheck` | `() => Promise` | Custom health check function | | `onAuthFailure` | `Function` | Callback when authorization fails | ### Request Example (Authorization) ```typescript import { createStepflowRouter, createApiKeyAuth } from "@stepflowjs/adapter-express"; const router = createStepflowRouter(stepflow, { auth: { global: createApiKeyAuth(process.env.STEPFLOW_API_KEY), health: () => ({ ok: true }), // Public health check }, }); ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Basic Usage of Stepflow.js Source: https://stepflow-production.up.railway.app/docs/triggers Demonstrates the basic setup for using Stepflow.js. It shows how to import the core library and register a trigger, likely for handling incoming events or requests. ```javascript import { Stepflow } from "@stepflowjs/core"; import { HttpTrigger } from "@stepflowjs/trigger-http"; // Example usage would follow here, likely involving instantiating Stepflow and registering the HttpTrigger. ``` -------------------------------- ### Initialize Express App and Listen on Port Source: https://stepflow-production.up.railway.app/docs/adapters/express This snippet shows the basic setup for an Express.js application. It initializes an Express app instance and configures it to listen on port 3000. This is a fundamental step for any Node.js web server. ```javascript const express = require("express"); const app = express(); app.listen(3000); ``` -------------------------------- ### Create a Stepflow Workflow Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start Defines a new Stepflow workflow with a unique ID and retry configuration. It includes steps for sending emails and a delay using `sleep`. The workflow takes event data, including userId and email, and returns a completion status. ```typescript import { createWorkflow } from "@stepflowjs/core"; export const welcomeWorkflow = createWorkflow( { id: "welcome-user", retries: 3, }, async ({ event, step, sleep }) => { const { userId, email } = event.data; // Step 1: Send welcome email await step.run("send-welcome", async () => { await sendEmail(email, "Welcome!"); }); // Wait 3 days await sleep("wait-for-followup", "3d"); // Step 2: Send follow-up await step.run("send-followup", async () => { await sendEmail(email, "How are you finding things?"); }); return { status: "completed", userId }; }, ); ``` -------------------------------- ### RedisStorageAdapter Initialization Source: https://stepflow-production.up.railway.app/docs/storage/redis Example of how to initialize the Stepflow with the RedisStorageAdapter. ```APIDOC ## POST /api/initialize ### Description Initializes the Stepflow application with the specified storage adapter. ### Method POST ### Endpoint /api/initialize ### Request Body - **storage** (object) - Required - Configuration for the storage adapter. - **url** (string) - Required - Redis connection URL. - **host** (string) - Optional - Redis host (default: localhost). - **port** (number) - Optional - Redis port (default: 6379). ### Request Example ```json { "storage": { "url": "redis://localhost:6379", "host": "localhost", "port": 6379 } } ``` ### Response #### Success Response (200) - **message** (string) - Indicates successful initialization. #### Response Example ```json { "message": "Stepflow initialized successfully with Redis storage." } ``` ``` -------------------------------- ### Install Stream Trigger (Bash) Source: https://stepflow-production.up.railway.app/docs/triggers/stream This snippet shows the command to install the Stream Trigger. It assumes a package manager is available. ```bash npm install @stepflow/stream-trigger ``` -------------------------------- ### Install Stepflow Core Package (Bash) Source: https://stepflow-production.up.railway.app/llms-full.txt Command to install the core Stepflow package using pnpm. This is the foundational package required for building workflows. ```bash pnpm add @stepflowjs/core ``` -------------------------------- ### Run Stepflow Step Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start This code shows how to execute a specific step within the Stepflow framework, identified by its name. It uses the 'await' keyword, indicating that the step execution is an asynchronous operation. This is crucial for managing sequential tasks in a workflow. ```javascript await step.run("Send welcome email"); ``` -------------------------------- ### Install NATS Trigger Source: https://stepflow-production.up.railway.app/docs/triggers/nats Install the NATS trigger package using pnpm. This package provides the necessary functionality to integrate Stepflow with NATS. ```bash pnpm add @stepflowjs/trigger-nats ``` -------------------------------- ### Install WebSocket Trigger Source: https://stepflow-production.up.railway.app/docs/triggers/websocket Installs the WebSocket Trigger package using pnpm. This is the first step to integrating WebSocket triggers into your Stepflow project. ```bash pnpm add @stepflowjs/trigger-websocket ``` -------------------------------- ### Install Kafka Trigger Source: https://stepflow-production.up.railway.app/docs/triggers/kafka Installs the Kafka trigger package for Stepflow using pnpm. This is the first step to integrating Kafka with your Stepflow workflows. ```bash pnpm add @stepflowjs/trigger-kafka ``` -------------------------------- ### Trigger a Stepflow Workflow Source: https://stepflow-production.up.railway.app/docs/getting-started/quick-start Initiates the execution of a registered Stepflow workflow by its ID ('welcome-user') and provides necessary data. It logs the workflow run ID upon successful triggering. ```typescript const { runId, publicAccessToken } = await stepflow.trigger("welcome-user", { userId: "user_123", email: "user@example.com", }); console.log("Workflow started:", runId); ``` -------------------------------- ### Install Cron Trigger Source: https://stepflow-production.up.railway.app/docs/triggers/cron Installs the Cron Trigger package using pnpm. This is the first step to using cron-based scheduling in your Stepflow application. ```bash pnpm add @stepflowjs/trigger-cron ``` -------------------------------- ### Initialize Stepflow.js Workflow Source: https://stepflow-production.up.railway.app/docs This snippet demonstrates how to import the MemoryStorageAdapter and create a new workflow using the createWorkflow function from Stepflow.js. It defines a workflow with a specific ID and an asynchronous function to handle steps. ```javascript import { MemoryStorageAdapter } from "@stepflowjs/storage-memory"; const workflow = createWorkflow({ id: "hello-world" }, async ({ step }) => { }); ``` -------------------------------- ### Initialize Stepflow with MyStorageAdapter Source: https://stepflow-production.up.railway.app/docs/triggers This snippet demonstrates how to initialize the Stepflow library, providing a custom storage adapter named 'MyStorageAdapter'. It's crucial for defining how Stepflow persists and retrieves data. ```javascript const stepflow = new Stepflow( storage: new MyStorageAdapter(), ); ``` -------------------------------- ### Install Next.js Adapter Source: https://stepflow-production.up.railway.app/docs/adapters/nextjs Installs the Next.js adapter for Stepflow using pnpm. This package provides route handlers for the Next.js App Router. ```bash pnpm add @stepflowjs/adapter-nextjs ``` -------------------------------- ### Initialize StepflowLogger in JavaScript Source: https://stepflow-production.up.railway.app/docs/observability/logging This JavaScript code snippet demonstrates how to import and initialize the StepflowLogger. It shows the basic configuration including log level, enabled status, and handler setup. The logger supports various configuration options and can be extended with custom handlers. ```javascript import { createLogger, consoleLogHandler } from "@stepflowjs/observability"; const logger = createLogger({ config: { level: "info", enabled: true, }, handlers: [consoleLogHandler], }); ``` -------------------------------- ### Install Memory Storage Adapter Source: https://stepflow-production.up.railway.app/docs/storage/memory Installs the in-memory storage adapter for Stepflow using pnpm. This package is used for development and testing purposes. ```bash pnpm add @stepflowjs/storage-memory ``` -------------------------------- ### Install Webhook Trigger - pnpm Source: https://stepflow-production.up.railway.app/docs/triggers/webhook Installs the Webhook Trigger package using pnpm. This is the first step to using the webhook functionality in your Stepflow project. ```bash pnpm add @stepflowjs/trigger-webhook ``` -------------------------------- ### Install @stepflowjs/storage-sqlite Source: https://stepflow-production.up.railway.app/docs/storage/sqlite This snippet shows how to install the @stepflowjs/storage-sqlite package using npm. This package provides the necessary adapter for using SQLite with Stepflow. ```bash npm install @stepflowjs/storage-sqlite ``` -------------------------------- ### Install Cron Trigger - npm Source: https://stepflow-production.up.railway.app/docs/triggers/cron This snippet shows how to install the Cron Trigger using npm. It is a prerequisite for using the cron scheduling functionality in Stepflow. ```bash npm install @stepflow/cron-trigger ``` -------------------------------- ### Client Initialization Source: https://stepflow-production.up.railway.app/llms-full.txt Initialize the Stepflow client with your API base URL and authentication keys. ```APIDOC ## Client Initialization ### Description Initialize the client with your Stepflow API base URL and authentication keys. Use `publicApiKey` for client-side and `apiKey` for server-side authentication. ### Method `new StepflowClient(options)` ### Parameters #### Request Body - **baseUrl** (string) - Required - The base URL of the Stepflow API. - **publicApiKey** (string) - Optional - The public API key for client-side authentication. - **apiKey** (string) - Optional - The API key for server-side authentication. ### Request Example ```typescript import { StepflowClient } from "@stepflowjs/client"; const client = new StepflowClient({ baseUrl: "https://api.your-app.com/stepflow", publicApiKey: "sf_pub_...", // For client-side // apiKey: "sf_...", // For server-side }); ``` ### Response #### Success Response (200) - **client** (StepflowClient) - An instance of the StepflowClient. #### Response Example ```typescript // client object is initialized and ready to use ``` ``` -------------------------------- ### Start a New Project Run Source: https://stepflow-production.up.railway.app/docs/api-reference Initiates a new run for a specified project. Requires a run ID and an optional access token. ```APIDOC ## POST /run ### Description Starts a new execution of a project. ### Method POST ### Endpoint /run ### Parameters #### Path Parameters None #### Query Parameters - **token** (string) - Optional - Public access token for the run. #### Request Body - **runId** (string) - Required - The unique identifier for the run. ### Request Example ```json { "runId": "your-run-id" } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message that the run has started. #### Response Example ```json { "message": "Run started successfully" } ``` ``` -------------------------------- ### Install Stepflow Adapter for Nitric Source: https://stepflow-production.up.railway.app/docs/adapters/nitric Installs the Stepflow adapter for Nitric using the pnpm package manager. This command adds the necessary dependency to your project. ```bash pnpm add @stepflowjs/adapter-nitric ```