88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
/**
|
|
* features/chat/shipping/shippingIntents.ts
|
|
* 用途:发货聊天用户输入意图识别,供 handleSend 前置拦截。
|
|
* 依赖:shippingMenu.resolveShippingNumericChoice、types/shipping.types。
|
|
* 逻辑:useChatShippingSendHandler 调用;覆盖手工上传、库存上传、Excel 生成/下载与切票。
|
|
*/
|
|
import { resolveShippingNumericChoice } from './shippingMenu';
|
|
import type { ShippingMenuAction } from '../types/shipping.types';
|
|
|
|
export interface ShippingTaskSwitchIntent {
|
|
mode: 'next' | 'prev' | 'task';
|
|
taskNo?: string;
|
|
}
|
|
|
|
/**
|
|
* 从自然语言文本解析库存列映射(part_number / reservation_id / available_qty → Excel 列名)。
|
|
*/
|
|
export function isShippingManualUploadIntent(text: string): boolean {
|
|
const normalized = text.trim();
|
|
if (!normalized) return false;
|
|
return [
|
|
/已在货代系统手工上传/,
|
|
/已手工上传/,
|
|
/手工上传完成/,
|
|
/手动上传完成/,
|
|
/货代.*上传完成/,
|
|
].some((pattern) => pattern.test(normalized));
|
|
}
|
|
|
|
export function isShippingInventoryUploadIntent(text: string, assistantContext: string): boolean {
|
|
const normalized = text.trim();
|
|
if (!normalized) return false;
|
|
const choice = resolveShippingNumericChoice(normalized, assistantContext);
|
|
if (choice === 'upload') return true;
|
|
return [
|
|
/^上传库存$/,
|
|
/上传库存文件/,
|
|
/手工上传/,
|
|
/选择库存/,
|
|
/upload.*inventory/i,
|
|
].some((pattern) => pattern.test(normalized));
|
|
}
|
|
|
|
export function isShippingGenerateExcelIntent(text: string): boolean {
|
|
const normalized = text.trim();
|
|
if (!normalized) return false;
|
|
return [
|
|
/^生成发货excel$/i,
|
|
/^生成发货\s*excel$/i,
|
|
/生成发货.*excel/i,
|
|
/生成.*发货.*excel/i,
|
|
].some((pattern) => pattern.test(normalized));
|
|
}
|
|
|
|
function normalizeShippingCommandText(text: string): string {
|
|
return String(text || '')
|
|
.trim()
|
|
.replace(/\s+/g, '')
|
|
.replace(/[,。!?、,.!?]/g, '')
|
|
.toLowerCase();
|
|
}
|
|
|
|
export function isShippingDownloadExcelIntent(text: string): boolean {
|
|
const normalized = normalizeShippingCommandText(text);
|
|
if (!normalized) return false;
|
|
if (!/(excel|xlsx|表格|发货文件|发货单)/i.test(normalized)) return false;
|
|
if (/(生成|创建|制作|重新生成|重生成)/.test(normalized)) return false;
|
|
return /(下载|获取|取得|拿|打开|查看|导出)/.test(normalized);
|
|
}
|
|
|
|
export function parseShippingTaskSwitchIntent(text: string): ShippingTaskSwitchIntent | null {
|
|
const normalized = String(text || '').trim();
|
|
if (!normalized) return null;
|
|
const taskMatch = normalized.match(/SN-\d{8}-[A-F0-9]{8}/i);
|
|
if (taskMatch?.[0] && /(切|切到|切换|goto|go to|switch)/i.test(normalized)) {
|
|
return { mode: 'task', taskNo: taskMatch[0].toUpperCase() };
|
|
}
|
|
if (/^(下一票|下一单|下一个|next)$/i.test(normalized) || /切到下一票/.test(normalized)) {
|
|
return { mode: 'next' };
|
|
}
|
|
if (/^(上一票|上一单|上一个|prev|previous)$/i.test(normalized) || /切到上一票/.test(normalized)) {
|
|
return { mode: 'prev' };
|
|
}
|
|
return null;
|
|
}
|
|
|
|
export type { ShippingMenuAction };
|