@opensumi/ide-ai-native 3.7.2-next-1740066619.0 → 3.7.2-next-1740323956.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.
Files changed (250) hide show
  1. package/lib/browser/ai-core.contribution.d.ts.map +1 -1
  2. package/lib/browser/ai-core.contribution.js +4 -0
  3. package/lib/browser/ai-core.contribution.js.map +1 -1
  4. package/lib/browser/chat/chat-agent.service.d.ts.map +1 -1
  5. package/lib/browser/chat/chat-agent.service.js +6 -0
  6. package/lib/browser/chat/chat-agent.service.js.map +1 -1
  7. package/lib/browser/chat/chat-model.d.ts.map +1 -1
  8. package/lib/browser/chat/chat-model.js +5 -23
  9. package/lib/browser/chat/chat-model.js.map +1 -1
  10. package/lib/browser/chat/chat-proxy.service.d.ts +1 -0
  11. package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
  12. package/lib/browser/chat/chat-proxy.service.js +8 -1
  13. package/lib/browser/chat/chat-proxy.service.js.map +1 -1
  14. package/lib/browser/chat/chat.internal.service.d.ts +4 -0
  15. package/lib/browser/chat/chat.internal.service.d.ts.map +1 -1
  16. package/lib/browser/chat/chat.internal.service.js +10 -1
  17. package/lib/browser/chat/chat.internal.service.js.map +1 -1
  18. package/lib/browser/chat/chat.view.d.ts.map +1 -1
  19. package/lib/browser/chat/chat.view.js +2 -2
  20. package/lib/browser/chat/chat.view.js.map +1 -1
  21. package/lib/browser/components/ChatContext/index.d.ts.map +1 -1
  22. package/lib/browser/components/ChatContext/index.js +18 -2
  23. package/lib/browser/components/ChatContext/index.js.map +1 -1
  24. package/lib/browser/components/ChatContext/style.module.less +12 -0
  25. package/lib/browser/components/ChatEditor.d.ts +1 -0
  26. package/lib/browser/components/ChatEditor.d.ts.map +1 -1
  27. package/lib/browser/components/ChatEditor.js +3 -3
  28. package/lib/browser/components/ChatEditor.js.map +1 -1
  29. package/lib/browser/components/ChatMarkdown.d.ts +1 -0
  30. package/lib/browser/components/ChatMarkdown.d.ts.map +1 -1
  31. package/lib/browser/components/ChatMarkdown.js +2 -2
  32. package/lib/browser/components/ChatMarkdown.js.map +1 -1
  33. package/lib/browser/components/ChatReply.d.ts.map +1 -1
  34. package/lib/browser/components/ChatReply.js +6 -8
  35. package/lib/browser/components/ChatReply.js.map +1 -1
  36. package/lib/browser/components/ChatToolRender.d.ts +1 -0
  37. package/lib/browser/components/ChatToolRender.d.ts.map +1 -1
  38. package/lib/browser/components/ChatToolRender.js +25 -7
  39. package/lib/browser/components/ChatToolRender.js.map +1 -1
  40. package/lib/browser/components/components.module.less +3 -2
  41. package/lib/browser/context/llm-context.service.d.ts +1 -0
  42. package/lib/browser/context/llm-context.service.d.ts.map +1 -1
  43. package/lib/browser/context/llm-context.service.js +24 -18
  44. package/lib/browser/context/llm-context.service.js.map +1 -1
  45. package/lib/browser/index.d.ts.map +1 -1
  46. package/lib/browser/index.js +11 -12
  47. package/lib/browser/index.js.map +1 -1
  48. package/lib/browser/mcp/base-apply.service.d.ts +67 -0
  49. package/lib/browser/mcp/base-apply.service.d.ts.map +1 -0
  50. package/lib/browser/mcp/base-apply.service.js +290 -0
  51. package/lib/browser/mcp/base-apply.service.js.map +1 -0
  52. package/lib/browser/mcp/mcp-server-proxy.service.d.ts +6 -1
  53. package/lib/browser/mcp/mcp-server-proxy.service.d.ts.map +1 -1
  54. package/lib/browser/mcp/mcp-server-proxy.service.js +2 -1
  55. package/lib/browser/mcp/mcp-server-proxy.service.js.map +1 -1
  56. package/lib/browser/mcp/mcp-server.feature.registry.d.ts +5 -1
  57. package/lib/browser/mcp/mcp-server.feature.registry.d.ts.map +1 -1
  58. package/lib/browser/mcp/mcp-server.feature.registry.js +17 -1
  59. package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
  60. package/lib/browser/mcp/tools/components/EditFile.d.ts +3 -0
  61. package/lib/browser/mcp/tools/components/EditFile.d.ts.map +1 -0
  62. package/lib/browser/mcp/tools/components/EditFile.js +101 -0
  63. package/lib/browser/mcp/tools/components/EditFile.js.map +1 -0
  64. package/lib/browser/mcp/tools/components/SearchResult.d.ts +11 -0
  65. package/lib/browser/mcp/tools/components/SearchResult.d.ts.map +1 -0
  66. package/lib/browser/mcp/tools/components/SearchResult.js +60 -0
  67. package/lib/browser/mcp/tools/components/SearchResult.js.map +1 -0
  68. package/lib/browser/mcp/tools/components/index.module.less +132 -0
  69. package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
  70. package/lib/browser/mcp/tools/createNewFileWithText.js +1 -2
  71. package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
  72. package/lib/browser/mcp/tools/{getSelectedText.d.ts → editFile.d.ts} +3 -3
  73. package/lib/browser/mcp/tools/editFile.d.ts.map +1 -0
  74. package/lib/browser/mcp/tools/editFile.js +95 -0
  75. package/lib/browser/mcp/tools/editFile.js.map +1 -0
  76. package/lib/browser/mcp/tools/{findFilesByNameSubstring.d.ts → fileSearch.d.ts} +3 -2
  77. package/lib/browser/mcp/tools/fileSearch.d.ts.map +1 -0
  78. package/lib/browser/mcp/tools/fileSearch.js +94 -0
  79. package/lib/browser/mcp/tools/fileSearch.js.map +1 -0
  80. package/lib/browser/mcp/tools/getDiagnosticsByPath.d.ts.map +1 -1
  81. package/lib/browser/mcp/tools/getDiagnosticsByPath.js +1 -2
  82. package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
  83. package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.d.ts.map +1 -1
  84. package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js +1 -2
  85. package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
  86. package/lib/browser/mcp/tools/{getFileTextByPath.d.ts → grepSearch.d.ts} +4 -3
  87. package/lib/browser/mcp/tools/grepSearch.d.ts.map +1 -0
  88. package/lib/browser/mcp/tools/grepSearch.js +118 -0
  89. package/lib/browser/mcp/tools/grepSearch.js.map +1 -0
  90. package/lib/browser/mcp/tools/handlers/EditFile.d.ts +10 -0
  91. package/lib/browser/mcp/tools/handlers/EditFile.d.ts.map +1 -0
  92. package/lib/browser/mcp/tools/handlers/EditFile.js +28 -0
  93. package/lib/browser/mcp/tools/handlers/EditFile.js.map +1 -0
  94. package/lib/browser/mcp/tools/handlers/ReadFile.d.ts +6 -0
  95. package/lib/browser/mcp/tools/handlers/ReadFile.d.ts.map +1 -1
  96. package/lib/browser/mcp/tools/handlers/ReadFile.js +14 -0
  97. package/lib/browser/mcp/tools/handlers/ReadFile.js.map +1 -1
  98. package/lib/browser/mcp/tools/handlers/utils.d.ts +2 -0
  99. package/lib/browser/mcp/tools/handlers/utils.d.ts.map +1 -0
  100. package/lib/browser/mcp/tools/handlers/utils.js +7 -0
  101. package/lib/browser/mcp/tools/handlers/utils.js.map +1 -0
  102. package/lib/browser/mcp/tools/listDir.d.ts.map +1 -1
  103. package/lib/browser/mcp/tools/listDir.js +3 -4
  104. package/lib/browser/mcp/tools/listDir.js.map +1 -1
  105. package/lib/browser/mcp/tools/readFile.d.ts.map +1 -1
  106. package/lib/browser/mcp/tools/readFile.js +3 -4
  107. package/lib/browser/mcp/tools/readFile.js.map +1 -1
  108. package/lib/browser/mcp/tools/runTerminalCmd.d.ts.map +1 -1
  109. package/lib/browser/mcp/tools/runTerminalCmd.js +1 -2
  110. package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
  111. package/lib/browser/model/msg-history-manager.d.ts +5 -0
  112. package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
  113. package/lib/browser/model/msg-history-manager.js +14 -0
  114. package/lib/browser/model/msg-history-manager.js.map +1 -1
  115. package/lib/browser/preferences/schema.d.ts.map +1 -1
  116. package/lib/browser/preferences/schema.js +5 -0
  117. package/lib/browser/preferences/schema.js.map +1 -1
  118. package/lib/browser/types.d.ts +14 -10
  119. package/lib/browser/types.d.ts.map +1 -1
  120. package/lib/browser/types.js +1 -2
  121. package/lib/browser/types.js.map +1 -1
  122. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts +1 -0
  123. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.d.ts.map +1 -1
  124. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js +3 -0
  125. package/lib/browser/widget/inline-stream-diff/inline-stream-diff.handler.js.map +1 -1
  126. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts +4 -0
  127. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
  128. package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
  129. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.d.ts.map +1 -1
  130. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js +1 -0
  131. package/lib/browser/widget/inline-stream-diff/live-preview.decoration.js.map +1 -1
  132. package/lib/common/index.d.ts +1 -0
  133. package/lib/common/index.d.ts.map +1 -1
  134. package/lib/common/index.js.map +1 -1
  135. package/lib/common/mcp-server-manager.d.ts +1 -1
  136. package/lib/common/mcp-server-manager.d.ts.map +1 -1
  137. package/lib/common/mcp-server-manager.js.map +1 -1
  138. package/lib/common/prompts/context-prompt-provider.d.ts +14 -0
  139. package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -0
  140. package/lib/common/prompts/context-prompt-provider.js +38 -0
  141. package/lib/common/prompts/context-prompt-provider.js.map +1 -0
  142. package/lib/common/tool-invocation-registry.d.ts +2 -1
  143. package/lib/common/tool-invocation-registry.d.ts.map +1 -1
  144. package/lib/common/tool-invocation-registry.js.map +1 -1
  145. package/lib/common/utils.d.ts +1 -0
  146. package/lib/common/utils.d.ts.map +1 -1
  147. package/lib/common/utils.js +3 -1
  148. package/lib/common/utils.js.map +1 -1
  149. package/lib/node/base-language-model.d.ts +2 -2
  150. package/lib/node/base-language-model.d.ts.map +1 -1
  151. package/lib/node/base-language-model.js +9 -5
  152. package/lib/node/base-language-model.js.map +1 -1
  153. package/lib/node/mcp/sumi-mcp-server.d.ts +1 -1
  154. package/lib/node/mcp/sumi-mcp-server.d.ts.map +1 -1
  155. package/lib/node/mcp/sumi-mcp-server.js +5 -2
  156. package/lib/node/mcp/sumi-mcp-server.js.map +1 -1
  157. package/lib/node/mcp-server-manager-impl.d.ts +1 -1
  158. package/lib/node/mcp-server-manager-impl.d.ts.map +1 -1
  159. package/lib/node/mcp-server-manager-impl.js +6 -5
  160. package/lib/node/mcp-server-manager-impl.js.map +1 -1
  161. package/lib/node/mcp-server.d.ts +2 -2
  162. package/lib/node/mcp-server.d.ts.map +1 -1
  163. package/lib/node/mcp-server.js +2 -1
  164. package/lib/node/mcp-server.js.map +1 -1
  165. package/lib/node/openai/openai-language-model.d.ts +1 -1
  166. package/lib/node/openai/openai-language-model.d.ts.map +1 -1
  167. package/lib/node/openai/openai-language-model.js +2 -2
  168. package/lib/node/openai/openai-language-model.js.map +1 -1
  169. package/package.json +24 -25
  170. package/src/browser/ai-core.contribution.ts +4 -0
  171. package/src/browser/chat/chat-agent.service.ts +7 -0
  172. package/src/browser/chat/chat-model.ts +0 -2
  173. package/src/browser/chat/chat-proxy.service.ts +12 -2
  174. package/src/browser/chat/chat.internal.service.ts +12 -1
  175. package/src/browser/chat/chat.view.tsx +2 -1
  176. package/src/browser/components/ChatContext/index.tsx +19 -3
  177. package/src/browser/components/ChatContext/style.module.less +12 -0
  178. package/src/browser/components/ChatEditor.tsx +13 -10
  179. package/src/browser/components/ChatMarkdown.tsx +3 -1
  180. package/src/browser/components/ChatReply.tsx +8 -15
  181. package/src/browser/components/ChatToolRender.tsx +36 -17
  182. package/src/browser/components/components.module.less +3 -2
  183. package/src/browser/context/llm-context.service.ts +30 -18
  184. package/src/browser/index.ts +11 -12
  185. package/src/browser/mcp/base-apply.service.ts +349 -0
  186. package/src/browser/mcp/mcp-server-proxy.service.ts +4 -2
  187. package/src/browser/mcp/mcp-server.feature.registry.ts +27 -4
  188. package/src/browser/mcp/tools/components/EditFile.tsx +144 -0
  189. package/src/browser/mcp/tools/components/SearchResult.tsx +92 -0
  190. package/src/browser/mcp/tools/components/index.module.less +132 -0
  191. package/src/browser/mcp/tools/createNewFileWithText.ts +1 -2
  192. package/src/browser/mcp/tools/editFile.ts +100 -0
  193. package/src/browser/mcp/tools/fileSearch.ts +99 -0
  194. package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -2
  195. package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -2
  196. package/src/browser/mcp/tools/grepSearch.ts +121 -0
  197. package/src/browser/mcp/tools/handlers/EditFile.ts +21 -0
  198. package/src/browser/mcp/tools/handlers/ReadFile.ts +19 -1
  199. package/src/browser/mcp/tools/handlers/utils.ts +3 -0
  200. package/src/browser/mcp/tools/listDir.ts +3 -4
  201. package/src/browser/mcp/tools/readFile.ts +3 -4
  202. package/src/browser/mcp/tools/runTerminalCmd.ts +1 -2
  203. package/src/browser/model/msg-history-manager.ts +19 -0
  204. package/src/browser/preferences/schema.ts +5 -0
  205. package/src/browser/types.ts +15 -11
  206. package/src/browser/widget/inline-stream-diff/inline-stream-diff.handler.tsx +4 -0
  207. package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +4 -0
  208. package/src/browser/widget/inline-stream-diff/live-preview.decoration.tsx +1 -0
  209. package/src/common/index.ts +1 -0
  210. package/src/common/mcp-server-manager.ts +18 -13
  211. package/src/common/prompts/context-prompt-provider.ts +46 -0
  212. package/src/common/tool-invocation-registry.ts +122 -124
  213. package/src/common/utils.ts +2 -0
  214. package/src/node/base-language-model.ts +20 -6
  215. package/src/node/mcp/sumi-mcp-server.ts +5 -2
  216. package/src/node/mcp-server-manager-impl.ts +13 -5
  217. package/src/node/mcp-server.ts +3 -2
  218. package/src/node/openai/openai-language-model.ts +2 -2
  219. package/lib/browser/mcp/tools/findFilesByNameSubstring.d.ts.map +0 -1
  220. package/lib/browser/mcp/tools/findFilesByNameSubstring.js +0 -92
  221. package/lib/browser/mcp/tools/findFilesByNameSubstring.js.map +0 -1
  222. package/lib/browser/mcp/tools/getCurrentFilePath.d.ts +0 -8
  223. package/lib/browser/mcp/tools/getCurrentFilePath.d.ts.map +0 -1
  224. package/lib/browser/mcp/tools/getCurrentFilePath.js +0 -49
  225. package/lib/browser/mcp/tools/getCurrentFilePath.js.map +0 -1
  226. package/lib/browser/mcp/tools/getFileTextByPath.d.ts.map +0 -1
  227. package/lib/browser/mcp/tools/getFileTextByPath.js +0 -97
  228. package/lib/browser/mcp/tools/getFileTextByPath.js.map +0 -1
  229. package/lib/browser/mcp/tools/getOpenEditorFileText.d.ts +0 -8
  230. package/lib/browser/mcp/tools/getOpenEditorFileText.d.ts.map +0 -1
  231. package/lib/browser/mcp/tools/getOpenEditorFileText.js +0 -50
  232. package/lib/browser/mcp/tools/getOpenEditorFileText.js.map +0 -1
  233. package/lib/browser/mcp/tools/getSelectedText.d.ts.map +0 -1
  234. package/lib/browser/mcp/tools/getSelectedText.js +0 -57
  235. package/lib/browser/mcp/tools/getSelectedText.js.map +0 -1
  236. package/lib/browser/mcp/tools/replaceOpenEditorFile.d.ts +0 -8
  237. package/lib/browser/mcp/tools/replaceOpenEditorFile.d.ts.map +0 -1
  238. package/lib/browser/mcp/tools/replaceOpenEditorFile.js +0 -79
  239. package/lib/browser/mcp/tools/replaceOpenEditorFile.js.map +0 -1
  240. package/lib/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.d.ts +0 -8
  241. package/lib/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.d.ts.map +0 -1
  242. package/lib/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.js +0 -84
  243. package/lib/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.js.map +0 -1
  244. package/src/browser/mcp/tools/findFilesByNameSubstring.ts +0 -93
  245. package/src/browser/mcp/tools/getCurrentFilePath.ts +0 -49
  246. package/src/browser/mcp/tools/getFileTextByPath.ts +0 -97
  247. package/src/browser/mcp/tools/getOpenEditorFileText.ts +0 -50
  248. package/src/browser/mcp/tools/getSelectedText.ts +0 -57
  249. package/src/browser/mcp/tools/replaceOpenEditorFile.ts +0 -80
  250. package/src/browser/mcp/tools/replaceOpenEditorFileByDiffPreviewer.ts +0 -91
