feat(sdk): add host integration extension points
This commit is contained in:
1 parent
12f828ea3d
commit
c050955ae3
13 files changed
+359
-7
No files matched your search
+18
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable, Mapping
|
||||
from collections.abc import Callable, Iterable, Mapping
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
@@ -18,6 +18,8 @@ from nanobot.session.manager import replay_max_messages_for_context
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from nanobot.agent.loop import AgentLoop
|
||||
from nanobot.bus.runtime_events import RuntimeEventHandler, RuntimeEventType
|
||||
from nanobot.runtime_context import RuntimeContextProvider
|
||||
|
||||
|
||||
class SessionClient:
|
||||
@@ -193,6 +195,21 @@ class RuntimeClient:
|
||||
"""Current runtime workspace."""
|
||||
return self._loop.workspace
|
||||
|
||||
def add_context_provider(
|
||||
self,
|
||||
provider: RuntimeContextProvider,
|
||||
) -> Callable[[], None]:
|
||||
"""Register per-turn model context and return an unsubscribe callback."""
|
||||
return self._loop.register_runtime_context_provider(provider)
|
||||
|
||||
def subscribe(
|
||||
self,
|
||||
event_type: RuntimeEventType,
|
||||
handler: RuntimeEventHandler,
|
||||
) -> Callable[[], None]:
|
||||
"""Subscribe to one runtime event type and return an unsubscribe callback."""
|
||||
return self._loop.runtime_events.subscribe(handler, event_type)
|
||||
|
||||
async def compact_session(self, session_key: str) -> SessionSnapshot:
|
||||
"""Run token/replay-window consolidation for one session."""
|
||||
session = self._loop.sessions.get_or_create(session_key)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
|
||||
@@ -22,6 +23,7 @@ def build_process_direct_kwargs(
|
||||
sender_id: str,
|
||||
media: list[str] | None,
|
||||
ephemeral: bool,
|
||||
attributes: Mapping[str, Any] | None = None,
|
||||
on_stream: Any | None = None,
|
||||
on_stream_end: Any | None = None,
|
||||
) -> dict[str, Any]:
|
||||
@@ -37,6 +39,8 @@ def build_process_direct_kwargs(
|
||||
if ephemeral:
|
||||
kwargs["ephemeral"] = True
|
||||
kwargs["_run_extra_hooks_for_ephemeral"] = True
|
||||
if attributes is not None:
|
||||
kwargs["attributes"] = dict(attributes)
|
||||
if on_stream is not None:
|
||||
kwargs["on_stream"] = on_stream
|
||||
if on_stream_end is not None:
|
||||
|
||||
Reference in new issue
Block a user