mirror of https://github.com/openclaw/openclaw.git
29 lines
761 B
TypeScript
29 lines
761 B
TypeScript
export type SessionLifecycleEvent = {
|
|
sessionKey: string;
|
|
reason: string;
|
|
parentSessionKey?: string;
|
|
label?: string;
|
|
displayName?: string;
|
|
};
|
|
|
|
type SessionLifecycleListener = (event: SessionLifecycleEvent) => void;
|
|
|
|
const SESSION_LIFECYCLE_LISTENERS = new Set<SessionLifecycleListener>();
|
|
|
|
export function onSessionLifecycleEvent(listener: SessionLifecycleListener): () => void {
|
|
SESSION_LIFECYCLE_LISTENERS.add(listener);
|
|
return () => {
|
|
SESSION_LIFECYCLE_LISTENERS.delete(listener);
|
|
};
|
|
}
|
|
|
|
export function emitSessionLifecycleEvent(event: SessionLifecycleEvent): void {
|
|
for (const listener of SESSION_LIFECYCLE_LISTENERS) {
|
|
try {
|
|
listener(event);
|
|
} catch {
|
|
// Best-effort, do not propagate listener errors.
|
|
}
|
|
}
|
|
}
|