hackagent 0.3.1__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.
- hackagent/__init__.py +12 -0
- hackagent/agent.py +214 -0
- hackagent/api/__init__.py +1 -0
- hackagent/api/agent/__init__.py +1 -0
- hackagent/api/agent/agent_create.py +347 -0
- hackagent/api/agent/agent_destroy.py +140 -0
- hackagent/api/agent/agent_list.py +242 -0
- hackagent/api/agent/agent_partial_update.py +361 -0
- hackagent/api/agent/agent_retrieve.py +235 -0
- hackagent/api/agent/agent_update.py +361 -0
- hackagent/api/apilogs/__init__.py +1 -0
- hackagent/api/apilogs/apilogs_list.py +170 -0
- hackagent/api/apilogs/apilogs_retrieve.py +162 -0
- hackagent/api/attack/__init__.py +1 -0
- hackagent/api/attack/attack_create.py +275 -0
- hackagent/api/attack/attack_destroy.py +146 -0
- hackagent/api/attack/attack_list.py +254 -0
- hackagent/api/attack/attack_partial_update.py +289 -0
- hackagent/api/attack/attack_retrieve.py +247 -0
- hackagent/api/attack/attack_update.py +289 -0
- hackagent/api/checkout/__init__.py +1 -0
- hackagent/api/checkout/checkout_create.py +225 -0
- hackagent/api/generate/__init__.py +1 -0
- hackagent/api/generate/generate_create.py +253 -0
- hackagent/api/judge/__init__.py +1 -0
- hackagent/api/judge/judge_create.py +253 -0
- hackagent/api/key/__init__.py +1 -0
- hackagent/api/key/key_create.py +179 -0
- hackagent/api/key/key_destroy.py +103 -0
- hackagent/api/key/key_list.py +170 -0
- hackagent/api/key/key_retrieve.py +162 -0
- hackagent/api/organization/__init__.py +1 -0
- hackagent/api/organization/organization_create.py +208 -0
- hackagent/api/organization/organization_destroy.py +104 -0
- hackagent/api/organization/organization_list.py +170 -0
- hackagent/api/organization/organization_me_retrieve.py +126 -0
- hackagent/api/organization/organization_partial_update.py +222 -0
- hackagent/api/organization/organization_retrieve.py +163 -0
- hackagent/api/organization/organization_update.py +222 -0
- hackagent/api/prompt/__init__.py +1 -0
- hackagent/api/prompt/prompt_create.py +171 -0
- hackagent/api/prompt/prompt_destroy.py +104 -0
- hackagent/api/prompt/prompt_list.py +185 -0
- hackagent/api/prompt/prompt_partial_update.py +185 -0
- hackagent/api/prompt/prompt_retrieve.py +163 -0
- hackagent/api/prompt/prompt_update.py +185 -0
- hackagent/api/result/__init__.py +1 -0
- hackagent/api/result/result_create.py +175 -0
- hackagent/api/result/result_destroy.py +106 -0
- hackagent/api/result/result_list.py +249 -0
- hackagent/api/result/result_partial_update.py +193 -0
- hackagent/api/result/result_retrieve.py +167 -0
- hackagent/api/result/result_trace_create.py +177 -0
- hackagent/api/result/result_update.py +189 -0
- hackagent/api/run/__init__.py +1 -0
- hackagent/api/run/run_create.py +187 -0
- hackagent/api/run/run_destroy.py +112 -0
- hackagent/api/run/run_list.py +291 -0
- hackagent/api/run/run_partial_update.py +201 -0
- hackagent/api/run/run_result_create.py +177 -0
- hackagent/api/run/run_retrieve.py +179 -0
- hackagent/api/run/run_run_tests_create.py +187 -0
- hackagent/api/run/run_update.py +201 -0
- hackagent/api/user/__init__.py +1 -0
- hackagent/api/user/user_create.py +212 -0
- hackagent/api/user/user_destroy.py +106 -0
- hackagent/api/user/user_list.py +174 -0
- hackagent/api/user/user_me_retrieve.py +126 -0
- hackagent/api/user/user_me_update.py +196 -0
- hackagent/api/user/user_partial_update.py +226 -0
- hackagent/api/user/user_retrieve.py +167 -0
- hackagent/api/user/user_update.py +226 -0
- hackagent/attacks/AdvPrefix/__init__.py +41 -0
- hackagent/attacks/AdvPrefix/completions.py +416 -0
- hackagent/attacks/AdvPrefix/config.py +259 -0
- hackagent/attacks/AdvPrefix/evaluation.py +745 -0
- hackagent/attacks/AdvPrefix/evaluators.py +564 -0
- hackagent/attacks/AdvPrefix/generate.py +711 -0
- hackagent/attacks/AdvPrefix/utils.py +307 -0
- hackagent/attacks/__init__.py +35 -0
- hackagent/attacks/advprefix.py +507 -0
- hackagent/attacks/base.py +106 -0
- hackagent/attacks/strategies.py +906 -0
- hackagent/cli/__init__.py +19 -0
- hackagent/cli/commands/__init__.py +20 -0
- hackagent/cli/commands/agent.py +100 -0
- hackagent/cli/commands/attack.py +417 -0
- hackagent/cli/commands/config.py +301 -0
- hackagent/cli/commands/results.py +327 -0
- hackagent/cli/config.py +249 -0
- hackagent/cli/main.py +515 -0
- hackagent/cli/tui/__init__.py +31 -0
- hackagent/cli/tui/actions_logger.py +200 -0
- hackagent/cli/tui/app.py +288 -0
- hackagent/cli/tui/base.py +137 -0
- hackagent/cli/tui/logger.py +318 -0
- hackagent/cli/tui/views/__init__.py +33 -0
- hackagent/cli/tui/views/agents.py +488 -0
- hackagent/cli/tui/views/attacks.py +624 -0
- hackagent/cli/tui/views/config.py +244 -0
- hackagent/cli/tui/views/dashboard.py +307 -0
- hackagent/cli/tui/views/results.py +1210 -0
- hackagent/cli/tui/widgets/__init__.py +24 -0
- hackagent/cli/tui/widgets/actions.py +346 -0
- hackagent/cli/tui/widgets/logs.py +435 -0
- hackagent/cli/utils.py +276 -0
- hackagent/client.py +286 -0
- hackagent/errors.py +37 -0
- hackagent/logger.py +83 -0
- hackagent/models/__init__.py +109 -0
- hackagent/models/agent.py +223 -0
- hackagent/models/agent_request.py +129 -0
- hackagent/models/api_token_log.py +184 -0
- hackagent/models/attack.py +154 -0
- hackagent/models/attack_request.py +82 -0
- hackagent/models/checkout_session_request_request.py +76 -0
- hackagent/models/checkout_session_response.py +59 -0
- hackagent/models/choice.py +81 -0
- hackagent/models/choice_message.py +67 -0
- hackagent/models/evaluation_status_enum.py +14 -0
- hackagent/models/generate_error_response.py +59 -0
- hackagent/models/generate_request_request.py +212 -0
- hackagent/models/generate_success_response.py +115 -0
- hackagent/models/generic_error_response.py +70 -0
- hackagent/models/message_request.py +67 -0
- hackagent/models/organization.py +102 -0
- hackagent/models/organization_minimal.py +68 -0
- hackagent/models/organization_request.py +71 -0
- hackagent/models/paginated_agent_list.py +123 -0
- hackagent/models/paginated_api_token_log_list.py +123 -0
- hackagent/models/paginated_attack_list.py +123 -0
- hackagent/models/paginated_organization_list.py +123 -0
- hackagent/models/paginated_prompt_list.py +123 -0
- hackagent/models/paginated_result_list.py +123 -0
- hackagent/models/paginated_run_list.py +123 -0
- hackagent/models/paginated_user_api_key_list.py +123 -0
- hackagent/models/paginated_user_profile_list.py +123 -0
- hackagent/models/patched_agent_request.py +128 -0
- hackagent/models/patched_attack_request.py +92 -0
- hackagent/models/patched_organization_request.py +71 -0
- hackagent/models/patched_prompt_request.py +125 -0
- hackagent/models/patched_result_request.py +237 -0
- hackagent/models/patched_run_request.py +138 -0
- hackagent/models/patched_user_profile_request.py +99 -0
- hackagent/models/prompt.py +220 -0
- hackagent/models/prompt_request.py +126 -0
- hackagent/models/result.py +294 -0
- hackagent/models/result_list_evaluation_status.py +14 -0
- hackagent/models/result_request.py +232 -0
- hackagent/models/run.py +233 -0
- hackagent/models/run_list_status.py +12 -0
- hackagent/models/run_request.py +133 -0
- hackagent/models/status_enum.py +12 -0
- hackagent/models/step_type_enum.py +14 -0
- hackagent/models/trace.py +121 -0
- hackagent/models/trace_request.py +94 -0
- hackagent/models/usage.py +75 -0
- hackagent/models/user_api_key.py +201 -0
- hackagent/models/user_api_key_request.py +73 -0
- hackagent/models/user_profile.py +135 -0
- hackagent/models/user_profile_minimal.py +76 -0
- hackagent/models/user_profile_request.py +99 -0
- hackagent/router/__init__.py +25 -0
- hackagent/router/adapters/__init__.py +20 -0
- hackagent/router/adapters/base.py +63 -0
- hackagent/router/adapters/google_adk.py +671 -0
- hackagent/router/adapters/litellm_adapter.py +524 -0
- hackagent/router/adapters/openai_adapter.py +426 -0
- hackagent/router/router.py +969 -0
- hackagent/router/types.py +54 -0
- hackagent/tracking/__init__.py +42 -0
- hackagent/tracking/context.py +163 -0
- hackagent/tracking/decorators.py +299 -0
- hackagent/tracking/tracker.py +441 -0
- hackagent/types.py +54 -0
- hackagent/utils.py +194 -0
- hackagent/vulnerabilities/__init__.py +13 -0
- hackagent/vulnerabilities/prompts.py +81 -0
- hackagent-0.3.1.dist-info/METADATA +122 -0
- hackagent-0.3.1.dist-info/RECORD +183 -0
- hackagent-0.3.1.dist-info/WHEEL +4 -0
- hackagent-0.3.1.dist-info/entry_points.txt +2 -0
- hackagent-0.3.1.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
from dateutil.parser import isoparse
|
|
9
|
+
|
|
10
|
+
from ..types import UNSET, Unset
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from ..models.organization_minimal import OrganizationMinimal
|
|
14
|
+
from ..models.user_profile_minimal import UserProfileMinimal
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T", bound="Agent")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@_attrs_define
|
|
21
|
+
class Agent:
|
|
22
|
+
"""Serializes Agent model instances to JSON and validates data for creating
|
|
23
|
+
or updating Agent instances.
|
|
24
|
+
|
|
25
|
+
This serializer provides a comprehensive representation of an Agent,
|
|
26
|
+
including its type, endpoint, and nested details for related 'organization'
|
|
27
|
+
and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
|
|
28
|
+
for write operations.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
organization_detail (OrganizationMinimalSerializer): Read-only nested
|
|
32
|
+
serializer for the agent's organization. Displays minimal details.
|
|
33
|
+
owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
|
|
34
|
+
for the agent's owner's user profile. Displays minimal details.
|
|
35
|
+
Can be null if the agent has no owner or the owner has no profile.
|
|
36
|
+
agent_type (CharField): The type of the agent as a string
|
|
37
|
+
(e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
|
|
38
|
+
|
|
39
|
+
Meta:
|
|
40
|
+
model (Agent): The model class that this serializer works with.
|
|
41
|
+
fields (tuple): The fields to include in the serialized output.
|
|
42
|
+
Includes standard Agent fields like 'endpoint', 'type',
|
|
43
|
+
and the read-only nested details.
|
|
44
|
+
read_only_fields (tuple): Fields that are read-only and cannot be
|
|
45
|
+
set during create/update operations through this serializer.
|
|
46
|
+
This includes 'id', 'created_at', 'updated_at', and the
|
|
47
|
+
nested detail fields.
|
|
48
|
+
|
|
49
|
+
Attributes:
|
|
50
|
+
id (UUID):
|
|
51
|
+
name (str):
|
|
52
|
+
endpoint (str): The primary API endpoint URL for interacting with the agent.
|
|
53
|
+
organization (UUID):
|
|
54
|
+
organization_detail (OrganizationMinimal):
|
|
55
|
+
owner (Union[None, int]):
|
|
56
|
+
owner_detail (Union['UserProfileMinimal', None]):
|
|
57
|
+
created_at (datetime.datetime):
|
|
58
|
+
updated_at (datetime.datetime):
|
|
59
|
+
agent_type (Union[Unset, str]): The specific SDK, ADK, or API type the agent is built upon (e.g., OpenAI SDK,
|
|
60
|
+
Generic ADK).
|
|
61
|
+
description (Union[Unset, str]):
|
|
62
|
+
metadata (Union[Unset, Any]): Optional JSON data providing specific details and configuration. Structure depends
|
|
63
|
+
heavily on Agent Type. Examples:
|
|
64
|
+
- For GENERIC_ADK: {'adk_app_name': 'my_adk_app', 'protocol_version': '1.0'}
|
|
65
|
+
- For OPENAI_SDK: {'model': 'gpt-4-turbo', 'api_key_secret_name': 'MY_OPENAI_KEY', 'instructions': 'You are a
|
|
66
|
+
helpful assistant.'}
|
|
67
|
+
- For GOOGLE_ADK: {'project_id': 'my-gcp-project', 'location': 'us-central1'}
|
|
68
|
+
- General applicable: {'version': '1.2.0', 'custom_headers': {'X-Custom-Header': 'value'}}
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
id: UUID
|
|
72
|
+
name: str
|
|
73
|
+
endpoint: str
|
|
74
|
+
organization: UUID
|
|
75
|
+
organization_detail: "OrganizationMinimal"
|
|
76
|
+
owner: Union[None, int]
|
|
77
|
+
owner_detail: Union["UserProfileMinimal", None]
|
|
78
|
+
created_at: datetime.datetime
|
|
79
|
+
updated_at: datetime.datetime
|
|
80
|
+
agent_type: Union[Unset, str] = UNSET
|
|
81
|
+
description: Union[Unset, str] = UNSET
|
|
82
|
+
metadata: Union[Unset, Any] = UNSET
|
|
83
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
84
|
+
|
|
85
|
+
def to_dict(self) -> dict[str, Any]:
|
|
86
|
+
from ..models.user_profile_minimal import UserProfileMinimal
|
|
87
|
+
|
|
88
|
+
id = str(self.id)
|
|
89
|
+
|
|
90
|
+
name = self.name
|
|
91
|
+
|
|
92
|
+
endpoint = self.endpoint
|
|
93
|
+
|
|
94
|
+
organization = str(self.organization)
|
|
95
|
+
|
|
96
|
+
organization_detail = self.organization_detail.to_dict()
|
|
97
|
+
|
|
98
|
+
owner: Union[None, int]
|
|
99
|
+
owner = self.owner
|
|
100
|
+
|
|
101
|
+
owner_detail: Union[None, dict[str, Any]]
|
|
102
|
+
if isinstance(self.owner_detail, UserProfileMinimal):
|
|
103
|
+
owner_detail = self.owner_detail.to_dict()
|
|
104
|
+
else:
|
|
105
|
+
owner_detail = self.owner_detail
|
|
106
|
+
|
|
107
|
+
created_at = self.created_at.isoformat()
|
|
108
|
+
|
|
109
|
+
updated_at = self.updated_at.isoformat()
|
|
110
|
+
|
|
111
|
+
agent_type = self.agent_type
|
|
112
|
+
|
|
113
|
+
description = self.description
|
|
114
|
+
|
|
115
|
+
metadata = self.metadata
|
|
116
|
+
|
|
117
|
+
field_dict: dict[str, Any] = {}
|
|
118
|
+
field_dict.update(self.additional_properties)
|
|
119
|
+
field_dict.update(
|
|
120
|
+
{
|
|
121
|
+
"id": id,
|
|
122
|
+
"name": name,
|
|
123
|
+
"endpoint": endpoint,
|
|
124
|
+
"organization": organization,
|
|
125
|
+
"organization_detail": organization_detail,
|
|
126
|
+
"owner": owner,
|
|
127
|
+
"owner_detail": owner_detail,
|
|
128
|
+
"created_at": created_at,
|
|
129
|
+
"updated_at": updated_at,
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
if agent_type is not UNSET:
|
|
133
|
+
field_dict["agent_type"] = agent_type
|
|
134
|
+
if description is not UNSET:
|
|
135
|
+
field_dict["description"] = description
|
|
136
|
+
if metadata is not UNSET:
|
|
137
|
+
field_dict["metadata"] = metadata
|
|
138
|
+
|
|
139
|
+
return field_dict
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
143
|
+
from ..models.organization_minimal import OrganizationMinimal
|
|
144
|
+
from ..models.user_profile_minimal import UserProfileMinimal
|
|
145
|
+
|
|
146
|
+
d = dict(src_dict)
|
|
147
|
+
id = UUID(d.pop("id"))
|
|
148
|
+
|
|
149
|
+
name = d.pop("name")
|
|
150
|
+
|
|
151
|
+
endpoint = d.pop("endpoint")
|
|
152
|
+
|
|
153
|
+
organization = UUID(d.pop("organization"))
|
|
154
|
+
|
|
155
|
+
organization_detail = OrganizationMinimal.from_dict(
|
|
156
|
+
d.pop("organization_detail")
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
def _parse_owner(data: object) -> Union[None, int]:
|
|
160
|
+
if data is None:
|
|
161
|
+
return data
|
|
162
|
+
return cast(Union[None, int], data)
|
|
163
|
+
|
|
164
|
+
owner = _parse_owner(d.pop("owner"))
|
|
165
|
+
|
|
166
|
+
def _parse_owner_detail(data: object) -> Union["UserProfileMinimal", None]:
|
|
167
|
+
if data is None:
|
|
168
|
+
return data
|
|
169
|
+
try:
|
|
170
|
+
if not isinstance(data, dict):
|
|
171
|
+
raise TypeError()
|
|
172
|
+
owner_detail_type_1 = UserProfileMinimal.from_dict(data)
|
|
173
|
+
|
|
174
|
+
return owner_detail_type_1
|
|
175
|
+
except: # noqa: E722
|
|
176
|
+
pass
|
|
177
|
+
return cast(Union["UserProfileMinimal", None], data)
|
|
178
|
+
|
|
179
|
+
owner_detail = _parse_owner_detail(d.pop("owner_detail"))
|
|
180
|
+
|
|
181
|
+
created_at = isoparse(d.pop("created_at"))
|
|
182
|
+
|
|
183
|
+
updated_at = isoparse(d.pop("updated_at"))
|
|
184
|
+
|
|
185
|
+
agent_type = d.pop("agent_type", UNSET)
|
|
186
|
+
|
|
187
|
+
description = d.pop("description", UNSET)
|
|
188
|
+
|
|
189
|
+
metadata = d.pop("metadata", UNSET)
|
|
190
|
+
|
|
191
|
+
agent = cls(
|
|
192
|
+
id=id,
|
|
193
|
+
name=name,
|
|
194
|
+
endpoint=endpoint,
|
|
195
|
+
organization=organization,
|
|
196
|
+
organization_detail=organization_detail,
|
|
197
|
+
owner=owner,
|
|
198
|
+
owner_detail=owner_detail,
|
|
199
|
+
created_at=created_at,
|
|
200
|
+
updated_at=updated_at,
|
|
201
|
+
agent_type=agent_type,
|
|
202
|
+
description=description,
|
|
203
|
+
metadata=metadata,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
agent.additional_properties = d
|
|
207
|
+
return agent
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def additional_keys(self) -> list[str]:
|
|
211
|
+
return list(self.additional_properties.keys())
|
|
212
|
+
|
|
213
|
+
def __getitem__(self, key: str) -> Any:
|
|
214
|
+
return self.additional_properties[key]
|
|
215
|
+
|
|
216
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
217
|
+
self.additional_properties[key] = value
|
|
218
|
+
|
|
219
|
+
def __delitem__(self, key: str) -> None:
|
|
220
|
+
del self.additional_properties[key]
|
|
221
|
+
|
|
222
|
+
def __contains__(self, key: str) -> bool:
|
|
223
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
from typing import Any, TypeVar, Union
|
|
3
|
+
|
|
4
|
+
from attrs import define as _attrs_define
|
|
5
|
+
from attrs import field as _attrs_field
|
|
6
|
+
|
|
7
|
+
from ..types import UNSET, Unset
|
|
8
|
+
|
|
9
|
+
T = TypeVar("T", bound="AgentRequest")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@_attrs_define
|
|
13
|
+
class AgentRequest:
|
|
14
|
+
"""Serializes Agent model instances to JSON and validates data for creating
|
|
15
|
+
or updating Agent instances.
|
|
16
|
+
|
|
17
|
+
This serializer provides a comprehensive representation of an Agent,
|
|
18
|
+
including its type, endpoint, and nested details for related 'organization'
|
|
19
|
+
and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
|
|
20
|
+
for write operations.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
organization_detail (OrganizationMinimalSerializer): Read-only nested
|
|
24
|
+
serializer for the agent's organization. Displays minimal details.
|
|
25
|
+
owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
|
|
26
|
+
for the agent's owner's user profile. Displays minimal details.
|
|
27
|
+
Can be null if the agent has no owner or the owner has no profile.
|
|
28
|
+
agent_type (CharField): The type of the agent as a string
|
|
29
|
+
(e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
|
|
30
|
+
|
|
31
|
+
Meta:
|
|
32
|
+
model (Agent): The model class that this serializer works with.
|
|
33
|
+
fields (tuple): The fields to include in the serialized output.
|
|
34
|
+
Includes standard Agent fields like 'endpoint', 'type',
|
|
35
|
+
and the read-only nested details.
|
|
36
|
+
read_only_fields (tuple): Fields that are read-only and cannot be
|
|
37
|
+
set during create/update operations through this serializer.
|
|
38
|
+
This includes 'id', 'created_at', 'updated_at', and the
|
|
39
|
+
nested detail fields.
|
|
40
|
+
|
|
41
|
+
Attributes:
|
|
42
|
+
name (str):
|
|
43
|
+
endpoint (str): The primary API endpoint URL for interacting with the agent.
|
|
44
|
+
agent_type (Union[Unset, str]): The specific SDK, ADK, or API type the agent is built upon (e.g., OpenAI SDK,
|
|
45
|
+
Generic ADK).
|
|
46
|
+
description (Union[Unset, str]):
|
|
47
|
+
metadata (Union[Unset, Any]): Optional JSON data providing specific details and configuration. Structure depends
|
|
48
|
+
heavily on Agent Type. Examples:
|
|
49
|
+
- For GENERIC_ADK: {'adk_app_name': 'my_adk_app', 'protocol_version': '1.0'}
|
|
50
|
+
- For OPENAI_SDK: {'model': 'gpt-4-turbo', 'api_key_secret_name': 'MY_OPENAI_KEY', 'instructions': 'You are a
|
|
51
|
+
helpful assistant.'}
|
|
52
|
+
- For GOOGLE_ADK: {'project_id': 'my-gcp-project', 'location': 'us-central1'}
|
|
53
|
+
- General applicable: {'version': '1.2.0', 'custom_headers': {'X-Custom-Header': 'value'}}
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
name: str
|
|
57
|
+
endpoint: str
|
|
58
|
+
agent_type: Union[Unset, str] = UNSET
|
|
59
|
+
description: Union[Unset, str] = UNSET
|
|
60
|
+
metadata: Union[Unset, Any] = UNSET
|
|
61
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> dict[str, Any]:
|
|
64
|
+
name = self.name
|
|
65
|
+
|
|
66
|
+
endpoint = self.endpoint
|
|
67
|
+
|
|
68
|
+
agent_type = self.agent_type
|
|
69
|
+
|
|
70
|
+
description = self.description
|
|
71
|
+
|
|
72
|
+
metadata = self.metadata
|
|
73
|
+
|
|
74
|
+
field_dict: dict[str, Any] = {}
|
|
75
|
+
field_dict.update(self.additional_properties)
|
|
76
|
+
field_dict.update(
|
|
77
|
+
{
|
|
78
|
+
"name": name,
|
|
79
|
+
"endpoint": endpoint,
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
if agent_type is not UNSET:
|
|
83
|
+
field_dict["agent_type"] = agent_type
|
|
84
|
+
if description is not UNSET:
|
|
85
|
+
field_dict["description"] = description
|
|
86
|
+
if metadata is not UNSET:
|
|
87
|
+
field_dict["metadata"] = metadata
|
|
88
|
+
|
|
89
|
+
return field_dict
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
93
|
+
d = dict(src_dict)
|
|
94
|
+
name = d.pop("name")
|
|
95
|
+
|
|
96
|
+
endpoint = d.pop("endpoint")
|
|
97
|
+
|
|
98
|
+
agent_type = d.pop("agent_type", UNSET)
|
|
99
|
+
|
|
100
|
+
description = d.pop("description", UNSET)
|
|
101
|
+
|
|
102
|
+
metadata = d.pop("metadata", UNSET)
|
|
103
|
+
|
|
104
|
+
agent_request = cls(
|
|
105
|
+
name=name,
|
|
106
|
+
endpoint=endpoint,
|
|
107
|
+
agent_type=agent_type,
|
|
108
|
+
description=description,
|
|
109
|
+
metadata=metadata,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
agent_request.additional_properties = d
|
|
113
|
+
return agent_request
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def additional_keys(self) -> list[str]:
|
|
117
|
+
return list(self.additional_properties.keys())
|
|
118
|
+
|
|
119
|
+
def __getitem__(self, key: str) -> Any:
|
|
120
|
+
return self.additional_properties[key]
|
|
121
|
+
|
|
122
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
123
|
+
self.additional_properties[key] = value
|
|
124
|
+
|
|
125
|
+
def __delitem__(self, key: str) -> None:
|
|
126
|
+
del self.additional_properties[key]
|
|
127
|
+
|
|
128
|
+
def __contains__(self, key: str) -> bool:
|
|
129
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from typing import Any, TypeVar, Union, cast
|
|
4
|
+
|
|
5
|
+
from attrs import define as _attrs_define
|
|
6
|
+
from attrs import field as _attrs_field
|
|
7
|
+
from dateutil.parser import isoparse
|
|
8
|
+
|
|
9
|
+
T = TypeVar("T", bound="APITokenLog")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@_attrs_define
|
|
13
|
+
class APITokenLog:
|
|
14
|
+
"""Serializer for APITokenLog model, providing read-only access to log entries.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
id (int):
|
|
18
|
+
timestamp (datetime.datetime):
|
|
19
|
+
api_key_prefix (Union[None, str]):
|
|
20
|
+
user_username (Union[None, str]):
|
|
21
|
+
organization_name (Union[None, str]):
|
|
22
|
+
model_id_used (str): Identifier of the AI model used.
|
|
23
|
+
api_endpoint (str): Internal endpoint name, e.g., 'generator' or 'judge'.
|
|
24
|
+
input_tokens (int):
|
|
25
|
+
output_tokens (int):
|
|
26
|
+
credits_deducted (str):
|
|
27
|
+
request_payload_preview (Union[None, str]): First ~256 chars of request payload
|
|
28
|
+
response_payload_preview (Union[None, str]): First ~256 chars of response payload
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
id: int
|
|
32
|
+
timestamp: datetime.datetime
|
|
33
|
+
api_key_prefix: Union[None, str]
|
|
34
|
+
user_username: Union[None, str]
|
|
35
|
+
organization_name: Union[None, str]
|
|
36
|
+
model_id_used: str
|
|
37
|
+
api_endpoint: str
|
|
38
|
+
input_tokens: int
|
|
39
|
+
output_tokens: int
|
|
40
|
+
credits_deducted: str
|
|
41
|
+
request_payload_preview: Union[None, str]
|
|
42
|
+
response_payload_preview: Union[None, str]
|
|
43
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
44
|
+
|
|
45
|
+
def to_dict(self) -> dict[str, Any]:
|
|
46
|
+
id = self.id
|
|
47
|
+
|
|
48
|
+
timestamp = self.timestamp.isoformat()
|
|
49
|
+
|
|
50
|
+
api_key_prefix: Union[None, str]
|
|
51
|
+
api_key_prefix = self.api_key_prefix
|
|
52
|
+
|
|
53
|
+
user_username: Union[None, str]
|
|
54
|
+
user_username = self.user_username
|
|
55
|
+
|
|
56
|
+
organization_name: Union[None, str]
|
|
57
|
+
organization_name = self.organization_name
|
|
58
|
+
|
|
59
|
+
model_id_used = self.model_id_used
|
|
60
|
+
|
|
61
|
+
api_endpoint = self.api_endpoint
|
|
62
|
+
|
|
63
|
+
input_tokens = self.input_tokens
|
|
64
|
+
|
|
65
|
+
output_tokens = self.output_tokens
|
|
66
|
+
|
|
67
|
+
credits_deducted = self.credits_deducted
|
|
68
|
+
|
|
69
|
+
request_payload_preview: Union[None, str]
|
|
70
|
+
request_payload_preview = self.request_payload_preview
|
|
71
|
+
|
|
72
|
+
response_payload_preview: Union[None, str]
|
|
73
|
+
response_payload_preview = self.response_payload_preview
|
|
74
|
+
|
|
75
|
+
field_dict: dict[str, Any] = {}
|
|
76
|
+
field_dict.update(self.additional_properties)
|
|
77
|
+
field_dict.update(
|
|
78
|
+
{
|
|
79
|
+
"id": id,
|
|
80
|
+
"timestamp": timestamp,
|
|
81
|
+
"api_key_prefix": api_key_prefix,
|
|
82
|
+
"user_username": user_username,
|
|
83
|
+
"organization_name": organization_name,
|
|
84
|
+
"model_id_used": model_id_used,
|
|
85
|
+
"api_endpoint": api_endpoint,
|
|
86
|
+
"input_tokens": input_tokens,
|
|
87
|
+
"output_tokens": output_tokens,
|
|
88
|
+
"credits_deducted": credits_deducted,
|
|
89
|
+
"request_payload_preview": request_payload_preview,
|
|
90
|
+
"response_payload_preview": response_payload_preview,
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
return field_dict
|
|
95
|
+
|
|
96
|
+
@classmethod
|
|
97
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
98
|
+
d = dict(src_dict)
|
|
99
|
+
id = d.pop("id")
|
|
100
|
+
|
|
101
|
+
timestamp = isoparse(d.pop("timestamp"))
|
|
102
|
+
|
|
103
|
+
def _parse_api_key_prefix(data: object) -> Union[None, str]:
|
|
104
|
+
if data is None:
|
|
105
|
+
return data
|
|
106
|
+
return cast(Union[None, str], data)
|
|
107
|
+
|
|
108
|
+
api_key_prefix = _parse_api_key_prefix(d.pop("api_key_prefix"))
|
|
109
|
+
|
|
110
|
+
def _parse_user_username(data: object) -> Union[None, str]:
|
|
111
|
+
if data is None:
|
|
112
|
+
return data
|
|
113
|
+
return cast(Union[None, str], data)
|
|
114
|
+
|
|
115
|
+
user_username = _parse_user_username(d.pop("user_username"))
|
|
116
|
+
|
|
117
|
+
def _parse_organization_name(data: object) -> Union[None, str]:
|
|
118
|
+
if data is None:
|
|
119
|
+
return data
|
|
120
|
+
return cast(Union[None, str], data)
|
|
121
|
+
|
|
122
|
+
organization_name = _parse_organization_name(d.pop("organization_name"))
|
|
123
|
+
|
|
124
|
+
model_id_used = d.pop("model_id_used")
|
|
125
|
+
|
|
126
|
+
api_endpoint = d.pop("api_endpoint")
|
|
127
|
+
|
|
128
|
+
input_tokens = d.pop("input_tokens")
|
|
129
|
+
|
|
130
|
+
output_tokens = d.pop("output_tokens")
|
|
131
|
+
|
|
132
|
+
credits_deducted = d.pop("credits_deducted")
|
|
133
|
+
|
|
134
|
+
def _parse_request_payload_preview(data: object) -> Union[None, str]:
|
|
135
|
+
if data is None:
|
|
136
|
+
return data
|
|
137
|
+
return cast(Union[None, str], data)
|
|
138
|
+
|
|
139
|
+
request_payload_preview = _parse_request_payload_preview(
|
|
140
|
+
d.pop("request_payload_preview")
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def _parse_response_payload_preview(data: object) -> Union[None, str]:
|
|
144
|
+
if data is None:
|
|
145
|
+
return data
|
|
146
|
+
return cast(Union[None, str], data)
|
|
147
|
+
|
|
148
|
+
response_payload_preview = _parse_response_payload_preview(
|
|
149
|
+
d.pop("response_payload_preview")
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
api_token_log = cls(
|
|
153
|
+
id=id,
|
|
154
|
+
timestamp=timestamp,
|
|
155
|
+
api_key_prefix=api_key_prefix,
|
|
156
|
+
user_username=user_username,
|
|
157
|
+
organization_name=organization_name,
|
|
158
|
+
model_id_used=model_id_used,
|
|
159
|
+
api_endpoint=api_endpoint,
|
|
160
|
+
input_tokens=input_tokens,
|
|
161
|
+
output_tokens=output_tokens,
|
|
162
|
+
credits_deducted=credits_deducted,
|
|
163
|
+
request_payload_preview=request_payload_preview,
|
|
164
|
+
response_payload_preview=response_payload_preview,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
api_token_log.additional_properties = d
|
|
168
|
+
return api_token_log
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def additional_keys(self) -> list[str]:
|
|
172
|
+
return list(self.additional_properties.keys())
|
|
173
|
+
|
|
174
|
+
def __getitem__(self, key: str) -> Any:
|
|
175
|
+
return self.additional_properties[key]
|
|
176
|
+
|
|
177
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
178
|
+
self.additional_properties[key] = value
|
|
179
|
+
|
|
180
|
+
def __delitem__(self, key: str) -> None:
|
|
181
|
+
del self.additional_properties[key]
|
|
182
|
+
|
|
183
|
+
def __contains__(self, key: str) -> bool:
|
|
184
|
+
return key in self.additional_properties
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
from collections.abc import Mapping
|
|
3
|
+
from typing import Any, TypeVar, Union, cast
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
|
|
6
|
+
from attrs import define as _attrs_define
|
|
7
|
+
from attrs import field as _attrs_field
|
|
8
|
+
from dateutil.parser import isoparse
|
|
9
|
+
|
|
10
|
+
T = TypeVar("T", bound="Attack")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@_attrs_define
|
|
14
|
+
class Attack:
|
|
15
|
+
"""Serializer for the Attack model, which represents an Attack configuration.
|
|
16
|
+
|
|
17
|
+
Handles the conversion of Attack configuration instances to JSON (and vice-versa)
|
|
18
|
+
for API requests and responses. It includes read-only fields for related
|
|
19
|
+
object names (like agent_name, owner_username) for convenience in API outputs.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
id (UUID):
|
|
23
|
+
type_ (str): A string identifier for the type of attack being configured (e.g., 'PREFIX_GENERATION',
|
|
24
|
+
'PROMPT_INJECTION').
|
|
25
|
+
agent (UUID):
|
|
26
|
+
agent_name (str):
|
|
27
|
+
owner (Union[None, int]):
|
|
28
|
+
owner_username (str):
|
|
29
|
+
organization (UUID):
|
|
30
|
+
organization_name (str):
|
|
31
|
+
configuration (Any): JSON containing client-provided configuration for an attack using this definition.
|
|
32
|
+
created_at (datetime.datetime):
|
|
33
|
+
updated_at (datetime.datetime):
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
id: UUID
|
|
37
|
+
type_: str
|
|
38
|
+
agent: UUID
|
|
39
|
+
agent_name: str
|
|
40
|
+
owner: Union[None, int]
|
|
41
|
+
owner_username: str
|
|
42
|
+
organization: UUID
|
|
43
|
+
organization_name: str
|
|
44
|
+
configuration: Any
|
|
45
|
+
created_at: datetime.datetime
|
|
46
|
+
updated_at: datetime.datetime
|
|
47
|
+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
48
|
+
|
|
49
|
+
def to_dict(self) -> dict[str, Any]:
|
|
50
|
+
id = str(self.id)
|
|
51
|
+
|
|
52
|
+
type_ = self.type_
|
|
53
|
+
|
|
54
|
+
agent = str(self.agent)
|
|
55
|
+
|
|
56
|
+
agent_name = self.agent_name
|
|
57
|
+
|
|
58
|
+
owner: Union[None, int]
|
|
59
|
+
owner = self.owner
|
|
60
|
+
|
|
61
|
+
owner_username = self.owner_username
|
|
62
|
+
|
|
63
|
+
organization = str(self.organization)
|
|
64
|
+
|
|
65
|
+
organization_name = self.organization_name
|
|
66
|
+
|
|
67
|
+
configuration = self.configuration
|
|
68
|
+
|
|
69
|
+
created_at = self.created_at.isoformat()
|
|
70
|
+
|
|
71
|
+
updated_at = self.updated_at.isoformat()
|
|
72
|
+
|
|
73
|
+
field_dict: dict[str, Any] = {}
|
|
74
|
+
field_dict.update(self.additional_properties)
|
|
75
|
+
field_dict.update(
|
|
76
|
+
{
|
|
77
|
+
"id": id,
|
|
78
|
+
"type": type_,
|
|
79
|
+
"agent": agent,
|
|
80
|
+
"agent_name": agent_name,
|
|
81
|
+
"owner": owner,
|
|
82
|
+
"owner_username": owner_username,
|
|
83
|
+
"organization": organization,
|
|
84
|
+
"organization_name": organization_name,
|
|
85
|
+
"configuration": configuration,
|
|
86
|
+
"created_at": created_at,
|
|
87
|
+
"updated_at": updated_at,
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return field_dict
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
95
|
+
d = dict(src_dict)
|
|
96
|
+
id = UUID(d.pop("id"))
|
|
97
|
+
|
|
98
|
+
type_ = d.pop("type")
|
|
99
|
+
|
|
100
|
+
agent = UUID(d.pop("agent"))
|
|
101
|
+
|
|
102
|
+
agent_name = d.pop("agent_name")
|
|
103
|
+
|
|
104
|
+
def _parse_owner(data: object) -> Union[None, int]:
|
|
105
|
+
if data is None:
|
|
106
|
+
return data
|
|
107
|
+
return cast(Union[None, int], data)
|
|
108
|
+
|
|
109
|
+
owner = _parse_owner(d.pop("owner"))
|
|
110
|
+
|
|
111
|
+
owner_username = d.pop("owner_username")
|
|
112
|
+
|
|
113
|
+
organization = UUID(d.pop("organization"))
|
|
114
|
+
|
|
115
|
+
organization_name = d.pop("organization_name")
|
|
116
|
+
|
|
117
|
+
configuration = d.pop("configuration")
|
|
118
|
+
|
|
119
|
+
created_at = isoparse(d.pop("created_at"))
|
|
120
|
+
|
|
121
|
+
updated_at = isoparse(d.pop("updated_at"))
|
|
122
|
+
|
|
123
|
+
attack = cls(
|
|
124
|
+
id=id,
|
|
125
|
+
type_=type_,
|
|
126
|
+
agent=agent,
|
|
127
|
+
agent_name=agent_name,
|
|
128
|
+
owner=owner,
|
|
129
|
+
owner_username=owner_username,
|
|
130
|
+
organization=organization,
|
|
131
|
+
organization_name=organization_name,
|
|
132
|
+
configuration=configuration,
|
|
133
|
+
created_at=created_at,
|
|
134
|
+
updated_at=updated_at,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
attack.additional_properties = d
|
|
138
|
+
return attack
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def additional_keys(self) -> list[str]:
|
|
142
|
+
return list(self.additional_properties.keys())
|
|
143
|
+
|
|
144
|
+
def __getitem__(self, key: str) -> Any:
|
|
145
|
+
return self.additional_properties[key]
|
|
146
|
+
|
|
147
|
+
def __setitem__(self, key: str, value: Any) -> None:
|
|
148
|
+
self.additional_properties[key] = value
|
|
149
|
+
|
|
150
|
+
def __delitem__(self, key: str) -> None:
|
|
151
|
+
del self.additional_properties[key]
|
|
152
|
+
|
|
153
|
+
def __contains__(self, key: str) -> bool:
|
|
154
|
+
return key in self.additional_properties
|