2026-05-25 13:35:39 +08:00
|
|
|
|
import assert from 'node:assert/strict'
|
|
|
|
|
|
import test from 'node:test'
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
mergeComposerPrefill,
|
|
|
|
|
|
resolveSuggestedActionPrefill
|
|
|
|
|
|
} from '../src/utils/assistantSuggestedActionPrefill.js'
|
|
|
|
|
|
|
|
|
|
|
|
test('suggested action prefill uses backend prompt payload', () => {
|
|
|
|
|
|
assert.equal(
|
|
|
|
|
|
resolveSuggestedActionPrefill({
|
|
|
|
|
|
action_type: 'prefill_composer',
|
|
|
|
|
|
payload: {
|
|
|
|
|
|
application_field: 'time',
|
|
|
|
|
|
prompt_prefill: '申请时间段:'
|
|
|
|
|
|
}
|
|
|
|
|
|
}),
|
|
|
|
|
|
'申请时间段:'
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
test('suggested action prefill falls back to application field templates', () => {
|
|
|
|
|
|
assert.equal(
|
|
|
|
|
|
resolveSuggestedActionPrefill({
|
|
|
|
|
|
action_type: 'prefill_composer',
|
|
|
|
|
|
payload: { application_field: 'amount' }
|
|
|
|
|
|
}),
|
2026-05-26 09:15:14 +08:00
|
|
|
|
'用户预估费用:'
|
2026-05-25 13:35:39 +08:00
|
|
|
|
)
|
|
|
|
|
|
assert.equal(
|
|
|
|
|
|
resolveSuggestedActionPrefill({
|
|
|
|
|
|
action_type: 'ask_clarification',
|
|
|
|
|
|
payload: { application_field: 'amount' }
|
|
|
|
|
|
}),
|
|
|
|
|
|
''
|
|
|
|
|
|
)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
test('composer prefill appends to existing draft without duplication', () => {
|
|
|
|
|
|
assert.equal(mergeComposerPrefill('', '事由:'), '事由:')
|
|
|
|
|
|
assert.equal(mergeComposerPrefill('地点:上海', '事由:'), '地点:上海\n事由:')
|
|
|
|
|
|
assert.equal(mergeComposerPrefill('地点:上海\n事由:', '事由:'), '地点:上海\n事由:')
|
|
|
|
|
|
})
|