@opensumi/ide-ai-native 3.9.1-next-1749175927.0 → 3.9.1-next-1749196667.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 (197) hide show
  1. package/lib/browser/ai-core.contribution.d.ts.map +1 -1
  2. package/lib/browser/ai-core.contribution.js +4 -9
  3. package/lib/browser/ai-core.contribution.js.map +1 -1
  4. package/lib/browser/chat/apply.service.d.ts +0 -3
  5. package/lib/browser/chat/apply.service.d.ts.map +1 -1
  6. package/lib/browser/chat/apply.service.js +0 -47
  7. package/lib/browser/chat/apply.service.js.map +1 -1
  8. package/lib/browser/chat/chat-manager.service.d.ts +0 -1
  9. package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
  10. package/lib/browser/chat/chat-manager.service.js +3 -9
  11. package/lib/browser/chat/chat-manager.service.js.map +1 -1
  12. package/lib/browser/chat/chat-model.d.ts +1 -8
  13. package/lib/browser/chat/chat-model.d.ts.map +1 -1
  14. package/lib/browser/chat/chat-model.js +76 -113
  15. package/lib/browser/chat/chat-model.js.map +1 -1
  16. package/lib/browser/chat/chat-proxy.service.d.ts +2 -0
  17. package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
  18. package/lib/browser/chat/chat-proxy.service.js +57 -50
  19. package/lib/browser/chat/chat-proxy.service.js.map +1 -1
  20. package/lib/browser/chat/chat.feature.registry.d.ts +1 -4
  21. package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
  22. package/lib/browser/chat/chat.feature.registry.js +0 -6
  23. package/lib/browser/chat/chat.feature.registry.js.map +1 -1
  24. package/lib/browser/chat/chat.view.d.ts.map +1 -1
  25. package/lib/browser/chat/chat.view.js +10 -51
  26. package/lib/browser/chat/chat.view.js.map +1 -1
  27. package/lib/browser/components/ChatEditor.js +2 -2
  28. package/lib/browser/components/ChatEditor.js.map +1 -1
  29. package/lib/browser/components/ChatHistory.d.ts.map +1 -1
  30. package/lib/browser/components/ChatHistory.js +1 -2
  31. package/lib/browser/components/ChatHistory.js.map +1 -1
  32. package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
  33. package/lib/browser/components/ChatMentionInput.js +28 -124
  34. package/lib/browser/components/ChatMentionInput.js.map +1 -1
  35. package/lib/browser/components/ChatToolRender.d.ts.map +1 -1
  36. package/lib/browser/components/ChatToolRender.js +2 -7
  37. package/lib/browser/components/ChatToolRender.js.map +1 -1
  38. package/lib/browser/components/ChatToolRender.module.less +0 -25
  39. package/lib/browser/components/components.module.less +0 -7
  40. package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
  41. package/lib/browser/components/mention-input/mention-input.js +13 -155
  42. package/lib/browser/components/mention-input/mention-input.js.map +1 -1
  43. package/lib/browser/components/mention-input/mention-input.module.less +0 -165
  44. package/lib/browser/components/mention-input/types.d.ts +1 -15
  45. package/lib/browser/components/mention-input/types.d.ts.map +1 -1
  46. package/lib/browser/components/mention-input/types.js +0 -1
  47. package/lib/browser/components/mention-input/types.js.map +1 -1
  48. package/lib/browser/components/utils.d.ts +2 -2
  49. package/lib/browser/context/llm-context.service.d.ts +2 -21
  50. package/lib/browser/context/llm-context.service.d.ts.map +1 -1
  51. package/lib/browser/context/llm-context.service.js +20 -162
  52. package/lib/browser/context/llm-context.service.js.map +1 -1
  53. package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.d.ts.map +1 -1
  54. package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.js.map +1 -1
  55. package/lib/browser/contrib/intelligent-completions/diff-computer.js +1 -1
  56. package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -1
  57. package/lib/browser/contrib/terminal/terminal.feature.registry.js.map +1 -1
  58. package/lib/browser/index.d.ts.map +1 -1
  59. package/lib/browser/index.js +0 -7
  60. package/lib/browser/index.js.map +1 -1
  61. package/lib/browser/layout/ai-layout.d.ts.map +1 -1
  62. package/lib/browser/layout/ai-layout.js +4 -6
  63. package/lib/browser/layout/ai-layout.js.map +1 -1
  64. package/lib/browser/layout/tabbar.view.d.ts +1 -1
  65. package/lib/browser/layout/tabbar.view.d.ts.map +1 -1
  66. package/lib/browser/layout/tabbar.view.js +12 -5
  67. package/lib/browser/layout/tabbar.view.js.map +1 -1
  68. package/lib/browser/mcp/base-apply.service.d.ts +4 -5
  69. package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
  70. package/lib/browser/mcp/base-apply.service.js +5 -23
  71. package/lib/browser/mcp/base-apply.service.js.map +1 -1
  72. package/lib/browser/mcp/mcp-server-proxy.service.d.ts +1 -3
  73. package/lib/browser/mcp/mcp-server-proxy.service.d.ts.map +1 -1
  74. package/lib/browser/mcp/mcp-server-proxy.service.js +0 -4
  75. package/lib/browser/mcp/mcp-server-proxy.service.js.map +1 -1
  76. package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
  77. package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
  78. package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
  79. package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
  80. package/lib/browser/model/msg-history-manager.d.ts +1 -47
  81. package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
  82. package/lib/browser/model/msg-history-manager.js +2 -127
  83. package/lib/browser/model/msg-history-manager.js.map +1 -1
  84. package/lib/browser/preferences/schema.d.ts.map +1 -1
  85. package/lib/browser/preferences/schema.js +0 -5
  86. package/lib/browser/preferences/schema.js.map +1 -1
  87. package/lib/browser/types.d.ts +1 -12
  88. package/lib/browser/types.d.ts.map +1 -1
  89. package/lib/browser/types.js.map +1 -1
  90. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
  91. package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
  92. package/lib/common/index.d.ts +1 -5
  93. package/lib/common/index.d.ts.map +1 -1
  94. package/lib/common/index.js +0 -2
  95. package/lib/common/index.js.map +1 -1
  96. package/lib/common/llm-context.d.ts +0 -19
  97. package/lib/common/llm-context.d.ts.map +1 -1
  98. package/lib/common/llm-context.js.map +1 -1
  99. package/lib/common/prompts/context-prompt-provider.d.ts +2 -0
  100. package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
  101. package/lib/common/prompts/context-prompt-provider.js +29 -35
  102. package/lib/common/prompts/context-prompt-provider.js.map +1 -1
  103. package/lib/common/types.d.ts +0 -21
  104. package/lib/common/types.d.ts.map +1 -1
  105. package/lib/common/types.js.map +1 -1
  106. package/lib/common/utils.d.ts +0 -1
  107. package/lib/common/utils.d.ts.map +1 -1
  108. package/lib/common/utils.js +2 -5
  109. package/lib/common/utils.js.map +1 -1
  110. package/lib/node/base-language-model.d.ts +1 -2
  111. package/lib/node/base-language-model.d.ts.map +1 -1
  112. package/lib/node/base-language-model.js +1 -10
  113. package/lib/node/base-language-model.js.map +1 -1
  114. package/lib/node/mcp/sumi-mcp-server.d.ts +1 -3
  115. package/lib/node/mcp/sumi-mcp-server.d.ts.map +1 -1
  116. package/lib/node/mcp/sumi-mcp-server.js +1 -7
  117. package/lib/node/mcp/sumi-mcp-server.js.map +1 -1
  118. package/lib/node/mcp-server-manager-impl.d.ts +1 -3
  119. package/lib/node/mcp-server-manager-impl.d.ts.map +1 -1
  120. package/lib/node/mcp-server-manager-impl.js +2 -14
  121. package/lib/node/mcp-server-manager-impl.js.map +1 -1
  122. package/package.json +24 -25
  123. package/src/browser/ai-core.contribution.ts +4 -14
  124. package/src/browser/chat/apply.service.ts +1 -62
  125. package/src/browser/chat/chat-manager.service.ts +7 -16
  126. package/src/browser/chat/chat-model.ts +73 -130
  127. package/src/browser/chat/chat-proxy.service.ts +81 -68
  128. package/src/browser/chat/chat.feature.registry.ts +1 -17
  129. package/src/browser/chat/chat.view.tsx +12 -74
  130. package/src/browser/components/ChatEditor.tsx +1 -1
  131. package/src/browser/components/ChatHistory.tsx +1 -2
  132. package/src/browser/components/ChatMentionInput.tsx +32 -144
  133. package/src/browser/components/ChatToolRender.module.less +0 -25
  134. package/src/browser/components/ChatToolRender.tsx +2 -10
  135. package/src/browser/components/components.module.less +0 -7
  136. package/src/browser/components/mention-input/mention-input.module.less +0 -165
  137. package/src/browser/components/mention-input/mention-input.tsx +29 -244
  138. package/src/browser/components/mention-input/types.ts +0 -15
  139. package/src/browser/context/llm-context.service.ts +21 -182
  140. package/src/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.ts +1 -1
  141. package/src/browser/contrib/intelligent-completions/diff-computer.ts +1 -1
  142. package/src/browser/contrib/terminal/terminal.feature.registry.ts +1 -1
  143. package/src/browser/index.ts +0 -8
  144. package/src/browser/layout/ai-layout.tsx +8 -12
  145. package/src/browser/layout/tabbar.view.tsx +23 -10
  146. package/src/browser/mcp/base-apply.service.ts +10 -30
  147. package/src/browser/mcp/mcp-server-proxy.service.ts +1 -6
  148. package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
  149. package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
  150. package/src/browser/mcp/tools/handlers/ListDir.ts +1 -1
  151. package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
  152. package/src/browser/model/msg-history-manager.ts +2 -181
  153. package/src/browser/preferences/schema.ts +0 -5
  154. package/src/browser/types.ts +0 -18
  155. package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +1 -0
  156. package/src/common/index.ts +1 -6
  157. package/src/common/llm-context.ts +0 -23
  158. package/src/common/prompts/context-prompt-provider.ts +40 -55
  159. package/src/common/types.ts +0 -18
  160. package/src/common/utils.ts +1 -4
  161. package/src/node/base-language-model.ts +13 -10
  162. package/src/node/mcp/sumi-mcp-server.ts +2 -10
  163. package/src/node/mcp-server-manager-impl.ts +2 -17
  164. package/lib/browser/rules/rules.contribution.d.ts +0 -29
  165. package/lib/browser/rules/rules.contribution.d.ts.map +0 -1
  166. package/lib/browser/rules/rules.contribution.js +0 -94
  167. package/lib/browser/rules/rules.contribution.js.map +0 -1
  168. package/lib/browser/rules/rules.module.less +0 -174
  169. package/lib/browser/rules/rules.service.d.ts +0 -25
  170. package/lib/browser/rules/rules.service.d.ts.map +0 -1
  171. package/lib/browser/rules/rules.service.js +0 -180
  172. package/lib/browser/rules/rules.service.js.map +0 -1
  173. package/lib/browser/rules/rules.view.d.ts +0 -3
  174. package/lib/browser/rules/rules.view.d.ts.map +0 -1
  175. package/lib/browser/rules/rules.view.js +0 -76
  176. package/lib/browser/rules/rules.view.js.map +0 -1
  177. package/lib/common/MDC_PARSER_README.md +0 -171
  178. package/lib/common/image-compression.d.ts +0 -25
  179. package/lib/common/image-compression.d.ts.map +0 -1
  180. package/lib/common/image-compression.js +0 -153
  181. package/lib/common/image-compression.js.map +0 -1
  182. package/lib/common/mdc-parser.d.ts +0 -60
  183. package/lib/common/mdc-parser.d.ts.map +0 -1
  184. package/lib/common/mdc-parser.js +0 -246
  185. package/lib/common/mdc-parser.js.map +0 -1
  186. package/lib/common/prompts/system-prompt.d.ts +0 -2
  187. package/lib/common/prompts/system-prompt.d.ts.map +0 -1
  188. package/lib/common/prompts/system-prompt.js +0 -5
  189. package/lib/common/prompts/system-prompt.js.map +0 -1
  190. package/src/browser/rules/rules.contribution.ts +0 -105
  191. package/src/browser/rules/rules.module.less +0 -174
  192. package/src/browser/rules/rules.service.ts +0 -189
  193. package/src/browser/rules/rules.view.tsx +0 -127
  194. package/src/common/MDC_PARSER_README.md +0 -171
  195. package/src/common/image-compression.ts +0 -174
  196. package/src/common/mdc-parser.ts +0 -295
  197. package/src/common/prompts/system-prompt.ts +0 -2
