@orbe-agro/client-core 5.6.346 → 5.6.348

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 (55) hide show
  1. package/dist/@ecme/components/template/Footer.js +1 -1
  2. package/dist/@ecme/components/view/ChatBox/ChatBox.js +5 -1
  3. package/dist/@ecme/components/view/ChatBox/ChatBox.js.map +1 -1
  4. package/dist/@ecme/components/view/ChatBox/components/ChatInput.js +19 -4
  5. package/dist/@ecme/components/view/ChatBox/components/ChatInput.js.map +1 -1
  6. package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js +21 -4
  7. package/dist/@ecme/views/concepts/ai/Chat/components/ChatView.js.map +1 -1
  8. package/dist/@ecme/views/concepts/ai/Chat/components/RespostaInterrompida.js +10 -0
  9. package/dist/@ecme/views/concepts/ai/Chat/components/RespostaInterrompida.js.map +1 -0
  10. package/dist/@ecme/views/concepts/ai/Chat/components/ToolCallChip.js +9 -1
  11. package/dist/@ecme/views/concepts/ai/Chat/components/ToolCallChip.js.map +1 -1
  12. package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js +44 -6
  13. package/dist/@ecme/views/concepts/ai/Chat/hooks/useChatSend.js.map +1 -1
  14. package/dist/@ecme/views/concepts/ai/Chat/store/generativeChatStore.js +14 -7
  15. package/dist/@ecme/views/concepts/ai/Chat/store/generativeChatStore.js.map +1 -1
  16. package/dist/@types/@ecme/components/view/ChatBox/ChatBox.d.ts.map +1 -1
  17. package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts +8 -0
  18. package/dist/@types/@ecme/components/view/ChatBox/components/ChatInput.d.ts.map +1 -1
  19. package/dist/@types/@ecme/views/concepts/ai/Chat/components/ChatView.d.ts.map +1 -1
  20. package/dist/@types/@ecme/views/concepts/ai/Chat/components/RespostaInterrompida.d.ts +10 -0
  21. package/dist/@types/@ecme/views/concepts/ai/Chat/components/RespostaInterrompida.d.ts.map +1 -0
  22. package/dist/@types/@ecme/views/concepts/ai/Chat/components/ToolCallChip.d.ts.map +1 -1
  23. package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useChatSend.d.ts +2 -0
  24. package/dist/@types/@ecme/views/concepts/ai/Chat/hooks/useChatSend.d.ts.map +1 -1
  25. package/dist/@types/@ecme/views/concepts/ai/Chat/store/generativeChatStore.d.ts +11 -0
  26. package/dist/@types/@ecme/views/concepts/ai/Chat/store/generativeChatStore.d.ts.map +1 -1
  27. package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts +7 -0
  28. package/dist/@types/@ecme/views/concepts/ai/Chat/types.d.ts.map +1 -1
  29. package/dist/@types/base/configs/endpoints.config/compras/compras.d.ts +4 -0
  30. package/dist/@types/base/configs/endpoints.config/compras/compras.d.ts.map +1 -1
  31. package/dist/@types/base/configs/endpoints.config/compras/config/cotacao.d.ts +4 -0
  32. package/dist/@types/base/configs/endpoints.config/compras/config/cotacao.d.ts.map +1 -1
  33. package/dist/@types/base/configs/endpoints.config/endpoints.navigation.d.ts +4 -0
  34. package/dist/@types/base/configs/endpoints.config/endpoints.navigation.d.ts.map +1 -1
  35. package/dist/@types/base/services/modules/compras/cotacao/CotacaoService.d.ts +1 -0
  36. package/dist/@types/base/services/modules/compras/cotacao/CotacaoService.d.ts.map +1 -1
  37. package/dist/base/configs/endpoints.config/compras/config/cotacao.js +2 -1
  38. package/dist/base/configs/endpoints.config/compras/config/cotacao.js.map +1 -1
  39. package/dist/base/index.js +2 -1
  40. package/dist/base/services/index.js +2 -1
  41. package/dist/base/services/modules/compras/cotacao/CotacaoService.js +8 -0
  42. package/dist/base/services/modules/compras/cotacao/CotacaoService.js.map +1 -1
  43. package/dist/base/services/modules/compras/index.js +2 -1
  44. package/dist/base/services/modules/index.js +2 -1
  45. package/lib/@ecme/components/view/ChatBox/ChatBox.tsx +4 -0
  46. package/lib/@ecme/components/view/ChatBox/components/ChatInput.tsx +33 -9
  47. package/lib/@ecme/views/concepts/ai/Chat/components/ChatView.tsx +21 -4
  48. package/lib/@ecme/views/concepts/ai/Chat/components/RespostaInterrompida.tsx +17 -0
  49. package/lib/@ecme/views/concepts/ai/Chat/components/ToolCallChip.tsx +10 -0
  50. package/lib/@ecme/views/concepts/ai/Chat/hooks/useChatSend.ts +74 -6
  51. package/lib/@ecme/views/concepts/ai/Chat/store/generativeChatStore.ts +20 -3
  52. package/lib/@ecme/views/concepts/ai/Chat/types.ts +7 -0
  53. package/lib/base/configs/endpoints.config/compras/config/cotacao.ts +1 -0
  54. package/lib/base/services/modules/compras/cotacao/CotacaoService.ts +8 -0
  55. package/package.json +1 -1
