feat(shipping-notice): 货代会话主区域切换为批次中心常驻并按附件派生会话标题
- 会话命名:新增业务命名纯函数,新建抽取会话按附件内容派生标题,仅新建不回填不改名 - 批次中心常驻主区域并展示会话标题:移除关闭入口、隐藏对话列、去除面板外壳与折叠/钉住徽标 - 清理对话流打开批次中心的冗余链路 - 新增设计文档与实施计划,同步功能清单说明
This commit is contained in:
1 parent
d396371020
commit
e472abc4e3
21 files changed
+1198
-206
No files matched your search
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
backend/app/services/shipping_notice/conversation_title.py
|
||||
|
||||
用途:为订单抽取**新建**会话推导业务化标题,替代写死的「订单抽取」。
|
||||
依赖:仅标准库(datetime/pathlib/re);禁止引入 Flask/DB 依赖,保持可单测。
|
||||
逻辑:取首个非空附件文件名去扩展名 → 循环剥离邮件前缀 → 截断 24 字符 →
|
||||
多文件追加「等 N 个文件」→ 追加 MM-DD 日期消歧 → 全空回退「订单抽取」。
|
||||
仅新建会话时调用;存量会话标题一律不改(设计决策见 2026-09-17 spec)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import PureWindowsPath
|
||||
|
||||
_FALLBACK_TITLE = '订单抽取'
|
||||
_NAME_MAX_CHARS = 24
|
||||
_TITLE_MAX_CHARS = 60
|
||||
# re:/fw:/fwd: 为半角冒号且大小写不敏感;回复/转发为全角冒号。循环剥离以支持多层嵌套。
|
||||
_MAIL_PREFIX_PATTERN = re.compile(r'^\s*(?:re|fw|fwd)\s*:|^\s*(?:回复|转发):', re.IGNORECASE)
|
||||
|
||||
|
||||
def _strip_mail_prefixes(name: str) -> str:
|
||||
"""循环剥离单个文件名开头的邮件前缀(Re:/Fw:/Fwd:/回复:/转发:)。"""
|
||||
current = name.strip()
|
||||
while True:
|
||||
stripped = _MAIL_PREFIX_PATTERN.sub('', current, count=1).lstrip()
|
||||
if stripped == current:
|
||||
return current
|
||||
current = stripped
|
||||
|
||||
|
||||
def derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str:
|
||||
"""
|
||||
按首个附件文件名推导订单抽取会话标题。
|
||||
|
||||
Args:
|
||||
filenames: 本次冻结 Intake 对应的资产原始文件名,按 Intake 顺序;
|
||||
允许包含空串占位(保持计数口径)。
|
||||
created_at: 会话创建时间(服务器 UTC,不做时区换算),提供 MM-DD 消歧后缀。
|
||||
Returns:
|
||||
形如「PO#6075309 等 11 个文件 09-15」的标题;文件名全空时回退「订单抽取」;
|
||||
末尾做 60 字符防御性钳制(24 字主名约束下正常不可达)。
|
||||
"""
|
||||
ordered = [str(name or '').strip() for name in filenames]
|
||||
usable = [name for name in ordered if name]
|
||||
if not usable:
|
||||
return _FALLBACK_TITLE
|
||||
# PureWindowsPath 同时把 '/' 与 '\' 视为目录分隔符,兼容两类上传来源的路径写法。
|
||||
stem = PureWindowsPath(usable[0]).stem
|
||||
base = _strip_mail_prefixes(stem)[:_NAME_MAX_CHARS].strip()
|
||||
if not base:
|
||||
return _FALLBACK_TITLE
|
||||
parts = [base]
|
||||
if len(ordered) > 1:
|
||||
parts.append(f'等 {len(ordered)} 个文件')
|
||||
parts.append(f'{created_at.month:02d}-{created_at.day:02d}')
|
||||
return ' '.join(parts)[:_TITLE_MAX_CHARS]
|
||||
@@ -56,6 +56,7 @@ from app.models import (
|
||||
ShippingOrderSchemaVersion,
|
||||
User,
|
||||
)
|
||||
from app.services.shipping_notice.conversation_title import derive_order_extraction_title
|
||||
from app.services.shipping_notice.order_extraction_route_contract import (
|
||||
PARSER_ENGINE_VERSION,
|
||||
PARSER_POLICY_VERSION,
|
||||
@@ -697,6 +698,16 @@ def _load_intakes(
|
||||
return rows
|
||||
|
||||
|
||||
def _intake_filenames(intakes: list[ShippingOrderIntake]) -> list[str]:
|
||||
"""按 Intake 顺序取资产原始文件名;无资产或资产缺失以空串占位,保持计数口径。"""
|
||||
asset_ids = [int(intake.asset_id) for intake in intakes if intake.asset_id]
|
||||
if not asset_ids:
|
||||
return []
|
||||
rows = db.session.query(FileAsset.id, FileAsset.original_filename).filter(FileAsset.id.in_(asset_ids)).all()
|
||||
filename_by_id = {row[0]: str(row[1] or '') for row in rows}
|
||||
return [filename_by_id.get(int(intake.asset_id), '') for intake in intakes if intake.asset_id]
|
||||
|
||||
|
||||
def _resolve_conversation(
|
||||
*,
|
||||
user_id: int,
|
||||
@@ -713,6 +724,7 @@ def _resolve_conversation(
|
||||
intakes: 已按用户锁定且通过业务资格校验的 Intake。
|
||||
Returns:
|
||||
已存在或本事务新建的 ChatSession;调用方负责最终提交。
|
||||
新建会话的 title 由 conversation_title 按首个 Intake 文件名派生;已存在会话不改动标题。
|
||||
Raises:
|
||||
ConflictError: 所选 Intake 已分属不同会话,或与显式会话不一致。
|
||||
"""
|
||||
@@ -737,7 +749,7 @@ def _resolve_conversation(
|
||||
session_id=uuid.uuid4().hex,
|
||||
user_id=user_id,
|
||||
agent_id=agent_id,
|
||||
title='订单抽取',
|
||||
title=derive_order_extraction_title(_intake_filenames(intakes), datetime.utcnow()),
|
||||
status='running',
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow(),
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
backend/tests/test_shipping_conversation_title.py
|
||||
|
||||
用途:验证订单抽取会话标题纯函数的派生规则(前缀剥离/截断/计数后缀/日期/回退)。
|
||||
依赖:纯函数,无 Flask/DB 夹具。
|
||||
逻辑:命名是内容派生的确定性函数,用逐条断言锁定规则,防止后续误改口径。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from app.services.shipping_notice.conversation_title import derive_order_extraction_title
|
||||
|
||||
|
||||
def test_strips_leading_mail_prefixes_and_appends_date():
|
||||
"""首个文件名循环剥离 Re/Fw/Fwd/回复/转发 前缀,末尾追加 MM-DD。"""
|
||||
title = derive_order_extraction_title(['回复:转发:FWD: PO#6075309.eml'], datetime(2026, 9, 15))
|
||||
assert title == 'PO#6075309 09-15'
|
||||
|
||||
|
||||
def test_multi_files_appends_count_suffix():
|
||||
"""文件总数大于 1 时追加「等 N 个文件」,N 按传入文件名总数计。"""
|
||||
title = derive_order_extraction_title(['PO#6075309.eml', 'invoice.pdf', 'list.pdf'], datetime(2026, 9, 15))
|
||||
assert title == 'PO#6075309 等 3 个文件 09-15'
|
||||
|
||||
|
||||
def test_truncates_long_name_to_24_chars():
|
||||
"""主名超过 24 字符截断,且不吞掉日期后缀。"""
|
||||
title = derive_order_extraction_title(['A' * 30 + '.pdf'], datetime(2026, 12, 31))
|
||||
assert title == 'A' * 24 + ' 12-31'
|
||||
|
||||
|
||||
def test_blank_filenames_fall_back_to_default():
|
||||
"""文件名全空(含空列表与纯空白项)回退写死标题「订单抽取」。"""
|
||||
assert derive_order_extraction_title([], datetime(2026, 9, 15)) == '订单抽取'
|
||||
assert derive_order_extraction_title(['', ' '], datetime(2026, 9, 15)) == '订单抽取'
|
||||
@@ -0,0 +1,87 @@
|
||||
"""
|
||||
backend/tests/test_shipping_order_extraction_conversation_title.py
|
||||
|
||||
用途:验证订单抽取新建会话按 Intake 资产文件名派生标题,且已存在会话标题一律不动。
|
||||
依赖:全局 Flask/SQLite 测试夹具(app)、Run service 的会话解析内部函数。
|
||||
逻辑:新建分支走 conversation_title 派生;追加归属等存量路径保持原标题(含「订单抽取」)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app import db
|
||||
from app.models import Agent, ChatSession, FileAsset, ShippingOrderIntake, User
|
||||
from app.services.shipping_notice.order_extraction_run_service import _resolve_conversation
|
||||
|
||||
|
||||
def _seed_user_agent(suffix: str) -> tuple[User, Agent]:
|
||||
"""构造用户与货代 Agent;suffix 保证同文件内多用例数据隔离。"""
|
||||
user = User(username=f'title-user-{suffix}', email=f'title-{suffix}@example.com', password_hash='x')
|
||||
agent = Agent(
|
||||
name=f'Title Agent {suffix}',
|
||||
agent_code='shipping_notice',
|
||||
runtime_provider='hybrid',
|
||||
dify_app_id=f'title-agent-{suffix}',
|
||||
dify_api_key='test-key',
|
||||
is_active=True,
|
||||
)
|
||||
user.agents.append(agent)
|
||||
db.session.add_all([user, agent])
|
||||
db.session.flush()
|
||||
return user, agent
|
||||
|
||||
|
||||
def _seed_intake(suffix: str, user: User, filename: str, conversation_id: str | None = None) -> ShippingOrderIntake:
|
||||
"""构造带资产文件名的已解析 Intake。"""
|
||||
asset = FileAsset(
|
||||
asset_no=f'FA-TITLE-{suffix}',
|
||||
owner_user_id=user.id,
|
||||
original_filename=filename,
|
||||
storage_provider='minio',
|
||||
storage_bucket='test',
|
||||
storage_key=f'temporary/{user.id}/{filename}',
|
||||
content_hash=(suffix.lower() * 64)[:64],
|
||||
file_size=10,
|
||||
mime_type='application/pdf',
|
||||
upload_status='ready',
|
||||
lifecycle_status='temporary',
|
||||
)
|
||||
db.session.add(asset)
|
||||
db.session.flush()
|
||||
intake = ShippingOrderIntake(
|
||||
intake_no=f'SNI-TITLE-{suffix}',
|
||||
asset_id=asset.id,
|
||||
user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
purpose='shipping_notice',
|
||||
parse_status='parsed',
|
||||
parser_version='test',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.flush()
|
||||
return intake
|
||||
|
||||
|
||||
def test_new_session_title_derives_from_intake_filenames(app):
|
||||
"""新建会话:标题 = 首个文件名(剥离邮件前缀)+ 等 N 个文件 + 日期后缀。"""
|
||||
user, agent = _seed_user_agent('NEW')
|
||||
first = _seed_intake('NEW1', user, 'RE: PO#6075309 for HOXIN.eml')
|
||||
second = _seed_intake('NEW2', user, 'invoice.pdf')
|
||||
|
||||
session = _resolve_conversation(user_id=user.id, agent_id=agent.id, conversation_id='', intakes=[first, second])
|
||||
|
||||
# 日期后缀来自 utcnow,断言前缀避免对当天日期产生脆弱依赖。
|
||||
assert session.title.startswith('PO#6075309 for HOXIN 等 2 个文件 ')
|
||||
|
||||
|
||||
def test_existing_session_title_stays_untouched(app):
|
||||
"""已存在会话:即便标题仍是写死的「订单抽取」,Intake 归属也不改标题。"""
|
||||
user, agent = _seed_user_agent('KEEP')
|
||||
session = ChatSession(session_id='title-session-keep', user_id=user.id, agent_id=agent.id, title='订单抽取')
|
||||
db.session.add(session)
|
||||
db.session.flush()
|
||||
intake = _seed_intake('KEEP1', user, 'RE: PO#6075309.eml', conversation_id=session.session_id)
|
||||
|
||||
resolved = _resolve_conversation(user_id=user.id, agent_id=agent.id, conversation_id='', intakes=[intake])
|
||||
|
||||
assert resolved.session_id == session.session_id
|
||||
assert resolved.title == '订单抽取'
|
||||
@@ -2590,6 +2590,21 @@ Task 工作台 = 非主界面,仅保留备用深链
|
||||
- **自动建单安全**:分类置信度与 LLM 字段置信度缺失 fail-closed;阈值来源写入 `confidence_policy`(schema / key_field / default_fallback)。
|
||||
- **货代上传**:`SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED` 默认 `false`(须显式开启);开启时启动/触发前校验 Worker(`freight_upload`)、凭据、共享目录与环境隔离。RPA 进行中投影 `display_lifecycle_status=upload_rpa_pending` 且 `is_waiting_manual_upload=false`,不得仅凭 lifecycle 显示为待人工上传。
|
||||
|
||||
### 会话主区域与批次进度中心(2026-09 方案 A)
|
||||
|
||||
- 货代发货智能体主区域规则:`isShippingNoticeAgent && conversation_id 非空` → 全屏渲染批次进度中心
|
||||
(`ShippingWorkflowTimeline`,常驻无关闭按钮);否则渲染欢迎页 + 输入框(唯一附件提交入口)。
|
||||
判定纯函数:`frontend/src/features/chat/shipping/shippingWorkbenchLayout.ts`。
|
||||
- 提交链路不变:`startRun` 成功 → 路由写回 `conversation_id` → 中心出现;对话流不再出现
|
||||
「本次订单文件处理」卡片入口,`open-batch-workbench` / `compact-shipping-progress` 链路已移除;
|
||||
`ShippingOrderExtractionCard` 保留为历史消息兜底渲染。
|
||||
- 中心头部复用会话标题(父级从侧栏 `displayHistory` 按 conversation_id 匹配传入 `conversation-title`)。
|
||||
- 新建抽取会话命名:`backend/app/services/shipping_notice/conversation_title.py`
|
||||
`derive_order_extraction_title(filenames, created_at)` —— 首个非空文件名去扩展名、剥离
|
||||
Re:/Fw:/Fwd:/回复:/转发:前缀、截 24 字、多文件追加「等 N 个文件」、追加 MM-DD;
|
||||
全空回退「订单抽取」。仅在 `_resolve_conversation` 新建分支调用;存量会话标题一律不改。
|
||||
- 同批次追加附件:中心不提供入口,通过「新建对话」重新提交(后端 append/create 裁决逻辑不变)。
|
||||
|
||||
#### 1.6.0a Gate 统一用户动作裁决(2026-08-19)
|
||||
|
||||
为避免“页面按 checkpoint、状态或 action code 猜按钮位置”导致展示与执行漂移,正式履约任务采用以下职责边界:
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
- 货代上传:下载 Excel、RPA 上传、按发货通知单号人工确认已上传、失败恢复和未知结果核对;未知结果禁止自动重试。
|
||||
- 通知完成:只读展示已核验的上传成功证据;仅 Task 聚合、全部预约单与成功 Upload Attempt 同时满足时显示并计入完成。
|
||||
- 通知完成:上传通知或登记上传回执;仅服务端确认的上传 Attempt 成功后显示完成结果。
|
||||
- 货代发货会话主区域为批次进度中心:有会话即全屏常驻展示(不可关闭),无会话显示欢迎页与附件提交入口;历史会话点击直达中心
|
||||
- 新建订单抽取会话自动按首个附件文件名命名(剥离邮件前缀 + 等 N 个文件 + 日期后缀);存量会话名不变
|
||||
- 平台把文本提交给 Dify 后,会继续确认 Dify 的 `indexing_status`;只有 `completed` 才展示“同步:已完成”。
|
||||
- Dify 返回 `error/failed` 或 60 秒内未完成索引时,同步任务、同步记录和文档卡片会显示失败原因;再次同步会重新提交失败文档。
|
||||
- 管理端“知识库配置 → Dify 设置”支持配置新建 Dataset 的默认检索模型(检索方式、重排序、Top K、相似度阈值开关及阈值),以及文档同步的自定义分段参数(最大 Token 数、重叠 Token 数);保存仅更新 HXOPS 运行时配置,不自动回写已创建的 Dify Dataset。
|
||||
|
||||
@@ -0,0 +1,724 @@
|
||||
# 货代批次进度中心优先 + 会话业务命名 实施计划
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** 货代发货智能体主区域改为「有会话即全屏批次进度中心、无会话显示欢迎页+输入框」,移除对话流「打开批次进度中心」冗余链路;新建抽取会话按首个附件文件名自动派生业务标题。
|
||||
|
||||
**Architecture:** 后端新增纯函数命名模块并在 `_resolve_conversation` 新建会话时调用;前端把 `ChatViewContent` 的 `batchWorkbenchOpen` 状态机坍缩为 `isShippingNoticeAgent && conversationId` 的纯判定,`ShippingWorkflowTimeline` 常驻主区域(移除关闭按钮、新增会话标题 prop),逐层移除 `open-batch-workbench` / `compact-shipping-progress` prop/emit 链。
|
||||
|
||||
**Tech Stack:** Flask + SQLAlchemy(后端纯函数 + service 接入);Vue 3 Composition API + Vitest(前端);pytest。
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-09-17-shipping-batch-center-first-design.md`(执行前先读 spec)
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- 禁止新增第三方依赖;无数据库结构变更(无 Alembic 迁移);无环境变量变更;无新增 i18n 文案。
|
||||
- 存量会话标题一律不改:`_resolve_conversation` 只在**新建**分支派生标题;不做惰性回填;不做手动改名 API。
|
||||
- `ShippingOrderExtractionCard` 组件整体保留,仅删除「打开批次进度中心」按钮与 `compactProgress` prop。
|
||||
- 注释遵循 AGENTS.md §5:文件层块注释(用途/依赖/逻辑)、函数层 docstring/JSDoc;改动逻辑必须同步更新受影响注释。
|
||||
- 提交信息遵循 Conventional Commits:`<type>(<scope>): 中文祈使句≤100字符`。
|
||||
- ⚠️ 当前分支 `hugo-shipping-notice` 存在大量与本计划无关的未提交改动:每次提交只 `git add` 本任务明确列出的文件,禁止 `git add -A` / `git add .`。
|
||||
- 前端文件顶部如已有块注释被改动逻辑影响,必须同步更新。
|
||||
|
||||
---
|
||||
|
||||
### Task 1: 后端纯函数 `derive_order_extraction_title`
|
||||
|
||||
**Files:**
|
||||
- Create: `backend/app/services/shipping_notice/conversation_title.py`
|
||||
- Test: `backend/tests/test_shipping_conversation_title.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 无(纯函数,仅标准库)。
|
||||
- Produces: `derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str`——Task 2 在 `_resolve_conversation` 中调用。规则:取首个非空文件名去扩展名(`/`、`\` 均视为目录分隔符)→ 循环剥离邮件前缀 `Re:` `Fw:` `Fwd:` `回复:` `转发:`(大小写不敏感)→ 主名截断 24 字符 → 文件总数 > 1 追加 `等 N 个文件`(N 为传入列表长度)→ 追加 ` MM-DD`(`created_at` 月份/日期,不换算时区)→ 全空回退 `订单抽取` → 最终长度钳制 ≤ 60(防御性,正常输入不可达)。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
创建 `backend/tests/test_shipping_conversation_title.py`:
|
||||
|
||||
```python
|
||||
"""
|
||||
backend/tests/test_shipping_conversation_title.py
|
||||
|
||||
用途:验证订单抽取会话标题纯函数的派生规则(前缀剥离/截断/计数后缀/日期/回退)。
|
||||
依赖:纯函数,无 Flask/DB 夹具。
|
||||
逻辑:命名是内容派生的确定性函数,用逐条断言锁定规则,防止后续误改口径。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from app.services.shipping_notice.conversation_title import derive_order_extraction_title
|
||||
|
||||
|
||||
def test_strips_leading_mail_prefixes_and_appends_date():
|
||||
"""首个文件名循环剥离 Re/Fw/Fwd/回复/转发 前缀,末尾追加 MM-DD。"""
|
||||
title = derive_order_extraction_title(['回复:转发:FWD: PO#6075309.eml'], datetime(2026, 9, 15))
|
||||
assert title == 'PO#6075309 09-15'
|
||||
|
||||
|
||||
def test_multi_files_appends_count_suffix():
|
||||
"""文件总数大于 1 时追加「等 N 个文件」,N 按传入文件名总数计。"""
|
||||
title = derive_order_extraction_title(['PO#6075309.eml', 'invoice.pdf', 'list.pdf'], datetime(2026, 9, 15))
|
||||
assert title == 'PO#6075309 等 3 个文件 09-15'
|
||||
|
||||
|
||||
def test_truncates_long_name_to_24_chars():
|
||||
"""主名超过 24 字符截断,且不吞掉日期后缀。"""
|
||||
title = derive_order_extraction_title(['A' * 30 + '.pdf'], datetime(2026, 12, 31))
|
||||
assert title == 'A' * 24 + ' 12-31'
|
||||
|
||||
|
||||
def test_blank_filenames_fall_back_to_default():
|
||||
"""文件名全空(含空列表与纯空白项)回退写死标题「订单抽取」。"""
|
||||
assert derive_order_extraction_title([], datetime(2026, 9, 15)) == '订单抽取'
|
||||
assert derive_order_extraction_title(['', ' '], datetime(2026, 9, 15)) == '订单抽取'
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 运行确认失败**
|
||||
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_conversation_title.py -v`
|
||||
Expected: FAIL(`ModuleNotFoundError` 或 `ImportError: cannot import name 'derive_order_extraction_title'`)
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
创建 `backend/app/services/shipping_notice/conversation_title.py`:
|
||||
|
||||
```python
|
||||
"""
|
||||
backend/app/services/shipping_notice/conversation_title.py
|
||||
|
||||
用途:为订单抽取**新建**会话推导业务化标题,替代写死的「订单抽取」。
|
||||
依赖:仅标准库(datetime/pathlib/re);禁止引入 Flask/DB 依赖,保持可单测。
|
||||
逻辑:取首个非空附件文件名去扩展名 → 循环剥离邮件前缀 → 截断 24 字符 →
|
||||
多文件追加「等 N 个文件」→ 追加 MM-DD 日期消歧 → 全空回退「订单抽取」。
|
||||
仅新建会话时调用;存量会话标题一律不改(设计决策见 2026-09-17 spec)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import PureWindowsPath
|
||||
|
||||
_FALLBACK_TITLE = '订单抽取'
|
||||
_NAME_MAX_CHARS = 24
|
||||
_TITLE_MAX_CHARS = 60
|
||||
# re:/fw:/fwd: 为半角冒号且大小写不敏感;回复/转发为全角冒号。循环剥离以支持多层嵌套。
|
||||
_MAIL_PREFIX_PATTERN = re.compile(r'^\s*(?:re|fw|fwd)\s*:|^\s*(?:回复|转发):', re.IGNORECASE)
|
||||
|
||||
|
||||
def _strip_mail_prefixes(name: str) -> str:
|
||||
"""循环剥离单个文件名开头的邮件前缀(Re:/Fw:/Fwd:/回复:/转发:)。"""
|
||||
current = name.strip()
|
||||
while True:
|
||||
stripped = _MAIL_PREFIX_PATTERN.sub('', current, count=1).lstrip()
|
||||
if stripped == current:
|
||||
return current
|
||||
current = stripped
|
||||
|
||||
|
||||
def derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str:
|
||||
"""
|
||||
按首个附件文件名推导订单抽取会话标题。
|
||||
|
||||
Args:
|
||||
filenames: 本次冻结 Intake 对应的资产原始文件名,按 Intake 顺序;
|
||||
允许包含空串占位(保持计数口径)。
|
||||
created_at: 会话创建时间(服务器 UTC,不做时区换算),提供 MM-DD 消歧后缀。
|
||||
Returns:
|
||||
形如「PO#6075309 等 11 个文件 09-15」的标题;文件名全空时回退「订单抽取」;
|
||||
末尾做 60 字符防御性钳制(24 字主名约束下正常不可达)。
|
||||
"""
|
||||
ordered = [str(name or '').strip() for name in filenames]
|
||||
usable = [name for name in ordered if name]
|
||||
if not usable:
|
||||
return _FALLBACK_TITLE
|
||||
# PureWindowsPath 同时把 '/' 与 '\' 视为目录分隔符,兼容两类上传来源的路径写法。
|
||||
stem = PureWindowsPath(usable[0]).stem
|
||||
base = _strip_mail_prefixes(stem)[:_NAME_MAX_CHARS].strip()
|
||||
if not base:
|
||||
return _FALLBACK_TITLE
|
||||
parts = [base]
|
||||
if len(ordered) > 1:
|
||||
parts.append(f'等 {len(ordered)} 个文件')
|
||||
parts.append(f'{created_at.month:02d}-{created_at.day:02d}')
|
||||
return ' '.join(parts)[:_TITLE_MAX_CHARS]
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行确认通过**
|
||||
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_conversation_title.py -v`
|
||||
Expected: 4 passed
|
||||
|
||||
- [ ] **Step 5: 提交**
|
||||
|
||||
```bash
|
||||
git add backend/app/services/shipping_notice/conversation_title.py backend/tests/test_shipping_conversation_title.py
|
||||
git commit -m "feat(shipping-notice): 新增订单抽取会话业务命名纯函数"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: `_resolve_conversation` 新建会话接入业务标题
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend/app/services/shipping_notice/order_extraction_run_service.py`(`_resolve_conversation`,约 700-757 行;import 区)
|
||||
- Test: `backend/tests/test_shipping_order_extraction_conversation_title.py`(新建)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1 的 `derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str`。
|
||||
- Produces: 无对外新接口;`_resolve_conversation` 新建分支产生的 `ChatSession.title` 变为业务标题(Task 4 的中心头部经由侧栏历史间接消费该标题)。
|
||||
|
||||
- [ ] **Step 1: 写失败测试**
|
||||
|
||||
创建 `backend/tests/test_shipping_order_extraction_conversation_title.py`:
|
||||
|
||||
```python
|
||||
"""
|
||||
backend/tests/test_shipping_order_extraction_conversation_title.py
|
||||
|
||||
用途:验证订单抽取新建会话按 Intake 资产文件名派生标题,且已存在会话标题一律不动。
|
||||
依赖:全局 Flask/SQLite 测试夹具(app)、Run service 的会话解析内部函数。
|
||||
逻辑:新建分支走 conversation_title 派生;追加归属等存量路径保持原标题(含「订单抽取」)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app import db
|
||||
from app.models import Agent, ChatSession, FileAsset, ShippingOrderIntake, User
|
||||
from app.services.shipping_notice.order_extraction_run_service import _resolve_conversation
|
||||
|
||||
|
||||
def _seed_user_agent(suffix: str) -> tuple[User, Agent]:
|
||||
"""构造用户与货代 Agent;suffix 保证同文件内多用例数据隔离。"""
|
||||
user = User(username=f'title-user-{suffix}', email=f'title-{suffix}@example.com', password_hash='x')
|
||||
agent = Agent(
|
||||
name=f'Title Agent {suffix}',
|
||||
agent_code='shipping_notice',
|
||||
runtime_provider='hybrid',
|
||||
dify_app_id=f'title-agent-{suffix}',
|
||||
dify_api_key='test-key',
|
||||
is_active=True,
|
||||
)
|
||||
user.agents.append(agent)
|
||||
db.session.add_all([user, agent])
|
||||
db.session.flush()
|
||||
return user, agent
|
||||
|
||||
|
||||
def _seed_intake(suffix: str, user: User, filename: str, conversation_id: str | None = None) -> ShippingOrderIntake:
|
||||
"""构造带资产文件名的已解析 Intake。"""
|
||||
asset = FileAsset(
|
||||
asset_no=f'FA-TITLE-{suffix}',
|
||||
owner_user_id=user.id,
|
||||
original_filename=filename,
|
||||
storage_provider='minio',
|
||||
storage_bucket='test',
|
||||
storage_key=f'temporary/{user.id}/{filename}',
|
||||
content_hash=(suffix.lower() * 64)[:64],
|
||||
file_size=10,
|
||||
mime_type='application/pdf',
|
||||
upload_status='ready',
|
||||
lifecycle_status='temporary',
|
||||
)
|
||||
db.session.add(asset)
|
||||
db.session.flush()
|
||||
intake = ShippingOrderIntake(
|
||||
intake_no=f'SNI-TITLE-{suffix}',
|
||||
asset_id=asset.id,
|
||||
user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
purpose='shipping_notice',
|
||||
parse_status='parsed',
|
||||
parser_version='test',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.flush()
|
||||
return intake
|
||||
|
||||
|
||||
def test_new_session_title_derives_from_intake_filenames(app):
|
||||
"""新建会话:标题 = 首个文件名(剥离邮件前缀)+ 等 N 个文件 + 日期后缀。"""
|
||||
user, agent = _seed_user_agent('NEW')
|
||||
first = _seed_intake('NEW1', user, 'RE: PO#6075309 for HOXIN.eml')
|
||||
second = _seed_intake('NEW2', user, 'invoice.pdf')
|
||||
|
||||
session = _resolve_conversation(user_id=user.id, agent_id=agent.id, conversation_id='', intakes=[first, second])
|
||||
|
||||
# 日期后缀来自 utcnow,断言前缀避免对当天日期产生脆弱依赖。
|
||||
assert session.title.startswith('PO#6075309 for HOXIN 等 2 个文件 ')
|
||||
|
||||
|
||||
def test_existing_session_title_stays_untouched(app):
|
||||
"""已存在会话:即便标题仍是写死的「订单抽取」,Intake 归属也不改标题。"""
|
||||
user, agent = _seed_user_agent('KEEP')
|
||||
session = ChatSession(session_id='title-session-keep', user_id=user.id, agent_id=agent.id, title='订单抽取')
|
||||
db.session.add(session)
|
||||
db.session.flush()
|
||||
intake = _seed_intake('KEEP1', user, 'RE: PO#6075309.eml', conversation_id=session.session_id)
|
||||
|
||||
resolved = _resolve_conversation(user_id=user.id, agent_id=agent.id, conversation_id='', intakes=[intake])
|
||||
|
||||
assert resolved.session_id == session.session_id
|
||||
assert resolved.title == '订单抽取'
|
||||
```
|
||||
|
||||
注意:若运行时报 `ShippingOrderIntake` 存在其他非空字段缺省不足(以 `app/models/shipping.py:304` 为准),按既有 `tests/test_shipping_order_extraction_runs.py` 的 `_seed_run_input`(188 行起)补齐同款字段,不得改模型。
|
||||
|
||||
- [ ] **Step 2: 运行确认失败**
|
||||
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_order_extraction_conversation_title.py -v`
|
||||
Expected: `test_new_session_title_derives_from_intake_filenames` FAIL(实际 title == '订单抽取');`test_existing_session_title_stays_untouched` PASS
|
||||
|
||||
- [ ] **Step 3: 最小实现**
|
||||
|
||||
`backend/app/services/shipping_notice/order_extraction_run_service.py`:
|
||||
|
||||
3a. import 区新增(与既有顶层 import 并列):
|
||||
|
||||
```python
|
||||
from app.services.shipping_notice.conversation_title import derive_order_extraction_title
|
||||
```
|
||||
|
||||
3b. 在 `_resolve_conversation` 定义之前新增模块级辅助函数:
|
||||
|
||||
```python
|
||||
def _intake_filenames(intakes: list[ShippingOrderIntake]) -> list[str]:
|
||||
"""按 Intake 顺序取资产原始文件名;无资产或资产缺失以空串占位,保持计数口径。"""
|
||||
asset_ids = [int(intake.asset_id) for intake in intakes if intake.asset_id]
|
||||
if not asset_ids:
|
||||
return []
|
||||
rows = db.session.query(FileAsset.id, FileAsset.original_filename).filter(FileAsset.id.in_(asset_ids)).all()
|
||||
filename_by_id = {row[0]: str(row[1] or '') for row in rows}
|
||||
return [filename_by_id.get(int(intake.asset_id), '') for intake in intakes if intake.asset_id]
|
||||
```
|
||||
|
||||
3c. `_resolve_conversation` 的 `else:` 新建分支(原 736-747 行附近)把写死的 `title='订单抽取',` 替换为派生调用,`FileAsset`/`datetime` 均已在文件顶部导入:
|
||||
|
||||
```python
|
||||
else:
|
||||
session = ChatSession(
|
||||
session_id=uuid.uuid4().hex,
|
||||
user_id=user_id,
|
||||
agent_id=agent_id,
|
||||
title=derive_order_extraction_title(_intake_filenames(intakes), datetime.utcnow()),
|
||||
status='running',
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow(),
|
||||
last_active_at=datetime.utcnow(),
|
||||
)
|
||||
```
|
||||
|
||||
3d. 同步注释:`_resolve_conversation` docstring 的 Returns 行后补一句「新建会话的 title 由 conversation_title 按首个 Intake 文件名派生;已存在会话不改动标题。」;函数头文件顶部块注释如提及标题逻辑则同步(先 grep `订单抽取` 确认)。
|
||||
|
||||
- [ ] **Step 4: 运行确认通过**
|
||||
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_order_extraction_conversation_title.py tests/test_shipping_conversation_title.py -v`
|
||||
Expected: 6 passed
|
||||
|
||||
- [ ] **Step 5: 回归既有 Run 用例**
|
||||
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_order_extraction_runs.py tests/test_shipping_order_extraction_concurrency.py -v`
|
||||
Expected: 全部 PASS(既有用例若断言了 `title == '订单抽取'`,仅允许把该断言放宽为「非空标题」并注明「标题已业务化」,其余逻辑禁改)
|
||||
|
||||
- [ ] **Step 6: 提交**
|
||||
|
||||
```bash
|
||||
git add backend/app/services/shipping_notice/order_extraction_run_service.py backend/tests/test_shipping_order_extraction_conversation_title.py
|
||||
git commit -m "feat(shipping-notice): 新建抽取会话按附件内容派生标题"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: 批次进度中心移除关闭入口 + 会话标题展示
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/chat/components/shipping/ShippingWorkflowTimeline.vue`(props/emits 定义约 71-75 行;头部模板约 861-890 行)
|
||||
- Test: `frontend/src/features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: 无。
|
||||
- Produces: 新 prop `conversationTitle?: string | null`(Task 4 传入);移除 `close` 事件(Task 4 同步移除监听);新增测试锚点 `data-testid="shipping-workflow-conversation-title"`。
|
||||
|
||||
- [ ] **Step 1: 更新/新增组件测试(先失败)**
|
||||
|
||||
在 `ShippingWorkflowTimeline.spec.ts` 中:
|
||||
|
||||
1a. 现有 mount 封装函数(返回 `mount(ShippingWorkflowTimeline, {...})`,约 104-113 行)改为支持透传额外 props(保持原函数名不变):
|
||||
|
||||
```ts
|
||||
function mountTimeline(
|
||||
processing: ConversationProcessingProjection | null,
|
||||
workItems: ShippingProcessingProjection[],
|
||||
extraProps: Record<string, unknown> = {},
|
||||
) {
|
||||
return mount(ShippingWorkflowTimeline, {
|
||||
attachTo: document.body,
|
||||
props: { conversationId: 'conv-1', controller: buildController(processing, workItems), ...extraProps },
|
||||
global: { plugins: [i18n], stubs: { teleport: true } },
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
1b. `describe` 内新增用例:
|
||||
|
||||
```ts
|
||||
it('has no close button and reuses the conversation title in the header', () => {
|
||||
const wrapper = mountTimeline(processingProjection(), [], { conversationTitle: 'PO#6075309 09-15' });
|
||||
|
||||
// 中心常驻不可关闭(方案 A):关闭按钮必须消失。
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-close"]').exists()).toBe(false);
|
||||
|
||||
// 会话标题直接复用侧栏命名,保持两处一致。
|
||||
const titleNode = wrapper.find('[data-testid="shipping-workflow-conversation-title"]');
|
||||
expect(titleNode.exists()).toBe(true);
|
||||
expect(titleNode.text()).toContain('PO#6075309 09-15');
|
||||
});
|
||||
|
||||
it('omits the title node when no conversation title is provided', () => {
|
||||
const wrapper = mountTimeline(processingProjection(), []);
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-conversation-title"]').exists()).toBe(false);
|
||||
});
|
||||
```
|
||||
|
||||
(若现有封装函数的参数名/默认 props 与上文不同,保持既有行为语义不变,仅追加 `extraProps` 透传能力。)
|
||||
|
||||
- [ ] **Step 2: 运行确认失败**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts`
|
||||
Expected: 新增第一个用例 FAIL(`shipping-workflow-close` 仍存在、`shipping-workflow-conversation-title` 不存在)
|
||||
|
||||
- [ ] **Step 3: 组件实现**
|
||||
|
||||
`ShippingWorkflowTimeline.vue`:
|
||||
|
||||
3a. props 定义(`conversationId` / `refreshTrigger` / `controller` 之后)新增:
|
||||
|
||||
```ts
|
||||
/** 当前会话标题;父级从侧栏历史匹配传入,中心头部直接复用(无新增接口)。 */
|
||||
conversationTitle?: string | null;
|
||||
```
|
||||
|
||||
3b. `defineEmits` 中删除 `close: [];`;随后 grep `emit(` 确认组件内无其余 emit 调用后,整体删除 `const emit = defineEmits<...>();` 块。
|
||||
|
||||
3c. 头部模板删除 × 关闭按钮整块:
|
||||
|
||||
```html
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md p-1.5 text-muted hover:bg-surface-muted hover:text-primary"
|
||||
data-testid="shipping-workflow-close"
|
||||
:title="t('chat.shippingProcessing.closeWorkbench')"
|
||||
@click="emit('close')"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
```
|
||||
|
||||
3d. 标题行(`panelTitle` 文本所在的 `flex items-center gap-1.5` div 内、`panelTitle` div 之后)新增:
|
||||
|
||||
```html
|
||||
<span
|
||||
v-if="conversationTitle"
|
||||
class="min-w-0 truncate rounded bg-surface-muted px-1.5 py-0.5 text-xs text-secondary"
|
||||
data-testid="shipping-workflow-conversation-title"
|
||||
:title="conversationTitle"
|
||||
>{{ conversationTitle }}</span>
|
||||
```
|
||||
|
||||
3e. 同步文件顶部块注释「标题栏仅保留批次名称、加载与截断提示」→「标题栏保留批次名称、会话标题、加载与截断提示;中心常驻不可关闭(方案 A)」。
|
||||
|
||||
- [ ] **Step 4: 运行确认通过**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts`
|
||||
Expected: 全部 PASS(含既有用例)
|
||||
|
||||
- [ ] **Step 5: 提交**
|
||||
|
||||
```bash
|
||||
git add frontend/src/features/chat/components/shipping/ShippingWorkflowTimeline.vue frontend/src/features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts
|
||||
git commit -m "feat(shipping-notice): 批次进度中心移除关闭入口并展示会话标题"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: `ChatViewContent` 规则坍缩为中心常驻
|
||||
|
||||
**Files:**
|
||||
- Create: `frontend/src/features/chat/shipping/shippingWorkbenchLayout.ts`
|
||||
- Modify: `frontend/src/features/chat/components/ChatViewContent.vue`(script 121-152 行、474-478 行、558/580 行、667-674 行、style 824-835 行、文件头注释 9-11 行)
|
||||
- Test: `frontend/src/features/chat/shipping/shippingWorkbenchLayout.spec.ts`(新建)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 3 的 `conversationTitle` prop;页面上下文已有 `page.displayHistory`(`DisplayHistoryItem[]`,含 `conversation_id` / `title` 字段,来自 `useChatSessions.ts:86`)。
|
||||
- Produces: `shouldShowShippingWorkbench(input: { isShippingNoticeAgent: boolean; conversationId: string | null | undefined }): boolean`;`ChatViewContent` 不再暴露 `open-batch-workbench` 监听与 `compact-shipping-progress` prop(Task 5 清理子组件侧)。
|
||||
|
||||
- [ ] **Step 1: 写纯判定函数的失败测试**
|
||||
|
||||
创建 `frontend/src/features/chat/shipping/shippingWorkbenchLayout.spec.ts`:
|
||||
|
||||
```ts
|
||||
/**
|
||||
* features/chat/shipping/shippingWorkbenchLayout.spec.ts
|
||||
* 用途:锁定货代会话主区域显隐规则(有会话即全屏批次进度中心,方案 A)。
|
||||
* 依赖:Vitest、纯函数。
|
||||
* 逻辑:判定必须同时满足货代智能体与非空会话 ID;普通智能体与新会话一律回落欢迎页。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { shouldShowShippingWorkbench } from './shippingWorkbenchLayout';
|
||||
|
||||
describe('shouldShowShippingWorkbench', () => {
|
||||
it('renders the workbench for the shipping agent once a conversation exists', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: 'conv-1' })).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps the welcome composer before a conversation is created', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: '' })).toBe(false);
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: null })).toBe(false);
|
||||
});
|
||||
|
||||
it('never switches other agents to the workbench', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: false, conversationId: 'conv-1' })).toBe(false);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
- [ ] **Step 2: 运行确认失败**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/shipping/shippingWorkbenchLayout.spec.ts`
|
||||
Expected: FAIL(模块不存在)
|
||||
|
||||
- [ ] **Step 3: 实现纯判定函数**
|
||||
|
||||
创建 `frontend/src/features/chat/shipping/shippingWorkbenchLayout.ts`:
|
||||
|
||||
```ts
|
||||
/**
|
||||
* features/chat/shipping/shippingWorkbenchLayout.ts
|
||||
* 用途:货代发货会话主区域显隐判定(批次进度中心优先,方案 A)。
|
||||
* 依赖:无(纯函数)。
|
||||
* 逻辑:货代智能体且存在非空会话 ID 时全屏渲染批次进度中心;
|
||||
* 否则(新会话欢迎页)显示欢迎页 + 输入框(唯一附件提交入口)。
|
||||
*/
|
||||
|
||||
export interface ShippingWorkbenchLayoutInput {
|
||||
isShippingNoticeAgent: boolean;
|
||||
conversationId: string | null | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定是否以批次进度中心作为会话主区域。
|
||||
* @param input - 智能体身份与当前会话 ID(路由 query 与 page 回填同源优先级)。
|
||||
* @returns true 表示全屏渲染批次进度中心;false 表示欢迎页 + 输入框。
|
||||
*/
|
||||
export function shouldShowShippingWorkbench(input: ShippingWorkbenchLayoutInput): boolean {
|
||||
return Boolean(input.isShippingNoticeAgent && String(input.conversationId || '').trim());
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 4: 运行确认通过**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/shipping/shippingWorkbenchLayout.spec.ts`
|
||||
Expected: 3 passed
|
||||
|
||||
- [ ] **Step 5: `ChatViewContent.vue` 接线**
|
||||
|
||||
5a. script 顶部 import 区新增:
|
||||
|
||||
```ts
|
||||
import { shouldShowShippingWorkbench } from '@/features/chat/shipping/shippingWorkbenchLayout';
|
||||
```
|
||||
|
||||
5b. 将 script 中 121-152 行整块(`batchWorkbenchOpen`、`showShippingWorkflowTimeline`、`compactShippingProgress`、`openBatchWorkbench`、`closeBatchWorkbench`、「批次中心只服务于用户主动打开时所在的会话」watcher)替换为:
|
||||
|
||||
```ts
|
||||
/**
|
||||
* 货代发货会话主区域规则(方案 A):
|
||||
* 有会话 ID → 全屏批次进度中心(常驻不可关闭);无会话 → 欢迎页 + 输入框(唯一提交入口)。
|
||||
*/
|
||||
const showShippingWorkflowTimeline = computed(() => shouldShowShippingWorkbench({
|
||||
isShippingNoticeAgent: page.isShippingNoticeAgent,
|
||||
conversationId: activeShippingConversationId.value,
|
||||
}));
|
||||
|
||||
/** 侧栏历史项中的会话标题;批次中心头部直接复用,保持侧栏与中心一致。 */
|
||||
const activeShippingConversationTitle = computed(() => (
|
||||
page.displayHistory.find((item) => item.conversation_id === activeShippingConversationId.value)?.title || ''
|
||||
));
|
||||
```
|
||||
|
||||
(原 watcher 的「切换会话关闭工作台」职责由中心自身按 `conversation-id` prop 重新加载数据取代,删除后无需替代逻辑。)
|
||||
|
||||
5c. 模板中 `ShippingWorkflowTimeline`(667-674 行)改为(删除 `@close`、新增标题 prop):
|
||||
|
||||
```html
|
||||
<ShippingWorkflowTimeline
|
||||
v-if="showShippingWorkflowTimeline"
|
||||
:conversation-id="activeShippingConversationId"
|
||||
:conversation-title="activeShippingConversationTitle"
|
||||
:refresh-trigger="page.workflowRefreshTrigger"
|
||||
:controller="shippingProcessing"
|
||||
/>
|
||||
```
|
||||
|
||||
5d. 模板 476-478 行两个包裹 div 移除工作台条件 class(中心 `flex-1` 自然占满,无需压缩列):
|
||||
|
||||
```html
|
||||
<div v-else class="flex min-h-0 min-w-0 flex-1">
|
||||
```
|
||||
|
||||
```html
|
||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
```
|
||||
|
||||
5e. 删除 `<ChatMessageList>` 上的 `:compact-shipping-progress="compactShippingProgress"`(558 行)与 `@open-batch-workbench="openBatchWorkbench"`(580 行)两行。
|
||||
|
||||
5f. 删除文件底部 `<style scoped>` 中 `@media (min-width: 1024px)` 整块(`.shipping-workbench-layout` / `.shipping-chat-column`);若 style 块因此为空则连 `<style scoped>` 标签一并删除。
|
||||
|
||||
5g. 文件头块注释(9-11 行)「右侧『本次处理』由 conversationId 驱动…」改写为「货代会话主区域:有会话即全屏批次进度中心(常驻),无会话为欢迎页+输入框;会话标题取自侧栏历史并传给中心」。
|
||||
|
||||
- [ ] **Step 6: 类型与测试门禁**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/shipping/shippingWorkbenchLayout.spec.ts src/features/chat/components/shipping/ShippingWorkflowTimeline.spec.ts && npm run build`
|
||||
Expected: 测试全绿、build 通过(此时 `ChatMessageList` 仍声明但无人传 `compact-shipping-progress`、`open-batch-workbench`,属合法中间态,Task 5 清理)
|
||||
|
||||
- [ ] **Step 7: 提交**
|
||||
|
||||
```bash
|
||||
git add frontend/src/features/chat/shipping/shippingWorkbenchLayout.ts frontend/src/features/chat/shipping/shippingWorkbenchLayout.spec.ts frontend/src/features/chat/components/ChatViewContent.vue
|
||||
git commit -m "feat(shipping-notice): 货代会话主区域切换为批次中心常驻"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: 移除 `open-batch-workbench` / `compactShippingProgress` 冗余链路
|
||||
|
||||
**Files:**
|
||||
- Modify: `frontend/src/features/chat/components/ChatMessageList.vue`(props 57 行、emits 71 行、模板 210/220 行)
|
||||
- Modify: `frontend/src/features/chat/components/messages/ChatMessageBubble.vue`(props 78 行、emits 92 行、模板 750/754 行)
|
||||
- Modify: `frontend/src/features/chat/components/shipping/ShippingOrderExtractionCard.vue`(props `compactProgress` 约 50-52 行、emits 约 55 行、lucide import 15 行、CTA 模板块约 947-960 行)
|
||||
- Test: `frontend/src/features/chat/components/shipping/ShippingOrderExtractionCard.spec.ts`(77、111-124、829、917、959 行附近)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 4 已移除父级监听/传参。
|
||||
- Produces: `ShippingOrderExtractionCard` 对外不再有 `open-batch-workbench` 事件与 `compactProgress` prop;消息链不再透传两者。组件其余能力(状态卡渲染/重试/刷新/取消)全部保留。
|
||||
|
||||
- [ ] **Step 1: 更新卡片测试(先失败)**
|
||||
|
||||
`ShippingOrderExtractionCard.spec.ts`:
|
||||
|
||||
1a. 77、829、917、959 行四处 `expect(wrapper.get('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(true);` 全部改为:
|
||||
|
||||
```ts
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
```
|
||||
|
||||
1b. 删除用例 `collapses file-level progress when the batch workbench is open`(约 111-124 行,`compactProgress` prop 已不存在,紧凑模式语义随之移除)。
|
||||
|
||||
- [ ] **Step 2: 运行确认失败**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping/ShippingOrderExtractionCard.spec.ts`
|
||||
Expected: 1a 改动后的四处断言 FAIL(按钮仍渲染)
|
||||
|
||||
- [ ] **Step 3: 删除链路实现**
|
||||
|
||||
3a. `ShippingOrderExtractionCard.vue`:
|
||||
- 删除 CTA 整块(外层 `div.flex.justify-end.border-t.border-default.bg-brand-50\/60.p-3` 连同内部「打开批次进度中心」按钮,约 947-960 行);
|
||||
- emits 定义删除 `'open-batch-workbench': [];`;props 删除 `compactProgress?: boolean;` 及其注释行;
|
||||
- 文件内 grep `ArrowRight`:仅按钮在用时从 lucide import 中移除;
|
||||
- 文件头块注释「唯一主 CTA、查看详情」与「批次工作台打开后切换为紧凑摘要」改为「无对话流 CTA(批次中心常驻,方案 A)」。
|
||||
|
||||
3b. `ChatMessageBubble.vue`:props 删除 `compactShippingProgress?: boolean;`(78 行);emits 删除 `'open-batch-workbench': [];`(92 行);模板删除 `:compact-progress="compactShippingProgress"`(750 行)与 `@open-batch-workbench="emit('open-batch-workbench')"`(754 行)。
|
||||
|
||||
3c. `ChatMessageList.vue`:props 删除 `compactShippingProgress?: boolean;`(57 行);emits 删除 `'open-batch-workbench': [];`(71 行);模板删除 `:compact-shipping-progress="compactShippingProgress"`(210 行)与 `@open-batch-workbench="emit('open-batch-workbench')"`(220 行)。
|
||||
|
||||
3d. 三处文件头块注释若提及 CTA/紧凑模式,同步为「对话流仅保留状态卡渲染(历史兜底),批次中心入口已移除(方案 A)」。
|
||||
|
||||
- [ ] **Step 4: 运行确认通过**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping/ShippingOrderExtractionCard.spec.ts && npm run build`
|
||||
Expected: 卡片 spec 全绿;build 通过(无未使用变量/导入的 TS 报错)
|
||||
|
||||
- [ ] **Step 5: 相关组件回归**
|
||||
|
||||
Run: `cd frontend && npx vitest run src/features/chat`
|
||||
Expected: chat 域全部 spec 通过(重点:`ChatMessageList` 相关、`ShippingConversationProcessingCard.spec.ts`、`ChatViewContent` 无既有 spec 不受影响)
|
||||
|
||||
- [ ] **Step 6: 提交**
|
||||
|
||||
```bash
|
||||
git add frontend/src/features/chat/components/ChatMessageList.vue frontend/src/features/chat/components/messages/ChatMessageBubble.vue frontend/src/features/chat/components/shipping/ShippingOrderExtractionCard.vue frontend/src/features/chat/components/shipping/ShippingOrderExtractionCard.spec.ts
|
||||
git commit -m "refactor(shipping-notice): 移除对话流打开批次中心冗余链路"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: 文档同步与全量门禁
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/funclist.md`(货代发货功能清单小节)
|
||||
- Modify: `docs/features/shipping-notice/technical.md`(交互链路章节)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1-5 的最终行为。
|
||||
- Produces: 与代码一致的文档(AGENTS.md §9 强制)。
|
||||
|
||||
- [ ] **Step 1: 更新 `docs/funclist.md`**
|
||||
|
||||
`grep -n "货代发货" docs/funclist.md` 定位小节;`grep -n "打开批次进度中心\|批次进度" docs/funclist.md` 找到既有相关行。在该小节新增两行(沿用本文件既有条目格式,列表或表格随原文):
|
||||
|
||||
```
|
||||
- 货代发货会话主区域为批次进度中心:有会话即全屏常驻展示(不可关闭),无会话显示欢迎页与附件提交入口;历史会话点击直达中心
|
||||
- 新建订单抽取会话自动按首个附件文件名命名(剥离邮件前缀 + 等 N 个文件 + 日期后缀);存量会话名不变
|
||||
```
|
||||
|
||||
既有「打开批次进度中心」相关条目改为「(已下线对话流入口,批次中心为会话主区域)」措辞,不删除历史行文风格。
|
||||
|
||||
- [ ] **Step 2: 更新 `docs/features/shipping-notice/technical.md`**
|
||||
|
||||
`grep -n "批次进度中心\|openBatchWorkbench\|batchWorkbenchOpen" docs/features/shipping-notice/technical.md` 定位相关章节,更新/新增如下要点(跟随原文档章节结构,不另起重复章节):
|
||||
|
||||
```markdown
|
||||
### 会话主区域与批次进度中心(2026-09 方案 A)
|
||||
|
||||
- 货代发货智能体主区域规则:`isShippingNoticeAgent && conversation_id 非空` → 全屏渲染批次进度中心
|
||||
(`ShippingWorkflowTimeline`,常驻无关闭按钮);否则渲染欢迎页 + 输入框(唯一附件提交入口)。
|
||||
判定纯函数:`frontend/src/features/chat/shipping/shippingWorkbenchLayout.ts`。
|
||||
- 提交链路不变:`startRun` 成功 → 路由写回 `conversation_id` → 中心出现;对话流不再出现
|
||||
「本次订单文件处理」卡片入口,`open-batch-workbench` / `compact-shipping-progress` 链路已移除;
|
||||
`ShippingOrderExtractionCard` 保留为历史消息兜底渲染。
|
||||
- 中心头部复用会话标题(父级从侧栏 `displayHistory` 按 conversation_id 匹配传入 `conversation-title`)。
|
||||
- 新建抽取会话命名:`backend/app/services/shipping_notice/conversation_title.py`
|
||||
`derive_order_extraction_title(filenames, created_at)` —— 首个非空文件名去扩展名、剥离
|
||||
Re:/Fw:/Fwd:/回复:/转发:前缀、截 24 字、多文件追加「等 N 个文件」、追加 MM-DD;
|
||||
全空回退「订单抽取」。仅在 `_resolve_conversation` 新建分支调用;存量会话标题一律不改。
|
||||
- 同批次追加附件:中心不提供入口,通过「新建对话」重新提交(后端 append/create 裁决逻辑不变)。
|
||||
```
|
||||
|
||||
- [ ] **Step 3: 全量门禁**
|
||||
|
||||
Run: `cd frontend && npm run build`
|
||||
Expected: 构建通过
|
||||
Run: `cd backend && python -m pytest tests/test_shipping_conversation_title.py tests/test_shipping_order_extraction_conversation_title.py tests/test_shipping_order_extraction_runs.py -v`
|
||||
Expected: 全部 PASS
|
||||
|
||||
- [ ] **Step 4: 提交**
|
||||
|
||||
```bash
|
||||
git add docs/funclist.md docs/features/shipping-notice/technical.md
|
||||
git commit -m "docs(shipping-notice): 同步批次中心优先与会话命名说明"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 验收核对(对照 spec §8)
|
||||
|
||||
1. 新会话发附件 → 提交成功后全屏批次进度中心,无对话卡、无关闭按钮(Task 3/4);
|
||||
2. 历史会话点击 → 直达该会话中心(Task 4 规则天然覆盖);
|
||||
3. 新批次会话名形如 `PO#6075309 for HOXIN 等 2 个文件 09-15`;存量名不变(Task 1/2);
|
||||
4. 普通智能体零变化;前端 build 与后端相关 pytest 全绿(Task 4-6)。
|
||||
@@ -0,0 +1,146 @@
|
||||
# 设计:货代发货批次进度中心优先(对话视图退役)+ 会话业务命名
|
||||
|
||||
日期:2026-09-17 分支:`hugo-shipping-notice`
|
||||
状态:已与需求方确认方向(方案 A + 命名仅新建会话时生效),待评审
|
||||
|
||||
## 1. 背景与问题
|
||||
|
||||
货代发货智能体(shipping notice)当前提交附件后的体验链路为:
|
||||
|
||||
1. 对话流出现「本次订单文件处理」摘要卡(`ShippingOrderExtractionCard`);
|
||||
2. 用户手动点击卡上「打开批次进度中心」→ 右侧渲染 `ShippingWorkflowTimeline`,
|
||||
左侧对话列压缩为 `clamp(360px, 32vw, 520px)` 但仍可见。
|
||||
|
||||
问题:
|
||||
|
||||
- 批次信息在对话流与批次进度中心**重复展示两遍**,用户不需要对话视图;
|
||||
- 侧栏历史会话名全部写死为「订单抽取」(`order_extraction_run_service.py` 新建
|
||||
`ChatSession` 时 `title='订单抽取'`),多条批次完全无法区分;
|
||||
- 全站没有会话改名入口。
|
||||
|
||||
## 2. 已确认的设计决策(需求方拍板)
|
||||
|
||||
| 决策点 | 结论 |
|
||||
| --- | --- |
|
||||
| 批次中心打开期间对话窗口 | 整体隐藏,中心占满主区域 |
|
||||
| 中心是否可关闭 | 不提供关闭;打开后常驻 |
|
||||
| 自动打开触发范围 | 每次提交后中心即呈现;因不可关闭,实际等价于「有会话即中心」 |
|
||||
| 历史会话回访 | 直接进入该会话的批次进度中心,不展示消息流 |
|
||||
| 同批次追加附件 | 中心不提供上传入口;新文件走「新建对话」重新提交 |
|
||||
| 会话命名 | 规则化业务命名(PO/主题 + 文件数 + 日期),**仅新建会话时生效**;存量「订单抽取」不处理、不做手动改名(如后续有需要另起设计) |
|
||||
|
||||
## 3. 方案 A:对话视图退役(前端)
|
||||
|
||||
### 3.1 目标规则
|
||||
|
||||
货代智能体主区域显示逻辑坍缩为一条:
|
||||
|
||||
```
|
||||
isShippingNoticeAgent && activeShippingConversationId 非空 → 全屏渲染批次进度中心
|
||||
否则(新会话欢迎页) → 欢迎页 + 输入框(唯一提交入口)
|
||||
```
|
||||
|
||||
- `ChatViewContent.vue`:删除 `batchWorkbenchOpen` / `openBatchWorkbench` /
|
||||
`closeBatchWorkbench` / `compactShippingProgress` 状态与函数;
|
||||
`showShippingWorkflowTimeline` 改为上式的纯计算属性;删除
|
||||
`@open-batch-workbench` 监听与「切换会话/Agent 关闭工作台」的 watcher;
|
||||
删除 `<style>` 中 `.shipping-workbench-layout` / `.shipping-chat-column`
|
||||
压缩列样式(中心 `flex-1` 天然占满)。
|
||||
- `ShippingWorkflowTimeline.vue`:移除标题栏 × 关闭按钮与 `close` 事件
|
||||
(`ChatViewContent` 不再监听)。
|
||||
- `ChatMessageList.vue` / `ChatMessageBubble.vue`:移除 `compact-shipping-progress`
|
||||
prop 透传链与 `open-batch-workbench` emit 链。
|
||||
- 提交链路不变:`startRun` 成功 → `onConversationResolved` 写回路由
|
||||
`conversation_id` → 中心自动出现;中间的「本次订单文件处理」对话卡态不再可见。
|
||||
|
||||
### 3.2 保留与删除边界
|
||||
|
||||
- **保留**:`ShippingOrderExtractionCard` 及货代消息渲染链(含
|
||||
`shipping-match-result` 等历史类型)原样保留、不再可达。理由:本地消息仍照常
|
||||
落库(`saveLocalMessageToBackend`),数据完整性不受影响;渲染链保留为兜底与
|
||||
可回滚点,不在本次范围内做大段删除。后续若中心优先稳定,可另起清理任务。
|
||||
- **保留**:输入框与上传链路(欢迎页提交的唯一入口);`order-review` 复核工作台
|
||||
路由模式(`mode=order-review`)不受影响,仍由中心阶段动作导航进入。
|
||||
- **删除**:仅「打开批次进度中心」按钮及上述状态机/样式/emit 链。
|
||||
|
||||
### 3.3 已知边界(接受)
|
||||
|
||||
- 货代智能体里直接发送纯文本:回复不再有展示区。按「运营工具而非聊天」定位接受;
|
||||
输入框行为不变(仍可发送,数据照常保存)。
|
||||
- 移动端与桌面端同样适用「有会话即中心」;原压缩列样式仅桌面生效,删除后无回归面。
|
||||
|
||||
## 4. 会话业务命名(后端,仅新建会话)
|
||||
|
||||
### 4.1 规则化命名
|
||||
|
||||
新模块 `backend/app/services/shipping_notice/conversation_title.py`,纯函数:
|
||||
|
||||
```python
|
||||
derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str
|
||||
```
|
||||
|
||||
规则(按序):
|
||||
|
||||
1. 取首个文件名(EML 或 direct_pdf 资产文件名),去扩展名;
|
||||
2. 去邮件前缀:`Re:` `Fw:` `Fwd:` `回复:` `转发:`(循环剥离,大小写不敏感);
|
||||
3. 截断至 24 字符(字符安全截断);
|
||||
4. 文件数 > 1 时追加 `等 N 个文件`;
|
||||
5. 追加 ` MM-DD`(提交日,服务器 UTC 不换算,直接取 `created_at`)消歧;
|
||||
6. 文件名全空时回退 `订单抽取`;总长钳制 ≤ 60 字符。
|
||||
|
||||
落点:`_resolve_conversation` **新建** `ChatSession` 时以本次冻结 intakes 的资产
|
||||
文件名推导 `title`(intakes 在事务内已在手,不产生额外查询)。已存在的会话一律
|
||||
不改动标题(含标题仍为「订单抽取」的存量会话)。标题是内容派生文本而非 UI 文案,
|
||||
与现状写死中文标题一致,不进 i18n。
|
||||
|
||||
### 4.2 批次中心头部复用
|
||||
|
||||
`ShippingWorkflowTimeline` 新增 `conversationTitle` prop,由 `ChatViewContent`
|
||||
从 `page.displayHistory` 按 `conversation_id` 匹配取 `title` 传入,不新增接口;
|
||||
标题为空时维持现有占位。
|
||||
|
||||
## 5. 非目标
|
||||
|
||||
- 不删除 `ShippingOrderExtractionCard` 及货代消息渲染链(见 3.2);
|
||||
- 不做惰性回填:存量「订单抽取」标题不处理、不更新(含追加提交场景);
|
||||
- 不做会话手动改名(改名 API 与侧栏改名入口均不做);
|
||||
- 不做 LLM 标题生成;不引入新依赖;
|
||||
- 无数据库结构变更、无 Alembic 迁移、无环境变量变更;
|
||||
- 不改动提交/抽取/投影后端链路(仅 `_resolve_conversation` 新建会话标题);
|
||||
- 我的待办页(`/workspace/shipping-notice/my-tasks`)改版另行推进,不在本设计内。
|
||||
|
||||
## 6. 测试策略
|
||||
|
||||
后端(pytest):
|
||||
|
||||
- `conversation_title` 纯函数:前缀剥离、截断、N>1 后缀、日期、空回退、长度钳制;
|
||||
- `_resolve_conversation`:新建会话标题派生;已存在会话标题一律不变(含
|
||||
「订单抽取」存量)。
|
||||
|
||||
前端(vitest,新建/扩展现有 spec 文件):
|
||||
|
||||
- `ChatViewContent`:货代 + 有 conversationId → 渲染中心;无 → 欢迎页;普通智能体
|
||||
不受影响;
|
||||
- `ShippingWorkflowTimeline`:无关闭按钮;头部批次名展示;
|
||||
- 更新受影响断言:`ShippingOrderExtractionCard.spec.ts`(移除
|
||||
`open-batch-workbench` 按钮用例)、涉及 `compact-shipping-progress` 的用例。
|
||||
|
||||
构建门禁:`cd frontend && npm run build` 通过;后端相关 pytest 绿。
|
||||
|
||||
## 7. 文档同步(与代码同一提交/PR)
|
||||
|
||||
- `docs/funclist.md`:货代发货下新增「批次进度中心为会话主界面」「新建批次会话
|
||||
按附件内容自动命名」条目,调整原「打开批次进度中心」描述;
|
||||
- `docs/features/shipping-notice/technical.md`:更新交互链路章节(提交 → 中心)、
|
||||
会话标题推导规则;
|
||||
- i18n:无新增文案(本次仅删除「打开批次进度中心」入口,无新 UI 文本;遗留
|
||||
unused key 清理交由后续清理任务)。
|
||||
|
||||
## 8. 验收标准
|
||||
|
||||
1. 货代智能体新会话发送附件 → 提交成功后主区域直接全屏显示批次进度中心,
|
||||
全程不出现「本次订单文件处理」对话卡;中心无关闭按钮;
|
||||
2. 侧栏点开历史「批次」会话 → 直接进入该会话的中心;
|
||||
3. 新提交创建的批次会话名形如 `PO#6075309 for Vendor#10804 等 11 个文件 09-15`,
|
||||
同日多批次可区分;存量会话名保持原样;
|
||||
4. 普通智能体(通用入口等)聊天体验零变化;`npm run build` 与相关测试全绿。
|
||||
@@ -54,7 +54,6 @@ const {
|
||||
pinMessagesToBottom?: boolean;
|
||||
/** 供父级滚动逻辑绑定 main 元素 */
|
||||
scrollContainerHolder: { el: Ref<HTMLElement | null> };
|
||||
compactShippingProgress?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -68,7 +67,6 @@ const emit = defineEmits<{
|
||||
'maintenance-edit-record': [record: MaintenanceRecord];
|
||||
'maintenance-view-record-history': [device: MaintenanceDevice];
|
||||
'maintenance-create-record-for-device': [device: MaintenanceDevice];
|
||||
'open-batch-workbench': [];
|
||||
/** 在途仓自动调拨:业务流激活时向上冒泡,父级据此隐藏聊天输入框。 */
|
||||
'transfer-flow-active': [active: boolean];
|
||||
}>();
|
||||
@@ -207,7 +205,6 @@ const hasFollowingShippingProgressCard = (items: ChatMessage[], index: number):
|
||||
:leave-handlers="leaveHandlers"
|
||||
:shipping-handlers="shippingHandlers"
|
||||
:training-handlers="trainingHandlers"
|
||||
:compact-shipping-progress="compactShippingProgress"
|
||||
:attachment-summary-only="hasFollowingShippingProgressCard(messages, index)"
|
||||
@copy="emit('copy', { message: msg, index })"
|
||||
@edit="emit('edit', $event)"
|
||||
@@ -217,7 +214,6 @@ const hasFollowingShippingProgressCard = (items: ChatMessage[], index: number):
|
||||
@maintenance-edit-record="emit('maintenance-edit-record', $event)"
|
||||
@maintenance-view-record-history="emit('maintenance-view-record-history', $event)"
|
||||
@maintenance-create-record-for-device="emit('maintenance-create-record-for-device', $event)"
|
||||
@open-batch-workbench="emit('open-batch-workbench')"
|
||||
/>
|
||||
<ToolRunProgressCard
|
||||
v-if="shouldRenderMessage(msg) && shouldShowToolRunProgressAfterMessage(msg, index)"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* 依赖:ChatSidebar、ChatMessageList、ChatInputBar、ShippingWorkflowTimeline、chat.context。
|
||||
|
||||
* 逻辑:本文件只做页面结构编排;货代 Chat 仅上传/进度通知,履约写操作不在本页;
|
||||
* 右侧「本次处理」由 conversationId 驱动 Workflow projection,extractionRunNo 仅作进度装饰;
|
||||
* 货代会话主区域:有会话即全屏批次进度中心(常驻),无会话为欢迎页+输入框;会话标题取自侧栏历史并传给中心;
|
||||
* 订单复核工作台异步分包,避免普通对话首屏拉取 PDF.js。
|
||||
|
||||
*/
|
||||
@@ -34,6 +34,8 @@ import ChatBrowserPanel from '@/features/chat/components/ChatBrowserPanel.vue';
|
||||
|
||||
import ShippingWorkflowTimeline from '@/features/chat/components/shipping/ShippingWorkflowTimeline.vue';
|
||||
|
||||
import { shouldShowShippingWorkbench } from '@/features/chat/shipping/shippingWorkbenchLayout';
|
||||
|
||||
import TrainingWorkspacePanel from '@/features/chat/components/TrainingWorkspacePanel.vue';
|
||||
|
||||
import LedgerConfigPanel from '@/features/maintenance/components/LedgerConfigPanel.vue';
|
||||
@@ -118,38 +120,19 @@ const isInTransitTransferAgent = computed(() => resolveAgentCode(page.currentAge
|
||||
const transferFlowActive = ref(false);
|
||||
watch(isInTransitTransferAgent, (isTransfer) => { if (!isTransfer) transferFlowActive.value = false; });
|
||||
|
||||
/** 批次进度工作台按需打开;关闭时不占用对话区右侧布局。 */
|
||||
const batchWorkbenchOpen = ref(false);
|
||||
|
||||
|
||||
|
||||
const showShippingWorkflowTimeline = computed(() => (
|
||||
page.isShippingNoticeAgent
|
||||
&& batchWorkbenchOpen.value
|
||||
&& Boolean(activeShippingConversationId.value)
|
||||
));
|
||||
|
||||
const compactShippingProgress = computed(() => batchWorkbenchOpen.value);
|
||||
|
||||
function openBatchWorkbench() {
|
||||
batchWorkbenchOpen.value = true;
|
||||
}
|
||||
|
||||
function closeBatchWorkbench() {
|
||||
batchWorkbenchOpen.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批次中心只服务于用户主动打开时所在的会话。切换历史会话或 Agent 后必须关闭,
|
||||
* 否则旧会话的右侧投影会短暂占用新会话的对话区并造成“本次处理”串批错觉。
|
||||
* 货代发货会话主区域规则(方案 A):
|
||||
* 有会话 ID → 全屏批次进度中心(常驻不可关闭);无会话 → 欢迎页 + 输入框(唯一提交入口)。
|
||||
*/
|
||||
watch(
|
||||
() => [activeShippingConversationId.value, Number(page.currentAgentId || 0)] as const,
|
||||
(next, previous) => {
|
||||
if (!previous || next[0] === previous[0] && next[1] === previous[1]) return;
|
||||
batchWorkbenchOpen.value = false;
|
||||
},
|
||||
);
|
||||
const showShippingWorkflowTimeline = computed(() => shouldShowShippingWorkbench({
|
||||
isShippingNoticeAgent: page.isShippingNoticeAgent,
|
||||
conversationId: activeShippingConversationId.value,
|
||||
}));
|
||||
|
||||
/** 侧栏历史项中的会话标题;批次中心头部直接复用,保持侧栏与中心一致。 */
|
||||
const activeShippingConversationTitle = computed(() => (
|
||||
page.displayHistory.find((item) => item.conversation_id === activeShippingConversationId.value)?.title || ''
|
||||
));
|
||||
|
||||
const embeddedIframeSrc = computed(() => {
|
||||
|
||||
@@ -473,9 +456,10 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
<ShippingOrderReviewView v-if="isOrderReviewMode" />
|
||||
|
||||
<div v-else class="flex min-h-0 min-w-0 flex-1" :class="showShippingWorkflowTimeline ? 'shipping-workbench-layout' : ''">
|
||||
<div v-else class="flex min-h-0 min-w-0 flex-1">
|
||||
|
||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col" :class="showShippingWorkflowTimeline ? 'shipping-chat-column' : ''">
|
||||
<!-- 中心展示时对话列整体隐藏(含输入框),新文件提交走新建对话(spec 方案 A 硬性决策)。 -->
|
||||
<div v-show="!showShippingWorkflowTimeline" class="flex min-h-0 min-w-0 flex-1 flex-col">
|
||||
|
||||
<TrainingWorkspacePanel
|
||||
|
||||
@@ -555,8 +539,6 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
:scroll-container-holder="page.scrollContainerHolder"
|
||||
|
||||
:compact-shipping-progress="compactShippingProgress"
|
||||
|
||||
@copy="page.copyToClipboard($event.message, $event.index)"
|
||||
|
||||
@edit="page.input = $event"
|
||||
@@ -577,8 +559,6 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
@maintenance-create-record-for-device="openMaintenanceRecordCreate"
|
||||
|
||||
@open-batch-workbench="openBatchWorkbench"
|
||||
|
||||
@transfer-flow-active="transferFlowActive = $event"
|
||||
|
||||
/>
|
||||
@@ -667,10 +647,9 @@ watch(() => page.currentAgentId, () => {
|
||||
<ShippingWorkflowTimeline
|
||||
v-if="showShippingWorkflowTimeline"
|
||||
:conversation-id="activeShippingConversationId"
|
||||
:conversation-title="activeShippingConversationTitle"
|
||||
:refresh-trigger="page.workflowRefreshTrigger"
|
||||
:controller="shippingProcessing"
|
||||
|
||||
@close="closeBatchWorkbench"
|
||||
/>
|
||||
|
||||
|
||||
@@ -821,16 +800,3 @@ watch(() => page.currentAgentId, () => {
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/** 打开批次工作台后,左侧对话保留为压缩入口,右侧取得主工作区宽度。 */
|
||||
@media (min-width: 1024px) {
|
||||
.shipping-workbench-layout {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.shipping-chat-column {
|
||||
flex: 0 0 clamp(360px, 32vw, 520px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -75,7 +75,6 @@ const {
|
||||
leaveHandlers: LeaveMessageHandlers;
|
||||
shippingHandlers: ShippingMessageHandlers;
|
||||
trainingHandlers: TrainingHandlers;
|
||||
compactShippingProgress?: boolean;
|
||||
/** 下方已有货代进度卡时,用户气泡附件只显示摘要。 */
|
||||
attachmentSummaryOnly?: boolean;
|
||||
}>();
|
||||
@@ -89,7 +88,6 @@ const emit = defineEmits<{
|
||||
'maintenance-edit-record': [record: MaintenanceRecord];
|
||||
'maintenance-view-record-history': [device: MaintenanceDevice];
|
||||
'maintenance-create-record-for-device': [device: MaintenanceDevice];
|
||||
'open-batch-workbench': [];
|
||||
}>();
|
||||
|
||||
const authStore = useAuthStore();
|
||||
@@ -747,11 +745,9 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
:retrying="retryingOrderExtraction"
|
||||
:refreshing="refreshingOrderExtraction"
|
||||
:cancelling="cancellingOrderExtraction"
|
||||
:compact-progress="compactShippingProgress"
|
||||
@retry="retryShippingOrderExtraction"
|
||||
@refresh="refreshShippingOrderExtraction"
|
||||
@cancel="cancelShippingOrderExtraction"
|
||||
@open-batch-workbench="emit('open-batch-workbench')"
|
||||
/>
|
||||
<LeaveMessageBlock
|
||||
v-if="isLeaveMessage"
|
||||
|
||||
+12
-16
@@ -74,7 +74,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(wrapper.get('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(true);
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('does not present historical handling items or CTA as current work when the live projection exists', () => {
|
||||
@@ -115,16 +116,6 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-primary-action"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('collapses file-level progress when the batch workbench is open', () => {
|
||||
const wrapper = mount(ShippingOrderExtractionCard, {
|
||||
props: { state: buildState(), runNo: 'SNER-COMPACT', compactProgress: true },
|
||||
global: { plugins: [i18n], provide: { [SHIPPING_WORKFLOW_KEY as symbol]: { processingWorkItems: ref([]) } } },
|
||||
});
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-status-groups"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('uses unified EML aggregation and keeps candidate creation out of completed', async () => {
|
||||
const aggregate = {
|
||||
workItemType: 'order_task', workItemNo: 'INTAKE:SNI-1', sourceType: 'eml', rootOrderTaskNo: 'OT-1',
|
||||
@@ -643,7 +634,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
expect(wrapper.text()).toContain('3 个文件');
|
||||
expect(wrapper.text()).toContain('系统处理中');
|
||||
expect(wrapper.text()).toContain('处理时间偏长');
|
||||
expect(wrapper.text()).toContain('打开批次进度中心');
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.text()).not.toContain('打开批次进度中心');
|
||||
expect(wrapper.text()).not.toContain('刷新状态');
|
||||
expect(wrapper.text()).not.toContain('取消本次识别');
|
||||
expect(wrapper.text()).not.toContain('PO-450003.pdf');
|
||||
@@ -731,7 +723,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
});
|
||||
expect(wrapper.text()).toContain('订单候选已生成');
|
||||
expect(wrapper.text()).toContain('候选待人工确认 · 2 项');
|
||||
expect(wrapper.text()).toContain('打开批次进度中心');
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.text()).not.toContain('打开批次进度中心');
|
||||
expect(wrapper.text()).not.toContain('部分附件需人工处理');
|
||||
expect(wrapper.findAll('[data-testid="shipping-order-extraction-handling-item"]').length).toBe(0);
|
||||
});
|
||||
@@ -826,7 +819,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
});
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-primary-action"]').exists()).toBe(false);
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-view-details"]').exists()).toBe(false);
|
||||
expect(wrapper.get('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(true);
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('does not render multi-OT ChatProgressSummary list', () => {
|
||||
@@ -914,7 +908,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
global: { plugins: [i18n] },
|
||||
});
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-primary-action"]').exists()).toBe(false);
|
||||
expect(wrapper.get('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(true);
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('does not render the removed view details link', () => {
|
||||
@@ -956,7 +951,8 @@ describe('ShippingOrderExtractionCard', () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(wrapper.get('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(true);
|
||||
// 方案 A:中心常驻后,对话流不再提供「打开批次进度中心」入口(回归保护:按钮不得复活)。
|
||||
expect(wrapper.find('[data-testid="shipping-order-extraction-open-batch-workbench"]').exists()).toBe(false);
|
||||
expect(wrapper.text()).toContain('共 1 个文件');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* features/chat/components/shipping/ShippingOrderExtractionCard.vue
|
||||
* 用途:聊天主区「本次订单文件处理」摘要卡——标题、文件数+状态、一行 handling 摘要、唯一主 CTA、查看详情。
|
||||
* 用途:聊天主区「本次订单文件处理」摘要卡——标题、文件数+状态、一行 handling 摘要、无对话流 CTA(批次中心常驻,方案 A)。
|
||||
* 依赖:订单抽取 Run 状态卡 DTO、shipping.api 文档/进度接口、ShippingOrderExtractionDetailsDrawer、vue-router、vue-i18n。
|
||||
* 逻辑:对话区默认展示状态-EML 聚合;批次工作台打开后切换为紧凑摘要,长进度/Gate/刷新取消由工作台承接。
|
||||
* 逻辑:对话区默认展示状态-EML 聚合;无对话流 CTA(批次中心常驻,方案 A),长进度/Gate/刷新取消由工作台承接。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { AlertCircle, ArrowRight, CheckCircle2, ChevronDown, CircleX, FileText, LoaderCircle, Mail, RefreshCw, TriangleAlert } from 'lucide-vue-next';
|
||||
import { AlertCircle, CheckCircle2, ChevronDown, CircleX, FileText, LoaderCircle, Mail, RefreshCw, TriangleAlert } from 'lucide-vue-next';
|
||||
import type {
|
||||
ShippingOrderExtractionHandlingItemState,
|
||||
ShippingOrderExtractionFileState,
|
||||
@@ -44,15 +44,12 @@ const props = defineProps<{
|
||||
readonlyReason?: string | null;
|
||||
/** 可选统一投影;摘要卡不再渲染进度,仅保留 prop 兼容宿主。 */
|
||||
processingProjection?: ShippingProcessingProjection | null;
|
||||
/** 批次工作台打开时,左侧只保留摘要,避免与工作台重复展示文件明细。 */
|
||||
compactProgress?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
retry: [];
|
||||
refresh: [];
|
||||
cancel: [reason?: string];
|
||||
'open-batch-workbench': [];
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
@@ -425,7 +422,6 @@ const hasAnyStatusGroupTask = computed(() => (
|
||||
*/
|
||||
const recognizingPlaceholderVisible = computed(() => (
|
||||
hasConversationStatusGroups.value
|
||||
&& !props.compactProgress
|
||||
&& !hasAnyStatusGroupTask.value
|
||||
&& (submittedFileCount.value ?? 0) > 0
|
||||
));
|
||||
@@ -850,7 +846,7 @@ async function onPrimaryChatAction() {
|
||||
<div v-if="handlingSummaryLine && !hasConversationStatusGroups" class="mt-1 text-sm text-secondary">{{ handlingSummaryLine }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="hasConversationStatusGroups && !compactProgress" class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-status-groups">
|
||||
<div v-if="hasConversationStatusGroups" class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-status-groups">
|
||||
<div v-if="recognizingPlaceholderVisible" class="flex items-center gap-2 rounded-lg border border-default bg-surface p-3 text-sm text-muted">
|
||||
<LoaderCircle class="h-4 w-4 animate-spin text-brand-500" />
|
||||
<span data-testid="shipping-order-extraction-recognizing-placeholder">{{ t('chat.shippingProcessing.recognizingAttachments') }}</span>
|
||||
@@ -899,7 +895,7 @@ async function onPrimaryChatAction() {
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
<div v-else-if="!compactProgress && emlAggregate" class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-eml-aggregate">
|
||||
<div v-else-if="emlAggregate" class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30" data-testid="shipping-order-extraction-eml-aggregate">
|
||||
<article class="overflow-hidden rounded-lg border border-default bg-surface shadow-sm">
|
||||
<div class="flex items-start gap-3 border-b border-default bg-surface-soft p-3 dark:bg-slate-950/30">
|
||||
<Mail class="mt-0.5 h-5 w-5 text-brand-500" />
|
||||
@@ -926,7 +922,7 @@ async function onPrimaryChatAction() {
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<div v-else-if="!compactProgress" class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30">
|
||||
<div v-else class="flex flex-col gap-2 bg-surface-soft p-2 dark:bg-slate-950/30">
|
||||
<div v-for="row in activeEmailRows" :key="row.unitId" class="overflow-hidden rounded-lg border border-default bg-surface shadow-sm">
|
||||
<div class="flex items-start gap-3 border-b border-default bg-surface-soft p-3 dark:bg-slate-950/30"><Mail class="mt-0.5 h-5 w-5 text-brand-500" /><div class="min-w-0 flex-1"><div class="flex items-center justify-between gap-3"><span class="font-medium">{{ t('chat.shippingProcessing.emailPrefix') }}{{ row.fileName }}</span><span class="rounded border px-2 py-0.5 text-xs" :class="isFailedParseRow(row) || emailHasFailedChild(row) ? 'border-rose-200 bg-rose-100/70 text-rose-600' : emailIsCompleted(row) ? 'border-emerald-200 bg-emerald-100/70 text-emerald-600' : 'border-brand-200 bg-brand-100/70 text-brand-600'">{{ isFailedParseRow(row) || emailHasFailedChild(row) ? t('chat.shippingProcessing.batchException') : emailIsCompleted(row) ? t('chat.shippingProcessing.batchExtracted') : t('chat.shippingProcessing.parsingAttachments') }}</span></div><span class="mt-1 block font-mono text-xs text-muted">{{ t('chat.shippingProcessing.emailMeta') }}</span></div></div>
|
||||
<div class="mx-4 my-2 flex flex-col gap-2 border-l-2 border-default bg-surface-soft p-3 pl-4 dark:border-slate-700 dark:bg-slate-950/30"><div v-for="child in childRows(row)" :key="`child-${child.unitId}`" class="flex items-center justify-between gap-3 text-sm"><span class="flex min-w-0 items-center gap-2"><CheckCircle2 v-if="child.status === 'candidate_ready'" class="h-4 w-4 text-emerald-500" /><LoaderCircle v-else-if="!isFailedParseRow(child)" class="h-4 w-4 animate-spin text-brand-500" /><AlertCircle v-else class="h-4 w-4 text-rose-500" /><span class="truncate">{{ child.fileName }}</span></span><span :class="rowStatusClass(child)">{{ rowStatusLabel(child) }}</span></div></div>
|
||||
@@ -936,20 +932,6 @@ async function onPrimaryChatAction() {
|
||||
<div v-for="row in failedRows" :key="`failed-${row.unitId}`" class="rounded-lg border border-rose-200 bg-rose-50 p-3 dark:border-rose-800 dark:bg-rose-950/30"><div class="flex items-center justify-between text-rose-600"><span class="flex items-center gap-2 font-medium"><AlertCircle class="h-5 w-5" />{{ row.fileName }}</span><span class="rounded bg-rose-100 px-2 py-0.5 text-xs">{{ t('chat.shippingProcessing.batchException') }}</span></div><p class="mt-2 pl-7 text-sm">{{ row.explainability?.message || t('chat.shippingProcessing.batchManualVerify') }}</p></div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end border-t border-default bg-brand-50/60 p-3 dark:bg-brand-950/20">
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
v-if="!compactProgress && (hasConversationStatusGroups || String(props.runNo || '').trim())"
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-lg bg-brand-600 px-5 py-2.5 text-sm font-medium text-white shadow-sm hover:bg-brand-700"
|
||||
data-testid="shipping-order-extraction-open-batch-workbench"
|
||||
@click="emit('open-batch-workbench')"
|
||||
>
|
||||
{{ t('chat.shippingProcessing.openBatchWorkbench') }}
|
||||
<ArrowRight class="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="false" class="flex items-start gap-3">
|
||||
<CircleX class="mt-0.5 h-4 w-4 shrink-0" />
|
||||
<div class="min-w-0 flex-1">
|
||||
|
||||
@@ -104,10 +104,11 @@ function buildController(
|
||||
function mountTimeline(
|
||||
processing = processingProjection(),
|
||||
workItems: ShippingProcessingProjection[] = [],
|
||||
extraProps: Record<string, unknown> = {},
|
||||
) {
|
||||
return mount(ShippingWorkflowTimeline, {
|
||||
attachTo: document.body,
|
||||
props: { conversationId: 'conv-1', controller: buildController(processing, workItems) },
|
||||
props: { conversationId: 'conv-1', controller: buildController(processing, workItems), ...extraProps },
|
||||
global: { plugins: [i18n], stubs: { teleport: true } },
|
||||
});
|
||||
}
|
||||
@@ -124,6 +125,24 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
gateRecovery.submitPrimaryAction.mockClear();
|
||||
});
|
||||
|
||||
it('has no close button and reuses the conversation title in the header', () => {
|
||||
const wrapper = mountTimeline(processingProjection(), [], { conversationTitle: 'PO#6075309 09-15' });
|
||||
|
||||
// 中心常驻不可关闭(方案 A):关闭按钮必须消失。
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-close"]').exists()).toBe(false);
|
||||
|
||||
// 会话标题直接复用侧栏命名,保持两处一致。
|
||||
const titleNode = wrapper.find('[data-testid="shipping-workflow-conversation-title"]');
|
||||
expect(titleNode.exists()).toBe(true);
|
||||
expect(titleNode.text()).toContain('PO#6075309 09-15');
|
||||
});
|
||||
|
||||
it('omits the title node when no conversation title is provided', () => {
|
||||
const wrapper = mountTimeline(processingProjection(), []);
|
||||
|
||||
expect(wrapper.find('[data-testid="shipping-workflow-conversation-title"]').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('prefers backend five-stage lifecycle nodes and shows the authorized download toolbar in freight upload', async () => {
|
||||
const processing = processingProjection({
|
||||
lifecycle_nodes: [
|
||||
@@ -205,25 +224,6 @@ describe('ShippingWorkflowTimeline', () => {
|
||||
expect(wrapper.find('[data-testid="shipping-processing-file-DOC-9"]').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('labels a manually actionable batch as action needed instead of processing', async () => {
|
||||
const task = { ...processingProjection().processing[0], group: 'needs_action' };
|
||||
const processing = processingProjection({
|
||||
summary: { total_files: 1, processing_files: 0, completed_files: 0, waiting_human_files: 1, failed_files: 0 },
|
||||
needs_action: [task], processing: [],
|
||||
status_groups: { failed: [], waiting_human: [task], processing: [], completed: [], cancelled: [], archived: [] },
|
||||
} as Partial<ConversationProcessingProjection>);
|
||||
const wrapper = mountTimeline(processing, [fileProjection({
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', lifecycleStage: 'order_review',
|
||||
lifecycleEntries: [], blocking_reason: null, primary_action: null, secondary_actions: [],
|
||||
},
|
||||
})]);
|
||||
await flushPromises();
|
||||
|
||||
// 关键断言:锁定表示仍有待办,不得与「处理中 0」形成视觉矛盾。
|
||||
expect(wrapper.get('[data-testid="shipping-workflow-panel-pinned"]').text()).toBe('待处理');
|
||||
});
|
||||
|
||||
it('navigates only through the backend lifecycle entry', async () => {
|
||||
const file = fileProjection({
|
||||
uiState: {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 用途:聊天页右侧「批次进度中心」——后端批次投影、五阶段进度和文件行操作。
|
||||
* 依赖:vue-i18n、useMessage、useShippingNoticeWorkflow、ShippingConversationProcessingCard、
|
||||
* ReasonDialog、ProcessGateRecoveryCard。
|
||||
* 逻辑:顶层以 OT / ShippingProcessing 为主路径;标题栏仅保留批次名称、加载与截断提示,
|
||||
* 逻辑:顶层以 OT / ShippingProcessing 为主路径;标题栏保留批次名称、会话标题、加载与截断提示;中心常驻不可关闭(方案 A),
|
||||
* 文件总览和进度仅消费后端批次 summary;
|
||||
* 文件清单消费后端 conversation_processing.status_groups;work_items 仅用于定位同一
|
||||
* 展示 DTO 的操作对象;整批操作走 Run API,单文件取消走 Unit API;
|
||||
@@ -14,7 +14,7 @@
|
||||
import { computed, inject, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { ChevronDown, ChevronRight, Lock, RefreshCw } from 'lucide-vue-next';
|
||||
import { RefreshCw } from 'lucide-vue-next';
|
||||
import {
|
||||
downloadWorkspaceShippingExcelFile,
|
||||
downloadWorkspaceShippingExportArchive,
|
||||
@@ -59,10 +59,8 @@ const props = defineProps<{
|
||||
refreshTrigger?: number;
|
||||
/** 测试或父级注入时可直接传入控制器,跳过自建轮询。 */
|
||||
controller?: UseShippingNoticeWorkflowReturn | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
/** 当前会话标题;父级从侧栏历史匹配传入,中心头部直接复用(无新增接口)。 */
|
||||
conversationTitle?: string | null;
|
||||
}>();
|
||||
|
||||
const { t, te } = useI18n();
|
||||
@@ -91,11 +89,6 @@ const ctl = computed((): UseShippingNoticeWorkflowReturn => (
|
||||
props.controller || injected || localController
|
||||
));
|
||||
|
||||
/**
|
||||
* 侧栏折叠态:默认展开。
|
||||
* 有处理中/待处理/未查看完成任务时强制展开,仅允许收起文件详情。
|
||||
*/
|
||||
const collapsed = ref(false);
|
||||
/** 复核返回对话时展示的聚焦提示(由 focus_notice 触发一次)。 */
|
||||
const focusTaskBanner = ref<string | null>(null);
|
||||
const actionBusyItemNo = ref<string | null>(null);
|
||||
@@ -249,34 +242,6 @@ const initialLoading = computed(() => Boolean(ctl.value.initialLoading?.value));
|
||||
const manualRefreshing = computed(() => Boolean(ctl.value.manualRefreshing?.value));
|
||||
const isRefreshing = computed(() => Boolean(ctl.value.isRefreshing?.value));
|
||||
const error = computed(() => ctl.value.error.value);
|
||||
/**
|
||||
* 右侧仍有用户必须持续可见的任务时,禁止收起整个处理面板。
|
||||
* 核心逻辑:处理中 / 待处理 / 未查看完成均属活跃可见任务;无此类任务才允许收起侧栏。
|
||||
*/
|
||||
const hasPinnedProcessingTasks = computed(() => {
|
||||
const projection = displayProcessing.value;
|
||||
if (!projection) return false;
|
||||
return statusGroupTasks('failed', 'waiting_human', 'processing', 'completed').length > 0;
|
||||
});
|
||||
|
||||
/**
|
||||
* 切换侧栏折叠:活跃任务存在时强制保持展开。
|
||||
*/
|
||||
function togglePanelCollapsed() {
|
||||
if (hasPinnedProcessingTasks.value) {
|
||||
collapsed.value = false;
|
||||
return;
|
||||
}
|
||||
collapsed.value = !collapsed.value;
|
||||
}
|
||||
|
||||
watch(
|
||||
hasPinnedProcessingTasks,
|
||||
(pinned) => {
|
||||
if (pinned) collapsed.value = false;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
/**
|
||||
* 移除右侧常驻「批次与文件列表」长列表抽屉(UI-REFACTOR 方案 7)。
|
||||
@@ -839,7 +804,6 @@ watch(
|
||||
return;
|
||||
}
|
||||
if (!focusedTaskExists.value) return;
|
||||
collapsed.value = false;
|
||||
focusTaskBanner.value = normalized;
|
||||
// [UI-01/UI-02] 真正选中进度卡,禁止只显示提示条。
|
||||
await onProcessingFocus(normalized);
|
||||
@@ -856,31 +820,12 @@ watch(
|
||||
|
||||
<template>
|
||||
<aside
|
||||
class="flex min-w-0 flex-1 shrink-0 flex-col border-l border-default bg-surface shadow-[-16px_0_40px_rgba(15,23,42,0.10)] transition-[width] duration-200"
|
||||
:class="collapsed ? '!w-14' : ''"
|
||||
class="flex min-w-0 flex-1 shrink-0 flex-col bg-surface"
|
||||
data-testid="shipping-workflow-timeline"
|
||||
>
|
||||
<div class="flex w-full items-center gap-1 border-b border-default px-2 py-2">
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md p-1.5 text-muted hover:bg-surface-muted hover:text-primary"
|
||||
data-testid="shipping-workflow-close"
|
||||
:title="t('chat.shippingProcessing.closeWorkbench')"
|
||||
@click="emit('close')"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
<component
|
||||
:is="hasPinnedProcessingTasks ? 'div' : 'button'"
|
||||
:type="hasPinnedProcessingTasks ? undefined : 'button'"
|
||||
class="flex min-w-0 flex-1 items-center justify-between gap-2 rounded-md px-1 py-1 text-left"
|
||||
:class="hasPinnedProcessingTasks
|
||||
? 'cursor-default'
|
||||
: 'hover:bg-surface-muted/60'"
|
||||
data-testid="shipping-workflow-panel-toggle"
|
||||
@click="togglePanelCollapsed"
|
||||
>
|
||||
<div v-if="!collapsed" class="min-w-0">
|
||||
<div class="flex min-w-0 flex-1 items-center justify-between gap-2 rounded-md px-1 py-1 text-left">
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<div class="text-sm font-semibold text-primary">
|
||||
{{ te('chat.shippingProcessing.panelTitle')
|
||||
@@ -888,14 +833,11 @@ watch(
|
||||
: t('chat.shippingProcessing.title') }}
|
||||
</div>
|
||||
<span
|
||||
v-if="hasPinnedProcessingTasks"
|
||||
class="inline-flex items-center gap-0.5 rounded bg-surface-muted px-1.5 py-0.5 text-[10px] font-medium text-secondary"
|
||||
data-testid="shipping-workflow-panel-pinned"
|
||||
:title="t('chat.shippingProcessing.panelPinnedHint')"
|
||||
>
|
||||
<Lock class="h-3 w-3 shrink-0" aria-hidden="true" />
|
||||
{{ t('chat.shippingProcessing.panelPinnedLabel') }}
|
||||
</span>
|
||||
v-if="conversationTitle"
|
||||
class="min-w-0 truncate rounded bg-surface-muted px-1.5 py-0.5 text-xs text-secondary"
|
||||
data-testid="shipping-workflow-conversation-title"
|
||||
:title="conversationTitle"
|
||||
>{{ conversationTitle }}</span>
|
||||
</div>
|
||||
<div class="mt-0.5 space-y-0.5 text-xs text-secondary" data-testid="shipping-workflow-panel-summary">
|
||||
<template v-if="initialLoading && !displayProcessing">
|
||||
@@ -918,12 +860,7 @@ watch(
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<ChevronDown
|
||||
v-if="!collapsed && !hasPinnedProcessingTasks"
|
||||
class="h-4 w-4 shrink-0 text-muted"
|
||||
/>
|
||||
<ChevronRight v-else-if="collapsed" class="h-4 w-4 shrink-0 text-muted" />
|
||||
</component>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md p-1.5 text-muted hover:bg-surface-muted hover:text-primary disabled:opacity-50"
|
||||
@@ -939,7 +876,7 @@ watch(
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="!collapsed" class="min-h-0 flex-1 overflow-y-auto p-5">
|
||||
<div class="min-h-0 flex-1 overflow-y-auto p-5">
|
||||
<div
|
||||
v-if="initialLoading && !displayProcessing"
|
||||
class="mb-4 space-y-3"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingWorkbenchLayout.spec.ts
|
||||
* 用途:锁定货代会话主区域显隐规则(有会话即全屏批次进度中心,方案 A)。
|
||||
* 依赖:Vitest、纯函数。
|
||||
* 逻辑:判定必须同时满足货代智能体与非空会话 ID;普通智能体与新会话一律回落欢迎页。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { shouldShowShippingWorkbench } from './shippingWorkbenchLayout';
|
||||
|
||||
describe('shouldShowShippingWorkbench', () => {
|
||||
it('renders the workbench for the shipping agent once a conversation exists', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: 'conv-1' })).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps the welcome composer before a conversation is created', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: '' })).toBe(false);
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: true, conversationId: null })).toBe(false);
|
||||
});
|
||||
|
||||
it('never switches other agents to the workbench', () => {
|
||||
expect(shouldShowShippingWorkbench({ isShippingNoticeAgent: false, conversationId: 'conv-1' })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingWorkbenchLayout.ts
|
||||
* 用途:货代发货会话主区域显隐判定(批次进度中心优先,方案 A)。
|
||||
* 依赖:无(纯函数)。
|
||||
* 逻辑:货代智能体且存在非空会话 ID 时全屏渲染批次进度中心;
|
||||
* 否则(新会话欢迎页)显示欢迎页 + 输入框(唯一附件提交入口)。
|
||||
*/
|
||||
|
||||
export interface ShippingWorkbenchLayoutInput {
|
||||
isShippingNoticeAgent: boolean;
|
||||
conversationId: string | null | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判定是否以批次进度中心作为会话主区域。
|
||||
* @param input - 智能体身份与当前会话 ID(路由 query 与 page 回填同源优先级)。
|
||||
* @returns true 表示全屏渲染批次进度中心;false 表示欢迎页 + 输入框。
|
||||
*/
|
||||
export function shouldShowShippingWorkbench(input: ShippingWorkbenchLayoutInput): boolean {
|
||||
return Boolean(input.isShippingNoticeAgent && String(input.conversationId || '').trim());
|
||||
}
|
||||
@@ -3077,8 +3077,6 @@
|
||||
"primaryFile": "Primary file: {name}",
|
||||
"continueProcessing": "Continue",
|
||||
"fileCountUnavailable": "File count unavailable",
|
||||
"panelPinnedHint": "Active tasks keep this panel open; you can still collapse file details",
|
||||
"panelPinnedLabel": "Action needed",
|
||||
"groupHistory": "History · {count}",
|
||||
"groupHistoryRecords": "Past versions · {count} files",
|
||||
"groupCancelled": "Cancelled · {count} files",
|
||||
|
||||
@@ -3203,8 +3203,6 @@
|
||||
"primaryFile": "ไฟล์หลัก: {name}",
|
||||
"continueProcessing": "ดำเนินการต่อ",
|
||||
"fileCountUnavailable": "ยังไม่มีจำนวนไฟล์",
|
||||
"panelPinnedHint": "มีงานที่กำลังทำหรือต้องดำเนินการ แผงนี้จะเปิดค้างไว้ คุณยังยุบรายละเอียดไฟล์ได้",
|
||||
"panelPinnedLabel": "ต้องดำเนินการ",
|
||||
"groupHistory": "ประวัติ · {count}",
|
||||
"groupHistoryRecords": "เวอร์ชันก่อนหน้า · {count} ไฟล์",
|
||||
"groupCancelled": "ยกเลิกแล้ว · {count} ไฟล์",
|
||||
|
||||
@@ -3151,8 +3151,6 @@
|
||||
"primaryFile": "主文件:{name}",
|
||||
"continueProcessing": "继续处理",
|
||||
"fileCountUnavailable": "文件数暂不可用",
|
||||
"panelPinnedHint": "仍有处理中或待处理任务,侧栏保持展开;可收起文件详情",
|
||||
"panelPinnedLabel": "待处理",
|
||||
"groupHistory": "处理记录 · {count}",
|
||||
"groupHistoryRecords": "历史版本 · {count} 个文件",
|
||||
"groupCancelled": "已取消 · {count} 个文件",
|
||||
|
||||
@@ -3203,8 +3203,6 @@
|
||||
"primaryFile": "主檔案:{name}",
|
||||
"continueProcessing": "繼續處理",
|
||||
"fileCountUnavailable": "檔案數暫不可用",
|
||||
"panelPinnedHint": "仍有處理中或待處理任務,側欄保持展開;可收起檔案詳情",
|
||||
"panelPinnedLabel": "待處理",
|
||||
"groupHistory": "處理記錄 · {count}",
|
||||
"groupHistoryRecords": "歷史版本 · {count} 個檔案",
|
||||
"groupCancelled": "已取消 · {count} 個檔案",
|
||||
|
||||
Reference in new issue
Block a user