Files
nanobot/nanobot/webui/client_contract.py
T
Xubin Renandchengyongru fbb61a373f feat(update): integrate managed installs and recoverable in-app updates (#6168)
Add owner-aware Stable and Preview updates with explicit consent, verified release plans, protected process handoff and bounded service recovery. Keep configuration and conversations separate from program rollback.

Include the compact About controls, Windows long-path support, native package recovery checks and optional macOS Dock lifecycle integration. Preserve documented guidance for installations owned by other managers.

This code integration does not publish packages, enable signing or advance the public update channel.

Co-authored-by: chengyongru <61816729+chengyongru@users.noreply.github.com>
2026-10-21 19:16:56 +08:00

92 lines
3.7 KiB
Python

"""The contract between a shipped WebUI and an independently updated gateway.
Package versions are display metadata, not compatibility decisions. Adding an
optional capability must not raise the protocol floor for unrelated features.
See .agent/review-guide.md before changing this contract.
"""
from __future__ import annotations
from typing import Literal, TypedDict, cast
from nanobot import __version__
WEBUI_PROTOCOL = 1
CORE_CAPABILITY = "webui.core.v1"
SUBAGENT_CAPABILITY = "webui.subagents.v1"
SUBAGENT_EVENTS_CAPABILITY = "webui.subagents.events.v1"
SUBAGENT_HISTORY_CAPABILITY = "webui.subagents.history.v1"
AUTOMATION_CHAT_CAPABILITY = "webui.automation-chat.v1"
BINARY_ATTACHMENTS_CAPABILITY = "webui.attachments.binary.v1"
UPDATE_PLAN_CAPABILITY = "webui.update-plans.v1"
UPDATE_JOB_CAPABILITY = "webui.update-jobs.read.v1"
UPDATE_PREPARATION_CAPABILITY = "webui.update-jobs.prepare.v1"
UPDATE_EXECUTION_CAPABILITY = "webui.update-jobs.execute.v1"
UPDATE_RETRY_CAPABILITY = "webui.update-jobs.retry-handoff.v1"
UPDATE_SETTLE_HANDOFF_CAPABILITY = "webui.update-jobs.settle-handoff.v1"
UPDATE_FLOW_CAPABILITY = "webui.update-flow.v1"
UPDATE_CHANNEL_CAPABILITY = "webui.update-channels.v1"
PROMPT_NAVIGATION_CAPABILITY = "webui.prompt-navigation.v1"
class Compatibility(TypedDict):
status: Literal["compatible", "unknown", "update_host", "update_client"]
client_version: str
host_version: str
def webui_contract() -> dict[str, object]:
return {
"version": __version__,
"min_protocol": WEBUI_PROTOCOL,
"max_protocol": WEBUI_PROTOCOL,
"capabilities": [
CORE_CAPABILITY, SUBAGENT_CAPABILITY, SUBAGENT_EVENTS_CAPABILITY,
SUBAGENT_HISTORY_CAPABILITY, AUTOMATION_CHAT_CAPABILITY,
BINARY_ATTACHMENTS_CAPABILITY, UPDATE_PLAN_CAPABILITY,
UPDATE_JOB_CAPABILITY, UPDATE_PREPARATION_CAPABILITY, UPDATE_EXECUTION_CAPABILITY,
UPDATE_RETRY_CAPABILITY, UPDATE_SETTLE_HANDOFF_CAPABILITY, UPDATE_FLOW_CAPABILITY, UPDATE_CHANNEL_CAPABILITY,
PROMPT_NAVIGATION_CAPABILITY,
],
}
def gateway_identity(gateway_id: str) -> dict[str, object]:
# protocolVersion belongs to the pre-existing terminal transport contract.
# Do not overload it with the version of the independently shipped WebUI.
return {"protocolVersion": 1, "gatewayId": gateway_id, "webui": webui_contract()}
def assess_webui_contract(value: object) -> Compatibility:
result: Compatibility = {
"status": "unknown", "client_version": __version__, "host_version": "",
}
if not isinstance(value, dict):
return result
# Only the mapping shape is established here; validate each value below.
data = cast(dict[object, object], value)
version = data.get("version")
if isinstance(version, str) and len(version) <= 80 and version.isprintable():
result["host_version"] = version
minimum, maximum = data.get("min_protocol"), data.get("max_protocol")
capabilities = data.get("capabilities")
if (type(minimum) is not int or type(maximum) is not int
or not 1 <= minimum <= maximum
or not isinstance(capabilities, list)
or not all(isinstance(item, str) for item in cast(list[object], capabilities))):
return result
if minimum > WEBUI_PROTOCOL:
result["status"] = "update_client"
elif maximum < WEBUI_PROTOCOL or CORE_CAPABILITY not in capabilities:
result["status"] = "update_host"
else:
result["status"] = "compatible"
return result
def compatibility_error(report: Compatibility) -> str:
return {
"compatible": "", "unknown": "webui_compatibility_unknown",
"update_host": "host_update_required", "update_client": "client_update_required",
}[report["status"]]