Fix auth and experience issue (#87)

Co-authored-by: Germey <germey@acedata.cloud>
This commit is contained in:
GermeyandGermey authored and GitHub committed 2024-07-28 05:16:52 +00:00
1 parent c7c755fcd6
commit 558eadb63c
24 files changed
+235 -427

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix auth and experience issues",
"packageName": "@acedatacloud/nexior",
"email": "germey@acedata.cloud",
"dependentChangeType": "patch"
}
+2 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="box"></div>
<div class="mark"></div>
</template>
<script lang="ts">
@@ -30,7 +30,7 @@ export default defineComponent({
opacity: 1;
}
}
.box {
.mark {
width: 2px;
height: 16px;
margin-top: 3px;
+13 -5
View File
@@ -2,8 +2,7 @@
<div
:class="{
message: true,
[message.role as string]: true,
hidden: errorText && message.role === 'assistant'
[message.role as string]: true
}"
:role="message.role"
>
@@ -15,12 +14,17 @@
class="avatar"
/>
</div>
<div class="main">
<div v-if="!errorText" class="main">
<div class="content">
<markdown-renderer v-if="!Array.isArray(message.content)" :content="message?.content" />
<div v-else>
<div v-for="(item, index) in message.content" :key="index">
<img v-if="item.type === 'image_url'" :src="item.image_url?.url" fit="cover" class="image" />
<img
v-if="item.type === 'image_url'"
:src="typeof item?.image_url === 'string' ? item.image_url : item.image_url?.url"
fit="cover"
class="image"
/>
<markdown-renderer v-if="item.type === 'text'" :key="index" :content="item.text" />
</div>
</div>
@@ -30,7 +34,7 @@
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content!" class="btn-copy" />
</div>
</div>
<el-alert v-if="errorText" class="error" :title="errorText" type="error" :closable="false" />
<el-alert v-else class="error" :title="errorText" type="error" :closable="false" />
<el-button v-if="showBuyMore" round type="primary" class="btn btn-buy" size="small" @click="onBuyMore">
{{ $t('common.button.buyMore') }}
</el-button>
@@ -190,6 +194,10 @@ export default defineComponent({
.content {
color: var(--el-text-color-primary);
}
.btn-buy {
display: inline-block;
margin-left: 5px;
}
}
&.user {
.main {
+84 -130
View File
@@ -1,41 +1,26 @@
<template>
<div class="selector">
<el-dropdown
v-for="(group, groupIndex) in groups"
:key="groupIndex"
trigger="click"
popper-class="popper"
@command="onCommandChange"
>
<el-button :class="{ group: true, active: group.value === activeGroup }" @click="onSwitchGroup(group)">
<font-awesome-icon :icon="group.icon" :class="'icon ' + group.value" />
<span v-if="group.value === activeGroup">
{{ model.getDisplayName() }}
<el-dropdown trigger="click" popper-class="popper">
<div>
<span class="name">{{ model?.getDisplayName() }}</span>
<span class="angle">
<font-awesome-icon icon="fa-solid fa-angle-down" />
</span>
<span v-else>
{{ group.label }}
</span>
<font-awesome-icon icon="fa-solid fa-chevron-down" />
</el-button>
</div>
<template #dropdown>
<el-dropdown-menu class="menu">
<el-dropdown-menu>
<el-dropdown-item
v-for="(groupModel, groupModelIndex) in group.options"
:key="groupModelIndex"
:command="groupModel"
class="option"
v-for="(option, optionKey) in options"
:key="optionKey"
@click="onCommandChange(option.model)"
>
<div class="item">
<div class="icon">
<font-awesome-icon :icon="group.icon" :class="'icon ' + group.value" />
<div class="icon" :style="{ color: option.color }">
<font-awesome-icon :icon="option.icon" />
</div>
<div class="info">
<p class="name">
{{ groupModel.getDisplayName() }}
</p>
<p class="description">
{{ groupModel.getDescription() }}
</p>
<p class="name">{{ option.model.getDisplayName() }}</p>
<p class="description">{{ option.model.getDescription() }}</p>
</div>
</div>
</el-dropdown-item>
@@ -47,7 +32,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDropdown, ElButton, ElDropdownItem } from 'element-plus';
import { ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IChatModel } from '@/models';
import {
@@ -58,41 +43,44 @@ import {
CHAT_MODEL_GPT_4_VISION
} from '@/constants';
const GROUPS = [
{
label: '3.5',
value: 'base',
icon: 'fa-solid fa-bolt',
options: [CHAT_MODEL_GPT_3_5, CHAT_MODEL_GPT_3_5_BROWSING]
},
{
label: '4.0',
value: 'plus',
icon: 'fa-solid fa-wand-magic-sparkles',
options: [CHAT_MODEL_GPT_4, CHAT_MODEL_GPT_4_BROWSING, CHAT_MODEL_GPT_4_VISION]
}
];
export default defineComponent({
name: 'ModelSelector',
components: {
ElDropdown,
ElButton,
ElDropdownMenu,
ElDropdownItem,
FontAwesomeIcon
},
emits: ['update:modelValue', 'select'],
data() {
// find active group according to model
const model = this.$store.state.chat.model;
const activeGroup = GROUPS.find((group) => {
return group.options.find((option: IChatModel) => {
return option.name === model.name;
});
})?.value;
return {
activeGroup,
groups: GROUPS
options: [
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5
},
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_VISION
}
]
};
},
computed: {
@@ -109,18 +97,6 @@ export default defineComponent({
}
},
methods: {
onSwitchGroup(group: any) {
if (this.activeGroup === group.value) {
return;
}
this.activeGroup = group.value;
const options = group.options;
// by default select first option
if (options && options.length > 0) {
this.$emit('select', options[0]);
this.$store.dispatch('chat/setModel', options[0]);
}
},
onCommandChange(command: IChatModel) {
this.$emit('select', command);
this.$store.dispatch('chat/setModel', command);
@@ -131,81 +107,59 @@ export default defineComponent({
<style lang="scss">
.popper {
border-radius: 10px;
border-radius: 20px;
overflow: hidden;
}
</style>
<style lang="scss" scoped>
.selector {
background-color: var(--el-bg-color-page);
cursor: pointer;
padding: 7px 6px;
border-radius: 15px;
margin-bottom: 10px;
.group {
padding: 20px 30px;
color: var(--el-text-color-primary);
border: none;
border-radius: 10px;
margin: 0 3px;
background-color: inherit;
&:hover,
&:focus,
&.active {
background-color: var(--el-fill-color-extra-light);
}
.icon {
display: inline-block;
margin-right: 5px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.fa-chevron-down {
margin-left: 5px;
font-weight: 100;
color: var(--el-text-color-primary);
transform: scale(0.8);
}
.name {
font-size: 16px;
font-weight: bold;
display: inline-block;
margin-right: 5px;
}
.angle {
display: inline-block;
max-width: 5px;
}
}
.menu {
.option {
.item {
display: flex;
flex-direction: row;
.icon {
width: 15px;
display: flex;
align-items: flex-start;
justify-content: center;
margin-right: 5px;
margin-top: 3px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.info {
width: calc(100% - 15px);
.name {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-primary);
margin: 0;
}
.description {
font-size: 12px;
color: var(--el-text-color-secondary);
margin: 0;
}
}
.item {
display: flex;
flex-direction: row;
.icon {
width: 15px;
display: flex;
align-items: flex-start;
justify-content: center;
margin-right: 5px;
margin-top: 3px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.info {
width: calc(100% - 15px);
.name {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-primary);
margin: 0;
}
.description {
font-size: 12px;
color: var(--el-text-color-secondary);
margin: 0;
}
}
}
-166
View File
@@ -1,166 +0,0 @@
<template>
<div class="selector">
<el-dropdown trigger="click" popper-class="popper">
<div>
<span class="name">{{ model?.getDisplayName() }}</span>
<span class="angle">
<font-awesome-icon icon="fa-solid fa-angle-down" />
</span>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="(option, optionKey) in options"
:key="optionKey"
@click="onCommandChange(option.model)"
>
<div class="item">
<div class="icon" :style="{ color: option.color }">
<font-awesome-icon :icon="option.icon" />
</div>
<div class="info">
<p class="name">{{ option.model.getDisplayName() }}</p>
<p class="description">{{ option.model.getDescription() }}</p>
</div>
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IChatModel } from '@/models';
import {
CHAT_MODEL_GPT_3_5,
CHAT_MODEL_GPT_3_5_BROWSING,
CHAT_MODEL_GPT_4,
CHAT_MODEL_GPT_4_BROWSING,
CHAT_MODEL_GPT_4_VISION
} from '@/constants';
export default defineComponent({
name: 'ModelSelector',
components: {
ElDropdown,
ElDropdownMenu,
ElDropdownItem,
FontAwesomeIcon
},
emits: ['update:modelValue', 'select'],
data() {
return {
options: [
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5
},
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_VISION
}
]
};
},
computed: {
model() {
const modelName = this.$store.state.chat.model.name;
const model = [
CHAT_MODEL_GPT_3_5,
CHAT_MODEL_GPT_3_5_BROWSING,
CHAT_MODEL_GPT_4,
CHAT_MODEL_GPT_4_BROWSING,
CHAT_MODEL_GPT_4_VISION
].find((model) => model.name === modelName);
return model;
}
},
methods: {
onCommandChange(command: IChatModel) {
this.$emit('select', command);
this.$store.dispatch('chat/setModel', command);
}
}
});
</script>
<style lang="scss">
.popper {
border-radius: 20px;
overflow: hidden;
}
</style>
<style lang="scss" scoped>
.selector {
cursor: pointer;
padding: 7px 6px;
border-radius: 15px;
margin-bottom: 10px;
.name {
font-size: 16px;
font-weight: bold;
display: inline-block;
margin-right: 5px;
}
.angle {
display: inline-block;
max-width: 5px;
}
}
.item {
display: flex;
flex-direction: row;
.icon {
width: 15px;
display: flex;
align-items: flex-start;
justify-content: center;
margin-right: 5px;
margin-top: 3px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.info {
width: calc(100% - 15px);
.name {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-primary);
margin: 0;
}
.description {
font-size: 12px;
color: var(--el-text-color-secondary);
margin: 0;
}
}
}
</style>
+2 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="box"></div>
<div class="mark"></div>
</template>
<script lang="ts">
@@ -30,7 +30,7 @@ export default defineComponent({
opacity: 1;
}
}
.box {
.mark {
width: 2px;
height: 16px;
margin-top: 3px;
+2
View File
@@ -15,6 +15,8 @@ export default defineComponent({
async mounted() {
if (this.redirect) {
await this.$router.push(this.redirect);
} else {
await this.$router.push('/');
}
}
});
+1 -1
View File
@@ -14,7 +14,7 @@ export default defineComponent({
};
},
async mounted() {
login(this.redirect);
login({ redirect: this.redirect });
},
methods: {}
});
+5 -3
View File
@@ -1,7 +1,7 @@
<template>
<layout>
<template #chat>
<model-selector2 class="selector" />
<model-selector class="selector" />
<application-status
:initializing="initializing"
:application="application"
@@ -43,7 +43,7 @@ import Message from '@/components/chat/Message.vue';
import { ROLE_ASSISTANT, ROLE_USER } from '@/constants';
import { IChatModel, IChatMessageState, IChatConversationResponse, IChatConversation, IChatMessage } from '@/models';
import InputBox from '@/components/chat/InputBox.vue';
import ModelSelector2 from '@/components/chat/ModelSelector2.vue';
import ModelSelector from '@/components/chat/ModelSelector.vue';
import { ERROR_CODE_CANCELED, ERROR_CODE_NOT_APPLIED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router';
import { Status } from '@/models';
@@ -65,7 +65,7 @@ export default defineComponent({
components: {
InputBox,
Introduction,
ModelSelector2,
ModelSelector,
Message,
ApplicationStatus,
Layout
@@ -177,6 +177,7 @@ export default defineComponent({
});
}
this.messages.push({
// @ts-ignore
content: content,
role: ROLE_USER
});
@@ -284,6 +285,7 @@ export default defineComponent({
if (isJSONString(data)) {
data = JSON.parse(data);
}
console.debug('error', data);
if (this.messages && this.messages.length > 0) {
this.messages[this.messages.length - 1].error = data.error;
}
+3 -4
View File
@@ -52,7 +52,6 @@ import {
ROLE_ASSISTANT,
ROLE_USER
} from '@/constants';
import { log } from '@/utils';
import { ROUTE_CHATDOC_CONVERSATION } from '@/router';
import axios from 'axios';
import { isJSONString } from '@/utils/is';
@@ -142,7 +141,7 @@ export default defineComponent({
async onFetchAnswer() {
const token = this.credential?.token;
const question = this.question;
log(this.onFetchAnswer, 'validated', question);
console.debug(this.onFetchAnswer, 'validated', question);
// reset question and references
this.question = '';
if (!token || !question) {
@@ -162,7 +161,7 @@ export default defineComponent({
role: ROLE_ASSISTANT,
state: IChatdocMessageState.PENDING
});
log(this.onFetchAnswer, 'start to get answer', this.messages);
console.debug('start to get answer', this.messages);
this.onScrollDown();
// request server to get answer
this.answering = true;
@@ -187,7 +186,7 @@ export default defineComponent({
}
)
.then(async () => {
log(this.onFetchAnswer, 'finished fetch answer');
console.debug('finished fetch answer');
this.messages[this.messages.length - 1].state = IChatdocMessageState.FINISHED;
await this.$store.dispatch('chatdoc/setConversation', {
id: conversationId,
+1
View File
@@ -224,6 +224,7 @@ export default defineComponent({
console.debug('start onGetApplication');
await this.$store.dispatch('midjourney/getApplication');
console.debug('end onGetApplication');
await this.onGetTasks();
},
onApply() {
applicationOperator
+1
View File
@@ -100,6 +100,7 @@ export default defineComponent({
console.debug('start onGetApplication');
await this.$store.dispatch('qrart/getApplication');
console.debug('end onGetApplication');
await this.onGetTasks();
},
onApply() {
applicationOperator
+1
View File
@@ -121,6 +121,7 @@ export default defineComponent({
console.debug('start onGetApplication');
await this.$store.dispatch('suno/getApplication');
console.debug('end onGetApplication');
await this.onGetTasks();
},
onApply() {
applicationOperator
+15 -14
View File
@@ -1,7 +1,6 @@
import { applicationOperator, chatOperator, serviceOperator } from '@/operators';
import { IRootState } from '../common/models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IChatState } from './models';
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
import { CHAT_SERVICE_ID } from '@/constants';
@@ -15,27 +14,27 @@ export const setModel = async ({ commit }: any, payload: IChatModel): Promise<vo
};
export const setApplication = async ({ commit }: any, payload: IApplication): Promise<void> => {
log(setApplication, 'set application', payload);
console.debug('set application', payload);
commit('setApplication', payload);
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
console.debug('set service', payload);
commit('setService', payload);
};
export const setConversations = async ({ commit }: any, payload: IChatConversation[]): Promise<void> => {
log(setConversations, 'set conversations', payload);
console.debug('set conversations', payload);
commit('setConversations', payload);
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
console.debug('set credential', payload);
commit('setCredential', payload);
};
export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise<void> => {
log(setConversation, 'set conversation', payload);
console.debug('set conversation', payload);
const conversations = state.conversations || [];
const index = conversations?.findIndex((conversation: IChatConversation) => conversation.id === payload.id);
if (index > -1) {
@@ -44,12 +43,12 @@ export const setConversation = async ({ commit, state }: any, payload: IChatConv
conversations?.unshift(payload);
}
commit('setConversations', conversations);
log(setConversation, 'set conversation success', conversations);
console.debug('set conversation success', conversations);
};
export const getService = async ({ commit, state }: ActionContext<IChatState, IRootState>): Promise<IService> => {
return new Promise(async (resolve, reject) => {
log(getService, 'start to get service for chat');
return new Promise((resolve, reject) => {
console.debug('start to get service for chat');
state.status.getService = Status.Request;
serviceOperator
.get(CHAT_SERVICE_ID)
@@ -70,8 +69,8 @@ export const getApplication = async ({
state,
rootState
}: ActionContext<IChatState, IRootState>): Promise<IApplication> => {
return new Promise(async (resolve, reject) => {
log(getApplication, 'start to get application for chat');
return new Promise((resolve, reject) => {
console.debug('start to get application for chat');
state.status.getApplication = Status.Request;
applicationOperator
.getAll({
@@ -79,6 +78,7 @@ export const getApplication = async ({
service_id: CHAT_SERVICE_ID
})
.then((response) => {
console.debug('get application success', response?.data);
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
@@ -86,6 +86,7 @@ export const getApplication = async ({
);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('save application success', response.data.items[0]);
})
.catch((error) => {
state.status.getApplication = Status.Error;
@@ -98,10 +99,10 @@ export const getConversations = async ({
commit,
state
}: ActionContext<IChatState, IRootState>): Promise<IChatConversation[]> => {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
state.status.getConversations = Status.Request;
const credential = state.credential;
log(getConversations, 'credential', credential);
console.debug('credential', credential);
const token = credential?.token;
if (!token) {
state.status.getConversations = Status.Error;
@@ -117,7 +118,7 @@ export const getConversations = async ({
}
)
.then((response) => {
log(getConversations, 'get conversations success', response.data?.items?.length);
console.debug('get conversations success', response.data?.items?.length);
commit('setConversations', response.data.items);
const conversations = response.data.items;
resolve(conversations);
+21 -22
View File
@@ -1,6 +1,5 @@
import { IRootState } from '../common/models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IChatdocState } from './models';
import {
IApplication,
@@ -20,12 +19,12 @@ export const setApplication = async ({ commit }: any, payload: IApplication): Pr
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
console.debug('set credential', payload);
commit('setCredential', payload);
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
console.debug('set service', payload);
commit('setService', payload);
};
@@ -69,7 +68,7 @@ export const getRepositories = async ({
commit,
state
}: ActionContext<IChatdocState, IRootState>): Promise<IChatdocRepository[]> => {
log(getRepositories, 'start to get repositories');
console.debug('start to get repositories');
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
@@ -82,7 +81,7 @@ export const getRepositories = async ({
token
})
).data.items;
log(getRepositories, 'get repositories success', repositories);
console.debug('get repositories success', repositories);
commit('setRepositories', repositories);
return repositories;
};
@@ -93,7 +92,7 @@ export const deleteRepository = async (
id: string;
}
): Promise<IChatdocRepository> => {
log(deleteRepository, 'start to delete repository');
console.debug('start to delete repository');
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
@@ -105,7 +104,7 @@ export const deleteRepository = async (
token
})
).data;
log(deleteRepository, 'delete repository success', repository);
console.debug('delete repository success', repository);
return repository;
};
@@ -115,7 +114,7 @@ export const deleteDocument = async (
id: string;
}
): Promise<IChatdocDocument> => {
log(deleteDocument, 'start to delete document');
console.debug('start to delete document');
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
@@ -127,13 +126,13 @@ export const deleteDocument = async (
token
})
).data;
log(deleteRepository, 'delete document success', document);
console.debug('delete document success', document);
return document;
};
export const getService = async ({ commit, state }: ActionContext<IChatdocState, IRootState>): Promise<IService> => {
return new Promise(async (resolve, reject) => {
log(getService, 'start to get service for chatdoc');
console.debug('start to get service for chatdoc');
state.status.getService = Status.Request;
serviceOperator
.get(CHATDOC_SERVICE_ID)
@@ -156,7 +155,7 @@ export const createRepository = async (
description?: string;
}
): Promise<IChatdocRepository> => {
log(createRepository, 'start to create repository');
console.debug('start to create repository');
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
@@ -168,7 +167,7 @@ export const createRepository = async (
token
})
).data;
log(createRepository, 'create repository success', repository);
console.debug('create repository success', repository);
return repository;
};
@@ -180,7 +179,7 @@ export const createDocument = async (
fileName: string;
}
): Promise<IChatdocDocument> => {
log(createDocument, 'start to create document');
console.debug('start to create document');
const credential = state.credential;
console.log('credential', credential);
const token = credential?.token;
@@ -192,7 +191,7 @@ export const createDocument = async (
token
})
).data;
log(createDocument, 'create document success', document);
console.debug('create document success', document);
return document;
};
@@ -204,7 +203,7 @@ export const setConversation = async (
repositoryId: string;
}
): Promise<void> => {
log(setConversation, 'set conversation', payload);
console.debug('set conversation', payload);
const repository: IChatdocRepository | undefined = state.repositories.find(
(repository: IChatdocRepository) => repository.id === payload.repositoryId
);
@@ -216,14 +215,14 @@ export const setConversation = async (
if (index > -1) {
conversations[index].messages = payload.messages;
}
log(setConversation, 'set conversation success', conversations);
console.debug('set conversation success', conversations);
};
export const getDocuments = async (
{ commit, state }: ActionContext<IChatdocState, IRootState>,
payload: { repositoryId: string }
): Promise<IChatdocDocument[]> => {
log(getRepositories, 'start to get documents');
console.debug('start to get documents');
const credential = state.credential;
console.log('credential for getDocuments', credential);
const token = credential?.token;
@@ -239,7 +238,7 @@ export const getDocuments = async (
token
})
).data.items;
log(getRepositories, 'get documents success', documents);
console.debug('get documents success', documents);
commit('setRepository', {
id: payload.repositoryId,
documents: documents
@@ -251,7 +250,7 @@ export const getConversations = async (
{ commit, state }: ActionContext<IChatdocState, IRootState>,
payload: { repositoryId: string }
): Promise<IChatdocConversation[]> => {
log(getConversations, 'start to get conversations');
console.debug('start to get conversations');
const credential = state.credential;
console.log('credential for getConversations', credential);
const token = credential?.token;
@@ -267,7 +266,7 @@ export const getConversations = async (
token
})
).data.items;
log(getConversations, 'get conversations success', conversations);
console.debug('get conversations success', conversations);
commit('setRepository', {
id: payload.repositoryId,
conversations: conversations
@@ -279,7 +278,7 @@ export const getRepository = async (
{ commit, state }: ActionContext<IChatdocState, IRootState>,
payload: { id: string }
): Promise<IChatdocRepository> => {
log(getRepository, 'start to get repository');
console.debug('start to get repository');
const credential = state.credential;
const token = credential?.token;
if (!token) {
@@ -291,7 +290,7 @@ export const getRepository = async (
token
})
).data;
log(getRepository, 'get repository success', repository);
console.debug('get repository success', repository);
commit('setRepository', repository);
return repository;
};
+4 -5
View File
@@ -1,6 +1,5 @@
import { IApplication, IChatdocRepository, ICredential, IService } from '@/models';
import { IChatdocState } from './models';
import { log } from '@/utils';
export const resetAll = (state: IChatdocState): void => {
state.application = undefined;
@@ -41,20 +40,20 @@ export const setCredential = (state: IChatdocState, payload: ICredential): void
};
export const setRepository = (state: IChatdocState, payload: IChatdocRepository): void => {
log(setRepository, 'mutation', payload);
console.debug('mutation', payload);
// find the repository and set it
const repository = payload;
const repositories = state.repositories;
if (!repositories) {
log(setRepository, 'no repositories');
console.debug('no repositories');
return;
}
const index = repositories.findIndex((item: IChatdocRepository) => item.id === repository.id);
if (index === -1) {
log(setRepository, 'no repository found');
console.debug('no repository found');
return;
}
log(setRepository, 'set repository for index', index, repository);
console.debug('set repository for index', index, repository);
repositories[index] = {
...repositories[index],
...repository
+25 -23
View File
@@ -1,7 +1,6 @@
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { userOperator, oauthOperator, siteOperator, exchangeOperator } from '@/operators';
import { log } from '@/utils/log';
import { IToken, IUser } from '@/models';
import { getSiteOrigin } from '@/utils/site';
import { login as authLogin } from '@/utils';
@@ -40,33 +39,36 @@ export const setExchange = ({ commit }: ActionContext<IRootState, IRootState>, p
};
export const getUser = async ({ commit }: ActionContext<IRootState, IRootState>): Promise<IUser> => {
log(getUser, 'start to get user');
console.debug('start to get user');
try {
commit('resetUser');
const { data: user } = await userOperator.getMe();
commit('setUser', user);
log(getUser, 'get user success', user);
console.debug('get user success', user);
return user;
} catch (error) {
log(getUser, 'get user failed', error);
console.error('get user failed', error);
}
};
export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>, code: string): Promise<IToken> => {
log(getToken, 'start to get token using code', code);
console.debug('start to get token using code', code);
try {
commit('resetToken');
const { data } = await oauthOperator.token({
code
});
console.debug('get token success', data);
const token = {
access: data.access_token,
refresh: data.refresh_token,
expiration: data.expires_in
};
commit('setToken', token);
log(getToken, 'get token success', data);
console.debug('get token success', data);
return token;
} catch (error) {
log(getToken, 'get token failed', error);
console.error('get token failed', error);
}
};
@@ -78,34 +80,34 @@ export const getExchangeRate = async (
return;
}
const key = `${payload.source}-${payload.target}`;
if (!state.exchange || !state.exchange[key]) {
try {
const { data } = await exchangeOperator.rate(payload);
commit('setExchange', {
[key]: data.rate
});
return state.exchange![key];
} catch (e) {
log(getExchangeRate, 'get exchange rate failed');
}
console.debug('start to get exchange rate', key);
try {
const { data } = await exchangeOperator.rate(payload);
console.debug('get exchange rate success', data);
commit('setExchange', {
[key]: data.rate
});
return state.exchange![key];
} catch (e) {
console.error('get exchange rate failed');
}
};
export const initializeSite = async ({ state, commit, dispatch }: ActionContext<IRootState, IRootState>) => {
log(initializeSite, 'start to initialize site');
console.debug('start to initialize site');
const origin = getSiteOrigin(state?.site);
try {
const { data } = await siteOperator.initialize({ origin });
commit('setSite', data);
log(initializeSite, 'initialize site success', data);
console.debug('initialize site success', data);
} catch (error) {
log(initializeSite, 'initialize site failed', error);
console.error('initialize site failed', error);
dispatch('login');
}
};
export const getSite = async ({ state, commit }: ActionContext<IRootState, IRootState>) => {
log(getSite, 'start to get site');
console.debug('start to get site');
try {
const origin = getSiteOrigin(state?.site);
const site = (
@@ -114,9 +116,9 @@ export const getSite = async ({ state, commit }: ActionContext<IRootState, IRoot
})
)?.data?.items?.[0];
commit('setSite', site);
log(getSite, 'get site success', site);
console.debug('get site success', site);
} catch (error) {
log(getSite, 'get site failed', error);
console.error('get site failed', error);
}
};
+3 -1
View File
@@ -3,6 +3,7 @@ import chatState from '../chat/state';
import midjourneyState from '../midjourney/state';
import chatdocState from '../chatdoc/state';
import qrartState from '../qrart/state';
import sunoState from '../suno/state';
export default (): IRootState => {
return {
@@ -19,6 +20,7 @@ export default (): IRootState => {
chatdoc: chatdocState(),
chat: chatState(),
midjourney: midjourneyState(),
qrart: qrartState()
qrart: qrartState(),
suno: sunoState()
};
};
+11 -10
View File
@@ -1,7 +1,6 @@
import { applicationOperator, midjourneyOperator, serviceOperator } from '@/operators';
import { IMidjourneyState } from './models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IRootState } from '../common/models';
import {
IApplication,
@@ -19,7 +18,7 @@ export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
console.debug(setCredential, 'set credential', payload);
commit('setCredential', payload);
};
@@ -32,7 +31,7 @@ export const setMode = ({ commit }: any, payload: string) => {
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
console.debug('set service', payload);
commit('setService', payload);
};
@@ -45,8 +44,8 @@ export const getApplication = async ({
state,
rootState
}: ActionContext<IMidjourneyState, IRootState>): Promise<IApplication> => {
log(getApplication, 'start to get application for midjourney');
return new Promise(async (resolve, reject) => {
console.debug('start to get application for midjourney');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
applicationOperator
.getAll({
@@ -54,6 +53,7 @@ export const getApplication = async ({
service_id: MIDJOURNEY_SERVICE_ID
})
.then((response) => {
console.debug('get application success', response?.data);
state.status.getApplication = Status.Success;
commit('setApplication', response.data.items[0]);
const credential = response.data.items?.[0]?.credentials?.find(
@@ -61,6 +61,7 @@ export const getApplication = async ({
);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('save application success', response.data.items[0]);
})
.catch((error) => {
state.status.getApplication = Status.Error;
@@ -74,8 +75,8 @@ export const setTasks = ({ commit }: any, payload: IMidjourneyTask[]) => {
};
export const getService = async ({ commit, state }: ActionContext<IMidjourneyState, IRootState>): Promise<IService> => {
return new Promise(async (resolve, reject) => {
log(getService, 'start to get service for midjourney');
return new Promise((resolve, reject) => {
console.debug('start to get service for midjourney');
state.status.getService = Status.Request;
serviceOperator
.get(MIDJOURNEY_SERVICE_ID)
@@ -95,8 +96,8 @@ export const getTasks = async (
{ commit, state }: ActionContext<IMidjourneyState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
): Promise<IMidjourneyTasksResponse> => {
return new Promise(async (resolve, reject) => {
log(getTasks, 'start to get tasks', offset, limit);
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
const credential = state.credential;
const token = credential?.token;
if (!token) {
@@ -114,7 +115,7 @@ export const getTasks = async (
}
)
.then((response) => {
log(getTasks, 'get tasks success', response.data);
console.debug('get tasks success', response.data);
commit('setTasks', response.data);
resolve(response.data);
})
+13 -10
View File
@@ -1,7 +1,6 @@
import { applicationOperator, qrartOperator, serviceOperator } from '@/operators';
import { IQrartState } from './models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IQrartConfig, IQrartTask, IService } from '@/models';
import { Status } from '@/models/common';
@@ -12,7 +11,7 @@ export const resetAll = ({ commit }: ActionContext<IQrartState, IRootState>): vo
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
console.debug('set credential', payload);
commit('setCredential', payload);
};
@@ -21,7 +20,7 @@ export const setConfig = ({ commit }: any, payload: IQrartConfig) => {
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
console.debug('set service', payload);
commit('setService', payload);
};
@@ -34,8 +33,8 @@ export const getApplication = async ({
state,
rootState
}: ActionContext<IQrartState, IRootState>): Promise<IApplication> => {
log(getApplication, 'start to get application for qrart');
return new Promise(async (resolve, reject) => {
console.debug('start to get application for qrart');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
applicationOperator
.getAll({
@@ -43,15 +42,19 @@ export const getApplication = async ({
service_id: QRART_SERVICE_ID
})
.then((response) => {
console.debug('get application success', response?.data);
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
);
console.debug('get credential success', credential);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('save application success', response.data.items[0]);
})
.catch((error) => {
console.error('get application error', error);
state.status.getApplication = Status.Error;
reject(error);
});
@@ -75,8 +78,8 @@ export const setTasksActive = ({ commit }: any, payload: IQrartTask) => {
};
export const getService = async ({ commit, state }: ActionContext<IQrartState, IRootState>): Promise<IService> => {
return new Promise(async (resolve, reject) => {
log(getService, 'start to get service for qrart');
return new Promise((resolve, reject) => {
console.debug('start to get service for qrart');
state.status.getService = Status.Request;
serviceOperator
.get(QRART_SERVICE_ID)
@@ -96,8 +99,8 @@ export const getTasks = async (
{ commit, state }: ActionContext<IQrartState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
): Promise<IQrartTask[]> => {
return new Promise(async (resolve, reject) => {
log(getTasks, 'start to get tasks', offset, limit);
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
const credential = state.credential;
const token = credential?.token;
if (!token) {
@@ -113,7 +116,7 @@ export const getTasks = async (
}
)
.then((response) => {
log(getTasks, 'get imagine tasks success', response.data.items);
console.debug('get imagine tasks success', response.data.items);
commit('setTasksItems', response.data.items);
commit('setTasksTotal', response.data.count);
resolve(response.data.items);
+10 -11
View File
@@ -1,7 +1,6 @@
import { applicationOperator, sunoOperator, serviceOperator } from '@/operators';
import { ISunoState } from './models';
import { ActionContext } from 'vuex';
import { log } from '@/utils/log';
import { IRootState } from '../common/models';
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService, Song } from '@/models';
import { Status } from '@/models/common';
@@ -12,7 +11,7 @@ export const resetAll = ({ commit }: ActionContext<ISunoState, IRootState>): voi
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
log(setCredential, 'set credential', payload);
console.debug('set credential', payload);
commit('setCredential', payload);
};
@@ -21,7 +20,7 @@ export const setConfig = ({ commit }: any, payload: ISunoConfig) => {
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
log(setService, 'set service', payload);
console.debug('set service', payload);
commit('setService', payload);
};
@@ -34,8 +33,8 @@ export const getApplication = async ({
state,
rootState
}: ActionContext<ISunoState, IRootState>): Promise<IApplication> => {
log(getApplication, 'start to get application for suno');
return new Promise(async (resolve, reject) => {
console.debug('start to get application for suno');
return new Promise((resolve, reject) => {
state.status.getApplication = Status.Request;
applicationOperator
.getAll({
@@ -78,9 +77,9 @@ export const setAudio = ({ commit }: any, payload: any) => {
commit('setAudio', payload);
};
export const getService = async ({ commit, state }: ActionContext<RootState, IRootState>): Promise<IService> => {
return new Promise(async (resolve, reject) => {
log(getService, 'start to get service for suno');
export const getService = async ({ commit, state }: ActionContext<ISunoState, IRootState>): Promise<IService> => {
return new Promise((resolve, reject) => {
console.debug('start to get service for suno');
state.status.getService = Status.Request;
serviceOperator
.get(SUNO_SERVICE_ID)
@@ -100,8 +99,8 @@ export const getTasks = async (
{ commit, state }: ActionContext<ISunoState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
): Promise<ISunoTask[]> => {
return new Promise(async (resolve, reject) => {
log(getTasks, 'start to get tasks', offset, limit);
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
const credential = state.credential;
const token = credential?.token;
if (!token) {
@@ -117,7 +116,7 @@ export const getTasks = async (
}
)
.then((response) => {
log(getTasks, 'get imagine tasks success', response.data.items);
console.debug('get imagine tasks success', response.data.items);
commit('setTasksItems', response.data.items);
commit('setTasksTotal', response.data.count);
resolve(response.data.items);
-1
View File
@@ -1,6 +1,5 @@
export * from './baseUrl';
export * from './mode';
export * from './log';
export * from './initializer';
export * from './highlight';
export * from './is';
+11 -9
View File
@@ -2,7 +2,6 @@ import { getCookie, setCookie } from 'typescript-cookie';
import favicon from '@/assets/images/favicon.ico';
import { getLocale } from '@/i18n';
import store from '@/store';
import { log } from './log';
import { IToken } from '@/models';
import psl from 'psl';
import { LOCALE_CURRENCY_MAPPING } from '@/constants';
@@ -34,7 +33,7 @@ export const initializeCookies = async () => {
// set the cookie to expire in 7 days
const expiration = new Date();
expiration.setDate(expiration.getDate() + 7);
console.log('set INVITER_ID to cookies', inviterId);
console.debug('set INVITER_ID to cookies', inviterId);
setCookie('INVITER_ID', inviterId, {
expires: expiration,
path: '/',
@@ -52,7 +51,7 @@ export const initializeCookies = async () => {
});
} else if (!getCookie('THEME')) {
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
console.log('set THEME to cookies', isDark ? 'dark' : 'light');
console.debug('set THEME to cookies', isDark ? 'dark' : 'light');
setCookie('THEME', isDark ? 'dark' : 'light', {
path: '/',
domain: getDomain()
@@ -68,7 +67,7 @@ export const initializeCookies = async () => {
locale = getLocale();
}
if (locale) {
console.log('set LOCALE to cookies', locale);
console.debug('set LOCALE to cookies', locale);
setCookie('LOCALE', locale, {
path: '/',
domain: getDomain()
@@ -144,7 +143,7 @@ export const initializeSite = async () => {
await store.dispatch('getSite');
// after getSite, the site should have been set
const site = store.state.site;
log(initializeSite, 'site', site);
console.debug('site', site);
// if site is not set, try to initialize site
if (!site?.origin) {
await store.dispatch('initializeSite');
@@ -157,9 +156,11 @@ export const initializeSite = async () => {
export const initializeToken = async () => {
const query = new URLSearchParams(window.location.search);
const code = query.get('code');
console.debug('get code', code);
if (code) {
console.debug('start get token by code', code);
const token = await store.dispatch('getToken', code);
console.debug('get token', token);
console.debug('success get token', token);
}
};
@@ -172,19 +173,20 @@ export const initializeUser = async () => {
console.debug('no access token, skip get user');
return;
}
console.debug('start to get user');
const user = await store.dispatch('getUser');
console.debug('get user', user);
};
export const initializeCurrency = async () => {
const locale = getCookie('LOCALE');
console.log('initialize currency', locale);
console.debug('initialize currency', locale);
const mapping = LOCALE_CURRENCY_MAPPING;
let currency = 'usd';
if (locale && mapping[locale]) {
currency = mapping[locale];
}
console.log('set currency', currency);
console.debug('set currency', currency);
await store.dispatch('setCurrency', currency);
};
@@ -197,6 +199,6 @@ export const initializeExchangeRate = async () => {
const target = mapping[locale];
const source = 'usd';
const payload = { source, target };
console.log('initialize exchange rate', payload);
console.debug('initialize exchange rate', payload);
await store.dispatch('getExchangeRate', payload);
};
-8
View File
@@ -1,8 +0,0 @@
/**
* Log function name and arguments
* @param func
* @param arg
*/
export const log = (func: Function, ...arg: any) => {
console.debug(`${func.name}`, ...arg);
};