Skip to content

Commit d8dc534

Browse files
committed
editor default path
1 parent f8d334b commit d8dc534

File tree

7 files changed

+59
-52
lines changed

7 files changed

+59
-52
lines changed

packages/global/openapi/core/ai/sandbox/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const SandboxFileOperationBodySchema = z.discriminatedUnion('action', [
99
action: z.literal('list'),
1010
appId: z.string(),
1111
chatId: z.string(),
12-
path: z.string().default('/workspace').describe('目录路径'),
12+
path: z.string().default('.').describe('目录路径'),
1313
outLinkAuthData: OutLinkChatAuthSchema.optional().describe('外链鉴权数据')
1414
}),
1515
z.object({

packages/service/core/ai/sandbox/controller.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export class SandboxClient {
7070
throw new Error(`Unsupported sandbox provider: ${env.AGENT_SANDBOX_PROVIDER}`);
7171
}
7272
})();
73-
7473
this.provider = createSandbox(params.provider, params.config, params.createConfig);
7574
}
7675

@@ -91,7 +90,6 @@ export class SandboxClient {
9190
},
9291
{ upsert: true }
9392
);
94-
9593
await this.provider.ensureRunning();
9694
}
9795

packages/service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"dependencies": {
1010
"@apidevtools/json-schema-ref-parser": "^11.7.2",
11-
"@fastgpt-sdk/sandbox-adapter": "^0.0.13",
11+
"@fastgpt-sdk/sandbox-adapter": "^0.0.18",
1212
"@fastgpt-sdk/storage": "catalog:",
1313
"@fastgpt-sdk/logger": "catalog:",
1414
"@fastgpt/global": "workspace:*",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/app/src/pageComponents/chat/SandboxEditor/Editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const SandboxEditor = ({ appId, chatId, outLinkAuthData }: Props) => {
252252
// 初始化加载根目录
253253
useMount(() => {
254254
setLoadingRoot(true);
255-
loadDirectory('', 0).finally(() => {
255+
loadDirectory('.', 0).finally(() => {
256256
setLoadingRoot(false);
257257
});
258258
});

projects/app/src/pages/api/core/ai/sandbox/download.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { OutLinkChatAuthSchema } from '@fastgpt/global/support/permission/chat';
1010
const DownloadBodySchema = z.object({
1111
appId: z.string(),
1212
chatId: z.string(),
13-
path: z.string().default('/workspace').describe('要下载的路径(文件或目录)'),
13+
path: z.string().default('.').describe('要下载的路径(文件或目录)'),
1414
outLinkAuthData: OutLinkChatAuthSchema.optional().describe('外链鉴权数据')
1515
});
1616

projects/app/src/pages/api/core/ai/sandbox/file.ts

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,58 +33,67 @@ async function handler(
3333
chatId
3434
});
3535

36-
await sandbox.ensureAvailable();
36+
try {
37+
await sandbox.ensureAvailable();
3738

38-
// 根据 action 分类执行
39-
switch (action) {
40-
case 'list': {
41-
const entries = await sandbox.provider.listDirectory(body.path);
42-
const files = entries.map((entry) => ({
43-
name: entry.name,
44-
path: entry.path,
45-
type: entry.isDirectory ? ('directory' as const) : ('file' as const),
46-
size: entry.isFile ? entry.size : undefined
47-
}));
48-
return { action: 'list', files };
49-
}
50-
51-
case 'read': {
52-
const results = await sandbox.provider.readFiles([body.path]);
53-
const result = results[0];
39+
// 根据 action 分类执行
40+
switch (action) {
41+
case 'list': {
42+
const entries = await sandbox.provider.listDirectory(body.path);
5443

55-
if (result.error) {
56-
return Promise.reject(result.error);
44+
const files = entries.map((entry) => ({
45+
name: entry.name,
46+
path: entry.path,
47+
type: entry.isDirectory ? ('directory' as const) : ('file' as const),
48+
size: entry.isFile ? entry.size : undefined
49+
}));
50+
return { action: 'list', files };
5751
}
5852

59-
// 尝试将 Uint8Array 转换为 UTF-8 字符串
60-
try {
61-
const decoder = new TextDecoder('utf-8', { fatal: true });
62-
const content = decoder.decode(result.content);
63-
return { action: 'read', content };
64-
} catch (error) {
65-
// 非 UTF-8 内容,返回特殊标记
66-
return { action: 'read', content: '[Binary File - Cannot Display]' };
53+
case 'read': {
54+
const results = await sandbox.provider.readFiles([body.path]);
55+
const result = results[0];
56+
57+
if (result.error) {
58+
return Promise.reject(result.error);
59+
}
60+
61+
// 尝试将 Uint8Array 转换为 UTF-8 字符串
62+
try {
63+
const decoder = new TextDecoder('utf-8', { fatal: true });
64+
const content = decoder.decode(result.content);
65+
return { action: 'read', content };
66+
} catch (error) {
67+
// 非 UTF-8 内容,返回特殊标记
68+
return { action: 'read', content: '[Binary File - Cannot Display]' };
69+
}
6770
}
68-
}
6971

70-
case 'write': {
71-
const results = await sandbox.provider.writeFiles([
72-
{
73-
path: body.path,
74-
data: body.content
72+
case 'write': {
73+
const results = await sandbox.provider.writeFiles([
74+
{
75+
path: body.path,
76+
data: body.content
77+
}
78+
]);
79+
const result = results[0];
80+
81+
if (result.error) {
82+
return Promise.reject(result.error);
7583
}
76-
]);
77-
const result = results[0];
7884

79-
if (result.error) {
80-
return Promise.reject(result.error);
85+
return { action: 'write', success: true };
8186
}
8287

83-
return { action: 'write', success: true };
88+
default:
89+
return Promise.reject('Invalid action');
8490
}
85-
86-
default:
87-
return Promise.reject('Invalid action');
91+
} catch (error: any) {
92+
if (error?.toJSON) {
93+
const err = error.toJSON();
94+
return Promise.reject(`[${err.name}] ${err.message}`);
95+
}
96+
return Promise.reject(error);
8897
}
8998
}
9099

0 commit comments

Comments
 (0)