feat(file-check): 更新文件检核工具 API Key 配置及相关文档

This commit is contained in:
hugo committed 2026-06-17 22:29:15 +08:00
1 parent 634dee4b81
commit 55cf7ff734
74 files changed
+1525 -1182

No files matched your search

@@ -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,