Skip to content

Commit 8dbe60e

Browse files
authored
Merge branch 'v3.8' into chore/improve-chat-context
2 parents 985cc40 + ebcf173 commit 8dbe60e

7 files changed

Lines changed: 50 additions & 19 deletions

File tree

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

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,13 @@ export class AINativeBrowserContribution
319319
}
320320
}
321321

322+
onReconnect(): void {
323+
const { supportsMCP } = this.aiNativeConfigService.capabilities;
324+
if (supportsMCP) {
325+
this.initMCPServers();
326+
}
327+
}
328+
322329
onDidStart() {
323330
runWhenIdle(() => {
324331
const { supportsRenameSuggestions, supportsInlineChat, supportsMCP } = this.aiNativeConfigService.capabilities;
@@ -339,26 +346,28 @@ export class AINativeBrowserContribution
339346
}
340347

341348
if (supportsMCP) {
342-
// 从 preferences 获取并初始化外部 MCP Servers
343-
const mcpServers = this.preferenceService.getValid<MCPServerDescription[]>(
344-
AINativeSettingSectionsId.MCPServers,
345-
);
349+
this.initMCPServers();
350+
}
351+
});
352+
}
346353

347-
// 查找内置 MCP Server 的配置
348-
const builtinServer = mcpServers?.find((server) => server.name === BUILTIN_MCP_SERVER_NAME);
354+
private initMCPServers() {
355+
// 从 preferences 获取并初始化外部 MCP Servers
356+
const mcpServers = this.preferenceService.getValid<MCPServerDescription[]>(AINativeSettingSectionsId.MCPServers);
349357

350-
// 总是初始化内置服务器,根据配置决定是否启用
351-
this.sumiMCPServerBackendProxy.initBuiltinMCPServer(builtinServer?.enabled ?? true);
358+
// 查找内置 MCP Server 的配置
359+
const builtinServer = mcpServers?.find((server) => server.name === BUILTIN_MCP_SERVER_NAME);
352360

353-
// 初始化其他外部 MCP Servers
354-
if (mcpServers && mcpServers.length > 0) {
355-
const externalServers = mcpServers.filter((server) => server.name !== BUILTIN_MCP_SERVER_NAME);
356-
if (externalServers.length > 0) {
357-
this.sumiMCPServerBackendProxy.initExternalMCPServers(externalServers);
358-
}
359-
}
361+
// 总是初始化内置服务器,根据配置决定是否启用
362+
this.sumiMCPServerBackendProxy.initBuiltinMCPServer(builtinServer?.enabled ?? true);
363+
364+
// 初始化其他外部 MCP Servers
365+
if (mcpServers && mcpServers.length > 0) {
366+
const externalServers = mcpServers.filter((server) => server.name !== BUILTIN_MCP_SERVER_NAME);
367+
if (externalServers.length > 0) {
368+
this.sumiMCPServerBackendProxy.initExternalMCPServers(externalServers);
360369
}
361-
});
370+
}
362371
}
363372

364373
private registerFeature() {

packages/ai-native/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class IntelligentCompletionsController extends BaseAIMonacoEditorControll
290290
const range = completionModel.items[0].range;
291291
if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) {
292292
runWhenIdle(() => {
293-
this.discard.get();
293+
this.hide();
294294
});
295295
}
296296
}

