aidev-bkplugin 2.2.2rc52__tar.gz → 2.2.2rc58__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.
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/PKG-INFO +2 -2
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/approval_resume.py +42 -4
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/session.py +79 -15
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/pyproject.toml +2 -2
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_session_pv_files_views.py +112 -20
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_session_view.py +136 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/apps.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/constants.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/enums.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/management/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/management/commands/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/management/commands/upgrade_sessions.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/migrations/0001_initial.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/migrations/0002_event_delivery.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/migrations/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/models.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/openapi/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/openapi/urls.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/openapi/views.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/apigw/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/apigw/permissions.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/checkpoint/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/checkpoint/bk_django_saver.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/authentication.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/decorators.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/exception.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/renderers.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/permissions.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/private/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/private/permissions.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/private/urls.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/private/views.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/agent.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/chat_completion.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/llm.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/user_operation.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_bkplugin.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_builder.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_config.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_execution.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_helpers.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_session.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/chat_tracing.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/database_event_bus.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/event_resource_manager.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/event_tracing.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/execution.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/llm.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/metric_runtime.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/otel_metrics.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/user_operation.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/settings.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/tasks.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/urls.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/utils.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/agent.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/base.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/chat.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/chat_group.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/flow_agent.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/llm.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/user_operation.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/readme.md +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/apps.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/conftest.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/conftest.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/test_bus.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/test_resource_manager.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/test_tracing.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/drf/test_renderers_trace.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/test_bk_django_saver.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/test_bk_django_saver_async.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/private/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/private/test_private_views.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/conftest.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/test_agent_config_fetcher.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/test_builder.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/test_session_manager.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_agent_completion.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_agui_handler.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_approval_resume.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_approval_resume_tracing.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_bkplugin.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_execution.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_llm.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_otel_metrics.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_resume_consumer.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_thread_chat_completion.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_user_operation.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/settings.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/test_apps.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/test_constants.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/test_management_metrics.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/__init__.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_agent_view.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_agent_code_propagation.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_completion_serializer.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_flow_agent.py +0 -0
- {aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_stream_status.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: aidev-bkplugin
|
|
3
|
-
Version: 2.2.
|
|
3
|
+
Version: 2.2.2rc58
|
|
4
4
|
Summary: AiDev Agent Bkplugin builtin functions
|
|
5
5
|
Requires-Python: <3.12,>=3.11
|
|
6
|
-
Requires-Dist: aidev-agent>=2.2.
|
|
6
|
+
Requires-Dist: aidev-agent>=2.2.2rc58
|
|
7
7
|
Requires-Dist: blueapps<5.0,>=4.15.1
|
|
8
8
|
Requires-Dist: django<5.0,>=4.2.28
|
|
9
9
|
Provides-Extra: opentelemetry
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/approval_resume.py
RENAMED
|
@@ -60,8 +60,12 @@ def _approval_resume_worker(session_code: str, username: str, graph_thread_id: s
|
|
|
60
60
|
username,
|
|
61
61
|
)
|
|
62
62
|
|
|
63
|
-
#
|
|
64
|
-
|
|
63
|
+
# 0. 轮询 handler:ApprovalStateHandler 直连平台 API(U-01 重构后自持数据访问,
|
|
64
|
+
# 不再收 resource_manager),username 预留 X-BKAIDEV-USER header 位。
|
|
65
|
+
# 注意:agent 构造保持在轮询**之后**——chat_history 须在回调落地后加载,
|
|
66
|
+
# 否则 resume 的 terminal_interrupt_ids 判定用的是回调前的陈旧记录,
|
|
67
|
+
# 已批中断不被排除而被重推(UAT:重推未 enrich 的北京审批卡)。
|
|
68
|
+
handler = ApprovalStateHandler(username=username)
|
|
65
69
|
poll_count = 0
|
|
66
70
|
while True:
|
|
67
71
|
poll_count += 1
|
|
@@ -94,11 +98,38 @@ def _approval_resume_worker(session_code: str, username: str, graph_thread_id: s
|
|
|
94
98
|
propagated_trace_context(approve_info.get("approval_trace_context")),
|
|
95
99
|
recording_span("bkplugin.approval.resume", record_exception=False),
|
|
96
100
|
):
|
|
97
|
-
_resume_approval(session_code, username, graph_thread_id, interrupts,
|
|
101
|
+
_resume_approval(session_code, username, graph_thread_id, interrupts, approve_info)
|
|
98
102
|
|
|
99
103
|
|
|
100
|
-
def _resume_approval(
|
|
104
|
+
def _resume_approval(
|
|
105
|
+
session_code: str,
|
|
106
|
+
username: str,
|
|
107
|
+
graph_thread_id: str,
|
|
108
|
+
interrupts: list[dict],
|
|
109
|
+
approve_info: dict,
|
|
110
|
+
) -> None:
|
|
111
|
+
"""审批回调后构建 agent 并后台续流(须在回调 trace 上下文内调用)。
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
session_code: 会话码。
|
|
115
|
+
username: 会话主人(续流执行身份)。
|
|
116
|
+
graph_thread_id: 图线程 id。
|
|
117
|
+
interrupts: 触发续流的 pending interrupts(来自 pending_interrupt 上下文)。
|
|
118
|
+
approve_info: ``ApprovalStateHandler.fetch_approve_result`` 富返回,
|
|
119
|
+
含 ``approve_result`` 与本回调已终态审批的 ``interrupts``。
|
|
120
|
+
"""
|
|
121
|
+
approve_result = approve_info["approve_result"]
|
|
122
|
+
|
|
101
123
|
try:
|
|
124
|
+
# 串行语义:只 resume 本回调已终态的审批(approve_info.interrupts 元素 id
|
|
125
|
+
# 即该审批的 interrupt id)。其余 pending(工单未建/未回调)保持挂起——
|
|
126
|
+
# 全量 hydrate 会把未批的审批也标记 approved,串行门禁会拦下整个 resume,
|
|
127
|
+
# 图不拉起、下一张工单永远建不出来(UAT:第二次审批死锁)。
|
|
128
|
+
approved_ids = {
|
|
129
|
+
element.get("id")
|
|
130
|
+
for element in (approve_info.get("interrupts") or [])
|
|
131
|
+
if isinstance(element, dict) and element.get("id")
|
|
132
|
+
}
|
|
102
133
|
resume_items = []
|
|
103
134
|
for interrupt in interrupts:
|
|
104
135
|
if not isinstance(interrupt, dict):
|
|
@@ -106,6 +137,8 @@ def _resume_approval(session_code, username, graph_thread_id, interrupts, approv
|
|
|
106
137
|
interrupt_id = interrupt.get("id") or interrupt.get("interruptId")
|
|
107
138
|
if not interrupt_id:
|
|
108
139
|
continue
|
|
140
|
+
if approved_ids and interrupt_id not in approved_ids:
|
|
141
|
+
continue # 非本回调审批:保持挂起,等其自身工单终态
|
|
109
142
|
# status / payload.approved 由 hydrate_resume_payload 根据三态统一填充
|
|
110
143
|
resume_items.append({"interruptId": interrupt_id})
|
|
111
144
|
|
|
@@ -118,6 +151,8 @@ def _resume_approval(session_code, username, graph_thread_id, interrupts, approv
|
|
|
118
151
|
|
|
119
152
|
ApprovalStateHandler.hydrate_resume_payload(resume_items, approve_result)
|
|
120
153
|
|
|
154
|
+
# 回调后构建 agent:chat_history 加载到回调后的最新记录(含已批终态),
|
|
155
|
+
# resume 侧 terminal 判定 / enrich 复用才能拿到正确数据
|
|
121
156
|
builder = AgentBuilder(username=username)
|
|
122
157
|
agent_instance = builder.by_session_code(session_code)
|
|
123
158
|
|
|
@@ -127,6 +162,9 @@ def _resume_approval(session_code, username, graph_thread_id, interrupts, approv
|
|
|
127
162
|
thread_id=graph_thread_id,
|
|
128
163
|
resume=resume_items,
|
|
129
164
|
caller_trace_context=trace_headers(),
|
|
165
|
+
# 不传 executor:审批 approvers 来自工具审批配置(ItsmTicketCreator 读
|
|
166
|
+
# target.approval.approvers),与调用人无关——提单人(username)不可成为
|
|
167
|
+
# 审批身份(禁止自审批)。缺省时建单请求不带 X-BKAIDEV-USER 头。
|
|
130
168
|
# 后台 drain(无 SSE 下游,下方 for _ in generator 自行排空):标记 background_only,
|
|
131
169
|
# 使消费者读到 EOD 时不立即清理队列,保留缓存历史供前端在清理窗口内接管续流。
|
|
132
170
|
background_only=True,
|
|
@@ -5,18 +5,22 @@ from aidev_agent.services.messages_handler import GeneratorStreamingHelper
|
|
|
5
5
|
from aidev_agent.services.messages_handler.constants import TimeoutConfig
|
|
6
6
|
from aidev_agent.services.messages_handler.factory import message_handler_factory
|
|
7
7
|
from aidev_agent.services.sandbox_pv_files import (
|
|
8
|
+
IMAGE_DOWNLOAD_URL_EXPIRES_IN,
|
|
8
9
|
SandboxFileError,
|
|
9
10
|
SandboxFileInvalidArgumentError,
|
|
10
11
|
SandboxFileInvalidRequestError,
|
|
11
12
|
SandboxFileNotFoundError,
|
|
12
13
|
SandboxPvFileService,
|
|
14
|
+
fill_user_image_urls,
|
|
15
|
+
iter_user_images_missing_url,
|
|
16
|
+
validate_session_upload_files,
|
|
13
17
|
)
|
|
14
18
|
from bkapi_client_core.exceptions import HTTPResponseError
|
|
15
|
-
from blueapps.core.exceptions import ClientBlueException
|
|
19
|
+
from blueapps.core.exceptions import ClientBlueException, ResourceNotFound, ServerBlueException
|
|
16
20
|
from django.conf import settings
|
|
17
21
|
from django.http import HttpResponse
|
|
18
22
|
from rest_framework.decorators import action
|
|
19
|
-
from rest_framework.parsers import FileUploadParser
|
|
23
|
+
from rest_framework.parsers import FileUploadParser, MultiPartParser
|
|
20
24
|
from rest_framework.views import Response
|
|
21
25
|
|
|
22
26
|
from aidev_bkplugin.constants import AGUI_PROTOCOL_VERSION, DEFAULT_SESSION_PAGE, DEFAULT_SESSION_PAGE_SIZE
|
|
@@ -136,15 +140,13 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
136
140
|
# ------------------------------------------------------------------
|
|
137
141
|
|
|
138
142
|
@staticmethod
|
|
139
|
-
def
|
|
140
|
-
"""沙箱文件异常 →
|
|
143
|
+
def _raise_pv_exc(exc: SandboxFileError) -> None:
|
|
144
|
+
"""沙箱文件异常 → blueapps 异常,与 path is required 等入口同一套信封。"""
|
|
141
145
|
if isinstance(exc, SandboxFileNotFoundError):
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
status_code = 500
|
|
147
|
-
return Response(data={"message": str(exc)}, status=status_code)
|
|
146
|
+
raise ResourceNotFound(message=str(exc)) from exc
|
|
147
|
+
if isinstance(exc, (SandboxFileInvalidArgumentError, SandboxFileInvalidRequestError)):
|
|
148
|
+
raise ClientBlueException(message=str(exc)) from exc
|
|
149
|
+
raise ServerBlueException(message=str(exc)) from exc
|
|
148
150
|
|
|
149
151
|
def _check_session_owner(self, request, session_code: str, require_access: bool = False) -> None:
|
|
150
152
|
"""校验 session 归属
|
|
@@ -215,6 +217,21 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
215
217
|
|
|
216
218
|
return SandboxPvFileService(resource_manager=rm, executor_info=executor_info)
|
|
217
219
|
|
|
220
|
+
@staticmethod
|
|
221
|
+
def _resolve_upload_snapshot(rm) -> str:
|
|
222
|
+
"""走平台 image 表查询:取 file-kit 已构建成功的最新镜像。"""
|
|
223
|
+
try:
|
|
224
|
+
result = rm.get_client().api.retrieve_latest_skill_version_image()
|
|
225
|
+
except Exception:
|
|
226
|
+
logger.exception("[pv_files] resolve_upload_snapshot 调平台失败")
|
|
227
|
+
raise
|
|
228
|
+
data = result.get("data") if isinstance(result, dict) else None
|
|
229
|
+
image = data.get("image") if isinstance(data, dict) else ""
|
|
230
|
+
image = image.strip() if isinstance(image, str) else ""
|
|
231
|
+
if not image:
|
|
232
|
+
logger.warning("[pv_files] resolve_upload_snapshot empty")
|
|
233
|
+
return image
|
|
234
|
+
|
|
218
235
|
@action(["GET"], url_path="pv_files", detail=True)
|
|
219
236
|
def pv_files(self, request, pk, **kwargs):
|
|
220
237
|
self._check_session_owner(request, pk, require_access=False)
|
|
@@ -228,7 +245,7 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
228
245
|
until=None,
|
|
229
246
|
)
|
|
230
247
|
except SandboxFileError as exc:
|
|
231
|
-
|
|
248
|
+
self._raise_pv_exc(exc)
|
|
232
249
|
return Response(data=data)
|
|
233
250
|
|
|
234
251
|
@action(["GET"], url_path="pv_files/stat", detail=True)
|
|
@@ -240,7 +257,7 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
240
257
|
try:
|
|
241
258
|
data = self._make_pv_file_service(request).stat_file(session_code=pk, path=path)
|
|
242
259
|
except SandboxFileError as exc:
|
|
243
|
-
|
|
260
|
+
self._raise_pv_exc(exc)
|
|
244
261
|
return Response(data=data)
|
|
245
262
|
|
|
246
263
|
@action(["GET"], url_path="pv_files/preview", detail=True)
|
|
@@ -255,7 +272,7 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
255
272
|
session_code=pk, path=path, max_bytes=max_bytes
|
|
256
273
|
)
|
|
257
274
|
except SandboxFileError as exc:
|
|
258
|
-
|
|
275
|
+
self._raise_pv_exc(exc)
|
|
259
276
|
response = HttpResponse(content, content_type="text/plain; charset=utf-8")
|
|
260
277
|
response["X-Truncated"] = "true" if truncated else "false"
|
|
261
278
|
return response
|
|
@@ -272,14 +289,61 @@ class ChatSessionViewSet(PluginViewSet):
|
|
|
272
289
|
session_code=pk, path=path, expires_in=expires_in
|
|
273
290
|
)
|
|
274
291
|
except SandboxFileError as exc:
|
|
275
|
-
|
|
292
|
+
self._raise_pv_exc(exc)
|
|
293
|
+
return Response(data=data)
|
|
294
|
+
|
|
295
|
+
@action(
|
|
296
|
+
["POST"],
|
|
297
|
+
url_path="pv_files/upload",
|
|
298
|
+
detail=True,
|
|
299
|
+
parser_classes=[MultiPartParser],
|
|
300
|
+
)
|
|
301
|
+
def pv_files_upload(self, request, pk, **kwargs):
|
|
302
|
+
"""批量上传文件到会话 PV。"""
|
|
303
|
+
self._check_session_owner(request, pk, require_access=True)
|
|
304
|
+
uploaded_files = request.FILES.getlist("files")
|
|
305
|
+
files = [
|
|
306
|
+
{
|
|
307
|
+
"name": upload_file.name,
|
|
308
|
+
"content": upload_file.read(),
|
|
309
|
+
"mime_type": upload_file.content_type or "application/octet-stream",
|
|
310
|
+
}
|
|
311
|
+
for upload_file in uploaded_files
|
|
312
|
+
]
|
|
313
|
+
try:
|
|
314
|
+
validate_session_upload_files(files)
|
|
315
|
+
except SandboxFileError as exc:
|
|
316
|
+
self._raise_pv_exc(exc)
|
|
317
|
+
|
|
318
|
+
svc = self._make_pv_file_service(request)
|
|
319
|
+
snapshot = self._resolve_upload_snapshot(PluginResourceManager(username=request.user.username))
|
|
320
|
+
if snapshot:
|
|
321
|
+
svc._executor_info["snapshot"] = snapshot
|
|
322
|
+
try:
|
|
323
|
+
data = svc.upload_files(session_code=pk, files=files)
|
|
324
|
+
except SandboxFileError as exc:
|
|
325
|
+
self._raise_pv_exc(exc)
|
|
276
326
|
return Response(data=data)
|
|
277
327
|
|
|
278
328
|
|
|
329
|
+
def _copy_session_content_payload(data):
|
|
330
|
+
"""复制写消息 payload,避免改写原始 request.data。"""
|
|
331
|
+
if not isinstance(data, dict):
|
|
332
|
+
return data
|
|
333
|
+
payload = dict(data)
|
|
334
|
+
content = payload.get("content")
|
|
335
|
+
if isinstance(content, list):
|
|
336
|
+
payload["content"] = [dict(item) if isinstance(item, dict) else item for item in content]
|
|
337
|
+
return payload
|
|
338
|
+
|
|
339
|
+
|
|
279
340
|
class ChatSessionContentViewSet(PluginViewSet):
|
|
280
341
|
def create(self, request):
|
|
281
342
|
username = request.user.username
|
|
282
|
-
|
|
343
|
+
payload = _copy_session_content_payload(request.data)
|
|
344
|
+
if isinstance(payload, dict) and any(iter_user_images_missing_url(payload)):
|
|
345
|
+
fill_user_image_urls(ChatSessionViewSet._make_pv_file_service(self, request), payload)
|
|
346
|
+
result = self.client.api.create_chat_session_content(json=payload, headers={"X-BKAIDEV-USER": username})
|
|
283
347
|
return Response(data=result["data"])
|
|
284
348
|
|
|
285
349
|
@action(["GET"], url_path="content", detail=False)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "aidev-bkplugin"
|
|
3
|
-
version = "2.2.
|
|
3
|
+
version = "2.2.2rc58"
|
|
4
4
|
description = "AiDev Agent Bkplugin builtin functions"
|
|
5
5
|
readme = "readme.md"
|
|
6
6
|
requires-python = "<3.12,>=3.11"
|
|
7
7
|
dependencies = [
|
|
8
|
-
"aidev-agent>=2.2.
|
|
8
|
+
"aidev-agent>=2.2.2rc58",
|
|
9
9
|
"blueapps>=4.15.1, <5.0",
|
|
10
10
|
"django>=4.2.28,<5.0",
|
|
11
11
|
]
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_session_pv_files_views.py
RENAMED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
覆盖点:
|
|
5
5
|
- 构造沙箱文件 Service 时正确注入 PluginResourceManager + executor_info
|
|
6
|
-
- 5 个 action 参数透传(GET list /
|
|
7
|
-
-
|
|
6
|
+
- 5 个 action 参数透传(GET list / stat / preview / download_url / upload)
|
|
7
|
+
- 上传会话归属校验与沙箱文件异常映射
|
|
8
|
+
- 沙箱文件异常 → blueapps 异常映射(404 / 400 / 500)
|
|
8
9
|
- preview 返回 HttpResponse(text/plain) + X-Truncated 头透传
|
|
9
10
|
- path/max_bytes/expires_in 缺失或默认值回退
|
|
10
11
|
"""
|
|
@@ -16,6 +17,7 @@ from unittest.mock import MagicMock, patch
|
|
|
16
17
|
|
|
17
18
|
import pytest
|
|
18
19
|
from django.conf import settings
|
|
20
|
+
from django.core.files.uploadedfile import SimpleUploadedFile
|
|
19
21
|
from django.http import HttpResponse
|
|
20
22
|
|
|
21
23
|
if not settings.configured:
|
|
@@ -62,7 +64,15 @@ from aidev_agent.services.sandbox_pv_files import ( # noqa: E402
|
|
|
62
64
|
from aidev_bkplugin.views import session as session_mod # noqa: E402
|
|
63
65
|
|
|
64
66
|
|
|
65
|
-
def _request(
|
|
67
|
+
def _request(
|
|
68
|
+
query_params=None,
|
|
69
|
+
username="alice",
|
|
70
|
+
method="GET",
|
|
71
|
+
cookies=None,
|
|
72
|
+
meta=None,
|
|
73
|
+
path="/pv-files",
|
|
74
|
+
files=None,
|
|
75
|
+
):
|
|
66
76
|
return SimpleNamespace(
|
|
67
77
|
query_params=query_params or {},
|
|
68
78
|
user=SimpleNamespace(username=username),
|
|
@@ -70,6 +80,7 @@ def _request(query_params=None, username="alice", method="GET", cookies=None, me
|
|
|
70
80
|
COOKIES=cookies or {},
|
|
71
81
|
META=meta or {},
|
|
72
82
|
path=path,
|
|
83
|
+
FILES=SimpleNamespace(getlist=lambda field_name: files or [] if field_name == "files" else []),
|
|
73
84
|
)
|
|
74
85
|
|
|
75
86
|
|
|
@@ -86,6 +97,7 @@ def mock_svc():
|
|
|
86
97
|
"""打桩沙箱文件 Service 实例;测试点:view 层是否正确构造 + 参数透传。"""
|
|
87
98
|
with patch.object(session_mod, "SandboxPvFileService") as svc_cls:
|
|
88
99
|
instance = MagicMock()
|
|
100
|
+
instance._executor_info = {}
|
|
89
101
|
svc_cls.return_value = instance
|
|
90
102
|
yield instance, svc_cls
|
|
91
103
|
|
|
@@ -97,6 +109,9 @@ def _reset_retrieve_chat_session_mock():
|
|
|
97
109
|
side_effect 泄露到后续 TestPvFiles* 用例(那些用例默认应"归属校验通过")。
|
|
98
110
|
"""
|
|
99
111
|
fake_client.api.retrieve_chat_session.reset_mock(side_effect=True, return_value=True)
|
|
112
|
+
session_mod.PluginResourceManager.return_value.resolve_access_token.return_value = None
|
|
113
|
+
latest_image = session_mod.PluginResourceManager.return_value.get_client.return_value.api.retrieve_latest_skill_version_image
|
|
114
|
+
latest_image.reset_mock()
|
|
100
115
|
yield
|
|
101
116
|
|
|
102
117
|
|
|
@@ -160,6 +175,22 @@ class TestMakePvFileService:
|
|
|
160
175
|
assert call_kwargs["executor_info"]["bk_ticket_key"] == "bk_token"
|
|
161
176
|
assert call_kwargs["executor_info"]["bk_ticket_value"] == "open-token-123"
|
|
162
177
|
|
|
178
|
+
def test_upload_injects_file_kit_snapshot(self, view, mock_svc):
|
|
179
|
+
"""上传时走平台 latest image 接口,把 file-kit 镜像写入 snapshot。"""
|
|
180
|
+
instance, svc_cls = mock_svc
|
|
181
|
+
rm = session_mod.PluginResourceManager.return_value
|
|
182
|
+
rm.get_client.return_value.api.retrieve_latest_skill_version_image.return_value = {
|
|
183
|
+
"data": {"image": "mirrors.tencent.com/bkpaas-sandbox/bkaidev/file-kit:0.0.9"}
|
|
184
|
+
}
|
|
185
|
+
uploaded_file = SimpleUploadedFile("report.txt", b"report", content_type="text/plain")
|
|
186
|
+
|
|
187
|
+
view.pv_files_upload(_request(method="POST", files=[uploaded_file]), pk="s1")
|
|
188
|
+
|
|
189
|
+
assert "snapshot" not in svc_cls.call_args.kwargs["executor_info"]
|
|
190
|
+
assert instance._executor_info["snapshot"] == (
|
|
191
|
+
"mirrors.tencent.com/bkpaas-sandbox/bkaidev/file-kit:0.0.9"
|
|
192
|
+
)
|
|
193
|
+
rm.get_client.return_value.api.retrieve_latest_skill_version_image.assert_called_once_with()
|
|
163
194
|
|
|
164
195
|
# ---------------------------------------------------------------------------
|
|
165
196
|
# pv_files (GET / DELETE)
|
|
@@ -175,10 +206,13 @@ class TestPvFilesGet:
|
|
|
175
206
|
instance.list_files.assert_called_once_with(session_code="s1", path="sub/", since=None, until=None)
|
|
176
207
|
|
|
177
208
|
def test_list_translates_not_found(self, view, mock_svc):
|
|
209
|
+
from blueapps.core.exceptions import ResourceNotFound
|
|
210
|
+
|
|
178
211
|
instance, _ = mock_svc
|
|
179
212
|
instance.list_files.side_effect = SandboxFileNotFoundError("nf")
|
|
180
|
-
|
|
181
|
-
|
|
213
|
+
with pytest.raises(ResourceNotFound) as excinfo:
|
|
214
|
+
view.pv_files(_request(), pk="s1")
|
|
215
|
+
assert excinfo.value.STATUS_CODE == 404
|
|
182
216
|
|
|
183
217
|
|
|
184
218
|
# ---------------------------------------------------------------------------
|
|
@@ -268,10 +302,13 @@ class TestPvFilesStat:
|
|
|
268
302
|
view.pv_files_stat(_request({}), pk="s1")
|
|
269
303
|
|
|
270
304
|
def test_stat_translates_invalid_arg(self, view, mock_svc):
|
|
305
|
+
from blueapps.core.exceptions import ClientBlueException
|
|
306
|
+
|
|
271
307
|
instance, _ = mock_svc
|
|
272
308
|
instance.stat_file.side_effect = SandboxFileInvalidArgumentError("ia")
|
|
273
|
-
|
|
274
|
-
|
|
309
|
+
with pytest.raises(ClientBlueException) as excinfo:
|
|
310
|
+
view.pv_files_stat(_request({"path": "x.txt"}), pk="s1")
|
|
311
|
+
assert excinfo.value.STATUS_CODE == 400
|
|
275
312
|
|
|
276
313
|
|
|
277
314
|
# ---------------------------------------------------------------------------
|
|
@@ -309,10 +346,13 @@ class TestPvFilesPreview:
|
|
|
309
346
|
assert instance.preview_file.call_args.kwargs["max_bytes"] == 65536
|
|
310
347
|
|
|
311
348
|
def test_preview_translates_415(self, view, mock_svc):
|
|
349
|
+
from blueapps.core.exceptions import ClientBlueException
|
|
350
|
+
|
|
312
351
|
instance, _ = mock_svc
|
|
313
352
|
instance.preview_file.side_effect = SandboxFileInvalidRequestError("415")
|
|
314
|
-
|
|
315
|
-
|
|
353
|
+
with pytest.raises(ClientBlueException) as excinfo:
|
|
354
|
+
view.pv_files_preview(_request({"path": "x.bin"}), pk="s1")
|
|
355
|
+
assert excinfo.value.STATUS_CODE == 400
|
|
316
356
|
|
|
317
357
|
def test_preview_requires_path(self, view, mock_svc):
|
|
318
358
|
from blueapps.core.exceptions import ClientBlueException
|
|
@@ -341,10 +381,13 @@ class TestPvFilesDownloadUrl:
|
|
|
341
381
|
assert instance.get_download_url.call_args.kwargs["expires_in"] == 600
|
|
342
382
|
|
|
343
383
|
def test_download_url_translates_server_error(self, view, mock_svc):
|
|
384
|
+
from blueapps.core.exceptions import ServerBlueException
|
|
385
|
+
|
|
344
386
|
instance, _ = mock_svc
|
|
345
387
|
instance.get_download_url.side_effect = SandboxFileServerError("boom")
|
|
346
|
-
|
|
347
|
-
|
|
388
|
+
with pytest.raises(ServerBlueException) as excinfo:
|
|
389
|
+
view.pv_files_download_url(_request({"path": "x.txt"}), pk="s1")
|
|
390
|
+
assert excinfo.value.STATUS_CODE == 500
|
|
348
391
|
|
|
349
392
|
def test_download_url_requires_path(self, view, mock_svc):
|
|
350
393
|
from blueapps.core.exceptions import ClientBlueException
|
|
@@ -353,24 +396,73 @@ class TestPvFilesDownloadUrl:
|
|
|
353
396
|
view.pv_files_download_url(_request({}), pk="s1")
|
|
354
397
|
|
|
355
398
|
|
|
399
|
+
class TestPvFilesUpload:
|
|
400
|
+
def test_upload_forwards_files_to_local_service(self, view, mock_svc):
|
|
401
|
+
instance, _ = mock_svc
|
|
402
|
+
upload_result = {
|
|
403
|
+
"count": 1,
|
|
404
|
+
"succeeded": 1,
|
|
405
|
+
"failed": 0,
|
|
406
|
+
"results": [{"path": "files/report.txt", "status": "success"}],
|
|
407
|
+
}
|
|
408
|
+
instance.upload_files.return_value = upload_result
|
|
409
|
+
uploaded_file = SimpleUploadedFile("report.txt", b"report", content_type="text/plain")
|
|
410
|
+
|
|
411
|
+
response = view.pv_files_upload(_request(method="POST", files=[uploaded_file]), pk="s1")
|
|
412
|
+
|
|
413
|
+
assert response.data == upload_result
|
|
414
|
+
instance.upload_files.assert_called_once_with(
|
|
415
|
+
session_code="s1",
|
|
416
|
+
files=[{"name": "report.txt", "content": b"report", "mime_type": "text/plain"}],
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
def test_upload_rejects_invalid_files_before_resolving_snapshot(self, view, mock_svc):
|
|
420
|
+
from blueapps.core.exceptions import ClientBlueException
|
|
421
|
+
|
|
422
|
+
instance, _ = mock_svc
|
|
423
|
+
|
|
424
|
+
with pytest.raises(ClientBlueException) as excinfo:
|
|
425
|
+
view.pv_files_upload(
|
|
426
|
+
_request(method="POST", files=[SimpleUploadedFile("payload.exe", b"binary")]),
|
|
427
|
+
pk="s1",
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
assert excinfo.value.message == "文件类型 .exe 不支持"
|
|
431
|
+
assert excinfo.value.STATUS_CODE == 400
|
|
432
|
+
instance.upload_files.assert_not_called()
|
|
433
|
+
session_mod.PluginResourceManager.return_value.get_client.return_value.api.retrieve_latest_skill_version_image.assert_not_called()
|
|
434
|
+
|
|
435
|
+
|
|
356
436
|
# ---------------------------------------------------------------------------
|
|
357
|
-
# 异常映射:SandboxFileError 基类兜底为
|
|
437
|
+
# 异常映射:SandboxFileError 基类兜底为 ServerBlueException
|
|
358
438
|
# ---------------------------------------------------------------------------
|
|
359
439
|
|
|
360
440
|
|
|
361
441
|
class TestExceptionMapping:
|
|
362
442
|
def test_base_error_fallback_to_500(self):
|
|
363
|
-
|
|
364
|
-
|
|
443
|
+
from blueapps.core.exceptions import ServerBlueException
|
|
444
|
+
|
|
445
|
+
with pytest.raises(ServerBlueException) as excinfo:
|
|
446
|
+
session_mod.ChatSessionViewSet._raise_pv_exc(SandboxFileError("unknown"))
|
|
447
|
+
assert excinfo.value.STATUS_CODE == 500
|
|
365
448
|
|
|
366
449
|
def test_not_found_error_maps_to_404(self):
|
|
367
|
-
|
|
368
|
-
|
|
450
|
+
from blueapps.core.exceptions import ResourceNotFound
|
|
451
|
+
|
|
452
|
+
with pytest.raises(ResourceNotFound) as excinfo:
|
|
453
|
+
session_mod.ChatSessionViewSet._raise_pv_exc(SandboxFileNotFoundError("nf"))
|
|
454
|
+
assert excinfo.value.STATUS_CODE == 404
|
|
369
455
|
|
|
370
456
|
def test_invalid_argument_maps_to_400(self):
|
|
371
|
-
|
|
372
|
-
|
|
457
|
+
from blueapps.core.exceptions import ClientBlueException
|
|
458
|
+
|
|
459
|
+
with pytest.raises(ClientBlueException) as excinfo:
|
|
460
|
+
session_mod.ChatSessionViewSet._raise_pv_exc(SandboxFileInvalidArgumentError("ia"))
|
|
461
|
+
assert excinfo.value.STATUS_CODE == 400
|
|
373
462
|
|
|
374
463
|
def test_invalid_request_maps_to_400(self):
|
|
375
|
-
|
|
376
|
-
|
|
464
|
+
from blueapps.core.exceptions import ClientBlueException
|
|
465
|
+
|
|
466
|
+
with pytest.raises(ClientBlueException) as excinfo:
|
|
467
|
+
session_mod.ChatSessionViewSet._raise_pv_exc(SandboxFileInvalidRequestError("ir"))
|
|
468
|
+
assert excinfo.value.STATUS_CODE == 400
|
|
@@ -200,6 +200,142 @@ def test_stop_clears_stale_notification_before_sending_cancel(monkeypatch, run_i
|
|
|
200
200
|
handler.mark_stopped.assert_not_called()
|
|
201
201
|
|
|
202
202
|
|
|
203
|
+
def test_create_attaches_image_url_to_user_binary(monkeypatch):
|
|
204
|
+
api = MagicMock()
|
|
205
|
+
api.create_chat_session_content.return_value = {
|
|
206
|
+
"data": {
|
|
207
|
+
"id": 34739,
|
|
208
|
+
"role": "user",
|
|
209
|
+
"session_code": "s1",
|
|
210
|
+
"content": [
|
|
211
|
+
{
|
|
212
|
+
"filename": "角色.png",
|
|
213
|
+
"id": "files/角色.png",
|
|
214
|
+
"mime_type": "image/png",
|
|
215
|
+
"type": "binary",
|
|
216
|
+
"url": "https://cdn/role.png",
|
|
217
|
+
},
|
|
218
|
+
{"type": "text", "text": "这个图片内容是啥?"},
|
|
219
|
+
],
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
file_service = MagicMock()
|
|
223
|
+
file_service.get_download_url.return_value = {"download_url": "https://cdn/role.png"}
|
|
224
|
+
monkeypatch.setattr(
|
|
225
|
+
session_mod.ChatSessionViewSet,
|
|
226
|
+
"_make_pv_file_service",
|
|
227
|
+
lambda self, request, **kwargs: file_service,
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
payload = {
|
|
231
|
+
"role": "user",
|
|
232
|
+
"session_code": "s1",
|
|
233
|
+
"content": [
|
|
234
|
+
{"filename": "角色.png", "id": "files/角色.png", "mime_type": "image/png", "type": "binary"},
|
|
235
|
+
{"type": "text", "text": "这个图片内容是啥?"},
|
|
236
|
+
],
|
|
237
|
+
}
|
|
238
|
+
response = _view(session_mod.ChatSessionContentViewSet, api).create(_request(data=payload))
|
|
239
|
+
|
|
240
|
+
sent = api.create_chat_session_content.call_args.kwargs["json"]
|
|
241
|
+
assert sent["content"][0]["url"] == "https://cdn/role.png"
|
|
242
|
+
assert "url" not in sent["content"][1]
|
|
243
|
+
file_service.get_download_url.assert_called_once_with(
|
|
244
|
+
session_code="s1",
|
|
245
|
+
path="files/角色.png",
|
|
246
|
+
expires_in=session_mod.IMAGE_DOWNLOAD_URL_EXPIRES_IN,
|
|
247
|
+
)
|
|
248
|
+
assert response.data["content"][0]["url"] == "https://cdn/role.png"
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def test_create_skips_signing_for_text_only_message(monkeypatch):
|
|
252
|
+
api = MagicMock()
|
|
253
|
+
api.create_chat_session_content.return_value = {"data": {"id": 1, "content": "你好"}}
|
|
254
|
+
make_service = MagicMock()
|
|
255
|
+
monkeypatch.setattr(session_mod.ChatSessionViewSet, "_make_pv_file_service", make_service)
|
|
256
|
+
|
|
257
|
+
_view(session_mod.ChatSessionContentViewSet, api).create(
|
|
258
|
+
_request(data={"role": "user", "session_code": "s1", "content": "你好"})
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
make_service.assert_not_called()
|
|
262
|
+
api.create_chat_session_content.assert_called_once()
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def test_create_still_writes_when_image_url_sign_fails(monkeypatch):
|
|
266
|
+
api = MagicMock()
|
|
267
|
+
api.create_chat_session_content.return_value = {"data": {"id": 1}}
|
|
268
|
+
file_service = MagicMock()
|
|
269
|
+
file_service.get_download_url.side_effect = session_mod.SandboxFileError("boom")
|
|
270
|
+
monkeypatch.setattr(
|
|
271
|
+
session_mod.ChatSessionViewSet,
|
|
272
|
+
"_make_pv_file_service",
|
|
273
|
+
lambda self, request, **kwargs: file_service,
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
payload = {
|
|
277
|
+
"role": "user",
|
|
278
|
+
"session_code": "s1",
|
|
279
|
+
"content": [{"type": "binary", "id": "files/角色.png", "mime_type": "image/png"}],
|
|
280
|
+
}
|
|
281
|
+
_view(session_mod.ChatSessionContentViewSet, api).create(_request(data=payload))
|
|
282
|
+
|
|
283
|
+
sent = api.create_chat_session_content.call_args.kwargs["json"]
|
|
284
|
+
assert "url" not in sent["content"][0]
|
|
285
|
+
api.create_chat_session_content.assert_called_once()
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def test_create_keeps_existing_image_url(monkeypatch):
|
|
289
|
+
api = MagicMock()
|
|
290
|
+
api.create_chat_session_content.return_value = {"data": {"id": 1}}
|
|
291
|
+
file_service = MagicMock()
|
|
292
|
+
monkeypatch.setattr(
|
|
293
|
+
session_mod.ChatSessionViewSet,
|
|
294
|
+
"_make_pv_file_service",
|
|
295
|
+
lambda self, request, **kwargs: file_service,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
payload = {
|
|
299
|
+
"role": "user",
|
|
300
|
+
"session_code": "s1",
|
|
301
|
+
"content": [
|
|
302
|
+
{
|
|
303
|
+
"type": "binary",
|
|
304
|
+
"id": "files/角色.png",
|
|
305
|
+
"mime_type": "image/png",
|
|
306
|
+
"url": "https://already/there",
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
}
|
|
310
|
+
_view(session_mod.ChatSessionContentViewSet, api).create(_request(data=payload))
|
|
311
|
+
|
|
312
|
+
sent = api.create_chat_session_content.call_args.kwargs["json"]
|
|
313
|
+
assert sent["content"][0]["url"] == "https://already/there"
|
|
314
|
+
file_service.get_download_url.assert_not_called()
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def test_create_ignores_preview_url_when_download_url_missing(monkeypatch):
|
|
318
|
+
api = MagicMock()
|
|
319
|
+
api.create_chat_session_content.return_value = {"data": {"id": 1}}
|
|
320
|
+
file_service = MagicMock()
|
|
321
|
+
file_service.get_download_url.return_value = {"preview_url": "https://preview/html"}
|
|
322
|
+
monkeypatch.setattr(
|
|
323
|
+
session_mod.ChatSessionViewSet,
|
|
324
|
+
"_make_pv_file_service",
|
|
325
|
+
lambda self, request, **kwargs: file_service,
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
payload = {
|
|
329
|
+
"role": "user",
|
|
330
|
+
"session_code": "s1",
|
|
331
|
+
"content": [{"type": "binary", "id": "files/角色.png", "mime_type": "image/png"}],
|
|
332
|
+
}
|
|
333
|
+
_view(session_mod.ChatSessionContentViewSet, api).create(_request(data=payload))
|
|
334
|
+
|
|
335
|
+
sent = api.create_chat_session_content.call_args.kwargs["json"]
|
|
336
|
+
assert "url" not in sent["content"][0]
|
|
337
|
+
|
|
338
|
+
|
|
203
339
|
def test_stop_omits_producer_state_when_detection_fails(monkeypatch):
|
|
204
340
|
"""broker 查询异常时保持旧协议,避免平台误判为无 producer。"""
|
|
205
341
|
handler = MagicMock()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/management/commands/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/apigw/__init__.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/apigw/permissions.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/checkpoint/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/__init__.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/authentication.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/decorators.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/exception.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/packages/drf/renderers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/chat_completion.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/serializers/user_operation.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_bkplugin.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_builder.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_config.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_execution.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_helpers.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/agent_session.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/chat_tracing.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/database_event_bus.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/event_tracing.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/metric_runtime.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/otel_metrics.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/services/user_operation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/aidev_bkplugin/views/user_operation.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/database_events/test_resource_manager.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/drf/test_renderers_trace.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/test_bk_django_saver.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/packages/test_bk_django_saver_async.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/agent/test_session_manager.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_agent_completion.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_approval_resume.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_approval_resume_tracing.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_resume_consumer.py
RENAMED
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/services/test_thread_chat_completion.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_completion_serializer.py
RENAMED
|
File without changes
|
|
File without changes
|
{aidev_bkplugin-2.2.2rc52 → aidev_bkplugin-2.2.2rc58}/tests/views/test_chat_stream_status.py
RENAMED
|
File without changes
|