@guyycodes/plugin-sdk
Version:
AI-powered plugin scaffolding tool - Create full-stack applications with 7+ AI models, 50+ business integrations, and production-ready infrastructure
941 lines (812 loc) • 22.5 kB
JavaScript
// appConfig.js
const fs = require('fs-extra');
const path = require('path');
async function createAppConfigNode(projectPath, projectName, backendType, integration = 'quickbooks') {
const manifest = {
"description": "custom integration plugin with Ai agents",
"version": "1.3.0",
"license": "MIT",
"environment": "localhost",
"server-name": `${projectName}`,
"apiUrl": "https://api.example.com",
"backendTag": `${projectName}-ts-backend`,
"gpu": {
"supportGPU": false,
},
"langsmith": {
"apiUrl": "https://api.smith.langchain.com",
"projectName": `${projectName}`,
"tracingEnabled": true
},
"network": {
"name": `server-net`
},
"deployment": {
"dev": {
"host": `${projectName}-dev.unitera.ai`,
"frontendUrl": "levelupco-plugin-dev.b-cdn.net",
"bucket": "levelupco-dev"
},
"staging": {
"host": `${projectName}-staging.unitera.ai`,
"frontendUrl": "levelupco-plugin-staging.b-cdn.net/",
"bucket": "levelupco-staging"
},
},
"api": {
"port": [3000],
"endpoints": {
"chat": "/chat",
"streaming":"/ws/chat",
"env":"/env",
"thisAddress":"/node_address",
"net_agent":"/set_next_agent",
"select_model":"/select_model",
"models":"/models",
"tools":"/tools",
"data":"/api/data"
},
"healthCheck": "/health"
},
"pluginConfig": {
"schema": {
"pricing": {
"model": "",
"oneTimePrice": "",
"subscriptionTier": "",
"tokenCostPer1M": 0
}
}
},
"integrations": {
"autoSync": true,
"syncInterval": 15,
"readOnly": false,
"appIntegrations": [
"shopify",
"woocommerce",
"quickbooks",
"stripe"
]
},
"categories": [
"inventory",
"analytics",
"e-commerce",
"automation"
],
"keywords": [
"inventory",
"stock",
"warehouse",
"tracking",
"reorder",
"analytics"
],
"ui": {
"expose": "./PluginApp",
"appIcons": {
"small": "https://levelupco-plugin-staging.b-cdn.net/plugin-small.png",
"large": "https://levelupco-plugin-staging.b-cdn.net/plugin-large.png"
},
"screenshots": [
"https://levelupco-plugin-staging.b-cdn.net/dashboard.png",
"https://levelupco-plugin-staging.b-cdn.net/reports.png"
]
},
"permissions": [
"read:inventory",
"write:inventory",
"read:analytics",
"notifications:reorder",
"integrations:shopify",
"integrations:quickbooks"
]
};
fs.writeJsonSync(path.join(projectPath, 'app.config.json'), manifest, { spaces: 2 });
}
async function createAppConfigPython(projectPath, projectName, backendType, integration = 'quickbooks') {
const appConfig = {
"description": "custom integration plugin with Ai agents",
"version": "1.3.0",
"license": "MIT",
"environment": "localhost",
"server-name": `${projectName}`,
"author": {
"name": "Sarah Johnson",
"email": "sarah.johnson@inventech.com",
"url": "https://inventech.com"
},
"backendTag": `${projectName}-backend`,
"region": "dal",
"gpu": {
"supportGPU": true,
"host": "216.81.248.115:12966",
"gpuType": "gpu-nvidia-a100",
"gpuCount": 1,
"gpuMemory": 4096,
"supportedRegions": ["dal", "lax", "sfo"],
"types": [
"gpu-nvidia-rtx-4000-sff-ada",
"gpu-nvidia-l4",
"gpu-nvidia-rtx-a6000",
"gpu-nvidia-l40s",
"gpu-nvidia-a100",
"2x-gpu-nvidia-a100",
"4x-gpu-nvidia-a100",
"8x-gpu-nvidia-a100",
"gpu-nvidia-h100",
"2x-gpu-nvidia-h100",
"4x-gpu-nvidia-h100",
"8x-gpu-nvidia-h100"
]
},
"langsmith": {
"apiUrl": "https://api.smith.langchain.com",
"projectName": `${projectName}`,
"tracingEnabled": true
},
"network": {
"name": "server-net"
},
"deployment": {
"dev": {
"host": `${projectName}-dev.unitera.ai`,
"frontendUrl": "levelupco-plugin-dev.b-cdn.net",
"bucket": "levelupco-dev"
},
"staging": {
"host": `${projectName}-staging.unitera.ai`,
"frontendUrl": "levelupco-plugin-staging.b-cdn.net/",
"bucket": "levelupco-staging"
},
},
"models": [{
"name": "phi4",
"modalities": ["image", "text", "audio"],
"entrypoint": "src/server/models/Phi4_multimodal/entrypoint.py"
},
{
"name": "Qwen25Math",
"modalities": ["text"],
"entrypoint": "src/server/models/Qwen25Math/entrypoint.py"
},
{
"name": "DeepHermes3",
"modalities": ["text"],
"entrypoint": "src/server/models/DeepHermes3/entrypoint.py"
},
{
"name": "Flux",
"modalities": ["text", "image"],
"entrypoint": "src/server/models/Flux/entrypoint.py"
},
{
"name": "FluxKontext",
"modalities": ["text", "image"],
"entrypoint": "src/server/models/FluxKontext/entrypoint.py"
},
{
"name": "Qwen25VL",
"modalities": ["text", "image"],
"entrypoint": "src/server/models/Qwen25VL/entrypoint.py"
},
{
"name": "Qwen25Code",
"modalities": ["text", "code"],
"entrypoint": "src/server/models/Qwen25Code/entrypoint.py"
}
],
"agent": {
"maxTokensPerRequest": 4000,
"responseTimeout": 30,
"enableMemory": true
},
"api": {
"port": [3000],
"endpoints": {
"chat": "/chat",
"streaming":"/ws/chat",
"env":"/env",
"thisAddress":"/node_address",
"net_agent":"/set_next_agent",
"select_model":"/select_model",
"models":"/models",
"tools":"/tools",
"data":"/api/data"
},
"healthCheck": "/health"
},
"pluginConfig": {
"schema": {
"pricing": {
"model": "",
"oneTimePrice": "",
"subscriptionTier": "",
"tokenCostPer1M": 0
}
}
},
"integrations": {
"white-label":false,
"autoSync": true,
"syncInterval": 15,
"readOnly": false,
"appIntegrations": [
"shopify",
"woocommerce",
"quickbooks",
"stripe"
]
},
"categories": [
"inventory",
"analytics",
"e-commerce",
"automation"
],
"keywords": [
"inventory",
"stock",
"warehouse",
"tracking",
"reorder",
"analytics"
],
"ui": {
"expose": "./PluginApp",
"appIcons": {
"small": "https://levelupco-plugin-staging.b-cdn.net/plugin-small.png",
"large": "https://levelupco-plugin-staging.b-cdn.net/plugin-large.png"
},
"screenshots": [
"https://levelupco-plugin-staging.b-cdn.net/dashboard.png",
"https://levelupco-plugin-staging.b-cdn.net/reports.png"
]
},
"permissions": [
"read:inventory",
"write:inventory",
"read:analytics",
"notifications:reorder",
"integrations:shopify",
"integrations:quickbooks"
]
}
fs.writeJsonSync(path.join(projectPath, 'app.config.json'), appConfig, { spaces: 2 });
}
async function createDockerIgnore(projectPath, projectName) {
const dockerIgnore = `/src/client/
/src/client/**
/scripts/
/package.json
# If you have model images or outputs elsewhere, ignore those too
src/server/models/*/model/
src/server/models/*/*/model/
src/server/models/*/model/images_output/
src/server/models/*/images_output/
!app.config.json
!manifest.json
!langgraph.json
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
env/
ENV/
.venv/
.env.local/
.env.*.local/
src/server/venv/
# Model files (download at runtime instead)
*.safetensors
*.bin
*.onnx
*.pt
*.pth
*.h5
*.keras
# Development
.git/
.gitignore
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
# Testing
.pytest_cache/
.coverage
htmlcov/
.tox/
*.cover
*.log
# Documentation
docs/
!README.md
# Build artifacts
build/
dist/
*.egg-info/
.eggs/
# Temporary files
tmp/
temp/
*.tmp
*.bak
.cache/
# Jupyter
.ipynb_checkpoints/
*.ipynb
# Docker
Dockerfile*
docker-compose*.yml
.dockerignore
# CI/CD
.github/
.gitlab-ci.yml
.travis.yml
# Node modules (if any frontend assets)
node_modules/
# Large data files
*.csv
!package.json
!tsconfig.json
!langgraph.json
*.xml
*.parquet
# Images (except necessary ones)
*.jpg
*.jpeg
*.png
*.gif
*.bmp
!public/*.png
!public/*.svg`;
fs.writeFileSync(path.join(projectPath, '.dockerignore'), dockerIgnore);
}
async function createGitIgnore(projectPath, projectName) {
const gitignore = `# Dependencies
node_modules/
# Environment variables
.env
.env.local
# Build outputs
dist/
build/
# IDE files
.vscode/
.idea/
*.swp
# OS files
.DS_Store
Thumbs.db
# Logs
*.log
# Model weights and large files - UPDATED PATHS
src/server/models/*/model/
src/server/models/*/*/model/
src/server/models/*/model/images_output/
src/server/models/*/images_output/
*.safetensors
*.bin
*.pt
*.pth
*.onnx
*.h5
*.keras
# Virtual environment
src/server/venv/
venv/
ENV/
env/
# Jupyter notebooks
.ipynb_checkpoints/
# pytest
.pytest_cache/
# Coverage reports
htmlcov/
.coverage
.coverage.*
coverage.xml
*.cover
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg`;
fs.writeFileSync(path.join(projectPath, '.gitignore'), gitignore);
}
async function createReadmeMd(projectPath, projectName) {
const readmeMd = `\# Python LangGraph Multi-Model Agent Server
A production-ready Python agent server built with LangGraph that features multiple AI models, web search, image generation, multimodal support, and extensive business integrations.
\#\# 🚀 Features
- 🤖 **Multi-Model Support**: Seamlessly switch between models:
- **GPT-4o-mini**: OpenAI's efficient model for general tasks
- **Qwen2.5-Math-7B**: Specialized mathematical reasoning with step-by-step solutions
- **DeepHermes-3**: Advanced reasoning and instruction following
- **Phi-4**: Microsoft's multimodal model supporting images and audio
- **FLUX.1-schnell**: State-of-the-art image generation
- 🔍 **Web Search Integration**: Real-time web search using Tavily API
- 🖼️ **Image Generation**: Create AI images with natural language prompts
- 🎯 **Multimodal Support**: Process images and audio inputs (Phi-4)
- 📊 **LangSmith Telemetry**: Full observability and tracing
- 🔄 **Streaming Responses**: Server-sent events for real-time interaction
- 🛠️ **Extensible Tool System**: Easy-to-add tools and integrations
- 🏢 **Business Integrations**: Pre-built integrations for 10+ popular services
- 🐳 **Production Ready**: Docker support with GPU acceleration
- 🔐 **Session Management**: Maintain conversation context
\#\# 🏗️ Architecture
\`\`\`mermaid
graph TD
A[Client] -->|HTTP/SSE| B[FastAPI Server]
B --> C[LangGraph Agent]
C --> D[Model Router]
D --> E[GPT-4o-mini]
D --> F[Local Models]
F --> G[Qwen Math]
F --> H[DeepHermes]
F --> I[Phi-4 Multimodal]
F --> J[FLUX Image Gen]
C --> K[Tool System]
K --> L[Web Search]
K --> M[Calculator]
K --> N[Business Tools]
N --> O[QuickBooks/Stripe/etc]
C --> P[LangSmith Telemetry]
B --> Q[Model Manager]
Q --> R[Auto Download]
\`\`\`
\#\# 🎯 Quick Start
\#\#\# Prerequisites
- Python 3.11+
- 8GB+ RAM (16GB+ recommended for local models)
- GPU (optional but recommended):
- Apple Silicon Mac (M1/M2/M3/M4) for MPS acceleration
- NVIDIA GPU with CUDA 12.2+ for Linux/Windows
- API Keys:
- OpenAI API Key (required)
- Tavily API Key (required for web search)
- LangChain/LangSmith API Key (required for telemetry)
- Business integration API keys (optional)
\#\#\# 1. Clone and Install
\`\`\`bash
git clone <your-repo>
cd python_agent/src/server
# Create virtual environment
python -m venv venv
source venv/bin/activate \# On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
\`\`\`
\#\#\# 2. Environment Setup
Create a \`.env\` file:
\`\`\`env
# Core API Keys (Required)
OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
LANGCHAIN_API_KEY=your_langchain_api_key_here
# LangSmith Configuration
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=chatbot-agent
LANGCHAIN_ENDPOINT=https://api.smith.langchain.com
# Optional: Business Integration Keys
QUICKBOOKS_CLIENT_ID=your_quickbooks_client_id
QUICKBOOKS_CLIENT_SECRET=your_quickbooks_client_secret
STRIPE_API_KEY=sk_live_...
SQUARE_ACCESS_TOKEN=...
SHOPIFY_STORE_URL=your-store.myshopify.com
SHOPIFY_ACCESS_TOKEN=...
MAILCHIMP_API_KEY=...
MAILCHIMP_SERVER_PREFIX=us1
HUBSPOT_ACCESS_TOKEN=...
SLACK_BOT_TOKEN=xoxb-...
CALENDLY_API_KEY=...
GOOGLE_SERVICE_ACCOUNT_FILE=path/to/service-account.json
# Server Configuration
PORT=3000
NODE_ENV=production
\`\`\`
\#\#\# 3. Run the Server
\`\`\`bash
# Development mode
python main.py
# Production mode with Gunicorn
gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:3000
\`\`\`
The server will start on \`http://localhost:3000\`
## 📡 API Endpoints
### Health & Status
\`\`\`bash
GET /health # Server health check
GET /env # Environment configuration
GET /tools # List available tools
GET /models # List models and availability
\`\`\`
### Chat Endpoints
#### Standard Chat
\`\`\`bash
POST /chat
Content-Type: application/json
{
"message": "What's the weather in San Francisco?",
"sessionId": "user-123",
"model": "gpt-4o-mini" # Optional: defaults to gpt-4o-mini
}
\`\`\`
#### Streaming Chat
\`\`\`bash
POST /chat/stream
Content-Type: application/json
{
"message": "Explain quantum computing",
"sessionId": "user-123",
"model": "DeepHermes3"
}
\`\`\`
Returns Server-Sent Events stream.
#### Multimodal Chat (Phi-4)
\`\`\`bash
POST /chat
Content-Type: application/json
{
"message": "What's in this image?",
"model": "phi4",
"images": ["https://example.com/image.jpg"],
"audios": ["path/to/audio.wav"]
}
\`\`\`
#### Image Generation (FLUX)
\`\`\`bash
POST /chat
Content-Type: application/json
{
"message": "A cyberpunk city at sunset with flying cars",
"model": "Flux"
}
\`\`\`
### Model Management
\`\`\`bash
POST /select_model
Content-Type: application/json
{
"model": "Qwen25Math"
}
\`\`\`
Downloads the model if not available, then activates it.
\#\# 🤖 Available Models
\#\#\# GPT-4o-mini (Default)
- **Type**: API-based (OpenAI)
- **Best for**: General queries, web search, tool use
- **Features**: Fast, efficient, supports all tools
\#\#\# Qwen2.5-Math-7B
- **Type**: Local model (7B parameters)
- **Best for**: Mathematical problems, calculations, proofs
- **Features**: Step-by-step reasoning, LaTeX support
- **Requirements**: ~15GB disk space, 8GB+ RAM
\#\#\# DeepHermes-3-Llama-3-8B
- **Type**: Local model (8B parameters)
- **Best for**: Complex reasoning, detailed explanations
- **Features**: Enhanced instruction following
- **Requirements**: ~16GB disk space, 8GB+ RAM
\#\#\# Phi-4 Multimodal
- **Type**: Local model (14B parameters)
- **Best for**: Analyzing images and audio
- **Features**: Vision + audio understanding
- **Requirements**: ~28GB disk space, 16GB+ RAM
\#\#\# FLUX.1-schnell
- **Type**: Local model (12B parameters)
- **Best for**: High-quality image generation
- **Features**: Fast image creation, 1024x1024 default
- **Requirements**: ~24GB disk space, GPU recommended
\#\# 🛠️ Tool System
\#\#\# Built-in Tools
\#\#\#\# Web Search
\`\`\`python
@tool
def web_search(query: str) -> str:
"""Search the web for current information"""
\`\`\`
\#\#\#\# Calculator
\`\`\`python
@tool
def calculator(expression: str) -> str:
"""Perform mathematical calculations"""
\`\`\`
\#\#\# Business Integrations
The server includes pre-built integrations for:
- **💳 Payment & Finance**: QuickBooks, Stripe, Square
- **🛍️ E-commerce**: Shopify
- **📧 Marketing & CRM**: Mailchimp, HubSpot
- **💬 Communication**: Slack
- **📅 Scheduling**: Calendly
- **📊 Analytics**: Looker Studio
- **🔧 Developer Tools**: MCP (Model Context Protocol)
See [integrations/README.md](integrations/README.md) for detailed setup and usage.
\#\#\# Adding Custom Tools
1. Create a new tool:
\`\`\`python
# tools/my_custom_tool.py
from langchain_core.tools import tool
@tool
def my_custom_tool(param: str) -> str:
"""Description of what the tool does"""
# Implementation
return "Result"
\`\`\`
2. Register in \`tools/tools.py\`:
\`\`\`python
from tools.my_custom_tool import my_custom_tool
AVAILABLE_TOOLS["my_custom_tool"] = my_custom_tool
\`\`\`
\#\# 💡 Usage Examples
### Mathematical Problem Solving
\`\`\`bash
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Solve x^2 + 5x + 6 = 0",
"model": "Qwen25Math"
}'
\`\`\`
### Image Analysis
\`\`\`bash
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "Describe this chart and explain the trends",
"model": "phi4",
"images": ["data:image/png;base64,iVBORw0KG..."]
}'
\`\`\`
### Image Generation
\`\`\`bash
curl -X POST http://localhost:3000/chat \
-H "Content-Type: application/json" \
-d '{
"message": "A serene Japanese garden with cherry blossoms",
"model": "Flux"
}'
\`\`\`
\#\#\# Business Automation
\`\`\`python
# Example: Create invoice and notify customer
message = """
Create a QuickBooks invoice for John Doe (john@example.com)
for $500 consulting services, then send them a Slack message
about the invoice.
"""
\`\`\`
\#\# 🐳 Docker Deployment
\#\#\# Standard Deployment
\`\`\`bash
docker build -t python-agent .
docker run -p 3000:3000 \
-e OPENAI_API_KEY=$OPENAI_API_KEY \
-e TAVILY_API_KEY=$TAVILY_API_KEY \
-e LANGCHAIN_API_KEY=$LANGCHAIN_API_KEY \
python-agent
\`\`\`
\#\#\# GPU-Enabled Deployment
\`\`\`bash
\# For NVIDIA GPUs
docker run --gpus all -p 3000:3000 \
-v $(pwd)/models:/app/models \
python-agent
# For development with volume mounts
docker run --gpus all -p 3000:3000 \
-v $(pwd):/app \
-v /app/venv \
python-agent
\`\`\`
\#\#\# Monitoring & Observability
All agent operations are traced to LangSmith when \`LANGCHAIN_TRACING_V2=true\`.
View traces at: https://smith.langchain.com
Key metrics tracked:
- Message flow through the agent graph
- Tool invocations and results
- Model inference times and token usage
- Error rates and debugging information
- Multi-step reasoning chains
\#\#\# Advanced Configuration
\#\#\#\# Memory Management
For large models on limited GPU memory:
\`\`\`python
# In model initialization
pipeline.enable_attention_slicing()
pipeline.enable_vae_slicing()
pipeline.enable_sequential_cpu_offload()
\`\`\`
\#\#\# Custom Model Parameters
\`\`\`python
# When calling chat endpoint
{
"message": "Your prompt",
"model": "gpt-4o-mini",
"temperature": 0.7,
"max_tokens": 1000
}
\`\`\`
\#\#\#\# Session Persistence
Sessions are maintained in memory by default. For production, configure Redis:
\`\`\`env
REDIS_URI=redis://localhost:6379
\`\`\`
\#\# 🆘 Troubleshooting
\#\#\# Common Issues
1. **Model Download Failures**
- Ensure sufficient disk space (50GB+ for all models)
- Check internet connection
- Try manual download: \`cd models/ModelName && python download_model.py\`
2. **GPU/MPS Not Detected**
- Verify PyTorch installation: \`python -c "import torch; print(torch.cuda.is_available())"\`
- For Mac: \`python -c "import torch; print(torch.backends.mps.is_available())"\`
- Reinstall PyTorch with appropriate CUDA version
3. **Memory Errors**
- Reduce batch size or image resolution
- Enable CPU offloading
- Use quantized models when available
4. **API Key Issues**
- Verify keys are set correctly in \`.env\`
- Check API key permissions and quotas
- Ensure no extra spaces or quotes in values
\#\#\# Debug Mode
\`\`\`bash
\# Enable debug logging
export LOG_LEVEL=DEBUG
python main.py
\`\`\`
\#\#\# Performance Optimization
1. **Model Loading**
- Models are cached after first load
- Use \`select_model\` endpoint to pre-load models
2. **Inference Speed**
- GPU acceleration provides 10-50x speedup
- Use appropriate model for task (don't use Phi-4 for simple text)
- Enable streaming for better perceived performance
3. **Concurrent Requests**
- Use Gunicorn with multiple workers
- Configure based on available RAM/VRAM
- Monitor with LangSmith for bottlenecks
\#\#\# Contributing
1. Fork the repository
2. Create a feature branch
3. Add tests for new functionality
4. Submit a pull request
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
\#\#\# Additional Resources
- [LangGraph Documentation](https://python.langchain.com/docs/langgraph)
- [Integration Guide](integrations/README.md)
- [Model Documentation](models/README.md)
- [API Reference](docs/API.md)
\#\#\# License
Apache 2.0 License - see [LICENSE](LICENSE) file for details.
`;
fs.writeFileSync(path.join(projectPath, 'README.md'), readmeMd);
}
module.exports = {
createReadmeMd,
createAppConfigNode,
createAppConfigPython,
createDockerIgnore,
createGitIgnore,
};