feat(ai): add personal expense application memory
This commit is contained in:
@@ -2,7 +2,9 @@ import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
normalizeInitialConversationMessages
|
||||
normalizeInitialConversationMessages,
|
||||
normalizeSnapshotMessage,
|
||||
serializeSessionMessages
|
||||
} from '../src/views/scripts/travelReimbursementConversationStateModel.js'
|
||||
|
||||
test('Orchestrator 会话恢复 assistant 的 application preview,并保留既有结果字段', () => {
|
||||
@@ -12,7 +14,14 @@ test('Orchestrator 会话恢复 assistant 的 application preview,并保留既
|
||||
applicationType: '差旅费用申请',
|
||||
location: '上海',
|
||||
reason: '客户现场实施'
|
||||
}
|
||||
},
|
||||
memoryApplications: [{
|
||||
memoryId: 'memory-session-1',
|
||||
fieldKey: 'reason',
|
||||
fieldLabel: '申请事由',
|
||||
value: '客户现场实施',
|
||||
status: 'applied'
|
||||
}]
|
||||
}
|
||||
const [message] = normalizeInitialConversationMessages({
|
||||
messages: [{
|
||||
@@ -24,6 +33,13 @@ test('Orchestrator 会话恢复 assistant 的 application preview,并保留既
|
||||
orchestrator_payload: {
|
||||
result: {
|
||||
application_preview: applicationPreview,
|
||||
learning_receipts: [{
|
||||
memoryId: 'memory-session-2',
|
||||
fieldKey: 'transport_mode',
|
||||
fieldLabel: '出行方式',
|
||||
value: '火车',
|
||||
status: 'candidate'
|
||||
}],
|
||||
draft_payload: { claim_id: 'claim-draft-1' },
|
||||
review_payload: { summary: '复核通过' },
|
||||
risk_flags: [{ code: 'policy-limit' }]
|
||||
@@ -34,11 +50,41 @@ test('Orchestrator 会话恢复 assistant 的 application preview,并保留既
|
||||
})
|
||||
|
||||
assert.deepEqual(message.applicationPreview, applicationPreview)
|
||||
assert.equal(message.applicationLearningReceipts[0].memoryId, 'memory-session-2')
|
||||
assert.deepEqual(message.draftPayload, { claim_id: 'claim-draft-1' })
|
||||
assert.deepEqual(message.reviewPayload, { summary: '复核通过' })
|
||||
assert.deepEqual(message.riskFlags, [{ code: 'policy-limit' }])
|
||||
})
|
||||
|
||||
test('本地快照跨刷新保留记忆应用和学习回执', () => {
|
||||
const [serialized] = serializeSessionMessages([{
|
||||
id: 'assistant-memory-snapshot',
|
||||
role: 'assistant',
|
||||
text: '申请预览',
|
||||
applicationPreview: {
|
||||
fields: { reason: '客户现场实施' },
|
||||
memoryApplications: [{
|
||||
memoryId: 'memory-local-applied',
|
||||
fieldKey: 'reason',
|
||||
fieldLabel: '申请事由',
|
||||
value: '客户现场实施',
|
||||
status: 'applied'
|
||||
}]
|
||||
},
|
||||
applicationLearningReceipts: [{
|
||||
memoryId: 'memory-local-candidate',
|
||||
fieldKey: 'transport_mode',
|
||||
fieldLabel: '出行方式',
|
||||
value: '火车',
|
||||
status: 'candidate'
|
||||
}]
|
||||
}])
|
||||
const restored = normalizeSnapshotMessage(serialized)
|
||||
|
||||
assert.equal(restored.applicationPreview.memoryApplications[0].status, 'applied')
|
||||
assert.equal(restored.applicationLearningReceipts[0].status, 'candidate')
|
||||
})
|
||||
|
||||
test('user 消息不能从 payload 恢复 application preview', () => {
|
||||
const [message] = normalizeInitialConversationMessages({
|
||||
messages: [{
|
||||
|
||||
Reference in New Issue
Block a user