feat: sandbox support str to base64 function;feat: compiance text ui (#2702)

* feat: sandbox strToBase64 function

* feat: compiance text ui
This commit is contained in:
Archer
2024-09-13 17:54:22 +08:00
committed by GitHub
parent 9de8849193
commit 092bb9ab17
7 changed files with 21 additions and 21 deletions

View File

@@ -18,7 +18,8 @@ weight: 813
1. 1.
2. 新增 - 聊天记录滚动加载,不再只加载 30 条。 2. 新增 - 聊天记录滚动加载,不再只加载 30 条。
3. 新增 - 工作流增加触摸板优先模式。 3. 新增 - 工作流增加触摸板优先模式。
4. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环 4. 新增 - 沙盒增加字符串转 base64 全局方法
5. 优化 - 工作流嵌套层级限制 20 层,避免因编排不合理导致的无限死循环。
5. 优化 - 工作流 handler 性能优化。 5. 优化 - 工作流 handler 性能优化。
6. 优化 - 工作流快捷键,避免调试测试时也会触发。 6. 优化 - 工作流快捷键,避免调试测试时也会触发。
7. 优化 - 流输出,切换 tab 时仍可以继续输出。 7. 优化 - 流输出,切换 tab 时仍可以继续输出。

View File

@@ -1,15 +1,6 @@
import { useSpeech } from '@/web/common/hooks/useSpeech'; import { useSpeech } from '@/web/common/hooks/useSpeech';
import { useSystemStore } from '@/web/common/system/useSystemStore'; import { useSystemStore } from '@/web/common/system/useSystemStore';
import { import { Box, CircularProgress, Flex, HStack, Image, Spinner, Textarea } from '@chakra-ui/react';
Box,
CircularProgress,
CircularProgressLabel,
Flex,
HStack,
Image,
Spinner,
Textarea
} from '@chakra-ui/react';
import React, { useRef, useEffect, useCallback, useMemo } from 'react'; import React, { useRef, useEffect, useCallback, useMemo } from 'react';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip'; 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 { formatFileSize } from '@fastgpt/global/common/file/tools';
import MyBox from '@fastgpt/web/components/common/MyBox'; import MyBox from '@fastgpt/web/components/common/MyBox';
import { getErrText } from '@fastgpt/global/common/error/utils'; 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')); const InputGuideBox = dynamic(() => import('./InputGuideBox'));

View File

@@ -6,7 +6,7 @@ import Markdown from '@/components/Markdown';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant'; import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import AIResponseBox from '../../../components/AIResponseBox'; import AIResponseBox from '../../../components/AIResponseBox';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import ComplianceTip from '@/components/support/compliance/ComplianceTip'; import ComplianceTip from '@/components/common/ComplianceTip/index';
const RenderOutput = () => { const RenderOutput = () => {
const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v); const { histories, isChatting } = useContextSelector(PluginRunContext, (v) => v);
const { t } = useTranslation(); const { t } = useTranslation();

View File

@@ -20,7 +20,7 @@ import AIModelSelector from '@/components/Select/AIModelSelector';
import MyIcon from '@fastgpt/web/components/common/Icon'; import MyIcon from '@fastgpt/web/components/common/Icon';
import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { useSystem } from '@fastgpt/web/hooks/useSystem';
import QuestionTip from '@fastgpt/web/components/common/MyTooltip/QuestionTip'; 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 = export type CreateDatasetType =
| DatasetTypeEnum.dataset | DatasetTypeEnum.dataset

View File

@@ -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}`;
};

View File

@@ -2,13 +2,18 @@ import { RunCodeDto, RunCodeResponse } from 'src/sandbox/dto/create-sandbox.dto'
import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm'; import IsolatedVM, { ExternalCopy, Isolate, Reference } from 'isolated-vm';
import { countToken } from './jsFn/tiktoken'; import { countToken } from './jsFn/tiktoken';
import { timeDelay } from './jsFn/delay'; import { timeDelay } from './jsFn/delay';
import { strToBase64 } from './jsFn/str2Base64';
const CustomLogStr = 'CUSTOM_LOG'; 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) { function getFnCode(code: string) {
// rewrite log
code = code.replace(/console\.log/g, `${CustomLogStr}`);
// Promise function rewrite
const rewriteSystemFn = ` const rewriteSystemFn = `
const thisDelay = (...args) => global_delay.applySyncPromise(undefined,args) const thisDelay = (...args) => global_delay.applySyncPromise(undefined,args)
`; `;
@@ -16,9 +21,6 @@ function getFnCode(code: string) {
// rewrite delay // rewrite delay
code = code.replace(/delay\((.*)\)/g, `thisDelay($1)`); code = code.replace(/delay\((.*)\)/g, `thisDelay($1)`);
// rewrite log
code = code.replace(/console\.log/g, `${CustomLogStr}`);
const runCode = ` const runCode = `
(async() => { (async() => {
try { try {
@@ -35,11 +37,12 @@ function getFnCode(code: string) {
return runCode; return runCode;
} }
// Register global function
function registerSystemFn(jail: IsolatedVM.Reference<Record<string | number | symbol, any>>) { function registerSystemFn(jail: IsolatedVM.Reference<Record<string | number | symbol, any>>) {
return Promise.all([ return Promise.all([
// delay
jail.set('global_delay', new Reference(timeDelay)), jail.set('global_delay', new Reference(timeDelay)),
jail.set('countToken', countToken) jail.set('countToken', countToken),
jail.set('strToBase64', strToBase64)
]); ]);
} }