@opensumi/ide-ai-native 3.7.2-next-1740323956.0 → 3.7.2-next-1740365741.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 +3 -1
- package/lib/browser/ai-core.contribution.d.ts.map +1 -1
- package/lib/browser/ai-core.contribution.js +13 -1
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/chat-manager.service.d.ts +30 -2
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +45 -1
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +33 -6
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +50 -29
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +1 -1
- package/lib/browser/chat/chat-proxy.service.js.map +1 -1
- package/lib/browser/chat/chat.internal.service.d.ts +4 -2
- package/lib/browser/chat/chat.internal.service.d.ts.map +1 -1
- package/lib/browser/chat/chat.internal.service.js +31 -12
- package/lib/browser/chat/chat.internal.service.js.map +1 -1
- package/lib/browser/chat/chat.module.less +8 -42
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +85 -31
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatHistory.d.ts +21 -0
- package/lib/browser/components/ChatHistory.d.ts.map +1 -0
- package/lib/browser/components/ChatHistory.js +148 -0
- package/lib/browser/components/ChatHistory.js.map +1 -0
- package/lib/browser/components/ChatReply.d.ts.map +1 -1
- package/lib/browser/components/ChatReply.js +3 -1
- package/lib/browser/components/ChatReply.js.map +1 -1
- package/lib/browser/components/ChatThinking.js +1 -1
- package/lib/browser/components/ChatThinking.js.map +1 -1
- package/lib/browser/components/chat-history.css +139 -0
- package/lib/browser/components/components.module.less +2 -2
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/layout/layout.module.less +1 -1
- package/lib/browser/mcp/tools/components/Terminal.d.ts +4 -0
- package/lib/browser/mcp/tools/components/Terminal.d.ts.map +1 -0
- package/lib/browser/mcp/tools/components/Terminal.js +64 -0
- package/lib/browser/mcp/tools/components/Terminal.js.map +1 -0
- package/lib/browser/mcp/tools/components/index.module.less +36 -0
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts +43 -0
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts.map +1 -0
- package/lib/browser/mcp/tools/handlers/RunCommand.js +104 -0
- package/lib/browser/mcp/tools/handlers/RunCommand.js.map +1 -0
- package/lib/browser/mcp/tools/runTerminalCmd.d.ts +1 -6
- package/lib/browser/mcp/tools/runTerminalCmd.d.ts.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js +9 -55
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +10 -0
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +14 -9
- package/lib/browser/model/msg-history-manager.js.map +1 -1
- package/package.json +23 -23
- package/src/browser/ai-core.contribution.ts +13 -1
- package/src/browser/chat/chat-manager.service.ts +83 -7
- package/src/browser/chat/chat-model.ts +62 -12
- package/src/browser/chat/chat-proxy.service.ts +1 -1
- package/src/browser/chat/chat.internal.service.ts +23 -5
- package/src/browser/chat/chat.module.less +8 -42
- package/src/browser/chat/chat.view.tsx +143 -60
- package/src/browser/components/ChatHistory.tsx +292 -0
- package/src/browser/components/ChatReply.tsx +5 -1
- package/src/browser/components/ChatThinking.tsx +1 -1
- package/src/browser/components/chat-history.css +139 -0
- package/src/browser/components/components.module.less +2 -2
- package/src/browser/layout/layout.module.less +1 -1
- package/src/browser/mcp/tools/components/Terminal.tsx +97 -0
- package/src/browser/mcp/tools/components/index.module.less +36 -0
- package/src/browser/mcp/tools/handlers/RunCommand.ts +115 -0
- package/src/browser/mcp/tools/runTerminalCmd.ts +7 -68
- package/src/browser/model/msg-history-manager.ts +15 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunCommandHandler = exports.inputSchema = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const zod_1 = tslib_1.__importDefault(require("zod"));
|
|
6
|
+
const di_1 = require("@opensumi/di");
|
|
7
|
+
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
|
|
8
|
+
const ide_terminal_next_1 = require("@opensumi/ide-terminal-next");
|
|
9
|
+
const promises_1 = require("@opensumi/ide-utils/lib/promises");
|
|
10
|
+
const color = {
|
|
11
|
+
italic: '\x1b[3m',
|
|
12
|
+
reset: '\x1b[0m',
|
|
13
|
+
};
|
|
14
|
+
exports.inputSchema = zod_1.default.object({
|
|
15
|
+
command: zod_1.default.string().describe('The terminal command to execute'),
|
|
16
|
+
is_background: zod_1.default.boolean().describe('Whether the command should be run in the background'),
|
|
17
|
+
explanation: zod_1.default
|
|
18
|
+
.string()
|
|
19
|
+
.describe('One sentence explanation as to why this command needs to be run and how it contributes to the goal.'),
|
|
20
|
+
require_user_approval: zod_1.default
|
|
21
|
+
.boolean()
|
|
22
|
+
.describe("Whether the user must approve the command before it is executed. Only set this to false if the command is safe and if it matches the user's requirements for commands that should be executed automatically."),
|
|
23
|
+
});
|
|
24
|
+
let RunCommandHandler = class RunCommandHandler {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.approvalDeferredMap = new Map();
|
|
27
|
+
this.terminalId = 0;
|
|
28
|
+
}
|
|
29
|
+
getShellLaunchConfig(command) {
|
|
30
|
+
return {
|
|
31
|
+
name: `MCP:Terminal_${this.terminalId++}`,
|
|
32
|
+
cwd: this.appConfig.workspaceDir,
|
|
33
|
+
args: ['-c', command],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async handler(args, logger) {
|
|
37
|
+
if (args.require_user_approval) {
|
|
38
|
+
const def = new promises_1.Deferred();
|
|
39
|
+
this.approvalDeferredMap.set(args.toolCallId, def);
|
|
40
|
+
const approval = await def.promise;
|
|
41
|
+
if (!approval) {
|
|
42
|
+
return {
|
|
43
|
+
isError: false,
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: 'User rejection',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const terminalClient = await this.terminalController.createTerminalWithWidget({
|
|
54
|
+
config: this.getShellLaunchConfig(args.command),
|
|
55
|
+
closeWhenExited: false,
|
|
56
|
+
});
|
|
57
|
+
this.terminalController.showTerminalPanel();
|
|
58
|
+
const result = [];
|
|
59
|
+
const def = new promises_1.Deferred();
|
|
60
|
+
terminalClient.onOutput((e) => {
|
|
61
|
+
result.push({
|
|
62
|
+
type: 'text',
|
|
63
|
+
text: e.data.toString(),
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
terminalClient.onExit((e) => {
|
|
67
|
+
const isError = e.code !== 0;
|
|
68
|
+
def.resolve({
|
|
69
|
+
isError,
|
|
70
|
+
content: result,
|
|
71
|
+
});
|
|
72
|
+
terminalClient.term.writeln(`\n${color.italic}> Command ${args.command} executed successfully. Terminal will close in ${3000 / 1000} seconds.${color.reset}\n`);
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
terminalClient.dispose();
|
|
75
|
+
this.terminalView.removeWidget(terminalClient.id);
|
|
76
|
+
}, 3000);
|
|
77
|
+
});
|
|
78
|
+
return def.promise;
|
|
79
|
+
}
|
|
80
|
+
handleApproval(callId, approval) {
|
|
81
|
+
if (!this.approvalDeferredMap.has(callId)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const def = this.approvalDeferredMap.get(callId);
|
|
85
|
+
def === null || def === void 0 ? void 0 : def.resolve(approval);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
exports.RunCommandHandler = RunCommandHandler;
|
|
89
|
+
tslib_1.__decorate([
|
|
90
|
+
(0, di_1.Autowired)(ide_terminal_next_1.ITerminalController),
|
|
91
|
+
tslib_1.__metadata("design:type", Object)
|
|
92
|
+
], RunCommandHandler.prototype, "terminalController", void 0);
|
|
93
|
+
tslib_1.__decorate([
|
|
94
|
+
(0, di_1.Autowired)(ide_core_browser_1.AppConfig),
|
|
95
|
+
tslib_1.__metadata("design:type", Object)
|
|
96
|
+
], RunCommandHandler.prototype, "appConfig", void 0);
|
|
97
|
+
tslib_1.__decorate([
|
|
98
|
+
(0, di_1.Autowired)(ide_terminal_next_1.ITerminalGroupViewService),
|
|
99
|
+
tslib_1.__metadata("design:type", Object)
|
|
100
|
+
], RunCommandHandler.prototype, "terminalView", void 0);
|
|
101
|
+
exports.RunCommandHandler = RunCommandHandler = tslib_1.__decorate([
|
|
102
|
+
(0, di_1.Injectable)()
|
|
103
|
+
], RunCommandHandler);
|
|
104
|
+
//# sourceMappingURL=RunCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RunCommand.js","sourceRoot":"","sources":["../../../../../src/browser/mcp/tools/handlers/RunCommand.ts"],"names":[],"mappings":";;;;AAAA,sDAAoB;AAEpB,qCAAqD;AACrD,iEAAuD;AACvD,mEAA6F;AAC7F,+DAA4D;AAI5D,MAAM,KAAK,GAAG;IACZ,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE,SAAS;CACjB,CAAC;AAEW,QAAA,WAAW,GAAG,aAAC,CAAC,MAAM,CAAC;IAClC,OAAO,EAAE,aAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IAC/D,aAAa,EAAE,aAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,qDAAqD,CAAC;IAC1F,WAAW,EAAE,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B;AAET;IADlB,IAAA,cAAS,EAAC,uCAAmB,CAAC;;6DAC4B;AAGxC;IADlB,IAAA,cAAS,EAAC,4BAAS,CAAC;;oDACmB;AAGrB;IADlB,IAAA,cAAS,EAAC,6CAAyB,CAAC;;uDACsB;4BARhD,iBAAiB;IAD7B,IAAA,eAAU,GAAE;GACA,iBAAiB,CAsF7B"}
|
|
@@ -5,14 +5,9 @@ export declare class RunTerminalCommandTool implements MCPServerContribution {
|
|
|
5
5
|
protected readonly terminalController: ITerminalController;
|
|
6
6
|
protected readonly appConfig: AppConfig;
|
|
7
7
|
protected readonly terminalView: ITerminalGroupViewService;
|
|
8
|
-
private
|
|
8
|
+
private readonly runCommandHandler;
|
|
9
9
|
registerMCPServer(registry: IMCPServerRegistry): void;
|
|
10
10
|
getToolDefinition(): MCPToolDefinition;
|
|
11
|
-
getShellLaunchConfig(command: string): {
|
|
12
|
-
name: string;
|
|
13
|
-
cwd: string;
|
|
14
|
-
args: string[];
|
|
15
|
-
};
|
|
16
11
|
private handler;
|
|
17
12
|
}
|
|
18
13
|
//# sourceMappingURL=runTerminalCmd.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runTerminalCmd.d.ts","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/runTerminalCmd.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAEnH,OAAO,EAAE,kBAAkB,EAAa,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"runTerminalCmd.d.ts","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/runTerminalCmd.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,mDAAmD,CAAC;AAEnH,OAAO,EAAE,kBAAkB,EAAa,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKtG,qBACa,sBAAuB,YAAW,qBAAqB;IAElE,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;IAG3D,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAGxC,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,yBAAyB,CAAC;IAG3D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAoB;IAEtD,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;IAKrD,iBAAiB,IAAI,iBAAiB;YAUxB,OAAO;CAGtB"}
|
|
@@ -2,78 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunTerminalCommandTool = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const zod_1 = require("zod");
|
|
6
5
|
const di_1 = require("@opensumi/di");
|
|
7
6
|
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
|
|
8
7
|
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
9
8
|
const controller_1 = require("@opensumi/ide-terminal-next/lib/common/controller");
|
|
10
9
|
const types_1 = require("../../types");
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
reset: '\x1b[0m',
|
|
14
|
-
};
|
|
15
|
-
const inputSchema = zod_1.z.object({
|
|
16
|
-
command: zod_1.z.string().describe('The terminal command to execute'),
|
|
17
|
-
is_background: zod_1.z.boolean().describe('Whether the command should be run in the background'),
|
|
18
|
-
explanation: zod_1.z
|
|
19
|
-
.string()
|
|
20
|
-
.describe('One sentence explanation as to why this command needs to be run and how it contributes to the goal.'),
|
|
21
|
-
require_user_approval: zod_1.z
|
|
22
|
-
.boolean()
|
|
23
|
-
.describe("Whether the user must approve the command before it is executed. Only set this to false if the command is safe and if it matches the user's requirements for commands that should be executed automatically."),
|
|
24
|
-
});
|
|
10
|
+
const Terminal_1 = require("./components/Terminal");
|
|
11
|
+
const RunCommand_1 = require("./handlers/RunCommand");
|
|
25
12
|
let RunTerminalCommandTool = class RunTerminalCommandTool {
|
|
26
|
-
constructor() {
|
|
27
|
-
this.terminalId = 0;
|
|
28
|
-
}
|
|
29
13
|
registerMCPServer(registry) {
|
|
30
14
|
registry.registerMCPTool(this.getToolDefinition());
|
|
15
|
+
registry.registerToolComponent('run_terminal_cmd', Terminal_1.TerminalToolComponent);
|
|
31
16
|
}
|
|
32
17
|
getToolDefinition() {
|
|
33
18
|
return {
|
|
34
19
|
name: 'run_terminal_cmd',
|
|
35
20
|
description: "PROPOSE a command to run on behalf of the user.\nIf you have this tool, note that you DO have the ability to run commands directly on the USER's system.\n\nAdhere to these rules:\n1. Based on the contents of the conversation, you will be told if you are in the same shell as a previous step or a new shell.\n2. If in a new shell, you should `cd` to the right directory and do necessary setup in addition to running the command.\n3. If in the same shell, the state will persist, no need to do things like `cd` to the same directory.\n4. For ANY commands that would use a pager, you should append ` | cat` to the command (or whatever is appropriate). You MUST do this for: git, less, head, tail, more, etc.\n5. For commands that are long running/expected to run indefinitely until interruption, please run them in the background. To run jobs in the background, set `is_background` to true rather than changing the details of the command.\n6. Dont include any newlines in the command.",
|
|
36
|
-
inputSchema,
|
|
21
|
+
inputSchema: RunCommand_1.inputSchema,
|
|
37
22
|
handler: this.handler.bind(this),
|
|
38
23
|
};
|
|
39
24
|
}
|
|
40
|
-
getShellLaunchConfig(command) {
|
|
41
|
-
return {
|
|
42
|
-
name: `MCP:Terminal_${this.terminalId++}`,
|
|
43
|
-
cwd: this.appConfig.workspaceDir,
|
|
44
|
-
args: ['-c', command],
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
25
|
async handler(args, logger) {
|
|
48
|
-
|
|
49
|
-
// FIXME: support approval
|
|
50
|
-
}
|
|
51
|
-
const terminalClient = await this.terminalController.createTerminalWithWidget({
|
|
52
|
-
config: this.getShellLaunchConfig(args.command),
|
|
53
|
-
closeWhenExited: false,
|
|
54
|
-
});
|
|
55
|
-
this.terminalController.showTerminalPanel();
|
|
56
|
-
const result = [];
|
|
57
|
-
const def = new ide_core_common_1.Deferred();
|
|
58
|
-
terminalClient.onOutput((e) => {
|
|
59
|
-
result.push({
|
|
60
|
-
type: 'output',
|
|
61
|
-
text: e.data.toString(),
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
terminalClient.onExit((e) => {
|
|
65
|
-
const isError = e.code !== 0;
|
|
66
|
-
def.resolve({
|
|
67
|
-
isError,
|
|
68
|
-
content: result,
|
|
69
|
-
});
|
|
70
|
-
terminalClient.term.writeln(`\n${color.italic}> Command ${args.command} executed successfully. Terminal will close in ${3000 / 1000} seconds.${color.reset}\n`);
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
terminalClient.dispose();
|
|
73
|
-
this.terminalView.removeWidget(terminalClient.id);
|
|
74
|
-
}, 3000);
|
|
75
|
-
});
|
|
76
|
-
return def.promise;
|
|
26
|
+
return this.runCommandHandler.handler(args, logger);
|
|
77
27
|
}
|
|
78
28
|
};
|
|
79
29
|
exports.RunTerminalCommandTool = RunTerminalCommandTool;
|
|
@@ -89,6 +39,10 @@ tslib_1.__decorate([
|
|
|
89
39
|
(0, di_1.Autowired)(controller_1.ITerminalGroupViewService),
|
|
90
40
|
tslib_1.__metadata("design:type", Object)
|
|
91
41
|
], RunTerminalCommandTool.prototype, "terminalView", void 0);
|
|
42
|
+
tslib_1.__decorate([
|
|
43
|
+
(0, di_1.Autowired)(RunCommand_1.RunCommandHandler),
|
|
44
|
+
tslib_1.__metadata("design:type", RunCommand_1.RunCommandHandler)
|
|
45
|
+
], RunTerminalCommandTool.prototype, "runCommandHandler", void 0);
|
|
92
46
|
exports.RunTerminalCommandTool = RunTerminalCommandTool = tslib_1.__decorate([
|
|
93
47
|
(0, ide_core_common_1.Domain)(types_1.MCPServerContribution)
|
|
94
48
|
], RunTerminalCommandTool);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runTerminalCmd.js","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/runTerminalCmd.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"runTerminalCmd.js","sourceRoot":"","sources":["../../../../src/browser/mcp/tools/runTerminalCmd.ts"],"names":[],"mappings":";;;;AAEA,qCAAyC;AACzC,iEAAuD;AACvD,+DAA6D;AAC7D,kFAAmH;AAEnH,uCAAsG;AAEtG,oDAA8D;AAC9D,sDAAuE;AAGhE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAajC,iBAAiB,CAAC,QAA4B;QAC5C,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;QACnD,QAAQ,CAAC,qBAAqB,CAAC,kBAAkB,EAAE,gCAAqB,CAAC,CAAC;IAC5E,CAAC;IAED,iBAAiB;QACf,OAAO;YACL,IAAI,EAAE,kBAAkB;YACxB,WAAW,EACT,u9BAAu9B;YACz9B,WAAW,EAAX,wBAAW;YACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SACjC,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,OAAO,CAAC,IAA0D,EAAE,MAAiB;QACjG,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;CACF,CAAA;AA/BY,wDAAsB;AAEd;IADlB,IAAA,cAAS,EAAC,gCAAmB,CAAC;;kEAC4B;AAGxC;IADlB,IAAA,cAAS,EAAC,4BAAS,CAAC;;yDACmB;AAGrB;IADlB,IAAA,cAAS,EAAC,sCAAyB,CAAC;;4DACsB;AAG1C;IADhB,IAAA,cAAS,EAAC,8BAAiB,CAAC;sCACO,8BAAiB;iEAAC;iCAX3C,sBAAsB;IADlC,IAAA,wBAAM,EAAC,6BAAqB,CAAC;GACjB,sBAAsB,CA+BlC"}
|
|
@@ -8,6 +8,10 @@ export declare class MsgHistoryManager extends Disposable {
|
|
|
8
8
|
readonly onMessageChange: Event<IHistoryChatMessage[]>;
|
|
9
9
|
private readonly _onMessageAdditionalChange;
|
|
10
10
|
readonly onMessageAdditionalChange: Event<Record<string, any>>;
|
|
11
|
+
constructor(data?: {
|
|
12
|
+
additional: Record<string, any>;
|
|
13
|
+
messages: IHistoryChatMessage[];
|
|
14
|
+
});
|
|
11
15
|
dispose(): void;
|
|
12
16
|
clearMessages(): void;
|
|
13
17
|
private doAddMessage;
|
|
@@ -17,6 +21,12 @@ export declare class MsgHistoryManager extends Disposable {
|
|
|
17
21
|
updateAssistantMessage(id: string, message: Omit<IExcludeMessage, 'role'>): void;
|
|
18
22
|
setMessageAdditional(id: string, additional: Record<string, any>): void;
|
|
19
23
|
getMessageAdditional(id: string): Record<string, any>;
|
|
24
|
+
toJSON(): {
|
|
25
|
+
messages: IHistoryChatMessage[];
|
|
26
|
+
additional: {
|
|
27
|
+
[k: string]: Record<string, any>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
20
30
|
}
|
|
21
31
|
export {};
|
|
22
32
|
//# sourceMappingURL=msg-history-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msg-history-manager.d.ts","sourceRoot":"","sources":["../../../src/browser/model/msg-history-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAW,KAAK,EAAQ,MAAM,2BAA2B,CAAC;AAE7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAEpF,KAAK,eAAe,GAAG,IAAI,CAAC,mBAAmB,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC;AAEjE,
|
|
1
|
+
{"version":3,"file":"msg-history-manager.d.ts","sourceRoot":"","sources":["../../../src/browser/model/msg-history-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAW,KAAK,EAAQ,MAAM,2BAA2B,CAAC;AAE7E,O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1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MsgHistoryManager = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const di_1 = require("@opensumi/di");
|
|
6
4
|
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
7
|
-
|
|
8
|
-
constructor() {
|
|
9
|
-
super(
|
|
5
|
+
class MsgHistoryManager extends ide_core_common_1.Disposable {
|
|
6
|
+
constructor(data) {
|
|
7
|
+
super();
|
|
10
8
|
this.messageMap = new Map();
|
|
11
9
|
this.messageAdditionalMap = new Map();
|
|
12
10
|
this._onMessageChange = new ide_core_common_1.Emitter();
|
|
13
11
|
this.onMessageChange = this._onMessageChange.event;
|
|
14
12
|
this._onMessageAdditionalChange = new ide_core_common_1.Emitter();
|
|
15
13
|
this.onMessageAdditionalChange = this._onMessageAdditionalChange.event;
|
|
14
|
+
if (data) {
|
|
15
|
+
this.messageMap = new Map(data.messages.map((item) => [item.id, item]));
|
|
16
|
+
this.messageAdditionalMap = new Map(Object.entries(data.additional));
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
dispose() {
|
|
18
20
|
this.clearMessages();
|
|
@@ -70,9 +72,12 @@ let MsgHistoryManager = class MsgHistoryManager extends ide_core_common_1.Dispos
|
|
|
70
72
|
getMessageAdditional(id) {
|
|
71
73
|
return this.messageAdditionalMap.get(id) || {};
|
|
72
74
|
}
|
|
73
|
-
|
|
75
|
+
toJSON() {
|
|
76
|
+
return {
|
|
77
|
+
messages: this.getMessages(),
|
|
78
|
+
additional: Object.fromEntries(this.messageAdditionalMap.entries()),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
74
82
|
exports.MsgHistoryManager = MsgHistoryManager;
|
|
75
|
-
exports.MsgHistoryManager = MsgHistoryManager = tslib_1.__decorate([
|
|
76
|
-
(0, di_1.Injectable)({ multiple: false })
|
|
77
|
-
], MsgHistoryManager);
|
|
78
83
|
//# sourceMappingURL=msg-history-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"msg-history-manager.js","sourceRoot":"","sources":["../../../src/browser/model/msg-history-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"msg-history-manager.js","sourceRoot":"","sources":["../../../src/browser/model/msg-history-manager.ts"],"names":[],"mappings":";;;AACA,+DAA6E;AAM7E,MAAa,iBAAkB,SAAQ,4BAAU;IAU/C,YAAY,IAA2E;QACrF,KAAK,EAAE,CAAC;QAVF,eAAU,GAAqC,IAAI,GAAG,EAAE,CAAC;QACzD,yBAAoB,GAAqC,IAAI,GAAG,EAAE,CAAC;QAE1D,qBAAgB,GAAG,IAAI,yBAAO,EAAyB,CAAC;QACzD,oBAAe,GAAiC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC;QAE3E,+BAA0B,GAAG,IAAI,yBAAO,EAAuB,CAAC;QACjE,8BAAyB,GAA+B,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC;QAI5G,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,IAAI,CAAC,oBAAoB,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAEQ,OAAO;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;QACrB,KAAK,CAAC,OAAO,EAAE,CAAC;IAClB,CAAC;IAEM,aAAa;QAClB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;IAEO,YAAY,CAAC,O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,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAEM,oBAAoB,CAAC,EAAU,EAAE,UAA+B;QACrE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;QAE9C,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAEM,oBAAoB,CAAC,EAAU;QACpC,OAAO,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IAED,MAAM;QACJ,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE;YAC5B,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;SACpE,CAAC;IACJ,CAAC;CACF;AAlGD,8CAkGC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensumi/ide-ai-native",
|
|
3
|
-
"version": "3.7.2-next-
|
|
3
|
+
"version": "3.7.2-next-1740365741.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"src"
|
|
@@ -23,26 +23,26 @@
|
|
|
23
23
|
"@ai-sdk/deepseek": "^0.1.8",
|
|
24
24
|
"@ai-sdk/openai": "^1.1.9",
|
|
25
25
|
"@modelcontextprotocol/sdk": "^1.3.1",
|
|
26
|
-
"@opensumi/ide-addons": "3.7.2-next-
|
|
27
|
-
"@opensumi/ide-components": "3.7.2-next-
|
|
28
|
-
"@opensumi/ide-connection": "3.7.2-next-
|
|
29
|
-
"@opensumi/ide-core-common": "3.7.2-next-
|
|
30
|
-
"@opensumi/ide-core-node": "3.7.2-next-
|
|
31
|
-
"@opensumi/ide-debug": "3.7.2-next-
|
|
32
|
-
"@opensumi/ide-design": "3.7.2-next-
|
|
33
|
-
"@opensumi/ide-editor": "3.7.2-next-
|
|
34
|
-
"@opensumi/ide-file-search": "3.7.2-next-
|
|
35
|
-
"@opensumi/ide-file-service": "3.7.2-next-
|
|
36
|
-
"@opensumi/ide-main-layout": "3.7.2-next-
|
|
37
|
-
"@opensumi/ide-markers": "3.7.2-next-
|
|
38
|
-
"@opensumi/ide-monaco": "3.7.2-next-
|
|
39
|
-
"@opensumi/ide-overlay": "3.7.2-next-
|
|
40
|
-
"@opensumi/ide-preferences": "3.7.2-next-
|
|
41
|
-
"@opensumi/ide-search": "3.7.2-next-
|
|
42
|
-
"@opensumi/ide-terminal-next": "3.7.2-next-
|
|
43
|
-
"@opensumi/ide-theme": "3.7.2-next-
|
|
44
|
-
"@opensumi/ide-utils": "3.7.2-next-
|
|
45
|
-
"@opensumi/ide-workspace": "3.7.2-next-
|
|
26
|
+
"@opensumi/ide-addons": "3.7.2-next-1740365741.0",
|
|
27
|
+
"@opensumi/ide-components": "3.7.2-next-1740365741.0",
|
|
28
|
+
"@opensumi/ide-connection": "3.7.2-next-1740365741.0",
|
|
29
|
+
"@opensumi/ide-core-common": "3.7.2-next-1740365741.0",
|
|
30
|
+
"@opensumi/ide-core-node": "3.7.2-next-1740365741.0",
|
|
31
|
+
"@opensumi/ide-debug": "3.7.2-next-1740365741.0",
|
|
32
|
+
"@opensumi/ide-design": "3.7.2-next-1740365741.0",
|
|
33
|
+
"@opensumi/ide-editor": "3.7.2-next-1740365741.0",
|
|
34
|
+
"@opensumi/ide-file-search": "3.7.2-next-1740365741.0",
|
|
35
|
+
"@opensumi/ide-file-service": "3.7.2-next-1740365741.0",
|
|
36
|
+
"@opensumi/ide-main-layout": "3.7.2-next-1740365741.0",
|
|
37
|
+
"@opensumi/ide-markers": "3.7.2-next-1740365741.0",
|
|
38
|
+
"@opensumi/ide-monaco": "3.7.2-next-1740365741.0",
|
|
39
|
+
"@opensumi/ide-overlay": "3.7.2-next-1740365741.0",
|
|
40
|
+
"@opensumi/ide-preferences": "3.7.2-next-1740365741.0",
|
|
41
|
+
"@opensumi/ide-search": "3.7.2-next-1740365741.0",
|
|
42
|
+
"@opensumi/ide-terminal-next": "3.7.2-next-1740365741.0",
|
|
43
|
+
"@opensumi/ide-theme": "3.7.2-next-1740365741.0",
|
|
44
|
+
"@opensumi/ide-utils": "3.7.2-next-1740365741.0",
|
|
45
|
+
"@opensumi/ide-workspace": "3.7.2-next-1740365741.0",
|
|
46
46
|
"@xterm/xterm": "5.5.0",
|
|
47
47
|
"ai": "^4.1.21",
|
|
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.7.2-next-
|
|
60
|
+
"@opensumi/ide-core-browser": "3.7.2-next-1740365741.0"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "1ee208bbd29e797ff9251531dacc732e91fd0981"
|
|
63
63
|
}
|
|
@@ -73,12 +73,16 @@ import {
|
|
|
73
73
|
AI_CHAT_VIEW_ID,
|
|
74
74
|
AI_MENU_BAR_DEBUG_TOOLBAR,
|
|
75
75
|
ChatProxyServiceToken,
|
|
76
|
+
IChatInternalService,
|
|
77
|
+
IChatManagerService,
|
|
76
78
|
ISumiMCPServerBackend,
|
|
77
79
|
SumiMCPServerProxyServicePath,
|
|
78
80
|
} from '../common';
|
|
79
81
|
import { MCPServerDescription } from '../common/mcp-server-manager';
|
|
80
82
|
|
|
83
|
+
import { ChatManagerService } from './chat/chat-manager.service';
|
|
81
84
|
import { ChatProxyService } from './chat/chat-proxy.service';
|
|
85
|
+
import { ChatInternalService } from './chat/chat.internal.service';
|
|
82
86
|
import { AIChatView } from './chat/chat.view';
|
|
83
87
|
import { CodeActionSingleHandler } from './contrib/code-action/code-action.handler';
|
|
84
88
|
import { AIInlineCompletionsProvider } from './contrib/inline-completions/completeProvider';
|
|
@@ -226,17 +230,25 @@ export class AINativeBrowserContribution
|
|
|
226
230
|
@Autowired(WorkbenchEditorService)
|
|
227
231
|
private readonly workbenchEditorService: WorkbenchEditorServiceImpl;
|
|
228
232
|
|
|
233
|
+
@Autowired(IChatManagerService)
|
|
234
|
+
private readonly chatManagerService: ChatManagerService;
|
|
235
|
+
|
|
236
|
+
@Autowired(IChatInternalService)
|
|
237
|
+
private readonly chatInternalService: ChatInternalService;
|
|
238
|
+
|
|
229
239
|
constructor() {
|
|
230
240
|
this.registerFeature();
|
|
231
241
|
}
|
|
232
242
|
|
|
233
|
-
initialize() {
|
|
243
|
+
async initialize() {
|
|
234
244
|
const { supportsChatAssistant } = this.aiNativeConfigService.capabilities;
|
|
235
245
|
|
|
236
246
|
if (supportsChatAssistant) {
|
|
237
247
|
ComponentRegistryImpl.addLayoutModule(this.appConfig.layoutConfig, AI_CHAT_VIEW_ID, AI_CHAT_CONTAINER_ID);
|
|
238
248
|
ComponentRegistryImpl.addLayoutModule(this.appConfig.layoutConfig, DESIGN_MENU_BAR_RIGHT, AI_CHAT_LOGO_AVATAR_ID);
|
|
239
249
|
this.chatProxyService.registerDefaultAgent();
|
|
250
|
+
this.chatInternalService.init();
|
|
251
|
+
await this.chatManagerService.init();
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
|
|
@@ -4,19 +4,41 @@ import {
|
|
|
4
4
|
CancellationTokenSource,
|
|
5
5
|
Disposable,
|
|
6
6
|
DisposableMap,
|
|
7
|
+
Emitter,
|
|
7
8
|
IChatProgress,
|
|
9
|
+
IStorage,
|
|
10
|
+
STORAGE_NAMESPACE,
|
|
11
|
+
StorageProvider,
|
|
8
12
|
} from '@opensumi/ide-core-common';
|
|
9
|
-
import { ChatMessageRole } from '@opensumi/ide-core-common/lib/types/ai-native';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
import { ChatModel, ChatRequestModel } from './chat-model';
|
|
13
|
+
import { ChatMessageRole, IChatMessage, IHistoryChatMessage } from '@opensumi/ide-core-common/lib/types/ai-native';
|
|
14
|
+
|
|
15
|
+
import { IChatAgentService, IChatFollowup, IChatRequestMessage, IChatResponseErrorDetails } from '../../common';
|
|
16
|
+
import { MsgHistoryManager } from '../model/msg-history-manager';
|
|
17
|
+
|
|
18
|
+
import { ChatModel, ChatRequestModel, ChatResponseModel, IChatProgressResponseContent } from './chat-model';
|
|
19
|
+
|
|
20
|
+
interface ISessionModel {
|
|
21
|
+
sessionId: string;
|
|
22
|
+
history: { additional: Record<string, any>; messages: IHistoryChatMessage[] };
|
|
23
|
+
requests: {
|
|
24
|
+
requestId: string;
|
|
25
|
+
message: IChatRequestMessage;
|
|
26
|
+
response: {
|
|
27
|
+
isCanceled: boolean;
|
|
28
|
+
responseText: string;
|
|
29
|
+
responseContents: IChatProgressResponseContent[];
|
|
30
|
+
errorDetails: IChatResponseErrorDetails | undefined;
|
|
31
|
+
followups: IChatFollowup[];
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
}
|
|
15
35
|
|
|
16
36
|
@Injectable()
|
|
17
37
|
export class ChatManagerService extends Disposable {
|
|
18
38
|
#sessionModels = this.registerDispose(new DisposableMap<string, ChatModel>());
|
|
19
39
|
#pendingRequests = this.registerDispose(new DisposableMap<string, CancellationTokenSource>());
|
|
40
|
+
private storageInitEmitter = new Emitter<void>();
|
|
41
|
+
public onStorageInit = this.storageInitEmitter.event;
|
|
20
42
|
|
|
21
43
|
@Autowired(INJECTOR_TOKEN)
|
|
22
44
|
injector: Injector;
|
|
@@ -24,12 +46,59 @@ export class ChatManagerService extends Disposable {
|
|
|
24
46
|
@Autowired(IChatAgentService)
|
|
25
47
|
chatAgentService: IChatAgentService;
|
|
26
48
|
|
|
49
|
+
@Autowired(StorageProvider)
|
|
50
|
+
private storageProvider: StorageProvider;
|
|
51
|
+
|
|
52
|
+
private _chatStorage: IStorage;
|
|
53
|
+
|
|
54
|
+
protected fromJSON(data: ISessionModel[]) {
|
|
55
|
+
// TODO: 支持ApplyService恢复
|
|
56
|
+
return data.map((item) => {
|
|
57
|
+
const model = new ChatModel({
|
|
58
|
+
sessionId: item.sessionId,
|
|
59
|
+
history: new MsgHistoryManager(item.history),
|
|
60
|
+
});
|
|
61
|
+
const requests = item.requests.map(
|
|
62
|
+
(request) =>
|
|
63
|
+
new ChatRequestModel(
|
|
64
|
+
request.requestId,
|
|
65
|
+
model,
|
|
66
|
+
request.message,
|
|
67
|
+
new ChatResponseModel(request.requestId, model, request.message.agentId, {
|
|
68
|
+
responseContents: request.response.responseContents,
|
|
69
|
+
isComplete: true,
|
|
70
|
+
responseText: request.response.responseText,
|
|
71
|
+
errorDetails: request.response.errorDetails,
|
|
72
|
+
followups: request.response.followups,
|
|
73
|
+
isCanceled: request.response.isCanceled,
|
|
74
|
+
}),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
model.restoreRequests(requests);
|
|
78
|
+
return model;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
27
82
|
constructor() {
|
|
28
83
|
super();
|
|
29
84
|
}
|
|
30
85
|
|
|
86
|
+
async init() {
|
|
87
|
+
this._chatStorage = await this.storageProvider(STORAGE_NAMESPACE.CHAT);
|
|
88
|
+
const sessionsModelData = this._chatStorage.get<ISessionModel[]>('sessionModels', []);
|
|
89
|
+
const savedSessions = this.fromJSON(sessionsModelData);
|
|
90
|
+
savedSessions.forEach((session) => {
|
|
91
|
+
this.#sessionModels.set(session.sessionId, session);
|
|
92
|
+
});
|
|
93
|
+
await this.storageInitEmitter.fireAndAwait();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getSessions() {
|
|
97
|
+
return Array.from(this.#sessionModels.values());
|
|
98
|
+
}
|
|
99
|
+
|
|
31
100
|
startSession() {
|
|
32
|
-
const model =
|
|
101
|
+
const model = new ChatModel();
|
|
33
102
|
this.#sessionModels.set(model.sessionId, model);
|
|
34
103
|
return model;
|
|
35
104
|
}
|
|
@@ -46,6 +115,7 @@ export class ChatManagerService extends Disposable {
|
|
|
46
115
|
this.#sessionModels.disposeKey(sessionId);
|
|
47
116
|
this.#pendingRequests.get(sessionId)?.cancel();
|
|
48
117
|
this.#pendingRequests.disposeKey(sessionId);
|
|
118
|
+
this.saveSessions();
|
|
49
119
|
}
|
|
50
120
|
|
|
51
121
|
createRequest(sessionId: string, message: string, agentId: string, command?: string) {
|
|
@@ -122,11 +192,17 @@ export class ChatManagerService extends Disposable {
|
|
|
122
192
|
} finally {
|
|
123
193
|
listener.dispose();
|
|
124
194
|
this.#pendingRequests.disposeKey(model.sessionId);
|
|
195
|
+
this.saveSessions();
|
|
125
196
|
}
|
|
126
197
|
}
|
|
127
198
|
|
|
199
|
+
protected saveSessions() {
|
|
200
|
+
this._chatStorage.set('sessionModels', this.getSessions());
|
|
201
|
+
}
|
|
202
|
+
|
|
128
203
|
cancelRequest(sessionId: string) {
|
|
129
204
|
this.#pendingRequests.get(sessionId)?.cancel();
|
|
130
205
|
this.#pendingRequests.disposeKey(sessionId);
|
|
206
|
+
this.saveSessions();
|
|
131
207
|
}
|
|
132
208
|
}
|