@@ -7,6 +7,7 @@ import ChatCustomContent from './ChatCustomContent'
7
7
  import ChatCustomAction from './ChatCustomAction'
8
8
  import AiThinkingIndicator from './AiThinkingIndicator'
9
9
  import AiErrorMessage from './AiErrorMessage'
10
+ import RespostaInterrompida from './RespostaInterrompida'
10
11
  import ToolCallChip from './ToolCallChip'
11
12
  import ApprovalCard from './ApprovalCard'
12
13
  import DataRequestCard from './DataRequestCard'
@@ -57,10 +58,20 @@ const ChatView = ({
57
58
  dropdownFloatingClass,
58
59
  }: ChatViewProps) => {
59
60
  const scrollRef = useRef<ScrollBarRef>(null)
60
- const { selectedConversation, chatHistory, isTyping, disabledChatFresh } =
61
- usGenerativeChatStore()
62
- const { handleSend, handleApproval, handleDataSubmit, handleFormato } =
63
- useChatSend()
61
+ const {
62
+ selectedConversation,
63
+ chatHistory,
64
+ isTyping,
65
+ execucao,
66
+ disabledChatFresh,
67
+ } = usGenerativeChatStore()
68
+ const {
69
+ handleSend,
70
+ handleStop,
71
+ handleApproval,
72
+ handleDataSubmit,
73
+ handleFormato,
74
+ } = useChatSend()
64
75
  // Conversa aberta da lista: as mensagens vêm do backend na primeira vez.
65
76
  const { carregando } = useConversationMessages()
66
77
  // Modelo que só lê texto: o botão de imagem fica desligado.
@@ -148,6 +159,7 @@ const ChatView = ({
148
159
  pendingFormat,
149
160
  relatorios,
150
161
  falhou,
162
+ interrompida,
151
163
  } = message as Conversation
152
164
  // Enquanto as ferramentas rodam o conteudo ainda e '':
153
165
  // sem esta guarda sobraria um balao cinza vazio.
@@ -226,6 +238,9 @@ const ChatView = ({
226
238
  {/* Falhou no meio: o que ja chegou fica, e o
227
239
  aviso vem depois, em vez de apagar tudo. */}
228
240
  {falhou && <AiErrorMessage />}
241
+ {/* Parou pelo botao: o que chegou fica, e o
242
+ aviso, discreto, vem depois. */}
243
+ {interrompida && <RespostaInterrompida />}
229
244
  </div>
230
245
  )
231
246
  }
@@ -250,6 +265,8 @@ const ChatView = ({
250
265
  return null
251
266
  }}
252
267
  onInputChange={handleInputChange}
268
+ executando={Boolean(execucao)}
269
+ onStop={handleStop}
253
270
  uploadProps={{
254
271
  ...UPLOAD_DE_IMAGENS,
255
272
  disabled: atual?.imagens === false,
@@ -0,0 +1,17 @@
1
+ import { TbPlayerStop } from 'react-icons/tb'
2
+
3
+ /**
4
+ * Aviso discreto no fim da resposta que o usuário parou pelo botão de parar.
5
+ *
6
+ * Cinza, e não vermelho como o `AiErrorMessage`: nada falhou, foi uma escolha
7
+ * dele. Vem depois do que já tinha chegado — texto, ferramentas e relatórios
8
+ * ficam como estavam.
9
+ */
10
+ const RespostaInterrompida = () => (
11
+ <span className="flex items-center gap-1.5 text-xs font-medium text-gray-500 dark:text-gray-400">
12
+ <TbPlayerStop size={14} />
13
+ Resposta interrompida
14
+ </span>
15
+ )
16
+
17
+ export default RespostaInterrompida
@@ -5,6 +5,7 @@ import {
5
5
  TbChevronDown,
6
6
  TbClock,
7
7
  TbLoader2,
8
+ TbPlayerStop,
8
9
  } from 'react-icons/tb'
9
10
  import classNames from '@/components/ui/utils/classNames'
10
11
  import {
@@ -62,6 +63,15 @@ const estadoDe = (tool: ToolCall): Estado => {
62
63
  classe: 'text-blue-600 dark:text-blue-400',
63
64
  }
64
65
  }
66
+ // O usuário parou a resposta no meio dela: cinza, porque não foi falha.
67
+ if (tool.interrompida) {
68
+ return {
69
+ texto: 'Interrompida',
70
+ Icone: TbPlayerStop,
71
+ classe: 'text-gray-500 dark:text-gray-400',
72
+ mostrarTexto: true,
73
+ }
74
+ }
65
75
  if (tool.isError) {
66
76
  return {
67
77
  texto: 'Não concluída',
@@ -58,6 +58,24 @@ const encerrar = (tools: ToolCall[]) =>
58
58
  : tool,
59
59
  )
60
60
 
61
+ /**
62
+ * As ferramentas que a parada deixou no meio terminam como "Interrompida": o
63
+ * resultado não chegou, e não foi falha — foi o usuário que parou. As que já
64
+ * tinham terminado ficam como estavam.
65
+ */
66
+ const interromper = (tools: ToolCall[]) =>
67
+ tools.map((tool) =>
68
+ tool.running || tool.aguardando
69
+ ? {
70
+ ...tool,
71
+ running: false,
72
+ aguardando: undefined,
73
+ progresso: undefined,
74
+ interrompida: true,
75
+ }
76
+ : tool,
77
+ )
78
+
61
79
  const useChatSend = () => {
62
80
  const { user } = useAuth()
63
81
  const {
@@ -67,6 +85,8 @@ const useChatSend = () => {
67
85
  pushConversation,
68
86
  updateConversation,
69
87
  setIsTyping,
88
+ setExecucao,
89
+ pararExecucao,
70
90
  } = usGenerativeChatStore()
71
91
  // Os dois vão em toda ida ao modelo: envio, aprovação e formulário.
72
92
  const esforco = useEsforcoStore((state) => state.esforco)
@@ -124,17 +144,26 @@ const useChatSend = () => {
124
144
  * Compartilhado pelo envio e pelas retomadas: quando o usuário responde a
125
145
  * uma pausa, a resposta continua na MESMA mensagem, então o acumulador de
126
146
  * texto e de ferramentas precisa partir do que já está lá.
147
+ *
148
+ * Cada resposta tem o seu `AbortController`, registrado no store: é o que o
149
+ * botão de parar aborta. Abortar fecha a conexão, e o backend cancela o
150
+ * turno do outro lado — não há outro pedido para "parar".
127
151
  */
128
152
  const consumirStream = async (
129
153
  chatId: string,
130
154
  messageId: string,
131
- executar: (onEvent: (evento: ChatEvent) => void) => Promise<void>,
155
+ executar: (
156
+ onEvent: (evento: ChatEvent) => void,
157
+ signal: AbortSignal,
158
+ ) => Promise<void>,
132
159
  inicial: {
133
160
  texto: string
134
161
  tools: ToolCall[]
135
162
  relatorios: RelatorioDoChat[]
136
163
  },
137
164
  ) => {
165
+ const controle = new AbortController()
166
+ setExecucao(controle)
138
167
  // Acumulados localmente: o store guarda o resultado, mas ler de volta a
139
168
  // cada token para concatenar seria uma corrida com o próprio set().
140
169
  let texto = inicial.texto
@@ -169,6 +198,23 @@ const useChatSend = () => {
169
198
  )
170
199
  }
171
200
 
201
+ /**
202
+ * Encerra a resposta que o usuário parou, sem apagar o que já chegou.
203
+ *
204
+ * Não é falha: as ferramentas no meio ficam "Interrompida", e a mensagem
205
+ * ganha o aviso discreto de resposta interrompida — mesmo vazia, quando
206
+ * ele parou antes do primeiro token.
207
+ */
208
+ const parar = () => {
209
+ terminou = true
210
+ tools = interromper(tools)
211
+ updateConversation(chatId, messageId, {
212
+ content: texto,
213
+ tools,
214
+ interrompida: true,
215
+ })
216
+ }
217
+
172
218
  const aplicar = (evento: ChatEvent) => {
173
219
  switch (evento.type) {
174
220
  case 'token':
@@ -284,14 +330,32 @@ const useChatSend = () => {
284
330
  }
285
331
  }
286
332
 
333
+ // Abortado pelo botão de parar: o fetch rejeita, e isso não é falha.
334
+ const parou = () => controle.signal.aborted
335
+
287
336
  try {
288
- await executar(aplicar)
337
+ await executar(aplicar, controle.signal)
289
338
  if (!terminou) {
290
- falhar()
339
+ if (parou()) {
340
+ parar()
341
+ } else {
342
+ falhar()
343
+ }
291
344
  }
292
345
  } catch {
293
- falhar()
346
+ // Abortada depois do `done` ou de uma pausa, nada muda: a resposta
347
+ // já tinha fechado.
348
+ if (!parou()) {
349
+ falhar()
350
+ } else if (!terminou) {
351
+ parar()
352
+ }
294
353
  } finally {
354
+ // Só limpa se ainda for a dela: uma resposta nova pode já ter
355
+ // registrado o próprio controle.
356
+ if (usGenerativeChatStore.getState().execucao === controle) {
357
+ setExecucao(null)
358
+ }
295
359
  setIsTyping(false)
296
360
  }
297
361
  }
@@ -310,7 +374,7 @@ const useChatSend = () => {
310
374
  await consumirStream(
311
375
  chatId,
312
376
  messageId,
313
- async (onEvent) =>
377
+ async (onEvent, signal) =>
314
378
  streamChat({
315
379
  prompt,
316
380
  conversationId: chatId,
@@ -319,6 +383,7 @@ const useChatSend = () => {
319
383
  imagens: imagens.length
320
384
  ? await Promise.all(imagens.map(paraImagemEnviada))
321
385
  : undefined,
386
+ signal,
322
387
  onEvent,
323
388
  }),
324
389
  { texto: '', tools: [], relatorios: [] },
@@ -383,12 +448,13 @@ const useChatSend = () => {
383
448
  await consumirStream(
384
449
  chatId,
385
450
  messageId,
386
- (onEvent) =>
451
+ (onEvent, signal) =>
387
452
  resumeChat({
388
453
  ...resposta,
389
454
  conversationId: chatId,
390
455
  esforco,
391
456
  modelo,
457
+ signal,
392
458
  onEvent,
393
459
  }),
394
460
  {
@@ -422,6 +488,8 @@ const useChatSend = () => {
422
488
 
423
489
  return {
424
490
  handleSend,
491
+ /** Para a resposta em andamento: o que chegou fica, com o aviso. */
492
+ handleStop: pararExecucao,
425
493
  handleApproval,
426
494
  handleDataSubmit,
427
495
  handleFormato,
@@ -14,6 +14,14 @@ export type GenerativeChatState = {
14
14
  chatHistory: ChatHistories
15
15
  renameDialog: RenameDialog
16
16
  isTyping: boolean
17
+ /**
18
+ * A resposta em andamento, para o botão de parar abortá-la.
19
+ *
20
+ * Fica no store, e não no hook: a landing e o ChatView têm cada um o seu
21
+ * `useChatSend`, e a sugestão clicada na landing também para pelo botão do
22
+ * ChatView. `null` quando nenhuma resposta está chegando.
23
+ */
24
+ execucao: AbortController | null
17
25
  }
18
26
 
19
27
  type GenerativeChatAction = {
@@ -23,6 +31,9 @@ type GenerativeChatAction = {
23
31
  setChatHistoryName: (payload: { id: string; title: string }) => void
24
32
  setRenameDialog: (payload: RenameDialog) => void
25
33
  setIsTyping: (payload: boolean) => void
34
+ setExecucao: (payload: AbortController | null) => void
35
+ /** Para a resposta em andamento: o stream aborta, e o backend cancela o turno. */
36
+ pararExecucao: () => void
26
37
  pushChatHistory: (payload: ChatHistory) => void
27
38
  pushConversation: (id: string, conversation: Conversation) => void
28
39
  /** Grava as mensagens buscadas no backend e marca a conversa como carregada. */
@@ -47,6 +58,7 @@ const initialState: GenerativeChatState = {
47
58
  open: false,
48
59
  },
49
60
  isTyping: false,
61
+ execucao: null,
50
62
  }
51
63
 
52
64
  export const usGenerativeChatStore = create<
@@ -54,13 +66,16 @@ export const usGenerativeChatStore = create<
54
66
  >((set, get) => ({
55
67
  ...initialState,
56
68
  // Arrays novos: `setSelectedConversationRecord` muta o array no lugar, e
57
- // reusar o do initialState traria de volta o que ele acumulou.
58
- reset: () =>
69
+ // reusar o do initialState traria de volta o que ele acumulou. A resposta em
70
+ // andamento para junto: ela é do usuário que saiu.
71
+ reset: () => {
72
+ get().execucao?.abort()
59
73
  set(() => ({
60
74
  ...initialState,
61
75
  selectedConversationRecord: [],
62
76
  chatHistory: [],
63
- })),
77
+ }))
78
+ },
64
79
  setSelectedConversation: (payload) =>
65
80
  set(() => ({ selectedConversation: payload })),
66
81
  setChatHistory: (payload) => set(() => ({ chatHistory: payload })),
@@ -136,6 +151,8 @@ export const usGenerativeChatStore = create<
136
151
  ),
137
152
  })),
138
153
  setIsTyping: (payload) => set(() => ({ isTyping: payload })),
154
+ setExecucao: (payload) => set(() => ({ execucao: payload })),
155
+ pararExecucao: () => get().execucao?.abort(),
139
156
  disabledChatFresh: () =>
140
157
  set(() => {
141
158
  const chatHistory = get().chatHistory.map((chat) => {
@@ -22,6 +22,8 @@ export type ToolCall = {
22
22
  * (ex.: "Lendo 1.200 de 4.800 registros…"). Some no `tool_end`.
23
23
  */
24
24
  progresso?: string
25
+ /** O usuario parou a resposta enquanto ela executava: o resultado nao chegou. */
26
+ interrompida?: boolean
25
27
  }
26
28
 
27
29
  /** O que trava uma ferramenta ate o usuario responder a pausa. */
@@ -132,6 +134,11 @@ export type Conversation = {
132
134
  * tinham chegado ficam, e o aviso de erro aparece depois deles.
133
135
  */
134
136
  falhou?: boolean
137
+ /**
138
+ * O usuario parou a resposta: o que ja tinha chegado fica, e um aviso
139
+ * discreto vem depois. Nao e falha - foi uma escolha dele.
140
+ */
141
+ interrompida?: boolean
135
142
  /** Ferramentas chamadas pelo agente nesta resposta. */
136
143
  tools?: ToolCall[]
137
144
  /** Preenchido quando o agente pausou esperando aprovacao humana. */
@@ -6,6 +6,7 @@ const cotacao = {
6
6
  update: { endpoint: COTACAO_BASE_URL, httpMethod: 'put' },
7
7
  executeAcao: { endpoint: `${COTACAO_BASE_URL}/execute-acao`, httpMethod: 'post' },
8
8
  findCotacoesEmProcessamento: { endpoint: `${COTACAO_BASE_URL}/find-em-processamento`, httpMethod: 'get' },
9
+ checkAvaliacoesRecentes: { endpoint: `${COTACAO_BASE_URL}/check-avaliacoes-recentes`, httpMethod: 'post' },
9
10
  }
10
11
 
11
12
  export default cotacao
@@ -40,4 +40,12 @@ export async function apiFindCotacoesEmProcessamento() {
40
40
  url: COTACAO_ENDPOINT.findCotacoesEmProcessamento.endpoint,
41
41
  method: COTACAO_ENDPOINT.findCotacoesEmProcessamento.httpMethod
42
42
  })
43
+ }
44
+
45
+ export async function apiCheckAvaliacoesRecentes(body) {
46
+ return ApiService.fetchDataWithAxios<any>({
47
+ url: COTACAO_ENDPOINT.checkAvaliacoesRecentes.endpoint,
48
+ method: COTACAO_ENDPOINT.checkAvaliacoesRecentes.httpMethod,
49
+ data: body,
50
+ })
43
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orbe-agro/client-core",
3
- "version": "5.6.346",
3
+ "version": "5.6.348",
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",