feat(deploy): finalize MVP deployment and file transfer approach
This commit is contained in:
parent
6369721876
commit
0f79494fbe
43 changed files with 3078 additions and 645 deletions
35
sdk/real.py
35
sdk/real.py
|
|
@ -1,8 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import re
|
||||
from collections.abc import AsyncIterator
|
||||
from pathlib import Path
|
||||
from urllib.parse import urljoin, urlsplit, urlunsplit
|
||||
|
||||
import structlog
|
||||
|
||||
|
|
@ -21,6 +24,11 @@ from sdk.upstream_agent_api import AgentApi, MsgEventSendFile, MsgEventTextChunk
|
|||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
def _ws_debug_enabled() -> bool:
|
||||
value = os.environ.get("SURFACES_DEBUG_WS", "")
|
||||
return value.strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
class RealPlatformClient(PlatformClient):
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -31,11 +39,20 @@ class RealPlatformClient(PlatformClient):
|
|||
agent_api_cls=AgentApi,
|
||||
) -> None:
|
||||
self._agent_id = agent_id
|
||||
self._agent_base_url = agent_base_url
|
||||
self._raw_agent_base_url = agent_base_url
|
||||
self._agent_base_url = self._normalize_agent_base_url(agent_base_url)
|
||||
self._agent_api_cls = agent_api_cls
|
||||
self._prototype_state = prototype_state
|
||||
self._platform = platform
|
||||
self._chat_send_locks: dict[str, asyncio.Lock] = {}
|
||||
if _ws_debug_enabled():
|
||||
logger.warning(
|
||||
"agent_client_initialized",
|
||||
agent_id=self._agent_id,
|
||||
platform=self._platform,
|
||||
raw_base_url=self._raw_agent_base_url,
|
||||
normalized_base_url=self._agent_base_url,
|
||||
)
|
||||
|
||||
@property
|
||||
def agent_id(self) -> str:
|
||||
|
|
@ -171,12 +188,28 @@ class RealPlatformClient(PlatformClient):
|
|||
yield event
|
||||
|
||||
def _build_chat_api(self, chat_id: str):
|
||||
if _ws_debug_enabled():
|
||||
logger.warning(
|
||||
"agent_chat_api_build",
|
||||
agent_id=self._agent_id,
|
||||
chat_id=str(chat_id),
|
||||
normalized_base_url=self._agent_base_url,
|
||||
ws_url=urljoin(self._agent_base_url, f"v1/agent_ws/{chat_id}/"),
|
||||
)
|
||||
return self._agent_api_cls(
|
||||
agent_id=self._agent_id,
|
||||
base_url=self._agent_base_url,
|
||||
chat_id=str(chat_id),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _normalize_agent_base_url(base_url: str) -> str:
|
||||
parsed = urlsplit(base_url)
|
||||
path = re.sub(r"(?:/v1)?/agent_ws(?:/[^/]+)?/?$", "", parsed.path.rstrip("/"))
|
||||
if path:
|
||||
path = f"{path}/"
|
||||
return urlunsplit((parsed.scheme, parsed.netloc, path, "", ""))
|
||||
|
||||
@staticmethod
|
||||
async def _close_chat_api(chat_api) -> None:
|
||||
close = getattr(chat_api, "close", None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue