feat: add sim & pingap

This commit is contained in:
Sun-ZhenXing
2025-12-27 11:24:44 +08:00
parent 72b36f2748
commit d536fbc995
25 changed files with 1727 additions and 483 deletions

105
apps/sim/.env.example Normal file
View File

@@ -0,0 +1,105 @@
# =============================================================================
# Sim - AI Agent Workflow Builder Configuration
# =============================================================================
# Documentation: https://docs.sim.ai
# GitHub: https://github.com/simstudioai/sim
# -----------------------------------------------------------------------------
# Time Zone Configuration
# -----------------------------------------------------------------------------
TZ=UTC
# -----------------------------------------------------------------------------
# Image Versions
# -----------------------------------------------------------------------------
SIM_VERSION=latest
SIM_REALTIME_VERSION=latest
SIM_MIGRATIONS_VERSION=latest
PGVECTOR_VERSION=pg17
# -----------------------------------------------------------------------------
# Global Registry (optional, e.g., mirror.example.com/)
# -----------------------------------------------------------------------------
# GLOBAL_REGISTRY=
# -----------------------------------------------------------------------------
# Port Overrides
# -----------------------------------------------------------------------------
SIM_PORT_OVERRIDE=3000
SIM_REALTIME_PORT_OVERRIDE=3002
POSTGRES_PORT_OVERRIDE=5432
# -----------------------------------------------------------------------------
# Application Configuration
# -----------------------------------------------------------------------------
NODE_ENV=production
NEXT_PUBLIC_APP_URL=http://localhost:3000
BETTER_AUTH_URL=http://localhost:3000
SOCKET_SERVER_URL=http://localhost:3002
NEXT_PUBLIC_SOCKET_URL=http://localhost:3002
# -----------------------------------------------------------------------------
# Security Secrets (REQUIRED: Generate secure values in production)
# -----------------------------------------------------------------------------
# Generate with: openssl rand -hex 32
BETTER_AUTH_SECRET=your_auth_secret_here
ENCRYPTION_KEY=your_encryption_key_here
# -----------------------------------------------------------------------------
# API Keys (Optional)
# -----------------------------------------------------------------------------
# COPILOT_API_KEY=
# SIM_AGENT_API_URL=
# -----------------------------------------------------------------------------
# Ollama Configuration
# -----------------------------------------------------------------------------
# For external Ollama on host machine:
# - macOS/Windows: http://host.docker.internal:11434
# - Linux: http://YOUR_HOST_IP:11434 (e.g., http://192.168.1.100:11434)
OLLAMA_URL=http://localhost:11434
# -----------------------------------------------------------------------------
# PostgreSQL Configuration
# -----------------------------------------------------------------------------
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=simstudio
# -----------------------------------------------------------------------------
# Resource Limits - Main Application
# -----------------------------------------------------------------------------
SIM_CPU_LIMIT=4.0
SIM_CPU_RESERVATION=2.0
SIM_MEMORY_LIMIT=8G
SIM_MEMORY_RESERVATION=4G
# -----------------------------------------------------------------------------
# Resource Limits - Realtime Server
# -----------------------------------------------------------------------------
SIM_REALTIME_CPU_LIMIT=2.0
SIM_REALTIME_CPU_RESERVATION=1.0
SIM_REALTIME_MEMORY_LIMIT=4G
SIM_REALTIME_MEMORY_RESERVATION=2G
# -----------------------------------------------------------------------------
# Resource Limits - Database Migrations
# -----------------------------------------------------------------------------
SIM_MIGRATIONS_CPU_LIMIT=1.0
SIM_MIGRATIONS_CPU_RESERVATION=0.5
SIM_MIGRATIONS_MEMORY_LIMIT=512M
SIM_MIGRATIONS_MEMORY_RESERVATION=256M
# -----------------------------------------------------------------------------
# Resource Limits - PostgreSQL
# -----------------------------------------------------------------------------
POSTGRES_CPU_LIMIT=2.0
POSTGRES_CPU_RESERVATION=1.0
POSTGRES_MEMORY_LIMIT=2G
POSTGRES_MEMORY_RESERVATION=1G
# -----------------------------------------------------------------------------
# Logging Configuration
# -----------------------------------------------------------------------------
LOG_MAX_SIZE=100m
LOG_MAX_FILE=3

224
apps/sim/README.md Normal file
View File

