@opensumi/ide-ai-native 3.9.1-next-1749007675.0 → 3.9.1-next-1749008258.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 +0 -1
- package/lib/browser/chat/chat-manager.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-manager.service.js +3 -8
- package/lib/browser/chat/chat-manager.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts +1 -3
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +17 -48
- package/lib/browser/chat/chat-model.js.map +1 -1
- package/lib/browser/chat/chat-proxy.service.d.ts +0 -2
- package/lib/browser/chat/chat-proxy.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-proxy.service.js +50 -57
- package/lib/browser/chat/chat-proxy.service.js.map +1 -1
- package/lib/browser/chat/chat.feature.registry.d.ts +1 -4
- package/lib/browser/chat/chat.feature.registry.d.ts.map +1 -1
- package/lib/browser/chat/chat.feature.registry.js +0 -6
- package/lib/browser/chat/chat.feature.registry.js.map +1 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +12 -29
- package/lib/browser/chat/chat.view.js.map +1 -1
- package/lib/browser/components/ChatMentionInput.d.ts.map +1 -1
- package/lib/browser/components/ChatMentionInput.js +141 -30
- package/lib/browser/components/ChatMentionInput.js.map +1 -1
- package/lib/browser/components/ChatToolRender.module.less +1 -0
- package/lib/browser/components/components.module.less +9 -8
- package/lib/browser/components/mention-input/mention-input.d.ts.map +1 -1
- package/lib/browser/components/mention-input/mention-input.js +161 -14
- package/lib/browser/components/mention-input/mention-input.js.map +1 -1
- package/lib/browser/components/mention-input/mention-input.module.less +165 -1
- package/lib/browser/components/mention-input/mention-select.d.ts +28 -0
- package/lib/browser/components/mention-input/mention-select.d.ts.map +1 -0
- package/lib/browser/components/mention-input/mention-select.js +136 -0
- package/lib/browser/components/mention-input/mention-select.js.map +1 -0
- package/lib/browser/components/mention-input/mention-select.module.less +297 -0
- package/lib/browser/components/mention-input/types.d.ts +16 -1
- package/lib/browser/components/mention-input/types.d.ts.map +1 -1
- package/lib/browser/components/mention-input/types.js +1 -0
- package/lib/browser/components/mention-input/types.js.map +1 -1
- package/lib/browser/components/utils.d.ts +2 -2
- package/lib/browser/context/llm-context.service.d.ts +21 -2
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +162 -20
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js +1 -1
- package/lib/browser/contrib/intelligent-completions/diff-computer.js.map +1 -1
- package/lib/browser/contrib/terminal/terminal.feature.registry.js.map +1 -1
- package/lib/browser/index.d.ts.map +1 -1
- package/lib/browser/index.js +7 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/mcp/base-apply.service.d.ts +2 -2
- package/lib/browser/mcp/base-apply.service.d.ts.map +1 -1
- package/lib/browser/mcp/base-apply.service.js.map +1 -1
- package/lib/browser/mcp/tools/getDiagnosticsByPath.js.map +1 -1
- package/lib/browser/mcp/tools/getOpenEditorFileDiagnostics.js.map +1 -1
- package/lib/browser/mcp/tools/handlers/ListDir.js.map +1 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/model/msg-history-manager.d.ts +1 -39
- package/lib/browser/model/msg-history-manager.d.ts.map +1 -1
- package/lib/browser/model/msg-history-manager.js +3 -170
- package/lib/browser/model/msg-history-manager.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +5 -0
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/browser/rules/rules.contribution.d.ts +29 -0
- package/lib/browser/rules/rules.contribution.d.ts.map +1 -0
- package/lib/browser/rules/rules.contribution.js +94 -0
- package/lib/browser/rules/rules.contribution.js.map +1 -0
- package/lib/browser/rules/rules.module.less +175 -0
- package/lib/browser/rules/rules.service.d.ts +25 -0
- package/lib/browser/rules/rules.service.d.ts.map +1 -0
- package/lib/browser/rules/rules.service.js +180 -0
- package/lib/browser/rules/rules.service.js.map +1 -0
- package/lib/browser/rules/rules.view.d.ts +3 -0
- package/lib/browser/rules/rules.view.d.ts.map +1 -0
- package/lib/browser/rules/rules.view.js +76 -0
- package/lib/browser/rules/rules.view.js.map +1 -0
- package/lib/browser/types.d.ts +1 -8
- package/lib/browser/types.d.ts.map +1 -1
- package/lib/browser/types.js.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.d.ts.map +1 -1
- package/lib/browser/widget/inline-stream-diff/live-preview.component.js.map +1 -1
- package/lib/common/MDC_PARSER_README.md +171 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/llm-context.d.ts +19 -0
- package/lib/common/llm-context.d.ts.map +1 -1
- package/lib/common/llm-context.js.map +1 -1
- package/lib/common/mdc-parser.d.ts +60 -0
- package/lib/common/mdc-parser.d.ts.map +1 -0
- package/lib/common/mdc-parser.js +246 -0
- package/lib/common/mdc-parser.js.map +1 -0
- package/lib/common/prompts/context-prompt-provider.d.ts +0 -2
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +35 -29
- package/lib/common/prompts/context-prompt-provider.js.map +1 -1
- package/lib/common/prompts/system-prompt.d.ts +2 -0
- package/lib/common/prompts/system-prompt.d.ts.map +1 -0
- package/lib/common/prompts/system-prompt.js +5 -0
- package/lib/common/prompts/system-prompt.js.map +1 -0
- package/lib/common/types.d.ts +7 -0
- package/lib/common/types.d.ts.map +1 -1
- package/lib/node/base-language-model.d.ts.map +1 -1
- package/lib/node/base-language-model.js.map +1 -1
- package/package.json +25 -24
- package/src/browser/chat/chat-manager.service.ts +6 -15
- package/src/browser/chat/chat-model.ts +19 -56
- package/src/browser/chat/chat-proxy.service.ts +68 -81
- package/src/browser/chat/chat.feature.registry.ts +1 -17
- package/src/browser/chat/chat.view.tsx +22 -28
- package/src/browser/components/ChatMentionInput.tsx +169 -35
- package/src/browser/components/ChatToolRender.module.less +1 -0
- package/src/browser/components/components.module.less +9 -8
- package/src/browser/components/mention-input/mention-input.module.less +165 -1
- package/src/browser/components/mention-input/mention-input.tsx +257 -32
- package/src/browser/components/mention-input/mention-select.module.less +297 -0
- package/src/browser/components/mention-input/mention-select.tsx +256 -0
- package/src/browser/components/mention-input/types.ts +16 -0
- package/src/browser/context/llm-context.service.ts +182 -21
- package/src/browser/contrib/intelligent-completions/decoration/additions-deletions.decoration.ts +1 -1
- package/src/browser/contrib/intelligent-completions/diff-computer.ts +1 -1
- package/src/browser/contrib/terminal/terminal.feature.registry.ts +1 -1
- package/src/browser/index.ts +8 -0
- package/src/browser/mcp/base-apply.service.ts +0 -1
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +1 -1
- package/src/browser/mcp/tools/getOpenEditorFileDiagnostics.ts +1 -1
- package/src/browser/mcp/tools/handlers/ListDir.ts +1 -1
- package/src/browser/mcp/tools/runTerminalCmd.ts +1 -1
- package/src/browser/model/msg-history-manager.ts +3 -230
- package/src/browser/preferences/schema.ts +5 -0
- package/src/browser/rules/rules.contribution.ts +105 -0
- package/src/browser/rules/rules.module.less +175 -0
- package/src/browser/rules/rules.service.ts +189 -0
- package/src/browser/rules/rules.view.tsx +127 -0
- package/src/browser/types.ts +0 -12
- package/src/browser/widget/inline-stream-diff/live-preview.component.tsx +0 -1
- package/src/common/MDC_PARSER_README.md +171 -0
- package/src/common/index.ts +3 -0
- package/src/common/llm-context.ts +23 -0
- package/src/common/mdc-parser.ts +295 -0
- package/src/common/prompts/context-prompt-provider.ts +55 -40
- package/src/common/prompts/system-prompt.ts +2 -0
- package/src/common/types.ts +8 -0
- package/src/node/base-language-model.ts +0 -1
|
@@ -21,7 +21,6 @@ import { IChatAgentService, IChatFollowup, IChatRequestMessage, IChatResponseErr
|
|
|
21
21
|
import { MsgHistoryManager } from '../model/msg-history-manager';
|
|
22
22
|
|
|
23
23
|
import { ChatModel, ChatRequestModel, ChatResponseModel, IChatProgressResponseContent } from './chat-model';
|
|
24
|
-
import { ChatFeatureRegistry } from './chat.feature.registry';
|
|
25
24
|
|
|
26
25
|
interface ISessionModel {
|
|
27
26
|
sessionId: string;
|
|
@@ -79,23 +78,17 @@ export class ChatManagerService extends Disposable {
|
|
|
79
78
|
@Autowired(PreferenceService)
|
|
80
79
|
private preferenceService: PreferenceService;
|
|
81
80
|
|
|
82
|
-
@Autowired(ChatFeatureRegistry)
|
|
83
|
-
private chatFeatureRegistry: ChatFeatureRegistry;
|
|
84
|
-
|
|
85
81
|
private _chatStorage: IStorage;
|
|
86
82
|
|
|
87
83
|
protected fromJSON(data: ISessionModel[]) {
|
|
88
84
|
return data
|
|
89
85
|
.filter((item) => item.history.messages.length > 0)
|
|
90
86
|
.map((item) => {
|
|
91
|
-
const model = new ChatModel(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
modelId: item.modelId,
|
|
97
|
-
},
|
|
98
|
-
);
|
|
87
|
+
const model = new ChatModel({
|
|
88
|
+
sessionId: item.sessionId,
|
|
89
|
+
history: new MsgHistoryManager(item.history),
|
|
90
|
+
modelId: item.modelId,
|
|
91
|
+
});
|
|
99
92
|
const requests = item.requests.map(
|
|
100
93
|
(request) =>
|
|
101
94
|
new ChatRequestModel(
|
|
@@ -138,9 +131,7 @@ export class ChatManagerService extends Disposable {
|
|
|
138
131
|
}
|
|
139
132
|
|
|
140
133
|
startSession() {
|
|
141
|
-
const model = new ChatModel(
|
|
142
|
-
this.chatFeatureRegistry,
|
|
143
|
-
);
|
|
134
|
+
const model = new ChatModel();
|
|
144
135
|
this.#sessionModels.set(model.sessionId, model);
|
|
145
136
|
this.listenSession(model);
|
|
146
137
|
return model;
|
|
@@ -29,7 +29,6 @@ import { MsgHistoryManager } from '../model/msg-history-manager';
|
|
|
29
29
|
import { IChatSlashCommandItem } from '../types';
|
|
30
30
|
|
|
31
31
|
import type { ImagePart, TextPart, ToolCallPart } from 'ai';
|
|
32
|
-
import { ChatFeatureRegistry } from './chat.feature.registry';
|
|
33
32
|
|
|
34
33
|
export type IChatProgressResponseContent =
|
|
35
34
|
| IChatMarkdownContent
|
|
@@ -297,13 +296,10 @@ export class ChatRequestModel implements IChatRequestModel {
|
|
|
297
296
|
export class ChatModel extends Disposable implements IChatModel {
|
|
298
297
|
private requestIdPool = 0;
|
|
299
298
|
|
|
300
|
-
constructor(
|
|
301
|
-
private chatFeatureRegistry: ChatFeatureRegistry,
|
|
302
|
-
initParams?: { sessionId?: string; history?: MsgHistoryManager; modelId?: string },
|
|
303
|
-
) {
|
|
299
|
+
constructor(initParams?: { sessionId?: string; history?: MsgHistoryManager; modelId?: string }) {
|
|
304
300
|
super();
|
|
305
301
|
this.#sessionId = initParams?.sessionId ?? uuid();
|
|
306
|
-
this.history = initParams?.history ?? new MsgHistoryManager(
|
|
302
|
+
this.history = initParams?.history ?? new MsgHistoryManager();
|
|
307
303
|
this.#modelId = initParams?.modelId;
|
|
308
304
|
}
|
|
309
305
|
|
|
@@ -350,9 +346,9 @@ export class ChatModel extends Disposable implements IChatModel {
|
|
|
350
346
|
role: 'user',
|
|
351
347
|
content: request.message.images?.length
|
|
352
348
|
? [
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
349
|
+
{ type: 'text', text: request.message.prompt },
|
|
350
|
+
...request.message.images.map((image) => ({ type: 'image', image: new URL(image) } as ImagePart)),
|
|
351
|
+
]
|
|
356
352
|
: request.message.prompt,
|
|
357
353
|
});
|
|
358
354
|
for (const part of request.response.responseParts) {
|
|
@@ -379,58 +375,18 @@ export class ChatModel extends Disposable implements IChatModel {
|
|
|
379
375
|
content: [],
|
|
380
376
|
});
|
|
381
377
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
toolCallId,
|
|
385
|
-
|
|
386
|
-
hasArguments: !!part.content.function.arguments,
|
|
387
|
-
hasResult: !!part.content.result,
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
const toolCallInfo = {
|
|
391
|
-
id: toolCallId,
|
|
392
|
-
name: part.content.function.name,
|
|
378
|
+
(history[history.length - 1].content as Array<TextPart | ToolCallPart>).push({
|
|
379
|
+
type: 'tool-call',
|
|
380
|
+
toolCallId: part.content.id,
|
|
381
|
+
toolName: part.content.function.name,
|
|
393
382
|
args: (() => {
|
|
394
383
|
try {
|
|
395
|
-
|
|
396
|
-
console.log('[ChatModel] Parsed toolCall arguments', {
|
|
397
|
-
toolCallId,
|
|
398
|
-
args,
|
|
399
|
-
});
|
|
400
|
-
return args;
|
|
401
|
-
} catch (e) {
|
|
402
|
-
console.error('[ChatModel] Failed to parse tool call arguments:', e);
|
|
403
|
-
return {};
|
|
404
|
-
}
|
|
405
|
-
})(),
|
|
406
|
-
result: (() => {
|
|
407
|
-
try {
|
|
408
|
-
const result = JSON.parse(part.content.result || '{}');
|
|
409
|
-
console.log('[ChatModel] Parsed toolCall result', {
|
|
410
|
-
toolCallId,
|
|
411
|
-
resultSize: JSON.stringify(result).length,
|
|
412
|
-
});
|
|
413
|
-
return result;
|
|
384
|
+
return JSON.parse(part.content.function.arguments || '{}');
|
|
414
385
|
} catch (e) {
|
|
415
|
-
console.error('
|
|
386
|
+
console.error('Failed to parse tool call arguments:', e);
|
|
416
387
|
return {};
|
|
417
388
|
}
|
|
418
389
|
})(),
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
// 保存 toolCall 信息到 history manager
|
|
422
|
-
console.log('[ChatModel] Saving toolCall to history manager', {
|
|
423
|
-
toolCallId,
|
|
424
|
-
requestId: request.requestId,
|
|
425
|
-
});
|
|
426
|
-
this.history.addToolCall(toolCallInfo);
|
|
427
|
-
this.history.setMessageAdditional(request.requestId, { toolCallId });
|
|
428
|
-
|
|
429
|
-
(history[history.length - 1].content as Array<TextPart | ToolCallPart>).push({
|
|
430
|
-
type: 'tool-call',
|
|
431
|
-
toolCallId: part.content.id,
|
|
432
|
-
toolName: part.content.function.name,
|
|
433
|
-
args: toolCallInfo.args,
|
|
434
390
|
});
|
|
435
391
|
history.push({
|
|
436
392
|
role: 'tool',
|
|
@@ -439,7 +395,14 @@ export class ChatModel extends Disposable implements IChatModel {
|
|
|
439
395
|
type: 'tool-result',
|
|
440
396
|
toolCallId: part.content.id,
|
|
441
397
|
toolName: part.content.function.name,
|
|
442
|
-
result:
|
|
398
|
+
result: (() => {
|
|
399
|
+
try {
|
|
400
|
+
return JSON.parse(part.content.result || '{}');
|
|
401
|
+
} catch (e) {
|
|
402
|
+
console.error('Failed to parse tool result:', e);
|
|
403
|
+
return {};
|
|
404
|
+
}
|
|
405
|
+
})(),
|
|
443
406
|
},
|
|
444
407
|
],
|
|
445
408
|
});
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Autowired, Injectable } from '@opensumi/di';
|
|
2
|
-
import {
|
|
2
|
+
import { PreferenceService } from '@opensumi/ide-core-browser';
|
|
3
3
|
import {
|
|
4
4
|
AIBackSerivcePath,
|
|
5
5
|
CancellationToken,
|
|
6
6
|
ChatAgentViewServiceToken,
|
|
7
7
|
ChatFeatureRegistryToken,
|
|
8
|
-
ChatServiceToken,
|
|
9
8
|
Deferred,
|
|
10
9
|
Disposable,
|
|
11
10
|
IAIBackService,
|
|
12
11
|
IAIReporter,
|
|
13
12
|
IApplicationService,
|
|
14
13
|
IChatProgress,
|
|
15
|
-
getOperatingSystemName,
|
|
16
14
|
} from '@opensumi/ide-core-common';
|
|
17
15
|
import { AINativeSettingSectionsId } from '@opensumi/ide-core-common/lib/settings/ai-native';
|
|
18
16
|
import { MonacoCommandRegistry } from '@opensumi/ide-editor/lib/browser/monaco-contrib/command/command.service';
|
|
@@ -27,10 +25,10 @@ import {
|
|
|
27
25
|
IChatAgentService,
|
|
28
26
|
IChatAgentWelcomeMessage,
|
|
29
27
|
} from '../../common';
|
|
28
|
+
import { DEFAULT_SYSTEM_PROMPT } from '../../common/prompts/system-prompt';
|
|
30
29
|
import { ChatToolRender } from '../components/ChatToolRender';
|
|
31
30
|
import { IChatAgentViewService } from '../types';
|
|
32
31
|
|
|
33
|
-
import { ChatService } from './chat.api.service';
|
|
34
32
|
import { ChatFeatureRegistry } from './chat.feature.registry';
|
|
35
33
|
|
|
36
34
|
/**
|
|
@@ -53,9 +51,6 @@ export class ChatProxyService extends Disposable {
|
|
|
53
51
|
@Autowired(MonacoCommandRegistry)
|
|
54
52
|
private readonly monacoCommandRegistry: MonacoCommandRegistry;
|
|
55
53
|
|
|
56
|
-
@Autowired(ChatServiceToken)
|
|
57
|
-
private aiChatService: ChatService;
|
|
58
|
-
|
|
59
54
|
@Autowired(IAIReporter)
|
|
60
55
|
private readonly aiReporter: IAIReporter;
|
|
61
56
|
|
|
@@ -71,9 +66,6 @@ export class ChatProxyService extends Disposable {
|
|
|
71
66
|
@Autowired(IMessageService)
|
|
72
67
|
private readonly messageService: IMessageService;
|
|
73
68
|
|
|
74
|
-
@Autowired(AppConfig)
|
|
75
|
-
private readonly appConfig: AppConfig;
|
|
76
|
-
|
|
77
69
|
private chatDeferred: Deferred<void> = new Deferred<void>();
|
|
78
70
|
|
|
79
71
|
public getRequestOptions() {
|
|
@@ -112,79 +104,74 @@ export class ChatProxyService extends Disposable {
|
|
|
112
104
|
initialProps: {},
|
|
113
105
|
});
|
|
114
106
|
|
|
115
|
-
this.
|
|
116
|
-
this.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.preferenceService.get<string>(
|
|
107
|
+
this.applicationService.getBackendOS().then(() => {
|
|
108
|
+
this.addDispose(
|
|
109
|
+
this.chatAgentService.registerAgent({
|
|
110
|
+
id: ChatProxyService.AGENT_ID,
|
|
111
|
+
metadata: {
|
|
112
|
+
systemPrompt: this.preferenceService.get<string>(
|
|
121
113
|
AINativeSettingSectionsId.SystemPrompt,
|
|
122
|
-
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (commandHandler && commandHandler.providerPrompt) {
|
|
142
|
-
const editor = this.monacoCommandRegistry.getActiveCodeEditor();
|
|
143
|
-
const slashCommandPrompt = await commandHandler.providerPrompt(message, editor);
|
|
144
|
-
prompt = slashCommandPrompt;
|
|
114
|
+
DEFAULT_SYSTEM_PROMPT,
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
invoke: async (
|
|
118
|
+
request: IChatAgentRequest,
|
|
119
|
+
progress: (part: IChatProgress) => void,
|
|
120
|
+
history: CoreMessage[],
|
|
121
|
+
token: CancellationToken,
|
|
122
|
+
): Promise<IChatAgentResult> => {
|
|
123
|
+
this.chatDeferred = new Deferred<void>();
|
|
124
|
+
const { message, command } = request;
|
|
125
|
+
let prompt: string = message;
|
|
126
|
+
if (command) {
|
|
127
|
+
const commandHandler = this.chatFeatureRegistry.getSlashCommandHandler(command);
|
|
128
|
+
if (commandHandler && commandHandler.providerPrompt) {
|
|
129
|
+
const editor = this.monacoCommandRegistry.getActiveCodeEditor();
|
|
130
|
+
const slashCommandPrompt = await commandHandler.providerPrompt(message, editor);
|
|
131
|
+
prompt = slashCommandPrompt;
|
|
132
|
+
}
|
|
145
133
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
);
|
|
134
|
+
|
|
135
|
+
const stream = await this.aiBackService.requestStream(
|
|
136
|
+
prompt,
|
|
137
|
+
{
|
|
138
|
+
requestId: request.requestId,
|
|
139
|
+
sessionId: request.sessionId,
|
|
140
|
+
history,
|
|
141
|
+
images: request.images,
|
|
142
|
+
...this.getRequestOptions(),
|
|
143
|
+
},
|
|
144
|
+
token,
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
listenReadable<IChatProgress>(stream, {
|
|
148
|
+
onData: (data) => {
|
|
149
|
+
progress(data);
|
|
150
|
+
},
|
|
151
|
+
onEnd: () => {
|
|
152
|
+
this.chatDeferred.resolve();
|
|
153
|
+
},
|
|
154
|
+
onError: (error) => {
|
|
155
|
+
this.messageService.error(error.message);
|
|
156
|
+
this.aiReporter.end(request.sessionId + '_' + request.requestId, {
|
|
157
|
+
message: error.message,
|
|
158
|
+
success: false,
|
|
159
|
+
command,
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
await this.chatDeferred.promise;
|
|
165
|
+
return {};
|
|
166
|
+
},
|
|
167
|
+
provideSlashCommands: async (): Promise<IChatAgentCommand[]> =>
|
|
168
|
+
this.chatFeatureRegistry
|
|
169
|
+
.getAllSlashCommand()
|
|
170
|
+
.map((s) => ({ ...s, name: s.name, description: s.description || '' })),
|
|
171
|
+
provideChatWelcomeMessage: async (): Promise<IChatAgentWelcomeMessage | undefined> => undefined,
|
|
172
|
+
}),
|
|
173
|
+
);
|
|
174
|
+
});
|
|
188
175
|
|
|
189
176
|
queueMicrotask(() => {
|
|
190
177
|
this.chatAgentService.updateAgent(ChatProxyService.AGENT_ID, {});
|
|
@@ -2,13 +2,7 @@ import { Injectable } from '@opensumi/di';
|
|
|
2
2
|
import { Disposable, Emitter, Event, getDebugLogger } from '@opensumi/ide-core-common';
|
|
3
3
|
|
|
4
4
|
import { IChatWelcomeMessageContent, ISampleQuestions, SLASH_SYMBOL } from '../../common';
|
|
5
|
-
import {
|
|
6
|
-
IChatFeatureRegistry,
|
|
7
|
-
IChatSlashCommandHandler,
|
|
8
|
-
IChatSlashCommandItem,
|
|
9
|
-
IImageUploadProvider,
|
|
10
|
-
IMessageSummaryProvider,
|
|
11
|
-
} from '../types';
|
|
5
|
+
import { IChatFeatureRegistry, IChatSlashCommandHandler, IChatSlashCommandItem, IImageUploadProvider } from '../types';
|
|
12
6
|
|
|
13
7
|
import { ChatSlashCommandItemModel, ChatWelcomeMessageModel } from './chat-model';
|
|
14
8
|
import { ChatProxyService } from './chat-proxy.service';
|
|
@@ -20,8 +14,6 @@ export class ChatFeatureRegistry extends Disposable implements IChatFeatureRegis
|
|
|
20
14
|
private slashCommandsHandlerMap: Map<string, IChatSlashCommandHandler> = new Map();
|
|
21
15
|
private imageUploadProvider: IImageUploadProvider | undefined;
|
|
22
16
|
|
|
23
|
-
private messageSummaryProvider?: IMessageSummaryProvider;
|
|
24
|
-
|
|
25
17
|
public registerImageUploadProvider(provider: IImageUploadProvider): void {
|
|
26
18
|
this.imageUploadProvider = provider;
|
|
27
19
|
}
|
|
@@ -30,14 +22,6 @@ export class ChatFeatureRegistry extends Disposable implements IChatFeatureRegis
|
|
|
30
22
|
return this.imageUploadProvider;
|
|
31
23
|
}
|
|
32
24
|
|
|
33
|
-
public registerMessageSummaryProvider(provider: IMessageSummaryProvider): void {
|
|
34
|
-
this.messageSummaryProvider = provider;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public getMessageSummaryProvider(): IMessageSummaryProvider | undefined {
|
|
38
|
-
return this.messageSummaryProvider;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
25
|
public chatWelcomeMessageModel?: ChatWelcomeMessageModel;
|
|
42
26
|
|
|
43
27
|
private _onDidWelcomeMessageChange: Emitter<void> = new Emitter<void>();
|
|
@@ -617,7 +617,12 @@ export const AIChatView = () => {
|
|
|
617
617
|
const { message, images, agentId, command, reportExtra } = value;
|
|
618
618
|
const { actionType, actionSource } = reportExtra || {};
|
|
619
619
|
|
|
620
|
-
const request = aiChatService.createRequest(
|
|
620
|
+
const request = aiChatService.createRequest(
|
|
621
|
+
message.replaceAll(LLM_CONTEXT_KEY_REGEX, ''),
|
|
622
|
+
agentId!,
|
|
623
|
+
images,
|
|
624
|
+
command,
|
|
625
|
+
);
|
|
621
626
|
if (!request) {
|
|
622
627
|
return;
|
|
623
628
|
}
|
|
@@ -641,7 +646,7 @@ export const AIChatView = () => {
|
|
|
641
646
|
600 * 1000,
|
|
642
647
|
);
|
|
643
648
|
msgHistoryManager.addUserMessage({
|
|
644
|
-
content: message
|
|
649
|
+
content: message,
|
|
645
650
|
images: images || [],
|
|
646
651
|
agentId: agentId!,
|
|
647
652
|
agentCommand: command!,
|
|
@@ -695,14 +700,9 @@ export const AIChatView = () => {
|
|
|
695
700
|
let processedContent = message;
|
|
696
701
|
const filePattern = /\{\{@file:(.*?)\}\}/g;
|
|
697
702
|
const fileMatches = message.match(filePattern);
|
|
698
|
-
let isCleanContext = false;
|
|
699
703
|
if (fileMatches) {
|
|
700
704
|
for (const match of fileMatches) {
|
|
701
705
|
const filePath = match.replace(/\{\{@file:(.*?)\}\}/, '$1');
|
|
702
|
-
if (filePath && !isCleanContext) {
|
|
703
|
-
isCleanContext = true;
|
|
704
|
-
llmContextService.cleanFileContext();
|
|
705
|
-
}
|
|
706
706
|
const fileUri = new URI(filePath);
|
|
707
707
|
const relativePath = (await workspaceService.asRelativePath(fileUri))?.path || fileUri.displayName;
|
|
708
708
|
processedContent = processedContent.replace(match, `\`${LLM_CONTEXT_KEY.AttachedFile}${relativePath}\``);
|
|
@@ -738,6 +738,18 @@ export const AIChatView = () => {
|
|
|
738
738
|
);
|
|
739
739
|
}
|
|
740
740
|
}
|
|
741
|
+
const rulePattern = /\{\{@rule:(.*?)\}\}/g;
|
|
742
|
+
const ruleMatches = processedContent.match(rulePattern);
|
|
743
|
+
if (ruleMatches) {
|
|
744
|
+
for (const match of ruleMatches) {
|
|
745
|
+
const ruleName = match.replace(/\{\{@rule:(.*?)\}\}/, '$1');
|
|
746
|
+
const ruleUri = new URI(ruleName);
|
|
747
|
+
processedContent = processedContent.replace(
|
|
748
|
+
match,
|
|
749
|
+
`\`${LLM_CONTEXT_KEY.AttachedFile}${ruleUri.displayName}\``,
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
741
753
|
return handleAgentReply({ message: processedContent, images, agentId, command, reportExtra });
|
|
742
754
|
},
|
|
743
755
|
[handleAgentReply],
|
|
@@ -918,7 +930,6 @@ export function DefaultChatViewHeader({
|
|
|
918
930
|
}) {
|
|
919
931
|
const aiChatService = useInjectable<ChatInternalService>(IChatInternalService);
|
|
920
932
|
const messageService = useInjectable<IMessageService>(IMessageService);
|
|
921
|
-
const chatFeatureRegistry = useInjectable<ChatFeatureRegistry>(ChatFeatureRegistryToken);
|
|
922
933
|
|
|
923
934
|
const [historyList, setHistoryList] = React.useState<IChatHistoryItem[]>([]);
|
|
924
935
|
const [currentTitle, setCurrentTitle] = React.useState<string>('');
|
|
@@ -948,26 +959,9 @@ export function DefaultChatViewHeader({
|
|
|
948
959
|
const getHistoryList = () => {
|
|
949
960
|
const currentMessages = aiChatService.sessionModel.history.getMessages();
|
|
950
961
|
const latestUserMessage = currentMessages.findLast((m) => m.role === ChatMessageRole.User);
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
: '';
|
|
955
|
-
const messages = aiChatService.sessionModel.history.getMessages().map((msg) => ({
|
|
956
|
-
role: msg.role,
|
|
957
|
-
content: msg.content,
|
|
958
|
-
}));
|
|
959
|
-
if (messages.length > 2 && summaryProvider && aiChatService.sessionModel.sessionId) {
|
|
960
|
-
summaryProvider.getMessageSummary(messages).then((summary) => {
|
|
961
|
-
if (summary) {
|
|
962
|
-
setCurrentTitle(summary.slice(0, MAX_TITLE_LENGTH));
|
|
963
|
-
} else {
|
|
964
|
-
setCurrentTitle(currentTitle);
|
|
965
|
-
}
|
|
966
|
-
});
|
|
967
|
-
} else {
|
|
968
|
-
setCurrentTitle(currentTitle);
|
|
969
|
-
}
|
|
970
|
-
|
|
962
|
+
setCurrentTitle(
|
|
963
|
+
latestUserMessage ? cleanAttachedTextWrapper(latestUserMessage.content).slice(0, MAX_TITLE_LENGTH) : '',
|
|
964
|
+
);
|
|
971
965
|
setHistoryList(
|
|
972
966
|
aiChatService.getSessions().map((session) => {
|
|
973
967
|
const history = session.history;
|