blaxel 0.64.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.
- blaxel/__init__.py +8 -0
- blaxel/agents/__init__.py +5 -0
- blaxel/agents/chain.py +153 -0
- blaxel/agents/chat.py +286 -0
- blaxel/agents/decorator.py +208 -0
- blaxel/agents/thread.py +24 -0
- blaxel/agents/voice/openai.py +255 -0
- blaxel/agents/voice/utils.py +25 -0
- blaxel/api/__init__.py +1 -0
- blaxel/api/agents/__init__.py +0 -0
- blaxel/api/agents/create_agent.py +155 -0
- blaxel/api/agents/delete_agent.py +146 -0
- blaxel/api/agents/get_agent.py +146 -0
- blaxel/api/agents/get_agent_logs.py +151 -0
- blaxel/api/agents/get_agent_metrics.py +150 -0
- blaxel/api/agents/get_agent_trace_ids.py +201 -0
- blaxel/api/agents/list_agent_revisions.py +155 -0
- blaxel/api/agents/list_agents.py +127 -0
- blaxel/api/agents/update_agent.py +168 -0
- blaxel/api/configurations/__init__.py +0 -0
- blaxel/api/configurations/get_configuration.py +122 -0
- blaxel/api/default/__init__.py +0 -0
- blaxel/api/default/get_trace.py +150 -0
- blaxel/api/default/get_trace_ids.py +218 -0
- blaxel/api/default/get_trace_logs.py +186 -0
- blaxel/api/default/list_mcp_hub_definitions.py +127 -0
- blaxel/api/functions/__init__.py +0 -0
- blaxel/api/functions/create_function.py +155 -0
- blaxel/api/functions/delete_function.py +146 -0
- blaxel/api/functions/get_function.py +146 -0
- blaxel/api/functions/get_function_logs.py +151 -0
- blaxel/api/functions/get_function_metrics.py +150 -0
- blaxel/api/functions/get_function_trace_ids.py +201 -0
- blaxel/api/functions/list_function_revisions.py +158 -0
- blaxel/api/functions/list_functions.py +131 -0
- blaxel/api/functions/update_function.py +168 -0
- blaxel/api/integrations/__init__.py +0 -0
- blaxel/api/integrations/create_integration_connection.py +167 -0
- blaxel/api/integrations/delete_integration_connection.py +158 -0
- blaxel/api/integrations/get_integration.py +97 -0
- blaxel/api/integrations/get_integration_connection.py +158 -0
- blaxel/api/integrations/get_integration_connection_model.py +104 -0
- blaxel/api/integrations/get_integration_connection_model_endpoint_configurations.py +97 -0
- blaxel/api/integrations/list_integration_connection_models.py +97 -0
- blaxel/api/integrations/list_integration_connections.py +139 -0
- blaxel/api/integrations/update_integration_connection.py +180 -0
- blaxel/api/invitations/__init__.py +0 -0
- blaxel/api/invitations/list_all_pending_invitations.py +142 -0
- blaxel/api/knowledgebases/__init__.py +0 -0
- blaxel/api/knowledgebases/create_knowledgebase.py +163 -0
- blaxel/api/knowledgebases/delete_knowledgebase.py +154 -0
- blaxel/api/knowledgebases/get_knowledgebase.py +154 -0
- blaxel/api/knowledgebases/list_knowledgebase_revisions.py +158 -0
- blaxel/api/knowledgebases/list_knowledgebases.py +139 -0
- blaxel/api/knowledgebases/update_knowledgebase.py +176 -0
- blaxel/api/locations/__init__.py +0 -0
- blaxel/api/locations/list_locations.py +139 -0
- blaxel/api/metrics/__init__.py +0 -0
- blaxel/api/metrics/get_metrics.py +130 -0
- blaxel/api/models/__init__.py +0 -0
- blaxel/api/models/create_model.py +163 -0
- blaxel/api/models/delete_model.py +154 -0
- blaxel/api/models/get_model.py +154 -0
- blaxel/api/models/get_model_logs.py +155 -0
- blaxel/api/models/get_model_metrics.py +158 -0
- blaxel/api/models/get_model_trace_ids.py +201 -0
- blaxel/api/models/list_model_revisions.py +158 -0
- blaxel/api/models/list_models.py +135 -0
- blaxel/api/models/update_model.py +176 -0
- blaxel/api/policies/__init__.py +0 -0
- blaxel/api/policies/create_policy.py +167 -0
- blaxel/api/policies/delete_policy.py +154 -0
- blaxel/api/policies/get_policy.py +154 -0
- blaxel/api/policies/list_policies.py +139 -0
- blaxel/api/policies/update_policy.py +180 -0
- blaxel/api/privateclusters/__init__.py +0 -0
- blaxel/api/privateclusters/create_private_cluster.py +132 -0
- blaxel/api/privateclusters/delete_private_cluster.py +156 -0
- blaxel/api/privateclusters/get_private_cluster.py +159 -0
- blaxel/api/privateclusters/get_private_cluster_health.py +97 -0
- blaxel/api/privateclusters/list_private_clusters.py +140 -0
- blaxel/api/privateclusters/update_private_cluster.py +156 -0
- blaxel/api/privateclusters/update_private_cluster_health.py +97 -0
- blaxel/api/service_accounts/__init__.py +0 -0
- blaxel/api/service_accounts/create_api_key_for_service_account.py +177 -0
- blaxel/api/service_accounts/create_workspace_service_account.py +170 -0
- blaxel/api/service_accounts/delete_api_key_for_service_account.py +104 -0
- blaxel/api/service_accounts/delete_workspace_service_account.py +160 -0
- blaxel/api/service_accounts/get_workspace_service_accounts.py +141 -0
- blaxel/api/service_accounts/list_api_keys_for_service_account.py +163 -0
- blaxel/api/service_accounts/update_workspace_service_account.py +183 -0
- blaxel/api/store/__init__.py +0 -0
- blaxel/api/store/get_store_agent.py +146 -0
- blaxel/api/store/get_store_function.py +146 -0
- blaxel/api/store/list_store_agents.py +131 -0
- blaxel/api/store/list_store_functions.py +131 -0
- blaxel/api/workspaces/__init__.py +0 -0
- blaxel/api/workspaces/accept_workspace_invitation.py +161 -0
- blaxel/api/workspaces/create_worspace.py +163 -0
- blaxel/api/workspaces/decline_workspace_invitation.py +158 -0
- blaxel/api/workspaces/delete_workspace.py +154 -0
- blaxel/api/workspaces/get_workspace.py +154 -0
- blaxel/api/workspaces/invite_workspace_user.py +174 -0
- blaxel/api/workspaces/leave_workspace.py +161 -0
- blaxel/api/workspaces/list_workspace_users.py +139 -0
- blaxel/api/workspaces/list_workspaces.py +139 -0
- blaxel/api/workspaces/remove_workspace_user.py +101 -0
- blaxel/api/workspaces/update_workspace.py +176 -0
- blaxel/api/workspaces/update_workspace_user_role.py +187 -0
- blaxel/authentication/__init__.py +45 -0
- blaxel/authentication/apikey.py +50 -0
- blaxel/authentication/authentication.py +176 -0
- blaxel/authentication/clientcredentials.py +103 -0
- blaxel/authentication/credentials.py +295 -0
- blaxel/authentication/device_mode.py +197 -0
- blaxel/client.py +281 -0
- blaxel/common/__init__.py +17 -0
- blaxel/common/error.py +27 -0
- blaxel/common/instrumentation.py +317 -0
- blaxel/common/logger.py +60 -0
- blaxel/common/secrets.py +39 -0
- blaxel/common/settings.py +150 -0
- blaxel/common/slugify.py +18 -0
- blaxel/common/utils.py +34 -0
- blaxel/deploy/__init__.py +8 -0
- blaxel/deploy/deploy.py +316 -0
- blaxel/deploy/format.py +46 -0
- blaxel/deploy/parser.py +192 -0
- blaxel/errors.py +16 -0
- blaxel/functions/__init__.py +7 -0
- blaxel/functions/common.py +228 -0
- blaxel/functions/decorator.py +64 -0
- blaxel/functions/local/local.py +48 -0
- blaxel/functions/mcp/client.py +96 -0
- blaxel/functions/mcp/mcp.py +168 -0
- blaxel/functions/mcp/utils.py +56 -0
- blaxel/functions/remote/remote.py +183 -0
- blaxel/models/__init__.py +233 -0
- blaxel/models/acl.py +133 -0
- blaxel/models/agent.py +126 -0
- blaxel/models/agent_chain.py +88 -0
- blaxel/models/agent_spec.py +346 -0
- blaxel/models/api_key.py +142 -0
- blaxel/models/configuration.py +85 -0
- blaxel/models/continent.py +70 -0
- blaxel/models/core_event.py +97 -0
- blaxel/models/core_spec.py +249 -0
- blaxel/models/core_spec_configurations.py +77 -0
- blaxel/models/country.py +70 -0
- blaxel/models/create_api_key_for_service_account_body.py +69 -0
- blaxel/models/create_workspace_service_account_body.py +71 -0
- blaxel/models/create_workspace_service_account_response_200.py +105 -0
- blaxel/models/delete_workspace_service_account_response_200.py +96 -0
- blaxel/models/entrypoint.py +96 -0
- blaxel/models/entrypoint_env.py +45 -0
- blaxel/models/flavor.py +70 -0
- blaxel/models/form.py +120 -0
- blaxel/models/form_config.py +45 -0
- blaxel/models/form_oauthomitempty.py +45 -0
- blaxel/models/form_secrets.py +45 -0
- blaxel/models/function.py +126 -0
- blaxel/models/function_kit.py +97 -0
- blaxel/models/function_spec.py +310 -0
- blaxel/models/get_trace_ids_response_200.py +45 -0
- blaxel/models/get_trace_logs_response_200.py +45 -0
- blaxel/models/get_trace_response_200.py +45 -0
- blaxel/models/get_workspace_service_accounts_response_200_item.py +96 -0
- blaxel/models/histogram_bucket.py +79 -0
- blaxel/models/histogram_stats.py +88 -0
- blaxel/models/integration_connection.py +96 -0
- blaxel/models/integration_connection_spec.py +114 -0
- blaxel/models/integration_connection_spec_config.py +45 -0
- blaxel/models/integration_connection_spec_secret.py +45 -0
- blaxel/models/integration_model.py +162 -0
- blaxel/models/integration_repository.py +88 -0
- blaxel/models/invite_workspace_user_body.py +60 -0
- blaxel/models/knowledgebase.py +126 -0
- blaxel/models/knowledgebase_spec.py +163 -0
- blaxel/models/knowledgebase_spec_options.py +45 -0
- blaxel/models/last_n_requests_metric.py +79 -0
- blaxel/models/latency_metric.py +144 -0
- blaxel/models/location_response.py +113 -0
- blaxel/models/mcp_definition.py +188 -0
- blaxel/models/mcp_definition_entrypoint.py +45 -0
- blaxel/models/mcp_definition_form.py +45 -0
- blaxel/models/metadata.py +139 -0
- blaxel/models/metadata_labels.py +45 -0
- blaxel/models/metric.py +79 -0
- blaxel/models/metrics.py +169 -0
- blaxel/models/metrics_models.py +45 -0
- blaxel/models/metrics_request_total_per_code.py +45 -0
- blaxel/models/metrics_rps_per_code.py +45 -0
- blaxel/models/model.py +126 -0
- blaxel/models/model_private_cluster.py +79 -0
- blaxel/models/model_spec.py +249 -0
- blaxel/models/o_auth.py +72 -0
- blaxel/models/owner_fields.py +70 -0
- blaxel/models/pending_invitation.py +124 -0
- blaxel/models/pending_invitation_accept.py +85 -0
- blaxel/models/pending_invitation_render.py +147 -0
- blaxel/models/pending_invitation_render_invited_by.py +88 -0
- blaxel/models/pending_invitation_render_workspace.py +70 -0
- blaxel/models/pending_invitation_workspace_details.py +72 -0
- blaxel/models/pod_template_spec.py +45 -0
- blaxel/models/policy.py +96 -0
- blaxel/models/policy_location.py +70 -0
- blaxel/models/policy_max_tokens.py +106 -0
- blaxel/models/policy_spec.py +151 -0
- blaxel/models/private_cluster.py +183 -0
- blaxel/models/private_location.py +61 -0
- blaxel/models/repository.py +70 -0
- blaxel/models/request_duration_over_time_metric.py +97 -0
- blaxel/models/request_duration_over_time_metrics.py +80 -0
- blaxel/models/request_total_by_origin_metric.py +115 -0
- blaxel/models/request_total_by_origin_metric_request_total_by_origin.py +45 -0
- blaxel/models/request_total_by_origin_metric_request_total_by_origin_and_code.py +45 -0
- blaxel/models/request_total_metric.py +123 -0
- blaxel/models/request_total_metric_request_total_per_code.py +45 -0
- blaxel/models/request_total_metric_rps_per_code.py +45 -0
- blaxel/models/resource_log.py +79 -0
- blaxel/models/resource_metrics.py +270 -0
- blaxel/models/resource_metrics_request_total_per_code.py +45 -0
- blaxel/models/resource_metrics_rps_per_code.py +45 -0
- blaxel/models/revision_configuration.py +97 -0
- blaxel/models/revision_metadata.py +124 -0
- blaxel/models/runtime.py +196 -0
- blaxel/models/runtime_startup_probe.py +45 -0
- blaxel/models/serverless_config.py +80 -0
- blaxel/models/spec_configuration.py +70 -0
- blaxel/models/store_agent.py +178 -0
- blaxel/models/store_agent_labels.py +45 -0
- blaxel/models/store_configuration.py +151 -0
- blaxel/models/store_configuration_option.py +79 -0
- blaxel/models/store_function.py +211 -0
- blaxel/models/store_function_kit.py +97 -0
- blaxel/models/store_function_labels.py +45 -0
- blaxel/models/store_function_parameter.py +88 -0
- blaxel/models/time_fields.py +70 -0
- blaxel/models/token_rate_metric.py +88 -0
- blaxel/models/token_rate_metrics.py +120 -0
- blaxel/models/token_total_metric.py +106 -0
- blaxel/models/trace_ids_response.py +45 -0
- blaxel/models/update_workspace_service_account_body.py +69 -0
- blaxel/models/update_workspace_service_account_response_200.py +96 -0
- blaxel/models/update_workspace_user_role_body.py +60 -0
- blaxel/models/websocket_channel.py +88 -0
- blaxel/models/workspace.py +148 -0
- blaxel/models/workspace_labels.py +45 -0
- blaxel/models/workspace_user.py +115 -0
- blaxel/py.typed +1 -0
- blaxel/run.py +108 -0
- blaxel/serve/app.py +131 -0
- blaxel/serve/middlewares/__init__.py +10 -0
- blaxel/serve/middlewares/accesslog.py +32 -0
- blaxel/serve/middlewares/processtime.py +28 -0
- blaxel/types.py +46 -0
- blaxel-0.64.0.dist-info/METADATA +96 -0
- blaxel-0.64.0.dist-info/RECORD +261 -0
- blaxel-0.64.0.dist-info/WHEEL +4 -0
- blaxel-0.64.0.dist-info/entry_points.txt +2 -0
- blaxel-0.64.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,176 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...models.workspace import Workspace
|
9
|
+
from ...types import Response
|
10
|
+
|
11
|
+
|
12
|
+
def _get_kwargs(
|
13
|
+
workspace_name: str,
|
14
|
+
*,
|
15
|
+
body: Workspace,
|
16
|
+
) -> dict[str, Any]:
|
17
|
+
headers: dict[str, Any] = {}
|
18
|
+
|
19
|
+
_kwargs: dict[str, Any] = {
|
20
|
+
"method": "put",
|
21
|
+
"url": f"/workspaces/{workspace_name}",
|
22
|
+
}
|
23
|
+
|
24
|
+
_body = body.to_dict()
|
25
|
+
|
26
|
+
_kwargs["json"] = _body
|
27
|
+
headers["Content-Type"] = "application/json"
|
28
|
+
|
29
|
+
_kwargs["headers"] = headers
|
30
|
+
return _kwargs
|
31
|
+
|
32
|
+
|
33
|
+
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Workspace]:
|
34
|
+
if response.status_code == 200:
|
35
|
+
response_200 = Workspace.from_dict(response.json())
|
36
|
+
|
37
|
+
return response_200
|
38
|
+
if client.raise_on_unexpected_status:
|
39
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
40
|
+
else:
|
41
|
+
return None
|
42
|
+
|
43
|
+
|
44
|
+
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Workspace]:
|
45
|
+
return Response(
|
46
|
+
status_code=HTTPStatus(response.status_code),
|
47
|
+
content=response.content,
|
48
|
+
headers=response.headers,
|
49
|
+
parsed=_parse_response(client=client, response=response),
|
50
|
+
)
|
51
|
+
|
52
|
+
|
53
|
+
def sync_detailed(
|
54
|
+
workspace_name: str,
|
55
|
+
*,
|
56
|
+
client: AuthenticatedClient,
|
57
|
+
body: Workspace,
|
58
|
+
) -> Response[Workspace]:
|
59
|
+
"""Update workspace
|
60
|
+
|
61
|
+
Updates a workspace by name.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
workspace_name (str):
|
65
|
+
body (Workspace): Workspace
|
66
|
+
|
67
|
+
Raises:
|
68
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
69
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
70
|
+
|
71
|
+
Returns:
|
72
|
+
Response[Workspace]
|
73
|
+
"""
|
74
|
+
|
75
|
+
kwargs = _get_kwargs(
|
76
|
+
workspace_name=workspace_name,
|
77
|
+
body=body,
|
78
|
+
)
|
79
|
+
|
80
|
+
response = client.get_httpx_client().request(
|
81
|
+
**kwargs,
|
82
|
+
)
|
83
|
+
|
84
|
+
return _build_response(client=client, response=response)
|
85
|
+
|
86
|
+
|
87
|
+
def sync(
|
88
|
+
workspace_name: str,
|
89
|
+
*,
|
90
|
+
client: AuthenticatedClient,
|
91
|
+
body: Workspace,
|
92
|
+
) -> Optional[Workspace]:
|
93
|
+
"""Update workspace
|
94
|
+
|
95
|
+
Updates a workspace by name.
|
96
|
+
|
97
|
+
Args:
|
98
|
+
workspace_name (str):
|
99
|
+
body (Workspace): Workspace
|
100
|
+
|
101
|
+
Raises:
|
102
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
103
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
Workspace
|
107
|
+
"""
|
108
|
+
|
109
|
+
return sync_detailed(
|
110
|
+
workspace_name=workspace_name,
|
111
|
+
client=client,
|
112
|
+
body=body,
|
113
|
+
).parsed
|
114
|
+
|
115
|
+
|
116
|
+
async def asyncio_detailed(
|
117
|
+
workspace_name: str,
|
118
|
+
*,
|
119
|
+
client: AuthenticatedClient,
|
120
|
+
body: Workspace,
|
121
|
+
) -> Response[Workspace]:
|
122
|
+
"""Update workspace
|
123
|
+
|
124
|
+
Updates a workspace by name.
|
125
|
+
|
126
|
+
Args:
|
127
|
+
workspace_name (str):
|
128
|
+
body (Workspace): Workspace
|
129
|
+
|
130
|
+
Raises:
|
131
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
132
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
Response[Workspace]
|
136
|
+
"""
|
137
|
+
|
138
|
+
kwargs = _get_kwargs(
|
139
|
+
workspace_name=workspace_name,
|
140
|
+
body=body,
|
141
|
+
)
|
142
|
+
|
143
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
144
|
+
|
145
|
+
return _build_response(client=client, response=response)
|
146
|
+
|
147
|
+
|
148
|
+
async def asyncio(
|
149
|
+
workspace_name: str,
|
150
|
+
*,
|
151
|
+
client: AuthenticatedClient,
|
152
|
+
body: Workspace,
|
153
|
+
) -> Optional[Workspace]:
|
154
|
+
"""Update workspace
|
155
|
+
|
156
|
+
Updates a workspace by name.
|
157
|
+
|
158
|
+
Args:
|
159
|
+
workspace_name (str):
|
160
|
+
body (Workspace): Workspace
|
161
|
+
|
162
|
+
Raises:
|
163
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
164
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
165
|
+
|
166
|
+
Returns:
|
167
|
+
Workspace
|
168
|
+
"""
|
169
|
+
|
170
|
+
return (
|
171
|
+
await asyncio_detailed(
|
172
|
+
workspace_name=workspace_name,
|
173
|
+
client=client,
|
174
|
+
body=body,
|
175
|
+
)
|
176
|
+
).parsed
|
@@ -0,0 +1,187 @@
|
|
1
|
+
from http import HTTPStatus
|
2
|
+
from typing import Any, Optional, Union, cast
|
3
|
+
|
4
|
+
import httpx
|
5
|
+
|
6
|
+
from ... import errors
|
7
|
+
from ...client import AuthenticatedClient, Client
|
8
|
+
from ...models.update_workspace_user_role_body import UpdateWorkspaceUserRoleBody
|
9
|
+
from ...models.workspace_user import WorkspaceUser
|
10
|
+
from ...types import Response
|
11
|
+
|
12
|
+
|
13
|
+
def _get_kwargs(
|
14
|
+
sub_or_email: str,
|
15
|
+
*,
|
16
|
+
body: UpdateWorkspaceUserRoleBody,
|
17
|
+
) -> dict[str, Any]:
|
18
|
+
headers: dict[str, Any] = {}
|
19
|
+
|
20
|
+
_kwargs: dict[str, Any] = {
|
21
|
+
"method": "put",
|
22
|
+
"url": f"/users/{sub_or_email}",
|
23
|
+
}
|
24
|
+
|
25
|
+
_body = body.to_dict()
|
26
|
+
|
27
|
+
_kwargs["json"] = _body
|
28
|
+
headers["Content-Type"] = "application/json"
|
29
|
+
|
30
|
+
_kwargs["headers"] = headers
|
31
|
+
return _kwargs
|
32
|
+
|
33
|
+
|
34
|
+
def _parse_response(
|
35
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
36
|
+
) -> Optional[Union[Any, WorkspaceUser]]:
|
37
|
+
if response.status_code == 200:
|
38
|
+
response_200 = WorkspaceUser.from_dict(response.json())
|
39
|
+
|
40
|
+
return response_200
|
41
|
+
if response.status_code == 400:
|
42
|
+
response_400 = cast(Any, None)
|
43
|
+
return response_400
|
44
|
+
if response.status_code == 404:
|
45
|
+
response_404 = cast(Any, None)
|
46
|
+
return response_404
|
47
|
+
if client.raise_on_unexpected_status:
|
48
|
+
raise errors.UnexpectedStatus(response.status_code, response.content)
|
49
|
+
else:
|
50
|
+
return None
|
51
|
+
|
52
|
+
|
53
|
+
def _build_response(
|
54
|
+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
|
55
|
+
) -> Response[Union[Any, WorkspaceUser]]:
|
56
|
+
return Response(
|
57
|
+
status_code=HTTPStatus(response.status_code),
|
58
|
+
content=response.content,
|
59
|
+
headers=response.headers,
|
60
|
+
parsed=_parse_response(client=client, response=response),
|
61
|
+
)
|
62
|
+
|
63
|
+
|
64
|
+
def sync_detailed(
|
65
|
+
sub_or_email: str,
|
66
|
+
*,
|
67
|
+
client: AuthenticatedClient,
|
68
|
+
body: UpdateWorkspaceUserRoleBody,
|
69
|
+
) -> Response[Union[Any, WorkspaceUser]]:
|
70
|
+
"""Update user role in workspace
|
71
|
+
|
72
|
+
Updates the role of a user in the workspace.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
sub_or_email (str):
|
76
|
+
body (UpdateWorkspaceUserRoleBody):
|
77
|
+
|
78
|
+
Raises:
|
79
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
80
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
Response[Union[Any, WorkspaceUser]]
|
84
|
+
"""
|
85
|
+
|
86
|
+
kwargs = _get_kwargs(
|
87
|
+
sub_or_email=sub_or_email,
|
88
|
+
body=body,
|
89
|
+
)
|
90
|
+
|
91
|
+
response = client.get_httpx_client().request(
|
92
|
+
**kwargs,
|
93
|
+
)
|
94
|
+
|
95
|
+
return _build_response(client=client, response=response)
|
96
|
+
|
97
|
+
|
98
|
+
def sync(
|
99
|
+
sub_or_email: str,
|
100
|
+
*,
|
101
|
+
client: AuthenticatedClient,
|
102
|
+
body: UpdateWorkspaceUserRoleBody,
|
103
|
+
) -> Optional[Union[Any, WorkspaceUser]]:
|
104
|
+
"""Update user role in workspace
|
105
|
+
|
106
|
+
Updates the role of a user in the workspace.
|
107
|
+
|
108
|
+
Args:
|
109
|
+
sub_or_email (str):
|
110
|
+
body (UpdateWorkspaceUserRoleBody):
|
111
|
+
|
112
|
+
Raises:
|
113
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
114
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
115
|
+
|
116
|
+
Returns:
|
117
|
+
Union[Any, WorkspaceUser]
|
118
|
+
"""
|
119
|
+
|
120
|
+
return sync_detailed(
|
121
|
+
sub_or_email=sub_or_email,
|
122
|
+
client=client,
|
123
|
+
body=body,
|
124
|
+
).parsed
|
125
|
+
|
126
|
+
|
127
|
+
async def asyncio_detailed(
|
128
|
+
sub_or_email: str,
|
129
|
+
*,
|
130
|
+
client: AuthenticatedClient,
|
131
|
+
body: UpdateWorkspaceUserRoleBody,
|
132
|
+
) -> Response[Union[Any, WorkspaceUser]]:
|
133
|
+
"""Update user role in workspace
|
134
|
+
|
135
|
+
Updates the role of a user in the workspace.
|
136
|
+
|
137
|
+
Args:
|
138
|
+
sub_or_email (str):
|
139
|
+
body (UpdateWorkspaceUserRoleBody):
|
140
|
+
|
141
|
+
Raises:
|
142
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
143
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
Response[Union[Any, WorkspaceUser]]
|
147
|
+
"""
|
148
|
+
|
149
|
+
kwargs = _get_kwargs(
|
150
|
+
sub_or_email=sub_or_email,
|
151
|
+
body=body,
|
152
|
+
)
|
153
|
+
|
154
|
+
response = await client.get_async_httpx_client().request(**kwargs)
|
155
|
+
|
156
|
+
return _build_response(client=client, response=response)
|
157
|
+
|
158
|
+
|
159
|
+
async def asyncio(
|
160
|
+
sub_or_email: str,
|
161
|
+
*,
|
162
|
+
client: AuthenticatedClient,
|
163
|
+
body: UpdateWorkspaceUserRoleBody,
|
164
|
+
) -> Optional[Union[Any, WorkspaceUser]]:
|
165
|
+
"""Update user role in workspace
|
166
|
+
|
167
|
+
Updates the role of a user in the workspace.
|
168
|
+
|
169
|
+
Args:
|
170
|
+
sub_or_email (str):
|
171
|
+
body (UpdateWorkspaceUserRoleBody):
|
172
|
+
|
173
|
+
Raises:
|
174
|
+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
|
175
|
+
httpx.TimeoutException: If the request takes longer than Client.timeout.
|
176
|
+
|
177
|
+
Returns:
|
178
|
+
Union[Any, WorkspaceUser]
|
179
|
+
"""
|
180
|
+
|
181
|
+
return (
|
182
|
+
await asyncio_detailed(
|
183
|
+
sub_or_email=sub_or_email,
|
184
|
+
client=client,
|
185
|
+
body=body,
|
186
|
+
)
|
187
|
+
).parsed
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from .apikey import ApiKeyProvider
|
2
|
+
from .authentication import (
|
3
|
+
PublicProvider,
|
4
|
+
RunClientWithCredentials,
|
5
|
+
get_authentication_headers,
|
6
|
+
new_client,
|
7
|
+
new_client_from_settings,
|
8
|
+
new_client_with_credentials,
|
9
|
+
)
|
10
|
+
from .credentials import (
|
11
|
+
Config,
|
12
|
+
ContextConfig,
|
13
|
+
Credentials,
|
14
|
+
WorkspaceConfig,
|
15
|
+
load_credentials,
|
16
|
+
load_credentials_from_settings,
|
17
|
+
)
|
18
|
+
from .device_mode import (
|
19
|
+
BearerToken,
|
20
|
+
DeviceLogin,
|
21
|
+
DeviceLoginFinalizeRequest,
|
22
|
+
DeviceLoginFinalizeResponse,
|
23
|
+
DeviceLoginResponse,
|
24
|
+
)
|
25
|
+
|
26
|
+
__all__ = (
|
27
|
+
"ApiKeyProvider",
|
28
|
+
"PublicProvider",
|
29
|
+
"RunClientWithCredentials",
|
30
|
+
"new_client_with_credentials",
|
31
|
+
"new_client_from_settings",
|
32
|
+
"new_client",
|
33
|
+
"get_authentication_headers",
|
34
|
+
"Config",
|
35
|
+
"ContextConfig",
|
36
|
+
"Credentials",
|
37
|
+
"WorkspaceConfig",
|
38
|
+
"load_credentials",
|
39
|
+
"load_credentials_from_settings",
|
40
|
+
"BearerToken",
|
41
|
+
"DeviceLogin",
|
42
|
+
"DeviceLoginFinalizeRequest",
|
43
|
+
"DeviceLoginFinalizeResponse",
|
44
|
+
"DeviceLoginResponse",
|
45
|
+
)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"""
|
2
|
+
This module provides the ApiKeyProvider class, which handles API key-based authentication for Blaxel.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from typing import Generator
|
6
|
+
|
7
|
+
from httpx import Auth, Request, Response
|
8
|
+
|
9
|
+
|
10
|
+
class ApiKeyProvider(Auth):
|
11
|
+
"""
|
12
|
+
A provider that authenticates requests using an API key.
|
13
|
+
"""
|
14
|
+
|
15
|
+
def __init__(self, credentials, workspace_name: str):
|
16
|
+
"""
|
17
|
+
Initializes the ApiKeyProvider with the given credentials and workspace name.
|
18
|
+
|
19
|
+
Parameters:
|
20
|
+
credentials: Credentials containing the API key.
|
21
|
+
workspace_name (str): The name of the workspace.
|
22
|
+
"""
|
23
|
+
self.credentials = credentials
|
24
|
+
self.workspace_name = workspace_name
|
25
|
+
|
26
|
+
def get_headers(self):
|
27
|
+
"""
|
28
|
+
Retrieves the authentication headers containing the API key and workspace information.
|
29
|
+
|
30
|
+
Returns:
|
31
|
+
dict: A dictionary of headers with API key and workspace.
|
32
|
+
"""
|
33
|
+
return {
|
34
|
+
"X-Blaxel-Api-Key": self.credentials.apiKey,
|
35
|
+
"X-Blaxel-Workspace": self.workspace_name,
|
36
|
+
}
|
37
|
+
|
38
|
+
def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
|
39
|
+
"""
|
40
|
+
Authenticates the request by adding API key and workspace headers.
|
41
|
+
|
42
|
+
Parameters:
|
43
|
+
request (Request): The HTTP request to authenticate.
|
44
|
+
|
45
|
+
Yields:
|
46
|
+
Request: The authenticated request.
|
47
|
+
"""
|
48
|
+
request.headers["X-Blaxel-Api-Key"] = self.credentials.apiKey
|
49
|
+
request.headers["X-Blaxel-Workspace"] = self.workspace_name
|
50
|
+
yield request
|
@@ -0,0 +1,176 @@
|
|
1
|
+
"""
|
2
|
+
This module provides classes and functions for handling various authentication methods,
|
3
|
+
including public access, API key authentication, client credentials, and bearer tokens.
|
4
|
+
It also includes utilities for creating authenticated clients and managing authentication headers.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from dataclasses import dataclass
|
8
|
+
from typing import Dict, Generator
|
9
|
+
|
10
|
+
from httpx import Auth, Request, Response
|
11
|
+
|
12
|
+
from blaxel.aimon.settings import Settings, get_settings
|
13
|
+
|
14
|
+
from ..client import AuthenticatedClient
|
15
|
+
from .apikey import ApiKeyProvider
|
16
|
+
from .clientcredentials import ClientCredentials
|
17
|
+
from .credentials import (
|
18
|
+
Credentials,
|
19
|
+
current_context,
|
20
|
+
load_credentials,
|
21
|
+
load_credentials_from_settings,
|
22
|
+
)
|
23
|
+
from .device_mode import BearerToken
|
24
|
+
|
25
|
+
global provider_singleton
|
26
|
+
provider_singleton = None
|
27
|
+
|
28
|
+
class PublicProvider(Auth):
|
29
|
+
"""
|
30
|
+
A provider that allows public access without any authentication.
|
31
|
+
"""
|
32
|
+
|
33
|
+
def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
|
34
|
+
"""
|
35
|
+
Processes the authentication flow for public access by yielding the request as-is.
|
36
|
+
|
37
|
+
Parameters:
|
38
|
+
request (Request): The HTTP request to process.
|
39
|
+
|
40
|
+
Yields:
|
41
|
+
Request: The unmodified request.
|
42
|
+
"""
|
43
|
+
yield request
|
44
|
+
|
45
|
+
|
46
|
+
@dataclass
|
47
|
+
class RunClientWithCredentials:
|
48
|
+
"""
|
49
|
+
A dataclass that holds credentials and workspace information for initializing an authenticated client.
|
50
|
+
|
51
|
+
Attributes:
|
52
|
+
credentials (Credentials): The credentials used for authentication.
|
53
|
+
workspace (str): The name of the workspace.
|
54
|
+
api_url (str): The base API URL.
|
55
|
+
run_url (str): The run-specific URL.
|
56
|
+
"""
|
57
|
+
credentials: Credentials
|
58
|
+
workspace: str
|
59
|
+
api_url: str = ""
|
60
|
+
run_url: str = ""
|
61
|
+
|
62
|
+
def __post_init__(self):
|
63
|
+
"""
|
64
|
+
Post-initialization to set the API and run URLs from settings.
|
65
|
+
"""
|
66
|
+
from ..common.settings import get_settings
|
67
|
+
|
68
|
+
settings = get_settings()
|
69
|
+
self.api_url = settings.base_url
|
70
|
+
self.run_url = settings.run_url
|
71
|
+
|
72
|
+
|
73
|
+
def new_client_from_settings(settings: Settings):
|
74
|
+
"""
|
75
|
+
Creates a new authenticated client using the provided settings.
|
76
|
+
|
77
|
+
Parameters:
|
78
|
+
settings (Settings): The settings containing authentication and workspace information.
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
AuthenticatedClient: An instance of AuthenticatedClient configured with the provided settings.
|
82
|
+
"""
|
83
|
+
credentials = load_credentials_from_settings(settings)
|
84
|
+
|
85
|
+
client_config = RunClientWithCredentials(
|
86
|
+
credentials=credentials,
|
87
|
+
workspace=settings.workspace,
|
88
|
+
)
|
89
|
+
return new_client_with_credentials(client_config)
|
90
|
+
|
91
|
+
|
92
|
+
def new_client():
|
93
|
+
"""
|
94
|
+
Creates a new authenticated client based on the current context and settings.
|
95
|
+
|
96
|
+
Returns:
|
97
|
+
AuthenticatedClient: An instance of AuthenticatedClient configured with the current context or settings.
|
98
|
+
"""
|
99
|
+
settings = get_settings()
|
100
|
+
context = current_context()
|
101
|
+
if context.workspace and not settings.authentication.client.credentials:
|
102
|
+
credentials = load_credentials(context.workspace)
|
103
|
+
client_config = RunClientWithCredentials(
|
104
|
+
credentials=credentials,
|
105
|
+
workspace=context.workspace,
|
106
|
+
)
|
107
|
+
else:
|
108
|
+
credentials = load_credentials_from_settings(settings)
|
109
|
+
client_config = RunClientWithCredentials(
|
110
|
+
credentials=credentials,
|
111
|
+
workspace=settings.workspace,
|
112
|
+
)
|
113
|
+
return new_client_with_credentials(client_config)
|
114
|
+
|
115
|
+
|
116
|
+
def new_client_with_credentials(config: RunClientWithCredentials):
|
117
|
+
"""
|
118
|
+
Creates a new authenticated client using the provided client configuration.
|
119
|
+
|
120
|
+
Parameters:
|
121
|
+
config (RunClientWithCredentials): The client configuration containing credentials and workspace information.
|
122
|
+
|
123
|
+
Returns:
|
124
|
+
AuthenticatedClient: An instance of AuthenticatedClient configured with the provided credentials.
|
125
|
+
"""
|
126
|
+
provider: Auth = None
|
127
|
+
if config.credentials.apiKey:
|
128
|
+
provider = ApiKeyProvider(config.credentials, config.workspace)
|
129
|
+
elif config.credentials.access_token:
|
130
|
+
provider = BearerToken(config.credentials, config.workspace, config.api_url)
|
131
|
+
elif config.credentials.client_credentials:
|
132
|
+
provider = ClientCredentials(config.credentials, config.workspace, config.api_url)
|
133
|
+
else:
|
134
|
+
provider = PublicProvider()
|
135
|
+
|
136
|
+
return AuthenticatedClient(base_url=config.api_url, provider=provider)
|
137
|
+
|
138
|
+
|
139
|
+
def get_authentication_headers(settings: Settings) -> Dict[str, str]:
|
140
|
+
"""
|
141
|
+
Retrieves authentication headers based on the current context and settings.
|
142
|
+
|
143
|
+
Parameters:
|
144
|
+
settings (Settings): The settings containing authentication and workspace information.
|
145
|
+
|
146
|
+
Returns:
|
147
|
+
Dict[str, str]: A dictionary of authentication headers.
|
148
|
+
"""
|
149
|
+
global provider_singleton
|
150
|
+
|
151
|
+
if provider_singleton:
|
152
|
+
return provider_singleton.get_headers()
|
153
|
+
|
154
|
+
context = current_context()
|
155
|
+
if context.workspace and not settings.authentication.client.credentials:
|
156
|
+
credentials = load_credentials(context.workspace)
|
157
|
+
else:
|
158
|
+
settings = get_settings()
|
159
|
+
credentials = load_credentials_from_settings(settings)
|
160
|
+
|
161
|
+
config = RunClientWithCredentials(
|
162
|
+
credentials=credentials,
|
163
|
+
workspace=settings.workspace,
|
164
|
+
)
|
165
|
+
provider = None
|
166
|
+
if config.credentials.apiKey:
|
167
|
+
provider = ApiKeyProvider(config.credentials, config.workspace)
|
168
|
+
elif config.credentials.access_token:
|
169
|
+
provider = BearerToken(config.credentials, config.workspace, config.api_url)
|
170
|
+
elif config.credentials.client_credentials:
|
171
|
+
provider = ClientCredentials(config.credentials, config.workspace, config.api_url)
|
172
|
+
|
173
|
+
if provider is None:
|
174
|
+
return None
|
175
|
+
provider_singleton = provider
|
176
|
+
return provider.get_headers()
|