mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-01 02:01:34 +08:00
aaa7d17ef1
* feat: encapsulate logger (#6535) * feat: encapsulate logger * update engines --------- Co-authored-by: archer <545436317@qq.com> * next config * dev shell * Agent sandbox (#6532) * docs: switch to docs layout and apply black theme (#6533) * feat: add Gemini 3.1 models - Add gemini-3.1-pro-preview (released February 19, 2026) - Add gemini-3.1-flash-lite-preview (released March 3, 2026) Both models support: - 1M context window - 64k max response - Vision - Tool choice * docs: switch to docs layout and apply black theme - Change layout from notebook to docs - Update logo to icon + text format - Apply fumadocs black theme - Simplify global.css (keep only navbar and TOC styles) - Fix icon components to properly accept className props - Add mobile text overflow handling - Update Node engine requirement to >=20.x * doc * doc * lock * fix: ts * doc * doc --------- Co-authored-by: archer <archer@archerdeMac-mini.local> Co-authored-by: archer <545436317@qq.com> * Doc (#6493) * cloud doc * doc refactor * doc move * seo * remove doc * yml * doc * fix: tsconfig * fix: tsconfig * sandbox version (#6497) * sandbox version * add sandbox log * update lock * fix * fix: sandbox * doc * add console * i18n * sandbxo in agent * feat: agent sandbox * lock * feat: sandbox ui * sandbox check exists * env tempalte * doc * lock * sandbox in chat window * sandbox entry * fix: test * rename var * sandbox config tip * update sandbox lifecircle * update prompt * rename provider test * sandbox logger * yml --------- Co-authored-by: Archer <archer@fastgpt.io> Co-authored-by: archer <archer@archerdeMac-mini.local> * perf: sandbox error tip * Add sandbox limit and fix some issue (#6550) * sandbox in plan * fix: some issue * fix: test * editor default path * fix: comment * perf: sandbox worksapce * doc * perf: del sandbox * sandbox build * fix: test * fix: pr comment --------- Co-authored-by: Ryo <whoeverimf5@gmail.com> Co-authored-by: Archer <archer@fastgpt.io> Co-authored-by: archer <archer@archerdeMac-mini.local>
76 lines
1.9 KiB
TypeScript
76 lines
1.9 KiB
TypeScript
import { SandboxCodeTypeEnum } from '@fastgpt/global/core/workflow/template/system/sandbox/constants';
|
|
import type { AxiosInstance } from 'axios';
|
|
import axios from 'axios';
|
|
import { getLogger, LogCategories } from '../../common/logger';
|
|
const logger = getLogger(LogCategories.MODULE.WORKFLOW.CODE_SANDBOX);
|
|
|
|
export type SanndboxPackagesResponse = {
|
|
js: string[];
|
|
python: string[];
|
|
builtinGlobals: string[];
|
|
};
|
|
|
|
export class CodeSandbox {
|
|
private readonly client: AxiosInstance;
|
|
|
|
constructor() {
|
|
const baseUrl = process.env.CODE_SANDBOX_URL || '';
|
|
const token = process.env.CODE_SANDBOX_TOKEN || '';
|
|
|
|
this.client = axios.create({
|
|
baseURL: `${baseUrl.replace(/\/$/, '')}/sandbox`,
|
|
timeout: 180000,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: token ? `Bearer ${token}` : undefined
|
|
}
|
|
});
|
|
|
|
this.client.interceptors.response.use(
|
|
(response) => {
|
|
const data = response.data;
|
|
if (!data.success) {
|
|
logger.warn('Request code sandbox failed', { data });
|
|
return Promise.reject(new Error(data.message || 'Request code sandbox failed'));
|
|
}
|
|
return response.data;
|
|
},
|
|
(error) => {
|
|
return Promise.reject(error);
|
|
}
|
|
);
|
|
}
|
|
|
|
async getPackages() {
|
|
const { data } = await this.client.get<SanndboxPackagesResponse>('/modules');
|
|
return data;
|
|
}
|
|
|
|
async runCode({
|
|
codeType,
|
|
code,
|
|
variables
|
|
}: {
|
|
codeType: string;
|
|
code: string;
|
|
variables: Record<string, any>;
|
|
}) {
|
|
const url = (() => {
|
|
if (codeType == SandboxCodeTypeEnum.py) {
|
|
return `/python`;
|
|
} else {
|
|
return `/js`;
|
|
}
|
|
})();
|
|
|
|
const { data } = await this.client.post<{
|
|
codeReturn: Record<string, any>;
|
|
log: string;
|
|
}>(url, { code, variables });
|
|
|
|
return data;
|
|
}
|
|
}
|
|
|
|
export const codeSandbox = new CodeSandbox();
|