meshagent-cli 0.22.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of meshagent-cli might be problematic. Click here for more details.

Files changed (45) hide show
  1. meshagent/cli/__init__.py +3 -0
  2. meshagent/cli/agent.py +273 -0
  3. meshagent/cli/api_keys.py +102 -0
  4. meshagent/cli/async_typer.py +79 -0
  5. meshagent/cli/auth.py +30 -0
  6. meshagent/cli/auth_async.py +295 -0
  7. meshagent/cli/call.py +215 -0
  8. meshagent/cli/chatbot.py +1983 -0
  9. meshagent/cli/cli.py +187 -0
  10. meshagent/cli/cli_mcp.py +408 -0
  11. meshagent/cli/cli_secrets.py +414 -0
  12. meshagent/cli/common_options.py +47 -0
  13. meshagent/cli/containers.py +725 -0
  14. meshagent/cli/database.py +997 -0
  15. meshagent/cli/developer.py +70 -0
  16. meshagent/cli/exec.py +397 -0
  17. meshagent/cli/helper.py +236 -0
  18. meshagent/cli/helpers.py +185 -0
  19. meshagent/cli/host.py +41 -0
  20. meshagent/cli/mailbot.py +1295 -0
  21. meshagent/cli/mailboxes.py +223 -0
  22. meshagent/cli/meeting_transcriber.py +138 -0
  23. meshagent/cli/messaging.py +157 -0
  24. meshagent/cli/multi.py +357 -0
  25. meshagent/cli/oauth2.py +341 -0
  26. meshagent/cli/participant_token.py +63 -0
  27. meshagent/cli/port.py +70 -0
  28. meshagent/cli/projects.py +105 -0
  29. meshagent/cli/queue.py +91 -0
  30. meshagent/cli/room.py +26 -0
  31. meshagent/cli/rooms.py +214 -0
  32. meshagent/cli/services.py +722 -0
  33. meshagent/cli/sessions.py +26 -0
  34. meshagent/cli/storage.py +813 -0
  35. meshagent/cli/sync.py +434 -0
  36. meshagent/cli/task_runner.py +1317 -0
  37. meshagent/cli/version.py +1 -0
  38. meshagent/cli/voicebot.py +624 -0
  39. meshagent/cli/webhook.py +100 -0
  40. meshagent/cli/worker.py +1403 -0
  41. meshagent_cli-0.22.2.dist-info/METADATA +49 -0
  42. meshagent_cli-0.22.2.dist-info/RECORD +45 -0
  43. meshagent_cli-0.22.2.dist-info/WHEEL +5 -0
  44. meshagent_cli-0.22.2.dist-info/entry_points.txt +2 -0
  45. meshagent_cli-0.22.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,63 @@
