Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions src/praisonai/praisonai/cli/commands/managed.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,32 @@ def sessions_resume(
print(result)


@sessions_app.command("delete")
def sessions_delete(
session_id: str = typer.Argument(..., help="Session ID to delete (sesn_01...)"),
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
):
"""Delete a session.

Example:
praisonai managed sessions delete sesn_01AbCdEf
praisonai managed sessions delete sesn_01AbCdEf --yes
"""
if not yes:
confirm = typer.confirm(f"Are you sure you want to delete session {session_id}?")
if not confirm:
typer.echo("Deletion cancelled.")
raise typer.Exit(0)

client = _get_client()
try:
client.beta.sessions.delete(session_id)
typer.echo(f"Session {session_id} deleted successfully.")
except Exception as e:
typer.echo(f"Error deleting session: {e}")
raise typer.Exit(1)


# ─────────────────────────────────────────────────────────────────────────────
# agents sub-commands
# ─────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -397,6 +423,32 @@ def agents_update(
typer.echo(f"Updated agent: {updated.id} (v{getattr(updated,'version','')})")


@agents_app.command("delete")
def agents_delete(
agent_id: str = typer.Argument(..., help="Agent ID to delete (agent_01...)"),
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
):
"""Delete an agent.

Example:
praisonai managed agents delete agent_01AbCdEf
praisonai managed agents delete agent_01AbCdEf --yes
"""
if not yes:
confirm = typer.confirm(f"Are you sure you want to delete agent {agent_id}?")
if not confirm:
typer.echo("Deletion cancelled.")
raise typer.Exit(0)

client = _get_client()
try:
client.beta.agents.delete(agent_id)
typer.echo(f"Agent {agent_id} deleted successfully.")
except Exception as e:
typer.echo(f"Error deleting agent: {e}")
raise typer.Exit(1)


# ─────────────────────────────────────────────────────────────────────────────
# envs sub-commands
# ─────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -441,6 +493,72 @@ def envs_get(
typer.echo(f"Config: {cfg}")


@envs_app.command("update")
def envs_update(
env_id: str = typer.Argument(..., help="Environment ID (env_01...)"),
packages: Optional[str] = typer.Option(None, "--packages", "-p", help="Comma-separated pip packages"),
networking: Optional[str] = typer.Option(None, "--networking", help="Networking type: 'full' or 'limited'"),
):
"""Update an environment's configuration.

Example:
praisonai managed envs update env_01AbCdEf --packages "numpy,pandas"
praisonai managed envs update env_01AbCdEf --networking limited
"""
client = _get_client()
kwargs = {}

if packages:
pkg_list = [p.strip() for p in packages.split(",") if p.strip()]
if not pkg_list:
typer.echo("Error: --packages must include at least one package name")
raise typer.Exit(1)
kwargs["packages"] = {"pip": pkg_list}
Comment on lines +508 to +516
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_client() is called before validating flags / checking the no-op case. As a result, praisonai managed envs update <id> (with no options) or with an invalid --networking value will still require the anthropic package + API key, even though the command exits without making an API call. Move client creation to just before client.beta.environments.update(...), after validation and the if not kwargs early-exit.

Copilot uses AI. Check for mistakes.

if networking:
if networking not in ["full", "limited"]:
typer.echo("Error: --networking must be 'full' or 'limited'")
raise typer.Exit(1)
kwargs["networking"] = {"type": networking}
Comment on lines +519 to +522
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The networking validation is currently case-sensitive. Converting the input to lowercase before validation and usage makes the CLI more robust and user-friendly (e.g., allowing --networking Full).

Suggested change
if networking not in ["full", "limited"]:
typer.echo("Error: --networking must be 'full' or 'limited'")
raise typer.Exit(1)
kwargs["networking"] = {"type": networking}
if networking.lower() not in ["full", "limited"]:
typer.echo("Error: --networking must be 'full' or 'limited'")
raise typer.Exit(1)
kwargs["networking"] = {"type": networking.lower()}


if not kwargs:
typer.echo("Nothing to update. Pass --packages or --networking.")
raise typer.Exit(0)

try:
updated = client.beta.environments.update(env_id, **kwargs)
typer.echo(f"Updated environment: {updated.id}")
except Exception as e:
typer.echo(f"Error updating environment: {e}")
raise typer.Exit(1)


@envs_app.command("delete")
def envs_delete(
env_id: str = typer.Argument(..., help="Environment ID to delete (env_01...)"),
yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation prompt"),
):
"""Delete an environment.

Example:
praisonai managed envs delete env_01AbCdEf
praisonai managed envs delete env_01AbCdEf --yes
"""
if not yes:
confirm = typer.confirm(f"Are you sure you want to delete environment {env_id}?")
if not confirm:
typer.echo("Deletion cancelled.")
raise typer.Exit(0)

client = _get_client()
try:
client.beta.environments.delete(env_id)
typer.echo(f"Environment {env_id} deleted successfully.")
except Exception as e:
typer.echo(f"Error deleting environment: {e}")
raise typer.Exit(1)


# ─────────────────────────────────────────────────────────────────────────────
# ids sub-commands (save / restore / show — no Anthropic IDs are user-defined)
# ─────────────────────────────────────────────────────────────────────────────
Expand Down
Loading