.agents/skills/upstash-workflow/reference/cloud.md
This document covers cloud-specific workflow configurations and patterns for the lobehub-cloud project.
The lobehub-cloud project extends the open-source lobehub codebase with cloud-specific features. Workflows can be implemented in either:
lobehub/
└── src/
├── app/(backend)/api/workflows/
│ ├── memory-user-memory/ # Memory extraction workflows
│ └── agent-eval-run/ # Benchmark evaluation workflows
└── server/workflows/
├── agentEvalRun/
└── ...
lobehub-cloud/
└── src/
├── app/(backend)/api/workflows/
│ ├── welcome-placeholder/ # Cloud-only: AI placeholder generation
│ ├── agent-welcome/ # Cloud-only: Agent welcome messages
│ ├── agent-eval-run/ # Re-export from lobehub
│ └── memory-user-memory/ # Re-export from lobehub
└── server/workflows/
├── welcomePlaceholder/
├── agentWelcome/
└── agentEvalRun/ # Re-export from lobehub
Use Case: Features exclusive to cloud users (AI generation, premium features)
Example: welcome-placeholder, agent-welcome
Implementation:
lobehub-cloud/src/app/(backend)/api/workflows/Structure:
lobehub-cloud/src/
├── app/(backend)/api/workflows/
│ └── feature-name/
│ ├── process-items/route.ts
│ ├── paginate-items/route.ts
│ └── execute-item/route.ts
└── server/workflows/
└── featureName/
└── index.ts
Use Case: Workflows implemented in open-source but also used in cloud
Example: agent-eval-run, memory-user-memory
Why Re-export?
Step 1: Implement workflow in lobehub submodule
// lobehub/src/app/(backend)/api/workflows/feature/layer/route.ts
import { serve } from '@upstash/workflow/nextjs';
export const { POST } = serve<Payload>(
async (context) => {
// Implementation
},
{ flowControl: { ... } }
);
Step 2: Create re-export in lobehub-cloud
// lobehub-cloud/src/app/(backend)/api/workflows/feature/layer/route.ts
export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature/layer/route';
Important: Use lobehub/src/... path, NOT @/... to avoid circular imports.
# Create directories
mkdir -p lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-1
mkdir -p lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-2
mkdir -p lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-3
# Create re-export files
echo "export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature-name/layer-1/route';" > \
lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-1/route.ts
echo "export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature-name/layer-2/route';" > \
lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-2/route.ts
echo "export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature-name/layer-3/route';" > \
lobehub-cloud/src/app/(backend)/api/workflows/feature-name/layer-3/route.ts
The cloud project uses tsconfig path mappings to override lobehub code:
// lobehub-cloud/tsconfig.json
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*", "./lobehub/src/*"]
}
}
}
Resolution Order:
./src/* (cloud code) - checked first./lobehub/src/* (open-source) - fallbackThis allows cloud to override specific modules while using lobehub defaults.
Place workflow class in cloud:
lobehub-cloud/src/server/workflows/featureName/index.ts
Place workflow class in lobehub, re-export in cloud if needed:
lobehub/src/server/workflows/featureName/index.ts
Both lobehub and cloud workflows require:
# Required for all workflows
APP_URL=https://your-app.com # Base URL for workflow endpoints
QSTASH_TOKEN=qstash_xxx # QStash authentication token
# Optional (for custom QStash URL)
QSTASH_URL=https://custom-qstash.com # Custom QStash endpoint
Cloud-Specific:
# Cloud database (for monetization features)
CLOUD_DATABASE_URL=postgresql://...
# Cloud-specific services
REDIS_URL=redis://...
Implement in Lobehub if:
Implement in Cloud if:
✅ Do:
// Simple re-export
export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature/route';
❌ Don't:
// Avoid circular imports with @/ path
export { POST } from '@/app/(backend)/api/workflows/feature/route'; // ❌
For shared features:
lobehub/ (open-source)Follow consistent naming across lobehub and cloud:
# Both should use same structure
lobehub/src/app/(backend)/api/workflows/feature-name/
lobehub-cloud/src/app/(backend)/api/workflows/feature-name/
Step 1: Copy workflow to lobehub
cp -r lobehub-cloud/src/app/(backend)/api/workflows/feature \
lobehub/src/app/(backend)/api/workflows/
Step 2: Remove cloud-specific dependencies
Step 3: Create re-exports in cloud
// lobehub-cloud/src/app/(backend)/api/workflows/feature/*/route.ts
export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature/*/route';
Step 4: Move workflow class to lobehub
mv lobehub-cloud/src/server/workflows/feature \
lobehub/src/server/workflows/
Step 5: Update cloud imports
// Change from
import { Workflow } from '@/server/workflows/feature';
// To
import { Workflow } from 'lobehub/src/server/workflows/feature';
Location: lobehub-cloud/src/app/(backend)/api/workflows/welcome-placeholder/
Why Cloud-Only: Uses proprietary AI generation service and Redis caching
Structure:
lobehub-cloud/
├── src/app/(backend)/api/workflows/welcome-placeholder/
│ ├── process-users/route.ts
│ ├── paginate-users/route.ts
│ └── generate-user/route.ts
└── src/server/workflows/welcomePlaceholder/
└── index.ts
Location:
lobehub/src/app/(backend)/api/workflows/agent-eval-run/lobehub-cloud/src/app/(backend)/api/workflows/agent-eval-run/Why Re-export: Core feature available in open-source, also used by cloud
Cloud Re-export Files:
// lobehub-cloud/src/app/(backend)/api/workflows/agent-eval-run/run-benchmark/route.ts
export { POST } from 'lobehub/src/app/(backend)/api/workflows/agent-eval-run/run-benchmark/route';
// lobehub-cloud/src/app/(backend)/api/workflows/agent-eval-run/paginate-test-cases/route.ts
export { POST } from 'lobehub/src/app/(backend)/api/workflows/agent-eval-run/paginate-test-cases/route';
// ... (all layers)
Error: Circular definition of import alias 'POST'
Cause: Using @/ path in re-export within cloud codebase
Solution: Use lobehub/src/ path instead
// ❌ Wrong
export { POST } from '@/app/(backend)/api/workflows/feature/route';
// ✅ Correct
export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature/route';
Cause: Missing re-export in cloud
Solution: Create re-export files for all workflow layers
# Check if re-export exists
ls lobehub-cloud/src/app/\(backend\)/api/workflows/feature-name/
# If missing, create re-exports
mkdir -p lobehub-cloud/src/app/\(backend\)/api/workflows/feature-name/layer
echo "export { POST } from 'lobehub/src/app/(backend)/api/workflows/feature-name/layer/route';" > lobehub-cloud/src/app/\(backend\)/api/workflows/feature-name/layer/route.ts
Cause: Cloud-specific types or services used in lobehub code
Solution: