feat(ai): add personal expense application memory
This commit is contained in:
@@ -7,6 +7,62 @@ import {
|
||||
|
||||
export const AI_APPLICATION_ACTION_SAVE_DRAFT = 'ai_application_save_draft'
|
||||
export const AI_APPLICATION_ACTION_SUBMIT = 'ai_application_submit'
|
||||
const AI_APPLICATION_MEMORY_FIELD_LABELS = {
|
||||
amount: '预计金额',
|
||||
application_type: '申请类型',
|
||||
applicationType: '申请类型',
|
||||
days: '出差天数',
|
||||
location: '出差地点',
|
||||
reason: '申请事由',
|
||||
time: '出差时间',
|
||||
time_range: '出差时间',
|
||||
transport_mode: '出行方式',
|
||||
transportMode: '出行方式'
|
||||
}
|
||||
|
||||
export function normalizeAiApplicationMemory(item = {}) {
|
||||
if (!item || typeof item !== 'object') return null
|
||||
const memoryId = normalizeText(item.memoryId || item.memory_id)
|
||||
const fieldKey = normalizeText(item.fieldKey || item.field_key)
|
||||
const rawStatus = normalizeText(item.status).toLowerCase()
|
||||
const status = rawStatus === 'active' ? 'applied' : rawStatus
|
||||
if (!memoryId || !fieldKey || !status) return null
|
||||
return {
|
||||
memoryId,
|
||||
fieldKey,
|
||||
fieldLabel:
|
||||
normalizeText(item.fieldLabel || item.field_label)
|
||||
|| AI_APPLICATION_MEMORY_FIELD_LABELS[fieldKey]
|
||||
|| fieldKey,
|
||||
value: normalizeText(item.value),
|
||||
status,
|
||||
evidenceCount: Number(item.evidenceCount ?? item.evidence_count ?? 0) || 0,
|
||||
approvedEvidenceCount:
|
||||
Number(item.approvedEvidenceCount ?? item.approved_evidence_count ?? 0) || 0,
|
||||
message: normalizeText(item.message)
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeAiApplicationMemories(items = []) {
|
||||
return (Array.isArray(items) ? items : [])
|
||||
.map((item) => normalizeAiApplicationMemory(item))
|
||||
.filter(Boolean)
|
||||
}
|
||||
|
||||
export function resolveAiApplicationPreviewMemories(preview = {}) {
|
||||
const items = Array.isArray(preview?.memoryApplications)
|
||||
? preview.memoryApplications
|
||||
: preview?.memory_applications
|
||||
return normalizeAiApplicationMemories(items)
|
||||
}
|
||||
|
||||
export function resolveAiApplicationLearningReceipts(payload = {}) {
|
||||
const result = payload?.result && typeof payload.result === 'object' ? payload.result : payload
|
||||
const items = Array.isArray(result?.learning_receipts)
|
||||
? result.learning_receipts
|
||||
: result?.learningReceipts
|
||||
return normalizeAiApplicationMemories(items)
|
||||
}
|
||||
|
||||
export function createAiApplicationRequestId(prefix = 'application') {
|
||||
const normalizedPrefix = normalizeText(prefix) || 'application'
|
||||
@@ -42,6 +98,13 @@ export async function registerAiApplicationPreviewDecision({
|
||||
const serverPreview = payload?.application_preview && typeof payload.application_preview === 'object'
|
||||
? payload.application_preview
|
||||
: {}
|
||||
const memoryApplications = resolveAiApplicationPreviewMemories({
|
||||
memoryApplications:
|
||||
serverPreview.memoryApplications
|
||||
?? serverPreview.memory_applications
|
||||
?? normalizedPreview.memoryApplications
|
||||
?? normalizedPreview.memory_applications
|
||||
})
|
||||
return normalizeApplicationPreview({
|
||||
...normalizedPreview,
|
||||
...serverPreview,
|
||||
@@ -52,6 +115,7 @@ export async function registerAiApplicationPreviewDecision({
|
||||
decisionId: normalizeText(payload?.decision_id || serverPreview.decisionId),
|
||||
decisionSource: normalizeText(payload?.decision_source || serverPreview.decisionSource),
|
||||
decisionExpiresAt: normalizeText(payload?.expires_at || serverPreview.decisionExpiresAt),
|
||||
memoryApplications,
|
||||
decisionTrackingStatus: 'registered'
|
||||
})
|
||||
}
|
||||
@@ -199,3 +263,14 @@ export function runAiApplicationPreviewAction(params = {}, options = {}) {
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
export function forgetAiApplicationMemory(memoryId, options = {}) {
|
||||
const normalizedMemoryId = normalizeText(memoryId)
|
||||
if (!normalizedMemoryId) {
|
||||
return Promise.reject(new Error('缺少要忘记的偏好标识。'))
|
||||
}
|
||||
return apiRequest(`/expense-application-memories/${encodeURIComponent(normalizedMemoryId)}`, {
|
||||
method: 'DELETE',
|
||||
...options
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user