Files
nanobot/nanobot/webui/client_contract.py
T
chengyongru 0f45d74fec feat(webui): add session-scoped reasoning effort (#6441)
* feat(webui): add session-scoped model options

Extend the composer preset menu with inherited reasoning effort and Codex Fast mode overrides. Persist choices with ordinary inputs, isolate captured runtimes, and restore browser preferences without changing shared presets.

Add regression coverage for pending preset ordering, settings initialization, session and host isolation, queue edits, Codex request mapping, and narrow-screen controls.

* feat(webui): refine session model options and add Codex Ultrafast

Fit the composer options into a compact single row and preview reasoning effort only during a drag. Add Fast/Ultrafast controls for eligible Codex models, preserve explicit session choices across reloads, and document the speed tiers.

* fix(webui): add Codex speed control to the component gallery

* fix(webui): preserve saved model options after preset rename

Use the session options for display when a browser preference no longer matches the preset. Omit model options from the next message unless the browser has a matching choice, so stale preferences cannot overwrite options the gateway already saved.
2026-11-18 15:46:16 +08:00

96 lines
4.0 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"
CONTEXT_GRAPH_REFERENCES_CAPABILITY = "webui.context-graph.references.v1"
PROMPT_NAVIGATION_CAPABILITY = "webui.prompt-navigation.v1"
SANDBOX_SETTINGS_CAPABILITY = "webui.sandbox-settings.v1"
MODEL_PRESET_SAVE_CAPABILITY = "webui.model-preset-save.v1"
MODEL_OPTIONS_CAPABILITY = "webui.model-options.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, CONTEXT_GRAPH_REFERENCES_CAPABILITY,
SANDBOX_SETTINGS_CAPABILITY, MODEL_PRESET_SAVE_CAPABILITY, MODEL_OPTIONS_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
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"]]