@controleonline/ui-crm 1.0.65 → 1.0.69
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,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.68",
|
|
3
3
|
"rc": 1,
|
|
4
|
-
"branch": "rc/1.0.
|
|
5
|
-
"baseMaster": "
|
|
4
|
+
"branch": "rc/1.0.68-rc.1",
|
|
5
|
+
"baseMaster": "3474e1ce7b6d3dbdf5b1e11d67e41e1fa22fbeb3",
|
|
6
6
|
"tasks": [
|
|
7
7
|
64,
|
|
8
|
-
|
|
8
|
+
72
|
|
9
9
|
],
|
|
10
10
|
"frozen": true,
|
|
11
11
|
"repositories": {
|
|
12
|
-
"ControleOnline/ui-crm": "
|
|
12
|
+
"ControleOnline/ui-crm": "d1666948e80d583c46e4534d21c055143d1c8c1c"
|
|
13
13
|
}
|
|
14
|
-
}
|
|
14
|
+
}
|
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
|
-
|
|
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
|
+
// With the company's own AI the chat goes straight to it; the type choice exists only without AI.
|
|
66
|
+
const options = [['support', 'Suporte'], ['relationship', 'Comercial']];
|
|
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,39 @@ 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 ? 'Como podemos ajudar? Descreva o que precisa.' : 'Escolha Suporte ou Comercial e descreva o que precisa.'}
|
|
116
|
+
</Text>
|
|
117
|
+
}
|
|
160
118
|
/>
|
|
161
119
|
)}
|
|
162
|
-
{chat.
|
|
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 && !chat.hasAi ? (
|
|
121
|
+
<View style={styles.ticketTypeRow}>
|
|
122
|
+
{options.map(([value, label]) => (
|
|
123
|
+
<TouchableOpacity
|
|
124
|
+
key={value}
|
|
125
|
+
onPress={() => chat.setTicketType(value)}
|
|
126
|
+
style={[styles.providerChip, chat.ticketType === value && styles.providerChipActive]}>
|
|
127
|
+
<Text style={[styles.providerChipText, chat.ticketType === value && styles.providerChipTextActive]}>{label}</Text>
|
|
128
|
+
</TouchableOpacity>
|
|
129
|
+
))}
|
|
181
130
|
</View>
|
|
182
|
-
)}
|
|
131
|
+
) : null}
|
|
132
|
+
<View style={styles.composer}>
|
|
133
|
+
<TextInput
|
|
134
|
+
style={styles.input}
|
|
135
|
+
value={draft}
|
|
136
|
+
onChangeText={setDraft}
|
|
137
|
+
placeholder={isNew ? 'Descreva o que precisa…' : 'Escreva uma mensagem…'}
|
|
138
|
+
placeholderTextColor="#8b98a5"
|
|
139
|
+
multiline
|
|
140
|
+
editable={!chat.sending}
|
|
141
|
+
/>
|
|
142
|
+
<TouchableOpacity style={[styles.sendBtn, (!draft.trim() || chat.sending) && styles.sendBtnDisabled]} disabled={!draft.trim() || chat.sending} onPress={submit}>
|
|
143
|
+
<Text style={styles.sendBtnText}>{chat.sending ? '…' : 'Enviar'}</Text>
|
|
144
|
+
</TouchableOpacity>
|
|
145
|
+
</View>
|
|
183
146
|
</View>
|
|
184
147
|
</KeyboardAvoidingView>
|
|
185
148
|
);
|
|
@@ -64,7 +64,8 @@ export default function useMcpChat() {
|
|
|
64
64
|
const res = await api.fetch('/mcp/chat/providers', {params: companyId ? {company_id: companyId} : {}});
|
|
65
65
|
const list = Array.isArray(res?.providers) ? res.providers : [];
|
|
66
66
|
setProviders(list);
|
|
67
|
-
|
|
67
|
+
// The company's chosen AI (General settings → IA); otherwise the first connected one.
|
|
68
|
+
setProvider(prev => prev || res?.default || list.find(p => p.default)?.provider || list[0]?.provider || null);
|
|
68
69
|
} catch (e) {
|
|
69
70
|
showError(e?.message || 'Falha ao carregar providers de IA');
|
|
70
71
|
}
|
|
@@ -74,15 +75,14 @@ export default function useMcpChat() {
|
|
|
74
75
|
if (!companyId) return;
|
|
75
76
|
const base = {provider: `/people/${companyId}`, 'order[alterDate]': 'desc', itemsPerPage: 50};
|
|
76
77
|
try {
|
|
77
|
-
//
|
|
78
|
-
const [internal,
|
|
78
|
+
// The user's conversations: chats with the company AI + tickets with the platform team.
|
|
79
|
+
const [internal, tickets] = await Promise.all([
|
|
79
80
|
api.fetch('/tasks', {params: {...base, type: 'ia', ...(currentPeopleId ? {registeredBy: `/people/${currentPeopleId}`} : {})}}),
|
|
80
|
-
api.fetch('/tasks', {params: {...base, 'exists[aiAgent]': true}}),
|
|
81
81
|
currentPeopleId
|
|
82
82
|
? api.fetch('/tasks', {params: {client: `/people/${currentPeopleId}`, announce: 'via:ai', 'order[alterDate]': 'desc', itemsPerPage: 50}})
|
|
83
83
|
: Promise.resolve([]),
|
|
84
84
|
]);
|
|
85
|
-
setTasks(mergeConversations([toItems(internal), toItems(
|
|
85
|
+
setTasks(mergeConversations([toItems(internal), toItems(tickets)], currentPeopleId));
|
|
86
86
|
} catch (e) {
|
|
87
87
|
showError(e?.message || 'Falha ao listar conversas');
|
|
88
88
|
} finally {
|
|
@@ -259,6 +259,7 @@ export default function useMcpChat() {
|
|
|
259
259
|
setActiveTaskId,
|
|
260
260
|
customerChat,
|
|
261
261
|
myTicket,
|
|
262
|
+
hasAi: providers.length > 0,
|
|
262
263
|
ticketType,
|
|
263
264
|
setTicketType,
|
|
264
265
|
messages,
|
|
@@ -31,6 +31,7 @@ import MapsSection from './sections/MapsSection';
|
|
|
31
31
|
import ShopSettingsSection from './sections/shop/ShopSettingsSection';
|
|
32
32
|
import LogSection from './sections/LogSection';
|
|
33
33
|
import MaintenanceSection from './sections/MaintenanceSection';
|
|
34
|
+
import AiDefaultSection from './sections/AiDefaultSection';
|
|
34
35
|
|
|
35
36
|
const MAIN_COMPANY_ONLY_TABS = new Set(['shop']);
|
|
36
37
|
const TECHNICAL_TABS = new Set(['logs', 'maintenance']);
|
|
@@ -99,6 +100,13 @@ const SETTINGS_TABS = [
|
|
|
99
100
|
stores: ['configs'],
|
|
100
101
|
Component: CrmSection,
|
|
101
102
|
},
|
|
103
|
+
{
|
|
104
|
+
key: 'ai',
|
|
105
|
+
label: 'IA',
|
|
106
|
+
icon: 'chat',
|
|
107
|
+
stores: ['configs'],
|
|
108
|
+
Component: AiDefaultSection,
|
|
109
|
+
},
|
|
102
110
|
{
|
|
103
111
|
key: 'loyalty',
|
|
104
112
|
label: 'Fidelidade',
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @agents General settings → IA: lists the AIs already connected to the company (keys are configured in
|
|
3
|
+
* Integrações) and chooses which one the /ai chat uses (POST /mcp/chat/default, api-platform-mcp#86).
|
|
4
|
+
*/
|
|
5
|
+
import React, {useCallback, useEffect, useState} from 'react';
|
|
6
|
+
import {ActivityIndicator, Text, TouchableOpacity, View} from 'react-native';
|
|
7
|
+
import {useNavigation} from '@react-navigation/native';
|
|
8
|
+
|
|
9
|
+
import {api} from '@controleonline/ui-common/src/api';
|
|
10
|
+
import useToastMessage from '@controleonline/ui-crm/src/react/hooks/useToastMessage';
|
|
11
|
+
|
|
12
|
+
import {useGeneralSettingsPalette, useGeneralSettingsStyles} from '../GeneralSettings.styles';
|
|
13
|
+
import GeneralSettingsSection from '../GeneralSettingsSection';
|
|
14
|
+
import {useGeneralSettingsConfig} from '../GeneralSettings.shared';
|
|
15
|
+
|
|
16
|
+
const TITLES = {grok: 'Grok (xAI)', openai: 'Codex / OpenAI', gemini: 'Gemini', claude: 'Claude'};
|
|
17
|
+
|
|
18
|
+
const AiDefaultSection = () => {
|
|
19
|
+
const navigation = useNavigation();
|
|
20
|
+
const localStyles = useGeneralSettingsStyles();
|
|
21
|
+
const palette = useGeneralSettingsPalette();
|
|
22
|
+
const {showError, showSuccess} = useToastMessage();
|
|
23
|
+
const {currentCompany, mainCompany} = useGeneralSettingsConfig();
|
|
24
|
+
const companyId = Number(currentCompany?.id || mainCompany?.id || 0) || null;
|
|
25
|
+
|
|
26
|
+
const [loading, setLoading] = useState(true);
|
|
27
|
+
const [saving, setSaving] = useState(null);
|
|
28
|
+
const [providers, setProviders] = useState([]);
|
|
29
|
+
const [selected, setSelected] = useState(null);
|
|
30
|
+
|
|
31
|
+
const load = useCallback(async () => {
|
|
32
|
+
if (!companyId) return;
|
|
33
|
+
setLoading(true);
|
|
34
|
+
try {
|
|
35
|
+
const res = await api.fetch('/mcp/chat/providers', {params: {company_id: companyId}});
|
|
36
|
+
const list = Array.isArray(res?.providers) ? res.providers : [];
|
|
37
|
+
setProviders(list);
|
|
38
|
+
setSelected(res?.default || list.find(p => p.default)?.provider || list[0]?.provider || null);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
showError(e?.message || 'Não foi possível carregar as IAs conectadas.');
|
|
41
|
+
} finally {
|
|
42
|
+
setLoading(false);
|
|
43
|
+
}
|
|
44
|
+
}, [companyId, showError]);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
load();
|
|
48
|
+
}, [load]);
|
|
49
|
+
|
|
50
|
+
const choose = async provider => {
|
|
51
|
+
if (provider === selected || saving) return;
|
|
52
|
+
setSaving(provider);
|
|
53
|
+
try {
|
|
54
|
+
await api.post('/mcp/chat/default', {provider, company_id: companyId});
|
|
55
|
+
setSelected(provider);
|
|
56
|
+
showSuccess(`${TITLES[provider] || provider} será usada no atendimento.`);
|
|
57
|
+
} catch (e) {
|
|
58
|
+
showError(e?.message || 'Não foi possível salvar a IA padrão.');
|
|
59
|
+
} finally {
|
|
60
|
+
setSaving(null);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<GeneralSettingsSection
|
|
66
|
+
title="Inteligência Artificial"
|
|
67
|
+
description="Escolha qual das IAs conectadas atende no /ai. As chaves e modelos de cada IA são configurados em Integrações.">
|
|
68
|
+
{loading ? (
|
|
69
|
+
<ActivityIndicator style={{marginTop: 12}} />
|
|
70
|
+
) : providers.length === 0 ? (
|
|
71
|
+
<View>
|
|
72
|
+
<Text style={localStyles.helperText}>Nenhuma IA conectada nesta empresa.</Text>
|
|
73
|
+
<TouchableOpacity onPress={() => navigation.navigate('IntegrationsPage')} style={{marginTop: 8}}>
|
|
74
|
+
<Text style={{color: palette?.primary || '#1976d2', fontWeight: '600'}}>Conectar uma IA em Integrações</Text>
|
|
75
|
+
</TouchableOpacity>
|
|
76
|
+
</View>
|
|
77
|
+
) : (
|
|
78
|
+
<View>
|
|
79
|
+
{providers.map(p => {
|
|
80
|
+
const active = p.provider === selected;
|
|
81
|
+
return (
|
|
82
|
+
<TouchableOpacity
|
|
83
|
+
key={p.provider}
|
|
84
|
+
onPress={() => choose(p.provider)}
|
|
85
|
+
disabled={!!saving}
|
|
86
|
+
style={{
|
|
87
|
+
flexDirection: 'row',
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
paddingVertical: 12,
|
|
90
|
+
paddingHorizontal: 12,
|
|
91
|
+
marginBottom: 8,
|
|
92
|
+
borderRadius: 10,
|
|
93
|
+
borderWidth: 1,
|
|
94
|
+
borderColor: active ? palette?.primary || '#1976d2' : palette?.border || '#e2e8f0',
|
|
95
|
+
backgroundColor: palette?.surface || palette?.background || 'transparent',
|
|
96
|
+
}}>
|
|
97
|
+
<View
|
|
98
|
+
style={{
|
|
99
|
+
width: 18,
|
|
100
|
+
height: 18,
|
|
101
|
+
borderRadius: 9,
|
|
102
|
+
borderWidth: 2,
|
|
103
|
+
marginRight: 12,
|
|
104
|
+
borderColor: palette?.primary || '#1976d2',
|
|
105
|
+
backgroundColor: active ? palette?.primary || '#1976d2' : 'transparent',
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
<View style={{flex: 1}}>
|
|
109
|
+
<Text style={localStyles.sectionTitle}>{TITLES[p.provider] || p.label || p.provider}</Text>
|
|
110
|
+
<Text style={localStyles.helperText}>{p.model ? `Modelo: ${p.model}` : 'Modelo padrão'}</Text>
|
|
111
|
+
</View>
|
|
112
|
+
{saving === p.provider ? <ActivityIndicator /> : active ? <Text style={localStyles.helperText}>Em uso</Text> : null}
|
|
113
|
+
</TouchableOpacity>
|
|
114
|
+
);
|
|
115
|
+
})}
|
|
116
|
+
</View>
|
|
117
|
+
)}
|
|
118
|
+
</GeneralSettingsSection>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default AiDefaultSection;
|