@orbe-agro/client-core 5.6.324 → 5.6.325

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.
Files changed (52) hide show
  1. package/dist/@ecme/assets/styles/app.css +29 -0
  2. package/dist/@ecme/assets/styles/tailwind/index.css +29 -0
  3. package/dist/@ecme/components/template/Footer.js +1 -1
  4. package/dist/@ecme/components/template/OrbeAiWidget/OrbeAiWidget.js +7 -1
  5. package/dist/@ecme/components/template/OrbeAiWidget/OrbeAiWidget.js.map +1 -1
  6. package/dist/@ecme/components/ui/Alert/Alert.js +2 -0
  7. package/dist/@ecme/components/ui/Alert/Alert.js.map +1 -1
  8. package/dist/@ecme/components/ui/Tooltip/Tooltip.js.map +1 -1
  9. package/dist/@ecme/components/view/ChatBox/ChatBox.js +3 -1
  10. package/dist/@ecme/components/view/ChatBox/ChatBox.js.map +1 -1
  11. package/dist/@ecme/components/view/ChatBox/components/ChatInput.js +2 -1
  12. package/dist/@ecme/components/view/ChatBox/components/ChatInput.js.map +1 -1
  13. package/dist/@ecme/services/AiService.js +4 -2
  14. package/dist/@ecme/services/AiService.js.map +1 -1
  15. package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js +45 -3
  16. package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js.map +1 -1
  17. package/dist/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.js +85 -0
  18. package/dist/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.js.map +1 -0
  19. package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js +20 -3
  20. package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js.map +1 -1
  21. package/dist/@ecme/views/concepts/ai/Chat/store/esforcoStore.js +15 -0
  22. package/dist/@ecme/views/concepts/ai/Chat/store/esforcoStore.js.map +1 -0
  23. package/dist/@types/@ecme/components/template/OrbeAiWidget/OrbeAiWidget.d.ts.map +1 -1
  24. package/dist/@types/@ecme/components/ui/Alert/Alert.d.ts.map +1 -1
  25. package/dist/@types/@ecme/components/ui/Tooltip/Tooltip.d.ts.map +1 -1
  26. package/dist/@types/@ecme/components/view/ChatBox/ChatBox.d.ts.map +1 -1
  27. package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts +3 -1
  28. package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts.map +1 -1
  29. package/dist/@types/@ecme/services/AiService.d.ts +7 -3
  30. package/dist/@types/@ecme/services/AiService.d.ts.map +1 -1
  31. package/dist/@types/@ecme/views/concepts/ai/Chat/components/ChatView.d.ts +6 -1
  32. package/dist/@types/@ecme/views/concepts/ai/Chat/components/ChatView.d.ts.map +1 -1
  33. package/dist/@types/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.d.ts +14 -0
  34. package/dist/@types/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.d.ts.map +1 -0
  35. package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useChatSend.d.ts.map +1 -1
  36. package/dist/@types/@ecme/views/concepts/ai/Chat/store/esforcoStore.d.ts +27 -0
  37. package/dist/@types/@ecme/views/concepts/ai/Chat/store/esforcoStore.d.ts.map +1 -0
  38. package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts +30 -0
  39. package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts.map +1 -1
  40. package/dist/base/assets/styles/init.css +33 -0
  41. package/lib/@ecme/components/template/OrbeAiWidget/OrbeAiWidget.tsx +4 -1
  42. package/lib/@ecme/components/ui/Alert/Alert.tsx +3 -0
  43. package/lib/@ecme/components/ui/Tooltip/Tooltip.tsx +2 -1
  44. package/lib/@ecme/components/view/ChatBox/ChatBox.tsx +2 -0
  45. package/lib/@ecme/components/view/ChatBox/components/ChatInput.tsx +5 -2
  46. package/lib/@ecme/services/AiService.ts +9 -3
  47. package/lib/@ecme/views/concepts/ai/Chat/components/ChatView.tsx +49 -3
  48. package/lib/@ecme/views/concepts/ai/Chat/components/EsforcoRaciocinio.tsx +115 -0
  49. package/lib/@ecme/views/concepts/ai/Chat/hooks/useChatSend.ts +24 -3
  50. package/lib/@ecme/views/concepts/ai/Chat/store/esforcoStore.ts +25 -0
  51. package/lib/@ecme/views/concepts/ai/Chat/types.ts +32 -0
  52. package/package.json +2 -1
