This commit is contained in:
Timothy Jaeryang Baek
2026-07-26 19:10:41 -04:00
parent 54f06d8c53
commit 94a60b0457
2 changed files with 36 additions and 2 deletions
+19 -1
View File
@@ -483,6 +483,16 @@ class EventDefinitions(BaseModel):
FUNCTION_DISABLED: EventDefinition = EventDefinition(
name='function.disabled', description='A function was disabled.', message='Function disabled'
)
FUNCTION_ENABLE_STARTED: EventDefinition = EventDefinition(
name='function.enable_started',
description='A function is about to be enabled.',
message='Function enable started',
)
FUNCTION_DISABLE_STARTED: EventDefinition = EventDefinition(
name='function.disable_started',
description='A function is about to be disabled.',
message='Function disable started',
)
FUNCTION_VALVES_UPDATED: EventDefinition = EventDefinition(
name='function.valves_updated', description='Function valves were updated.', message='Function valves updated'
)
@@ -1067,7 +1077,9 @@ class NotificationEventSink:
schedule_notification_dispatch(app, event)
async def dispatch_event_functions(app: Any, event: Event, request: Any | None = None) -> None:
async def dispatch_event_functions(
app: Any, event: Event, request: Any | None = None, extra_function_ids: list[str] | None = None
) -> None:
if not ENABLE_PLUGINS:
return
@@ -1079,6 +1091,12 @@ async def dispatch_event_functions(app: Any, event: Event, request: Any | None =
try:
event_functions = await Functions.get_functions_by_type('event', active_only=True)
if extra_function_ids:
extra_functions = await Functions.get_functions_by_ids(extra_function_ids)
existing_ids = {function.id for function in event_functions}
event_functions.extend(
function for function in extra_functions if function.type == 'event' and function.id not in existing_ids
)
except Exception:
log.exception('Event functions could not be loaded for %s', event.event)
return
+17 -1
View File
@@ -11,7 +11,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, status
from open_webui.config import CACHE_DIR
from open_webui.constants import ERROR_MESSAGES
from open_webui.env import AIOHTTP_CLIENT_SESSION_SSL, AIOHTTP_CLIENT_TIMEOUT, ENABLE_PLUGINS
from open_webui.events import EVENTS, publish_event
from open_webui.events import EVENTS, build_event, dispatch_event_functions, publish_event, schedule_webhook_dispatch
from open_webui.internal.db import get_async_session
from open_webui.models.functions import (
FunctionForm,
@@ -293,6 +293,22 @@ async def toggle_function_by_id(
):
function = await Functions.get_function_by_id(id, db=db)
if function:
lifecycle_event = build_event(
request,
EVENTS.FUNCTION_DISABLE_STARTED if function.is_active else EVENTS.FUNCTION_ENABLE_STARTED,
actor=user,
subject_id=function.id,
subject_type='function',
data={'type': function.type, 'name': function.name},
)
await dispatch_event_functions(
request.app,
lifecycle_event,
request=request,
extra_function_ids=[function.id] if not function.is_active else None,
)
schedule_webhook_dispatch(request.app, lifecycle_event)
function = await Functions.update_function_by_id(id, {'is_active': not function.is_active}, db=db)
if function: