diff --git a/docSite/content/zh-cn/docs/development/upgrading/4811.md b/docSite/content/zh-cn/docs/development/upgrading/4811.md index f43a4caa8..600023c2c 100644 --- a/docSite/content/zh-cn/docs/development/upgrading/4811.md +++ b/docSite/content/zh-cn/docs/development/upgrading/4811.md @@ -18,7 +18,8 @@ weight: 813 1. 2. 新增 - 聊天记录滚动加载,不再只加载 30 条。 3. 新增 - 工作流增加触摸板优先模式。 -4. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。 +4. 新增 - 沙盒增加字符串转 base64 全局方法。 +5. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。 5. 优化 - 工作流 handler 性能优化。 6. 优化 - 工作流快捷键,避免调试测试时也会触发。 7. 优化 - 流输出,切换 tab 时仍可以继续输出。 diff --git a/projects/app/src/components/support/compliance/ComplianceTip.tsx b/projects/app/src/components/common/ComplianceTip/index.tsx similarity index 100% rename from projects/app/src/components/support/compliance/ComplianceTip.tsx rename to projects/app/src/components/common/ComplianceTip/index.tsx diff --git a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx index 2fac61248..4f62fd2ce 100644 --- a/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/ChatBox/Input/ChatInput.tsx @@ -1,15 +1,6 @@ import { useSpeech } from '@/web/common/hooks/useSpeech'; import { useSystemStore } from '@/web/common/system/useSystemStore'; -import { - Box, - CircularProgress, - CircularProgressLabel, - Flex, - HStack, - Image, - Spinner, - Textarea -} from '@chakra-ui/react'; +import { Box, CircularProgress, Flex, HStack, Image, Spinner, Textarea } from '@chakra-ui/react'; import React, { useRef, useEffect, useCallback, useMemo } from 'react'; import { useTranslation } from 'next-i18next'; import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; @@ -38,7 +29,7 @@ import { clone } from 'lodash'; import { formatFileSize } from '@fastgpt/global/common/file/tools'; import MyBox from '@fastgpt/web/components/common/MyBox'; import { getErrText } from '@fastgpt/global/common/error/utils'; -import ComplianceTip from '@/components/support/compliance/ComplianceTip'; +import ComplianceTip from '@/components/common/ComplianceTip/index'; const InputGuideBox = dynamic(() => import('./InputGuideBox')); diff --git a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderOutput.tsx b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderOutput.tsx index b2873ad1e..0a575cd45 100644 --- a/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderOutput.tsx +++ b/projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderOutput.tsx @@ -6,7 +6,7 @@ import Markdown from '@/components/Markdown'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import AIResponseBox from '../../../components/AIResponseBox'; import { useTranslation } from 'next-i18next'; -import ComplianceTip from '@/components/support/compliance/ComplianceTip'; +import ComplianceTip from '@/components/common/ComplianceTip/index'; const RenderOutput = () => { const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v); const { t } = useTranslation(); diff --git a/projects/app/src/pages/dataset/list/component/CreateModal.tsx b/projects/app/src/pages/dataset/list/component/CreateModal.tsx index 839f67c2e..0291f9420 100644 --- a/projects/app/src/pages/dataset/list/component/CreateModal.tsx +++ b/projects/app/src/pages/dataset/list/component/CreateModal.tsx @@ -20,7 +20,7 @@ import AIModelSelector from '@/components/Select/AIModelSelector'; import MyIcon from '@fastgpt/web/components/common/Icon'; import { useSystem } from '@fastgpt/web/hooks/useSystem'; import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; -import ComplianceTip from '@/components/support/compliance/ComplianceTip'; +import ComplianceTip from '@/components/common/ComplianceTip/index'; export type CreateDatasetType = | DatasetTypeEnum.dataset diff --git a/projects/sandbox/src/sandbox/jsFn/str2Base64.ts b/projects/sandbox/src/sandbox/jsFn/str2Base64.ts new file mode 100644 index 000000000..e6753db46 --- /dev/null +++ b/projects/sandbox/src/sandbox/jsFn/str2Base64.ts @@ -0,0 +1,5 @@ +export const strToBase64 = (str: string, prefix: string) => { + const base64_string = Buffer.from(str, 'utf-8').toString('base64'); + + return `${prefix}${base64_string}`; +}; diff --git a/projects/sandbox/src/sandbox/utils.ts b/projects/sandbox/src/sandbox/utils.ts index 9f067ea08..cc7b38708 100644 --- a/projects/sandbox/src/sandbox/utils.ts +++ b/projects/sandbox/src/sandbox/utils.ts @@ -2,13 +2,18 @@ import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto' import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm'; import { countToken } from './jsFn/tiktoken'; import { timeDelay } from './jsFn/delay'; +import { strToBase64 } from './jsFn/str2Base64'; const CustomLogStr = 'CUSTOM_LOG'; /* - Rewrite code to add custom functions: Promise function; Log. - */ + Rewrite code to add custom functions: Promise function; Log. +*/ function getFnCode(code: string) { + // rewrite log + code = code.replace(/console\.log/g, `${CustomLogStr}`); + + // Promise function rewrite const rewriteSystemFn = ` const thisDelay = (...args) => global_delay.applySyncPromise(undefined,args) `; @@ -16,9 +21,6 @@ function getFnCode(code: string) { // rewrite delay code = code.replace(/delay\((.*)\)/g, `thisDelay($1)`); - // rewrite log - code = code.replace(/console\.log/g, `${CustomLogStr}`); - const runCode = ` (async() => { try { @@ -35,11 +37,12 @@ function getFnCode(code: string) { return runCode; } +// Register global function function registerSystemFn(jail: IsolatedVM.Reference>) { return Promise.all([ - // delay jail.set('global_delay', new Reference(timeDelay)), - jail.set('countToken', countToken) + jail.set('countToken', countToken), + jail.set('strToBase64', strToBase64) ]); }