Skip to content

Commit 67947c9

Browse files
committed
feat: support MCP Agent
1 parent 962ef62 commit 67947c9

File tree

7 files changed

+54
-390
lines changed

7 files changed

+54
-390
lines changed

src/ai/browser/ai-model.contribution.ts

Lines changed: 20 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Autowired } from '@opensumi/di'
2-
import { AI_NATIVE_SETTING_GROUP_ID, localize, MaybePromise, Delayer, CommandService } from '@opensumi/ide-core-common';
2+
import { AI_NATIVE_SETTING_GROUP_ID, localize, MaybePromise, Delayer, CommandService, AINativeSettingSectionsId } from '@opensumi/ide-core-common';
33
import { Domain, PreferenceContribution, PreferenceSchema, ClientAppContribution, IClientApp, PreferenceService, COMMON_COMMANDS, IPreferenceSettingsService } from '@opensumi/ide-core-browser'
44
import { ISettingRegistry, SettingContribution } from '@opensumi/ide-preferences';
55
import { AIModelServicePath, IAIModelServiceProxy, ModelSettingId } from '../common'
@@ -18,46 +18,6 @@ const aiNativePreferenceSchema: PreferenceSchema = {
1818
[ModelSettingId.apiKey]: {
1919
type: 'string',
2020
},
21-
[ModelSettingId.chatModelName]: {
22-
type: 'string',
23-
},
24-
[ModelSettingId.chatSystemPrompt]: {
25-
type: 'string',
26-
},
27-
[ModelSettingId.chatMaxTokens]: {
28-
type: 'number',
29-
minimum: 0,
30-
defaultValue: 1024,
31-
description: localize('preference.ai.model.maxTokens.description'),
32-
},
33-
[ModelSettingId.chatTemperature]: {
34-
type: 'string',
35-
// minimum: 0,
36-
// maximum: 1,
37-
defaultValue: '0.20',
38-
description: localize('preference.ai.model.temperature.description'),
39-
},
40-
[ModelSettingId.chatPresencePenalty]: {
41-
type: 'string',
42-
// minimum: -2.0,
43-
// maximum: 2.0,
44-
defaultValue: '1.0',
45-
description: localize('preference.ai.model.presencePenalty.description'),
46-
},
47-
[ModelSettingId.chatFrequencyPenalty]: {
48-
type: 'string',
49-
// minimum: -2.0,
50-
// maximum: 2.0,
51-
defaultValue: '1.0',
52-
description: localize('preference.ai.model.frequencyPenalty.description'),
53-
},
54-
[ModelSettingId.chatTopP]: {
55-
type: 'string',
56-
// minimum: 0,
57-
// maximum: 1,
58-
defaultValue: '1',
59-
description: localize('preference.ai.model.topP.description'),
60-
},
6121
[ModelSettingId.codeModelName]: {
6222
type: 'string',
6323
description: localize('preference.ai.model.code.modelName.tooltip')
@@ -145,11 +105,8 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
145105
delayer.trigger(() => this.setModeConfig(values))
146106
})
147107
})
148-
this.checkModelConfig(values).then((valid) => {
149-
if (valid) {
150-
delayer.trigger(() => this.setModeConfig(values))
151-
}
152-
})
108+
delayer.trigger(() => this.setModeConfig(values));
109+
this.checkModelConfig();
153110
}
154111

