@opensumi/ide-ai-native 3.9.1-next-1749115679.0 → 3.9.1-next-1749175927.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 +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 -78
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +32 -16
- package/lib/browser/chat/chat.view.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 +1 -7
- package/lib/browser/mcp/mcp-server.feature.registry.js.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts +3 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +40 -14
- 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 +5 -9
- package/lib/browser/mcp/tools/fileSearch.js.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.d.ts.map +1 -1
- package/lib/browser/mcp/tools/grepSearch.js +10 -22
- package/lib/browser/mcp/tools/grepSearch.js.map +1 -1
- 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 +1 -11
- package/lib/browser/mcp/tools/handlers/RunCommand.d.ts.map +1 -1
- package/lib/browser/mcp/tools/handlers/RunCommand.js +4 -11
- 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 +15 -19
- package/lib/browser/mcp/tools/listDir.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/types.d.ts +4 -0
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js.map +1 -1
- package/lib/node/mcp-server.sse.d.ts +1 -187
- 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 +1 -187
- package/lib/node/mcp-server.stdio.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/browser/chat/chat-manager.service.ts +16 -7
- package/src/browser/chat/chat-model.ts +130 -75
- package/src/browser/chat/chat.view.tsx +46 -14
- package/src/browser/mcp/mcp-server.feature.registry.ts +1 -6
- package/src/browser/mcp/tools/createNewFileWithText.ts +46 -17
- package/src/browser/mcp/tools/fileSearch.ts +5 -8
- package/src/browser/mcp/tools/grepSearch.ts +21 -32
- 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 +14 -21
- package/src/browser/mcp/tools/listDir.ts +12 -15
- package/src/browser/model/msg-history-manager.ts +181 -2
- package/src/browser/types.ts +6 -0
- package/src/node/mcp-server.sse.ts +2 -1
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts +0 -15
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.d.ts.map +0 -1
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js +0 -53
- package/lib/browser/mcp/tools/handlers/CreateNewFileWithText.js.map +0 -1
- package/src/browser/mcp/tools/handlers/CreateNewFileWithText.ts +0 -49
|
@@ -63,21 +63,18 @@ export class ListDirTool implements MCPServerContribution {
|
|
|
63
63
|
|
|
64
64
|
// 设置消息的附加数据
|
|
65
65
|
const messages = this.chatInternalService.sessionModel.history.getMessages();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
66
|
+
this.chatInternalService.sessionModel.history.setMessageAdditional(messages[messages.length - 1].id, {
|
|
67
|
+
[args.toolCallId]: {
|
|
68
|
+
files: fileUris,
|
|
69
|
+
title: `Listed directory "${args.relativeWorkspacePath}"`,
|
|
70
|
+
details: result.files.map((file) => ({
|
|
71
|
+
type: file.isDirectory ? 'dir' : 'file',
|
|
72
|
+
name: file.name,
|
|
73
|
+
info: file.isDirectory ? `${file.numChildren ?? '?'} items` : `${file.size}KB, ${file.numLines} lines`,
|
|
74
|
+
lastModified: file.lastModified,
|
|
75
|
+
})),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
81
78
|
|
|
82
79
|
logger.appendLine(`Listed ${fileUris.length} files in directory "${args.relativeWorkspacePath}"`);
|
|
83
80
|
|
|
@@ -1,11 +1,61 @@
|
|
|
1
1
|
import { Disposable, Emitter, Event, uuid } from '@opensumi/ide-core-common';
|
|
2
2
|
import { ChatMessageRole, IHistoryChatMessage } from '@opensumi/ide-core-common/lib/types/ai-native';
|
|
3
3
|
|
|
4
|
+
import { ChatFeatureRegistry } from '../chat/chat.feature.registry';
|
|
5
|
+
|
|
4
6
|
type IExcludeMessage = Omit<IHistoryChatMessage, 'id' | 'order'>;
|
|
5
7
|
|
|
8
|
+
interface IMemoryConfig {
|
|
9
|
+
shortTermSize: number; // 最近消息窗口大小(10条)
|
|
10
|
+
bufferSize: number; // 缓冲区大小(5条)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface IMemorySummary {
|
|
14
|
+
content: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
messageIds: string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface IToolCallInfo {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
args: Record<string, any>;
|
|
23
|
+
result: any;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface MessageBufferManager {
|
|
27
|
+
messages: IHistoryChatMessage[];
|
|
28
|
+
add(message: IHistoryChatMessage): void;
|
|
29
|
+
clear(): void;
|
|
30
|
+
size(): number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class SimpleMessageBuffer implements MessageBufferManager {
|
|
34
|
+
private _messages: IHistoryChatMessage[] = [];
|
|
35
|
+
|
|
36
|
+
get messages(): IHistoryChatMessage[] {
|
|
37
|
+
return this._messages;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
add(message: IHistoryChatMessage): void {
|
|
41
|
+
this._messages.push(message);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
clear(): void {
|
|
45
|
+
this._messages = [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
size(): number {
|
|
49
|
+
return this._messages.length;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
6
53
|
export class MsgHistoryManager extends Disposable {
|
|
7
54
|
private messageMap: Map<string, IHistoryChatMessage> = new Map();
|
|
8
55
|
private messageAdditionalMap: Map<string, Record<string, any>> = new Map();
|
|
56
|
+
private memorySummaries: IMemorySummary[] = [];
|
|
57
|
+
private toolCallMap: Map<string, IToolCallInfo> = new Map();
|
|
58
|
+
private isCompressing = false; // 添加压缩锁,防止重复压缩
|
|
9
59
|
|
|
10
60
|
private readonly _onMessageChange = new Emitter<IHistoryChatMessage[]>();
|
|
11
61
|
public readonly onMessageChange: Event<IHistoryChatMessage[]> = this._onMessageChange.event;
|
|
@@ -13,11 +63,33 @@ export class MsgHistoryManager extends Disposable {
|
|
|
13
63
|
private readonly _onMessageAdditionalChange = new Emitter<Record<string, any>>();
|
|
14
64
|
public readonly onMessageAdditionalChange: Event<Record<string, any>> = this._onMessageAdditionalChange.event;
|
|
15
65
|
|
|
16
|
-
|
|
66
|
+
private messageBuffer: MessageBufferManager;
|
|
67
|
+
|
|
68
|
+
memoryConfig: IMemoryConfig = {
|
|
69
|
+
shortTermSize: 10,
|
|
70
|
+
bufferSize: 5,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
constructor(
|
|
74
|
+
private chatFeatureRegistry: ChatFeatureRegistry,
|
|
75
|
+
data?: {
|
|
76
|
+
additional: Record<string, any>;
|
|
77
|
+
messages: IHistoryChatMessage[];
|
|
78
|
+
toolCalls?: Record<string, IToolCallInfo>;
|
|
79
|
+
memorySummaries?: IMemorySummary[];
|
|
80
|
+
},
|
|
81
|
+
) {
|
|
17
82
|
super();
|
|
83
|
+
this.messageBuffer = new SimpleMessageBuffer();
|
|
18
84
|
if (data) {
|
|
19
85
|
this.messageMap = new Map(data.messages.map((item) => [item.id, item]));
|
|
20
86
|
this.messageAdditionalMap = new Map(Object.entries(data.additional));
|
|
87
|
+
if (data.toolCalls) {
|
|
88
|
+
this.toolCallMap = new Map(Object.entries(data.toolCalls));
|
|
89
|
+
}
|
|
90
|
+
if (data.memorySummaries) {
|
|
91
|
+
this.memorySummaries = data.memorySummaries;
|
|
92
|
+
}
|
|
21
93
|
}
|
|
22
94
|
}
|
|
23
95
|
|
|
@@ -33,6 +105,91 @@ export class MsgHistoryManager extends Disposable {
|
|
|
33
105
|
public clearMessages() {
|
|
34
106
|
this.messageMap.clear();
|
|
35
107
|
this.messageAdditionalMap.clear();
|
|
108
|
+
this.memorySummaries = [];
|
|
109
|
+
this.toolCallMap.clear();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 压缩历史消息的方法:
|
|
114
|
+
* 1. 保持最新的10条消息不变
|
|
115
|
+
* 2. 当累积了5条超出限制的消息时,对这5条(最早的消息)进行总结
|
|
116
|
+
* 3. 总结完成后删除这5条消息
|
|
117
|
+
* 4. 重复这个过程,确保消息数量始终在可控范围内
|
|
118
|
+
*/
|
|
119
|
+
private async compressMemory() {
|
|
120
|
+
// 如果正在压缩中,直接返回
|
|
121
|
+
if (this.isCompressing) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const messages = this.messageList;
|
|
126
|
+
// 只有当消息总数超过短期记忆限制时才进行压缩
|
|
127
|
+
if (messages.length <= this.memoryConfig.shortTermSize) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
this.isCompressing = true;
|
|
133
|
+
|
|
134
|
+
// 1. 获取超出短期记忆限制的最新一条消息
|
|
135
|
+
const latestExcessMessage = messages[messages.length - this.memoryConfig.shortTermSize - 1];
|
|
136
|
+
|
|
137
|
+
// 如果这条消息已经被总结过,就不需要再处理
|
|
138
|
+
if (latestExcessMessage.isSummarized) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// 2. 将这条消息添加到缓冲区
|
|
143
|
+
this.messageBuffer.add(latestExcessMessage);
|
|
144
|
+
|
|
145
|
+
// 3. 当缓冲区达到指定大小时,进行总结
|
|
146
|
+
if (this.messageBuffer.size() >= this.memoryConfig.bufferSize) {
|
|
147
|
+
const messagesToSummarize = this.messageBuffer.messages;
|
|
148
|
+
|
|
149
|
+
const summaryProvider = this.chatFeatureRegistry.getMessageSummaryProvider?.();
|
|
150
|
+
if (summaryProvider) {
|
|
151
|
+
const messageContents = messagesToSummarize.map((msg) => ({
|
|
152
|
+
role: msg.role,
|
|
153
|
+
content: msg.content,
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
const memorize = await summaryProvider.generateMemorizedMessage(messageContents);
|
|
157
|
+
if (memorize) {
|
|
158
|
+
// 添加新的记忆总结
|
|
159
|
+
this.memorySummaries.push({
|
|
160
|
+
content: memorize,
|
|
161
|
+
timestamp: Date.now(),
|
|
162
|
+
messageIds: messagesToSummarize.map((msg) => msg.id),
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// 标记消息为已总结
|
|
166
|
+
for (const msg of messagesToSummarize) {
|
|
167
|
+
const existingMsg = this.messageMap.get(msg.id);
|
|
168
|
+
if (existingMsg) {
|
|
169
|
+
this.messageMap.set(msg.id, {
|
|
170
|
+
...existingMsg,
|
|
171
|
+
isSummarized: true,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 清空缓冲区
|
|
177
|
+
this.messageBuffer.clear();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} finally {
|
|
182
|
+
this.isCompressing = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public addToolCall(toolCall: IToolCallInfo): void {
|
|
187
|
+
this.toolCallMap.set(toolCall.id, toolCall);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public getToolCall(id: string): IToolCallInfo | undefined {
|
|
191
|
+
const toolCall = this.toolCallMap.get(id);
|
|
192
|
+
return toolCall;
|
|
36
193
|
}
|
|
37
194
|
|
|
38
195
|
private doAddMessage(message: IExcludeMessage): string {
|
|
@@ -48,11 +205,19 @@ export class MsgHistoryManager extends Disposable {
|
|
|
48
205
|
|
|
49
206
|
this.messageMap.set(id, msg);
|
|
50
207
|
|
|
208
|
+
// 在添加新消息后尝试压缩记忆
|
|
209
|
+
this.compressMemory().catch((error) => {
|
|
210
|
+
// eslint-disable-next-line no-console
|
|
211
|
+
console.error('[MsgHistoryManager] Error compressing memory', error);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// 无论压缩是否完成,都触发消息变更事件
|
|
51
215
|
this._onMessageChange.fire(this.getMessages());
|
|
52
216
|
return id;
|
|
53
217
|
}
|
|
54
218
|
|
|
55
219
|
private get messageList(): IHistoryChatMessage[] {
|
|
220
|
+
// 按 order 升序排序,保持消息的原始顺序
|
|
56
221
|
return Array.from(this.messageMap.values()).sort((a, b) => a.order - b.order);
|
|
57
222
|
}
|
|
58
223
|
|
|
@@ -65,6 +230,17 @@ export class MsgHistoryManager extends Disposable {
|
|
|
65
230
|
return this.messageList;
|
|
66
231
|
}
|
|
67
232
|
|
|
233
|
+
public getMemorySummaries(): IMemorySummary[] {
|
|
234
|
+
return this.memorySummaries;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public setMemoryConfig(config: Partial<IMemoryConfig>) {
|
|
238
|
+
this.memoryConfig = {
|
|
239
|
+
...this.memoryConfig,
|
|
240
|
+
...config,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
68
244
|
public addUserMessage(
|
|
69
245
|
message: Required<Pick<IExcludeMessage, 'agentId' | 'agentCommand' | 'content' | 'relationId' | 'images'>>,
|
|
70
246
|
): string {
|
|
@@ -118,9 +294,12 @@ export class MsgHistoryManager extends Disposable {
|
|
|
118
294
|
}
|
|
119
295
|
|
|
120
296
|
toJSON() {
|
|
121
|
-
|
|
297
|
+
const data = {
|
|
122
298
|
messages: this.getMessages(),
|
|
123
299
|
additional: Object.fromEntries(this.messageAdditionalMap.entries()),
|
|
300
|
+
memorySummaries: this.memorySummaries,
|
|
301
|
+
toolCalls: Object.fromEntries(this.toolCallMap.entries()),
|
|
124
302
|
};
|
|
303
|
+
return data;
|
|
125
304
|
}
|
|
126
305
|
}
|
package/src/browser/types.ts
CHANGED
|
@@ -308,6 +308,12 @@ export interface IMessageSummaryProvider {
|
|
|
308
308
|
content: string;
|
|
309
309
|
}>,
|
|
310
310
|
): Promise<string | undefined>;
|
|
311
|
+
generateMemorizedMessage(
|
|
312
|
+
messages: Array<{
|
|
313
|
+
role: ChatMessageRole;
|
|
314
|
+
content: string;
|
|
315
|
+
}>,
|
|
316
|
+
): Promise<string | undefined>;
|
|
311
317
|
}
|
|
312
318
|
|
|
313
319
|
export const AINativeCoreContribution = Symbol('AINativeCoreContribution');
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// have to import with extension since the exports map is ./* -> ./dist/cjs/*
|
|
2
2
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
3
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
3
|
import { EventSource } from 'eventsource';
|
|
5
4
|
|
|
6
5
|
import { ILogger } from '@opensumi/ide-core-common';
|
|
@@ -48,6 +47,8 @@ export class SSEMCPServer implements IMCPServer {
|
|
|
48
47
|
}
|
|
49
48
|
this.logger?.log(`Starting server "${this.name}" with url: ${this.url}`);
|
|
50
49
|
|
|
50
|
+
const SSEClientTransport = (await import('@modelcontextprotocol/sdk/client/sse.js')).SSEClientTransport;
|
|
51
|
+
|
|
51
52
|
const transport = new SSEClientTransport(new URL(this.url), this.transportOptions);
|
|
52
53
|
|
|
53
54
|
transport.onerror = (error) => {
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CodeBlockData } from '../../../../common/types';
|
|
2
|
-
/**
|
|
3
|
-
* 创建新文件处理器
|
|
4
|
-
* 用于处理创建新文件并写入内容的操作
|
|
5
|
-
*/
|
|
6
|
-
export declare class CreateNewFileWithTextHandler {
|
|
7
|
-
private readonly workspaceService;
|
|
8
|
-
private readonly fileService;
|
|
9
|
-
private applyService;
|
|
10
|
-
handler(params: {
|
|
11
|
-
targetFile: string;
|
|
12
|
-
codeEdit: string;
|
|
13
|
-
}, toolCallId: string): Promise<CodeBlockData>;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=CreateNewFileWithText.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateNewFileWithText.d.ts","sourceRoot":"","sources":["../../../../../src/browser/mcp/tools/handlers/CreateNewFileWithText.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAGzD;;;GAGG;AACH,qBACa,4BAA4B;IAEvC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IAGrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAqB;IAGjD,OAAO,CAAC,YAAY,CAAmB;IAEjC,OAAO,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAyB5G"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateNewFileWithTextHandler = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const di_1 = require("@opensumi/di");
|
|
6
|
-
const ide_core_common_1 = require("@opensumi/ide-core-common");
|
|
7
|
-
const ide_file_service_1 = require("@opensumi/ide-file-service");
|
|
8
|
-
const ide_workspace_1 = require("@opensumi/ide-workspace");
|
|
9
|
-
const base_apply_service_1 = require("../../base-apply.service");
|
|
10
|
-
/**
|
|
11
|
-
* 创建新文件处理器
|
|
12
|
-
* 用于处理创建新文件并写入内容的操作
|
|
13
|
-
*/
|
|
14
|
-
let CreateNewFileWithTextHandler = class CreateNewFileWithTextHandler {
|
|
15
|
-
async handler(params, toolCallId) {
|
|
16
|
-
// 获取工作区根目录
|
|
17
|
-
const workspaceRoots = this.workspaceService.tryGetRoots();
|
|
18
|
-
if (!workspaceRoots || workspaceRoots.length === 0) {
|
|
19
|
-
throw new Error("can't find project dir");
|
|
20
|
-
}
|
|
21
|
-
// 构建完整的文件路径
|
|
22
|
-
const rootUri = ide_core_common_1.URI.parse(workspaceRoots[0].uri);
|
|
23
|
-
const fullPath = ide_core_common_1.path.join(rootUri.codeUri.fsPath, params.targetFile);
|
|
24
|
-
const fileUri = ide_core_common_1.URI.file(fullPath);
|
|
25
|
-
// 创建父目录
|
|
26
|
-
const parentDir = ide_core_common_1.path.dirname(fullPath);
|
|
27
|
-
const parentUri = ide_core_common_1.URI.file(parentDir);
|
|
28
|
-
await this.fileService.createFolder(parentUri.toString());
|
|
29
|
-
// 创建文件
|
|
30
|
-
await this.fileService.createFile(fileUri.toString());
|
|
31
|
-
// 使用 applyService 写入文件内容
|
|
32
|
-
const codeBlock = await this.applyService.registerCodeBlock(params.targetFile, params.codeEdit, toolCallId);
|
|
33
|
-
await this.applyService.apply(codeBlock);
|
|
34
|
-
return codeBlock;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
exports.CreateNewFileWithTextHandler = CreateNewFileWithTextHandler;
|
|
38
|
-
tslib_1.__decorate([
|
|
39
|
-
(0, di_1.Autowired)(ide_workspace_1.IWorkspaceService),
|
|
40
|
-
tslib_1.__metadata("design:type", Object)
|
|
41
|
-
], CreateNewFileWithTextHandler.prototype, "workspaceService", void 0);
|
|
42
|
-
tslib_1.__decorate([
|
|
43
|
-
(0, di_1.Autowired)(ide_file_service_1.IFileServiceClient),
|
|
44
|
-
tslib_1.__metadata("design:type", Object)
|
|
45
|
-
], CreateNewFileWithTextHandler.prototype, "fileService", void 0);
|
|
46
|
-
tslib_1.__decorate([
|
|
47
|
-
(0, di_1.Autowired)(base_apply_service_1.BaseApplyService),
|
|
48
|
-
tslib_1.__metadata("design:type", base_apply_service_1.BaseApplyService)
|
|
49
|
-
], CreateNewFileWithTextHandler.prototype, "applyService", void 0);
|
|
50
|
-
exports.CreateNewFileWithTextHandler = CreateNewFileWithTextHandler = tslib_1.__decorate([
|
|
51
|
-
(0, di_1.Injectable)()
|
|
52
|
-
], CreateNewFileWithTextHandler);
|
|
53
|
-
//# sourceMappingURL=CreateNewFileWithText.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CreateNewFileWithText.js","sourceRoot":"","sources":["../../../../../src/browser/mcp/tools/handlers/CreateNewFileWithText.ts"],"names":[],"mappings":";;;;AAAA,qCAAqD;AACrD,+DAAsD;AACtD,iEAAgE;AAChE,2DAA4D;AAG5D,iEAA4D;AAE5D;;;GAGG;AAEI,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAUvC,KAAK,CAAC,OAAO,CAAC,MAAgD,EAAE,UAAkB;QAChF,WAAW;QACX,MAAM,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAC3D,IAAI,CAAC,cAAc,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAED,YAAY;QACZ,MAAM,OAAO,GAAG,qBAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,QAAQ,GAAG,sBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,qBAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnC,QAAQ;QACR,MAAM,SAAS,GAAG,sBAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,SAAS,GAAG,qBAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,MAAM,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE1D,OAAO;QACP,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEtD,yBAAyB;QACzB,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC5G,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACzC,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAnCY,oEAA4B;AAEtB;IADhB,IAAA,cAAS,EAAC,iCAAiB,CAAC;;sEACwB;AAGpC;IADhB,IAAA,cAAS,EAAC,qCAAkB,CAAC;;iEACmB;AAGzC;IADP,IAAA,cAAS,EAAC,qCAAgB,CAAC;sCACN,qCAAgB;kEAAC;uCAR5B,4BAA4B;IADxC,IAAA,eAAU,GAAE;GACA,4BAA4B,CAmCxC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
-
import { URI, path } from '@opensumi/ide-core-common';
|
|
3
|
-
import { IFileServiceClient } from '@opensumi/ide-file-service';
|
|
4
|
-
import { IWorkspaceService } from '@opensumi/ide-workspace';
|
|
5
|
-
|
|
6
|
-
import { CodeBlockData } from '../../../../common/types';
|
|
7
|
-
import { BaseApplyService } from '../../base-apply.service';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 创建新文件处理器
|
|
11
|
-
* 用于处理创建新文件并写入内容的操作
|
|
12
|
-
*/
|
|
13
|
-
@Injectable()
|
|
14
|
-
export class CreateNewFileWithTextHandler {
|
|
15
|
-
@Autowired(IWorkspaceService)
|
|
16
|
-
private readonly workspaceService: IWorkspaceService;
|
|
17
|
-
|
|
18
|
-
@Autowired(IFileServiceClient)
|
|
19
|
-
private readonly fileService: IFileServiceClient;
|
|
20
|
-
|
|
21
|
-
@Autowired(BaseApplyService)
|
|
22
|
-
private applyService: BaseApplyService;
|
|
23
|
-
|
|
24
|
-
async handler(params: { targetFile: string; codeEdit: string }, toolCallId: string): Promise<CodeBlockData> {
|
|
25
|
-
// 获取工作区根目录
|
|
26
|
-
const workspaceRoots = this.workspaceService.tryGetRoots();
|
|
27
|
-
if (!workspaceRoots || workspaceRoots.length === 0) {
|
|
28
|
-
throw new Error("can't find project dir");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 构建完整的文件路径
|
|
32
|
-
const rootUri = URI.parse(workspaceRoots[0].uri);
|
|
33
|
-
const fullPath = path.join(rootUri.codeUri.fsPath, params.targetFile);
|
|
34
|
-
const fileUri = URI.file(fullPath);
|
|
35
|
-
|
|
36
|
-
// 创建父目录
|
|
37
|
-
const parentDir = path.dirname(fullPath);
|
|
38
|
-
const parentUri = URI.file(parentDir);
|
|
39
|
-
await this.fileService.createFolder(parentUri.toString());
|
|
40
|
-
|
|
41
|
-
// 创建文件
|
|
42
|
-
await this.fileService.createFile(fileUri.toString());
|
|
43
|
-
|
|
44
|
-
// 使用 applyService 写入文件内容
|
|
45
|
-
const codeBlock = await this.applyService.registerCodeBlock(params.targetFile, params.codeEdit, toolCallId);
|
|
46
|
-
await this.applyService.apply(codeBlock);
|
|
47
|
-
return codeBlock;
|
|
48
|
-
}
|
|
49
|
-
}
|