add-resource-events
Add real-time event emission to a resource service. Use when adding SSE/real-time capabilities to a resource. Triggers on "add events", "real-time events", "SSE events".
Best use case
add-resource-events is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Add real-time event emission to a resource service. Use when adding SSE/real-time capabilities to a resource. Triggers on "add events", "real-time events", "SSE events".
Teams using add-resource-events should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/add-resource-events/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How add-resource-events Compares
| Feature / Agent | add-resource-events | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Add real-time event emission to a resource service. Use when adding SSE/real-time capabilities to a resource. Triggers on "add events", "real-time events", "SSE events".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Add Resource Events
Enables real-time event emission for a resource service via Server-Sent Events (SSE).
## Quick Reference
**Event Infrastructure**:
- `src/events/event-emitter.ts` - Singleton `AppEventEmitter`
- `src/events/base.service.ts` - `BaseService` with `emitEvent()`
- `src/schemas/event.schema.ts` - Event type definitions
- `src/routes/events.router.ts` - SSE endpoint
**Event Pattern**: `{serviceName}:{action}` (e.g., `notes:created`, `notes:updated`)
## Prerequisites
To add events to a resource:
1. Service must extend `BaseService` (see `create-resource-service`)
2. Authorization methods for events in `AuthorizationService`
## How It Works
### 1. BaseService Provides emitEvent()
```typescript
// src/events/base.service.ts
export abstract class BaseService {
constructor(protected serviceName: string) {}
protected emitEvent<T>(
action: ServiceEventType["action"],
data: T,
options?: {
id?: string;
user?: { userId: string; [key: string]: unknown };
},
) {
appEvents.emitServiceEvent(this.serviceName, {
id: options?.id || uuidv4(),
action,
data,
user: eventUser,
timestamp: new Date(),
resourceType: this.serviceName,
});
}
}
```
### 2. Resource Service Emits Events
```typescript
export class NoteService extends BaseService {
constructor(...) {
super("notes"); // Service name for event routing
}
async create(data, user) {
// ... create logic ...
this.emitEvent("created", note, { id: note.id, user });
return note;
}
async update(id, data, user) {
// ... update logic ...
this.emitEvent("updated", updatedNote, { id: updatedNote.id, user });
return updatedNote;
}
async delete(id, user) {
// ... delete logic ...
this.emitEvent("deleted", note, { id: note.id, user });
return true;
}
}
```
### 3. Events Router Streams to Clients
```typescript
// src/routes/events.router.ts
appEvents.on("notes:created", eventHandler);
appEvents.on("notes:updated", eventHandler);
appEvents.on("notes:deleted", eventHandler);
```
## Adding Events to a New Resource
### Step 1: Extend BaseService
Your service must extend `BaseService`:
```typescript
import { BaseService } from "@/events/base.service";
export class {Entity}Service extends BaseService {
constructor(...) {
super("{entities}"); // Plural for event namespace
}
}
```
### Step 2: Emit Events in CRUD Methods
Add `emitEvent()` calls after successful operations:
```typescript
async create(data, user) {
const {entity} = await this.repository.create(data, user.userId);
this.emitEvent("created", {entity}, { id: {entity}.id, user });
return {entity};
}
async update(id, data, user) {
const updated = await this.repository.update(id, data);
if (!updated) return null;
this.emitEvent("updated", updated, { id: updated.id, user });
return updated;
}
async delete(id, user) {
const {entity} = await this.repository.findById(id);
const deleted = await this.repository.remove(id);
if (deleted) {
this.emitEvent("deleted", {entity}, { id: {entity}.id, user });
}
return deleted;
}
```
### Step 3: Add Event Authorization
In `src/services/authorization.service.ts`:
```typescript
async canReceive{Entity}Event(
user: AuthenticatedUserContextType,
{entity}Data: { createdBy: string; [key: string]: unknown },
): Promise<boolean> {
if (this.isAdmin(user)) return true;
if ({entity}Data.createdBy === user.userId) return true;
return false;
}
```
### Step 4: Update Events Router
In `src/routes/events.router.ts`, add listeners:
```typescript
// Listen to {entity} events
appEvents.on("{entities}:created", eventHandler);
appEvents.on("{entities}:updated", eventHandler);
appEvents.on("{entities}:deleted", eventHandler);
```
Update the `shouldUserReceiveEvent` function:
```typescript
async function shouldUserReceiveEvent(
event: ServiceEventType,
user: AuthenticatedUserContextType,
authorizationService: AuthorizationService,
): Promise<boolean> {
switch (event.resourceType) {
case "notes":
// ... existing ...
case "{entities}":
if (
typeof event.data === "object" &&
event.data !== null &&
"createdBy" in event.data
) {
return await authorizationService.canReceive{Entity}Event(
user,
event.data as { createdBy: string; [key: string]: unknown },
);
}
return false;
default:
return false;
}
}
```
### Step 5: Add Event Schema (Optional)
In `src/schemas/event.schema.ts`:
```typescript
export const {entity}EventSchema = serviceEventSchema.extend({
data: z.object({
id: z.string(),
// ... entity-specific fields
createdAt: z.date().optional(),
updatedAt: z.date().optional(),
}),
});
export type {Entity}EventType = z.infer<typeof {entity}EventSchema>;
```
## Event Flow
```
1. Client: POST /notes (create a note)
2. Controller: calls NoteService.create()
3. Service: creates note, calls this.emitEvent("created", note, ...)
4. BaseService: appEvents.emitServiceEvent("notes", { action: "created", ... })
5. EventEmitter: emits "notes:created" event
6. Events Router: catches event, checks authorization
7. SSE Stream: sends to authorized clients
8. Client: receives { event: "notes:created", data: {...} }
```
## Client-Side Usage
```javascript
const eventSource = new EventSource("/events", {
headers: { Authorization: `Bearer ${token}` },
});
eventSource.addEventListener("notes:created", (event) => {
const data = JSON.parse(event.data);
console.log("New note:", data);
});
eventSource.addEventListener("notes:updated", (event) => {
const data = JSON.parse(event.data);
console.log("Updated note:", data);
});
eventSource.addEventListener("notes:deleted", (event) => {
const data = JSON.parse(event.data);
console.log("Deleted note:", data);
});
```
## What NOT to Do
- Do NOT emit events before confirming operation succeeded
- Do NOT emit events for failed/unauthorized operations
- Do NOT skip authorization checks in events router
- Do NOT forget to clean up event listeners on disconnect
## See Also
- `create-resource-service` - Creating services with event emission
- `create-routes` - Events router example
- `test-resource-service` - Testing event emissionRelated Skills
ado-resource-validator
Validates Azure DevOps projects, area paths, and teams exist with auto-creation of missing resources. Use when setting up ADO integration, configuring .env variables, or troubleshooting missing project errors. Supports project-per-team, area-path-based, and team-based strategies.
add-resource
Add new learning resources (books, articles, courses, papers) to the appropriate resources.md file. Use when user mentions adding, saving, or tracking learning materials.
ack-resources
AWS Controllers for Kubernetes (ACK) for Kubernetes-native AWS resource management. Use when managing AWS resources via kubectl, implementing GitOps for infrastructure, creating self-service developer platforms, integrating AWS services with EKS workloads, or adopting existing AWS resources into Kubernetes.
Bootstrap Resource Object
## 0. 목적
1k-adding-socket-events
Adds new WebSocket event subscriptions to OneKey. Use when implementing new socket events, handling server push messages, or adding real-time data subscriptions. Socket, WebSocket, event, subscription, push, real-time.
ux
This AI agent skill provides comprehensive guidance for creating professional and insightful User Experience (UX) designs, covering user research, information architecture, interaction design, visual guidance, and usability evaluation. It aims to produce actionable, user-centered solutions that avoid generic AI aesthetics.
whisper-transcribe
Transcribes audio and video files to text using OpenAI's Whisper CLI, enhanced with contextual grounding from local markdown files for improved accuracy.
grail-miner
This skill assists in setting up, managing, and optimizing Grail miners on Bittensor Subnet 81, handling tasks like environment configuration, R2 storage, model checkpoint management, and performance tuning.
ontopo
An AI agent skill to search for Israeli restaurants, check table availability, view menus, and retrieve booking links via the Ontopo platform, acting as an unofficial interface to its data.
lets-go-rss
A lightweight, full-platform RSS subscription manager that aggregates content from YouTube, Vimeo, Behance, Twitter/X, and Chinese platforms like Bilibili, Weibo, and Douyin, featuring deduplication and AI smart classification.
tech-blog
Generates comprehensive technical blog posts, offering detailed explanations of system internals, architecture, and implementation, either through source code analysis or document-driven research.
chrome-debug
This skill empowers AI agents to debug web applications and inspect browser behavior using the Chrome DevTools Protocol (CDP), offering both collaborative (headful) and automated (headless) modes.