@controleonline/ui-crm 1.0.65 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.66",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.66-rc.1",
|
|
5
|
+
"baseMaster": "7250a195dc6b3e88fcb69245e4ee4dbebf1b5249",
|
|
6
6
|
"tasks": [
|
|
7
|
-
64
|
|
8
|
-
1447
|
|
7
|
+
64
|
|
9
8
|
],
|
|
10
9
|
"frozen": true,
|
|
11
10
|
"repositories": {
|
|
12
|
-
"ControleOnline/ui-crm": "
|
|
11
|
+
"ControleOnline/ui-crm": "1914b740bf6800954bded23345c82beca57d04fc"
|
|
13
12
|
}
|
|
14
|
-
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* @agents /ai
|
|
3
|
-
*
|
|
2
|
+
* @agents /ai — customer-facing help chat.
|
|
3
|
+
* Left: the user's latest conversations (AI chats and tickets with the platform team).
|
|
4
|
+
* New conversation: "IA" when the user's company has its own AI (it solves with MCP tools and, if it
|
|
5
|
+
* cannot, turns the chat into a Support/Commercial ticket); otherwise choose Suporte or Comercial
|
|
6
|
+
* and a ticket is opened for the platform team. Logic: useMcpChat.
|
|
4
7
|
*/
|
|
5
|
-
import React, {
|
|
8
|
+
import React, {useRef, useState} from 'react';
|
|
6
9
|
import {
|
|
7
10
|
ActivityIndicator,
|
|
8
11
|
FlatList,
|
|
@@ -17,43 +20,21 @@ import {
|
|
|
17
20
|
import useMcpChat from './useMcpChat';
|
|
18
21
|
import styles from './McpPage.styles';
|
|
19
22
|
|
|
20
|
-
const {idOf, isCustomerConversation,
|
|
23
|
+
const {idOf, isCustomerConversation, stageLabel, messageRole} = require('./mcpChatUtils');
|
|
21
24
|
|
|
22
|
-
const
|
|
23
|
-
const CHANNEL_LABELS = {whatsapp: 'WhatsApp', email: 'E-mail', web: 'Site', ai: 'IA'};
|
|
24
|
-
const ROLE_LABELS = {ai: 'IA', note: 'Nota interna', customer: 'Cliente', staff: 'Equipe', me: null};
|
|
25
|
+
const ROLE_LABELS = {ai: 'IA', note: null, customer: null, staff: 'Equipe', me: null};
|
|
25
26
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<Text numberOfLines={1} style={styles.taskRowText}>
|
|
31
|
-
{item.name || `Conversa #${idOf(item)}`}
|
|
32
|
-
</Text>
|
|
33
|
-
{customer ? (
|
|
34
|
-
<Text style={styles.taskRowMeta}>
|
|
35
|
-
{CHANNEL_LABELS[conversationChannel(item)]} · {stageLabel(item)}
|
|
36
|
-
</Text>
|
|
37
|
-
) : null}
|
|
38
|
-
</TouchableOpacity>
|
|
39
|
-
);
|
|
40
|
-
};
|
|
27
|
+
const conversationLabel = task =>
|
|
28
|
+
isCustomerConversation(task)
|
|
29
|
+
? `${stageLabel(task)} · ${task?.taskStatus?.status || 'aberto'}`
|
|
30
|
+
: 'IA';
|
|
41
31
|
|
|
42
32
|
export default function McpPage() {
|
|
43
33
|
const chat = useMcpChat();
|
|
44
34
|
const [draft, setDraft] = useState('');
|
|
45
35
|
const listRef = useRef(null);
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
const mine = t => idOf(t.client) === Number(chat.currentPeopleId);
|
|
49
|
-
return [
|
|
50
|
-
chat.tasks.filter(t => !isCustomerConversation(t)),
|
|
51
|
-
chat.tasks.filter(t => isCustomerConversation(t) && mine(t)),
|
|
52
|
-
chat.tasks.filter(t => isCustomerConversation(t) && !mine(t)),
|
|
53
|
-
];
|
|
54
|
-
}, [chat.tasks, chat.currentPeopleId]);
|
|
55
|
-
const noAi = chat.providers.length === 0;
|
|
56
|
-
const ticketComposer = chat.myTicket || (!chat.activeTaskId && noAi);
|
|
36
|
+
const task = chat.activeTask;
|
|
37
|
+
const isNew = !chat.activeTaskId;
|
|
57
38
|
|
|
58
39
|
const submit = async () => {
|
|
59
40
|
const text = draft;
|
|
@@ -63,60 +44,50 @@ export default function McpPage() {
|
|
|
63
44
|
};
|
|
64
45
|
|
|
65
46
|
const renderMessage = ({item}) => {
|
|
66
|
-
const role = messageRole(item, {companyId: chat.companyId, task
|
|
67
|
-
|
|
47
|
+
const role = messageRole(item, {companyId: chat.companyId, task, currentPeopleId: chat.currentPeopleId});
|
|
48
|
+
if (role === 'note') return null; // internal notes of the team never show here
|
|
49
|
+
const right = role === 'me' || role === 'customer';
|
|
68
50
|
return (
|
|
69
|
-
<View style={[styles.bubble, right ? styles.bubbleUser : styles.bubbleAi
|
|
51
|
+
<View style={[styles.bubble, right ? styles.bubbleUser : styles.bubbleAi]}>
|
|
70
52
|
{ROLE_LABELS[role] ? <Text style={styles.bubbleAuthor}>{ROLE_LABELS[role]}</Text> : null}
|
|
71
53
|
<Text style={styles.bubbleText}>{item?.body || ''}</Text>
|
|
72
|
-
{item?.status
|
|
54
|
+
{item?.status === 'error' ? <Text style={styles.bubbleMeta}>não enviado</Text> : null}
|
|
73
55
|
</View>
|
|
74
56
|
);
|
|
75
57
|
};
|
|
76
58
|
|
|
77
59
|
const typing = chat.aiStatus ? (
|
|
78
60
|
<View style={[styles.bubble, styles.bubbleAi]}>
|
|
79
|
-
<Text style={styles.bubbleMeta}>{chat.aiStatus === 'processing' ? 'IA
|
|
61
|
+
<Text style={styles.bubbleMeta}>{chat.aiStatus === 'processing' ? 'IA analisando…' : 'Enviado, aguardando a IA…'}</Text>
|
|
80
62
|
</View>
|
|
81
63
|
) : null;
|
|
82
64
|
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
<Text style={styles.sectionTitle}>{title}</Text>
|
|
86
|
-
{items.length === 0 ? <Text style={styles.emptyText}>{empty}</Text> : null}
|
|
87
|
-
{items.map(item => (
|
|
88
|
-
<TaskRow key={String(idOf(item))} item={item} selected={idOf(item) === Number(chat.activeTaskId)} onPress={() => chat.setActiveTaskId(idOf(item))} />
|
|
89
|
-
))}
|
|
90
|
-
</View>
|
|
91
|
-
);
|
|
65
|
+
const options = chat.hasAi ? [['ai', 'IA']] : [['support', 'Suporte'], ['relationship', 'Comercial']];
|
|
66
|
+
const selected = chat.hasAi ? 'ai' : chat.ticketType;
|
|
92
67
|
|
|
93
|
-
const task = chat.activeTask;
|
|
94
68
|
return (
|
|
95
69
|
<KeyboardAvoidingView style={styles.root} behavior={Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={80}>
|
|
96
70
|
<View style={styles.sidebar}>
|
|
97
71
|
<View style={styles.sidebarHeader}>
|
|
98
|
-
<Text style={styles.sidebarTitle}>
|
|
72
|
+
<Text style={styles.sidebarTitle}>Atendimento</Text>
|
|
99
73
|
<TouchableOpacity onPress={chat.startNewChat} style={styles.newBtn}>
|
|
100
|
-
<Text style={styles.newBtnText}>Novo
|
|
74
|
+
<Text style={styles.newBtnText}>Novo</Text>
|
|
101
75
|
</TouchableOpacity>
|
|
102
76
|
</View>
|
|
103
|
-
<ScrollView horizontal style={styles.providerRow} contentContainerStyle={styles.providerRowContent}>
|
|
104
|
-
{noAi ? <Text style={styles.emptyText}>Sem IA própria: suas mensagens abrem um chamado.</Text> : null}
|
|
105
|
-
{chat.providers.map(p => (
|
|
106
|
-
<TouchableOpacity key={p.provider} onPress={() => chat.setProvider(p.provider)} style={[styles.providerChip, p.provider === chat.provider && styles.providerChipActive]}>
|
|
107
|
-
<Text style={[styles.providerChipText, p.provider === chat.provider && styles.providerChipTextActive]}>
|
|
108
|
-
{PROVIDER_LABELS[p.provider] || p.label || p.provider}
|
|
109
|
-
</Text>
|
|
110
|
-
</TouchableOpacity>
|
|
111
|
-
))}
|
|
112
|
-
</ScrollView>
|
|
113
77
|
{chat.loadingList ? (
|
|
114
78
|
<ActivityIndicator style={styles.spinner} />
|
|
115
79
|
) : (
|
|
116
80
|
<ScrollView>
|
|
117
|
-
{
|
|
118
|
-
{
|
|
119
|
-
|
|
81
|
+
{chat.tasks.length === 0 ? <Text style={styles.emptyText}>Nenhum chamado ainda.</Text> : null}
|
|
82
|
+
{chat.tasks.map(item => {
|
|
83
|
+
const id = idOf(item);
|
|
84
|
+
return (
|
|
85
|
+
<TouchableOpacity key={String(id)} onPress={() => chat.setActiveTaskId(id)} style={[styles.taskRow, id === Number(chat.activeTaskId) && styles.taskRowActive]}>
|
|
86
|
+
<Text numberOfLines={1} style={styles.taskRowText}>{item.name || `Chamado #${id}`}</Text>
|
|
87
|
+
<Text style={styles.taskRowMeta}>{conversationLabel(item)}</Text>
|
|
88
|
+
</TouchableOpacity>
|
|
89
|
+
);
|
|
90
|
+
})}
|
|
120
91
|
</ScrollView>
|
|
121
92
|
)}
|
|
122
93
|
</View>
|
|
@@ -124,26 +95,9 @@ export default function McpPage() {
|
|
|
124
95
|
<View style={styles.chatPane}>
|
|
125
96
|
<View style={styles.chatHeader}>
|
|
126
97
|
<View style={styles.chatHeaderText}>
|
|
127
|
-
<Text style={styles.chatTitle}>{task?.name ||
|
|
128
|
-
<Text style={styles.chatSubtitle}>
|
|
129
|
-
{chat.myTicket
|
|
130
|
-
? `Chamado ${stageLabel(task)} · ${task?.taskStatus?.status || 'aberto'}${task?.aiAgent ? ' · IA atendendo' : ''}`
|
|
131
|
-
: chat.customerChat
|
|
132
|
-
? `${CHANNEL_LABELS[conversationChannel(task)]} · ${stageLabel(task)} · IA atendendo`
|
|
133
|
-
: ticketComposer
|
|
134
|
-
? 'Novo chamado'
|
|
135
|
-
: PROVIDER_LABELS[chat.provider] || chat.provider || 'Selecione a IA'}
|
|
136
|
-
</Text>
|
|
98
|
+
<Text style={styles.chatTitle}>{isNew ? 'Como podemos ajudar?' : task?.name || `Chamado #${chat.activeTaskId}`}</Text>
|
|
99
|
+
{!isNew && task ? <Text style={styles.chatSubtitle}>{conversationLabel(task)}</Text> : null}
|
|
137
100
|
</View>
|
|
138
|
-
{chat.customerChat ? (
|
|
139
|
-
<View style={styles.actionsRow}>
|
|
140
|
-
{(task?.type === 'ia' ? ['relationship', 'support'] : [task?.type]).map(type => (
|
|
141
|
-
<TouchableOpacity key={type} style={styles.actionBtn} onPress={() => chat.takeOver(type)}>
|
|
142
|
-
<Text style={styles.actionBtnText}>{`Assumir${task?.type === 'ia' ? ` (${stageLabel({type})})` : ''}`}</Text>
|
|
143
|
-
</TouchableOpacity>
|
|
144
|
-
))}
|
|
145
|
-
</View>
|
|
146
|
-
) : null}
|
|
147
101
|
</View>
|
|
148
102
|
{chat.loadingChat ? (
|
|
149
103
|
<ActivityIndicator style={styles.spinner} />
|
|
@@ -156,30 +110,40 @@ export default function McpPage() {
|
|
|
156
110
|
ListFooterComponent={typing}
|
|
157
111
|
contentContainerStyle={styles.messagesContent}
|
|
158
112
|
onContentSizeChange={() => listRef.current?.scrollToEnd?.({animated: true})}
|
|
159
|
-
ListEmptyComponent={
|
|
113
|
+
ListEmptyComponent={
|
|
114
|
+
<Text style={styles.emptyText}>
|
|
115
|
+
{chat.hasAi ? 'Pergunte à IA. Se ela não resolver, abre um chamado com a nossa equipe.' : 'Escolha Suporte ou Comercial e descreva o que precisa.'}
|
|
116
|
+
</Text>
|
|
117
|
+
}
|
|
160
118
|
/>
|
|
161
119
|
)}
|
|
162
|
-
{
|
|
163
|
-
<
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
{
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
</View>
|
|
174
|
-
) : null}
|
|
175
|
-
<View style={styles.composer}>
|
|
176
|
-
<TextInput style={styles.input} value={draft} onChangeText={setDraft} placeholder={chat.myTicket ? 'Escreva no chamado…' : ticketComposer ? 'Descreva o que precisa; abriremos um chamado com a nossa equipe…' : 'Pergunte à IA…'} placeholderTextColor="#8b98a5" multiline editable={!chat.sending} />
|
|
177
|
-
<TouchableOpacity style={[styles.sendBtn, (!draft.trim() || chat.sending) && styles.sendBtnDisabled]} disabled={!draft.trim() || chat.sending} onPress={submit}>
|
|
178
|
-
<Text style={styles.sendBtnText}>{chat.sending ? '…' : ticketComposer && !chat.myTicket ? 'Abrir chamado' : 'Enviar'}</Text>
|
|
179
|
-
</TouchableOpacity>
|
|
180
|
-
</View>
|
|
120
|
+
{isNew ? (
|
|
121
|
+
<View style={styles.ticketTypeRow}>
|
|
122
|
+
{options.map(([value, label]) => (
|
|
123
|
+
<TouchableOpacity
|
|
124
|
+
key={value}
|
|
125
|
+
disabled={chat.hasAi}
|
|
126
|
+
onPress={() => chat.setTicketType(value)}
|
|
127
|
+
style={[styles.providerChip, selected === value && styles.providerChipActive]}>
|
|
128
|
+
<Text style={[styles.providerChipText, selected === value && styles.providerChipTextActive]}>{label}</Text>
|
|
129
|
+
</TouchableOpacity>
|
|
130
|
+
))}
|
|
181
131
|
</View>
|
|
182
|
-
)}
|
|
132
|
+
) : null}
|
|
133
|
+
<View style={styles.composer}>
|
|
134
|
+
<TextInput
|
|
135
|
+
style={styles.input}
|
|
136
|
+
value={draft}
|
|
137
|
+
onChangeText={setDraft}
|
|
138
|
+
placeholder={isNew ? 'Descreva o que precisa…' : 'Escreva uma mensagem…'}
|
|
139
|
+
placeholderTextColor="#8b98a5"
|
|
140
|
+
multiline
|
|
141
|
+
editable={!chat.sending}
|
|
142
|
+
/>
|
|
143
|
+
<TouchableOpacity style={[styles.sendBtn, (!draft.trim() || chat.sending) && styles.sendBtnDisabled]} disabled={!draft.trim() || chat.sending} onPress={submit}>
|
|
144
|
+
<Text style={styles.sendBtnText}>{chat.sending ? '…' : 'Enviar'}</Text>
|
|
145
|
+
</TouchableOpacity>
|
|
146
|
+
</View>
|
|
183
147
|
</View>
|
|
184
148
|
</KeyboardAvoidingView>
|
|
185
149
|
);
|
|
@@ -74,15 +74,14 @@ export default function useMcpChat() {
|
|
|
74
74
|
if (!companyId) return;
|
|
75
75
|
const base = {provider: `/people/${companyId}`, 'order[alterDate]': 'desc', itemsPerPage: 50};
|
|
76
76
|
try {
|
|
77
|
-
//
|
|
78
|
-
const [internal,
|
|
77
|
+
// The user's conversations: chats with the company AI + tickets with the platform team.
|
|
78
|
+
const [internal, tickets] = await Promise.all([
|
|
79
79
|
api.fetch('/tasks', {params: {...base, type: 'ia', ...(currentPeopleId ? {registeredBy: `/people/${currentPeopleId}`} : {})}}),
|
|
80
|
-
api.fetch('/tasks', {params: {...base, 'exists[aiAgent]': true}}),
|
|
81
80
|
currentPeopleId
|
|
82
81
|
? api.fetch('/tasks', {params: {client: `/people/${currentPeopleId}`, announce: 'via:ai', 'order[alterDate]': 'desc', itemsPerPage: 50}})
|
|
83
82
|
: Promise.resolve([]),
|
|
84
83
|
]);
|
|
85
|
-
setTasks(mergeConversations([toItems(internal), toItems(
|
|
84
|
+
setTasks(mergeConversations([toItems(internal), toItems(tickets)], currentPeopleId));
|
|
86
85
|
} catch (e) {
|
|
87
86
|
showError(e?.message || 'Falha ao listar conversas');
|
|
88
87
|
} finally {
|
|
@@ -259,6 +258,7 @@ export default function useMcpChat() {
|
|
|
259
258
|
setActiveTaskId,
|
|
260
259
|
customerChat,
|
|
261
260
|
myTicket,
|
|
261
|
+
hasAi: providers.length > 0,
|
|
262
262
|
ticketType,
|
|
263
263
|
setTicketType,
|
|
264
264
|
messages,
|