Files
syops/frontend/src/features/chat/shipping/shippingTaskId.ts
T

25 lines
860 B
TypeScript

/**
* 出货聊天:任务编号提取(纯函数)。
*
* 从消息正文匹配 SHIPPING_TASK_ID_RE,或从侧栏会话标题模糊查找。
*/
import { SHIPPING_TASK_ID_RE } from '../constants/shipping';
import type { ChatSessionItem } from '../types/chat.types';
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);
if (match?.[0]) return match[0].toUpperCase();
}
return '';
}
export function findHistorySessionForShippingTask(
history: ChatSessionItem[],
taskId: string,
): ChatSessionItem | null {
const needle = taskId.trim().toUpperCase();
if (!needle) return null;
return history.find((item) => String(item.title || '').toUpperCase().includes(needle)) || null;
}