@opensumi/ide-ai-native 3.9.1-next-1749007675.0 → 3.9.1-next-1749008258.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/chat/chat-manager.service.d.ts +0 -1
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +3 -8
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +1 -3
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +17 -48
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts +0 -2
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +50 -57
- package/lib/browser/chat/chat-proxy.service.js.map +1 -1
- package/lib/browser/chat/chat.feature.registry.d.ts +1 -4
- package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
- package/lib/browser/chat/chat.feature.registry.js +0 -6
- package/lib/browser/chat/chat.feature.registry.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +12 -29
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
- package/lib/browser/components/ChatMentionInput.js +141 -30
- package/lib/browser/components/ChatMentionInput.js.map +1 -1
- package/lib/browser/components/ChatToolRender.module.less +1 -0
- package/lib/browser/components/components.module.less +9 -8
- package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
- package/lib/browser/components/mention-input/mention-input.js +161 -14
- package/lib/browser/components/mention-input/mention-input.js.map +1 -1
- package/lib/browser/components/mention-input/mention-input.module.less +165 -1
- package/lib/browser/components/mention-input/mention-select.d.ts +28 -0
- package/lib/browser/components/mention-input/mention-select.d.ts.map +1 -0
- package/lib/browser/components/mention-input/mention-select.js +136 -0
- package/lib/browser/components/mention-input/mention-select.js.map +1 -0
- package/lib/browser/components/mention-input/mention-select.module.less +297 -0
- package/lib/browser/components/mention-input/types.d.ts +16 -1
- package/lib/browser/components/mention-input/types.d.ts.map +1 -1
- package/lib/browser/components/mention-input/types.js +1 -0
- package/lib/browser/components/mention-input/types.js.map +1 -1
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/context/llm-context.service.d.ts +21 -2
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +162 -20
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -1
- package/lib/browser/contrib/terminal/terminal.feature.registry.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +7 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +2 -2
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +1 -39
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +3 -170
- package/lib/browser/model/msg-history-manager.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +5 -0
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/rules/rules.contribution.d.ts +29 -0
- package/lib/browser/rules/rules.contribution.d.ts.map +1 -0
- package/lib/browser/rules/rules.contribution.js +94 -0
- package/lib/browser/rules/rules.contribution.js.map +1 -0
- package/lib/browser/rules/rules.module.less +175 -0
- package/lib/browser/rules/rules.service.d.ts +25 -0
- package/lib/browser/rules/rules.service.d.ts.map +1 -0
- package/lib/browser/rules/rules.service.js +180 -0
- package/lib/browser/rules/rules.service.js.map +1 -0
- package/lib/browser/rules/rules.view.d.ts +3 -0
- package/lib/browser/rules/rules.view.d.ts.map +1 -0
- package/lib/browser/rules/rules.view.js +76 -0
- package/lib/browser/rules/rules.view.js.map +1 -0
- package/lib/browser/types.d.ts +1 -8
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
- package/lib/common/MDC_PARSER_README.md +171 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/llm-context.d.ts +19 -0
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/mdc-parser.d.ts +60 -0
- package/lib/common/mdc-parser.d.ts.map +1 -0
- package/lib/common/mdc-parser.js +246 -0
- package/lib/common/mdc-parser.js.map +1 -0
- package/lib/common/prompts/context-prompt-provider.d.ts +0 -2
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +35 -29
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/lib/common/prompts/system-prompt.d.ts +2 -0
- package/lib/common/prompts/system-prompt.d.ts.map +1 -0
- package/lib/common/prompts/system-prompt.js +5 -0
- package/lib/common/prompts/system-prompt.js.map +1 -0
- package/lib/common/types.d.ts +7 -0
- package/lib/common/types.d.ts.map +1 -1
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js.map +1 -1
- package/package.json +25 -24
- package/src/browser/chat/chat-manager.service.ts +6 -15
- package/src/browser/chat/chat-model.ts +19 -56
- package/src/browser/chat/chat-proxy.service.ts +68 -81
- package/src/browser/chat/chat.feature.registry.ts +1 -17
- package/src/browser/chat/chat.view.tsx +22 -28
- package/src/browser/components/ChatMentionInput.tsx +169 -35
- package/src/browser/components/ChatToolRender.module.less +1 -0
- package/src/browser/components/components.module.less +9 -8
- package/src/browser/components/mention-input/mention-input.module.less +165 -1
- package/src/browser/components/mention-input/mention-input.tsx +257 -32
- package/src/browser/components/mention-input/mention-select.module.less +297 -0
- package/src/browser/components/mention-input/mention-select.tsx +256 -0
- package/src/browser/components/mention-input/types.ts +16 -0
- package/src/browser/context/llm-context.service.ts +182 -21
- package/src/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.ts +1 -1
- package/src/browser/contrib/intelligent-completions/diff-computer.ts +1 -1
- package/src/browser/contrib/terminal/terminal.feature.registry.ts +1 -1
- package/src/browser/index.ts +8 -0
- package/src/browser/mcp/base-apply.service.ts +0 -1
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
- package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
- package/src/browser/mcp/tools/handlers/ListDir.ts +1 -1
- package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
- package/src/browser/model/msg-history-manager.ts +3 -230
- package/src/browser/preferences/schema.ts +5 -0
- package/src/browser/rules/rules.contribution.ts +105 -0
- package/src/browser/rules/rules.module.less +175 -0
- package/src/browser/rules/rules.service.ts +189 -0
- package/src/browser/rules/rules.view.tsx +127 -0
- package/src/browser/types.ts +0 -12
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +0 -1
- package/src/common/MDC_PARSER_README.md +171 -0
- package/src/common/index.ts +3 -0
- package/src/common/llm-context.ts +23 -0
- package/src/common/mdc-parser.ts +295 -0
- package/src/common/prompts/context-prompt-provider.ts +55 -40
- package/src/common/prompts/system-prompt.ts +2 -0
- package/src/common/types.ts +8 -0
- package/src/node/base-language-model.ts +0 -1
|
@@ -2,7 +2,7 @@ import * as path from 'path';
|
|
|
2
2
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import { Autowired
|
|
5
|
+
import { Autowired } from '@opensumi/di';
|
|
6
6
|
import { Domain, URI } from '@opensumi/ide-core-common';
|
|
7
7
|
import { WorkbenchEditorService } from '@opensumi/ide-editor';
|
|
8
8
|
import { IWorkspaceService } from '@opensumi/ide-workspace';
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
import { Autowired } from '@opensumi/di';
|
|
4
4
|
import { AppConfig } from '@opensumi/ide-core-browser';
|
|
5
|
-
import {
|
|
5
|
+
import { Domain } from '@opensumi/ide-core-common';
|
|
6
6
|
import { ITerminalController, ITerminalGroupViewService } from '@opensumi/ide-terminal-next/lib/common/controller';
|
|
7
7
|
|
|
8
8
|
import { IMCPServerRegistry, MCPLogger, MCPServerContribution, MCPToolDefinition } from '../../types';
|
|
@@ -1,40 +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
|
-
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
|
-
|
|
33
6
|
export class MsgHistoryManager extends Disposable {
|
|
34
7
|
private messageMap: Map<string, IHistoryChatMessage> = new Map();
|
|
35
8
|
private messageAdditionalMap: Map<string, Record<string, any>> = new Map();
|
|
36
|
-
private memorySummaries: IMemorySummary[] = [];
|
|
37
|
-
private toolCallMap: Map<string, IToolCallInfo> = new Map();
|
|
38
9
|
|
|
39
10
|
private readonly _onMessageChange = new Emitter<IHistoryChatMessage[]>();
|
|
40
11
|
public readonly onMessageChange: Event<IHistoryChatMessage[]> = this._onMessageChange.event;
|
|
@@ -42,36 +13,11 @@ export class MsgHistoryManager extends Disposable {
|
|
|
42
13
|
private readonly _onMessageAdditionalChange = new Emitter<Record<string, any>>();
|
|
43
14
|
public readonly onMessageAdditionalChange: Event<Record<string, any>> = this._onMessageAdditionalChange.event;
|
|
44
15
|
|
|
45
|
-
|
|
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
|
-
) {
|
|
16
|
+
constructor(data?: { additional: Record<string, any>; messages: IHistoryChatMessage[] }) {
|
|
60
17
|
super();
|
|
61
18
|
if (data) {
|
|
62
19
|
this.messageMap = new Map(data.messages.map((item) => [item.id, item]));
|
|
63
20
|
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
|
-
});
|
|
75
21
|
}
|
|
76
22
|
}
|
|
77
23
|
|
|
@@ -85,133 +31,8 @@ export class MsgHistoryManager extends Disposable {
|
|
|
85
31
|
}
|
|
86
32
|
|
|
87
33
|
public clearMessages() {
|
|
88
|
-
console.log('[MsgHistoryManager] Clearing all messages and related data');
|
|
89
34
|
this.messageMap.clear();
|
|
90
35
|
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;
|
|
215
36
|
}
|
|
216
37
|
|
|
217
38
|
private doAddMessage(message: IExcludeMessage): string {
|
|
@@ -225,18 +46,9 @@ export class MsgHistoryManager extends Disposable {
|
|
|
225
46
|
type: message.type || 'string',
|
|
226
47
|
};
|
|
227
48
|
|
|
228
|
-
console.log('[MsgHistoryManager] Adding new message', {
|
|
229
|
-
messageId: id,
|
|
230
|
-
role: message.role,
|
|
231
|
-
order,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
49
|
this.messageMap.set(id, msg);
|
|
235
50
|
|
|
236
|
-
|
|
237
|
-
this.compressMemory().then(() => {
|
|
238
|
-
this._onMessageChange.fire(this.getMessages());
|
|
239
|
-
});
|
|
51
|
+
this._onMessageChange.fire(this.getMessages());
|
|
240
52
|
return id;
|
|
241
53
|
}
|
|
242
54
|
|
|
@@ -253,31 +65,9 @@ export class MsgHistoryManager extends Disposable {
|
|
|
253
65
|
return this.messageList;
|
|
254
66
|
}
|
|
255
67
|
|
|
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
|
-
|
|
274
68
|
public addUserMessage(
|
|
275
69
|
message: Required<Pick<IExcludeMessage, 'agentId' | 'agentCommand' | 'content' | 'relationId' | 'images'>>,
|
|
276
70
|
): string {
|
|
277
|
-
console.log('[MsgHistoryManager] Adding user message', {
|
|
278
|
-
agentId: message.agentId,
|
|
279
|
-
command: message.agentCommand,
|
|
280
|
-
});
|
|
281
71
|
return this.doAddMessage({
|
|
282
72
|
...message,
|
|
283
73
|
role: ChatMessageRole.User,
|
|
@@ -285,7 +75,6 @@ export class MsgHistoryManager extends Disposable {
|
|
|
285
75
|
}
|
|
286
76
|
|
|
287
77
|
public addAssistantMessage(message: Omit<IExcludeMessage, 'role'>): string {
|
|
288
|
-
console.log('[MsgHistoryManager] Adding assistant message');
|
|
289
78
|
return this.doAddMessage({
|
|
290
79
|
...message,
|
|
291
80
|
role: ChatMessageRole.Assistant,
|
|
@@ -294,12 +83,10 @@ export class MsgHistoryManager extends Disposable {
|
|
|
294
83
|
|
|
295
84
|
public updateAssistantMessage(id: string, message: Omit<IExcludeMessage, 'role'>) {
|
|
296
85
|
if (!this.messageMap.has(id)) {
|
|
297
|
-
console.log('[MsgHistoryManager] Failed to update assistant message: message not found', { messageId: id });
|
|
298
86
|
return;
|
|
299
87
|
}
|
|
300
88
|
|
|
301
89
|
const oldMessage = this.messageMap.get(id);
|
|
302
|
-
console.log('[MsgHistoryManager] Updating assistant message', { messageId: id });
|
|
303
90
|
|
|
304
91
|
this.messageMap.set(id, {
|
|
305
92
|
...oldMessage!,
|
|
@@ -309,7 +96,6 @@ export class MsgHistoryManager extends Disposable {
|
|
|
309
96
|
|
|
310
97
|
public setMessageAdditional(id: string, additional: Record<string, any>) {
|
|
311
98
|
if (!this.messageMap.has(id)) {
|
|
312
|
-
console.log('[MsgHistoryManager] Failed to set message additional: message not found', { messageId: id });
|
|
313
99
|
return;
|
|
314
100
|
}
|
|
315
101
|
|
|
@@ -319,11 +105,6 @@ export class MsgHistoryManager extends Disposable {
|
|
|
319
105
|
...additional,
|
|
320
106
|
};
|
|
321
107
|
|
|
322
|
-
console.log('[MsgHistoryManager] Setting message additional', {
|
|
323
|
-
messageId: id,
|
|
324
|
-
hasToolCallId: !!additional.toolCallId,
|
|
325
|
-
});
|
|
326
|
-
|
|
327
108
|
this.messageAdditionalMap.set(id, newAdditional);
|
|
328
109
|
this._onMessageAdditionalChange.fire(newAdditional);
|
|
329
110
|
}
|
|
@@ -337,17 +118,9 @@ export class MsgHistoryManager extends Disposable {
|
|
|
337
118
|
}
|
|
338
119
|
|
|
339
120
|
toJSON() {
|
|
340
|
-
|
|
121
|
+
return {
|
|
341
122
|
messages: this.getMessages(),
|
|
342
123
|
additional: Object.fromEntries(this.messageAdditionalMap.entries()),
|
|
343
|
-
memorySummaries: this.memorySummaries,
|
|
344
|
-
toolCalls: Object.fromEntries(this.toolCallMap.entries()),
|
|
345
124
|
};
|
|
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;
|
|
352
125
|
}
|
|
353
126
|
}
|
|
@@ -177,5 +177,10 @@ 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
|
+
},
|
|
180
185
|
},
|
|
181
186
|
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import { getIcon } from '@opensumi/ide-components';
|
|
3
|
+
import { ClientAppContribution } from '@opensumi/ide-core-browser';
|
|
4
|
+
import { LabelService } from '@opensumi/ide-core-browser/lib/services';
|
|
5
|
+
import {
|
|
6
|
+
CommandContribution,
|
|
7
|
+
CommandRegistry,
|
|
8
|
+
Domain,
|
|
9
|
+
RulesServiceToken,
|
|
10
|
+
URI,
|
|
11
|
+
localize,
|
|
12
|
+
} from '@opensumi/ide-core-common';
|
|
13
|
+
import {
|
|
14
|
+
BrowserEditorContribution,
|
|
15
|
+
EditorComponentRegistry,
|
|
16
|
+
EditorComponentRenderMode,
|
|
17
|
+
IResource,
|
|
18
|
+
ResourceService,
|
|
19
|
+
WorkbenchEditorService,
|
|
20
|
+
} from '@opensumi/ide-editor/lib/browser/types';
|
|
21
|
+
import { IconService } from '@opensumi/ide-theme/lib/browser';
|
|
22
|
+
import { IWorkspaceService } from '@opensumi/ide-workspace/lib/common';
|
|
23
|
+
|
|
24
|
+
import { RulesService } from './rules.service';
|
|
25
|
+
import { RulesView } from './rules.view';
|
|
26
|
+
|
|
27
|
+
export namespace RulesCommands {
|
|
28
|
+
export const OPEN_RULES_FILE = {
|
|
29
|
+
id: 'rules.openRulesConfig',
|
|
30
|
+
label: 'Open Rules Configuration',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const COMPONENTS_ID = 'opensumi-rules-viewer';
|
|
35
|
+
export const RULES_COMPONENTS_SCHEME_ID = 'rules';
|
|
36
|
+
|
|
37
|
+
export type IRulesResource = IResource<{ configType: string }>;
|
|
38
|
+
|
|
39
|
+
@Domain(BrowserEditorContribution, CommandContribution, ClientAppContribution)
|
|
40
|
+
export class RulesContribution implements BrowserEditorContribution, CommandContribution, ClientAppContribution {
|
|
41
|
+
@Autowired(IWorkspaceService)
|
|
42
|
+
protected readonly workspaceService: IWorkspaceService;
|
|
43
|
+
|
|
44
|
+
@Autowired(IconService)
|
|
45
|
+
protected readonly iconService: IconService;
|
|
46
|
+
|
|
47
|
+
@Autowired(WorkbenchEditorService)
|
|
48
|
+
protected readonly editorService: WorkbenchEditorService;
|
|
49
|
+
|
|
50
|
+
@Autowired()
|
|
51
|
+
labelService: LabelService;
|
|
52
|
+
|
|
53
|
+
@Autowired(RulesServiceToken)
|
|
54
|
+
protected readonly rulesService: RulesService;
|
|
55
|
+
|
|
56
|
+
onStart() {
|
|
57
|
+
this.rulesService.initProjectRules();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
registerEditorComponent(registry: EditorComponentRegistry) {
|
|
61
|
+
registry.registerEditorComponent({
|
|
62
|
+
uid: COMPONENTS_ID,
|
|
63
|
+
scheme: RULES_COMPONENTS_SCHEME_ID,
|
|
64
|
+
component: RulesView,
|
|
65
|
+
renderMode: EditorComponentRenderMode.ONE_PER_WORKBENCH,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
registry.registerEditorComponentResolver(RULES_COMPONENTS_SCHEME_ID, (resource, results) => {
|
|
69
|
+
results.push({
|
|
70
|
+
type: 'component',
|
|
71
|
+
componentId: COMPONENTS_ID,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
registerResource(service: ResourceService) {
|
|
77
|
+
service.registerResourceProvider({
|
|
78
|
+
scheme: RULES_COMPONENTS_SCHEME_ID,
|
|
79
|
+
provideResource: async (uri: URI): Promise<IRulesResource> => {
|
|
80
|
+
const { configType } = uri.getParsedQuery();
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
uri,
|
|
84
|
+
name: localize('ai.native.rules.title'),
|
|
85
|
+
icon: getIcon('rules'),
|
|
86
|
+
metadata: {
|
|
87
|
+
configType,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
registerCommands(registry: CommandRegistry) {
|
|
95
|
+
registry.registerCommand(RulesCommands.OPEN_RULES_FILE, {
|
|
96
|
+
execute: () => {
|
|
97
|
+
const uri = new URI().withScheme(RULES_COMPONENTS_SCHEME_ID);
|
|
98
|
+
this.editorService.open(uri, {
|
|
99
|
+
preview: false,
|
|
100
|
+
focus: true,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
padding: 20px;
|
|
3
|
+
color: var(--foreground);
|
|
4
|
+
textarea {
|
|
5
|
+
resize: vertical;
|
|
6
|
+
min-height: 60px;
|
|
7
|
+
}
|
|
8
|
+
input,
|
|
9
|
+
textarea {
|
|
10
|
+
width: 100%;
|
|
11
|
+
padding: 8px;
|
|
12
|
+
border: 1px solid var(--input-border);
|
|
13
|
+
border-radius: 4px;
|
|
14
|
+
background-color: var(--input-background);
|
|
15
|
+
color: var(--input-foreground);
|
|
16
|
+
font-size: 13px;
|
|
17
|
+
font-family: var(--monaco-monospace-font);
|
|
18
|
+
|
|
19
|
+
&:focus {
|
|
20
|
+
border-color: var(--focusBorder);
|
|
21
|
+
outline: none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&::placeholder {
|
|
25
|
+
color: var(--descriptionForeground);
|
|
26
|
+
opacity: 0.6;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.header {
|
|
32
|
+
display: flex;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
align-items: flex-start;
|
|
35
|
+
margin-bottom: 24px;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.title {
|
|
39
|
+
margin: 0 0 8px 0;
|
|
40
|
+
font-size: 24px;
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.description {
|
|
45
|
+
margin: 0;
|
|
46
|
+
color: var(--descriptionForeground);
|
|
47
|
+
font-size: 14px;
|
|
48
|
+
line-height: 1.5;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.user_rules {
|
|
52
|
+
display: flex;
|
|
53
|
+
flex-direction: column;
|
|
54
|
+
gap: 16px;
|
|
55
|
+
.user_rules_header {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.project_rules {
|
|
62
|
+
margin-top: 20px;
|
|
63
|
+
display: flex;
|
|
64
|
+
flex-direction: column;
|
|
65
|
+
gap: 16px;
|
|
66
|
+
h3 {
|
|
67
|
+
position: relative;
|
|
68
|
+
}
|
|
69
|
+
.actionButton {
|
|
70
|
+
position: absolute;
|
|
71
|
+
right: 0;
|
|
72
|
+
top: 0;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.project_rules_header {
|
|
77
|
+
display: flex;
|
|
78
|
+
justify-content: space-between;
|
|
79
|
+
align-items: flex-start;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.project_rules_header_left {
|
|
83
|
+
width: 100%;
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.actionButton {
|
|
89
|
+
padding: 8px 16px;
|
|
90
|
+
border-radius: 4px;
|
|
91
|
+
background-color: var(--button-primary-background);
|
|
92
|
+
color: var(--button-primary-foreground);
|
|
93
|
+
border: none;
|
|
94
|
+
cursor: pointer;
|
|
95
|
+
font-size: 13px;
|
|
96
|
+
.actionButtonIcon {
|
|
97
|
+
margin-right: 5px;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
&:hover {
|
|
101
|
+
background-color: var(--button-primary-hover-background);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.project_rules_list {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: column;
|
|
108
|
+
gap: 8px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.rule_item {
|
|
112
|
+
display: flex;
|
|
113
|
+
justify-content: space-between;
|
|
114
|
+
align-items: center;
|
|
115
|
+
padding: 12px;
|
|
116
|
+
border: 1px solid var(--input-border);
|
|
117
|
+
border-radius: 4px;
|
|
118
|
+
background-color: var(--input-background);
|
|
119
|
+
opacity: 0.6;
|
|
120
|
+
|
|
121
|
+
&:hover {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.rule_item_left {
|
|
127
|
+
display: flex;
|
|
128
|
+
flex-direction: column;
|
|
129
|
+
gap: 4px;
|
|
130
|
+
flex: 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.rule_item_right {
|
|
134
|
+
display: flex;
|
|
135
|
+
align-items: center;
|
|
136
|
+
flex-shrink: 0;
|
|
137
|
+
margin-left: 16px;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.rule_filename {
|
|
141
|
+
font-size: 13px;
|
|
142
|
+
font-weight: 500;
|
|
143
|
+
color: var(--foreground);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.rule_description {
|
|
147
|
+
font-size: 12px;
|
|
148
|
+
color: var(--descriptionForeground);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.rule_warning {
|
|
152
|
+
font-size: 12px;
|
|
153
|
+
color: var(--editorWarning-foreground);
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: center;
|
|
156
|
+
gap: 4px;
|
|
157
|
+
|
|
158
|
+
&::before {
|
|
159
|
+
content: '⚠';
|
|
160
|
+
color: var(--editorWarning-foreground);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.rule_applies_to {
|
|
165
|
+
font-size: 12px;
|
|
166
|
+
color: var(--descriptionForeground);
|
|
167
|
+
font-family: var(--monaco-monospace-font);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.empty_state {
|
|
171
|
+
text-align: center;
|
|
172
|
+
padding: 32px;
|
|
173
|
+
color: var(--descriptionForeground);
|
|
174
|
+
font-style: italic;
|
|
175
|
+
}
|