@@ -1,61 +1,11 @@
1
1
  import { Disposable, Emitter, Event, uuid } from '@opensumi/ide-core-common';
2
2
  import { ChatMessageRole, IHistoryChatMessage } from '@opensumi/ide-core-common/lib/types/ai-native';
3
3
 
4
- import { ChatFeatureRegistry } from '../chat/chat.feature.registry';
5
-
6
4
  type IExcludeMessage = Omit<IHistoryChatMessage, 'id' | 'order'>;
7
5
 
8
- interface IMemoryConfig {
9
- shortTermSize: number; // 最近消息窗口大小(10条)
10
- bufferSize: number; // 缓冲区大小(5条)
11
- }
12
-
13
- interface IMemorySummary {
14
- content: string;
15
- timestamp: number;
16
- messageIds: string[];
17
- }
18
-
19
- interface IToolCallInfo {
20
- id: string;
21
- name: string;
22
- args: Record<string, any>;
23
- result: any;
24
- }
25
-
26
- export interface MessageBufferManager {
27
- messages: IHistoryChatMessage[];
28
- add(message: IHistoryChatMessage): void;
29
- clear(): void;
30
- size(): number;
31
- }
32
-
33
- class SimpleMessageBuffer implements MessageBufferManager {
34
- private _messages: IHistoryChatMessage[] = [];
35
-
36
- get messages(): IHistoryChatMessage[] {
37
- return this._messages;
38
- }
39
-
40
- add(message: IHistoryChatMessage): void {
41
- this._messages.push(message);
42
- }
43
-
44
- clear(): void {
45
- this._messages = [];
46
- }
47
-
48
- size(): number {
49
- return this._messages.length;
50
- }
51
- }
52
-
53
6
  export class MsgHistoryManager extends Disposable {
54
7
  private messageMap: Map<string, IHistoryChatMessage> = new Map();
55
8
  private messageAdditionalMap: Map<string, Record<string, any>> = new Map();
56
- private memorySummaries: IMemorySummary[] = [];
57
- private toolCallMap: Map<string, IToolCallInfo> = new Map();
58
- private isCompressing = false; // 添加压缩锁,防止重复压缩
59
9
 
60
10
  private readonly _onMessageChange = new Emitter<IHistoryChatMessage[]>();
61
11
  public readonly onMessageChange: Event<IHistoryChatMessage[]> = this._onMessageChange.event;
@@ -63,33 +13,11 @@ export class MsgHistoryManager extends Disposable {
63
13
  private readonly _onMessageAdditionalChange = new Emitter<Record<string, any>>();
64
14
  public readonly onMessageAdditionalChange: Event<Record<string, any>> = this._onMessageAdditionalChange.event;
65
15
 
66
- private messageBuffer: MessageBufferManager;
67
-
68
- memoryConfig: IMemoryConfig = {
69
- shortTermSize: 10,
70
- bufferSize: 5,
71
- };
72
-
73
- constructor(
74
- private chatFeatureRegistry: ChatFeatureRegistry,
75
- data?: {
76
- additional: Record<string, any>;
77
- messages: IHistoryChatMessage[];
78
- toolCalls?: Record<string, IToolCallInfo>;
79
- memorySummaries?: IMemorySummary[];
80
- },
81
- ) {
16
+ constructor(data?: { additional: Record<string, any>; messages: IHistoryChatMessage[] }) {
82
17
  super();
83
- this.messageBuffer = new SimpleMessageBuffer();
84
18
  if (data) {
85
19
  this.messageMap = new Map(data.messages.map((item) => [item.id, item]));
86
20
  this.messageAdditionalMap = new Map(Object.entries(data.additional));
87
- if (data.toolCalls) {
88
- this.toolCallMap = new Map(Object.entries(data.toolCalls));
89
- }
90
- if (data.memorySummaries) {
91
- this.memorySummaries = data.memorySummaries;
92
- }
93
21
  }
94
22
  }
95
23
 
@@ -105,91 +33,6 @@ export class MsgHistoryManager extends Disposable {
105
33
  public clearMessages() {
106
34
  this.messageMap.clear();
107
35
  this.messageAdditionalMap.clear();
108
- this.memorySummaries = [];
109
- this.toolCallMap.clear();
110
- }
111
-
112
- /**
113
- * 压缩历史消息的方法:
114
- * 1. 保持最新的10条消息不变
115
- * 2. 当累积了5条超出限制的消息时,对这5条(最早的消息)进行总结
116
- * 3. 总结完成后删除这5条消息
117
- * 4. 重复这个过程,确保消息数量始终在可控范围内
118
- */
119
- private async compressMemory() {
120
- // 如果正在压缩中,直接返回
121
- if (this.isCompressing) {
122
- return;
123
- }
124
-
125
- const messages = this.messageList;
126
- // 只有当消息总数超过短期记忆限制时才进行压缩
127
- if (messages.length <= this.memoryConfig.shortTermSize) {
128
- return;
129
- }
130
-
131
- try {
132
- this.isCompressing = true;
133
-
134
- // 1. 获取超出短期记忆限制的最新一条消息
135
- const latestExcessMessage = messages[messages.length - this.memoryConfig.shortTermSize - 1];
136
-
137
- // 如果这条消息已经被总结过,就不需要再处理
138
- if (latestExcessMessage.isSummarized) {
139
- return;
140
- }
141
-
142
- // 2. 将这条消息添加到缓冲区
143
- this.messageBuffer.add(latestExcessMessage);
144
-
145
- // 3. 当缓冲区达到指定大小时,进行总结
146
- if (this.messageBuffer.size() >= this.memoryConfig.bufferSize) {
147
- const messagesToSummarize = this.messageBuffer.messages;
148
-
149
- const summaryProvider = this.chatFeatureRegistry.getMessageSummaryProvider?.();
150
- if (summaryProvider) {
151
- const messageContents = messagesToSummarize.map((msg) => ({
152
- role: msg.role,
153
- content: msg.content,
154
- }));
155
-
156
- const memorize = await summaryProvider.generateMemorizedMessage(messageContents);
157
- if (memorize) {
158
- // 添加新的记忆总结
159
- this.memorySummaries.push({
160
- content: memorize,
161
- timestamp: Date.now(),
162
- messageIds: messagesToSummarize.map((msg) => msg.id),
163
- });
164
-
165
- // 标记消息为已总结
166
- for (const msg of messagesToSummarize) {
167
- const existingMsg = this.messageMap.get(msg.id);
168
- if (existingMsg) {
169
- this.messageMap.set(msg.id, {
170
- ...existingMsg,
171
- isSummarized: true,
172
- });
173
- }
174
- }
175
-
176
- // 清空缓冲区
177
- this.messageBuffer.clear();
178
- }
179
- }
180
- }
181
- } finally {
182
- this.isCompressing = false;
183
- }
184
- }
185
-
186
- public addToolCall(toolCall: IToolCallInfo): void {
187
- this.toolCallMap.set(toolCall.id, toolCall);
188
- }
189
-
190
- public getToolCall(id: string): IToolCallInfo | undefined {
191
- const toolCall = this.toolCallMap.get(id);
192
- return toolCall;
193
36
  }
194
37
 
195
38
  private doAddMessage(message: IExcludeMessage): string {
@@ -205,19 +48,11 @@ export class MsgHistoryManager extends Disposable {
205
48
 
206
49
  this.messageMap.set(id, msg);
207
50
 
208
- // 在添加新消息后尝试压缩记忆
209
- this.compressMemory().catch((error) => {
210
- // eslint-disable-next-line no-console
211
- console.error('[MsgHistoryManager] Error compressing memory', error);
212
- });
213
-
214
- // 无论压缩是否完成,都触发消息变更事件
215
51
  this._onMessageChange.fire(this.getMessages());
216
52
  return id;
217
53
  }
218
54
 
219
55
  private get messageList(): IHistoryChatMessage[] {
220
- // 按 order 升序排序,保持消息的原始顺序
221
56
  return Array.from(this.messageMap.values()).sort((a, b) => a.order - b.order);
222
57
  }
223
58
 
@@ -230,17 +65,6 @@ export class MsgHistoryManager extends Disposable {
230
65
  return this.messageList;
231
66
  }
232
67
 
233
- public getMemorySummaries(): IMemorySummary[] {
234
- return this.memorySummaries;
235
- }
236
-
237
- public setMemoryConfig(config: Partial<IMemoryConfig>) {
238
- this.memoryConfig = {
239
- ...this.memoryConfig,
240
- ...config,
241
- };
242
- }
243
-
244
68
  public addUserMessage(
245
69
  message: Required<Pick<IExcludeMessage, 'agentId' | 'agentCommand' | 'content' | 'relationId' | 'images'>>,
246
70
  ): string {
@@ -294,12 +118,9 @@ export class MsgHistoryManager extends Disposable {
294
118
  }
295
119
 
296
120
  toJSON() {
297
- const data = {
121
+ return {
298
122
  messages: this.getMessages(),
299
123
  additional: Object.fromEntries(this.messageAdditionalMap.entries()),
300
- memorySummaries: this.memorySummaries,
301
- toolCalls: Object.fromEntries(this.toolCallMap.entries()),
302
124
  };
303
- return data;
304
125
  }
305
126
  }
@@ -177,10 +177,5 @@ export const aiNativePreferenceSchema: PreferenceSchema = {
177
177
  type: 'string',
178
178
  description: '%preference.ai.native.chat.system.prompt.description%',
179
179
  },
180
- [AINativeSettingSectionsId.GlobalRules]: {
181
- type: 'string',
182
- default: '',
183
- description: '%preference.ai.native.globalRules.description%',
184
- },
185
180
  },
186
181
  };
@@ -5,7 +5,6 @@ import { ZodSchema } from 'zod';
5
5
  import { AIActionItem } from '@opensumi/ide-core-browser/lib/components/ai-native/index';
6
6
  import {
7
7
  CancellationToken,
8
- ChatMessageRole,
9
8
  ChatResponse,
10
9
  Deferred,
11
10
  IAICompletionOption,
@@ -135,8 +134,6 @@ export interface IChatFeatureRegistry {
135
134
  registerImageUploadProvider(provider: IImageUploadProvider): void;
136
135
  registerWelcome(content: IChatWelcomeMessageContent | React.ReactNode, sampleQuestions?: ISampleQuestions[]): void;
137
136
  registerSlashCommand(command: IChatSlashCommandItem, handler: IChatSlashCommandHandler): void;
138
-
139
- registerMessageSummaryProvider(provider: IMessageSummaryProvider): void;
140
137
  }
141
138
 
142
139
  export type ChatWelcomeRender = (props: {
@@ -301,21 +298,6 @@ export interface IImageUploadProvider {
301
298
  imageUpload(file: File): Promise<DataContent | URL>;
302
299
  }
303
300
 
304
- export interface IMessageSummaryProvider {
305
- getMessageSummary(
306
- messages: Array<{
307
- role: ChatMessageRole;
308
- content: string;
309
- }>,
310
- ): Promise<string | undefined>;
311
- generateMemorizedMessage(
312
- messages: Array<{
313
- role: ChatMessageRole;
314
- content: string;
315
- }>,
316
- ): Promise<string | undefined>;
317
- }
318
-
319
301
  export const AINativeCoreContribution = Symbol('AINativeCoreContribution');
320
302
 
321
303
  export interface AINativeCoreContribution {
@@ -13,6 +13,7 @@ import {
13
13
  Position,
14
14
  } from '@opensumi/ide-monaco';
15
15
  import { ReactInlineContentWidget } from '@opensumi/ide-monaco/lib/browser/ai-native/BaseInlineContentWidget';
16
+ import { URI } from '@opensumi/ide-monaco/lib/browser/monaco-api';
16
17
  import { ContentWidgetPositionPreference } from '@opensumi/ide-monaco/lib/browser/monaco-exports/editor';
17
18
  import { EditorOption } from '@opensumi/monaco-editor-core/esm/vs/editor/common/config/editorOptions';
18
19
  import { IScrollEvent } from '@opensumi/monaco-editor-core/esm/vs/editor/common/editorCommon';
@@ -15,9 +15,8 @@ import {
15
15
  import { DESIGN_MENUBAR_CONTAINER_VIEW_ID } from '@opensumi/ide-design/lib/common/constants';
16
16
  import { IPosition, ITextModel, InlineCompletionContext } from '@opensumi/ide-monaco/lib/common';
17
17
 
18
- import { ImageCompressionOptions } from './image-compression';
19
18
  import { IMCPServer, MCPServerDescription } from './mcp-server-manager';
20
- import { IMCPToolResult, IPartialEditEvent, MCPTool } from './types';
19
+ import { IPartialEditEvent, MCPTool } from './types';
21
20
 
22
21
  import type { CoreMessage } from 'ai';
23
22
 
@@ -153,7 +152,6 @@ export interface ISumiMCPServerBackend {
153
152
  $removeServer(name: string): void;
154
153
  $syncServer(name: string): Promise<void>;
155
154
  $getMCPServerByName(name: string): IMCPServer | undefined;
156
- $compressToolResult(result: IMCPToolResult, options: ImageCompressionOptions): Promise<IMCPToolResult>;
157
155
  }
158
156
 
159
157
  export const SumiMCPServerProxyServicePath = 'SumiMCPServerProxyServicePath';
@@ -333,6 +331,3 @@ export interface IInlineDiffService {
333
331
  }
334
332
 
335
333
  export const InlineDiffServiceToken = Symbol('InlineDiffService');
336
-
337
- export * from './tool-invocation-registry';
338
- export * from './mdc-parser';
@@ -1,7 +1,5 @@
1
1
  import { Event, URI } from '@opensumi/ide-core-common/lib/utils';
2
2
 
3
- import { ProjectRule } from './types';
4
-
5
3
  export interface LLMContextService {
6
4
  /**
7
5
  * 开始自动收集
@@ -23,11 +21,6 @@ export interface LLMContextService {
23
21
  */
24
22
  addFolderToContext(uri: URI, isManual?: boolean): void;
25
23
 
26
- /**
27
- * 添加规则到 context 中
28
- */
29
- addRuleToContext(uri: URI, isManual?: boolean): void;
30
-
31
24
  /**
32
25
  * 清除上下文
33
26
  */
@@ -40,7 +33,6 @@ export interface LLMContextService {
40
33
  viewed: FileContext[];
41
34
  attached: FileContext[];
42
35
  attachedFolders: FileContext[];
43
- attachedRules: ProjectRule[];
44
36
  version: number;
45
37
  }>;
46
38
 
@@ -50,18 +42,6 @@ export interface LLMContextService {
50
42
  */
51
43
  removeFileFromContext(uri: URI, isManual?: boolean): void;
52
44
 
53
- /**
54
- * 从 context 中移除文件夹
55
- * @param uri URI
56
- */
57
- removeFolderFromContext(uri: URI): void;
58
-
59
- /**
60
- * 从 context 中移除规则
61
- * @param uri URI
62
- */
63
- removeRuleFromContext(uri: URI): void;
64
-
65
45
  /** 导出为可序列化格式 */
66
46
  serialize(): Promise<SerializedContext>;
67
47
  }
@@ -78,15 +58,12 @@ export interface AttachFileContext {
78
58
  lineErrors: string[];
79
59
  path: string;
80
60
  language: string;
81
- selection?: [number, number];
82
61
  }
83
62
 
84
63
  export interface SerializedContext {
85
64
  recentlyViewFiles: string[];
86
65
  attachedFiles: Array<AttachFileContext>;
87
66
  attachedFolders: string[];
88
- attachedRules: string[];
89
- globalRules: string[];
90
67
  }
91
68
 
92
69
  export enum LLM_CONTEXT_KEY {
@@ -2,7 +2,7 @@ import { Autowired, Injectable } from '@opensumi/di';
2
2
  import { WorkbenchEditorService } from '@opensumi/ide-editor/lib/common/editor';
3
3
  import { IWorkspaceService } from '@opensumi/ide-workspace';
4
4
 
5
- import { AttachFileContext, SerializedContext } from '../llm-context';
5
+ import { SerializedContext } from '../llm-context';
6
6
 
7
7
  export const ChatAgentPromptProvider = Symbol('ChatAgentPromptProvider');
8
8
 
@@ -23,17 +23,14 @@ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
23
23
  protected readonly workspaceService: IWorkspaceService;
24
24
 
25
25
  async provideContextPrompt(context: SerializedContext, userMessage: string) {
26
- let currentFileInfo = await this.getCurrentFileInfo();
27
- if (context.attachedFiles.some((file) => file.path === currentFileInfo?.path)) {
28
- currentFileInfo = null;
29
- }
26
+ const currentFileInfo =
27
+ context.attachedFiles.length > 0 || context.attachedFolders.length > 0 ? null : await this.getCurrentFileInfo();
30
28
 
31
29
  return this.buildPromptTemplate({
32
- attachedFiles: context.attachedFiles,
33
- attachedFolders: context.attachedFolders,
30
+ recentFiles: this.buildRecentFilesSection(context.recentlyViewFiles),
31
+ attachedFiles: this.buildAttachedFilesSection(context.attachedFiles),
32
+ attachedFolders: this.buildAttachedFoldersSection(context.attachedFolders),
34
33
  currentFile: currentFileInfo,
35
- attachedRules: context.attachedRules,
36
- globalRules: context.globalRules,
37
34
  userMessage,
38
35
  });
39
36
  }
@@ -49,56 +46,33 @@ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
49
46
  const currentPath =
50
47
  (await this.workspaceService.asRelativePath(currentModel.uri))?.path || currentModel.uri.codeUri.fsPath;
51
48
 
52
- // 获取当前选中行信息
53
- const selection = editor?.monacoEditor?.getSelection();
54
- const currentLine = selection ? selection.startLineNumber : undefined;
55
- let lineContent = '';
56
-
57
- if (currentLine && editor?.monacoEditor) {
58
- const model = editor.monacoEditor.getModel();
59
- if (model) {
60
- lineContent = model.getLineContent(currentLine)?.trim() || '';
61
- }
62
- }
63
-
64
49
  return {
65
50
  path: currentPath,
66
51
  languageId: currentModel.languageId,
67
52
  content: currentModel.getText(),
68
- currentLine,
69
- lineContent,
70
53
  };
71
54
  }
72
55
 
73
- private async buildPromptTemplate({
56
+ private buildPromptTemplate({
57
+ recentFiles,
74
58
  attachedFiles,
75
59
  attachedFolders,
76
60
  currentFile,
77
- attachedRules,
78
- globalRules,
79
61
  userMessage,
80
62
  }: {
81
- attachedFiles: AttachFileContext[];
82
- attachedFolders: string[];
83
- currentFile: {
84
- path: string;
85
- languageId: string;
86
- content: string;
87
- currentLine?: number;
88
- lineContent?: string;
89
- } | null;
90
- attachedRules: string[];
91
- globalRules: string[];
63
+ recentFiles: string;
64
+ attachedFiles: string;
65
+ attachedFolders: string;
66
+ currentFile: { path: string; languageId: string; content: string } | null;
92
67
  userMessage: string;
93
68
  }) {
94
69
  const sections = [
95
- ...globalRules,
96
- ...attachedFolders,
97
70
  '<additional_data>',
98
71
  'Below are some potentially helpful/relevant pieces of information for figuring out to respond',
72
+ recentFiles,
73
+ attachedFiles,
74
+ attachedFolders,
99
75
  this.buildCurrentFileSection(currentFile),
100
- this.buildAttachedFilesSection(attachedFiles),
101
- ...attachedRules,
102
76
  '</additional_data>',
103
77
  '<user_query>',
104
78
  userMessage,
@@ -108,7 +82,17 @@ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
108
82
  return sections.join('\n');
109
83
  }
110
84
 
111
- private buildAttachedFilesSection(files: AttachFileContext[]): string {
85
+ private buildRecentFilesSection(files: string[]): string {
86
+ if (!files.length) {
87
+ return '';
88
+ }
89
+
90
+ return `<recently_viewed_files>
91
+ ${files.map((file, idx) => ` ${idx + 1}: ${file}`).join('\n')}
92
+ </recently_viewed_files>`;
93
+ }
94
+
95
+ private buildAttachedFilesSection(files: { path: string; content: string; lineErrors: string[] }[]): string {
112
96
  if (!files.length) {
113
97
  return '';
114
98
  }
@@ -128,9 +112,9 @@ export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
128
112
  return `<attached_files>\n${fileContents}\n</attached_files>`;
129
113
  }
130
114
 
131
- private buildFileContentSection(file: AttachFileContext): string {
115
+ private buildFileContentSection(file: { path: string; content: string }): string {
132
116
  return `<file_contents>
133
- \`\`\`${file.path}${file.selection ? `, lines: ${file.selection?.[0]}-${file.selection?.[1]}` : ''}
117
+ \`\`\`${file.path}
134
118
  ${file.content}
135
119
  \`\`\`
136
120
  </file_contents>`;
@@ -144,22 +128,23 @@ ${file.content}
144
128
  return `<linter_errors>\n${errors.join('\n')}\n</linter_errors>`;
145
129
  }
146
130
 
147
- private buildCurrentFileSection(
148
- fileInfo: { path: string; languageId: string; content: string; currentLine?: number; lineContent?: string } | null,
149
- ): string {
150
- if (!fileInfo) {
131
+ private buildAttachedFoldersSection(folders: string[]): string {
132
+ if (!folders.length) {
151
133
  return '';
152
134
  }
153
135
 
154
- let currentFileSection = `<current_file>\nPath: ${fileInfo.path}`;
136
+ return `<attached_folders>\n${folders.join('\n')}</attached_folders>`;
137
+ }
155
138
 
156
- if (fileInfo.currentLine && fileInfo.lineContent) {
157
- currentFileSection += `\nCurrently selected line: ${fileInfo.currentLine}`;
158
- currentFileSection += `\nLine ${fileInfo.currentLine} content: \`${fileInfo.lineContent}\``;
139
+ private buildCurrentFileSection(fileInfo: { path: string; languageId: string; content: string } | null): string {
140
+ if (!fileInfo) {
141
+ return '';
159
142
  }
160
143
 
161
- currentFileSection += '\n</current_file>';
162
-
163
- return currentFileSection;
144
+ return `<current_opened_file>
145
+ \`\`\`${fileInfo.languageId} ${fileInfo.path}
146
+ ${fileInfo.content}
147
+ \`\`\`
148
+ </current_opened_file>`;
164
149
  }
165
150
  }
@@ -1,8 +1,6 @@
1
1
  import { IMarker } from '@opensumi/ide-core-browser';
2
2
  import { Uri } from '@opensumi/monaco-editor-core';
3
3
 
4
- import { ImageCompressionOptions } from './image-compression';
5
-
6
4
  export enum NearestCodeBlockType {
7
5
  Block = 'block',
8
6
  Line = 'line',
@@ -24,12 +22,6 @@ export interface INearestCodeBlock {
24
22
  type?: NearestCodeBlockType;
25
23
  }
26
24
 
27
- export type IMCPToolResultContent = { type: 'text'; text: string } | { type: 'image'; data: string; mimeType?: string };
28
- export interface IMCPToolResult {
29
- content: IMCPToolResultContent[];
30
- isError?: boolean;
31
- }
32
-
33
25
  // SUMI MCP Server 网页部分暴露给 Node.js 部分的能力
34
26
  export interface IMCPServerProxyService {
35
27
  $callMCPTool(
@@ -49,8 +41,6 @@ export interface IMCPServerProxyService {
49
41
  $startServer(serverName: string): Promise<void>;
50
42
  // 停止指定的 MCP 服务器
51
43
  $stopServer(serverName: string): Promise<void>;
52
- // 压缩工具结果
53
- $compressToolResult(result: IMCPToolResult, options: ImageCompressionOptions): Promise<IMCPToolResult>;
54
44
  }
55
45
 
56
46
  export interface MCPServer {
@@ -135,11 +125,3 @@ export interface SSEClientTransportOptions {
135
125
  */
136
126
  requestInit?: RequestInit;
137
127
  }
138
-
139
- export interface ProjectRule {
140
- path: string;
141
- content: string;
142
- description?: string;
143
- globs?: string | string[];
144
- alwaysApply?: boolean;
145
- }
@@ -54,11 +54,8 @@ export const extractCodeBlocks = (content: string): string => {
54
54
  // 确保 Tool Name 符合 Claude 3.5+ Sonnet 要求的 ^[a-zA-Z0-9_-]{1,64}$ 正则
55
55
  export const toClaudeToolName = (name: string) => name.replace(/[^a-zA-Z0-9_-]/g, '').slice(0, 64);
56
56
 
57
- export const TOOL_NAME_SEPARATOR = '__';
58
57
  export const getToolName = (toolName: string, serverName: string) =>
59
- serverName === BUILTIN_MCP_SERVER_NAME
60
- ? toolName
61
- : toClaudeToolName(`mcp${TOOL_NAME_SEPARATOR}${serverName}${TOOL_NAME_SEPARATOR}${toolName}`);
58
+ serverName === BUILTIN_MCP_SERVER_NAME ? toolName : toClaudeToolName(`mcp_${serverName}_${toolName}`);
62
59
 
63
60
  export const cleanAttachedTextWrapper = (text: string) => {
64
61
  const rgAttachedFile = /`<attached_file>(.*)`/g;
@@ -1,8 +1,17 @@
1
- import { CoreMessage, ImagePart, TextPart, ToolExecutionOptions, jsonSchema, streamText, tool } from 'ai';
1
+ import {
2
+ CoreMessage,
3
+ CoreUserMessage,
4
+ ImagePart,
5
+ TextPart,
6
+ ToolExecutionOptions,
7
+ jsonSchema,
8
+ streamText,
9
+ tool,
10
+ } from 'ai';
2
11
 
3
12
  import { Autowired, Injectable } from '@opensumi/di';
4
13
  import { IAIBackServiceOption } from '@opensumi/ide-core-common';
5
- import { ChatReadableStream, INodeLogger } from '@opensumi/ide-core-node';
14
+ import { ChatReadableStream } from '@opensumi/ide-core-node';
6
15
  import { CancellationToken } from '@opensumi/ide-utils';
7
16
 
8
17
  import { ModelInfo } from '../common';
@@ -19,9 +28,6 @@ export abstract class BaseLanguageModel {
19
28
  @Autowired(ToolInvocationRegistryManager)
20
29
  protected readonly toolInvocationRegistryManager: IToolInvocationRegistryManager;
21
30
 
22
- @Autowired(INodeLogger)
23
- protected readonly logger: INodeLogger;
24
-
25
31
  protected abstract initializeProvider(options: IAIBackServiceOption): any;
26
32
 
27
33
  async request(
@@ -61,11 +67,8 @@ export abstract class BaseLanguageModel {
61
67
  description: toolRequest.description || '',
62
68
  // TODO 这里应该是 z.object 而不是 JSON Schema
63
69
  parameters: jsonSchema(toolRequest.parameters),
64
- execute: async (args: any, options: ToolExecutionOptions) => {
65
- // 执行原始工具
66
- const result = await toolRequest.handler(JSON.stringify(args), options);
67
- return result;
68
- },
70
+ execute: async (args: any, options: ToolExecutionOptions) =>
71
+ await toolRequest.handler(JSON.stringify(args), options),
69
72
  });
70
73
  }
71
74
 
@@ -12,10 +12,9 @@ import { INodeLogger } from '@opensumi/ide-core-node';
12
12
 
13
13
  import pkg from '../../../package.json';
14
14
  import { BUILTIN_MCP_SERVER_NAME, ISumiMCPServerBackend } from '../../common';
15
- import { ImageCompressionOptions } from '../../common/image-compression';
16
15
  import { IMCPServer, MCPServerDescription } from '../../common/mcp-server-manager';
17
16
  import { IToolInvocationRegistryManager, ToolInvocationRegistryManager } from '../../common/tool-invocation-registry';
18
- import { IMCPServerProxyService, IMCPToolResult, MCPTool, MCP_SERVER_TYPE } from '../../common/types';
17
+ import { IMCPServerProxyService, MCPTool, MCP_SERVER_TYPE } from '../../common/types';
19
18
  import { MCPServerManagerImpl } from '../mcp-server-manager-impl';
20
19
  import { SSEMCPServer } from '../mcp-server.sse';
21
20
  import { StdioMCPServer } from '../mcp-server.stdio';
@@ -44,7 +43,7 @@ export class SumiMCPServerBackend extends RPCService<IMCPServerProxyService> imp
44
43
 
45
44
  constructor() {
46
45
  super();
47
- this.mcpServerManager = new MCPServerManagerImpl(this.toolInvocationRegistryManager, this.logger, this);
46
+ this.mcpServerManager = new MCPServerManagerImpl(this.toolInvocationRegistryManager, this.logger);
48
47
  }
49
48
 
50
49
  public setConnectionClientId(clientId: string) {
@@ -52,13 +51,6 @@ export class SumiMCPServerBackend extends RPCService<IMCPServerProxyService> imp
52
51
  this.mcpServerManager.setClientId(clientId);
53
52
  }
54
53
 
55
- async $compressToolResult(result: IMCPToolResult, options: ImageCompressionOptions) {
56
- if (!this.client) {
57
- throw new Error('SUMI MCP RPC Client not initialized');
58
- }
59
- return this.client.$compressToolResult(result, options);
60
- }
61
-
62
54
  async $getMCPTools() {
63
55
  if (!this.client) {
64
56
  throw new Error('SUMI MCP RPC Client not initialized');