dominus-sdk-python 9.0.11__tar.gz → 9.0.12__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.
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/PKG-INFO +2 -2
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/README.md +1 -1
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/__init__.py +3 -1
- dominus_sdk_python-9.0.12/dominus/helpers/auth.py +57 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/core.py +18 -2
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/__init__.py +2 -0
- dominus_sdk_python-9.0.12/dominus/namespaces/usage.py +214 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/start.py +4 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/PKG-INFO +2 -2
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/SOURCES.txt +3 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/pyproject.toml +1 -1
- dominus_sdk_python-9.0.12/tests/test_token_precedence.py +174 -0
- dominus_sdk_python-9.0.12/tests/test_usage_namespace.py +210 -0
- dominus_sdk_python-9.0.11/dominus/helpers/auth.py +0 -23
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/config/__init__.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/config/endpoints.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/contract/__init__.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/contract/envelope.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/contract/projections.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/errors.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/__init__.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/cache.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/console_capture.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/crypto.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/sse.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/helpers/trace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/admin.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/ai.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/artifacts.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/auth.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/authority.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/browser.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/coder.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/courier.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/db.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/ddl.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/deployer.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/fastapi.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/files.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/health.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/jobs.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/logs.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/platform.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/portal.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/processor.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/publisher.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/recipes.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/redis.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/secrets.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/secure.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/stash.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/sync.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/warden.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/namespaces/workflow.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/py.typed +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus/services/__init__.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/dependency_links.txt +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/requires.txt +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/top_level.txt +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/setup.cfg +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_ai_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_artifacts_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_auth.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_authority_public_vocabulary.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_browser_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_contract.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_control_plane_namespaces.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_error_recovery_action.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_errors.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_errors_aliases.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_flat_commands.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_health.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_logs.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_namespace_barrel_exports.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_platform_coder_namespaces.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_provisioning_parity.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_public_exports.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_publisher_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_readme_quickstart_catalog.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_recipes_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_recipes_stash_routing.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_secrets_presence_contract.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_stash_artifact_facade.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_stash_tables_namespace.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_transport_compat.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_version_consistency.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_workflow_lifecycle.py +0 -0
- {dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_workflow_refs.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dominus-sdk-python
|
|
3
|
-
Version: 9.0.
|
|
3
|
+
Version: 9.0.12
|
|
4
4
|
Summary: Python SDK for the Dominus gateway-first platform
|
|
5
5
|
Author-email: CareBridge Systems <dev@carebridge.io>
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -48,7 +48,7 @@ cleanup audit is `docs/janitor/2026-09-14-1300-sdk-python-cleanup-audit.md`.
|
|
|
48
48
|
- Gateway-scoped client mode for MCP and other user-JWT sessions
|
|
49
49
|
- Transport compatibility for wrapped `{success,data}` responses and unwrapped Warden/control-plane success objects
|
|
50
50
|
- Local helpers for JWT verification, trace propagation, retries, and console capture
|
|
51
|
-
- Current package version: `9.0.
|
|
51
|
+
- Current package version: `9.0.12`
|
|
52
52
|
|
|
53
53
|
## Install
|
|
54
54
|
|
|
@@ -15,7 +15,7 @@ cleanup audit is `docs/janitor/2026-09-14-1300-sdk-python-cleanup-audit.md`.
|
|
|
15
15
|
- Gateway-scoped client mode for MCP and other user-JWT sessions
|
|
16
16
|
- Transport compatibility for wrapped `{success,data}` responses and unwrapped Warden/control-plane success objects
|
|
17
17
|
- Local helpers for JWT verification, trace propagation, retries, and console capture
|
|
18
|
-
- Current package version: `9.0.
|
|
18
|
+
- Current package version: `9.0.12`
|
|
19
19
|
|
|
20
20
|
## Install
|
|
21
21
|
|
|
@@ -121,6 +121,7 @@ from .namespaces.platform import PlatformNamespace
|
|
|
121
121
|
from .namespaces.coder import CoderNamespace
|
|
122
122
|
from .namespaces.publisher import PublisherNamespace
|
|
123
123
|
from .namespaces.stash import StashNamespace, StashTablesNamespace
|
|
124
|
+
from .namespaces.usage import UsageNamespace
|
|
124
125
|
|
|
125
126
|
# Export AI namespace for agent-runtime operations
|
|
126
127
|
from .namespaces.ai import (
|
|
@@ -190,7 +191,7 @@ from .errors import (
|
|
|
190
191
|
TimeoutError as DominusTimeoutError,
|
|
191
192
|
)
|
|
192
193
|
|
|
193
|
-
__version__ = "9.0.
|
|
194
|
+
__version__ = "9.0.12"
|
|
194
195
|
__all__ = [
|
|
195
196
|
# Main SDK instance
|
|
196
197
|
"dominus",
|
|
@@ -249,6 +250,7 @@ __all__ = [
|
|
|
249
250
|
"PublisherNamespace",
|
|
250
251
|
"StashNamespace",
|
|
251
252
|
"StashTablesNamespace",
|
|
253
|
+
"UsageNamespace",
|
|
252
254
|
# AI namespace for agent-runtime operations
|
|
253
255
|
"AiNamespace",
|
|
254
256
|
"RagSubNamespace",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Token resolution helper.
|
|
3
|
+
|
|
4
|
+
Handles resolution of authentication token from environment variables.
|
|
5
|
+
No hardcoded tokens supported - environment variable only.
|
|
6
|
+
"""
|
|
7
|
+
import os
|
|
8
|
+
from typing import Optional
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _resolve_token() -> Optional[str]:
|
|
12
|
+
"""
|
|
13
|
+
Resolve auth token from environment variable.
|
|
14
|
+
|
|
15
|
+
Precedence: DOMINUS_USER_TOKEN outranks DOMINUS_TOKEN. This is intentional
|
|
16
|
+
(the README quick start is a gateway user-token flow), but it means an
|
|
17
|
+
ambient operator token silently shadows a project PSK. Callers that intend
|
|
18
|
+
project-PSK auth must scrub DOMINUS_USER_TOKEN (and DOMINUS_MCP_USER_TOKEN)
|
|
19
|
+
from the environment before importing this package.
|
|
20
|
+
|
|
21
|
+
Note: When fetching from Infisical via Sovereign, the secret is stored as
|
|
22
|
+
PROVISION_DOMINUS_TOKEN but should be set as DOMINUS_TOKEN in environment.
|
|
23
|
+
The PROVISION_ prefix is dropped when setting environment variables.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
Token string or None if not set
|
|
27
|
+
"""
|
|
28
|
+
return os.getenv("DOMINUS_USER_TOKEN") or os.getenv("DOMINUS_TOKEN")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _shadowed_token_hint(token: Optional[str]) -> Optional[str]:
|
|
32
|
+
"""
|
|
33
|
+
Diagnose a token that may have been shadowed by environment precedence.
|
|
34
|
+
|
|
35
|
+
Returns a message naming BOTH variables when, and only when, the ambiguity
|
|
36
|
+
is real: DOMINUS_USER_TOKEN and DOMINUS_TOKEN are both set AND ``token`` is
|
|
37
|
+
the shadowing value that precedence selected. A caller-supplied token that
|
|
38
|
+
is not the environment's chosen value was never ambiguous, so it returns
|
|
39
|
+
None, as does any environment where only one variable is set.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
token: The token an auth attempt actually used
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
Diagnostic message, or None when there is nothing ambiguous to report
|
|
46
|
+
"""
|
|
47
|
+
user_token = os.getenv("DOMINUS_USER_TOKEN")
|
|
48
|
+
psk_token = os.getenv("DOMINUS_TOKEN")
|
|
49
|
+
if not user_token or not psk_token or token != user_token:
|
|
50
|
+
return None
|
|
51
|
+
return (
|
|
52
|
+
"DOMINUS_USER_TOKEN outranks DOMINUS_TOKEN (dominus/helpers/auth.py) and "
|
|
53
|
+
"both are set in this environment, so this attempt authenticated with "
|
|
54
|
+
"DOMINUS_USER_TOKEN. If you intended project-PSK auth, unset "
|
|
55
|
+
"DOMINUS_USER_TOKEN (and DOMINUS_MCP_USER_TOKEN) before importing the "
|
|
56
|
+
"SDK and retry."
|
|
57
|
+
)
|
|
@@ -11,6 +11,7 @@ import json
|
|
|
11
11
|
import time
|
|
12
12
|
from typing import Any, Optional
|
|
13
13
|
|
|
14
|
+
from .auth import _shadowed_token_hint
|
|
14
15
|
from .cache import dominus_cache, gateway_circuit_breaker, exponential_backoff_with_jitter
|
|
15
16
|
|
|
16
17
|
# Max retries for HTTP requests (reduced from implicit to explicit)
|
|
@@ -349,6 +350,13 @@ def is_jwt_valid(jwt_token: str) -> bool:
|
|
|
349
350
|
return False
|
|
350
351
|
|
|
351
352
|
|
|
353
|
+
def _mint_failure_message(message: str, shadow_hint: Optional[str]) -> str:
|
|
354
|
+
"""Append the token-shadowing diagnostic to a failed-mint message."""
|
|
355
|
+
if not shadow_hint:
|
|
356
|
+
return message
|
|
357
|
+
return f"{message}\n{shadow_hint}"
|
|
358
|
+
|
|
359
|
+
|
|
352
360
|
async def _get_service_jwt(psk_token: str, base_url: str) -> str:
|
|
353
361
|
"""
|
|
354
362
|
Get service JWT by calling gateway /jwt/mint with PSK.
|
|
@@ -392,6 +400,10 @@ async def _get_service_jwt(psk_token: str, base_url: str) -> str:
|
|
|
392
400
|
body_json = {"method": "auth.self", "params": {}}
|
|
393
401
|
body_b64 = _b64_encode(body_json)
|
|
394
402
|
|
|
403
|
+
# A rejected mint is indistinguishable from a bad PSK when an ambient
|
|
404
|
+
# DOMINUS_USER_TOKEN shadowed the intended project PSK at import.
|
|
405
|
+
shadow_hint = _shadowed_token_hint(psk_token)
|
|
406
|
+
|
|
395
407
|
# Retry loop for JWT minting
|
|
396
408
|
JWT_MINT_RETRIES = 3
|
|
397
409
|
last_error = None
|
|
@@ -419,7 +431,9 @@ async def _get_service_jwt(psk_token: str, base_url: str) -> str:
|
|
|
419
431
|
if not result.get("success"):
|
|
420
432
|
error_msg = result.get("error", "Unknown auth error")
|
|
421
433
|
gateway_circuit_breaker.record_failure()
|
|
422
|
-
raise RuntimeError(
|
|
434
|
+
raise RuntimeError(
|
|
435
|
+
_mint_failure_message(f"Auth error: {error_msg}", shadow_hint)
|
|
436
|
+
)
|
|
423
437
|
|
|
424
438
|
data = result.get("data", {})
|
|
425
439
|
jwt = data.get("access_token") or data.get("token")
|
|
@@ -465,7 +479,9 @@ async def _get_service_jwt(psk_token: str, base_url: str) -> str:
|
|
|
465
479
|
raise RuntimeError(f"Failed to get JWT: {e}") from e
|
|
466
480
|
# For other errors, we've already handled retries in the status check above
|
|
467
481
|
gateway_circuit_breaker.record_failure()
|
|
468
|
-
raise RuntimeError(
|
|
482
|
+
raise RuntimeError(
|
|
483
|
+
_mint_failure_message(f"Failed to get JWT: {e}", shadow_hint)
|
|
484
|
+
) from e
|
|
469
485
|
|
|
470
486
|
# Should not reach here, but just in case
|
|
471
487
|
gateway_circuit_breaker.record_failure()
|
|
@@ -28,6 +28,7 @@ from .platform import PlatformNamespace
|
|
|
28
28
|
from .coder import CoderNamespace
|
|
29
29
|
from .publisher import PublisherNamespace
|
|
30
30
|
from .stash import StashNamespace, StashTablesNamespace
|
|
31
|
+
from .usage import UsageNamespace
|
|
31
32
|
from .ai import (
|
|
32
33
|
AiNamespace,
|
|
33
34
|
RagSubNamespace,
|
|
@@ -65,6 +66,7 @@ __all__ = [
|
|
|
65
66
|
"PublisherNamespace",
|
|
66
67
|
"StashNamespace",
|
|
67
68
|
"StashTablesNamespace",
|
|
69
|
+
"UsageNamespace",
|
|
68
70
|
"AiNamespace",
|
|
69
71
|
"RagSubNamespace",
|
|
70
72
|
"ArtifactsSubNamespace",
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Usage Namespace - Dominus consumption and provider-cost reporting.
|
|
3
|
+
|
|
4
|
+
Canonical SDK entry point for the dominus-usage service's authorized read
|
|
5
|
+
surface: summary, evidence, coverage, and explain. All four route through
|
|
6
|
+
the gateway (``use_gateway=True``), which maps ``/api/usage/*`` ->
|
|
7
|
+
``/svc/usage/*`` upstream to dominus-usage.
|
|
8
|
+
|
|
9
|
+
This namespace is a thin pass-through: it never converts quantities/amounts
|
|
10
|
+
to float, never infers a default window or grouping (the service applies
|
|
11
|
+
last-7-days / meter+project+environment+logical_service when omitted), and
|
|
12
|
+
never adds a token of its own. An explicitly minted human bearer reaches
|
|
13
|
+
Usage unchanged via the existing ``Dominus(gateway_user_token=...)``
|
|
14
|
+
constructor behavior, exactly like ``dominus.authority.*``.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Any, Dict, Optional, Sequence, TYPE_CHECKING, Union
|
|
19
|
+
from urllib.parse import urlencode
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
from ..start import Dominus
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _query_string(params: Dict[str, Any]) -> str:
|
|
26
|
+
"""Build a ``?...`` query string, repeating the key for list/tuple values."""
|
|
27
|
+
pairs: list[tuple[str, str]] = []
|
|
28
|
+
for key, value in params.items():
|
|
29
|
+
if value is None or value == "":
|
|
30
|
+
continue
|
|
31
|
+
if isinstance(value, (list, tuple)):
|
|
32
|
+
for item in value:
|
|
33
|
+
if item is None or item == "":
|
|
34
|
+
continue
|
|
35
|
+
pairs.append((key, str(item)))
|
|
36
|
+
else:
|
|
37
|
+
pairs.append((key, str(value)))
|
|
38
|
+
if not pairs:
|
|
39
|
+
return ""
|
|
40
|
+
return "?" + urlencode(pairs)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class UsageNamespace:
|
|
44
|
+
"""
|
|
45
|
+
Usage service namespace: typed consumption and provider-cost reads.
|
|
46
|
+
|
|
47
|
+
Usage::
|
|
48
|
+
|
|
49
|
+
await dominus.usage.summary(since="2026-09-01T00:00:00Z", meter="ai.tokens.input")
|
|
50
|
+
await dominus.usage.evidence(project_id="proj_123", limit=100)
|
|
51
|
+
await dominus.usage.coverage()
|
|
52
|
+
await dominus.usage.explain(observation_id="obs_123")
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
def __init__(self, client: "Dominus"):
|
|
56
|
+
self._client = client
|
|
57
|
+
|
|
58
|
+
async def _get(self, endpoint: str, *, timeout: float = 30.0) -> Dict[str, Any]:
|
|
59
|
+
return await self._client._request(
|
|
60
|
+
endpoint=endpoint,
|
|
61
|
+
method="GET",
|
|
62
|
+
use_gateway=True,
|
|
63
|
+
timeout=timeout,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
async def summary(
|
|
67
|
+
self,
|
|
68
|
+
*,
|
|
69
|
+
since: Optional[str] = None,
|
|
70
|
+
until: Optional[str] = None,
|
|
71
|
+
group_by: Optional[Union[str, Sequence[str]]] = None,
|
|
72
|
+
project_id: Optional[str] = None,
|
|
73
|
+
environment: Optional[str] = None,
|
|
74
|
+
logical_service: Optional[str] = None,
|
|
75
|
+
family_root_id: Optional[str] = None,
|
|
76
|
+
meter: Optional[str] = None,
|
|
77
|
+
provider: Optional[str] = None,
|
|
78
|
+
timeout: float = 30.0,
|
|
79
|
+
) -> Dict[str, Any]:
|
|
80
|
+
"""Unit-aware usage rows plus distinct provider-reported/estimated cost.
|
|
81
|
+
|
|
82
|
+
``GET /api/usage/summary``. Omitting ``since``/``until`` uses the
|
|
83
|
+
service's last-7-days default; omitting ``group_by`` uses its default
|
|
84
|
+
grouping. Quantities/amounts are returned as decimal strings, never
|
|
85
|
+
converted to float.
|
|
86
|
+
"""
|
|
87
|
+
qs = _query_string(
|
|
88
|
+
{
|
|
89
|
+
"since": since,
|
|
90
|
+
"until": until,
|
|
91
|
+
"group_by": group_by,
|
|
92
|
+
"project_id": project_id,
|
|
93
|
+
"environment": environment,
|
|
94
|
+
"logical_service": logical_service,
|
|
95
|
+
"family_root_id": family_root_id,
|
|
96
|
+
"meter": meter,
|
|
97
|
+
"provider": provider,
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
return await self._get(f"/api/usage/summary{qs}", timeout=timeout)
|
|
101
|
+
|
|
102
|
+
async def evidence(
|
|
103
|
+
self,
|
|
104
|
+
*,
|
|
105
|
+
since: Optional[str] = None,
|
|
106
|
+
until: Optional[str] = None,
|
|
107
|
+
project_id: Optional[str] = None,
|
|
108
|
+
environment: Optional[str] = None,
|
|
109
|
+
logical_service: Optional[str] = None,
|
|
110
|
+
family_root_id: Optional[str] = None,
|
|
111
|
+
meter: Optional[str] = None,
|
|
112
|
+
provider: Optional[str] = None,
|
|
113
|
+
limit: Optional[int] = None,
|
|
114
|
+
cursor: Optional[str] = None,
|
|
115
|
+
timeout: float = 30.0,
|
|
116
|
+
) -> Dict[str, Any]:
|
|
117
|
+
"""Cursor-paginated observation/provider-source evidence.
|
|
118
|
+
|
|
119
|
+
``GET /api/usage/evidence``. ``limit`` defaults to 100 and is bounded
|
|
120
|
+
to 500 server-side; pass the response's ``next_cursor`` back in to
|
|
121
|
+
page forward.
|
|
122
|
+
"""
|
|
123
|
+
qs = _query_string(
|
|
124
|
+
{
|
|
125
|
+
"since": since,
|
|
126
|
+
"until": until,
|
|
127
|
+
"project_id": project_id,
|
|
128
|
+
"environment": environment,
|
|
129
|
+
"logical_service": logical_service,
|
|
130
|
+
"family_root_id": family_root_id,
|
|
131
|
+
"meter": meter,
|
|
132
|
+
"provider": provider,
|
|
133
|
+
"limit": limit,
|
|
134
|
+
"cursor": cursor,
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
return await self._get(f"/api/usage/evidence{qs}", timeout=timeout)
|
|
138
|
+
|
|
139
|
+
async def coverage(
|
|
140
|
+
self,
|
|
141
|
+
*,
|
|
142
|
+
since: Optional[str] = None,
|
|
143
|
+
until: Optional[str] = None,
|
|
144
|
+
project_id: Optional[str] = None,
|
|
145
|
+
environment: Optional[str] = None,
|
|
146
|
+
logical_service: Optional[str] = None,
|
|
147
|
+
family_root_id: Optional[str] = None,
|
|
148
|
+
meter: Optional[str] = None,
|
|
149
|
+
provider: Optional[str] = None,
|
|
150
|
+
timeout: float = 30.0,
|
|
151
|
+
) -> Dict[str, Any]:
|
|
152
|
+
"""Registered meter/source coverage, freshness, and gap reasons.
|
|
153
|
+
|
|
154
|
+
``GET /api/usage/coverage``. Never reports unsupported capture as
|
|
155
|
+
complete; ``gaps`` names each unavailable reason explicitly.
|
|
156
|
+
"""
|
|
157
|
+
qs = _query_string(
|
|
158
|
+
{
|
|
159
|
+
"since": since,
|
|
160
|
+
"until": until,
|
|
161
|
+
"project_id": project_id,
|
|
162
|
+
"environment": environment,
|
|
163
|
+
"logical_service": logical_service,
|
|
164
|
+
"family_root_id": family_root_id,
|
|
165
|
+
"meter": meter,
|
|
166
|
+
"provider": provider,
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
return await self._get(f"/api/usage/coverage{qs}", timeout=timeout)
|
|
170
|
+
|
|
171
|
+
async def explain(
|
|
172
|
+
self,
|
|
173
|
+
*,
|
|
174
|
+
observation_id: Optional[str] = None,
|
|
175
|
+
operation_id: Optional[str] = None,
|
|
176
|
+
since: Optional[str] = None,
|
|
177
|
+
until: Optional[str] = None,
|
|
178
|
+
project_id: Optional[str] = None,
|
|
179
|
+
environment: Optional[str] = None,
|
|
180
|
+
logical_service: Optional[str] = None,
|
|
181
|
+
family_root_id: Optional[str] = None,
|
|
182
|
+
meter: Optional[str] = None,
|
|
183
|
+
timeout: float = 30.0,
|
|
184
|
+
) -> Dict[str, Any]:
|
|
185
|
+
"""Explanation linking permitted observations, attempts, and cost basis.
|
|
186
|
+
|
|
187
|
+
``GET /api/usage/explain``. Exactly one of ``observation_id`` or
|
|
188
|
+
``operation_id`` must be supplied; supplying both (or neither) is
|
|
189
|
+
rejected locally before the request is sent, matching the service's
|
|
190
|
+
own ambiguous-selector rejection. The remaining filters narrow which
|
|
191
|
+
observations can match an ``operation_id`` lookup; they are inert for
|
|
192
|
+
an ``observation_id`` lookup, which the service resolves unfiltered.
|
|
193
|
+
"""
|
|
194
|
+
if bool(observation_id) == bool(operation_id):
|
|
195
|
+
raise ValueError(
|
|
196
|
+
"usage.explain requires exactly one of observation_id or operation_id"
|
|
197
|
+
)
|
|
198
|
+
qs = _query_string(
|
|
199
|
+
{
|
|
200
|
+
"observation_id": observation_id,
|
|
201
|
+
"operation_id": operation_id,
|
|
202
|
+
"since": since,
|
|
203
|
+
"until": until,
|
|
204
|
+
"project_id": project_id,
|
|
205
|
+
"environment": environment,
|
|
206
|
+
"logical_service": logical_service,
|
|
207
|
+
"family_root_id": family_root_id,
|
|
208
|
+
"meter": meter,
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
return await self._get(f"/api/usage/explain{qs}", timeout=timeout)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
__all__ = ["UsageNamespace"]
|
|
@@ -196,6 +196,10 @@ class Dominus:
|
|
|
196
196
|
from .namespaces.recipes import RecipesNamespace
|
|
197
197
|
self.recipes = RecipesNamespace(self)
|
|
198
198
|
|
|
199
|
+
# Usage service (dominus-usage; consumption and provider-cost reports)
|
|
200
|
+
from .namespaces.usage import UsageNamespace
|
|
201
|
+
self.usage = UsageNamespace(self)
|
|
202
|
+
|
|
199
203
|
# Cache for JWT public key
|
|
200
204
|
self._public_key_cache = None
|
|
201
205
|
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dominus-sdk-python
|
|
3
|
-
Version: 9.0.
|
|
3
|
+
Version: 9.0.12
|
|
4
4
|
Summary: Python SDK for the Dominus gateway-first platform
|
|
5
5
|
Author-email: CareBridge Systems <dev@carebridge.io>
|
|
6
6
|
License-Expression: LicenseRef-Proprietary
|
|
@@ -48,7 +48,7 @@ cleanup audit is `docs/janitor/2026-09-14-1300-sdk-python-cleanup-audit.md`.
|
|
|
48
48
|
- Gateway-scoped client mode for MCP and other user-JWT sessions
|
|
49
49
|
- Transport compatibility for wrapped `{success,data}` responses and unwrapped Warden/control-plane success objects
|
|
50
50
|
- Local helpers for JWT verification, trace propagation, retries, and console capture
|
|
51
|
-
- Current package version: `9.0.
|
|
51
|
+
- Current package version: `9.0.12`
|
|
52
52
|
|
|
53
53
|
## Install
|
|
54
54
|
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/SOURCES.txt
RENAMED
|
@@ -44,6 +44,7 @@ dominus/namespaces/secrets.py
|
|
|
44
44
|
dominus/namespaces/secure.py
|
|
45
45
|
dominus/namespaces/stash.py
|
|
46
46
|
dominus/namespaces/sync.py
|
|
47
|
+
dominus/namespaces/usage.py
|
|
47
48
|
dominus/namespaces/warden.py
|
|
48
49
|
dominus/namespaces/workflow.py
|
|
49
50
|
dominus/services/__init__.py
|
|
@@ -76,7 +77,9 @@ tests/test_recipes_stash_routing.py
|
|
|
76
77
|
tests/test_secrets_presence_contract.py
|
|
77
78
|
tests/test_stash_artifact_facade.py
|
|
78
79
|
tests/test_stash_tables_namespace.py
|
|
80
|
+
tests/test_token_precedence.py
|
|
79
81
|
tests/test_transport_compat.py
|
|
82
|
+
tests/test_usage_namespace.py
|
|
80
83
|
tests/test_version_consistency.py
|
|
81
84
|
tests/test_workflow_lifecycle.py
|
|
82
85
|
tests/test_workflow_refs.py
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"""Token precedence contract for ``DOMINUS_USER_TOKEN`` vs ``DOMINUS_TOKEN``.
|
|
2
|
+
|
|
3
|
+
``DOMINUS_USER_TOKEN`` outranks ``DOMINUS_TOKEN`` by design (the README quick
|
|
4
|
+
start is a user-token flow). The hazard is that the shadowing is silent: when an
|
|
5
|
+
operator token is ambient and the caller intended project-PSK auth, a 401 reads
|
|
6
|
+
exactly like a bad PSK. These tests lock the precedence itself as unchanged and
|
|
7
|
+
assert that a failed mint names both variables so the shadowing is diagnosable
|
|
8
|
+
from the error alone.
|
|
9
|
+
"""
|
|
10
|
+
import sys
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
import pytest
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
18
|
+
if str(ROOT) not in sys.path:
|
|
19
|
+
sys.path.insert(0, str(ROOT))
|
|
20
|
+
|
|
21
|
+
import dominus.helpers.auth as auth_module # noqa: E402
|
|
22
|
+
import dominus.helpers.core as core_module # noqa: E402
|
|
23
|
+
from dominus.helpers.auth import _resolve_token, _shadowed_token_hint # noqa: E402
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
USER_TOKEN = "u" * 64
|
|
27
|
+
PROJECT_PSK = "p" * 64
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@pytest.fixture(autouse=True)
|
|
31
|
+
def _clean_token_env(monkeypatch):
|
|
32
|
+
"""No ambient token state leaks into, or out of, these tests."""
|
|
33
|
+
monkeypatch.delenv("DOMINUS_USER_TOKEN", raising=False)
|
|
34
|
+
monkeypatch.delenv("DOMINUS_TOKEN", raising=False)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@pytest.fixture
|
|
38
|
+
def _closed_breaker():
|
|
39
|
+
"""Keep the shared gateway circuit breaker deterministic across tests."""
|
|
40
|
+
breaker = core_module.gateway_circuit_breaker
|
|
41
|
+
breaker._failure_count = 0
|
|
42
|
+
breaker._state = breaker.CLOSED
|
|
43
|
+
breaker._half_open_calls = 0
|
|
44
|
+
yield breaker
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# --- Precedence contract (must NOT change) ---------------------------------
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_resolve_token_prefers_user_token_when_both_set(monkeypatch):
|
|
51
|
+
monkeypatch.setenv("DOMINUS_USER_TOKEN", USER_TOKEN)
|
|
52
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
53
|
+
|
|
54
|
+
assert _resolve_token() == USER_TOKEN
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_resolve_token_falls_back_to_project_psk(monkeypatch):
|
|
58
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
59
|
+
|
|
60
|
+
assert _resolve_token() == PROJECT_PSK
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# --- Shadowing diagnostic ---------------------------------------------------
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_shadowed_token_hint_is_quiet_when_only_project_psk_is_set(monkeypatch):
|
|
67
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
68
|
+
|
|
69
|
+
assert _shadowed_token_hint(PROJECT_PSK) is None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_shadowed_token_hint_is_quiet_when_only_user_token_is_set(monkeypatch):
|
|
73
|
+
monkeypatch.setenv("DOMINUS_USER_TOKEN", USER_TOKEN)
|
|
74
|
+
|
|
75
|
+
assert _shadowed_token_hint(USER_TOKEN) is None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_shadowed_token_hint_names_both_variables_when_user_token_shadows(monkeypatch):
|
|
79
|
+
monkeypatch.setenv("DOMINUS_USER_TOKEN", USER_TOKEN)
|
|
80
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
81
|
+
|
|
82
|
+
hint = _shadowed_token_hint(USER_TOKEN)
|
|
83
|
+
|
|
84
|
+
assert hint is not None
|
|
85
|
+
assert "DOMINUS_USER_TOKEN" in hint
|
|
86
|
+
assert "DOMINUS_TOKEN" in hint
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_shadowed_token_hint_is_quiet_for_an_explicit_non_env_token(monkeypatch):
|
|
90
|
+
"""A caller-supplied token was never ambiguous, so do not blame the env."""
|
|
91
|
+
monkeypatch.setenv("DOMINUS_USER_TOKEN", USER_TOKEN)
|
|
92
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
93
|
+
|
|
94
|
+
assert _shadowed_token_hint(PROJECT_PSK) is None
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# --- Mint failure path ------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class Fake401Response:
|
|
101
|
+
status_code = 401
|
|
102
|
+
|
|
103
|
+
def __init__(self):
|
|
104
|
+
self.text = ""
|
|
105
|
+
|
|
106
|
+
def raise_for_status(self):
|
|
107
|
+
raise httpx.HTTPStatusError(
|
|
108
|
+
"401 Unauthorized",
|
|
109
|
+
request=httpx.Request("POST", "https://gateway.example/jwt/mint"),
|
|
110
|
+
response=httpx.Response(401),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class FakeAsyncClient:
|
|
115
|
+
def __init__(self, *args, **kwargs):
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
async def __aenter__(self):
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
async def __aexit__(self, exc_type, exc, tb):
|
|
122
|
+
return False
|
|
123
|
+
|
|
124
|
+
async def post(self, url, content=None):
|
|
125
|
+
return Fake401Response()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@pytest.fixture
|
|
129
|
+
def _minting_against_401(monkeypatch):
|
|
130
|
+
monkeypatch.setattr(core_module.httpx, "AsyncClient", FakeAsyncClient)
|
|
131
|
+
monkeypatch.setattr(
|
|
132
|
+
core_module, "get_gateway_url", lambda: "https://gateway.example", raising=False
|
|
133
|
+
)
|
|
134
|
+
monkeypatch.setattr(
|
|
135
|
+
core_module, "get_proxy_config", lambda: None, raising=False
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
async def _no_sleep(_seconds):
|
|
139
|
+
return None
|
|
140
|
+
|
|
141
|
+
monkeypatch.setattr(core_module.asyncio, "sleep", _no_sleep)
|
|
142
|
+
|
|
143
|
+
# The endpoint getters are imported inside the function body.
|
|
144
|
+
import dominus.config.endpoints as endpoints
|
|
145
|
+
|
|
146
|
+
monkeypatch.setattr(endpoints, "get_gateway_url", lambda: "https://gateway.example")
|
|
147
|
+
monkeypatch.setattr(endpoints, "get_proxy_config", lambda: None)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
@pytest.mark.asyncio
|
|
151
|
+
async def test_mint_failure_names_both_variables_when_shadowed(
|
|
152
|
+
monkeypatch, _closed_breaker, _minting_against_401
|
|
153
|
+
):
|
|
154
|
+
monkeypatch.setenv("DOMINUS_USER_TOKEN", USER_TOKEN)
|
|
155
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
156
|
+
|
|
157
|
+
with pytest.raises(RuntimeError) as excinfo:
|
|
158
|
+
await core_module._get_service_jwt(USER_TOKEN, "https://gateway.example")
|
|
159
|
+
|
|
160
|
+
message = str(excinfo.value)
|
|
161
|
+
assert "DOMINUS_USER_TOKEN" in message
|
|
162
|
+
assert "DOMINUS_TOKEN" in message
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@pytest.mark.asyncio
|
|
166
|
+
async def test_mint_failure_omits_hint_when_not_shadowed(
|
|
167
|
+
monkeypatch, _closed_breaker, _minting_against_401
|
|
168
|
+
):
|
|
169
|
+
monkeypatch.setenv("DOMINUS_TOKEN", PROJECT_PSK)
|
|
170
|
+
|
|
171
|
+
with pytest.raises(RuntimeError) as excinfo:
|
|
172
|
+
await core_module._get_service_jwt(PROJECT_PSK, "https://gateway.example")
|
|
173
|
+
|
|
174
|
+
assert "DOMINUS_USER_TOKEN" not in str(excinfo.value)
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from dominus.namespaces.usage import UsageNamespace
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class FakeClient:
|
|
7
|
+
def __init__(self, response=None):
|
|
8
|
+
self.calls = []
|
|
9
|
+
self._response = response if response is not None else {"schema_version": 1}
|
|
10
|
+
|
|
11
|
+
async def _request(
|
|
12
|
+
self,
|
|
13
|
+
endpoint,
|
|
14
|
+
method="POST",
|
|
15
|
+
body=None,
|
|
16
|
+
user_token=None,
|
|
17
|
+
use_gateway=False,
|
|
18
|
+
timeout=30.0,
|
|
19
|
+
actor=None,
|
|
20
|
+
**kwargs,
|
|
21
|
+
):
|
|
22
|
+
self.calls.append(
|
|
23
|
+
{
|
|
24
|
+
"endpoint": endpoint,
|
|
25
|
+
"method": method,
|
|
26
|
+
"body": body,
|
|
27
|
+
"user_token": user_token,
|
|
28
|
+
"use_gateway": use_gateway,
|
|
29
|
+
"timeout": timeout,
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
return self._response
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.asyncio
|
|
36
|
+
async def test_summary_defaults_send_no_query_string():
|
|
37
|
+
client = FakeClient()
|
|
38
|
+
usage = UsageNamespace(client)
|
|
39
|
+
|
|
40
|
+
await usage.summary()
|
|
41
|
+
|
|
42
|
+
assert client.calls == [
|
|
43
|
+
{
|
|
44
|
+
"endpoint": "/api/usage/summary",
|
|
45
|
+
"method": "GET",
|
|
46
|
+
"body": None,
|
|
47
|
+
"user_token": None,
|
|
48
|
+
"use_gateway": True,
|
|
49
|
+
"timeout": 30.0,
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.asyncio
|
|
55
|
+
async def test_summary_builds_full_query_string_with_repeated_group_by():
|
|
56
|
+
client = FakeClient()
|
|
57
|
+
usage = UsageNamespace(client)
|
|
58
|
+
|
|
59
|
+
await usage.summary(
|
|
60
|
+
since="2026-09-01T00:00:00Z",
|
|
61
|
+
until="2026-09-08T00:00:00Z",
|
|
62
|
+
group_by=["meter", "project"],
|
|
63
|
+
project_id="proj_123",
|
|
64
|
+
environment="production",
|
|
65
|
+
logical_service="gateway",
|
|
66
|
+
family_root_id="fam_1",
|
|
67
|
+
meter="ai.tokens.input",
|
|
68
|
+
provider="anthropic",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
assert client.calls[0]["endpoint"] == (
|
|
72
|
+
"/api/usage/summary?since=2026-09-01T00%3A00%3A00Z&until=2026-09-08T00%3A00%3A00Z"
|
|
73
|
+
"&group_by=meter&group_by=project&project_id=proj_123&environment=production"
|
|
74
|
+
"&logical_service=gateway&family_root_id=fam_1&meter=ai.tokens.input&provider=anthropic"
|
|
75
|
+
)
|
|
76
|
+
assert client.calls[0]["method"] == "GET"
|
|
77
|
+
assert client.calls[0]["use_gateway"] is True
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@pytest.mark.asyncio
|
|
81
|
+
async def test_summary_accepts_single_group_by_string():
|
|
82
|
+
client = FakeClient()
|
|
83
|
+
usage = UsageNamespace(client)
|
|
84
|
+
|
|
85
|
+
await usage.summary(group_by="meter")
|
|
86
|
+
|
|
87
|
+
assert client.calls[0]["endpoint"] == "/api/usage/summary?group_by=meter"
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.mark.asyncio
|
|
91
|
+
async def test_summary_never_converts_decimal_quantities_to_float():
|
|
92
|
+
client = FakeClient(
|
|
93
|
+
response={
|
|
94
|
+
"usage": [{"quantity": "12.345678901234567890", "unit": "tokens"}],
|
|
95
|
+
"provider_reported_cost": [{"amount": "0.010000000000000001", "currency": "USD"}],
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
usage = UsageNamespace(client)
|
|
99
|
+
|
|
100
|
+
result = await usage.summary()
|
|
101
|
+
|
|
102
|
+
assert isinstance(result["usage"][0]["quantity"], str)
|
|
103
|
+
assert result["usage"][0]["quantity"] == "12.345678901234567890"
|
|
104
|
+
assert isinstance(result["provider_reported_cost"][0]["amount"], str)
|
|
105
|
+
assert result["provider_reported_cost"][0]["amount"] == "0.010000000000000001"
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@pytest.mark.asyncio
|
|
109
|
+
async def test_evidence_builds_pagination_query_string():
|
|
110
|
+
client = FakeClient()
|
|
111
|
+
usage = UsageNamespace(client)
|
|
112
|
+
|
|
113
|
+
await usage.evidence(project_id="proj_123", limit=250, cursor="cursor-abc")
|
|
114
|
+
|
|
115
|
+
assert client.calls[0]["endpoint"] == (
|
|
116
|
+
"/api/usage/evidence?project_id=proj_123&limit=250&cursor=cursor-abc"
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@pytest.mark.asyncio
|
|
121
|
+
async def test_evidence_defaults_omit_limit_and_cursor_from_query_string():
|
|
122
|
+
client = FakeClient()
|
|
123
|
+
usage = UsageNamespace(client)
|
|
124
|
+
|
|
125
|
+
await usage.evidence()
|
|
126
|
+
|
|
127
|
+
assert client.calls[0]["endpoint"] == "/api/usage/evidence"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@pytest.mark.asyncio
|
|
131
|
+
async def test_coverage_builds_filtered_query_string():
|
|
132
|
+
client = FakeClient()
|
|
133
|
+
usage = UsageNamespace(client)
|
|
134
|
+
|
|
135
|
+
await usage.coverage(meter="ai.tokens.input", provider="openai")
|
|
136
|
+
|
|
137
|
+
assert client.calls[0]["endpoint"] == "/api/usage/coverage?meter=ai.tokens.input&provider=openai"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@pytest.mark.asyncio
|
|
141
|
+
async def test_explain_by_observation_id():
|
|
142
|
+
client = FakeClient()
|
|
143
|
+
usage = UsageNamespace(client)
|
|
144
|
+
|
|
145
|
+
await usage.explain(observation_id="obs_123")
|
|
146
|
+
|
|
147
|
+
assert client.calls[0]["endpoint"] == "/api/usage/explain?observation_id=obs_123"
|
|
148
|
+
assert client.calls[0]["method"] == "GET"
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@pytest.mark.asyncio
|
|
152
|
+
async def test_explain_by_operation_id():
|
|
153
|
+
client = FakeClient()
|
|
154
|
+
usage = UsageNamespace(client)
|
|
155
|
+
|
|
156
|
+
await usage.explain(operation_id="op_456")
|
|
157
|
+
|
|
158
|
+
assert client.calls[0]["endpoint"] == "/api/usage/explain?operation_id=op_456"
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.asyncio
|
|
162
|
+
async def test_explain_by_operation_id_narrows_with_scope_filters():
|
|
163
|
+
client = FakeClient()
|
|
164
|
+
usage = UsageNamespace(client)
|
|
165
|
+
|
|
166
|
+
await usage.explain(
|
|
167
|
+
operation_id="op_456",
|
|
168
|
+
project_id="proj_123",
|
|
169
|
+
environment="production",
|
|
170
|
+
logical_service="gateway",
|
|
171
|
+
family_root_id="fam_1",
|
|
172
|
+
meter="ai.tokens.input",
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
assert client.calls[0]["endpoint"] == (
|
|
176
|
+
"/api/usage/explain?operation_id=op_456&project_id=proj_123&environment=production"
|
|
177
|
+
"&logical_service=gateway&family_root_id=fam_1&meter=ai.tokens.input"
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
@pytest.mark.asyncio
|
|
182
|
+
async def test_explain_rejects_both_selectors_without_a_request():
|
|
183
|
+
client = FakeClient()
|
|
184
|
+
usage = UsageNamespace(client)
|
|
185
|
+
|
|
186
|
+
with pytest.raises(ValueError):
|
|
187
|
+
await usage.explain(observation_id="obs_123", operation_id="op_456")
|
|
188
|
+
|
|
189
|
+
assert client.calls == []
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
@pytest.mark.asyncio
|
|
193
|
+
async def test_explain_rejects_neither_selector_without_a_request():
|
|
194
|
+
client = FakeClient()
|
|
195
|
+
usage = UsageNamespace(client)
|
|
196
|
+
|
|
197
|
+
with pytest.raises(ValueError):
|
|
198
|
+
await usage.explain()
|
|
199
|
+
|
|
200
|
+
assert client.calls == []
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@pytest.mark.asyncio
|
|
204
|
+
async def test_singleton_exposes_usage_namespace():
|
|
205
|
+
from dominus import dominus
|
|
206
|
+
|
|
207
|
+
assert callable(dominus.usage.summary)
|
|
208
|
+
assert callable(dominus.usage.evidence)
|
|
209
|
+
assert callable(dominus.usage.coverage)
|
|
210
|
+
assert callable(dominus.usage.explain)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Token resolution helper.
|
|
3
|
-
|
|
4
|
-
Handles resolution of authentication token from environment variables.
|
|
5
|
-
No hardcoded tokens supported - environment variable only.
|
|
6
|
-
"""
|
|
7
|
-
import os
|
|
8
|
-
from typing import Optional
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def _resolve_token() -> Optional[str]:
|
|
12
|
-
"""
|
|
13
|
-
Resolve auth token from environment variable.
|
|
14
|
-
|
|
15
|
-
Note: When fetching from Infisical via Sovereign, the secret is stored as
|
|
16
|
-
PROVISION_DOMINUS_TOKEN but should be set as DOMINUS_TOKEN in environment.
|
|
17
|
-
The PROVISION_ prefix is dropped when setting environment variables.
|
|
18
|
-
|
|
19
|
-
Returns:
|
|
20
|
-
Token string or None if not set
|
|
21
|
-
"""
|
|
22
|
-
return os.getenv("DOMINUS_USER_TOKEN") or os.getenv("DOMINUS_TOKEN")
|
|
23
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/dominus_sdk_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_authority_public_vocabulary.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_control_plane_namespaces.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_namespace_barrel_exports.py
RENAMED
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_platform_coder_namespaces.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_readme_quickstart_catalog.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_secrets_presence_contract.py
RENAMED
|
File without changes
|
|
File without changes
|
{dominus_sdk_python-9.0.11 → dominus_sdk_python-9.0.12}/tests/test_stash_tables_namespace.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|