Files
openchamber/packages/ui/src/lib/configSync.ts
T
Bohdan Triapitsyn 2c833cef40 feat: Implement skill management functionality
- Added skill scope helpers and CRUD operations for skills in opencodeConfig.ts.
- Introduced API endpoints for skill management in main.tsx and index.js.
- Enhanced server-side logic to support skill discovery, creation, updating, and deletion.
- Implemented supporting file operations for skills, including reading, writing, and deleting files.
- Updated package.json to use the latest version of @opencode-ai/sdk.
2025-12-30 17:36:52 +02:00

63 lines
1.5 KiB
TypeScript

export type ConfigChangeScope = "agents" | "providers" | "commands" | "skills" | "all";
export interface ConfigChangeEvent {
scopes: ConfigChangeScope[];
source?: string;
timestamp: number;
}
type ConfigChangeListener = (event: ConfigChangeEvent) => void | Promise<void>;
const listeners = new Set<ConfigChangeListener>();
export function subscribeToConfigChanges(
listener: ConfigChangeListener,
): () => void {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}
export function emitConfigChange(
scopes: ConfigChangeScope | ConfigChangeScope[],
options?: { source?: string },
): void {
const normalized = Array.isArray(scopes) ? scopes : [scopes];
const uniqueScopes = Array.from(new Set(normalized));
if (uniqueScopes.length === 0) {
return;
}
if (uniqueScopes.includes("all")) {
uniqueScopes.splice(0, uniqueScopes.length, "all");
}
const event: ConfigChangeEvent = {
scopes: uniqueScopes,
source: options?.source,
timestamp: Date.now(),
};
for (const listener of listeners) {
try {
const result = listener(event);
if (result instanceof Promise) {
result.catch((error) => {
console.error("[ConfigSync] Async listener failed:", error);
});
}
} catch (error) {
console.error("[ConfigSync] Listener threw:", error);
}
}
}
export function scopeMatches(
event: ConfigChangeEvent,
scope: ConfigChangeScope,
): boolean {
return event.scopes.includes("all") || event.scopes.includes(scope);
}