|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from importlib.metadata import version as _pkg_version |
4 | 5 | from typing import TYPE_CHECKING, Any |
5 | 6 |
|
6 | 7 | import httpx |
7 | 8 |
|
8 | 9 | from agentscore.errors import AgentScoreError |
9 | 10 |
|
| 11 | +logger = logging.getLogger("agentscore") |
| 12 | + |
| 13 | +# Server truncates idempotency_key at 200 chars; warn the caller past that so two |
| 14 | +# distinct payments that share the first 200 chars don't silently dedup. |
| 15 | +_IDEMPOTENCY_KEY_MAX = 200 |
| 16 | + |
10 | 17 | if TYPE_CHECKING: |
11 | 18 | from agentscore.types import ( |
12 | 19 | AssessResponse, |
@@ -209,6 +216,11 @@ def associate_wallet( |
209 | 216 | # Truthy check (not `is not None`) so empty strings don't ship a useless key — mirrors |
210 | 217 | # node-sdk's behavior of only forwarding when the key actually has content. |
211 | 218 | if idempotency_key: |
| 219 | + if len(idempotency_key) > _IDEMPOTENCY_KEY_MAX: |
| 220 | + logger.warning( |
| 221 | + "associate_wallet: idempotency_key longer than %d chars will be truncated server-side.", |
| 222 | + _IDEMPOTENCY_KEY_MAX, |
| 223 | + ) |
212 | 224 | body["idempotency_key"] = idempotency_key |
213 | 225 | client = self._get_sync_client() |
214 | 226 | response = client.post("/v1/credentials/wallets", json=body) |
@@ -316,6 +328,11 @@ async def aassociate_wallet( |
316 | 328 | # Truthy check (not `is not None`) so empty strings don't ship a useless key — mirrors |
317 | 329 | # node-sdk's behavior of only forwarding when the key actually has content. |
318 | 330 | if idempotency_key: |
| 331 | + if len(idempotency_key) > _IDEMPOTENCY_KEY_MAX: |
| 332 | + logger.warning( |
| 333 | + "aassociate_wallet: idempotency_key longer than %d chars will be truncated server-side.", |
| 334 | + _IDEMPOTENCY_KEY_MAX, |
| 335 | + ) |
319 | 336 | body["idempotency_key"] = idempotency_key |
320 | 337 | client = self._get_async_client() |
321 | 338 | response = await client.post("/v1/credentials/wallets", json=body) |
|
0 commit comments