[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6CSK091RY8Y5430K19V64YG":3,"skill-same:01M6CSK091RY8Y5430K19V64YG":101},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":34,"publishedAt":55,"linkOnly":56,"markdownContent":57,"markdownBody":58,"frontMatter":59,"refName":69,"commitSha":70,"skillDirectory":71,"forksCount":72,"repositoryHtmlUrl":73,"repositoryHomepageUrl":73,"ownerHtmlUrl":74,"ownerBlogUrl":6,"ownerDescription":75,"updatedAt":76,"install":77,"resources":90},"01M6CSK091RY8Y5430K19V64YG","comfyui-gateway",null,"REST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).","Sam-06060\u002Fjarvis-assistant","Sam-06060","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F208600848?v=4","01M6CRKT7C7FXD21V6HXF293S0","Samson Frank Ganta","01M6CRKTBEKYFD8YX5Z1GT99EE",6,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fcomfyui-gateway\u002FSKILL.md",[18,23,26,29],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000016","图像与多媒体",{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":30,"categoryName":31,"taxonomyType":32,"taxonomyTypeDesc":33},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54],"comfyui gateway","comfyui","gateway","base64","delivery","community","image-generation","webhooks","api","api-gateway","REST","image","api gateway","code","auth","workflow","gemini","typescript","safe","cli","2026-11-10 10:12:30",false,"---\nname: comfyui-gateway\ndescription: REST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\nrisk: safe\nsource: community\ndate_added: '2026-03-06'\nauthor: renat\ntags:\n- comfyui\n- api-gateway\n- image-generation\n- typescript\ntools:\n- claude-code\n- antigravity\n- cursor\n- gemini-cli\n- codex-cli\n---\n\n# ComfyUI Gateway\n\n## Overview\n\nREST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\n\n## When to Use This Skill\n\n- When the user mentions \"comfyui\" or related topics\n- When the user mentions \"comfy ui\" or related topics\n- When the user mentions \"stable diffusion api gateway\" or related topics\n- When the user mentions \"gateway comfyui\" or related topics\n- When the user mentions \"api gateway imagens\" or related topics\n- When the user mentions \"queue imagens\" or related topics\n\n## Do Not Use This Skill When\n\n- The task is unrelated to comfyui gateway\n- A simpler, more specific tool can handle the request\n- The user needs general-purpose assistance without domain expertise\n\n## How It Works\n\nA production-grade REST API gateway that transforms any ComfyUI server into a universal,\nsecure, and scalable service. Supports workflow templates with placeholders, job queuing\nwith priorities, webhook callbacks, result caching, and multiple storage backends.\n\n## Architecture Overview\n\n```\n┌─────────────┐     ┌──────────────────────────────────┐     ┌──────────┐\n│   Clients    │────▶│        ComfyUI Gateway           │────▶│ ComfyUI  │\n│ (curl, n8n,  │     │                                  │     │ Server   │\n│  Claude,     │     │  ┌─────────┐  ┌──────────────┐  │     │ (local\u002F  │\n│  Lovable,    │     │  │ Fastify │  │ BullMQ Queue │  │     │  remote) │\n│  Supabase)   │     │  │ API     │──│ (or in-mem)  │  │     └──────────┘\n│              │◀────│  └─────────┘  └──────────────┘  │\n│              │     │  ┌─────────┐  ┌──────────────┐  │     ┌──────────┐\n│              │     │  │ Auth +  │  │ Storage      │  │────▶│ S3\u002FMinIO │\n│              │     │  │ RateL.  │  │ (local\u002FS3)   │  │     │(optional)│\n│              │     │  └─────────┘  └──────────────┘  │     └──────────┘\n└─────────────┘     └──────────────────────────────────┘\n```\n\n## Components\n\n| Component | Purpose | File(s) |\n|-----------|---------|---------|\n| **API Gateway** | REST endpoints, validation, CORS | `src\u002Fapi\u002F` |\n| **Worker** | Processes jobs, talks to ComfyUI | `src\u002Fworker\u002F` |\n| **ComfyUI Client** | HTTP + WebSocket to ComfyUI | `src\u002Fcomfyui\u002F` |\n| **Workflow Manager** | Template storage, placeholder rendering | `src\u002Fworkflows\u002F` |\n| **Storage Provider** | Local disk + S3-compatible | `src\u002Fstorage\u002F` |\n| **Cache** | Hash-based deduplication | `src\u002Fcache\u002F` |\n| **Notifier** | Webhook with HMAC signing | `src\u002Fnotifications\u002F` |\n| **Auth** | API key + JWT + rate limiting | `src\u002Fauth\u002F` |\n| **DB** | SQLite (better-sqlite3) or Postgres | `src\u002Fdb\u002F` |\n| **CLI** | Init, add-workflow, run, worker | `src\u002Fcli\u002F` |\n\n## Quick Start\n\n```bash\n\n## 1. Install\n\ncd comfyui-gateway\nnpm install\n\n## 2. Configure\n\ncp .env.example .env\n\n## 3. Initialize\n\nnpx tsx src\u002Fcli\u002Findex.ts init\n\n## 4. Add A Workflow\n\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow .\u002Fworkflows\u002Fsdxl_realism_v1.json \\\n  --id sdxl_realism_v1 --schema .\u002Fworkflows\u002Fsdxl_realism_v1.schema.json\n\n## 5. Start (Api + Worker In One Process)\n\nnpm run dev\n\n## Or Separately:\n\nnpm run start:api   # API only\nnpm run start:worker # Worker only\n```\n\n## Environment Variables\n\nAll configuration is via `.env` — nothing is hardcoded:\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `PORT` | `3000` | API server port |\n| `HOST` | `0.0.0.0` | API bind address |\n| `COMFYUI_URL` | `http:\u002F\u002F127.0.0.1:8188` | ComfyUI server URL |\n| `COMFYUI_TIMEOUT_MS` | `300000` | Max wait for ComfyUI (5min) |\n| `API_KEYS` | `\"\"` | Comma-separated API keys (`key:role`) |\n| `JWT_SECRET` | `\"\"` | JWT signing secret (empty = JWT disabled) |\n| `REDIS_URL` | `\"\"` | Redis URL (empty = in-memory queue) |\n| `DATABASE_URL` | `.\u002Fdata\u002Fgateway.db` | SQLite path or Postgres URL |\n| `STORAGE_PROVIDER` | `local` | `local` or `s3` |\n| `STORAGE_LOCAL_PATH` | `.\u002Fdata\u002Foutputs` | Local output directory |\n| `S3_ENDPOINT` | `\"\"` | S3\u002FMinIO endpoint |\n| `S3_BUCKET` | `\"\"` | S3 bucket name |\n| `S3_ACCESS_KEY` | `\"\"` | S3 access key |\n| `S3_SECRET_KEY` | `\"\"` | S3 secret key |\n| `S3_REGION` | `us-east-1` | S3 region |\n| `WEBHOOK_SECRET` | `\"\"` | HMAC signing secret for webhooks |\n| `WEBHOOK_ALLOWED_DOMAINS` | `*` | Comma-separated allowed callback domains |\n| `MAX_CONCURRENCY` | `1` | Parallel jobs per GPU |\n| `MAX_IMAGE_SIZE` | `2048` | Maximum dimension (width or height) |\n| `MAX_BATCH_SIZE` | `4` | Maximum batch size |\n| `CACHE_ENABLED` | `true` | Enable result caching |\n| `CACHE_TTL_SECONDS` | `86400` | Cache TTL (24h) |\n| `RATE_LIMIT_MAX` | `100` | Requests per window |\n| `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit window (1min) |\n| `LOG_LEVEL` | `info` | Pino log level |\n| `PRIVACY_MODE` | `false` | Redact prompts from logs |\n| `CORS_ORIGINS` | `*` | Allowed CORS origins |\n| `NODE_ENV` | `development` | Environment |\n\n## Health & Capabilities\n\n```\nGET \u002Fhealth\n→ { ok: true, version, comfyui: { reachable, url, models? }, uptime }\n\nGET \u002Fcapabilities\n→ { workflows: [...], maxSize, maxBatch, formats, storageProvider }\n```\n\n## Workflows (Crud)\n\n```\nGET    \u002Fworkflows            → list all workflows\nPOST   \u002Fworkflows            → register new workflow\nGET    \u002Fworkflows\u002F:id        → workflow details + input schema\nPUT    \u002Fworkflows\u002F:id        → update workflow\nDELETE \u002Fworkflows\u002F:id        → remove workflow\n```\n\n## Jobs\n\n```\nPOST   \u002Fjobs                 → create job (returns jobId immediately)\nGET    \u002Fjobs\u002F:jobId          → status + progress + outputs\nGET    \u002Fjobs\u002F:jobId\u002Flogs     → sanitized execution logs\nPOST   \u002Fjobs\u002F:jobId\u002Fcancel   → request cancellation\nGET    \u002Fjobs                 → list jobs (filters: status, workflowId, after, before, limit)\n```\n\n## Outputs\n\n```\nGET    \u002Foutputs\u002F:jobId       → list output files + metadata\nGET    \u002Foutputs\u002F:jobId\u002F:file → download\u002Fstream file\n```\n\n## Job Lifecycle\n\n```\nqueued → running → succeeded\n                 → failed\n                 → canceled\n```\n\n1. Client POSTs to `\u002Fjobs` with workflowId + inputs\n2. Gateway validates, checks cache, checks idempotency\n3. If cache hit → returns existing outputs immediately (status: `cache_hit`)\n4. Otherwise → enqueues job, returns `jobId` + `pollUrl`\n5. Worker picks up job, renders workflow template, submits to ComfyUI\n6. Worker polls ComfyUI for progress (or listens via WebSocket)\n7. On completion → downloads outputs, stores them, updates DB\n8. If callbackUrl → sends signed webhook POST\n9. Client polls `\u002Fjobs\u002F:jobId` or receives webhook\n\n## Workflow Templates\n\nWorkflows are ComfyUI JSON with `{{placeholder}}` tokens. The gateway resolves\nthese at runtime using the job's `inputs` and `params`:\n\n```json\n{\n  \"3\": {\n    \"class_type\": \"KSampler\",\n    \"inputs\": {\n      \"seed\": \"{{seed}}\",\n      \"steps\": \"{{steps}}\",\n      \"cfg\": \"{{cfg}}\",\n      \"sampler_name\": \"{{sampler}}\",\n      \"scheduler\": \"normal\",\n      \"denoise\": 1,\n      \"model\": [\"4\", 0],\n      \"positive\": [\"6\", 0],\n      \"negative\": [\"7\", 0],\n      \"latent_image\": [\"5\", 0]\n    }\n  },\n  \"6\": {\n    \"class_type\": \"CLIPTextEncode\",\n    \"inputs\": {\n      \"text\": \"{{prompt}}\",\n      \"clip\": [\"4\", 1]\n    }\n  }\n}\n```\n\nEach workflow has an `inputSchema` (Zod) that validates what the client sends.\n\n## Security Model\n\n- **API Keys**: `X-API-Key` header; keys configured via `API_KEYS` env var as `key1:admin,key2:user`\n- **JWT**: Optional; when `JWT_SECRET` is set, accepts `Authorization: Bearer \u003Ctoken>`\n- **Roles**: `admin` (full CRUD on workflows + jobs), `user` (create jobs, read own jobs)\n- **Rate Limiting**: Per key + per IP, configurable window and max\n- **Webhook Security**: HMAC-SHA256 signature in `X-Signature` header\n- **Callback Allowlist**: Only approved domains receive webhooks\n- **Privacy Mode**: When enabled, prompts are redacted from logs and DB\n- **Idempotency**: `metadata.requestId` prevents duplicate processing\n- **CORS**: Configurable allowed origins\n- **Input Validation**: Zod schemas on every endpoint; max size\u002Fbatch enforced\n\n## Comfyui Integration\n\nThe gateway communicates with ComfyUI via its native HTTP API:\n\n| ComfyUI Endpoint | Gateway Usage |\n|------------------|---------------|\n| `POST \u002Fprompt` | Submit rendered workflow |\n| `GET \u002Fhistory\u002F{id}` | Poll job completion |\n| `GET \u002Fview?filename=...` | Download generated images |\n| `GET \u002Fobject_info` | Discover available nodes\u002Fmodels |\n| `WS \u002Fws?clientId=...` | Real-time progress (optional) |\n\nThe client auto-detects ComfyUI version and adapts:\n- Tries WebSocket first for progress, falls back to polling\n- Handles both `\u002Fhistory` response formats\n- Detects OOM errors and classifies them with recommendations\n\n## Cache Strategy\n\nCache key = SHA-256 of `workflowId + sorted(inputs) + sorted(params) + checkpoint`.\nOn cache hit, the gateway returns a \"virtual\" job with pre-existing outputs — no GPU\ncomputation needed. Cache is stored alongside job data in the DB with configurable TTL.\n\n## Error Classification\n\n| Error Code | Meaning | Retry? |\n|------------|---------|--------|\n| `COMFYUI_UNREACHABLE` | Cannot connect to ComfyUI | Yes (with backoff) |\n| `COMFYUI_OOM` | Out of memory on GPU | No (reduce dimensions) |\n| `COMFYUI_TIMEOUT` | Execution exceeded timeout | Maybe (increase timeout) |\n| `COMFYUI_NODE_ERROR` | Node execution failed | No (check workflow) |\n| `VALIDATION_ERROR` | Invalid inputs | No (fix request) |\n| `WORKFLOW_NOT_FOUND` | Unknown workflowId | No (register workflow) |\n| `RATE_LIMITED` | Too many requests | Yes (wait) |\n| `AUTH_FAILED` | Invalid\u002Fmissing credentials | No (fix auth) |\n| `CACHE_HIT` | (Not an error) Served from cache | N\u002FA |\n\n## Bundled Workflows\n\nThree production-ready workflow templates are included:\n\n## 1. `Sdxl_Realism_V1` — Photorealistic Generation\n\n- Checkpoint: SDXL base\n- Optimized for: Portraits, landscapes, product shots\n- Default: 1024x1024, 30 steps, cfg 7.0\n\n## 2. `Sprite_Transparent_Bg` — Game Sprites With Alpha\n\n- Checkpoint: SD 1.5 or SDXL\n- Optimized for: 2D game assets, transparent backgrounds\n- Default: 512x512, 25 steps, cfg 7.5\n\n## 3. `Icon_512` — App Icons With Optional Upscale\n\n- Checkpoint: SDXL base\n- Optimized for: Square icons, clean edges\n- Default: 512x512, 20 steps, cfg 6.0, optional 2x upscale\n\n## Observability\n\n- **Structured Logs**: Pino JSON logs with `correlationId` on every request\n- **Metrics**: Jobs queued\u002Frunning\u002Fsucceeded\u002Ffailed, avg processing time, cache hit rate\n- **Audit Log**: Admin actions (workflow CRUD, key management) logged with timestamp + actor\n\n## Cli Reference\n\n```bash\nnpx tsx src\u002Fcli\u002Findex.ts init                    # Create dirs, .env.example\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow \u003Cfile>      # Register workflow template\n  --id \u003Cid> --name \u003Cname> --schema \u003Cschema.json>\nnpx tsx src\u002Fcli\u002Findex.ts list-workflows           # Show registered workflows\nnpx tsx src\u002Fcli\u002Findex.ts run                      # Start API server\nnpx tsx src\u002Fcli\u002Findex.ts worker                   # Start job worker\nnpx tsx src\u002Fcli\u002Findex.ts health                   # Check ComfyUI connectivity\n```\n\n## Troubleshooting\n\nRead `references\u002Ftroubleshooting.md` for detailed guidance on:\n- ComfyUI not reachable (firewall, wrong port, Docker networking)\n- OOM errors (reduce resolution, batch, or steps)\n- Slow generation (GPU utilization, queue depth, model loading)\n- Webhook failures (DNS, SSL, timeout, domain allowlist)\n- Redis connection issues (fallback to in-memory)\n- Storage permission errors (local path, S3 credentials)\n\n## Integration Examples\n\nRead `references\u002Fintegration.md` for ready-to-use examples with:\n- curl commands for every endpoint\n- n8n webhook workflow\n- Supabase Edge Function caller\n- Claude Code \u002F Claude.ai integration\n- Python requests client\n- JavaScript fetch client\n\n## File Structure\n\n```\ncomfyui-gateway\u002F\n├── SKILL.md\n├── package.json\n├── tsconfig.json\n├── .env.example\n├── src\u002F\n│   ├── api\u002F\n│   │   ├── server.ts          # Fastify setup + plugins\n│   │   ├── routes\u002F\n│   │   │   ├── health.ts      # GET \u002Fhealth, \u002Fcapabilities\n│   │   │   ├── workflows.ts   # CRUD \u002Fworkflows\n│   │   │   ├── jobs.ts        # CRUD \u002Fjobs\n│   │   │   └── outputs.ts     # GET \u002Foutputs\n│   │   ├── middleware\u002F\n│   │   │   └── error-handler.ts\n│   │   └── plugins\u002F\n│   │       ├── auth.ts        # API key + JWT\n│   │       ├── rate-limit.ts\n│   │       └── cors.ts\n│   ├── worker\u002F\n│   │   └── processor.ts       # Job processor\n│   ├── comfyui\u002F\n│   │   └── client.ts          # ComfyUI HTTP + WS client\n│   ├── storage\u002F\n│   │   ├── index.ts           # Provider factory\n│   │   ├── local.ts           # Local filesystem\n│   │   └── s3.ts              # S3-compatible\n│   ├── workflows\u002F\n│   │   └── manager.ts         # Template CRUD + rendering\n│   ├── cache\u002F\n│   │   └── index.ts           # Hash-based cache\n│   ├── notifications\u002F\n│   │   └── webhook.ts         # HMAC-signed callbacks\n│   ├── auth\u002F\n│   │   └── index.ts           # Key\u002FJWT validation + roles\n│   ├── db\u002F\n│   │   ├── index.ts           # DB factory (SQLite\u002FPostgres)\n│   │   └── migrations.ts      # Schema creation\n│   ├── cli\u002F\n│   │   └── index.ts           # CLI commands\n│   ├── utils\u002F\n│   │   ├── config.ts          # Env loading + validation\n│   │   ├── errors.ts          # Error classes\n│   │   ├── logger.ts          # Pino setup\n│   │   └── hash.ts            # SHA-256 hashing\n│   └── index.ts               # Main entrypoint\n├── config\u002F\n│   └── workflows\u002F             # Bundled workflow templates\n│       ├── sdxl_realism_v1.json\n│       ├── sdxl_realism_v1.schema.json\n│       ├── sprite_transparent_bg.json\n│       ├── sprite_transparent_bg.schema.json\n│       ├── icon_512.json\n│       └── icon_512.schema.json\n├── data\u002F\n│   ├── outputs\u002F               # Generated images\n│   ├── workflows\u002F             # User-added wor\n\n## Best Practices\n\n- Provide clear, specific context about your project and requirements\n- Review all suggestions before applying them to production code\n- Combine with other complementary skills for comprehensive analysis\n\n## Common Pitfalls\n\n- Using this skill for tasks outside its domain expertise\n- Applying recommendations without understanding your specific context\n- Not providing enough project context for accurate analysis\n\n## Related Skills\n\n- `ai-studio-image` - Complementary skill for enhanced analysis\n- `image-studio` - Complementary skill for enhanced analysis\n- `stability-ai` - Complementary skill for enhanced analysis\n","# ComfyUI Gateway\n\n## Overview\n\nREST API gateway for ComfyUI servers. Workflow management, job queuing, webhooks, caching, auth, rate limiting, and image delivery (URL + base64).\n\n## When to Use This Skill\n\n- When the user mentions \"comfyui\" or related topics\n- When the user mentions \"comfy ui\" or related topics\n- When the user mentions \"stable diffusion api gateway\" or related topics\n- When the user mentions \"gateway comfyui\" or related topics\n- When the user mentions \"api gateway imagens\" or related topics\n- When the user mentions \"queue imagens\" or related topics\n\n## Do Not Use This Skill When\n\n- The task is unrelated to comfyui gateway\n- A simpler, more specific tool can handle the request\n- The user needs general-purpose assistance without domain expertise\n\n## How It Works\n\nA production-grade REST API gateway that transforms any ComfyUI server into a universal,\nsecure, and scalable service. Supports workflow templates with placeholders, job queuing\nwith priorities, webhook callbacks, result caching, and multiple storage backends.\n\n## Architecture Overview\n\n```\n┌─────────────┐     ┌──────────────────────────────────┐     ┌──────────┐\n│   Clients    │────▶│        ComfyUI Gateway           │────▶│ ComfyUI  │\n│ (curl, n8n,  │     │                                  │     │ Server   │\n│  Claude,     │     │  ┌─────────┐  ┌──────────────┐  │     │ (local\u002F  │\n│  Lovable,    │     │  │ Fastify │  │ BullMQ Queue │  │     │  remote) │\n│  Supabase)   │     │  │ API     │──│ (or in-mem)  │  │     └──────────┘\n│              │◀────│  └─────────┘  └──────────────┘  │\n│              │     │  ┌─────────┐  ┌──────────────┐  │     ┌──────────┐\n│              │     │  │ Auth +  │  │ Storage      │  │────▶│ S3\u002FMinIO │\n│              │     │  │ RateL.  │  │ (local\u002FS3)   │  │     │(optional)│\n│              │     │  └─────────┘  └──────────────┘  │     └──────────┘\n└─────────────┘     └──────────────────────────────────┘\n```\n\n## Components\n\n| Component | Purpose | File(s) |\n|-----------|---------|---------|\n| **API Gateway** | REST endpoints, validation, CORS | `src\u002Fapi\u002F` |\n| **Worker** | Processes jobs, talks to ComfyUI | `src\u002Fworker\u002F` |\n| **ComfyUI Client** | HTTP + WebSocket to ComfyUI | `src\u002Fcomfyui\u002F` |\n| **Workflow Manager** | Template storage, placeholder rendering | `src\u002Fworkflows\u002F` |\n| **Storage Provider** | Local disk + S3-compatible | `src\u002Fstorage\u002F` |\n| **Cache** | Hash-based deduplication | `src\u002Fcache\u002F` |\n| **Notifier** | Webhook with HMAC signing | `src\u002Fnotifications\u002F` |\n| **Auth** | API key + JWT + rate limiting | `src\u002Fauth\u002F` |\n| **DB** | SQLite (better-sqlite3) or Postgres | `src\u002Fdb\u002F` |\n| **CLI** | Init, add-workflow, run, worker | `src\u002Fcli\u002F` |\n\n## Quick Start\n\n```bash\n\n## 1. Install\n\ncd comfyui-gateway\nnpm install\n\n## 2. Configure\n\ncp .env.example .env\n\n## 3. Initialize\n\nnpx tsx src\u002Fcli\u002Findex.ts init\n\n## 4. Add A Workflow\n\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow .\u002Fworkflows\u002Fsdxl_realism_v1.json \\\n  --id sdxl_realism_v1 --schema .\u002Fworkflows\u002Fsdxl_realism_v1.schema.json\n\n## 5. Start (Api + Worker In One Process)\n\nnpm run dev\n\n## Or Separately:\n\nnpm run start:api   # API only\nnpm run start:worker # Worker only\n```\n\n## Environment Variables\n\nAll configuration is via `.env` — nothing is hardcoded:\n\n| Variable | Default | Description |\n|----------|---------|-------------|\n| `PORT` | `3000` | API server port |\n| `HOST` | `0.0.0.0` | API bind address |\n| `COMFYUI_URL` | `http:\u002F\u002F127.0.0.1:8188` | ComfyUI server URL |\n| `COMFYUI_TIMEOUT_MS` | `300000` | Max wait for ComfyUI (5min) |\n| `API_KEYS` | `\"\"` | Comma-separated API keys (`key:role`) |\n| `JWT_SECRET` | `\"\"` | JWT signing secret (empty = JWT disabled) |\n| `REDIS_URL` | `\"\"` | Redis URL (empty = in-memory queue) |\n| `DATABASE_URL` | `.\u002Fdata\u002Fgateway.db` | SQLite path or Postgres URL |\n| `STORAGE_PROVIDER` | `local` | `local` or `s3` |\n| `STORAGE_LOCAL_PATH` | `.\u002Fdata\u002Foutputs` | Local output directory |\n| `S3_ENDPOINT` | `\"\"` | S3\u002FMinIO endpoint |\n| `S3_BUCKET` | `\"\"` | S3 bucket name |\n| `S3_ACCESS_KEY` | `\"\"` | S3 access key |\n| `S3_SECRET_KEY` | `\"\"` | S3 secret key |\n| `S3_REGION` | `us-east-1` | S3 region |\n| `WEBHOOK_SECRET` | `\"\"` | HMAC signing secret for webhooks |\n| `WEBHOOK_ALLOWED_DOMAINS` | `*` | Comma-separated allowed callback domains |\n| `MAX_CONCURRENCY` | `1` | Parallel jobs per GPU |\n| `MAX_IMAGE_SIZE` | `2048` | Maximum dimension (width or height) |\n| `MAX_BATCH_SIZE` | `4` | Maximum batch size |\n| `CACHE_ENABLED` | `true` | Enable result caching |\n| `CACHE_TTL_SECONDS` | `86400` | Cache TTL (24h) |\n| `RATE_LIMIT_MAX` | `100` | Requests per window |\n| `RATE_LIMIT_WINDOW_MS` | `60000` | Rate limit window (1min) |\n| `LOG_LEVEL` | `info` | Pino log level |\n| `PRIVACY_MODE` | `false` | Redact prompts from logs |\n| `CORS_ORIGINS` | `*` | Allowed CORS origins |\n| `NODE_ENV` | `development` | Environment |\n\n## Health & Capabilities\n\n```\nGET \u002Fhealth\n→ { ok: true, version, comfyui: { reachable, url, models? }, uptime }\n\nGET \u002Fcapabilities\n→ { workflows: [...], maxSize, maxBatch, formats, storageProvider }\n```\n\n## Workflows (Crud)\n\n```\nGET    \u002Fworkflows            → list all workflows\nPOST   \u002Fworkflows            → register new workflow\nGET    \u002Fworkflows\u002F:id        → workflow details + input schema\nPUT    \u002Fworkflows\u002F:id        → update workflow\nDELETE \u002Fworkflows\u002F:id        → remove workflow\n```\n\n## Jobs\n\n```\nPOST   \u002Fjobs                 → create job (returns jobId immediately)\nGET    \u002Fjobs\u002F:jobId          → status + progress + outputs\nGET    \u002Fjobs\u002F:jobId\u002Flogs     → sanitized execution logs\nPOST   \u002Fjobs\u002F:jobId\u002Fcancel   → request cancellation\nGET    \u002Fjobs                 → list jobs (filters: status, workflowId, after, before, limit)\n```\n\n## Outputs\n\n```\nGET    \u002Foutputs\u002F:jobId       → list output files + metadata\nGET    \u002Foutputs\u002F:jobId\u002F:file → download\u002Fstream file\n```\n\n## Job Lifecycle\n\n```\nqueued → running → succeeded\n                 → failed\n                 → canceled\n```\n\n1. Client POSTs to `\u002Fjobs` with workflowId + inputs\n2. Gateway validates, checks cache, checks idempotency\n3. If cache hit → returns existing outputs immediately (status: `cache_hit`)\n4. Otherwise → enqueues job, returns `jobId` + `pollUrl`\n5. Worker picks up job, renders workflow template, submits to ComfyUI\n6. Worker polls ComfyUI for progress (or listens via WebSocket)\n7. On completion → downloads outputs, stores them, updates DB\n8. If callbackUrl → sends signed webhook POST\n9. Client polls `\u002Fjobs\u002F:jobId` or receives webhook\n\n## Workflow Templates\n\nWorkflows are ComfyUI JSON with `{{placeholder}}` tokens. The gateway resolves\nthese at runtime using the job's `inputs` and `params`:\n\n```json\n{\n  \"3\": {\n    \"class_type\": \"KSampler\",\n    \"inputs\": {\n      \"seed\": \"{{seed}}\",\n      \"steps\": \"{{steps}}\",\n      \"cfg\": \"{{cfg}}\",\n      \"sampler_name\": \"{{sampler}}\",\n      \"scheduler\": \"normal\",\n      \"denoise\": 1,\n      \"model\": [\"4\", 0],\n      \"positive\": [\"6\", 0],\n      \"negative\": [\"7\", 0],\n      \"latent_image\": [\"5\", 0]\n    }\n  },\n  \"6\": {\n    \"class_type\": \"CLIPTextEncode\",\n    \"inputs\": {\n      \"text\": \"{{prompt}}\",\n      \"clip\": [\"4\", 1]\n    }\n  }\n}\n```\n\nEach workflow has an `inputSchema` (Zod) that validates what the client sends.\n\n## Security Model\n\n- **API Keys**: `X-API-Key` header; keys configured via `API_KEYS` env var as `key1:admin,key2:user`\n- **JWT**: Optional; when `JWT_SECRET` is set, accepts `Authorization: Bearer \u003Ctoken>`\n- **Roles**: `admin` (full CRUD on workflows + jobs), `user` (create jobs, read own jobs)\n- **Rate Limiting**: Per key + per IP, configurable window and max\n- **Webhook Security**: HMAC-SHA256 signature in `X-Signature` header\n- **Callback Allowlist**: Only approved domains receive webhooks\n- **Privacy Mode**: When enabled, prompts are redacted from logs and DB\n- **Idempotency**: `metadata.requestId` prevents duplicate processing\n- **CORS**: Configurable allowed origins\n- **Input Validation**: Zod schemas on every endpoint; max size\u002Fbatch enforced\n\n## Comfyui Integration\n\nThe gateway communicates with ComfyUI via its native HTTP API:\n\n| ComfyUI Endpoint | Gateway Usage |\n|------------------|---------------|\n| `POST \u002Fprompt` | Submit rendered workflow |\n| `GET \u002Fhistory\u002F{id}` | Poll job completion |\n| `GET \u002Fview?filename=...` | Download generated images |\n| `GET \u002Fobject_info` | Discover available nodes\u002Fmodels |\n| `WS \u002Fws?clientId=...` | Real-time progress (optional) |\n\nThe client auto-detects ComfyUI version and adapts:\n- Tries WebSocket first for progress, falls back to polling\n- Handles both `\u002Fhistory` response formats\n- Detects OOM errors and classifies them with recommendations\n\n## Cache Strategy\n\nCache key = SHA-256 of `workflowId + sorted(inputs) + sorted(params) + checkpoint`.\nOn cache hit, the gateway returns a \"virtual\" job with pre-existing outputs — no GPU\ncomputation needed. Cache is stored alongside job data in the DB with configurable TTL.\n\n## Error Classification\n\n| Error Code | Meaning | Retry? |\n|------------|---------|--------|\n| `COMFYUI_UNREACHABLE` | Cannot connect to ComfyUI | Yes (with backoff) |\n| `COMFYUI_OOM` | Out of memory on GPU | No (reduce dimensions) |\n| `COMFYUI_TIMEOUT` | Execution exceeded timeout | Maybe (increase timeout) |\n| `COMFYUI_NODE_ERROR` | Node execution failed | No (check workflow) |\n| `VALIDATION_ERROR` | Invalid inputs | No (fix request) |\n| `WORKFLOW_NOT_FOUND` | Unknown workflowId | No (register workflow) |\n| `RATE_LIMITED` | Too many requests | Yes (wait) |\n| `AUTH_FAILED` | Invalid\u002Fmissing credentials | No (fix auth) |\n| `CACHE_HIT` | (Not an error) Served from cache | N\u002FA |\n\n## Bundled Workflows\n\nThree production-ready workflow templates are included:\n\n## 1. `Sdxl_Realism_V1` — Photorealistic Generation\n\n- Checkpoint: SDXL base\n- Optimized for: Portraits, landscapes, product shots\n- Default: 1024x1024, 30 steps, cfg 7.0\n\n## 2. `Sprite_Transparent_Bg` — Game Sprites With Alpha\n\n- Checkpoint: SD 1.5 or SDXL\n- Optimized for: 2D game assets, transparent backgrounds\n- Default: 512x512, 25 steps, cfg 7.5\n\n## 3. `Icon_512` — App Icons With Optional Upscale\n\n- Checkpoint: SDXL base\n- Optimized for: Square icons, clean edges\n- Default: 512x512, 20 steps, cfg 6.0, optional 2x upscale\n\n## Observability\n\n- **Structured Logs**: Pino JSON logs with `correlationId` on every request\n- **Metrics**: Jobs queued\u002Frunning\u002Fsucceeded\u002Ffailed, avg processing time, cache hit rate\n- **Audit Log**: Admin actions (workflow CRUD, key management) logged with timestamp + actor\n\n## Cli Reference\n\n```bash\nnpx tsx src\u002Fcli\u002Findex.ts init                    # Create dirs, .env.example\nnpx tsx src\u002Fcli\u002Findex.ts add-workflow \u003Cfile>      # Register workflow template\n  --id \u003Cid> --name \u003Cname> --schema \u003Cschema.json>\nnpx tsx src\u002Fcli\u002Findex.ts list-workflows           # Show registered workflows\nnpx tsx src\u002Fcli\u002Findex.ts run                      # Start API server\nnpx tsx src\u002Fcli\u002Findex.ts worker                   # Start job worker\nnpx tsx src\u002Fcli\u002Findex.ts health                   # Check ComfyUI connectivity\n```\n\n## Troubleshooting\n\nRead `references\u002Ftroubleshooting.md` for detailed guidance on:\n- ComfyUI not reachable (firewall, wrong port, Docker networking)\n- OOM errors (reduce resolution, batch, or steps)\n- Slow generation (GPU utilization, queue depth, model loading)\n- Webhook failures (DNS, SSL, timeout, domain allowlist)\n- Redis connection issues (fallback to in-memory)\n- Storage permission errors (local path, S3 credentials)\n\n## Integration Examples\n\nRead `references\u002Fintegration.md` for ready-to-use examples with:\n- curl commands for every endpoint\n- n8n webhook workflow\n- Supabase Edge Function caller\n- Claude Code \u002F Claude.ai integration\n- Python requests client\n- JavaScript fetch client\n\n## File Structure\n\n```\ncomfyui-gateway\u002F\n├── SKILL.md\n├── package.json\n├── tsconfig.json\n├── .env.example\n├── src\u002F\n│   ├── api\u002F\n│   │   ├── server.ts          # Fastify setup + plugins\n│   │   ├── routes\u002F\n│   │   │   ├── health.ts      # GET \u002Fhealth, \u002Fcapabilities\n│   │   │   ├── workflows.ts   # CRUD \u002Fworkflows\n│   │   │   ├── jobs.ts        # CRUD \u002Fjobs\n│   │   │   └── outputs.ts     # GET \u002Foutputs\n│   │   ├── middleware\u002F\n│   │   │   └── error-handler.ts\n│   │   └── plugins\u002F\n│   │       ├── auth.ts        # API key + JWT\n│   │       ├── rate-limit.ts\n│   │       └── cors.ts\n│   ├── worker\u002F\n│   │   └── processor.ts       # Job processor\n│   ├── comfyui\u002F\n│   │   └── client.ts          # ComfyUI HTTP + WS client\n│   ├── storage\u002F\n│   │   ├── index.ts           # Provider factory\n│   │   ├── local.ts           # Local filesystem\n│   │   └── s3.ts              # S3-compatible\n│   ├── workflows\u002F\n│   │   └── manager.ts         # Template CRUD + rendering\n│   ├── cache\u002F\n│   │   └── index.ts           # Hash-based cache\n│   ├── notifications\u002F\n│   │   └── webhook.ts         # HMAC-signed callbacks\n│   ├── auth\u002F\n│   │   └── index.ts           # Key\u002FJWT validation + roles\n│   ├── db\u002F\n│   │   ├── index.ts           # DB factory (SQLite\u002FPostgres)\n│   │   └── migrations.ts      # Schema creation\n│   ├── cli\u002F\n│   │   └── index.ts           # CLI commands\n│   ├── utils\u002F\n│   │   ├── config.ts          # Env loading + validation\n│   │   ├── errors.ts          # Error classes\n│   │   ├── logger.ts          # Pino setup\n│   │   └── hash.ts            # SHA-256 hashing\n│   └── index.ts               # Main entrypoint\n├── config\u002F\n│   └── workflows\u002F             # Bundled workflow templates\n│       ├── sdxl_realism_v1.json\n│       ├── sdxl_realism_v1.schema.json\n│       ├── sprite_transparent_bg.json\n│       ├── sprite_transparent_bg.schema.json\n│       ├── icon_512.json\n│       └── icon_512.schema.json\n├── data\u002F\n│   ├── outputs\u002F               # Generated images\n│   ├── workflows\u002F             # User-added wor\n\n## Best Practices\n\n- Provide clear, specific context about your project and requirements\n- Review all suggestions before applying them to production code\n- Combine with other complementary skills for comprehensive analysis\n\n## Common Pitfalls\n\n- Using this skill for tasks outside its domain expertise\n- Applying recommendations without understanding your specific context\n- Not providing enough project context for accurate analysis\n\n## Related Skills\n\n- `ai-studio-image` - Complementary skill for enhanced analysis\n- `image-studio` - Complementary skill for enhanced analysis\n- `stability-ai` - Complementary skill for enhanced analysis\n",{"name":5,"risk":53,"tags":60,"tools":61,"author":67,"source":40,"date_added":68,"description":7},[36,44,41,52],[62,63,64,65,66],"claude-code","antigravity","cursor","gemini-cli","codex-cli","renat","2026-03-06","main","a50a3aa6b39fb0e1b7db88bef1bfc9c93606e126","modules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fcomfyui-gateway",0,"https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant","https:\u002F\u002Fgithub.com\u002FSam-06060","Mobile Application Developer | Kotlin | Flutter, KMP, Swfit, Android,Swift UI | Building at Saar It Resources | Creator of Jarvis (AI Assistant)","2026-06-23 05:13:38",{"source":8,"skillName":5,"commands":78,"prompt":88,"zipAvailable":89},[79,82,85],{"tool":80,"command":81},"npx","npx skills add Sam-06060\u002Fjarvis-assistant --skill comfyui-gateway",{"tool":83,"command":84},"bunx","bunx skills add Sam-06060\u002Fjarvis-assistant --skill comfyui-gateway",{"tool":86,"command":87},"pnpm","pnpm dlx skills add Sam-06060\u002Fjarvis-assistant --skill comfyui-gateway","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fcomfyui-gateway\u002FSKILL.md",true,[91,97],{"path":92,"resourceType":93,"resourceTypeDesc":94,"sizeBytes":95,"sourceHtmlUrl":96},"references\u002Fintegration.md","REFERENCE","参考文档",48284,"https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fcomfyui-gateway\u002Freferences\u002Fintegration.md",{"path":98,"resourceType":93,"resourceTypeDesc":94,"sizeBytes":99,"sourceHtmlUrl":100},"references\u002Ftroubleshooting.md",29528,"https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fcomfyui-gateway\u002Freferences\u002Ftroubleshooting.md",[102,113,128,153,172,198],{"skillNo":103,"name":104,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":110,"publishedAt":55},"01M6GDRVS6FXX3ESH0C9DW01C0","test_skill","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fscratch\u002Ftest_skill\u002FSKILL.md",[107],{"categoryNo":108,"categoryName":109,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",[111,112],"Test Skill","test",{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":55},"01M6GDRQ40HX22MA6XWC31RHHK","zustand-store-ts","Create Zustand stores following established patterns with proper TypeScript types and middleware.","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fzustand-store-ts\u002FSKILL.md",[],[120,121,122,123,124,125,126,40,127,52],"zustand store ts","zustand","store","with","types","middleware","patterns","create",{"skillNo":129,"name":130,"nameZh":6,"description":131,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":132,"categories":133,"keywords":135,"publishedAt":55},"01M6GDRKEA0WE670SPFWX5GKCN","zoom-automation","Automate Zoom meeting creation, management, recordings, webinars, and participant tracking via Rube MCP (Composio). Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fzoom-automation\u002FSKILL.md",[134],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},[136,137,138,139,140,141,142,143,144,145,146,147,148,149,40,150,151,152],"automation","zoom automation","zoom","first","Tools","search","MCP","via","meeting","automate","critical","creation","webinars","composio","recordings","management","tracking",{"skillNo":154,"name":155,"nameZh":6,"description":156,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":157,"categories":158,"keywords":160,"publishedAt":55},"01M6GDRFS1452PC71JQ38S24HR","zoho-crm-automation","Automate Zoho CRM tasks via Rube MCP (Composio): create\u002Fupdate records, search contacts, manage leads, and convert leads. Always search tools first for current schemas.","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fzoho-crm-automation\u002FSKILL.md",[159],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},[161,136,162,163,164,165,166,40,141,167,149,168,146,145,140,169,127,170,142,171],"crm automation","zoho crm","crm","zoho crm automation","zoho","leads","contacts","records","update","tasks","manage",{"skillNo":173,"name":174,"nameZh":6,"description":175,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":176,"categories":177,"keywords":181,"publishedAt":55},"01M6GDRCKQBAVTGHX5XBH26KPZ","zod-validation-expert","Expert in Zod — TypeScript-first schema validation. Covers parsing, custom errors, refinements, type inference, and integration with React Hook Form, Next.js, and tRPC.","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fzod-validation-expert\u002FSKILL.md",[178],{"categoryNo":179,"categoryName":180,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",[182,183,184,185,186,52,53,187,188,189,190,191,123,192,193,194,195,40,196,197],"expert","zod","zod validation expert","validation","react","parsing","errors","schema validation","react hook form","hook","trpc","form","type","next","schema","Next.js",{"skillNo":199,"name":200,"nameZh":6,"description":201,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":202,"categories":203,"keywords":205,"publishedAt":55},"01M6GDR658B08K4MY0RWD4A6EH","zeroize-audit","Detects missing zeroization of sensitive data in source code and identifies zeroization removed by compiler optimizations, with assembly-level analysis, and control-flow verification. Use for auditing C\u002FC++\u002FRust code handling secrets, keys, passwords, or other sensitive data.","https:\u002F\u002Fgithub.com\u002FSam-06060\u002Fjarvis-assistant\u002Fblob\u002Fmain\u002Fmodules\u002Fagent_skills\u002Fawesome-skills\u002Fplaybooks\u002Fzeroize-audit\u002FSKILL.md",[204],{"categoryNo":27,"categoryName":28,"taxonomyType":21,"taxonomyTypeDesc":22},[206,207,208,209,210,211,212,213,40,214,215,216,217,218,219,220,221,48,222,142],"zeroize audit","audit","write","passwords","get","project","c++","activate","assembly","read","Bash","secrets","analysis","data","flow","verification","rust"]