@opensumi/ide-ai-native 3.9.1-next-1749003325.0 → 3.9.1-next-1749007675.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 (146) hide show
  1. package/lib/browser/chat/chat-manager.service.d.ts +1 -0
  2. package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
  3. package/lib/browser/chat/chat-manager.service.js +8 -3
  4. package/lib/browser/chat/chat-manager.service.js.map +1 -1
  5. package/lib/browser/chat/chat-model.d.ts +3 -1
  6. package/lib/browser/chat/chat-model.d.ts.map +1 -1
  7. package/lib/browser/chat/chat-model.js +48 -17
  8. package/lib/browser/chat/chat-model.js.map +1 -1
  9. package/lib/browser/chat/chat-proxy.service.d.ts +2 -0
  10. package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
  11. package/lib/browser/chat/chat-proxy.service.js +57 -50
  12. package/lib/browser/chat/chat-proxy.service.js.map +1 -1
  13. package/lib/browser/chat/chat.feature.registry.d.ts +4 -1
  14. package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
  15. package/lib/browser/chat/chat.feature.registry.js +6 -0
  16. package/lib/browser/chat/chat.feature.registry.js.map +1 -1
  17. package/lib/browser/chat/chat.view.d.ts.map +1 -1
  18. package/lib/browser/chat/chat.view.js +29 -12
  19. package/lib/browser/chat/chat.view.js.map +1 -1
  20. package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
  21. package/lib/browser/components/ChatMentionInput.js +30 -141
  22. package/lib/browser/components/ChatMentionInput.js.map +1 -1
  23. package/lib/browser/components/ChatToolRender.module.less +0 -1
  24. package/lib/browser/components/components.module.less +7 -9
  25. package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
  26. package/lib/browser/components/mention-input/mention-input.js +14 -161
  27. package/lib/browser/components/mention-input/mention-input.js.map +1 -1
  28. package/lib/browser/components/mention-input/mention-input.module.less +1 -165
  29. package/lib/browser/components/mention-input/types.d.ts +1 -16
  30. package/lib/browser/components/mention-input/types.d.ts.map +1 -1
  31. package/lib/browser/components/mention-input/types.js +0 -1
  32. package/lib/browser/components/mention-input/types.js.map +1 -1
  33. package/lib/browser/components/utils.d.ts +2 -2
  34. package/lib/browser/context/llm-context.service.d.ts +2 -21
  35. package/lib/browser/context/llm-context.service.d.ts.map +1 -1
  36. package/lib/browser/context/llm-context.service.js +20 -162
  37. package/lib/browser/context/llm-context.service.js.map +1 -1
  38. package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.d.ts.map +1 -1
  39. package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.js.map +1 -1
  40. package/lib/browser/contrib/intelligent-completions/diff-computer.js +1 -1
  41. package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -1
  42. package/lib/browser/contrib/terminal/terminal.feature.registry.js.map +1 -1
  43. package/lib/browser/index.d.ts.map +1 -1
  44. package/lib/browser/index.js +0 -7
  45. package/lib/browser/index.js.map +1 -1
  46. package/lib/browser/mcp/base-apply.service.d.ts +2 -2
  47. package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
  48. package/lib/browser/mcp/base-apply.service.js.map +1 -1
  49. package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
  50. package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
  51. package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
  52. package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
  53. package/lib/browser/model/msg-history-manager.d.ts +39 -1
  54. package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
  55. package/lib/browser/model/msg-history-manager.js +170 -3
  56. package/lib/browser/model/msg-history-manager.js.map +1 -1
  57. package/lib/browser/preferences/schema.d.ts.map +1 -1
  58. package/lib/browser/preferences/schema.js +0 -5
  59. package/lib/browser/preferences/schema.js.map +1 -1
  60. package/lib/browser/types.d.ts +8 -1
  61. package/lib/browser/types.d.ts.map +1 -1
  62. package/lib/browser/types.js.map +1 -1
  63. package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
  64. package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
  65. package/lib/common/index.d.ts +0 -2
  66. package/lib/common/index.d.ts.map +1 -1
  67. package/lib/common/index.js +0 -2
  68. package/lib/common/index.js.map +1 -1
  69. package/lib/common/llm-context.d.ts +0 -19
  70. package/lib/common/llm-context.d.ts.map +1 -1
  71. package/lib/common/llm-context.js.map +1 -1
  72. package/lib/common/prompts/context-prompt-provider.d.ts +2 -0
  73. package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
  74. package/lib/common/prompts/context-prompt-provider.js +29 -35
  75. package/lib/common/prompts/context-prompt-provider.js.map +1 -1
  76. package/lib/common/types.d.ts +0 -7
  77. package/lib/common/types.d.ts.map +1 -1
  78. package/lib/node/base-language-model.d.ts.map +1 -1
  79. package/lib/node/base-language-model.js.map +1 -1
  80. package/package.json +24 -25
  81. package/src/browser/chat/chat-manager.service.ts +15 -6
  82. package/src/browser/chat/chat-model.ts +56 -19
  83. package/src/browser/chat/chat-proxy.service.ts +81 -68
  84. package/src/browser/chat/chat.feature.registry.ts +17 -1
  85. package/src/browser/chat/chat.view.tsx +28 -22
  86. package/src/browser/components/ChatMentionInput.tsx +35 -169
  87. package/src/browser/components/ChatToolRender.module.less +0 -1
  88. package/src/browser/components/components.module.less +7 -9
  89. package/src/browser/components/mention-input/mention-input.module.less +1 -165
  90. package/src/browser/components/mention-input/mention-input.tsx +32 -257
  91. package/src/browser/components/mention-input/types.ts +0 -16
  92. package/src/browser/context/llm-context.service.ts +21 -182
  93. package/src/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.ts +1 -1
  94. package/src/browser/contrib/intelligent-completions/diff-computer.ts +1 -1
  95. package/src/browser/contrib/terminal/terminal.feature.registry.ts +1 -1
  96. package/src/browser/index.ts +0 -8
  97. package/src/browser/mcp/base-apply.service.ts +1 -0
  98. package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
  99. package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
  100. package/src/browser/mcp/tools/handlers/ListDir.ts +1 -1
  101. package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
  102. package/src/browser/model/msg-history-manager.ts +230 -3
  103. package/src/browser/preferences/schema.ts +0 -5
  104. package/src/browser/types.ts +12 -0
  105. package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +1 -0
  106. package/src/common/index.ts +0 -3
  107. package/src/common/llm-context.ts +0 -23
  108. package/src/common/prompts/context-prompt-provider.ts +40 -55
  109. package/src/common/types.ts +0 -8
  110. package/src/node/base-language-model.ts +1 -0
  111. package/lib/browser/components/mention-input/mention-select.d.ts +0 -28
  112. package/lib/browser/components/mention-input/mention-select.d.ts.map +0 -1
  113. package/lib/browser/components/mention-input/mention-select.js +0 -136
  114. package/lib/browser/components/mention-input/mention-select.js.map +0 -1
  115. package/lib/browser/components/mention-input/mention-select.module.less +0 -297
  116. package/lib/browser/rules/rules.contribution.d.ts +0 -29
  117. package/lib/browser/rules/rules.contribution.d.ts.map +0 -1
  118. package/lib/browser/rules/rules.contribution.js +0 -94
  119. package/lib/browser/rules/rules.contribution.js.map +0 -1
  120. package/lib/browser/rules/rules.module.less +0 -175
  121. package/lib/browser/rules/rules.service.d.ts +0 -25
  122. package/lib/browser/rules/rules.service.d.ts.map +0 -1
  123. package/lib/browser/rules/rules.service.js +0 -180
  124. package/lib/browser/rules/rules.service.js.map +0 -1
  125. package/lib/browser/rules/rules.view.d.ts +0 -3
  126. package/lib/browser/rules/rules.view.d.ts.map +0 -1
  127. package/lib/browser/rules/rules.view.js +0 -76
  128. package/lib/browser/rules/rules.view.js.map +0 -1
  129. package/lib/common/MDC_PARSER_README.md +0 -171
  130. package/lib/common/mdc-parser.d.ts +0 -60
  131. package/lib/common/mdc-parser.d.ts.map +0 -1
  132. package/lib/common/mdc-parser.js +0 -246
  133. package/lib/common/mdc-parser.js.map +0 -1
  134. package/lib/common/prompts/system-prompt.d.ts +0 -2
  135. package/lib/common/prompts/system-prompt.d.ts.map +0 -1
  136. package/lib/common/prompts/system-prompt.js +0 -5
  137. package/lib/common/prompts/system-prompt.js.map +0 -1
  138. package/src/browser/components/mention-input/mention-select.module.less +0 -297
  139. package/src/browser/components/mention-input/mention-select.tsx +0 -256
  140. package/src/browser/rules/rules.contribution.ts +0 -105
  141. package/src/browser/rules/rules.module.less +0 -175
  142. package/src/browser/rules/rules.service.ts +0 -189
  143. package/src/browser/rules/rules.view.tsx +0 -127
  144. package/src/common/MDC_PARSER_README.md +0 -171
  145. package/src/common/mdc-parser.ts +0 -295
  146. package/src/common/prompts/system-prompt.ts +0 -2
