feat: integrate Chinese speech understanding and capability routing
This commit is contained in:
@@ -2,23 +2,66 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class CapabilityDefinition:
|
||||
"""One capability together with its authoritative catalog provenance."""
|
||||
|
||||
name: str
|
||||
domain: str
|
||||
availability: str
|
||||
catalog_id: str
|
||||
catalog_path: Path
|
||||
executor_binding: str
|
||||
spec: dict[str, Any]
|
||||
|
||||
@property
|
||||
def target_devices(self) -> tuple[str, ...]:
|
||||
return tuple(str(value) for value in self.spec.get("target_devices", ()))
|
||||
|
||||
@property
|
||||
def target_scopes(self) -> tuple[str, ...]:
|
||||
return tuple(str(value) for value in self.spec.get("target_scopes", ()))
|
||||
|
||||
@property
|
||||
def parameters(self) -> tuple[dict[str, Any], ...]:
|
||||
return tuple(dict(value) for value in self.spec.get("parameters", ()))
|
||||
|
||||
|
||||
class CapabilityRegistry:
|
||||
"""Expose domain catalogs without embedding domain semantics in prompts or code."""
|
||||
|
||||
def __init__(self, repository_root: Path, executable_domains: set[str]) -> None:
|
||||
self.root = repository_root
|
||||
self.executable_domains = set(executable_domains)
|
||||
self._definitions: list[CapabilityDefinition] = []
|
||||
self._snapshot = self._load()
|
||||
|
||||
def snapshot(self) -> dict[str, Any]:
|
||||
return self._snapshot
|
||||
|
||||
def definitions(self, *, domain: str | None = None) -> tuple[CapabilityDefinition, ...]:
|
||||
"""Return catalog entries without inventing aliases or execution support."""
|
||||
|
||||
return tuple(
|
||||
definition
|
||||
for definition in self._definitions
|
||||
if domain is None or definition.domain == domain
|
||||
)
|
||||
|
||||
def find(self, name: str) -> tuple[CapabilityDefinition, ...]:
|
||||
"""Return every authoritative definition for a canonical capability id."""
|
||||
|
||||
return tuple(
|
||||
definition for definition in self._definitions if definition.name == name
|
||||
)
|
||||
|
||||
def _load(self) -> dict[str, Any]:
|
||||
domains = []
|
||||
catalog_paths = [
|
||||
@@ -31,16 +74,37 @@ class CapabilityRegistry:
|
||||
catalog = yaml.safe_load(catalog_path.read_text(encoding="utf-8"))
|
||||
domain = catalog["spec"]["domain"]
|
||||
native_can_catalog = catalog_path.parent.name == "native_can_capabilities"
|
||||
availability = (
|
||||
"native_can"
|
||||
if native_can_catalog
|
||||
else "executable"
|
||||
if domain in self.executable_domains
|
||||
else "catalog_only"
|
||||
)
|
||||
executor_binding = (
|
||||
"NativeCanRuntime/NativeCanExecutor"
|
||||
if native_can_catalog
|
||||
else "SeatCompiler/SeatExecutor"
|
||||
if domain == "seat"
|
||||
else f"ConfiguredDomainRuntime[{domain}]"
|
||||
)
|
||||
catalog_id = str(catalog.get("metadata", {}).get("id", catalog_path.stem))
|
||||
self._definitions.extend(
|
||||
CapabilityDefinition(
|
||||
name=str(capability["name"]),
|
||||
domain=str(domain),
|
||||
availability=availability,
|
||||
catalog_id=catalog_id,
|
||||
catalog_path=catalog_path,
|
||||
executor_binding=executor_binding,
|
||||
spec=dict(capability),
|
||||
)
|
||||
for capability in catalog["spec"]["capabilities"]
|
||||
)
|
||||
domains.append(
|
||||
{
|
||||
"domain": domain,
|
||||
"availability": (
|
||||
"native_can"
|
||||
if native_can_catalog
|
||||
else "executable"
|
||||
if domain in self.executable_domains
|
||||
else "catalog_only"
|
||||
),
|
||||
"availability": availability,
|
||||
"capabilities": catalog["spec"]["capabilities"],
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user