managed-deepagents 0.9.3.dev13__py3-none-win_amd64.whl → 0.9.3.dev14__py3-none-win_amd64.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.
- managed_deepagents/_binaries/mda.exe +0 -0
- managed_deepagents/_identity_auth.py +94 -13
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/METADATA +1 -1
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/RECORD +8 -8
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/WHEEL +0 -0
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/entry_points.txt +0 -0
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/licenses/LICENSE +0 -0
- {managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/top_level.txt +0 -0
|
Binary file
|
|
@@ -13,12 +13,17 @@ import asyncio
|
|
|
13
13
|
import hmac
|
|
14
14
|
import json
|
|
15
15
|
import os
|
|
16
|
+
import secrets
|
|
17
|
+
import threading
|
|
18
|
+
import time
|
|
19
|
+
from collections import OrderedDict
|
|
16
20
|
from collections.abc import Iterable, Mapping
|
|
17
21
|
from http import HTTPStatus
|
|
18
22
|
from importlib import import_module
|
|
23
|
+
from ssl import SSLCertVerificationError
|
|
19
24
|
from typing import TYPE_CHECKING, Any, Literal, Protocol, TypedDict, cast
|
|
20
25
|
from urllib.error import HTTPError, URLError
|
|
21
|
-
from urllib.parse import urljoin
|
|
26
|
+
from urllib.parse import urljoin, urlsplit
|
|
22
27
|
from urllib.request import Request as UrlRequest
|
|
23
28
|
from urllib.request import urlopen
|
|
24
29
|
|
|
@@ -115,6 +120,7 @@ __all__ = [
|
|
|
115
120
|
"ManagedUser",
|
|
116
121
|
"build_managed_auth",
|
|
117
122
|
"channel_events_bypass_user",
|
|
123
|
+
"clear_langsmith_verification_cache_for_tests",
|
|
118
124
|
"is_channel_events_request",
|
|
119
125
|
"resolve_request_identity",
|
|
120
126
|
]
|
|
@@ -570,19 +576,20 @@ def _verify_langsmith_api_key(
|
|
|
570
576
|
forwarded_headers = {"x-api-key": api_key}
|
|
571
577
|
if tenant_header := headers.get("x-tenant-id"):
|
|
572
578
|
forwarded_headers["x-tenant-id"] = str(tenant_header)
|
|
573
|
-
|
|
579
|
+
try:
|
|
580
|
+
url = urljoin(f"{endpoint.rstrip('/')}/", "auth/public")
|
|
581
|
+
parsed = urlsplit(url)
|
|
582
|
+
except ValueError as error:
|
|
583
|
+
raise ManagedAuthError(503, "LangSmith API-key verification unavailable") from error
|
|
584
|
+
if parsed.scheme not in {"http", "https"} or parsed.username or parsed.password:
|
|
585
|
+
raise ManagedAuthError(503, "LangSmith API-key verification unavailable")
|
|
586
|
+
cache_key = (url, api_key, forwarded_headers.get("x-tenant-id", ""))
|
|
587
|
+
if (cached := _cached_langsmith_verification(cache_key)) is not None:
|
|
588
|
+
return cached
|
|
574
589
|
request = UrlRequest( # noqa: S310 - endpoint is platform-owned configuration
|
|
575
590
|
url, headers=forwarded_headers, method="GET"
|
|
576
591
|
)
|
|
577
|
-
|
|
578
|
-
with urlopen(request, timeout=2.0) as response: # noqa: S310 - platform-owned endpoint
|
|
579
|
-
status = response.status
|
|
580
|
-
payload = response.read()
|
|
581
|
-
except HTTPError as error:
|
|
582
|
-
status = error.code
|
|
583
|
-
payload = b""
|
|
584
|
-
except (OSError, TimeoutError, URLError) as error:
|
|
585
|
-
raise ManagedAuthError(503, "LangSmith API-key verification unavailable") from error
|
|
592
|
+
status, payload = _request_langsmith_verification(request)
|
|
586
593
|
|
|
587
594
|
if status == HTTPStatus.UNAUTHORIZED:
|
|
588
595
|
raise ManagedAuthError(401, "invalid API key")
|
|
@@ -598,7 +605,77 @@ def _verify_langsmith_api_key(
|
|
|
598
605
|
) from error
|
|
599
606
|
if not isinstance(decoded, dict):
|
|
600
607
|
raise ManagedAuthError(503, "LangSmith API-key verification returned an invalid response")
|
|
601
|
-
|
|
608
|
+
verified = cast("LangSmithAuthResponse", decoded)
|
|
609
|
+
_cache_langsmith_verification(cache_key, verified)
|
|
610
|
+
return verified
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
_LangSmithVerificationKey = tuple[str, str, str]
|
|
614
|
+
_LANGSMITH_VERIFICATION_TTL_SECONDS = 60.0
|
|
615
|
+
_LANGSMITH_VERIFICATION_CACHE_SIZE = 1000
|
|
616
|
+
_langsmith_verification_cache: OrderedDict[
|
|
617
|
+
_LangSmithVerificationKey, tuple[float, LangSmithAuthResponse]
|
|
618
|
+
] = OrderedDict()
|
|
619
|
+
_langsmith_verification_cache_lock = threading.Lock()
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
def clear_langsmith_verification_cache_for_tests() -> None:
|
|
623
|
+
"""Drop cached LangSmith API-key verifications. Test-only."""
|
|
624
|
+
with _langsmith_verification_cache_lock:
|
|
625
|
+
_langsmith_verification_cache.clear()
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
def _cached_langsmith_verification(key: _LangSmithVerificationKey) -> LangSmithAuthResponse | None:
|
|
629
|
+
with _langsmith_verification_cache_lock:
|
|
630
|
+
entry = _langsmith_verification_cache.pop(key, None)
|
|
631
|
+
if entry is None or entry[0] <= time.monotonic():
|
|
632
|
+
return None
|
|
633
|
+
_langsmith_verification_cache[key] = entry
|
|
634
|
+
return entry[1]
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
def _cache_langsmith_verification(
|
|
638
|
+
key: _LangSmithVerificationKey, verified: LangSmithAuthResponse
|
|
639
|
+
) -> None:
|
|
640
|
+
with _langsmith_verification_cache_lock:
|
|
641
|
+
_langsmith_verification_cache.pop(key, None)
|
|
642
|
+
_langsmith_verification_cache[key] = (
|
|
643
|
+
time.monotonic() + _LANGSMITH_VERIFICATION_TTL_SECONDS,
|
|
644
|
+
verified,
|
|
645
|
+
)
|
|
646
|
+
if len(_langsmith_verification_cache) > _LANGSMITH_VERIFICATION_CACHE_SIZE:
|
|
647
|
+
_langsmith_verification_cache.popitem(last=False)
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def _request_langsmith_verification(request: UrlRequest) -> tuple[int, bytes]:
|
|
651
|
+
"""Verify credentials in at most three attempts with capped jittered backoff."""
|
|
652
|
+
attempts = 3
|
|
653
|
+
for attempt in range(attempts):
|
|
654
|
+
status = 503
|
|
655
|
+
payload = b""
|
|
656
|
+
try:
|
|
657
|
+
with urlopen(request, timeout=2.0) as response: # noqa: S310 - platform-owned endpoint
|
|
658
|
+
status = response.status
|
|
659
|
+
payload = response.read()
|
|
660
|
+
except HTTPError as error:
|
|
661
|
+
status = error.code
|
|
662
|
+
payload = b""
|
|
663
|
+
error.close()
|
|
664
|
+
except (OSError, URLError) as error:
|
|
665
|
+
status = 503
|
|
666
|
+
reason = error.reason if isinstance(error, URLError) else error
|
|
667
|
+
if (
|
|
668
|
+
attempt == attempts - 1
|
|
669
|
+
or not isinstance(reason, OSError)
|
|
670
|
+
or isinstance(reason, SSLCertVerificationError)
|
|
671
|
+
):
|
|
672
|
+
raise ManagedAuthError(503, "LangSmith API-key verification unavailable") from error
|
|
673
|
+
if status not in {408, 500, 502, 503, 504}:
|
|
674
|
+
break
|
|
675
|
+
if attempt < attempts - 1:
|
|
676
|
+
time.sleep(secrets.randbelow(min(100 * 2**attempt, 200) + 1) / 1000)
|
|
677
|
+
|
|
678
|
+
return status, payload
|
|
602
679
|
|
|
603
680
|
|
|
604
681
|
def _langsmith_managed_user(verified: LangSmithAuthResponse, tenant_id: str) -> ManagedUser:
|
|
@@ -785,5 +862,9 @@ def _normalize_headers(headers: HeadersLike) -> dict[str, str]:
|
|
|
785
862
|
return out
|
|
786
863
|
|
|
787
864
|
|
|
788
|
-
def _http_exception(err: ManagedAuthError) ->
|
|
865
|
+
def _http_exception(err: ManagedAuthError) -> Exception:
|
|
866
|
+
"""Agent Server keeps only 401/403 from SDK exceptions, so 503 uses Starlette."""
|
|
867
|
+
if err.status == HTTPStatus.SERVICE_UNAVAILABLE:
|
|
868
|
+
starlette_exceptions = import_module("starlette.exceptions")
|
|
869
|
+
return starlette_exceptions.HTTPException(status_code=err.status, detail=err.detail)
|
|
789
870
|
return Auth.exceptions.HTTPException(status_code=err.status, detail=err.detail)
|
{managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: managed-deepagents
|
|
3
|
-
Version: 0.9.3.
|
|
3
|
+
Version: 0.9.3.dev14
|
|
4
4
|
Summary: Managed Deep Agents — the define_deep_agent authoring interface plus the CLI that compiles and deploys a code-first Deep Agent repository to a managed LangGraph runtime.
|
|
5
5
|
Author: LangChain
|
|
6
6
|
License: MIT
|
{managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/RECORD
RENAMED
|
@@ -11,7 +11,7 @@ managed_deepagents/_cors.py,sha256=V96RPrqewdRWG5RpEMEBnPuRq9_zF8nf4vf99k5dkuI,7
|
|
|
11
11
|
managed_deepagents/_credential_gate.py,sha256=2BsZ13jJns7qFMxD89JnQoujXmkfoOBelRQEx0A8WBE,12208
|
|
12
12
|
managed_deepagents/_eval_filesystem.py,sha256=_oRR0CUzpO7XND2JkkNUZH63m5kwxmGcR7cfqfFO378,8768
|
|
13
13
|
managed_deepagents/_extension.py,sha256=MqCWS4AGxiURPtLlA2y_tWKdRL8Zu1-VZyQ6Q3HDgzc,5315
|
|
14
|
-
managed_deepagents/_identity_auth.py,sha256=
|
|
14
|
+
managed_deepagents/_identity_auth.py,sha256=xTi1IiaN3ZRsfOXwpuUU4T9R7Lmhb3lpLkq9zmLbAvs,34936
|
|
15
15
|
managed_deepagents/_identity_http.py,sha256=AvPpbGtJ60zTovPrLnFwUOum2Aqg5kfVntCIlYCQ4IE,16230
|
|
16
16
|
managed_deepagents/_identity_links.py,sha256=T-Ae45zliSDkWhEG8_YH8hS5Kixt77_bpdAoBcSGe3U,8082
|
|
17
17
|
managed_deepagents/_identity_runtime.py,sha256=6Q3YU2N_9WDIlkHqIxhDGclCD2eyxfIACNBPtVl5Hg4,26279
|
|
@@ -40,7 +40,7 @@ managed_deepagents/run_context.py,sha256=1Nc3pew_nROgKi18PAKhn7vOAed-PmxArqUTpce
|
|
|
40
40
|
managed_deepagents/runtime.py,sha256=88QmwIzEVCyq4p2BWOmw20xJJLSyemfbPneVfNnx7C0,95214
|
|
41
41
|
managed_deepagents/sandbox.py,sha256=8qaswX6F2LYJX1uGq_7XwAGHZjGOD9VQ0WISqPK_ohs,4734
|
|
42
42
|
managed_deepagents/schedules.py,sha256=XROsDs-QwCWH0yEwakIN5Rhl5aM06eZX5-JFJ-KG1To,5898
|
|
43
|
-
managed_deepagents/_binaries/mda.exe,sha256=
|
|
43
|
+
managed_deepagents/_binaries/mda.exe,sha256=fySWOU-Lb3tDL7-NdXJBlt0P605IGoYERWzKYkfR6Jo,4537856
|
|
44
44
|
managed_deepagents/_channels/__init__.py,sha256=tY94zltWKNw-FIzbGjrh0cSAc2JIHCEAvcY7hzoRED0,801
|
|
45
45
|
managed_deepagents/_channels/assistant_text.py,sha256=ZLYAF1MQVE5_EN49MoPJdB8Ckf3vNPpXNBhkdA4egF0,3414
|
|
46
46
|
managed_deepagents/_channels/binding.py,sha256=DnxB7FXkbY5B3PCEAGz3JJBCCnQSdWz8PU8ze4fdcZU,5302
|
|
@@ -102,9 +102,9 @@ managed_deepagents/identity/__init__.py,sha256=YMB5p2DRyyY_82gGNVfGHjfjnUFRTtMne
|
|
|
102
102
|
managed_deepagents/identity/claims.py,sha256=prby7r_8Lww3MmoBm8PX6PsSGE3GwSHkr8mVIz_08nU,1180
|
|
103
103
|
managed_deepagents/identity/options.py,sha256=x_yMbXEFR7zXyehEjDHG2qjAlukXjrRBcQLcM6IndLM,2550
|
|
104
104
|
managed_deepagents/identity/supabase.py,sha256=8uobl3WCrQL_ieSXG8KTLf1th7Qjim9liZT50HeaJE0,6026
|
|
105
|
-
managed_deepagents-0.9.3.
|
|
106
|
-
managed_deepagents-0.9.3.
|
|
107
|
-
managed_deepagents-0.9.3.
|
|
108
|
-
managed_deepagents-0.9.3.
|
|
109
|
-
managed_deepagents-0.9.3.
|
|
110
|
-
managed_deepagents-0.9.3.
|
|
105
|
+
managed_deepagents-0.9.3.dev14.dist-info/licenses/LICENSE,sha256=WnPZQQ608ojZUkXl7BW6VbKloIAibZiGm1K6cjeZOL8,1066
|
|
106
|
+
managed_deepagents-0.9.3.dev14.dist-info/METADATA,sha256=TXTHoOQIupl9poZD5XnnB9QHLaz4TetyyLLiPl_0R1s,33510
|
|
107
|
+
managed_deepagents-0.9.3.dev14.dist-info/WHEEL,sha256=3I5VVWZdsFlU417aCS2bMRuerS8wsfvBq99MyatBV3A,97
|
|
108
|
+
managed_deepagents-0.9.3.dev14.dist-info/entry_points.txt,sha256=ziZqkKuaDO3qHCjKmBhrx9cm3ok8bZ9xcEDpUTj4unM,53
|
|
109
|
+
managed_deepagents-0.9.3.dev14.dist-info/top_level.txt,sha256=fdBo4O0Hlol_w022tTLB5ftZpamb4yJoQ3MUvjgTGfA,19
|
|
110
|
+
managed_deepagents-0.9.3.dev14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{managed_deepagents-0.9.3.dev13.dist-info → managed_deepagents-0.9.3.dev14.dist-info}/top_level.txt
RENAMED
|
File without changes
|