@@ -1,11 +1,40 @@
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
+
4
6
  type IExcludeMessage = Omit<IHistoryChatMessage, 'id' | 'order'>;
5
7
 
8
+ interface IMemoryConfig {
9
+ shortTermSize: number; // 短期记忆窗口大小
10
+ midTermSize: number; // 中期记忆窗口大小
11
+ longTermSize: number; // 长期记忆窗口大小
12
+ }
13
+
14
+ interface IMemorySummary {
15
+ content: string;
16
+ timestamp: number;
17
+ messageIds: string[];
18
+ toolCalls?: Array<{
19
+ id: string;
20
+ name: string;
21
+ args?: Record<string, any>;
22
+ result?: string;
23
+ }>;
24
+ }
25
+
26
+ interface IToolCallInfo {
27
+ id: string;
28
+ name: string;
29
+ args: Record<string, any>;
30
+ result: any;
31
+ }
32
+
6
33
  export class MsgHistoryManager extends Disposable {
7
34
  private messageMap: Map<string, IHistoryChatMessage> = new Map();
8
35
  private messageAdditionalMap: Map<string, Record<string, any>> = new Map();
36
+ private memorySummaries: IMemorySummary[] = [];
37
+ private toolCallMap: Map<string, IToolCallInfo> = new Map();
9
38
 
10
39
  private readonly _onMessageChange = new Emitter<IHistoryChatMessage[]>();
11
40
  public readonly onMessageChange: Event<IHistoryChatMessage[]> = this._onMessageChange.event;
@@ -13,11 +42,36 @@ export class MsgHistoryManager extends Disposable {
13
42
  private readonly _onMessageAdditionalChange = new Emitter<Record<string, any>>();
14
43
  public readonly onMessageAdditionalChange: Event<Record<string, any>> = this._onMessageAdditionalChange.event;
15
44
 
16
- constructor(data?: { additional: Record<string, any>; messages: IHistoryChatMessage[] }) {
45
+ private memoryConfig: IMemoryConfig = {
46
+ shortTermSize: 10, // 最近的10条消息保持完整
47
+ midTermSize: 20, // 接下来的20条消息进行总结
48
+ longTermSize: 50, // 最多保留50条消息
49
+ };
50
+
51
+ constructor(
52
+ private chatFeatureRegistry: ChatFeatureRegistry,
53
+ data?: {
54
+ additional: Record<string, any>;
55
+ messages: IHistoryChatMessage[];
56
+ toolCalls?: Record<string, IToolCallInfo>;
57
+ memorySummaries?: IMemorySummary[];
58
+ },
59
+ ) {
17
60
  super();
18
61
  if (data) {
19
62
  this.messageMap = new Map(data.messages.map((item) => [item.id, item]));
20
63
  this.messageAdditionalMap = new Map(Object.entries(data.additional));
64
+ if (data.toolCalls) {
65
+ this.toolCallMap = new Map(Object.entries(data.toolCalls));
66
+ }
67
+ if (data.memorySummaries) {
68
+ this.memorySummaries = data.memorySummaries;
69
+ }
70
+ console.log('[MsgHistoryManager] Initialized with data:', {
71
+ messagesCount: this.messageMap.size,
72
+ toolCallsCount: this.toolCallMap.size,
73
+ memorySummariesCount: this.memorySummaries.length,
74
+ });
21
75
  }
22
76
  }
23
77
 
@@ -31,8 +85,133 @@ export class MsgHistoryManager extends Disposable {
31
85
  }
32
86
 
33
87
  public clearMessages() {
88
+ console.log('[MsgHistoryManager] Clearing all messages and related data');
34
89
  this.messageMap.clear();
35
90
  this.messageAdditionalMap.clear();
91
+ this.memorySummaries = [];
92
+ this.toolCallMap.clear();
93
+ }
94
+
95
+ private async compressMemory() {
96
+ const messages = this.messageList;
97
+ const summaryProvider = this.chatFeatureRegistry.getMessageSummaryProvider();
98
+
99
+ // 1. 短期记忆处理(保持完整信息)
100
+ if (messages.length <= this.memoryConfig.shortTermSize) {
101
+ return;
102
+ }
103
+
104
+ // 2. 中期记忆处理
105
+ const midTermStart = this.memoryConfig.shortTermSize;
106
+ const midTermEnd = Math.min(
107
+ messages.length,
108
+ this.memoryConfig.shortTermSize + this.memoryConfig.midTermSize,
109
+ );
110
+
111
+ if (midTermStart < midTermEnd) {
112
+ const midTermMessages = messages.slice(midTermStart, midTermEnd);
113
+
114
+ // 收集中期记忆的 toolCall 信息(保留参数和简化结果)
115
+ const midTermToolCalls: IToolCallInfo[] = [];
116
+ midTermMessages.forEach((msg) => {
117
+ const additional = this.messageAdditionalMap.get(msg.id);
118
+ if (additional?.toolCallId) {
119
+ const toolCall = this.toolCallMap.get(additional.toolCallId);
120
+ if (toolCall) {
121
+ midTermToolCalls.push({
122
+ id: toolCall.id,
123
+ name: toolCall.name,
124
+ args: toolCall.args,
125
+ // 中期记忆只保留简化的结果
126
+ result: typeof toolCall.result === 'object' ?
127
+ JSON.stringify(toolCall.result).slice(0, 100) + '...' :
128
+ String(toolCall.result).slice(0, 100) + '...',
129
+ });
130
+ }
131
+ }
132
+ });
133
+
134
+ // 对中期记忆进行总结
135
+ const midTermContents = midTermMessages.map((msg) => ({
136
+ role: msg.role,
137
+ content: msg.content,
138
+ }));
139
+
140
+ if (summaryProvider) {
141
+ const midTermSummary = await summaryProvider.getMessageSummary(midTermContents);
142
+ if (midTermSummary) {
143
+ this.memorySummaries.push({
144
+ content: midTermSummary,
145
+ timestamp: Date.now(),
146
+ messageIds: midTermMessages.map((msg) => msg.id),
147
+ toolCalls: midTermToolCalls.length > 0 ? midTermToolCalls : undefined,
148
+ });
149
+ }
150
+ }
151
+ }
152
+
153
+ // 3. 长期记忆处理
154
+ const longTermStart = midTermEnd;
155
+ const longTermEnd = Math.min(
156
+ messages.length,
157
+ this.memoryConfig.shortTermSize + this.memoryConfig.midTermSize + this.memoryConfig.longTermSize,
158
+ );
159
+
160
+ if (longTermStart < longTermEnd) {
161
+ const longTermMessages = messages.slice(longTermStart, longTermEnd);
162
+
163
+ // 对长期记忆进行更简洁的总结,不包含 toolCall 信息
164
+ const longTermContents = longTermMessages.map((msg) => ({
165
+ role: msg.role,
166
+ content: msg.content,
167
+ }));
168
+
169
+ if (summaryProvider) {
170
+ const longTermSummary = await summaryProvider.getMessageSummary(longTermContents);
171
+ if (longTermSummary) {
172
+ this.memorySummaries.push({
173
+ content: longTermSummary,
174
+ timestamp: Date.now(),
175
+ messageIds: longTermMessages.map((msg) => msg.id),
176
+ // 长期记忆不保留 toolCall 信息
177
+ });
178
+ }
179
+ }
180
+ }
181
+
182
+ // 4. 删除超出范围的消息
183
+ const maxSize = this.memoryConfig.shortTermSize +
184
+ this.memoryConfig.midTermSize +
185
+ this.memoryConfig.longTermSize;
186
+
187
+ if (messages.length > maxSize) {
188
+ const toRemove = messages.slice(maxSize);
189
+ toRemove.forEach((msg) => {
190
+ const additional = this.messageAdditionalMap.get(msg.id);
191
+ if (additional?.toolCallId) {
192
+ this.toolCallMap.delete(additional.toolCallId);
193
+ }
194
+ this.messageMap.delete(msg.id);
195
+ this.messageAdditionalMap.delete(msg.id);
196
+ });
197
+ }
198
+ }
199
+
200
+ public addToolCall(toolCall: IToolCallInfo): void {
201
+ console.log('[MsgHistoryManager] Adding toolCall', {
202
+ toolCallId: toolCall.id,
203
+ toolName: toolCall.name,
204
+ });
205
+ this.toolCallMap.set(toolCall.id, toolCall);
206
+ }
207
+
208
+ public getToolCall(id: string): IToolCallInfo | undefined {
209
+ const toolCall = this.toolCallMap.get(id);
210
+ console.log('[MsgHistoryManager] Getting toolCall', {
211
+ toolCallId: id,
212
+ found: !!toolCall,
213
+ });
214
+ return toolCall;
36
215
  }
37
216
 
38
217
  private doAddMessage(message: IExcludeMessage): string {
@@ -46,9 +225,18 @@ export class MsgHistoryManager extends Disposable {
46
225
  type: message.type || 'string',
47
226
  };
48
227
 
228
+ console.log('[MsgHistoryManager] Adding new message', {
229
+ messageId: id,
230
+ role: message.role,
231
+ order,
232
+ });
233
+
49
234
  this.messageMap.set(id, msg);
50
235
 
51
- this._onMessageChange.fire(this.getMessages());
236
+ // 在添加新消息后尝试压缩记忆
237
+ this.compressMemory().then(() => {
238
+ this._onMessageChange.fire(this.getMessages());
239
+ });
52
240
  return id;
53
241
  }
54
242
 
@@ -65,9 +253,31 @@ export class MsgHistoryManager extends Disposable {
65
253
  return this.messageList;
66
254
  }
67
255
 
256
+ public getMemorySummaries(): IMemorySummary[] {
257
+ console.log('[MsgHistoryManager] Getting memory summaries', {
258
+ summariesCount: this.memorySummaries.length,
259
+ });
260
+ return this.memorySummaries;
261
+ }
262
+
263
+ public setMemoryConfig(config: Partial<IMemoryConfig>) {
264
+ console.log('[MsgHistoryManager] Updating memory config', {
265
+ oldConfig: this.memoryConfig,
266
+ newConfig: { ...this.memoryConfig, ...config },
267
+ });
268
+ this.memoryConfig = {
269
+ ...this.memoryConfig,
270
+ ...config,
271
+ };
272
+ }
273
+
68
274
  public addUserMessage(
69
275
  message: Required<Pick<IExcludeMessage, 'agentId' | 'agentCommand' | 'content' | 'relationId' | 'images'>>,
70
276
  ): string {
277
+ console.log('[MsgHistoryManager] Adding user message', {
278
+ agentId: message.agentId,
279
+ command: message.agentCommand,
280
+ });
71
281
  return this.doAddMessage({
72
282
  ...message,
73
283
  role: ChatMessageRole.User,
@@ -75,6 +285,7 @@ export class MsgHistoryManager extends Disposable {
75
285
  }
76
286
 
77
287
  public addAssistantMessage(message: Omit<IExcludeMessage, 'role'>): string {
288
+ console.log('[MsgHistoryManager] Adding assistant message');
78
289
  return this.doAddMessage({
79
290
  ...message,
80
291
  role: ChatMessageRole.Assistant,
@@ -83,10 +294,12 @@ export class MsgHistoryManager extends Disposable {
83
294
 
84
295
  public updateAssistantMessage(id: string, message: Omit<IExcludeMessage, 'role'>) {
85
296
  if (!this.messageMap.has(id)) {
297
+ console.log('[MsgHistoryManager] Failed to update assistant message: message not found', { messageId: id });
86
298
  return;
87
299
  }
88
300
 
89
301
  const oldMessage = this.messageMap.get(id);
302
+ console.log('[MsgHistoryManager] Updating assistant message', { messageId: id });
90
303
 
91
304
  this.messageMap.set(id, {
92
305
  ...oldMessage!,
@@ -96,6 +309,7 @@ export class MsgHistoryManager extends Disposable {
96
309
 
97
310
  public setMessageAdditional(id: string, additional: Record<string, any>) {
98
311
  if (!this.messageMap.has(id)) {
312
+ console.log('[MsgHistoryManager] Failed to set message additional: message not found', { messageId: id });
99
313
  return;
100
314
  }
101
315
 
@@ -105,6 +319,11 @@ export class MsgHistoryManager extends Disposable {
105
319
  ...additional,
106
320
  };
107
321
 
322
+ console.log('[MsgHistoryManager] Setting message additional', {
323
+ messageId: id,
324
+ hasToolCallId: !!additional.toolCallId,
325
+ });
326
+
108
327
  this.messageAdditionalMap.set(id, newAdditional);
109
328
  this._onMessageAdditionalChange.fire(newAdditional);
110
329
  }
@@ -118,9 +337,17 @@ export class MsgHistoryManager extends Disposable {
118
337
  }
119
338
 
120
339
  toJSON() {
121
- return {
340
+ const data = {
122
341
  messages: this.getMessages(),
123
342
  additional: Object.fromEntries(this.messageAdditionalMap.entries()),
343
+ memorySummaries: this.memorySummaries,
344
+ toolCalls: Object.fromEntries(this.toolCallMap.entries()),
124
345
  };
346
+ console.log('[MsgHistoryManager] Serializing to JSON', {
347
+ messagesCount: data.messages.length,
348
+ toolCallsCount: Object.keys(data.toolCalls).length,
349
+ memorySummariesCount: data.memorySummaries.length,
350
+ });
351
+ return data;
125
352
  }
126
353
  }
@@ -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,6 +5,7 @@ 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,
8
9
  ChatResponse,
9
10
  Deferred,
10
11
  IAICompletionOption,
@@ -134,6 +135,8 @@ export interface IChatFeatureRegistry {
134
135
  registerImageUploadProvider(provider: IImageUploadProvider): void;
135
136
  registerWelcome(content: IChatWelcomeMessageContent | React.ReactNode, sampleQuestions?: ISampleQuestions[]): void;
136
137
  registerSlashCommand(command: IChatSlashCommandItem, handler: IChatSlashCommandHandler): void;
138
+
139
+ registerMessageSummaryProvider(provider: IMessageSummaryProvider): void;
137
140
  }
138
141
 
139
142
  export type ChatWelcomeRender = (props: {
@@ -298,6 +301,15 @@ export interface IImageUploadProvider {
298
301
  imageUpload(file: File): Promise<DataContent | URL>;
299
302
  }
300
303
 
304
+ export interface IMessageSummaryProvider {
305
+ getMessageSummary(
306
+ messages: Array<{
307
+ role: ChatMessageRole;
308
+ content: string;
309
+ }>,
310
+ ): Promise<string | undefined>;
311
+ }
312
+
301
313
  export const AINativeCoreContribution = Symbol('AINativeCoreContribution');
302
314
 
303
315
  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';
@@ -333,6 +333,3 @@ export interface IInlineDiffService {
333
333
  }
334
334
 
335
335
  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
  }
@@ -135,11 +135,3 @@ export interface SSEClientTransportOptions {
135
135
  */
136
136
  requestInit?: RequestInit;
137
137
  }
138
-
139
- export interface ProjectRule {
140
- path: string;
141
- content: string;
142
- description?: string;
143
- globs?: string | string[];
144
- alwaysApply?: boolean;
145
- }
@@ -6,6 +6,7 @@ import { ChatReadableStream, INodeLogger } from '@opensumi/ide-core-node';
6
6
  import { CancellationToken } from '@opensumi/ide-utils';
7
7
 
8
8
  import { ModelInfo } from '../common';
9
+ import { compressToolResultSmart, getBase64ImageSize } from '../common/image-compression';
9
10
  import {
10
11
  IToolInvocationRegistryManager,
11
12
  ToolInvocationRegistryManager,
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- export interface ExtendedModelOption {
3
- label: string;
4
- value: string;
5
- icon?: string;
6
- iconClass?: string;
7
- tags?: string[];
8
- features?: string[];
9
- description?: string;
10
- disabled?: boolean;
11
- badge?: string;
12
- badgeColor?: string;
13
- selected?: boolean;
14
- }
15
- export interface MentionSelectProps {
16
- options: ExtendedModelOption[];
17
- value?: string;
18
- onChange?: (value: string) => void;
19
- placeholder?: string;
20
- disabled?: boolean;
21
- className?: string;
22
- size?: 'small' | 'medium' | 'large';
23
- showThinking?: boolean;
24
- thinkingEnabled?: boolean;
25
- onThinkingChange?: (enabled: boolean) => void;
26
- }
27
- export declare const MentionSelect: React.FC<MentionSelectProps>;
28
- //# sourceMappingURL=mention-select.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mention-select.d.ts","sourceRoot":"","sources":["../../../../src/browser/components/mention-input/mention-select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAO3D,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC/C;AAiBD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA6MtD,CAAC"}