Add support for renew credentials (#27)
This commit is contained in:
1 parent
d8aadea2fe
commit
ada9fbe674
30 files changed
+228
-75
No files matched your search
@@ -3,7 +3,7 @@ import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatState } from './models';
|
||||
import { IApplication, IChatConversation, IChatModel, IService, Status } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
import { CHAT_SERVICE_ID } from '@/constants';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IChatState, IRootState>): void => {
|
||||
@@ -29,6 +29,11 @@ export const setConversations = async ({ commit }: any, payload: IChatConversati
|
||||
commit('setConversations', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise<void> => {
|
||||
log(setConversation, 'set conversation', payload);
|
||||
const conversations = state.conversations;
|
||||
@@ -76,6 +81,10 @@ export const getApplication = async ({
|
||||
.then((response) => {
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0].credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -91,9 +100,9 @@ export const getConversations = async ({
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IChatConversation[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
state.status.getConversations = Status.Request;
|
||||
const application = state.application;
|
||||
log(getConversations, 'application', application);
|
||||
const token = application?.credentials?.[0].token;
|
||||
const credential = state.credential;
|
||||
log(getConversations, 'credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
state.status.getConversations = Status.Error;
|
||||
return reject(new Error('Token not found'));
|
||||
@@ -126,6 +135,7 @@ export default {
|
||||
setModel,
|
||||
getService,
|
||||
setService,
|
||||
setCredential,
|
||||
setApplication,
|
||||
getApplication,
|
||||
setConversation,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { IApplication, IChatConversation, IChatModel, IService, Status } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
|
||||
export interface IChatState {
|
||||
model: IChatModel;
|
||||
application: IApplication | undefined;
|
||||
service: IService | undefined;
|
||||
conversations: IChatConversation[] | undefined;
|
||||
credential: ICredential | undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplication: Status;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IApplication, IChatConversation, IChatModel, IService } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService } from '@/models';
|
||||
import { IChatState } from './models';
|
||||
|
||||
export const resetAll = (state: IChatState): void => {
|
||||
@@ -10,6 +10,10 @@ export const setModel = (state: IChatState, payload: IChatModel): void => {
|
||||
state.model = payload;
|
||||
};
|
||||
|
||||
export const setCredential = (state: IChatState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setApplication = (state: IChatState, payload: IApplication): void => {
|
||||
state.application = payload;
|
||||
};
|
||||
@@ -25,6 +29,7 @@ export const setConversations = (state: IChatState, payload: IChatConversation[]
|
||||
export default {
|
||||
setModel,
|
||||
setService,
|
||||
setCredential,
|
||||
setConversations,
|
||||
setApplication,
|
||||
resetAll
|
||||
|
||||
@@ -1 +1 @@
|
||||
export default ['chat.application', 'chat.service', 'chat.conversations', 'chat.model'];
|
||||
export default ['chat.application', 'chat.service', 'chat.credential', 'chat.conversations', 'chat.model'];
|
||||
@@ -7,7 +7,10 @@ export default (): IChatState => {
|
||||
model: CHAT_MODEL_GPT_3_5,
|
||||
application: undefined,
|
||||
conversations: undefined,
|
||||
service: undefined,
|
||||
credential: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplication: Status.None,
|
||||
getConversations: Status.None
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user