155112
registerSetting(registry: ISettingRegistry): void {
@@ -164,34 +121,6 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
164121
id: ModelSettingId.apiKey,
165122
localized: 'preference.ai.model.apiKey',
166123
},
167-
{
168-
id: ModelSettingId.chatModelName,
169-
localized: 'preference.ai.model.chat.modelName',
170-
},
171-
{
172-
id: ModelSettingId.chatSystemPrompt,
173-
localized: 'preference.ai.model.chat.systemPrompt',
174-
},
175-
{
176-
id: ModelSettingId.chatMaxTokens,
177-
localized: 'preference.ai.model.chat.maxTokens',
178-
},
179-
{
180-
id: ModelSettingId.chatTemperature,
181-
localized: 'preference.ai.model.chat.temperature',
182-
},
183-
{
184-
id: ModelSettingId.chatPresencePenalty,
185-
localized: 'preference.ai.model.chat.presencePenalty',
186-
},
187-
{
188-
id: ModelSettingId.chatFrequencyPenalty,
189-
localized: 'preference.ai.model.chat.frequencyPenalty',
190-
},
191-
{
192-
id: ModelSettingId.chatTopP,
193-
localized: 'preference.ai.model.chat.topP',
194-
},
195124
{
196125
id: ModelSettingId.codeModelName,
197126
localized: 'preference.ai.model.code.modelName',
@@ -228,18 +157,24 @@ export class AIModelContribution implements PreferenceContribution, SettingContr
228157
});
229158
}
230159

