@opensumi/ide-ai-native 3.8.1-next-1741093151.0 → 3.8.1-next-1741096184.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.js +1 -1
- package/lib/browser/ai-core.contribution.js.map +1 -1
- package/lib/browser/chat/chat-agent.service.d.ts +1 -0
- package/lib/browser/chat/chat-agent.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-agent.service.js +14 -3
- package/lib/browser/chat/chat-agent.service.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +13 -20
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatReply.d.ts.map +1 -1
- package/lib/browser/components/ChatReply.js +5 -0
- package/lib/browser/components/ChatReply.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +1 -0
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js +27 -0
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.d.ts +8 -0
- package/lib/browser/mcp/mcp-server.feature.registry.d.ts.map +1 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js +24 -1
- package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
- package/lib/browser/types.d.ts +4 -0
- package/lib/browser/types.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/browser/ai-core.contribution.ts +1 -1
- package/src/browser/chat/chat-agent.service.ts +25 -10
- package/src/browser/chat/chat.view.tsx +18 -40
- package/src/browser/components/ChatReply.tsx +5 -1
- package/src/browser/mcp/base-apply.service.ts +38 -1
- package/src/browser/mcp/mcp-server.feature.registry.ts +34 -2
- package/src/browser/types.ts +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// OpenSumi as MCP Server 前端的代理服务
|
|
2
2
|
import { Autowired, Injectable } from '@opensumi/di';
|
|
3
|
-
import { ILogger } from '@opensumi/ide-core-common';
|
|
3
|
+
import { AIServiceType, IAIReporter, ILogger } from '@opensumi/ide-core-common';
|
|
4
4
|
|
|
5
5
|
import { BUILTIN_MCP_SERVER_NAME } from '../../common';
|
|
6
6
|
import { getToolName } from '../../common/utils';
|
|
@@ -19,13 +19,26 @@ export class MCPServerRegistry implements IMCPServerRegistry {
|
|
|
19
19
|
private tools: MCPToolDefinition[] = [];
|
|
20
20
|
private toolComponents: Record<string, React.FC<IMCPServerToolComponentProps>> = {};
|
|
21
21
|
|
|
22
|
+
private _activeMessageInfo: {
|
|
23
|
+
messageId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
22
27
|
@Autowired(ILogger)
|
|
23
28
|
private readonly baseLogger: ILogger;
|
|
24
29
|
|
|
30
|
+
@Autowired(IAIReporter)
|
|
31
|
+
private readonly aiReporter: IAIReporter;
|
|
32
|
+
|
|
25
33
|
private get logger(): MCPLogger {
|
|
26
34
|
return new LoggerAdapter(this.baseLogger);
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
/** 设置当前活跃的消息信息,便于toolCall打点 */
|
|
38
|
+
set activeMessageInfo(params: { messageId: string; sessionId: string }) {
|
|
39
|
+
this._activeMessageInfo = params;
|
|
40
|
+
}
|
|
41
|
+
|
|
29
42
|
getMCPTool(name: string, serverName = BUILTIN_MCP_SERVER_NAME): MCPToolDefinition | undefined {
|
|
30
43
|
return this.tools.find((tool) => getToolName(tool.name, serverName) === name);
|
|
31
44
|
}
|
|
@@ -65,14 +78,33 @@ export class MCPServerRegistry implements IMCPServerRegistry {
|
|
|
65
78
|
// 统一校验并转换
|
|
66
79
|
const toolCallId = args.toolCallId;
|
|
67
80
|
args = tool.inputSchema.parse(args);
|
|
68
|
-
|
|
81
|
+
const result = await tool.handler({ ...args, toolCallId }, this.logger);
|
|
82
|
+
this.reportToolCall(name, args, result, toolCallId);
|
|
83
|
+
return result;
|
|
69
84
|
} catch (error) {
|
|
70
85
|
// eslint-disable-next-line no-console
|
|
71
86
|
console.error('callMCPTool error:', error);
|
|
87
|
+
this.reportToolCall(name, args, error, args.toolCallId);
|
|
72
88
|
return {
|
|
73
89
|
content: [{ type: 'text', text: `The tool ${name} failed to execute. Error: ${error}` }],
|
|
74
90
|
isError: true,
|
|
75
91
|
};
|
|
76
92
|
}
|
|
77
93
|
}
|
|
94
|
+
|
|
95
|
+
private reportToolCall(name: string, args: any, result: any, toolCallId: string) {
|
|
96
|
+
const tool = this.tools.find((tool) => tool.name === name);
|
|
97
|
+
if (!tool) {
|
|
98
|
+
throw new Error(`MCP tool ${name} not found`);
|
|
99
|
+
}
|
|
100
|
+
this.aiReporter.record(
|
|
101
|
+
{
|
|
102
|
+
msgType: AIServiceType.ToolCall,
|
|
103
|
+
message: JSON.stringify({ args, name, result }),
|
|
104
|
+
messageId: this._activeMessageInfo.messageId,
|
|
105
|
+
sessionId: this._activeMessageInfo.sessionId,
|
|
106
|
+
},
|
|
107
|
+
toolCallId,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
78
110
|
}
|
package/src/browser/types.ts
CHANGED
|
@@ -372,6 +372,7 @@ export interface IMCPServerToolComponentProps {
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
export interface IMCPServerRegistry {
|
|
375
|
+
activeMessageInfo: { messageId: string; sessionId: string };
|
|
375
376
|
registerMCPTool(tool: MCPToolDefinition): void;
|
|
376
377
|
getMCPTools(): MCPToolDefinition[];
|
|
377
378
|
getMCPTool(name: string): MCPToolDefinition | undefined;
|