Merge branch 'dev' into order-delivery-reply
# Conflicts: # .env.shared # backend/app/api/chat.py # backend/app/core/config/settings.py # backend/app/models/user.py # backend/app/services/admin/permission_service.py # docs/demand.md # frontend/src/app/router/routes/workspace.routes.ts # frontend/src/features/admin/modules/users/components/UserFormModal.vue # frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts # frontend/src/features/admin/types/user.types.ts # frontend/src/features/auth/stores/auth.store.ts # frontend/src/features/user/views/UserProfilePage.vue # frontend/src/locales/en/admin.json # frontend/src/locales/en/errors.json # frontend/src/locales/th/admin.json # frontend/src/locales/th/errors.json # frontend/src/locales/zh-CN/admin.json # frontend/src/locales/zh-CN/errors.json # frontend/src/locales/zh-TW/admin.json # frontend/src/locales/zh-TW/errors.json # frontend/src/shared/utils/auth.ts
This commit is contained in:
commit
616034a4cd
541 files changed
+43805
-14767
No files matched your search
@@ -36,7 +36,7 @@ def get_chat_query_preview(chat_log_id: int):
|
||||
if not sql:
|
||||
raise ValidationError('query preview sql is missing')
|
||||
|
||||
from app.services.text2sql import Text2SQLService
|
||||
from app.services.integrations.text2sql import Text2SQLService
|
||||
total_count = payload.get('total_count')
|
||||
try:
|
||||
total_count = int(total_count) if total_count is not None else None
|
||||
|
||||
@@ -39,6 +39,7 @@ def chat_completions():
|
||||
# 前端传入的 conversation_id 在 B2 里代表本地 session_id
|
||||
conversation_id = data.get('conversation_id')
|
||||
shipping_task_id = str(data.get('task_id') or '').strip()
|
||||
shipping_batch_no = str(data.get('batch_no') or '').strip()
|
||||
kb_type = data.get('kb_type', '企业知识库')
|
||||
files = data.get('files')
|
||||
request_id = uuid.uuid4().hex[:12]
|
||||
@@ -87,7 +88,7 @@ def chat_completions():
|
||||
role=getattr(user, 'role', None),
|
||||
)
|
||||
|
||||
from app.services.dify import DifyService
|
||||
from app.services.integrations.dify import DifyService
|
||||
|
||||
external_conversation_id = None
|
||||
if conversation_id:
|
||||
@@ -174,6 +175,7 @@ def chat_completions():
|
||||
normalized_files=normalized_files,
|
||||
adapter_hints=_build_chat_adapter_hints(
|
||||
shipping_task_id=shipping_task_id,
|
||||
shipping_batch_no=shipping_batch_no,
|
||||
),
|
||||
shipping_task_id=shipping_task_id,
|
||||
kb_type=kb_type,
|
||||
@@ -214,6 +216,7 @@ def chat_completions():
|
||||
user_role=user_proxy.role,
|
||||
adapter_hints=_build_chat_adapter_hints(
|
||||
shipping_task_id=shipping_task_id,
|
||||
shipping_batch_no=shipping_batch_no,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -10,19 +10,21 @@ from __future__ import annotations
|
||||
from .shared import * # noqa: F403
|
||||
|
||||
|
||||
def _build_chat_adapter_hints(*, shipping_task_id: str | None = None) -> dict | None:
|
||||
def _build_chat_adapter_hints(*, shipping_task_id: str | None = None, shipping_batch_no: str | None = None) -> dict | None:
|
||||
"""
|
||||
构建聊天入口分发给领域 adapter 的提示字典。
|
||||
|
||||
核心逻辑:平台入口只暴露通用参数;像发货通知这类业务专用 task 提示,
|
||||
核心逻辑:平台入口只暴露通用参数;像发货通知这类业务专用 task/batch 提示,
|
||||
统一收敛到 adapter_hints 这个不透明容器里,避免平台函数签名泄漏领域字段。
|
||||
"""
|
||||
task_id = str(shipping_task_id or '').strip()
|
||||
if not task_id:
|
||||
batch_no = str(shipping_batch_no or '').strip()
|
||||
if not task_id and not batch_no:
|
||||
return None
|
||||
return {
|
||||
'shipping_notice': {
|
||||
'task_id': task_id or None,
|
||||
'batch_no': batch_no or None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +37,7 @@ def _should_reset_provider_conversation_for_asset_query(query: str, agent_proxy)
|
||||
- 仅当用户本轮问题可脱离上一轮上下文独立完成时触发;
|
||||
- 这样可以保留本地同一历史会话,又避免把上一轮超大结果继续带给上游模型,导致 context length 爆掉。
|
||||
"""
|
||||
from app.services.text2sql import Text2SQLService
|
||||
from app.services.integrations.text2sql import Text2SQLService
|
||||
|
||||
return Text2SQLService._should_reset_provider_conversation(query, agent_proxy)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ def get_oa_employees():
|
||||
page = 1
|
||||
page_size = 20
|
||||
try:
|
||||
from app.services.oa_sqlserver import OASQLServerService
|
||||
from app.services.integrations.oa.sqlserver import OASQLServerService
|
||||
result = OASQLServerService.search_employees(keyword, page, page_size)
|
||||
return jsonify(result)
|
||||
except Exception as e:
|
||||
@@ -39,7 +39,7 @@ def resolve_oa_names():
|
||||
sub_ids = request.args.get('subcompany_ids', '').strip()
|
||||
result = {}
|
||||
try:
|
||||
from app.services.oa_sqlserver import OASQLServerService
|
||||
from app.services.integrations.oa.sqlserver import OASQLServerService
|
||||
if dept_ids:
|
||||
for did in dept_ids.split(','):
|
||||
did = did.strip()
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
api/chat/sessions.py
|
||||
|
||||
用途:处理聊天会话、历史消息与本地结构化消息路由。
|
||||
依赖:chat.shared、chat.core、ChatSession、ChatLog。
|
||||
逻辑:校验当前用户和 Agent 后读写会话及日志,保持历史数据兼容查询。
|
||||
依赖:chat.shared、chat.core、ChatSession、ChatLog、_normalize_user_attachments。
|
||||
逻辑:校验当前用户和 Agent 后读写会话及日志;用户附件快照写库前规范化,超限显式失败不落半截。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -246,7 +246,8 @@ def save_local_message():
|
||||
保存前端本地生成的聊天记录(如表单、确认弹窗、合同审查结果卡等)。
|
||||
|
||||
核心逻辑:user 角色用 content/query 落库;纯文本 assistant 忽略 query 防重复气泡;
|
||||
结构化 typed 消息(leave-form / procurement-contract-review 等)保留 query,供历史回放与会话标题。
|
||||
结构化 typed 消息(leave-form / procurement-contract-review 等)保留 query,供历史回放与会话标题;
|
||||
user 角色 payload 含 user_attachments 时写库前调用 _normalize_user_attachments,超限抛 ValidationError。
|
||||
"""
|
||||
user = getattr(g, 'current_user', None)
|
||||
agent = getattr(g, 'current_agent', None)
|
||||
@@ -286,6 +287,13 @@ def save_local_message():
|
||||
if user_query and _looks_like_review_auto_title(session.title or ''):
|
||||
session.title = _session_title_from_text(user_query)
|
||||
|
||||
# [STEP] 用户附件快照写前规范化;超限由 _normalize_user_attachments 显式失败,禁止落半截
|
||||
if role == 'user' and isinstance(payload, dict) and 'user_attachments' in payload:
|
||||
payload = {
|
||||
**payload,
|
||||
'user_attachments': _normalize_user_attachments(payload.get('user_attachments')),
|
||||
}
|
||||
|
||||
# 如果 payload 里面包含 formId,且该 formId 已经被保存过,可以直接更新该记录
|
||||
# 这样能保证前端表单状态(例如已确认)被持久化
|
||||
local_id = payload.get('formId') if payload and isinstance(payload, dict) else None
|
||||
|
||||
@@ -24,9 +24,9 @@ from flask import Blueprint, request, Response, stream_with_context, jsonify, g,
|
||||
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.services.integrations.dify import DifyService
|
||||
from app.core.config.settings import Config
|
||||
from app.services.integration_api import IntegrationApiService
|
||||
from app.services.integrations.integration_api import IntegrationApiService
|
||||
from app.core.decorators import require_agent_permission
|
||||
from app.models import Agent, ChatLog, ChatSession, Feedback
|
||||
from app import db
|
||||
@@ -43,7 +43,7 @@ from app.core.errors import (
|
||||
SHIPPING_NOTICE_AGENT_CODE = 'shipping_notice'
|
||||
|
||||
# 用户消息附件白名单(迁移自 legacy app/api/chat.py;供 ChatLog payload 与历史接口复用)。
|
||||
CHAT_USER_ATTACHMENT_LIMIT = 20
|
||||
CHAT_USER_ATTACHMENT_LIMIT = 200
|
||||
CHAT_USER_ATTACHMENT_MAX_SIZE = 10 * 1024 * 1024 * 1024
|
||||
CHAT_USER_ATTACHMENT_TYPES = {'image', 'document', 'audio', 'video', 'custom'}
|
||||
CHAT_USER_ATTACHMENT_SOURCES = {'local', 'remote', 'shipping_notice'}
|
||||
@@ -53,18 +53,31 @@ def _normalize_user_attachments(value) -> list[dict]:
|
||||
"""
|
||||
校验并清洗用户消息附件快照,供 ChatLog payload 与历史接口复用。
|
||||
|
||||
核心逻辑:仅接受展示白名单字段;剥离路径、控制字符与未知枚举,不接收 URL、上传 ID 或资产编号。
|
||||
核心逻辑:仅接受展示白名单字段;剥离路径、控制字符与未知枚举;
|
||||
列表长度超过 CHAT_USER_ATTACHMENT_LIMIT 时显式失败,禁止静默截断。
|
||||
|
||||
Args:
|
||||
value: 前端 user_attachments 原始值;必须为列表,最多处理 20 项。
|
||||
value: 前端 user_attachments 原始值;必须为列表。
|
||||
|
||||
Returns:
|
||||
可安全写入 JSON 的附件快照列表;非法项目被忽略。
|
||||
|
||||
Raises:
|
||||
ValidationError: 列表长度超过上限(code=CHAT.USER_ATTACHMENTS_LIMIT_EXCEEDED)。
|
||||
"""
|
||||
if not isinstance(value, list):
|
||||
return []
|
||||
if len(value) > CHAT_USER_ATTACHMENT_LIMIT:
|
||||
raise ValidationError(
|
||||
f'User attachments exceed limit ({CHAT_USER_ATTACHMENT_LIMIT})',
|
||||
code='CHAT.USER_ATTACHMENTS_LIMIT_EXCEEDED',
|
||||
details={
|
||||
'limit': CHAT_USER_ATTACHMENT_LIMIT,
|
||||
'count': len(value),
|
||||
},
|
||||
)
|
||||
normalized: list[dict] = []
|
||||
for item in value[:CHAT_USER_ATTACHMENT_LIMIT]:
|
||||
for item in value:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
raw_name = str(item.get('name') or '')
|
||||
|
||||
@@ -27,7 +27,7 @@ def upload_chat_file():
|
||||
if not upload:
|
||||
raise ValidationError('file is required')
|
||||
|
||||
from app.services.dify import DifyService
|
||||
from app.services.integrations.dify import DifyService
|
||||
from app.core.config.settings import Config
|
||||
|
||||
params = DifyService.get_app_parameters(agent, force_refresh=True)
|
||||
|
||||
Reference in new issue
Block a user