|
1 | 1 | """ |
2 | 2 | Obs command group for PraisonAI CLI. |
3 | 3 |
|
4 | | -Provides observability diagnostics and management. |
| 4 | +Thin wrapper that re-exports the CLI from praisonai_tools. |
5 | 5 | """ |
6 | 6 |
|
7 | | -from typing import Optional |
| 7 | +try: |
| 8 | + from praisonai_tools.observability.cli import app |
| 9 | +except ImportError: |
| 10 | + import typer |
| 11 | + app = typer.Typer(help="Observability diagnostics and management") |
8 | 12 |
|
9 | | -import typer |
10 | | - |
11 | | - |
12 | | -app = typer.Typer(help="Observability diagnostics and management") |
13 | | - |
14 | | - |
15 | | -@app.command("doctor") |
16 | | -def obs_doctor( |
17 | | - json_output: bool = typer.Option(False, "--json", help="Output as JSON"), |
18 | | -): |
19 | | - """ |
20 | | - Run observability health checks. |
21 | | -
|
22 | | - Checks provider status, connection, and available providers. |
23 | | -
|
24 | | - Examples: |
25 | | - praisonai obs doctor |
26 | | - praisonai obs doctor --json |
27 | | - """ |
28 | | - try: |
29 | | - from praisonai_tools.observability import obs |
30 | | - except ImportError: |
| 13 | + @app.callback(invoke_without_command=True) |
| 14 | + def obs_fallback(ctx: typer.Context): |
| 15 | + """Observability diagnostics and management.""" |
31 | 16 | from rich.console import Console |
32 | | - console = Console(stderr=True) |
33 | | - console.print("[red]✗ praisonai-tools not installed.[/red]") |
34 | | - console.print("[dim]Install with: pip install praisonai-tools[/dim]") |
| 17 | + Console(stderr=True).print("[red]✗ praisonai-tools not installed.[/red]") |
| 18 | + Console(stderr=True).print("[dim]Install with: pip install praisonai-tools[/dim]") |
35 | 19 | raise typer.Exit(1) |
36 | | - |
37 | | - results = obs.doctor() |
38 | | - |
39 | | - if json_output: |
40 | | - import json |
41 | | - typer.echo(json.dumps(results, indent=2, default=str)) |
42 | | - raise typer.Exit(0) |
43 | | - |
44 | | - # Pretty-print with Rich |
45 | | - from rich.console import Console |
46 | | - from rich.table import Table |
47 | | - |
48 | | - console = Console() |
49 | | - console.print("\n[bold cyan]🔍 PraisonAI Observability Doctor[/bold cyan]\n") |
50 | | - |
51 | | - table = Table(show_header=True, header_style="bold") |
52 | | - table.add_column("Check", style="dim", min_width=20) |
53 | | - table.add_column("Result") |
54 | | - |
55 | | - # Enabled |
56 | | - enabled = results.get("enabled", False) |
57 | | - table.add_row( |
58 | | - "Enabled", |
59 | | - "[green]✓ Yes[/green]" if enabled else "[yellow]✗ No[/yellow]", |
60 | | - ) |
61 | | - |
62 | | - # Provider |
63 | | - provider = results.get("provider") |
64 | | - table.add_row( |
65 | | - "Active Provider", |
66 | | - f"[green]{provider}[/green]" if provider else "[dim]None[/dim]", |
67 | | - ) |
68 | | - |
69 | | - # Connection |
70 | | - conn_status = results.get("connection_status") |
71 | | - conn_msg = results.get("connection_message", "") |
72 | | - if conn_status is True: |
73 | | - table.add_row("Connection", f"[green]✓ {conn_msg}[/green]") |
74 | | - elif conn_status is False: |
75 | | - table.add_row("Connection", f"[red]✗ {conn_msg}[/red]") |
76 | | - else: |
77 | | - table.add_row("Connection", "[dim]N/A[/dim]") |
78 | | - |
79 | | - # Available providers |
80 | | - available = results.get("available_providers", []) |
81 | | - table.add_row( |
82 | | - "Available Providers", |
83 | | - ", ".join(available) if available else "[dim]None[/dim]", |
84 | | - ) |
85 | | - |
86 | | - # Registered providers |
87 | | - registered = results.get("registered_providers", []) |
88 | | - table.add_row( |
89 | | - "Registered Providers", |
90 | | - ", ".join(registered) if registered else "[dim]None[/dim]", |
91 | | - ) |
92 | | - |
93 | | - console.print(table) |
94 | | - console.print() |
95 | | - |
96 | | - raise typer.Exit(0) |
97 | | - |
98 | | - |
99 | | -@app.callback(invoke_without_command=True) |
100 | | -def obs_callback(ctx: typer.Context): |
101 | | - """Observability diagnostics and management.""" |
102 | | - if ctx.invoked_subcommand is None: |
103 | | - # Default to doctor when no subcommand given |
104 | | - ctx.invoke(obs_doctor) |
0 commit comments