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

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