code7-leia 1.0.10 → 1.0.13

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 (62) hide show
  1. package/dist/index.es.js +3357 -2922
  2. package/package.json +6 -6
  3. package/src/components/CustomToast/index.tsx +62 -0
  4. package/src/components/CustomToast/styles.tsx +74 -0
  5. package/src/components/EmptyState/index.tsx +88 -0
  6. package/src/components/EmptyState/styles.tsx +81 -0
  7. package/src/components/FileArea/components/AreaUpload/index.tsx +137 -0
  8. package/src/components/FileArea/components/AreaUpload/styles.tsx +86 -0
  9. package/src/components/FileArea/components/Modal/ModalButtonClose.tsx +23 -0
  10. package/src/components/FileArea/components/Modal/ModalContent.tsx +26 -0
  11. package/src/components/FileArea/components/Modal/ModalFooter.tsx +18 -0
  12. package/src/components/FileArea/components/Modal/ModalHeader.tsx +18 -0
  13. package/src/components/FileArea/components/Modal/ModalTitle.tsx +18 -0
  14. package/src/components/FileArea/components/Modal/index.tsx +131 -0
  15. package/src/components/FileArea/components/Modal/styles.tsx +121 -0
  16. package/src/components/FileArea/components/Search/index.tsx +45 -0
  17. package/src/components/FileArea/components/Search/styles.tsx +26 -0
  18. package/src/components/FileArea/components/Spinner/index.tsx +22 -0
  19. package/src/components/FileArea/components/Spinner/styles.tsx +59 -0
  20. package/src/components/FileArea/components/Table/index.tsx +34 -0
  21. package/src/components/FileArea/components/Table/styles.tsx +60 -0
  22. package/src/components/FileArea/index.tsx +279 -0
  23. package/src/components/FileArea/styles.tsx +183 -0
  24. package/src/components/LengthCounter/index.tsx +29 -0
  25. package/src/components/LengthCounter/styles.ts +11 -0
  26. package/src/components/Modal/index.tsx +30 -0
  27. package/src/components/Modal/styles.ts +52 -0
  28. package/src/components/MultiSelect/index.tsx +102 -0
  29. package/src/components/MultiSelect/styles.tsx +85 -0
  30. package/src/components/PersonasArea/index.tsx +196 -0
  31. package/src/components/PersonasArea/styles.ts +137 -0
  32. package/src/components/Select/index.tsx +60 -0
  33. package/src/components/Select/styles.tsx +49 -0
  34. package/src/components/TestArea/components/InputTest/index.tsx +23 -0
  35. package/src/components/TestArea/components/InputTest/styles.tsx +28 -0
  36. package/src/components/TestArea/components/TextArea/index.tsx +97 -0
  37. package/src/components/TestArea/components/TextArea/styles.tsx +173 -0
  38. package/src/components/TestArea/index.tsx +99 -0
  39. package/src/components/TestArea/styles.tsx +112 -0
  40. package/src/contexts/LeiaProvider.tsx +133 -0
  41. package/src/index.tsx +6 -0
  42. package/src/interface/FileData.ts +11 -0
  43. package/src/interface/Language.ts +95 -0
  44. package/src/interface/Table.ts +12 -0
  45. package/src/service/Api.ts +9 -0
  46. package/src/service/ApiDev.ts +9 -0
  47. package/src/service/ApiHml.ts +9 -0
  48. package/src/store/index.ts +13 -0
  49. package/src/store/modules/actions.ts +88 -0
  50. package/src/store/modules/reducer.ts +46 -0
  51. package/src/store/modules/sagas.ts +127 -0
  52. package/src/store/modules/types.ts +19 -0
  53. package/src/types/image.d.ts +4 -0
  54. package/src/utils/formatAxios.tsx +15 -0
  55. package/src/utils/getApi.tsx +16 -0
  56. package/src/utils/getLanguage.tsx +17 -0
  57. package/src/utils/languages/en.ts +107 -0
  58. package/src/utils/languages/es.ts +107 -0
  59. package/src/utils/languages/pt-br.ts +111 -0
  60. package/src/utils/stringNormalize.ts +9 -0
  61. package/dist/code7-leia.css +0 -1
  62. package/dist/index.cjs.js +0 -1072
