Files
X-Financial/web/src/utils/assistantSuggestedActionPrefill.js
caoxiaozhu 0e861d8fa6 feat: 增强风险规则生成引擎与预算中心页面
后端拆分风险规则生成为解释器、语义分析、本体对齐等子模块,
优化模板执行和流程图生成,完善员工种子数据和导入逻辑,增强
报销单权限策略和草稿持久化,前端新增预算中心视图和趋势图
组件,重构审计页面和风险规则测试对话框交互,完善文档中心
和报销创建页面细节,补充单元测试覆盖。
2026-05-26 09:15:14 +08:00

47 lines
1.3 KiB
JavaScript

const APPLICATION_FIELD_PREFILLS = {
time: '申请时间段:',
time_range: '申请时间段:',
location: '地点:',
reason: '事由:',
days: '天数:',
transport_mode: '出行方式:',
amount: '用户预估费用:'
}
export function resolveSuggestedActionPrefill(action = {}) {
const payload = action?.payload && typeof action.payload === 'object' ? action.payload : {}
const explicitPrefill = String(
payload.prompt_prefill
|| payload.input_prefill
|| payload.prefill_text
|| ''
).trim()
if (explicitPrefill) {
return explicitPrefill
}
const actionType = String(action?.action_type || '').trim()
if (actionType !== 'prefill_composer') {
return ''
}
const applicationField = String(payload.application_field || '').trim()
return APPLICATION_FIELD_PREFILLS[applicationField] || ''
}
export function mergeComposerPrefill(currentDraft = '', prefill = '') {
const normalizedPrefill = String(prefill || '').trim()
if (!normalizedPrefill) {
return String(currentDraft || '')
}
const current = String(currentDraft || '')
if (!current.trim()) {
return normalizedPrefill
}
if (current.includes(normalizedPrefill)) {
return current
}
return `${current.trimEnd()}\n${normalizedPrefill}`
}