@opensumi/ide-ai-native 3.9.1-next-1747965564.0 → 3.9.1-next-1748333549.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/mcp/mcp-server.feature.registry.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js +1 -7
- package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts +3 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +41 -13
- package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.js +5 -9
- package/lib/browser/mcp/tools/fileSearch.js.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.js +10 -22
- package/lib/browser/mcp/tools/grepSearch.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ReadFile.js +1 -1
- package/lib/browser/mcp/tools/handlers/ReadFile.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts +1 -11
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.js +4 -11
- package/lib/browser/mcp/tools/handlers/RunCommand.js.map +1 -1
- package/lib/browser/mcp/tools/listDir.d.ts.map +1 -1
- package/lib/browser/mcp/tools/listDir.js +15 -19
- package/lib/browser/mcp/tools/listDir.js.map +1 -1
- package/lib/node/mcp-server.sse.d.ts +1 -187
- package/lib/node/mcp-server.sse.d.ts.map +1 -1
- package/lib/node/mcp-server.sse.js +2 -2
- package/lib/node/mcp-server.sse.js.map +1 -1
- package/lib/node/mcp-server.stdio.d.ts +1 -187
- package/lib/node/mcp-server.stdio.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/browser/mcp/mcp-server.feature.registry.ts +1 -6
- package/src/browser/mcp/tools/createNewFileWithText.ts +47 -16
- package/src/browser/mcp/tools/fileSearch.ts +5 -8
- package/src/browser/mcp/tools/grepSearch.ts +21 -32
- package/src/browser/mcp/tools/handlers/ListDir.ts +2 -2
- package/src/browser/mcp/tools/handlers/ReadFile.ts +2 -2
- package/src/browser/mcp/tools/handlers/RunCommand.ts +14 -21
- package/src/browser/mcp/tools/listDir.ts +12 -15
- package/src/node/mcp-server.sse.ts +2 -1
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts +0 -15
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts.map +0 -1
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js +0 -54
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js.map +0 -1
- package/src/browser/mcp/tools/handlers/CreateNewFileWithText.ts +0 -55
|
@@ -44,12 +44,7 @@ export class MCPServerRegistry implements IMCPServerRegistry {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
registerMCPTool(tool: MCPToolDefinition): void {
|
|
47
|
-
|
|
48
|
-
if (existingIndex !== -1) {
|
|
49
|
-
this.tools[existingIndex] = tool;
|
|
50
|
-
} else {
|
|
51
|
-
this.tools.push(tool);
|
|
52
|
-
}
|
|
47
|
+
this.tools.push(tool);
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
registerToolComponent(
|
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
|
|
3
3
|
import { Autowired } from '@opensumi/di';
|
|
4
|
-
import { Domain } from '@opensumi/ide-core-common';
|
|
4
|
+
import { Domain, URI, path } from '@opensumi/ide-core-common';
|
|
5
|
+
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
6
|
+
import { IWorkspaceService } from '@opensumi/ide-workspace';
|
|
5
7
|
|
|
6
8
|
import { IMCPServerRegistry, MCPLogger, MCPServerContribution, MCPToolDefinition } from '../../types';
|
|
9
|
+
import { BaseApplyService } from '../base-apply.service';
|
|
7
10
|
|
|
8
11
|
import { EditFileToolComponent } from './components/EditFile';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
code_edit: z.string().describe('The content to write into the new file'),
|
|
15
|
-
})
|
|
16
|
-
.transform((data) => ({
|
|
17
|
-
targetFile: data.target_file,
|
|
18
|
-
codeEdit: data.code_edit,
|
|
19
|
-
}));
|
|
12
|
+
|
|
13
|
+
const inputSchema = z.object({
|
|
14
|
+
target_file: z.string().describe('The relative path where the file should be created'),
|
|
15
|
+
code_edit: z.string().describe('The content to write into the new file'),
|
|
16
|
+
});
|
|
20
17
|
|
|
21
18
|
@Domain(MCPServerContribution)
|
|
22
19
|
export class CreateNewFileWithTextTool implements MCPServerContribution {
|
|
23
|
-
@Autowired(
|
|
24
|
-
private readonly
|
|
20
|
+
@Autowired(IWorkspaceService)
|
|
21
|
+
private readonly workspaceService: IWorkspaceService;
|
|
22
|
+
|
|
23
|
+
@Autowired(IFileServiceClient)
|
|
24
|
+
private readonly fileService: IFileServiceClient;
|
|
25
|
+
|
|
26
|
+
@Autowired(BaseApplyService)
|
|
27
|
+
private applyService: BaseApplyService;
|
|
25
28
|
|
|
26
29
|
registerMCPServer(registry: IMCPServerRegistry): void {
|
|
27
30
|
registry.registerMCPTool(this.getToolDefinition());
|
|
@@ -47,11 +50,39 @@ export class CreateNewFileWithTextTool implements MCPServerContribution {
|
|
|
47
50
|
|
|
48
51
|
private async handler(args: z.infer<typeof inputSchema> & { toolCallId: string }, logger: MCPLogger) {
|
|
49
52
|
try {
|
|
50
|
-
|
|
53
|
+
// 获取工作区根目录
|
|
54
|
+
const workspaceRoots = this.workspaceService.tryGetRoots();
|
|
55
|
+
if (!workspaceRoots || workspaceRoots.length === 0) {
|
|
56
|
+
logger.appendLine('Error: Cannot determine project directory');
|
|
57
|
+
return {
|
|
58
|
+
content: [{ type: 'text', text: "can't find project dir" }],
|
|
59
|
+
isError: true,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 构建完整的文件路径
|
|
64
|
+
const rootUri = URI.parse(workspaceRoots[0].uri);
|
|
65
|
+
const fullPath = path.join(rootUri.codeUri.fsPath, args.target_file);
|
|
66
|
+
const fileUri = URI.file(fullPath);
|
|
67
|
+
|
|
68
|
+
// 创建父目录
|
|
69
|
+
const parentDir = path.dirname(fullPath);
|
|
70
|
+
const parentUri = URI.file(parentDir);
|
|
71
|
+
await this.fileService.createFolder(parentUri.toString());
|
|
72
|
+
|
|
73
|
+
// 创建文件
|
|
74
|
+
await this.fileService.createFile(fileUri.toString());
|
|
75
|
+
|
|
76
|
+
// 使用 applyService 写入文件内容
|
|
77
|
+
const codeBlock = await this.applyService.registerCodeBlock(args.target_file, args.code_edit, args.toolCallId);
|
|
78
|
+
await this.applyService.apply(codeBlock);
|
|
79
|
+
|
|
80
|
+
logger.appendLine(`Successfully created file at: ${args.target_file}`);
|
|
51
81
|
return {
|
|
52
|
-
content: [{ type: 'text', text: '
|
|
82
|
+
content: [{ type: 'text', text: 'ok' }],
|
|
53
83
|
};
|
|
54
84
|
} catch (error) {
|
|
85
|
+
logger.appendLine(`Error during file creation: ${error}`);
|
|
55
86
|
return {
|
|
56
87
|
content: [{ type: 'text', text: error.message }],
|
|
57
88
|
isError: true,
|
|
@@ -80,14 +80,11 @@ export class FileSearchTool implements MCPServerContribution {
|
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
const messages = this.chatInternalService.sessionModel.history.getMessages();
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
}
|
|
83
|
+
this.chatInternalService.sessionModel.history.setMessageAdditional(messages[messages.length - 1].id, {
|
|
84
|
+
[args.toolCallId]: {
|
|
85
|
+
files,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
91
88
|
|
|
92
89
|
logger.appendLine(`Found ${files.length} files matching "${args.query}"`);
|
|
93
90
|
|
|
@@ -12,27 +12,19 @@ import { IMCPServerRegistry, MCPLogger, MCPServerContribution, MCPToolDefinition
|
|
|
12
12
|
|
|
13
13
|
import { GrepSearchToolComponent } from './components/ExpandableFileList';
|
|
14
14
|
|
|
15
|
-
const inputSchema = z
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
.transform((data) => ({
|
|
30
|
-
query: data.query,
|
|
31
|
-
caseSensitive: data.case_sensitive,
|
|
32
|
-
includePattern: data.include_pattern,
|
|
33
|
-
excludePattern: data.exclude_pattern,
|
|
34
|
-
explanation: data.explanation,
|
|
35
|
-
}));
|
|
15
|
+
const inputSchema = z.object({
|
|
16
|
+
query: z.string().describe('The regex pattern to search for'),
|
|
17
|
+
case_sensitive: z.boolean().optional().describe('Whether the search should be case sensitive'),
|
|
18
|
+
include_pattern: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.describe('Glob pattern for files to include (e.g. "*.ts" for TypeScript files)'),
|
|
22
|
+
exclude_pattern: z.string().optional().describe('Glob pattern for files to exclude'),
|
|
23
|
+
explanation: z
|
|
24
|
+
.string()
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('One sentence explanation as to why this tool is being used, and how it contributes to the goal.'),
|
|
27
|
+
});
|
|
36
28
|
|
|
37
29
|
const MAX_RESULTS = 50;
|
|
38
30
|
|
|
@@ -80,9 +72,9 @@ export class GrepSearchTool implements MCPServerContribution {
|
|
|
80
72
|
await this.searchService.doSearch(
|
|
81
73
|
searchPattern,
|
|
82
74
|
{
|
|
83
|
-
isMatchCase: !!args.
|
|
84
|
-
include: args.
|
|
85
|
-
exclude: args.
|
|
75
|
+
isMatchCase: !!args.case_sensitive,
|
|
76
|
+
include: args.include_pattern?.split(','),
|
|
77
|
+
exclude: args.exclude_pattern?.split(','),
|
|
86
78
|
maxResults: MAX_RESULTS,
|
|
87
79
|
isUseRegexp: true,
|
|
88
80
|
isToggleOpen: false,
|
|
@@ -119,14 +111,11 @@ export class GrepSearchTool implements MCPServerContribution {
|
|
|
119
111
|
}
|
|
120
112
|
deferred.resolve(results.join('\n\n'));
|
|
121
113
|
const messages = this.chatInternalService.sessionModel.history.getMessages();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
114
|
+
this.chatInternalService.sessionModel.history.setMessageAdditional(messages[messages.length - 1].id, {
|
|
115
|
+
[args.toolCallId]: {
|
|
116
|
+
files,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
130
119
|
});
|
|
131
120
|
const text = await deferred.promise;
|
|
132
121
|
return {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
-
import { AppConfig,
|
|
2
|
+
import { AppConfig, Throttler, URI } from '@opensumi/ide-core-browser';
|
|
3
3
|
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -67,7 +67,7 @@ export class ListDirHandler {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// 解析相对路径
|
|
70
|
-
const absolutePath =
|
|
70
|
+
const absolutePath = `${this.appConfig.workspaceDir}/${relativeWorkspacePath}`;
|
|
71
71
|
const fileStat = await this.fileSystemService.getFileStat(absolutePath, true);
|
|
72
72
|
// 验证路径有效性
|
|
73
73
|
if (!fileStat || !fileStat.isDirectory) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
2
|
import { FileSearchQuickCommandHandler } from '@opensumi/ide-addons/lib/browser/file-search.contribution';
|
|
3
3
|
import { AppConfig } from '@opensumi/ide-core-browser';
|
|
4
|
-
import { CancellationToken, URI
|
|
4
|
+
import { CancellationToken, URI } from '@opensumi/ide-core-common';
|
|
5
5
|
import { IEditorDocumentModelRef, IEditorDocumentModelService } from '@opensumi/ide-editor/lib/browser';
|
|
6
6
|
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
7
7
|
|
|
@@ -107,7 +107,7 @@ export class FileHandler {
|
|
|
107
107
|
throw new Error('No read file parameters provided. Need to give at least the path.');
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
const uri = new URI(
|
|
110
|
+
const uri = new URI(`${this.appConfig.workspaceDir}/${fileParams.relativeWorkspacePath}`);
|
|
111
111
|
if (!uri) {
|
|
112
112
|
const similarFiles = await this.findSimilarFiles(fileParams.relativeWorkspacePath, 3);
|
|
113
113
|
throw this.createFileNotFoundError(fileParams.relativeWorkspacePath, similarFiles);
|
|
@@ -13,25 +13,18 @@ const color = {
|
|
|
13
13
|
reset: '\x1b[0m',
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export const inputSchema = z
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
.transform((data) => ({
|
|
30
|
-
command: data.command,
|
|
31
|
-
isBackground: data.is_background,
|
|
32
|
-
explanation: data.explanation,
|
|
33
|
-
requireUserApproval: data.require_user_approval,
|
|
34
|
-
}));
|
|
16
|
+
export const inputSchema = z.object({
|
|
17
|
+
command: z.string().describe('The terminal command to execute'),
|
|
18
|
+
is_background: z.boolean().describe('Whether the command should be run in the background'),
|
|
19
|
+
explanation: z
|
|
20
|
+
.string()
|
|
21
|
+
.describe('One sentence explanation as to why this command needs to be run and how it contributes to the goal.'),
|
|
22
|
+
require_user_approval: z
|
|
23
|
+
.boolean()
|
|
24
|
+
.describe(
|
|
25
|
+
"Whether the user must approve the command before it is executed. Only set this to false if the command is safe and if it matches the user's requirements for commands that should be executed automatically.",
|
|
26
|
+
),
|
|
27
|
+
});
|
|
35
28
|
|
|
36
29
|
@Injectable()
|
|
37
30
|
export class RunCommandHandler {
|
|
@@ -73,7 +66,7 @@ export class RunCommandHandler {
|
|
|
73
66
|
|
|
74
67
|
async handler(args: z.infer<typeof inputSchema> & { toolCallId: string }, logger: MCPLogger) {
|
|
75
68
|
logger.appendLine(`Executing command: ${args.command}`);
|
|
76
|
-
if (this.isAlwaysApproval(args.
|
|
69
|
+
if (this.isAlwaysApproval(args.require_user_approval)) {
|
|
77
70
|
const def = new Deferred<boolean>();
|
|
78
71
|
this.approvalDeferredMap.set(args.toolCallId, def);
|
|
79
72
|
const approval = await def.promise;
|
|
@@ -100,7 +93,7 @@ export class RunCommandHandler {
|
|
|
100
93
|
const result: { type: string; text: string }[] = [];
|
|
101
94
|
const def = new Deferred<{ isError?: boolean; content: { type: string; text: string }[] }>();
|
|
102
95
|
|
|
103
|
-
if (args.
|
|
96
|
+
if (args.is_background) {
|
|
104
97
|
def.resolve({
|
|
105
98
|
isError: false,
|
|
106
99
|
content: [{ type: 'text', text: `Successful run command ${args.command} in background.` }],
|
|
@@ -63,21 +63,18 @@ export class ListDirTool implements MCPServerContribution {
|
|
|
63
63
|
|
|
64
64
|
// 设置消息的附加数据
|
|
65
65
|
const messages = this.chatInternalService.sessionModel.history.getMessages();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
66
|
+
this.chatInternalService.sessionModel.history.setMessageAdditional(messages[messages.length - 1].id, {
|
|
67
|
+
[args.toolCallId]: {
|
|
68
|
+
files: fileUris,
|
|
69
|
+
title: `Listed directory "${args.relativeWorkspacePath}"`,
|
|
70
|
+
details: result.files.map((file) => ({
|
|
71
|
+
type: file.isDirectory ? 'dir' : 'file',
|
|
72
|
+
name: file.name,
|
|
73
|
+
info: file.isDirectory ? `${file.numChildren ?? '?'} items` : `${file.size}KB, ${file.numLines} lines`,
|
|
74
|
+
lastModified: file.lastModified,
|
|
75
|
+
})),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
81
78
|
|
|
82
79
|
logger.appendLine(`Listed ${fileUris.length} files in directory "${args.relativeWorkspacePath}"`);
|
|
83
80
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// have to import with extension since the exports map is ./* -> ./dist/cjs/*
|
|
2
2
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
3
|
import { EventSource } from 'eventsource';
|
|
5
4
|
|
|
6
5
|
import { ILogger } from '@opensumi/ide-core-common';
|
|
@@ -48,6 +47,8 @@ export class SSEMCPServer implements IMCPServer {
|
|
|
48
47
|
}
|
|
49
48
|
this.logger?.log(`Starting server "${this.name}" with url: ${this.url}`);
|
|
50
49
|
|
|
50
|
+
const SSEClientTransport = (await import('@modelcontextprotocol/sdk/client/sse.js')).SSEClientTransport;
|
|
51
|
+
|
|
51
52
|
const transport = new SSEClientTransport(new URL(this.url), this.transportOptions);
|
|
52
53
|
|
|
53
54
|
transport.onerror = (error) => {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MCPLogger } from '../../../types';
|
|
2
|
-
/**
|
|
3
|
-
* 创建新文件处理器
|
|
4
|
-
* 用于处理创建新文件并写入内容的操作
|
|
5
|
-
*/
|
|
6
|
-
export declare class CreateNewFileWithTextHandler {
|
|
7
|
-
private readonly workspaceService;
|
|
8
|
-
private readonly fileService;
|
|
9
|
-
private applyService;
|
|
10
|
-
handler(params: {
|
|
11
|
-
targetFile: string;
|
|
12
|
-
codeEdit: string;
|
|
13
|
-
}, toolCallId: string, logger: MCPLogger): Promise<void>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=CreateNewFileWithText.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateNewFileWithText.d.ts","sourceRoot":"","sources":["../../../../../src/browser/mcp/tools/handlers/CreateNewFileWithText.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;;GAGG;AACH,qBACa,4BAA4B;IAEvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAGjD,OAAO,CAAC,YAAY,CAAmB;IAEjC,OAAO,CACX,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAChD,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,IAAI,CAAC;CA2BjB"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateNewFileWithTextHandler = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const di_1 = require("@opensumi/di");
|
|
6
|
-
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
7
|
-
const ide_file_service_1 = require("@opensumi/ide-file-service");
|
|
8
|
-
const ide_workspace_1 = require("@opensumi/ide-workspace");
|
|
9
|
-
const base_apply_service_1 = require("../../base-apply.service");
|
|
10
|
-
/**
|
|
11
|
-
* 创建新文件处理器
|
|
12
|
-
* 用于处理创建新文件并写入内容的操作
|
|
13
|
-
*/
|
|
14
|
-
let CreateNewFileWithTextHandler = class CreateNewFileWithTextHandler {
|
|
15
|
-
async handler(params, toolCallId, logger) {
|
|
16
|
-
// 获取工作区根目录
|
|
17
|
-
const workspaceRoots = this.workspaceService.tryGetRoots();
|
|
18
|
-
if (!workspaceRoots || workspaceRoots.length === 0) {
|
|
19
|
-
logger.appendLine('Error: Cannot determine project directory');
|
|
20
|
-
throw new Error("can't find project dir");
|
|
21
|
-
}
|
|
22
|
-
// 构建完整的文件路径
|
|
23
|
-
const rootUri = ide_core_common_1.URI.parse(workspaceRoots[0].uri);
|
|
24
|
-
const fullPath = ide_core_common_1.path.join(rootUri.codeUri.fsPath, params.targetFile);
|
|
25
|
-
const fileUri = ide_core_common_1.URI.file(fullPath);
|
|
26
|
-
// 创建父目录
|
|
27
|
-
const parentDir = ide_core_common_1.path.dirname(fullPath);
|
|
28
|
-
const parentUri = ide_core_common_1.URI.file(parentDir);
|
|
29
|
-
await this.fileService.createFolder(parentUri.toString());
|
|
30
|
-
// 创建文件
|
|
31
|
-
await this.fileService.createFile(fileUri.toString());
|
|
32
|
-
// 使用 applyService 写入文件内容
|
|
33
|
-
const codeBlock = await this.applyService.registerCodeBlock(params.targetFile, params.codeEdit, toolCallId);
|
|
34
|
-
await this.applyService.apply(codeBlock);
|
|
35
|
-
logger.appendLine(`Successfully created file at: ${params.targetFile}`);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
exports.CreateNewFileWithTextHandler = CreateNewFileWithTextHandler;
|
|
39
|
-
tslib_1.__decorate([
|
|
40
|
-
(0, di_1.Autowired)(ide_workspace_1.IWorkspaceService),
|
|
41
|
-
tslib_1.__metadata("design:type", Object)
|
|
42
|
-
], CreateNewFileWithTextHandler.prototype, "workspaceService", void 0);
|
|
43
|
-
tslib_1.__decorate([
|
|
44
|
-
(0, di_1.Autowired)(ide_file_service_1.IFileServiceClient),
|
|
45
|
-
tslib_1.__metadata("design:type", Object)
|
|
46
|
-
], CreateNewFileWithTextHandler.prototype, "fileService", void 0);
|
|
47
|
-
tslib_1.__decorate([
|
|
48
|
-
(0, di_1.Autowired)(base_apply_service_1.BaseApplyService),
|
|
49
|
-
tslib_1.__metadata("design:type", base_apply_service_1.BaseApplyService)
|
|
50
|
-
], CreateNewFileWithTextHandler.prototype, "applyService", void 0);
|
|
51
|
-
exports.CreateNewFileWithTextHandler = CreateNewFileWithTextHandler = tslib_1.__decorate([
|
|
52
|
-
(0, di_1.Injectable)()
|
|
53
|
-
], CreateNewFileWithTextHandler);
|
|
54
|
-
//# sourceMappingURL=CreateNewFileWithText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateNewFileWithText.js","sourceRoot":"","sources":["../../../../../src/browser/mcp/tools/handlers/CreateNewFileWithText.ts"],"names":[],"mappings":";;;;AAAA,qCAAqD;AACrD,+DAAsD;AACtD,iEAAgE;AAChE,2DAA4D;AAG5D,iEAA4D;AAE5D;;;GAGG;AAEI,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAUvC,KAAK,CAAC,OAAO,CACX,MAAgD,EAChD,UAAkB,EAClB,MAAiB;QAEjB,WAAW;QACX,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAC3D,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,UAAU,CAAC,2CAA2C,CAAC,CAAC;YAC/D,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,YAAY;QACZ,MAAM,OAAO,GAAG,qBAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,QAAQ,GAAG,sBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,qBAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,QAAQ;QACR,MAAM,SAAS,GAAG,sBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,SAAS,GAAG,qBAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE1D,OAAO;QACP,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtD,yBAAyB;QACzB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC5G,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAEzC,MAAM,CAAC,UAAU,CAAC,iCAAiC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IAC1E,CAAC;CACF,CAAA;AAzCY,oEAA4B;AAEtB;IADhB,IAAA,cAAS,EAAC,iCAAiB,CAAC;;sEACwB;AAGpC;IADhB,IAAA,cAAS,EAAC,qCAAkB,CAAC;;iEACmB;AAGzC;IADP,IAAA,cAAS,EAAC,qCAAgB,CAAC;sCACN,qCAAgB;kEAAC;uCAR5B,4BAA4B;IADxC,IAAA,eAAU,GAAE;GACA,4BAA4B,CAyCxC"}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
-
import { URI, path } from '@opensumi/ide-core-common';
|
|
3
|
-
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
4
|
-
import { IWorkspaceService } from '@opensumi/ide-workspace';
|
|
5
|
-
|
|
6
|
-
import { MCPLogger } from '../../../types';
|
|
7
|
-
import { BaseApplyService } from '../../base-apply.service';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 创建新文件处理器
|
|
11
|
-
* 用于处理创建新文件并写入内容的操作
|
|
12
|
-
*/
|
|
13
|
-
@Injectable()
|
|
14
|
-
export class CreateNewFileWithTextHandler {
|
|
15
|
-
@Autowired(IWorkspaceService)
|
|
16
|
-
private readonly workspaceService: IWorkspaceService;
|
|
17
|
-
|
|
18
|
-
@Autowired(IFileServiceClient)
|
|
19
|
-
private readonly fileService: IFileServiceClient;
|
|
20
|
-
|
|
21
|
-
@Autowired(BaseApplyService)
|
|
22
|
-
private applyService: BaseApplyService;
|
|
23
|
-
|
|
24
|
-
async handler(
|
|
25
|
-
params: { targetFile: string; codeEdit: string },
|
|
26
|
-
toolCallId: string,
|
|
27
|
-
logger: MCPLogger,
|
|
28
|
-
): Promise<void> {
|
|
29
|
-
// 获取工作区根目录
|
|
30
|
-
const workspaceRoots = this.workspaceService.tryGetRoots();
|
|
31
|
-
if (!workspaceRoots || workspaceRoots.length === 0) {
|
|
32
|
-
logger.appendLine('Error: Cannot determine project directory');
|
|
33
|
-
throw new Error("can't find project dir");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 构建完整的文件路径
|
|
37
|
-
const rootUri = URI.parse(workspaceRoots[0].uri);
|
|
38
|
-
const fullPath = path.join(rootUri.codeUri.fsPath, params.targetFile);
|
|
39
|
-
const fileUri = URI.file(fullPath);
|
|
40
|
-
|
|
41
|
-
// 创建父目录
|
|
42
|
-
const parentDir = path.dirname(fullPath);
|
|
43
|
-
const parentUri = URI.file(parentDir);
|
|
44
|
-
await this.fileService.createFolder(parentUri.toString());
|
|
45
|
-
|
|
46
|
-
// 创建文件
|
|
47
|
-
await this.fileService.createFile(fileUri.toString());
|
|
48
|
-
|
|
49
|
-
// 使用 applyService 写入文件内容
|
|
50
|
-
const codeBlock = await this.applyService.registerCodeBlock(params.targetFile, params.codeEdit, toolCallId);
|
|
51
|
-
await this.applyService.apply(codeBlock);
|
|
52
|
-
|
|
53
|
-
logger.appendLine(`Successfully created file at: ${params.targetFile}`);
|
|
54
|
-
}
|
|
55
|
-
}
|