cheshirecat-python-sdk 1.2.1__py3-none-any.whl → 1.7.9__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.
- cheshirecat_python_sdk/__init__.py +0 -1
- cheshirecat_python_sdk/builders/memory.py +0 -12
- cheshirecat_python_sdk/builders/why.py +0 -6
- cheshirecat_python_sdk/client.py +30 -5
- cheshirecat_python_sdk/clients/http_client.py +21 -7
- cheshirecat_python_sdk/clients/websocket_client.py +21 -15
- cheshirecat_python_sdk/configuration.py +1 -1
- cheshirecat_python_sdk/endpoints/__init__.py +6 -1
- cheshirecat_python_sdk/endpoints/admins.py +37 -70
- cheshirecat_python_sdk/endpoints/auth.py +54 -0
- cheshirecat_python_sdk/endpoints/auth_handler.py +8 -8
- cheshirecat_python_sdk/endpoints/base.py +48 -17
- cheshirecat_python_sdk/endpoints/chunker.py +8 -8
- cheshirecat_python_sdk/endpoints/conversation.py +83 -0
- cheshirecat_python_sdk/endpoints/custom_endpoint.py +57 -0
- cheshirecat_python_sdk/endpoints/embedder.py +4 -4
- cheshirecat_python_sdk/endpoints/file_manager.py +59 -8
- cheshirecat_python_sdk/endpoints/health_check.py +22 -0
- cheshirecat_python_sdk/endpoints/large_language_model.py +8 -8
- cheshirecat_python_sdk/endpoints/memory.py +70 -145
- cheshirecat_python_sdk/endpoints/message.py +29 -13
- cheshirecat_python_sdk/endpoints/plugins.py +31 -26
- cheshirecat_python_sdk/endpoints/rabbit_hole.py +51 -23
- cheshirecat_python_sdk/endpoints/users.py +22 -56
- cheshirecat_python_sdk/endpoints/utils.py +71 -0
- cheshirecat_python_sdk/endpoints/vector_database.py +52 -0
- cheshirecat_python_sdk/enums.py +0 -11
- cheshirecat_python_sdk/models/api/admins.py +4 -0
- cheshirecat_python_sdk/models/api/conversations.py +24 -0
- cheshirecat_python_sdk/models/api/factories.py +6 -0
- cheshirecat_python_sdk/models/api/file_managers.py +18 -0
- cheshirecat_python_sdk/models/api/memories.py +2 -10
- cheshirecat_python_sdk/models/api/messages.py +8 -6
- cheshirecat_python_sdk/models/api/nested/memories.py +5 -5
- cheshirecat_python_sdk/models/api/nested/plugins.py +8 -2
- cheshirecat_python_sdk/models/api/plugins.py +30 -22
- cheshirecat_python_sdk/models/api/tokens.py +19 -0
- cheshirecat_python_sdk/models/api/users.py +2 -0
- cheshirecat_python_sdk/models/dtos.py +3 -13
- cheshirecat_python_sdk/utils.py +2 -1
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.7.9.dist-info}/METADATA +12 -10
- cheshirecat_python_sdk-1.7.9.dist-info/RECORD +49 -0
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.7.9.dist-info}/WHEEL +1 -1
- cheshirecat_python_sdk/endpoints/settings.py +0 -63
- cheshirecat_python_sdk/models/api/settings.py +0 -22
- cheshirecat_python_sdk-1.2.1.dist-info/RECORD +0 -43
- {cheshirecat_python_sdk-1.2.1.dist-info → cheshirecat_python_sdk-1.7.9.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from cheshirecat_python_sdk.client import CheshireCatClient
|
|
2
2
|
from cheshirecat_python_sdk.clients import HttpClient, WSClient
|
|
3
3
|
from cheshirecat_python_sdk.configuration import Configuration
|
|
4
|
-
from cheshirecat_python_sdk.enums import Collection, Role
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
from cheshirecat_python_sdk.builders import *
|
|
@@ -6,31 +6,19 @@ from cheshirecat_python_sdk.models.dtos import Memory, MemoryPoint
|
|
|
6
6
|
|
|
7
7
|
class MemoryBuilder(BaseBuilder):
|
|
8
8
|
def __init__(self):
|
|
9
|
-
self.episodic: Dict[str, Any] | None = None
|
|
10
9
|
self.declarative: Dict[str, Any] | None = None
|
|
11
|
-
self.procedural: Dict[str, Any] | None = None
|
|
12
10
|
|
|
13
11
|
@staticmethod
|
|
14
12
|
def create():
|
|
15
13
|
return MemoryBuilder()
|
|
16
14
|
|
|
17
|
-
def set_episodic(self, episodic: Dict[str, Any] | None = None):
|
|
18
|
-
self.episodic = episodic or {}
|
|
19
|
-
return self
|
|
20
|
-
|
|
21
15
|
def set_declarative(self, declarative: Dict[str, Any] | None = None):
|
|
22
16
|
self.declarative = declarative or {}
|
|
23
17
|
return self
|
|
24
18
|
|
|
25
|
-
def set_procedural(self, procedural: Dict[str, Any] | None = None):
|
|
26
|
-
self.procedural = procedural or {}
|
|
27
|
-
return self
|
|
28
|
-
|
|
29
19
|
def build(self):
|
|
30
20
|
memory = Memory()
|
|
31
|
-
memory.episodic = self.episodic
|
|
32
21
|
memory.declarative = self.declarative
|
|
33
|
-
memory.procedural = self.procedural
|
|
34
22
|
|
|
35
23
|
return memory
|
|
36
24
|
|
|
@@ -9,7 +9,6 @@ class WhyBuilder(BaseBuilder):
|
|
|
9
9
|
self.input: str | None = None
|
|
10
10
|
self.intermediate_steps: Dict[str, Any] | None = None
|
|
11
11
|
self.memory: Memory | None = None
|
|
12
|
-
self.model_interactions: Dict[str, Any] | None = None
|
|
13
12
|
|
|
14
13
|
@staticmethod
|
|
15
14
|
def create() -> "WhyBuilder":
|
|
@@ -27,14 +26,9 @@ class WhyBuilder(BaseBuilder):
|
|
|
27
26
|
self.memory = memory
|
|
28
27
|
return self
|
|
29
28
|
|
|
30
|
-
def set_model_interactions(self, model_interactions: Dict[str, Any] | None = None) -> "WhyBuilder":
|
|
31
|
-
self.model_interactions = model_interactions
|
|
32
|
-
return self
|
|
33
|
-
|
|
34
29
|
def build(self) -> Why:
|
|
35
30
|
return Why(
|
|
36
31
|
input=self.input,
|
|
37
32
|
intermediate_steps=self.intermediate_steps,
|
|
38
33
|
memory=self.memory,
|
|
39
|
-
model_interactions=self.model_interactions,
|
|
40
34
|
)
|
cheshirecat_python_sdk/client.py
CHANGED
|
@@ -2,8 +2,11 @@ from cheshirecat_python_sdk.clients import HttpClient, WSClient
|
|
|
2
2
|
from cheshirecat_python_sdk.configuration import Configuration
|
|
3
3
|
from cheshirecat_python_sdk.endpoints import (
|
|
4
4
|
AdminsEndpoint,
|
|
5
|
+
AuthEndpoint,
|
|
5
6
|
AuthHandlerEndpoint,
|
|
6
7
|
ChunkerEndpoint,
|
|
8
|
+
ConversationEndpoint,
|
|
9
|
+
CustomEndpoint,
|
|
7
10
|
EmbedderEndpoint,
|
|
8
11
|
FileManagerEndpoint,
|
|
9
12
|
LargeLanguageModelEndpoint,
|
|
@@ -11,8 +14,10 @@ from cheshirecat_python_sdk.endpoints import (
|
|
|
11
14
|
MessageEndpoint,
|
|
12
15
|
PluginsEndpoint,
|
|
13
16
|
RabbitHoleEndpoint,
|
|
14
|
-
SettingsEndpoint,
|
|
15
17
|
UsersEndpoint,
|
|
18
|
+
UtilsEndpoint,
|
|
19
|
+
VectorDatabaseEndpoint,
|
|
20
|
+
HealthCheckEndpoint,
|
|
16
21
|
)
|
|
17
22
|
|
|
18
23
|
|
|
@@ -51,6 +56,10 @@ class CheshireCatClient:
|
|
|
51
56
|
def admins(self):
|
|
52
57
|
return AdminsEndpoint(self)
|
|
53
58
|
|
|
59
|
+
@property
|
|
60
|
+
def auth(self):
|
|
61
|
+
return AuthEndpoint(self)
|
|
62
|
+
|
|
54
63
|
@property
|
|
55
64
|
def auth_handler(self):
|
|
56
65
|
return AuthHandlerEndpoint(self)
|
|
@@ -59,6 +68,10 @@ class CheshireCatClient:
|
|
|
59
68
|
def chunker(self):
|
|
60
69
|
return ChunkerEndpoint(self)
|
|
61
70
|
|
|
71
|
+
@property
|
|
72
|
+
def conversation(self):
|
|
73
|
+
return ConversationEndpoint(self)
|
|
74
|
+
|
|
62
75
|
@property
|
|
63
76
|
def embedder(self):
|
|
64
77
|
return EmbedderEndpoint(self)
|
|
@@ -87,10 +100,22 @@ class CheshireCatClient:
|
|
|
87
100
|
def rabbit_hole(self):
|
|
88
101
|
return RabbitHoleEndpoint(self)
|
|
89
102
|
|
|
90
|
-
@property
|
|
91
|
-
def settings(self):
|
|
92
|
-
return SettingsEndpoint(self)
|
|
93
|
-
|
|
94
103
|
@property
|
|
95
104
|
def users(self):
|
|
96
105
|
return UsersEndpoint(self)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def utils(self):
|
|
109
|
+
return UtilsEndpoint(self)
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def custom(self):
|
|
113
|
+
return CustomEndpoint(self)
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def vector_database(self):
|
|
117
|
+
return VectorDatabaseEndpoint(self)
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def health_check(self):
|
|
121
|
+
return HealthCheckEndpoint(self)
|
|
@@ -15,8 +15,9 @@ class HttpClient:
|
|
|
15
15
|
self.port = port
|
|
16
16
|
self.apikey = apikey
|
|
17
17
|
self.token = None
|
|
18
|
-
self.user_id = None
|
|
19
18
|
self.agent_id = None
|
|
19
|
+
self.user_id = None
|
|
20
|
+
self.chat_id = None
|
|
20
21
|
self.is_https = is_https
|
|
21
22
|
self.headers = {}
|
|
22
23
|
|
|
@@ -38,27 +39,40 @@ class HttpClient:
|
|
|
38
39
|
def __before_secure_request(self):
|
|
39
40
|
if self.apikey:
|
|
40
41
|
self.headers["Authorization"] = f"Bearer {self.apikey}"
|
|
41
|
-
if self.user_id:
|
|
42
|
-
self.headers["user_id"] = self.user_id
|
|
43
42
|
if self.agent_id:
|
|
44
|
-
self.headers["
|
|
43
|
+
self.headers["X-Agent-ID"] = self.agent_id
|
|
44
|
+
if self.user_id:
|
|
45
|
+
self.headers["X-User-ID"] = self.user_id
|
|
46
|
+
if self.chat_id:
|
|
47
|
+
self.headers["X-Chat-ID"] = self.chat_id
|
|
45
48
|
|
|
46
49
|
def __before_jwt_request(self):
|
|
47
50
|
if self.token:
|
|
48
51
|
self.headers["Authorization"] = f"Bearer {self.token}"
|
|
49
52
|
if self.agent_id:
|
|
50
|
-
self.headers["
|
|
53
|
+
self.headers["X-Agent-ID"] = self.agent_id
|
|
54
|
+
if self.chat_id:
|
|
55
|
+
self.headers["X-Chat-ID"] = self.chat_id
|
|
51
56
|
|
|
52
|
-
def get_client(
|
|
57
|
+
def get_client(
|
|
58
|
+
self,
|
|
59
|
+
agent_id: str | None = None,
|
|
60
|
+
user_id: str | None = None,
|
|
61
|
+
chat_id: str | None = None,
|
|
62
|
+
) -> BaseUrlSession:
|
|
53
63
|
if not self.apikey and not self.token:
|
|
54
64
|
raise ValueError("You must provide an apikey or a token")
|
|
55
65
|
|
|
56
|
-
self.agent_id = agent_id
|
|
66
|
+
self.agent_id = agent_id
|
|
57
67
|
self.user_id = user_id
|
|
68
|
+
self.chat_id = chat_id
|
|
58
69
|
|
|
59
70
|
for middleware in self.middlewares:
|
|
60
71
|
middleware()
|
|
61
72
|
|
|
73
|
+
return self.get_base_session()
|
|
74
|
+
|
|
75
|
+
def get_base_session(self) -> BaseUrlSession:
|
|
62
76
|
session = BaseUrlSession(base_url=self.get_http_uri())
|
|
63
77
|
session.headers = self.headers
|
|
64
78
|
|
|
@@ -22,31 +22,37 @@ class WSClient:
|
|
|
22
22
|
self.token = token
|
|
23
23
|
return self
|
|
24
24
|
|
|
25
|
-
def get_ws_uri(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
raise ValueError("You must provide an apikey or a token")
|
|
33
|
-
|
|
34
|
-
if user_id:
|
|
35
|
-
query["user_id"] = user_id
|
|
25
|
+
def get_ws_uri(
|
|
26
|
+
self,
|
|
27
|
+
agent_id: str,
|
|
28
|
+
user_id: str,
|
|
29
|
+
chat_id: str | None = None,
|
|
30
|
+
) -> str:
|
|
31
|
+
query = {"user_id": user_id}
|
|
36
32
|
|
|
37
33
|
scheme = "wss" if self.is_wss else "ws"
|
|
38
|
-
path = f"ws/{agent_id}"
|
|
34
|
+
path = f"ws/{agent_id}"
|
|
35
|
+
if chat_id:
|
|
36
|
+
path += f"/{chat_id}"
|
|
37
|
+
|
|
39
38
|
query_string = urlencode(query)
|
|
40
39
|
port_suffix = f":{self.port}" if self.port else ""
|
|
41
40
|
|
|
42
41
|
return f"{scheme}://{self.host}{port_suffix}/{path}?{query_string}"
|
|
43
42
|
|
|
44
|
-
async def get_client(self, agent_id: str
|
|
45
|
-
uri = self.get_ws_uri(agent_id, user_id)
|
|
43
|
+
async def get_client(self, agent_id: str, user_id: str, chat_id: str | None = None) -> ClientConnection:
|
|
44
|
+
uri = self.get_ws_uri(agent_id, user_id, chat_id)
|
|
46
45
|
if self.ws_client is None:
|
|
47
46
|
try:
|
|
47
|
+
if self.token:
|
|
48
|
+
headers = {"Authorization": f"Bearer {self.token}"}
|
|
49
|
+
elif self.apikey:
|
|
50
|
+
headers = {"Authorization": f"Bearer {self.apikey}"}
|
|
51
|
+
else:
|
|
52
|
+
raise ValueError("You must provide an apikey or a token")
|
|
53
|
+
|
|
48
54
|
# Create a WebSocket connection
|
|
49
|
-
websocket = await connect(uri, ping_interval=100000, ping_timeout=100000)
|
|
55
|
+
websocket = await connect(uri, ping_interval=100000, ping_timeout=100000, additional_headers=headers)
|
|
50
56
|
self.ws_client = websocket
|
|
51
57
|
except InvalidURI as e:
|
|
52
58
|
raise ValueError(f"Invalid WebSocket URI: {uri}") from e
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
from cheshirecat_python_sdk.endpoints.admins import AdminsEndpoint
|
|
2
|
+
from cheshirecat_python_sdk.endpoints.auth import AuthEndpoint
|
|
2
3
|
from cheshirecat_python_sdk.endpoints.auth_handler import AuthHandlerEndpoint
|
|
3
4
|
from cheshirecat_python_sdk.endpoints.chunker import ChunkerEndpoint
|
|
5
|
+
from cheshirecat_python_sdk.endpoints.conversation import ConversationEndpoint
|
|
6
|
+
from cheshirecat_python_sdk.endpoints.custom_endpoint import CustomEndpoint
|
|
4
7
|
from cheshirecat_python_sdk.endpoints.embedder import EmbedderEndpoint
|
|
5
8
|
from cheshirecat_python_sdk.endpoints.file_manager import FileManagerEndpoint
|
|
6
9
|
from cheshirecat_python_sdk.endpoints.large_language_model import LargeLanguageModelEndpoint
|
|
@@ -8,5 +11,7 @@ from cheshirecat_python_sdk.endpoints.memory import MemoryEndpoint
|
|
|
8
11
|
from cheshirecat_python_sdk.endpoints.message import MessageEndpoint
|
|
9
12
|
from cheshirecat_python_sdk.endpoints.plugins import PluginsEndpoint
|
|
10
13
|
from cheshirecat_python_sdk.endpoints.rabbit_hole import RabbitHoleEndpoint
|
|
11
|
-
from cheshirecat_python_sdk.endpoints.settings import SettingsEndpoint
|
|
12
14
|
from cheshirecat_python_sdk.endpoints.users import UsersEndpoint
|
|
15
|
+
from cheshirecat_python_sdk.endpoints.utils import UtilsEndpoint
|
|
16
|
+
from cheshirecat_python_sdk.endpoints.vector_database import VectorDatabaseEndpoint
|
|
17
|
+
from cheshirecat_python_sdk.endpoints.health_check import HealthCheckEndpoint
|
|
@@ -3,16 +3,13 @@ from typing import List
|
|
|
3
3
|
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint, MultipartPayload
|
|
4
4
|
from cheshirecat_python_sdk.models.api.admins import (
|
|
5
5
|
AdminOutput,
|
|
6
|
-
ResetOutput,
|
|
7
|
-
CreatedOutput,
|
|
8
6
|
PluginInstallOutput,
|
|
9
7
|
PluginInstallFromRegistryOutput,
|
|
10
8
|
PluginDetailsOutput,
|
|
11
9
|
PluginDeleteOutput,
|
|
12
10
|
)
|
|
13
11
|
from cheshirecat_python_sdk.models.api.nested.plugins import PluginSettingsOutput
|
|
14
|
-
from cheshirecat_python_sdk.models.api.plugins import PluginCollectionOutput, PluginsSettingsOutput
|
|
15
|
-
from cheshirecat_python_sdk.models.api.tokens import TokenOutput
|
|
12
|
+
from cheshirecat_python_sdk.models.api.plugins import PluginCollectionOutput, PluginsSettingsOutput, PluginToggleOutput
|
|
16
13
|
from cheshirecat_python_sdk.utils import deserialize, file_attributes
|
|
17
14
|
|
|
18
15
|
|
|
@@ -21,22 +18,6 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
21
18
|
super().__init__(client)
|
|
22
19
|
self.prefix = "/admins"
|
|
23
20
|
|
|
24
|
-
def token(self, username: str, password: str) -> TokenOutput:
|
|
25
|
-
"""
|
|
26
|
-
This endpoint is used to get a token for the user. The token is used to authenticate the user in the system.
|
|
27
|
-
When the token expires, the user must request a new token.
|
|
28
|
-
:param username: The username of the user.
|
|
29
|
-
:param password: The password of the user.
|
|
30
|
-
:return: TokenOutput, the token of the user.
|
|
31
|
-
"""
|
|
32
|
-
response = self.get_http_client().post(
|
|
33
|
-
self.format_url("/auth/token"),
|
|
34
|
-
json={"username": username, "password": password},
|
|
35
|
-
)
|
|
36
|
-
result = deserialize(response.json(), TokenOutput)
|
|
37
|
-
self.client.add_token(result.access_token)
|
|
38
|
-
return result
|
|
39
|
-
|
|
40
21
|
def post_admin(self, username: str, password: str, permissions: dict | None = None) -> AdminOutput:
|
|
41
22
|
"""
|
|
42
23
|
Create a new admin user.
|
|
@@ -47,9 +28,9 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
47
28
|
"""
|
|
48
29
|
payload = {"username": username, "password": password}
|
|
49
30
|
if permissions:
|
|
50
|
-
payload["permissions"] = permissions
|
|
31
|
+
payload["permissions"] = permissions # type: ignore
|
|
51
32
|
|
|
52
|
-
return self.post_json(self.format_url("/users"), AdminOutput, payload
|
|
33
|
+
return self.post_json(self.format_url("/users"), self.system_id, output_class=AdminOutput, payload=payload)
|
|
53
34
|
|
|
54
35
|
def get_admins(self, limit: int | None = None, skip: int | None = None) -> List[AdminOutput]:
|
|
55
36
|
"""
|
|
@@ -65,6 +46,8 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
65
46
|
query["skip"] = skip
|
|
66
47
|
|
|
67
48
|
response = self.get_http_client(self.system_id).get(self.format_url("/users"), params=query)
|
|
49
|
+
response.raise_for_status()
|
|
50
|
+
|
|
68
51
|
result = []
|
|
69
52
|
for item in response.json():
|
|
70
53
|
result.append(deserialize(item, AdminOutput))
|
|
@@ -76,7 +59,7 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
76
59
|
:param admin_id: The ID of the user.
|
|
77
60
|
:return: AdminOutput, the details of the user.
|
|
78
61
|
"""
|
|
79
|
-
return self.get(self.format_url(f"/users/{admin_id}"),
|
|
62
|
+
return self.get(self.format_url(f"/users/{admin_id}"), self.system_id, output_class=AdminOutput)
|
|
80
63
|
|
|
81
64
|
def put_admin(
|
|
82
65
|
self,
|
|
@@ -101,7 +84,7 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
101
84
|
if permissions:
|
|
102
85
|
payload["permissions"] = permissions
|
|
103
86
|
|
|
104
|
-
return self.put(self.format_url(f"/users/{admin_id}"), AdminOutput, payload
|
|
87
|
+
return self.put(self.format_url(f"/users/{admin_id}"), self.system_id, output_class=AdminOutput, payload=payload)
|
|
105
88
|
|
|
106
89
|
def delete_admin(self, admin_id: str) -> AdminOutput:
|
|
107
90
|
"""
|
|
@@ -109,45 +92,7 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
109
92
|
:param admin_id: The ID of the user.
|
|
110
93
|
:return: AdminOutput, the details of the user.
|
|
111
94
|
"""
|
|
112
|
-
return self.delete(self.format_url(f"/users/{admin_id}"),
|
|
113
|
-
|
|
114
|
-
def post_factory_reset(self) -> ResetOutput:
|
|
115
|
-
"""
|
|
116
|
-
Reset the system to the factory settings.
|
|
117
|
-
:return: ResetOutput, the details of the reset.
|
|
118
|
-
"""
|
|
119
|
-
return self.post_json(self.format_url("/utils/factory/reset/"), ResetOutput, {}, self.system_id)
|
|
120
|
-
|
|
121
|
-
def get_agents(self) -> List[str]:
|
|
122
|
-
"""
|
|
123
|
-
Get a list of all agents.
|
|
124
|
-
:return: List[str], the IDs of the agents.
|
|
125
|
-
"""
|
|
126
|
-
return self.get(self.format_url("/utils/agents/"), None, agent_id=self.system_id)
|
|
127
|
-
|
|
128
|
-
def post_agent_create(self, agent_id: str | None = None) -> CreatedOutput:
|
|
129
|
-
"""
|
|
130
|
-
Create a new agent.
|
|
131
|
-
:param agent_id: The ID of the agent.
|
|
132
|
-
:return: CreatedOutput, the details of the agent.
|
|
133
|
-
"""
|
|
134
|
-
return self.post_json(self.format_url("/utils/agent/create/"), CreatedOutput, {}, agent_id)
|
|
135
|
-
|
|
136
|
-
def post_agent_reset(self, agent_id: str | None = None) -> ResetOutput:
|
|
137
|
-
"""
|
|
138
|
-
Reset an agent to the factory settings.
|
|
139
|
-
:param agent_id: The ID of the agent.
|
|
140
|
-
:return: ResetOutput, the details of the reset.
|
|
141
|
-
"""
|
|
142
|
-
return self.post_json(self.format_url("/utils/agent/reset/"), ResetOutput, {}, agent_id)
|
|
143
|
-
|
|
144
|
-
def post_agent_destroy(self, agent_id: str | None = None) -> ResetOutput:
|
|
145
|
-
"""
|
|
146
|
-
Destroy an agent.
|
|
147
|
-
:param agent_id: The ID of the agent.
|
|
148
|
-
:return: ResetOutput, the details of the reset.
|
|
149
|
-
"""
|
|
150
|
-
return self.post_json(self.format_url("/utils/agent/destroy/"), ResetOutput, {}, agent_id)
|
|
95
|
+
return self.delete(self.format_url(f"/users/{admin_id}"), self.system_id, output_class=AdminOutput)
|
|
151
96
|
|
|
152
97
|
def get_available_plugins(self, plugin_name: str | None = None) -> PluginCollectionOutput:
|
|
153
98
|
"""
|
|
@@ -157,8 +102,8 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
157
102
|
"""
|
|
158
103
|
return self.get(
|
|
159
104
|
self.format_url("/plugins"),
|
|
160
|
-
PluginCollectionOutput,
|
|
161
105
|
self.system_id,
|
|
106
|
+
output_class=PluginCollectionOutput,
|
|
162
107
|
query={"query": plugin_name} if plugin_name else None,
|
|
163
108
|
)
|
|
164
109
|
|
|
@@ -168,7 +113,10 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
168
113
|
with open(path_zip, "rb") as file:
|
|
169
114
|
payload.files = [("file", file_attributes(path_zip, file))]
|
|
170
115
|
result = self.post_multipart(
|
|
171
|
-
self.format_url("/plugins/upload"),
|
|
116
|
+
self.format_url("/plugins/upload"),
|
|
117
|
+
self.system_id,
|
|
118
|
+
output_class=PluginInstallOutput,
|
|
119
|
+
payload=payload,
|
|
172
120
|
)
|
|
173
121
|
return result
|
|
174
122
|
|
|
@@ -178,14 +126,19 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
178
126
|
:param url: The URL of the plugin.
|
|
179
127
|
:return: PluginInstallFromRegistryOutput, the details of the installation.
|
|
180
128
|
"""
|
|
181
|
-
return self.post_json(
|
|
129
|
+
return self.post_json(
|
|
130
|
+
self.format_url("/plugins/upload/registry"),
|
|
131
|
+
self.system_id,
|
|
132
|
+
output_class=PluginInstallFromRegistryOutput,
|
|
133
|
+
payload={"url": url},
|
|
134
|
+
)
|
|
182
135
|
|
|
183
136
|
def get_plugins_settings(self) -> PluginsSettingsOutput:
|
|
184
137
|
"""
|
|
185
138
|
Get the default settings of all the plugins.
|
|
186
139
|
:return: PluginsSettingsOutput, the details of the settings.
|
|
187
140
|
"""
|
|
188
|
-
return self.get(self.format_url("/plugins/settings"),
|
|
141
|
+
return self.get(self.format_url("/plugins/settings"), self.system_id, output_class=PluginsSettingsOutput)
|
|
189
142
|
|
|
190
143
|
def get_plugin_settings(self, plugin_id: str) -> PluginSettingsOutput:
|
|
191
144
|
"""
|
|
@@ -193,7 +146,9 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
193
146
|
:param plugin_id: The ID of the plugin.
|
|
194
147
|
:return: PluginSettingsOutput, the details of the settings.
|
|
195
148
|
"""
|
|
196
|
-
return self.get(
|
|
149
|
+
return self.get(
|
|
150
|
+
self.format_url(f"/plugins/settings/{plugin_id}"), self.system_id, output_class=PluginSettingsOutput
|
|
151
|
+
)
|
|
197
152
|
|
|
198
153
|
def get_plugin_details(self, plugin_id: str) -> PluginDetailsOutput:
|
|
199
154
|
"""
|
|
@@ -201,7 +156,7 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
201
156
|
:param plugin_id: The ID of the plugin.
|
|
202
157
|
:return: PluginDetailsOutput, the details of the plugin.
|
|
203
158
|
"""
|
|
204
|
-
return self.get(self.format_url(f"/plugins/{plugin_id}"),
|
|
159
|
+
return self.get(self.format_url(f"/plugins/{plugin_id}"), self.system_id, output_class=PluginDetailsOutput)
|
|
205
160
|
|
|
206
161
|
def delete_plugin(self, plugin_id: str) -> PluginDeleteOutput:
|
|
207
162
|
"""
|
|
@@ -209,4 +164,16 @@ class AdminsEndpoint(AbstractEndpoint):
|
|
|
209
164
|
:param plugin_id: The ID of the plugin.
|
|
210
165
|
:return: PluginDeleteOutput, the details of the plugin.
|
|
211
166
|
"""
|
|
212
|
-
return self.delete(self.format_url(f"/plugins/{plugin_id}"),
|
|
167
|
+
return self.delete(self.format_url(f"/plugins/{plugin_id}"), self.system_id, output_class=PluginDeleteOutput)
|
|
168
|
+
|
|
169
|
+
def put_toggle_plugin(self, plugin_id: str) -> PluginToggleOutput:
|
|
170
|
+
"""
|
|
171
|
+
This endpoint toggles a plugin, on a system level
|
|
172
|
+
:param plugin_id: The id of the plugin to toggle
|
|
173
|
+
:return: PluginToggleOutput, the toggled plugin
|
|
174
|
+
"""
|
|
175
|
+
return self.put(
|
|
176
|
+
self.format_url(f"/plugins/toggle/{plugin_id}"),
|
|
177
|
+
self.system_id,
|
|
178
|
+
output_class=PluginToggleOutput,
|
|
179
|
+
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from cheshirecat_python_sdk.endpoints.base import AbstractEndpoint
|
|
4
|
+
from cheshirecat_python_sdk.models.api.tokens import TokenOutput, MeOutput
|
|
5
|
+
from cheshirecat_python_sdk.utils import deserialize
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AuthEndpoint(AbstractEndpoint):
|
|
9
|
+
def __init__(self, client: "CheshireCatClient"):
|
|
10
|
+
super().__init__(client)
|
|
11
|
+
self.prefix = "/auth"
|
|
12
|
+
|
|
13
|
+
def token(self, username: str, password: str) -> TokenOutput:
|
|
14
|
+
"""
|
|
15
|
+
This endpoint is used to get a token for the user. The token is used to authenticate the user in the system. When
|
|
16
|
+
the token expires, the user must request a new token.
|
|
17
|
+
"""
|
|
18
|
+
response = self.get_http_session().post(
|
|
19
|
+
self.format_url("/token"),
|
|
20
|
+
json={
|
|
21
|
+
"username": username,
|
|
22
|
+
"password": password,
|
|
23
|
+
},
|
|
24
|
+
)
|
|
25
|
+
response.raise_for_status()
|
|
26
|
+
|
|
27
|
+
result = deserialize(response.json(), TokenOutput)
|
|
28
|
+
self.client.add_token(result.access_token)
|
|
29
|
+
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def get_available_permissions(self) -> dict[int | str, Any]:
|
|
33
|
+
"""
|
|
34
|
+
This endpoint is used to get a list of available permissions in the system. The permissions are used to define
|
|
35
|
+
the access rights of the users in the system. The permissions are defined by the system administrator.
|
|
36
|
+
:return array<int|string, Any>, the available permissions
|
|
37
|
+
"""
|
|
38
|
+
response = self.get_http_client().get(self.format_url("/available-permissions"))
|
|
39
|
+
response.raise_for_status()
|
|
40
|
+
|
|
41
|
+
return response.json()
|
|
42
|
+
|
|
43
|
+
def me(self, token: str) -> MeOutput:
|
|
44
|
+
"""
|
|
45
|
+
This endpoint is used to get the current user information. The user information includes the list of agents
|
|
46
|
+
the user has access to. This endpoint requires authentication.
|
|
47
|
+
"""
|
|
48
|
+
self.client.add_token(token)
|
|
49
|
+
|
|
50
|
+
response = self.get_http_client().get("/me")
|
|
51
|
+
response.raise_for_status()
|
|
52
|
+
|
|
53
|
+
result = deserialize(response.json(), MeOutput)
|
|
54
|
+
return result
|
|
@@ -9,7 +9,7 @@ class AuthHandlerEndpoint(AbstractEndpoint):
|
|
|
9
9
|
super().__init__(client)
|
|
10
10
|
self.prefix = "/auth_handler"
|
|
11
11
|
|
|
12
|
-
def get_auth_handlers_settings(self, agent_id: str
|
|
12
|
+
def get_auth_handlers_settings(self, agent_id: str) -> FactoryObjectSettingsOutput:
|
|
13
13
|
"""
|
|
14
14
|
Get all auth handler settings for the agent with the given ID.
|
|
15
15
|
:param agent_id: The ID of the agent.
|
|
@@ -17,11 +17,11 @@ class AuthHandlerEndpoint(AbstractEndpoint):
|
|
|
17
17
|
"""
|
|
18
18
|
return self.get(
|
|
19
19
|
self.format_url("/settings"),
|
|
20
|
-
FactoryObjectSettingsOutput,
|
|
21
20
|
agent_id,
|
|
21
|
+
output_class=FactoryObjectSettingsOutput,
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
-
def get_auth_handler_settings(self, auth_handler: str, agent_id: str
|
|
24
|
+
def get_auth_handler_settings(self, auth_handler: str, agent_id: str) -> FactoryObjectSettingOutput:
|
|
25
25
|
"""
|
|
26
26
|
Get the settings for the auth handler with the given name.
|
|
27
27
|
:param auth_handler: The name of the auth handler.
|
|
@@ -30,23 +30,23 @@ class AuthHandlerEndpoint(AbstractEndpoint):
|
|
|
30
30
|
"""
|
|
31
31
|
return self.get(
|
|
32
32
|
self.format_url(f"/settings/{auth_handler}"),
|
|
33
|
-
FactoryObjectSettingOutput,
|
|
34
33
|
agent_id,
|
|
34
|
+
output_class=FactoryObjectSettingOutput,
|
|
35
35
|
)
|
|
36
36
|
|
|
37
37
|
def put_auth_handler_settings(
|
|
38
|
-
self, auth_handler: str, values: Dict[str, Any]
|
|
38
|
+
self, auth_handler: str, agent_id: str, values: Dict[str, Any]
|
|
39
39
|
) -> FactoryObjectSettingOutput:
|
|
40
40
|
"""
|
|
41
41
|
Update the settings for the auth handler with the given name.
|
|
42
42
|
:param auth_handler: The name of the auth handler.
|
|
43
|
-
:param values: The new settings for the auth handler.
|
|
44
43
|
:param agent_id: The ID of the agent.
|
|
44
|
+
:param values: The new settings for the auth handler.
|
|
45
45
|
:return: FactoryObjectSettingOutput, containing the updated settings for the auth handler.
|
|
46
46
|
"""
|
|
47
47
|
return self.put(
|
|
48
48
|
self.format_url(f"/settings/{auth_handler}"),
|
|
49
|
-
FactoryObjectSettingOutput,
|
|
50
|
-
values,
|
|
51
49
|
agent_id,
|
|
50
|
+
output_class=FactoryObjectSettingOutput,
|
|
51
|
+
payload=values,
|
|
52
52
|
)
|