mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-16 19:00:47 +08:00
初始化:独立 oclaw 仓库首提交
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
This commit is contained in:
commit
ba3836f00f
579 changed files with 83112 additions and 0 deletions
50
interfaces/gateway/http_adapter.py
Normal file
50
interfaces/gateway/http_adapter.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from oclaw.platform.config.paths import db_path
|
||||
from oclaw.platform.persistence.sqlite_store import SqliteStore
|
||||
|
||||
from .context_builder import build_common_gateway_context
|
||||
from .dispatcher import build_gateway_method_handlers
|
||||
|
||||
|
||||
def _build_http_context() -> dict[str, Any]:
|
||||
store = SqliteStore(db_path())
|
||||
context = build_common_gateway_context(store=store)
|
||||
context["session_event_subscribers"] = set()
|
||||
context["session_message_subscribers"] = {}
|
||||
return context
|
||||
|
||||
|
||||
def dispatch_gateway_http_method(method: str, params: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
handlers = build_gateway_method_handlers()
|
||||
m = str(method or "").strip()
|
||||
handler = handlers.get(m)
|
||||
if not callable(handler):
|
||||
return {"ok": False, "payload": None, "error": {"code": "INVALID_REQUEST", "message": f"unknown method: {m}"}}
|
||||
|
||||
result: dict[str, Any] = {"ok": False, "payload": None, "error": {"code": "UNAVAILABLE", "message": "no response"}}
|
||||
|
||||
def _respond(ok: bool, payload: Any | None, error: dict[str, Any] | None, _meta: dict[str, Any] | None) -> None:
|
||||
result["ok"] = bool(ok)
|
||||
result["payload"] = payload
|
||||
result["error"] = error
|
||||
|
||||
opts = {
|
||||
"req": {"id": "http", "method": m, "params": dict(params or {})},
|
||||
"params": dict(params or {}),
|
||||
"client": {"conn_id": "http", "internal": {}},
|
||||
"respond": _respond,
|
||||
"context": _build_http_context(),
|
||||
"is_webchat_connect": lambda _p: False,
|
||||
}
|
||||
try:
|
||||
handler(opts)
|
||||
except Exception as exc:
|
||||
return {"ok": False, "payload": None, "error": {"code": "UNAVAILABLE", "message": f"{type(exc).__name__}: {exc}"}}
|
||||
return result
|
||||
|
||||
|
||||
__all__ = ["dispatch_gateway_http_method"]
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue