fix(packaging): keep source clients in lockstep
This commit is contained in:
@@ -120,15 +120,20 @@ def _resolve_tui_command() -> list[str]:
|
||||
"on that platform; use the classic prompt until the upstream runtime supports it"
|
||||
)
|
||||
asset = f"nanobot-tui-{system}-{machine}{suffix}"
|
||||
source_dir = _source_checkout_tui_dir()
|
||||
if source_dir is not None:
|
||||
bun = shutil.which("bun")
|
||||
if not bun:
|
||||
raise TuiUnavailableError(
|
||||
"this source checkout requires Bun to run its matching TUI; "
|
||||
"install Bun, then run `nanobot agent` again"
|
||||
)
|
||||
return _resolve_source_tui_command(source_dir, bun)
|
||||
|
||||
packaged = Path(__file__).resolve().parents[1] / "tui" / "bin" / asset
|
||||
if packaged.is_file():
|
||||
return [str(packaged)]
|
||||
|
||||
source_dir = Path(__file__).resolve().parents[2] / "tui"
|
||||
bun = shutil.which("bun")
|
||||
if bun and (source_dir / "package.json").is_file():
|
||||
return _resolve_source_tui_command(source_dir, bun)
|
||||
|
||||
downloaded = _download_release_tui(asset)
|
||||
if downloaded is not None:
|
||||
return [str(downloaded)]
|
||||
@@ -139,6 +144,15 @@ def _resolve_tui_command() -> list[str]:
|
||||
)
|
||||
|
||||
|
||||
def _source_checkout_tui_dir() -> Path | None:
|
||||
"""Return this checkout's TUI source, never a neighboring unrelated directory."""
|
||||
project_root = Path(__file__).resolve().parents[2]
|
||||
source_dir = project_root / "tui"
|
||||
if (project_root / "pyproject.toml").is_file() and (source_dir / "package.json").is_file():
|
||||
return source_dir
|
||||
return None
|
||||
|
||||
|
||||
def _resolve_source_tui_command(source_dir: Path, bun: str) -> list[str]:
|
||||
dependency = source_dir / "node_modules" / "@opentui" / "core"
|
||||
try:
|
||||
|
||||
@@ -218,6 +218,10 @@ def webui(
|
||||
)
|
||||
|
||||
webui_bundle_mode = _webui_build_mode_for_interactive(yes=yes)
|
||||
_prepare_webui_bundle_for_gateway(
|
||||
runtime_config,
|
||||
mode="skip" if dev else webui_bundle_mode,
|
||||
)
|
||||
|
||||
config_arg = str(config_path)
|
||||
workspace_arg = str(Path(workspace).expanduser().resolve(strict=False)) if workspace else None
|
||||
@@ -236,10 +240,6 @@ def webui(
|
||||
|
||||
def ensure_shared_gateway(*, client_lease: GatewayClientLease) -> None:
|
||||
"""Start or refresh the one managed gateway shared by local clients."""
|
||||
_prepare_webui_bundle_for_gateway(
|
||||
runtime_config,
|
||||
mode="skip" if dev else webui_bundle_mode,
|
||||
)
|
||||
result = client_lease.ensure_on_demand_gateway(start_options)
|
||||
restarted = False
|
||||
restart_attempted = False
|
||||
|
||||
@@ -24,6 +24,7 @@ from nanobot.webui.build import (
|
||||
BuildMode,
|
||||
WebUIBuildError,
|
||||
ensure_webui_bundle,
|
||||
inspect_webui_bundle,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -191,6 +192,11 @@ def _prepare_webui_bundle_for_gateway(
|
||||
return typer.confirm(message, default=True)
|
||||
|
||||
try:
|
||||
# A source checkout is the development product. Every gateway entrypoint
|
||||
# keeps its browser client in lockstep with Python; only Vite mode skips
|
||||
# the production bundle intentionally.
|
||||
if mode != "skip" and inspect_webui_bundle().source_available:
|
||||
mode = "auto"
|
||||
ensure_webui_bundle(
|
||||
mode=mode,
|
||||
confirm=_confirm if mode == "prompt" else None,
|
||||
|
||||
Reference in New Issue
Block a user