|
| 1 | +"""Implementation of the ``aion init`` command group.""" |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +import getpass |
| 5 | +import sys |
| 6 | +from typing import Optional |
| 7 | + |
| 8 | +import typer |
| 9 | + |
| 10 | +from ..services.quickstart import QuickstartOptions, QuickstartService |
| 11 | + |
| 12 | + |
| 13 | +def _prompt_missing(options: QuickstartOptions) -> QuickstartOptions: |
| 14 | + if options.admin_email is None: |
| 15 | + options.admin_email = typer.prompt("Admin email") |
| 16 | + if options.admin_pass is None: |
| 17 | + options.admin_pass = getpass.getpass("Admin password: ") |
| 18 | + if not options.model: |
| 19 | + options.model = typer.prompt("Default model", default="gpt-4o-mini") |
| 20 | + return options |
| 21 | + |
| 22 | + |
| 23 | +def register(app: typer.Typer) -> None: |
| 24 | + init_app = typer.Typer(help="Bootstrap a new AION OS deployment") |
| 25 | + |
| 26 | + @init_app.callback() |
| 27 | + def init_command( |
| 28 | + ctx: typer.Context, |
| 29 | + quickstart: bool = typer.Option( |
| 30 | + False, "--quickstart", help="Run the guided quickstart workflow." |
| 31 | + ), |
| 32 | + no_browser: bool = typer.Option( |
| 33 | + False, "--no-browser", help="Force headless mode even if a browser exists." |
| 34 | + ), |
| 35 | + admin_email: Optional[str] = typer.Option( |
| 36 | + None, "--admin-email", help="Seed admin email for the console." |
| 37 | + ), |
| 38 | + admin_pass: Optional[str] = typer.Option( |
| 39 | + None, "--admin-pass", help="Seed admin password for the console." |
| 40 | + ), |
| 41 | + provider: str = typer.Option( |
| 42 | + "local", "--provider", help="Default provider to configure (local|api|hybrid)." |
| 43 | + ), |
| 44 | + api_key: Optional[str] = typer.Option( |
| 45 | + None, "--api-key", help="API key when provider requires one." |
| 46 | + ), |
| 47 | + model: Optional[str] = typer.Option( |
| 48 | + None, "--model", help="Default model identifier to set up." |
| 49 | + ), |
| 50 | + port: int = typer.Option(3000, "--port", help="Port to bind the console to."), |
| 51 | + ) -> None: |
| 52 | + if not quickstart: |
| 53 | + typer.echo("Use --quickstart to launch the guided bootstrap workflow.") |
| 54 | + raise typer.Exit(code=1) |
| 55 | + |
| 56 | + options = QuickstartOptions( |
| 57 | + quickstart=quickstart, |
| 58 | + no_browser=no_browser, |
| 59 | + admin_email=admin_email, |
| 60 | + admin_pass=admin_pass, |
| 61 | + provider=provider, |
| 62 | + api_key=api_key, |
| 63 | + model=model, |
| 64 | + port=port, |
| 65 | + extra_args=list(ctx.args), |
| 66 | + ) |
| 67 | + if options.no_browser or not sys.stdin.isatty(): # type: ignore[attr-defined] |
| 68 | + options = _prompt_missing(options) |
| 69 | + |
| 70 | + service = QuickstartService() |
| 71 | + result = service.run(options=options) |
| 72 | + typer.secho("Quickstart completed", fg=typer.colors.GREEN) |
| 73 | + for key, value in result.items(): |
| 74 | + typer.echo(f"{key}: {value}") |
| 75 | + |
| 76 | + app.add_typer(init_app, name="init") |
| 77 | + |
| 78 | + |
| 79 | +__all__ = ["register"] |
0 commit comments