feat(file-check): 更新文件检核工具 API Key 配置及相关文档
This commit is contained in:
1 parent
634dee4b81
commit
55cf7ff734
74 files changed
+1525
-1182
No files matched your search
@@ -251,6 +251,24 @@ const batchCompletionPercent = computed(() => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingInventorySelectionActive && page.shippingBatchTasks?.length > 1"
|
||||
class="mt-3 flex flex-wrap items-center justify-between gap-3 rounded-2xl border border-amber-200 bg-amber-50/90 px-3 py-3 text-sm text-amber-900"
|
||||
>
|
||||
<div class="space-y-1">
|
||||
<div class="font-semibold">{{ t('chat.shippingNoticeUi.inventoryTaskPickTitle') }}</div>
|
||||
<div class="text-xs text-amber-800">
|
||||
{{ t('chat.shippingNoticeUi.inventoryTaskPickHint') }}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-amber-300 px-3 py-1 text-xs font-medium text-amber-800 transition hover:bg-amber-100"
|
||||
@click="page.cancelShippingInventoryTaskSelection()"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.cancelInventoryTaskPick') }}
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingBatchTasksExpanded && page.shippingBatchTasks?.length"
|
||||
class="mt-3 grid gap-2 border-t border-default/70 pt-3 sm:grid-cols-2 xl:grid-cols-3"
|
||||
@@ -279,6 +297,27 @@ const batchCompletionPercent = computed(() => {
|
||||
· {{ t('chat.shippingNoticeUi.batchProgress', { index: task.batch_index, total: task.batch_total }) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="page.shippingInventorySelectionActive"
|
||||
class="mt-3 flex items-center justify-between gap-2"
|
||||
>
|
||||
<span
|
||||
v-if="page.shippingInventorySelectionTaskId === task.task_no"
|
||||
class="rounded-full bg-brand-50 px-2 py-1 text-[11px] font-medium text-brand-700"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.inventoryTargetTask', { taskId: task.task_no }) }}
|
||||
</span>
|
||||
<span v-else class="text-[11px] text-muted">
|
||||
{{ t('chat.shippingNoticeUi.inventoryTargetIdle') }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-full border border-brand-200 px-2.5 py-1 text-[11px] font-medium text-brand-700 transition hover:bg-brand-50"
|
||||
@click.stop="page.selectShippingInventoryUploadTask(task.task_no)"
|
||||
>
|
||||
{{ t('chat.shippingNoticeUi.uploadInventoryToTask') }}
|
||||
</button>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/components/ShippingWorkflowStepper.vue
|
||||
* 货代发货七步流程 Stepper。
|
||||
* 用途:货代发货七步流程 Stepper 展示组件。
|
||||
* 依赖:shipping/shippingStepper、vue-i18n。
|
||||
* 逻辑:Chat 与工作台传入 steps 数组;本组件只负责步骤高亮与标签渲染。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/components/messages/ShippingInventoryMappingMessage.vue
|
||||
* 出货 Agent:库存 Excel 列映射表单消息 UI。
|
||||
* 用途:发货 Agent 库存 Excel 列映射表单消息 UI。
|
||||
* 依赖:chat.types、shipping.api.types、shipping.types。
|
||||
* 逻辑:ChatView 渲染 mapping 类型消息时挂载;通过 ShippingMappingHandlers 与 useChatShipping 交互。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import type { ChatMessage } from '../../types/chat.types';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/components/messages/ShippingParseReviewMessage.vue
|
||||
* 出货 Agent:parse_review 阶段订单表编辑消息 UI。
|
||||
* 用途:发货 Agent parse_review 阶段单头/订单行可编辑消息 UI。
|
||||
* 依赖:chat.types、shipping.api.types、vue-i18n。
|
||||
* 逻辑:ChatView 渲染 parse_review 消息时挂载;通过 ShippingParseReviewHandlers 提交字段更正。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
|
||||
@@ -412,7 +412,11 @@ export function useChatPage() {
|
||||
shippingBatchTasks: shipping.shippingBatchTasks,
|
||||
activeShippingTaskDetail: shipping.activeShippingTaskDetail,
|
||||
shippingBatchTasksExpanded: shipping.shippingBatchTasksExpanded,
|
||||
shippingInventorySelectionActive: shipping.shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId: shipping.shippingInventorySelectionTaskId,
|
||||
switchShippingFocusTask: shipping.switchShippingFocusTask,
|
||||
selectShippingInventoryUploadTask: shipping.selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection: shipping.cancelShippingInventoryTaskSelection,
|
||||
shippingSuggestedPrompt: shipping.shippingSuggestedPrompt,
|
||||
handleShippingInventorySelected: shipping.handleShippingInventorySelected,
|
||||
useShippingSuggestedPrompt: shipping.useShippingSuggestedPrompt,
|
||||
|
||||
@@ -125,6 +125,9 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const shippingAutoFlowRequested = ref(false);
|
||||
const shippingInventoryPickerRef = ref<HTMLInputElement | null>(null);
|
||||
const pendingShippingUploadTaskId = ref('');
|
||||
const pendingShippingInventoryFile = ref<File | null>(null);
|
||||
const shippingInventorySelectionActive = ref(false);
|
||||
const shippingInventorySelectionTaskId = ref('');
|
||||
|
||||
const prepareMarkdownDisplayText = (text: string) => {
|
||||
const stripped = isShippingNoticeAgent.value ? extractShippingActionsDirective(text).cleanedText : text;
|
||||
@@ -308,6 +311,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
openShippingInventoryPicker,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
handleShippingInventorySelected,
|
||||
shippingSuggestedPrompt,
|
||||
useShippingSuggestedPrompt,
|
||||
@@ -318,9 +323,14 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingAutoFlowRequested,
|
||||
shippingInventoryPickerRef,
|
||||
pendingShippingUploadTaskId,
|
||||
pendingShippingInventoryFile,
|
||||
resolvedShippingTaskId,
|
||||
resolvedShippingBatchNo,
|
||||
shippingBatchSummary,
|
||||
shippingBatchTasks,
|
||||
shippingBatchTasksExpanded,
|
||||
shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId,
|
||||
shippingInventorySchemaPreviewCache,
|
||||
getActiveShippingTaskId,
|
||||
sendShippingMenuMessage,
|
||||
@@ -463,6 +473,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
shippingAutoFlowRequested,
|
||||
shippingInventoryPickerRef,
|
||||
pendingShippingUploadTaskId,
|
||||
shippingInventorySelectionActive,
|
||||
shippingInventorySelectionTaskId,
|
||||
allowsSendWithAttachmentsOnly,
|
||||
shippingTaskIdFromQuery,
|
||||
shippingBatchNoFromQuery,
|
||||
@@ -488,6 +500,8 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
removeShippingParseReviewLine,
|
||||
handleShippingActionClick,
|
||||
handleShippingInventorySelected,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
shippingActionButtonClass,
|
||||
shippingSuggestedPrompt,
|
||||
useShippingSuggestedPrompt,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/constants/shipping.ts
|
||||
* 发货通知功能常量:任务编号正则、菜单动作规格与决策动作集合。
|
||||
* 用途:发货通知功能常量 — 任务编号正则、菜单动作规格与决策动作集合。
|
||||
* 依赖:types/shipping.types(ShippingMenuAction)。
|
||||
* 逻辑:shipping/* handler 与 useChatShipping 引用本模块,避免动作 id 硬编码分散。
|
||||
*/
|
||||
import type { ShippingMenuAction } from '../types/shipping.types';
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* 出货聊天:会话侧栏同步、带任务编号的菜单消息发送。
|
||||
* features/chat/shipping/shippingConversation.ts
|
||||
* 用途:发货聊天会话侧栏同步与带任务编号的菜单消息发送。
|
||||
* 依赖:chat.types、shipping.types、Vue Ref/ComputedRef。
|
||||
* 逻辑:useChatShipping 通过 createShippingConversationHelpers 发送菜单类消息并刷新历史。
|
||||
*/
|
||||
import type { ChatSessionItem } from '../types/chat.types';
|
||||
import type { ChatUploadFileSpec } from '../types/shipping.types';
|
||||
@@ -30,6 +33,9 @@ export async function ensureShippingHistorySynced(ctx: ShippingConversationConte
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发货会话辅助函数(菜单消息发送 + 历史同步)。
|
||||
*/
|
||||
export function createShippingConversationHelpers(ctx: ShippingConversationContext) {
|
||||
const sendShippingMenuMessage = async (message: string) => {
|
||||
const taskId = ctx.getActiveShippingTaskId();
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
/**
|
||||
* 出货聊天:决策 API 响应 → 助手消息 Markdown 文案(纯函数)。
|
||||
* features/chat/shipping/shippingDecisionFormat.ts
|
||||
* 用途:决策 API 响应格式化为助手 Markdown 消息。
|
||||
* 依赖:无;useChatShippingDecision 在 submit_decision 成功后调用。
|
||||
* 逻辑:按 decision 类型追加映射提示、下一步指引与任务编号尾注。
|
||||
*/
|
||||
/**
|
||||
* 将 submit_decision 结果格式化为本地 assistant 消息 Markdown。
|
||||
*/
|
||||
export function formatShippingDecisionAssistantMessage(
|
||||
decision: string,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* 出货聊天:发货 Excel 浏览器下载(触发 a[download])。
|
||||
* features/chat/shipping/shippingDownload.ts
|
||||
* 用途:工作台发货 Excel 浏览器端下载(触发 a[download])。
|
||||
* 依赖:shipping.api.workspaceShippingExportUrl、shared/utils/auth。
|
||||
* 逻辑:useChatShippingSendHandler 在用户请求下载 Excel 时调用。
|
||||
*/
|
||||
import { workspaceShippingExportUrl } from '@/features/chat/api/shipping.api';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* 出货聊天:用户输入意图识别(纯函数,供 handleSend 前置拦截)。
|
||||
*
|
||||
* 覆盖:手工上传声明、库存上传、生成/下载 Excel、自然语言列映射(sku→列名)。
|
||||
* features/chat/shipping/shippingIntents.ts
|
||||
* 用途:发货聊天用户输入意图识别,供 handleSend 前置拦截。
|
||||
* 依赖:shippingMenu.resolveShippingNumericChoice、types/shipping.types。
|
||||
* 逻辑:useChatShippingSendHandler 调用;覆盖手工上传、库存上传、Excel 生成/下载、列映射与切票。
|
||||
*/
|
||||
import { resolveShippingNumericChoice } from './shippingMenu';
|
||||
import type { ShippingMenuAction } from '../types/shipping.types';
|
||||
@@ -11,6 +12,9 @@ export interface ShippingTaskSwitchIntent {
|
||||
taskNo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从自然语言文本解析库存列映射(sku / available_qty / reservation_id → Excel 列名)。
|
||||
*/
|
||||
export function parseShippingColumnMappingFromText(content: string): Record<string, string> | null {
|
||||
const raw = String(content || '').trim();
|
||||
if (!raw) return null;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* 出货聊天:本地消息写入(不经过 Dify SSE,直接 push 到 messages 并落库)。
|
||||
* features/chat/shipping/shippingLocalMessages.ts
|
||||
* 用途:发货聊天本地消息写入(不经 Dify SSE,直接 push 并落库)。
|
||||
* 依赖:chat.types、Vue Ref。
|
||||
* 逻辑:useChatShipping 在菜单/决策拦截成功后写入本地 user/assistant 消息。
|
||||
*/
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { Ref } from 'vue';
|
||||
@@ -10,6 +13,9 @@ export interface ShippingLocalMessageContext {
|
||||
saveLocalMessageToBackend: (msg: ChatMessage, userQuery?: string) => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建本地 user/assistant 消息 push 函数。
|
||||
*/
|
||||
export function createShippingLocalMessages(ctx: ShippingLocalMessageContext) {
|
||||
const pushShippingLocalUserMessage = async (text: string) => {
|
||||
const content = String(text || '').trim();
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
/**
|
||||
* 出货聊天:库存列映射 payload 读取与字段对齐 Markdown 生成(纯函数)。
|
||||
*
|
||||
* 消息 type === 'shipping-inventory-mapping' 时 payload 含 schema_preview + form。
|
||||
* features/chat/shipping/shippingMapping.ts
|
||||
* 用途:库存列映射消息 payload 读取与字段对齐 Markdown 生成。
|
||||
* 依赖:shippingText.normalizeShippingHeaderForDisplay、chat.types、shipping.types。
|
||||
* 逻辑:ShippingInventoryMappingMessage 与 useChatShippingMappingForm 读取 mapping 消息数据。
|
||||
*/
|
||||
import { normalizeShippingHeaderForDisplay } from './shippingText';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingInventoryMappingFormPayload } from '../types/shipping.types';
|
||||
|
||||
/**
|
||||
* 从 shipping-inventory-mapping 类型消息中提取 taskId、schema_preview 与 form。
|
||||
*/
|
||||
export function getShippingInventoryMappingPayload(chatMsg: ChatMessage): ShippingInventoryMappingFormPayload | null {
|
||||
if (!chatMsg || chatMsg.type !== 'shipping-inventory-mapping') return null;
|
||||
const payload = chatMsg.payload;
|
||||
@@ -28,6 +32,9 @@ export function getShippingInventorySampleRowText(chatMsg: ChatMessage): string
|
||||
return Array.isArray(row) ? row.map((cell) => String(cell)).join(' | ') : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 field_alignment API 响应转为 Markdown 表格文本,供发送给 Agent 确认。
|
||||
*/
|
||||
export function buildShippingFieldAlignmentText(payload: { data?: { field_alignment?: Record<string, unknown> } }): string {
|
||||
const alignment = payload?.data?.field_alignment;
|
||||
if (!alignment || typeof alignment !== 'object') return '';
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
/**
|
||||
* 出货聊天:匹配结果卡片 payload 读取。
|
||||
* features/chat/shipping/shippingMatchResult.ts
|
||||
* 用途:从 ChatMessage 读取 shipping-match-result 类型 payload。
|
||||
* 依赖:chat.types、shipping.types。
|
||||
* 逻辑:ShippingMatchResultCard 与 useChatShipping 渲染匹配结果卡片时使用。
|
||||
*/
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingMatchResultPayload } from '../types/shipping.types';
|
||||
|
||||
/** 从 shipping-match-result 消息提取 taskId 与 line_results。 */
|
||||
export function getShippingMatchResultPayload(chatMsg: ChatMessage): ShippingMatchResultPayload | null {
|
||||
if (!chatMsg || chatMsg.type !== 'shipping-match-result') return null;
|
||||
const payload = chatMsg.payload;
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
/**
|
||||
* 出货聊天:数字菜单解析、动作按钮合并、决策文本识别(纯函数)。
|
||||
*
|
||||
* 菜单行格式示例:「1. 上传库存文件」→ action: upload
|
||||
* resolveShippingActionButtons:优先 API 按钮,其次 HTML 指令,最后内容推断
|
||||
* features/chat/shipping/shippingMenu.ts
|
||||
* 用途:发货聊天数字菜单解析、动作按钮合并与决策文本识别(纯函数)。
|
||||
* 依赖:shippingText.extractShippingActionsDirective、types/shipping.types。
|
||||
* 逻辑:useChatShippingSendHandler 在发送前调用;优先 API 按钮,其次 HTML 指令,最后内容推断。
|
||||
*/
|
||||
import { extractShippingActionsDirective } from './shippingText';
|
||||
import type { ShippingActionButton, ShippingMenuAction } from '../types/shipping.types';
|
||||
|
||||
/**
|
||||
* 将 human_options 动作 id 列表转为带 Tailwind 样式的按钮 class。
|
||||
*/
|
||||
export function shippingActionButtonClass(variant?: string): string {
|
||||
if (variant === 'primary') {
|
||||
return 'rounded-xl bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-emerald-700 disabled:cursor-not-allowed disabled:opacity-60';
|
||||
@@ -73,6 +76,9 @@ export function normalizeApiShippingButtons(
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并 API 按钮、HTML 指令与内容推断,得到最终 action_buttons 与 cleanedText。
|
||||
*/
|
||||
export function resolveShippingActionButtons(
|
||||
content: string,
|
||||
apiButtons: Array<{ id: string; label: string; message: string; variant?: string }> | null,
|
||||
@@ -95,6 +101,9 @@ export function resolveShippingActionButtons(
|
||||
return { buttons: [], cleanedText: directive.cleanedText, fromDirective: false };
|
||||
}
|
||||
|
||||
/**
|
||||
* 从用户文本与助手上下文识别 submit_decision 所需的 action id。
|
||||
*/
|
||||
export function resolveShippingDecisionFromText(text: string, assistantContext: string): string | null {
|
||||
const normalized = text.trim();
|
||||
const direct: Record<string, string> = {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
/**
|
||||
* 出货聊天:parse_review 订单表消息 payload 读取。
|
||||
* features/chat/shipping/shippingParseReview.ts
|
||||
* 用途:从 ChatMessage 读取 shipping-parse-review 类型 payload。
|
||||
* 依赖:chat.types、shipping.types。
|
||||
* 逻辑:ShippingParseReviewMessage 渲染 parse_review 可编辑订单表时使用。
|
||||
*/
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
import type { ShippingParseReviewPayload } from '../types/shipping.types';
|
||||
|
||||
/** 从 shipping-parse-review 消息提取 taskId、checkpoint 与 lines。 */
|
||||
export function getShippingParseReviewPayload(chatMsg: ChatMessage): ShippingParseReviewPayload | null {
|
||||
if (!chatMsg || chatMsg.type !== 'shipping-parse-review') return null;
|
||||
const payload = chatMsg.payload;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/**
|
||||
* 出货七步 Stepper:基于现有 shipping task 状态推导前端步骤展示。
|
||||
* features/chat/shipping/shippingStepper.ts
|
||||
* 用途:基于 shipping task 状态推导前端七步 Stepper 展示数据。
|
||||
* 依赖:无外部模块;ShippingWorkflowStepper.vue 消费本模块输出。
|
||||
* 逻辑:buildShippingWorkflowSteps 将 process_status / checkpoint 等映射为步骤 id 与 done/active 状态。
|
||||
*/
|
||||
export interface ShippingTaskStepperSource {
|
||||
process_status?: string | null;
|
||||
@@ -62,6 +65,9 @@ function deriveCurrentIndex(task: ShippingTaskStepperSource | null | undefined):
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 task 状态映射为七步 Stepper 项(id / label / done / active)。
|
||||
*/
|
||||
export function buildShippingWorkflowSteps(
|
||||
task: ShippingTaskStepperSource | null | undefined,
|
||||
): ShippingWorkflowStepItem[] {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/**
|
||||
* 出货聊天:任务编号提取(纯函数)。
|
||||
*
|
||||
* 从消息正文匹配 SHIPPING_TASK_ID_RE,或从侧栏会话标题模糊查找。
|
||||
* features/chat/shipping/shippingTaskId.ts
|
||||
* 用途:从消息或会话历史中识别发货任务编号(SN- 格式)。
|
||||
* 依赖:constants/shipping.SHIPPING_TASK_ID_RE、chat.types。
|
||||
* 逻辑:useChatShipping 切换任务/恢复会话时调用。
|
||||
*/
|
||||
import { SHIPPING_TASK_ID_RE } from '../constants/shipping';
|
||||
import type { ChatSessionItem } from '../types/chat.types';
|
||||
|
||||
/** 从消息列表倒序查找最近出现的 SN- 任务编号。 */
|
||||
export function findLatestShippingTaskId(msgs: Array<{ content?: string }>): string {
|
||||
for (let i = msgs.length - 1; i >= 0; i -= 1) {
|
||||
const match = String(msgs[i]?.content || '').match(SHIPPING_TASK_ID_RE);
|
||||
@@ -14,6 +16,7 @@ export function findLatestShippingTaskId(msgs: Array<{ content?: string }>): str
|
||||
return '';
|
||||
}
|
||||
|
||||
/** 在侧栏历史中按标题模糊匹配含 taskId 的会话。 */
|
||||
export function findHistorySessionForShippingTask(
|
||||
history: ChatSessionItem[],
|
||||
taskId: string,
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
/**
|
||||
* 出货聊天:消息文本净化与动作指令解析(纯函数,无 Vue 依赖)。
|
||||
*
|
||||
* - sanitizeShippingConversationText:隐藏后台状态 token,统一 task_id 展示
|
||||
* - extractShippingActionsDirective:解析 <!-- HXOPS_SHIPPING_ACTIONS --> 注释块
|
||||
* - normalizeShippingHeaderForDisplay:表头列名展示(空格转 NBSP)
|
||||
* features/chat/shipping/shippingText.ts
|
||||
* 用途:发货聊天消息文本净化与 HTML 动作指令解析(纯函数,无 Vue 依赖)。
|
||||
* 依赖:constants/shippingNoticeActions、types/shipping.types。
|
||||
* 逻辑:ChatView 渲染前 sanitize;shippingMenu 解析 <!-- HXOPS_SHIPPING_ACTIONS --> 注释块。
|
||||
*/
|
||||
import { SHIPPING_INTERNAL_STATUS_TOKENS, SHIPPING_KNOWN_ACTION_ID_SET } from '@/constants/shippingNoticeActions';
|
||||
import type { ShippingActionButton, ShippingActionVariant } from '../types/shipping.types';
|
||||
|
||||
/**
|
||||
* 隐藏 Agent 回复中的内部状态 token,并将 task_id 统一为「任务编号」展示。
|
||||
*/
|
||||
export function sanitizeShippingConversationText(text: string, enabled: boolean): string {
|
||||
if (!enabled) return text;
|
||||
let result = String(text || '')
|
||||
@@ -26,6 +28,9 @@ export function sanitizeShippingConversationText(text: string, enabled: boolean)
|
||||
return result.replace(/\n{3,}/g, '\n\n').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析消息中的 HXOPS_SHIPPING_ACTIONS HTML 注释,提取 action_buttons 并返回净化后文本。
|
||||
*/
|
||||
export function extractShippingActionsDirective(rawText: string): {
|
||||
cleanedText: string;
|
||||
buttons: ShippingActionButton[];
|
||||
@@ -65,6 +70,9 @@ export function extractShippingActionsDirective(rawText: string): {
|
||||
return { cleanedText: cleaned, buttons };
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存表头列名展示规范化(空格转 NBSP,避免 Markdown 表格换行)。
|
||||
*/
|
||||
export function normalizeShippingHeaderForDisplay(raw: unknown): string {
|
||||
const text = String(raw ?? '').replace(/\s+/g, ' ').trim();
|
||||
return text.replace(/ /g, '\u00A0');
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
/**
|
||||
* 出货聊天:库存上传后发给 Dify 的提示语、附件类型分类(纯函数)。
|
||||
* features/chat/shipping/shippingUploadPrompt.ts
|
||||
* 用途:库存上传后发给 Dify 的提示语构建与附件类型分类。
|
||||
* 依赖:无;useChatShippingUploadHandler 在上传成功后调用。
|
||||
* 逻辑:按 checkpoint 生成不同 follow-up 提示;classifyShippingUploadFile 区分库存/通知附件。
|
||||
*/
|
||||
/**
|
||||
* 根据上传 API 响应 checkpoint 生成发给 Agent 的 follow-up 提示语。
|
||||
*/
|
||||
export function buildShippingInventoryUploadPrompt(
|
||||
result: Record<string, unknown> | null | undefined,
|
||||
@@ -23,6 +29,9 @@ export function buildShippingInventoryUploadPrompt(
|
||||
return `${prefix}。请继续处理库存导入,并告诉我下一步。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按扩展名判断附件是库存 Excel 还是发货通知文件。
|
||||
*/
|
||||
export function classifyShippingUploadFile(
|
||||
file: File,
|
||||
extractExt: (name: string) => string,
|
||||
|
||||
@@ -28,6 +28,7 @@ export interface ShippingParseReviewContext {
|
||||
msg: { warning: (text: string) => void };
|
||||
}
|
||||
|
||||
/** 由任务详情与 checkpoint 构建 parse_review 卡片 payload。 */
|
||||
function buildParseReviewPayload(
|
||||
taskId: string,
|
||||
detail: Awaited<ReturnType<typeof getWorkspaceShippingTask>>,
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
createWorkspaceShippingBatchFromNotices,
|
||||
createWorkspaceShippingTask,
|
||||
uploadWorkspaceShippingInventory,
|
||||
type ShippingTaskSummary,
|
||||
} from '@/features/chat/api/shipping.api';
|
||||
import { extractExt } from '../constants/shipping';
|
||||
import { buildShippingInventoryUploadPrompt, classifyShippingUploadFile } from './shippingUploadPrompt';
|
||||
@@ -22,16 +23,21 @@ export interface ShippingUploadHandlerContext {
|
||||
shippingAutoFlowRequested: Ref<boolean>;
|
||||
shippingInventoryPickerRef: Ref<HTMLInputElement | null>;
|
||||
pendingShippingUploadTaskId: Ref<string>;
|
||||
pendingShippingInventoryFile: Ref<File | null>;
|
||||
resolvedShippingTaskId: Ref<string>;
|
||||
resolvedShippingBatchNo: Ref<string>;
|
||||
shippingBatchSummary: Ref<unknown | null>;
|
||||
shippingBatchTasks: Ref<ShippingTaskSummary[]>;
|
||||
shippingBatchTasksExpanded: Ref<boolean>;
|
||||
shippingInventorySelectionActive: Ref<boolean>;
|
||||
shippingInventorySelectionTaskId: Ref<string>;
|
||||
shippingInventorySchemaPreviewCache: Ref<Record<string, unknown>>;
|
||||
getActiveShippingTaskId: () => string;
|
||||
sendShippingMenuMessage: (message: string) => Promise<void>;
|
||||
pushShippingLocalAssistantMessage: (text: string) => Promise<void>;
|
||||
refreshShippingActions: () => Promise<void>;
|
||||
msg: { warning: (text: string) => void };
|
||||
t: (key: string) => string;
|
||||
t: (key: string, params?: Record<string, unknown>) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +48,14 @@ export interface ShippingUploadHandlerContext {
|
||||
* @returns 自动上传、文件选择器和建议提示相关处理函数
|
||||
*/
|
||||
export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext) {
|
||||
const hasMultipleShippingBatchTasks = () =>
|
||||
Array.isArray(ctx.shippingBatchTasks.value) && ctx.shippingBatchTasks.value.length > 1;
|
||||
|
||||
const resetInventoryTaskSelection = () => {
|
||||
ctx.shippingInventorySelectionActive.value = false;
|
||||
ctx.shippingInventorySelectionTaskId.value = '';
|
||||
};
|
||||
|
||||
const continueShippingInventoryUploadWithDify = async (
|
||||
taskId: string,
|
||||
result: Record<string, unknown> | null | undefined,
|
||||
@@ -59,6 +73,59 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
await ctx.sendShippingMenuMessage(buildShippingInventoryUploadPrompt(result, fileName));
|
||||
};
|
||||
|
||||
const uploadInventoryForTask = async (taskId: string, file: File) => {
|
||||
ctx.resolvedShippingTaskId.value = taskId;
|
||||
const result = await uploadWorkspaceShippingInventory(taskId, file);
|
||||
await continueShippingInventoryUploadWithDify(taskId, result as unknown as Record<string, unknown>, file.name);
|
||||
};
|
||||
|
||||
const promptInventoryTaskSelection = async (pendingFile?: File) => {
|
||||
if (pendingFile) ctx.pendingShippingInventoryFile.value = pendingFile;
|
||||
ctx.shippingBatchTasksExpanded.value = true;
|
||||
ctx.pendingShippingUploadTaskId.value = '';
|
||||
ctx.shippingInventorySelectionTaskId.value = '';
|
||||
ctx.shippingInventorySelectionActive.value = true;
|
||||
await ctx.pushShippingLocalAssistantMessage(
|
||||
ctx.t(
|
||||
pendingFile
|
||||
? 'chat.shippingNoticeUi.inventoryTaskPickPendingHint'
|
||||
: 'chat.shippingNoticeUi.inventoryTaskPickHint',
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
const selectShippingInventoryUploadTask = (taskId: string): boolean => {
|
||||
const normalizedTaskId = String(taskId || '').trim().toUpperCase();
|
||||
if (!normalizedTaskId) {
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeMissingTaskId'));
|
||||
return false;
|
||||
}
|
||||
ctx.resolvedShippingTaskId.value = normalizedTaskId;
|
||||
ctx.shippingInventorySelectionTaskId.value = normalizedTaskId;
|
||||
ctx.pendingShippingUploadTaskId.value = normalizedTaskId;
|
||||
ctx.shippingInventorySelectionActive.value = false;
|
||||
|
||||
const pendingFile = ctx.pendingShippingInventoryFile.value;
|
||||
if (pendingFile) {
|
||||
ctx.pendingShippingInventoryFile.value = null;
|
||||
ctx.pendingShippingUploadTaskId.value = '';
|
||||
void uploadInventoryForTask(normalizedTaskId, pendingFile).catch((e: unknown) => {
|
||||
const errorMessage = e instanceof Error ? e.message : ctx.t('chat.shippingNoticeUploadFailed');
|
||||
ctx.msg.warning(errorMessage);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
ctx.shippingInventoryPickerRef.value?.click();
|
||||
return true;
|
||||
};
|
||||
|
||||
const cancelShippingInventoryTaskSelection = () => {
|
||||
ctx.pendingShippingInventoryFile.value = null;
|
||||
ctx.pendingShippingUploadTaskId.value = '';
|
||||
resetInventoryTaskSelection();
|
||||
};
|
||||
|
||||
const syncBatchContextFromNoticeResponse = (result: Record<string, unknown> | null | undefined) => {
|
||||
const batchNo = String(
|
||||
(result?.batch_no as string | undefined)
|
||||
@@ -81,6 +148,10 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
const handleShippingAutoUploadFile = async (file: File) => {
|
||||
const kind = classifyShippingUploadFile(file, extractExt);
|
||||
if (kind === 'inventory') {
|
||||
if (hasMultipleShippingBatchTasks()) {
|
||||
await promptInventoryTaskSelection(file);
|
||||
return;
|
||||
}
|
||||
let taskId = ctx.getActiveShippingTaskId();
|
||||
if (!taskId) {
|
||||
const created = await createWorkspaceShippingTask({
|
||||
@@ -93,9 +164,7 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
return;
|
||||
}
|
||||
}
|
||||
ctx.resolvedShippingTaskId.value = taskId;
|
||||
const result = await uploadWorkspaceShippingInventory(taskId, file);
|
||||
await continueShippingInventoryUploadWithDify(taskId, result as unknown as Record<string, unknown>, file.name);
|
||||
await uploadInventoryForTask(taskId, file);
|
||||
return;
|
||||
}
|
||||
const result = await createWorkspaceShippingBatchFromNotices(
|
||||
@@ -173,14 +242,16 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
};
|
||||
|
||||
const openShippingInventoryPicker = (): boolean => {
|
||||
if (hasMultipleShippingBatchTasks()) {
|
||||
void promptInventoryTaskSelection();
|
||||
return true;
|
||||
}
|
||||
const taskId = ctx.getActiveShippingTaskId();
|
||||
if (!taskId) {
|
||||
ctx.msg.warning(ctx.t('chat.shippingNoticeMissingTaskId'));
|
||||
return false;
|
||||
}
|
||||
ctx.pendingShippingUploadTaskId.value = taskId;
|
||||
ctx.shippingInventoryPickerRef.value?.click();
|
||||
return true;
|
||||
return selectShippingInventoryUploadTask(taskId);
|
||||
};
|
||||
|
||||
const handleShippingInventorySelected = async (event: Event) => {
|
||||
@@ -189,13 +260,17 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
fileInput.value = '';
|
||||
const taskId = ctx.pendingShippingUploadTaskId.value;
|
||||
ctx.pendingShippingUploadTaskId.value = '';
|
||||
if (!file || !taskId) return;
|
||||
if (!file || !taskId) {
|
||||
ctx.shippingInventorySelectionTaskId.value = '';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await uploadWorkspaceShippingInventory(taskId, file);
|
||||
await continueShippingInventoryUploadWithDify(taskId, result as unknown as Record<string, unknown>, file.name);
|
||||
await uploadInventoryForTask(taskId, file);
|
||||
} catch (e: unknown) {
|
||||
const errorMessage = e instanceof Error ? e.message : ctx.t('chat.shippingNoticeUploadFailed');
|
||||
ctx.msg.warning(errorMessage);
|
||||
} finally {
|
||||
ctx.shippingInventorySelectionTaskId.value = '';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -220,6 +295,8 @@ export function createShippingUploadHandlers(ctx: ShippingUploadHandlerContext)
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
openShippingInventoryPicker,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
handleShippingInventorySelected,
|
||||
shippingSuggestedPrompt,
|
||||
useShippingSuggestedPrompt,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/types/shipping.api.types.ts
|
||||
* 货代发货 Agent / 工作台发货任务 API 契约类型。
|
||||
* 用途:货代发货 Agent / 工作台 API 请求与响应契约类型。
|
||||
* 依赖:无(纯类型模块)。
|
||||
* 逻辑:shipping.api.ts 与 Chat/工作台组件统一引用本文件 DTO 类型。
|
||||
*/
|
||||
export interface ShippingTaskSummary {
|
||||
id: number;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* features/chat/types/shipping.types.ts
|
||||
* 发货通知(出货)流程相关类型:库存映射表单、菜单动作与附件。
|
||||
* 用途:发货通知聊天流程相关 TypeScript 类型定义。
|
||||
* 依赖:无(纯类型模块)。
|
||||
* 逻辑:shipping/* composable 与 Chat 消息组件统一引用本文件类型。
|
||||
*/
|
||||
|
||||
export type ShippingActionVariant = 'primary' | 'secondary' | 'danger';
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
"nextTask": "Next",
|
||||
"collapseTasks": "Hide tasks",
|
||||
"viewTasks": "View tasks",
|
||||
"inventoryTaskPickTitle": "Select inventory target task",
|
||||
"inventoryTaskPickHint": "This batch contains multiple tasks. To avoid cross-task mistakes, choose which task this inventory belongs to before uploading.",
|
||||
"inventoryTaskPickPendingHint": "This batch contains multiple tasks. To avoid cross-task mistakes, select the target task first and the pending inventory file will continue uploading after selection.",
|
||||
"cancelInventoryTaskPick": "Cancel",
|
||||
"uploadInventoryToTask": "Upload to this task",
|
||||
"inventoryTargetTask": "Inventory target {taskId}",
|
||||
"inventoryTargetIdle": "Waiting for target selection",
|
||||
"fileCount": "Files",
|
||||
"runningCount": "Running",
|
||||
"completedCount": "Completed",
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
"nextTask": "ถัดไป",
|
||||
"collapseTasks": "ซ่อนงาน",
|
||||
"viewTasks": "ดูงาน",
|
||||
"inventoryTaskPickTitle": "เลือกงานเป้าหมายของสต็อก",
|
||||
"inventoryTaskPickHint": "ชุดงานนี้มีหลายงาน เพื่อป้องกันการอัปโหลดผิดงาน โปรดเลือกก่อนว่าสต็อกนี้เป็นของงานใด",
|
||||
"inventoryTaskPickPendingHint": "ชุดงานนี้มีหลายงาน เพื่อป้องกันการอัปโหลดผิดงาน โปรดเลือกงานเป้าหมายก่อน แล้วระบบจะอัปโหลดไฟล์สต็อกที่เพิ่งเลือกต่อให้",
|
||||
"cancelInventoryTaskPick": "ยกเลิก",
|
||||
"uploadInventoryToTask": "อัปโหลดไปงานนี้",
|
||||
"inventoryTargetTask": "เป้าหมายสต็อก {taskId}",
|
||||
"inventoryTargetIdle": "รอเลือกงานเป้าหมาย",
|
||||
"fileCount": "จำนวนไฟล์",
|
||||
"runningCount": "กำลังดำเนินการ",
|
||||
"completedCount": "เสร็จแล้ว",
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
"nextTask": "下一票",
|
||||
"collapseTasks": "收起任务",
|
||||
"viewTasks": "查看任务",
|
||||
"inventoryTaskPickTitle": "请选择库存归属任务",
|
||||
"inventoryTaskPickHint": "当前批次包含多票。为避免串单,请先明确选择库存要上传到哪一票。",
|
||||
"inventoryTaskPickPendingHint": "当前批次包含多票。为避免串单,请先选择库存归属任务,系统会在选定后继续上传刚才的库存文件。",
|
||||
"cancelInventoryTaskPick": "取消选择",
|
||||
"uploadInventoryToTask": "上传库存到此票",
|
||||
"inventoryTargetTask": "库存目标 {taskId}",
|
||||
"inventoryTargetIdle": "等待选择库存目标",
|
||||
"fileCount": "文件数",
|
||||
"runningCount": "处理中",
|
||||
"completedCount": "已完成",
|
||||
|
||||
@@ -84,6 +84,13 @@
|
||||
"nextTask": "下一票",
|
||||
"collapseTasks": "收起任務",
|
||||
"viewTasks": "查看任務",
|
||||
"inventoryTaskPickTitle": "請選擇庫存歸屬任務",
|
||||
"inventoryTaskPickHint": "當前批次包含多票。為避免串單,請先明確選擇庫存要上傳到哪一票。",
|
||||
"inventoryTaskPickPendingHint": "當前批次包含多票。為避免串單,請先選擇庫存歸屬任務,系統會在選定後繼續上傳剛才的庫存檔案。",
|
||||
"cancelInventoryTaskPick": "取消選擇",
|
||||
"uploadInventoryToTask": "上傳庫存到此票",
|
||||
"inventoryTargetTask": "庫存目標 {taskId}",
|
||||
"inventoryTargetIdle": "等待選擇庫存目標",
|
||||
"fileCount": "檔案數",
|
||||
"runningCount": "處理中",
|
||||
"completedCount": "已完成",
|
||||
|
||||
Reference in new issue
Block a user