agent-editor-mock.ts
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import { agentListMockFixtures, agentPositionOptions, type AgentPositionOption, type AgentStatus } from './agent-list-mock';
export type AgentEditorScenario =
| 'normal'
| 'loading'
| 'positionError'
| 'employeeError'
| 'skillError'
| 'saveError'
| 'saving';
export interface AgentSkillOption {
id: string;
name: string;
}
export interface AgentEmployeeOption {
user_id: number;
id: string;
name: string;
position_ids: string[];
status?: 'idle' | 'mounted';
}
export interface AgentDetailRecord {
agent_id: number;
name: string;
code: string;
positions: AgentPositionOption[];
managed_user: { user_id: number; user_name: string } | null;
description: string;
skill_ids: string[];
status: AgentStatus;
is_manager: boolean;
}
export interface AgentEditorFixture {
scenario: AgentEditorScenario;
detailLoading: boolean;
positionsLoading: boolean;
positionsError: boolean;
employeesLoading: boolean;
employeesError: boolean;
skillsLoading: boolean;
skillsError: boolean;
saveLoading: boolean;
saveError: boolean;
positions: AgentPositionOption[];
skills: AgentSkillOption[];
employees: AgentEmployeeOption[];
detail?: AgentDetailRecord;
}
export interface AgentDraftPayload {
name: string;
positionIds: string[];
managedUserId: number | undefined;
description: string;
skillIds: string[];
status: AgentStatus;
}
export const agentSkillOptions: AgentSkillOption[] = [
{ id: 'summary', name: '会话总结' },
{ id: 'reply', name: '智能回复' },
{ id: 'quality', name: '质检分析' },
{ id: 'lead', name: '线索跟进' },
];
const employeeDirectory: AgentEmployeeOption[] = [
{ user_id: 1, id: 'wx-sales-1', name: '陈晓岚', position_ids: ['sales'], status: 'idle' },
{ user_id: 2, id: 'wx-sales-2', name: '黄启航', position_ids: ['sales', 'ops'], status: 'mounted' },
{ user_id: 3, id: 'wx-service-1', name: '周语晴', position_ids: ['service'], status: 'idle' },
{ user_id: 4, id: 'wx-ops-1', name: '林择一', position_ids: ['ops'], status: 'idle' },
{ user_id: 5, id: 'wx-manager-1', name: '系统管家企微', position_ids: [], status: 'idle' },
];
const detailRecords: Record<string, AgentDetailRecord> = {
'1': {
agent_id: 1,
name: '管家Agent',
code: 'steward',
positions: [],
managed_user: { user_id: 5, user_name: '系统管家企微' },
description: '负责系统级调度与兜底回复。',
skill_ids: [],
status: 'enable',
is_manager: true,
},
'101': {
agent_id: 101,
name: '复盘Agent',
code: 'review_agent',
positions: [agentPositionOptions[0]],
managed_user: { user_id: 1, user_name: '陈晓岚' },
description: '负责成交复盘与客户跟进建议。',
skill_ids: ['summary', 'lead'],
status: 'enable',
is_manager: false,
},
'102': {
agent_id: 102,
name: '质检Agent',
code: 'quality_agent',
positions: [agentPositionOptions[1]],
managed_user: { user_id: 3, user_name: '周语晴' },
description: '负责会话质检与问题归因。',
skill_ids: ['quality'],
status: 'disable',
is_manager: false,
},
};
export function getAgentDetail(agentId?: string) {
if (!agentId) return undefined;
return detailRecords[agentId];
}
export function getEmployeesByPositions(positionIds: string[]) {
if (positionIds.length === 0) {
return [];
}
return employeeDirectory.filter((employee) => employee.position_ids.some((positionId) => positionIds.includes(positionId)));
}
export function getAgentEditorFixture({
agentId,
mode,
scenario = 'normal',
positionIds = [],
}: {
agentId?: string;
mode: 'create' | 'edit' | 'detail';
scenario?: AgentEditorScenario;
positionIds?: string[];
}): AgentEditorFixture {
const detail = mode === 'create' ? undefined : getAgentDetail(agentId);
const resolvedPositionIds = positionIds.length > 0
? positionIds
: detail?.positions.map((position) => position.id) ?? [];
return {
scenario,
detail,
detailLoading: scenario === 'loading' && mode !== 'create',
positionsLoading: false,
positionsError: scenario === 'positionError',
employeesLoading: false,
employeesError: scenario === 'employeeError',
skillsLoading: false,
skillsError: scenario === 'skillError',
saveLoading: scenario === 'saving',
saveError: scenario === 'saveError',
positions: agentPositionOptions,
employees: scenario === 'employeeError' ? [] : getEmployeesByPositions(resolvedPositionIds),
skills: scenario === 'skillError' ? [] : agentSkillOptions,
};
}
export function createAgentRecord(payload: AgentDraftPayload, positionOptions?: AgentPositionOption[]) {
const nextId = Math.max(...agentListMockFixtures.normal.items.map((item) => item.agent_id)) + 1;
const employee = employeeDirectory.find((item) => item.user_id === payload.managedUserId);
const positions = positionOptions ?? agentPositionOptions;
return {
agent_id: nextId,
name: payload.name,
code: `agent_${nextId}`,
positions: positions.filter((position) => payload.positionIds.includes(position.id)),
managed_user: payload.managedUserId && employee ? { user_id: payload.managedUserId, user_name: employee.name } : null,
description: payload.description,
skill_ids: payload.skillIds,
status: payload.status,
is_manager: false,
} satisfies AgentDetailRecord;
}