fix(api): keep unconfigured services running and preserve Docker onboarding

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-19 13:02:26 +08:00
1 parent e20737a509
commit de8fbc3ad2
13 files changed
+133 -63

No files matched your search

+8
View File
@@ -20,6 +20,7 @@ from loguru import logger
from nanobot.agent.hook import AgentHook, AgentRunHookContext
from nanobot.config.paths import get_media_dir
from nanobot.providers.base import LLMUsage
from nanobot.providers.unconfigured_provider import UnconfiguredProvider
from nanobot.utils.helpers import safe_filename
from nanobot.utils.media_decode import (
MAX_FILE_SIZE,
@@ -275,6 +276,13 @@ async def handle_chat_completions(request: web.Request) -> web.Response | web.St
content_type = _as_str(cast(object, request.content_type or ""))
agent_loop = request.app[_AGENT_LOOP_KEY]
if isinstance(agent_loop.provider, UnconfiguredProvider):
return _error_json(
503,
"Model is not configured. Open Settings → Models to configure a provider "
"and model, then restart the API server.",
err_type="configuration_error",
)
timeout_s: float = request.app[_REQUEST_TIMEOUT_KEY]
model_name: str = request.app[_MODEL_NAME_KEY]
+8
View File
@@ -393,9 +393,17 @@ def serve(
tools = ToolRegistry()
register_image_generation_tool(runtime_config, tools, workspace=runtime_config.workspace_path)
mcp_provider = MCPProvider.from_config(runtime_config, tools)
from nanobot.providers.factory import build_unconfigured_provider_snapshot
setup_error = _provider_setup_error(runtime_config)
unconfigured_provider = (
build_unconfigured_provider_snapshot(runtime_config, setup_error).provider
if setup_error else None
)
try:
agent_loop = AgentLoop.from_config(
runtime_config, bus,
provider=unconfigured_provider,
session_manager=session_manager,
hook_factories=[create_file_edit_activity_hook],
tool_registry=tools,
+23 -19
View File
@@ -5,32 +5,36 @@ import secrets
import sys
from pathlib import Path
from filelock import FileLock
from nanobot.channels.websocket.runtime import WebSocketConfig
from nanobot.config.loader import save_config
from nanobot.config.schema import Config
def initialize_config(path: Path) -> None:
if path.exists():
print(f"[entrypoint] existing {path} found — leaving it in place")
print(f"[entrypoint] WebUI password: {path} (channels.websocket.tokenIssueSecret)")
return
path.parent.mkdir(parents=True, exist_ok=True)
with FileLock(path.parent / ".docker-bootstrap.lock"):
if path.exists():
print(f"[entrypoint] existing {path} found — leaving it in place")
print(f"[entrypoint] WebUI password: {path} (channels.websocket.tokenIssueSecret)")
return
web_token = os.environ.get("NANOBOT_WEB_TOKEN") or secrets.token_hex(16)
api_key = os.environ.get("NANOBOT_API_KEY") or secrets.token_hex(16)
websocket = WebSocketConfig(
enabled=True, host="0.0.0.0", token_issue_secret=web_token,
websocket_requires_token=True,
)
config = Config.model_validate({
"gateway": {"host": "0.0.0.0"},
"channels": {"websocket": websocket.model_dump(by_alias=True)},
"api": {"host": "0.0.0.0", "api_key": api_key},
})
save_config(config, path)
print(f"[entrypoint] initialized {path}")
print(f"[entrypoint] WebUI: http://localhost:8765 — password: {web_token}")
print(f"[entrypoint] OpenAI-compatible API key: {api_key}")
web_token = os.environ.get("NANOBOT_WEB_TOKEN") or secrets.token_hex(16)
api_key = os.environ.get("NANOBOT_API_KEY") or secrets.token_hex(16)
websocket = WebSocketConfig(
enabled=True, host="0.0.0.0", token_issue_secret=web_token,
websocket_requires_token=True,
)
config = Config.model_validate({
"gateway": {"host": "0.0.0.0"},
"channels": {"websocket": websocket.model_dump(by_alias=True)},
"api": {"host": "0.0.0.0", "api_key": api_key},
})
save_config(config, path)
print(f"[entrypoint] initialized {path}")
print(f"[entrypoint] WebUI: http://localhost:8765 — password: {web_token}")
print(f"[entrypoint] OpenAI-compatible API key: {api_key}")
if __name__ == "__main__":
+1 -1
View File
@@ -222,7 +222,7 @@ def make_provider(
def build_unconfigured_provider_snapshot(config: Config, setup_error: str) -> ProviderSnapshot:
"""Build a non-networking runtime so the WebUI can collect first-time setup."""
"""Build a non-networking runtime while provider/model setup is incomplete."""
from nanobot.providers.unconfigured_provider import UnconfiguredProvider
preset = config.resolve_preset()
+2 -2
View File
@@ -1,4 +1,4 @@
"""Provider used while the local WebUI is waiting for first-time setup."""
"""Provider used while an application is waiting for model setup."""
from __future__ import annotations
@@ -8,7 +8,7 @@ from nanobot.providers.base import LLMProvider, LLMResponse
class UnconfiguredProvider(LLMProvider):
"""Keep the gateway available for settings before a model is configured."""
"""Keep the runtime available before a model is configured."""
def __init__(self, default_model: str) -> None:
super().__init__(provider_name="unconfigured")