Merge branch 'dev' into hugo-shipping-notice

# Conflicts:
#	.env.dev
#	.env.test
#	backend/app/api/__init__.py
#	docs/funclist.md
#	frontend/src/features/chat/composables/useChatPage.ts
This commit is contained in:
hugo committed 2026-07-06 08:35:40 +08:00
commit f72c1c9f0e
101 files changed
+11163 -334

No files matched your search

+127 -2
View File
@@ -22,6 +22,7 @@ from sqlalchemy import func, desc, or_, exists, and_
from openpyxl import load_workbook
from app.services.agent_runtime_context.dify_inputs import build_chat_dify_inputs
from app.services.dify import DifyService
from app.core.config.settings import Config
from app.services.integration_api import IntegrationApiService
from app.core.decorators import require_agent_permission
from app.models import Agent, ChatLog, ChatSession, Feedback
@@ -237,8 +238,18 @@ def _normalize_windows_share_path(path_value: str) -> str:
def _is_allowed_share_path(target_url: str) -> bool:
normalized_target = _normalize_windows_share_path(target_url)
normalized_root = _normalize_windows_share_path(PLM_PREVIEW_SHARE_ROOT)
return bool(normalized_root and normalized_target.startswith('\\\\') and normalized_target.lower().startswith(normalized_root.lower()))
if not normalized_target.startswith('\\\\'):
return False
history_share_root = ''
if has_request_context():
history_share_root = str(current_app.config.get('FIXED_ASSET_HISTORY_SHARE_ROOT') or '').strip()
if not history_share_root:
history_share_root = str(Config.FIXED_ASSET_HISTORY_SHARE_ROOT or '').strip()
roots = [
_normalize_windows_share_path(PLM_PREVIEW_SHARE_ROOT),
_normalize_windows_share_path(history_share_root),
]
return any(root and normalized_target.lower().startswith(root.lower()) for root in roots)
def _is_allowed_preview_url(target_url: str) -> bool:
"""
@@ -1135,6 +1146,111 @@ def get_chat_query_preview(chat_log_id: int):
'query': query,
})
@chat_bp.route('/asset-history/search', methods=['GET'])
@require_agent_permission
def search_asset_history_files():
"""
检索固定资产履历文件。
用途:聊天结果表格点击“资产编号”时,返回共享盘中的候选履历文件列表。
约束:至少提供资产编号或资产名称之一;不直接返回文件内容,只返回预览所需路径元数据。
"""
asset_id = (request.args.get('asset_id') or '').strip()
asset_name = (request.args.get('asset_name') or '').strip()
limit = request.args.get('limit', type=int) or 20
limit = max(1, min(limit, 50))
# #region debug-point C:asset-history-api-entry
import json as _debug_json
import urllib.request as _debug_urllib_request
try:
_debug_payload = _debug_json.dumps({
'sessionId': 'asset-history-click',
'runId': 'pre-fix',
'hypothesisId': 'C',
'location': 'backend/chat.py:search_asset_history_files',
'msg': '[DEBUG] asset history api entry',
'data': {
'asset_id': asset_id,
'asset_name': asset_name,
'limit': limit,
},
}).encode('utf-8')
_debug_urllib_request.urlopen(_debug_urllib_request.Request(
'http://127.0.0.1:7777/event',
data=_debug_payload,
headers={'Content-Type': 'application/json'},
method='POST',
), timeout=2).read()
except Exception:
pass
# #endregion
if not asset_id and not asset_name:
raise ValidationError('asset_id or asset_name is required')
from app.services.fixed_asset_history import FixedAssetHistoryService
if not FixedAssetHistoryService.is_enabled():
# #region debug-point C:asset-history-api-disabled
try:
_debug_payload = _debug_json.dumps({
'sessionId': 'asset-history-click',
'runId': 'pre-fix',
'hypothesisId': 'C',
'location': 'backend/chat.py:search_asset_history_files',
'msg': '[DEBUG] asset history api disabled',
'data': {
'share_root': str(Config.FIXED_ASSET_HISTORY_SHARE_ROOT or ''),
},
}).encode('utf-8')
_debug_urllib_request.urlopen(_debug_urllib_request.Request(
'http://127.0.0.1:7777/event',
data=_debug_payload,
headers={'Content-Type': 'application/json'},
method='POST',
), timeout=2).read()
except Exception:
pass
# #endregion
raise ServiceUnavailableError('asset history share is not configured')
items = FixedAssetHistoryService.search_history_files(
asset_id=asset_id,
asset_name=asset_name,
limit=limit,
)
# #region debug-point C:asset-history-api-success
try:
_debug_payload = _debug_json.dumps({
'sessionId': 'asset-history-click',
'runId': 'pre-fix',
'hypothesisId': 'C',
'location': 'backend/chat.py:search_asset_history_files',
'msg': '[DEBUG] asset history api success',
'data': {
'asset_id': asset_id,
'asset_name': asset_name,
'item_count': len(items),
},
}).encode('utf-8')
_debug_urllib_request.urlopen(_debug_urllib_request.Request(
'http://127.0.0.1:7777/event',
data=_debug_payload,
headers={'Content-Type': 'application/json'},
method='POST',
), timeout=2).read()
except Exception:
pass
# #endregion
return jsonify({
'asset_id': asset_id,
'asset_name': asset_name,
'total': len(items),
'items': items,
})
@chat_bp.route('/completions', methods=['POST'])
@require_agent_permission
def chat_completions():
@@ -1260,6 +1376,7 @@ def chat_completions():
leave_feature_enabled = _can_use_leave_feature(agent_proxy)
from app.services.faq_cache import FaqCacheService
from app.services.maintenance_chat_service import MaintenanceChatService
faq_hit = FaqCacheService.try_match(query, agent_id) if not normalized_files else None
if faq_hit:
@@ -1271,6 +1388,14 @@ def chat_completions():
external_conversation_id,
session_id=session.session_id,
)
elif not normalized_files and MaintenanceChatService.supports(query, agent_proxy):
generator = MaintenanceChatService.stream_chat(
query,
user_proxy,
agent_proxy,
external_conversation_id,
session_id=session.session_id,
)
elif PLMOracleService.supports(query, agent_proxy):
generator = PLMOracleService.stream_chat(query, user_proxy, agent_proxy, external_conversation_id, session_id=session.session_id)
elif leave_supported and leave_feature_enabled: