|
8 | 8 | from typing import Any, Optional |
9 | 9 |
|
10 | 10 | import logfire |
11 | | -from httpx import Response, URL, AsyncClient, HTTPStatusError |
| 11 | +from httpx import Response, URL, AsyncClient, HTTPStatusError, Headers |
12 | 12 | from httpx._client import UseClientDefault, USE_CLIENT_DEFAULT |
13 | 13 | from httpx._types import ( |
14 | 14 | RequestContent, |
@@ -58,6 +58,22 @@ def _transport_error_span_attrs(exc: Exception) -> dict[str, Any]: |
58 | 58 | } |
59 | 59 |
|
60 | 60 |
|
| 61 | +def _request_headers(headers: HeaderTypes | None) -> HeaderTypes | None: |
| 62 | + """Merge request-local workspace permalink headers into outbound API calls.""" |
| 63 | + from basic_memory.workspace_context import workspace_permalink_headers |
| 64 | + |
| 65 | + workspace_headers = workspace_permalink_headers() |
| 66 | + if not workspace_headers: |
| 67 | + return headers |
| 68 | + |
| 69 | + if headers is None: |
| 70 | + return workspace_headers |
| 71 | + |
| 72 | + merged_headers = Headers(headers) |
| 73 | + merged_headers.update(workspace_headers) |
| 74 | + return merged_headers |
| 75 | + |
| 76 | + |
61 | 77 | def get_error_message( |
62 | 78 | status_code: int, url: URL | str, method: str, msg: Optional[str] = None |
63 | 79 | ) -> str: |
@@ -224,7 +240,7 @@ async def call_get( |
224 | 240 | response = await client.get( |
225 | 241 | url, |
226 | 242 | params=params, |
227 | | - headers=headers, |
| 243 | + headers=_request_headers(headers), |
228 | 244 | cookies=cookies, |
229 | 245 | auth=auth, |
230 | 246 | follow_redirects=follow_redirects, |
@@ -328,7 +344,7 @@ async def call_put( |
328 | 344 | files=files, |
329 | 345 | json=json, |
330 | 346 | params=params, |
331 | | - headers=headers, |
| 347 | + headers=_request_headers(headers), |
332 | 348 | cookies=cookies, |
333 | 349 | auth=auth, |
334 | 350 | follow_redirects=follow_redirects, |
@@ -432,7 +448,7 @@ async def call_patch( |
432 | 448 | files=files, |
433 | 449 | json=json, |
434 | 450 | params=params, |
435 | | - headers=headers, |
| 451 | + headers=_request_headers(headers), |
436 | 452 | cookies=cookies, |
437 | 453 | auth=auth, |
438 | 454 | follow_redirects=follow_redirects, |
@@ -542,7 +558,7 @@ async def call_post( |
542 | 558 | files=files, |
543 | 559 | json=json, |
544 | 560 | params=params, |
545 | | - headers=headers, |
| 561 | + headers=_request_headers(headers), |
546 | 562 | cookies=cookies, |
547 | 563 | auth=auth, |
548 | 564 | follow_redirects=follow_redirects, |
@@ -667,7 +683,7 @@ async def call_delete( |
667 | 683 | response = await client.delete( |
668 | 684 | url=url, |
669 | 685 | params=params, |
670 | | - headers=headers, |
| 686 | + headers=_request_headers(headers), |
671 | 687 | cookies=cookies, |
672 | 688 | auth=auth, |
673 | 689 | follow_redirects=follow_redirects, |
|
0 commit comments