feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持
This commit is contained in:
1 parent
ac4262cd75
commit
c8ce77199e
183 files changed
+11690
-2300
No files matched your search
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* features/chat/shipping/shippingTurnActions.ts
|
||||
* 用途:将发货通知菜单/决策 action.id 映射为 Chat Turn action_type + payload。
|
||||
* 依赖:constants/shipping。
|
||||
* 逻辑:useChatShippingDecision 与 useChatShippingMenuHandler 调用本模块,不再直调 workspace API 插消息。
|
||||
*/
|
||||
import { SHIPPING_DECISION_ACTIONS } from '../constants/shipping';
|
||||
|
||||
export interface ShippingChatTurnSpec {
|
||||
actionType: string;
|
||||
payload: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将发货 UI 动作 id 解析为平台 Chat Turn 规格。
|
||||
* @param actionId - 状态机 action_buttons.id
|
||||
* @param taskNo - 任务编号
|
||||
* @param extra - 额外参数,如 confirm_inventory_source 的 source_code
|
||||
* @returns Chat Turn 规格;无法映射时返回 null
|
||||
*/
|
||||
export function resolveShippingChatTurn(
|
||||
actionId: string,
|
||||
taskNo: string,
|
||||
extra?: { sourceCode?: string },
|
||||
): ShippingChatTurnSpec | null {
|
||||
const normalizedTaskNo = String(taskNo || '').trim().toUpperCase();
|
||||
if (!normalizedTaskNo) return null;
|
||||
const id = String(actionId || '').trim();
|
||||
if (!id) return null;
|
||||
|
||||
if (SHIPPING_DECISION_ACTIONS.has(id)) {
|
||||
return {
|
||||
actionType: 'shipping.submit_decision',
|
||||
payload: { task_no: normalizedTaskNo, decision: id },
|
||||
};
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case 'generate_excel':
|
||||
return { actionType: 'shipping.generate_excel', payload: { task_no: normalizedTaskNo } };
|
||||
case 'retry_upload':
|
||||
return { actionType: 'shipping.retry_upload', payload: { task_no: normalizedTaskNo } };
|
||||
case 'match_inventory':
|
||||
return { actionType: 'shipping.match_inventory', payload: { task_no: normalizedTaskNo } };
|
||||
case 'mark_manual_uploaded':
|
||||
return { actionType: 'shipping.mark_manual_uploaded', payload: { task_no: normalizedTaskNo } };
|
||||
case 'confirm_inventory_source': {
|
||||
const sourceCode = String(extra?.sourceCode || '').trim().toUpperCase();
|
||||
if (!sourceCode) return null;
|
||||
return {
|
||||
actionType: 'shipping.confirm_inventory_source',
|
||||
payload: { task_no: normalizedTaskNo, source_code: sourceCode },
|
||||
};
|
||||
}
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 submit_decision Chat Turn(文本/菜单决策共用)。
|
||||
*/
|
||||
export function buildShippingSubmitDecisionTurn(
|
||||
taskNo: string,
|
||||
decision: string,
|
||||
): ShippingChatTurnSpec {
|
||||
return {
|
||||
actionType: 'shipping.submit_decision',
|
||||
payload: {
|
||||
task_no: String(taskNo || '').trim().toUpperCase(),
|
||||
decision: String(decision || '').trim(),
|
||||
},
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 构造发货通知建批 Chat Turn(multipart 上传)。
|
||||
*/
|
||||
export function buildShippingCreateBatchTurn(
|
||||
files: File[],
|
||||
conversationId?: string | null,
|
||||
): { actionType: string; displayText: string; payload: Record<string, unknown>; files: File[] } {
|
||||
const count = files.length;
|
||||
const displayText = count === 1
|
||||
? `上传发货通知:${files[0]?.name || '附件'}`
|
||||
: `上传 ${count} 份发货通知`;
|
||||
return {
|
||||
actionType: 'shipping.create_batch_from_notices',
|
||||
displayText,
|
||||
payload: {
|
||||
conversation_id: conversationId || undefined,
|
||||
file_count: count,
|
||||
},
|
||||
files,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造货代领域 refs,键名与 agent_runtime_context.refs 对齐。
|
||||
*/
|
||||
export function buildShippingTurnRefs(taskNo: string, batchNo?: string): Record<string, string> {
|
||||
const refs: Record<string, string> = {};
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
const batch = String(batchNo || '').trim();
|
||||
if (task) refs.task_no = task;
|
||||
if (batch) refs.batch_no = batch;
|
||||
return refs;
|
||||
}
|
||||
|
||||
export function buildShippingUploadInventoryTurn(taskNo: string, file: File) {
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
return {
|
||||
actionType: 'shipping.upload_inventory',
|
||||
displayText: `上传库存文件:${file.name}`,
|
||||
payload: { task_no: task },
|
||||
files: [file],
|
||||
refs: buildShippingTurnRefs(task),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildShippingReplaceNoticeTurn(taskNo: string, file: File) {
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
return {
|
||||
actionType: 'shipping.replace_notice',
|
||||
displayText: `重新上传发货通知:${file.name}`,
|
||||
payload: { task_no: task },
|
||||
files: [file],
|
||||
refs: buildShippingTurnRefs(task),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildShippingApplyMappingTurn(taskNo: string, mapping: Record<string, string>) {
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
return {
|
||||
actionType: 'shipping.apply_inventory_mapping',
|
||||
displayText: `应用库存列映射(任务 ${task})`,
|
||||
payload: { task_no: task, map_json: mapping },
|
||||
refs: buildShippingTurnRefs(task),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildShippingSwitchFocusTurn(batchNo: string, taskNo: string, displayText: string) {
|
||||
const batch = String(batchNo || '').trim();
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
return {
|
||||
actionType: 'shipping.switch_batch_focus',
|
||||
displayText,
|
||||
payload: { batch_no: batch, task_no: task },
|
||||
refs: buildShippingTurnRefs(task, batch),
|
||||
};
|
||||
}
|
||||
|
||||
export function buildShippingQueryShortageTurn(taskNo: string, displayText: string) {
|
||||
const task = String(taskNo || '').trim().toUpperCase();
|
||||
return {
|
||||
actionType: 'shipping.query_shortage_details',
|
||||
displayText,
|
||||
payload: { task_no: task },
|
||||
refs: buildShippingTurnRefs(task),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user