ap-client 0.7.1.dev2__tar.gz → 0.7.1.dev5__tar.gz
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.
- ap_client-0.7.1.dev5/.gitignore +260 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/PKG-INFO +6 -5
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/__init__.py +1 -1
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/api.py +282 -6
- ap_client-0.7.1.dev5/ap_client/canonical_get.py +210 -0
- ap_client-0.7.1.dev5/ap_client/canonical_put.py +914 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/cli.py +165 -58
- ap_client-0.7.1.dev5/ap_client/cluster_layout_fetcher.py +357 -0
- ap_client-0.7.1.dev5/ap_client/cluster_region_resolver.py +394 -0
- ap_client-0.7.1.dev5/ap_client/control_http.py +415 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/dataset_commands.py +344 -41
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/dfs_commands.py +44 -14
- ap_client-0.7.1.dev5/ap_client/fs_commands.py +765 -0
- ap_client-0.7.1.dev5/ap_client/fs_storage.py +53 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/instance_commands.py +30 -4
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/irepo_sdk.py +374 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/ossutil_io.py +177 -77
- ap_client-0.7.1.dev5/ap_client/profile_cascade_all.py +149 -0
- ap_client-0.7.1.dev5/ap_client/profile_cascade_cli.py +356 -0
- ap_client-0.7.1.dev5/ap_client/profile_cascade_display.py +279 -0
- ap_client-0.7.1.dev5/ap_client/profile_cascade_state.py +207 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/profile_commands.py +538 -48
- ap_client-0.7.1.dev5/ap_client/profile_diagnostics.py +121 -0
- ap_client-0.7.1.dev5/ap_client/profile_display.py +194 -0
- ap_client-0.7.1.dev5/ap_client/profile_references.py +41 -0
- ap_client-0.7.1.dev5/ap_client/replica_policy.py +114 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/repo_read_guard.py +14 -3
- ap_client-0.7.1.dev5/ap_client/shared_adapter.py +1442 -0
- ap_client-0.7.1.dev5/ap_client/shared_commands.py +1114 -0
- ap_client-0.7.1.dev5/ap_client/submission_metadata.py +162 -0
- ap_client-0.7.1.dev5/ap_client/tool_manifest.py +184 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/pyproject.toml +5 -4
- ap_client-0.7.1.dev2/ap_client/fs_commands.py +0 -861
- ap_client-0.7.1.dev2/ap_client/fs_storage.py +0 -146
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/akpool_commands.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/config.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/dataset_name.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/dataset_register.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/exporter.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/fs_transfer.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/instance_options.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/managed_ak.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/manifest_view.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/ossutil_hash.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/share_api.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/split_publish.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/tbb.py +0 -0
- {ap_client-0.7.1.dev2 → ap_client-0.7.1.dev5}/ap_client/waiter.py +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
|
|
2
|
+
# Local config (never commit — copy from .env.example)
|
|
3
|
+
.env
|
|
4
|
+
tests/integration/.env
|
|
5
|
+
|
|
6
|
+
# Byte-compiled / optimized / DLL files
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[codz]
|
|
9
|
+
*$py.class
|
|
10
|
+
|
|
11
|
+
# C extensions
|
|
12
|
+
*.so
|
|
13
|
+
|
|
14
|
+
# Distribution / packaging
|
|
15
|
+
.Python
|
|
16
|
+
build/
|
|
17
|
+
develop-eggs/
|
|
18
|
+
dist/
|
|
19
|
+
downloads/
|
|
20
|
+
eggs/
|
|
21
|
+
.eggs/
|
|
22
|
+
lib/
|
|
23
|
+
lib64/
|
|
24
|
+
parts/
|
|
25
|
+
sdist/
|
|
26
|
+
var/
|
|
27
|
+
wheels/
|
|
28
|
+
share/python-wheels/
|
|
29
|
+
*.egg-info/
|
|
30
|
+
.installed.cfg
|
|
31
|
+
*.egg
|
|
32
|
+
MANIFEST
|
|
33
|
+
|
|
34
|
+
# PyInstaller
|
|
35
|
+
# Usually these files are written by a python script from a template
|
|
36
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
37
|
+
*.manifest
|
|
38
|
+
*.spec
|
|
39
|
+
|
|
40
|
+
# Installer logs
|
|
41
|
+
pip-log.txt
|
|
42
|
+
pip-delete-this-directory.txt
|
|
43
|
+
|
|
44
|
+
# Unit test / coverage reports
|
|
45
|
+
htmlcov/
|
|
46
|
+
.tox/
|
|
47
|
+
.nox/
|
|
48
|
+
.coverage
|
|
49
|
+
.coverage.*
|
|
50
|
+
.cache
|
|
51
|
+
nosetests.xml
|
|
52
|
+
coverage.xml
|
|
53
|
+
*.cover
|
|
54
|
+
*.py.cover
|
|
55
|
+
.hypothesis/
|
|
56
|
+
.pytest_cache/
|
|
57
|
+
cover/
|
|
58
|
+
|
|
59
|
+
# Translations
|
|
60
|
+
*.mo
|
|
61
|
+
*.pot
|
|
62
|
+
|
|
63
|
+
# Django stuff:
|
|
64
|
+
*.log
|
|
65
|
+
local_settings.py
|
|
66
|
+
db.sqlite3
|
|
67
|
+
db.sqlite3-journal
|
|
68
|
+
|
|
69
|
+
# Flask stuff:
|
|
70
|
+
instance/
|
|
71
|
+
.webassets-cache
|
|
72
|
+
|
|
73
|
+
# Scrapy stuff:
|
|
74
|
+
.scrapy
|
|
75
|
+
|
|
76
|
+
# Sphinx documentation
|
|
77
|
+
docs/_build/
|
|
78
|
+
|
|
79
|
+
# PyBuilder
|
|
80
|
+
.pybuilder/
|
|
81
|
+
target/
|
|
82
|
+
|
|
83
|
+
# Jupyter Notebook
|
|
84
|
+
.ipynb_checkpoints
|
|
85
|
+
|
|
86
|
+
# IPython
|
|
87
|
+
profile_default/
|
|
88
|
+
ipython_config.py
|
|
89
|
+
|
|
90
|
+
# pyenv
|
|
91
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
92
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
93
|
+
# .python-version
|
|
94
|
+
|
|
95
|
+
# pipenv
|
|
96
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
97
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
98
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
99
|
+
# install all needed dependencies.
|
|
100
|
+
# Pipfile.lock
|
|
101
|
+
|
|
102
|
+
# UV
|
|
103
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
104
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
105
|
+
# commonly ignored for libraries.
|
|
106
|
+
# uv.lock
|
|
107
|
+
|
|
108
|
+
# poetry
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
110
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
111
|
+
# commonly ignored for libraries.
|
|
112
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
113
|
+
# poetry.lock
|
|
114
|
+
# poetry.toml
|
|
115
|
+
|
|
116
|
+
# pdm
|
|
117
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
118
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
119
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
120
|
+
# pdm.lock
|
|
121
|
+
# pdm.toml
|
|
122
|
+
.pdm-python
|
|
123
|
+
.pdm-build/
|
|
124
|
+
|
|
125
|
+
# pixi
|
|
126
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
127
|
+
# pixi.lock
|
|
128
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
129
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
130
|
+
.pixi
|
|
131
|
+
|
|
132
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
133
|
+
__pypackages__/
|
|
134
|
+
|
|
135
|
+
# Celery stuff
|
|
136
|
+
celerybeat-schedule
|
|
137
|
+
celerybeat.pid
|
|
138
|
+
|
|
139
|
+
# Redis
|
|
140
|
+
*.rdb
|
|
141
|
+
*.aof
|
|
142
|
+
*.pid
|
|
143
|
+
|
|
144
|
+
# RabbitMQ
|
|
145
|
+
mnesia/
|
|
146
|
+
rabbitmq/
|
|
147
|
+
rabbitmq-data/
|
|
148
|
+
|
|
149
|
+
# ActiveMQ
|
|
150
|
+
activemq-data/
|
|
151
|
+
|
|
152
|
+
# SageMath parsed files
|
|
153
|
+
*.sage.py
|
|
154
|
+
|
|
155
|
+
# Environments
|
|
156
|
+
.envrc
|
|
157
|
+
.venv
|
|
158
|
+
env/
|
|
159
|
+
venv/
|
|
160
|
+
ENV/
|
|
161
|
+
env.bak/
|
|
162
|
+
venv.bak/
|
|
163
|
+
|
|
164
|
+
# Spyder project settings
|
|
165
|
+
.spyderproject
|
|
166
|
+
.spyproject
|
|
167
|
+
|
|
168
|
+
# Rope project settings
|
|
169
|
+
.ropeproject
|
|
170
|
+
|
|
171
|
+
# mkdocs documentation
|
|
172
|
+
/site
|
|
173
|
+
|
|
174
|
+
# mypy
|
|
175
|
+
.mypy_cache/
|
|
176
|
+
.dmypy.json
|
|
177
|
+
dmypy.json
|
|
178
|
+
|
|
179
|
+
# Pyre type checker
|
|
180
|
+
.pyre/
|
|
181
|
+
|
|
182
|
+
# pytype static type analyzer
|
|
183
|
+
.pytype/
|
|
184
|
+
|
|
185
|
+
# Cython debug symbols
|
|
186
|
+
cython_debug/
|
|
187
|
+
|
|
188
|
+
# PyCharm
|
|
189
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
190
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
191
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
192
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
193
|
+
# .idea/
|
|
194
|
+
|
|
195
|
+
# Abstra
|
|
196
|
+
# Abstra is an AI-powered process automation framework.
|
|
197
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
198
|
+
# Learn more at https://abstra.io/docs
|
|
199
|
+
.abstra/
|
|
200
|
+
|
|
201
|
+
# Visual Studio Code
|
|
202
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
203
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
204
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
205
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
206
|
+
.vscode/
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
results/
|
|
224
|
+
ix-run*/
|
|
225
|
+
CLAUDE.md
|
|
226
|
+
.claude/*
|
|
227
|
+
!.claude/skills/
|
|
228
|
+
DESIGN.md
|
|
229
|
+
deploy/k8s/secret.yaml
|
|
230
|
+
# Generated by deploy/gitops/prepare_cluster.py; may contain live credentials.
|
|
231
|
+
deploy/gitops/clusters/*/secrets.yaml
|
|
232
|
+
.idea/
|
|
233
|
+
web/
|
|
234
|
+
.qoder/
|
|
235
|
+
.DS_Store
|
|
236
|
+
|
|
237
|
+
# Stress test output files
|
|
238
|
+
stress-test/results.txt
|
|
239
|
+
stress-test/stress_report*.md
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
.DS_Store
|
|
243
|
+
|
|
244
|
+
# Git worktrees
|
|
245
|
+
.worktrees/
|
|
246
|
+
|
|
247
|
+
artifacts/
|
|
248
|
+
logs/backend.log.*
|
|
249
|
+
|
|
250
|
+
# Temporary diff files
|
|
251
|
+
.tmp_*
|
|
252
|
+
|
|
253
|
+
# local dev scratch (cluster endpoints, scripts) — not for commit
|
|
254
|
+
.dev/
|
|
255
|
+
|
|
256
|
+
# Temporary files
|
|
257
|
+
temp/
|
|
258
|
+
|
|
259
|
+
# Local implementation notes
|
|
260
|
+
/AK_IMPLEMENTATION_RESULT.md
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: ap-client
|
|
3
|
-
Version: 0.7.1.
|
|
3
|
+
Version: 0.7.1.dev5
|
|
4
4
|
Summary: Agent Platform API Client & CLI
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: click<8.2.0,>=8.1.8
|
|
6
7
|
Requires-Dist: irepo-artifact==0.2.4
|
|
7
8
|
Requires-Dist: pyyaml>=6.0
|
|
8
9
|
Requires-Dist: requests>=2.28.0
|
|
9
10
|
Requires-Dist: rich>=13.0.0
|
|
10
|
-
Requires-Dist: typer
|
|
11
|
+
Requires-Dist: typer<0.21.0,>=0.20.1
|
|
11
12
|
Requires-Dist: websockets>=13.0
|
|
12
13
|
Provides-Extra: all
|
|
13
|
-
Requires-Dist: instance-repo[oss]
|
|
14
|
+
Requires-Dist: instance-repo[oss]==1.6.0.dev2; extra == 'all'
|
|
14
15
|
Provides-Extra: dataset
|
|
15
|
-
Requires-Dist: instance-repo[oss]
|
|
16
|
+
Requires-Dist: instance-repo[oss]==1.6.0.dev2; extra == 'dataset'
|
|
16
17
|
Description-Content-Type: text/markdown
|
|
17
18
|
|
|
18
19
|
A lightweight Python SDK and command line interface for Agent Platform. It provides helpers for configuring API access and managing templates, datasets, jobs, and groups.
|
|
@@ -6,6 +6,7 @@ import os
|
|
|
6
6
|
import platform
|
|
7
7
|
import re
|
|
8
8
|
import sys
|
|
9
|
+
import threading
|
|
9
10
|
import time
|
|
10
11
|
import uuid
|
|
11
12
|
from email.utils import parsedate_to_datetime
|
|
@@ -287,6 +288,14 @@ class APIError(Exception):
|
|
|
287
288
|
return f"API Error {self.status_code}: {self.detail} (request_id={self.request_id})"
|
|
288
289
|
|
|
289
290
|
|
|
291
|
+
class CanonicalControlAPIError(APIError):
|
|
292
|
+
"""Operation-only sanitized error; never holds a native response or cause."""
|
|
293
|
+
def __init__(self, reason, *, status_code=None, biz_code=None):
|
|
294
|
+
self.reason = reason
|
|
295
|
+
detail = {"code": biz_code} if type(biz_code) is int else "canonical control request failed"
|
|
296
|
+
super().__init__(status_code, detail, None, None)
|
|
297
|
+
|
|
298
|
+
|
|
290
299
|
class PaginationProtocolError(RuntimeError):
|
|
291
300
|
"""The server stopped honoring a pagination protocol already in use."""
|
|
292
301
|
|
|
@@ -371,6 +380,8 @@ class APIClient:
|
|
|
371
380
|
|
|
372
381
|
def __init__(self, config: Config):
|
|
373
382
|
self.config = config
|
|
383
|
+
self._control_channel = None
|
|
384
|
+
self._control_channel_lock = threading.Lock()
|
|
374
385
|
self.session = requests.Session()
|
|
375
386
|
headers = dict(config.headers)
|
|
376
387
|
user_agent = _build_user_agent(headers.get("User-Agent"))
|
|
@@ -426,8 +437,13 @@ class APIClient:
|
|
|
426
437
|
timeout: TimeoutType = None,
|
|
427
438
|
deadline: Optional[float] = None,
|
|
428
439
|
_return_response: bool = False,
|
|
440
|
+
max_response_bytes: Optional[int] = None,
|
|
429
441
|
) -> Any:
|
|
430
|
-
"""Send
|
|
442
|
+
"""Send through the normal channel unless bounded control is opted in."""
|
|
443
|
+
if max_response_bytes is not None:
|
|
444
|
+
return self._request_control_json(method, path, params=params,
|
|
445
|
+
json_body=json_body, timeout=timeout, deadline=deadline,
|
|
446
|
+
max_response_bytes=max_response_bytes, return_response=_return_response)
|
|
431
447
|
self._require_cluster_config()
|
|
432
448
|
return self._request_http(
|
|
433
449
|
method,
|
|
@@ -596,6 +612,130 @@ class APIClient:
|
|
|
596
612
|
raise APIError(resp.status_code, detail, request_id, resp) from exc
|
|
597
613
|
raise RuntimeError("unreachable retry state")
|
|
598
614
|
|
|
615
|
+
def _request_control_json(self, method, path, *, params, json_body, timeout,
|
|
616
|
+
deadline, max_response_bytes, return_response):
|
|
617
|
+
from .control_http import (ControlHTTPError, OwnedControlChannel, validate_limit,
|
|
618
|
+
_check_deadline)
|
|
619
|
+
|
|
620
|
+
if return_response:
|
|
621
|
+
raise CanonicalControlAPIError("invalid_request")
|
|
622
|
+
self._require_cluster_config()
|
|
623
|
+
failure = None
|
|
624
|
+
try:
|
|
625
|
+
validate_limit(max_response_bytes)
|
|
626
|
+
_check_deadline(deadline)
|
|
627
|
+
if isinstance(timeout, bool):
|
|
628
|
+
raise ControlHTTPError('invalid_deadline')
|
|
629
|
+
if isinstance(timeout, (int, float)):
|
|
630
|
+
if not math.isfinite(timeout) or timeout < 0:
|
|
631
|
+
raise ControlHTTPError('invalid_deadline')
|
|
632
|
+
if deadline is None:
|
|
633
|
+
# A finite SDK per-request remaining duration owns one
|
|
634
|
+
# deadline across this request's retries, never per attempt.
|
|
635
|
+
deadline = time.monotonic() + timeout
|
|
636
|
+
_check_deadline(deadline)
|
|
637
|
+
except ControlHTTPError as exc:
|
|
638
|
+
failure = CanonicalControlAPIError(exc.reason)
|
|
639
|
+
if failure is not None:
|
|
640
|
+
raise failure
|
|
641
|
+
with self._control_channel_lock:
|
|
642
|
+
if self._control_channel is None:
|
|
643
|
+
self._control_channel = OwnedControlChannel(self.session)
|
|
644
|
+
channel = self._control_channel
|
|
645
|
+
timeout = _default_timeout() if timeout is None else _normalize_explicit_timeout(timeout)
|
|
646
|
+
url = self._url(path)
|
|
647
|
+
attempts = self._max_attempts_for(method)
|
|
648
|
+
for attempt in range(1, attempts + 1):
|
|
649
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
650
|
+
raise CanonicalControlAPIError("deadline")
|
|
651
|
+
failure = response = None
|
|
652
|
+
try:
|
|
653
|
+
response = channel.request(method, url, headers={"X-Request-ID": str(uuid.uuid4())},
|
|
654
|
+
params=params, json_body=json_body,
|
|
655
|
+
timeout=_deadline_timeout(timeout, deadline), deadline=deadline,
|
|
656
|
+
max_response_bytes=max_response_bytes)
|
|
657
|
+
except ControlHTTPError as exc:
|
|
658
|
+
failure = CanonicalControlAPIError(exc.reason, status_code=exc.status)
|
|
659
|
+
retryable = exc.retryable or (exc.status is not None and
|
|
660
|
+
_is_retryable_status(exc.status) and exc.reason != "redirect")
|
|
661
|
+
except APIError:
|
|
662
|
+
failure = CanonicalControlAPIError("deadline")
|
|
663
|
+
retryable = False
|
|
664
|
+
if failure is not None:
|
|
665
|
+
if attempt < attempts and retryable:
|
|
666
|
+
delay = _retry_delay(attempt)
|
|
667
|
+
if deadline is not None:
|
|
668
|
+
remaining = deadline - time.monotonic()
|
|
669
|
+
if remaining <= 0:
|
|
670
|
+
raise CanonicalControlAPIError("deadline")
|
|
671
|
+
delay = min(delay, remaining)
|
|
672
|
+
time.sleep(delay)
|
|
673
|
+
continue
|
|
674
|
+
raise failure
|
|
675
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
676
|
+
raise CanonicalControlAPIError("deadline")
|
|
677
|
+
if not 200 <= response.status_code < 300:
|
|
678
|
+
if attempt < attempts and _is_retryable_status(response.status_code):
|
|
679
|
+
try:
|
|
680
|
+
delay = _retry_delay(attempt, response)
|
|
681
|
+
except (ValueError, TypeError, OverflowError, OSError):
|
|
682
|
+
delay = _retry_delay(attempt)
|
|
683
|
+
if not math.isfinite(delay):
|
|
684
|
+
delay = _retry_delay(attempt)
|
|
685
|
+
if deadline is not None:
|
|
686
|
+
remaining = deadline - time.monotonic()
|
|
687
|
+
if remaining <= 0:
|
|
688
|
+
raise CanonicalControlAPIError("deadline")
|
|
689
|
+
delay = min(delay, remaining)
|
|
690
|
+
time.sleep(delay)
|
|
691
|
+
continue
|
|
692
|
+
parsed = None
|
|
693
|
+
if response.refusal is None:
|
|
694
|
+
try:
|
|
695
|
+
parsed = json.loads(response.content.decode("utf-8", errors="replace"))
|
|
696
|
+
except (ValueError, UnicodeError, RecursionError):
|
|
697
|
+
pass
|
|
698
|
+
# Preserve both existing API envelope shapes while retaining
|
|
699
|
+
# only the typed numeric classification, never message/data.
|
|
700
|
+
detail = parsed.get("detail", parsed) if isinstance(parsed, dict) else None
|
|
701
|
+
if isinstance(detail, str):
|
|
702
|
+
decoded = None
|
|
703
|
+
try:
|
|
704
|
+
decoded = json.loads(detail)
|
|
705
|
+
except (ValueError, RecursionError):
|
|
706
|
+
pass
|
|
707
|
+
detail = decoded
|
|
708
|
+
code = detail.get("code") if isinstance(detail, dict) else None
|
|
709
|
+
raise CanonicalControlAPIError("http_error", status_code=response.status_code,
|
|
710
|
+
biz_code=code if type(code) is int else None)
|
|
711
|
+
if not response.content:
|
|
712
|
+
return None
|
|
713
|
+
text = None
|
|
714
|
+
try:
|
|
715
|
+
text = response.content.decode("utf-8", errors="strict")
|
|
716
|
+
except UnicodeError:
|
|
717
|
+
pass
|
|
718
|
+
if text is None:
|
|
719
|
+
raise CanonicalControlAPIError("invalid_utf8", status_code=response.status_code)
|
|
720
|
+
parsed = None
|
|
721
|
+
valid_json = False
|
|
722
|
+
try:
|
|
723
|
+
parsed = json.loads(text)
|
|
724
|
+
valid_json = True
|
|
725
|
+
except (ValueError, RecursionError):
|
|
726
|
+
pass
|
|
727
|
+
if not valid_json:
|
|
728
|
+
raise CanonicalControlAPIError("invalid_json", status_code=response.status_code)
|
|
729
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
730
|
+
raise CanonicalControlAPIError("deadline")
|
|
731
|
+
return parsed
|
|
732
|
+
raise CanonicalControlAPIError("network")
|
|
733
|
+
|
|
734
|
+
def _max_attempts_for(self, method: str) -> int:
|
|
735
|
+
if method.upper() not in _RETRYABLE_METHODS:
|
|
736
|
+
return 1
|
|
737
|
+
return max(1, self.config.http_max_attempts)
|
|
738
|
+
|
|
599
739
|
def _require_cluster_config(self) -> None:
|
|
600
740
|
if has_cluster_header(self.config.headers):
|
|
601
741
|
return
|
|
@@ -1204,6 +1344,7 @@ class APIClient:
|
|
|
1204
1344
|
priority_weight: Optional[int] = None,
|
|
1205
1345
|
transparency: Optional[Literal["whitebox", "blackbox"]] = None,
|
|
1206
1346
|
idempotency_key: Optional[str] = None,
|
|
1347
|
+
group_concurrency_policy: Optional[dict] = None,
|
|
1207
1348
|
) -> dict:
|
|
1208
1349
|
"""Create a group with optional scheduling defaults for its Jobs.
|
|
1209
1350
|
|
|
@@ -1254,6 +1395,8 @@ class APIClient:
|
|
|
1254
1395
|
effective_queue_id = queue_id if queue_id is not None else queue
|
|
1255
1396
|
if effective_queue_id is not None:
|
|
1256
1397
|
body["queue_id"] = effective_queue_id
|
|
1398
|
+
if group_concurrency_policy is not None:
|
|
1399
|
+
body["group_concurrency_policy"] = group_concurrency_policy
|
|
1257
1400
|
if max_concurrency is not None:
|
|
1258
1401
|
body["max_concurrency"] = max_concurrency
|
|
1259
1402
|
if priority is not None:
|
|
@@ -2048,6 +2191,7 @@ class APIClient:
|
|
|
2048
2191
|
priority: Optional[str] = None,
|
|
2049
2192
|
priority_weight: Optional[int] = None,
|
|
2050
2193
|
priority_update_mode: Optional[str] = None,
|
|
2194
|
+
group_concurrency_policy: Optional[dict] = None,
|
|
2051
2195
|
) -> dict:
|
|
2052
2196
|
"""Update group properties.
|
|
2053
2197
|
|
|
@@ -2075,6 +2219,8 @@ class APIClient:
|
|
|
2075
2219
|
raise ValueError("priority_update_mode requires priority or priority_weight")
|
|
2076
2220
|
body: dict = {}
|
|
2077
2221
|
|
|
2222
|
+
if group_concurrency_policy is not None:
|
|
2223
|
+
body["group_concurrency_policy"] = group_concurrency_policy
|
|
2078
2224
|
if max_concurrency is not None:
|
|
2079
2225
|
body["max_concurrency"] = max_concurrency
|
|
2080
2226
|
if eval_config is not None:
|
|
@@ -3072,6 +3218,8 @@ class APIClient:
|
|
|
3072
3218
|
account_pool: Optional[str] = None,
|
|
3073
3219
|
metadata: Optional[dict] = None,
|
|
3074
3220
|
tags: Optional[list[str]] = None,
|
|
3221
|
+
parents: Optional[list[str | dict]] = None,
|
|
3222
|
+
auto_follow_parents: Optional[list[str]] = None,
|
|
3075
3223
|
) -> dict:
|
|
3076
3224
|
"""Create a new submission profile."""
|
|
3077
3225
|
body: dict = {"name": name, "spec": spec}
|
|
@@ -3083,6 +3231,10 @@ class APIClient:
|
|
|
3083
3231
|
body["metadata"] = metadata
|
|
3084
3232
|
if tags is not None:
|
|
3085
3233
|
body["tags"] = tags
|
|
3234
|
+
if parents is not None:
|
|
3235
|
+
body["parents"] = parents
|
|
3236
|
+
if auto_follow_parents is not None:
|
|
3237
|
+
body["auto_follow_parents"] = auto_follow_parents
|
|
3086
3238
|
return self._post(self._PROFILES_BASE, body)
|
|
3087
3239
|
|
|
3088
3240
|
def list_profiles(
|
|
@@ -3224,6 +3376,9 @@ class APIClient:
|
|
|
3224
3376
|
account_pool: Optional[str] = None,
|
|
3225
3377
|
metadata: Optional[dict] = None,
|
|
3226
3378
|
reason: Optional[str] = None,
|
|
3379
|
+
version: Optional[int] = None,
|
|
3380
|
+
parents: Optional[list[str | dict]] = None,
|
|
3381
|
+
auto_follow_parents: Optional[list[str]] = None,
|
|
3227
3382
|
) -> dict:
|
|
3228
3383
|
"""Update a submission profile, preserving an omitted default Pool.
|
|
3229
3384
|
|
|
@@ -3239,7 +3394,108 @@ class APIClient:
|
|
|
3239
3394
|
body["metadata"] = metadata
|
|
3240
3395
|
if reason is not None:
|
|
3241
3396
|
body["reason"] = reason
|
|
3242
|
-
|
|
3397
|
+
if version is not None:
|
|
3398
|
+
if type(version) is not int or version < 1:
|
|
3399
|
+
raise ValueError("version must be a positive integer")
|
|
3400
|
+
body["version"] = version
|
|
3401
|
+
if parents is not None:
|
|
3402
|
+
body["parents"] = parents
|
|
3403
|
+
if auto_follow_parents is not None:
|
|
3404
|
+
body["auto_follow_parents"] = auto_follow_parents
|
|
3405
|
+
return self._put(f"{self._PROFILES_BASE}/{quote(profile_id, safe='')}", body)
|
|
3406
|
+
|
|
3407
|
+
def patch_profile(self, profile_id: str, fields: dict) -> dict:
|
|
3408
|
+
"""Patch own definition; callers should supply their original version."""
|
|
3409
|
+
return self._request(
|
|
3410
|
+
"PATCH", f"{self._PROFILES_BASE}/{quote(profile_id, safe='')}", json_body=fields
|
|
3411
|
+
)
|
|
3412
|
+
|
|
3413
|
+
def resolve_profile(self, identifier: str, *, version: Optional[int] = None) -> dict:
|
|
3414
|
+
return self._get(
|
|
3415
|
+
f"{self._PROFILES_BASE}/{quote(identifier, safe='')}/resolved",
|
|
3416
|
+
params={"version": version} if version is not None else None,
|
|
3417
|
+
)
|
|
3418
|
+
|
|
3419
|
+
def preview_profile(self, draft: dict) -> dict:
|
|
3420
|
+
return self._post(f"{self._PROFILES_BASE}/resolve", draft)
|
|
3421
|
+
|
|
3422
|
+
def profile_children(
|
|
3423
|
+
self,
|
|
3424
|
+
identifier: str,
|
|
3425
|
+
*,
|
|
3426
|
+
page: int = 1,
|
|
3427
|
+
page_size: int = 20,
|
|
3428
|
+
target_version: Optional[int] = None,
|
|
3429
|
+
eligible_only: bool = False,
|
|
3430
|
+
current_only: bool = False,
|
|
3431
|
+
) -> dict:
|
|
3432
|
+
params = {"page": page, "page_size": page_size}
|
|
3433
|
+
if target_version is not None:
|
|
3434
|
+
params["target_version"] = target_version
|
|
3435
|
+
if eligible_only:
|
|
3436
|
+
params["eligible_only"] = "true"
|
|
3437
|
+
if current_only:
|
|
3438
|
+
params["current_only"] = "true"
|
|
3439
|
+
return self._get(
|
|
3440
|
+
f"{self._PROFILES_BASE}/{quote(identifier, safe='')}/children",
|
|
3441
|
+
params=params,
|
|
3442
|
+
)
|
|
3443
|
+
|
|
3444
|
+
def profile_diff(
|
|
3445
|
+
self,
|
|
3446
|
+
identifier: str,
|
|
3447
|
+
from_version: Optional[int] = None,
|
|
3448
|
+
to_version: Optional[int] = None,
|
|
3449
|
+
view: str = "own",
|
|
3450
|
+
*,
|
|
3451
|
+
compare_to: Optional[str] = None,
|
|
3452
|
+
) -> dict:
|
|
3453
|
+
"""Compare versions of one Profile, or two Profiles (omitted versions use current)."""
|
|
3454
|
+
params = {"from": from_version, "to": to_version, "view": view}
|
|
3455
|
+
if compare_to is not None:
|
|
3456
|
+
params["compare_to"] = compare_to
|
|
3457
|
+
result = self._get(
|
|
3458
|
+
f"{self._PROFILES_BASE}/{quote(identifier, safe='')}/diff",
|
|
3459
|
+
params=params,
|
|
3460
|
+
)
|
|
3461
|
+
if compare_to is not None:
|
|
3462
|
+
# Older servers ignore unknown query fields. Do not present their
|
|
3463
|
+
# single-Profile response as a successful cross-Profile comparison.
|
|
3464
|
+
for field in ("from_profile", "to_profile"):
|
|
3465
|
+
ref = result.get(field) if isinstance(result, dict) else None
|
|
3466
|
+
if (
|
|
3467
|
+
not isinstance(ref, dict)
|
|
3468
|
+
or not isinstance(ref.get("profile_id"), str)
|
|
3469
|
+
or not ref["profile_id"].startswith("sp-")
|
|
3470
|
+
or type(ref.get("version")) is not int
|
|
3471
|
+
or ref["version"] < 1
|
|
3472
|
+
):
|
|
3473
|
+
raise APIError(
|
|
3474
|
+
200,
|
|
3475
|
+
"Server did not confirm cross-Profile diff support; upgrade the server before comparing different Profiles",
|
|
3476
|
+
None,
|
|
3477
|
+
None,
|
|
3478
|
+
)
|
|
3479
|
+
return result
|
|
3480
|
+
|
|
3481
|
+
def cascade_profiles(self, identifier: str, request: dict) -> dict:
|
|
3482
|
+
return self._post(f"{self._PROFILES_BASE}/{quote(identifier, safe='')}/cascades", request)
|
|
3483
|
+
|
|
3484
|
+
def get_profile_cascade(self, operation_id: str) -> dict:
|
|
3485
|
+
return self._get(f"/apis/v1/profile-cascades/{quote(operation_id, safe='')}")
|
|
3486
|
+
|
|
3487
|
+
def profile_cascade_history(
|
|
3488
|
+
self, profile_id: str, *, page: int = 1, page_size: int = 20
|
|
3489
|
+
) -> dict:
|
|
3490
|
+
return self._get(
|
|
3491
|
+
f"{self._PROFILES_BASE}/{quote(profile_id, safe='')}/cascades",
|
|
3492
|
+
params={"page": page, "page_size": page_size},
|
|
3493
|
+
)
|
|
3494
|
+
|
|
3495
|
+
def retry_profile_cascade(self, operation_id: str, items: list[dict]) -> dict:
|
|
3496
|
+
return self._post(
|
|
3497
|
+
f"/apis/v1/profile-cascades/{quote(operation_id, safe='')}/retry", {"items": items}
|
|
3498
|
+
)
|
|
3243
3499
|
|
|
3244
3500
|
def delete_profile(self, profile_id: str) -> dict:
|
|
3245
3501
|
"""Delete a submission profile."""
|
|
@@ -3523,12 +3779,34 @@ def _redact_url_query_secrets(value: str) -> str:
|
|
|
3523
3779
|
|
|
3524
3780
|
|
|
3525
3781
|
def _response_error_detail(resp: requests.Response) -> Any:
|
|
3782
|
+
"""错误响应体 → detail(兼容两代服务端错误形态,G2 修复)。
|
|
3783
|
+
|
|
3784
|
+
* FastAPI ``{"detail": <str|dict>}``:保持旧语义——detail 键优先
|
|
3785
|
+
(dict 时**整个内层 dict** 作为 detail 返回,不只是取 message);
|
|
3786
|
+
* Go/Gin 裸信封 ``{code, message, data}``(apiserver
|
|
3787
|
+
``pkg/api/response/response.go writeErrorData``):**整个响应 dict**
|
|
3788
|
+
作为 detail 返回——9404x 数字 code 与 ``data``(error_code/
|
|
3789
|
+
apply_url 等结构化负载)不再被降级成 message 字符串丢失;
|
|
3790
|
+
* 旧 ``{"message": ...}``(无 detail)形态:保持旧语义取 message
|
|
3791
|
+
字符串(detail/message 缺省回退 resp.text)。
|
|
3792
|
+
|
|
3793
|
+
detail 消费方(如 shared_adapter._decode_api_error)按"dict 即结构化
|
|
3794
|
+
错误体"自行解 code/data;str detail 继续支持(旧展示路径不变)。
|
|
3795
|
+
"""
|
|
3526
3796
|
try:
|
|
3527
3797
|
err_data = resp.json()
|
|
3528
3798
|
except Exception:
|
|
3529
3799
|
return resp.text
|
|
3530
3800
|
if isinstance(err_data, dict):
|
|
3531
|
-
|
|
3801
|
+
if "detail" in err_data:
|
|
3802
|
+
inner = err_data["detail"]
|
|
3803
|
+
if isinstance(inner, dict):
|
|
3804
|
+
return inner # FastAPI detail=dict:内层即结构化错误体
|
|
3805
|
+
return inner # detail=str:旧语义
|
|
3806
|
+
if "code" in err_data:
|
|
3807
|
+
# Go 裸信封 {code, message, data}:保留完整结构化错误体
|
|
3808
|
+
return err_data
|
|
3809
|
+
return err_data.get("message", resp.text)
|
|
3532
3810
|
return err_data
|
|
3533
3811
|
|
|
3534
3812
|
|
|
@@ -3550,9 +3828,7 @@ def _retry_delay(
|
|
|
3550
3828
|
*,
|
|
3551
3829
|
max_wait: float | None = None,
|
|
3552
3830
|
) -> float:
|
|
3553
|
-
delay = _HTTP_RETRY_INITIAL_DELAY * (
|
|
3554
|
-
_HTTP_RETRY_BACKOFF_FACTOR ** min(2, max(0, attempt - 1))
|
|
3555
|
-
)
|
|
3831
|
+
delay = _HTTP_RETRY_INITIAL_DELAY * (_HTTP_RETRY_BACKOFF_FACTOR ** min(2, max(0, attempt - 1)))
|
|
3556
3832
|
# Local backoff may be shortened to the wait ceiling; a gateway hint never is.
|
|
3557
3833
|
if max_wait is not None:
|
|
3558
3834
|
delay = min(delay, max_wait)
|