@@ -0,0 +1,173 @@
1
+ import styled from 'styled-components';
2
+
3
+ type ContainerProps = {
4
+ marginBottom?: string;
5
+ };
6
+
7
+ export const Container = styled.div<ContainerProps>`
8
+ display: flex;
9
+ flex-flow: column;
10
+ margin-bottom: ${({ marginBottom }) => marginBottom};
11
+ max-width: 100%;
12
+ `;
13
+
14
+ export const InputWrapper = styled.div`
15
+ display: flex;
16
+ align-items: center;
17
+ position: relative;
18
+ margin-right: 5px;
19
+ width: 725px;
20
+ max-width: 100%;
21
+
22
+ .icon {
23
+ position: absolute;
24
+ color: #5a5d68;
25
+
26
+ &.start-icon {
27
+ left: 12px;
28
+ }
29
+ &.end-icon {
30
+ right: 12px;
31
+ }
32
+ }
33
+
34
+ & .pass-view {
35
+ position: absolute;
36
+ right: 0;
37
+ top: 0;
38
+ bottom: 0;
39
+ padding: 14px;
40
+ font-size: 1rem;
41
+ color: #5a5d68;
42
+ }
43
+ `;
44
+
45
+ export const LabelWrapper = styled.label`
46
+ margin-bottom: 8px;
47
+
48
+ .label {
49
+ display: block;
50
+ color: #5a5d68;
51
+
52
+ font-style: normal;
53
+ font-weight: 600;
54
+ font-size: 0.875rem;
55
+ line-height: 114%;
56
+ letter-spacing: -0.02em;
57
+ }
58
+
59
+ .description {
60
+ font-style: normal;
61
+ font-weight: 500;
62
+ font-size: 0.625rem;
63
+ line-height: 120%;
64
+ color: #5a5d68;
65
+ display: block;
66
+ }
67
+ `;
68
+
69
+ export const CustomTextArea = styled.textarea`
70
+ font-family: 'Monospace', -apple-system, BlinkMacSystemFont, sans-serif;
71
+ font-size: 0.875rem;
72
+ font-style: normal;
73
+ font-weight: 500;
74
+ line-height: 20px;
75
+ text-align: left;
76
+ letter-spacing: -0.02em;
77
+ resize: vertical;
78
+ padding: 8px 12px;
79
+
80
+ border-radius: 4px;
81
+ border: 1px solid #979aa5;
82
+ color: #5a5d68 !important;
83
+ width: 100%;
84
+
85
+ background: #ffffff;
86
+ transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out,
87
+ border 0.2s ease-in-out;
88
+
89
+ &:focus {
90
+ outline: none;
91
+ box-shadow: 0 0 0 3px #6690ff;
92
+ }
93
+
94
+ &:hover {
95
+ border: 1px solid #102693;
96
+ }
97
+ &:active {
98
+ border: 1px solid #102693;
99
+ }
100
+ &:disabled {
101
+ border: 1px solid #dadce3;
102
+ background: #f3f5f9;
103
+ color: #dadce3;
104
+ }
105
+
106
+ &.small {
107
+ height: 32px;
108
+ }
109
+
110
+ &.medium {
111
+ height: 120px;
112
+ }
113
+
114
+ &.large {
115
+ height: 48px;
116
+ font-size: 1rem;
117
+ }
118
+
119
+ &.success {
120
+ background: #e3f8cc;
121
+ border: 1px solid #19660a;
122
+ color: #19660a;
123
+ }
124
+
125
+ &.danger {
126
+ background: #fae0d2;
127
+ border: 1px solid #871821;
128
+ color: #871821;
129
+ }
130
+
131
+ &.error {
132
+ background: #fae0d2;
133
+ border: 1px solid #871821;
134
+ color: #871821;
135
+ }
136
+
137
+ &.has-start-icon {
138
+ padding-left: 40px;
139
+ }
140
+ &.has-end-icon {
141
+ padding-right: 40px;
142
+ }
143
+ `;
144
+
145
+ export const Helper = styled.div`
146
+ &.helper {
147
+ font-style: normal;
148
+ font-weight: 500;
149
+ font-size: 0.625rem;
150
+ line-height: 120%;
151
+ color: #5a5d68;
152
+ display: block;
153
+ margin-top: 4px;
154
+
155
+ &.success {
156
+ color: #19660a;
157
+ }
158
+
159
+ &.danger {
160
+ color: #871821;
161
+ }
162
+ }
163
+ `;
164
+
165
+ export const Error = styled.div`
166
+ font-style: normal;
167
+ font-weight: 500;
168
+ font-size: 0.625rem;
169
+ line-height: 120%;
170
+ display: block;
171
+ margin-top: 4px;
172
+ color: #871821;
173
+ `;
@@ -0,0 +1,99 @@
1
+ import React, { useState } from 'react';
2
+ import { getLanguage } from '../../utils/getLanguage'
3
+ import * as S from './styles';
4
+ import Select from '../Select'
5
+ import InputTest from './components/InputTest'
6
+ import TextArea from './components/TextArea'
7
+ import { PiWaveformBold } from 'react-icons/pi';
8
+ import { FaList } from 'react-icons/fa';
9
+ import EmptyState from '../EmptyState';
10
+ import { useLeia } from '../../contexts/LeiaProvider';
11
+ import { MdPerson2 } from "react-icons/md";
12
+ import { useDispatch, useSelector } from 'react-redux';
13
+ import { testAction } from '../../store/modules/actions';
14
+
15
+ export const TestArea = () => {
16
+ const { id, language, personas, propTags, token, env, readonly } = useLeia();
17
+ const t = getLanguage(language)
18
+ const results = useSelector((state: any) => state.message);
19
+ const isloading = useSelector((state: any) => state.isloading);
20
+ const [search, setSearch] = useState('');
21
+ const [prompt, setPrompt] = useState('');
22
+ const [profile, setProfile] = useState('');
23
+ const [presset, setPresset] = useState('');
24
+ const dispatch = useDispatch();
25
+ const tags = propTags ? propTags.tags : [];
26
+
27
+
28
+ const optionsPersona = personas && personas.map(persona => {
29
+ return { label: persona.name, value: persona.name }
30
+ })
31
+
32
+ const optionsPresset = tags.map(tag => {
33
+ return { label: tag, value: tag }
34
+ })
35
+
36
+ const handleSelectPersona = (value: string) => {
37
+ setProfile(value);
38
+ };
39
+
40
+ const handleSelectPresset = (value: string) => {
41
+ setPresset(value);
42
+ };
43
+
44
+ const handleSearch = (value: string) => {
45
+ setSearch(value);
46
+ };
47
+
48
+ const handlePrompt = (value: string) => {
49
+ setPrompt(value);
50
+ };
51
+
52
+ const handleTest = () => {
53
+ dispatch(testAction(search, prompt, profile, presset, id, token, env))
54
+ };
55
+
56
+ const returnTest = () => {
57
+ return (
58
+ <S.Container isloading={isloading}>
59
+ <div id='loading' />
60
+ <S.Header>
61
+ <div className='infos'>
62
+ <h2>{t.test}</h2>
63
+ <p>{t.testArea.description}</p>
64
+ </div>
65
+ </S.Header>
66
+ <S.Inputs>
67
+ <InputTest placeholder={t.testArea.typeSentence} onChange={handleSearch} />
68
+ <Select placeholder={t.testArea.selectPersona} options={optionsPersona} onSelect={handleSelectPersona} />
69
+ <Select placeholder={t.testArea.selectPresset} options={optionsPresset} onSelect={handleSelectPresset} />
70
+ <button onClick={handleTest}><PiWaveformBold /> {t.buttons.test}</button>
71
+ </S.Inputs>
72
+ <S.Inputs>
73
+ {profile === "Custom" && <TextArea className="textarea-message" placeholder={t.testArea.typePrompt} value={prompt} onChange={(e) => { handlePrompt(e.target.value); }} />}
74
+ </S.Inputs>
75
+ {
76
+ !results ? (
77
+ <EmptyState
78
+ icon={<FaList></FaList>}
79
+ title={t.testArea.emptyState.title}
80
+ description={t.testArea.emptyState.description}
81
+ activeButton={false}
82
+ />
83
+ ) : <S.Result>
84
+ <div className='icon'>
85
+ <MdPerson2 />
86
+ </div>
87
+ <div className='text'>{results}</div>
88
+ </S.Result>
89
+ }
90
+ </S.Container>
91
+ )
92
+ }
93
+
94
+ return (
95
+ <S.Container>
96
+ {returnTest()}
97
+ </S.Container>
98
+ );
99
+ };
@@ -0,0 +1,112 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ interface ContainerProps {
4
+ isloading?: boolean;
5
+ }
6
+
7
+
8
+ export const Container = styled.div<ContainerProps>`
9
+ ${(props) =>
10
+ props.isloading &&
11
+ css`
12
+ #loading {
13
+ position: fixed;
14
+ top: 0;
15
+ left: 0;
16
+ width: 100%;
17
+ height: 100%;
18
+ background-color: rgb(151,154,165, 0.7);
19
+ display: flex;
20
+ justify-content: center;
21
+ align-items: center;
22
+ z-index: 9999;
23
+ }
24
+
25
+ #loading::after {
26
+ content: "";
27
+ border: 4px solid #f3f3f3; /* Cor do símbolo de carregamento */
28
+ border-top: 4px solid #5a5d68; /* Cor do símbolo de carregamento */
29
+ border-radius: 50%;
30
+ width: 13px;
31
+ height: 13px;
32
+ animation: spin 1s linear infinite;
33
+ }
34
+
35
+ @keyframes spin {
36
+ 0% { transform: rotate(0deg); }
37
+ 100% { transform: rotate(360deg); }
38
+ }
39
+ `}
40
+
41
+ `;
42
+
43
+ export const Header = styled.div`
44
+ display: flex;
45
+ flex-direction: column;
46
+ .infos {
47
+ display: flex;
48
+ flex-direction: column;
49
+ padding: 14px 0;
50
+
51
+ h2 {
52
+ font-size: 20px
53
+ }
54
+
55
+ p {
56
+ font-size: 14px
57
+ }
58
+ }
59
+ `
60
+
61
+ export const Inputs = styled.div`
62
+ display: inline-flex;
63
+ justify-content: space-between;
64
+ margin-bottom: 10px;
65
+ width: 725px;
66
+ margin-right: 500px;
67
+
68
+ button {
69
+ background: #102693;
70
+ padding: 10px 20px;
71
+ color: white;
72
+ border-radius: 4px;
73
+ width: 190px;
74
+ height: 45px;
75
+ display: flex;
76
+ justify-content: space-between;
77
+ align-items: center;
78
+
79
+ svg {
80
+ width: 23px;
81
+ height: 23px;
82
+ }
83
+ }
84
+ `
85
+
86
+ export const Result = styled.div`
87
+ display: flex;
88
+ justify-content: left;
89
+ background: #F3F5F9;
90
+ padding: 15px;
91
+ border-radius: 5px;
92
+ margin-top: 15px;
93
+
94
+ .text{
95
+ margin-left: 5px;
96
+ font-size: 14px;
97
+ line-height: 1.5;
98
+ }
99
+
100
+ .icon {
101
+ display: flex;
102
+ justify-content: center;
103
+ align-items: center;
104
+ margin-right: 5px;
105
+
106
+ svg {
107
+ width: 35px;
108
+ height: 35px;
109
+ }
110
+ }
111
+
112
+ `
@@ -0,0 +1,133 @@
1
+ import React, { createContext, useContext, useEffect, useState } from "react";
2
+ import { Provider } from "react-redux";
3
+
4
+ import { ContainerToast } from "../components/CustomToast";
5
+ import { getApi } from "../utils/getApi";
6
+ import store from "../store";
7
+
8
+ export interface LeiaProviderProps {
9
+ id: string;
10
+ language: "en" | "pt-br" | "es";
11
+ readonly?: boolean;
12
+ token: string;
13
+ env: string;
14
+ children?: React.ReactNode;
15
+ }
16
+
17
+ interface LeiaContextProps extends Omit<LeiaProviderProps, 'children'> {
18
+ propTags: { tags: [] };
19
+ personas: [{ name: string; description: string }];
20
+ createPersona: (data: any) => Promise<any>;
21
+ updatePersona: (id: string, data: any) => Promise<any>;
22
+ deletePersona: (id: string) => Promise<any>;
23
+ }
24
+
25
+ const LeiaContext = createContext<LeiaContextProps | undefined>(
26
+ undefined
27
+ );
28
+
29
+ export const useLeia = () => {
30
+ const context = useContext(LeiaContext);
31
+ if (!context) {
32
+ throw new Error(
33
+ "useLeia deve ser usado dentro de um LeiaProvider"
34
+ );
35
+ }
36
+ return context;
37
+ };
38
+
39
+ export const LeiaProvider: React.FC<LeiaProviderProps> = ({
40
+ children,
41
+ ...props
42
+ }) => {
43
+ const { id, language, token, env } = props;
44
+ const [tags, setTags] = useState<any>(null);
45
+ const [personas, setPersonas] = useState<any>(null);
46
+ const api = getApi(env);
47
+
48
+ const createPersona = async (data: any) => {
49
+ try {
50
+ const response = await api.post(`/personas?token=${token}`, data);
51
+ setPersonas((prev: any) => [...prev, { ...data, _id: response?.data?.id, created_at: new Date() }]);
52
+ return response.data;
53
+ } catch (error) {
54
+ console.error("Erro ao criar persona:", error);
55
+ throw error;
56
+ }
57
+ }
58
+
59
+ const updatePersona = async (id: string, data: any) => {
60
+ try {
61
+ await api.put(`/personas/${id}?token=${token}`, data);
62
+ setPersonas((prev: any) =>
63
+ prev.map((persona: any) =>
64
+ persona._id === id ? { ...persona, ...data } : persona
65
+ )
66
+ );
67
+ } catch (error) {
68
+ console.error("Erro ao atualizar persona:", error);
69
+ throw error;
70
+ }
71
+ }
72
+
73
+ const deletePersona = async (id: string) => {
74
+ try {
75
+ await api.delete(`/personas/${id}?token=${token}`);
76
+ setPersonas((prev: any) => prev.filter((persona: any) => persona._id !== id));
77
+ } catch (error) {
78
+ console.error("Erro ao deletar persona:", error);
79
+ throw error;
80
+ }
81
+ }
82
+
83
+ useEffect(() => {
84
+ const fetchData = async () => {
85
+ try {
86
+ const { data } = await api.get(`/tags/${id}`);
87
+
88
+ if (data) {
89
+ setTags(data);
90
+ } else {
91
+ console.error("Erro ao fazer a solicitação");
92
+ }
93
+ } catch (error) {
94
+ console.error("Erro ao fazer a solicitação:", error);
95
+ }
96
+ };
97
+
98
+ const personas = async () => {
99
+ try {
100
+ const { data } = await api.get(`/personas?language=${language}&token=${token}`);
101
+
102
+ if (data) {
103
+ setPersonas(data);
104
+ } else {
105
+ console.error("Erro ao fazer a solicitação");
106
+ }
107
+ } catch (error) {
108
+ console.error("Erro ao fazer a solicitação:", error);
109
+ }
110
+ };
111
+
112
+ fetchData();
113
+ personas();
114
+ }, [id]);
115
+
116
+ const values = {
117
+ ...props,
118
+ propTags: tags,
119
+ personas,
120
+ createPersona,
121
+ updatePersona,
122
+ deletePersona,
123
+ };
124
+
125
+ return (
126
+ <Provider store={store}>
127
+ <LeiaContext.Provider value={values}>
128
+ {children}
129
+ <ContainerToast />
130
+ </LeiaContext.Provider>
131
+ </Provider>
132
+ );
133
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,6 @@
1
+ import { LeiaProvider } from "./contexts/LeiaProvider";
2
+ import { FileArea } from "./components/FileArea";
3
+ import { TestArea } from "./components/TestArea";
4
+ import { PersonasArea } from "./components/PersonasArea";
5
+
6
+ export { LeiaProvider, FileArea, TestArea, PersonasArea };
@@ -0,0 +1,11 @@
1
+ export interface tag {
2
+ name: string,
3
+ trained: boolean
4
+ }
5
+
6
+ export interface FileData {
7
+ name: string,
8
+ tags: [tag]
9
+ trained: boolean,
10
+ link: string,
11
+ }
@@ -0,0 +1,95 @@
1
+ type FileArea = {
2
+ description: string;
3
+ status: string;
4
+ fileName: string;
5
+ presset: string;
6
+ actions: string;
7
+ search: string;
8
+ fileUpload: string;
9
+ training: string;
10
+ emptyState: {
11
+ title: string;
12
+ description: string;
13
+ };
14
+ modal: {
15
+ descriptionUpload: string;
16
+ chooseFile: string;
17
+ uploadFile: string;
18
+ deleteFileTitle: string;
19
+ deleteFile: string;
20
+ trainingTitle: string;
21
+ trainingDescription: string
22
+ };
23
+ };
24
+
25
+ type Buttons = {
26
+ cancel: string;
27
+ send: string;
28
+ delete: string;
29
+ test: string;
30
+ addNewPresset: string;
31
+ addPresset: string;
32
+ training: string;
33
+ };
34
+
35
+ type TestArea = {
36
+ description: string;
37
+ typeSentence: string;
38
+ typePrompt: string;
39
+ selectPersona: string;
40
+ selectPresset: string;
41
+ emptyState: {
42
+ title: string;
43
+ description: string;
44
+ };
45
+ };
46
+
47
+ type Toast = {
48
+ deleteFile: {
49
+ success: {
50
+ title: String,
51
+ description: String
52
+ },
53
+ fail: {
54
+ title: String,
55
+ description: String
56
+ }
57
+ },
58
+ uploadFile: {
59
+ success: {
60
+ title: String,
61
+ description: String
62
+ },
63
+ fail: {
64
+ title: String,
65
+ description: String
66
+ }
67
+ },
68
+ Test: {
69
+ fail: {
70
+ title: String,
71
+ description: String
72
+ }
73
+ },
74
+ Train: {
75
+ fail: {
76
+ title: String,
77
+ description: String
78
+ },
79
+ success: {
80
+ title: String,
81
+ description: String
82
+ }
83
+ }
84
+ }
85
+
86
+ export type Language = any | {
87
+ files: string;
88
+ test: string;
89
+ fileArea: FileArea;
90
+ buttons: Buttons;
91
+ testArea: TestArea;
92
+ toast: Toast;
93
+ personas: any;
94
+ copyPrefix: string;
95
+ };
@@ -0,0 +1,12 @@
1
+ export interface TableProps {
2
+ children: React.ReactNode;
3
+ className?: string;
4
+ size?: 'small' | 'medium' | 'large';
5
+ isloading?: boolean;
6
+ }
7
+
8
+ export interface SpinnerProps {
9
+ color?: string;
10
+ size?: 'sm' | 'md' | 'lg';
11
+ className?: string;
12
+ }
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+
3
+ export const API_TOKEN = 'API_TOKEN';
4
+
5
+ const url = 'https://api.leia.digitalcontact.cloud';
6
+
7
+ axios.defaults.baseURL = `${url}`;
8
+
9
+ export default axios.create();
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+
3
+ export const API_TOKEN = 'API_TOKEN';
4
+
5
+ const url = 'http://localhost:5000';
6
+
7
+ axios.defaults.baseURL = `${url}`;
8
+
9
+ export default axios.create();
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+
3
+ export const API_TOKEN = 'API_TOKEN';
4
+
5
+ const url = 'https://api-hml.leia.digitalcontact.cloud';
6
+
7
+ axios.defaults.baseURL = `${url}`;
8
+
9
+ export default axios.create();
@@ -0,0 +1,13 @@
1
+ import { createStore, applyMiddleware } from 'redux';
2
+ import createSagaMiddleware from 'redux-saga';
3
+ import Reducer from './modules/reducer';
4
+ import Sagas from './modules/sagas';
5
+
6
+ const sagaMiddleware = createSagaMiddleware();
7
+
8
+ const store = createStore(Reducer, applyMiddleware(sagaMiddleware));
9
+
10
+ sagaMiddleware.run(Sagas);
11
+
12
+ export default store;
13
+