V4.8.17 feature (#3485)
* feat: add third party account config (#3443) * temp * editor workflow variable style * add team to dispatch * i18n * delete console * change openai account position * fix * fix * fix * fix * fix * 4.8.17 test (#3461) * perf: external provider config * perf: ui * feat: add template config (#3434) * change template position * template config * delete console * delete * fix * fix * perf: Mongo visutal field (#3464) * remve invalid code * perf: team member visutal code * perf: virtual search; perf: search test data * fix: ts * fix: image response headers * perf: template code * perf: auth layout;perf: auto save (#3472) * perf: auth layout * perf: auto save * perf: auto save * fix: template guide display & http input support external variables (#3475) * fix: template guide display * http editor support external workflow variables * perf: auto save;fix: ifelse checker line break; (#3478) * perf: auto save * perf: auto save * fix: ifelse checker line break * perf: doc * perf: doc * fix: update var type error * 4.8.17 test (#3479) * perf: auto save * perf: auto save * perf: template code * 4.8.17 test (#3480) * perf: auto save * perf: auto save * perf: model price model * feat: add react memo * perf: model provider filter * fix: ts (#3481) * perf: auto save * perf: auto save * fix: ts * simple app tool select (#3473) * workflow plugin userguide & simple tool ui * simple tool filter * reuse component * change component to hook * fix * perf: too selector modal (#3484) * perf: auto save * perf: auto save * perf: markdown render * perf: too selector * fix: app version require tmbId * perf: templates refresh * perf: templates refresh * hide auto save error tip * perf: toolkit guide --------- Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
@@ -2,14 +2,39 @@ import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { getUserDetail } from '@fastgpt/service/support/user/controller';
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { UserType } from '@fastgpt/global/support/user/type';
|
||||
|
||||
export type TokenLoginQuery = {};
|
||||
export type TokenLoginBody = {};
|
||||
export type TokenLoginResponse = {};
|
||||
export type TokenLoginResponse = UserType;
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<TokenLoginBody, TokenLoginQuery>,
|
||||
_res: ApiResponseType<any>
|
||||
): Promise<TokenLoginResponse> {
|
||||
const { tmbId } = await authCert({ req, authToken: true });
|
||||
return getUserDetail({ tmbId });
|
||||
const user = await getUserDetail({ tmbId });
|
||||
|
||||
// Remove sensitive information
|
||||
if (user.team.lafAccount) {
|
||||
user.team.lafAccount = {
|
||||
appid: user.team.lafAccount.appid,
|
||||
token: '',
|
||||
pat: ''
|
||||
};
|
||||
}
|
||||
if (user.team.openaiAccount) {
|
||||
user.team.openaiAccount = {
|
||||
key: '',
|
||||
baseUrl: user.team.openaiAccount.baseUrl
|
||||
};
|
||||
}
|
||||
if (user.team.externalWorkflowVariables) {
|
||||
user.team.externalWorkflowVariables = Object.fromEntries(
|
||||
Object.entries(user.team.externalWorkflowVariables).map(([key, value]) => [key, ''])
|
||||
);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
export default NextAPI(handler);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { MongoUser } from '@fastgpt/service/support/user/schema';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { UserUpdateParams } from '@/types/user';
|
||||
import { getAIApi, openaiBaseUrl } from '@fastgpt/service/core/ai/config';
|
||||
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
|
||||
|
||||
/* update user info */
|
||||
@@ -14,7 +13,7 @@ async function handler(
|
||||
req: ApiRequestProps<UserAccountUpdateBody, UserAccountUpdateQuery>,
|
||||
_res: ApiResponseType<any>
|
||||
): Promise<UserAccountUpdateResponse> {
|
||||
const { avatar, timezone, openaiAccount, lafAccount } = req.body;
|
||||
const { avatar, timezone } = req.body;
|
||||
|
||||
const { tmbId } = await authCert({ req, authToken: true });
|
||||
const tmb = await MongoTeamMember.findById(tmbId);
|
||||
@@ -22,25 +21,6 @@ async function handler(
|
||||
throw new Error('can not find it');
|
||||
}
|
||||
const userId = tmb.userId;
|
||||
// auth key
|
||||
if (openaiAccount?.key) {
|
||||
console.log('auth user openai key', openaiAccount?.key);
|
||||
const baseUrl = openaiAccount?.baseUrl || openaiBaseUrl;
|
||||
openaiAccount.baseUrl = baseUrl;
|
||||
|
||||
const ai = getAIApi({
|
||||
userKey: openaiAccount
|
||||
});
|
||||
|
||||
const response = await ai.chat.completions.create({
|
||||
model: 'gpt-4o-mini',
|
||||
max_tokens: 1,
|
||||
messages: [{ role: 'user', content: 'hi' }]
|
||||
});
|
||||
if (response?.choices?.[0]?.message?.content === undefined) {
|
||||
throw new Error('Key response is empty');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新对应的记录
|
||||
await MongoUser.updateOne(
|
||||
@@ -49,9 +29,7 @@ async function handler(
|
||||
},
|
||||
{
|
||||
...(avatar && { avatar }),
|
||||
...(timezone && { timezone }),
|
||||
openaiAccount: openaiAccount?.key ? openaiAccount : null,
|
||||
lafAccount: lafAccount?.token ? lafAccount : null
|
||||
...(timezone && { timezone })
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { authUserPer } from '@fastgpt/service/support/permission/user/auth';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import axios from 'axios';
|
||||
import { addLog } from '@fastgpt/service/common/system/log';
|
||||
|
||||
export type checkUsageQuery = { key: string };
|
||||
|
||||
export type checkUsageBody = {};
|
||||
|
||||
export type checkUsageResponse =
|
||||
| {
|
||||
total: number;
|
||||
used: number;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<checkUsageBody, checkUsageQuery>,
|
||||
res: ApiResponseType<any>
|
||||
): Promise<checkUsageResponse> {
|
||||
try {
|
||||
const { key } = req.query;
|
||||
|
||||
const { tmb } = await authUserPer({ req, authToken: true, per: ReadPermissionVal });
|
||||
|
||||
const url = global.feConfigs.externalProviderWorkflowVariables?.find(
|
||||
(item) => item.key === key
|
||||
)?.url;
|
||||
if (!url || !tmb.externalWorkflowVariables?.[key]) return undefined;
|
||||
|
||||
const { data } = await axios.get<checkUsageResponse>(url, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${tmb.externalWorkflowVariables[key]}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!data) return undefined;
|
||||
|
||||
return {
|
||||
total: data.total || 0,
|
||||
used: data.used || 0
|
||||
};
|
||||
} catch (error) {
|
||||
addLog.debug('checkUsage error', { error });
|
||||
}
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
Reference in New Issue
Block a user