feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估
- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。 - 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。 - 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。 - 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。 - 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
1 parent
cef3d5b26a
commit
3a9fbac2fc
226 files changed
+25010
-2098
No files matched your search
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* features/chat/utils/chatText.spec.ts
|
||||
* 用途:验证对话展示清理模型推理和纯调试包装,同时保留正常业务回答。
|
||||
* 依赖:Vitest、chatText。
|
||||
* 逻辑:覆盖推理标签、调试 JSON、技术前奏和正常 JSON 示例。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { stripReasoningPrelude } from './chatText';
|
||||
|
||||
describe('stripReasoningPrelude', () => {
|
||||
it('removes reasoning tags and technical prelude lines', () => {
|
||||
expect(stripReasoningPrelude('<think>internal</think>订单已处理完成。')).toBe('订单已处理完成。');
|
||||
expect(stripReasoningPrelude('workflow_run_id: run-1\nnode_id: node-2\n订单已处理完成。'))
|
||||
.toBe('订单已处理完成。');
|
||||
});
|
||||
|
||||
it('hides pure debug JSON but keeps business JSON examples', () => {
|
||||
expect(stripReasoningPrelude('{"workflow_run_id":"run-1","status":"failed"}')).toBe('');
|
||||
expect(stripReasoningPrelude('{"订单号":"PO-1","数量":2}'))
|
||||
.toBe('{"订单号":"PO-1","数量":2}');
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,7 @@
|
||||
/** 去除模型 reasoning 前奏,供 Markdown 展示与出货模块使用 */
|
||||
/**
|
||||
* 去除模型推理与调试包装,供 Markdown 展示与出货模块使用。
|
||||
* 仅处理明确的推理标签、纯调试 JSON 和开头技术诊断行,不改写正常业务回答。
|
||||
*/
|
||||
export const stripReasoningPrelude = (text: string) => {
|
||||
if (!text) return '';
|
||||
let cleaned = text
|
||||
@@ -6,6 +9,31 @@ export const stripReasoningPrelude = (text: string) => {
|
||||
.replace(/<analysis[\s\S]*?<\/analysis>/gi, '')
|
||||
.trim();
|
||||
|
||||
if (/^(?:\{|\[)/.test(cleaned)) {
|
||||
try {
|
||||
const parsed = JSON.parse(cleaned) as unknown;
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
const keys = Object.keys(parsed as Record<string, unknown>);
|
||||
const technicalKeys = new Set([
|
||||
'workflow_run_id', 'node_id', 'node_execution_id', 'status', 'error',
|
||||
'outputs', 'inputs', 'metadata', 'traceback', 'tool_output', 'tool_response',
|
||||
]);
|
||||
if (keys.length > 0 && keys.every((key) => technicalKeys.has(key))) return '';
|
||||
}
|
||||
} catch {
|
||||
// 非完整 JSON 继续按普通回答展示。
|
||||
}
|
||||
}
|
||||
|
||||
const lines = cleaned.split('\n');
|
||||
while (
|
||||
lines.length > 1
|
||||
&& /^\s*(?:workflow(?:_run)?_id|node(?:_execution)?_id|tool(?:_output|_response)?|traceback|status|error)(?:[_\s-]*(?:code|message))?\s*[:=]/i.test(lines[0] || '')
|
||||
) {
|
||||
lines.shift();
|
||||
}
|
||||
cleaned = lines.join('\n').trim();
|
||||
|
||||
const reasoningMarkers = [
|
||||
'让我分析',
|
||||
'根据应答生成规则',
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* features/chat/utils/streamErrorMessage.spec.ts
|
||||
* 用途:验证流式异常不会把后端或浏览器技术正文展示给用户。
|
||||
* 依赖:Vitest、streamErrorMessage。
|
||||
* 逻辑:保留明确连接中断分类,其余中英文异常一律使用通用提示。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { resolveStreamErrorText } from './streamErrorMessage';
|
||||
|
||||
const labels = {
|
||||
networkDisconnectedEmpty: '连接中断',
|
||||
partialInterrupted: '回答不完整',
|
||||
upstreamDisconnected: '服务连接中断',
|
||||
generic: '请稍后重试',
|
||||
};
|
||||
|
||||
describe('resolveStreamErrorText', () => {
|
||||
it('maps known disconnects to business messages', () => {
|
||||
expect(resolveStreamErrorText('Failed to fetch', false, labels)).toBe('连接中断');
|
||||
expect(resolveStreamErrorText('response ended prematurely', true, labels)).toBe('回答不完整');
|
||||
});
|
||||
|
||||
it('does not expose Chinese or English technical errors', () => {
|
||||
expect(resolveStreamErrorText('Dify API Key 配置错误', false, labels)).toBe('请稍后重试');
|
||||
expect(resolveStreamErrorText('HTTP 500 node_execution_id=abc', false, labels)).toBe('请稍后重试');
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,8 @@
|
||||
* features/chat/utils/streamErrorMessage.ts
|
||||
* 用途:将 SSE / 浏览器流式读错映射为用户可读文案。
|
||||
* 依赖:vue-i18n chat.streamError 词条。
|
||||
* 逻辑:useChat 在 catch 与 error 事件中调用 applyStreamErrorToMessage。
|
||||
* 逻辑:useChat 在 catch 与 error 事件中调用 applyStreamErrorToMessage;
|
||||
* 只识别明确的连接中断,其余异常正文不向用户透传。
|
||||
*/
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
@@ -63,9 +64,6 @@ export function resolveStreamErrorText(
|
||||
if (isUpstreamDisconnectError(rawMessage)) {
|
||||
return hasContent ? labels.partialInterrupted : labels.upstreamDisconnected;
|
||||
}
|
||||
if (/[\u4e00-\u9fff]/.test(rawMessage)) {
|
||||
return rawMessage;
|
||||
}
|
||||
return labels.generic;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user