@@ -5757,6 +5757,9 @@ video {
5757
5757
  .w-6{
5758
5758
  width: 1.5rem;
5759
5759
  }
5760
+ .w-72{
5761
+ width: 18rem;
5762
+ }
5760
5763
  .w-8{
5761
5764
  width: 2rem;
5762
5765
  }
@@ -6420,6 +6423,10 @@ video {
6420
6423
  .border-none{
6421
6424
  border-style: none;
6422
6425
  }
6426
+ .border-emerald-300{
6427
+ --tw-border-opacity: 1;
6428
+ border-color: rgb(110 231 183 / var(--tw-border-opacity, 1));
6429
+ }
6423
6430
  .border-error{
6424
6431
  border-color: var(--error);
6425
6432
  }
@@ -6567,6 +6574,10 @@ video {
6567
6574
  --tw-bg-opacity: 1;
6568
6575
  background-color: rgb(167 243 208 / var(--tw-bg-opacity, 1));
6569
6576
  }
6577
+ .bg-emerald-50{
6578
+ --tw-bg-opacity: 1;
6579
+ background-color: rgb(236 253 245 / var(--tw-bg-opacity, 1));
6580
+ }
6570
6581
  .bg-emerald-500{
6571
6582
  --tw-bg-opacity: 1;
6572
6583
  background-color: rgb(16 185 129 / var(--tw-bg-opacity, 1));
@@ -7264,6 +7275,10 @@ video {
7264
7275
  --tw-text-opacity: 1;
7265
7276
  color: rgb(5 150 105 / var(--tw-text-opacity, 1));
7266
7277
  }
7278
+ .text-emerald-700{
7279
+ --tw-text-opacity: 1;
7280
+ color: rgb(4 120 87 / var(--tw-text-opacity, 1));
7281
+ }
7267
7282
  .text-error{
7268
7283
  color: var(--error);
7269
7284
  }
@@ -7731,6 +7746,11 @@ video {
7731
7746
  background-color: rgb(37 99 235 / var(--tw-bg-opacity, 1));
7732
7747
  }
7733
7748
 
7749
+ .hover\:bg-emerald-100:hover{
7750
+ --tw-bg-opacity: 1;
7751
+ background-color: rgb(209 250 229 / var(--tw-bg-opacity, 1));
7752
+ }
7753
+
7734
7754
  .hover\:bg-gray-100:hover{
7735
7755
  background-color: var(--gray-100);
7736
7756
  }
@@ -8068,6 +8088,11 @@ video {
8068
8088
  border-style: solid;
8069
8089
  }
8070
8090
 
8091
+ .dark\:border-emerald-700:is(.dark *){
8092
+ --tw-border-opacity: 1;
8093
+ border-color: rgb(4 120 87 / var(--tw-border-opacity, 1));
8094
+ }
8095
+
8071
8096
  .dark\:border-gray-500:is(.dark *){
8072
8097
  border-color: var(--gray-500);
8073
8098
  }
@@ -8157,6 +8182,10 @@ video {
8157
8182
  background-color: rgb(16 185 129 / 0.2);
8158
8183
  }
8159
8184
 
8185
+ .dark\:bg-emerald-900\/30:is(.dark *){
8186
+ background-color: rgb(6 78 59 / 0.3);
8187
+ }
8188
+
8160
8189
  .dark\:bg-fuchsia-200:is(.dark *){
8161
8190
  --tw-bg-opacity: 1;
8162
8191
  background-color: rgb(245 208 254 / var(--tw-bg-opacity, 1));
@@ -8514,6 +8543,10 @@ video {
8514
8543
  background-color: rgb(0 0 0 / var(--tw-bg-opacity, 1));
8515
8544
  }
8516
8545
 
8546
+ .dark\:hover\:bg-emerald-900\/50:hover:is(.dark *){
8547
+ background-color: rgb(6 78 59 / 0.5);
8548
+ }
8549
+
8517
8550
  .dark\:hover\:bg-gray-200:hover:is(.dark *){
8518
8551
  background-color: var(--gray-200);
8519
8552
  }
@@ -125,7 +125,10 @@ const OrbeAiWidget = () => {
125
125
  </div>
126
126
 
127
127
  <div className="min-h-0 flex-1 p-2">
128
- <ChatView showMobileNav={false} />
128
+ <ChatView
129
+ showMobileNav={false}
130
+ dropdownFloatingClass="!z-[10000]"
131
+ />
129
132
  <ChatHistoryRenameDialog overlayClassName="!z-[10000]" />
130
133
  </div>
131
134
 
@@ -8,6 +8,7 @@ import {
8
8
  HiXCircle,
9
9
  } from 'react-icons/hi'
10
10
  import { motion } from 'framer-motion'
11
+ import type { MotionStyle } from 'framer-motion'
11
12
  import CloseButton from '../CloseButton'
12
13
  import StatusIcon from '../StatusIcon'
13
14
  import type { TypeAttributes, CommonProps } from '../@types/common'
@@ -78,6 +79,7 @@ const Alert = (props: AlertProps) => {
78
79
  onClose,
79
80
  ref,
80
81
  showIcon = false,
82
+ style,
81
83
  triggerByToast = false,
82
84
  ...rest
83
85
  } = props
@@ -149,6 +151,7 @@ const Alert = (props: AlertProps) => {
149
151
  <motion.div
150
152
  ref={ref}
151
153
  className={alertClass}
154
+ style={style as MotionStyle}
152
155
  initial={{ opacity: 1 }}
153
156
  animate={display === 'hiding' ? 'exit' : 'animate'}
154
157
  transition={{ duration: 0.25, type: 'tween' }}
@@ -1,6 +1,7 @@
1
1
  import { useState } from 'react'
2
2
  import classNames from 'classnames'
3
3
  import { motion, AnimatePresence } from 'framer-motion'
4
+ import type { MotionStyle } from 'framer-motion'
4
5
  import Arrow from './Arrow'
5
6
  import type { CommonProps } from '../@types/common'
6
7
  import type { ArrowPlacement } from './Arrow'
@@ -127,7 +128,7 @@ const Tooltip = (props: TooltipProps) => {
127
128
  duration: 0.15,
128
129
  type: 'tween',
129
130
  }}
130
- style={floatingStyles}
131
+ style={floatingStyles as MotionStyle}
131
132
  {...getFloatingProps()}
132
133
  >
133
134
  <span>{title}</span>
@@ -27,6 +27,7 @@ const ChatBox = forwardRef<ScrollBarRef, ChatBoxProps>((props, ref) => {
27
27
  header,
28
28
  placeholder,
29
29
  onInputChange,
30
+ inputActions,
30
31
  showAvatar,
31
32
  avatarGap,
32
33
  customRenderer,
@@ -49,6 +50,7 @@ const ChatBox = forwardRef<ScrollBarRef, ChatBoxProps>((props, ref) => {
49
50
  <ChatInput
50
51
  placeholder={placeholder}
51
52
  onInputChange={onInputChange}
53
+ inputActions={inputActions}
52
54
  />
53
55
  }
54
56
  >
@@ -3,12 +3,14 @@ import Button from '@/components/ui/Button'
3
3
  import Upload from '@/components/ui/Upload'
4
4
  import hooks from '@/components/ui/hooks'
5
5
  import { TbPhotoPlus, TbArrowRight } from 'react-icons/tb'
6
- import type { KeyboardEvent, Ref } from 'react'
6
+ import type { KeyboardEvent, ReactNode, Ref } from 'react'
7
7
 
8
8
  export type ChatInputProps = {
9
9
  placeholder?: string
10
10
  onInputChange?: (payload: { value: string; attachments: File[] }) => void
11
11
  ref?: Ref<HTMLInputElement>
12
+ /** Controles extras dentro da caixa, logo antes do botão de enviar. */
13
+ inputActions?: ReactNode
12
14
  }
13
15
 
14
16
  const { useMergeRef } = hooks
@@ -16,7 +18,7 @@ const { useMergeRef } = hooks
16
18
  const ChatInput = (props: ChatInputProps) => {
17
19
  const [attachments, setAttachments] = useState<File[]>([])
18
20
 
19
- const { placeholder, onInputChange, ref = null } = props
21
+ const { placeholder, onInputChange, ref = null, inputActions } = props
20
22
 
21
23
  const inputRef = useRef<HTMLInputElement>(null)
22
24
 
@@ -78,6 +80,7 @@ const ChatInput = (props: ChatInputProps) => {
78
80
  placeholder={placeholder}
79
81
  onKeyDown={handleKeyDown}
80
82
  />
83
+ {inputActions}
81
84
  <Button
82
85
  size="xs"
83
86
  shape="circle"
@@ -1,7 +1,7 @@
1
1
  import { authHeaders } from './aiAuthHeaders'
2
2
  import ApiService from './ApiService'
3
3
  import { readSse } from './sseParser'
4
- import type { ChatEvent } from '@/views/concepts/ai/Chat/types'
4
+ import type { ChatEvent, Esforco } from '@/views/concepts/ai/Chat/types'
5
5
  import type { AxiosRequestConfig } from 'axios'
6
6
 
7
7
  const AI_DEV_URL = 'http://localhost:8000'
@@ -80,6 +80,8 @@ export type StreamChatParams = {
80
80
  prompt: string
81
81
  /** Identifica a conversa; o backend usa como thread da memoria. */
82
82
  conversationId?: string
83
+ /** Nivel de raciocinio desta mensagem; ausente = o padrao do backend. */
84
+ esforco?: Esforco
83
85
  signal?: AbortSignal
84
86
  onEvent: (evento: ChatEvent) => void
85
87
  }
@@ -94,6 +96,8 @@ export type ResumeChatParams = {
94
96
  approved?: boolean
95
97
  dados?: Record<string, unknown> | null
96
98
  conversationId?: string
99
+ /** A retomada tambem chama o modelo: vale o mesmo nivel do envio. */
100
+ esforco?: Esforco
97
101
  signal?: AbortSignal
98
102
  onEvent: (evento: ChatEvent) => void
99
103
  }
@@ -107,12 +111,13 @@ export type ResumeChatParams = {
107
111
  export async function streamChat({
108
112
  prompt,
109
113
  conversationId,
114
+ esforco,
110
115
  signal,
111
116
  onEvent,
112
117
  }: StreamChatParams): Promise<void> {
113
118
  await postarEConsumir(
114
119
  '/ai/chat/stream',
115
- { prompt, conversation_id: conversationId },
120
+ { prompt, conversation_id: conversationId, esforco },
116
121
  onEvent,
117
122
  signal,
118
123
  )
@@ -131,12 +136,13 @@ export async function resumeChat({
131
136
  approved,
132
137
  dados,
133
138
  conversationId,
139
+ esforco,
134
140
  signal,
135
141
  onEvent,
136
142
  }: ResumeChatParams): Promise<void> {
137
143
  await postarEConsumir(
138
144
  '/ai/chat/resume',
139
- { approved, dados, conversation_id: conversationId },
145
+ { approved, dados, conversation_id: conversationId, esforco },
140
146
  onEvent,
141
147
  signal,
142
148
  )
@@ -1,4 +1,6 @@
1
- import { useRef, useEffect, useMemo } from 'react'
1
+ import { useRef, useEffect, useMemo, useCallback } from 'react'
2
+ import { TbDownload } from 'react-icons/tb'
3
+ import * as XLSX from 'xlsx'
2
4
  import Card from '@/components/ui/Card'
3
5
  import ChatBox from '@/components/view/ChatBox'
4
6
  import ChatLandingView from './ChatLandingView'
@@ -10,6 +12,7 @@ import AiErrorMessage from './AiErrorMessage'
10
12
  import ToolCallChip from './ToolCallChip'
11
13
  import ApprovalCard from './ApprovalCard'
12
14
  import DataRequestCard from './DataRequestCard'
15
+ import EsforcoRaciocinio from './EsforcoRaciocinio'
13
16
  import { usGenerativeChatStore } from '../store/generativeChatStore'
14
17
  import useChatSend from '../hooks/useChatSend'
15
18
  import useConversationMessages from '../hooks/useConversationMessages'
@@ -38,9 +41,17 @@ type ChatViewProps = {
38
41
  * flutuante desliga, porque tem o próprio drawer dentro do painel.
39
42
  */
40
43
  showMobileNav?: boolean
44
+ /**
45
+ * Classes dos menus flutuantes do chat. O widget passa um z-index acima do
46
+ * próprio painel; sem isso o menu abriria atrás dele.
47
+ */
48
+ dropdownFloatingClass?: string
41
49
  }
42
50
 
43
- const ChatView = ({ showMobileNav = true }: ChatViewProps) => {
51
+ const ChatView = ({
52
+ showMobileNav = true,
53
+ dropdownFloatingClass,
54
+ }: ChatViewProps) => {
44
55
  const scrollRef = useRef<ScrollBarRef>(null)
45
56
  const { selectedConversation, chatHistory, isTyping, disabledChatFresh } =
46
57
  usGenerativeChatStore()
@@ -82,6 +93,23 @@ const ChatView = ({ showMobileNav = true }: ChatViewProps) => {
82
93
  scrollToBottom()
83
94
  }
84
95
 
96
+ const handleSpreadsheetDownload = useCallback(
97
+ (titulo: string, abas: Array<{ nome: string; colunas: string[]; linhas: Record<string, unknown>[] }>) => {
98
+ const workbook = XLSX.utils.book_new()
99
+ for (const aba of abas) {
100
+ const sheet = XLSX.utils.aoa_to_sheet([
101
+ aba.colunas,
102
+ ...aba.linhas.map((linha) =>
103
+ aba.colunas.map((col) => linha[col] ?? ''),
104
+ ),
105
+ ])
106
+ XLSX.utils.book_append_sheet(workbook, sheet, aba.nome.slice(0, 31))
107
+ }
108
+ XLSX.writeFile(workbook, `${titulo}.xlsx`)
109
+ },
110
+ [],
111
+ )
112
+
85
113
  return (
86
114
  <Card className="flex-1 h-full" bodyClass="h-full">
87
115
  {showMobileNav && <ChatMobileNav />}
@@ -122,7 +150,7 @@ const ChatView = ({ showMobileNav = true }: ChatViewProps) => {
122
150
  if (message.sender.id === 'ai') {
123
151
  // As ferramentas e as pausas chegam pelo streaming e
124
152
  // vivem no Conversation; o tipo do ChatBox nao os conhece.
125
- const { tools, pendingApproval, pendingInput } =
153
+ const { tools, pendingApproval, pendingInput, spreadsheet } =
126
154
  message as Conversation
127
155
  // Enquanto as ferramentas rodam o conteudo ainda e '':
128
156
  // sem esta guarda sobraria um balao cinza vazio.
@@ -150,6 +178,21 @@ const ChatView = ({ showMobileNav = true }: ChatViewProps) => {
150
178
  />
151
179
  </div>
152
180
  )}
181
+ {spreadsheet && (
182
+ <button
183
+ type="button"
184
+ onClick={() =>
185
+ handleSpreadsheetDownload(
186
+ spreadsheet.titulo,
187
+ spreadsheet.abas,
188
+ )
189
+ }
190
+ className="inline-flex items-center gap-2 rounded-lg border border-emerald-300 bg-emerald-50 px-3 py-2 text-sm font-medium text-emerald-700 transition-colors hover:bg-emerald-100 dark:border-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400 dark:hover:bg-emerald-900/50"
191
+ >
192
+ <TbDownload size={18} />
193
+ <span>Baixar {spreadsheet.titulo}.xlsx</span>
194
+ </button>
195
+ )}
153
196
  {pendingInput && (
154
197
  <DataRequestCard
155
198
  input={pendingInput}
@@ -192,6 +235,9 @@ const ChatView = ({ showMobileNav = true }: ChatViewProps) => {
192
235
  return null
193
236
  }}
194
237
  onInputChange={handleInputChange}
238
+ inputActions={
239
+ <EsforcoRaciocinio floatingClass={dropdownFloatingClass} />
240
+ }
195
241
  >
196
242
  {/* Os children ficam entre a lista e o input: sem conversa e a
197
243
  landing com os cards; com conversa, o aviso sobre a IA. */}
@@ -0,0 +1,115 @@
1
+ import { TbBrain, TbCheck, TbChevronDown } from 'react-icons/tb'
2
+ import Dropdown from '@/components/ui/Dropdown'
3
+ import { useEsforcoStore } from '../store/esforcoStore'
4
+ import type { Esforco } from '../types'
5
+
6
+ type NivelDeEsforco = {
7
+ valor: Esforco
8
+ rotulo: string
9
+ descricao: string
10
+ }
11
+
12
+ /** Os níveis, do menor para o maior raciocínio. Servem o botão e o menu. */
13
+ const NIVEIS: ReadonlyArray<NivelDeEsforco> = [
14
+ {
15
+ valor: 'minimal',
16
+ rotulo: 'Mínimo',
17
+ descricao: 'Mais rápido, para consultas diretas.',
18
+ },
19
+ {
20
+ valor: 'medium',
21
+ rotulo: 'Médio',
22
+ descricao: 'Equilíbrio entre rapidez e cuidado. Recomendado.',
23
+ },
24
+ {
25
+ valor: 'high',
26
+ rotulo: 'Alto',
27
+ descricao: 'Pensa mais antes de responder; bom para análises.',
28
+ },
29
+ {
30
+ valor: 'max',
31
+ rotulo: 'Máximo',
32
+ descricao: 'Pensa o máximo possível antes de responder.',
33
+ },
34
+ ]
35
+
36
+ /** O `eventKey` do Dropdown é `string`; só um dos níveis acima é aceito. */
37
+ const ehEsforco = (valor: string): valor is Esforco =>
38
+ NIVEIS.some((nivel) => nivel.valor === valor)
39
+
40
+ type EsforcoRaciocinioProps = {
41
+ /** Classes do menu flutuante; o widget passa um z-index acima do painel. */
42
+ floatingClass?: string
43
+ }
44
+
45
+ /**
46
+ * Seletor do nível de raciocínio, dentro da caixa de mensagem.
47
+ *
48
+ * O botão mostra o nível atual; o menu abre para cima, com uma linha
49
+ * explicando cada nível. A escolha vale para as próximas mensagens (e para as
50
+ * retomadas de aprovação e de formulário); as respostas já dadas não mudam.
51
+ */
52
+ const EsforcoRaciocinio = ({ floatingClass }: EsforcoRaciocinioProps) => {
53
+ const { esforco, setEsforco } = useEsforcoStore()
54
+ const atual = NIVEIS.find((nivel) => nivel.valor === esforco)
55
+
56
+ const handleSelect = (valor: string) => {
57
+ if (ehEsforco(valor)) {
58
+ setEsforco(valor)
59
+ }
60
+ }
61
+
62
+ return (
63
+ <Dropdown
64
+ placement="top-end"
65
+ activeKey={esforco}
66
+ menuClass="w-72"
67
+ floatingClass={floatingClass}
68
+ renderTitle={
69
+ <button
70
+ type="button"
71
+ aria-label={`Nível de raciocínio: ${atual?.rotulo}`}
72
+ className="flex 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"
73
+ >
74
+ <TbBrain className="text-base" />
75
+ <span>{atual?.rotulo}</span>
76
+ <TbChevronDown />
77
+ </button>
78
+ }
79
+ >
80
+ <Dropdown.Item variant="header">
81
+ <div className="px-3 pb-2">
82
+ <div className="heading-text text-sm font-bold">
83
+ Raciocínio
84
+ </div>
85
+ <div className="text-xs text-gray-500 dark:text-gray-400">
86
+ Quanto o assistente pensa antes de responder.
87
+ </div>
88
+ </div>
89
+ </Dropdown.Item>
90
+ {NIVEIS.map((nivel) => (
91
+ <Dropdown.Item
92
+ key={nivel.valor}
93
+ eventKey={nivel.valor}
94
+ onSelect={handleSelect}
95
+ // O MenuItem fixa 42px de altura e `nowrap`, feitos para
96
+ // uma linha; aqui cada item tem título e descrição.
97
+ style={{ height: 'auto' }}
98
+ className="items-start whitespace-normal py-2"
99
+ >
100
+ <div className="flex-1">
101
+ <div>{nivel.rotulo}</div>
102
+ <div className="text-xs font-normal text-gray-500 dark:text-gray-400">
103
+ {nivel.descricao}
104
+ </div>
105
+ </div>
106
+ {nivel.valor === esforco && (
107
+ <TbCheck className="mt-0.5 shrink-0 text-lg" />
108
+ )}
109
+ </Dropdown.Item>
110
+ ))}
111
+ </Dropdown>
112
+ )
113
+ }
114
+
115
+ export default EsforcoRaciocinio
@@ -1,4 +1,5 @@
1
1
  import { usGenerativeChatStore } from '../store/generativeChatStore'
2
+ import { useEsforcoStore } from '../store/esforcoStore'
2
3
  import { resumeChat, streamChat } from '@/services/AiService'
3
4
  import { useAuth } from '@/auth'
4
5
  import dayjs from 'dayjs'
@@ -20,6 +21,8 @@ const useChatSend = () => {
20
21
  updateConversation,
21
22
  setIsTyping,
22
23
  } = usGenerativeChatStore()
24
+ // Vai em toda ida ao modelo: envio, aprovação e formulário.
25
+ const esforco = useEsforcoStore((state) => state.esforco)
23
26
 
24
27
  const creteMyMessage = (id: string, prompt: string) => {
25
28
  pushConversation(id, {
@@ -147,6 +150,12 @@ const useChatSend = () => {
147
150
  })
148
151
  break
149
152
 
153
+ case 'spreadsheet_data':
154
+ updateConversation(chatId, messageId, {
155
+ spreadsheet: evento.data as Conversation['spreadsheet'],
156
+ })
157
+ break
158
+
150
159
  case 'done':
151
160
  // O done é a fonte autoritativa do texto DESTA requisição —
152
161
  // se algum token se perdeu, ele corrige.
@@ -188,7 +197,13 @@ const useChatSend = () => {
188
197
  await consumirStream(
189
198
  chatId,
190
199
  messageId,
191
- (onEvent) => streamChat({ prompt, conversationId: chatId, onEvent }),
200
+ (onEvent) =>
201
+ streamChat({
202
+ prompt,
203
+ conversationId: chatId,
204
+ esforco,
205
+ onEvent,
206
+ }),
192
207
  { texto: '', tools: [] },
193
208
  )
194
209
  }
@@ -247,7 +262,12 @@ const useChatSend = () => {
247
262
  chatId,
248
263
  messageId,
249
264
  (onEvent) =>
250
- resumeChat({ approved, conversationId: chatId, onEvent }),
265
+ resumeChat({
266
+ approved,
267
+ conversationId: chatId,
268
+ esforco,
269
+ onEvent,
270
+ }),
251
271
  { texto: mensagem.content ?? '', tools: mensagem.tools ?? [] },
252
272
  )
253
273
  }
@@ -280,7 +300,8 @@ const useChatSend = () => {
280
300
  await consumirStream(
281
301
  chatId,
282
302
  messageId,
283
- (onEvent) => resumeChat({ dados, conversationId: chatId, onEvent }),
303
+ (onEvent) =>
304
+ resumeChat({ dados, conversationId: chatId, esforco, onEvent }),
284
305
  { texto: mensagem.content ?? '', tools: mensagem.tools ?? [] },
285
306
  )
286
307
  }
@@ -0,0 +1,25 @@
1
+ import { create } from 'zustand'
2
+ import { persist } from 'zustand/middleware'
3
+ import type { Esforco } from '../types'
4
+
5
+ type EsforcoState = {
6
+ esforco: Esforco
7
+ setEsforco: (payload: Esforco) => void
8
+ }
9
+
10
+ /**
11
+ * Nível de raciocínio escolhido no chat.
12
+ *
13
+ * Persistido no navegador, como tema e idioma: é preferência de uso, não dado
14
+ * da conversa. Por isso mora fora do `generativeChatStore`, que não persiste e
15
+ * é zerado quando o usuário da sessão muda.
16
+ */
17
+ export const useEsforcoStore = create<EsforcoState>()(
18
+ persist(
19
+ (set) => ({
20
+ esforco: 'medium',
21
+ setEsforco: (payload) => set(() => ({ esforco: payload })),
22
+ }),
23
+ { name: 'orbe-ai-esforco' },
24
+ ),
25
+ )
@@ -66,6 +66,15 @@ export type Conversation = {
66
66
  pendingApproval?: PendingApproval
67
67
  /** Preenchido quando o agente pausou pedindo os dados que faltam. */
68
68
  pendingInput?: PendingInput
69
+ /** Preenchido quando o agente gerou dados de planilha para download. */
70
+ spreadsheet?: {
71
+ titulo: string
72
+ abas: Array<{
73
+ nome: string
74
+ colunas: string[]
75
+ linhas: Record<string, unknown>[]
76
+ }>
77
+ }
69
78
  }
70
79
 
71
80
  /**
@@ -93,6 +102,21 @@ export type ChatEvent =
93
102
  is_error: boolean
94
103
  }
95
104
  }
105
+ | {
106
+ /**
107
+ * O agente gerou dados de planilha. O front gera o .xlsx no navegador
108
+ * (SheetJS) e mostra um botao de download.
109
+ */
110
+ type: 'spreadsheet_data'
111
+ data: {
112
+ titulo: string
113
+ abas: Array<{
114
+ nome: string
115
+ colunas: string[]
116
+ linhas: Record<string, unknown>[]
117
+ }>
118
+ }
119
+ }
96
120
  | {
97
121
  /**
98
122
  * O agente parou antes de uma operacao de escrita e espera decisao.
@@ -155,6 +179,14 @@ export type HistoryChat = Omit<ChatHistory, 'conversation'> & {
155
179
  conversation: HistoryMessage[]
156
180
  }
157
181
 
182
+ /**
183
+ * Nível de raciocínio do modelo, escolhido no chat e enviado em cada mensagem.
184
+ *
185
+ * Os valores são os do OpenRouter, sem tradução — o backend valida contra o
186
+ * mesmo conjunto (enum `Esforco`) e responde 422 para qualquer outro.
187
+ */
188
+ export type Esforco = 'minimal' | 'medium' | 'high' | 'max'
189
+
158
190
  /** Resumo de uma conversa, como vem do GET /ai/chat/conversations. */
159
191
  export type ConversationSummary = {
160
192
  id: string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbe-agro/client-core",
3
- "version": "5.6.324",
3
+ "version": "5.6.325",
4
4
  "description": "Biblioteca principal de componentes e utilidades para os microfrontends do Orbe Agro.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -117,6 +117,7 @@
117
117
  "simplebar-react": "^3.3.0",
118
118
  "swr": "^2.3.0",
119
119
  "tailwind-merge": "^2.5.2",
120
+ "xlsx": "^0.18.5",
120
121
  "yet-another-react-lightbox": "^3.21.7",
121
122
  "zod": "^3.23.8",
122
123
  "zustand": "^5.0.2"