V4.14.1 feature (#5880)

* feat: app split (#5858)

* feat: app split script

* fix: app split

* chore: app split script try-catch

* adjust dashborad page (#5872)

* create page

* create page

* create button

* router name

* bot

* template

* create page

* mobile

* toolfolder

* fix

* fix

* fix build

* split tool select

* img

* doc

* rename enum

* fix page adjust (#5883)

* fix page adjust

* fix ad store

* fix: initv4141 (#5886)

* fix: create app

* doc

* hide api

* doc

* feat: payment pause interactive (#5892)

* fix: copy clbs (#5889)

* fix: copy clbs

* fix: copy clbs

* fix: http protocol handling in baseURL (#5890)

* fix: http protocol handling in baseURL

* ui fix

* auto saved version

* fix

* auto save

* fix: model permission modal (#5895)

* folder

* fix: del app

* navbar

* fix: plugin file selector (#5893)

* fix: plugin file selector

* fix: plugin file selector

* workflow tool inputform

* pick

---------

Co-authored-by: archer <545436317@qq.com>

* fix: workflow tool time

* doc

* fix workorder button (#5896)

* add inform track (#5897)

* remove invalid track

* comment

* feat: marketplace refresh api (#5884)

* marketplace refresh

* fix: helper bot menu button (#5898)

---------

Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com>
Co-authored-by: heheer <heheer@sealos.io>
Co-authored-by: 伍闲犬 <whoeverimf5@gmail.com>
This commit is contained in:
Archer
2025-11-11 14:05:02 +08:00
committed by GitHub
parent 74e16204e3
commit d571c768ea
188 changed files with 8246 additions and 2560 deletions
@@ -8,6 +8,10 @@ import { addHours } from 'date-fns';
import { imageFileType } from '@fastgpt/global/common/file/constants';
import { retryFn } from '@fastgpt/global/common/system/utils';
import { UserError } from '@fastgpt/global/common/error/utils';
import { S3Sources } from '../../s3/type';
import { getS3AvatarSource } from '../../s3/sources/avatar';
import path from 'path';
import { getNanoid } from '@fastgpt/global/common/string/tools';
export const maxImgSize = 1024 * 1024 * 12;
const base64MimeRegex = /data:image\/([^\)]+);base64/;
@@ -56,60 +60,67 @@ export async function uploadMongoImg({
return `${process.env.NEXT_PUBLIC_BASE_URL || ''}${imageBaseUrl}${String(_id)}.${extension}`;
}
export const copyImage = async ({
export const copyAvatarImage = async ({
teamId,
imageUrl,
ttl,
session
}: {
teamId: string;
imageUrl: string;
ttl: boolean;
session?: ClientSession;
}) => {
const imageId = getIdFromPath(imageUrl);
if (!imageId) return imageUrl;
if (!imageUrl) return;
const image = await MongoImage.findOne(
{
_id: imageId,
teamId
},
undefined,
{
session
}
);
if (!image) return imageUrl;
// S3
if (imageUrl.startsWith(`${imageBaseUrl}/${S3Sources.avatar}`)) {
const extendName = path.extname(imageUrl);
const key = await getS3AvatarSource().copyAvatar({
sourceKey: imageUrl.slice(imageBaseUrl.length),
targetKey: `${S3Sources.avatar}/${teamId}/${getNanoid(6)}${extendName}`,
ttl
});
return key;
}
const [newImage] = await MongoImage.create(
[
{
teamId,
binary: image.binary,
metadata: image.metadata
}
],
{
session,
ordered: true
}
);
return `${process.env.NEXT_PUBLIC_BASE_URL || ''}${imageBaseUrl}${String(newImage._id)}.${image.metadata?.mime?.split('/')[1]}`;
};
const getIdFromPath = (path?: string) => {
if (!path) return;
const paths = path.split('/');
const paths = imageUrl.split('/');
const name = paths[paths.length - 1];
if (!name) return;
const id = name.split('.')[0];
if (!id || !Types.ObjectId.isValid(id)) return;
return id;
// Mongo
if (id && Types.ObjectId.isValid(id)) {
const image = await MongoImage.findOne(
{
_id: id,
teamId
},
undefined,
{
session
}
);
if (!image) return imageUrl;
const [newImage] = await MongoImage.create(
[
{
teamId,
binary: image.binary,
metadata: image.metadata
}
],
{
session,
ordered: true
}
);
return `${process.env.NEXT_PUBLIC_BASE_URL || ''}${imageBaseUrl}${String(newImage._id)}.${image.metadata?.mime?.split('/')[1]}`;
}
return imageUrl;
};
export const removeImageByPath = (path?: string, session?: ClientSession) => {
if (!path) return;
+18 -1
View File
@@ -79,7 +79,24 @@ export class S3BaseBucket {
return this.delete(src);
}
copy(src: string, dst: string, options?: CopyConditions): ReturnType<Client['copyObject']> {
async copy({
src,
dst,
ttl,
options
}: {
src: string;
dst: string;
ttl: boolean;
options?: CopyConditions;
}): ReturnType<Client['copyObject']> {
if (ttl) {
await MongoS3TTL.create({
minioKey: dst,
bucketName: this.name,
expiredTime: addHours(new Date(), 24)
});
}
return this.client.copyObject(this.name, src, dst, options);
}
@@ -66,6 +66,23 @@ class S3AvatarSource {
await this.deleteAvatar(oldAvatar, session);
}
}
async copyAvatar({
sourceKey,
targetKey,
ttl
}: {
sourceKey: string;
targetKey: string;
ttl: boolean;
}) {
await this.bucket.copy({
src: sourceKey,
dst: targetKey,
ttl
});
return targetKey;
}
}
export function getS3AvatarSource() {
@@ -22,6 +22,10 @@ class S3ChatSource {
return (this.instance ??= new S3ChatSource());
}
static isChatFileKey(key?: string): key is `${typeof S3Sources.chat}/${string}` {
return key?.startsWith(`${S3Sources.chat}/`) ?? false;
}
async createGetChatFileURL(params: { key: string; expiredHours?: number; external: boolean }) {
const { key, expiredHours = 1, external = false } = params; // 默认一个小时
+5 -4
View File
@@ -4,7 +4,7 @@ import {
FlowNodeInputTypeEnum,
FlowNodeTypeEnum
} from '@fastgpt/global/core/workflow/node/constant';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { AppFolderTypeList } from '@fastgpt/global/core/app/constants';
import { MongoApp } from './schema';
import type { StoreNodeItemType } from '@fastgpt/global/core/workflow/type/node';
import { encryptSecretValue, storeSecretValue } from '../../common/secret/utils';
@@ -153,7 +153,7 @@ export const onDelOneApp = async ({
});
const deletedAppIds = apps
.filter((app) => app.type !== AppTypeEnum.folder)
.filter((app) => !AppFolderTypeList.includes(app.type))
.map((app) => String(app._id));
// Remove eval job
@@ -217,6 +217,7 @@ export const onDelOneApp = async ({
{ session }
);
// Delete avatar
await removeImageByPath(app.avatar, session);
};
@@ -239,10 +240,10 @@ export const onDelOneApp = async ({
for await (const app of apps) {
if (session) {
await del(app, session);
return deletedAppIds;
}
await mongoSessionRun((session) => del(app, session));
return deletedAppIds;
}
return deletedAppIds;
};
+4 -1
View File
@@ -148,7 +148,10 @@ export const runHTTPTool = async ({
const { data } = await axios({
method: method.toUpperCase(),
baseURL: baseUrl.startsWith('https://') ? baseUrl : `https://${baseUrl}`,
baseURL:
baseUrl.startsWith('http://') || baseUrl.startsWith('https://')
? baseUrl
: `https://${baseUrl}`,
url: toolPath,
headers,
data: body,
+1 -1
View File
@@ -238,7 +238,7 @@ export async function getChildAppPreviewNode({
})
: true;
if (item.type === AppTypeEnum.toolSet) {
if (item.type === AppTypeEnum.mcpToolSet) {
const children = await getMCPChildren(item);
version.nodes[0].toolConfig = {
mcpToolSet: {
@@ -71,6 +71,19 @@ export const serverGetWorkflowToolRunUserQuery = ({
if (input.renderTypeList.includes(FlowNodeInputTypeEnum.password)) {
value = encryptSecretValue(value);
} else if (
input.renderTypeList.includes(FlowNodeInputTypeEnum.fileSelect) &&
Array.isArray(value)
) {
value = value.map((item) => {
return {
id: item.id,
key: item.key,
name: item.name,
type: item.type,
url: item.key ? undefined : item.url
};
});
}
return {
+2 -1
View File
@@ -34,6 +34,7 @@ const AppVersionSchema = new Schema(
type: chatConfigType
},
isPublish: Boolean,
isAutoSave: Boolean,
versionName: String
},
{
@@ -41,7 +42,7 @@ const AppVersionSchema = new Schema(
}
);
AppVersionSchema.index({ appId: 1, _id: -1 });
AppVersionSchema.index({ appId: 1, time: -1 });
export const MongoAppVersion = getMongoModel<AppVersionSchemaType>(
AppVersionCollectionName,
+2
View File
@@ -389,6 +389,8 @@ export const updateInteractiveChat = async (props: Props) => {
: item;
});
finalInteractive.params.submitted = true;
} else if (finalInteractive.type === 'paymentPause') {
chatItem.value.pop();
}
if (aiResponse.customFeedbacks) {
+50 -5
View File
@@ -1,11 +1,14 @@
import { ChatItemValueTypeEnum } from '@fastgpt/global/core/chat/constants';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
import { getS3ChatSource } from '../../common/s3/sources/chat';
import type { FlowNodeInputItemType } from '@fastgpt/global/core/workflow/type/io';
import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
export const addPreviewUrlToChatItems = async (histories: ChatItemType[]) => {
// Presign file urls
const s3ChatSource = getS3ChatSource();
for await (const item of histories) {
export const addPreviewUrlToChatItems = async (
histories: ChatItemType[],
type: 'chatFlow' | 'workflowTool'
) => {
async function addToChatflow(item: ChatItemType) {
for await (const value of item.value) {
if (value.type === ChatItemValueTypeEnum.file && value.file && value.file.key) {
value.file.url = await s3ChatSource.createGetChatFileURL({
@@ -15,4 +18,46 @@ export const addPreviewUrlToChatItems = async (histories: ChatItemType[]) => {
}
}
}
async function addToWorkflowTool(item: ChatItemType) {
if (item.obj !== ChatRoleEnum.Human || !Array.isArray(item.value)) return;
for (let j = 0; j < item.value.length; j++) {
const value = item.value[j];
if (value.type !== ChatItemValueTypeEnum.text) continue;
const inputValueString = value.text?.content || '';
const parsedInputValue = JSON.parse(inputValueString) as FlowNodeInputItemType[];
for (const input of parsedInputValue) {
if (
input.renderTypeList[0] !== FlowNodeInputTypeEnum.fileSelect ||
!Array.isArray(input.value)
)
continue;
for (const file of input.value) {
if (!file.key) continue;
const url = await getS3ChatSource().createGetChatFileURL({
key: file.key,
external: true
});
file.url = url;
}
}
item.value[j].text = {
...value.text,
content: JSON.stringify(parsedInputValue)
};
}
}
// Presign file urls
const s3ChatSource = getS3ChatSource();
for await (const item of histories) {
if (type === 'chatFlow') {
await addToChatflow(item);
} else if (type === 'workflowTool') {
await addToWorkflowTool(item);
}
}
};
@@ -55,6 +55,8 @@ import type { RequireOnlyOne } from '@fastgpt/global/common/type/utils';
import { getS3ChatSource } from '../../../common/s3/sources/chat';
import { addPreviewUrlToChatItems } from '../../chat/utils';
import type { MCPClient } from '../../app/mcp';
import { TeamErrEnum } from '@fastgpt/global/common/error/code/team';
import { i18nT } from '../../../../web/i18n/utils';
type Props = Omit<ChatDispatchProps, 'workflowDispatchDeep' | 'timezone' | 'externalProvider'> & {
runtimeNodes: RuntimeNodeItemType[];
@@ -132,7 +134,7 @@ export async function dispatchWorkFlow({
}
// Add preview url to chat items
await addPreviewUrlToChatItems(histories);
await addPreviewUrlToChatItems(histories, 'chatFlow');
for (const item of query) {
if (item.type !== ChatItemValueTypeEnum.file || !item.file?.key) continue;
item.file.url = await getS3ChatSource().createGetChatFileURL({
@@ -620,6 +622,23 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
}
};
}
private async checkTeamBlance(): Promise<NodeResponseCompleteType | undefined> {
try {
await checkTeamAIPoints(data.runningUserInfo.teamId);
} catch (error) {
// Next time you enter the system, you will still start from the current node(Current check team blance node).
if (error === TeamErrEnum.aiPointsNotEnough) {
return {
[DispatchNodeResponseKeyEnum.interactive]: {
type: 'paymentPause',
params: {
description: i18nT('chat:balance_not_enough_pause')
}
}
};
}
}
}
/* Check node run/skip or wait */
private async checkNodeCanRun(
node: RuntimeNodeItemType,
@@ -652,6 +671,7 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
this.chatResponses.push(responseData);
}
// Push usage in real time. Avoid a workflow usage a large number of points
if (nodeDispatchUsages) {
if (usageId) {
pushChatItemUsage({
@@ -763,6 +783,7 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
};
};
// Check queue status
if (data.maxRunTimes <= 0) {
addLog.error('Max run times is 0', {
appId: data.runningAppInfo.id
@@ -790,8 +811,17 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
runtimeEdges
});
const nodeRunResult = await (() => {
const nodeRunResult = await (async () => {
if (status === 'run') {
const blanceCheckResult = await this.checkTeamBlance();
if (blanceCheckResult) {
return {
node,
runStatus: 'pause' as const,
result: blanceCheckResult
};
}
// All source edges status to waiting
runtimeEdges.forEach((item) => {
if (item.target === node.nodeId) {
@@ -870,10 +900,21 @@ export const runWorkflow = async (data: RunWorkflowProps): Promise<DispatchFlowR
this.debugNextStepRunNodes = this.debugNextStepRunNodes.concat([nodeRunResult.node]);
}
this.nodeInteractiveResponse = {
entryNodeIds: [nodeRunResult.node.nodeId],
interactiveResponse
};
// For the pause interactive response, there may be multiple nodes triggered at the same time, so multiple entry nodes need to be recorded.
// For other interactive nodes, only one will be triggered at the same time.
if (interactiveResponse.type === 'paymentPause') {
this.nodeInteractiveResponse = {
entryNodeIds: this.nodeInteractiveResponse?.entryNodeIds
? this.nodeInteractiveResponse.entryNodeIds.concat(nodeRunResult.node.nodeId)
: [nodeRunResult.node.nodeId],
interactiveResponse
};
} else {
this.nodeInteractiveResponse = {
entryNodeIds: [nodeRunResult.node.nodeId],
interactiveResponse
};
}
return;
} else if (isDebugMode) {
// Debug 模式下一步时候,会自己增加 activeNode
@@ -6,6 +6,7 @@ import type {
DispatchNodeResultType,
ModuleDispatchProps
} from '@fastgpt/global/core/workflow/runtime/type';
import { getS3ChatSource } from '../../../../common/s3/sources/chat';
export type PluginInputProps = ModuleDispatchProps<{
[key: string]: any;
@@ -21,12 +22,12 @@ export const dispatchPluginInput = async (
const { params, query } = props;
const { files } = chatValue2RuntimePrompt(query);
/*
/*
对 params 中文件类型数据进行处理
* 插件单独运行时,这里会是一个特殊的数组
* 插件调用的话,这个参数是一个 string[] 不会进行处理
* 硬性要求:API 单独调用插件时,要避免这种特殊类型冲突
TODO: 需要 filter max files
*/
for (const key in params) {
@@ -37,6 +38,17 @@ export const dispatchPluginInput = async (
(item) => item.type === ChatFileTypeEnum.file || item.type === ChatFileTypeEnum.image
)
) {
// 为文件对象重新签发 URL(如果有 key 但没有 url
for (let i = 0; i < val.length; i++) {
const fileItem = val[i];
if (fileItem.key && !fileItem.url) {
val[i].url = await getS3ChatSource().createGetChatFileURL({
key: fileItem.key,
external: true,
expiredHours: 1
});
}
}
params[key] = val.map((item) => item.url);
}
}
@@ -49,8 +49,8 @@ export const checkTeamAppLimit = async (teamId: string, amount = 1) => {
$in: [
AppTypeEnum.simple,
AppTypeEnum.workflow,
AppTypeEnum.plugin,
AppTypeEnum.toolSet,
AppTypeEnum.workflowTool,
AppTypeEnum.mcpToolSet,
AppTypeEnum.httpToolSet
]
}
@@ -65,7 +65,12 @@ export const checkTeamAppLimit = async (teamId: string, amount = 1) => {
if (global?.licenseData?.maxApps && typeof global?.licenseData?.maxApps === 'number') {
const totalApps = await MongoApp.countDocuments({
type: {
$in: [AppTypeEnum.simple, AppTypeEnum.workflow, AppTypeEnum.plugin, AppTypeEnum.toolSet]
$in: [
AppTypeEnum.simple,
AppTypeEnum.workflow,
AppTypeEnum.workflowTool,
AppTypeEnum.mcpToolSet
]
}
});
if (totalApps >= global.licenseData.maxApps) {
+5 -5
View File
@@ -12,13 +12,13 @@ import { retryFn } from '@fastgpt/global/common/system/utils';
export function getI18nAppType(type: AppTypeEnum): string {
if (type === AppTypeEnum.folder) return i18nT('account_team:type.Folder');
if (type === AppTypeEnum.simple) return i18nT('account_team:type.Simple bot');
if (type === AppTypeEnum.simple) return i18nT('app:type.Chat_Agent');
if (type === AppTypeEnum.workflow) return i18nT('account_team:type.Workflow bot');
if (type === AppTypeEnum.plugin) return i18nT('account_team:type.Plugin');
if (type === AppTypeEnum.workflowTool) return i18nT('app:toolType_workflow');
if (type === AppTypeEnum.httpPlugin) return i18nT('account_team:type.Http plugin');
if (type === AppTypeEnum.httpToolSet) return i18nT('account_team:type.Http tool set');
if (type === AppTypeEnum.toolSet) return i18nT('account_team:type.Tool set');
if (type === AppTypeEnum.tool) return i18nT('account_team:type.Tool');
if (type === AppTypeEnum.httpToolSet) return i18nT('app:toolType_http');
if (type === AppTypeEnum.mcpToolSet) return i18nT('app:toolType_mcp');
if (type === AppTypeEnum.tool) return i18nT('app:toolType_mcp');
return i18nT('common:UnKnow');
}