code7-leia 0.2.27 → 0.2.28
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/code7-leia.cjs.development.js +143 -145
- package/dist/code7-leia.cjs.development.js.map +1 -1
- package/dist/code7-leia.cjs.production.min.js +1 -1
- package/dist/code7-leia.cjs.production.min.js.map +1 -1
- package/dist/code7-leia.esm.js +143 -145
- package/dist/code7-leia.esm.js.map +1 -1
- package/dist/service/ApiDev.d.ts +3 -0
- package/dist/utils/getApi.d.ts +1 -0
- package/package.json +1 -1
- package/src/contexts/SharedPropsProvider.tsx +4 -4
- package/src/service/ApiDev.ts +9 -0
- package/src/service/ApiHml.ts +1 -1
- package/src/store/modules/sagas.ts +14 -13
- package/src/utils/getApi.tsx +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getApi: (env: string) => import("axios").AxiosInstance;
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import apiHml from '../service/ApiHml';
|
|
2
|
+
import { getApi } from 'src/utils/getApi';
|
|
4
3
|
|
|
5
4
|
interface Props {
|
|
6
5
|
id: string;
|
|
@@ -30,11 +29,12 @@ export const SharedPropsProvider: React.FC<Props> = ({ children, ...props }) =>
|
|
|
30
29
|
const { id, language, env } = props;
|
|
31
30
|
const [tags, setTags] = useState<any>(null);
|
|
32
31
|
const [personas, setPersonas] = useState<any>(null);
|
|
32
|
+
const api = getApi(env)
|
|
33
33
|
|
|
34
34
|
useEffect(() => {
|
|
35
35
|
const fetchData = async () => {
|
|
36
36
|
try {
|
|
37
|
-
const { data } =
|
|
37
|
+
const { data } = await api.get(`/tags/${id}`);
|
|
38
38
|
|
|
39
39
|
if (data) {
|
|
40
40
|
setTags(data);
|
|
@@ -48,7 +48,7 @@ export const SharedPropsProvider: React.FC<Props> = ({ children, ...props }) =>
|
|
|
48
48
|
|
|
49
49
|
const personas = async () => {
|
|
50
50
|
try {
|
|
51
|
-
const { data } =
|
|
51
|
+
const { data } = await api.get(`/personas?language=${language}`);
|
|
52
52
|
|
|
53
53
|
if (data) {
|
|
54
54
|
setPersonas(data);
|
package/src/service/ApiHml.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { takeLatest, all, put, call } from 'redux-saga/effects';
|
|
2
|
-
import
|
|
3
|
-
import apiHml from '../../service/ApiHml'
|
|
2
|
+
import { getApi } from '../../utils/getApi'
|
|
4
3
|
import Types from './types'
|
|
5
4
|
import { getFilesActionSuccess,
|
|
6
5
|
deleteFilesActionSuccess,
|
|
@@ -15,7 +14,8 @@ export function* getFilesSaga(action: any) {
|
|
|
15
14
|
try {
|
|
16
15
|
yield put(commonLoadingStart());
|
|
17
16
|
const { id, token, env } = action.payload
|
|
18
|
-
const
|
|
17
|
+
const api = getApi(env)
|
|
18
|
+
const { data } = yield call(api.get, `/training/${id}?token=${token}`);
|
|
19
19
|
yield put(getFilesActionSuccess({ files: data.files}));
|
|
20
20
|
} catch (error) {
|
|
21
21
|
console.log('-----------getFiles.error------------------->', error);
|
|
@@ -29,9 +29,9 @@ export function* deleteFilesSaga(action: any) {
|
|
|
29
29
|
try {
|
|
30
30
|
yield put(commonLoadingStart());
|
|
31
31
|
const { id, name, token, env } = action.payload
|
|
32
|
-
|
|
33
|
-
yield call(
|
|
34
|
-
const { data } = yield call(
|
|
32
|
+
const api = getApi(env)
|
|
33
|
+
yield call(api.delete, `/delete/${id}/${name}?token=${token}`);
|
|
34
|
+
const { data } = yield call(api.get, `/training/${id}?token=${token}`);
|
|
35
35
|
yield put(deleteFilesActionSuccess({ files: data.files, success: true }));
|
|
36
36
|
} catch (error) {
|
|
37
37
|
toast.error({title: t.toast.deleteFile.fail.title, description: t.toast.deleteFile.fail.description});
|
|
@@ -45,7 +45,8 @@ export function* testSaga(action: any) {
|
|
|
45
45
|
try {
|
|
46
46
|
yield put(commonLoadingStart());
|
|
47
47
|
const { question, prompt, profile, presset, files_directory, token, env } = action.payload
|
|
48
|
-
const
|
|
48
|
+
const api = getApi(env)
|
|
49
|
+
const { data } = yield call(api.post, `/ask`, { question, description: prompt, profile, tag: presset, files_directory, token });
|
|
49
50
|
yield put(testActionSuccess({ message: data.message }));
|
|
50
51
|
} catch (error) {
|
|
51
52
|
console.log('-----------testSaga.error------------------->', error);
|
|
@@ -59,7 +60,7 @@ export function* uploadFilesSaga(action: any) {
|
|
|
59
60
|
try {
|
|
60
61
|
yield put(commonLoadingStart());
|
|
61
62
|
const { id, file, pressets, token, env } = action.payload;
|
|
62
|
-
|
|
63
|
+
const api = getApi(env)
|
|
63
64
|
const blob = new Blob([file.content]);
|
|
64
65
|
const formData = new FormData();
|
|
65
66
|
const sanitizedPath = file.properties.path.replace(/^\/+|\/+$/g, '');
|
|
@@ -73,13 +74,13 @@ export function* uploadFilesSaga(action: any) {
|
|
|
73
74
|
? `/upload/${id}?token=${token}&${queryParams}`
|
|
74
75
|
: `/upload/${id}?token=${token}`;
|
|
75
76
|
|
|
76
|
-
yield call(
|
|
77
|
+
yield call(api.post, url, formData, {
|
|
77
78
|
headers: {
|
|
78
79
|
'Content-Type': 'multipart/form-data',
|
|
79
80
|
},
|
|
80
81
|
});
|
|
81
82
|
|
|
82
|
-
const { data } = yield call(
|
|
83
|
+
const { data } = yield call(api.get, `/training/${id}?token=${token}`);
|
|
83
84
|
yield put(uploadFilesActionSuccess({ files: data.files }));
|
|
84
85
|
} catch (error) {
|
|
85
86
|
toast.error({
|
|
@@ -99,12 +100,12 @@ export function* TrainingSaga(action: any) {
|
|
|
99
100
|
yield put(commonLoadingStart());
|
|
100
101
|
const { id, pressets, token, env } = action.payload;
|
|
101
102
|
const tag = pressets.join(',');
|
|
102
|
-
|
|
103
|
+
const api = getApi(env)
|
|
103
104
|
const queryParams = new URLSearchParams({ tag }).toString();
|
|
104
105
|
|
|
105
|
-
yield call(
|
|
106
|
+
yield call(api.post, pressets.length > 0 ? `/training?${queryParams}` : `/training`,{ files_directory: id, token });
|
|
106
107
|
|
|
107
|
-
const { data } = yield call(
|
|
108
|
+
const { data } = yield call(api.get, `/training/${id}?token=${token}`);
|
|
108
109
|
yield put(uploadFilesActionSuccess({ files: data.files }));
|
|
109
110
|
toast.success({title: t.toast.Train.success.title, description: t.toast.Train.success.description});
|
|
110
111
|
} catch (error) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import api from '../service/Api'
|
|
2
|
+
import apiHml from '../service/ApiHml'
|
|
3
|
+
import apiDev from '../service/ApiDev'
|
|
4
|
+
|
|
5
|
+
export const getApi = (env: string) => {
|
|
6
|
+
switch (env.toLowerCase()) {
|
|
7
|
+
case 'dev':
|
|
8
|
+
return apiDev;
|
|
9
|
+
case 'prod':
|
|
10
|
+
return api;
|
|
11
|
+
case 'test':
|
|
12
|
+
return apiHml;
|
|
13
|
+
default:
|
|
14
|
+
return api;
|
|
15
|
+
}
|
|
16
|
+
};
|