一键导入
sse-ai-optimization
Use AI to accelerate SSE development. Includes prompt templates for code generation, refactoring, testing, and architectural decisions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use AI to accelerate SSE development. Includes prompt templates for code generation, refactoring, testing, and architectural decisions.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | sse-ai-optimization |
| description | Use AI to accelerate SSE development. Includes prompt templates for code generation, refactoring, testing, and architectural decisions. |
| triggers | ["sse ai","ai sse","optimize sse","ai realtime","generate sse","test sse"] |
Leverage AI to reduce SSE development time by 70%: Generate, debug, test, and optimize SSE code.
SSE development involves repetitive patterns:
AI can:
Prompt Template:
Generate a basic SSE endpoint in Next.js App Router that:
- Streams notifications to authenticated users
- Sends a heartbeat every 30 seconds
- Includes proper error handling and cleanup
- Uses [TransformStream / ReadableStream]
Example:
Generate a basic SSE endpoint in Next.js App Router for a social app that streams notifications.
Include JWT auth verification, heartbeat every 30 seconds, and cleanup on client disconnect.
Expected output: Complete route handler with:
Prompt Template:
Create a Payload CMS afterChange hook that:
- Detects when a [Post/Comment/Like] is [created/updated]
- Triggers SSE notification to [specific user / all followers]
- Uses [EventEmitter / Redis pub/sub] for delivery
Example:
Show me how to integrate Payload CMS afterChange hook with SSE.
When a post gets liked, notify the post author via SSE using Redis pub/sub.
Expected output: Hook code with:
Prompt Template:
Refactor my SSE code to use Redis pub/sub for:
- Multi-instance server deployment
- Handling [100+ / 1000+] concurrent users
- Broadcasting to user segments
Example:
Refactor my EventEmitter-based SSE to use Redis pub/sub.
I have multiple server instances and need to broadcast notifications
across all instances to 500+ concurrent users. Show connection pooling.
Expected output:
Prompt Template:
Add client-side error handling to my SSE component:
- Implement exponential backoff (1s, 2s, 4s, 8s, 16s)
- Max retry limit of [5/10] attempts
- Display connection status to user
- Log errors for debugging
Example:
My SSE client keeps losing connection. Add robust error handling with:
- Exponential backoff reconnection
- Visual status indicator (connected/disconnected)
- Max 5 retry attempts
- Detailed error logging
Expected output: React component with:
Prompt Template:
Write [Jest/Vitest] tests for my SSE endpoint:
- Test [successful connection / message streaming / client disconnect]
- Mock [fetch / Response / ReadableStream]
- Test [error scenarios / timeout]
- Measure latency
Example:
Write Jest tests for my SSE route handler. Test:
1. Client connects and receives initial message
2. Heartbeat message sent every 30s
3. Client disconnect closes stream
4. Error on invalid auth token
Expected output: Test suite with:
Prompt Template:
Optimize my SSE for [1000 / 10000] concurrent users:
- Current bottleneck: [memory / latency / message throughput]
- Show [batching / connection pooling / selective delivery] approach
- Estimate resource usage
Example:
My SSE is hitting memory limits at 1000 concurrent users.
Suggest optimizations using:
- Message batching (100ms window)
- Selective delivery (only send to interested users)
- Memory pooling
Show estimated resource usage and latency impact.
Expected output:
Prompt Template:
Compare SSE vs [WebSockets / Long Polling / Polling] for my use case:
- Features needed: [realtime / bidirectional / fallback]
- Scale: [10 / 100 / 1000 / 10000] users
- Latency requirement: [<100ms / <500ms / <1s]
Example:
Should I use SSE or WebSockets for my social feed?
- One-way: Server sends posts, users only "like" via HTTP
- Scale: Expected 500-1000 concurrent users
- Latency: <200ms acceptable
Show pros/cons and recommendation.
Expected output:
Total: 2.5-3 hours vs 6-8 hours manual (70% time savings)
Combine multiple prompts in sequence:
1. Generate SSE endpoint
↓
2. Generate Payload hook
↓
3. Generate React component
↓
4. Generate tests
↓
5. Optimize for scale
Each output feeds into next prompt.
Prompt for buggy SSE:
Debug this SSE endpoint - messages buffer until connection closes:
[paste code]
Why is this happening? How do I fix it?
Expected: Diagnosis (Vercel buffering) + fix (TransformStream)
Prompt for errors:
My SSE client throws "Failed to parse event.data" occasionally.
[paste error + code]
What's wrong? How do I fix the parsing?
Expected: Identify cause (invalid JSON) + solution (add try-catch)
sse-basics skill - Use templates from heresse-debugging skill - Debugging strategiessse-scaling skill - Scaling patternssse-payload-integration skill - CMS integrationDocs/life-1/03-research/sse-nextjs.md - Prototype codeTime: 3 hours (vs 8 hours manual)
Result: Production-ready SSE system with tests, docs, and optimizations.
Use Case diagram specialist for researching, analyzing, and building UML Use Case diagrams (actors, use cases, include/extend, system boundary) and Use Case Specifications
Mermaid diagram specialist for creating flowcharts, sequence diagrams, ERDs, and architecture visualizations
Core implementation of Server-Sent Events (SSE) for realtime one-way communication in Next.js. Basic patterns for setup, message format, and client consumption.
Debugging and error handling for SSE streams. Addresses common pitfalls including Vercel buffering, timeouts, connection drops, and reconnection strategies.
Integrate SSE with Payload CMS for realtime updates. Covers afterChange hooks to trigger events, authenticated routes, and real-time social app features.
Scaling SSE for high-concurrency social apps. Covers pub/sub patterns, Redis integration, fan-out strategies, and production limits.