52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
|
|
import {
|
||
|
|
AI_APPLICATION_ACTION_SAVE_DRAFT,
|
||
|
|
AI_APPLICATION_ACTION_SUBMIT
|
||
|
|
} from '../../services/aiApplicationPreviewActions.js'
|
||
|
|
|
||
|
|
export function isReimbursementCreationIntent(prompt = '') {
|
||
|
|
const compact = String(prompt || '').replace(/\s+/g, '')
|
||
|
|
if (!compact || !/报销|报账/.test(compact)) {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
if (/标准|制度|规则|政策|口径|怎么|如何|能不能|可以吗|查一下|查询|状态|进度|多少钱|多少/.test(compact)) {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return (
|
||
|
|
/^(我要|我想|我需要|帮我|请帮我|需要|发起|新建|创建|提交|办理|走).{0,16}(报销|报账)/.test(compact) ||
|
||
|
|
/^(报销|报账)(一下|一笔|单|流程)?$/.test(compact)
|
||
|
|
)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveInlineApplicationPreviewTextAction(text = '') {
|
||
|
|
const normalized = String(text || '').replace(/\s+/g, '').trim()
|
||
|
|
if (!normalized) {
|
||
|
|
return ''
|
||
|
|
}
|
||
|
|
if (/^(保存草稿|保存|存草稿|先保存)$/.test(normalized)) {
|
||
|
|
return AI_APPLICATION_ACTION_SAVE_DRAFT
|
||
|
|
}
|
||
|
|
if (/^(提交|提交申请|确认提交|提交审批|直接提交)$/.test(normalized)) {
|
||
|
|
return AI_APPLICATION_ACTION_SUBMIT
|
||
|
|
}
|
||
|
|
return ''
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveLatestApplicationPreviewMessage(messages = []) {
|
||
|
|
return [...(Array.isArray(messages) ? messages : [])]
|
||
|
|
.reverse()
|
||
|
|
.find((message) => message?.role === 'assistant' && message.applicationPreview) || null
|
||
|
|
}
|
||
|
|
|
||
|
|
export function isOrphanInlineApplicationPreviewMessage(message = {}) {
|
||
|
|
if (message?.applicationPreview || message?.role !== 'assistant') {
|
||
|
|
return false
|
||
|
|
}
|
||
|
|
return /下方表格|申请核对表|点击对应行即可直接编辑/.test(String(message.content || message.text || ''))
|
||
|
|
}
|
||
|
|
|
||
|
|
export function resolveLatestOrphanApplicationPreviewMessage(messages = []) {
|
||
|
|
return [...(Array.isArray(messages) ? messages : [])]
|
||
|
|
.reverse()
|
||
|
|
.find((message) => isOrphanInlineApplicationPreviewMessage(message)) || null
|
||
|
|
}
|