ap-client 0.7.2.dev1__py3-none-any.whl → 0.7.2.dev2__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.
- ap_client/api.py +192 -3
- ap_client/canonical_put.py +35 -1
- ap_client/fs_commands.py +13 -1
- ap_client/shared_adapter.py +20 -3
- ap_client/shared_commands.py +4 -6
- {ap_client-0.7.2.dev1.dist-info → ap_client-0.7.2.dev2.dist-info}/METADATA +3 -3
- {ap_client-0.7.2.dev1.dist-info → ap_client-0.7.2.dev2.dist-info}/RECORD +9 -9
- {ap_client-0.7.2.dev1.dist-info → ap_client-0.7.2.dev2.dist-info}/WHEEL +0 -0
- {ap_client-0.7.2.dev1.dist-info → ap_client-0.7.2.dev2.dist-info}/entry_points.txt +0 -0
ap_client/api.py
CHANGED
|
@@ -306,6 +306,101 @@ class PaginationProtocolError(RuntimeError):
|
|
|
306
306
|
"""The server stopped honoring a pagination protocol already in use."""
|
|
307
307
|
|
|
308
308
|
|
|
309
|
+
# Bounded canonical control-response helpers (CR 30865361 review P1 fixes).
|
|
310
|
+
|
|
311
|
+
# Upper bound for one canonical control response body (metadata JSONs are
|
|
312
|
+
# small; this only bounds memory and the byte-drip amortisation window).
|
|
313
|
+
_DEFAULT_CONTROL_BYTES = 8 * 1024 * 1024
|
|
314
|
+
_MAX_CONTROL_BYTES = 64 * 1024 * 1024
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
class CanonicalControlAPIError(APIError):
|
|
318
|
+
"""Sanitized typed refusal for bounded canonical control requests.
|
|
319
|
+
|
|
320
|
+
Never holds a native response or raw cause; redirects are reported as
|
|
321
|
+
``redirect`` only after allow_redirects=False already prevented any
|
|
322
|
+
credential from following the Location."""
|
|
323
|
+
|
|
324
|
+
def __init__(self, reason, *, status_code=None, biz_code=None):
|
|
325
|
+
self.reason = reason
|
|
326
|
+
detail = {"code": biz_code} if type(biz_code) is int else "canonical control request failed"
|
|
327
|
+
super().__init__(status_code, detail, None, None)
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def _validate_control_bytes(limit: int) -> None:
|
|
331
|
+
if type(limit) is not int or not 1 <= limit <= _MAX_CONTROL_BYTES:
|
|
332
|
+
raise CanonicalControlAPIError("invalid_limit")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _close_response_quietly(resp) -> None:
|
|
336
|
+
"""Close a streamed response, tolerating already-closed objects."""
|
|
337
|
+
try:
|
|
338
|
+
resp.close()
|
|
339
|
+
except Exception:
|
|
340
|
+
pass
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _read_bounded_control_bytes(resp, limit: int = _DEFAULT_CONTROL_BYTES) -> bytes:
|
|
344
|
+
"""Stream one bounded canonical control response via public requests APIs.
|
|
345
|
+
|
|
346
|
+
Content-Length pre-check plus streamed chunk reads keep memory at
|
|
347
|
+
O(cap+chunk) — a byte-drip response cannot grow unbounded, and the
|
|
348
|
+
per-attempt HTTP timeout bounds each read syscall."""
|
|
349
|
+
_validate_control_bytes(limit)
|
|
350
|
+
length = resp.headers.get("Content-Length")
|
|
351
|
+
if isinstance(length, str) and length.isascii() and length.isdecimal():
|
|
352
|
+
digits, cap = length.lstrip('0') or '0', str(limit)
|
|
353
|
+
if len(digits) > len(cap) or (len(digits) == len(cap) and digits > cap):
|
|
354
|
+
raise CanonicalControlAPIError("response_limit", status_code=resp.status_code)
|
|
355
|
+
data = bytearray()
|
|
356
|
+
for block in resp.iter_content(chunk_size=min(65536, max(1, limit))):
|
|
357
|
+
if block:
|
|
358
|
+
if len(block) > limit - len(data):
|
|
359
|
+
raise CanonicalControlAPIError("response_limit", status_code=resp.status_code)
|
|
360
|
+
data.extend(block)
|
|
361
|
+
return bytes(data)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _bounded_response_prefix(resp, limit: int = _DEFAULT_CONTROL_BYTES) -> bytes:
|
|
365
|
+
"""Read one bounded first block of an error body for typed classification.
|
|
366
|
+
|
|
367
|
+
Oversized bodies contribute only this bounded prefix; their real status
|
|
368
|
+
stays reportable."""
|
|
369
|
+
try:
|
|
370
|
+
for block in resp.iter_content(chunk_size=min(65536, max(1, limit))):
|
|
371
|
+
if block:
|
|
372
|
+
return bytes(block[:limit])
|
|
373
|
+
except Exception:
|
|
374
|
+
pass
|
|
375
|
+
return b""
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _bounded_error_biz_code(prefix: bytes) -> Optional[int]:
|
|
379
|
+
"""Typed numeric classification only; never message/data.
|
|
380
|
+
|
|
381
|
+
Decodes the dual envelope (bare ``{code,message,data}`` or FastAPI
|
|
382
|
+
``{detail}``) from a bounded prefix so raw error text is never
|
|
383
|
+
forwarded; only the typed numeric family survives."""
|
|
384
|
+
parsed = None
|
|
385
|
+
if prefix:
|
|
386
|
+
try:
|
|
387
|
+
parsed = json.loads(prefix.decode("utf-8", errors="replace"))
|
|
388
|
+
except (ValueError, UnicodeError, RecursionError):
|
|
389
|
+
pass
|
|
390
|
+
detail = parsed.get("detail", parsed) if isinstance(parsed, dict) else None
|
|
391
|
+
if isinstance(detail, str):
|
|
392
|
+
decoded = None
|
|
393
|
+
try:
|
|
394
|
+
decoded = json.loads(detail)
|
|
395
|
+
except (ValueError, RecursionError):
|
|
396
|
+
pass
|
|
397
|
+
detail = decoded
|
|
398
|
+
code = detail.get("code") if isinstance(detail, dict) else None
|
|
399
|
+
if type(code) is bool or not isinstance(code, int):
|
|
400
|
+
code = None
|
|
401
|
+
return code
|
|
402
|
+
|
|
403
|
+
|
|
309
404
|
def _ensure_next_token_honored(response: dict, *, next_token: Optional[str], endpoint: str) -> None:
|
|
310
405
|
# An old server ignores the unknown next_token param and answers with its
|
|
311
406
|
# default first page, so a `response.get("next_token")` loop would silently
|
|
@@ -442,8 +537,16 @@ class APIClient:
|
|
|
442
537
|
deadline: Optional[float] = None,
|
|
443
538
|
_return_response: bool = False,
|
|
444
539
|
_single_attempt: bool = False,
|
|
540
|
+
_bounded: bool = False,
|
|
445
541
|
) -> Any:
|
|
446
|
-
"""Send through the normal authenticated HTTP channel.
|
|
542
|
+
"""Send through the normal authenticated HTTP channel.
|
|
543
|
+
|
|
544
|
+
``_bounded`` (canonical adapter control requests) opts this single
|
|
545
|
+
request into the bounded canonical response projection: redirects
|
|
546
|
+
refused (auth headers never follow a cross-origin Location), a
|
|
547
|
+
finite timeout owns ONE deadline across retries, streamed bounded
|
|
548
|
+
reads (O(cap+chunk) memory), and late successes refused.
|
|
549
|
+
"""
|
|
447
550
|
self._require_cluster_config()
|
|
448
551
|
return self._request_http(
|
|
449
552
|
method,
|
|
@@ -454,6 +557,7 @@ class APIClient:
|
|
|
454
557
|
deadline=deadline,
|
|
455
558
|
_return_response=_return_response,
|
|
456
559
|
_single_attempt=_single_attempt,
|
|
560
|
+
_bounded=_bounded,
|
|
457
561
|
)
|
|
458
562
|
|
|
459
563
|
def _request_http(
|
|
@@ -467,6 +571,7 @@ class APIClient:
|
|
|
467
571
|
deadline: Optional[float] = None,
|
|
468
572
|
_return_response: bool = False,
|
|
469
573
|
_single_attempt: bool = False,
|
|
574
|
+
_bounded: bool = False,
|
|
470
575
|
) -> Any:
|
|
471
576
|
"""One retry budget shared by cluster and central requests.
|
|
472
577
|
|
|
@@ -477,6 +582,12 @@ class APIClient:
|
|
|
477
582
|
timeout = _default_timeout()
|
|
478
583
|
else:
|
|
479
584
|
timeout = _normalize_explicit_timeout(timeout)
|
|
585
|
+
# Bounded canonical projection (P1 fix): a finite per-request duration
|
|
586
|
+
# owns ONE deadline across this request's retries, never per attempt,
|
|
587
|
+
# so a slow byte-drip response cannot outlive its budget.
|
|
588
|
+
if _bounded and deadline is None and isinstance(timeout, (int, float)) \
|
|
589
|
+
and not isinstance(timeout, bool) and math.isfinite(timeout) and timeout >= 0:
|
|
590
|
+
deadline = time.monotonic() + timeout
|
|
480
591
|
verbose = self.config.verbose
|
|
481
592
|
max_attempts = 1 if _single_attempt else max(1, self.config.http_max_attempts)
|
|
482
593
|
max_wait = self.config.http_max_wait
|
|
@@ -513,7 +624,13 @@ class APIClient:
|
|
|
513
624
|
try:
|
|
514
625
|
# A single-attempt mutation must also stop on redirects.
|
|
515
626
|
# Read the body separately so a truncated error still keeps its HTTP status.
|
|
516
|
-
|
|
627
|
+
# Bounded canonical requests always refuse redirects (auth
|
|
628
|
+
# headers must never follow a cross-origin Location) and read
|
|
629
|
+
# the body streamed-bounded instead of unbounded .content.
|
|
630
|
+
if _single_attempt or _bounded:
|
|
631
|
+
options = {"allow_redirects": False, "stream": True}
|
|
632
|
+
else:
|
|
633
|
+
options = {}
|
|
517
634
|
resp = self.session.request(
|
|
518
635
|
method,
|
|
519
636
|
url,
|
|
@@ -523,9 +640,21 @@ class APIClient:
|
|
|
523
640
|
timeout=attempt_timeout,
|
|
524
641
|
**options,
|
|
525
642
|
)
|
|
526
|
-
if _single_attempt:
|
|
643
|
+
if _single_attempt and not _bounded:
|
|
644
|
+
# Legacy single-attempt semantics: read the body so a
|
|
645
|
+
# truncated error keeps its status. The bounded projection
|
|
646
|
+
# reads the body itself (streamed, bounded).
|
|
527
647
|
_ = resp.content
|
|
528
648
|
except requests.RequestException as exc:
|
|
649
|
+
if _bounded:
|
|
650
|
+
# Bounded canonical projection: a network failure during a
|
|
651
|
+
# streamed bounded read is a typed refusal, not a retry of
|
|
652
|
+
# an unbounded request.
|
|
653
|
+
resp_is_error = resp is not None and not 200 <= resp.status_code < 300
|
|
654
|
+
if resp_is_error:
|
|
655
|
+
resp.close()
|
|
656
|
+
reason = "deadline" if (deadline is not None and time.monotonic() >= deadline) else "network"
|
|
657
|
+
raise CanonicalControlAPIError(reason) from None
|
|
529
658
|
if _single_attempt and resp is not None:
|
|
530
659
|
status = resp.status_code
|
|
531
660
|
resp.close()
|
|
@@ -561,6 +690,66 @@ class APIClient:
|
|
|
561
690
|
duration_ms = (time.perf_counter() - start) * 1000
|
|
562
691
|
if verbose:
|
|
563
692
|
self._log_response(method, url, request_id, resp, duration_ms)
|
|
693
|
+
if _bounded:
|
|
694
|
+
# Bounded canonical projection: sanitize every exit — refusals
|
|
695
|
+
# never carry a cause; redirects are refused before any auth
|
|
696
|
+
# header could follow the Location; the body is read streamed
|
|
697
|
+
# and bounded, and a late success (budget exhausted mid-read)
|
|
698
|
+
# is refused.
|
|
699
|
+
try:
|
|
700
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
701
|
+
raise CanonicalControlAPIError("deadline")
|
|
702
|
+
if _return_response:
|
|
703
|
+
raise CanonicalControlAPIError("invalid_request")
|
|
704
|
+
if 300 <= resp.status_code < 400:
|
|
705
|
+
# Request had allow_redirects=False: the redirect was
|
|
706
|
+
# NOT followed — the Location was never requested and
|
|
707
|
+
# auth headers were never sent there. Refuse.
|
|
708
|
+
raise CanonicalControlAPIError("redirect", status_code=resp.status_code)
|
|
709
|
+
if not 200 <= resp.status_code < 300:
|
|
710
|
+
if read_only and attempt < max_attempts and _is_retryable_status(resp.status_code):
|
|
711
|
+
delay = _retry_delay(attempt, resp, max_wait=max_wait)
|
|
712
|
+
if not math.isfinite(delay):
|
|
713
|
+
delay = _retry_delay(attempt)
|
|
714
|
+
if deadline is not None:
|
|
715
|
+
remaining = deadline - time.monotonic()
|
|
716
|
+
if remaining <= 0:
|
|
717
|
+
raise CanonicalControlAPIError("deadline")
|
|
718
|
+
delay = min(delay, remaining)
|
|
719
|
+
resp.close()
|
|
720
|
+
if deadline is not None:
|
|
721
|
+
_deadline_sleep(delay, deadline)
|
|
722
|
+
else:
|
|
723
|
+
time.sleep(delay)
|
|
724
|
+
continue
|
|
725
|
+
prefix = _bounded_response_prefix(resp, _DEFAULT_CONTROL_BYTES)
|
|
726
|
+
code = _bounded_error_biz_code(prefix)
|
|
727
|
+
raise CanonicalControlAPIError(
|
|
728
|
+
"http_error", status_code=resp.status_code, biz_code=code)
|
|
729
|
+
data = _read_bounded_control_bytes(resp)
|
|
730
|
+
if not data:
|
|
731
|
+
resp.close()
|
|
732
|
+
return None
|
|
733
|
+
refusal = None
|
|
734
|
+
try:
|
|
735
|
+
parsed = data.decode("utf-8", errors="strict")
|
|
736
|
+
except UnicodeError:
|
|
737
|
+
refusal = "invalid_utf8"
|
|
738
|
+
if refusal is None:
|
|
739
|
+
try:
|
|
740
|
+
result = json.loads(parsed)
|
|
741
|
+
except (ValueError, RecursionError):
|
|
742
|
+
refusal = "invalid_json"
|
|
743
|
+
if refusal is not None:
|
|
744
|
+
raise CanonicalControlAPIError(
|
|
745
|
+
refusal, status_code=resp.status_code)
|
|
746
|
+
if deadline is not None and time.monotonic() >= deadline:
|
|
747
|
+
# Refuse a late success; the budget is already spent.
|
|
748
|
+
raise CanonicalControlAPIError("deadline")
|
|
749
|
+
resp.close()
|
|
750
|
+
return result
|
|
751
|
+
finally:
|
|
752
|
+
_close_response_quietly(resp)
|
|
564
753
|
if not resp.ok or (_single_attempt and not 200 <= resp.status_code < 300):
|
|
565
754
|
pop_rejected = _is_pop_rejection(resp)
|
|
566
755
|
if pop_rejected and recovery_deadline is None:
|
ap_client/canonical_put.py
CHANGED
|
@@ -165,6 +165,11 @@ class APIClientTransportAdapter:
|
|
|
165
165
|
options = dict(timeout=timeout, deadline=self._base_deadline if deadline is None else deadline)
|
|
166
166
|
if single_attempt:
|
|
167
167
|
options["_single_attempt"] = True
|
|
168
|
+
# ALL canonical control requests go through the bounded projection
|
|
169
|
+
# (review P1): redirects refused (auth headers never follow a
|
|
170
|
+
# cross-origin Location), a finite timeout owns one deadline across
|
|
171
|
+
# retries, streamed bounded reads, late successes refused.
|
|
172
|
+
options["_bounded"] = True
|
|
168
173
|
if json_body is not None:
|
|
169
174
|
options['json_body'] = json_body
|
|
170
175
|
if params is not None:
|
|
@@ -172,7 +177,36 @@ class APIClientTransportAdapter:
|
|
|
172
177
|
try:
|
|
173
178
|
return self._client._request(method, path, **options)
|
|
174
179
|
except Exception as exc:
|
|
175
|
-
from .api import APIError
|
|
180
|
+
from .api import APIError, CanonicalControlAPIError
|
|
181
|
+
if isinstance(exc, CanonicalControlAPIError):
|
|
182
|
+
# Sanitized typed refusal from the bounded projection: map
|
|
183
|
+
# the closed reason set to the SDK's typed error family so
|
|
184
|
+
# deadline/budget semantics survive the bridge (never raw
|
|
185
|
+
# causes or response bodies).
|
|
186
|
+
reason = getattr(exc, "reason", None)
|
|
187
|
+
if reason == "deadline":
|
|
188
|
+
from instance_repo.errors import RequestDeadlineExceeded
|
|
189
|
+
raise RequestDeadlineExceeded(
|
|
190
|
+
"canonical control request deadline exhausted") from None
|
|
191
|
+
if reason in ("response_limit", "invalid_limit"):
|
|
192
|
+
from instance_repo.errors import SchemaError
|
|
193
|
+
raise SchemaError("canonical control response exceeded its bound") from None
|
|
194
|
+
if reason in ("invalid_utf8", "invalid_json"):
|
|
195
|
+
from instance_repo.errors import SchemaError
|
|
196
|
+
raise SchemaError("canonical control response is not valid JSON") from None
|
|
197
|
+
if reason == "redirect":
|
|
198
|
+
from instance_repo.errors import TransportError
|
|
199
|
+
raise TransportError("canonical control redirect refused") from None
|
|
200
|
+
status = getattr(exc, "status_code", None)
|
|
201
|
+
biz = None
|
|
202
|
+
detail = getattr(exc, "detail", None)
|
|
203
|
+
if isinstance(detail, dict):
|
|
204
|
+
biz = detail.get("code")
|
|
205
|
+
if type(biz) is not int:
|
|
206
|
+
biz = None
|
|
207
|
+
from instance_repo.errors import TransportError
|
|
208
|
+
raise TransportError("apiserver rejected the request",
|
|
209
|
+
status=status, biz_code=biz) from None
|
|
176
210
|
if isinstance(exc, APIError) or getattr(exc, 'status_code', None) is not None:
|
|
177
211
|
raise self._translate_api_error(exc) from None
|
|
178
212
|
else:
|
ap_client/fs_commands.py
CHANGED
|
@@ -180,6 +180,10 @@ def _canonical_remote_segment_guard(kind: str, value: str) -> None:
|
|
|
180
180
|
|
|
181
181
|
``--dir`` 的既有语义允许一个尾部分隔符(目录前缀惯用写法,见
|
|
182
182
|
:func:`_canonical_directory_path`),校验前先剥掉,不误伤合法输入。
|
|
183
|
+
``filepath``(位置参数)同理允许一个尾部分隔符:``ap fs put folder/
|
|
184
|
+
--source x`` 是合法的目录目标(文件落到 folder/<本地 basename>),与
|
|
185
|
+
``--dir folder/`` 语义一致;双分隔符(``folder//``)、中间空段、绝对
|
|
186
|
+
路径与 ``.``/``..`` 父段仍被拒绝。
|
|
183
187
|
"""
|
|
184
188
|
if not isinstance(value, str) or not value:
|
|
185
189
|
return # 空值由上层各自的必填语义处理
|
|
@@ -192,7 +196,7 @@ def _canonical_remote_segment_guard(kind: str, value: str) -> None:
|
|
|
192
196
|
"pass a local source via --source, e.g. ap fs put a.txt --source /tmp/a.txt",
|
|
193
197
|
2,
|
|
194
198
|
)
|
|
195
|
-
candidate = value[:-1] if
|
|
199
|
+
candidate = value[:-1] if value.endswith("/") else value
|
|
196
200
|
segments = candidate.split("/")
|
|
197
201
|
if any(s in ("", ".", "..") for s in segments):
|
|
198
202
|
raise _fail(
|
|
@@ -206,6 +210,10 @@ def _canonical_file_path(filepath, directory):
|
|
|
206
210
|
_canonical_remote_segment_guard("filepath", filepath)
|
|
207
211
|
_canonical_remote_segment_guard("--dir", directory)
|
|
208
212
|
prefix = _canonical_directory_path(directory) if directory is not None else ""
|
|
213
|
+
# A filepath with one trailing separator denotes a directory target
|
|
214
|
+
# (the local basename is appended); normalise it to the plain segment.
|
|
215
|
+
if isinstance(filepath, str) and filepath.endswith("/") and filepath not in ("", "/"):
|
|
216
|
+
filepath = filepath[:-1]
|
|
209
217
|
return prefix + "/" + filepath if prefix else filepath
|
|
210
218
|
|
|
211
219
|
|
|
@@ -639,6 +647,10 @@ def fs_put(
|
|
|
639
647
|
# 同 fs get:本地输入校验的 typer.Exit 原样穿透。
|
|
640
648
|
raise
|
|
641
649
|
except Exception as exc:
|
|
650
|
+
with open("/tmp/dbg_up.log", "a") as _f:
|
|
651
|
+
import traceback
|
|
652
|
+
_f.write(f"{type(exc).__name__}: {exc}\n")
|
|
653
|
+
traceback.print_exc(file=_f)
|
|
642
654
|
failure = canonical_users_error(exc, stage="upload")
|
|
643
655
|
if outcomes and "completed" not in failure[0]:
|
|
644
656
|
failure[0]["completed"] = [upload_outcome_payload(outcome) for outcome in outcomes]
|
ap_client/shared_adapter.py
CHANGED
|
@@ -27,6 +27,23 @@ import requests
|
|
|
27
27
|
from .api import APIError
|
|
28
28
|
from .config import get_config
|
|
29
29
|
|
|
30
|
+
|
|
31
|
+
def _shared_config():
|
|
32
|
+
"""Config for shared/control HTTP entry points honoring CLI overrides.
|
|
33
|
+
|
|
34
|
+
The CLI writes the global ``--cluster`` choice into
|
|
35
|
+
``api._cluster_override`` (and ``-v`` into ``api._verbose_override``);
|
|
36
|
+
a bare ``get_config()`` would silently prefer ``AP_CLUSTER`` from the
|
|
37
|
+
environment over the explicit ``--cluster`` flag. Route every
|
|
38
|
+
shared-side config consumption through the same override contract the
|
|
39
|
+
private canonical factory uses, so context, discovery and upload
|
|
40
|
+
pre-binding all agree on one cluster/verbosity.
|
|
41
|
+
"""
|
|
42
|
+
from . import api
|
|
43
|
+
return get_config(verbose=api._verbose_override,
|
|
44
|
+
cluster=api._cluster_override)
|
|
45
|
+
|
|
46
|
+
|
|
30
47
|
__all__ = [
|
|
31
48
|
"PROTOCOL_ID",
|
|
32
49
|
"SHARED_ERROR_CODES",
|
|
@@ -535,7 +552,7 @@ class _LegacyHttpSharedClient(_SharedHttpBase):
|
|
|
535
552
|
if client is None:
|
|
536
553
|
from .api import APIClient
|
|
537
554
|
|
|
538
|
-
client = APIClient(
|
|
555
|
+
client = APIClient(_shared_config())
|
|
539
556
|
self.client = client
|
|
540
557
|
|
|
541
558
|
def _request(self, method: str, path: str, *, params=None, body=None) -> dict[str, Any]:
|
|
@@ -748,7 +765,7 @@ class HttpSharedClient(_LegacyHttpSharedClient):
|
|
|
748
765
|
def __init__(self, client=None, *, deadline=None, shared_library_id=None):
|
|
749
766
|
if client is None:
|
|
750
767
|
from .api import APIClient
|
|
751
|
-
client = APIClient(
|
|
768
|
+
client = APIClient(_shared_config())
|
|
752
769
|
from .api import APIClient
|
|
753
770
|
if isinstance(client, APIClient):
|
|
754
771
|
# Credential-bearing shared responses must never enter wire logs,
|
|
@@ -1369,7 +1386,7 @@ def _query(params: dict[str, str]) -> str:
|
|
|
1369
1386
|
def _default_repo_config_fetcher() -> Callable[[str], dict[str, Any]]:
|
|
1370
1387
|
from .api import APIClient
|
|
1371
1388
|
|
|
1372
|
-
client = APIClient(
|
|
1389
|
+
client = APIClient(_shared_config())
|
|
1373
1390
|
|
|
1374
1391
|
def fetcher(path: str) -> dict[str, Any]:
|
|
1375
1392
|
return client._request("GET", path)
|
ap_client/shared_commands.py
CHANGED
|
@@ -29,6 +29,7 @@ from .shared_adapter import (
|
|
|
29
29
|
SharedApiError,
|
|
30
30
|
SharedRelease,
|
|
31
31
|
UserDataContextError,
|
|
32
|
+
_shared_config,
|
|
32
33
|
load_user_data_context,
|
|
33
34
|
)
|
|
34
35
|
|
|
@@ -937,9 +938,7 @@ def fs_context(
|
|
|
937
938
|
# 修复:把 CLI 已解析的 X-Cluster(来自 --cluster / AP_CLUSTER)传给
|
|
938
939
|
# repo-config;否则请求只带 scope=user-data,服务端要求 cluster 或
|
|
939
940
|
# storage_env 必填而直接 400(该命令此前在任何环境都无法工作)。
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
_cfg = get_config()
|
|
941
|
+
_cfg = _shared_config()
|
|
943
942
|
_cluster = ""
|
|
944
943
|
for _k, _v in _cfg.headers.items():
|
|
945
944
|
if _k.lower() == "x-cluster":
|
|
@@ -987,9 +986,8 @@ def _load_region_facts() -> tuple[dict, str]:
|
|
|
987
986
|
"""
|
|
988
987
|
from .api import APIClient
|
|
989
988
|
from .cluster_layout_fetcher import ClusterLayoutHTTPError
|
|
990
|
-
from .config import get_config
|
|
991
989
|
|
|
992
|
-
cfg =
|
|
990
|
+
cfg = _shared_config()
|
|
993
991
|
cluster = ""
|
|
994
992
|
for key, value in (cfg.headers or {}).items():
|
|
995
993
|
if key.lower() == "x-cluster":
|
|
@@ -998,7 +996,7 @@ def _load_region_facts() -> tuple[dict, str]:
|
|
|
998
996
|
if not cluster:
|
|
999
997
|
return {}, "cluster is not configured (AP_CLUSTER / --cluster)"
|
|
1000
998
|
try:
|
|
1001
|
-
resolver = build_region_resolver(APIClient(
|
|
999
|
+
resolver = build_region_resolver(APIClient(_shared_config()))
|
|
1002
1000
|
layout = resolver.layout(cluster)
|
|
1003
1001
|
except ClusterLayoutHTTPError as exc:
|
|
1004
1002
|
if exc.kind == "endpoint_unsupported":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ap-client
|
|
3
|
-
Version: 0.7.2.
|
|
3
|
+
Version: 0.7.2.dev2
|
|
4
4
|
Summary: Agent Platform API Client & CLI
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Requires-Dist: click<8.2.0,>=8.1.8
|
|
@@ -11,9 +11,9 @@ Requires-Dist: rich>=13.0.0
|
|
|
11
11
|
Requires-Dist: typer<0.21.0,>=0.20.1
|
|
12
12
|
Requires-Dist: websockets>=13.0
|
|
13
13
|
Provides-Extra: all
|
|
14
|
-
Requires-Dist: instance-repo[oss]<2.0.0,>=1.
|
|
14
|
+
Requires-Dist: instance-repo[oss]<2.0.0,>=1.7.0.dev0; extra == 'all'
|
|
15
15
|
Provides-Extra: dataset
|
|
16
|
-
Requires-Dist: instance-repo[oss]<2.0.0,>=1.
|
|
16
|
+
Requires-Dist: instance-repo[oss]<2.0.0,>=1.7.0.dev0; extra == 'dataset'
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
|
|
19
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.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ap_client/__init__.py,sha256=3_72pFnCJjc9foZlmC_d5cSQkLzpoY0nLhtcnyqDdiQ,507
|
|
2
2
|
ap_client/akpool_commands.py,sha256=DhhPka8Nf03HSYYcokn0EEgAjEtLYtVm3ix6pPjdmYQ,6794
|
|
3
|
-
ap_client/api.py,sha256=
|
|
3
|
+
ap_client/api.py,sha256=aj7HykGpKaYYgyToyR3UVByCWiIj4MoJhtXrZ1AWsMU,160159
|
|
4
4
|
ap_client/canonical_get.py,sha256=RE8VX6tcrXBzwQ2EyZYJchgL-BxAgObh5s-1vpZnZ7Q,8477
|
|
5
|
-
ap_client/canonical_put.py,sha256=
|
|
5
|
+
ap_client/canonical_put.py,sha256=2tFX8v-yB01n5UTpfZlAXr7vYwpufhNIUpMyvCo6Fe4,40616
|
|
6
6
|
ap_client/cli.py,sha256=_O_YobpDz04fKMNQQQ59Ojrf1vx497-a3WEPm-5klAU,349898
|
|
7
7
|
ap_client/cluster_layout_fetcher.py,sha256=QSdUa_iin5cl6DXrrB_w0-d_HhZ1XIWyxqjy_0CIuU4,15024
|
|
8
8
|
ap_client/cluster_region_resolver.py,sha256=Tw4JMZaK6rJZQF96KSh9v9FoL98ZDo14nrEwQ8owp8E,16289
|
|
@@ -12,7 +12,7 @@ ap_client/dataset_name.py,sha256=GFJ9SGlaQiqRVz38RHzRJfET-KUM63zWrtNnMWu7ynI,424
|
|
|
12
12
|
ap_client/dataset_register.py,sha256=8lcaeExM3qJ9O254ZmnQFGFZRZDum6l3a4mFvl8beOo,18112
|
|
13
13
|
ap_client/dfs_commands.py,sha256=uJ_E-e_Y9fRq9g3dO-1wTrif1cIUJzsz8nvCxc97lRk,29840
|
|
14
14
|
ap_client/exporter.py,sha256=Nij-TdGYGrOvgTlWj_6W_0UoPY0PsUCpUdcsIBscRRM,38853
|
|
15
|
-
ap_client/fs_commands.py,sha256=
|
|
15
|
+
ap_client/fs_commands.py,sha256=TH7fVt0F_tgUBNy3qloiyZWo8ppE_imYRsqvaaGMsM0,37586
|
|
16
16
|
ap_client/fs_storage.py,sha256=_j16NuzwA6B-NF7oxtyae9Rz8HkQNcLM7clzmUUxRcE,2686
|
|
17
17
|
ap_client/fs_transfer.py,sha256=haiH_wv0QGOoxw1RfG3PR7K5xyxkCb5uO8MnR8p49rc,13158
|
|
18
18
|
ap_client/instance_commands.py,sha256=-XR1lfM9uUGl3HNHs_uQY2glCNlGLRXFZSqGDLhekIc,49967
|
|
@@ -33,14 +33,14 @@ ap_client/profile_references.py,sha256=P0w3FbCHNF8HsQegXkTuA75Yuz_Cf9-yO9m-VOrev
|
|
|
33
33
|
ap_client/replica_policy.py,sha256=yAr5Tvr1TOdKdn00SrFiD7KK4knULsHGLOcUGUFK1T4,4562
|
|
34
34
|
ap_client/repo_read_guard.py,sha256=wyY8BDAplW3Gz617y1CT0uif5fV_FA-Fvom6RDANqo0,1895
|
|
35
35
|
ap_client/share_api.py,sha256=m9cDePltmE4VFPC3Oku-TSjiwOpUqqMvq4Zmc_6Ueeo,8839
|
|
36
|
-
ap_client/shared_adapter.py,sha256=
|
|
37
|
-
ap_client/shared_commands.py,sha256=
|
|
36
|
+
ap_client/shared_adapter.py,sha256=LYqbRArxI0CHum5LCJb6Pe1Fxx_Wb4HwAqZde8mP7o4,63222
|
|
37
|
+
ap_client/shared_commands.py,sha256=9nASx3mdra3Sekow-32oZEBroj5vAcXJm4j7n32_VSI,50472
|
|
38
38
|
ap_client/split_publish.py,sha256=fcG5V_Xc5sa5IG5GY8K7lp4Y5q5UVoUHIQgJOOo-1RA,6596
|
|
39
39
|
ap_client/submission_metadata.py,sha256=DI02H-B5ODR4M03cAQ6VDGcQwIrnZD03WF2HpE_KfHQ,8152
|
|
40
40
|
ap_client/tbb.py,sha256=WJstsdqxCXvuNuSdIOc0Y6Q4GgUWE0cAj0dP4iMKHVM,7149
|
|
41
41
|
ap_client/tool_manifest.py,sha256=ag17QVnW9OKEkKhwT5WZpsuVKjkQ2etJ1f2plCLXqrM,6868
|
|
42
42
|
ap_client/waiter.py,sha256=l-9F4j7z3-VpeMKEKAdNg_4ahReu0fEFsoby1bMiQd0,7794
|
|
43
|
-
ap_client-0.7.2.
|
|
44
|
-
ap_client-0.7.2.
|
|
45
|
-
ap_client-0.7.2.
|
|
46
|
-
ap_client-0.7.2.
|
|
43
|
+
ap_client-0.7.2.dev2.dist-info/METADATA,sha256=noRHcPZcH_lB6PKKeahDjZ32W1a3EztMFnJGclm8nso,748
|
|
44
|
+
ap_client-0.7.2.dev2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
45
|
+
ap_client-0.7.2.dev2.dist-info/entry_points.txt,sha256=lxFlc62mI5NftTCQ5W1fTPQLnItvI8AYQ3aIlOLVLn0,42
|
|
46
|
+
ap_client-0.7.2.dev2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|