@opensumi/ide-ai-native 3.8.1-next-1740625266.0 → 3.8.1-next-1740726474.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 +5 -0
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +18 -1
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +2 -0
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +8 -2
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat.module.less +1 -2
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +6 -38
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatContext/index.js +2 -2
- package/lib/browser/components/ChatContext/index.js.map +1 -1
- package/lib/browser/components/ChatInput.d.ts.map +1 -1
- package/lib/browser/components/ChatInput.js +25 -1
- package/lib/browser/components/ChatInput.js.map +1 -1
- package/lib/browser/components/ChatToolRender.d.ts.map +1 -1
- package/lib/browser/components/ChatToolRender.js +2 -3
- package/lib/browser/components/ChatToolRender.js.map +1 -1
- package/lib/browser/components/chat-history.module.less +1 -1
- package/lib/browser/components/components.module.less +20 -0
- package/lib/browser/context/llm-context.service.d.ts +16 -5
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +78 -47
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/layout/layout.module.less +4 -4
- package/lib/browser/mcp/tools/components/index.module.less +1 -0
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +1 -0
- package/lib/browser/mcp/tools/createNewFileWithText.js.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.d.ts.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js +1 -0
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.js +2 -0
- package/lib/browser/mcp/tools/handlers/RunCommand.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.d.ts.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js +1 -0
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/common/llm-context.d.ts +12 -9
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/prompts/context-prompt-provider.d.ts +4 -3
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +33 -22
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/package.json +23 -23
- package/src/browser/chat/chat-manager.service.ts +17 -1
- package/src/browser/chat/chat-model.ts +18 -3
- package/src/browser/chat/chat.module.less +1 -2
- package/src/browser/chat/chat.view.tsx +7 -70
- package/src/browser/components/ChatContext/index.tsx +2 -2
- package/src/browser/components/ChatInput.tsx +67 -4
- package/src/browser/components/ChatToolRender.tsx +1 -2
- package/src/browser/components/chat-history.module.less +1 -1
- package/src/browser/components/components.module.less +20 -0
- package/src/browser/context/llm-context.service.ts +90 -54
- package/src/browser/layout/layout.module.less +4 -4
- package/src/browser/mcp/tools/components/index.module.less +1 -0
- package/src/browser/mcp/tools/createNewFileWithText.ts +1 -0
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -0
- package/src/browser/mcp/tools/handlers/RunCommand.ts +2 -0
- package/src/browser/mcp/tools/runTerminalCmd.ts +1 -0
- package/src/common/llm-context.ts +10 -4
- package/src/common/prompts/context-prompt-provider.ts +38 -29
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-context.d.ts","sourceRoot":"","sources":["../../src/common/llm-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,IAAI,IAAI,CAAC;IAE5B,kBAAkB,IAAI,IAAI,CAAC;IAE3B;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEnF;;OAEG;IACH,gBAAgB,IAAI,IAAI,CAAC;IAEzB,4BAA4B,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"llm-context.d.ts","sourceRoot":"","sources":["../../src/common/llm-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,mBAAmB,IAAI,IAAI,CAAC;IAE5B,kBAAkB,IAAI,IAAI,CAAC;IAE3B;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAEnF;;OAEG;IACH,gBAAgB,IAAI,IAAI,CAAC;IAEzB,4BAA4B,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,WAAW,EAAE,CAAC;QAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC;IAExF;;;OAGG;IACH,qBAAqB,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAE1D,gBAAgB;IAChB,SAAS,IAAI,iBAAiB,CAAC;CAChC;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,eAAO,MAAM,sBAAsB,eAA8B,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-context.js","sourceRoot":"","sources":["../../src/common/llm-context.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"llm-context.js","sourceRoot":"","sources":["../../src/common/llm-context.ts"],"names":[],"mappings":";;;AAkCa,QAAA,sBAAsB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WorkbenchEditorService } from '@opensumi/ide-editor/lib/common/editor';
|
|
2
2
|
import { SerializedContext } from '../llm-context';
|
|
3
3
|
export declare const ChatAgentPromptProvider: unique symbol;
|
|
4
4
|
export interface ChatAgentPromptProvider {
|
|
@@ -6,9 +6,10 @@ export interface ChatAgentPromptProvider {
|
|
|
6
6
|
* 提供上下文提示
|
|
7
7
|
* @param context 上下文
|
|
8
8
|
*/
|
|
9
|
-
provideContextPrompt(context: SerializedContext, userMessage: string):
|
|
9
|
+
provideContextPrompt(context: SerializedContext, userMessage: string): string;
|
|
10
10
|
}
|
|
11
11
|
export declare class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
|
|
12
|
-
|
|
12
|
+
protected readonly workbenchEditorService: WorkbenchEditorService;
|
|
13
|
+
provideContextPrompt(context: SerializedContext, userMessage: string): string;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=context-prompt-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-prompt-provider.d.ts","sourceRoot":"","sources":["../../../src/common/prompts/context-prompt-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"context-prompt-provider.d.ts","sourceRoot":"","sources":["../../../src/common/prompts/context-prompt-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,eAAO,MAAM,uBAAuB,eAAoC,CAAC;AAEzE,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/E;AAED,qBACa,8BAA+B,YAAW,uBAAuB;IAE5E,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IAElE,oBAAoB,CAAC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;CAkC9E"}
|
|
@@ -3,35 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DefaultChatAgentPromptProvider = exports.ChatAgentPromptProvider = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const di_1 = require("@opensumi/di");
|
|
6
|
+
const editor_1 = require("@opensumi/ide-editor/lib/common/editor");
|
|
6
7
|
exports.ChatAgentPromptProvider = Symbol('ChatAgentPromptProvider');
|
|
7
8
|
let DefaultChatAgentPromptProvider = class DefaultChatAgentPromptProvider {
|
|
8
9
|
provideContextPrompt(context, userMessage) {
|
|
10
|
+
const editor = this.workbenchEditorService.currentEditor;
|
|
11
|
+
const currentModel = editor === null || editor === void 0 ? void 0 : editor.currentDocumentModel;
|
|
9
12
|
return `
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
<additional_data>
|
|
14
|
+
Below are some potentially helpful/relevant pieces of information for figuring out to respond
|
|
15
|
+
<recently_viewed_files>
|
|
16
|
+
${context.recentlyViewFiles.map((file, idx) => ` ${idx + 1}: ${file}`).join('\n')}
|
|
17
|
+
</recently_viewed_files>
|
|
18
|
+
<attached_files>
|
|
19
|
+
${context.attachedFiles.map((file) => `
|
|
20
|
+
<file_contents>
|
|
21
|
+
\`\`\`${file.language} ${file.path}
|
|
22
|
+
${file.content}
|
|
23
|
+
\`\`\`
|
|
24
|
+
</file_contents>
|
|
25
|
+
<linter_errors>
|
|
26
|
+
${file.lineErrors.join('\n')}
|
|
27
|
+
</linter_errors>
|
|
28
|
+
`)}
|
|
29
|
+
</attached_files>
|
|
30
|
+
${currentModel ? `<current_opened_file>
|
|
31
|
+
\`\`\`${currentModel.languageId} ${currentModel.uri.toString()}
|
|
32
|
+
${currentModel.getText()}
|
|
33
|
+
\`\`\`
|
|
34
|
+
</current_opened_file>` : ''}
|
|
35
|
+
</additional_data>
|
|
36
|
+
<user_query>
|
|
37
|
+
${userMessage}
|
|
38
|
+
</user_query>`;
|
|
32
39
|
}
|
|
33
40
|
};
|
|
34
41
|
exports.DefaultChatAgentPromptProvider = DefaultChatAgentPromptProvider;
|
|
42
|
+
tslib_1.__decorate([
|
|
43
|
+
(0, di_1.Autowired)(editor_1.WorkbenchEditorService),
|
|
44
|
+
tslib_1.__metadata("design:type", editor_1.WorkbenchEditorService)
|
|
45
|
+
], DefaultChatAgentPromptProvider.prototype, "workbenchEditorService", void 0);
|
|
35
46
|
exports.DefaultChatAgentPromptProvider = DefaultChatAgentPromptProvider = tslib_1.__decorate([
|
|
36
47
|
(0, di_1.Injectable)()
|
|
37
48
|
], DefaultChatAgentPromptProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-prompt-provider.js","sourceRoot":"","sources":["../../../src/common/prompts/context-prompt-provider.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"context-prompt-provider.js","sourceRoot":"","sources":["../../../src/common/prompts/context-prompt-provider.ts"],"names":[],"mappings":";;;;AAAA,qCAAqD;AACrD,mEAAgF;AAInE,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAWlE,IAAM,8BAA8B,GAApC,MAAM,8BAA8B;IAIzC,oBAAoB,CAAC,OAA0B,EAAE,WAAmB;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,sBAAsB,CAAC,aAAa,CAAC;QACzD,MAAM,YAAY,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,oBAAoB,CAAC;QAClD,OAAO;;;;EAIT,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;MAG9E,OAAO,CAAC,aAAa,CAAC,GAAG,CACzB,CAAC,IAAI,EAAE,EAAE,CACP;;YAEI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI;MAChC,IAAI,CAAC,OAAO;;;;MAIZ,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;;eAEjB,CACV;;EAEH,YAAY,CAAC,CAAC,CAAC;UACP,YAAY,CAAC,UAAU,IAAI,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE;EAC9D,YAAY,CAAC,OAAO,EAAE;;yBAEC,CAAC,CAAC,CAAC,EAAE;;;EAG5B,WAAW;cACC,CAAC;IACb,CAAC;CACF,CAAA;AAtCY,wEAA8B;AAEtB;IADlB,IAAA,cAAS,EAAC,+BAAsB,CAAC;sCACS,+BAAsB;8EAAC;yCAFvD,8BAA8B;IAD1C,IAAA,eAAU,GAAE;GACA,8BAA8B,CAsC1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-ai-native",
|
|
3
|
-
"version": "3.8.1-next-
|
|
3
|
+
"version": "3.8.1-next-1740726474.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"@ai-sdk/deepseek": "^0.1.11",
|
|
24
24
|
"@ai-sdk/openai-compatible": "^0.1.11",
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.3.1",
|
|
26
|
-
"@opensumi/ide-addons": "3.8.1-next-
|
|
27
|
-
"@opensumi/ide-components": "3.8.1-next-
|
|
28
|
-
"@opensumi/ide-connection": "3.8.1-next-
|
|
29
|
-
"@opensumi/ide-core-common": "3.8.1-next-
|
|
30
|
-
"@opensumi/ide-core-node": "3.8.1-next-
|
|
31
|
-
"@opensumi/ide-debug": "3.8.1-next-
|
|
32
|
-
"@opensumi/ide-design": "3.8.1-next-
|
|
33
|
-
"@opensumi/ide-editor": "3.8.1-next-
|
|
34
|
-
"@opensumi/ide-file-search": "3.8.1-next-
|
|
35
|
-
"@opensumi/ide-file-service": "3.8.1-next-
|
|
36
|
-
"@opensumi/ide-main-layout": "3.8.1-next-
|
|
37
|
-
"@opensumi/ide-markers": "3.8.1-next-
|
|
38
|
-
"@opensumi/ide-monaco": "3.8.1-next-
|
|
39
|
-
"@opensumi/ide-overlay": "3.8.1-next-
|
|
40
|
-
"@opensumi/ide-preferences": "3.8.1-next-
|
|
41
|
-
"@opensumi/ide-search": "3.8.1-next-
|
|
42
|
-
"@opensumi/ide-terminal-next": "3.8.1-next-
|
|
43
|
-
"@opensumi/ide-theme": "3.8.1-next-
|
|
44
|
-
"@opensumi/ide-utils": "3.8.1-next-
|
|
45
|
-
"@opensumi/ide-workspace": "3.8.1-next-
|
|
26
|
+
"@opensumi/ide-addons": "3.8.1-next-1740726474.0",
|
|
27
|
+
"@opensumi/ide-components": "3.8.1-next-1740726474.0",
|
|
28
|
+
"@opensumi/ide-connection": "3.8.1-next-1740726474.0",
|
|
29
|
+
"@opensumi/ide-core-common": "3.8.1-next-1740726474.0",
|
|
30
|
+
"@opensumi/ide-core-node": "3.8.1-next-1740726474.0",
|
|
31
|
+
"@opensumi/ide-debug": "3.8.1-next-1740726474.0",
|
|
32
|
+
"@opensumi/ide-design": "3.8.1-next-1740726474.0",
|
|
33
|
+
"@opensumi/ide-editor": "3.8.1-next-1740726474.0",
|
|
34
|
+
"@opensumi/ide-file-search": "3.8.1-next-1740726474.0",
|
|
35
|
+
"@opensumi/ide-file-service": "3.8.1-next-1740726474.0",
|
|
36
|
+
"@opensumi/ide-main-layout": "3.8.1-next-1740726474.0",
|
|
37
|
+
"@opensumi/ide-markers": "3.8.1-next-1740726474.0",
|
|
38
|
+
"@opensumi/ide-monaco": "3.8.1-next-1740726474.0",
|
|
39
|
+
"@opensumi/ide-overlay": "3.8.1-next-1740726474.0",
|
|
40
|
+
"@opensumi/ide-preferences": "3.8.1-next-1740726474.0",
|
|
41
|
+
"@opensumi/ide-search": "3.8.1-next-1740726474.0",
|
|
42
|
+
"@opensumi/ide-terminal-next": "3.8.1-next-1740726474.0",
|
|
43
|
+
"@opensumi/ide-theme": "3.8.1-next-1740726474.0",
|
|
44
|
+
"@opensumi/ide-utils": "3.8.1-next-1740726474.0",
|
|
45
|
+
"@opensumi/ide-workspace": "3.8.1-next-1740726474.0",
|
|
46
46
|
"@xterm/xterm": "5.5.0",
|
|
47
47
|
"ai": "^4.1.45",
|
|
48
48
|
"ansi-regex": "^2.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"zod-to-json-schema": "^3.24.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@opensumi/ide-core-browser": "3.8.1-next-
|
|
60
|
+
"@opensumi/ide-core-browser": "3.8.1-next-1740726474.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "85947469e2ab64bd9dbc45d43549e9c7b80daa32"
|
|
63
63
|
}
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
import { ChatMessageRole, IChatMessage, IHistoryChatMessage } from '@opensumi/ide-core-common/lib/types/ai-native';
|
|
15
15
|
|
|
16
16
|
import { IChatAgentService, IChatFollowup, IChatRequestMessage, IChatResponseErrorDetails } from '../../common';
|
|
17
|
+
import { LLMContextService, LLMContextServiceToken } from '../../common/llm-context';
|
|
18
|
+
import { ChatAgentPromptProvider } from '../../common/prompts/context-prompt-provider';
|
|
17
19
|
import { MsgHistoryManager } from '../model/msg-history-manager';
|
|
18
20
|
|
|
19
21
|
import { ChatModel, ChatRequestModel, ChatResponseModel, IChatProgressResponseContent } from './chat-model';
|
|
@@ -50,6 +52,12 @@ export class ChatManagerService extends Disposable {
|
|
|
50
52
|
@Autowired(StorageProvider)
|
|
51
53
|
private storageProvider: StorageProvider;
|
|
52
54
|
|
|
55
|
+
@Autowired(ChatAgentPromptProvider)
|
|
56
|
+
protected readonly promptProvider: ChatAgentPromptProvider;
|
|
57
|
+
|
|
58
|
+
@Autowired(LLMContextServiceToken)
|
|
59
|
+
protected readonly contextService: LLMContextService;
|
|
60
|
+
|
|
53
61
|
private _chatStorage: IStorage;
|
|
54
62
|
|
|
55
63
|
protected fromJSON(data: ISessionModel[]) {
|
|
@@ -100,12 +108,20 @@ export class ChatManagerService extends Disposable {
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
startSession() {
|
|
103
|
-
const model = new ChatModel(
|
|
111
|
+
const model = new ChatModel({
|
|
112
|
+
provideContext: this.provideContextPrompt.bind(this),
|
|
113
|
+
});
|
|
104
114
|
this.#sessionModels.set(model.sessionId, model);
|
|
105
115
|
this.listenSession(model);
|
|
106
116
|
return model;
|
|
107
117
|
}
|
|
108
118
|
|
|
119
|
+
private provideContextPrompt(message: string) {
|
|
120
|
+
const context = this.contextService.serialize();
|
|
121
|
+
const fullMessage = this.promptProvider.provideContextPrompt(context, message);
|
|
122
|
+
return fullMessage;
|
|
123
|
+
}
|
|
124
|
+
|
|
109
125
|
getSession(sessionId: string): ChatModel | undefined {
|
|
110
126
|
return this.#sessionModels.get(sessionId);
|
|
111
127
|
}
|
|
@@ -274,13 +274,22 @@ export class ChatRequestModel implements IChatRequestModel {
|
|
|
274
274
|
export class ChatModel extends Disposable implements IChatModel {
|
|
275
275
|
private static requestIdPool = 0;
|
|
276
276
|
|
|
277
|
-
|
|
277
|
+
private provideContextPrompt?: (string) => string;
|
|
278
|
+
|
|
279
|
+
constructor(initParams?: {
|
|
280
|
+
sessionId?: string;
|
|
281
|
+
history?: MsgHistoryManager;
|
|
282
|
+
requests?: ChatRequestModel[];
|
|
283
|
+
provideContext?: (msg: string) => string;
|
|
284
|
+
}) {
|
|
278
285
|
super();
|
|
279
286
|
this.#sessionId = initParams?.sessionId ?? uuid();
|
|
280
287
|
this.history = initParams?.history ?? new MsgHistoryManager();
|
|
281
288
|
if (initParams?.requests) {
|
|
282
289
|
this.#requests = new Map(initParams.requests.map((r) => [r.requestId, r]));
|
|
283
290
|
}
|
|
291
|
+
|
|
292
|
+
this.provideContextPrompt = initParams?.provideContext;
|
|
284
293
|
}
|
|
285
294
|
|
|
286
295
|
#sessionId: string;
|
|
@@ -300,9 +309,15 @@ export class ChatModel extends Disposable implements IChatModel {
|
|
|
300
309
|
readonly history: MsgHistoryManager;
|
|
301
310
|
|
|
302
311
|
addRequest(message: IChatRequestMessage): ChatRequestModel {
|
|
312
|
+
const msg = message;
|
|
313
|
+
// first msg
|
|
314
|
+
if (this.provideContextPrompt) {
|
|
315
|
+
msg.prompt = this.provideContextPrompt(msg.prompt);
|
|
316
|
+
}
|
|
317
|
+
|
|
303
318
|
const requestId = `${this.sessionId}_request_${ChatModel.requestIdPool++}`;
|
|
304
|
-
const response = new ChatResponseModel(requestId, this,
|
|
305
|
-
const request = new ChatRequestModel(requestId, this,
|
|
319
|
+
const response = new ChatResponseModel(requestId, this, msg.agentId);
|
|
320
|
+
const request = new ChatRequestModel(requestId, this, msg, response);
|
|
306
321
|
|
|
307
322
|
this.#requests.set(requestId, request);
|
|
308
323
|
return request;
|
|
@@ -279,7 +279,6 @@
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
|
|
283
282
|
.chat_tips_container {
|
|
284
283
|
display: flex;
|
|
285
284
|
align-items: center;
|
|
@@ -290,6 +289,6 @@
|
|
|
290
289
|
}
|
|
291
290
|
|
|
292
291
|
.chat_history {
|
|
293
|
-
width: calc(100% -
|
|
292
|
+
width: calc(100% - 40px);
|
|
294
293
|
color: var(--design-text-foreground);
|
|
295
294
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
AINativeConfigService,
|
|
6
6
|
CommandService,
|
|
7
7
|
getIcon,
|
|
8
|
-
useEventEffect,
|
|
9
8
|
useInjectable,
|
|
10
9
|
useUpdateOnEvent,
|
|
11
10
|
} from '@opensumi/ide-core-browser';
|
|
@@ -42,8 +41,6 @@ import {
|
|
|
42
41
|
IChatMessageStructure,
|
|
43
42
|
TokenMCPServerProxyService,
|
|
44
43
|
} from '../../common';
|
|
45
|
-
import { LLMContextService, LLMContextServiceToken } from '../../common/llm-context';
|
|
46
|
-
import { ChatAgentPromptProvider } from '../../common/prompts/context-prompt-provider';
|
|
47
44
|
import { ChatContext } from '../components/ChatContext';
|
|
48
45
|
import { CodeBlockWrapperInput } from '../components/ChatEditor';
|
|
49
46
|
import ChatHistory, { IChatHistoryItem } from '../components/ChatHistory';
|
|
@@ -82,17 +79,11 @@ export const AIChatView = () => {
|
|
|
82
79
|
const chatAgentService = useInjectable<IChatAgentService>(IChatAgentService);
|
|
83
80
|
const chatFeatureRegistry = useInjectable<ChatFeatureRegistry>(ChatFeatureRegistryToken);
|
|
84
81
|
const chatRenderRegistry = useInjectable<ChatRenderRegistry>(ChatRenderRegistryToken);
|
|
85
|
-
const contextService = useInjectable<LLMContextService>(LLMContextServiceToken);
|
|
86
|
-
const promptProvider = useInjectable<ChatAgentPromptProvider>(ChatAgentPromptProvider);
|
|
87
|
-
const mcpServerProxyService = useInjectable<MCPServerProxyService>(TokenMCPServerProxyService);
|
|
88
82
|
|
|
89
83
|
const layoutService = useInjectable<IMainLayoutService>(IMainLayoutService);
|
|
90
84
|
const msgHistoryManager = aiChatService.sessionModel.history;
|
|
91
85
|
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
92
86
|
const chatInputRef = React.useRef<{ setInputValue: (v: string) => void } | null>(null);
|
|
93
|
-
const dialogService = useInjectable<IDialogService>(IDialogService);
|
|
94
|
-
const aiNativeConfigService = useInjectable<AINativeConfigService>(AINativeConfigService);
|
|
95
|
-
const commandService = useInjectable<CommandService>(CommandService);
|
|
96
87
|
|
|
97
88
|
const [shortcutCommands, setShortcutCommands] = React.useState<ChatSlashCommandItemModel[]>([]);
|
|
98
89
|
|
|
@@ -114,8 +105,6 @@ export const AIChatView = () => {
|
|
|
114
105
|
const [defaultAgentId, setDefaultAgentId] = React.useState<string>('');
|
|
115
106
|
const [command, setCommand] = React.useState('');
|
|
116
107
|
const [theme, setTheme] = React.useState<string | null>(null);
|
|
117
|
-
const [mcpToolsCount, setMcpToolsCount] = React.useState<number>(0);
|
|
118
|
-
const [mcpServersCount, setMcpServersCount] = React.useState<number>(0);
|
|
119
108
|
|
|
120
109
|
React.useEffect(() => {
|
|
121
110
|
const featureSlashCommands = chatFeatureRegistry.getAllShortcutSlashCommand();
|
|
@@ -515,10 +504,7 @@ export const AIChatView = () => {
|
|
|
515
504
|
const { message, agentId, command, reportExtra } = value;
|
|
516
505
|
const { actionType, actionSource } = reportExtra || {};
|
|
517
506
|
|
|
518
|
-
const
|
|
519
|
-
const fullMessage = await promptProvider.provideContextPrompt(context, message);
|
|
520
|
-
|
|
521
|
-
const request = aiChatService.createRequest(fullMessage, agentId!, command);
|
|
507
|
+
const request = aiChatService.createRequest(message, agentId!, command);
|
|
522
508
|
if (!request) {
|
|
523
509
|
return;
|
|
524
510
|
}
|
|
@@ -667,32 +653,6 @@ export const AIChatView = () => {
|
|
|
667
653
|
};
|
|
668
654
|
}, [aiChatService.sessionModel]);
|
|
669
655
|
|
|
670
|
-
useEventEffect(
|
|
671
|
-
mcpServerProxyService.onChangeMCPServers,
|
|
672
|
-
() => {
|
|
673
|
-
mcpServerProxyService.getAllMCPTools().then((tools) => {
|
|
674
|
-
setMcpToolsCount(tools.length);
|
|
675
|
-
});
|
|
676
|
-
mcpServerProxyService.$getServers().then((servers) => {
|
|
677
|
-
setMcpServersCount(servers.length);
|
|
678
|
-
});
|
|
679
|
-
},
|
|
680
|
-
[mcpServerProxyService],
|
|
681
|
-
);
|
|
682
|
-
|
|
683
|
-
const handleShowMCPTools = React.useCallback(async () => {
|
|
684
|
-
const tools = await mcpServerProxyService.getAllMCPTools();
|
|
685
|
-
dialogService.open({
|
|
686
|
-
message: <MCPToolsDialog tools={tools} />,
|
|
687
|
-
type: MessageType.Empty,
|
|
688
|
-
buttons: ['关闭'],
|
|
689
|
-
});
|
|
690
|
-
}, [mcpServerProxyService, dialogService]);
|
|
691
|
-
|
|
692
|
-
const handleShowMCPConfig = React.useCallback(() => {
|
|
693
|
-
commandService.executeCommand(OPEN_MCP_CONFIG_COMMAND.id);
|
|
694
|
-
}, [commandService]);
|
|
695
|
-
|
|
696
656
|
return (
|
|
697
657
|
<div id={styles.ai_chat_view}>
|
|
698
658
|
<div className={styles.header_container}>
|
|
@@ -732,18 +692,6 @@ export const AIChatView = () => {
|
|
|
732
692
|
</Popover>
|
|
733
693
|
))}
|
|
734
694
|
</div>
|
|
735
|
-
<div className={styles.header_operate_right}>
|
|
736
|
-
{aiNativeConfigService.capabilities.supportsMCP && (
|
|
737
|
-
<>
|
|
738
|
-
<div className={styles.tag} onClick={handleShowMCPConfig}>
|
|
739
|
-
{`MCP Servers: ${mcpServersCount}`}
|
|
740
|
-
</div>
|
|
741
|
-
<div className={styles.tag} onClick={handleShowMCPTools}>
|
|
742
|
-
{`MCP Tools: ${mcpToolsCount}`}
|
|
743
|
-
</div>
|
|
744
|
-
</>
|
|
745
|
-
)}
|
|
746
|
-
</div>
|
|
747
695
|
</div>
|
|
748
696
|
<ChatInputWrapperRender
|
|
749
697
|
onSend={(value, agentId, command) =>
|
|
@@ -786,6 +734,8 @@ export function DefaultChatViewHeader({
|
|
|
786
734
|
const aiNativeConfigService = useInjectable<AINativeConfigService>(AINativeConfigService);
|
|
787
735
|
const mcpServerProxyService = useInjectable<MCPServerProxyService>(TokenMCPServerProxyService);
|
|
788
736
|
const aiChatService = useInjectable<ChatInternalService>(IChatInternalService);
|
|
737
|
+
const commandService = useInjectable<CommandService>(CommandService);
|
|
738
|
+
|
|
789
739
|
const [historyList, setHistoryList] = React.useState<IChatHistoryItem[]>([]);
|
|
790
740
|
const [currentTitle, setCurrentTitle] = React.useState<string>('');
|
|
791
741
|
const handleNewChat = React.useCallback(() => {
|
|
@@ -806,6 +756,10 @@ export function DefaultChatViewHeader({
|
|
|
806
756
|
[aiChatService],
|
|
807
757
|
);
|
|
808
758
|
|
|
759
|
+
const handleShowMCPConfig = React.useCallback(() => {
|
|
760
|
+
commandService.executeCommand(OPEN_MCP_CONFIG_COMMAND.id);
|
|
761
|
+
}, [commandService]);
|
|
762
|
+
|
|
809
763
|
const handleShowMCPTools = React.useCallback(async () => {
|
|
810
764
|
const tools = await mcpServerProxyService.getAllMCPTools();
|
|
811
765
|
dialogService.open({
|
|
@@ -894,23 +848,6 @@ export function DefaultChatViewHeader({
|
|
|
894
848
|
ariaLabel={localize('aiNative.operate.clear.title')}
|
|
895
849
|
/>
|
|
896
850
|
</Popover>
|
|
897
|
-
{aiNativeConfigService.capabilities.supportsMCP && (
|
|
898
|
-
<Popover
|
|
899
|
-
overlayClassName={styles.popover_icon}
|
|
900
|
-
id={'ai-chat-header-tools'}
|
|
901
|
-
position={PopoverPosition.left}
|
|
902
|
-
title={localize('aiNative.operate.tools.title')}
|
|
903
|
-
>
|
|
904
|
-
<EnhanceIcon
|
|
905
|
-
wrapperClassName={styles.action_btn}
|
|
906
|
-
className={getIcon('menubar-tool')}
|
|
907
|
-
onClick={handleShowMCPTools}
|
|
908
|
-
tabIndex={0}
|
|
909
|
-
role='button'
|
|
910
|
-
ariaLabel={localize('aiNative.operate.tools.title')}
|
|
911
|
-
/>
|
|
912
|
-
</Popover>
|
|
913
|
-
)}
|
|
914
851
|
<Popover
|
|
915
852
|
overlayClassName={styles.popover_icon}
|
|
916
853
|
id={'ai-chat-header-close'}
|
|
@@ -39,7 +39,7 @@ export const ChatContext = memo(() => {
|
|
|
39
39
|
50,
|
|
40
40
|
)((files) => {
|
|
41
41
|
if (files) {
|
|
42
|
-
updateAddedFiles(files);
|
|
42
|
+
updateAddedFiles([...files.attached]);
|
|
43
43
|
}
|
|
44
44
|
}, contextService);
|
|
45
45
|
|
|
@@ -57,7 +57,7 @@ export const ChatContext = memo(() => {
|
|
|
57
57
|
}, []);
|
|
58
58
|
|
|
59
59
|
const onDidDeselect = useCallback((uri: URI) => {
|
|
60
|
-
contextService.removeFileFromContext(uri);
|
|
60
|
+
contextService.removeFileFromContext(uri, true);
|
|
61
61
|
}, []);
|
|
62
62
|
|
|
63
63
|
const onDidClickFile = useCallback((uri: URI) => {
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
import cls from 'classnames';
|
|
2
2
|
import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
|
-
import { useInjectable, useLatest } from '@opensumi/ide-core-browser';
|
|
4
|
+
import { AINativeConfigService, useInjectable, useLatest } from '@opensumi/ide-core-browser';
|
|
5
5
|
import { Icon, Popover, PopoverPosition, getIcon } from '@opensumi/ide-core-browser/lib/components';
|
|
6
6
|
import { EnhanceIcon } from '@opensumi/ide-core-browser/lib/components/ai-native';
|
|
7
7
|
import { InteractiveInput } from '@opensumi/ide-core-browser/lib/components/ai-native/interactive-input/index';
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ChatAgentViewServiceToken,
|
|
10
|
+
ChatFeatureRegistryToken,
|
|
11
|
+
MessageType,
|
|
12
|
+
localize,
|
|
13
|
+
runWhenIdle,
|
|
14
|
+
} from '@opensumi/ide-core-common';
|
|
15
|
+
import { CommandService } from '@opensumi/ide-core-common/lib/command';
|
|
9
16
|
import { MonacoCommandRegistry } from '@opensumi/ide-editor/lib/browser/monaco-contrib/command/command.service';
|
|
17
|
+
import { IDialogService } from '@opensumi/ide-overlay';
|
|
10
18
|
|
|
11
|
-
import { AT_SIGN_SYMBOL, IChatAgentService, SLASH_SYMBOL } from '../../common';
|
|
19
|
+
import { AT_SIGN_SYMBOL, IChatAgentService, SLASH_SYMBOL, TokenMCPServerProxyService } from '../../common';
|
|
12
20
|
import { ChatAgentViewService } from '../chat/chat-agent.view.service';
|
|
13
21
|
import { ChatSlashCommandItemModel } from '../chat/chat-model';
|
|
14
22
|
import { ChatProxyService } from '../chat/chat-proxy.service';
|
|
15
23
|
import { ChatFeatureRegistry } from '../chat/chat.feature.registry';
|
|
24
|
+
import { OPEN_MCP_CONFIG_COMMAND } from '../mcp/config/mcp-config.commands';
|
|
25
|
+
import { MCPServerProxyService } from '../mcp/mcp-server-proxy.service';
|
|
26
|
+
import { MCPToolsDialog } from '../mcp/mcp-tools-dialog.view';
|
|
16
27
|
import { IChatSlashCommandItem } from '../types';
|
|
17
28
|
|
|
18
|
-
import { ChatContext } from './ChatContext';
|
|
19
29
|
import styles from './components.module.less';
|
|
20
30
|
|
|
21
31
|
const INSTRUCTION_BOTTOM = 8;
|
|
@@ -195,12 +205,29 @@ export const ChatInput = React.forwardRef((props: IChatInputProps, ref) => {
|
|
|
195
205
|
const [isExpand, setIsExpand] = useState(false);
|
|
196
206
|
const [placeholder, setPlaceHolder] = useState(localize('aiNative.chat.input.placeholder.default'));
|
|
197
207
|
|
|
208
|
+
const dialogService = useInjectable<IDialogService>(IDialogService);
|
|
209
|
+
const aiNativeConfigService = useInjectable<AINativeConfigService>(AINativeConfigService);
|
|
210
|
+
const mcpServerProxyService = useInjectable<MCPServerProxyService>(TokenMCPServerProxyService);
|
|
198
211
|
const monacoCommandRegistry = useInjectable<MonacoCommandRegistry>(MonacoCommandRegistry);
|
|
199
212
|
const chatAgentService = useInjectable<IChatAgentService>(IChatAgentService);
|
|
200
213
|
const chatFeatureRegistry = useInjectable<ChatFeatureRegistry>(ChatFeatureRegistryToken);
|
|
214
|
+
const commandService = useInjectable<CommandService>(CommandService);
|
|
201
215
|
|
|
202
216
|
const currentAgentIdRef = useLatest(agentId);
|
|
203
217
|
|
|
218
|
+
const handleShowMCPConfig = React.useCallback(() => {
|
|
219
|
+
commandService.executeCommand(OPEN_MCP_CONFIG_COMMAND.id);
|
|
220
|
+
}, [commandService]);
|
|
221
|
+
|
|
222
|
+
const handleShowMCPTools = React.useCallback(async () => {
|
|
223
|
+
const tools = await mcpServerProxyService.getAllMCPTools();
|
|
224
|
+
dialogService.open({
|
|
225
|
+
message: <MCPToolsDialog tools={tools} />,
|
|
226
|
+
type: MessageType.Empty,
|
|
227
|
+
buttons: ['关闭'],
|
|
228
|
+
});
|
|
229
|
+
}, [mcpServerProxyService, dialogService]);
|
|
230
|
+
|
|
204
231
|
useImperativeHandle(ref, () => ({
|
|
205
232
|
setInputValue: (v: string) => {
|
|
206
233
|
setValue(v);
|
|
@@ -462,6 +489,42 @@ export const ChatInput = React.forwardRef((props: IChatInputProps, ref) => {
|
|
|
462
489
|
height={inputHeight}
|
|
463
490
|
popoverPosition={PopoverPosition.left}
|
|
464
491
|
/>
|
|
492
|
+
<div className={styles.chat_input_footer}>
|
|
493
|
+
{aiNativeConfigService.capabilities.supportsMCP && (
|
|
494
|
+
<div className={styles.mcp_desc}>
|
|
495
|
+
<Popover
|
|
496
|
+
overlayClassName={styles.popover_icon}
|
|
497
|
+
id={'ai-chat-header-mcp-server'}
|
|
498
|
+
position={PopoverPosition.left}
|
|
499
|
+
title={'MCP Server'}
|
|
500
|
+
>
|
|
501
|
+
<EnhanceIcon
|
|
502
|
+
wrapperClassName={styles.action_btn}
|
|
503
|
+
className={'codicon codicon-server'}
|
|
504
|
+
onClick={handleShowMCPConfig}
|
|
505
|
+
tabIndex={0}
|
|
506
|
+
role='button'
|
|
507
|
+
ariaLabel={'MCP Server'}
|
|
508
|
+
/>
|
|
509
|
+
</Popover>
|
|
510
|
+
<Popover
|
|
511
|
+
overlayClassName={styles.popover_icon}
|
|
512
|
+
id={'ai-chat-header-tools'}
|
|
513
|
+
position={PopoverPosition.left}
|
|
514
|
+
title={localize('aiNative.operate.tools.title')}
|
|
515
|
+
>
|
|
516
|
+
<EnhanceIcon
|
|
517
|
+
wrapperClassName={styles.action_btn}
|
|
518
|
+
className={getIcon('menubar-tool')}
|
|
519
|
+
onClick={handleShowMCPTools}
|
|
520
|
+
tabIndex={0}
|
|
521
|
+
role='button'
|
|
522
|
+
ariaLabel={localize('aiNative.operate.tools.title')}
|
|
523
|
+
/>
|
|
524
|
+
</Popover>
|
|
525
|
+
</div>
|
|
526
|
+
)}
|
|
527
|
+
</div>
|
|
465
528
|
</div>
|
|
466
529
|
);
|
|
467
530
|
});
|
|
@@ -67,13 +67,12 @@ export const ChatToolRender = (props: { value: IChatToolContent['content']; mess
|
|
|
67
67
|
<div className={styles['chat-tool-render']}>
|
|
68
68
|
<div className={styles['tool-header']} onClick={toggleExpand}>
|
|
69
69
|
<div className={styles['tool-name']}>
|
|
70
|
-
<
|
|
70
|
+
<Icon iconClass={`codicon codicon-triangle-${isExpanded ? 'down' : 'right'}`} />
|
|
71
71
|
{label}
|
|
72
72
|
</div>
|
|
73
73
|
{value.state && (
|
|
74
74
|
<div className={styles['tool-state']}>
|
|
75
75
|
<span className={styles['state-icon']}>{stateInfo.icon}</span>
|
|
76
|
-
<span className={styles['state-label']}>{stateInfo.label}</span>
|
|
77
76
|
</div>
|
|
78
77
|
)}
|
|
79
78
|
</div>
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
.chat_input_container {
|
|
97
97
|
position: relative;
|
|
98
98
|
border-radius: 9px;
|
|
99
|
+
padding: 10px 0px 0px 0px;
|
|
99
100
|
border: 1px solid var(--kt-input-border);
|
|
100
101
|
background-color: var(--design-chatInput-background);
|
|
101
102
|
&.active {
|
|
@@ -505,3 +506,22 @@
|
|
|
505
506
|
}
|
|
506
507
|
}
|
|
507
508
|
}
|
|
509
|
+
|
|
510
|
+
.chat_input_footer {
|
|
511
|
+
padding: 0px 10px;
|
|
512
|
+
display: flex;
|
|
513
|
+
align-items: center;
|
|
514
|
+
font-size: 12px;
|
|
515
|
+
|
|
516
|
+
.model_selector {
|
|
517
|
+
display: flex;
|
|
518
|
+
font-size: 11px;
|
|
519
|
+
align-items: center;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
.mcp_desc {
|
|
523
|
+
padding: 5px 0px;
|
|
524
|
+
display: flex;
|
|
525
|
+
align-items: center;
|
|
526
|
+
}
|
|
527
|
+
}
|