astera-customerAI / runtime /v8_bridge.py
G-ACE's picture
Deploy current Customer AI runtime 96b5a02fe7bbc525787d1a4359b7358d63d4d89a
d04144c verified
Raw History Blame Contribute Delete
1.17 kB
from __future__ import annotations
from typing import Any, Protocol
from .schemas import NeedTask, RoleResult, SharedRolePacket
class V8Adapter(Protocol):
async def analyze_need(self, message: str, context: dict[str, Any]) -> dict[str, Any]: ...
async def compare_results(self, packet: SharedRolePacket, results: list[RoleResult]) -> dict[str, Any]: ...
class V8Bridge:
def __init__(self, adapter: V8Adapter): self.adapter = adapter
async def analyze_need(self, message: str, context: dict[str, Any]) -> tuple[str, str, list[NeedTask]]:
raw = await self.adapter.analyze_need(message, context)
tasks = [NeedTask.model_validate(item) for item in raw.get("tasks", [])]
if not tasks: raise ValueError("v8_preflight_missing_tasks")
return str(raw.get("normalized_need") or message).strip(), str(raw.get("audience") or "general").strip() or "general", tasks
async def compare(self, packet: SharedRolePacket, results: list[RoleResult]) -> dict[str, Any]:
raw = await self.adapter.compare_results(packet, results)
if not isinstance(raw, dict): raise TypeError("v8_compare_invalid")
return raw