@opensumi/ide-ai-native 3.9.1-next-1749540423.0 → 3.9.1-next-1749547010.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 +9 -4
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/apply.service.d.ts +3 -0
- package/lib/browser/chat/apply.service.d.ts.map +1 -1
- package/lib/browser/chat/apply.service.js +47 -0
- package/lib/browser/chat/apply.service.js.map +1 -1
- package/lib/browser/chat/chat-manager.service.d.ts +1 -0
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +9 -3
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +8 -1
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +113 -76
- 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 +4 -1
- package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
- package/lib/browser/chat/chat.feature.registry.js +6 -0
- 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 +50 -10
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatHistory.d.ts.map +1 -1
- package/lib/browser/components/ChatHistory.js +2 -1
- 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 +148 -30
- 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 +7 -2
- package/lib/browser/components/ChatToolRender.js.map +1 -1
- package/lib/browser/components/ChatToolRender.module.less +25 -0
- package/lib/browser/components/components.module.less +37 -8
- package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
- package/lib/browser/components/mention-input/mention-input.js +150 -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 +28 -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/layout/ai-layout.d.ts.map +1 -1
- package/lib/browser/layout/ai-layout.js +6 -4
- 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 +5 -12
- package/lib/browser/layout/tabbar.view.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +5 -4
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js +23 -5
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts +3 -1
- package/lib/browser/mcp/mcp-server-proxy.service.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server-proxy.service.js +4 -0
- package/lib/browser/mcp/mcp-server-proxy.service.js.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js +7 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts +1 -3
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +14 -40
- package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/fileSearch.js +9 -5
- package/lib/browser/mcp/tools/fileSearch.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/grepSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.js +22 -10
- package/lib/browser/mcp/tools/grepSearch.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts +15 -0
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts.map +1 -0
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js +53 -0
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js.map +1 -0
- package/lib/browser/mcp/tools/handlers/ListDir.js +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ReadFile.js +1 -1
- package/lib/browser/mcp/tools/handlers/ReadFile.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts +11 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.js +11 -4
- package/lib/browser/mcp/tools/handlers/RunCommand.js.map +1 -1
- package/lib/browser/mcp/tools/listDir.d.ts.map +1 -1
- package/lib/browser/mcp/tools/listDir.js +19 -15
- package/lib/browser/mcp/tools/listDir.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +47 -1
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +127 -2
- 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 +12 -1
- 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/image-compression.d.ts +25 -0
- package/lib/common/image-compression.d.ts.map +1 -0
- package/lib/common/image-compression.js +153 -0
- package/lib/common/image-compression.js.map +1 -0
- package/lib/common/index.d.ts +5 -1
- 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/model.d.ts +1 -0
- 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 +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 +21 -0
- package/lib/common/types.d.ts.map +1 -1
- package/lib/common/types.js.map +1 -1
- package/lib/common/utils.d.ts +1 -0
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +5 -2
- 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 +2 -1
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js +12 -2
- 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 +3 -1
- package/lib/node/mcp/sumi-mcp-server.d.ts.map +1 -1
- package/lib/node/mcp/sumi-mcp-server.js +7 -1
- package/lib/node/mcp/sumi-mcp-server.js.map +1 -1
- package/lib/node/mcp-server-manager-impl.d.ts +3 -1
- package/lib/node/mcp-server-manager-impl.d.ts.map +1 -1
- package/lib/node/mcp-server-manager-impl.js +14 -2
- package/lib/node/mcp-server-manager-impl.js.map +1 -1
- package/lib/node/mcp-server.sse.d.ts +187 -1
- package/lib/node/mcp-server.sse.d.ts.map +1 -1
- package/lib/node/mcp-server.sse.js +2 -2
- package/lib/node/mcp-server.sse.js.map +1 -1
- package/lib/node/mcp-server.stdio.d.ts +187 -1
- package/lib/node/mcp-server.stdio.d.ts.map +1 -1
- package/package.json +27 -26
- package/src/browser/ai-core.contribution.ts +14 -4
- package/src/browser/chat/apply.service.ts +62 -1
- package/src/browser/chat/chat-manager.service.ts +16 -7
- package/src/browser/chat/chat-model.ts +130 -73
- package/src/browser/chat/chat-proxy.service.ts +68 -81
- package/src/browser/chat/chat.feature.registry.ts +17 -1
- package/src/browser/chat/chat.view.tsx +73 -12
- package/src/browser/components/ChatHistory.tsx +2 -1
- package/src/browser/components/ChatMentionInput.tsx +180 -35
- package/src/browser/components/ChatReply.tsx +4 -4
- package/src/browser/components/ChatToolRender.module.less +25 -0
- package/src/browser/components/ChatToolRender.tsx +10 -2
- package/src/browser/components/components.module.less +37 -8
- package/src/browser/components/mention-input/mention-input.module.less +165 -1
- package/src/browser/components/mention-input/mention-input.tsx +232 -31
- 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 +29 -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/layout/ai-layout.tsx +12 -8
- package/src/browser/layout/tabbar.view.tsx +10 -23
- package/src/browser/mcp/base-apply.service.ts +30 -10
- package/src/browser/mcp/mcp-server-proxy.service.ts +6 -1
- package/src/browser/mcp/mcp-server.feature.registry.ts +6 -1
- package/src/browser/mcp/tools/createNewFileWithText.ts +17 -46
- package/src/browser/mcp/tools/fileSearch.ts +8 -5
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
- package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
- package/src/browser/mcp/tools/grepSearch.ts +32 -21
- package/src/browser/mcp/tools/handlers/CreateNewFileWithText.ts +49 -0
- package/src/browser/mcp/tools/handlers/ListDir.ts +2 -2
- package/src/browser/mcp/tools/handlers/ReadFile.ts +2 -2
- package/src/browser/mcp/tools/handlers/RunCommand.ts +21 -14
- package/src/browser/mcp/tools/listDir.ts +15 -12
- package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
- package/src/browser/model/msg-history-manager.ts +181 -2
- 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 +18 -0
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +0 -1
- package/src/common/image-compression.ts +174 -0
- package/src/common/index.ts +6 -1
- package/src/common/llm-context.ts +23 -0
- package/src/common/mdc-parser.ts +295 -0
- package/src/common/model.ts +1 -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 +18 -0
- package/src/common/utils.ts +4 -1
- package/src/node/base-language-model.ts +11 -14
- package/src/node/mcp/sumi-mcp-server.ts +10 -2
- package/src/node/mcp-server-manager-impl.ts +17 -2
- package/src/node/mcp-server.sse.ts +1 -2
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
-
import {
|
|
2
|
+
import { PreferenceService } from '@opensumi/ide-core-browser';
|
|
3
3
|
import {
|
|
4
4
|
AIBackSerivcePath,
|
|
5
5
|
CancellationToken,
|
|
6
6
|
ChatAgentViewServiceToken,
|
|
7
7
|
ChatFeatureRegistryToken,
|
|
8
|
-
ChatServiceToken,
|
|
9
8
|
Deferred,
|
|
10
9
|
Disposable,
|
|
11
10
|
IAIBackService,
|
|
12
11
|
IAIReporter,
|
|
13
12
|
IApplicationService,
|
|
14
13
|
IChatProgress,
|
|
15
|
-
getOperatingSystemName,
|
|
16
14
|
} from '@opensumi/ide-core-common';
|
|
17
15
|
import { AINativeSettingSectionsId } from '@opensumi/ide-core-common/lib/settings/ai-native';
|
|
18
16
|
import { MonacoCommandRegistry } from '@opensumi/ide-editor/lib/browser/monaco-contrib/command/command.service';
|
|
@@ -27,10 +25,10 @@ import {
|
|
|
27
25
|
IChatAgentService,
|
|
28
26
|
IChatAgentWelcomeMessage,
|
|
29
27
|
} from '../../common';
|
|
28
|
+
import { DEFAULT_SYSTEM_PROMPT } from '../../common/prompts/system-prompt';
|
|
30
29
|
import { ChatToolRender } from '../components/ChatToolRender';
|
|
31
30
|
import { IChatAgentViewService } from '../types';
|
|
32
31
|
|
|
33
|
-
import { ChatService } from './chat.api.service';
|
|
34
32
|
import { ChatFeatureRegistry } from './chat.feature.registry';
|
|
35
33
|
|
|
36
34
|
/**
|
|
@@ -53,9 +51,6 @@ export class ChatProxyService extends Disposable {
|
|
|
53
51
|
@Autowired(MonacoCommandRegistry)
|
|
54
52
|
private readonly monacoCommandRegistry: MonacoCommandRegistry;
|
|
55
53
|
|
|
56
|
-
@Autowired(ChatServiceToken)
|
|
57
|
-
private aiChatService: ChatService;
|
|
58
|
-
|
|
59
54
|
@Autowired(IAIReporter)
|
|
60
55
|
private readonly aiReporter: IAIReporter;
|
|
61
56
|
|
|
@@ -71,9 +66,6 @@ export class ChatProxyService extends Disposable {
|
|
|
71
66
|
@Autowired(IMessageService)
|
|
72
67
|
private readonly messageService: IMessageService;
|
|
73
68
|
|
|
74
|
-
@Autowired(AppConfig)
|
|
75
|
-
private readonly appConfig: AppConfig;
|
|
76
|
-
|
|
77
69
|
private chatDeferred: Deferred<void> = new Deferred<void>();
|
|
78
70
|
|
|
79
71
|
public getRequestOptions() {
|
|
@@ -112,79 +104,74 @@ export class ChatProxyService extends Disposable {
|
|
|
112
104
|
initialProps: {},
|
|
113
105
|
});
|
|
114
106
|
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.preferenceService.get<string>(
|
|
107
|
+
this.applicationService.getBackendOS().then(() => {
|
|
108
|
+
this.addDispose(
|
|
109
|
+
this.chatAgentService.registerAgent({
|
|
110
|
+
id: ChatProxyService.AGENT_ID,
|
|
111
|
+
metadata: {
|
|
112
|
+
systemPrompt: this.preferenceService.get<string>(
|
|
121
113
|
AINativeSettingSectionsId.SystemPrompt,
|
|
122
|
-
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (commandHandler && commandHandler.providerPrompt) {
|
|
142
|
-
const editor = this.monacoCommandRegistry.getActiveCodeEditor();
|
|
143
|
-
const slashCommandPrompt = await commandHandler.providerPrompt(message, editor);
|
|
144
|
-
prompt = slashCommandPrompt;
|
|
114
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
invoke: async (
|
|
118
|
+
request: IChatAgentRequest,
|
|
119
|
+
progress: (part: IChatProgress) => void,
|
|
120
|
+
history: CoreMessage[],
|
|
121
|
+
token: CancellationToken,
|
|
122
|
+
): Promise<IChatAgentResult> => {
|
|
123
|
+
this.chatDeferred = new Deferred<void>();
|
|
124
|
+
const { message, command } = request;
|
|
125
|
+
let prompt: string = message;
|
|
126
|
+
if (command) {
|
|
127
|
+
const commandHandler = this.chatFeatureRegistry.getSlashCommandHandler(command);
|
|
128
|
+
if (commandHandler && commandHandler.providerPrompt) {
|
|
129
|
+
const editor = this.monacoCommandRegistry.getActiveCodeEditor();
|
|
130
|
+
const slashCommandPrompt = await commandHandler.providerPrompt(message, editor);
|
|
131
|
+
prompt = slashCommandPrompt;
|
|
132
|
+
}
|
|
145
133
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
);
|
|
134
|
+
|
|
135
|
+
const stream = await this.aiBackService.requestStream(
|
|
136
|
+
prompt,
|
|
137
|
+
{
|
|
138
|
+
requestId: request.requestId,
|
|
139
|
+
sessionId: request.sessionId,
|
|
140
|
+
history,
|
|
141
|
+
images: request.images,
|
|
142
|
+
...this.getRequestOptions(),
|
|
143
|
+
},
|
|
144
|
+
token,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
listenReadable<IChatProgress>(stream, {
|
|
148
|
+
onData: (data) => {
|
|
149
|
+
progress(data);
|
|
150
|
+
},
|
|
151
|
+
onEnd: () => {
|
|
152
|
+
this.chatDeferred.resolve();
|
|
153
|
+
},
|
|
154
|
+
onError: (error) => {
|
|
155
|
+
this.messageService.error(error.message);
|
|
156
|
+
this.aiReporter.end(request.sessionId + '_' + request.requestId, {
|
|
157
|
+
message: error.message,
|
|
158
|
+
success: false,
|
|
159
|
+
command,
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
await this.chatDeferred.promise;
|
|
165
|
+
return {};
|
|
166
|
+
},
|
|
167
|
+
provideSlashCommands: async (): Promise<IChatAgentCommand[]> =>
|
|
168
|
+
this.chatFeatureRegistry
|
|
169
|
+
.getAllSlashCommand()
|
|
170
|
+
.map((s) => ({ ...s, name: s.name, description: s.description || '' })),
|
|
171
|
+
provideChatWelcomeMessage: async (): Promise<IChatAgentWelcomeMessage | undefined> => undefined,
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
});
|
|
188
175
|
|
|
189
176
|
queueMicrotask(() => {
|
|
190
177
|
this.chatAgentService.updateAgent(ChatProxyService.AGENT_ID, {});
|
|
@@ -2,7 +2,13 @@ import { Injectable } from '@opensumi/di';
|
|
|
2
2
|
import { Disposable, Emitter, Event, getDebugLogger } from '@opensumi/ide-core-common';
|
|
3
3
|
|
|
4
4
|
import { IChatWelcomeMessageContent, ISampleQuestions, SLASH_SYMBOL } from '../../common';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
IChatFeatureRegistry,
|
|
7
|
+
IChatSlashCommandHandler,
|
|
8
|
+
IChatSlashCommandItem,
|
|
9
|
+
IImageUploadProvider,
|
|
10
|
+
IMessageSummaryProvider,
|
|
11
|
+
} from '../types';
|
|
6
12
|
|
|
7
13
|
import { ChatSlashCommandItemModel, ChatWelcomeMessageModel } from './chat-model';
|
|
8
14
|
import { ChatProxyService } from './chat-proxy.service';
|
|
@@ -14,6 +20,8 @@ export class ChatFeatureRegistry extends Disposable implements IChatFeatureRegis
|
|
|
14
20
|
private slashCommandsHandlerMap: Map<string, IChatSlashCommandHandler> = new Map();
|
|
15
21
|
private imageUploadProvider: IImageUploadProvider | undefined;
|
|
16
22
|
|
|
23
|
+
private messageSummaryProvider?: IMessageSummaryProvider;
|
|
24
|
+
|
|
17
25
|
public registerImageUploadProvider(provider: IImageUploadProvider): void {
|
|
18
26
|
this.imageUploadProvider = provider;
|
|
19
27
|
}
|
|
@@ -22,6 +30,14 @@ export class ChatFeatureRegistry extends Disposable implements IChatFeatureRegis
|
|
|
22
30
|
return this.imageUploadProvider;
|
|
23
31
|
}
|
|
24
32
|
|
|
33
|
+
public registerMessageSummaryProvider(provider: IMessageSummaryProvider): void {
|
|
34
|
+
this.messageSummaryProvider = provider;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public getMessageSummaryProvider(): IMessageSummaryProvider | undefined {
|
|
38
|
+
return this.messageSummaryProvider;
|
|
39
|
+
}
|
|
40
|
+
|
|
25
41
|
public chatWelcomeMessageModel?: ChatWelcomeMessageModel;
|
|
26
42
|
|
|
27
43
|
private _onDidWelcomeMessageChange: Emitter<void> = new Emitter<void>();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import debounce from 'lodash/debounce';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { MessageList } from 'react-chat-elements';
|
|
3
4
|
|
|
@@ -617,7 +618,12 @@ export const AIChatView = () => {
|
|
|
617
618
|
const { message, images, agentId, command, reportExtra } = value;
|
|
618
619
|
const { actionType, actionSource } = reportExtra || {};
|
|
619
620
|
|
|
620
|
-
const request = aiChatService.createRequest(
|
|
621
|
+
const request = aiChatService.createRequest(
|
|
622
|
+
message.replaceAll(LLM_CONTEXT_KEY_REGEX, ''),
|
|
623
|
+
agentId!,
|
|
624
|
+
images,
|
|
625
|
+
command,
|
|
626
|
+
);
|
|
621
627
|
if (!request) {
|
|
622
628
|
return;
|
|
623
629
|
}
|
|
@@ -641,7 +647,7 @@ export const AIChatView = () => {
|
|
|
641
647
|
600 * 1000,
|
|
642
648
|
);
|
|
643
649
|
msgHistoryManager.addUserMessage({
|
|
644
|
-
content: message
|
|
650
|
+
content: message,
|
|
645
651
|
images: images || [],
|
|
646
652
|
agentId: agentId!,
|
|
647
653
|
agentCommand: command!,
|
|
@@ -695,14 +701,9 @@ export const AIChatView = () => {
|
|
|
695
701
|
let processedContent = message;
|
|
696
702
|
const filePattern = /\{\{@file:(.*?)\}\}/g;
|
|
697
703
|
const fileMatches = message.match(filePattern);
|
|
698
|
-
let isCleanContext = false;
|
|
699
704
|
if (fileMatches) {
|
|
700
705
|
for (const match of fileMatches) {
|
|
701
706
|
const filePath = match.replace(/\{\{@file:(.*?)\}\}/, '$1');
|
|
702
|
-
if (filePath && !isCleanContext) {
|
|
703
|
-
isCleanContext = true;
|
|
704
|
-
llmContextService.cleanFileContext();
|
|
705
|
-
}
|
|
706
707
|
const fileUri = new URI(filePath);
|
|
707
708
|
const relativePath = (await workspaceService.asRelativePath(fileUri))?.path || fileUri.displayName;
|
|
708
709
|
processedContent = processedContent.replace(match, `\`${LLM_CONTEXT_KEY.AttachedFile}${relativePath}\``);
|
|
@@ -738,6 +739,18 @@ export const AIChatView = () => {
|
|
|
738
739
|
);
|
|
739
740
|
}
|
|
740
741
|
}
|
|
742
|
+
const rulePattern = /\{\{@rule:(.*?)\}\}/g;
|
|
743
|
+
const ruleMatches = processedContent.match(rulePattern);
|
|
744
|
+
if (ruleMatches) {
|
|
745
|
+
for (const match of ruleMatches) {
|
|
746
|
+
const ruleName = match.replace(/\{\{@rule:(.*?)\}\}/, '$1');
|
|
747
|
+
const ruleUri = new URI(ruleName);
|
|
748
|
+
processedContent = processedContent.replace(
|
|
749
|
+
match,
|
|
750
|
+
`\`${LLM_CONTEXT_KEY.AttachedFile}${ruleUri.displayName}\``,
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
741
754
|
return handleAgentReply({ message: processedContent, images, agentId, command, reportExtra });
|
|
742
755
|
},
|
|
743
756
|
[handleAgentReply],
|
|
@@ -918,6 +931,7 @@ export function DefaultChatViewHeader({
|
|
|
918
931
|
}) {
|
|
919
932
|
const aiChatService = useInjectable<ChatInternalService>(IChatInternalService);
|
|
920
933
|
const messageService = useInjectable<IMessageService>(IMessageService);
|
|
934
|
+
const chatFeatureRegistry = useInjectable<ChatFeatureRegistry>(ChatFeatureRegistryToken);
|
|
921
935
|
|
|
922
936
|
const [historyList, setHistoryList] = React.useState<IChatHistoryItem[]>([]);
|
|
923
937
|
const [currentTitle, setCurrentTitle] = React.useState<string>('');
|
|
@@ -943,13 +957,60 @@ export function DefaultChatViewHeader({
|
|
|
943
957
|
[aiChatService],
|
|
944
958
|
);
|
|
945
959
|
|
|
960
|
+
// 防抖函数,避免频繁触发摘要生成
|
|
961
|
+
const debouncedGetSummary = React.useCallback(
|
|
962
|
+
debounce(
|
|
963
|
+
async (messages: { role: ChatMessageRole; content: string }[], currentTitle: string): Promise<string> => {
|
|
964
|
+
const summaryProvider = chatFeatureRegistry.getMessageSummaryProvider();
|
|
965
|
+
if (!summaryProvider || !aiChatService.sessionModel.sessionId) {
|
|
966
|
+
return currentTitle;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
try {
|
|
970
|
+
const summary = await summaryProvider.getMessageSummary(messages);
|
|
971
|
+
return summary ? summary.slice(0, MAX_TITLE_LENGTH) : currentTitle;
|
|
972
|
+
} catch (error) {
|
|
973
|
+
return currentTitle;
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
1000,
|
|
977
|
+
{ leading: false, trailing: true },
|
|
978
|
+
),
|
|
979
|
+
[chatFeatureRegistry, aiChatService.sessionModel.sessionId],
|
|
980
|
+
);
|
|
981
|
+
|
|
982
|
+
// 使用 ref 来跟踪最新的请求
|
|
983
|
+
const latestSummaryRequestRef = React.useRef<number>(0);
|
|
984
|
+
|
|
946
985
|
React.useEffect(() => {
|
|
947
|
-
const getHistoryList = () => {
|
|
986
|
+
const getHistoryList = async () => {
|
|
948
987
|
const currentMessages = aiChatService.sessionModel.history.getMessages();
|
|
949
|
-
const latestUserMessage = currentMessages.
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
988
|
+
const latestUserMessage = [...currentMessages].find((m) => m.role === ChatMessageRole.User);
|
|
989
|
+
const currentTitle = latestUserMessage
|
|
990
|
+
? cleanAttachedTextWrapper(latestUserMessage.content).slice(0, MAX_TITLE_LENGTH)
|
|
991
|
+
: '';
|
|
992
|
+
|
|
993
|
+
// 设置初始标题
|
|
994
|
+
setCurrentTitle(currentTitle);
|
|
995
|
+
|
|
996
|
+
const messages = currentMessages.map((msg) => ({
|
|
997
|
+
role: msg.role,
|
|
998
|
+
content: msg.content,
|
|
999
|
+
}));
|
|
1000
|
+
|
|
1001
|
+
// 只有当消息数量超过阈值时才生成摘要
|
|
1002
|
+
if (messages.length > 2) {
|
|
1003
|
+
const requestId = Date.now();
|
|
1004
|
+
latestSummaryRequestRef.current = requestId;
|
|
1005
|
+
|
|
1006
|
+
const summary = await debouncedGetSummary(messages, currentTitle);
|
|
1007
|
+
|
|
1008
|
+
// 检查是否是最新请求
|
|
1009
|
+
if (requestId === latestSummaryRequestRef.current && summary) {
|
|
1010
|
+
setCurrentTitle(summary);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
953
1014
|
setHistoryList(
|
|
954
1015
|
aiChatService.getSessions().map((session) => {
|
|
955
1016
|
const history = session.history;
|
|
@@ -216,7 +216,8 @@ const ChatHistory: FC<IChatHistoryProps> = memo(
|
|
|
216
216
|
// 渲染历史记录列表
|
|
217
217
|
const renderHistory = useCallback(() => {
|
|
218
218
|
const filteredList = historyList
|
|
219
|
-
.slice(
|
|
219
|
+
.slice(-MAX_HISTORY_LIST)
|
|
220
|
+
.reverse()
|
|
220
221
|
.filter((item) => item.title && item.title.includes(searchValue));
|
|
221
222
|
|
|
222
223
|
const groupedHistoryList = formatHistory(filteredList);
|