Skip to content

Commit cc53781

Browse files
committed
livekit-api: keyword arguments for Public API client calls
1 parent ef38dbc commit cc53781

3 files changed

Lines changed: 43 additions & 38 deletions

File tree

‎livekit-api/livekit/api/database_service.py‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ class DatabaseService(PublicApiService):
2323
async def create_database(self, req: AgentDB.CreateRequest) -> AgentDB.CreateResponse:
2424
"""Creates an empty database. Not idempotent: a retry creates a second one."""
2525
return await self._client.request(
26-
self._client.databases.database_service_create_database_without_preload_content,
27-
self._auth_header(),
28-
AgentDB.CreateResponse,
26+
operation=self._client.databases.database_service_create_database_without_preload_content,
27+
headers=self._auth_header(),
28+
response_class=AgentDB.CreateResponse,
2929
database_service_create_database_body=DatabaseServiceCreateDatabaseBody.from_dict(
3030
to_json(req)
3131
),
3232
)
3333

3434
async def get_database(self, database_id: str) -> AgentDB.AgentDatabase:
3535
return await self._client.request(
36-
self._client.databases.database_service_get_database_without_preload_content,
37-
self._auth_header(),
38-
AgentDB.AgentDatabase,
36+
operation=self._client.databases.database_service_get_database_without_preload_content,
37+
headers=self._auth_header(),
38+
response_class=AgentDB.AgentDatabase,
3939
field="database",
4040
database_id=database_id,
4141
)
4242

