Skip to content

Commit bb9f262

Browse files
CopilotSoulter
andcommitted
refactor: extract hardcoded original_umo key to constant
Co-authored-by: Soulter <[email protected]>
1 parent 3091b92 commit bb9f262

5 files changed

Lines changed: 18 additions & 6 deletions

File tree

astrbot/core/astr_main_agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,16 @@ def _get_compress_provider(
832832

833833
def _apply_global_context_info(event: AstrMessageEvent, req: ProviderRequest) -> None:
834834
"""Add platform and session information to user prompt when in global unified context mode."""
835-
from astrbot.core.config.default import GLOBAL_UNIFIED_CONTEXT_UMO
835+
from astrbot.core.config.default import (
836+
GLOBAL_UNIFIED_CONTEXT_UMO,
837+
ORIGINAL_UMO_KEY,
838+
)
836839

837840
if event.unified_msg_origin != GLOBAL_UNIFIED_CONTEXT_UMO:
838841
return
839842

840843
# Get original UMO from extras
841-
original_umo = event.get_extra("original_umo")
844+
original_umo = event.get_extra(ORIGINAL_UMO_KEY)
842845
if not original_umo:
843846
return
844847

astrbot/core/astr_main_agent_resources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ async def call(
258258
self, context: ContextWrapper[AstrAgentContext], **kwargs
259259
) -> ToolExecResult:
260260
# In global context mode, default to original UMO if session not specified
261-
original_umo = context.context.event.get_extra("original_umo")
261+
from astrbot.core.config.default import ORIGINAL_UMO_KEY
262+
263+
original_umo = context.context.event.get_extra(ORIGINAL_UMO_KEY)
262264
default_session = original_umo or context.context.event.unified_msg_origin
263265
session = kwargs.get("session") or default_session
264266
messages = kwargs.get("messages")

astrbot/core/config/default.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
# Constant UMO for global unified context mode
2121
GLOBAL_UNIFIED_CONTEXT_UMO = "global::global"
22+
# Key for storing original UMO in event extras when global context mode is enabled
23+
ORIGINAL_UMO_KEY = "original_umo"
2224

2325
# 默认配置
2426
DEFAULT_CONFIG = {

astrbot/core/pipeline/respond/stage.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ async def process(
170170
)
171171

172172
# Restore original UMO before sending if in global context mode
173-
original_umo = event.get_extra("original_umo")
173+
from astrbot.core.config.default import ORIGINAL_UMO_KEY
174+
175+
original_umo = event.get_extra(ORIGINAL_UMO_KEY)
174176
if original_umo:
175177
logger.debug(
176178
f"Restoring original UMO before sending: {event.unified_msg_origin} -> {original_umo}"

astrbot/core/pipeline/waking_check/stage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ async def process(
8282
) -> None | AsyncGenerator[None, None]:
8383
# apply global unified context mode
8484
if self.global_unified_context_mode:
85-
from astrbot.core.config.default import GLOBAL_UNIFIED_CONTEXT_UMO
85+
from astrbot.core.config.default import (
86+
GLOBAL_UNIFIED_CONTEXT_UMO,
87+
ORIGINAL_UMO_KEY,
88+
)
8689

8790
original_umo = event.unified_msg_origin
8891
event.unified_msg_origin = GLOBAL_UNIFIED_CONTEXT_UMO
8992
# Store original UMO for reference in later stages
90-
event.set_extra("original_umo", original_umo)
93+
event.set_extra(ORIGINAL_UMO_KEY, original_umo)
9194
logger.debug(
9295
f"Global unified context mode enabled. Changed UMO from {original_umo} to {GLOBAL_UNIFIED_CONTEXT_UMO}"
9396
)

0 commit comments

Comments
 (0)