@@ -8,10 +8,14 @@ type IExcludeMessage = Omit<IHistoryChatMessage, 'id' | 'order'>;
8
8
  @Injectable({ multiple: false })
9
9
  export class MsgHistoryManager extends Disposable {
10
10
  private messageMap: Map<string, IHistoryChatMessage> = new Map();
11
+ private messageAdditionalMap: Map<string, Record<string, any>> = new Map();
11
12
 
12
13
  private readonly _onMessageChange = new Emitter<IHistoryChatMessage[]>();
13
14
  public readonly onMessageChange: Event<IHistoryChatMessage[]> = this._onMessageChange.event;
14
15
 
16
+ private readonly _onMessageAdditionalChange = new Emitter<Record<string, any>>();
17
+ public readonly onMessageAdditionalChange: Event<Record<string, any>> = this._onMessageAdditionalChange.event;
18
+
15
19
  override dispose(): void {
16
20
  this.clearMessages();
17
21
  super.dispose();
@@ -19,6 +23,7 @@ export class MsgHistoryManager extends Disposable {
19
23
 
20
24
  public clearMessages() {
21
25
  this.messageMap.clear();
26
+ this.messageAdditionalMap.clear();
22
27
  }
23
28
 
24
29
  private doAddMessage(message: IExcludeMessage): string {
@@ -70,4 +75,18 @@ export class MsgHistoryManager extends Disposable {
70
75
  content: message.content,
71
76
  });
72
77
  }
78
+
79
+ public setMessageAdditional(id: string, additional: Record<string, any>) {
80
+ if (!this.messageMap.has(id)) {
81
+ return;
82
+ }
83
+
84
+ this.messageAdditionalMap.set(id, additional);
85
+
86
+ this._onMessageAdditionalChange.fire(additional);
87
+ }
88
+
89
+ public getMessageAdditional(id: string): Record<string, any> {
90
+ return this.messageAdditionalMap.get(id) || {};
91
+ }
73
92
  }
@@ -122,5 +122,10 @@ export const aiNativePreferenceSchema: PreferenceSchema = {
122
122
  type: 'boolean',
123
123
  default: false,
124
124
  },
125
+ [AINativeSettingSectionsId.SystemPrompt]: {
126
+ type: 'string',
127
+ default: '',
128
+ description: localize('preference.ai.native.chat.system.prompt.description'),
129
+ },
125
130
  },
