agent-Specialization/server/context/__init__.py
JOJO aa9bf377a3 feat(runtime): Gateway 收尾——session 传输暴露、host Bearer 通道、flask 依赖拆解、审批链路收口
- session.* 传输暴露:新增 gateway_api 蓝图(list/create/history),RuntimeService 补 create_session
- host Bearer 通道:gateway_auth 双通道认证(host 模式+回环限定,token 存 DATA_DIR/host_api_token),tasks/approval 路由接入
- api_v1 会话路由转调公共入口消双轨,会话索引/列表补齐 run_mode/model_key/custom_prompt_name/personalization_name
- flask 包依赖拆解:_flask_bridge 延迟桥接 + context 子包 PEP 562 懒加载,import server.tasks/runtime 不再拉起 flask
- 审批链路:mark_expired 终态回写(超时/软停止/取消三路径)+ 终态 TTL 惰性清理(3600s)
- 测试 patch 点随迁;全量 75 测试失败恰为 4 项存量,独立启动验收 4/4 全绿

Co-authored-by: Astrion powered by Kimi-K3 <astrion-agent@users.noreply.github.com>
2026-09-08 11:37:51 +08:00

77 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# server/context/__init__.py - 兼容入口(原 server/context.py 拆分为子包)
# 所有历史导入路径 `from server.context import X` 不变。
#
# 2026-09-08G4 拆解):改为 PEP 562 模块级 __getattr__ 懒加载——
# 符号首次被引用时才加载对应子模块避免任务核心层server.tasks
# import 单个符号就连带拉起全部子模块(含 Web 适配层的 flask 依赖链)。
from importlib import import_module as _import_module
_SYMBOL_MODULE = {
# identity
"NoWorkspaceError": "server.context.identity",
"RuntimeIdentity": "server.context.identity",
"_resolve_user_role": "server.context.identity",
# broadcast
"make_terminal_callback": "server.context.broadcast",
"attach_user_broadcast": "server.context.broadcast",
"_wrap_callback_with_conversation_id": "server.context.broadcast",
# personalization
"_apply_workspace_personalization_preferences": "server.context.personalization",
# usage
"get_or_create_usage_tracker": "server.context.usage",
"emit_user_quota_update": "server.context.usage",
# upload
"get_gui_manager": "server.context.upload",
"get_upload_guard": "server.context.upload",
"build_upload_error_response": "server.context.upload",
# conversation
"ensure_conversation_loaded": "server.context.conversation",
"apply_conversation_overrides": "server.context.conversation",
# resources
"get_user_resources": "server.context.resources",
"_make_terminal_key": "server.context.resources",
"_touch_terminal_activity": "server.context.resources",
"_set_terminal_workspace_label": "server.context.resources",
"_ensure_workspace_skills_synced": "server.context.resources",
# decorators
"with_terminal": "server.context.decorators",
"get_terminal_for_sid": "server.context.decorators",
# reaper
"reset_system_state": "server.context.reaper",
"reap_idle_conversation_terminals": "server.context.reaper",
"start_conversation_terminal_reaper": "server.context.reaper",
}
__all__ = [
"NoWorkspaceError",
"RuntimeIdentity",
"get_user_resources",
"with_terminal",
"get_terminal_for_sid",
"get_gui_manager",
"get_upload_guard",
"build_upload_error_response",
"ensure_conversation_loaded",
"apply_conversation_overrides",
"reset_system_state",
"get_or_create_usage_tracker",
"emit_user_quota_update",
"make_terminal_callback",
"attach_user_broadcast",
"reap_idle_conversation_terminals",
"start_conversation_terminal_reaper",
]
def __getattr__(name):
module_name = _SYMBOL_MODULE.get(name)
if module_name is None:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
value = getattr(_import_module(module_name), name)
globals()[name] = value # 缓存,后续访问直接命中
return value
def __dir__():
return sorted(set(list(globals()) + list(_SYMBOL_MODULE)))