update add mark

This commit is contained in:
2025-05-26 02:57:33 +08:00
parent e38b8df9f0
commit 22cb48b9f3
17 changed files with 351 additions and 164 deletions

View File

@@ -12,6 +12,27 @@ export type PostChat = {
user?: string;
};
export type ChatDataOpts = {
id?: string;
title?: string;
messages?: any[];
data?: any;
type?: 'temp' | 'keep' | string;
};
export type ChatOpts = {
username: string;
model: string;
/**
* 获取完整消息回复
*/
getFull?: boolean;
group: string;
/**
* openai的参数
*/
options?: any;
};
export const appDefine = QueryUtil.create({
chat: {
path: 'ai',

View File

@@ -1,5 +1,5 @@
import { appDefine } from './defines/ai.ts';
import { PostChat } from './defines/ai.ts';
import { PostChat, ChatOpts, ChatDataOpts } from './defines/ai.ts';
import { BaseQuery, DataOpts, Query } from '@kevisual/query/query';
@@ -22,4 +22,80 @@ export class QueryApp<T extends Query = Query> extends BaseQuery<T, typeof appDe
postChat(data: PostChat, opts?: DataOpts) {
return this.chain('chat').post(data, opts);
}
/**
* 获取模型列表
* @param opts
* @returns
*/
getModelList(data?: { usernames?: string[] }, opts?: DataOpts) {
return this.query.post(
{
path: 'ai',
key: 'get-model-list',
data,
},
opts,
);
}
/**
* 聊天对话模型
* @param data
* @param chatOpts
* @param opts
* @returns
*/
chat(data: ChatDataOpts, chatOpts: ChatOpts, opts?: DataOpts) {
const { username, model, group, getFull = true } = chatOpts;
if (!username || !model || !group) {
throw new Error('username, model, group is required');
}
return this.query.post(
{
path: 'ai',
key: 'chat',
...chatOpts,
getFull,
data,
},
opts,
);
}
clearConfigCache(opts?: DataOpts) {
return this.query.post(
{
path: 'ai',
key: 'clear-cache',
},
opts,
);
}
/**
* 获取聊天使用情况
* @param opts
* @returns
*/
getChatUsage(opts?: DataOpts) {
return this.query.post(
{
path: 'ai',
key: 'get-chat-usage',
},
opts,
);
}
/**
* 清除当前用户模型自己的统计
* @param opts
* @returns
*/
clearSelfUsage(opts?: DataOpts) {
return this.query.post(
{
path: 'ai',
key: 'clear-chat-limit',
},
opts,
);
}
}

View File

@@ -35,7 +35,7 @@ export class QueryLogin extends BaseQuery {
super({
query: opts?.query || new Query(),
});
this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts.cache });
this.cacheStore = new LoginCacheStore({ name: 'login', cache: opts?.cache! });
this.isBrowser = opts?.isBrowser ?? true;
this.init();
this.onLoad = opts?.onLoad;
@@ -271,7 +271,7 @@ export class QueryLogin extends BaseQuery {
config.headers['Authorization'] = `Bearer ${_token}`;
}
if (!_token) {
// TODO: 取消请求,因为没有登陆
return false;
}
return config;
},
@@ -303,6 +303,21 @@ export class QueryLogin extends BaseQuery {
const token = this.storage.getItem('token');
return !!token;
}
/**
* 检查本地用户列表
* @returns
*/
async getToken() {
const token = this.storage.getItem('token');
return token || '';
}
async beforeRequest(opts: any = {}) {
const token = this.storage.getItem('token');
if (token) {
opts.headers = { ...opts.headers, Authorization: `Bearer ${token}` };
}
return opts;
}
/**
* 请求更新,切换用户, 使用switchUser
* @param username
@@ -318,7 +333,7 @@ export class QueryLogin extends BaseQuery {
*/
async switchUser(username: string) {
const localUserList = await this.cacheStore.getCurrentUserList();
const user = localUserList.find((userItem) => userItem.user.username === username);
const user = localUserList.find((userItem) => userItem.user!.username === username);
if (user) {
this.storage.setItem('token', user.accessToken || '');
await this.beforeSetLoginUser({ accessToken: user.accessToken, refreshToken: user.refreshToken });

View File

@@ -143,7 +143,7 @@ export class QueryMark extends QueryMarkBase<SimpleObject> {
this.markType = opts?.markType || 'simple';
}
async getMarkList(search?: SearchOpts, opts?: DataOpts) {
return this.post({ key: 'list', ...search, markType: this.markType }, opts);
return this.post<Result<ResultMarkList>>({ key: 'list', ...search, markType: this.markType }, opts);
}
async updateMark(data: any, opts?: DataOpts) {
if (!data.id) {