@orbe-agro/client-core 5.6.339 → 5.6.340
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.
- package/dist/@ecme/assets/styles/app.css +39 -26
- package/dist/@ecme/assets/styles/tailwind/index.css +39 -26
- package/dist/@ecme/components/template/Footer.js +1 -1
- package/dist/@ecme/components/view/ChatBox/components/ChatInput.js +3 -2
- package/dist/@ecme/components/view/ChatBox/components/ChatInput.js.map +1 -1
- package/dist/@ecme/index.js +2 -1
- package/dist/@ecme/services/AiService.js +19 -2
- package/dist/@ecme/services/AiService.js.map +1 -1
- package/dist/@ecme/services/index.js +2 -1
- package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js +42 -40
- package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js.map +1 -1
- package/dist/@ecme/views/concepts/ai/Chat/components/FormatoCard.js +81 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/FormatoCard.js.map +1 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/ModeloERaciocinio.js +142 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/ModeloERaciocinio.js.map +1 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/PlanilhaNaMensagem.js +47 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/PlanilhaNaMensagem.js.map +1 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/RelatorioNaMensagem.js +64 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/RelatorioNaMensagem.js.map +1 -0
- package/dist/@ecme/views/concepts/ai/Chat/components/ToolCallChip.js +7 -3
- package/dist/@ecme/views/concepts/ai/Chat/components/ToolCallChip.js.map +1 -1
- package/dist/@ecme/views/concepts/ai/Chat/components/toolPresentation.js +12 -1
- package/dist/@ecme/views/concepts/ai/Chat/components/toolPresentation.js.map +1 -1
- package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js +47 -33
- package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js.map +1 -1
- package/dist/@ecme/views/concepts/ai/Chat/hooks/useModelos.js +31 -0
- package/dist/@ecme/views/concepts/ai/Chat/hooks/useModelos.js.map +1 -0
- package/dist/@ecme/views/concepts/ai/Chat/store/modeloStore.js +15 -0
- package/dist/@ecme/views/concepts/ai/Chat/store/modeloStore.js.map +1 -0
- package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts +2 -2
- package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts.map +1 -1
- package/dist/@types/@ecme/services/AiService.d.ts +15 -5
- package/dist/@types/@ecme/services/AiService.d.ts.map +1 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/ChatView.d.ts.map +1 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/FormatoCard.d.ts +16 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/FormatoCard.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/ModeloERaciocinio.d.ts +16 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/ModeloERaciocinio.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/PlanilhaNaMensagem.d.ts +14 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/PlanilhaNaMensagem.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/RelatorioNaMensagem.d.ts +15 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/RelatorioNaMensagem.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/ToolCallChip.d.ts.map +1 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/toolPresentation.d.ts.map +1 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useChatSend.d.ts +2 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useChatSend.d.ts.map +1 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useModelos.d.ts +26 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useModelos.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/store/modeloStore.d.ts +27 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/store/modeloStore.d.ts.map +1 -0
- package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts +89 -24
- package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts.map +1 -1
- package/dist/base/assets/styles/init.css +46 -30
- package/lib/@ecme/components/view/ChatBox/components/ChatInput.tsx +5 -4
- package/lib/@ecme/services/AiService.ts +31 -4
- package/lib/@ecme/views/concepts/ai/Chat/components/ChatView.tsx +43 -38
- package/lib/@ecme/views/concepts/ai/Chat/components/FormatoCard.tsx +123 -0
- package/lib/@ecme/views/concepts/ai/Chat/components/ModeloERaciocinio.tsx +200 -0
- package/lib/@ecme/views/concepts/ai/Chat/components/PlanilhaNaMensagem.tsx +65 -0
- package/lib/@ecme/views/concepts/ai/Chat/components/RelatorioNaMensagem.tsx +77 -0
- package/lib/@ecme/views/concepts/ai/Chat/components/ToolCallChip.tsx +12 -6
- package/lib/@ecme/views/concepts/ai/Chat/components/toolPresentation.ts +13 -0
- package/lib/@ecme/views/concepts/ai/Chat/hooks/useChatSend.ts +97 -60
- package/lib/@ecme/views/concepts/ai/Chat/hooks/useModelos.ts +63 -0
- package/lib/@ecme/views/concepts/ai/Chat/store/modeloStore.ts +25 -0
- package/lib/@ecme/views/concepts/ai/Chat/types.ts +96 -24
- package/package.json +1 -1
- package/dist/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.js +0 -85
- package/dist/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.js.map +0 -1
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.d.ts +0 -14
- package/dist/@types/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.d.ts.map +0 -1
- package/lib/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.tsx +0 -115
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { useRef, useEffect, useMemo
|
|
2
|
-
import { TbDownload } from 'react-icons/tb'
|
|
3
|
-
import * as XLSX from 'xlsx'
|
|
1
|
+
import { useRef, useEffect, useMemo } from 'react'
|
|
4
2
|
import Card from '@/components/ui/Card'
|
|
5
3
|
import ChatBox from '@/components/view/ChatBox'
|
|
6
4
|
import ChatLandingView from './ChatLandingView'
|
|
@@ -12,12 +10,16 @@ import AiErrorMessage from './AiErrorMessage'
|
|
|
12
10
|
import ToolCallChip from './ToolCallChip'
|
|
13
11
|
import ApprovalCard from './ApprovalCard'
|
|
14
12
|
import DataRequestCard from './DataRequestCard'
|
|
15
|
-
import
|
|
13
|
+
import FormatoCard from './FormatoCard'
|
|
14
|
+
import ModeloERaciocinio from './ModeloERaciocinio'
|
|
16
15
|
import ImagensDaMensagem from './ImagensDaMensagem'
|
|
16
|
+
import PlanilhaNaMensagem from './PlanilhaNaMensagem'
|
|
17
|
+
import RelatorioNaMensagem from './RelatorioNaMensagem'
|
|
17
18
|
import { UPLOAD_DE_IMAGENS } from '../imagens'
|
|
18
19
|
import { usGenerativeChatStore } from '../store/generativeChatStore'
|
|
19
20
|
import useChatSend from '../hooks/useChatSend'
|
|
20
21
|
import useConversationMessages from '../hooks/useConversationMessages'
|
|
22
|
+
import useModelos from '../hooks/useModelos'
|
|
21
23
|
import type { Conversation } from '../types'
|
|
22
24
|
import type { ScrollBarRef } from '@/components/ui/ScrollBar'
|
|
23
25
|
|
|
@@ -57,9 +59,12 @@ const ChatView = ({
|
|
|
57
59
|
const scrollRef = useRef<ScrollBarRef>(null)
|
|
58
60
|
const { selectedConversation, chatHistory, isTyping, disabledChatFresh } =
|
|
59
61
|
usGenerativeChatStore()
|
|
60
|
-
const { handleSend, handleApproval, handleDataSubmit } =
|
|
62
|
+
const { handleSend, handleApproval, handleDataSubmit, handleFormato } =
|
|
63
|
+
useChatSend()
|
|
61
64
|
// Conversa aberta da lista: as mensagens vêm do backend na primeira vez.
|
|
62
65
|
const { carregando } = useConversationMessages()
|
|
66
|
+
// Modelo que só lê texto: o botão de imagem fica desligado.
|
|
67
|
+
const { atual } = useModelos()
|
|
63
68
|
|
|
64
69
|
const scrollToBottom = () => {
|
|
65
70
|
if (scrollRef.current?.getScrollElement) {
|
|
@@ -96,23 +101,6 @@ const ChatView = ({
|
|
|
96
101
|
scrollToBottom()
|
|
97
102
|
}
|
|
98
103
|
|
|
99
|
-
const handleSpreadsheetDownload = useCallback(
|
|
100
|
-
(titulo: string, abas: Array<{ nome: string; colunas: string[]; linhas: Record<string, unknown>[] }>) => {
|
|
101
|
-
const workbook = XLSX.utils.book_new()
|
|
102
|
-
for (const aba of abas) {
|
|
103
|
-
const sheet = XLSX.utils.aoa_to_sheet([
|
|
104
|
-
aba.colunas,
|
|
105
|
-
...aba.linhas.map((linha) =>
|
|
106
|
-
aba.colunas.map((col) => linha[col] ?? ''),
|
|
107
|
-
),
|
|
108
|
-
])
|
|
109
|
-
XLSX.utils.book_append_sheet(workbook, sheet, aba.nome.slice(0, 31))
|
|
110
|
-
}
|
|
111
|
-
XLSX.writeFile(workbook, `${titulo}.xlsx`)
|
|
112
|
-
},
|
|
113
|
-
[],
|
|
114
|
-
)
|
|
115
|
-
|
|
116
104
|
return (
|
|
117
105
|
<Card className="flex-1 h-full" bodyClass="h-full">
|
|
118
106
|
{showMobileNav && <ChatMobileNav />}
|
|
@@ -153,8 +141,13 @@ const ChatView = ({
|
|
|
153
141
|
if (message.sender.id === 'ai') {
|
|
154
142
|
// As ferramentas e as pausas chegam pelo streaming e
|
|
155
143
|
// vivem no Conversation; o tipo do ChatBox nao os conhece.
|
|
156
|
-
const {
|
|
157
|
-
|
|
144
|
+
const {
|
|
145
|
+
tools,
|
|
146
|
+
pendingApproval,
|
|
147
|
+
pendingInput,
|
|
148
|
+
pendingFormat,
|
|
149
|
+
relatorios,
|
|
150
|
+
} = message as Conversation
|
|
158
151
|
// Enquanto as ferramentas rodam o conteudo ainda e '':
|
|
159
152
|
// sem esta guarda sobraria um balao cinza vazio.
|
|
160
153
|
const temTexto = Boolean(
|
|
@@ -181,20 +174,29 @@ const ChatView = ({
|
|
|
181
174
|
/>
|
|
182
175
|
</div>
|
|
183
176
|
)}
|
|
184
|
-
{
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
177
|
+
{relatorios?.map((relatorio) =>
|
|
178
|
+
relatorio.formato === 'xlsx' ? (
|
|
179
|
+
<PlanilhaNaMensagem
|
|
180
|
+
key={relatorio.id}
|
|
181
|
+
planilha={relatorio}
|
|
182
|
+
/>
|
|
183
|
+
) : (
|
|
184
|
+
<RelatorioNaMensagem
|
|
185
|
+
key={relatorio.id}
|
|
186
|
+
relatorio={relatorio}
|
|
187
|
+
/>
|
|
188
|
+
),
|
|
189
|
+
)}
|
|
190
|
+
{pendingFormat && (
|
|
191
|
+
<FormatoCard
|
|
192
|
+
onChoose={(formato) =>
|
|
193
|
+
handleFormato(
|
|
194
|
+
selectedConversation,
|
|
195
|
+
message.id,
|
|
196
|
+
formato,
|
|
191
197
|
)
|
|
192
198
|
}
|
|
193
|
-
|
|
194
|
-
>
|
|
195
|
-
<TbDownload size={18} />
|
|
196
|
-
<span>Baixar {spreadsheet.titulo}.xlsx</span>
|
|
197
|
-
</button>
|
|
199
|
+
/>
|
|
198
200
|
)}
|
|
199
201
|
{pendingInput && (
|
|
200
202
|
<DataRequestCard
|
|
@@ -244,9 +246,12 @@ const ChatView = ({
|
|
|
244
246
|
return null
|
|
245
247
|
}}
|
|
246
248
|
onInputChange={handleInputChange}
|
|
247
|
-
uploadProps={
|
|
249
|
+
uploadProps={{
|
|
250
|
+
...UPLOAD_DE_IMAGENS,
|
|
251
|
+
disabled: atual?.imagens === false,
|
|
252
|
+
}}
|
|
248
253
|
inputActions={
|
|
249
|
-
<
|
|
254
|
+
<ModeloERaciocinio floatingClass={dropdownFloatingClass} />
|
|
250
255
|
}
|
|
251
256
|
>
|
|
252
257
|
{/* Os children ficam entre a lista e o input: sem conversa e a
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
TbFileExport,
|
|
4
|
+
TbFileSpreadsheet,
|
|
5
|
+
TbReportAnalytics,
|
|
6
|
+
} from 'react-icons/tb'
|
|
7
|
+
import Button from '@/components/ui/Button'
|
|
8
|
+
import classNames from '@/components/ui/utils/classNames'
|
|
9
|
+
import type { IconType } from 'react-icons'
|
|
10
|
+
import type { FormatoDoRelatorio } from '../types'
|
|
11
|
+
|
|
12
|
+
type OpcaoDeFormato = {
|
|
13
|
+
formato: FormatoDoRelatorio
|
|
14
|
+
titulo: string
|
|
15
|
+
descricao: string
|
|
16
|
+
Icone: IconType
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const OPCOES: ReadonlyArray<OpcaoDeFormato> = [
|
|
20
|
+
{
|
|
21
|
+
formato: 'html',
|
|
22
|
+
titulo: 'Relatório HTML',
|
|
23
|
+
descricao:
|
|
24
|
+
'Visual, com indicadores e gráficos. Abre aqui e no navegador.',
|
|
25
|
+
Icone: TbReportAnalytics,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
formato: 'xlsx',
|
|
29
|
+
titulo: 'Planilha Excel',
|
|
30
|
+
descricao: 'Os registros em colunas, para filtrar e trabalhar.',
|
|
31
|
+
Icone: TbFileSpreadsheet,
|
|
32
|
+
},
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
type FormatoCardProps = {
|
|
36
|
+
/** `null` = o usuario fechou sem escolher. */
|
|
37
|
+
onChoose: (formato: FormatoDoRelatorio | null) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A escolha do formato de um relatorio que o usuario pediu sem dizer qual.
|
|
42
|
+
*
|
|
43
|
+
* O agente fica PARADO enquanto este card estiver na tela, como no ApprovalCard
|
|
44
|
+
* e no DataRequestCard - e divide o visual deles, para o usuario reconhecer as
|
|
45
|
+
* tres paradas como a mesma coisa. Depois do clique tudo desabilita: dois
|
|
46
|
+
* cliques mandariam duas retomadas, e a segunda falha.
|
|
47
|
+
*/
|
|
48
|
+
const FormatoCard = ({ onChoose }: FormatoCardProps) => {
|
|
49
|
+
// `undefined` = ainda nao escolheu; `null` = fechou sem escolher.
|
|
50
|
+
const [escolha, setEscolha] = useState<FormatoDoRelatorio | null>()
|
|
51
|
+
const decidido = escolha !== undefined
|
|
52
|
+
|
|
53
|
+
const escolher = (formato: FormatoDoRelatorio | null) => {
|
|
54
|
+
setEscolha(formato)
|
|
55
|
+
onChoose(formato)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div className="not-prose mt-1 overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
|
60
|
+
<div className="flex items-center gap-2 border-b border-gray-200 px-4 py-2.5 dark:border-gray-700">
|
|
61
|
+
<TbFileExport
|
|
62
|
+
size={16}
|
|
63
|
+
className="text-gray-400 dark:text-gray-500"
|
|
64
|
+
/>
|
|
65
|
+
<span className="text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">
|
|
66
|
+
Formato do relatório
|
|
67
|
+
</span>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div className="px-4 py-3.5">
|
|
71
|
+
<div className="mb-3 text-sm text-gray-500 dark:text-gray-400">
|
|
72
|
+
Em qual formato você quer o relatório?
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div className="grid gap-2 sm:grid-cols-2">
|
|
76
|
+
{OPCOES.map(({ formato, titulo, descricao, Icone }) => (
|
|
77
|
+
<button
|
|
78
|
+
key={formato}
|
|
79
|
+
type="button"
|
|
80
|
+
disabled={decidido}
|
|
81
|
+
aria-pressed={escolha === formato}
|
|
82
|
+
onClick={() => escolher(formato)}
|
|
83
|
+
className={classNames(
|
|
84
|
+
'flex items-start gap-2.5 rounded-lg border px-3 py-2.5 text-left transition-colors disabled:cursor-not-allowed',
|
|
85
|
+
escolha === formato
|
|
86
|
+
? 'border-primary bg-primary-subtle'
|
|
87
|
+
: 'border-gray-200 enabled:hover:border-primary enabled:hover:bg-gray-50 disabled:opacity-60 dark:border-gray-700 dark:enabled:hover:bg-gray-700',
|
|
88
|
+
)}
|
|
89
|
+
>
|
|
90
|
+
<span className="mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary">
|
|
91
|
+
<Icone size={17} />
|
|
92
|
+
</span>
|
|
93
|
+
<span className="min-w-0">
|
|
94
|
+
<span className="block font-semibold text-gray-900 dark:text-gray-100">
|
|
95
|
+
{titulo}
|
|
96
|
+
</span>
|
|
97
|
+
<span className="block text-xs text-gray-500 dark:text-gray-400">
|
|
98
|
+
{descricao}
|
|
99
|
+
</span>
|
|
100
|
+
</span>
|
|
101
|
+
</button>
|
|
102
|
+
))}
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
<div className="mt-4 flex items-center gap-2">
|
|
106
|
+
<Button
|
|
107
|
+
size="sm"
|
|
108
|
+
loading={escolha === null}
|
|
109
|
+
disabled={decidido}
|
|
110
|
+
onClick={() => escolher(null)}
|
|
111
|
+
>
|
|
112
|
+
Agora não
|
|
113
|
+
</Button>
|
|
114
|
+
<span className="ml-auto text-xs text-gray-400 dark:text-gray-500">
|
|
115
|
+
Os dados saem da consulta, com o seu acesso
|
|
116
|
+
</span>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export default FormatoCard
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { TbBrain, TbCheck, TbChevronDown, TbSparkles } from 'react-icons/tb'
|
|
2
|
+
import Dropdown from '@/components/ui/Dropdown'
|
|
3
|
+
import useModelos from '../hooks/useModelos'
|
|
4
|
+
import { useEsforcoStore } from '../store/esforcoStore'
|
|
5
|
+
import { useModeloStore } from '../store/modeloStore'
|
|
6
|
+
import type { Esforco } from '../types'
|
|
7
|
+
|
|
8
|
+
type NivelDeEsforco = {
|
|
9
|
+
valor: Esforco
|
|
10
|
+
rotulo: string
|
|
11
|
+
descricao: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Os níveis, do menor para o maior raciocínio. Servem o botão e o menu. */
|
|
15
|
+
const NIVEIS: ReadonlyArray<NivelDeEsforco> = [
|
|
16
|
+
{
|
|
17
|
+
valor: 'minimal',
|
|
18
|
+
rotulo: 'Mínimo',
|
|
19
|
+
descricao: 'Mais rápido, para consultas diretas.',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
valor: 'medium',
|
|
23
|
+
rotulo: 'Médio',
|
|
24
|
+
descricao: 'Equilíbrio entre rapidez e cuidado. Recomendado.',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
valor: 'high',
|
|
28
|
+
rotulo: 'Alto',
|
|
29
|
+
descricao: 'Pensa mais antes de responder; bom para análises.',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
valor: 'max',
|
|
33
|
+
rotulo: 'Máximo',
|
|
34
|
+
descricao: 'Pensa o máximo possível antes de responder.',
|
|
35
|
+
},
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/** O `eventKey` do Dropdown é `string`; só um dos níveis acima é aceito. */
|
|
39
|
+
const ehEsforco = (valor: string): valor is Esforco =>
|
|
40
|
+
NIVEIS.some((nivel) => nivel.valor === valor)
|
|
41
|
+
|
|
42
|
+
// O MenuItem fixa 42px de altura e `nowrap`, feitos para uma linha; aqui um
|
|
43
|
+
// item pode ter título e descrição.
|
|
44
|
+
const ALTURA_LIVRE = { height: 'auto' }
|
|
45
|
+
const ITEM_EM_DUAS_LINHAS = 'items-start whitespace-normal py-2'
|
|
46
|
+
|
|
47
|
+
type SecaoProps = {
|
|
48
|
+
titulo: string
|
|
49
|
+
descricao: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Cabeçalho de uma seção do menu. */
|
|
53
|
+
const Secao = ({ titulo, descricao }: SecaoProps) => (
|
|
54
|
+
<Dropdown.Item variant="header">
|
|
55
|
+
<div className="px-3 pb-2">
|
|
56
|
+
<div className="heading-text text-sm font-bold">{titulo}</div>
|
|
57
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
58
|
+
{descricao}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
</Dropdown.Item>
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
type OpcaoProps = {
|
|
65
|
+
titulo: string
|
|
66
|
+
descricao?: string
|
|
67
|
+
marcada: boolean
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Conteúdo de um item: título, descrição e o check no escolhido. */
|
|
71
|
+
const Opcao = ({ titulo, descricao, marcada }: OpcaoProps) => (
|
|
72
|
+
<>
|
|
73
|
+
<div className="flex-1">
|
|
74
|
+
<div>{titulo}</div>
|
|
75
|
+
{descricao && (
|
|
76
|
+
<div className="text-xs font-normal text-gray-500 dark:text-gray-400">
|
|
77
|
+
{descricao}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
{marcada && <TbCheck className="mt-0.5 shrink-0 text-lg" />}
|
|
82
|
+
</>
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
type ModeloERaciocinioProps = {
|
|
86
|
+
/** Classes do menu flutuante; o widget passa um z-index acima do painel. */
|
|
87
|
+
floatingClass?: string
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* O modelo e o nível de raciocínio, num menu só dentro da caixa de mensagem.
|
|
92
|
+
*
|
|
93
|
+
* Com mais de um modelo para escolher, o botão mostra o modelo e o menu tem as
|
|
94
|
+
* duas seções. Com um só, sem a permissão de escolher (ver `useModelos`) ou sem
|
|
95
|
+
* a lista do backend, fica como era: o botão mostra o nível e o menu só tem o
|
|
96
|
+
* raciocínio. A escolha vale para as próximas mensagens (e para as retomadas de
|
|
97
|
+
* aprovação e de formulário); as respostas já dadas não mudam.
|
|
98
|
+
*/
|
|
99
|
+
const ModeloERaciocinio = ({ floatingClass }: ModeloERaciocinioProps) => {
|
|
100
|
+
const { esforco, setEsforco } = useEsforcoStore()
|
|
101
|
+
const setModelo = useModeloStore((state) => state.setModelo)
|
|
102
|
+
const { modelos, escolhido } = useModelos()
|
|
103
|
+
|
|
104
|
+
const nivelAtual = NIVEIS.find((nivel) => nivel.valor === esforco)
|
|
105
|
+
const modeloAtual = modelos.length > 1 ? escolhido : undefined
|
|
106
|
+
|
|
107
|
+
const handleEsforco = (valor: string) => {
|
|
108
|
+
if (ehEsforco(valor)) {
|
|
109
|
+
setEsforco(valor)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Como no nível: só um id da lista do backend é aceito. */
|
|
114
|
+
const handleModelo = (id: string) => {
|
|
115
|
+
if (modelos.some((modelo) => modelo.id === id)) {
|
|
116
|
+
setModelo(id)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const rotuloDoBotao = modeloAtual
|
|
121
|
+
? `Modelo: ${modeloAtual.nome}. Raciocínio: ${nivelAtual?.rotulo}`
|
|
122
|
+
: `Nível de raciocínio: ${nivelAtual?.rotulo}`
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<Dropdown
|
|
126
|
+
placement="top-end"
|
|
127
|
+
menuClass="w-72 max-h-[60vh] overflow-y-auto"
|
|
128
|
+
// Sem largura mínima: num painel estreito o nome do modelo é
|
|
129
|
+
// cortado antes de o campo de texto sumir.
|
|
130
|
+
toggleClassName="min-w-0"
|
|
131
|
+
floatingClass={floatingClass}
|
|
132
|
+
renderTitle={
|
|
133
|
+
<button
|
|
134
|
+
type="button"
|
|
135
|
+
aria-label={rotuloDoBotao}
|
|
136
|
+
title={rotuloDoBotao}
|
|
137
|
+
className="flex min-w-0 items-center gap-1 rounded-lg px-2 py-1 text-xs font-semibold text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-100"
|
|
138
|
+
>
|
|
139
|
+
{modeloAtual ? (
|
|
140
|
+
<TbSparkles className="shrink-0 text-base" />
|
|
141
|
+
) : (
|
|
142
|
+
<TbBrain className="shrink-0 text-base" />
|
|
143
|
+
)}
|
|
144
|
+
<span className="min-w-0 max-w-[9rem] truncate">
|
|
145
|
+
{modeloAtual?.nome ?? nivelAtual?.rotulo}
|
|
146
|
+
</span>
|
|
147
|
+
<TbChevronDown className="shrink-0" />
|
|
148
|
+
</button>
|
|
149
|
+
}
|
|
150
|
+
>
|
|
151
|
+
{modeloAtual && (
|
|
152
|
+
<>
|
|
153
|
+
<Secao
|
|
154
|
+
titulo="Modelo"
|
|
155
|
+
descricao="Qual inteligência artificial responde."
|
|
156
|
+
/>
|
|
157
|
+
{modelos.map((modelo) => (
|
|
158
|
+
<Dropdown.Item
|
|
159
|
+
key={modelo.id}
|
|
160
|
+
eventKey={modelo.id}
|
|
161
|
+
onSelect={handleModelo}
|
|
162
|
+
style={ALTURA_LIVRE}
|
|
163
|
+
className={ITEM_EM_DUAS_LINHAS}
|
|
164
|
+
>
|
|
165
|
+
<Opcao
|
|
166
|
+
titulo={modelo.nome}
|
|
167
|
+
descricao={
|
|
168
|
+
modelo.imagens ? undefined : 'Só lê texto.'
|
|
169
|
+
}
|
|
170
|
+
marcada={modelo.id === modeloAtual.id}
|
|
171
|
+
/>
|
|
172
|
+
</Dropdown.Item>
|
|
173
|
+
))}
|
|
174
|
+
<Dropdown.Item variant="divider" />
|
|
175
|
+
</>
|
|
176
|
+
)}
|
|
177
|
+
<Secao
|
|
178
|
+
titulo="Raciocínio"
|
|
179
|
+
descricao="Quanto o assistente pensa antes de responder."
|
|
180
|
+
/>
|
|
181
|
+
{NIVEIS.map((nivel) => (
|
|
182
|
+
<Dropdown.Item
|
|
183
|
+
key={nivel.valor}
|
|
184
|
+
eventKey={nivel.valor}
|
|
185
|
+
onSelect={handleEsforco}
|
|
186
|
+
style={ALTURA_LIVRE}
|
|
187
|
+
className={ITEM_EM_DUAS_LINHAS}
|
|
188
|
+
>
|
|
189
|
+
<Opcao
|
|
190
|
+
titulo={nivel.rotulo}
|
|
191
|
+
descricao={nivel.descricao}
|
|
192
|
+
marcada={nivel.valor === esforco}
|
|
193
|
+
/>
|
|
194
|
+
</Dropdown.Item>
|
|
195
|
+
))}
|
|
196
|
+
</Dropdown>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export default ModeloERaciocinio
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { TbDownload, TbFileSpreadsheet } from 'react-icons/tb'
|
|
2
|
+
import * as XLSX from 'xlsx'
|
|
3
|
+
import Button from '@/components/ui/Button'
|
|
4
|
+
import type { PlanilhaDoChat } from '../types'
|
|
5
|
+
|
|
6
|
+
type PlanilhaNaMensagemProps = {
|
|
7
|
+
planilha: PlanilhaDoChat
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** O Excel limita o nome da aba a 31 caracteres. */
|
|
11
|
+
const MAX_NOME_DA_ABA = 31
|
|
12
|
+
|
|
13
|
+
/** Monta o .xlsx no navegador, uma aba por aba do backend, com o nome que ele deu. */
|
|
14
|
+
const baixarPlanilha = ({ abas, arquivo }: PlanilhaDoChat) => {
|
|
15
|
+
const workbook = XLSX.utils.book_new()
|
|
16
|
+
for (const aba of abas) {
|
|
17
|
+
const folha = XLSX.utils.aoa_to_sheet([aba.colunas, ...aba.linhas])
|
|
18
|
+
XLSX.utils.book_append_sheet(
|
|
19
|
+
workbook,
|
|
20
|
+
folha,
|
|
21
|
+
aba.nome.slice(0, MAX_NOME_DA_ABA),
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
XLSX.writeFile(workbook, arquivo)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Uma planilha gerada pelo agente: o resumo e o download.
|
|
29
|
+
*
|
|
30
|
+
* Os registros chegam do backend como vieram da consulta; o .xlsx so nasce no
|
|
31
|
+
* clique, para a mensagem nao carregar um arquivo que talvez ninguem baixe. A
|
|
32
|
+
* primeira aba e a dos registros, e por ela se conta as linhas.
|
|
33
|
+
*/
|
|
34
|
+
const PlanilhaNaMensagem = ({ planilha }: PlanilhaNaMensagemProps) => {
|
|
35
|
+
const linhas = planilha.abas[0]?.linhas.length ?? 0
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div className="not-prose w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
|
39
|
+
<div className="flex flex-wrap items-center gap-3 px-4 py-3">
|
|
40
|
+
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary">
|
|
41
|
+
<TbFileSpreadsheet size={17} />
|
|
42
|
+
</span>
|
|
43
|
+
<div className="min-w-0 flex-1">
|
|
44
|
+
<div className="truncate font-semibold text-gray-900 dark:text-gray-100">
|
|
45
|
+
{planilha.titulo}
|
|
46
|
+
</div>
|
|
47
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
48
|
+
Planilha Excel · {linhas}{' '}
|
|
49
|
+
{linhas === 1 ? 'linha' : 'linhas'}
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
<Button
|
|
53
|
+
size="sm"
|
|
54
|
+
variant="solid"
|
|
55
|
+
icon={<TbDownload />}
|
|
56
|
+
onClick={() => baixarPlanilha(planilha)}
|
|
57
|
+
>
|
|
58
|
+
Baixar planilha
|
|
59
|
+
</Button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default PlanilhaNaMensagem
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { TbDownload, TbEye, TbEyeOff, TbReportAnalytics } from 'react-icons/tb'
|
|
3
|
+
import Button from '@/components/ui/Button'
|
|
4
|
+
import type { RelatorioHtml } from '../types'
|
|
5
|
+
|
|
6
|
+
type RelatorioNaMensagemProps = {
|
|
7
|
+
relatorio: RelatorioHtml
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Baixa o MESMO texto que a prévia mostra, com o nome que o backend deu. */
|
|
11
|
+
const baixarHtml = ({ html, arquivo }: RelatorioHtml) => {
|
|
12
|
+
const link = document.createElement('a')
|
|
13
|
+
link.href = URL.createObjectURL(
|
|
14
|
+
new Blob([html], { type: 'text/html;charset=utf-8' }),
|
|
15
|
+
)
|
|
16
|
+
link.download = arquivo
|
|
17
|
+
link.click()
|
|
18
|
+
URL.revokeObjectURL(link.href)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Um relatório gerado pelo agente: a prévia dentro do chat e o download.
|
|
23
|
+
*
|
|
24
|
+
* A prévia é um iframe com `sandbox=""` e `srcDoc`: o HTML roda isolado — sem
|
|
25
|
+
* script, sem formulário, sem acesso a esta página — e não precisa de rota de
|
|
26
|
+
* visualização. O download fica fora do iframe e baixa exatamente o documento
|
|
27
|
+
* da prévia (`relatorio.html`).
|
|
28
|
+
*/
|
|
29
|
+
const RelatorioNaMensagem = ({ relatorio }: RelatorioNaMensagemProps) => {
|
|
30
|
+
const [aberto, setAberto] = useState(false)
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div className="not-prose w-full overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
|
34
|
+
<div className="flex flex-wrap items-center gap-3 px-4 py-3">
|
|
35
|
+
<span className="flex size-8 shrink-0 items-center justify-center rounded-lg bg-primary-subtle text-primary">
|
|
36
|
+
<TbReportAnalytics size={17} />
|
|
37
|
+
</span>
|
|
38
|
+
<div className="min-w-0 flex-1">
|
|
39
|
+
<div className="truncate font-semibold text-gray-900 dark:text-gray-100">
|
|
40
|
+
{relatorio.titulo}
|
|
41
|
+
</div>
|
|
42
|
+
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
43
|
+
Relatório em HTML · versão {relatorio.versao}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
<div className="flex flex-wrap gap-2">
|
|
47
|
+
<Button
|
|
48
|
+
size="sm"
|
|
49
|
+
variant="solid"
|
|
50
|
+
icon={aberto ? <TbEyeOff /> : <TbEye />}
|
|
51
|
+
aria-expanded={aberto}
|
|
52
|
+
onClick={() => setAberto((anterior) => !anterior)}
|
|
53
|
+
>
|
|
54
|
+
{aberto ? 'Fechar prévia' : 'Visualizar relatório'}
|
|
55
|
+
</Button>
|
|
56
|
+
<Button
|
|
57
|
+
size="sm"
|
|
58
|
+
icon={<TbDownload />}
|
|
59
|
+
onClick={() => baixarHtml(relatorio)}
|
|
60
|
+
>
|
|
61
|
+
Baixar HTML
|
|
62
|
+
</Button>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
{aberto && (
|
|
66
|
+
<iframe
|
|
67
|
+
title={`Prévia do relatório: ${relatorio.titulo}`}
|
|
68
|
+
sandbox=""
|
|
69
|
+
srcDoc={relatorio.html}
|
|
70
|
+
className="block h-[70vh] max-h-[760px] min-h-[360px] w-full border-t border-gray-200 bg-white dark:border-gray-700"
|
|
71
|
+
/>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default RelatorioNaMensagem
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
rotularExecucao,
|
|
14
14
|
rotularFerramenta,
|
|
15
15
|
} from './toolPresentation'
|
|
16
|
-
import type { ToolCall } from '../types'
|
|
16
|
+
import type { Espera, ToolCall } from '../types'
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Uma consulta ou operacao que o agente executou, no meio da conversa.
|
|
@@ -32,18 +32,24 @@ type Estado = {
|
|
|
32
32
|
/**
|
|
33
33
|
* Se o texto do estado acompanha o icone na pilula.
|
|
34
34
|
*
|
|
35
|
-
* So quando o icone sozinho nao basta: "aguardando confirmacao
|
|
36
|
-
* concluida" pedem uma acao ou explicam uma falha. Em execucao o rotulo ja
|
|
35
|
+
* So quando o icone sozinho nao basta: "aguardando" (a confirmacao ou o
|
|
36
|
+
* formato) e "nao concluida" pedem uma acao ou explicam uma falha. Em execucao o rotulo ja
|
|
37
37
|
* esta no gerundio ("Consultando contratos…") e o ✓ de concluida e obvio —
|
|
38
38
|
* escrever isso de novo so engorda a pilula.
|
|
39
39
|
*/
|
|
40
40
|
mostrarTexto?: boolean
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** O texto da pilula enquanto o agente espera o usuario responder a pausa. */
|
|
44
|
+
const ESPERAS: Record<Espera, string> = {
|
|
45
|
+
confirmacao: 'Aguardando confirmação',
|
|
46
|
+
formato: 'Aguardando o formato',
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
const estadoDe = (tool: ToolCall): Estado => {
|
|
44
|
-
if (tool.
|
|
50
|
+
if (tool.aguardando) {
|
|
45
51
|
return {
|
|
46
|
-
texto:
|
|
52
|
+
texto: ESPERAS[tool.aguardando],
|
|
47
53
|
Icone: TbClock,
|
|
48
54
|
classe: 'text-amber-600 dark:text-amber-400',
|
|
49
55
|
mostrarTexto: true,
|
|
@@ -79,7 +85,7 @@ const ToolCallChip = ({ tool }: ToolCallChipProps) => {
|
|
|
79
85
|
const [aberto, setAberto] = useState(false)
|
|
80
86
|
const estado = estadoDe(tool)
|
|
81
87
|
const IconeFerramenta = iconeFerramenta(tool.name)
|
|
82
|
-
const emAndamento = tool.running && !tool.
|
|
88
|
+
const emAndamento = tool.running && !tool.aguardando
|
|
83
89
|
const campos = camposVisiveis(tool.args, tool.name)
|
|
84
90
|
const rotulo = emAndamento
|
|
85
91
|
? `${rotularExecucao(tool.name)}…`
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
TbListSearch,
|
|
9
9
|
TbPackage,
|
|
10
10
|
TbPackages,
|
|
11
|
+
TbPalette,
|
|
12
|
+
TbReportAnalytics,
|
|
11
13
|
TbSearch,
|
|
12
14
|
TbTool,
|
|
13
15
|
TbUserSearch,
|
|
@@ -88,6 +90,17 @@ const FERRAMENTAS: Record<string, Ferramenta> = {
|
|
|
88
90
|
executando: 'Consultando produto',
|
|
89
91
|
icone: TbPackage,
|
|
90
92
|
},
|
|
93
|
+
// Um relatorio em HTML ou uma planilha Excel: o mesmo workflow no backend.
|
|
94
|
+
gerar_relatorio: {
|
|
95
|
+
rotulo: 'Geração de relatório',
|
|
96
|
+
executando: 'Gerando relatório',
|
|
97
|
+
icone: TbReportAnalytics,
|
|
98
|
+
},
|
|
99
|
+
personalizar_relatorio: {
|
|
100
|
+
rotulo: 'Personalização de relatório',
|
|
101
|
+
executando: 'Personalizando relatório',
|
|
102
|
+
icone: TbPalette,
|
|
103
|
+
},
|
|
91
104
|
// Nao executa nada no ERP: e o sinal de que faltam campos. Mas o agente a
|
|
92
105
|
// pede como qualquer outra, entao um chip aparece junto do formulario.
|
|
93
106
|
solicitar_dados: {
|