@opensumi/ide-ai-native 3.9.1-next-1749181695.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.
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +4 -9
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/apply.service.d.ts +0 -3
- package/lib/browser/chat/apply.service.d.ts.map +1 -1
- package/lib/browser/chat/apply.service.js +0 -47
- package/lib/browser/chat/apply.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +1 -3
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts +2 -0
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +57 -50
- 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 +8 -33
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatEditor.js +2 -2
- package/lib/browser/components/ChatEditor.js.map +1 -1
- package/lib/browser/components/ChatHistory.d.ts.map +1 -1
- package/lib/browser/components/ChatHistory.js +1 -2
- package/lib/browser/components/ChatHistory.js.map +1 -1
- package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
- package/lib/browser/components/ChatMentionInput.js +30 -148
- package/lib/browser/components/ChatMentionInput.js.map +1 -1
- package/lib/browser/components/ChatReply.js +2 -2
- package/lib/browser/components/ChatReply.js.map +1 -1
- package/lib/browser/components/ChatToolRender.d.ts.map +1 -1
- package/lib/browser/components/ChatToolRender.js +2 -7
- package/lib/browser/components/ChatToolRender.js.map +1 -1
- package/lib/browser/components/ChatToolRender.module.less +0 -25
- package/lib/browser/components/components.module.less +8 -37
- package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
- package/lib/browser/components/mention-input/mention-input.js +14 -150
- package/lib/browser/components/mention-input/mention-input.js.map +1 -1
- package/lib/browser/components/mention-input/mention-input.module.less +1 -165
- package/lib/browser/components/mention-input/types.d.ts +1 -28
- package/lib/browser/components/mention-input/types.d.ts.map +1 -1
- package/lib/browser/components/mention-input/types.js +0 -1
- 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 +2 -21
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +20 -162
- 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 +0 -7
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/layout/ai-layout.d.ts.map +1 -1
- package/lib/browser/layout/ai-layout.js +4 -6
- package/lib/browser/layout/ai-layout.js.map +1 -1
- package/lib/browser/layout/tabbar.view.d.ts +1 -1
- package/lib/browser/layout/tabbar.view.d.ts.map +1 -1
- package/lib/browser/layout/tabbar.view.js +12 -5
- package/lib/browser/layout/tabbar.view.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +4 -5
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js +5 -23
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts +1 -3
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.js +0 -4
- package/lib/browser/mcp/mcp-server-proxy.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/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +0 -5
- package/lib/browser/preferences/schema.js.map +1 -1
- 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/index.d.ts +1 -5
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -2
- package/lib/common/index.js.map +1 -1
- package/lib/common/llm-context.d.ts +0 -19
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/model.d.ts +0 -1
- package/lib/common/model.d.ts.map +1 -1
- package/lib/common/model.js.map +1 -1
- package/lib/common/prompts/context-prompt-provider.d.ts +2 -0
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +29 -35
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/lib/common/types.d.ts +0 -21
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/types.js.map +1 -1
- package/lib/common/utils.d.ts +0 -1
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +2 -5
- package/lib/common/utils.js.map +1 -1
- package/lib/node/anthropic/anthropic-language-model.d.ts +1 -1
- package/lib/node/base-language-model.d.ts +1 -2
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js +2 -12
- package/lib/node/base-language-model.js.map +1 -1
- package/lib/node/deepseek/deepseek-language-model.d.ts +1 -1
- package/lib/node/mcp/sumi-mcp-server.d.ts +1 -3
- package/lib/node/mcp/sumi-mcp-server.d.ts.map +1 -1
- package/lib/node/mcp/sumi-mcp-server.js +1 -7
- package/lib/node/mcp/sumi-mcp-server.js.map +1 -1
- package/lib/node/mcp-server-manager-impl.d.ts +1 -3
- package/lib/node/mcp-server-manager-impl.d.ts.map +1 -1
- package/lib/node/mcp-server-manager-impl.js +2 -14
- package/lib/node/mcp-server-manager-impl.js.map +1 -1
- package/package.json +25 -26
- package/src/browser/ai-core.contribution.ts +4 -14
- package/src/browser/chat/apply.service.ts +1 -62
- package/src/browser/chat/chat-model.ts +1 -3
- package/src/browser/chat/chat-proxy.service.ts +81 -68
- package/src/browser/chat/chat.feature.registry.ts +1 -17
- package/src/browser/chat/chat.view.tsx +10 -40
- package/src/browser/components/ChatEditor.tsx +1 -1
- package/src/browser/components/ChatHistory.tsx +1 -2
- package/src/browser/components/ChatMentionInput.tsx +35 -180
- package/src/browser/components/ChatReply.tsx +4 -4
- package/src/browser/components/ChatToolRender.module.less +0 -25
- package/src/browser/components/ChatToolRender.tsx +2 -10
- package/src/browser/components/components.module.less +8 -37
- package/src/browser/components/mention-input/mention-input.module.less +1 -165
- package/src/browser/components/mention-input/mention-input.tsx +31 -232
- package/src/browser/components/mention-input/types.ts +0 -29
- package/src/browser/context/llm-context.service.ts +21 -182
- 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 +0 -8
- package/src/browser/layout/ai-layout.tsx +8 -12
- package/src/browser/layout/tabbar.view.tsx +23 -10
- package/src/browser/mcp/base-apply.service.ts +10 -30
- package/src/browser/mcp/mcp-server-proxy.service.ts +1 -6
- 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/preferences/schema.ts +0 -5
- package/src/browser/types.ts +0 -12
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +1 -0
- package/src/common/index.ts +1 -6
- package/src/common/llm-context.ts +0 -23
- package/src/common/model.ts +0 -1
- package/src/common/prompts/context-prompt-provider.ts +40 -55
- package/src/common/types.ts +0 -18
- package/src/common/utils.ts +1 -4
- package/src/node/base-language-model.ts +14 -11
- package/src/node/mcp/sumi-mcp-server.ts +2 -10
- package/src/node/mcp-server-manager-impl.ts +2 -17
- package/lib/browser/components/mention-input/mention-select.d.ts +0 -28
- package/lib/browser/components/mention-input/mention-select.d.ts.map +0 -1
- package/lib/browser/components/mention-input/mention-select.js +0 -136
- package/lib/browser/components/mention-input/mention-select.js.map +0 -1
- package/lib/browser/components/mention-input/mention-select.module.less +0 -297
- package/lib/browser/rules/rules.contribution.d.ts +0 -29
- package/lib/browser/rules/rules.contribution.d.ts.map +0 -1
- package/lib/browser/rules/rules.contribution.js +0 -94
- package/lib/browser/rules/rules.contribution.js.map +0 -1
- package/lib/browser/rules/rules.module.less +0 -175
- package/lib/browser/rules/rules.service.d.ts +0 -25
- package/lib/browser/rules/rules.service.d.ts.map +0 -1
- package/lib/browser/rules/rules.service.js +0 -180
- package/lib/browser/rules/rules.service.js.map +0 -1
- package/lib/browser/rules/rules.view.d.ts +0 -3
- package/lib/browser/rules/rules.view.d.ts.map +0 -1
- package/lib/browser/rules/rules.view.js +0 -76
- package/lib/browser/rules/rules.view.js.map +0 -1
- package/lib/common/image-compression.d.ts +0 -25
- package/lib/common/image-compression.d.ts.map +0 -1
- package/lib/common/image-compression.js +0 -153
- package/lib/common/image-compression.js.map +0 -1
- package/lib/common/mdc-parser.d.ts +0 -60
- package/lib/common/mdc-parser.d.ts.map +0 -1
- package/lib/common/mdc-parser.js +0 -246
- package/lib/common/mdc-parser.js.map +0 -1
- package/lib/common/prompts/system-prompt.d.ts +0 -2
- package/lib/common/prompts/system-prompt.d.ts.map +0 -1
- package/lib/common/prompts/system-prompt.js +0 -5
- package/lib/common/prompts/system-prompt.js.map +0 -1
- package/src/browser/components/mention-input/mention-select.module.less +0 -297
- package/src/browser/components/mention-input/mention-select.tsx +0 -256
- package/src/browser/rules/rules.contribution.ts +0 -105
- package/src/browser/rules/rules.module.less +0 -175
- package/src/browser/rules/rules.service.ts +0 -189
- package/src/browser/rules/rules.view.tsx +0 -127
- package/src/common/image-compression.ts +0 -174
- package/src/common/mdc-parser.ts +0 -295
- package/src/common/prompts/system-prompt.ts +0 -2
package/src/browser/types.ts
CHANGED
|
@@ -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,15 +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
|
-
}
|
|
312
|
-
|
|
313
301
|
export const AINativeCoreContribution = Symbol('AINativeCoreContribution');
|
|
314
302
|
|
|
315
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';
|
package/src/common/index.ts
CHANGED
|
@@ -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 {
|
|
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 {
|
package/src/common/model.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
|
56
|
+
private buildPromptTemplate({
|
|
57
|
+
recentFiles,
|
|
74
58
|
attachedFiles,
|
|
75
59
|
attachedFolders,
|
|
76
60
|
currentFile,
|
|
77
|
-
attachedRules,
|
|
78
|
-
globalRules,
|
|
79
61
|
userMessage,
|
|
80
62
|
}: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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:
|
|
115
|
+
private buildFileContentSection(file: { path: string; content: string }): string {
|
|
132
116
|
return `<file_contents>
|
|
133
|
-
\`\`\`${file.path}
|
|
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
|
|
148
|
-
|
|
149
|
-
): string {
|
|
150
|
-
if (!fileInfo) {
|
|
131
|
+
private buildAttachedFoldersSection(folders: string[]): string {
|
|
132
|
+
if (!folders.length) {
|
|
151
133
|
return '';
|
|
152
134
|
}
|
|
153
135
|
|
|
154
|
-
|
|
136
|
+
return `<attached_folders>\n${folders.join('\n')}</attached_folders>`;
|
|
137
|
+
}
|
|
155
138
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
private buildCurrentFileSection(fileInfo: { path: string; languageId: string; content: string } | null): string {
|
|
140
|
+
if (!fileInfo) {
|
|
141
|
+
return '';
|
|
159
142
|
}
|
|
160
143
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
144
|
+
return `<current_opened_file>
|
|
145
|
+
\`\`\`${fileInfo.languageId} ${fileInfo.path}
|
|
146
|
+
${fileInfo.content}
|
|
147
|
+
\`\`\`
|
|
148
|
+
</current_opened_file>`;
|
|
164
149
|
}
|
|
165
150
|
}
|
package/src/common/types.ts
CHANGED
|
@@ -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
|
-
}
|
package/src/common/utils.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
|
@@ -116,7 +119,7 @@ export abstract class BaseLanguageModel {
|
|
|
116
119
|
messages,
|
|
117
120
|
abortSignal: abortController.signal,
|
|
118
121
|
experimental_toolCallStreaming: true,
|
|
119
|
-
maxSteps:
|
|
122
|
+
maxSteps: 12,
|
|
120
123
|
maxTokens,
|
|
121
124
|
system: systemPrompt,
|
|
122
125
|
providerOptions,
|
|
@@ -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,
|
|
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
|
|
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');
|
|
@@ -3,16 +3,14 @@ import { ToolExecutionOptions } from 'ai';
|
|
|
3
3
|
import { ILogger } from '@opensumi/ide-core-common';
|
|
4
4
|
import { getShellPath } from '@opensumi/ide-core-node';
|
|
5
5
|
|
|
6
|
-
import { ISumiMCPServerBackend } from '../common';
|
|
7
6
|
import { IMCPServer, MCPServerDescription, MCPServerManager, MCPTool } from '../common/mcp-server-manager';
|
|
8
7
|
import { IToolInvocationRegistryManager, ToolRequest } from '../common/tool-invocation-registry';
|
|
9
|
-
import {
|
|
8
|
+
import { MCP_SERVER_TYPE } from '../common/types';
|
|
10
9
|
import { getToolName } from '../common/utils';
|
|
11
10
|
|
|
12
11
|
import { BuiltinMCPServer } from './mcp/sumi-mcp-server';
|
|
13
12
|
import { SSEMCPServer } from './mcp-server.sse';
|
|
14
13
|
import { StdioMCPServer } from './mcp-server.stdio';
|
|
15
|
-
|
|
16
14
|
// 这应该是 Browser Tab 维度的,每个 Tab 对应一个 MCPServerManagerImpl
|
|
17
15
|
export class MCPServerManagerImpl implements MCPServerManager {
|
|
18
16
|
protected servers: Map<string, IMCPServer> = new Map();
|
|
@@ -29,7 +27,6 @@ export class MCPServerManagerImpl implements MCPServerManager {
|
|
|
29
27
|
constructor(
|
|
30
28
|
private readonly toolInvocationRegistryManager: IToolInvocationRegistryManager,
|
|
31
29
|
private readonly logger: ILogger,
|
|
32
|
-
private readonly proxy: ISumiMCPServerBackend,
|
|
33
30
|
) {}
|
|
34
31
|
|
|
35
32
|
async updateShellPath() {
|
|
@@ -113,19 +110,7 @@ export class MCPServerManagerImpl implements MCPServerManager {
|
|
|
113
110
|
const res = await this.callTool(serverName, tool.name, options?.toolCallId || '', arg_string);
|
|
114
111
|
this.logger.debug(`[MCP: ${serverName}] ${tool.name} called with ${arg_string}`);
|
|
115
112
|
this.logger.debug('Tool execution result:', res);
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
this.proxy?.$compressToolResult &&
|
|
119
|
-
(compressedResult.content || []).some((item) => item.type === 'image')
|
|
120
|
-
) {
|
|
121
|
-
compressedResult = await this.proxy.$compressToolResult(res as IMCPToolResult, {
|
|
122
|
-
maxSizeKB: 100,
|
|
123
|
-
maxWidth: 600,
|
|
124
|
-
quality: 0.6,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
this.logger.debug('Compressed tool execution result:', compressedResult);
|
|
128
|
-
return JSON.stringify(compressedResult);
|
|
113
|
+
return JSON.stringify(res);
|
|
129
114
|
} catch (error) {
|
|
130
115
|
this.logger.error(`Error in tool handler for ${tool.name} on MCP server ${serverName}:`, error);
|
|
131
116
|
throw error;
|
|
@@ -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"}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MentionSelect = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
6
|
-
const react_1 = tslib_1.__importStar(require("react"));
|
|
7
|
-
const click_outside_1 = require("@opensumi/ide-components/lib/click-outside");
|
|
8
|
-
const components_1 = require("@opensumi/ide-core-browser/lib/components");
|
|
9
|
-
const mention_select_module_less_1 = tslib_1.__importDefault(require("./mention-select.module.less"));
|
|
10
|
-
const ThinkingToggle = ({ enabled, onChange }) => (react_1.default.createElement("div", { className: mention_select_module_less_1.default.thinking_toggle, onClick: () => onChange(!enabled) },
|
|
11
|
-
react_1.default.createElement(components_1.Icon, { iconClass: (0, components_1.getIcon)(enabled ? 'check' : 'circle-outline'), className: (0, classnames_1.default)(mention_select_module_less_1.default.thinking_icon, {
|
|
12
|
-
[mention_select_module_less_1.default.enabled]: enabled,
|
|
13
|
-
}) }),
|
|
14
|
-
react_1.default.createElement("span", { className: mention_select_module_less_1.default.thinking_label }, "Thinking")));
|
|
15
|
-
const MentionSelect = ({ options, value, onChange, placeholder, disabled = false, className, size = 'small', showThinking = false, thinkingEnabled = false, onThinkingChange, }) => {
|
|
16
|
-
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
17
|
-
const [activeIndex, setActiveIndex] = (0, react_1.useState)(-1);
|
|
18
|
-
const [dropdownDirection, setDropdownDirection] = (0, react_1.useState)('up');
|
|
19
|
-
const selectRef = (0, react_1.useRef)(null);
|
|
20
|
-
const dropdownRef = (0, react_1.useRef)(null);
|
|
21
|
-
const selectedOption = options.find((option) => option.selected) || options.find((option) => option.value === value);
|
|
22
|
-
const handleToggle = () => {
|
|
23
|
-
if (!disabled) {
|
|
24
|
-
setIsOpen(!isOpen);
|
|
25
|
-
setActiveIndex(-1);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const handleSelect = (option) => {
|
|
29
|
-
if (!option.disabled) {
|
|
30
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(option.value);
|
|
31
|
-
setIsOpen(false);
|
|
32
|
-
setActiveIndex(-1);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
const handleKeyDown = (e) => {
|
|
36
|
-
if (disabled) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
switch (e.key) {
|
|
40
|
-
case 'Enter':
|
|
41
|
-
case ' ':
|
|
42
|
-
e.preventDefault();
|
|
43
|
-
if (!isOpen) {
|
|
44
|
-
setIsOpen(true);
|
|
45
|
-
}
|
|
46
|
-
else if (activeIndex >= 0) {
|
|
47
|
-
handleSelect(options[activeIndex]);
|
|
48
|
-
}
|
|
49
|
-
break;
|
|
50
|
-
case 'Escape':
|
|
51
|
-
e.preventDefault();
|
|
52
|
-
setIsOpen(false);
|
|
53
|
-
setActiveIndex(-1);
|
|
54
|
-
break;
|
|
55
|
-
case 'ArrowDown':
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
if (!isOpen) {
|
|
58
|
-
setIsOpen(true);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
setActiveIndex((prev) => (prev < options.length - 1 ? prev + 1 : 0));
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
case 'ArrowUp':
|
|
65
|
-
e.preventDefault();
|
|
66
|
-
if (isOpen) {
|
|
67
|
-
setActiveIndex((prev) => (prev > 0 ? prev - 1 : options.length - 1));
|
|
68
|
-
}
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
const handleClickOutside = () => {
|
|
73
|
-
setIsOpen(false);
|
|
74
|
-
setActiveIndex(-1);
|
|
75
|
-
};
|
|
76
|
-
(0, react_1.useEffect)(() => {
|
|
77
|
-
if (isOpen && selectRef.current) {
|
|
78
|
-
const selectRect = selectRef.current.getBoundingClientRect();
|
|
79
|
-
const viewportHeight = window.innerHeight;
|
|
80
|
-
const dropdownHeight = Math.min(400, options.length * 60);
|
|
81
|
-
const spaceAbove = selectRect.top;
|
|
82
|
-
const spaceBelow = viewportHeight - selectRect.bottom;
|
|
83
|
-
if (spaceAbove < dropdownHeight && spaceBelow > spaceAbove) {
|
|
84
|
-
setDropdownDirection('down');
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
setDropdownDirection('up');
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, [isOpen, options.length]);
|
|
91
|
-
(0, react_1.useEffect)(() => {
|
|
92
|
-
if (isOpen && activeIndex >= 0 && dropdownRef.current) {
|
|
93
|
-
const activeElement = dropdownRef.current.children[activeIndex];
|
|
94
|
-
if (activeElement) {
|
|
95
|
-
activeElement.scrollIntoView({
|
|
96
|
-
behavior: 'smooth',
|
|
97
|
-
block: 'nearest',
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}, [isOpen, activeIndex]);
|
|
102
|
-
return (react_1.default.createElement(click_outside_1.ClickOutside, { onOutsideClick: handleClickOutside },
|
|
103
|
-
react_1.default.createElement("div", { ref: selectRef, className: (0, classnames_1.default)(mention_select_module_less_1.default.mention_select, mention_select_module_less_1.default[`size_${size}`], {
|
|
104
|
-
[mention_select_module_less_1.default.disabled]: disabled,
|
|
105
|
-
[mention_select_module_less_1.default.open]: isOpen,
|
|
106
|
-
[mention_select_module_less_1.default.dropdown_up]: dropdownDirection === 'up',
|
|
107
|
-
[mention_select_module_less_1.default.dropdown_down]: dropdownDirection === 'down',
|
|
108
|
-
}, className), onClick: handleToggle, onKeyDown: handleKeyDown, tabIndex: disabled ? -1 : 0, role: 'combobox', "aria-expanded": isOpen, "aria-haspopup": 'listbox' },
|
|
109
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.select_trigger },
|
|
110
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.select_content }, selectedOption ? (react_1.default.createElement("div", { className: mention_select_module_less_1.default.selected_option },
|
|
111
|
-
react_1.default.createElement("span", { className: mention_select_module_less_1.default.option_label }, selectedOption.label),
|
|
112
|
-
selectedOption.badge && (react_1.default.createElement("span", { className: mention_select_module_less_1.default.option_badge, style: { backgroundColor: selectedOption.badgeColor } }, selectedOption.badge)))) : (react_1.default.createElement("span", { className: mention_select_module_less_1.default.placeholder }, placeholder))),
|
|
113
|
-
react_1.default.createElement(components_1.Icon, { iconClass: (0, components_1.getIcon)('down-arrow'), className: (0, classnames_1.default)(mention_select_module_less_1.default.dropdown_arrow, {
|
|
114
|
-
[mention_select_module_less_1.default.open]: isOpen,
|
|
115
|
-
}) })),
|
|
116
|
-
isOpen && (react_1.default.createElement("div", { ref: dropdownRef, className: mention_select_module_less_1.default.dropdown, role: 'listbox' },
|
|
117
|
-
showThinking && onThinkingChange && (react_1.default.createElement("div", { className: mention_select_module_less_1.default.thinking_section },
|
|
118
|
-
react_1.default.createElement(ThinkingToggle, { enabled: thinkingEnabled, onChange: onThinkingChange }),
|
|
119
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.divider }))),
|
|
120
|
-
options.map((option, index) => (react_1.default.createElement("div", { key: option.value, className: (0, classnames_1.default)(mention_select_module_less_1.default.option, {
|
|
121
|
-
[mention_select_module_less_1.default.active]: index === activeIndex,
|
|
122
|
-
[mention_select_module_less_1.default.selected]: option.selected || option.value === value,
|
|
123
|
-
[mention_select_module_less_1.default.disabled]: option.disabled,
|
|
124
|
-
}), onClick: () => handleSelect(option), role: 'option', "aria-selected": option.selected || option.value === value },
|
|
125
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.option_main },
|
|
126
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.option_header },
|
|
127
|
-
react_1.default.createElement("div", { className: mention_select_module_less_1.default.option_title },
|
|
128
|
-
option.icon && react_1.default.createElement(components_1.Icon, { icon: option.icon, className: mention_select_module_less_1.default.option_icon }),
|
|
129
|
-
option.iconClass && react_1.default.createElement(components_1.Icon, { iconClass: option.iconClass, className: mention_select_module_less_1.default.option_icon }),
|
|
130
|
-
react_1.default.createElement("span", { className: mention_select_module_less_1.default.option_label }, option.label),
|
|
131
|
-
option.badge && (react_1.default.createElement("span", { className: mention_select_module_less_1.default.option_badge, style: { backgroundColor: option.badgeColor } }, option.badge)))),
|
|
132
|
-
option.description && react_1.default.createElement("div", { className: mention_select_module_less_1.default.option_description }, option.description),
|
|
133
|
-
option.tags && option.tags.length > 0 && (react_1.default.createElement("div", { className: mention_select_module_less_1.default.option_tags }, option.tags.map((tag, idx) => (react_1.default.createElement("span", { key: idx, className: mention_select_module_less_1.default.tag }, tag))))))))))))));
|
|
134
|
-
};
|
|
135
|
-
exports.MentionSelect = MentionSelect;
|
|
136
|
-
//# sourceMappingURL=mention-select.js.map
|