refac
This commit is contained in:
1 parent
771a024b40
commit
c55e373b99
14 files changed
+921
-161
No files matched your search
@@ -161,6 +161,12 @@ class EventDefinitions(BaseModel):
|
||||
CHAT_CREATED: EventDefinition = EventDefinition(
|
||||
name='chat.created', description='A chat was created.', message='Chat created'
|
||||
)
|
||||
CHAT_FINISHED: EventDefinition = EventDefinition(
|
||||
name='chat.finished', description='A chat response finished.', message='Chat finished'
|
||||
)
|
||||
CHAT_FAILED: EventDefinition = EventDefinition(
|
||||
name='chat.failed', description='A chat response failed.', message='Chat failed'
|
||||
)
|
||||
CHAT_IMPORTED: EventDefinition = EventDefinition(
|
||||
name='chat.imported', description='A chat was imported.', message='Chat imported'
|
||||
)
|
||||
@@ -622,6 +628,12 @@ class EventDefinitions(BaseModel):
|
||||
TERMINAL_SESSION_CLOSED: EventDefinition = EventDefinition(
|
||||
name='terminal.session.closed', description='A terminal session was closed.', message='Terminal Session closed'
|
||||
)
|
||||
NOTIFICATION_TEST: EventDefinition = EventDefinition(
|
||||
name='notification.test', description='A notification target test was sent.', message='Notification test'
|
||||
)
|
||||
NOTIFICATION_MANUAL: EventDefinition = EventDefinition(
|
||||
name='notification.manual', description='A manual notification was sent.', message='Notification sent'
|
||||
)
|
||||
|
||||
|
||||
EVENTS = EventDefinitions()
|
||||
@@ -629,6 +641,7 @@ EVENT_DEFINITIONS = tuple(getattr(EVENTS, field_name) for field_name in EventDef
|
||||
EVENT_DEFINITIONS_BY_NAME = {definition.name: definition for definition in EVENT_DEFINITIONS}
|
||||
EVENT_CATALOG = tuple(definition.name for definition in EVENT_DEFINITIONS)
|
||||
EVENT_CATALOG_SET = set(EVENT_CATALOG)
|
||||
CHAT_NOTIFICATION_EVENTS = (EVENTS.CHAT_FINISHED.name, EVENTS.CHAT_FAILED.name)
|
||||
|
||||
|
||||
def get_event_catalog() -> list[dict[str, str]]:
|
||||
@@ -1024,6 +1037,21 @@ class WebhookEventSink:
|
||||
schedule_webhook_dispatch(app, event)
|
||||
|
||||
|
||||
def schedule_notification_dispatch(app: Any, event: Event) -> None:
|
||||
try:
|
||||
from open_webui.utils.notifications import dispatch_notification_event
|
||||
|
||||
asyncio.create_task(dispatch_notification_event(app, event))
|
||||
except RuntimeError:
|
||||
log.exception('Notification delivery could not be scheduled for %s', event.event)
|
||||
|
||||
|
||||
class NotificationEventSink:
|
||||
async def handle_event(self, app: Any, event: Event, request: Any | None = None) -> None:
|
||||
if event.event in CHAT_NOTIFICATION_EVENTS:
|
||||
schedule_notification_dispatch(app, event)
|
||||
|
||||
|
||||
async def dispatch_event_functions(app: Any, event: Event, request: Any | None = None) -> None:
|
||||
if not ENABLE_PLUGINS:
|
||||
return
|
||||
@@ -1084,7 +1112,7 @@ class EventFunctionSink:
|
||||
schedule_event_function_dispatch(app, event, request)
|
||||
|
||||
|
||||
EVENT_SINKS = [EventFunctionSink(), WebhookEventSink()]
|
||||
EVENT_SINKS = [EventFunctionSink(), WebhookEventSink(), NotificationEventSink()]
|
||||
|
||||
|
||||
async def publish_event(
|
||||
|
||||
Reference in new issue
Block a user