Add support for renew credentials (#27)

This commit is contained in:
AceDataCloud committed 2024-04-14 17:23:57 +00:00
1 parent d8aadea2fe
commit ada9fbe674
30 files changed
+228 -75

No files matched your search

+14 -4
View File
@@ -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,
+2 -1
View File
@@ -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;
+6 -1
View File
@@ -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
View File
@@ -1 +1 @@
export default ['chat.application', 'chat.service', 'chat.conversations', 'chat.model'];
export default ['chat.application', 'chat.service', 'chat.credential', 'chat.conversations', 'chat.model'];
+3
View File
@@ -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
}
+34 -23
View File
@@ -8,6 +8,7 @@ import {
IChatdocDocument,
IChatdocMessage,
IChatdocRepository,
ICredential,
IService,
Status
} from '@/models';
@@ -18,6 +19,11 @@ export const setApplication = async ({ commit }: any, payload: IApplication): Pr
commit('setApplication', payload);
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
commit('setCredential', payload);
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
commit('setService', payload);
@@ -42,6 +48,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) => {
@@ -60,9 +70,9 @@ export const getRepositories = async ({
state
}: ActionContext<IChatdocState, IRootState>): Promise<IChatdocRepository[]> => {
log(getRepositories, 'start to get repositories');
const application = state.application;
console.log('application', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
if (!token) {
commit('setRepositories', undefined);
return Promise.reject('no token');
@@ -84,9 +94,9 @@ export const deleteRepository = async (
}
): Promise<IChatdocRepository> => {
log(deleteRepository, 'start to delete repository');
const application = state.application;
console.log('application', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
if (!token) {
return Promise.reject('no token');
}
@@ -106,9 +116,9 @@ export const deleteDocument = async (
}
): Promise<IChatdocDocument> => {
log(deleteDocument, 'start to delete document');
const application = state.application;
console.log('application', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
if (!token) {
return Promise.reject('no token');
}
@@ -147,9 +157,9 @@ export const createRepository = async (
}
): Promise<IChatdocRepository> => {
log(createRepository, 'start to create repository');
const application = state.application;
console.log('application', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
if (!token) {
return Promise.reject('no token');
}
@@ -171,9 +181,9 @@ export const createDocument = async (
}
): Promise<IChatdocDocument> => {
log(createDocument, 'start to create document');
const application = state.application;
console.log('application', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
if (!token) {
return Promise.reject('no token');
}
@@ -214,9 +224,9 @@ export const getDocuments = async (
payload: { repositoryId: string }
): Promise<IChatdocDocument[]> => {
log(getRepositories, 'start to get documents');
const application = state.application;
console.log('application for getDocuments', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential for getDocuments', credential);
const token = credential?.token;
if (!token) {
commit('setRepository', {
id: payload.repositoryId,
@@ -242,9 +252,9 @@ export const getConversations = async (
payload: { repositoryId: string }
): Promise<IChatdocConversation[]> => {
log(getConversations, 'start to get conversations');
const application = state.application;
console.log('application for getConversations', application);
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
console.log('credential for getConversations', credential);
const token = credential?.token;
if (!token) {
commit('setRepository', {
id: payload.repositoryId,
@@ -272,8 +282,8 @@ export const getRepository = async (
payload: { id: string }
): Promise<IChatdocRepository> => {
log(getRepository, 'start to get repository');
const application = state.application;
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
const token = credential?.token;
if (!token) {
commit('setRepository', { id: payload.id });
return Promise.reject('no token');
@@ -296,6 +306,7 @@ export default {
setApplication,
getApplication,
getRepositories,
setCredential,
deleteRepository,
getRepository,
setRepository,
+2 -1
View File
@@ -1,9 +1,10 @@
import { IApplication, IChatdocRepository, IService, Status } from '@/models';
import { IApplication, IChatdocRepository, ICredential, IService, Status } from '@/models';
export interface IChatdocState {
service: IService | undefined;
application: IApplication | undefined;
repositories: IChatdocRepository[] | undefined;
credential: ICredential | undefined;
status: {
getService: Status;
getApplication: Status;
+6 -1
View File
@@ -1,4 +1,4 @@
import { IApplication, IChatdocRepository, IService } from '@/models';
import { IApplication, IChatdocRepository, ICredential, IService } from '@/models';
import { IChatdocState } from './models';
import { log } from '@/utils';
@@ -36,6 +36,10 @@ export const setRepositories = (state: IChatdocState, payload: IChatdocRepositor
}
};
export const setCredential = (state: IChatdocState, payload: ICredential): void => {
state.credential = payload;
};
export const setRepository = (state: IChatdocState, payload: IChatdocRepository): void => {
log(setRepository, 'mutation', payload);
// find the repository and set it
@@ -62,5 +66,6 @@ export default {
setApplication,
setRepositories,
setRepository,
setCredential,
resetAll
};
+1 -1
View File
@@ -1 +1 @@
export default ['chatdoc.repositories', 'chatdoc.service', 'chatdoc.application'];
export default ['chatdoc.repositories', 'chatdoc.credential', 'chatdoc.service', 'chatdoc.application'];
+1
View File
@@ -6,6 +6,7 @@ export default (): IChatdocState => {
service: undefined,
application: undefined,
repositories: undefined,
credential: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
+20 -3
View File
@@ -3,7 +3,14 @@ import { IMidjourneyState } from './models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IRootState } from '../common/models';
import { IApplication, IMidjourneyImagineTask, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
import {
IApplication,
ICredential,
IMidjourneyImagineTask,
IMidjourneyMode,
IMidjourneyPreset,
IService
} from '@/models';
import { Status } from '@/models/common';
import { MIDJOURNEY_SERVICE_ID } from '@/constants';
@@ -11,6 +18,11 @@ export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>
commit('resetAll');
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
commit('setCredential', payload);
};
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
commit('setPreset', payload);
};
@@ -44,6 +56,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) => {
@@ -81,8 +97,8 @@ export const getImagineTasks = async (
): Promise<IMidjourneyImagineTask[]> => {
return new Promise(async (resolve, reject) => {
log(getImagineTasks, 'start to get imagine tasks', offset, limit);
const application = state.application;
const token = application?.credentials?.[0]?.token;
const credential = state.credential;
const token = credential?.token;
if (!token) {
return reject('no token');
}
@@ -111,6 +127,7 @@ export default {
setService,
getService,
resetAll,
setCredential,
setPreset,
setMode,
setApplication,
+10 -1
View File
@@ -1,10 +1,19 @@
import { IApplication, IMidjourneyImagineTask, IMidjourneyMode, IMidjourneyPreset, IService, Status } from '@/models';
import {
IApplication,
ICredential,
IMidjourneyImagineTask,
IMidjourneyMode,
IMidjourneyPreset,
IService,
Status
} from '@/models';
export interface IMidjourneyState {
service: IService | undefined;
application: IApplication | undefined;
imagineTasks: IMidjourneyImagineTask[] | undefined;
imagineTasksTotal: number | undefined;
credential: ICredential | undefined;
preset: IMidjourneyPreset;
mode: IMidjourneyMode;
status: {
+6 -1
View File
@@ -1,4 +1,4 @@
import { IApplication, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
import { IApplication, ICredential, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
import { IMidjourneyState } from './models';
export const resetAll = (state: IMidjourneyState): void => {
@@ -11,6 +11,10 @@ export const setService = (state: IMidjourneyState, payload: IService): void =>
state.service = payload;
};
export const setCredential = (state: IMidjourneyState, payload: ICredential): void => {
state.credential = payload;
};
export const setApplication = (state: IMidjourneyState, payload: IApplication): void => {
state.application = payload;
};
@@ -34,6 +38,7 @@ export const setImagineTasksTotal = (state: IMidjourneyState, payload: number):
export default {
setApplication,
setPreset,
setCredential,
setService,
setMode,
setImagineTasks,
+7 -1
View File
@@ -1 +1,7 @@
export default ['midjourney.preset', 'midjourney.mode', 'midjourney.application', 'midjourney.imagineTasks'];
export default [
'midjourney.preset',
'midjourney.credential',
'midjourney.mode',
'midjourney.application',
'midjourney.imagineTasks'
];
+1
View File
@@ -8,6 +8,7 @@ export default (): IMidjourneyState => {
application: undefined,
imagineTasks: undefined,
imagineTasksTotal: undefined,
credential: undefined,
preset: {},
mode: MIDJOURNEY_MODE_FAST,
status: {