Files
group_xinghuo_jinrong/web/src/api/risk.ts
T
zhanghongyu_0626 3ad244add0 feat(analyst): Enhance dashboard metrics and customer service interactions
- Updated the `dashboard` function in `analyst.py` to include additional metrics for different user roles, improving data visibility for analysts, customers, advisors, and risk officers.
- Introduced a new `prepare_customer_stream` function in `customer_service.py` to facilitate streaming responses for customer interactions, enhancing the chat experience.
- Added new API endpoints in `analyst.ts` for fetching dashboard metrics and managing analyst assets, streamlining data handling and user interactions.
- Updated frontend components to support new dashboard features and asset management, ensuring a cohesive user experience across the application.

This update significantly improves the functionality and usability of the analyst and customer service features, providing users with enhanced tools for data analysis and interaction.
2026-09-09 21:32:59 +08:00

73 lines
2.0 KiB
TypeScript

import { apiFetch } from './client'
const RISK_AGENT_TYPE = 'risk'
function riskHeaders(token: string, extra?: HeadersInit): HeadersInit {
return {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
'X-Agent-Type': RISK_AGENT_TYPE,
...extra,
}
}
export type RiskAlertItem = {
alert_id: string
alert_type: string
customer_id: string
risk_score: number
status: string
created_at: string
}
type ListAlertsResponse = {
items: RiskAlertItem[]
total: number
disclaimer: string
page?: number
page_size?: number
}
export async function listPendingAlerts(token: string, pageSize = 100) {
const { data } = await apiFetch<ListAlertsResponse>(
`/api/risk/alerts?status=pending_review&page_size=${pageSize}`,
{ headers: riskHeaders(token) },
)
return data
}
export type ListAlertsParams = {
status?: string
alert_type?: string
customer_id?: string
page?: number
page_size?: number
}
export async function listAlerts(token: string, params: ListAlertsParams = {}) {
const q = new URLSearchParams()
if (params.status) q.set('status', params.status)
if (params.alert_type) q.set('alert_type', params.alert_type)
if (params.customer_id) q.set('customer_id', params.customer_id)
q.set('page', String(params.page ?? 1))
q.set('page_size', String(params.page_size ?? 20))
const { data } = await apiFetch<ListAlertsResponse>(`/api/risk/alerts?${q.toString()}`, {
headers: riskHeaders(token),
})
return data
}
export type HandleAlertPayload = {
handler_result: 'confirmed_normal' | 'confirmed_suspicious' | 'reported'
handler_comment?: string
}
export async function handleAlert(token: string, alertId: string, payload: HandleAlertPayload) {
const { data } = await apiFetch<Record<string, unknown>>(
`/api/risk/alerts/${encodeURIComponent(alertId)}/handle`,
{ method: 'POST', headers: riskHeaders(token), body: JSON.stringify(payload) },
)
return data
}