fix prototype backend review issues
This commit is contained in:
parent
94bdb44b93
commit
37643a9695
9 changed files with 182 additions and 46 deletions
|
|
@ -1,3 +1,9 @@
|
|||
from sdk.real import RealPlatformClient
|
||||
|
||||
__all__ = ["RealPlatformClient"]
|
||||
|
||||
|
||||
def __getattr__(name: str):
|
||||
if name == "RealPlatformClient":
|
||||
from sdk.real import RealPlatformClient
|
||||
|
||||
return RealPlatformClient
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ from dataclasses import dataclass
|
|||
from typing import AsyncIterator
|
||||
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
|
||||
|
||||
import aiohttp
|
||||
|
||||
from sdk.interface import MessageChunk, MessageResponse, PlatformError
|
||||
|
||||
|
||||
|
|
@ -41,6 +39,8 @@ class AgentSessionClient:
|
|||
)
|
||||
|
||||
async def stream_message(self, *, thread_key: str, text: str) -> AsyncIterator[MessageChunk]:
|
||||
import aiohttp
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.ws_connect(
|
||||
self._ws_url(thread_key),
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class PrototypeStateStore:
|
|||
|
||||
async def get_or_create_user(
|
||||
self,
|
||||
*,
|
||||
external_id: str,
|
||||
platform: str,
|
||||
display_name: str | None = None,
|
||||
|
|
@ -54,14 +53,14 @@ class PrototypeStateStore:
|
|||
created_at=datetime.now(UTC),
|
||||
is_new=True,
|
||||
)
|
||||
self._users[key] = user
|
||||
self._users[key] = user.model_copy(update={"is_new": False})
|
||||
return user.model_copy()
|
||||
|
||||
async def get_settings(self, user_id: str) -> UserSettings:
|
||||
stored = self._settings.get(user_id, {})
|
||||
return UserSettings(
|
||||
skills={**DEFAULT_SKILLS, **stored.get("skills", {})},
|
||||
connectors=stored.get("connectors", {}),
|
||||
connectors=dict(stored.get("connectors", {})),
|
||||
soul={**DEFAULT_SOUL, **stored.get("soul", {})},
|
||||
safety={**DEFAULT_SAFETY, **stored.get("safety", {})},
|
||||
plan={**DEFAULT_PLAN, **stored.get("plan", {})},
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import AsyncIterator
|
||||
from typing import TYPE_CHECKING, AsyncIterator
|
||||
|
||||
from sdk.agent_session import AgentSessionClient, build_thread_key
|
||||
from sdk.agent_session import build_thread_key
|
||||
from sdk.interface import Attachment, MessageChunk, MessageResponse, PlatformClient, User, UserSettings
|
||||
from sdk.prototype_state import PrototypeStateStore
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sdk.agent_session import AgentSessionClient
|
||||
|
||||
|
||||
class RealPlatformClient(PlatformClient):
|
||||
def __init__(
|
||||
self,
|
||||
agent_sessions: AgentSessionClient,
|
||||
prototype_state: PrototypeStateStore,
|
||||
platform: str,
|
||||
platform: str = "matrix",
|
||||
) -> None:
|
||||
self._agent_sessions = agent_sessions
|
||||
self._prototype_state = prototype_state
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue