@opensumi/ide-ai-native 3.8.1-next-1740965430.0 → 3.8.1-next-1741071284.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 +0 -8
- package/lib/browser/chat/chat-agent.service.d.ts.map +1 -1
- package/lib/browser/chat/chat-agent.service.js +0 -34
- package/lib/browser/chat/chat-agent.service.js.map +1 -1
- package/lib/browser/chat/chat-model.d.ts.map +1 -1
- package/lib/browser/chat/chat-model.js +2 -3
- package/lib/browser/chat/chat-model.js.map +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.module.less +2 -1
- package/lib/browser/chat/chat.view.d.ts.map +1 -1
- package/lib/browser/chat/chat.view.js +60 -9
- 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 +1 -25
- 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 +3 -2
- 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 +0 -20
- package/lib/browser/context/llm-context.service.d.ts +5 -18
- package/lib/browser/context/llm-context.service.d.ts.map +1 -1
- package/lib/browser/context/llm-context.service.js +47 -80
- package/lib/browser/context/llm-context.service.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js +1 -1
- package/lib/browser/contrib/intelligent-completions/intelligent-completions.controller.js.map +1 -1
- package/lib/browser/contrib/intelligent-completions/view/default.d.ts.map +1 -1
- package/lib/browser/contrib/intelligent-completions/view/default.js +6 -0
- package/lib/browser/contrib/intelligent-completions/view/default.js.map +1 -1
- package/lib/browser/layout/layout.module.less +4 -4
- package/lib/browser/mcp/tools/components/index.module.less +0 -1
- package/lib/browser/mcp/tools/createNewFileWithText.d.ts.map +1 -1
- package/lib/browser/mcp/tools/createNewFileWithText.js +0 -1
- 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 +0 -1
- 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 +0 -2
- 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 +0 -1
- package/lib/browser/mcp/tools/runTerminalCmd.js.map +1 -1
- package/lib/browser/preferences/schema.d.ts.map +1 -1
- package/lib/browser/preferences/schema.js +1 -0
- package/lib/browser/preferences/schema.js.map +1 -1
- package/lib/common/llm-context.d.ts +9 -13
- 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 +3 -4
- package/lib/common/prompts/context-prompt-provider.d.ts.map +1 -1
- package/lib/common/prompts/context-prompt-provider.js +22 -33
- package/lib/common/prompts/context-prompt-provider.js.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 +3 -42
- package/src/browser/chat/chat-model.ts +6 -11
- package/src/browser/chat/chat-proxy.service.ts +1 -2
- package/src/browser/chat/chat.module.less +2 -1
- package/src/browser/chat/chat.view.tsx +95 -10
- package/src/browser/components/ChatContext/index.tsx +2 -2
- package/src/browser/components/ChatInput.tsx +3 -67
- package/src/browser/components/ChatToolRender.tsx +2 -1
- package/src/browser/components/chat-history.module.less +1 -1
- package/src/browser/components/components.module.less +0 -20
- package/src/browser/context/llm-context.service.ts +54 -93
- package/src/browser/contrib/intelligent-completions/intelligent-completions.controller.ts +1 -1
- package/src/browser/contrib/intelligent-completions/view/default.ts +7 -0
- package/src/browser/layout/layout.module.less +4 -4
- package/src/browser/mcp/tools/components/index.module.less +0 -1
- package/src/browser/mcp/tools/createNewFileWithText.ts +0 -1
- package/src/browser/mcp/tools/getDiagnosticsByPath.ts +0 -1
- package/src/browser/mcp/tools/handlers/RunCommand.ts +0 -2
- package/src/browser/mcp/tools/runTerminalCmd.ts +0 -1
- package/src/browser/preferences/schema.ts +1 -0
- package/src/common/llm-context.ts +4 -10
- package/src/common/prompts/context-prompt-provider.ts +29 -38
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { EditorSelectionChangeEvent } from '@opensumi/ide-editor/lib/browser/types';
|
|
13
13
|
import { IMarkerService } from '@opensumi/ide-markers/lib/common/types';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { FileContext, LLMContextService, SerializedContext } from '../../common/llm-context';
|
|
16
16
|
|
|
17
17
|
@Injectable()
|
|
18
18
|
export class LLMContextServiceImpl extends WithEventBus implements LLMContextService {
|
|
@@ -27,68 +27,40 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
|
|
|
27
27
|
|
|
28
28
|
private isAutoCollecting = false;
|
|
29
29
|
|
|
30
|
-
private
|
|
30
|
+
private contextFiles: FileContext[] = [];
|
|
31
31
|
|
|
32
|
-
private
|
|
33
|
-
private readonly maxViewFilesLimit = 20;
|
|
34
|
-
private readonly attachedFiles: FileContext[] = [];
|
|
35
|
-
private readonly recentlyViewFiles: FileContext[] = [];
|
|
36
|
-
private readonly onDidContextFilesChangeEmitter = new Emitter<{ viewed: FileContext[]; attached: FileContext[]; version: number }>();
|
|
37
|
-
onDidContextFilesChangeEvent = this.onDidContextFilesChangeEmitter.event;
|
|
38
|
-
|
|
39
|
-
private addFileToList(file: FileContext, list: FileContext[], maxLimit: number) {
|
|
40
|
-
const existingIndex = list.findIndex((f) => f.uri.toString() === file.uri.toString());
|
|
41
|
-
if (existingIndex > -1) {
|
|
42
|
-
list.splice(existingIndex, 1);
|
|
43
|
-
}
|
|
32
|
+
private maxFiles: number = 10; // 上下文的最大长度限制
|
|
44
33
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
list.shift();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
34
|
+
private onDidContextFilesChangeEmitter = new Emitter<FileContext[]>();
|
|
35
|
+
onDidContextFilesChangeEvent = this.onDidContextFilesChangeEmitter.event;
|
|
50
36
|
|
|
51
|
-
addFileToContext(uri: URI, selection?: [number, number], isManual =
|
|
52
|
-
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
37
|
+
addFileToContext(uri: URI, selection?: [number, number], isManual = true): void {
|
|
38
|
+
this.removeFileFromContext(uri);
|
|
55
39
|
|
|
56
|
-
|
|
57
|
-
const targetList = isManual ? this.attachedFiles : this.recentlyViewFiles;
|
|
58
|
-
const maxLimit = isManual ? this.maxAttachFilesLimit : this.maxViewFilesLimit;
|
|
40
|
+
this.contextFiles.push({ uri, selection, isManual });
|
|
59
41
|
|
|
60
|
-
if (
|
|
61
|
-
this.
|
|
42
|
+
if (this.contextFiles.length > this.maxFiles) {
|
|
43
|
+
this.contextFiles.shift();
|
|
62
44
|
}
|
|
63
45
|
|
|
64
|
-
this.addFileToList(file, targetList, maxLimit);
|
|
65
|
-
this.notifyContextChange();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private notifyContextChange(): void {
|
|
69
46
|
this.onDidContextFilesChangeEmitter.fire(this.getAllContextFiles());
|
|
70
47
|
}
|
|
71
48
|
|
|
72
49
|
cleanFileContext() {
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
50
|
+
this.contextFiles = [];
|
|
51
|
+
this.onDidContextFilesChangeEmitter.fire(this.getAllContextFiles());
|
|
75
52
|
}
|
|
76
53
|
|
|
77
54
|
private getAllContextFiles() {
|
|
78
|
-
return
|
|
79
|
-
viewed: this.recentlyViewFiles,
|
|
80
|
-
attached: this.attachedFiles,
|
|
81
|
-
version: this.contextVersion++,
|
|
82
|
-
};
|
|
55
|
+
return [...this.contextFiles];
|
|
83
56
|
}
|
|
84
57
|
|
|
85
|
-
removeFileFromContext(uri: URI
|
|
86
|
-
const
|
|
87
|
-
const index = targetList.findIndex((file) => file.uri.toString() === uri.toString());
|
|
58
|
+
removeFileFromContext(uri: URI): void {
|
|
59
|
+
const index = this.contextFiles.findIndex((file) => file.uri.toString() === uri.toString());
|
|
88
60
|
if (index > -1) {
|
|
89
|
-
|
|
61
|
+
this.contextFiles.splice(index, 1);
|
|
62
|
+
this.onDidContextFilesChangeEmitter.fire(this.getAllContextFiles());
|
|
90
63
|
}
|
|
91
|
-
this.notifyContextChange();
|
|
92
64
|
}
|
|
93
65
|
|
|
94
66
|
startAutoCollection(): void {
|
|
@@ -106,7 +78,8 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
|
|
|
106
78
|
if (event.payload.uri.scheme !== 'file') {
|
|
107
79
|
return;
|
|
108
80
|
}
|
|
109
|
-
|
|
81
|
+
// FIXME: 暂时不自动添加
|
|
82
|
+
// this.addFileToContext(event.payload.uri);
|
|
110
83
|
}),
|
|
111
84
|
);
|
|
112
85
|
|
|
@@ -115,8 +88,6 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
|
|
|
115
88
|
if (event.payload.scheme !== 'file') {
|
|
116
89
|
return;
|
|
117
90
|
}
|
|
118
|
-
|
|
119
|
-
this.removeFileFromContext(event.payload, false);
|
|
120
91
|
}),
|
|
121
92
|
);
|
|
122
93
|
|
|
@@ -138,12 +109,11 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
|
|
|
138
109
|
].sort() as [number, number];
|
|
139
110
|
|
|
140
111
|
if (selection[0] === selection[1]) {
|
|
141
|
-
this.addFileToContext(event.payload.editorUri, undefined
|
|
112
|
+
this.addFileToContext(event.payload.editorUri, undefined);
|
|
142
113
|
} else {
|
|
143
114
|
this.addFileToContext(
|
|
144
115
|
event.payload.editorUri,
|
|
145
116
|
selection.sort((a, b) => a - b),
|
|
146
|
-
false,
|
|
147
117
|
);
|
|
148
118
|
}
|
|
149
119
|
}
|
|
@@ -157,51 +127,42 @@ export class LLMContextServiceImpl extends WithEventBus implements LLMContextSer
|
|
|
157
127
|
|
|
158
128
|
serialize(): SerializedContext {
|
|
159
129
|
const files = this.getAllContextFiles();
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return files
|
|
170
|
-
.map((file) => workspaceRoot.relative(file.uri)?.toString() || file.uri.parent.toString())
|
|
130
|
+
const recentlyViewFiles = files
|
|
131
|
+
.filter((v) => !v.selection)
|
|
132
|
+
.map((file) => {
|
|
133
|
+
const relativePath = URI.file(this.appConfig.workspaceDir).relative(file.uri);
|
|
134
|
+
if (relativePath) {
|
|
135
|
+
return relativePath.toString();
|
|
136
|
+
}
|
|
137
|
+
return file.uri.parent.toString();
|
|
138
|
+
})
|
|
171
139
|
.filter(Boolean);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private serializeAttachedFiles(files: FileContext[], workspaceRoot: URI): AttachFileContext[] {
|
|
175
|
-
return files
|
|
176
|
-
.map((file) => this.serializeAttachedFile(file, workspaceRoot))
|
|
177
|
-
.filter(Boolean) as unknown as AttachFileContext[];
|
|
178
|
-
}
|
|
179
140
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return this.markerService
|
|
200
|
-
.getManager()
|
|
201
|
-
.getMarkers({
|
|
202
|
-
resource: uri.toString(),
|
|
203
|
-
severities: MarkerSeverity.Error,
|
|
141
|
+
const attachedFiles = files
|
|
142
|
+
.filter((v) => v.selection)
|
|
143
|
+
.map((file) => {
|
|
144
|
+
const ref = this.docModelManager.getModelReference(file.uri);
|
|
145
|
+
const content = ref!.instance.getText();
|
|
146
|
+
const lineErrors = this.markerService
|
|
147
|
+
.getManager()
|
|
148
|
+
.getMarkers({
|
|
149
|
+
resource: file.uri.toString(),
|
|
150
|
+
severities: MarkerSeverity.Error,
|
|
151
|
+
})
|
|
152
|
+
.map((marker) => marker.message);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
content,
|
|
156
|
+
lineErrors,
|
|
157
|
+
path: URI.file(this.appConfig.workspaceDir).relative(file.uri)!.toString(),
|
|
158
|
+
language: ref?.instance.languageId!,
|
|
159
|
+
};
|
|
204
160
|
})
|
|
205
|
-
.
|
|
161
|
+
.filter(Boolean);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
recentlyViewFiles,
|
|
165
|
+
attachedFiles,
|
|
166
|
+
};
|
|
206
167
|
}
|
|
207
168
|
}
|
|
@@ -290,7 +290,7 @@ export class IntelligentCompletionsController extends BaseAIMonacoEditorControll
|
|
|
290
290
|
const range = completionModel.items[0].range;
|
|
291
291
|
if (position.lineNumber < range.startLineNumber || position.lineNumber > range.endLineNumber) {
|
|
292
292
|
runWhenIdle(() => {
|
|
293
|
-
this.
|
|
293
|
+
this.hide();
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
296
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { AI_CODE_EDITS_COMMANDS } from '@opensumi/ide-core-browser/lib/ai-native/command';
|
|
2
|
+
import { CommandService } from '@opensumi/ide-core-common';
|
|
1
3
|
import {
|
|
2
4
|
InlineCompletionContext,
|
|
3
5
|
InlineCompletionTriggerKind,
|
|
@@ -27,6 +29,7 @@ import {
|
|
|
27
29
|
|
|
28
30
|
import { CodeEditsResultValue, ICodeEdit, ICodeEditsResult } from '../index';
|
|
29
31
|
|
|
32
|
+
|
|
30
33
|
import { BaseCodeEditsView } from './base';
|
|
31
34
|
|
|
32
35
|
/**
|
|
@@ -115,6 +118,10 @@ export class DefaultCodeEditsView extends BaseCodeEditsView {
|
|
|
115
118
|
return completionModel;
|
|
116
119
|
},
|
|
117
120
|
freeInlineCompletions: () => [],
|
|
121
|
+
handleRejection: (completions, item) => {
|
|
122
|
+
const commandService: CommandService = this.injector.get(CommandService);
|
|
123
|
+
commandService.executeCommand(AI_CODE_EDITS_COMMANDS.DISCARD.id);
|
|
124
|
+
},
|
|
118
125
|
} as InlineCompletionsProvider<ICodeEditsResult<ICodeEdit>>,
|
|
119
126
|
],
|
|
120
127
|
} as unknown as LanguageFeatureRegistry<InlineCompletionsProvider>,
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
padding: 8px 12px;
|
|
15
15
|
min-width: initial;
|
|
16
16
|
margin: 0;
|
|
17
|
+
|
|
18
|
+
::after {
|
|
19
|
+
content: '';
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
.rce-mbox-text {
|
|
20
24
|
line-height: 18px;
|
|
21
25
|
width: inherit;
|
|
22
26
|
font-size: 12px;
|
|
23
|
-
|
|
24
|
-
&::after {
|
|
25
|
-
display: none;
|
|
26
|
-
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
.rce-smsg {
|
|
@@ -27,7 +27,6 @@ export class CreateNewFileWithTextTool implements MCPServerContribution {
|
|
|
27
27
|
getToolDefinition(): MCPToolDefinition {
|
|
28
28
|
return {
|
|
29
29
|
name: 'create_new_file_with_text',
|
|
30
|
-
label: 'Create File',
|
|
31
30
|
description:
|
|
32
31
|
'Creates a new file at the specified path within the project directory and populates it with the provided text. ' +
|
|
33
32
|
'Use this tool to generate new files in your project structure. ' +
|
|
@@ -29,7 +29,6 @@ export class GetDiagnosticsByPathTool implements MCPServerContribution {
|
|
|
29
29
|
getToolDefinition(): MCPToolDefinition {
|
|
30
30
|
return {
|
|
31
31
|
name: 'get_diagnostics_by_path',
|
|
32
|
-
label: 'Get Diagnostics',
|
|
33
32
|
description:
|
|
34
33
|
'Retrieves diagnostic information (errors, warnings, etc.) from a specific file in the project. ' +
|
|
35
34
|
'Use this tool to get information about problems in any project file. ' +
|
|
@@ -49,7 +49,6 @@ export class RunCommandHandler {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async handler(args: z.infer<typeof inputSchema> & { toolCallId: string }, logger: MCPLogger) {
|
|
52
|
-
logger.appendLine(`Executing command: ${args.command}`);
|
|
53
52
|
if (args.require_user_approval) {
|
|
54
53
|
const def = new Deferred<boolean>();
|
|
55
54
|
this.approvalDeferredMap.set(args.toolCallId, def);
|
|
@@ -90,7 +89,6 @@ export class RunCommandHandler {
|
|
|
90
89
|
content: result,
|
|
91
90
|
});
|
|
92
91
|
|
|
93
|
-
logger.appendLine(`Command ${args.command} finished with exit code: ${e.code}`);
|
|
94
92
|
terminalClient.term.writeln(
|
|
95
93
|
`\n${color.italic}> Command ${args.command} executed successfully. Terminal will close in ${
|
|
96
94
|
3000 / 1000
|
|
@@ -32,7 +32,6 @@ export class RunTerminalCommandTool implements MCPServerContribution {
|
|
|
32
32
|
getToolDefinition(): MCPToolDefinition {
|
|
33
33
|
return {
|
|
34
34
|
name: 'run_terminal_cmd',
|
|
35
|
-
label: 'Run Command',
|
|
36
35
|
description:
|
|
37
36
|
"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.",
|
|
38
37
|
inputSchema,
|
|
@@ -15,13 +15,13 @@ export interface LLMContextService {
|
|
|
15
15
|
*/
|
|
16
16
|
cleanFileContext(): void;
|
|
17
17
|
|
|
18
|
-
onDidContextFilesChangeEvent: Event<
|
|
18
|
+
onDidContextFilesChangeEvent: Event<FileContext[]>;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* 从 context 中移除文件
|
|
22
22
|
* @param uri URI
|
|
23
23
|
*/
|
|
24
|
-
removeFileFromContext(uri: URI
|
|
24
|
+
removeFileFromContext(uri: URI): void;
|
|
25
25
|
|
|
26
26
|
/** 导出为可序列化格式 */
|
|
27
27
|
serialize(): SerializedContext;
|
|
@@ -30,18 +30,12 @@ export interface LLMContextService {
|
|
|
30
30
|
export interface FileContext {
|
|
31
31
|
uri: URI;
|
|
32
32
|
selection?: [number, number];
|
|
33
|
+
isManual: boolean;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export const LLMContextServiceToken = Symbol('LLMContextService');
|
|
36
37
|
|
|
37
|
-
export interface AttachFileContext {
|
|
38
|
-
content: string;
|
|
39
|
-
lineErrors: string[];
|
|
40
|
-
path: string;
|
|
41
|
-
language: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
38
|
export interface SerializedContext {
|
|
45
39
|
recentlyViewFiles: string[];
|
|
46
|
-
attachedFiles: Array<
|
|
40
|
+
attachedFiles: Array<{ content: string; lineErrors: string[]; path: string; language: string }>;
|
|
47
41
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Injectable } from '@opensumi/di';
|
|
2
|
+
import { MaybePromise } from '@opensumi/ide-core-common/lib/utils';
|
|
3
3
|
|
|
4
4
|
import { SerializedContext } from '../llm-context';
|
|
5
5
|
|
|
@@ -10,46 +10,37 @@ export interface ChatAgentPromptProvider {
|
|
|
10
10
|
* 提供上下文提示
|
|
11
11
|
* @param context 上下文
|
|
12
12
|
*/
|
|
13
|
-
provideContextPrompt(context: SerializedContext, userMessage: string): string
|
|
13
|
+
provideContextPrompt(context: SerializedContext, userMessage: string): MaybePromise<string>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
@Injectable()
|
|
17
17
|
export class DefaultChatAgentPromptProvider implements ChatAgentPromptProvider {
|
|
18
|
-
|
|
19
|
-
protected readonly workbenchEditorService: WorkbenchEditorService;
|
|
20
|
-
|
|
21
|
-
provideContextPrompt(context: SerializedContext, userMessage: string): string {
|
|
22
|
-
const editor = this.workbenchEditorService.currentEditor;
|
|
23
|
-
const currentModel = editor?.currentDocumentModel;
|
|
18
|
+
provideContextPrompt(context: SerializedContext, userMessage: string): MaybePromise<string> {
|
|
24
19
|
return `
|
|
25
|
-
<additional_data>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
${context.recentlyViewFiles.map((file, idx) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
</additional_data>
|
|
51
|
-
<user_query>
|
|
52
|
-
${userMessage}
|
|
53
|
-
</user_query>`;
|
|
20
|
+
<additional_data>
|
|
21
|
+
Below are some potentially helpful/relevant pieces of information for figuring out to respond
|
|
22
|
+
<recently_viewed_files>
|
|
23
|
+
${context.recentlyViewFiles.map((file, idx) => `${idx + 1} : ${file}`)}
|
|
24
|
+
</recently_viewed_files>
|
|
25
|
+
<attached_files>
|
|
26
|
+
${context.attachedFiles.map(
|
|
27
|
+
(file) =>
|
|
28
|
+
`
|
|
29
|
+
<file_contents>
|
|
30
|
+
\`\`\`${file.language} ${file.path}
|
|
31
|
+
${file.content}
|
|
32
|
+
\`\`\`
|
|
33
|
+
</file_contents>
|
|
34
|
+
<linter_errors>
|
|
35
|
+
${file.lineErrors.join('\n')}
|
|
36
|
+
</linter_errors>
|
|
37
|
+
`,
|
|
38
|
+
)}
|
|
39
|
+
|
|
40
|
+
</attached_files>
|
|
41
|
+
</additional_data>
|
|
42
|
+
<user_query>
|
|
43
|
+
${userMessage}
|
|
44
|
+
</user_query>`;
|
|
54
45
|
}
|
|
55
46
|
}
|