添加模式卡片下发
This commit is contained in:
@@ -10,6 +10,7 @@ import mimetypes
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from collections.abc import Callable, Mapping
|
||||
@@ -84,6 +85,9 @@ from cognitive_agent.infrastructure.speech import ( # noqa: E402
|
||||
)
|
||||
|
||||
STATIC_ROOT = REPOSITORY_ROOT / "apps" / "web-console"
|
||||
DEFAULT_MODE_SCENE_CATALOG_PATH = (
|
||||
REPOSITORY_ROOT.parent / "scenses" / "demo-scenes.json"
|
||||
)
|
||||
mimetypes.add_type("application/manifest+json", ".webmanifest")
|
||||
mimetypes.add_type("model/gltf-binary", ".glb")
|
||||
REQUEST_ID_PATTERN = re.compile(r"^req-[a-z0-9-]+$")
|
||||
@@ -258,6 +262,13 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
|
||||
HTTPStatus.OK if assistant_available else HTTPStatus.SERVICE_UNAVAILABLE,
|
||||
)
|
||||
return
|
||||
if path == "/n7/scenes":
|
||||
vehicle_id = str(parse_qs(parsed_url.query).get("vehicle_id", [""])[0]) or None
|
||||
self._json(
|
||||
self.service.mode_scene_catalog(vehicle_id),
|
||||
headers={"Access-Control-Allow-Origin": "*"},
|
||||
)
|
||||
return
|
||||
if path in {"/login", "/login.html"}:
|
||||
if self.auth.config.enabled and self._session_username() is not None:
|
||||
self._redirect("/")
|
||||
@@ -440,6 +451,20 @@ class SeatDemoHandler(BaseHTTPRequestHandler):
|
||||
return
|
||||
self._serve_static(path, parsed_url.query)
|
||||
|
||||
def do_OPTIONS(self) -> None: # noqa: N802 - stdlib handler API
|
||||
path = unquote(urlparse(self.path).path)
|
||||
if path != "/n7/scenes":
|
||||
self._json({"error": "not_found"}, HTTPStatus.NOT_FOUND)
|
||||
return
|
||||
self.send_response(HTTPStatus.NO_CONTENT)
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.send_header("Access-Control-Allow-Methods", "GET, OPTIONS")
|
||||
self.send_header("Access-Control-Allow-Headers", "Accept, Content-Type")
|
||||
self.send_header("Content-Length", "0")
|
||||
self.send_header("Cache-Control", "no-store")
|
||||
self._send_security_headers()
|
||||
self.end_headers()
|
||||
|
||||
def do_POST(self) -> None: # noqa: N802 - stdlib handler API
|
||||
path = unquote(urlparse(self.path).path)
|
||||
if not self._require_same_origin():
|
||||
@@ -3306,7 +3331,25 @@ def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Run the cabin orchestration demo")
|
||||
parser.add_argument("--host", default=os.getenv("HOST", "127.0.0.1"))
|
||||
parser.add_argument("--port", type=int, default=int(os.getenv("PORT", "8000")))
|
||||
parser.add_argument(
|
||||
"--scene-catalog",
|
||||
type=Path,
|
||||
default=Path(
|
||||
os.getenv("N7_SCENE_CATALOG_PATH", "").strip()
|
||||
or DEFAULT_MODE_SCENE_CATALOG_PATH
|
||||
),
|
||||
help="JSON path synchronized from preset and user-created mode cards",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--scene-server-id",
|
||||
default=os.getenv("N7_SCENE_SERVER_ID", "n7-cognitive-agent"),
|
||||
help="server_id written to the N7 scene catalog",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
scene_catalog_status = SeatDemoHandler.service.configure_mode_scene_catalog(
|
||||
args.scene_catalog,
|
||||
server_id=args.scene_server_id,
|
||||
)
|
||||
server = ThreadingHTTPServer((args.host, args.port), SeatDemoHandler)
|
||||
SeatDemoHandler.speech.start()
|
||||
SeatDemoHandler.assistant.start(
|
||||
@@ -3331,6 +3374,20 @@ def main() -> None:
|
||||
)
|
||||
else:
|
||||
print(f"Cabin orchestration demo: http://{args.host}:{args.port}", flush=True)
|
||||
if scene_catalog_status["state"] == "ready":
|
||||
print(
|
||||
"N7 mode scene catalog: "
|
||||
f"{scene_catalog_status['path']} "
|
||||
f"({scene_catalog_status['scene_count']} scenes)",
|
||||
flush=True,
|
||||
)
|
||||
else:
|
||||
print(
|
||||
"N7 mode scene catalog synchronization unavailable: "
|
||||
f"{scene_catalog_status.get('last_error') or 'unknown error'}",
|
||||
file=sys.stderr,
|
||||
flush=True,
|
||||
)
|
||||
hardware_execution_ready = any(
|
||||
(
|
||||
SeatDemoHandler.service.hardware_settings.configured,
|
||||
|
||||
Reference in New Issue
Block a user