Skip to content

Commit 5325fea

Browse files
Merge pull request #126 from restackio/agentReactFlow
Agent with React Flow
2 parents 77e1b34 + 2d81f14 commit 5325fea

File tree

103 files changed

+5316
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+5316
-0
lines changed

agent-reactflow/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# Dependencies
4+
node_modules
5+
.pnp
6+
.pnp.js
7+
8+
# Local env files
9+
.env
10+
.env.local
11+
.env.development.local
12+
.env.test.local
13+
.env.production.local
14+
15+
# Testing
16+
coverage
17+
18+
# Turbo
19+
.turbo
20+
21+
# Vercel
22+
.vercel
23+
24+
# Build Outputs
25+
.next/
26+
out/
27+
build
28+
dist
29+
30+
31+
# Debug
32+
npm-debug.log*
33+
yarn-debug.log*
34+
yarn-error.log*
35+
36+
# Misc
37+
.DS_Store
38+
*.pem
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"eslint.workingDirectories": [
3+
{
4+
"mode": "auto"
5+
}
6+
]
7+
}

agent-reactflow/Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ============
2+
# Base stage
3+
# ============
4+
FROM node:20-bullseye-slim AS base
5+
# Use the official Node 20 image based on bullseye slim.
6+
# This stage serves as the base image for all subsequent stages.
7+
8+
# ============
9+
# Builder stage
10+
# ============
11+
FROM base AS builder
12+
13+
WORKDIR /app
14+
15+
# Install Turbo globally as it is needed during the build.
16+
RUN npm install -g [email protected]
17+
18+
# Copy all application source code.
19+
COPY . .
20+
21+
# Prune the workspace to only include the necessary scopes.
22+
RUN turbo prune --docker --scope @agent-reactflow/backend
23+
24+
# ============
25+
# Installer stage
26+
# ============
27+
FROM base AS installer
28+
29+
WORKDIR /app
30+
31+
# Update the certificate store in this Debian-based stage.
32+
RUN apt-get update && \
33+
apt-get install -y ca-certificates && \
34+
update-ca-certificates
35+
36+
RUN npm install -g [email protected] && \
37+
npm install -g [email protected]
38+
39+
# Copy pre-pruned dependency files from the builder stage.
40+
COPY --from=builder /app/out/json/ .
41+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
42+
43+
# Install dependencies.
44+
RUN pnpm install
45+
46+
# Copy the full application and build it.
47+
COPY --from=builder /app/out/full/ .
48+
RUN pnpm build
49+
50+
# ============
51+
# Final Runner stage
52+
# ============
53+
FROM node:20-alpine AS runner
54+
55+
WORKDIR /app
56+
57+
# Copy the production-ready built application from the installer stage.
58+
COPY --from=installer /app .
59+
60+
# Install only runtime packages. Here we install curl and ca-certificates,
61+
# then update the certificate store for secure TLS connections.
62+
RUN npm install -g [email protected] && \
63+
apk add --no-cache curl ca-certificates && update-ca-certificates
64+
65+
# Start the application using pnpm.
66+
CMD ["pnpm", "start"]
67+
68+
# # Dummy shell for troubleshooting
69+
# CMD ["sh"]

agent-reactflow/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Agent with React Flow
2+
3+
A sample repository to have low code editor with React Flow of Agents built with Restack.
4+
5+
### Apps
6+
7+
- `frontend`: another [Next.js](https://nextjs.org/) app
8+
- `backend`: a [Restack](https://restack.io/) app
9+
10+
## Requirements
11+
12+
- **Node 20+**
13+
- **pnpm** (recommended)
14+
15+
## Start Restack
16+
17+
To start Restack, use the following Docker command:
18+
19+
```bash
20+
docker run -d --pull always --name restack -p 5233:5233 -p 6233:6233 -p 7233:7233 -p 9233:9233 ghcr.io/restackio/restack:main
21+
```
22+
23+
## Install dependencies and start services
24+
25+
```bash
26+
pnpm i
27+
pnpm run dev
28+
```
29+
30+
Leveraging turborepo, this will start both frontend and backend.
31+
Your code will be running and syncing with Restack to execute agents.
32+
33+
## Run agents
34+
35+
### from frontend
36+
37+
![Run agents from frontend](./agent-reactflow.png)
73.2 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# For inference
3+
OPENAI_API_KEY=
4+
5+
# For Restack Cloud deployment
6+
RESTACK_ENGINE_ID=
7+
RESTACK_ENGINE_ADDRESS=
8+
RESTACK_ENGINE_API_KEY=
9+
RESTACK_ENGINE_API_ADDRESS=
10+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.env
2+
node_modules
3+
media
4+
dist
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# ------- Image ----------
2+
3+
FROM node:20-bullseye-slim AS installer
4+
5+
RUN apt-get update \
6+
&& apt-get install -y ca-certificates \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
COPY ./package.json ./app/package.json
10+
COPY ./tsconfig.json ./app/tsconfig.json
11+
12+
13+
WORKDIR /app
14+
15+
RUN npm install
16+
17+
# ------- Builder ----------
18+
19+
FROM node:20-bullseye-slim AS builder
20+
WORKDIR /app
21+
COPY --from=installer /app .
22+
COPY ./src ./src
23+
24+
RUN npm run build
25+
26+
# ------- Runner ----------
27+
28+
FROM node:20-bullseye-slim AS runner
29+
30+
RUN addgroup --system --gid 1001 service
31+
RUN adduser --system --uid 1001 service
32+
USER service
33+
34+
WORKDIR /app
35+
36+
COPY --from=builder /app .
37+
38+
ENV NODE_OPTIONS=”--max-old-space-size=4096″
39+
40+
CMD ["node", "dist/services"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { client } from "./src/client";
2+
3+
export type EventInput = {
4+
agentId: string;
5+
runId: string;
6+
};
7+
8+
async function eventAgent(input: EventInput) {
9+
try {
10+
await client.sendAgentEvent({
11+
event: {
12+
name: "flowEvent",
13+
input: { name: "idVerification", input: { type: "id", documentNumber: "1234567890" } },
14+
},
15+
agent: {
16+
agentId: input.agentId,
17+
runId: input.runId,
18+
},
19+
});
20+
21+
// await client.sendAgentEvent({
22+
// event: {
23+
// name: "end",
24+
// },
25+
// agent: {
26+
// agentId: input.agentId,
27+
// runId: input.runId,
28+
// },
29+
// });
30+
31+
process.exit(0); // Exit the process successfully
32+
} catch (error) {
33+
console.error("Error sending event to agent:", error);
34+
process.exit(1); // Exit the process with an error code
35+
}
36+
}
37+
38+
eventAgent({"agentId":"1743008631706-agentFlow","runId":"0195d369-0b9d-7ded-ab82-20e275e295da"});

0 commit comments

Comments
 (0)