@credithub/harlan-components 1.44.4 → 1.45.0
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/components/dossie/generativeAi/dataUtils.js +38 -24
- package/dist/components/dossie/generativeAi/generativeAi.js +7 -5
- package/dist/components/dossie/generativeAi/queryUtils.d.ts +2 -2
- package/dist/components/dossie/generativeAi/queryUtils.js +18 -7
- package/dist/components/dossie/generativeAi/responseUtils.js +0 -10
- package/dist/components/protestos/protestos.js +10 -2
- package/lib/cjs/index.js +1015 -496
- package/lib/esm/index.js +1015 -496
- package/package.json +5 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { remove } from 'diacritics';
|
|
3
|
+
import stringSimilarity from 'string-similarity';
|
|
2
4
|
import { safeStringify } from './responseUtils';
|
|
3
5
|
export function flattenData(data) {
|
|
4
6
|
var flattened = {};
|
|
@@ -65,11 +67,23 @@ function deepCleanData(data) {
|
|
|
65
67
|
return Object.keys(cleanedObject).length > 0 ? cleanedObject : null;
|
|
66
68
|
}
|
|
67
69
|
export var selectRelevantData = function (data) {
|
|
68
|
-
var _a, _b, _c, _d, _e, _f
|
|
69
|
-
var
|
|
70
|
+
var _a, _b, _c, _d, _e, _f;
|
|
71
|
+
var _g = data || {}, protestosDeCredito = _g.protestos, chequesSemFundo = _g.ccf, dividasPublicas = _g.dividasPublicas, contasBancarias = _g.bankAccounts, dadosDeChequesSemFundo = _g.ccfData, dividas = _g.divida, _h = _g.dossie, dossie = _h === void 0 ? {} : _h, liminar = _g.liminar, socios = _g.partners, dadosPessoasExpostasPoliticamente = _g.pepData, detalhesProcessosJuridicos = _g.processosJuridicosData, dadosReclameAqui = _g.reclameAqui, relatoriosRefinBoaVista = _g.refinBoaVista, relatoriosRefinSerasa = _g.refinSerasa, dadosScore = _g.scoreData, relatoriosSCR = _g.scr, registrosDeVeiculos = _g.veiculos, ResumoDosDados = _g.documentHistory;
|
|
70
72
|
var tipoPessoa = ((_b = (_a = dossie === null || dossie === void 0 ? void 0 : dossie.carousel) === null || _a === void 0 ? void 0 : _a.document) === null || _b === void 0 ? void 0 : _b.length) === 11
|
|
71
73
|
? 'Pessoa Física'
|
|
72
74
|
: 'Pessoa Jurídica';
|
|
75
|
+
var normalizeName = function (name) {
|
|
76
|
+
if (!name)
|
|
77
|
+
return '';
|
|
78
|
+
return remove(name) // Remove acentos e caracteres especiais
|
|
79
|
+
.toLowerCase() // Converte para letras minúsculas
|
|
80
|
+
.replace(/\s+/g, ' ') // Remove espaços extras
|
|
81
|
+
.trim(); // Remove espaços nas extremidades
|
|
82
|
+
};
|
|
83
|
+
var similarNames = function (name1, name2) {
|
|
84
|
+
var similarity = stringSimilarity.compareTwoStrings(name1, name2);
|
|
85
|
+
return similarity >= 0.5;
|
|
86
|
+
};
|
|
73
87
|
var sociosAnonimizados = (_c = socios === null || socios === void 0 ? void 0 : socios.partners) === null || _c === void 0 ? void 0 : _c.map(function (socio, index) { return ({
|
|
74
88
|
nome: "S\u00F3cio ".concat(index + 1),
|
|
75
89
|
cargo: socio.cargo,
|
|
@@ -77,40 +91,40 @@ export var selectRelevantData = function (data) {
|
|
|
77
91
|
dividasPublicas: socio.dividasPublicas || {},
|
|
78
92
|
protestos: socio.protestos || {}
|
|
79
93
|
}); });
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
return (_a = processo.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (envolvido) {
|
|
83
|
-
var _a, _b, _c;
|
|
84
|
-
return ((_a = envolvido.nome_sem_filtro) === null || _a === void 0 ? void 0 : _a.toLowerCase()) ===
|
|
85
|
-
((_c = (_b = dossie.carousel) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.toLowerCase()) &&
|
|
86
|
-
envolvido.envolvido_tipo === 'Passivo';
|
|
87
|
-
});
|
|
88
|
-
})) === null || _e === void 0 ? void 0 : _e.map(function (processo) { return ({
|
|
89
|
-
assuntos: processo.assuntos,
|
|
90
|
-
classe_processual: processo.classe_processual,
|
|
91
|
-
diario_sigla: processo.diario_sigla,
|
|
92
|
-
updated_at: processo.updated_at
|
|
93
|
-
}); });
|
|
94
|
-
var processosAtivo = (_g = (_f = detalhesProcessosJuridicos === null || detalhesProcessosJuridicos === void 0 ? void 0 : detalhesProcessosJuridicos.empresa) === null || _f === void 0 ? void 0 : _f.filter(function (processo) {
|
|
94
|
+
var empresaNomeNormalizado = normalizeName((_d = dossie.carousel) === null || _d === void 0 ? void 0 : _d.name);
|
|
95
|
+
var processosPassivos = (_f = (_e = detalhesProcessosJuridicos === null || detalhesProcessosJuridicos === void 0 ? void 0 : detalhesProcessosJuridicos.empresa) === null || _e === void 0 ? void 0 : _e.filter(function (processo) {
|
|
95
96
|
var _a;
|
|
96
97
|
return (_a = processo.envolvidos_ultima_movimentacao) === null || _a === void 0 ? void 0 : _a.some(function (envolvido) {
|
|
97
|
-
var
|
|
98
|
-
return ((
|
|
99
|
-
|
|
100
|
-
envolvido.envolvido_tipo === 'Ativo';
|
|
98
|
+
var nomeNormalizado = normalizeName(envolvido.nome_sem_filtro);
|
|
99
|
+
return (similarNames(nomeNormalizado, empresaNomeNormalizado) &&
|
|
100
|
+
envolvido.envolvido_tipo === 'Passivo');
|
|
101
101
|
});
|
|
102
|
-
})) === null ||
|
|
102
|
+
})) === null || _f === void 0 ? void 0 : _f.map(function (processo) { return ({
|
|
103
103
|
assuntos: processo.assuntos,
|
|
104
104
|
classe_processual: processo.classe_processual,
|
|
105
105
|
diario_sigla: processo.diario_sigla,
|
|
106
106
|
updated_at: processo.updated_at
|
|
107
107
|
}); });
|
|
108
|
+
// const processosAtivo = detalhesProcessosJuridicos?.empresa
|
|
109
|
+
// ?.filter((processo: any) =>
|
|
110
|
+
// processo.envolvidos_ultima_movimentacao?.some((envolvido: any) => {
|
|
111
|
+
// const nomeNormalizado = normalizeName(envolvido.nome_sem_filtro);
|
|
112
|
+
// return (
|
|
113
|
+
// similarNames(nomeNormalizado, empresaNomeNormalizado) &&
|
|
114
|
+
// envolvido.envolvido_tipo === 'Ativo'
|
|
115
|
+
// );
|
|
116
|
+
// })
|
|
117
|
+
// )
|
|
118
|
+
// ?.map((processo: any) => ({
|
|
119
|
+
// assuntos: processo.assuntos,
|
|
120
|
+
// classe_processual: processo.classe_processual,
|
|
121
|
+
// diario_sigla: processo.diario_sigla,
|
|
122
|
+
// updated_at: processo.updated_at
|
|
123
|
+
// }));
|
|
108
124
|
var resumoDaEmpresa = dossie.summary;
|
|
109
125
|
var dadosOrganizados = {
|
|
110
126
|
protestosDeCredito: protestosDeCredito,
|
|
111
127
|
processosJuridicosPassivos: processosPassivos,
|
|
112
|
-
processosJuridicosAtivos: processosAtivo,
|
|
113
|
-
detalhesProcessosJuridicos: detalhesProcessosJuridicos,
|
|
114
128
|
chequesSemFundo: chequesSemFundo,
|
|
115
129
|
dividasPublicas: dividasPublicas,
|
|
116
130
|
contasBancarias: contasBancarias,
|
|
@@ -158,9 +158,9 @@ var GenerativeAI = function (_a) {
|
|
|
158
158
|
var queryData = useMemo(function () {
|
|
159
159
|
if (!queryEnabled || !serializedData || serializedData === '{}')
|
|
160
160
|
return undefined;
|
|
161
|
-
var
|
|
162
|
-
return
|
|
163
|
-
}, [queryEnabled, serializedData, messageHistory]);
|
|
161
|
+
var generatedQuery = createQueryAndMessages(serializedData, messageHistory, userInput);
|
|
162
|
+
return generatedQuery;
|
|
163
|
+
}, [queryEnabled, serializedData, messageHistory, userInput]);
|
|
164
164
|
var _r = useStreamQuery("SELECT FROM 'LlamaApi'.'Consulta'", queryData, !!queryData), response = _r.response, error = _r.error, isLoading = _r.isLoading, refetch = _r.refetch;
|
|
165
165
|
useEffect(function () {
|
|
166
166
|
abortControllerRef.current = new AbortController();
|
|
@@ -204,10 +204,12 @@ var GenerativeAI = function (_a) {
|
|
|
204
204
|
var newMessage_1 = { role: 'user', content: userInput };
|
|
205
205
|
setMessageHistory(function (prevMessages) { return __spreadArray(__spreadArray([], prevMessages, true), [newMessage_1], false); });
|
|
206
206
|
setUserInput('');
|
|
207
|
-
setQueryEnabled(
|
|
207
|
+
setQueryEnabled(false);
|
|
208
|
+
setTimeout(function () {
|
|
209
|
+
setQueryEnabled(true);
|
|
210
|
+
}, 0);
|
|
208
211
|
setIsProcessing(true);
|
|
209
212
|
incrementalResponseRef.current = '';
|
|
210
|
-
refetch();
|
|
211
213
|
}
|
|
212
214
|
};
|
|
213
215
|
var handleStopStream = function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const createQueryAndMessages: (relevantData: string, messageHistory: any[],
|
|
1
|
+
export declare const createQueryAndMessages: (relevantData: string, messageHistory: any[], userInput?: string) => {
|
|
2
2
|
model: string;
|
|
3
3
|
messages: string;
|
|
4
|
-
};
|
|
4
|
+
} | undefined;
|
|
@@ -9,19 +9,30 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
9
9
|
};
|
|
10
10
|
import { stringify } from 'yaml';
|
|
11
11
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
-
export var createQueryAndMessages = function (relevantData, messageHistory,
|
|
12
|
+
export var createQueryAndMessages = function (relevantData, messageHistory, userInput) {
|
|
13
13
|
var parsedData = JSON.parse(relevantData);
|
|
14
|
+
var tipoPessoaMessage = parsedData.tipoPessoa === 'Pessoa Física'
|
|
15
|
+
? 'Esta análise é para uma pessoa física.'
|
|
16
|
+
: 'Esta análise é para uma pessoa jurídica.';
|
|
14
17
|
var analysisHeader = parsedData.tipoPessoa === 'Pessoa Física'
|
|
15
18
|
? "\n Analisar o dossi\u00EA da seguinte pessoa f\u00EDsica:\n - Foco em identificar restri\u00E7\u00F5es financeiras, protestos e riscos pessoais que possam impactar o cr\u00E9dito.\n "
|
|
16
19
|
: "\n Analisar o dossi\u00EA da seguinte empresa:\n - Foco em identificar protestos, processos judiciais e problemas financeiros que possam impactar a empresa.\n ";
|
|
17
|
-
var
|
|
18
|
-
|
|
20
|
+
var baseContent = "\n ".concat(analysisHeader, "\n\n ").concat(tipoPessoaMessage, "\n\n ```yaml\n ").concat(stringify(parsedData), "\n ```\n\n **Responda sempre em portugu\u00EAs claro, eliminando dados irrelevantes ou n\u00E3o intelig\u00EDveis.**\n ").trim();
|
|
21
|
+
var messages = __spreadArray([], messageHistory, true);
|
|
22
|
+
if (messageHistory.length === 0) {
|
|
23
|
+
messages.push({
|
|
19
24
|
role: 'user',
|
|
20
|
-
content:
|
|
21
|
-
}
|
|
22
|
-
|
|
25
|
+
content: baseContent
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (userInput) {
|
|
29
|
+
messages.push({
|
|
30
|
+
role: 'user',
|
|
31
|
+
content: userInput
|
|
32
|
+
});
|
|
33
|
+
}
|
|
23
34
|
return {
|
|
24
35
|
model: 'deepseek-chat',
|
|
25
|
-
messages: JSON.stringify(
|
|
36
|
+
messages: JSON.stringify(messages)
|
|
26
37
|
};
|
|
27
38
|
};
|
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
[];
|
|
2
|
-
/*export const isValidLlamaApiResponse = (
|
|
3
|
-
response: any
|
|
4
|
-
): response is LlamaApiResponse => {
|
|
5
|
-
return (
|
|
6
|
-
response &&
|
|
7
|
-
typeof response === 'object' &&
|
|
8
|
-
response.document &&
|
|
9
|
-
typeof response.document.messages === 'string'
|
|
10
|
-
);
|
|
11
|
-
};*/
|
|
12
2
|
export function safeStringify(obj) {
|
|
13
3
|
var seen = new WeakSet();
|
|
14
4
|
return JSON.stringify(obj, function (_, value) {
|
|
@@ -22,7 +22,7 @@ import { useGlobalData } from '../../contexts/globalDataContext';
|
|
|
22
22
|
import { formatDatePtBrToDate } from '../../utils/date';
|
|
23
23
|
import { extractIntegerFromText } from '../../utils/number';
|
|
24
24
|
import XPathUtils from '../../utils/xpath';
|
|
25
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
25
|
+
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
|
26
26
|
import styled from 'styled-components';
|
|
27
27
|
import StatusMessage from '../interface/statusMessage';
|
|
28
28
|
import Section from '../section';
|
|
@@ -38,8 +38,15 @@ var byDate = function (protesto, protesto2) {
|
|
|
38
38
|
};
|
|
39
39
|
var Protestos = function () {
|
|
40
40
|
var ctx = useContext(Queries.Protestos);
|
|
41
|
+
var ctxLiminar = useContext(Queries.Liminar);
|
|
41
42
|
var setData = useGlobalData().setData;
|
|
42
43
|
var _a = useState(false), dataUpdated = _a[0], setDataUpdated = _a[1];
|
|
44
|
+
var total = useMemo(function () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (ctxLiminar.type === RequestStatus.Success)
|
|
47
|
+
return ((_b = (_a = ctxLiminar === null || ctxLiminar === void 0 ? void 0 : ctxLiminar.document) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.reduce(function (carry, e) { return carry + Number(e[9]); }, 0)) || 0;
|
|
48
|
+
return 0;
|
|
49
|
+
}, [ctxLiminar.type]);
|
|
43
50
|
useEffect(function () {
|
|
44
51
|
if (ctx.type !== RequestStatus.Success || dataUpdated || !ctx.document) {
|
|
45
52
|
return;
|
|
@@ -72,7 +79,8 @@ var Protestos = function () {
|
|
|
72
79
|
}, [ctx, setData, dataUpdated]);
|
|
73
80
|
return (React.createElement(Section, { ctx: ctx, title: "Apontamentos na Central de Protestos (CENPROT)", subtitle: "Consulta de protestos de cr\u00E9dito, imposto e gerais.", icon: ProtestosIcon, onSuccess: function (data) {
|
|
74
81
|
var registrosText = XPathUtils.select('string(//registros)', data);
|
|
75
|
-
var
|
|
82
|
+
var haveExeption = XPathUtils.select('string(//raw)', data) != 'false';
|
|
83
|
+
var registros = haveExeption ? extractIntegerFromText(registrosText) + total : extractIntegerFromText(registrosText);
|
|
76
84
|
var protestosDeCredito = XPathUtils.selectArray('//body//protesto', data).filter(function (protesto) {
|
|
77
85
|
return REGEX_PROTESTOS_DE_CREDITO.test(XPathUtils.select('string(./nomeCedente)', protesto));
|
|
78
86
|
});
|