1
+ import typer
2
+ from rich import print
3
+ from typing import Annotated
4
+ from meshagent.api import ParticipantToken
5
+ from meshagent.cli import async_typer
6
+ from meshagent.cli.helper import get_client, resolve_key, resolve_project_id
7
+ import pathlib
8
+ from typing import Optional
9
+ from meshagent.api.participant_token import ParticipantTokenSpec
10
+ from pydantic_yaml import parse_yaml_raw_as
11
+ from meshagent.cli.common_options import ProjectIdOption
12
+
13
+ app = async_typer.AsyncTyper(help="Generate participant tokens (JWTs)")
14
+
15
+
16
+ @app.async_command("generate", help="Generate a participant token (JWT) from a spec")
17
+ async def generate(
18
+ *,
19
+ project_id: ProjectIdOption,
20
+ output: Annotated[
21
+ Optional[str],
22
+ typer.Option("--output", "-o", help="File path to a file"),
23
+ ] = None,
24
+ input: Annotated[
25
+ str,
26
+ typer.Option("--input", "-i", help="File path to a token spec"),
27
+ ],
28
+ key: Annotated[
29
+ str,
30
+ typer.Option("--key", help="an api key to sign the token with"),
31
+ ] = None,
32
+ ):
33
+ """Generate a signed participant token (JWT) from a YAML spec."""
34
+
35
+ project_id = await resolve_project_id(project_id=project_id)
36
+ key = await resolve_key(project_id=project_id, key=key)
37
+
38
+ client = await get_client()
39
+ try:
40
+ with open(str(pathlib.Path(input).expanduser().resolve()), "rb") as f:
41
+ spec = parse_yaml_raw_as(ParticipantTokenSpec, f.read())
42
+
43
+ token = ParticipantToken(
44
+ name=spec.identity,
45
+ )
46
+
47
+ if spec.role is not None:
48
+ token.add_role_grant(role=spec.role)
49
+ if spec.room is not None:
50
+ token.add_room_grant(spec.room)
51
+
52
+ token.add_api_grant(spec.api)
53
+
54
+ if output is None:
55
+ print(token.to_jwt(api_key=key))
56
+
57
+ else:
58
+ pathlib.Path(output).expanduser().resolve().write_text(
59
+ token.to_jwt(api_key=key)
60
+ )
61
+
62
+ finally:
63
+ await client.close()
meshagent/cli/port.py ADDED
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+
5
+
6
+ from typing import Annotated
7
+
8
+ import typer
9
+
10
+ from meshagent.cli import async_typer
11
+ from meshagent.cli.common_options import ProjectIdOption
12
+ from meshagent.cli.helper import get_client, resolve_project_id
13
+
14
+ from meshagent.api.port_forward import port_forward
15
+
16
+ app = async_typer.AsyncTyper(help="Port forwarding into room containers")
17
+
18
+
19
+ @app.async_command("forward", help="Forward a container port to localhost")
20
+ async def forward(
21
+ *,
22
+ project_id: ProjectIdOption,
23
+ room: Annotated[
24
+ str,
25
+ typer.Option(
26
+ "--room",
27
+ "-r",
28
+ help="Room name containing the target container",
29
+ ),
30
+ ],
31
+ container_id: Annotated[
32
+ str,
33
+ typer.Option(
34
+ "--container-id",
35
+ "-c",
36
+ help="Container ID to port-forward into",
37
+ ),
38
+ ],
39
+ port: Annotated[
40
+ str,
41
+ typer.Option(
42
+ "--port",
43
+ "-p",
44
+ help="Port mapping in the form LOCAL:REMOTE",
45
+ ),
46
+ ],
47
+ ):
48
+ """Create a local TCP listener forwarding into a room container."""
49
+
50
+ client = await get_client()
51
+ try:
52
+ project_id = await resolve_project_id(project_id)
53
+
54
+ connection = await client.connect_room(project_id=project_id, room=room)
55
+
56
+ ports = port.split(":")
57
+
58
+ handler = await port_forward(
59
+ listen_port=int(ports[0]),
60
+ port=int(ports[1]),
61
+ container_id=container_id,
62
+ token=connection.jwt,
63
+ )
64
+
65
+ await asyncio.sleep(10000)
66
+
67
+ await handler.close()
68
+
69
+ finally:
70
+ await client.close()
@@ -0,0 +1,105 @@
1
+ import typer
2
+ from rich import print
3
+ from meshagent.cli import async_typer
4
+ from meshagent.cli.helper import (
5
+ get_client,
6
+ print_json_table,
7
+ set_active_project,
8
+ get_active_project,
9
+ )
10
+ from meshagent.cli.common_options import OutputFormatOption
11
+
12
+ app = async_typer.AsyncTyper(help="Manage or activate your meshagent projects")
13
+
14
+
15
+ @app.async_command("create")
16
+ async def create(name: str):
17
+ client = await get_client()
18
+ try:
19
+ result = await client.create_project(name)
20
+ print(f"[green]Project created:[/] {result['id']}")
21
+ finally:
22
+ await client.close()
23
+
24
+
25
+ @app.async_command("list")
26
+ async def list(
27
+ o: OutputFormatOption = "table",
28
+ ):
29
+ client = await get_client()
30
+ projects = await client.list_projects()
31
+ active_project = await get_active_project()
32
+ for project in projects["projects"]:
33
+ if project["id"] == active_project:
34
+ project["name"] = "*" + project["name"]
35
+
36
+ if o == "json":
37
+ print(projects)
38
+ else:
39
+ print_json_table(projects["projects"], "id", "name")
40
+ await client.close()
41
+
42
+
43
+ @app.async_command("activate")
44
+ async def activate(
45
+ project_id: str | None = typer.Argument(None),
46
+ interactive: bool = typer.Option(
47
+ False,
48
+ "-i",
49
+ "--interactive",
50
+ help="Interactively select or create a project",
51
+ ),
52
+ ):
53
+ client = await get_client()
54
+ try:
55
+ if interactive:
56
+ response = await client.list_projects()
57
+ projects = response["projects"]
58
+
59
+ if not projects:
60
+ if typer.confirm(
61
+ "There are no projects. Would you like to create one?",
62
+ default=True,
63
+ ):
64
+ name = typer.prompt("Project name")
65
+ created = await client.create_project(name)
66
+ project_id = created["id"]
67
+ else:
68
+ raise typer.Exit(code=0)
69
+ else:
70
+ for idx, proj in enumerate(projects, start=1):
71
+ print(f"[{idx}] {proj['name']} ({proj['id']})")
72
+ new_project_index = len(projects) + 1
73
+ print(f"[{new_project_index}] Create a new project")
74
+ exit_index = new_project_index + 1
75
+ print(f"[{exit_index}] Exit")
76
+
77
+ choice = typer.prompt("Select a project", type=int)
78
+ if choice == exit_index:
79
+ return
80
+ elif choice == new_project_index:
81
+ name = typer.prompt("Project name")
82
+ # TODO: validate name
83
+ created = await client.create_project(name)
84
+ project_id = created["id"]
85
+ elif 1 <= choice <= len(projects):
86
+ project_id = projects[choice - 1]["id"]
87
+ else:
88
+ print("[red]Invalid selection[/red]")
89
+ raise typer.Exit(code=1)
90
+
91
+ if project_id is None and not interactive:
92
+ print("[red]project_id required[/red]")
93
+ raise typer.Exit(code=1)
94
+
95
+ if project_id is not None:
96
+ projects = (await client.list_projects())["projects"]
97
+ for project in projects:
98
+ if project["id"] == project_id:
99
+ await set_active_project(project_id=project_id)
100
+ return project_id
101
+
102
+ print(f"[red]Invalid project id: {project_id}[/red]")
103
+ raise typer.Exit(code=1)
104
+ finally:
105
+ await client.close()
meshagent/cli/queue.py ADDED
@@ -0,0 +1,91 @@
1
+ import typer
2
+ from rich import print
3
+ from typing import Annotated, Optional
4
+ from meshagent.cli.common_options import ProjectIdOption, RoomOption
5
+ import json as _json
6
+
7
+ from meshagent.api.helpers import meshagent_base_url, websocket_room_url
8
+ from meshagent.api import (
9
+ RoomClient,
10
+ WebSocketClientProtocol,
11
+ RoomException,
12
+ )
13
+ from meshagent.cli.helper import resolve_project_id, resolve_room
14
+ from meshagent.cli import async_typer
15
+ from meshagent.cli.helper import get_client
16
+
17
+ app = async_typer.AsyncTyper(help="Use queues in a room")
18
+
19
+
20
+ @app.async_command("send")
21
+ async def send(
22
+ *,
23
+ project_id: ProjectIdOption,
24
+ room: RoomOption,
25
+ queue: Annotated[str, typer.Option(..., help="Queue name")],
26
+ json: Optional[str] = typer.Option(..., help="a JSON message to send to the queue"),
27
+ file: Annotated[
28
+ Optional[str],
29
+ typer.Option("--file", "-f", help="File path to a JSON file"),
30
+ ] = None,
31
+ ):
32
+ account_client = await get_client()
33
+ try:
34
+ project_id = await resolve_project_id(project_id=project_id)
35
+ room = resolve_room(room)
36
+
37
+ connection = await account_client.connect_room(project_id=project_id, room=room)
38
+
39
+ print("[bold green]Connecting to room...[/bold green]")
40
+ async with RoomClient(
41
+ protocol=WebSocketClientProtocol(
42
+ url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
43
+ token=connection.jwt,
44
+ )
45
+ ) as client:
46
+ if file is not None:
47
+ with open(file, "rb") as f:
48
+ message = f.read()
49
+ else:
50
+ message = _json.loads(json)
51
+
52
+ await client.queues.send(name=queue, message=message)
53
+
54
+ except RoomException as e:
55
+ print(f"[red]{e}[/red]")
56
+ finally:
57
+ await account_client.close()
58
+
59
+
60
+ @app.async_command("receive")
61
+ async def receive(
62
+ *,
63
+ project_id: ProjectIdOption,
64
+ room: RoomOption,
65
+ queue: Annotated[str, typer.Option(..., help="Queue name")],
66
+ ):
67
+ account_client = await get_client()
68
+ try:
69
+ project_id = await resolve_project_id(project_id=project_id)
70
+ room = resolve_room(room)
71
+
72
+ connection = await account_client.connect_room(project_id=project_id, room=room)
73
+
74
+ async with RoomClient(
75
+ protocol=WebSocketClientProtocol(
76
+ url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
77
+ token=connection.jwt,
78
+ )
79
+ ) as client:
80
+ response = await client.queues.receive(name=queue, wait=False)
81
+ if response is None:
82
+ print("[bold yellow]Queue did not contain any messages.[/bold yellow]")
83
+ raise typer.Exit(1)
84
+ else:
85
+ print(response)
86
+
87
+ except RoomException as e:
88
+ print(f"[red]{e}[/red]")
89
+ raise typer.Exit(1)
90
+ finally:
91
+ await account_client.close()
meshagent/cli/room.py ADDED
@@ -0,0 +1,26 @@
1
+ from meshagent.cli import async_typer
2
+ from meshagent.cli import database
3
+ from meshagent.cli import queue
4
+ from meshagent.cli import agent
5
+ from meshagent.cli import messaging
6
+ from meshagent.cli import storage
7
+ from meshagent.cli import developer
8
+ from meshagent.cli import oauth2
9
+ from meshagent.cli import containers
10
+
11
+ from meshagent.cli import sync
12
+
13
+
14
+ app = async_typer.AsyncTyper(help="Operate within a room")
15
+
16
+ app.add_typer(agent.app, name="agents", help="Interact with agents and toolkits")
17
+ app.add_typer(oauth2.app, name="secrets", help="Manage secrets for your project")
18
+ app.add_typer(queue.app, name="queue", help="Use queues in a room")
19
+ app.add_typer(messaging.app, name="messaging", help="Send and receive messages")
20
+ app.add_typer(storage.app, name="storage", help="Manage storage for a room")
21
+ app.add_typer(developer.app, name="developer", help="Developer utilities for a room")
22
+ app.add_typer(database.app, name="database", help="Manage database tables in a room")
23
+ app.add_typer(
24
+ containers.app, name="container", help="Manage containers and images in a room"
25
+ )
26
+ app.add_typer(sync.app, name="sync")
meshagent/cli/rooms.py ADDED
@@ -0,0 +1,214 @@
1
+ # rooms_cli.py (add to the same module or import into your CLI package)
2
+
3
+ import typer
4
+ from rich import print
5
+ from typing import Annotated, Optional
6
+ import json
7
+
8
+ from meshagent.cli import async_typer
9
+ from meshagent.cli.common_options import ProjectIdOption
10
+ from meshagent.cli.helper import (
11
+ get_client,
12
+ resolve_project_id,
13
+ resolve_room,
14
+ )
15
+ from meshagent.api import RoomException
16
+
17
+ app = async_typer.AsyncTyper(help="Create, list, and manage rooms in a project")
18
+
19
+ # ---------------------------
20
+ # Helpers
21
+ # ---------------------------
22
+
23
+
24
+ async def _resolve_room_id_or_fail(
25
+ account_client, *, project_id: str, room_id: Optional[str], room_name: Optional[str]
26
+ ) -> str:
27
+ """
28
+ If room_id is provided, return it.
29
+ Else, resolve via room_name -> account_client.get_room(...).id
30
+ """
31
+ if room_id:
32
+ return room_id
33
+ if not room_name:
34
+ raise RoomException("You must provide either --id or --name.")
35
+ room = await account_client.get_room(project_id=project_id, name=room_name)
36
+ return room.id
37
+
38
+
39
+ def _maybe_parse_json(label: str, s: Optional[str]):
40
+ if s is None:
41
+ return None
42
+ try:
43
+ return json.loads(s)
44
+ except json.JSONDecodeError as e:
45
+ raise RoomException(f"Invalid {label} JSON: {e}") from e
46
+
47
+
48
+ # ---------------------------
49
+ # Commands
50
+ # ---------------------------
51
+
52
+
53
+ @app.async_command("create")
54
+ async def room_create_command(
55
+ *,
56
+ project_id: ProjectIdOption,
57
+ name: Annotated[str, typer.Option(..., help="Room name")],
58
+ if_not_exists: Annotated[
59
+ bool, typer.Option(help="Do not error if the room already exists")
60
+ ] = False,
61
+ metadata: Annotated[
62
+ Optional[str], typer.Option(help="Optional JSON object for room metadata")
63
+ ] = None,
64
+ ):
65
+ """
66
+ Create a room in the project.
67
+ """
68
+ account_client = await get_client()
69
+ try:
70
+ project_id = await resolve_project_id(project_id=project_id)
71
+
72
+ meta_obj = _maybe_parse_json("metadata", metadata)
73
+
74
+ print(f"[bold green]Creating room {name}[/bold green]")
75
+ room = await account_client.create_room(
76
+ project_id=project_id,
77
+ name=name,
78
+ if_not_exists=if_not_exists,
79
+ metadata=meta_obj,
80
+ )
81
+
82
+ print(
83
+ json.dumps(
84
+ {"id": room.id, "name": room.name, "metadata": room.metadata}, indent=2
85
+ )
86
+ )
87
+
88
+ except RoomException as ex:
89
+ print(f"[red]{ex}[/red]")
90
+ raise typer.Exit(1)
91
+ finally:
92
+ await account_client.close()
93
+
94
+
95
+ @app.async_command("delete")
96
+ async def room_delete_command(
97
+ *,
98
+ project_id: ProjectIdOption,
99
+ id: Annotated[Optional[str], typer.Option(help="Room ID (preferred)")] = None,
100
+ name: Optional[str] = None,
101
+ ):
102
+ """
103
+ Delete a room by ID (or by name if --name is supplied).
104
+ """
105
+ account_client = await get_client()
106
+ try:
107
+ project_id = await resolve_project_id(project_id=project_id)
108
+ room_name = resolve_room(name) if name else None
109
+ rid = await _resolve_room_id_or_fail(
110
+ account_client, project_id=project_id, room_id=id, room_name=room_name
111
+ )
112
+
113
+ print(f"[bold yellow]Deleting room id={rid}...[/bold yellow]")
114
+ await account_client.delete_room(project_id=project_id, room_id=rid)
115
+ print("[bold cyan]Room deleted.[/bold cyan]")
116
+ except RoomException as ex:
117
+ print(f"[red]{ex}[/red]")
118
+ raise typer.Exit(1)
119
+ finally:
120
+ await account_client.close()
121
+
122
+
123
+ @app.async_command("update")
124
+ async def room_update_command(
125
+ *,
126
+ project_id: ProjectIdOption,
127
+ id: Annotated[Optional[str], typer.Option(help="Room ID (preferred)")] = None,
128
+ name: Optional[str] = None,
129
+ new_name: Annotated[str, typer.Option(..., help="New room name")],
130
+ ):
131
+ """
132
+ Update a room's name (ID is preferred; name will be resolved to ID if needed).
133
+ """
134
+ account_client = await get_client()
135
+ try:
136
+ project_id = await resolve_project_id(project_id=project_id)
137
+ room_name = resolve_room(name) if name else None
138
+ rid = await _resolve_room_id_or_fail(
139
+ account_client, project_id=project_id, room_id=id, room_name=room_name
140
+ )
141
+
142
+ print(
143
+ f"[bold green]Updating room id={rid} -> name='{new_name}'...[/bold green]"
144
+ )
145
+ await account_client.update_room(
146
+ project_id=project_id, room_id=rid, name=new_name
147
+ )
148
+ print("[bold cyan]Room updated.[/bold cyan]")
149
+ except RoomException as ex:
150
+ print(f"[red]{ex}[/red]")
151
+ raise typer.Exit(1)
152
+ finally:
153
+ await account_client.close()
154
+
155
+
156
+ @app.async_command("list")
157
+ async def room_list_command(
158
+ *,
159
+ project_id: ProjectIdOption,
160
+ limit: Annotated[
161
+ int, typer.Option(help="Max rooms to return", min=1, max=500)
162
+ ] = 50,
163
+ offset: Annotated[int, typer.Option(help="Offset for pagination", min=0)] = 0,
164
+ order_by: Annotated[
165
+ str, typer.Option(help='Order by column (e.g. "room_name", "created_at")')
166
+ ] = "room_name",
167
+ ):
168
+ """
169
+ List rooms in the project.
170
+ """
171
+ account_client = await get_client()
172
+ try:
173
+ project_id = await resolve_project_id(project_id=project_id)
174
+ print("[bold green]Fetching rooms...[/bold green]")
175
+
176
+ rooms = await account_client.list_rooms(
177
+ project_id=project_id,
178
+ limit=limit,
179
+ offset=offset,
180
+ order_by=order_by,
181
+ )
182
+ output = [{"id": r.id, "name": r.name, "metadata": r.metadata} for r in rooms]
183
+ print(json.dumps(output, indent=2))
184
+ except RoomException as ex:
185
+ print(f"[red]{ex}[/red]")
186
+ raise typer.Exit(1)
187
+ finally:
188
+ await account_client.close()
189
+
190
+
191
+ @app.async_command("get")
192
+ async def room_get_command(
193
+ *,
194
+ project_id: ProjectIdOption,
195
+ name: Optional[str] = None,
196
+ ):
197
+ """
198
+ Get a single room by name (handy for resolving the ID).
199
+ """
200
+ account_client = await get_client()
201
+ try:
202
+ project_id = await resolve_project_id(project_id=project_id)
203
+ room_name = resolve_room(name)
204
+
205
+ print(f"[bold green]Fetching room '{room_name}'...[/bold green]")
206
+ r = await account_client.get_room(project_id=project_id, name=room_name)
207
+ print(
208
+ json.dumps({"id": r.id, "name": r.name, "metadata": r.metadata}, indent=2)
209
+ )
210
+ except RoomException as ex:
211
+ print(f"[red]{ex}[/red]")
212
+ raise typer.Exit(1)
213
+ finally:
214
+ await account_client.close()