import { prepareNotificationContent } from './plugins/perception/notification-content.js'; import type { CanonicalEvent } from '../framework/events/index.js'; import type { EventIngressOptions } from '../framework/events/event-ingress.js'; import type { RuntimeEpochPlugin } from '../framework/plugins/index.js'; import { createClawclawEventCatalog } from '../clawclaw-event-catalog.js'; /** Fixed host lifecycle exception. Game facts and Behavior outputs are not in this list. */ export const CLAWCLAW_SYSTEM_CONTROL_EVENTS = new Set([ 'service_status', 'joined', 'room_created', 'room_joined', 'session_resumed', 'session_recovered', 'not_in_queue', 'poll_error', 'error', 'game_start_failed', 'game_terminal_missing', 'game_stream_disconnected', 'game_stream_reconnected', 'stop_requested', 'quit_requested', 'match_start', 'match_waiting', 'match_timeout', 'match_exited', 'user_left_game', 'session_left', 'quit_failed', 'room_attached', 'room_lobby_reconnect_failed', 'room_lobby_missing', 'room_returning_to_lobby', 'room_ping_timeout', 'room_destroyed', 'room.self_left', 'room.game_start_failed', 'lobby_connection_replaced', ]); export const BUILTIN_PERCEPTION_PREFIX = 'clawclaw.perception.system.'; export function createClawclawNotificationPolicy( plugins: readonly RuntimeEpochPlugin>[], ): NonNullable { const producers = new Set(plugins.filter(plugin => plugin.agentNotificationProducer).map(plugin => plugin.id)); const systemCatalog = createClawclawEventCatalog(); return input => { if (input.producerPluginId && producers.has(input.producerPluginId)) { // Mandatory builtin notifications are not controlled by user visual delivery preferences. const fixed = input.producerPluginId.startsWith(BUILTIN_PERCEPTION_PREFIX) ? systemCatalog.get(input.type) : undefined; return { source: 'perception', ...(fixed ? { deliveryClass: fixed.deliveryClass, wakeAgent: input.wakeAgent ?? true } : {}) }; } if (input.producerPluginId === undefined && CLAWCLAW_SYSTEM_CONTROL_EVENTS.has(input.type)) { return { source: 'system', content: prepareNotificationContent(input.type, input.payload ?? {}, null, 'system', input) }; } return undefined; }; } export function isClawclawAgentNotification(event: CanonicalEvent): boolean { return event.deliveryClass !== 'internal_only' && (event.notificationSource === 'perception' || event.notificationSource === 'system'); }