ms-tau-sdk 2.0.30.dev92__tar.gz → 2.0.30.dev93__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.
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/CHANGELOG.md +21 -1
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/PKG-INFO +1 -1
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/pyproject.toml +1 -1
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/tau_local_development/SKILL.md +7 -1
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/client.py +150 -27
- ms_tau_sdk-2.0.30.dev93/src/ms_tau_sdk/backend/hydrate_endpoint.py +352 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/local.py +40 -5
- ms_tau_sdk-2.0.30.dev93/src/ms_tau_sdk/backend/release_access.py +77 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/manager.py +80 -11
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/requester.py +2 -57
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/settings.py +110 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/.gitignore +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/README.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/app.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/cli.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/config.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/env_file.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/logs.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/proxy.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/state.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/static/BULMA-LICENSE.txt +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/static/app.js +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/static/board.css +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/static/bulma.min.css +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/packages/tau-board/src/ms_tau_board/static/index.html +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/SKILL.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/agents/openai.yaml +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/design-agent-icons-and-motion/references/metatables-example.html +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/tau_a2a_runtime_adapter/SKILL.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/tau_project_customization/SKILL.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/tau_repository_integration/SKILL.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/agent_skills/tau_security_and_access/SKILL.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/a2a.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/chat.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/conversations.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/dependencies.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/health.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/inspection.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/local_chat.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/models.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/request_identity.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/api/sessions.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/app.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/application.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/assertions.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/auth.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/mcp.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/models.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/routes.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/backend/team_memberships.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/cli.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/errors.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/logging.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/a2a_failure.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/a2a_message.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/a2a_roles.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/assistant_ui.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/caller_context.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/chat_history.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/protocols/strict_json.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/providers/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/providers/definitions.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/providers/factory.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/providers/tau_compat.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/SYSTEM.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/context_compat.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/loader.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/prompts/review-code-repository.md +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/resources/selection.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/deployment_health.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/events.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/extensions.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/failures.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/live_turns.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/observability.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/provenance.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/session.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/snapshots.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/runtime/task_context.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/sessions/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/sessions/storage.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/skills.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/__init__.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/mainsequence_mcp.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/mcp_applications.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/mcp_connection.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/skill_read.py +0 -0
- {ms_tau_sdk-2.0.30.dev92 → ms_tau_sdk-2.0.30.dev93}/src/ms_tau_sdk/tools/task_control.py +0 -0
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 2.0.30 — 2026-11-
|
|
3
|
+
## 2.0.30 — 2026-11-10
|
|
4
|
+
|
|
5
|
+
- **Provider credentials can come from an application's own hydrate endpoint.** An application
|
|
6
|
+
that serves people the platform does not know, and keeps their model credentials itself, can
|
|
7
|
+
serve tdag-django's hydrate contract, and the runtime then hydrates every session's credential
|
|
8
|
+
from it and none from the platform.
|
|
9
|
+
`MAINSEQUENCE_TAU_PROVIDER_CREDENTIAL_HYDRATE_RELEASE_UID` names a FastAPI release, in hosted and
|
|
10
|
+
in local mode: the runtime obtains a short-lived token for it through `resolve-runtime-access`,
|
|
11
|
+
with its own credential and no delegation, and posts tdag-django's body to
|
|
12
|
+
`{rpc_url}/api/v1/model-provider-credentials/hydrate/` with that token alone. In local mode,
|
|
13
|
+
`TAU_LOCAL_PROVIDER_CREDENTIAL_HYDRATE_URL` may instead name the developer's own service on a
|
|
14
|
+
loopback origin, which receives no credential of any kind. In local mode with either, every
|
|
15
|
+
hydration names its session in `agent_session_uid`, readiness hydrates nothing, and a session
|
|
16
|
+
hydrates from the endpoint when it loads or its model is selected, before its first turn. A
|
|
17
|
+
hosted session still bootstraps from the platform, whose credential is dropped unread. The
|
|
18
|
+
runtime checks the answer's shape, its provider control against the session's and that its
|
|
19
|
+
credential `uid` stays the same across refreshes; a `409` reports its `error_code` and truncated
|
|
20
|
+
`error_detail`. `/health` reports `provider_credential_source`. Unset, every request is
|
|
21
|
+
unchanged. See
|
|
22
|
+
[custom hydrate endpoints](docs/reference/settings.md#custom-provider-credential-hydrate-endpoints)
|
|
23
|
+
and [ADR 0027](docs/adrs/0027-custom-provider-credential-hydrate-endpoints.md).
|
|
4
24
|
|
|
5
25
|
- **Sessions may name the person they serve, and applications learn which session a tool call
|
|
6
26
|
serves.** A session the platform returns may carry `subowner: {issuer_uid, subject}`, the person
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: ms-tau-sdk
|
|
3
|
-
Version: 2.0.30.
|
|
3
|
+
Version: 2.0.30.dev93
|
|
4
4
|
Summary: Workspace-bound Tau application primitives for Main Sequence projects
|
|
5
5
|
Project-URL: Changelog, https://github.com/mainsequence-sdk/ms-tau-sdk/blob/development/CHANGELOG.md
|
|
6
6
|
Project-URL: Documentation, https://github.com/mainsequence-sdk/ms-tau-sdk/tree/development/docs
|
|
@@ -51,6 +51,12 @@ explicit `TAU_LOCAL_PROVIDER` and `TAU_LOCAL_MODEL`, returns provider-control ev
|
|
|
51
51
|
the provider credential used for inference. Provider secrets are neither environment settings nor
|
|
52
52
|
local state.
|
|
53
53
|
|
|
54
|
+
An application that keeps its own people's model credentials can hydrate them instead: set
|
|
55
|
+
`MAINSEQUENCE_TAU_PROVIDER_CREDENTIAL_HYDRATE_RELEASE_UID` to its release, or, in local mode only,
|
|
56
|
+
`TAU_LOCAL_PROVIDER_CREDENTIAL_HYDRATE_URL` to its service on a loopback origin such as
|
|
57
|
+
`http://127.0.0.1:8611`. Every hydration then names the local session in `agent_session_uid`, and
|
|
58
|
+
readiness hydrates nothing. A loopback address receives no credential of any kind. See ADR 0027.
|
|
59
|
+
|
|
54
60
|
## Exact local/remote boundary
|
|
55
61
|
|
|
56
62
|
| Concern | Local-mode behavior |
|
|
@@ -59,7 +65,7 @@ local state.
|
|
|
59
65
|
| Chat history, snapshots, leases, activity, and cancellation | Workspace SQLite |
|
|
60
66
|
| Public A2A Message and Task state | Workspace SQLite |
|
|
61
67
|
| Main Sequence authentication and token refresh | Remote. The token comes from the Main Sequence CLI session, or from an exported JWT pair |
|
|
62
|
-
| Provider authorization, hydration, and inference | Remote and real |
|
|
68
|
+
| Provider authorization, hydration, and inference | Remote and real; hydration comes from a custom endpoint when one is set |
|
|
63
69
|
| Main Sequence MCP catalog and tool calls | Remote and real; platform mutations remain possible |
|
|
64
70
|
| Project instructions, skills, hooks, and extensions | Normal repository `.tau` composition |
|
|
65
71
|
|
|
@@ -20,6 +20,7 @@ from ms_tau_sdk.errors import (
|
|
|
20
20
|
BackendConflictError,
|
|
21
21
|
BackendError,
|
|
22
22
|
BackendTimeoutError,
|
|
23
|
+
ConfigurationError,
|
|
23
24
|
LocalModeUnsupportedError,
|
|
24
25
|
SessionNotFoundError,
|
|
25
26
|
)
|
|
@@ -29,6 +30,11 @@ from ms_tau_sdk.settings import TauSDKSettings
|
|
|
29
30
|
|
|
30
31
|
from .assertions import ASSERTION_HEADER
|
|
31
32
|
from .auth import BackendAuth
|
|
33
|
+
from .hydrate_endpoint import (
|
|
34
|
+
CustomHydrateEndpoint,
|
|
35
|
+
LocalAddressHydrateEndpoint,
|
|
36
|
+
ReleaseHydrateEndpoint,
|
|
37
|
+
)
|
|
32
38
|
from .models import (
|
|
33
39
|
AgentCardEnvelope,
|
|
34
40
|
AgentSession,
|
|
@@ -205,25 +211,68 @@ class MainSequenceClient:
|
|
|
205
211
|
auth: BackendAuth,
|
|
206
212
|
*,
|
|
207
213
|
client: httpx.AsyncClient | None = None,
|
|
214
|
+
hydrate_client: httpx.AsyncClient | None = None,
|
|
208
215
|
) -> None:
|
|
209
216
|
self.settings = settings
|
|
210
217
|
self.auth = auth
|
|
211
218
|
self._client = client or httpx.AsyncClient(
|
|
212
219
|
base_url=settings.backend_url,
|
|
213
|
-
timeout=
|
|
214
|
-
connect=settings.backend_connect_timeout_seconds,
|
|
215
|
-
read=settings.backend_read_timeout_seconds,
|
|
216
|
-
write=settings.backend_write_timeout_seconds,
|
|
217
|
-
pool=settings.backend_pool_timeout_seconds,
|
|
218
|
-
),
|
|
220
|
+
timeout=self._timeout(settings),
|
|
219
221
|
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
|
|
220
222
|
)
|
|
221
223
|
self._owns_client = client is None
|
|
222
224
|
self.auth.bind_client(self._client)
|
|
225
|
+
# A custom hydrate endpoint is called through its own client, never through the
|
|
226
|
+
# platform's, so no platform cookie or header can reach it (ADR 0027).
|
|
227
|
+
self._hydrate_http = hydrate_client
|
|
228
|
+
self._owns_hydrate_http = hydrate_client is None
|
|
229
|
+
self._hydrate_endpoint = self._custom_hydrate_endpoint()
|
|
230
|
+
|
|
231
|
+
@staticmethod
|
|
232
|
+
def _timeout(settings: TauSDKSettings) -> httpx.Timeout:
|
|
233
|
+
return httpx.Timeout(
|
|
234
|
+
connect=settings.backend_connect_timeout_seconds,
|
|
235
|
+
read=settings.backend_read_timeout_seconds,
|
|
236
|
+
write=settings.backend_write_timeout_seconds,
|
|
237
|
+
pool=settings.backend_pool_timeout_seconds,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
def _custom_hydrate_endpoint(self) -> CustomHydrateEndpoint | None:
|
|
241
|
+
"""The custom endpoint every hydration goes to instead of tdag-django, or None."""
|
|
242
|
+
|
|
243
|
+
release_uid = self.settings.provider_credential_hydrate_release_uid
|
|
244
|
+
if release_uid is not None:
|
|
245
|
+
|
|
246
|
+
async def resolve(uid: str) -> ReleaseRuntimeAccess:
|
|
247
|
+
# The runtime's own access, without a delegation: hydration serves the session.
|
|
248
|
+
return await self.resolve_release_runtime_access(uid, proof=None)
|
|
249
|
+
|
|
250
|
+
return ReleaseHydrateEndpoint(
|
|
251
|
+
self.settings,
|
|
252
|
+
release_uid,
|
|
253
|
+
resolve=resolve,
|
|
254
|
+
http=self._hydrate_http_client,
|
|
255
|
+
)
|
|
256
|
+
origin = self.settings.local_provider_credential_hydrate_url
|
|
257
|
+
if origin is not None and self.settings.local_mode:
|
|
258
|
+
return LocalAddressHydrateEndpoint(
|
|
259
|
+
self.settings, origin, http=self._hydrate_http_client
|
|
260
|
+
)
|
|
261
|
+
return None
|
|
262
|
+
|
|
263
|
+
def _hydrate_http_client(self) -> httpx.AsyncClient:
|
|
264
|
+
if self._hydrate_http is None:
|
|
265
|
+
self._hydrate_http = httpx.AsyncClient(
|
|
266
|
+
timeout=self._timeout(self.settings),
|
|
267
|
+
follow_redirects=False,
|
|
268
|
+
)
|
|
269
|
+
return self._hydrate_http
|
|
223
270
|
|
|
224
271
|
async def aclose(self) -> None:
|
|
225
272
|
if self._owns_client:
|
|
226
273
|
await self._client.aclose()
|
|
274
|
+
if self._owns_hydrate_http and self._hydrate_http is not None:
|
|
275
|
+
await self._hydrate_http.aclose()
|
|
227
276
|
|
|
228
277
|
async def begin_local_conversation_message(
|
|
229
278
|
self,
|
|
@@ -882,13 +931,7 @@ class MainSequenceClient:
|
|
|
882
931
|
}
|
|
883
932
|
if custom_id is not None:
|
|
884
933
|
payload["custom_id"] = custom_id
|
|
885
|
-
|
|
886
|
-
"POST",
|
|
887
|
-
model_provider_credentials("hydrate"),
|
|
888
|
-
json=payload,
|
|
889
|
-
idempotent=True,
|
|
890
|
-
)
|
|
891
|
-
evidence = self._provider_evidence(provider, data)
|
|
934
|
+
evidence = await self._hydrate(provider, model=model, payload=payload)
|
|
892
935
|
if custom_id is not None and evidence.credential.custom_id != custom_id:
|
|
893
936
|
raise BackendError("Backend did not hydrate the requested configured provider")
|
|
894
937
|
return evidence
|
|
@@ -902,32 +945,112 @@ class MainSequenceClient:
|
|
|
902
945
|
holder_id: str,
|
|
903
946
|
custom_id: str | None = None,
|
|
904
947
|
organization_environment_uid: str | None = None,
|
|
948
|
+
agent_session_uid: str | None = None,
|
|
905
949
|
) -> ProviderExecutionEvidence:
|
|
906
|
-
"""Hydrate a selection the user's policies allow, using the backend's access checks.
|
|
950
|
+
"""Hydrate a selection the user's policies allow, using the backend's access checks.
|
|
951
|
+
|
|
952
|
+
With a custom hydrate endpoint the body also names ``agent_session_uid``, the local
|
|
953
|
+
session the hydration is for, so that the endpoint answers the credential of the person
|
|
954
|
+
that session serves (ADR 0027). Without one, the body is tdag-django's and never names a
|
|
955
|
+
session.
|
|
956
|
+
"""
|
|
907
957
|
selection: dict[str, str] = {"provider": provider, "model": model}
|
|
908
958
|
if thinking_level:
|
|
909
959
|
selection["thinking_level"] = thinking_level
|
|
910
|
-
payload: dict[str, Any] = {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
960
|
+
payload: dict[str, Any] = {}
|
|
961
|
+
if self._hydrate_endpoint is not None:
|
|
962
|
+
if not agent_session_uid:
|
|
963
|
+
raise ConfigurationError(
|
|
964
|
+
"A custom provider credential hydrate endpoint hydrates only for a session"
|
|
965
|
+
)
|
|
966
|
+
payload["agent_session_uid"] = agent_session_uid
|
|
967
|
+
payload.update(
|
|
968
|
+
{
|
|
969
|
+
"providers": [provider],
|
|
970
|
+
"holder_id": holder_id,
|
|
971
|
+
"supported_provider_control_schema_versions": [1],
|
|
972
|
+
"execution_selection": selection,
|
|
973
|
+
}
|
|
974
|
+
)
|
|
916
975
|
if organization_environment_uid is not None:
|
|
917
976
|
payload["organization_environment_uid"] = organization_environment_uid
|
|
918
977
|
if custom_id is not None:
|
|
919
978
|
payload["custom_id"] = custom_id
|
|
920
|
-
|
|
921
|
-
"POST",
|
|
922
|
-
model_provider_credentials("hydrate"),
|
|
923
|
-
json=payload,
|
|
924
|
-
idempotent=True,
|
|
925
|
-
)
|
|
926
|
-
evidence = self._provider_evidence(provider, data)
|
|
979
|
+
evidence = await self._hydrate(provider, model=model, payload=payload)
|
|
927
980
|
if custom_id is not None and evidence.credential.custom_id != custom_id:
|
|
928
981
|
raise BackendError("Backend did not hydrate the requested configured provider")
|
|
929
982
|
return evidence
|
|
930
983
|
|
|
984
|
+
async def _hydrate(
|
|
985
|
+
self,
|
|
986
|
+
provider: str,
|
|
987
|
+
*,
|
|
988
|
+
model: str,
|
|
989
|
+
payload: Mapping[str, Any],
|
|
990
|
+
) -> ProviderExecutionEvidence:
|
|
991
|
+
"""Post one hydrate body to tdag-django, or to the custom endpoint when one is set."""
|
|
992
|
+
|
|
993
|
+
if self._hydrate_endpoint is None:
|
|
994
|
+
data = await self._request(
|
|
995
|
+
"POST",
|
|
996
|
+
model_provider_credentials("hydrate"),
|
|
997
|
+
json=payload,
|
|
998
|
+
idempotent=True,
|
|
999
|
+
)
|
|
1000
|
+
return self._provider_evidence(provider, data)
|
|
1001
|
+
data = await self._hydrate_endpoint.hydrate(payload)
|
|
1002
|
+
return self._custom_provider_evidence(provider, model=model, data=data)
|
|
1003
|
+
|
|
1004
|
+
def _custom_provider_evidence(
|
|
1005
|
+
self,
|
|
1006
|
+
provider: str,
|
|
1007
|
+
*,
|
|
1008
|
+
model: str,
|
|
1009
|
+
data: Mapping[str, Any],
|
|
1010
|
+
) -> ProviderExecutionEvidence:
|
|
1011
|
+
"""Check a custom endpoint's answer against tdag-django's contract (ADR 0027, section 3).
|
|
1012
|
+
|
|
1013
|
+
It holds exactly one credential, for the selected provider, with the endpoint's stable
|
|
1014
|
+
``uid``; nothing missing or revoked; and the provider control of the selected provider and
|
|
1015
|
+
model. An error names fields, never their values.
|
|
1016
|
+
"""
|
|
1017
|
+
|
|
1018
|
+
source = "The provider credential hydrate endpoint"
|
|
1019
|
+
credentials = data.get("credentials")
|
|
1020
|
+
if not isinstance(credentials, Mapping) or list(credentials) != [provider]:
|
|
1021
|
+
raise BackendError(f"{source} must answer exactly one credential, for {provider}")
|
|
1022
|
+
if data.get("missing") or data.get("revoked"):
|
|
1023
|
+
raise BackendError(f"{source} answered a missing or revoked credential")
|
|
1024
|
+
hydrated = credentials[provider]
|
|
1025
|
+
uid = hydrated.get("uid") if isinstance(hydrated, Mapping) else None
|
|
1026
|
+
if not isinstance(uid, str) or not uid.strip():
|
|
1027
|
+
raise BackendError(f"{source} must name the stable uid of its credential")
|
|
1028
|
+
raw = hydrated.get("credential")
|
|
1029
|
+
kind = hydrated.get("credential_kind")
|
|
1030
|
+
if not isinstance(raw, Mapping):
|
|
1031
|
+
raise BackendError(f"{source} answered an invalid credential for {provider}")
|
|
1032
|
+
if kind is not None and raw.get("type") is not None and raw.get("type") != kind:
|
|
1033
|
+
raise BackendError(f"{source} answered a credential whose type is not its kind")
|
|
1034
|
+
evidence: ProviderExecutionEvidence | None = None
|
|
1035
|
+
invalid_fields: list[str] = []
|
|
1036
|
+
try:
|
|
1037
|
+
evidence = self._provider_evidence(provider, data)
|
|
1038
|
+
except ValidationError as error:
|
|
1039
|
+
invalid_fields = sorted(
|
|
1040
|
+
{".".join(str(part) for part in item["loc"]) for item in error.errors()}
|
|
1041
|
+
)
|
|
1042
|
+
if evidence is None:
|
|
1043
|
+
# Raised outside the handler: a validation error repeats its input, a credential.
|
|
1044
|
+
raise BackendError(
|
|
1045
|
+
f"{source} answered invalid credential fields: {', '.join(invalid_fields)}"
|
|
1046
|
+
)
|
|
1047
|
+
control = evidence.provider_control
|
|
1048
|
+
if control.provider != provider or control.model.model != model:
|
|
1049
|
+
raise BackendConflictError(
|
|
1050
|
+
f"{source}'s provider control does not match the session's selection"
|
|
1051
|
+
)
|
|
1052
|
+
return evidence
|
|
1053
|
+
|
|
931
1054
|
def _provider_evidence(self, provider: str, data: object) -> ProviderExecutionEvidence:
|
|
932
1055
|
if not isinstance(data, dict):
|
|
933
1056
|
raise BackendError("Backend provider hydration response is invalid")
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"""Custom provider credential hydrate endpoints (ADR 0027).
|
|
2
|
+
|
|
3
|
+
tdag-django's ``POST /api/v1/model-provider-credentials/hydrate/`` defines the hydrate contract. A
|
|
4
|
+
custom endpoint implements the same contract for people the platform does not know:
|
|
5
|
+
|
|
6
|
+
- a FastAPI release that ``MAINSEQUENCE_TAU_PROVIDER_CREDENTIAL_HYDRATE_RELEASE_UID`` names, in
|
|
7
|
+
hosted and in local mode. The runtime calls it with a short-lived token the platform mints for
|
|
8
|
+
that release (``resolve-runtime-access``, without a delegation); and
|
|
9
|
+
- in local mode only, the developer's own loopback service that
|
|
10
|
+
``TAU_LOCAL_PROVIDER_CREDENTIAL_HYDRATE_URL`` names. Nothing leaves the machine, so the call
|
|
11
|
+
carries no authorization at all and the service decides the caller itself.
|
|
12
|
+
|
|
13
|
+
Only the token, to the release, crosses: never the runtime's Main Sequence credential, a caller
|
|
14
|
+
assertion, a lease token, caller context or an ``X-MainSequence-*`` header. No answer, token or
|
|
15
|
+
credential value is logged or kept in an error.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import asyncio
|
|
21
|
+
import time
|
|
22
|
+
from collections.abc import Awaitable, Callable, Mapping
|
|
23
|
+
from typing import Any
|
|
24
|
+
|
|
25
|
+
import httpx
|
|
26
|
+
import structlog
|
|
27
|
+
|
|
28
|
+
from ms_tau_sdk.errors import (
|
|
29
|
+
ApplicationReadinessTimeoutError,
|
|
30
|
+
ApplicationWakingError,
|
|
31
|
+
BackendConflictError,
|
|
32
|
+
BackendError,
|
|
33
|
+
BackendTimeoutError,
|
|
34
|
+
)
|
|
35
|
+
from ms_tau_sdk.settings import TauSDKSettings
|
|
36
|
+
|
|
37
|
+
from .models import ReleaseRuntimeAccess
|
|
38
|
+
from .release_access import ReleaseAccess, release_access_from_answer
|
|
39
|
+
from .routes import model_provider_credentials
|
|
40
|
+
|
|
41
|
+
logger = structlog.get_logger(__name__)
|
|
42
|
+
|
|
43
|
+
HYDRATE_PATH = model_provider_credentials("hydrate")
|
|
44
|
+
RETRYABLE_STATUS_CODES = frozenset({500, 502, 503, 504})
|
|
45
|
+
_ATTEMPTS = 3
|
|
46
|
+
_ERROR_CODE_LIMIT = 128
|
|
47
|
+
_ERROR_DETAIL_LIMIT = 500
|
|
48
|
+
|
|
49
|
+
type HttpClientFactory = Callable[[], httpx.AsyncClient]
|
|
50
|
+
type ResolveReleaseAccess = Callable[[str], Awaitable[ReleaseRuntimeAccess]]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _refusal_detail(response: httpx.Response) -> dict[str, str] | None:
|
|
54
|
+
"""The refusal's ``error_code`` and truncated ``error_detail``, and nothing else."""
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
body = response.json()
|
|
58
|
+
except ValueError:
|
|
59
|
+
return None
|
|
60
|
+
if not isinstance(body, Mapping):
|
|
61
|
+
return None
|
|
62
|
+
detail: dict[str, str] = {}
|
|
63
|
+
code = body.get("error_code")
|
|
64
|
+
text = body.get("error_detail")
|
|
65
|
+
if isinstance(code, str):
|
|
66
|
+
detail["error_code"] = code[:_ERROR_CODE_LIMIT]
|
|
67
|
+
if isinstance(text, str):
|
|
68
|
+
detail["error_detail"] = text[:_ERROR_DETAIL_LIMIT]
|
|
69
|
+
return detail or None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _log_fields(detail: Mapping[str, str] | None) -> dict[str, str]:
|
|
73
|
+
if not detail:
|
|
74
|
+
return {}
|
|
75
|
+
fields: dict[str, str] = {}
|
|
76
|
+
if "error_code" in detail:
|
|
77
|
+
fields["backend_error_code"] = detail["error_code"]
|
|
78
|
+
if "error_detail" in detail:
|
|
79
|
+
fields["backend_error_detail"] = detail["error_detail"]
|
|
80
|
+
return fields
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class CustomHydrateEndpoint:
|
|
84
|
+
"""One custom hydrate endpoint. It posts the hydrate body and returns the parsed answer.
|
|
85
|
+
|
|
86
|
+
The answer is checked against the contract by ``MainSequenceClient``; here only the HTTP
|
|
87
|
+
exchange is handled: the address, the authorization, retries and refusals.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
target_system = "provider_credential_hydrate_endpoint"
|
|
91
|
+
description = "The provider credential hydrate endpoint"
|
|
92
|
+
|
|
93
|
+
def __init__(self, settings: TauSDKSettings, *, http: HttpClientFactory) -> None:
|
|
94
|
+
self.settings = settings
|
|
95
|
+
self._http = http
|
|
96
|
+
|
|
97
|
+
async def hydrate(self, payload: Mapping[str, Any]) -> dict[str, Any]:
|
|
98
|
+
"""Post ``payload`` and return the answer's JSON object, or raise without a value."""
|
|
99
|
+
|
|
100
|
+
raise NotImplementedError
|
|
101
|
+
|
|
102
|
+
async def _send(
|
|
103
|
+
self,
|
|
104
|
+
url: httpx.URL,
|
|
105
|
+
payload: Mapping[str, Any],
|
|
106
|
+
*,
|
|
107
|
+
authorization: str | None,
|
|
108
|
+
) -> httpx.Response:
|
|
109
|
+
"""Post once, again on a transport failure or a server error, up to three times.
|
|
110
|
+
|
|
111
|
+
The endpoint answers a repeated request the same way (ADR 0027, section 6).
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
headers = {"Accept": "application/json"}
|
|
115
|
+
if authorization is not None:
|
|
116
|
+
headers["Authorization"] = f"Bearer {authorization}"
|
|
117
|
+
attempt = 0
|
|
118
|
+
while True:
|
|
119
|
+
attempt += 1
|
|
120
|
+
client = self._http()
|
|
121
|
+
# Built here, never from the client's defaults, so that no cookie and no header the
|
|
122
|
+
# client kept travels with it.
|
|
123
|
+
request = httpx.Request(
|
|
124
|
+
"POST",
|
|
125
|
+
url,
|
|
126
|
+
json=dict(payload),
|
|
127
|
+
headers=headers,
|
|
128
|
+
extensions={"timeout": client.timeout.as_dict()},
|
|
129
|
+
)
|
|
130
|
+
started_at = time.monotonic()
|
|
131
|
+
failure: httpx.HTTPError | None = None
|
|
132
|
+
response: httpx.Response | None = None
|
|
133
|
+
try:
|
|
134
|
+
response = await client.send(request, follow_redirects=False)
|
|
135
|
+
except httpx.HTTPError as error:
|
|
136
|
+
failure = error
|
|
137
|
+
finally:
|
|
138
|
+
client.cookies.clear()
|
|
139
|
+
duration_ms = round((time.monotonic() - started_at) * 1000, 3)
|
|
140
|
+
if response is None:
|
|
141
|
+
assert failure is not None
|
|
142
|
+
retryable = isinstance(failure, httpx.TransportError) and attempt < _ATTEMPTS
|
|
143
|
+
logger.warning(
|
|
144
|
+
"dependency.call.failed",
|
|
145
|
+
message="Provider credential hydration call failed",
|
|
146
|
+
dependency_operation=f"POST {HYDRATE_PATH}",
|
|
147
|
+
target_system=self.target_system,
|
|
148
|
+
dependency_attempt=attempt,
|
|
149
|
+
duration_ms=duration_ms,
|
|
150
|
+
error_type=type(failure).__name__,
|
|
151
|
+
outcome="failed",
|
|
152
|
+
retryable=retryable,
|
|
153
|
+
)
|
|
154
|
+
if retryable:
|
|
155
|
+
await asyncio.sleep(0.25 * (2 ** (attempt - 1)))
|
|
156
|
+
continue
|
|
157
|
+
# Raised outside the handler: the error holds the request and its token.
|
|
158
|
+
if isinstance(failure, httpx.TimeoutException):
|
|
159
|
+
raise BackendTimeoutError(
|
|
160
|
+
f"{self.description} did not answer in time",
|
|
161
|
+
timeout_seconds=self.settings.backend_read_timeout_seconds,
|
|
162
|
+
)
|
|
163
|
+
raise BackendError(
|
|
164
|
+
f"{self.description} could not be reached: {type(failure).__name__}"
|
|
165
|
+
)
|
|
166
|
+
retryable = response.status_code in RETRYABLE_STATUS_CODES and attempt < _ATTEMPTS
|
|
167
|
+
logger.info(
|
|
168
|
+
"dependency.call.completed",
|
|
169
|
+
message="Provider credential hydration call completed",
|
|
170
|
+
dependency_operation=f"POST {HYDRATE_PATH}",
|
|
171
|
+
target_system=self.target_system,
|
|
172
|
+
dependency_attempt=attempt,
|
|
173
|
+
status_code=response.status_code,
|
|
174
|
+
duration_ms=duration_ms,
|
|
175
|
+
outcome=(
|
|
176
|
+
"success"
|
|
177
|
+
if response.is_success
|
|
178
|
+
else "rejected"
|
|
179
|
+
if response.status_code < 500
|
|
180
|
+
else "failed"
|
|
181
|
+
),
|
|
182
|
+
retryable=retryable,
|
|
183
|
+
**(_log_fields(_refusal_detail(response)) if not response.is_success else {}),
|
|
184
|
+
)
|
|
185
|
+
if retryable:
|
|
186
|
+
await asyncio.sleep(0.25 * (2 ** (attempt - 1)))
|
|
187
|
+
continue
|
|
188
|
+
return response
|
|
189
|
+
|
|
190
|
+
def _answer(self, response: httpx.Response) -> dict[str, Any]:
|
|
191
|
+
status = response.status_code
|
|
192
|
+
if status == 409:
|
|
193
|
+
raise BackendConflictError(
|
|
194
|
+
f"{self.description} refused the hydration",
|
|
195
|
+
status_code=409,
|
|
196
|
+
detail=_refusal_detail(response),
|
|
197
|
+
)
|
|
198
|
+
if status == 403:
|
|
199
|
+
raise BackendError(
|
|
200
|
+
f"{self.description} refused this runtime",
|
|
201
|
+
status_code=403,
|
|
202
|
+
detail=_refusal_detail(response),
|
|
203
|
+
)
|
|
204
|
+
if not response.is_success:
|
|
205
|
+
raise BackendError(
|
|
206
|
+
f"{self.description} failed with HTTP {status}",
|
|
207
|
+
status_code=status,
|
|
208
|
+
)
|
|
209
|
+
if len(response.content) > self.settings.backend_max_response_bytes:
|
|
210
|
+
raise BackendError(f"{self.description} answer exceeded the configured size limit")
|
|
211
|
+
try:
|
|
212
|
+
data = response.json()
|
|
213
|
+
except ValueError:
|
|
214
|
+
data = None
|
|
215
|
+
if not isinstance(data, dict):
|
|
216
|
+
raise BackendError(f"{self.description} answered a body that is not a JSON object")
|
|
217
|
+
return data
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class LocalAddressHydrateEndpoint(CustomHydrateEndpoint):
|
|
221
|
+
"""The developer's own loopback service, in local mode. The call carries no authorization."""
|
|
222
|
+
|
|
223
|
+
target_system = "local_provider_credential_hydrate_address"
|
|
224
|
+
description = "The local provider credential hydrate address"
|
|
225
|
+
|
|
226
|
+
def __init__(self, settings: TauSDKSettings, origin: str, *, http: HttpClientFactory) -> None:
|
|
227
|
+
super().__init__(settings, http=http)
|
|
228
|
+
self.url = httpx.URL(origin.rstrip("/") + HYDRATE_PATH)
|
|
229
|
+
|
|
230
|
+
async def hydrate(self, payload: Mapping[str, Any]) -> dict[str, Any]:
|
|
231
|
+
response = await self._send(self.url, payload, authorization=None)
|
|
232
|
+
return self._answer(response)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class ReleaseHydrateEndpoint(CustomHydrateEndpoint):
|
|
236
|
+
"""A FastAPI release, called with a token the platform mints for it.
|
|
237
|
+
|
|
238
|
+
The token is the runtime's own (no delegation): hydration serves the session, not the person
|
|
239
|
+
of a turn. It is kept in memory until it nears expiry, and a ``401`` obtains a new one once.
|
|
240
|
+
"""
|
|
241
|
+
|
|
242
|
+
target_system = "provider_credential_hydrate_release"
|
|
243
|
+
description = "The provider credential hydrate release"
|
|
244
|
+
|
|
245
|
+
def __init__(
|
|
246
|
+
self,
|
|
247
|
+
settings: TauSDKSettings,
|
|
248
|
+
release_uid: str,
|
|
249
|
+
*,
|
|
250
|
+
resolve: ResolveReleaseAccess,
|
|
251
|
+
http: HttpClientFactory,
|
|
252
|
+
) -> None:
|
|
253
|
+
super().__init__(settings, http=http)
|
|
254
|
+
self.release_uid = release_uid
|
|
255
|
+
self._resolve = resolve
|
|
256
|
+
self._access: ReleaseAccess | None = None
|
|
257
|
+
self._lock = asyncio.Lock()
|
|
258
|
+
|
|
259
|
+
def __repr__(self) -> str:
|
|
260
|
+
return f"ReleaseHydrateEndpoint(release_uid={self.release_uid!r})"
|
|
261
|
+
|
|
262
|
+
async def hydrate(self, payload: Mapping[str, Any]) -> dict[str, Any]:
|
|
263
|
+
access = await self._release_access(stale=None)
|
|
264
|
+
response = await self._send(self._url(access), payload, authorization=access.token.value)
|
|
265
|
+
if response.status_code == 401:
|
|
266
|
+
# The token may have expired early or been revoked: obtain a new one, once.
|
|
267
|
+
access = await self._release_access(stale=access)
|
|
268
|
+
response = await self._send(
|
|
269
|
+
self._url(access), payload, authorization=access.token.value
|
|
270
|
+
)
|
|
271
|
+
if response.status_code == 401:
|
|
272
|
+
raise BackendError(f"{self.description} refused its token", status_code=401)
|
|
273
|
+
return self._answer(response)
|
|
274
|
+
|
|
275
|
+
def _url(self, access: ReleaseAccess) -> httpx.URL:
|
|
276
|
+
url = httpx.URL(str(access.rpc_url).rstrip("/") + HYDRATE_PATH)
|
|
277
|
+
if (url.scheme, url.host, url.port) != (
|
|
278
|
+
access.rpc_url.scheme,
|
|
279
|
+
access.rpc_url.host,
|
|
280
|
+
access.rpc_url.port,
|
|
281
|
+
):
|
|
282
|
+
raise BackendError("Backend release access names an invalid RPC URL")
|
|
283
|
+
return url
|
|
284
|
+
|
|
285
|
+
async def _release_access(self, *, stale: ReleaseAccess | None) -> ReleaseAccess:
|
|
286
|
+
async with self._lock:
|
|
287
|
+
cached = self._access
|
|
288
|
+
if cached is not None and cached is not stale and not cached.token.needs_refresh():
|
|
289
|
+
return cached
|
|
290
|
+
self._access = None
|
|
291
|
+
access = await self._ready_access()
|
|
292
|
+
self._access = access
|
|
293
|
+
return access
|
|
294
|
+
|
|
295
|
+
async def _ready_access(self) -> ReleaseAccess:
|
|
296
|
+
"""Obtain token access, waiting while the release wakes, within the ready timeout."""
|
|
297
|
+
|
|
298
|
+
timeout_seconds = self.settings.mcp_application_ready_timeout_seconds
|
|
299
|
+
started = asyncio.get_running_loop().time()
|
|
300
|
+
deadline = asyncio.timeout(None)
|
|
301
|
+
waiting = False
|
|
302
|
+
try:
|
|
303
|
+
async with deadline:
|
|
304
|
+
while True:
|
|
305
|
+
answer = await self._runtime_access()
|
|
306
|
+
try:
|
|
307
|
+
access = release_access_from_answer(answer)
|
|
308
|
+
except ApplicationWakingError as error:
|
|
309
|
+
if not waiting:
|
|
310
|
+
waiting = True
|
|
311
|
+
deadline.reschedule(started + timeout_seconds)
|
|
312
|
+
logger.info(
|
|
313
|
+
"runtime.provider_credential_release.waiting",
|
|
314
|
+
resource_release_uid=self.release_uid,
|
|
315
|
+
runtime_access_state="waking",
|
|
316
|
+
retry_after_seconds=error.retry_after_seconds,
|
|
317
|
+
)
|
|
318
|
+
await asyncio.sleep(error.retry_after_seconds)
|
|
319
|
+
else:
|
|
320
|
+
if waiting:
|
|
321
|
+
logger.info(
|
|
322
|
+
"runtime.provider_credential_release.ready",
|
|
323
|
+
resource_release_uid=self.release_uid,
|
|
324
|
+
)
|
|
325
|
+
return access
|
|
326
|
+
except TimeoutError:
|
|
327
|
+
if not deadline.expired():
|
|
328
|
+
raise
|
|
329
|
+
raise ApplicationReadinessTimeoutError(timeout_seconds=timeout_seconds)
|
|
330
|
+
|
|
331
|
+
async def _runtime_access(self) -> ReleaseRuntimeAccess:
|
|
332
|
+
failure: BackendError
|
|
333
|
+
try:
|
|
334
|
+
return await self._resolve(self.release_uid)
|
|
335
|
+
except BackendError as error:
|
|
336
|
+
# A transport failure keeps the request, and its credentials, as its cause, so only
|
|
337
|
+
# safe metadata is carried on, including a timeout's classification.
|
|
338
|
+
failure = (
|
|
339
|
+
BackendTimeoutError(str(error), timeout_seconds=error.timeout_seconds)
|
|
340
|
+
if isinstance(error, BackendTimeoutError)
|
|
341
|
+
else BackendError(str(error), status_code=error.backend_status)
|
|
342
|
+
)
|
|
343
|
+
failure.detail = error.detail
|
|
344
|
+
raise failure
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
__all__ = [
|
|
348
|
+
"HYDRATE_PATH",
|
|
349
|
+
"CustomHydrateEndpoint",
|
|
350
|
+
"LocalAddressHydrateEndpoint",
|
|
351
|
+
"ReleaseHydrateEndpoint",
|
|
352
|
+
]
|