ap-client 0.7.1.dev5__tar.gz → 0.8.0.dev0__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.
Files changed (48) hide show
  1. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/PKG-INFO +6 -7
  2. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/__init__.py +1 -1
  3. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/api.py +2 -164
  4. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/cli.py +213 -101
  5. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/dfs_commands.py +10 -25
  6. ap_client-0.8.0.dev0/ap_client/fs_commands.py +861 -0
  7. ap_client-0.8.0.dev0/ap_client/fs_storage.py +146 -0
  8. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/irepo_sdk.py +0 -317
  9. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/ossutil_io.py +9 -153
  10. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/submission_metadata.py +35 -15
  11. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/pyproject.toml +5 -6
  12. ap_client-0.7.1.dev5/.gitignore +0 -260
  13. ap_client-0.7.1.dev5/ap_client/canonical_get.py +0 -210
  14. ap_client-0.7.1.dev5/ap_client/canonical_put.py +0 -914
  15. ap_client-0.7.1.dev5/ap_client/cluster_layout_fetcher.py +0 -357
  16. ap_client-0.7.1.dev5/ap_client/cluster_region_resolver.py +0 -394
  17. ap_client-0.7.1.dev5/ap_client/control_http.py +0 -415
  18. ap_client-0.7.1.dev5/ap_client/fs_commands.py +0 -765
  19. ap_client-0.7.1.dev5/ap_client/fs_storage.py +0 -53
  20. ap_client-0.7.1.dev5/ap_client/replica_policy.py +0 -114
  21. ap_client-0.7.1.dev5/ap_client/shared_adapter.py +0 -1442
  22. ap_client-0.7.1.dev5/ap_client/shared_commands.py +0 -1114
  23. ap_client-0.7.1.dev5/ap_client/tool_manifest.py +0 -184
  24. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/akpool_commands.py +0 -0
  25. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/config.py +0 -0
  26. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/dataset_commands.py +0 -0
  27. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/dataset_name.py +0 -0
  28. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/dataset_register.py +0 -0
  29. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/exporter.py +0 -0
  30. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/fs_transfer.py +0 -0
  31. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/instance_commands.py +0 -0
  32. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/instance_options.py +0 -0
  33. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/managed_ak.py +0 -0
  34. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/manifest_view.py +0 -0
  35. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/ossutil_hash.py +0 -0
  36. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_cascade_all.py +0 -0
  37. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_cascade_cli.py +0 -0
  38. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_cascade_display.py +0 -0
  39. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_cascade_state.py +0 -0
  40. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_commands.py +0 -0
  41. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_diagnostics.py +0 -0
  42. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_display.py +0 -0
  43. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/profile_references.py +0 -0
  44. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/repo_read_guard.py +0 -0
  45. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/share_api.py +0 -0
  46. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/split_publish.py +0 -0
  47. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/tbb.py +0 -0
  48. {ap_client-0.7.1.dev5 → ap_client-0.8.0.dev0}/ap_client/waiter.py +0 -0
@@ -1,19 +1,18 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: ap-client
3
- Version: 0.7.1.dev5
3
+ Version: 0.8.0.dev0
4
4
  Summary: Agent Platform API Client & CLI
5
5
  Requires-Python: >=3.10
6
- Requires-Dist: click<8.2.0,>=8.1.8
7
- Requires-Dist: irepo-artifact==0.2.4
6
+ Requires-Dist: irepo-artifact==0.2.6
8
7
  Requires-Dist: pyyaml>=6.0
9
8
  Requires-Dist: requests>=2.28.0
10
9
  Requires-Dist: rich>=13.0.0
11
- Requires-Dist: typer<0.21.0,>=0.20.1
10
+ Requires-Dist: typer>=0.9.0
12
11
  Requires-Dist: websockets>=13.0
13
12
  Provides-Extra: all
14
- Requires-Dist: instance-repo[oss]==1.6.0.dev2; extra == 'all'
13
+ Requires-Dist: instance-repo[oss]<2.0.0,>=1.4.0; extra == 'all'
15
14
  Provides-Extra: dataset
16
- Requires-Dist: instance-repo[oss]==1.6.0.dev2; extra == 'dataset'
15
+ Requires-Dist: instance-repo[oss]<2.0.0,>=1.4.0; extra == 'dataset'
17
16
  Description-Content-Type: text/markdown
18
17
 
19
18
  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.
@@ -9,7 +9,7 @@ from .exporter import ExportSummary
9
9
  try:
10
10
  __version__ = version("ap-client")
11
11
  except PackageNotFoundError:
12
- __version__ = "0.7.1.dev5"
12
+ __version__ = "0+unknown"
13
13
 
14
14
  __all__ = [
15
15
  "APIClient",
@@ -6,7 +6,6 @@ import os
6
6
  import platform
7
7
  import re
8
8
  import sys
9
- import threading
10
9
  import time
11
10
  import uuid
12
11
  from email.utils import parsedate_to_datetime
@@ -288,14 +287,6 @@ class APIError(Exception):
288
287
  return f"API Error {self.status_code}: {self.detail} (request_id={self.request_id})"
289
288
 
290
289
 
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
-
299
290
  class PaginationProtocolError(RuntimeError):
300
291
  """The server stopped honoring a pagination protocol already in use."""
301
292
 
@@ -380,8 +371,6 @@ class APIClient:
380
371
 
381
372
  def __init__(self, config: Config):
382
373
  self.config = config
383
- self._control_channel = None
384
- self._control_channel_lock = threading.Lock()
385
374
  self.session = requests.Session()
386
375
  headers = dict(config.headers)
387
376
  user_agent = _build_user_agent(headers.get("User-Agent"))
@@ -437,13 +426,8 @@ class APIClient:
437
426
  timeout: TimeoutType = None,
438
427
  deadline: Optional[float] = None,
439
428
  _return_response: bool = False,
440
- max_response_bytes: Optional[int] = None,
441
429
  ) -> Any:
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)
430
+ """Send an HTTP request with X-Request-ID and optional verbose logging."""
447
431
  self._require_cluster_config()
448
432
  return self._request_http(
449
433
  method,
@@ -612,130 +596,6 @@ class APIClient:
612
596
  raise APIError(resp.status_code, detail, request_id, resp) from exc
613
597
  raise RuntimeError("unreachable retry state")
614
598
 
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
-
739
599
  def _require_cluster_config(self) -> None:
740
600
  if has_cluster_header(self.config.headers):
741
601
  return
@@ -3779,34 +3639,12 @@ def _redact_url_query_secrets(value: str) -> str:
3779
3639
 
3780
3640
 
3781
3641
  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
- """
3796
3642
  try:
3797
3643
  err_data = resp.json()
3798
3644
  except Exception:
3799
3645
  return resp.text
3800
3646
  if isinstance(err_data, dict):
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)
3647
+ return err_data.get("detail", err_data.get("message", resp.text))
3810
3648
  return err_data
3811
3649
 
3812
3650