Skip to content

Commit dca6160

Browse files
committed
feat: feature flag io_publisher
1 parent 51395d3 commit dca6160

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/askui/chat/api/runs/events/io_publisher.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,33 @@
55
from typing import Any
66

77
from askui.chat.api.runs.events.events import Event
8+
from askui.chat.api.settings import Settings
89

910

1011
class IOPublisher:
1112
"""Publisher that serializes events to JSON and writes to stdout."""
1213

14+
def __init__(self, enabled: bool) -> None:
15+
"""
16+
Initialize the IO publisher.
17+
18+
Args:
19+
settings: The settings instance containing configuration for the IO publisher.
20+
"""
21+
self._enabled = enabled
22+
1323
def publish(self, event: Event) -> None:
1424
"""
1525
Publish an event by serializing it to JSON and writing to stdout.
1626
27+
If the publisher is disabled, this method does nothing.
28+
1729
Args:
1830
event: The event to publish
1931
"""
32+
if not self._enabled:
33+
return
34+
2035
try:
2136
event_dict: dict[str, Any] = event.model_dump(mode="json")
2237
event_json = json.dumps(event_dict)

src/askui/chat/api/runs/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(
4444
self._chat_history_manager = chat_history_manager
4545
self._settings = settings
4646
self._event_service = EventService(settings.data_dir, self)
47-
self._io_publisher = IOPublisher()
47+
self._io_publisher = IOPublisher(settings.enable_io_events)
4848

4949
def _find_by_id(
5050
self, workspace_id: WorkspaceId | None, thread_id: ThreadId, run_id: RunId

src/askui/chat/api/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,7 @@ class Settings(BaseSettings):
118118
default_factory=OtelSettings,
119119
description="OpenTelemetry configuration settings",
120120
)
121+
enable_io_events: bool = Field(
122+
default=False,
123+
description="Whether to enable the publishing events to stdout",
124+
)

0 commit comments

Comments
 (0)