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.

meshagent/cli/agent.py CHANGED
@@ -1,20 +1,19 @@
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
6
6
  import asyncio
7
7
 
8
8
  from meshagent.api.helpers import meshagent_base_url, websocket_room_url
9
9
  from meshagent.api import (
10
10
  RoomClient,
11
- ParticipantToken,
12
11
  WebSocketClientProtocol,
13
12
  RoomException,
14
13
  )
15
- from meshagent.cli.helper import resolve_project_id, resolve_api_key
14
+ from meshagent.cli.helper import resolve_project_id
16
15
  from meshagent.cli import async_typer
17
- from meshagent.cli.helper import get_client, resolve_token_jwt, resolve_room
16
+ from meshagent.cli.helper import get_client, resolve_room
18
17
 
19
18
  app = async_typer.AsyncTyper()
20
19
 
@@ -24,9 +23,6 @@ async def ask(
24
23
  *,
25
24
  project_id: ProjectIdOption = None,
26
25
  room: RoomOption,
27
- api_key_id: ApiKeyIdOption = None,
28
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
29
- role: str = "user",
30
26
  agent: Annotated[str, typer.Option()],
31
27
  input: Annotated[str, typer.Option()],
32
28
  timeout: Annotated[
@@ -39,27 +35,15 @@ async def ask(
39
35
  account_client = await get_client()
40
36
  try:
41
37
  project_id = await resolve_project_id(project_id=project_id)
42
- api_key_id = await resolve_api_key(project_id, api_key_id)
43
38
  room = resolve_room(room)
44
39
 
45
- key = (
46
- await account_client.decrypt_project_api_key(
47
- project_id=project_id, id=api_key_id
48
- )
49
- )["token"]
50
-
51
- token = ParticipantToken(
52
- name=name, project_id=project_id, api_key_id=api_key_id
53
- )
54
-
55
- token.add_role_grant(role=role)
56
- token.add_room_grant(room)
40
+ connection = await account_client.connect_room(project_id=project_id, room=room)
57
41
 
58
42
  print("[bold green]Connecting to room...[/bold green]")
59
43
  async with RoomClient(
60
44
  protocol=WebSocketClientProtocol(
61
45
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
62
- token=token.to_jwt(token=key),
46
+ token=connection.jwt,
63
47
  )
64
48
  ) as client:
65
49
  found = timeout == 0
@@ -97,10 +81,6 @@ async def invoke_tool(
97
81
  *,
98
82
  project_id: ProjectIdOption = None,
99
83
  room: RoomOption,
100
- token_path: Annotated[Optional[str], typer.Option()] = None,
101
- api_key_id: ApiKeyIdOption = None,
102
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
103
- role: str = "user",
104
84
  toolkit: Annotated[str, typer.Option(..., help="Toolkit name")],
105
85
  tool: Annotated[str, typer.Option(..., help="Tool name")],
106
86
  arguments: Annotated[
@@ -130,23 +110,15 @@ async def invoke_tool(
130
110
  account_client = await get_client()
131
111
  try:
132
112
  project_id = await resolve_project_id(project_id=project_id)
133
- api_key_id = await resolve_api_key(project_id, api_key_id)
134
113
  room = resolve_room(room)
135
114
 
136
- jwt = await resolve_token_jwt(
137
- project_id=project_id,
138
- api_key_id=api_key_id,
139
- token_path=token_path,
140
- name=name,
141
- role=role,
142
- room=room,
143
- )
115
+ connection = await account_client.connect_room(project_id=project_id, room=room)
144
116
 
145
117
  print("[bold green]Connecting to room...[/bold green]")
146
118
  async with RoomClient(
147
119
  protocol=WebSocketClientProtocol(
148
120
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
149
- token=jwt,
121
+ token=connection.jwt,
150
122
  )
151
123
  ) as client:
152
124
  found = timeout == 0
@@ -194,10 +166,6 @@ async def list_agents_command(
194
166
  *,
195
167
  project_id: ProjectIdOption = None,
196
168
  room: RoomOption,
197
- token_path: Annotated[Optional[str], typer.Option()] = None,
198
- api_key_id: ApiKeyIdOption = None,
199
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
200
- role: str = "user",
201
169
  ):
202
170
  """
203
171
  List all agents available in the room.
@@ -205,23 +173,15 @@ async def list_agents_command(
205
173
  account_client = await get_client()
206
174
  try:
207
175
  project_id = await resolve_project_id(project_id=project_id)
208
- api_key_id = await resolve_api_key(project_id, api_key_id)
209
176
  room = resolve_room(room)
210
177
 
211
- jwt = await resolve_token_jwt(
212
- project_id=project_id,
213
- api_key_id=api_key_id,
214
- token_path=token_path,
215
- name=name,
216
- role=role,
217
- room=room,
218
- )
178
+ connection = await account_client.connect_room(project_id=project_id, room=room)
219
179
 
220
180
  print("[bold green]Connecting to room...[/bold green]")
221
181
  async with RoomClient(
222
182
  protocol=WebSocketClientProtocol(
223
183
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
224
- token=jwt,
184
+ token=connection.jwt,
225
185
  )
226
186
  ) as client:
227
187
  print("[bold green]Fetching list of agents...[/bold green]")
@@ -250,9 +210,6 @@ async def list_toolkits_command(
250
210
  *,
251
211
  project_id: ProjectIdOption = None,
252
212
  room: RoomOption,
253
- token_path: Annotated[Optional[str], typer.Option()] = None,
254
- api_key_id: ApiKeyIdOption = None,
255
- name: Annotated[str, typer.Option(..., help="Participant name")] = "cli",
256
213
  role: str = "user",
257
214
  participant_id: Annotated[
258
215
  Optional[str], typer.Option(..., help="Optional participant ID")
@@ -264,22 +221,14 @@ async def list_toolkits_command(
264
221
  account_client = await get_client()
265
222
  try:
266
223
  project_id = await resolve_project_id(project_id=project_id)
267
- api_key_id = await resolve_api_key(project_id, api_key_id)
268
224
  room = resolve_room(room)
269
- jwt = await resolve_token_jwt(
270
- project_id=project_id,
271
- api_key_id=api_key_id,
272
- token_path=token_path,
273
- name=name,
274
- role=role,
275
- room=room,
276
- )
225
+ connection = await account_client.connect_room(project_id=project_id, room=room)
277
226
 
278
227
  print("[bold green]Connecting to room...[/bold green]")
279
228
  async with RoomClient(
280
229
  protocol=WebSocketClientProtocol(
281
230
  url=websocket_room_url(room_name=room, base_url=meshagent_base_url()),
282
- token=jwt,
231
+ token=connection.jwt,
283
232
  )
284
233
  ) as client:
285
234
  print("[bold green]Fetching list of toolkits...[/bold green]")
meshagent/cli/api_keys.py CHANGED
@@ -1,4 +1,3 @@
1
- import typer
2
1
  import json
3
2
  from rich import print
4
3
 
@@ -11,7 +10,8 @@ from meshagent.cli.helper import (
11
10
  set_active_api_key,
12
11
  )
13
12
  from meshagent.cli.common_options import OutputFormatOption
14
-
13
+ from typing import Annotated
14
+ import typer
15
15
 
16
16
  app = async_typer.AsyncTyper(help="Manage or activate api-keys for your project")
17
17
 
@@ -24,7 +24,8 @@ async def list(
24
24
  ):
25
25
  project_id = await resolve_project_id(project_id=project_id)
26
26
  client = await get_client()
27
- keys = (await client.list_project_api_keys(project_id=project_id))["keys"]
27
+ keys = (await client.list_api_keys(project_id=project_id))["keys"]
28
+
28
29
  if len(keys) > 0:
29
30
  if o == "json":
30
31
  sanitized_keys = [
@@ -40,110 +41,62 @@ async def list(
40
41
 
41
42
  @app.async_command("create")
42
43
  async def create(
43
- *, project_id: ProjectIdOption = None, name: str, description: str = ""
44
+ *,
45
+ project_id: ProjectIdOption = None,
46
+ name: str,
47
+ description: Annotated[
48
+ str, typer.Option(..., help="a description for the api key")
49
+ ] = "",
50
+ activate: Annotated[
51
+ bool,
52
+ typer.Option(
53
+ ..., help="use this key by default for commands that accept an API key"
54
+ ),
55
+ ] = False,
56
+ silent: Annotated[bool, typer.Option(..., help="do not print api key")] = False,
44
57
  ):
45
58
  project_id = await resolve_project_id(project_id=project_id)
46
59
 
47
60
  client = await get_client()
48
- api_key = await client.create_project_api_key(
61
+ api_key = await client.create_api_key(
49
62
  project_id=project_id, name=name, description=description
50
63
  )
51
- print(api_key["token"])
52
- await client.close()
53
-
54
-
55
- @app.async_command("delete")
56
- async def delete(*, project_id: ProjectIdOption = None, id: str):
57
- project_id = await resolve_project_id(project_id=project_id)
64
+ if not silent:
65
+ if not activate:
66
+ print(
67
+ "[green]This is your token. Save it for later, you will not be able to get the value again:[/green]\n"
68
+ )
69
+ print(api_key["value"])
70
+ print(
71
+ "[green]\nNote: you can use the --activate flag to save a key in your local project settings when creating a key.[/green]\n"
72
+ )
73
+ else:
74
+ print("[green]This is your token:[/green]\n")
75
+ print(api_key["value"])
58
76
 
59
- client = await get_client()
60
- await client.delete_project_api_key(project_id=project_id, id=id)
61
77
  await client.close()
62
-
63
-
64
- @app.async_command("show")
65
- async def show(*, project_id: ProjectIdOption = None, api_key_id: str):
66
- client = await get_client()
67
- try:
68
- project_id = await resolve_project_id(project_id=project_id)
69
-
70
- key = await client.decrypt_project_api_key(project_id=project_id, id=api_key_id)
71
-
72
- print(key["token"])
73
-
74
- finally:
75
- await client.close()
78
+ if activate:
79
+ await set_active_api_key(project_id=project_id, key=api_key["value"])
80
+ print(
81
+ "[green]your api key has been activated and will be used automatically with commands that require a key[/green]\n"
82
+ )
76
83
 
77
84
 
78
85
  @app.async_command("activate")
79
86
  async def activate(
80
- api_key_id: str | None = typer.Argument(None),
87
+ *,
81
88
  project_id: ProjectIdOption = None,
82
- interactive: bool = typer.Option(
83
- False,
84
- "-i",
85
- "--interactive",
86
- help="Interactively select or create an api key",
87
- ),
89
+ key: str,
88
90
  ):
89
- client = await get_client()
90
- try:
91
- project_id = await resolve_project_id(project_id)
92
- if interactive:
93
- response = await client.list_project_api_keys(project_id=project_id)
94
- api_keys = response["keys"]
95
-
96
- if not api_keys:
97
- if typer.confirm(
98
- "There are no API keys. Would you like to create one?",
99
- default=True,
100
- ):
101
- name = typer.prompt("API key name")
102
- created = await client.create_project_api_key(
103
- project_id=project_id,
104
- name=name,
105
- description="",
106
- )
107
- api_key_id = created["id"]
108
- else:
109
- raise typer.Exit(code=0)
110
- else:
111
- for idx, key in enumerate(api_keys, start=1):
112
- print(f"[{idx}] {key['name']} ({key['id']})")
113
- new_key_index = len(api_keys) + 1
114
- print(f"[{new_key_index}] Create a new api key")
115
- exit_index = new_key_index + 1
116
- print(f"[{exit_index}] Exit")
117
-
118
- choice = typer.prompt("Select an api key", type=int)
119
- if choice == exit_index:
120
- return
121
- elif choice == new_key_index:
122
- name = typer.prompt("API key name")
123
- created = await client.create_project_api_key(
124
- project_id=project_id,
125
- name=name,
126
- description="",
127
- )
128
- api_key_id = created["id"]
129
- elif 1 <= choice <= len(api_keys):
130
- api_key_id = api_keys[choice - 1]["id"]
131
- else:
132
- print("[red]Invalid selection[/red]")
133
- raise typer.Exit(code=1)
91
+ project_id = await resolve_project_id(project_id=project_id)
92
+ if activate:
93
+ await set_active_api_key(project_id=project_id, key=key)
134
94
 
135
- if api_key_id is None and not interactive:
136
- print("[red]api_key_id required[/red]")
137
- raise typer.Exit(code=1)
138
95
 
139
- response = await client.list_project_api_keys(project_id=project_id)
140
- api_keys = response["keys"]
141
- for api_key in api_keys:
142
- if api_key["id"] == api_key_id:
143
- await set_active_api_key(project_id=project_id, api_key_id=api_key_id)
144
- return api_key_id
96
+ @app.async_command("delete")
97
+ async def delete(*, project_id: ProjectIdOption = None, id: str):
98
+ project_id = await resolve_project_id(project_id=project_id)
145
99
 
146
- print(f"[red]Invalid api key id or project id: {project_id}[/red]")
147
- raise typer.Exit(code=1)
148
- finally:
149
- await client.close()
100
+ client = await get_client()
101
+ await client.delete_api_key(project_id=project_id, id=id)
102
+ await client.close()