meshagent-cli 0.5.15__py3-none-any.whl → 0.6.0__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.

@@ -1,12 +1,14 @@
1
1
  import typer
2
2
  from rich import print
3
3
  from typing import Annotated
4
- from meshagent.cli.common_options import ProjectIdOption, ApiKeyIdOption, RoomOption
5
4
  from meshagent.api import ParticipantToken
6
- from meshagent.cli.helper import resolve_project_id, resolve_api_key, resolve_room
7
5
  from meshagent.cli import async_typer
8
- from meshagent.cli.helper import get_client
6
+ from meshagent.cli.helper import get_client, resolve_key, resolve_project_id
9
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
10
12
 
11
13
  app = async_typer.AsyncTyper()
12
14
 
@@ -15,35 +17,44 @@ app = async_typer.AsyncTyper()
15
17
  async def generate(
16
18
  *,
17
19
  project_id: ProjectIdOption = None,
18
- token_path: Annotated[str, typer.Option()],
19
- room: RoomOption,
20
- api_key_id: ApiKeyIdOption = None,
21
- name: Annotated[str, typer.Option()],
22
- role: str = "agent",
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,
23
32
  ):
33
+ project_id = await resolve_project_id(project_id=project_id)
34
+ key = await resolve_key(project_id=project_id, key=key)
35
+
24
36
  client = await get_client()
25
37
  try:
26
- project_id = await resolve_project_id(project_id=project_id)
27
- api_key_id = await resolve_api_key(project_id=project_id, api_key_id=api_key_id)
28
- room = resolve_room(room)
29
- key = (
30
- await client.decrypt_project_api_key(project_id=project_id, id=api_key_id)
31
- )["token"]
38
+ with open(str(pathlib.Path(input).expanduser().resolve()), "rb") as f:
39
+ spec = parse_yaml_raw_as(ParticipantTokenSpec, f.read())
32
40
 
33
41
  token = ParticipantToken(
34
- name=name, project_id=project_id, api_key_id=api_key_id
42
+ name=spec.identity,
35
43
  )
36
44
 
37
- token.add_role_grant(role=role)
45
+ if spec.role is not None:
46
+ token.add_role_grant(role=spec.role)
47
+ if spec.room is not None:
48
+ token.add_room_grant(spec.room)
38
49
 
39
- token.add_room_grant(room)
50
+ token.add_api_grant(spec.api)
40
51
 
41
- if token_path is None:
42
- print(token.to_jwt(token=key))
52
+ if output is None:
53
+ print(token.to_jwt(api_key=key))
43
54
 
44
55
  else:
45
- pathlib.Path(token_path).expanduser().resolve().write_text(
46
- token.to_jwt(token=key)
56
+ pathlib.Path(output).expanduser().resolve().write_text(
57
+ token.to_jwt(api_key=key)
47
58
  )
48
59
 
49
60
  finally:
meshagent/cli/queue.py CHANGED
@@ -1,17 +1,16 @@
1
1
  import typer
2
2
  from rich import print
3
3
  from typing import Annotated, Optional
4
- from meshagent.cli.common_options import ProjectIdOption, ApiKeyIdOption, RoomOption
4
+ from meshagent.cli.common_options import ProjectIdOption, RoomOption
5
5
  import json as _json
6
6
 
7
7
  from meshagent.api.helpers import meshagent_base_url, websocket_room_url
8
8
  from meshagent.api import (
9
9
  RoomClient,
10
- ParticipantToken,
11
10
  WebSocketClientProtocol,
12
11
  RoomException,
13
12
  )
14
- from meshagent.cli.helper import resolve_project_id, resolve_api_key, resolve_room
13
+ from meshagent.cli.helper import resolve_project_id, resolve_room
15
14
  from meshagent.cli import async_typer
16
15
  from meshagent.cli.helper import get_client
17
16
 
@@ -23,9 +22,6 @@ async def send(
23
22
  *,
24
23
  project_id: ProjectIdOption = None,
25
24
  room: RoomOption,
26
- api_key_id: ApiKeyIdOption = None,
27
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
28
- role: str = "user",
29
25
  queue: Annotated[str, typer.Option(..., help="Queue name")],
30
26
  json: Optional[str] = typer.Option(..., help="a JSON message to send to the queue"),
31
27
  file: Annotated[
@@ -36,27 +32,15 @@ async def send(
36
32
  account_client = await get_client()
37
33
  try:
38
34
  project_id = await resolve_project_id(project_id=project_id)
39
- api_key_id = await resolve_api_key(project_id, api_key_id)
40
35
  room = resolve_room(room)
41
36
 
42
- key = (
43
- await account_client.decrypt_project_api_key(
44
- project_id=project_id, id=api_key_id
45
- )
46
- )["token"]
47
-
48
- token = ParticipantToken(
49
- name=name, project_id=project_id, api_key_id=api_key_id
50
- )
51
-
52
- token.add_role_grant(role=role)
53
- token.add_room_grant(room)
37
+ connection = await account_client.connect_room(project_id=project_id, room=room)
54
38
 
55
39
  print("[bold green]Connecting to room...[/bold green]")
56
40
  async with RoomClient(
57
41
  protocol=WebSocketClientProtocol(
58
42
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
59
- token=token.to_jwt(token=key),
43
+ token=connection.jwt,
60
44
  )
61
45
  ) as client:
62
46
  if file is not None:
@@ -78,34 +62,19 @@ async def receive(
78
62
  *,
79
63
  project_id: ProjectIdOption = None,
80
64
  room: RoomOption,
81
- api_key_id: ApiKeyIdOption = None,
82
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
83
- role: str = "user",
84
65
  queue: Annotated[str, typer.Option(..., help="Queue name")],
85
66
  ):
86
67
  account_client = await get_client()
87
68
  try:
88
69
  project_id = await resolve_project_id(project_id=project_id)
89
- api_key_id = await resolve_api_key(project_id, api_key_id)
90
70
  room = resolve_room(room)
91
71
 
92
- key = (
93
- await account_client.decrypt_project_api_key(
94
- project_id=project_id, id=api_key_id
95
- )
96
- )["token"]
97
-
98
- token = ParticipantToken(
99
- name=name, project_id=project_id, api_key_id=api_key_id
100
- )
101
-
102
- token.add_role_grant(role=role)
103
- token.add_room_grant(room)
72
+ connection = await account_client.connect_room(project_id=project_id, room=room)
104
73
 
105
74
  async with RoomClient(
106
75
  protocol=WebSocketClientProtocol(
107
76
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
108
- token=token.to_jwt(token=key),
77
+ token=connection.jwt,
109
78
  )
110
79
  ) as client:
111
80
  response = await client.queues.receive(name=queue, wait=False)