@opensumi/ide-ai-native 3.9.1-next-1747897586.0 → 3.9.1-next-1747965564.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.
@@ -1,8 +1,6 @@
1
1
  import { IMCPServerRegistry, MCPServerContribution, MCPToolDefinition } from '../../types';
2
2
  export declare class CreateNewFileWithTextTool implements MCPServerContribution {
3
- private readonly workspaceService;
4
- private readonly fileService;
5
- private applyService;
3
+ private readonly createNewFileWithTextHandler;
6
4
  registerMCPServer(registry: IMCPServerRegistry): void;
7
5
  getToolDefinition(): MCPToolDefinition;
8
6
  private handler;
@@ -1 +1 @@
1
- {"version":3,"file":"createNewFileWithText.d.ts","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/createNewFileWithText.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAa,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAetG,qBACa,yBAA0B,YAAW,qBAAqB;IAErE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAGjD,OAAO,CAAC,YAAY,CAAmB;IAEvC,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAKrD,iBAAiB,IAAI,iBAAiB;YAiBxB,OAAO;CAyCtB"}
1
+ {"version":3,"file":"createNewFileWithText.d.ts","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/createNewFileWithText.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAa,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAetG,qBACa,yBAA0B,YAAW,qBAAqB;IAErE,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAA+B;IAE5E,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAKrD,iBAAiB,IAAI,iBAAiB;YAiBxB,OAAO;CAatB"}
@@ -5,11 +5,9 @@ const tslib_1 = require("tslib");
5
5
  const zod_1 = require("zod");
6
6
  const di_1 = require("@opensumi/di");
7
7
  const ide_core_common_1 = require("@opensumi/ide-core-common");
8
- const ide_file_service_1 = require("@opensumi/ide-file-service");
9
- const ide_workspace_1 = require("@opensumi/ide-workspace");
10
8
  const types_1 = require("../../types");
11
- const base_apply_service_1 = require("../base-apply.service");
12
9
  const EditFile_1 = require("./components/EditFile");
10
+ const CreateNewFileWithText_1 = require("./handlers/CreateNewFileWithText");
13
11
  const inputSchema = zod_1.z
14
12
  .object({
15
13
  target_file: zod_1.z.string().describe('The relative path where the file should be created'),
@@ -41,35 +39,12 @@ let CreateNewFileWithTextTool = class CreateNewFileWithTextTool {
41
39
  }
42
40
  async handler(args, logger) {
43
41
  try {
44
- // 获取工作区根目录
45
- const workspaceRoots = this.workspaceService.tryGetRoots();
46
- if (!workspaceRoots || workspaceRoots.length === 0) {
47
- logger.appendLine('Error: Cannot determine project directory');
48
- return {
49
- content: [{ type: 'text', text: "can't find project dir" }],
50
- isError: true,
51
- };
52
- }
53
- // 构建完整的文件路径
54
- const rootUri = ide_core_common_1.URI.parse(workspaceRoots[0].uri);
55
- const fullPath = ide_core_common_1.path.join(rootUri.codeUri.fsPath, args.targetFile);
56
- const fileUri = ide_core_common_1.URI.file(fullPath);
57
- // 创建父目录
58
- const parentDir = ide_core_common_1.path.dirname(fullPath);
59
- const parentUri = ide_core_common_1.URI.file(parentDir);
60
- await this.fileService.createFolder(parentUri.toString());
61
- // 创建文件
62
- await this.fileService.createFile(fileUri.toString());
63
- // 使用 applyService 写入文件内容
64
- const codeBlock = await this.applyService.registerCodeBlock(args.targetFile, args.codeEdit, args.toolCallId);
65
- await this.applyService.apply(codeBlock);
66
- logger.appendLine(`Successfully created file at: ${args.targetFile}`);
42
+ await this.createNewFileWithTextHandler.handler(args, args.toolCallId, logger);
67
43
  return {
68
- content: [{ type: 'text', text: 'ok' }],
44
+ content: [{ type: 'text', text: 'create file with text success' }],
69
45
  };
70
46
  }
71
47
  catch (error) {
72
- logger.appendLine(`Error during file creation: ${error}`);
73
48
  return {
74
49
  content: [{ type: 'text', text: error.message }],
75
50
  isError: true,
@@ -79,17 +54,9 @@ let CreateNewFileWithTextTool = class CreateNewFileWithTextTool {
79
54
  };
80
55
  exports.CreateNewFileWithTextTool = CreateNewFileWithTextTool;
81
56
  tslib_1.__decorate([
82
- (0, di_1.Autowired)(ide_workspace_1.IWorkspaceService),
83
- tslib_1.__metadata("design:type", Object)
84
- ], CreateNewFileWithTextTool.prototype, "workspaceService", void 0);
85
- tslib_1.__decorate([
86
- (0, di_1.Autowired)(ide_file_service_1.IFileServiceClient),
87
- tslib_1.__metadata("design:type", Object)
88
- ], CreateNewFileWithTextTool.prototype, "fileService", void 0);
89
- tslib_1.__decorate([
90
- (0, di_1.Autowired)(base_apply_service_1.BaseApplyService),
91
- tslib_1.__metadata("design:type", base_apply_service_1.BaseApplyService)
92
- ], CreateNewFileWithTextTool.prototype, "applyService", void 0);
57
+ (0, di_1.Autowired)(CreateNewFileWithText_1.CreateNewFileWithTextHandler),
58
+ tslib_1.__metadata("design:type", CreateNewFileWithText_1.CreateNewFileWithTextHandler)
59
+ ], CreateNewFileWithTextTool.prototype, "createNewFileWithTextHandler", void 0);
93
60
  exports.CreateNewFileWithTextTool = CreateNewFileWithTextTool = tslib_1.__decorate([
94
61
  (0, ide_core_common_1.Domain)(types_1.MCPServerContribution)
95
62
  ], CreateNewFileWithTextTool);
@@ -1 +1 @@
1
- {"version":3,"file":"createNewFileWithText.js","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/createNewFileWithText.ts"],"names":[],"mappings":";;;;AAAA,6BAAwB;AAExB,qCAAyC;AACzC,+DAA8D;AAC9D,iEAAgE;AAChE,2DAA4D;AAE5D,uCAAsG;AACtG,8DAAyD;AAEzD,oDAA8D;AAE9D,MAAM,WAAW,GAAG,OAAC;KAClB,MAAM,CAAC;IACN,WAAW,EAAE,OAAC,CAAC,MAAM,E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OAAO,EAAE,CAAC;gBAChD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAzEY,8DAAyB;AAEnB;IADhB,IAAA,cAAS,EAAC,iCAAiB,CAAC;;mEACwB;AAGpC;IADhB,IAAA,cAAS,EAAC,qCAAkB,CAAC;;8DACmB;AAGzC;IADP,IAAA,cAAS,EAAC,qCAAgB,CAAC;sCACN,qCAAgB;+DAAC;oCAR5B,yBAAyB;IADrC,IAAA,wBAAM,EAAC,6BAAqB,CAAC;GACjB,yBAAyB,CAyErC"}
1
+ {"version":3,"file":"createNewFileWithText.js","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/createNewFileWithText.ts"],"names":[],"mappings":";;;;AAAA,6BAAwB;AAExB,qCAAyC;AACzC,+DAAmD;AAEnD,uCAAsG;AAEtG,oDAA8D;AAC9D,4EAAgF;AAEhF,MAAM,WAAW,GAAG,OAAC;KAClB,MAAM,CAAC;IACN,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;IACtF,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;CACzE,CAAC;KACD,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC,WAAW;IAC5B,QAAQ,EAAE,IAAI,CAAC,SAAS;CACzB,CAAC,CAAC,CAAC;AAGC,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAIpC,iBAAiB,CAAC,QAA4B;QAC5C,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACnD,QAAQ,CAAC,qBAAqB,CAAC,2BAA2B,EAAE,gCAAqB,CAAC,CAAC;IACrF,CAAC;IAED,iBAAiB;QACf,OAAO;YACL,IAAI,EAAE,2BAA2B;YACjC,KAAK,EAAE,aAAa;YACpB,KAAK,EAAE,CAAC;YACR,WAAW,EACT,iHAAiH;gBACjH,iEAAiE;gBACjE,yCAAyC;gBACzC,2DAA2D;gBAC3D,2EAA2E;gBAC3E,yEAAyE;YAC3E,WAAW;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SACjC,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAA0D,EAAE,MAAiB;QACjG,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,4BAA4B,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAC/E,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,+BAA+B,EAAE,CAAC;aACnE,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;gBAChD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAvCY,8DAAyB;AAEnB;IADhB,IAAA,cAAS,EAAC,oDAA4B,CAAC;sCACO,oDAA4B;+EAAC;oCAFjE,yBAAyB;IADrC,IAAA,wBAAM,EAAC,6BAAqB,CAAC;GACjB,yBAAyB,CAuCrC"}
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,54 @@
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
@@ -0,0 +1 @@
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;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AA,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensumi/ide-ai-native",
3
- "version": "3.9.1-next-1747897586.0",
3
+ "version": "3.9.1-next-1747965564.0",
4
4
  "files": [
5
5
  "lib",
6
6
  "src"
@@ -24,27 +24,27 @@
24
24
  "@ai-sdk/openai": "^1.1.9",
25
25
  "@ai-sdk/openai-compatible": "^0.1.11",
26
26
  "@modelcontextprotocol/sdk": "^1.11.4",
27
- "@opensumi/ide-addons": "3.9.1-next-1747897586.0",
28
- "@opensumi/ide-components": "3.9.1-next-1747897586.0",
29
- "@opensumi/ide-connection": "3.9.1-next-1747897586.0",
30
- "@opensumi/ide-core-common": "3.9.1-next-1747897586.0",
31
- "@opensumi/ide-core-node": "3.9.1-next-1747897586.0",
32
- "@opensumi/ide-debug": "3.9.1-next-1747897586.0",
33
- "@opensumi/ide-design": "3.9.1-next-1747897586.0",
34
- "@opensumi/ide-editor": "3.9.1-next-1747897586.0",
35
- "@opensumi/ide-file-search": "3.9.1-next-1747897586.0",
36
- "@opensumi/ide-file-service": "3.9.1-next-1747897586.0",
37
- "@opensumi/ide-main-layout": "3.9.1-next-1747897586.0",
38
- "@opensumi/ide-markers": "3.9.1-next-1747897586.0",
39
- "@opensumi/ide-monaco": "3.9.1-next-1747897586.0",
40
- "@opensumi/ide-outline": "3.9.1-next-1747897586.0",
41
- "@opensumi/ide-overlay": "3.9.1-next-1747897586.0",
42
- "@opensumi/ide-preferences": "3.9.1-next-1747897586.0",
43
- "@opensumi/ide-search": "3.9.1-next-1747897586.0",
44
- "@opensumi/ide-terminal-next": "3.9.1-next-1747897586.0",
45
- "@opensumi/ide-theme": "3.9.1-next-1747897586.0",
46
- "@opensumi/ide-utils": "3.9.1-next-1747897586.0",
47
- "@opensumi/ide-workspace": "3.9.1-next-1747897586.0",
27
+ "@opensumi/ide-addons": "3.9.1-next-1747965564.0",
28
+ "@opensumi/ide-components": "3.9.1-next-1747965564.0",
29
+ "@opensumi/ide-connection": "3.9.1-next-1747965564.0",
30
+ "@opensumi/ide-core-common": "3.9.1-next-1747965564.0",
31
+ "@opensumi/ide-core-node": "3.9.1-next-1747965564.0",
32
+ "@opensumi/ide-debug": "3.9.1-next-1747965564.0",
33
+ "@opensumi/ide-design": "3.9.1-next-1747965564.0",
34
+ "@opensumi/ide-editor": "3.9.1-next-1747965564.0",
35
+ "@opensumi/ide-file-search": "3.9.1-next-1747965564.0",
36
+ "@opensumi/ide-file-service": "3.9.1-next-1747965564.0",
37
+ "@opensumi/ide-main-layout": "3.9.1-next-1747965564.0",
38
+ "@opensumi/ide-markers": "3.9.1-next-1747965564.0",
39
+ "@opensumi/ide-monaco": "3.9.1-next-1747965564.0",
40
+ "@opensumi/ide-outline": "3.9.1-next-1747965564.0",
41
+ "@opensumi/ide-overlay": "3.9.1-next-1747965564.0",
42
+ "@opensumi/ide-preferences": "3.9.1-next-1747965564.0",
43
+ "@opensumi/ide-search": "3.9.1-next-1747965564.0",
44
+ "@opensumi/ide-terminal-next": "3.9.1-next-1747965564.0",
45
+ "@opensumi/ide-theme": "3.9.1-next-1747965564.0",
46
+ "@opensumi/ide-utils": "3.9.1-next-1747965564.0",
47
+ "@opensumi/ide-workspace": "3.9.1-next-1747965564.0",
48
48
  "@xterm/xterm": "5.5.0",
49
49
  "ai": "^4.1.45",
50
50
  "ansi-regex": "^2.0.0",
@@ -61,7 +61,7 @@
61
61
  "zod-to-json-schema": "^3.24.1"
62
62
  },
63
63
  "devDependencies": {
64
- "@opensumi/ide-core-browser": "3.9.1-next-1747897586.0"
64
+ "@opensumi/ide-core-browser": "3.9.1-next-1747965564.0"
65
65
  },
66
- "gitHead": "d9d184251a55864b66ad58cef0097d78eed4b4f7"
66
+ "gitHead": "530be4f4e7e75f2ba69374c600bf6292629838f2"
67
67
  }
@@ -1,14 +1,12 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  import { Autowired } from '@opensumi/di';
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';
4
+ import { Domain } from '@opensumi/ide-core-common';
7
5
 
8
6
  import { IMCPServerRegistry, MCPLogger, MCPServerContribution, MCPToolDefinition } from '../../types';
9
- import { BaseApplyService } from '../base-apply.service';
10
7
 
11
8
  import { EditFileToolComponent } from './components/EditFile';
9
+ import { CreateNewFileWithTextHandler } from './handlers/CreateNewFileWithText';
12
10
 
13
11
  const inputSchema = z
14
12
  .object({
@@ -22,14 +20,8 @@ const inputSchema = z
22
20
 
23
21
  @Domain(MCPServerContribution)
24
22
  export class CreateNewFileWithTextTool implements MCPServerContribution {
25
- @Autowired(IWorkspaceService)
26
- private readonly workspaceService: IWorkspaceService;
27
-
28
- @Autowired(IFileServiceClient)
29
- private readonly fileService: IFileServiceClient;
30
-
31
- @Autowired(BaseApplyService)
32
- private applyService: BaseApplyService;
23
+ @Autowired(CreateNewFileWithTextHandler)
24
+ private readonly createNewFileWithTextHandler: CreateNewFileWithTextHandler;
33
25
 
34
26
  registerMCPServer(registry: IMCPServerRegistry): void {
35
27
  registry.registerMCPTool(this.getToolDefinition());
@@ -55,39 +47,11 @@ export class CreateNewFileWithTextTool implements MCPServerContribution {
55
47
 
56
48
  private async handler(args: z.infer<typeof inputSchema> & { toolCallId: string }, logger: MCPLogger) {
57
49
  try {
58
- // 获取工作区根目录
59
- const workspaceRoots = this.workspaceService.tryGetRoots();
60
- if (!workspaceRoots || workspaceRoots.length === 0) {
61
- logger.appendLine('Error: Cannot determine project directory');
62
- return {
63
- content: [{ type: 'text', text: "can't find project dir" }],
64
- isError: true,
65
- };
66
- }
67
-
68
- // 构建完整的文件路径
69
- const rootUri = URI.parse(workspaceRoots[0].uri);
70
- const fullPath = path.join(rootUri.codeUri.fsPath, args.targetFile);
71
- const fileUri = URI.file(fullPath);
72
-
73
- // 创建父目录
74
- const parentDir = path.dirname(fullPath);
75
- const parentUri = URI.file(parentDir);
76
- await this.fileService.createFolder(parentUri.toString());
77
-
78
- // 创建文件
79
- await this.fileService.createFile(fileUri.toString());
80
-
81
- // 使用 applyService 写入文件内容
82
- const codeBlock = await this.applyService.registerCodeBlock(args.targetFile, args.codeEdit, args.toolCallId);
83
- await this.applyService.apply(codeBlock);
84
-
85
- logger.appendLine(`Successfully created file at: ${args.targetFile}`);
50
+ await this.createNewFileWithTextHandler.handler(args, args.toolCallId, logger);
86
51
  return {
87
- content: [{ type: 'text', text: 'ok' }],
52
+ content: [{ type: 'text', text: 'create file with text success' }],
88
53
  };
89
54
  } catch (error) {
90
- logger.appendLine(`Error during file creation: ${error}`);
91
55
  return {
92
56
  content: [{ type: 'text', text: error.message }],
93
57
  isError: true,
@@ -0,0 +1,55 @@
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
+ }