packages/ai-native/src/browser/contrib/intelligent-completions/view/default.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AI_CODE_EDITS_COMMANDS } from '@opensumi/ide-core-browser/lib/ai-native/command';
2+
import { CommandService } from '@opensumi/ide-core-common';
13
import {
24
InlineCompletionContext,
35
InlineCompletionTriggerKind,
@@ -27,6 +29,7 @@ import {
2729

2830
import { CodeEditsResultValue, ICodeEdit, ICodeEditsResult } from '../index';
2931

32+
3033
import { BaseCodeEditsView } from './base';
3134

3235
/**
@@ -115,6 +118,10 @@ export class DefaultCodeEditsView extends BaseCodeEditsView {
115118
return completionModel;
116119
},
117120
freeInlineCompletions: () => [],
121+
handleRejection: (completions, item) => {
122+
const commandService: CommandService = this.injector.get(CommandService);
123+
commandService.executeCommand(AI_CODE_EDITS_COMMANDS.DISCARD.id);
124+
},
118125
} as InlineCompletionsProvider<ICodeEditsResult<ICodeEdit>>,
119126
],
120127
} as unknown as LanguageFeatureRegistry<InlineCompletionsProvider>,

packages/ai-native/src/browser/mcp/tools/components/Terminal.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { memo, useCallback, useMemo, useState } from 'react';
33
import { useInjectable } from '@opensumi/ide-core-browser';
44
import { Button, Icon } from '@opensumi/ide-core-browser/lib/components';
55
import { localize } from '@opensumi/ide-core-common';
6+
import { stripAnsi } from '@opensumi/ide-utils/lib/ansi';
67

78
import { IMCPServerToolComponentProps } from '../../../types';
89
import { RunCommandHandler } from '../handlers/RunCommand';
@@ -58,13 +59,23 @@ export const TerminalToolComponent = memo((props: IMCPServerToolComponentProps)
5859
<div className={styles.run_cmd_tool}>
5960
{props.state === 'result' && (
6061
<div>
62+
{args && (
63+
<>
64+
<div className={styles.command_title}>
65+
<Icon icon='terminal' />
66+
<span>{localize('ai.native.mcp.terminal.command')}</span>
67+
</div>
68+
<p className={styles.command_content}>
69+
<code>$ {args.command}</code>
70+
</p>
71+
</>
72+
)}
6173
<div className={styles.command_title}>
62-
<Icon icon='terminal' />
6374
<span>{localize('ai.native.mcp.terminal.output')}</span>
6475
</div>
6576
{output ? (
6677
<div className={styles.command_content}>
67-
<code>{output.text}</code>
78+
<code>{stripAnsi(output.text)}</code>
6879
</div>
6980
) : (
7081
''

packages/core-browser/src/components/ai-native/interactive-input/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ export const InteractiveInput = React.forwardRef(
173173
const value = history.current?.[history.current.length - 1 - historyIndex.current];
174174
if (value) {
175175
setInternalValue(value);
176+
onValueChange?.(value);
176177
historyIndex.current = Math.min(historyIndex.current + 1, history.current?.length || 0);
177178
}
178179
} else if (event.key === Key.ARROW_DOWN.code) {
179180
event.preventDefault();
180181
const value = history.current?.[history.current.length - 1 - historyIndex.current];
181182
if (value) {
182183
setInternalValue(value);
184+
onValueChange?.(value);
183185
historyIndex.current = Math.max(historyIndex.current - 1, 0);
184186
}
185187
}

packages/i18n/src/common/en-US.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ export const localizationBundle = {
15761576
'preference.ai.native.mcp.servers.type.sse': 'SSE connection',
15771577

15781578
// MCP Terminal Tool
1579+
'ai.native.mcp.terminal.command': 'Command',
15791580
'ai.native.mcp.terminal.output': 'Output',
15801581
'ai.native.mcp.terminal.allow-question': 'Allow the terminal to run the command?',
15811582
'ai.native.mcp.terminal.allow': 'Allow',

packages/i18n/src/common/zh-CN.lang.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ export const localizationBundle = {
13391339
'preference.ai.native.mcp.servers.type.sse': 'SSE 连接',
13401340

13411341
// MCP Terminal Tool
1342+
'ai.native.mcp.terminal.command': '命令',
13421343
'ai.native.mcp.terminal.output': '输出',
13431344
'ai.native.mcp.terminal.allow-question': '是否允许运行命令?',
13441345
'ai.native.mcp.terminal.allow': '允许',

0 commit comments

Comments
 (0)