Remove chatdoc (#227)
Co-authored-by: AceDataCloud <office@acedata.cloud>
This commit is contained in:
1 parent
7c25bbd23a
commit
f34a3931df
60 files changed
+42
-6340
No files matched your search
@@ -1,357 +0,0 @@
|
||||
import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IChatdocState } from './models';
|
||||
import {
|
||||
IApplication,
|
||||
IChatdocConversation,
|
||||
IChatdocDocument,
|
||||
IChatdocMessage,
|
||||
IChatdocRepository,
|
||||
ICredential,
|
||||
IService,
|
||||
Status
|
||||
} from '@/models';
|
||||
import { chatdocOperator, applicationOperator, serviceOperator, credentialOperator } from '@/operators';
|
||||
import { CHATDOC_SERVICE_ID } from '@/constants';
|
||||
import { getFinalApplication } from '@/utils';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IChatdocState, IRootState>): void => {
|
||||
commit('resetAll');
|
||||
};
|
||||
|
||||
export const setApplication = async ({ commit, dispatch }: any, payload: IApplication): Promise<void> => {
|
||||
console.debug('set application', payload);
|
||||
commit('setApplication', payload);
|
||||
if (!payload) {
|
||||
console.debug('application is null, return');
|
||||
return;
|
||||
}
|
||||
const credential = payload?.credentials?.find((credential) => credential?.host === window.location.origin);
|
||||
if (credential) {
|
||||
console.debug('credential exists, set credential', credential);
|
||||
commit('setCredential', credential);
|
||||
} else {
|
||||
console.debug('credential not exists, start to create credential for application', payload);
|
||||
await dispatch('createCredential');
|
||||
}
|
||||
};
|
||||
|
||||
export const setApplications = async ({ commit }: any, payload: IApplication[]): Promise<void> => {
|
||||
console.debug('set applications', payload);
|
||||
commit('setApplications', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const createCredential = async ({ commit, state }: any): Promise<ICredential | undefined> => {
|
||||
const application = state.application;
|
||||
console.debug('prepare to create credential for application', application);
|
||||
if (!application) {
|
||||
console.error('Application not found');
|
||||
return undefined;
|
||||
}
|
||||
console.debug('creating create credential for application', application);
|
||||
const { data: credential } = await credentialOperator.create({
|
||||
application_id: application?.id,
|
||||
host: window.location.origin
|
||||
});
|
||||
console.debug('created credential success', credential);
|
||||
commit('setCredential', credential);
|
||||
console.debug('end createCredential');
|
||||
return credential;
|
||||
};
|
||||
|
||||
export const getService = async ({
|
||||
commit,
|
||||
state
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IService | undefined> => {
|
||||
state.status.getService = Status.Request;
|
||||
try {
|
||||
const { data: service } = await serviceOperator.get(CHATDOC_SERVICE_ID);
|
||||
state.status.getService = Status.Success;
|
||||
commit('setService', service);
|
||||
return service;
|
||||
} catch (error) {
|
||||
state.status.getService = Status.Error;
|
||||
commit('setService', undefined);
|
||||
}
|
||||
};
|
||||
|
||||
export const getApplications = async ({
|
||||
commit,
|
||||
dispatch,
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IApplication[] | undefined> => {
|
||||
console.debug('start to get applications for chat');
|
||||
state.status.getApplications = Status.Request;
|
||||
const currentApplication = state.application;
|
||||
console.debug('current application', currentApplication);
|
||||
try {
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: rootState?.user?.id,
|
||||
service_id: CHATDOC_SERVICE_ID
|
||||
});
|
||||
state.status.getApplications = Status.Success;
|
||||
commit('setApplications', applications.items);
|
||||
const finalApplication = getFinalApplication(applications.items, currentApplication);
|
||||
if (finalApplication) {
|
||||
console.debug('set final application', finalApplication, finalApplication?.type);
|
||||
await dispatch('setApplication', finalApplication);
|
||||
} else {
|
||||
console.debug('set application undefined', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
return applications.items;
|
||||
} catch (error) {
|
||||
console.error('get applications failed', error);
|
||||
state.status.getApplications = Status.Error;
|
||||
commit('setApplications', undefined);
|
||||
commit('setApplication', undefined);
|
||||
}
|
||||
};
|
||||
|
||||
export const getRepositories = async ({
|
||||
commit,
|
||||
state
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IChatdocRepository[]> => {
|
||||
console.debug('start to get repositories');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepositories', undefined);
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const repositories = (
|
||||
await chatdocOperator.getAllRepositories({
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
console.debug('get repositories success', repositories);
|
||||
commit('setRepositories', repositories);
|
||||
return repositories;
|
||||
};
|
||||
|
||||
export const deleteRepository = async (
|
||||
{ state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: {
|
||||
id: string;
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
console.debug('start to delete repository');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const repository = (
|
||||
await chatdocOperator.deleteRepository(payload.id, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
console.debug('delete repository success', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
export const deleteDocument = async (
|
||||
{ state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: {
|
||||
id: string;
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
console.debug('start to delete document');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const document = (
|
||||
await chatdocOperator.deleteDocument(payload.id, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
console.debug('delete document success', document);
|
||||
return document;
|
||||
};
|
||||
|
||||
export const createRepository = async (
|
||||
{ state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: {
|
||||
name: string;
|
||||
description?: string;
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
console.debug('start to create repository');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const repository = (
|
||||
await chatdocOperator.createRepository(payload, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
console.debug('create repository success', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
export const createDocument = async (
|
||||
{ state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: {
|
||||
repositoryId: string;
|
||||
fileUrl: string;
|
||||
fileName: string;
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
console.debug('start to create document');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const document = (
|
||||
await chatdocOperator.createDocument(payload, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
console.debug('create document success', document);
|
||||
return document;
|
||||
};
|
||||
|
||||
export const setConversation = async (
|
||||
{ commit, state }: any,
|
||||
payload: {
|
||||
id: string;
|
||||
messages: IChatdocMessage[];
|
||||
repositoryId: string;
|
||||
}
|
||||
): Promise<void> => {
|
||||
console.debug('set conversation', payload);
|
||||
const repository: IChatdocRepository | undefined = state.repositories.find(
|
||||
(repository: IChatdocRepository) => repository.id === payload.repositoryId
|
||||
);
|
||||
const conversations = repository?.conversations;
|
||||
if (!conversations) {
|
||||
return Promise.reject('no conversations');
|
||||
}
|
||||
const index = conversations?.findIndex((conversation: IChatdocConversation) => conversation.id === payload.id);
|
||||
if (index > -1) {
|
||||
conversations[index].messages = payload.messages;
|
||||
}
|
||||
console.debug('set conversation success', conversations);
|
||||
};
|
||||
|
||||
export const getDocuments = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocDocument[]> => {
|
||||
console.debug('start to get documents');
|
||||
const credential = state.credential;
|
||||
console.log('credential for getDocuments', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
documents: []
|
||||
});
|
||||
return [];
|
||||
}
|
||||
const documents = (
|
||||
await chatdocOperator.getAllDocuments(payload.repositoryId, {
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
console.debug('get documents success', documents);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
documents: documents
|
||||
});
|
||||
return documents;
|
||||
};
|
||||
|
||||
export const getConversations = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocConversation[]> => {
|
||||
console.debug('start to get conversations');
|
||||
const credential = state.credential;
|
||||
console.log('credential for getConversations', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
conversations: []
|
||||
});
|
||||
return [];
|
||||
}
|
||||
const conversations = (
|
||||
await chatdocOperator.getAllConversations(payload.repositoryId, {
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
console.debug('get conversations success', conversations);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
conversations: conversations
|
||||
});
|
||||
return conversations;
|
||||
};
|
||||
|
||||
export const getRepository = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { id: string }
|
||||
): Promise<IChatdocRepository> => {
|
||||
console.debug('start to get repository');
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', { id: payload.id });
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
const repository = (
|
||||
await chatdocOperator.getRepository(payload.id, {
|
||||
token
|
||||
})
|
||||
).data;
|
||||
console.debug('get repository success', repository);
|
||||
commit('setRepository', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
export const setRepository = async ({ commit }: any, payload: { repository: IChatdocRepository }): Promise<void> => {
|
||||
commit('setRepository', payload);
|
||||
};
|
||||
|
||||
export default {
|
||||
createCredential,
|
||||
setService,
|
||||
setConversation,
|
||||
getService,
|
||||
createRepository,
|
||||
setApplication,
|
||||
getApplications,
|
||||
getRepositories,
|
||||
setCredential,
|
||||
deleteRepository,
|
||||
getRepository,
|
||||
setRepository,
|
||||
getConversations,
|
||||
getDocuments,
|
||||
resetAll,
|
||||
createDocument,
|
||||
deleteDocument
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
import { Module } from 'vuex';
|
||||
import actions from './actions';
|
||||
import mutations from './mutations';
|
||||
import state from './state';
|
||||
import { IChatdocState } from './models';
|
||||
|
||||
export const chatdoc: Module<IChatdocState, any> = {
|
||||
namespaced: true,
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
};
|
||||
|
||||
export default chatdoc;
|
||||
@@ -1,14 +0,0 @@
|
||||
import { IApplication, IChatdocRepository, ICredential, IService, Status } from '@/models';
|
||||
|
||||
export interface IChatdocState {
|
||||
service: IService | undefined;
|
||||
application: IApplication | undefined;
|
||||
applications: IApplication[] | undefined;
|
||||
repositories: IChatdocRepository[] | undefined;
|
||||
credential: ICredential | undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplications: Status;
|
||||
getRepositories: Status;
|
||||
};
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
import { IApplication, IChatdocRepository, ICredential, IService } from '@/models';
|
||||
import { IChatdocState } from './models';
|
||||
|
||||
export const resetAll = (state: IChatdocState): void => {
|
||||
state.application = undefined;
|
||||
state.repositories = [];
|
||||
};
|
||||
|
||||
export const setService = (state: IChatdocState, payload: IService): void => {
|
||||
state.service = payload;
|
||||
};
|
||||
|
||||
export const setApplication = (state: IChatdocState, payload: IApplication): void => {
|
||||
state.application = payload;
|
||||
};
|
||||
export const setApplications = (state: IChatdocState, payload: IApplication[]): void => {
|
||||
state.applications = payload;
|
||||
};
|
||||
|
||||
export const setRepositories = (state: IChatdocState, payload: IChatdocRepository[]): void => {
|
||||
const currentRepositories = state.repositories;
|
||||
if (currentRepositories && payload) {
|
||||
// merge current repositories into payload
|
||||
payload.forEach((repository: IChatdocRepository) => {
|
||||
const index = currentRepositories?.findIndex((item: IChatdocRepository) => item.id === repository.id);
|
||||
if (index !== -1) {
|
||||
payload[index] = {
|
||||
...currentRepositories[index],
|
||||
...repository
|
||||
};
|
||||
}
|
||||
});
|
||||
state.repositories = payload;
|
||||
return;
|
||||
} else {
|
||||
// set the repositories
|
||||
state.repositories = payload;
|
||||
}
|
||||
};
|
||||
|
||||
export const setCredential = (state: IChatdocState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setRepository = (state: IChatdocState, payload: IChatdocRepository): void => {
|
||||
console.debug('mutation', payload);
|
||||
// find the repository and set it
|
||||
const repository = payload;
|
||||
const repositories = state.repositories;
|
||||
if (!repositories) {
|
||||
console.debug('no repositories');
|
||||
return;
|
||||
}
|
||||
const index = repositories.findIndex((item: IChatdocRepository) => item.id === repository.id);
|
||||
if (index === -1) {
|
||||
console.debug('no repository found');
|
||||
return;
|
||||
}
|
||||
console.debug('set repository for index', index, repository);
|
||||
repositories[index] = {
|
||||
...repositories[index],
|
||||
...repository
|
||||
};
|
||||
};
|
||||
|
||||
export default {
|
||||
setService,
|
||||
setApplication,
|
||||
setApplications,
|
||||
setRepositories,
|
||||
setRepository,
|
||||
setCredential,
|
||||
resetAll
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export default ['chatdoc.repositories', 'chatdoc.credential', 'chatdoc.service', 'chatdoc.application'];
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Status } from '@/models';
|
||||
import { IChatdocState } from './models';
|
||||
|
||||
export default (): IChatdocState => {
|
||||
return {
|
||||
service: undefined,
|
||||
application: undefined,
|
||||
applications: undefined,
|
||||
repositories: undefined,
|
||||
credential: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplications: Status.None,
|
||||
getRepositories: Status.None
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -159,7 +159,6 @@ export const logout = async ({ dispatch }: ActionContext<IRootState, IRootState>
|
||||
await dispatch('resetAll');
|
||||
await dispatch('chat/resetAll');
|
||||
await dispatch('midjourney/resetAll');
|
||||
await dispatch('chatdoc/resetAll');
|
||||
await dispatch('flux/resetAll');
|
||||
await dispatch('hailuo/resetAll');
|
||||
await dispatch('headshots/resetAll');
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { ISite, IToken, IUser } from '@/models';
|
||||
import { IMidjourneyState } from '../midjourney/models';
|
||||
import { IChatState } from '../chat/models';
|
||||
import { IChatdocState } from '../chatdoc/models';
|
||||
import { IQrartState } from '../qrart/models';
|
||||
import { ILumaState } from '../luma/models';
|
||||
import { IPikaState } from '../pika/models';
|
||||
@@ -34,7 +33,6 @@ export interface ICommonState {
|
||||
export interface IAppState {
|
||||
midjourney: IMidjourneyState;
|
||||
chat: IChatState;
|
||||
chatdoc: IChatdocState;
|
||||
qrart: IQrartState;
|
||||
luma: ILumaState;
|
||||
pika: IPikaState;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { IRootState } from './models';
|
||||
import chatState from '../chat/state';
|
||||
import midjourneyState from '../midjourney/state';
|
||||
import chatdocState from '../chatdoc/state';
|
||||
import qrartState from '../qrart/state';
|
||||
import lumaState from '../luma/state';
|
||||
import pikaState from '../pika/state';
|
||||
@@ -28,7 +27,6 @@ export default (): IRootState => {
|
||||
},
|
||||
setting: {},
|
||||
site: {},
|
||||
chatdoc: chatdocState(),
|
||||
chat: chatState(),
|
||||
midjourney: midjourneyState(),
|
||||
qrart: qrartState(),
|
||||
|
||||
+1
-5
@@ -2,7 +2,6 @@ import { createStore } from 'vuex';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
import midjourney from './midjourney';
|
||||
import chat from './chat';
|
||||
import chatdoc from './chatdoc';
|
||||
import qrart from './qrart';
|
||||
import luma from './luma';
|
||||
import pika from './pika';
|
||||
@@ -14,7 +13,6 @@ import suno from './suno';
|
||||
import root from './common';
|
||||
import persistChat from './chat/persist';
|
||||
import persistMidjourney from './midjourney/persist';
|
||||
import persistChatdoc from './chatdoc/persist';
|
||||
import persistQrart from './qrart/persist';
|
||||
import persistLuma from './luma/persist';
|
||||
import persistPika from './pika/persist';
|
||||
@@ -37,8 +35,7 @@ const store = createStore({
|
||||
flux: flux,
|
||||
hailuo: hailuo,
|
||||
headshots: headshots,
|
||||
suno: suno,
|
||||
chatdoc: chatdoc
|
||||
suno: suno
|
||||
},
|
||||
plugins: [
|
||||
createPersistedState({
|
||||
@@ -46,7 +43,6 @@ const store = createStore({
|
||||
...persistRoot,
|
||||
...persistChat,
|
||||
...persistMidjourney,
|
||||
...persistChatdoc,
|
||||
...persistQrart,
|
||||
...persistLuma,
|
||||
...persistPika,
|
||||
|
||||
Reference in new issue
Block a user