Add prepared urban route guidance to Gaussian simulation planning
Introduce a content-bound scene route provider, advisory runtime graph and plan-preview-launch workflow. Preserve live sensing authority and retire blocked intermediate goals without discarding final-arrival evidence. Bound native visual context losslessly and provide verified cache relocation. Full Maroseyka route qualification remains open.
This commit is contained in:
@@ -30,6 +30,8 @@ from k1link.simulation.ai_polygon.contracts import (
|
||||
WorldSettings,
|
||||
)
|
||||
from k1link.simulation.ai_polygon.editor_cache import EditorCache
|
||||
from k1link.simulation.ai_polygon.route_preparation import RoutePreparationStore, provider_identity
|
||||
from k1link.web.route_preparation_api import build_route_preparation_router, public_plan, public_run
|
||||
from k1link.simulation.ai_polygon.robots import robot_catalog, select_robot
|
||||
from k1link.simulation.ai_polygon.runs import RunStore
|
||||
from k1link.simulation.ai_polygon.worlds import CHUNK_BYTES, SOURCES, WorldStore
|
||||
@@ -41,6 +43,7 @@ def build_ai_polygon_router(
|
||||
worlds = WorldStore(data_dir)
|
||||
runs = RunStore(worlds, queue)
|
||||
editor = EditorCache(data_dir, worlds)
|
||||
routes = RoutePreparationStore(data_dir)
|
||||
router = APIRouter(prefix="/api/v1/ai-polygon", tags=["ai-polygon"])
|
||||
adapters = Path(__file__).resolve().parents[3] / "simulation/ai-polygon"
|
||||
from k1link.web.ai_profile_api import build_ai_profile_router
|
||||
@@ -62,9 +65,12 @@ def build_ai_polygon_router(
|
||||
if not authorization or not secrets.compare_digest(authorization, expected):
|
||||
raise HTTPException(401, "Worker authentication required")
|
||||
|
||||
router.include_router(build_route_preparation_router(routes, worlds, editor, runs, invoke, authenticate))
|
||||
|
||||
@router.get("/catalog")
|
||||
def catalog():
|
||||
runtime = runs.status()
|
||||
runtime = {**runtime, "active_run": public_run(runtime.get("active_run"))}
|
||||
locations = worlds.list()
|
||||
if "project-sog" not in (runtime.get("worker") or {}).get("scene_formats", []):
|
||||
locations = [
|
||||
@@ -83,8 +89,8 @@ def build_ai_polygon_router(
|
||||
"robots": robot_catalog(adapters),
|
||||
"worlds": locations,
|
||||
"runtime": runtime,
|
||||
"runs": runs.library.visible(runs.list(), "run_id")[:30],
|
||||
"plans": runs.plans.visible_list(),
|
||||
"runs": [public_run(r) for r in runs.library.visible(runs.list(), "run_id")[:30]],
|
||||
"plans": [public_plan(p) for p in runs.plans.visible_list()],
|
||||
}
|
||||
|
||||
@router.get("/worker/worlds/{world_id}/project-assets")
|
||||
@@ -169,16 +175,19 @@ def build_ai_polygon_router(
|
||||
if cached["status"] != "ready" or editor.identity(world) != cached["identity"]:
|
||||
raise HTTPException(409, "Локация изменилась. Откройте планирование заново.")
|
||||
robot = invoke(select_robot, body.robot_id, body.robot_sha256)
|
||||
prepared = invoke(routes.for_plan, body.route_preparation_key, world, robot,
|
||||
[p.model_dump(mode="json") for p in body.points]) if body.route_preparation_key else None
|
||||
context = {"world": world, "robot": robot, "run_id": None}
|
||||
return invoke(
|
||||
lambda: runs.plans.create(
|
||||
context,
|
||||
body.name,
|
||||
[p.model_dump() for p in body.points],
|
||||
[p.model_dump(mode="json") for p in body.points],
|
||||
body.sequence,
|
||||
draft_id=body.draft_id,
|
||||
cache_key=body.cache_key,
|
||||
editor_collider_sha256=cached["files"]["collision.glb"]["sha256"],
|
||||
prepared_route=prepared,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -192,8 +201,8 @@ def build_ai_polygon_router(
|
||||
|
||||
@router.post("/runs", status_code=201)
|
||||
def start(body: RunCreate, idempotency_key: str = Header(alias="Idempotency-Key")):
|
||||
if editor.pending():
|
||||
raise HTTPException(409, "Дождитесь загрузки локальной сцены.")
|
||||
if editor.pending() or routes.pending():
|
||||
raise HTTPException(409, "Дождитесь подготовки сцены и маршрута.")
|
||||
if body.clock == "realtime":
|
||||
graph = invoke(compose, adapters, body.composition)
|
||||
body = body.model_copy(update={"composition": graph.selection_document()})
|
||||
@@ -306,6 +315,16 @@ def build_ai_polygon_router(
|
||||
except RuntimeError:
|
||||
return value
|
||||
return {"action": "editor-cache", "cache": pending}
|
||||
if value["action"] == "idle" and runs.queue is not None:
|
||||
pending = routes.pending()
|
||||
worker = runs.status().get("worker") or {}
|
||||
if pending and worker.get("route_provider_sha256") == provider_identity():
|
||||
try:
|
||||
runs.queue.reserve_simulation("aicache-" + pending["key"])
|
||||
claimed = routes.claim(pending["key"],body.instance_id)
|
||||
except RuntimeError:
|
||||
return value
|
||||
return {"action": "route-preparation", "preparation": claimed}
|
||||
return value
|
||||
|
||||
@router.post("/worker/editor-cache/{key}")
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"""Existing simulation planning surface's bounded asynchronous route port."""
|
||||
import json
|
||||
from fastapi import APIRouter, Header, HTTPException, Request
|
||||
|
||||
from k1link.simulation.ai_polygon.contracts import RoutePrepare
|
||||
from k1link.simulation.ai_polygon.robots import select_robot
|
||||
from k1link.simulation.ai_polygon.route_preparation import provider_identity
|
||||
|
||||
|
||||
def public_plan(plan):
|
||||
if not plan or not plan.get('prepared_route'):
|
||||
return plan
|
||||
return {**plan,'prepared_route':{k:v for k,v in plan['prepared_route'].items() if k!='routing'}}
|
||||
|
||||
|
||||
def public_run(run):
|
||||
if not run or not (run.get('plan') or {}).get('prepared_route'):
|
||||
return run
|
||||
return {**run,'plan':public_plan(run['plan']),
|
||||
'execution_inputs':{k:v for k,v in run.get('execution_inputs',{}).items() if k!='routing'}}
|
||||
|
||||
|
||||
def public_preparation(row):
|
||||
return {k:v for k,v in row.items() if k not in ('world','robot','owner','result')} | {
|
||||
'result': {k:v for k,v in row['result'].items() if k!='routing'} if row.get('result') else None}
|
||||
|
||||
|
||||
def build_route_preparation_router(store, worlds, editor, runs, invoke, authenticate):
|
||||
router=APIRouter()
|
||||
|
||||
@router.post('/route-preparations',status_code=201)
|
||||
def prepare(body:RoutePrepare):
|
||||
with runs.lock:
|
||||
cached=invoke(editor.get,body.cache_key)
|
||||
world=invoke(worlds.get,cached['world']['world_id'])
|
||||
if cached['status']!='ready' or editor.identity(world)!=cached['identity']:
|
||||
raise HTTPException(409,'Локация изменилась. Откройте планирование заново.')
|
||||
worker=runs.status().get('worker') or {}
|
||||
if worker.get('route_provider_sha256')!=provider_identity():
|
||||
raise HTTPException(409,'Подключите Worker с модулем подготовки маршрута.')
|
||||
robot=invoke(select_robot,body.robot_id,body.robot_sha256)
|
||||
row=invoke(store.request,world,robot,[p.model_dump(mode="json") for p in body.points])
|
||||
return public_preparation(row)
|
||||
|
||||
@router.get('/route-preparations/{key}')
|
||||
def status(key:str):
|
||||
return public_preparation(invoke(store.get,key))
|
||||
|
||||
@router.post('/worker/route-preparations/{key}')
|
||||
async def update(key:str,request:Request,authorization:str|None=Header(default=None),
|
||||
instance_id:str=Header(alias='Worker-Instance')):
|
||||
authenticate(authorization)
|
||||
invoke(runs.heartbeat,instance_id)
|
||||
raw=bytearray()
|
||||
async for block in request.stream():
|
||||
raw.extend(block)
|
||||
if len(raw)>4*1024**2:
|
||||
raise HTTPException(413,'Route result exceeds budget')
|
||||
try:
|
||||
body=json.loads(raw)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(400,'Invalid route result') from exc
|
||||
row=invoke(store.update,key,body,instance_id)
|
||||
if body.get('action')=='release' and runs.queue is not None:
|
||||
invoke(runs.queue.release_simulation,'aicache-'+key)
|
||||
return public_preparation(row)
|
||||
|
||||
return router
|
||||
Reference in New Issue
Block a user