4343
async def list_databases(self, req: AgentDB.ListRequest) -> AgentDB.ListResponse:
4444
return await self._client.list(
45-
self._client.databases.database_service_list_databases_without_preload_content,
46-
self._auth_header(),
47-
AgentDB.ListResponse,
45+
operation=self._client.databases.database_service_list_databases_without_preload_content,
46+
headers=self._auth_header(),
47+
response_class=AgentDB.ListResponse,
4848
items="databases",
4949
page_token=req.page_token,
5050
limit=req.page_size,
@@ -53,17 +53,17 @@ async def list_databases(self, req: AgentDB.ListRequest) -> AgentDB.ListResponse
5353
async def delete_database(self, database_id: str) -> None:
5454
"""Deletes the database with its data."""
5555
await self._client.request(
56-
self._client.databases.database_service_delete_database_without_preload_content,
57-
self._auth_header(),
58-
Empty,
56+
operation=self._client.databases.database_service_delete_database_without_preload_content,
57+
headers=self._auth_header(),
58+
response_class=Empty,
5959
database_id=database_id,
6060
)
6161

6262
async def export_database(self, database_id: str) -> AgentDB.ExportResponse:
6363
"""A pre-authenticated download URL of a consistent snapshot of the database."""
6464
return await self._client.request(
65-
self._client.databases.database_service_export_database_without_preload_content,
66-
self._auth_header(),
67-
AgentDB.ExportResponse,
65+
operation=self._client.databases.database_service_export_database_without_preload_content,
66+
headers=self._auth_header(),
67+
response_class=AgentDB.ExportResponse,
6868
database_id=database_id,
6969
)

‎livekit-api/livekit/api/public_api_client.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(
8787

8888
async def request(
8989
self,
90+
*,
9091
operation: Callable[..., Awaitable[aiohttp.ClientResponse]],
9192
headers: Dict[str, str],
9293
response_class: Type[M],
@@ -96,11 +97,12 @@ async def request(
9697
) -> M:
9798
"""Calls a generated operation and parses its JSON (or its `field`) into `response_class`.
9899
A parameter at its protobuf default (`""`, `0`) is left unset."""
99-
data = await self._call(operation, headers, params)
100+
data = await self._call(operation=operation, headers=headers, params=params)
100101
return _parse(data.get(field) if field else data, response_class)
101102

102103
async def list(
103104
self,
105+
*,
104106
operation: Callable[..., Awaitable[aiohttp.ClientResponse]],
105107
headers: Dict[str, str],
106108
response_class: Type[M],
@@ -113,13 +115,16 @@ async def list(
113115
"""Calls a generated list operation for one page: its `items` and `pageInfo` become the
114116
protocol response's `items` field and `next_page_token`."""
115117
data = await self._call(
116-
operation, headers, {"page_cursor": page_token, "page_page_size": limit, **params}
118+
operation=operation,
119+
headers=headers,
120+
params={"page_cursor": page_token, "page_page_size": limit, **params},
117121
)
118122
next_page = (data.get("pageInfo") or {}).get("nextCursor", "")
119123
return _parse({items: data.get("items"), "nextPageToken": next_page}, response_class)
120124

121125
async def _call(
122126
self,
127+
*,
123128
operation: Callable[..., Awaitable[aiohttp.ClientResponse]],
124129
headers: Dict[str, str],
125130
params: Dict[str, Any],

‎livekit-api/livekit/api/thread_service.py‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@ class ThreadService(PublicApiService):
3333
async def create_thread(self, req: AgentThread.CreateRequest) -> AgentThread.Thread:
3434
"""Creates a thread and its database."""
3535
return await self._client.request(
36-
self._client.threads.thread_service_create_thread_without_preload_content,
37-
self._auth_header(),
38-
AgentThread.Thread,
36+
operation=self._client.threads.thread_service_create_thread_without_preload_content,
37+
headers=self._auth_header(),
38+
response_class=AgentThread.Thread,
3939
field="thread",
4040
thread_service_create_thread_body=ThreadServiceCreateThreadBody.from_dict(to_json(req)),
4141
)
4242

4343
async def get_thread(self, thread_id: str) -> AgentThread.Thread:
4444
return await self._client.request(
45-
self._client.threads.thread_service_get_thread_without_preload_content,
46-
self._auth_header(),
47-
AgentThread.Thread,
45+
operation=self._client.threads.thread_service_get_thread_without_preload_content,
46+
headers=self._auth_header(),
47+
response_class=AgentThread.Thread,
4848
field="thread",
4949
thread_id=thread_id,
5050
)
5151

5252
async def list_threads(self, req: AgentThread.ListRequest) -> AgentThread.ListResponse:
5353
"""The threads of one scope (every scope when empty), newest first."""
5454
return await self._client.list(
55-
self._client.threads.thread_service_list_threads_without_preload_content,
56-
self._auth_header(),
57-
AgentThread.ListResponse,
55+
operation=self._client.threads.thread_service_list_threads_without_preload_content,
56+
headers=self._auth_header(),
57+
response_class=AgentThread.ListResponse,
5858
items="threads",
5959
page_token=req.page_token,
6060
limit=req.limit,
@@ -67,9 +67,9 @@ async def update_thread(self, req: AgentThread.UpdateRequest) -> AgentThread.Thr
6767
body = to_json(req)
6868
body.pop("threadId", None)
6969
return await self._client.request(
70-
self._client.threads.thread_service_update_thread_without_preload_content,
71-
self._auth_header(),
72-
AgentThread.Thread,
70+
operation=self._client.threads.thread_service_update_thread_without_preload_content,
71+
headers=self._auth_header(),
72+
response_class=AgentThread.Thread,
7373
field="thread",
7474
thread_id=req.thread_id,
7575
thread_service_update_thread_body=ThreadServiceUpdateThreadBody.from_dict(body),
@@ -78,9 +78,9 @@ async def update_thread(self, req: AgentThread.UpdateRequest) -> AgentThread.Thr
7878
async def delete_thread(self, thread_id: str) -> None:
7979
"""Deletes the thread and its database."""
8080
await self._client.request(
81-
self._client.threads.thread_service_delete_thread_without_preload_content,
82-
self._auth_header(),
83-
Empty,
81+
operation=self._client.threads.thread_service_delete_thread_without_preload_content,
82+
headers=self._auth_header(),
83+
response_class=Empty,
8484
thread_id=thread_id,
8585
)
8686

@@ -89,9 +89,9 @@ async def get_thread_items(
8989
) -> AgentThread.GetItemsResponse:
9090
"""The thread's chat items, oldest first unless `sort_order` says otherwise."""
9191
return await self._client.list(
92-
self._client.threads.thread_service_get_thread_items_without_preload_content,
93-
self._auth_header(),
94-
AgentThread.GetItemsResponse,
92+
operation=self._client.threads.thread_service_get_thread_items_without_preload_content,
93+
headers=self._auth_header(),
94+
response_class=AgentThread.GetItemsResponse,
9595
items="items",
9696
page_token=req.page_token,
9797
limit=req.limit,
@@ -108,9 +108,9 @@ async def get_thread_tasks(self, req: AgentTask.GetTasksRequest) -> AgentTask.Ge
108108
else None
109109
)
110110
return await self._client.list(
111-
self._client.threads.thread_service_get_thread_tasks_without_preload_content,
112-
self._auth_header(),
113-
AgentTask.GetTasksResponse,
111+
operation=self._client.threads.thread_service_get_thread_tasks_without_preload_content,
112+
headers=self._auth_header(),
113+
response_class=AgentTask.GetTasksResponse,
114114
items="tasks",
115115
page_token=req.page_token,
116116
limit=req.limit,

0 commit comments

Comments
 (0)