231-
private async checkModelConfig(values: Record<string, any>) {
232-
if (values.baseUrl && values.chatModelName) {
233-
return true
234-
}
235-
const res = await this.messageService.info(localize('ai.model.noConfig'), [
236-
localize('ai.model.go')
237-
])
238-
if (res === localize('ai.model.go')) {
239-
await this.commandService.executeCommand(COMMON_COMMANDS.OPEN_PREFERENCES.id)
240-
this.preferenceSettingsService.scrollToPreference(ModelSettingId.baseUrl)
160+
private async checkModelConfig() {
161+
const requirePreference = [
162+
AINativeSettingSectionsId.DeepseekApiKey,
163+
AINativeSettingSectionsId.OpenaiApiKey,
164+
AINativeSettingSectionsId.AnthropicApiKey,
165+
];
166+
167+
const hasRequirePreference = requirePreference.some(preference => !!this.preferenceService.getValid(preference));
168+
if (!hasRequirePreference) {
169+
this.preferenceService.has(AINativeSettingSectionsId.DeepseekApiKey);
170+
const res = await this.messageService.info(localize('ai.model.noConfig'), [
171+
localize('ai.model.go')
172+
]);
173+
if (res === localize('ai.model.go')) {
174+
await this.commandService.executeCommand(COMMON_COMMANDS.OPEN_PREFERENCES.id)
175+
this.preferenceSettingsService.scrollToPreference(AINativeSettingSectionsId.LLMModelSelection);
176+
}
241177
}
242-
return false
243178
}
244179

245180
private setModeConfig(values: Record<string, any>) {

src/ai/browser/ai-native.contribution.ts

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -72,146 +72,6 @@ export class AINativeContribution implements ComponentContribution, AINativeCore
7272
},
7373
],
7474
);
75-
76-
const interceptExecute = (value: string, slash: string, editor?: ICodeEditor): string => {
77-
if (!editor) {
78-
return '';
79-
}
80-
const model = editor.getModel();
81-
82-
const selection = editor.getSelection();
83-
let selectCode: string | undefined;
84-
if (selection) {
85-
selectCode = model!.getValueInRange(selection);
86-
}
87-
88-
const parseValue = value.replace(slash, '');
89-
90-
if (!parseValue.trim()) {
91-
if (!selectCode) {
92-
this.messageService.info('很抱歉,您并未选中或输入任何代码,请先选中或输入代码');
93-
return '';
94-
}
95-
96-
return value + `\n\`\`\`${model?.getLanguageId()}\n${selectCode}\n\`\`\``;
97-
}
98-
99-
return value;
100-
};
101-
102-
registry.registerSlashCommand(
103-
{
104-
name: 'Explain',
105-
description: '解释代码',
106-
isShortcut: true,
107-
tooltip: '解释代码',
108-
},
109-
{
110-
providerInputPlaceholder(_value, _editor) {
111-
return '请输入或者粘贴代码';
112-
},
113-
providerPrompt(value: string, editor?: ICodeEditor) {
114-
if (!editor) {
115-
return value;
116-
}
117-
const parseValue = value.replace('/Explain', '');
118-
const model = editor.getModel();
119-
return explainPrompt(model?.getLanguageId() || '', parseValue);
120-
},
121-
execute: (value: string, send: TChatSlashCommandSend, editor?: ICodeEditor) => {
122-
const parseValue = interceptExecute(value, '/Explain', editor);
123-
124-
if (!parseValue) {
125-
return;
126-
}
127-
128-
send(parseValue);
129-
},
130-
},
131-
);
132-
133-
registry.registerSlashCommand(
134-
{
135-
name: 'Test',
136-
description: '生成单测',
137-
isShortcut: true,
138-
tooltip: '生成单测'
139-
},
140-
{
141-
providerInputPlaceholder(_value, _editor) {
142-
return '请输入或者粘贴代码';
143-
},
144-
providerPrompt(value: string, editor?: ICodeEditor) {
145-
if (!editor) {
146-
return value;
147-
}
148-
const parseValue = value.replace('/Text', '');
149-
return testPrompt(parseValue);
150-
},
151-
execute: (value: string, send: TChatSlashCommandSend, editor?: ICodeEditor) => {
152-
const parseValue = interceptExecute(value, '/Text', editor);
153-
154-
if (!parseValue) {
155-
return;
156-
}
157-
158-
send(parseValue);
159-
},
160-
},
161-
);
162-
163-
registry.registerSlashCommand(
164-
{
165-
name: 'Optimize',
166-
description: '优化代码',
167-
isShortcut: true,
168-
tooltip: '优化代码'
169-
},
170-
{
171-
providerInputPlaceholder(_value, _editor) {
172-
return '请输入或者粘贴代码';
173-
},
174-
providerPrompt(value: string, editor?: ICodeEditor) {
175-
if (!editor) {
176-
return value;
177-
}
178-
const parseValue = value.replace('/Optimize', '');
179-
return optimizePrompt(parseValue);
180-
},
181-
execute: (value: string, send: TChatSlashCommandSend, editor?: ICodeEditor) => {
182-
const parseValue = interceptExecute(value, '/Optimize', editor);
183-
184-
if (!parseValue) {
185-
return;
186-
}
187-
188-
send(parseValue);
189-
},
190-
},
191-
);
192-
193-
registry.registerSlashCommand(
194-
{
195-
name: 'IDE',
196-
description: '执行 IDE 相关命令',
197-
},
198-
{
199-
providerInputPlaceholder(_value, _editor) {
200-
return '可以问我任何问题,或键入主题 \"/\"';
201-
},
202-
providerRender: CommandRender,
203-
execute: (value: string, send: TChatSlashCommandSend) => {
204-
const parseValue = value.replace('/IDE', '');
205-
206-
if (!parseValue) {
207-
this.messageService.warning('请输入要执行的 IDE 命令');
208-
return;
209-
}
210-
211-
send(parseValue);
212-
},
213-
},
214-
);
21575
}
21676

21777
registerInlineChatFeature(registry: IInlineChatFeatureRegistry) {

src/ai/common/types.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ export interface IAIModelServiceProxy {
99
export const ModelSettingId = {
1010
baseUrl: 'ai.model.baseUrl',
1111
apiKey: 'ai.model.apiKey',
12-
chatModelName: 'ai.model.chat.modelName',
13-
chatSystemPrompt: 'ai.model.chat.systemPrompt',
14-
chatTemperature: 'ai.model.chat.temperature',
15-
chatMaxTokens: 'ai.model.chat.maxTokens',
16-
chatPresencePenalty: 'ai.model.chat.presencePenalty',
17-
chatFrequencyPenalty: 'ai.model.chat.frequencyPenalty',
18-
chatTopP: 'ai.model.chat.topP',
1912
codeModelName: 'ai.model.code.modelName',
2013
codeSystemPrompt: 'ai.model.code.systemPrompt',
2114
codeFimTemplate: 'ai.model.code.fimTemplate',

0 commit comments

Comments
 (0)