126
131
  };
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { ZodSchema } from 'zod';
2
3
 
3
4
  import { AIActionItem } from '@opensumi/ide-core-browser/lib/components/ai-native/index';
4
5
  import {
@@ -349,8 +350,9 @@ export interface MCPLogger {
349
350
 
350
351
  export interface MCPToolDefinition {
351
352
  name: string;
353
+ label?: string;
352
354
  description: string;
353
- inputSchema: any; // JSON Schema
355
+ inputSchema: ZodSchema<any>; // JSON Schema
354
356
  handler: (
355
357
  args: any,
356
358
  logger: MCPLogger,
@@ -360,9 +362,21 @@ export interface MCPToolDefinition {
360
362
  }>;
361
363
  }
362
364
 
365
+ export interface IMCPServerToolComponentProps {
366
+ state?: 'streaming-start' | 'streaming' | 'complete' | 'result';
367
+ args?: Record<string, any>;
368
+ result?: any;
369
+ index?: number;
370
+ messageId?: string;
371
+ toolCallId?: string;
372
+ }
373
+
363
374
  export interface IMCPServerRegistry {
364
375
  registerMCPTool(tool: MCPToolDefinition): void;
365
376
  getMCPTools(): MCPToolDefinition[];
377
+ getMCPTool(name: string): MCPToolDefinition | undefined;
378
+ registerToolComponent(name: string, component: React.FC<IMCPServerToolComponentProps>): void;
379
+ getToolComponent(name: string): React.FC<IMCPServerToolComponentProps> | undefined;
366
380
  callMCPTool(
367
381
  name: string,
368
382
  args: any,
@@ -405,13 +419,3 @@ export interface IAIMiddleware {
405
419
  provideInlineCompletions?: IProvideInlineCompletionsSignature;
406
420
  };
407
421
  }
408
-
409
- export const ChatAgentPromptProvider = Symbol('ChatAgentPromptProvider');
410
-
411
- export interface ChatAgentPromptProvider {
412
- /**
413
- * 提供上下文提示
414
- * @param context 上下文
415
- */
416
- provideContextPrompt(context: SerializedContext, userMessage: string): MaybePromise<string>;
417
- }
@@ -69,6 +69,10 @@ export class InlineStreamDiffHandler extends Disposable implements IInlineDiffPr
69
69
 
70
70
  public livePreviewDiffDecorationModel: LivePreviewDiffDecorationModel;
71
71
 
72
+ public get uri() {
73
+ return this.originalModel.uri;
74
+ }
75
+
72
76
  constructor(private readonly monacoEditor: ICodeEditor) {
73
77
  super();
74
78
 
@@ -65,6 +65,10 @@ export interface IPartialEditEvent {
65
65
  * 已添加行数
66
66
  */
67
67
  totalAddedLinesCount: number;
68
+ /**
69
+ * 已采纳的个数
70
+ */
71
+ acceptPartialEditCount: number;
68
72
  /**
69
73
  * 已删除行数
70
74
  */
@@ -426,6 +426,7 @@ export class LivePreviewDiffDecorationModel extends Disposable {
426
426
  uri: this.model.uri,
427
427
  totalPartialEditCount: this.partialEditWidgetList.length,
428
428
  resolvedPartialEditCount: this.partialEditWidgetList.filter((w) => w.isHidden).length,
429
+ acceptPartialEditCount: this.partialEditWidgetList.filter((w) => w.isAccepted).length,
429
430
  currentPartialEdit: {
430
431
  addedLinesCount,
431
432
  deletedLinesCount,
@@ -179,6 +179,7 @@ export interface IChatAgentMetadata {
179
179
  fullName?: string;
180
180
  icon?: Uri;
181
181
  iconDark?: Uri;
182
+ systemPrompt?: string;
182
183
  }
183
184
 
184
185
  export interface IChatAgentRequest {
@@ -1,19 +1,24 @@
1
1
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
2
 
3
3
  export interface MCPServerManager {
4
- callTool(serverName: string, toolName: string, arg_string: string): ReturnType<Client['callTool']>;
5
- removeServer(name: string): void;
6
- addOrUpdateServer(description: MCPServerDescription): void;
7
- // invoke in node.js only
8
- addOrUpdateServerDirectly(server: any): void;
9
- initBuiltinServer(builtinMCPServer: any): void;
10
- getTools(serverName: string): ReturnType<Client['listTools']>;
11
- getServerNames(): Promise<string[]>;
12
- startServer(serverName: string): Promise<void>;
13
- stopServer(serverName: string): Promise<void>;
14
- getStartedServers(): Promise<string[]>;
15
- registerTools(serverName: string): Promise<void>;
16
- addExternalMCPServers(servers: MCPServerDescription[]): void;
4
+ callTool(
5
+ serverName: string,
6
+ toolName: string,
7
+ toolCallId: string,
8
+ arg_string: string,
9
+ ): ReturnType<Client['callTool']>;
10
+ removeServer(name: string): void;
11
+ addOrUpdateServer(description: MCPServerDescription): void;
12
+ // invoke in node.js only
13
+ addOrUpdateServerDirectly(server: any): void;
14
+ initBuiltinServer(builtinMCPServer: any): void;
15
+ getTools(serverName: string): ReturnType<Client['listTools']>;
16
+ getServerNames(): Promise<string[]>;
17
+ startServer(serverName: string): Promise<void>;
18
+ stopServer(serverName: string): Promise<void>;
19
+ getStartedServers(): Promise<string[]>;
20
+ registerTools(serverName: string): Promise<void>;
21
+ addExternalMCPServers(servers: MCPServerDescription[]): void;
17
22
  }
18
23
 
19
24
  export type MCPTool = Awaited<ReturnType<MCPServerManager['getTools']>>['tools'][number];
@@ -0,0 +1,46 @@
1
+ import { Injectable } from '@opensumi/di';
2
+ import { MaybePromise } from '@opensumi/ide-core-common/lib/utils';
3
+
4
+ import { SerializedContext } from '../llm-context';
5
+
6
+ export const ChatAgentPromptProvider = Symbol('ChatAgentPromptProvider');
7
+
8
+ export interface ChatAgentPromptProvider {
9
+ /**
10
+ * 提供上下文提示
11
+ * @param context 上下文
12
+ */
13
+ provideContextPrompt(context: SerializedContext, userMessage: string): MaybePromise<string>;
14
+ }
15
+
16
+ @Injectable()
17
+ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
18
+ provideContextPrompt(context: SerializedContext, userMessage: string): MaybePromise<string> {
19
+ return `
20
+ <additional_data>
21
+ Below are some potentially helpful/relevant pieces of information for figuring out to respond
22
+ <recently_viewed_files>
23
+ ${context.recentlyViewFiles.map((file, idx) => `${idx + 1} : ${file}`)}
24
+ </recently_viewed_files>
25
+ <attached_files>
26
+ ${context.attachedFiles.map(
27
+ (file) =>
28
+ `
29
+ <file_contents>
30
+ \`\`\`${file.language} ${file.path}
31
+ ${file.content}
32
+ \`\`\`
33
+ </file_contents>
34
+ <linter_errors>
35
+ ${file.lineErrors.join('\n')}
36
+ </linter_errors>
37
+ `,
38
+ )}
39
+
40
+ </attached_files>
41
+ </additional_data>
42
+ <user_query>
43
+ ${userMessage}
44
+ </user_query>`;
45
+ }
46
+ }
@@ -1,33 +1,32 @@
1
+ import { ToolExecutionOptions } from 'ai';
1
2
  import { z } from 'zod';
2
3
 
3
4
  import { Injectable } from '@opensumi/di';
4
5
 
5
- import { MCPToolParameter } from './mcp-server-manager';
6
-
7
6
  export const ToolParameterSchema = z.object({
8
- type: z.enum(['string', 'number', 'boolean', 'object', 'array']),
9
- description: z.string().optional(),
10
- enum: z.array(z.any()).optional(),
11
- items: z.lazy(() => ToolParameterSchema).optional(),
12
- properties: z.record(z.lazy(() => ToolParameterSchema)).optional(),
13
- required: z.array(z.string()).optional(),
7
+ type: z.enum(['string', 'number', 'boolean', 'object', 'array']),
8
+ description: z.string().optional(),
9
+ enum: z.array(z.any()).optional(),
10
+ items: z.lazy(() => ToolParameterSchema).optional(),
11
+ properties: z.record(z.lazy(() => ToolParameterSchema)).optional(),
12
+ required: z.array(z.string()).optional(),
14
13
  });
15
14
 
16
15
  export type ToolParameter = z.infer<typeof ToolParameterSchema>;
17
16
 
18
17
  export interface ToolRequest {
19
- id: string;
20
- name: string;
21
- parameters?: any;
22
- description?: string;
23
- handler: (arg_string: string) => Promise<any>;
24
- providerName?: string;
18
+ id: string;
19
+ name: string;
20
+ parameters?: any;
21
+ description?: string;
22
+ handler: (arg_string: string, options?: ToolExecutionOptions) => Promise<any>;
23
+ providerName?: string;
25
24
  }
26
25
 
27
26
  export namespace ToolRequest {
28
- export function isToolParameter(obj: unknown): obj is ToolParameter {
29
- return ToolParameterSchema.safeParse(obj).success;
30
- }
27
+ export function isToolParameter(obj: unknown): obj is ToolParameter {
28
+ return ToolParameterSchema.safeParse(obj).success;
29
+ }
31
30
  }
32
31
 
33
32
  export const ToolInvocationRegistry = Symbol('ToolInvocationRegistry');
@@ -36,135 +35,134 @@ export const ToolInvocationRegistry = Symbol('ToolInvocationRegistry');
36
35
  * 为 Agent 提供的所有可用函数调用的注册表
37
36
  */
38
37
  export interface ToolInvocationRegistry {
39
- /**
40
- * 在注册表中注册一个工具
41
- *
42
- * @param tool - 要注册的 `ToolRequest` 对象
43
- */
44
- registerTool(tool: ToolRequest): void;
45
-
46
- /**
47
- * 从注册表中获取特定的 `ToolRequest`
48
- *
49
- * @param toolId - 要获取的工具的唯一标识符
50
- * @returns 对应提供的工具 ID 的 `ToolRequest` 对象,
51
- * 如果在注册表中找不到该工具,则返回 `undefined`
52
- */
53
- getFunction(toolId: string): ToolRequest | undefined;
54
-
55
- /**
56
- * 从注册表中获取多个 `ToolRequest`
57
- *
58
- * @param toolIds - 要获取的工具 ID 列表
59
- * @returns 指定工具 ID 的 `ToolRequest` 对象数组
60
- * 如果找不到某个工具 ID,将在返回的数组中跳过该工具
61
- */
62
- getFunctions(...toolIds: string[]): ToolRequest[];
63
-
64
- /**
65
- * 获取当前注册表中的所有 `ToolRequest`
66
- *
67
- * @returns 注册表中所有 `ToolRequest` 对象的数组
68
- */
69
- getAllFunctions(): ToolRequest[];
70
-
71
- /**
72
- * 注销特定工具提供者的所有工具
73
- *
74
- * @param providerName - 要移除其工具的工具提供者名称(在 `ToolRequest` 中指定)
75
- */
76
- unregisterAllTools(providerName: string): void;
38
+ /**
39
+ * 在注册表中注册一个工具
40
+ *
41
+ * @param tool - 要注册的 `ToolRequest` 对象
42
+ */
43
+ registerTool(tool: ToolRequest): void;
44
+
45
+ /**
46
+ * 从注册表中获取特定的 `ToolRequest`
47
+ *
48
+ * @param toolId - 要获取的工具的唯一标识符
49
+ * @returns 对应提供的工具 ID 的 `ToolRequest` 对象,
50
+ * 如果在注册表中找不到该工具,则返回 `undefined`
51
+ */
52
+ getFunction(toolId: string): ToolRequest | undefined;
53
+
54
+ /**
55
+ * 从注册表中获取多个 `ToolRequest`
56
+ *
57
+ * @param toolIds - 要获取的工具 ID 列表
58
+ * @returns 指定工具 ID 的 `ToolRequest` 对象数组
59
+ * 如果找不到某个工具 ID,将在返回的数组中跳过该工具
60
+ */
61
+ getFunctions(...toolIds: string[]): ToolRequest[];
62
+
63
+ /**
64
+ * 获取当前注册表中的所有 `ToolRequest`
65
+ *
66
+ * @returns 注册表中所有 `ToolRequest` 对象的数组
67
+ */
68
+ getAllFunctions(): ToolRequest[];
69
+
70
+ /**
71
+ * 注销特定工具提供者的所有工具
72
+ *
73
+ * @param providerName - 要移除其工具的工具提供者名称(在 `ToolRequest` 中指定)
74
+ */
75
+ unregisterAllTools(providerName: string): void;
77
76
  }
78
77
 
79
78
  export const ToolProvider = Symbol('ToolProvider');
80
79
  export interface ToolProvider {
81
- getTool(): ToolRequest;
80
+ getTool(): ToolRequest;
82
81
  }
83
82
 
84
83
  export class ToolInvocationRegistryImpl implements ToolInvocationRegistry {
85
- private tools: Map<string, ToolRequest> = new Map<string, ToolRequest>();
86
-
87
- unregisterAllTools(providerName: string): void {
88
- const toolsToRemove: string[] = [];
89
- for (const [id, tool] of this.tools.entries()) {
90
- if (tool.providerName === providerName) {
91
- toolsToRemove.push(id);
92
- }
93
- }
94
- toolsToRemove.forEach((id) => this.tools.delete(id));
95
- }
96
-
97
- getAllFunctions(): ToolRequest[] {
98
- return Array.from(this.tools.values());
84
+ private tools: Map<string, ToolRequest> = new Map<string, ToolRequest>();
85
+
86
+ unregisterAllTools(providerName: string): void {
87
+ const toolsToRemove: string[] = [];
88
+ for (const [id, tool] of this.tools.entries()) {
89
+ if (tool.providerName === providerName) {
90
+ toolsToRemove.push(id);
91
+ }
99
92
  }
100
-
101
- registerTool(tool: ToolRequest): void {
102
- if (this.tools.has(tool.id)) {
103
- // TODO: 使用适当的日志机制
104
- this.tools.set(tool.id, tool);
105
- } else {
106
- this.tools.set(tool.id, tool);
107
- }
108
- }
109
-
110
- getFunction(toolId: string): ToolRequest | undefined {
111
- return this.tools.get(toolId);
112
- }
113
-
114
- getFunctions(...toolIds: string[]): ToolRequest[] {
115
- const tools: ToolRequest[] = toolIds.map((toolId) => {
116
- const tool = this.tools.get(toolId);
117
- if (tool) {
118
- return tool;
119
- } else {
120
- throw new Error(`找不到 ID 为 ${toolId} 的函数`);
121
- }
122
- });
123
- return tools;
93
+ toolsToRemove.forEach((id) => this.tools.delete(id));
94
+ }
95
+
96
+ getAllFunctions(): ToolRequest[] {
97
+ return Array.from(this.tools.values());
98
+ }
99
+
100
+ registerTool(tool: ToolRequest): void {
101
+ if (this.tools.has(tool.id)) {
102
+ // TODO: 使用适当的日志机制
103
+ this.tools.set(tool.id, tool);
104
+ } else {
105
+ this.tools.set(tool.id, tool);
124
106
  }
107
+ }
108
+
109
+ getFunction(toolId: string): ToolRequest | undefined {
110
+ return this.tools.get(toolId);
111
+ }
112
+
113
+ getFunctions(...toolIds: string[]): ToolRequest[] {
114
+ const tools: ToolRequest[] = toolIds.map((toolId) => {
115
+ const tool = this.tools.get(toolId);
116
+ if (tool) {
117
+ return tool;
118
+ } else {
119
+ throw new Error(`找不到 ID 为 ${toolId} 的函数`);
120
+ }
121
+ });
122
+ return tools;
123
+ }
125
124
  }
126
125
 
127
126
  /**
128
127
  * 管理多个 ToolInvocationRegistry 实例的管理器,每个实例与一个 clientId 关联
129
128
  */
130
129
  export interface IToolInvocationRegistryManager {
131
- /**
132
- * 获取或创建特定 clientId 的 ToolInvocationRegistry
133
- */
134
- getRegistry(clientId: string): ToolInvocationRegistry;
135
-
136
- /**
137
- * 移除特定 clientId 的 ToolInvocationRegistry
138
- */
139
- removeRegistry(clientId: string): void;
140
-
141
- /**
142
- * 检查特定 clientId 是否存在对应的注册表
143
- */
144
- hasRegistry(clientId: string): boolean;
130
+ /**
131
+ * 获取或创建特定 clientId 的 ToolInvocationRegistry
132
+ */
133
+ getRegistry(clientId: string): ToolInvocationRegistry;
134
+
135
+ /**
136
+ * 移除特定 clientId 的 ToolInvocationRegistry
137
+ */
138
+ removeRegistry(clientId: string): void;
139
+
140
+ /**
141
+ * 检查特定 clientId 是否存在对应的注册表
142
+ */
143
+ hasRegistry(clientId: string): boolean;
145
144
  }
146
145
 
147
146
  export const ToolInvocationRegistryManager = Symbol('ToolInvocationRegistryManager');
148
147
 
149
148
  @Injectable()
150
149
  export class ToolInvocationRegistryManagerImpl implements IToolInvocationRegistryManager {
151
- private registries: Map<string, ToolInvocationRegistry> = new Map();
152
-
153
- getRegistry(clientId: string): ToolInvocationRegistry {
154
- let registry = this.registries.get(clientId);
155
- if (!registry) {
156
- registry = new ToolInvocationRegistryImpl();
157
- this.registries.set(clientId, registry);
158
- }
159
- return registry;
160
- }
150
+ private registries: Map<string, ToolInvocationRegistry> = new Map();
161
151
 
162
- removeRegistry(clientId: string): void {
163
- this.registries.delete(clientId);
152
+ getRegistry(clientId: string): ToolInvocationRegistry {
153
+ let registry = this.registries.get(clientId);
154
+ if (!registry) {
155
+ registry = new ToolInvocationRegistryImpl();
156
+ this.registries.set(clientId, registry);
164
157
  }
158
+ return registry;
159
+ }
165
160
 
166
- hasRegistry(clientId: string): boolean {
167
- return this.registries.has(clientId);
168
- }
169
- }
161
+ removeRegistry(clientId: string): void {
162
+ this.registries.delete(clientId);
163
+ }
170
164
 
165
+ hasRegistry(clientId: string): boolean {
166
+ return this.registries.has(clientId);
167
+ }
168
+ }
@@ -48,3 +48,5 @@ export const extractCodeBlocks = (content: string): string => {
48
48
 
49
49
  return newContents.join('\n');
50
50
  };
51
+
52
+ export const getToolName = (toolName: string, serverName = 'sumi-builtin') => `mcp_${serverName}_${toolName}`;
@@ -1,4 +1,4 @@
1
- import { CoreMessage, jsonSchema, streamText, tool } from 'ai';
1
+ import { CoreMessage, ToolExecutionOptions, jsonSchema, streamText, tool } from 'ai';
2
2
 
3
3
  import { Autowired, Injectable } from '@opensumi/di';
4
4
  import { ChatMessageRole, IAIBackServiceOption, IChatMessage } from '@opensumi/ide-core-common';
@@ -52,6 +52,11 @@ export abstract class BaseLanguageModel {
52
52
  allFunctions,
53
53
  chatReadableStream,
54
54
  options.history || [],
55
+ options.modelId,
56
+ options.temperature,
57
+ options.topP,
58
+ options.topK,
59
+ options.providerOptions,
55
60
  cancellationToken,
56
61
  );
57
62
  }
@@ -61,11 +66,12 @@ export abstract class BaseLanguageModel {
61
66
  description: toolRequest.description || '',
62
67
  // TODO 这里应该是 z.object 而不是 JSON Schema
63
68
  parameters: jsonSchema(toolRequest.parameters),
64
- execute: async (args: any) => await toolRequest.handler(JSON.stringify(args)),
69
+ execute: async (args: any, options: ToolExecutionOptions) =>
70
+ await toolRequest.handler(JSON.stringify(args), options),
65
71
  });
66
72
  }
67
73
 
68
- protected abstract getModelIdentifier(provider: any): any;
74
+ protected abstract getModelIdentifier(provider: any, modelId?: string): any;
69
75
 
70
76
  protected async handleStreamingRequest(
71
77
  provider: any,
@@ -73,6 +79,11 @@ export abstract class BaseLanguageModel {
73
79
  tools: ToolRequest[],
74
80
  chatReadableStream: ChatReadableStream,
75
81
  history: IChatMessage[] = [],
82
+ modelId?: string,
83
+ temperature?: number,
84
+ topP?: number,
85
+ topK?: number,
86
+ providerOptions?: Record<string, any>,
76
87
  cancellationToken?: CancellationToken,
77
88
  ): Promise<any> {
78
89
  try {
@@ -92,15 +103,18 @@ export abstract class BaseLanguageModel {
92
103
  })),
93
104
  { role: 'user', content: request },
94
105
  ];
95
-
96
- const stream = await streamText({
97
- model: this.getModelIdentifier(provider),
106
+ const stream = streamText({
107
+ model: this.getModelIdentifier(provider, modelId),
98
108
  maxTokens: 4096,
99
109
  tools: aiTools,
100
110
  messages,
101
111
  abortSignal: abortController.signal,
102
112
  experimental_toolCallStreaming: true,
103
113
  maxSteps: 12,
114
+ temperature,
115
+ topP: topP || 0.8,
116
+ topK: topK || 1,
117
+ providerOptions,
104
118
  });
105
119
 
106
120
  for await (const chunk of stream.fullStream) {
@@ -156,7 +156,7 @@ export class BuiltinMCPServer implements IMCPServer {
156
156
  this.started = true;
157
157
  }
158
158
 
159
- async callTool(toolName: string, arg_string: string): Promise<any> {
159
+ async callTool(toolName: string, toolCallId: string, arg_string: string): Promise<any> {
160
160
  if (!this.started) {
161
161
  throw new Error('MCP Server not started');
162
162
  }
@@ -171,7 +171,10 @@ export class BuiltinMCPServer implements IMCPServer {
171
171
  );
172
172
  throw error;
173
173
  }
174
- return this.sumiMCPServer.callMCPTool(toolName, args);
174
+ return this.sumiMCPServer.callMCPTool(toolName, {
175
+ ...args,
176
+ toolCallId,
177
+ });
175
178
  }
176
179
 
177
180
  async getTools(): ReturnType<Client['listTools']> {
@@ -1,7 +1,10 @@
1
+ import { ToolExecutionOptions } from 'ai';
2
+
1
3
  import { ILogger } from '@opensumi/ide-core-common';
2
4
 
3
5
  import { MCPServerDescription, MCPServerManager, MCPTool } from '../common/mcp-server-manager';
4
6
  import { IToolInvocationRegistryManager, ToolRequest } from '../common/tool-invocation-registry';
7
+ import { getToolName } from '../common/utils';
5
8
 
6
9
  import { BuiltinMCPServer } from './mcp/sumi-mcp-server';
7
10
  import { IMCPServer, MCPServerImpl } from './mcp-server';
@@ -41,12 +44,17 @@ export class MCPServerManagerImpl implements MCPServerManager {
41
44
  return startedServers;
42
45
  }
43
46
 
44
- callTool(serverName: string, toolName: string, arg_string: string): ReturnType<IMCPServer['callTool']> {
47
+ callTool(
48
+ serverName: string,
49
+ toolName: string,
50
+ toolCallId: string,
51
+ arg_string: string,
52
+ ): ReturnType<IMCPServer['callTool']> {
45
53
  const server = this.servers.get(serverName);
46
54
  if (!server) {
47
55
  throw new Error(`MCP server "${toolName}" not found.`);
48
56
  }
49
- return server.callTool(toolName, arg_string);
57
+ return server.callTool(toolName, toolCallId, arg_string);
50
58
  }
51
59
 
52
60
  async startServer(serverName: string): Promise<void> {
@@ -62,7 +70,7 @@ export class MCPServerManagerImpl implements MCPServerManager {
62
70
  }
63
71
 
64
72
  private convertToToolRequest(tool: MCPTool, serverName: string): ToolRequest {
65
- const id = `mcp_${serverName}_${tool.name}`;
73
+ const id = getToolName(tool.name, serverName);
66
74
 
67
75
  return {
68
76
  id,
@@ -70,9 +78,9 @@ export class MCPServerManagerImpl implements MCPServerManager {
70
78
  providerName: serverName,
71
79
  parameters: tool.inputSchema,
72
80
  description: tool.description,
73
- handler: async (arg_string: string) => {
81
+ handler: async (arg_string: string, options?: ToolExecutionOptions) => {
74
82
  try {
75
- const res = await this.callTool(serverName, tool.name, arg_string);
83
+ const res = await this.callTool(serverName, tool.name, options?.toolCallId || '', arg_string);
76
84
  this.logger.debug(`[MCP: ${serverName}] ${tool.name} called with ${arg_string}`);
77
85
  this.logger.debug('Tool execution result:', res);
78
86
  return JSON.stringify(res);