2020 pass
2121
2222import typer
23- from prompt_toolkit import print_formatted_text
24- from prompt_toolkit import PromptSession
23+ from prompt_toolkit import PromptSession , print_formatted_text
24+ from prompt_toolkit . application import run_in_terminal
2525from prompt_toolkit .formatted_text import ANSI , HTML
2626from prompt_toolkit .history import FileHistory
2727from prompt_toolkit .patch_stdout import patch_stdout
28- from prompt_toolkit .application import run_in_terminal
2928from rich .console import Console
3029from rich .markdown import Markdown
3130from rich .table import Table
@@ -216,30 +215,47 @@ def main(
216215
217216
218217@app .command ()
219- def onboard ():
218+ def onboard (interactive : bool = typer . Option ( True , "--interactive/--no-interactive" , help = "Use interactive wizard" ) ):
220219 """Initialize nanobot configuration and workspace."""
221220 from nanobot .config .loader import get_config_path , load_config , save_config
222221 from nanobot .config .schema import Config
223222
224223 config_path = get_config_path ()
225224
226225 if config_path .exists ():
227- console .print (f"[yellow]Config already exists at { config_path } [/yellow]" )
228- console .print (" [bold]y[/bold] = overwrite with defaults (existing values will be lost)" )
229- console .print (" [bold]N[/bold] = refresh config, keeping existing values and adding new fields" )
230- if typer .confirm ("Overwrite?" ):
231- config = Config ()
232- save_config (config )
233- console .print (f"[green]✓[/green] Config reset to defaults at { config_path } " )
234- else :
226+ if interactive :
235227 config = load_config ()
236- save_config (config )
237- console .print (f"[green]✓[/green] Config refreshed at { config_path } (existing values preserved)" )
228+ else :
229+ console .print (f"[yellow]Config already exists at { config_path } [/yellow]" )
230+ console .print (" [bold]y[/bold] = overwrite with defaults (existing values will be lost)" )
231+ console .print (" [bold]N[/bold] = refresh config, keeping existing values and adding new fields" )
232+ if typer .confirm ("Overwrite?" ):
233+ config = Config ()
234+ save_config (config )
235+ console .print (f"[green]✓[/green] Config reset to defaults at { config_path } " )
236+ else :
237+ config = load_config ()
238+ save_config (config )
239+ console .print (f"[green]✓[/green] Config refreshed at { config_path } (existing values preserved)" )
238240 else :
239- save_config (Config ())
241+ config = Config ()
242+ save_config (config )
240243 console .print (f"[green]✓[/green] Created config at { config_path } " )
241244
242- console .print ("[dim]Config template now uses `maxTokens` + `contextWindowTokens`; `memoryWindow` is no longer a runtime setting.[/dim]" )
245+ # Run interactive wizard if enabled
246+ if interactive :
247+ from nanobot .cli .onboard_wizard import run_onboard
248+
249+ try :
250+ config = run_onboard ()
251+ save_config (config )
252+ console .print (f"[green]✓[/green] Config saved at { config_path } " )
253+ except Exception as e :
254+ console .print (f"[red]✗[/red] Error during configuration: { e } " )
255+ console .print ("[yellow]Please run 'nanobot onboard' again to complete setup.[/yellow]" )
256+ raise typer .Exit (1 )
257+ else :
258+ console .print ("[dim]Config template now uses `maxTokens` + `contextWindowTokens`; `memoryWindow` is no longer a runtime setting.[/dim]" )
243259
244260 _onboard_plugins (config_path )
245261
@@ -254,9 +270,8 @@ def onboard():
254270
255271 console .print (f"\n { __logo__ } nanobot is ready!" )
256272 console .print ("\n Next steps:" )
257- console .print (" 1. Add your API key to [cyan]~/.nanobot/config.json[/cyan]" )
258- console .print (" Get one at: https://openrouter.ai/keys" )
259- console .print (" 2. Chat: [cyan]nanobot agent -m \" Hello!\" [/cyan]" )
273+ console .print (" 1. Chat: [cyan]nanobot agent -m \" Hello!\" [/cyan]" )
274+ console .print (" 2. Start gateway: [cyan]nanobot gateway[/cyan]" )
260275 console .print ("\n [dim]Want Telegram/WhatsApp? See: https://github.com/HKUDS/nanobot#-chat-apps[/dim]" )
261276
262277
@@ -300,9 +315,9 @@ def _onboard_plugins(config_path: Path) -> None:
300315
301316def _make_provider (config : Config ):
302317 """Create the appropriate LLM provider from config."""
318+ from nanobot .providers .azure_openai_provider import AzureOpenAIProvider
303319 from nanobot .providers .base import GenerationSettings
304320 from nanobot .providers .openai_codex_provider import OpenAICodexProvider
305- from nanobot .providers .azure_openai_provider import AzureOpenAIProvider
306321
307322 model = config .agents .defaults .model
308323 provider_name = config .get_provider_name (model )
0 commit comments