@@ -0,0 +1,224 @@
# Sim - AI Agent Workflow Builder
Open-source platform to build and deploy AI agent workflows. Developers at trail-blazing startups to Fortune 500 companies deploy agentic workflows on the Sim platform.
## Features
- **Visual Workflow Builder**: Multi-step AI agents and tools with drag-and-drop interface
- **LLM Orchestration**: Coordinate LLM calls, tools, webhooks, and external APIs
- **Scheduled Execution**: Event-driven and scheduled agent executions
- **RAG Support**: First-class support for retrieval-augmented generation
- **Multi-tenant**: Workspace-based access model for teams
- **100+ Integrations**: Connect with popular services and APIs
## Requirements
| Resource | Minimum | Recommended |
| -------- | --------- | ----------- |
| CPU | 2 cores | 4+ cores |
| RAM | 12 GB | 16+ GB |
| Storage | 20 GB SSD | 50+ GB SSD |
| Docker | 20.10+ | Latest |
## Quick Start
```bash
# Copy environment file
cp .env.example .env
# IMPORTANT: Generate secure secrets in production
sed -i "s/your_auth_secret_here/$(openssl rand -hex 32)/" .env
sed -i "s/your_encryption_key_here/$(openssl rand -hex 32)/" .env
# Start services
docker compose up -d
# View logs
docker compose logs -f simstudio
```
Access the application at [http://localhost:3000](http://localhost:3000)
## Configuration
### Required Environment Variables
Before deployment, update these critical settings in `.env`:
```bash
# Security (REQUIRED - generate with: openssl rand -hex 32)
BETTER_AUTH_SECRET=<your-secret-here>
ENCRYPTION_KEY=<your-secret-here>
# Application URLs (update for production)
NEXT_PUBLIC_APP_URL=https://sim.yourdomain.com
BETTER_AUTH_URL=https://sim.yourdomain.com
NEXT_PUBLIC_SOCKET_URL=https://sim.yourdomain.com
# Database credentials (change defaults in production)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=<strong-password>
POSTGRES_DB=simstudio
```
### Using with Ollama
Sim can work with local AI models using [Ollama](https://ollama.ai):
**External Ollama (running on host machine)**:
```bash
# macOS/Windows
OLLAMA_URL=http://host.docker.internal:11434
# Linux - use your actual host IP
OLLAMA_URL=http://192.168.1.100:11434
```
> **Note**: Inside Docker, `localhost` refers to the container. Use `host.docker.internal` (macOS/Windows) or your host's IP address (Linux).
### Port Configuration
Default ports can be overridden via environment variables:
```bash
SIM_PORT_OVERRIDE=3000 # Main application
SIM_REALTIME_PORT_OVERRIDE=3002 # Realtime server
POSTGRES_PORT_OVERRIDE=5432 # PostgreSQL database
```
### Resource Limits
Adjust resource allocation based on your workload:
```bash
# Main application
SIM_CPU_LIMIT=4.0
SIM_MEMORY_LIMIT=8G
# Realtime server
SIM_REALTIME_CPU_LIMIT=2.0
SIM_REALTIME_MEMORY_LIMIT=4G
# PostgreSQL
POSTGRES_CPU_LIMIT=2.0
POSTGRES_MEMORY_LIMIT=2G
```
## Service Architecture
The deployment consists of 4 services:
1. **simstudio**: Main Next.js application (port 3000)
2. **realtime**: WebSocket server for real-time features (port 3002)
3. **migrations**: Database schema management (runs once)
4. **db**: PostgreSQL 17 with pgvector extension (port 5432)
## Common Operations
### View Logs
```bash
# All services
docker compose logs -f
# Specific service
docker compose logs -f simstudio
```
### Stop Services
```bash
docker compose down
```
### Update to Latest Version
```bash
docker compose pull
docker compose up -d
```
### Backup Database
```bash
docker compose exec db pg_dump -U postgres simstudio > backup_$(date +%Y%m%d).sql
```
### Restore Database
```bash
cat backup.sql | docker compose exec -T db psql -U postgres simstudio
```
## Security Considerations
- **Change default credentials**: Update `POSTGRES_PASSWORD` in production
- **Generate strong secrets**: Use `openssl rand -hex 32` for all secret values
- **Use HTTPS**: Configure reverse proxy (Nginx/Caddy) with SSL certificates
- **Network isolation**: Keep database on internal network
- **Regular backups**: Automate database backups
- **Update regularly**: Pull latest images to get security patches
## Production Deployment
For production deployments:
1. **Use reverse proxy** (Nginx, Caddy, Traefik) for SSL/TLS termination
2. **Configure firewall** to restrict database access
3. **Set up monitoring** (health checks, metrics, logs)
4. **Enable backups** (automated PostgreSQL backups)
5. **Use external database** for better performance and reliability (optional)
Example Caddy configuration:
```caddy
sim.yourdomain.com {
reverse_proxy localhost:3000
handle /socket.io/* {
reverse_proxy localhost:3002
}
}
```
## Troubleshooting
### Models not showing in dropdown
If using external Ollama on host machine, ensure `OLLAMA_URL` uses `host.docker.internal` or your host's IP address, not `localhost`.
### Database connection errors
- Verify PostgreSQL is healthy: `docker compose ps`
- Check database logs: `docker compose logs db`
- Ensure migrations completed: `docker compose logs migrations`
### Port conflicts
If ports are already in use, override them:
```bash
SIM_PORT_OVERRIDE=3100 \
SIM_REALTIME_PORT_OVERRIDE=3102 \
POSTGRES_PORT_OVERRIDE=5433 \
docker compose up -d
```
## Additional Resources
- **Official Documentation**: [https://docs.sim.ai](https://docs.sim.ai)
- **GitHub Repository**: [https://github.com/simstudioai/sim](https://github.com/simstudioai/sim)
- **Cloud-hosted Version**: [https://sim.ai](https://sim.ai)
- **Self-hosting Guide**: [https://docs.sim.ai/self-hosting](https://docs.sim.ai/self-hosting)
## License
This configuration follows the Sim project licensing. Check the [official repository](https://github.com/simstudioai/sim) for license details.
## Support
For issues and questions:
- GitHub Issues: [https://github.com/simstudioai/sim/issues](https://github.com/simstudioai/sim/issues)
- Documentation: [https://docs.sim.ai](https://docs.sim.ai)

224
apps/sim/README.zh.md Normal file
View File

@@ -0,0 +1,224 @@
# Sim - AI Agent Workflow Builder
开源 AI 智能体工作流构建和部署平台。从初创公司到世界 500 强企业的开发者都在 Sim 平台上部署智能体工作流。
## 功能特性
- **可视化工作流构建器**:通过拖拽界面构建多步骤 AI 智能体和工具
- **LLM 编排**:协调 LLM 调用、工具、Webhook 和外部 API
- **计划执行**:支持事件驱动和定时调度的智能体执行
- **RAG 支持**一流的检索增强生成RAG支持
- **多租户**:基于工作空间的团队访问模型
- **100+ 集成**:连接流行的服务和 API
## 系统要求
| 资源 | 最低要求 | 推荐配置 |
| ------ | --------- | ---------------- |
| CPU | 2 核 | 4 核及以上 |
| 内存 | 12 GB | 16 GB 及以上 |
| 存储 | 20 GB SSD | 50 GB 及以上 SSD |
| Docker | 20.10+ | 最新版本 |
## 快速开始
```bash
# 复制环境配置文件
cp .env.example .env
# 重要:在生产环境中生成安全密钥
sed -i "s/your_auth_secret_here/$(openssl rand -hex 32)/" .env
sed -i "s/your_encryption_key_here/$(openssl rand -hex 32)/" .env
# 启动服务
docker compose up -d
# 查看日志
docker compose logs -f simstudio
```
访问应用:[http://localhost:3000](http://localhost:3000)
## 配置说明
### 必需的环境变量
在部署前,请在 `.env` 文件中更新这些关键设置:
```bash
# 安全密钥(必需 - 使用以下命令生成openssl rand -hex 32
BETTER_AUTH_SECRET=<your-secret-here>
ENCRYPTION_KEY=<your-secret-here>
# 应用 URL生产环境需更新
NEXT_PUBLIC_APP_URL=https://sim.yourdomain.com
BETTER_AUTH_URL=https://sim.yourdomain.com
NEXT_PUBLIC_SOCKET_URL=https://sim.yourdomain.com
# 数据库凭据(生产环境需更改默认值)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=<strong-password>
POSTGRES_DB=simstudio
```
### 使用 Ollama
Sim 可以配合本地 AI 模型使用 [Ollama](https://ollama.ai)
**外部 Ollama运行在宿主机上**
```bash
# macOS/Windows
OLLAMA_URL=http://host.docker.internal:11434
# Linux - 使用宿主机实际 IP
OLLAMA_URL=http://192.168.1.100:11434
```
> **注意**:在 Docker 内部,`localhost` 指向容器本身。请使用 `host.docker.internal`macOS/Windows或宿主机 IP 地址Linux
### 端口配置
默认端口可通过环境变量覆盖:
```bash
SIM_PORT_OVERRIDE=3000 # 主应用
SIM_REALTIME_PORT_OVERRIDE=3002 # 实时服务器
POSTGRES_PORT_OVERRIDE=5432 # PostgreSQL 数据库
```
### 资源限制
根据工作负载调整资源分配:
```bash
# 主应用
SIM_CPU_LIMIT=4.0
SIM_MEMORY_LIMIT=8G
# 实时服务器
SIM_REALTIME_CPU_LIMIT=2.0
SIM_REALTIME_MEMORY_LIMIT=4G
# PostgreSQL
POSTGRES_CPU_LIMIT=2.0
POSTGRES_MEMORY_LIMIT=2G
```
## 服务架构
部署包含 4 个服务:
1. **simstudio**:主 Next.js 应用(端口 3000
2. **realtime**WebSocket 实时功能服务器(端口 3002
3. **migrations**:数据库架构管理(仅运行一次)
4. **db**PostgreSQL 17 with pgvector 扩展(端口 5432
## 常用操作
### 查看日志
```bash
# 所有服务
docker compose logs -f
# 特定服务
docker compose logs -f simstudio
```
### 停止服务
```bash
docker compose down
```
### 更新到最新版本
```bash
docker compose pull
docker compose up -d
```
### 备份数据库
```bash
docker compose exec db pg_dump -U postgres simstudio > backup_$(date +%Y%m%d).sql
```
### 恢复数据库
```bash
cat backup.sql | docker compose exec -T db psql -U postgres simstudio
```
## 安全注意事项
- **更改默认凭据**:在生产环境中更新 `POSTGRES_PASSWORD`
- **生成强密钥**:使用 `openssl rand -hex 32` 生成所有密钥值
- **使用 HTTPS**配置反向代理Nginx/Caddy和 SSL 证书
- **网络隔离**:将数据库保持在内部网络
- **定期备份**:自动化数据库备份
- **定期更新**:拉取最新镜像获取安全补丁
## 生产环境部署
生产环境部署建议:
1. **使用反向代理**Nginx、Caddy、Traefik进行 SSL/TLS 终止
2. **配置防火墙**限制数据库访问
3. **设置监控**(健康检查、指标、日志)
4. **启用备份**(自动化 PostgreSQL 备份)
5. **使用外部数据库**以获得更好的性能和可靠性(可选)
Caddy 配置示例:
```caddy
sim.yourdomain.com {
reverse_proxy localhost:3000
handle /socket.io/* {
reverse_proxy localhost:3002
}
}
```
## 故障排查
### 模型不显示在下拉列表中
如果使用宿主机上的外部 Ollama请确保 `OLLAMA_URL` 使用 `host.docker.internal` 或宿主机 IP 地址,而不是 `localhost`
### 数据库连接错误
- 验证 PostgreSQL 健康状态:`docker compose ps`
- 检查数据库日志:`docker compose logs db`
- 确保迁移完成:`docker compose logs migrations`
### 端口冲突
如果端口已被占用,可以覆盖它们:
```bash
SIM_PORT_OVERRIDE=3100 \
SIM_REALTIME_PORT_OVERRIDE=3102 \
POSTGRES_PORT_OVERRIDE=5433 \
docker compose up -d
```
## 相关资源
- **官方文档**[https://docs.sim.ai](https://docs.sim.ai)
- **GitHub 仓库**[https://github.com/simstudioai/sim](https://github.com/simstudioai/sim)
- **云托管版本**[https://sim.ai](https://sim.ai)
- **自托管指南**[https://docs.sim.ai/self-hosting](https://docs.sim.ai/self-hosting)
## 许可证
此配置遵循 Sim 项目许可。请查看[官方仓库](https://github.com/simstudioai/sim)了解许可证详情。
## 支持
如有问题和疑问:
- GitHub Issues[https://github.com/simstudioai/sim/issues](https://github.com/simstudioai/sim/issues)
- 文档:[https://docs.sim.ai](https://docs.sim.ai)

View File

@@ -0,0 +1,136 @@
# Sim - AI Agent Workflow Builder
# Open-source platform to build and deploy AI agent workflows
# Documentation: https://docs.sim.ai
x-defaults: &defaults
restart: unless-stopped
logging:
driver: json-file
options:
max-size: ${LOG_MAX_SIZE:-100m}
max-file: "${LOG_MAX_FILE:-3}"
services:
simstudio:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}ghcr.io/simstudioai/simstudio:${SIM_VERSION:-latest}
ports:
- "${SIM_PORT_OVERRIDE:-3000}:3000"
environment:
- TZ=${TZ:-UTC}
- NODE_ENV=production
- DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio}
- BETTER_AUTH_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000}
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000}
- BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here}
- ENCRYPTION_KEY=${ENCRYPTION_KEY:-your_encryption_key_here}
- COPILOT_API_KEY=${COPILOT_API_KEY:-}
- SIM_AGENT_API_URL=${SIM_AGENT_API_URL:-}
- OLLAMA_URL=${OLLAMA_URL:-http://localhost:11434}
- SOCKET_SERVER_URL=${SOCKET_SERVER_URL:-http://localhost:3002}
- NEXT_PUBLIC_SOCKET_URL=${NEXT_PUBLIC_SOCKET_URL:-http://localhost:3002}
depends_on:
db:
condition: service_healthy
migrations:
condition: service_completed_successfully
realtime:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "--quiet", "http://127.0.0.1:3000"]
interval: 90s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: ${SIM_CPU_LIMIT:-4.0}
memory: ${SIM_MEMORY_LIMIT:-8G}
reservations:
cpus: ${SIM_CPU_RESERVATION:-2.0}
memory: ${SIM_MEMORY_RESERVATION:-4G}
realtime:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}ghcr.io/simstudioai/realtime:${SIM_REALTIME_VERSION:-latest}
ports:
- "${SIM_REALTIME_PORT_OVERRIDE:-3002}:3002"
environment:
- TZ=${TZ:-UTC}
- DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio}
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL:-http://localhost:3000}
- BETTER_AUTH_URL=${BETTER_AUTH_URL:-http://localhost:3000}
- BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET:-your_auth_secret_here}
depends_on:
db:
condition: service_healthy
healthcheck:
test: ["CMD", "wget", "--spider", "--quiet", "http://127.0.0.1:3002/health"]
interval: 90s
timeout: 10s
retries: 3
start_period: 30s
deploy:
resources:
limits:
cpus: ${SIM_REALTIME_CPU_LIMIT:-2.0}
memory: ${SIM_REALTIME_MEMORY_LIMIT:-4G}
reservations:
cpus: ${SIM_REALTIME_CPU_RESERVATION:-1.0}
memory: ${SIM_REALTIME_MEMORY_RESERVATION:-2G}
migrations:
image: ${GLOBAL_REGISTRY:-}ghcr.io/simstudioai/migrations:${SIM_MIGRATIONS_VERSION:-latest}
working_dir: /app/packages/db
environment:
- TZ=${TZ:-UTC}
- DATABASE_URL=postgresql://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@db:5432/${POSTGRES_DB:-simstudio}
depends_on:
db:
condition: service_healthy
command: ["bun", "run", "db:migrate"]
restart: "no"
logging:
driver: json-file
options:
max-size: ${LOG_MAX_SIZE:-100m}
max-file: "${LOG_MAX_FILE:-3}"
deploy:
resources:
limits:
cpus: ${SIM_MIGRATIONS_CPU_LIMIT:-1.0}
memory: ${SIM_MIGRATIONS_MEMORY_LIMIT:-512M}
reservations:
cpus: ${SIM_MIGRATIONS_CPU_RESERVATION:-0.5}
memory: ${SIM_MIGRATIONS_MEMORY_RESERVATION:-256M}
db:
<<: *defaults
image: ${GLOBAL_REGISTRY:-}pgvector/pgvector:${PGVECTOR_VERSION:-pg17}
ports:
- "${POSTGRES_PORT_OVERRIDE:-5432}:5432"
environment:
- TZ=${TZ:-UTC}
- POSTGRES_USER=${POSTGRES_USER:-postgres}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
- POSTGRES_DB=${POSTGRES_DB:-simstudio}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
interval: 10s
timeout: 5s
retries: 5
start_period: 10s
deploy:
resources:
limits:
cpus: ${POSTGRES_CPU_LIMIT:-2.0}
memory: ${POSTGRES_MEMORY_LIMIT:-2G}
reservations:
cpus: ${POSTGRES_CPU_RESERVATION:-1.0}
memory: ${POSTGRES_MEMORY_RESERVATION:-1G}
volumes:
postgres_data: