|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 | # Copyright (c) Alibaba, Inc. and its affiliates. |
3 | | -"""Single process-wide SDK session id. |
| 3 | +"""Compatibility re-export; the implementation moved to ``dashscope._shared``. |
4 | 4 |
|
5 | | -The ``x-dashscope-sdk-session-id`` header lets server-side access logs |
6 | | -group every request one SDK session makes. A process can emit requests |
7 | | -through both stacks at once -- the 1.x API classes and the 2.0 transport |
8 | | --- and the 2.0 client even delegates some calls (rl, agentstudio) |
9 | | -straight into 1.x. If each stack minted its own id, one logical session |
10 | | -would split across several ids and the grouping breaks. |
11 | | -
|
12 | | -This leaf module is the one source of truth both import. It depends only |
13 | | -on the stdlib so it can be pulled in from anywhere without dragging |
14 | | -``dashscope/__init__`` (and its v2 surface) into a cycle. |
15 | | -
|
16 | | -The embedded ``acli`` deliberately keeps its own id: it is a one-way |
17 | | -sync copy of the agenticCLI repo (design doc §3.2), so wiring it to this |
18 | | -module would be silently reverted by the next sync and cannot be |
19 | | -upstreamed as written. |
| 5 | +The session id state lives only in ``dashscope._shared._sdk_session`` so a |
| 6 | +process keeps exactly one id. Import from there in new code. |
20 | 7 | """ |
21 | 8 |
|
22 | | -from __future__ import annotations |
23 | | - |
24 | | -import threading |
25 | | -import uuid |
26 | | - |
27 | | -_session_id = None |
28 | | -_lock = threading.Lock() |
29 | | - |
30 | | - |
31 | | -def sdk_session_id() -> str: |
32 | | - """Return this process's session id, generating it on first use. |
| 9 | +from dashscope._shared._sdk_session import sdk_session_id |
33 | 10 |
|
34 | | - Double-checked locking: concurrent callers must not each mint their |
35 | | - own id and break the one-id-per-process invariant log grouping |
36 | | - relies on. |
37 | | - """ |
38 | | - global _session_id # pylint: disable=global-statement |
39 | | - if _session_id is None: |
40 | | - with _lock: |
41 | | - if _session_id is None: |
42 | | - _session_id = uuid.uuid4().hex |
43 | | - return _session_id |
| 11 | +__all__ = ["sdk_session_id"] |
0 commit comments