Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions agent-reactflow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Dependencies
node_modules
.pnp
.pnp.js

# Local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Testing
coverage

# Turbo
.turbo

# Vercel
.vercel

# Build Outputs
.next/
out/
build
dist


# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Misc
.DS_Store
*.pem
7 changes: 7 additions & 0 deletions agent-reactflow/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
}
]
}
69 changes: 69 additions & 0 deletions agent-reactflow/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ============
# Base stage
# ============
FROM node:20-bullseye-slim AS base
# Use the official Node 20 image based on bullseye slim.
# This stage serves as the base image for all subsequent stages.

# ============
# Builder stage
# ============
FROM base AS builder

WORKDIR /app

# Install Turbo globally as it is needed during the build.
RUN npm install -g turbo@2.4.4

# Copy all application source code.
COPY . .

# Prune the workspace to only include the necessary scopes.
RUN turbo prune --docker --scope @agent-reactflow/backend

# ============
# Installer stage
# ============
FROM base AS installer

WORKDIR /app

# Update the certificate store in this Debian-based stage.
RUN apt-get update && \
apt-get install -y ca-certificates && \
update-ca-certificates

RUN npm install -g pnpm@10.6.1 && \
npm install -g turbo@2.4.4

# Copy pre-pruned dependency files from the builder stage.
COPY --from=builder /app/out/json/ .
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml

# Install dependencies.
RUN pnpm install

# Copy the full application and build it.
COPY --from=builder /app/out/full/ .
RUN pnpm build

# ============
# Final Runner stage
# ============
FROM node:20-alpine AS runner

WORKDIR /app

# Copy the production-ready built application from the installer stage.
COPY --from=installer /app .

# Install only runtime packages. Here we install curl and ca-certificates,
# then update the certificate store for secure TLS connections.
RUN npm install -g pnpm@10.6.1 && \
apk add --no-cache curl ca-certificates && update-ca-certificates

# Start the application using pnpm.
CMD ["pnpm", "start"]

# # Dummy shell for troubleshooting
# CMD ["sh"]
37 changes: 37 additions & 0 deletions agent-reactflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Agent with React Flow

A sample repository to have low code editor with React Flow of Agents built with Restack.

### Apps

- `frontend`: another [Next.js](https://nextjs.org/) app
- `backend`: a [Restack](https://restack.io/) app

## Requirements

- **Node 20+**
- **pnpm** (recommended)

## Start Restack

To start Restack, use the following Docker command:

```bash
docker run -d --pull always --name restack -p 5233:5233 -p 6233:6233 -p 7233:7233 -p 9233:9233 ghcr.io/restackio/restack:main
```

## Install dependencies and start services

```bash
pnpm i
pnpm run dev
```

Leveraging turborepo, this will start both frontend and backend.
Your code will be running and syncing with Restack to execute agents.

## Run agents

### from frontend

![Run agents from frontend](./agent-reactflow.png)
Binary file added agent-reactflow/agent-reactflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions agent-reactflow/apps/backend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# For inference
OPENAI_API_KEY=

# For Restack Cloud deployment
RESTACK_ENGINE_ID=
RESTACK_ENGINE_ADDRESS=
RESTACK_ENGINE_API_KEY=
RESTACK_ENGINE_API_ADDRESS=

4 changes: 4 additions & 0 deletions agent-reactflow/apps/backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
node_modules
media
dist
40 changes: 40 additions & 0 deletions agent-reactflow/apps/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# ------- Image ----------

FROM node:20-bullseye-slim AS installer

RUN apt-get update \
&& apt-get install -y ca-certificates \
&& rm -rf /var/lib/apt/lists/*

COPY ./package.json ./app/package.json
COPY ./tsconfig.json ./app/tsconfig.json


WORKDIR /app

RUN npm install

# ------- Builder ----------

FROM node:20-bullseye-slim AS builder
WORKDIR /app
COPY --from=installer /app .
COPY ./src ./src

RUN npm run build

# ------- Runner ----------

FROM node:20-bullseye-slim AS runner

RUN addgroup --system --gid 1001 service
RUN adduser --system --uid 1001 service
USER service

WORKDIR /app

COPY --from=builder /app .

ENV NODE_OPTIONS=”--max-old-space-size=4096″

CMD ["node", "dist/services"]
38 changes: 38 additions & 0 deletions agent-reactflow/apps/backend/eventAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { client } from "./src/client";

export type EventInput = {
agentId: string;
runId: string;
};

async function eventAgent(input: EventInput) {
try {
await client.sendAgentEvent({
event: {
name: "flowEvent",
input: { name: "idVerification", input: { type: "id", documentNumber: "1234567890" } },
},
agent: {
agentId: input.agentId,
runId: input.runId,
},
});

// await client.sendAgentEvent({
// event: {
// name: "end",
// },
// agent: {
// agentId: input.agentId,
// runId: input.runId,
// },
// });

process.exit(0); // Exit the process successfully
} catch (error) {
console.error("Error sending event to agent:", error);
process.exit(1); // Exit the process with an error code
}
}

eventAgent({"agentId":"1743008631706-agentFlow","runId":"0195d369-0b9d-7ded-ab82-20e275e295da"});
Loading