coze-coding-utils 0.1.7__tar.gz → 0.1.8__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.
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/PKG-INFO +1 -1
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/pyproject.toml +1 -1
- coze_coding_utils-0.1.8/src/coze_coding_utils/__init__.py +3 -0
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/src/coze_coding_utils/runtime_ctx/context.py +36 -33
- coze_coding_utils-0.1.7/src/coze_coding_utils/__init__.py +0 -3
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/.gitignore +0 -0
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/LICENSE +0 -0
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/README.md +0 -0
- {coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/src/coze_coding_utils/runtime_ctx/__init__.py +0 -0
{coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/src/coze_coding_utils/runtime_ctx/context.py
RENAMED
|
@@ -12,6 +12,7 @@ HEADER_RPC_PERSIST_REC_REC_BIZ_SCENE = "rpc-persist-rec-rec-biz-scene"
|
|
|
12
12
|
HEADER_RPC_PERSIST_COZE_RECORD_ROOT_ID = "rpc-persist-coze-record-root-id" # root_id,串联一次完整请求,通常标识一次完整对话
|
|
13
13
|
HEADER_RPC_PERSIST_REC_ROOT_ENTITY_TYPE = "rpc-persist-rec-rec-root-entity-type" # 对应最顶层实体类型,用于标识资源消耗的来源归属实体
|
|
14
14
|
HEADER_RPC_PERSIST_REC_ROOT_ENTITY_ID = "rpc-persist-rec-rec-root-entity-id" #对应最顶层实体ID
|
|
15
|
+
HEADER_RPC_PERSIST_REC_REC_EXT_INFO = "rpc-persist-rec-rec-ext-info" # 扩展信息,json字符串格式
|
|
15
16
|
|
|
16
17
|
# Environment variable keys
|
|
17
18
|
ENV_SPACE_ID = "COZE_PROJECT_SPACE_ID"
|
|
@@ -26,14 +27,16 @@ class Context:
|
|
|
26
27
|
project_id: str
|
|
27
28
|
logid: str = ""
|
|
28
29
|
method: str = ""
|
|
30
|
+
|
|
29
31
|
x_tt_env: Optional[str] = None
|
|
30
32
|
x_use_ppe: Optional[str] = None
|
|
31
33
|
x_tt_env_fe: Optional[str] = None
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
rpc_persist_rec_rec_biz_scene: Optional[str] = None
|
|
34
36
|
rpc_persist_coze_record_root_id: Optional[str] = None
|
|
35
37
|
rpc_persist_rec_root_entity_type: Optional[str] = None
|
|
36
38
|
rpc_persist_rec_root_entity_id: Optional[str] = None
|
|
39
|
+
rpc_persist_rec_rec_ext_info: Optional[str] = None
|
|
37
40
|
|
|
38
41
|
|
|
39
42
|
def new_context(method: str, headers: Optional[Mapping[str, str]] = None) -> Context:
|
|
@@ -44,23 +47,24 @@ def new_context(method: str, headers: Optional[Mapping[str, str]] = None) -> Con
|
|
|
44
47
|
project_id=os.getenv(ENV_PROJECT_ID, ""),
|
|
45
48
|
method=method,
|
|
46
49
|
)
|
|
50
|
+
# logid 与 method 保持一致,不读取头部覆盖
|
|
51
|
+
ctx.logid = method
|
|
47
52
|
if headers:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
ctx.rpc_persist_rec_root_entity_id = headers[HEADER_RPC_PERSIST_REC_ROOT_ENTITY_ID]
|
|
53
|
+
norm = {k.casefold(): v for k, v in headers.items()}
|
|
54
|
+
HEADERS_TO_ATTR = {
|
|
55
|
+
HEADER_X_TT_ENV: "x_tt_env",
|
|
56
|
+
HEADER_X_USE_PPE: "x_use_ppe",
|
|
57
|
+
HEADER_X_TT_ENV_FE: "x_tt_env_fe",
|
|
58
|
+
HEADER_RPC_PERSIST_REC_REC_BIZ_SCENE: "rpc_persist_rec_rec_biz_scene",
|
|
59
|
+
HEADER_RPC_PERSIST_COZE_RECORD_ROOT_ID: "rpc_persist_coze_record_root_id",
|
|
60
|
+
HEADER_RPC_PERSIST_REC_ROOT_ENTITY_TYPE: "rpc_persist_rec_root_entity_type",
|
|
61
|
+
HEADER_RPC_PERSIST_REC_ROOT_ENTITY_ID: "rpc_persist_rec_root_entity_id",
|
|
62
|
+
HEADER_RPC_PERSIST_REC_REC_EXT_INFO: "rpc_persist_rec_rec_ext_info",
|
|
63
|
+
}
|
|
64
|
+
for hk, attr in HEADERS_TO_ATTR.items():
|
|
65
|
+
val = norm.get(hk)
|
|
66
|
+
if val:
|
|
67
|
+
setattr(ctx, attr, val)
|
|
64
68
|
return ctx
|
|
65
69
|
|
|
66
70
|
|
|
@@ -69,22 +73,21 @@ def default_headers(ctx: Context | None) -> Dict[str, str]:
|
|
|
69
73
|
if not ctx:
|
|
70
74
|
return {}
|
|
71
75
|
headers: Dict[str, str] = {}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
headers[HEADER_RPC_PERSIST_REC_ROOT_ENTITY_ID] = ctx.rpc_persist_rec_root_entity_id
|
|
76
|
+
ATTR_TO_HEADER = {
|
|
77
|
+
"logid": HEADER_X_TT_LOGID,
|
|
78
|
+
"x_tt_env": HEADER_X_TT_ENV,
|
|
79
|
+
"x_use_ppe": HEADER_X_USE_PPE,
|
|
80
|
+
"x_tt_env_fe": HEADER_X_TT_ENV_FE,
|
|
81
|
+
"rpc_persist_rec_rec_biz_scene": HEADER_RPC_PERSIST_REC_REC_BIZ_SCENE,
|
|
82
|
+
"rpc_persist_coze_record_root_id": HEADER_RPC_PERSIST_COZE_RECORD_ROOT_ID,
|
|
83
|
+
"rpc_persist_rec_root_entity_type": HEADER_RPC_PERSIST_REC_ROOT_ENTITY_TYPE,
|
|
84
|
+
"rpc_persist_rec_root_entity_id": HEADER_RPC_PERSIST_REC_ROOT_ENTITY_ID,
|
|
85
|
+
"rpc_persist_rec_rec_ext_info": HEADER_RPC_PERSIST_REC_REC_EXT_INFO,
|
|
86
|
+
}
|
|
87
|
+
for attr, hk in ATTR_TO_HEADER.items():
|
|
88
|
+
v = getattr(ctx, attr)
|
|
89
|
+
if v:
|
|
90
|
+
headers[hk] = v
|
|
88
91
|
return headers
|
|
89
92
|
|
|
90
93
|
__all__ = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{coze_coding_utils-0.1.7 → coze_coding_utils-0.1.8}/src/coze_coding_utils/runtime_ctx/__init__.py
RENAMED
|
File without changes
|