release: bump version to 0.84.0
This commit is contained in:
1 parent
3b1b9ef68c
commit
e1cc27f13d
241 files changed
+42779
-6027
No files matched your search
+120
-162
@@ -37,23 +37,17 @@ from app.services.cable_graph import build_graph_from_data, CableGraph, haversin
|
||||
from app.services.compute_center_locations import (
|
||||
RENDERABLE_PRECISIONS,
|
||||
ResolutionDiagnostic,
|
||||
build_compute_center_location_query,
|
||||
collect_location_candidates,
|
||||
get_compute_center_location_dict,
|
||||
refresh_compute_center_location_cache,
|
||||
resolve_compute_center_location_full,
|
||||
upsert_compute_center_location,
|
||||
)
|
||||
from app.services.ai_client import get_ai_provider_client
|
||||
from app.api.v1.settings import get_runtime_web_search_config, get_web_search_client
|
||||
from app.api.v1.settings import get_runtime_web_search_config
|
||||
from app.services.ai_tools.web_search import normalize_web_search_provider
|
||||
from app.services.collectors.bgp_common import RIPE_RIS_COLLECTOR_COORDS
|
||||
from app.services.location.llm_fallback import (
|
||||
collect_llm_location_fallback_candidate,
|
||||
collect_location_search_evidence,
|
||||
)
|
||||
from app.services.location.agent_resolver import (
|
||||
run_controlled_location_agent,
|
||||
run_l1_structured_facility_resolvers,
|
||||
from app.services.location.workflow_tools import (
|
||||
TERMINAL_UNLOCATABLE_STATUSES,
|
||||
run_location_workflow,
|
||||
)
|
||||
from app.services.persistent_logs import record_system_log
|
||||
from app.services.vessel_ais_aggregation import (
|
||||
@@ -79,6 +73,9 @@ from app.core.logging import get_logger
|
||||
router = APIRouter()
|
||||
logger = get_logger(__name__, service="api")
|
||||
_vis_read_dep = Depends(require_earth_or_api_access("visualization:read"))
|
||||
_vis_tile_read_dep = Depends(
|
||||
require_earth_or_api_access("visualization:read", rate_limit_tier="tile")
|
||||
)
|
||||
TERRAIN_TILE_URL_TEMPLATE = (
|
||||
"https://s3.amazonaws.com/elevation-tiles-prod/terrarium/{z}/{x}/{y}.png"
|
||||
)
|
||||
@@ -296,7 +293,14 @@ def _extract_satellite_record(record: CollectedData) -> tuple[dict[str, Any], An
|
||||
|
||||
tle_line1 = metadata.get("tle_line1")
|
||||
tle_line2 = metadata.get("tle_line2")
|
||||
if not tle_line1 or not tle_line2:
|
||||
# Stored 6-digit NORAD TLE lines (70+ chars) shift orbital element columns; regenerate using Alpha-5.
|
||||
valid_tle = (
|
||||
isinstance(tle_line1, str)
|
||||
and isinstance(tle_line2, str)
|
||||
and len(tle_line1.rstrip()) == 69
|
||||
and len(tle_line2.rstrip()) == 69
|
||||
)
|
||||
if not valid_tle:
|
||||
tle_line1, tle_line2 = build_tle_lines_from_elements(
|
||||
norad_cat_id=norad_id,
|
||||
epoch=metadata.get("epoch"),
|
||||
@@ -719,16 +723,27 @@ def convert_compute_centers_to_geojson(records: List[CollectedData]) -> Dict[str
|
||||
features: List[Dict[str, Any]] = []
|
||||
unresolved: List[Dict[str, Any]] = []
|
||||
withheld_count = 0
|
||||
withheld_by_status: Dict[str, int] = {}
|
||||
|
||||
for record in records:
|
||||
metadata = record.extra_data or {}
|
||||
if metadata.get("compute_contract") == "v1" and metadata.get("anonymous"):
|
||||
withheld_count += 1
|
||||
withheld_by_status["anonymous"] = withheld_by_status.get("anonymous", 0) + 1
|
||||
continue
|
||||
result = resolve_compute_center_location_full(record, metadata)
|
||||
site_type = compute_site_type(record)
|
||||
|
||||
if not result.is_resolved:
|
||||
stored_loc = get_compute_center_location_dict(
|
||||
getattr(record, "source", None),
|
||||
getattr(record, "source_id", None),
|
||||
)
|
||||
stored_status = str(stored_loc.get("verification_status") or "").strip().lower()
|
||||
if stored_status in TERMINAL_UNLOCATABLE_STATUSES:
|
||||
withheld_count += 1
|
||||
withheld_by_status[stored_status] = withheld_by_status.get(stored_status, 0) + 1
|
||||
continue
|
||||
diagnostic = result.diagnostic or ResolutionDiagnostic(
|
||||
failure_reason="Unknown resolver failure",
|
||||
attempted_queries=(),
|
||||
@@ -816,7 +831,13 @@ def convert_compute_centers_to_geojson(records: List[CollectedData]) -> Dict[str
|
||||
}
|
||||
)
|
||||
|
||||
return {"type": "FeatureCollection", "features": features, "unresolved": unresolved, "withheld_count": withheld_count}
|
||||
return {
|
||||
"type": "FeatureCollection",
|
||||
"features": features,
|
||||
"unresolved": unresolved,
|
||||
"withheld_count": withheld_count,
|
||||
"withheld_by_status": withheld_by_status,
|
||||
}
|
||||
|
||||
|
||||
VESSEL_TYPE_FILTERS = {
|
||||
@@ -1693,7 +1714,7 @@ async def _build_landing_points_geojson(db: AsyncSession) -> dict[str, Any]:
|
||||
raise HTTPException(status_code=500, detail=f"Internal error: {str(e)}")
|
||||
|
||||
|
||||
@router.get("/terrain/terrarium/{z}/{x}/{y}.png", dependencies=[_vis_read_dep])
|
||||
@router.get("/terrain/terrarium/{z}/{x}/{y}.png", dependencies=[_vis_tile_read_dep])
|
||||
async def get_terrarium_tile(z: int, x: int, y: int):
|
||||
"""Proxy Terrarium elevation tiles through the backend to avoid browser CORS issues."""
|
||||
if not _is_valid_terrain_tile(z, x, y):
|
||||
@@ -1783,7 +1804,7 @@ async def _fetch_terrain_tile(
|
||||
return content, content_type, dict(headers)
|
||||
|
||||
|
||||
@router.post("/terrain/terrarium/batch", dependencies=[_vis_read_dep])
|
||||
@router.post("/terrain/terrarium/batch", dependencies=[_vis_tile_read_dep])
|
||||
async def get_terrarium_tile_batch(payload: TerrariumTileBatchRequest):
|
||||
"""Fetch Terrarium elevation tiles in batches so the browser avoids many tiny requests."""
|
||||
unique_tiles: list[TerrariumTileRequest] = []
|
||||
@@ -2095,6 +2116,8 @@ async def _build_compute_centers_geojson(
|
||||
"type": "FeatureCollection",
|
||||
"features": [],
|
||||
"unresolved": [],
|
||||
"withheld_count": 0,
|
||||
"withheld_by_status": {},
|
||||
"count": 0,
|
||||
"stats": {
|
||||
"total": 0,
|
||||
@@ -2140,6 +2163,8 @@ async def _build_compute_centers_geojson(
|
||||
"type": "FeatureCollection",
|
||||
"features": sanitized_features,
|
||||
"unresolved": unresolved,
|
||||
"withheld_count": int(geojson.get("withheld_count") or 0),
|
||||
"withheld_by_status": geojson.get("withheld_by_status") or {},
|
||||
"count": len(sanitized_features),
|
||||
"stats": {
|
||||
"total": len(sanitized_features),
|
||||
@@ -2188,6 +2213,8 @@ class SaveComputeCenterLocationRequest(BaseModel):
|
||||
raw_payload: Dict[str, Any] = Field(default_factory=dict)
|
||||
needs_confirmation: bool = False
|
||||
verification_status: Optional[str] = None
|
||||
workflow_run_id: Optional[str] = None
|
||||
feedback_rating: Optional[int] = None
|
||||
|
||||
model_config = {"populate_by_name": True}
|
||||
|
||||
@@ -2202,7 +2229,11 @@ async def _compute_center_location_web_search_capability(db: AsyncSession) -> Di
|
||||
"reason": f"WebSearch 配置读取失败:{exc}",
|
||||
}
|
||||
provider_config = config.active_provider_config
|
||||
has_api_key = bool((provider_config.api_key or "").strip()) or not provider_config.api_key_env
|
||||
provider_name = normalize_web_search_provider(provider_config.provider)
|
||||
has_api_key = (
|
||||
provider_name == "searxng"
|
||||
or bool((provider_config.api_key or "").strip())
|
||||
)
|
||||
if not config.enabled:
|
||||
return {
|
||||
"enabled": False,
|
||||
@@ -2230,9 +2261,6 @@ async def get_compute_center_location_capability(
|
||||
return await _compute_center_location_web_search_capability(db)
|
||||
|
||||
|
||||
_TERMINAL_UNLOCATABLE_STATUSES = frozenset({"undisclosed", "multi_site", "anonymous"})
|
||||
|
||||
|
||||
@router.post("/compute-centers/{source_id}/collect-location")
|
||||
async def collect_compute_center_location(
|
||||
source_id: str,
|
||||
@@ -2240,155 +2268,78 @@ async def collect_compute_center_location(
|
||||
_admin: User = Depends(require_admin_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Run deterministic facility lookups, Wikidata/PeeringDB, and controlled Tool-Calling location resolution."""
|
||||
"""Run the unified `location.resolve_unknown` DAG workflow to locate a compute facility."""
|
||||
if not source_id or not source_id.strip():
|
||||
raise HTTPException(status_code=400, detail="source_id is required")
|
||||
|
||||
record = await _load_compute_center_record(db, source_id)
|
||||
name = payload.name or (record.name if record else None)
|
||||
metadata = (record.extra_data or {}) if record else {}
|
||||
|
||||
operator = payload.operator or metadata.get("operator") or metadata.get("organization") or metadata.get("owner")
|
||||
site = payload.site or metadata.get("site")
|
||||
organization = payload.organization or metadata.get("organization")
|
||||
city = payload.city or get_record_field(record, "city") if record else payload.city
|
||||
city = payload.city or (get_record_field(record, "city") if record else None)
|
||||
country = payload.country or (get_record_field(record, "country") if record else None)
|
||||
source = payload.source or (record.source if record else None)
|
||||
record_id = payload.record_id or (record.id if record else None)
|
||||
raw_sources = metadata.get("sources") if isinstance(metadata.get("sources"), list) else []
|
||||
raw_sources = list(metadata.get("sources") if isinstance(metadata.get("sources"), list) else [])
|
||||
source_url = metadata.get("source_url") or metadata.get("detail_url")
|
||||
builds_upon = metadata.get("builds_upon")
|
||||
source_raw_country = metadata.get("raw_country")
|
||||
|
||||
if not payload.force and source and source_id:
|
||||
cached = get_compute_center_location_dict(source, source_id)
|
||||
cached_status = str(cached.get("verification_status") or "").strip().lower()
|
||||
if cached_status in _TERMINAL_UNLOCATABLE_STATUSES:
|
||||
return {
|
||||
"source_id": source_id,
|
||||
"record_id": record_id,
|
||||
"name": name,
|
||||
"success": False,
|
||||
"terminal_status": cached_status,
|
||||
"failure_reason": cached.get("source_note") or f"Marked as {cached_status}",
|
||||
"candidates": [],
|
||||
"attempted_queries": [],
|
||||
"llm_failure_reason": None,
|
||||
"context": {
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"city": city,
|
||||
"country": country,
|
||||
},
|
||||
}
|
||||
earth_ctx = {
|
||||
"entity_type": "compute_center",
|
||||
"source_id": source_id,
|
||||
"record_id": record_id,
|
||||
"source": source,
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"organization": organization,
|
||||
"city": city,
|
||||
"country": country,
|
||||
"sources": raw_sources,
|
||||
"source_url": source_url,
|
||||
"builds_upon": builds_upon,
|
||||
"source_raw_country": source_raw_country,
|
||||
"force": bool(payload.force),
|
||||
}
|
||||
|
||||
candidates, attempted_queries = await asyncio.to_thread(
|
||||
collect_location_candidates,
|
||||
name=name,
|
||||
source=source,
|
||||
source_id=source_id,
|
||||
operator=operator,
|
||||
site=site,
|
||||
organization=organization,
|
||||
city=city,
|
||||
country=country,
|
||||
record_id=record_id,
|
||||
sources=raw_sources,
|
||||
source_url=source_url,
|
||||
builds_upon=builds_upon,
|
||||
source_raw_country=source_raw_country,
|
||||
res = await run_location_workflow(
|
||||
db=db,
|
||||
entity_type="compute_center",
|
||||
earth_context=earth_ctx,
|
||||
targets=[{"entity_type": "compute_center", "entity_id": source_id, "label": name or source_id}],
|
||||
record_run=True,
|
||||
trigger_evolution=True,
|
||||
)
|
||||
llm_failure_reason = None
|
||||
terminal_status: str | None = None
|
||||
query = build_compute_center_location_query(
|
||||
name=name,
|
||||
source=source,
|
||||
source_id=source_id,
|
||||
operator=operator,
|
||||
site=site,
|
||||
organization=organization,
|
||||
city=city,
|
||||
country=country,
|
||||
sources=raw_sources,
|
||||
source_url=source_url,
|
||||
builds_upon=builds_upon,
|
||||
source_raw_country=source_raw_country,
|
||||
)
|
||||
if not candidates:
|
||||
l1_candidates, l1_queries, _allow_low_short_circuit = await run_l1_structured_facility_resolvers(
|
||||
query, db=db
|
||||
)
|
||||
if l1_candidates:
|
||||
candidates = l1_candidates
|
||||
attempted_queries = [*attempted_queries, *l1_queries]
|
||||
|
||||
if not candidates:
|
||||
capability = await _compute_center_location_web_search_capability(db)
|
||||
llm_result = None
|
||||
if not capability.get("enabled") and not raw_sources and not source_url:
|
||||
llm_failure_reason = str(capability.get("reason") or "WebSearch unavailable")
|
||||
else:
|
||||
try:
|
||||
provider_client = await get_ai_provider_client(db)
|
||||
web_search_client = await get_web_search_client(db)
|
||||
if hasattr(provider_client, "analyze"):
|
||||
llm_result, terminal_status = await run_controlled_location_agent(
|
||||
provider_client=provider_client,
|
||||
web_search_client=web_search_client,
|
||||
query=query,
|
||||
entity_type="compute_center",
|
||||
db=db,
|
||||
attempted_queries=[],
|
||||
)
|
||||
else:
|
||||
search_result = await collect_location_search_evidence(
|
||||
web_search_client=web_search_client,
|
||||
query=query,
|
||||
entity_type="compute_center",
|
||||
)
|
||||
attempted_queries = [*attempted_queries, *search_result.attempted_queries]
|
||||
if not search_result.evidence:
|
||||
llm_failure_reason = search_result.failure_reason
|
||||
raise RuntimeError(search_result.failure_reason or "no WebSearch evidence")
|
||||
llm_result = await collect_llm_location_fallback_candidate(
|
||||
provider_client=provider_client,
|
||||
query=query,
|
||||
entity_type="compute_center",
|
||||
db=db,
|
||||
attempted_queries=attempted_queries,
|
||||
search_evidence=search_result.evidence,
|
||||
)
|
||||
except Exception as exc:
|
||||
if llm_failure_reason is None:
|
||||
llm_failure_reason = f"LLM location factcheck unavailable: {exc}"
|
||||
attempted_queries = [
|
||||
*attempted_queries,
|
||||
f"llm_factcheck:compute_center:{name or source_id or 'unknown'}",
|
||||
]
|
||||
if llm_result is not None:
|
||||
attempted_queries = [*attempted_queries, *llm_result.attempted_queries]
|
||||
candidates = llm_result.candidates
|
||||
llm_failure_reason = llm_result.failure_reason
|
||||
candidates = res.get("candidates") or []
|
||||
terminal_status = res.get("terminal_status")
|
||||
failure_reason = res.get("failure_reason")
|
||||
attempted_queries = list(res.get("attempted_queries") or [])
|
||||
workflow_run_id = res.get("workflow_run_id")
|
||||
context = {
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"city": city,
|
||||
"country": country,
|
||||
}
|
||||
|
||||
if terminal_status in _TERMINAL_UNLOCATABLE_STATUSES:
|
||||
if terminal_status in TERMINAL_UNLOCATABLE_STATUSES:
|
||||
return {
|
||||
"source_id": source_id,
|
||||
"record_id": record_id,
|
||||
"name": name,
|
||||
"success": False,
|
||||
"terminal_status": terminal_status,
|
||||
"failure_reason": llm_failure_reason or f"Marked as {terminal_status}",
|
||||
"failure_reason": failure_reason or f"Marked as {terminal_status}",
|
||||
"candidates": [],
|
||||
"attempted_queries": list(attempted_queries),
|
||||
"llm_failure_reason": llm_failure_reason,
|
||||
"context": {
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"city": city,
|
||||
"country": country,
|
||||
},
|
||||
"attempted_queries": attempted_queries,
|
||||
"llm_failure_reason": failure_reason,
|
||||
"workflow_run_id": workflow_run_id,
|
||||
"context": context,
|
||||
}
|
||||
|
||||
if not candidates:
|
||||
@@ -2400,8 +2351,9 @@ async def collect_compute_center_location(
|
||||
"record_id": record_id,
|
||||
"name": name,
|
||||
"success": False,
|
||||
"llm_failure_reason": llm_failure_reason,
|
||||
"attempted_queries": list(attempted_queries),
|
||||
"llm_failure_reason": failure_reason,
|
||||
"attempted_queries": attempted_queries,
|
||||
"workflow_run_id": workflow_run_id,
|
||||
"context": {
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
@@ -2420,15 +2372,10 @@ async def collect_compute_center_location(
|
||||
" result reached city-level precision."
|
||||
),
|
||||
"candidates": [],
|
||||
"attempted_queries": list(attempted_queries),
|
||||
"llm_failure_reason": llm_failure_reason,
|
||||
"context": {
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"city": city,
|
||||
"country": country,
|
||||
},
|
||||
"attempted_queries": attempted_queries,
|
||||
"llm_failure_reason": failure_reason,
|
||||
"workflow_run_id": workflow_run_id,
|
||||
"context": context,
|
||||
}
|
||||
|
||||
best_candidate = candidates[0].to_dict()
|
||||
@@ -2442,8 +2389,9 @@ async def collect_compute_center_location(
|
||||
"success": True,
|
||||
"candidate_count": len(candidates),
|
||||
"best_candidate": best_candidate,
|
||||
"llm_failure_reason": llm_failure_reason,
|
||||
"attempted_queries": list(attempted_queries),
|
||||
"llm_failure_reason": failure_reason,
|
||||
"attempted_queries": attempted_queries,
|
||||
"workflow_run_id": workflow_run_id,
|
||||
"context": {
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
@@ -2459,14 +2407,9 @@ async def collect_compute_center_location(
|
||||
"success": True,
|
||||
"candidates": [candidate.to_dict() for candidate in candidates],
|
||||
"best_candidate": best_candidate,
|
||||
"attempted_queries": list(attempted_queries),
|
||||
"context": {
|
||||
"name": name,
|
||||
"operator": operator,
|
||||
"site": site,
|
||||
"city": city,
|
||||
"country": country,
|
||||
},
|
||||
"attempted_queries": attempted_queries,
|
||||
"workflow_run_id": workflow_run_id,
|
||||
"context": context,
|
||||
}
|
||||
|
||||
|
||||
@@ -2521,6 +2464,21 @@ async def save_compute_center_location(
|
||||
or ("unverified" if payload.needs_confirmation else "verified"),
|
||||
)
|
||||
|
||||
if payload.workflow_run_id:
|
||||
try:
|
||||
from app.services.ai.workflow_evolver import record_run_feedback
|
||||
|
||||
rating = payload.feedback_rating if payload.feedback_rating in (-1, 0, 1) else 1
|
||||
await record_run_feedback(
|
||||
db,
|
||||
payload.workflow_run_id,
|
||||
rating=rating,
|
||||
note=f"Adopted compute-center location for {source_id}",
|
||||
actor=f"admin:{getattr(_admin, 'username', 'admin')}",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"source": saved.source,
|
||||
|
||||
Reference in new issue
Block a user