Skip to content

Commit 1b4ccfb

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,30 @@
44
import sys
55
from typing import Any
66

7+
from askui.chat.api.dependencies import get_settings
78
from askui.chat.api.runs.events.events import Event
89

910

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

14+
def __init__(self) -> None:
15+
"""Initialize the IO publisher."""
16+
settings = get_settings()
17+
self._enabled = settings.enable_io_events
18+
1319
def publish(self, event: Event) -> None:
1420
"""
1521
Publish an event by serializing it to JSON and writing to stdout.
1622
23+
If the publisher is disabled, this method does nothing.
24+
1725
Args:
1826
event: The event to publish
1927
"""
28+
if not self._enabled:
29+
return
30+
2031
try:
2132
event_dict: dict[str, Any] = event.model_dump(mode="json")
2233
event_json = json.dumps(event_dict)

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)