@theia/ai-code-completion 1.55.1 → 1.57.0-next.112
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/README.md +2 -1
- package/lib/browser/ai-code-completion-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-code-completion-frontend-module.js +6 -2
- package/lib/browser/ai-code-completion-frontend-module.js.map +1 -1
- package/lib/browser/ai-code-completion-preference.d.ts +3 -1
- package/lib/browser/ai-code-completion-preference.d.ts.map +1 -1
- package/lib/browser/ai-code-completion-preference.js +23 -4
- package/lib/browser/ai-code-completion-preference.js.map +1 -1
- package/lib/browser/ai-code-frontend-application-contribution.d.ts +3 -2
- package/lib/browser/ai-code-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/ai-code-frontend-application-contribution.js +15 -3
- package/lib/browser/ai-code-frontend-application-contribution.js.map +1 -1
- package/lib/browser/ai-code-inline-completion-provider.d.ts +1 -1
- package/lib/browser/ai-code-inline-completion-provider.d.ts.map +1 -1
- package/lib/browser/ai-code-inline-completion-provider.js +1 -1
- package/lib/browser/ai-code-inline-completion-provider.js.map +1 -1
- package/lib/{common → browser}/code-completion-agent.d.ts +7 -2
- package/lib/browser/code-completion-agent.d.ts.map +1 -0
- package/lib/browser/code-completion-agent.js +211 -0
- package/lib/browser/code-completion-agent.js.map +1 -0
- package/lib/browser/code-completion-postprocessor.d.ts +11 -0
- package/lib/browser/code-completion-postprocessor.d.ts.map +1 -0
- package/lib/browser/code-completion-postprocessor.js +49 -0
- package/lib/browser/code-completion-postprocessor.js.map +1 -0
- package/lib/browser/code-completion-postprocessor.spec.d.ts +2 -0
- package/lib/browser/code-completion-postprocessor.spec.d.ts.map +1 -0
- package/lib/browser/code-completion-postprocessor.spec.js +73 -0
- package/lib/browser/code-completion-postprocessor.spec.js.map +1 -0
- package/package.json +9 -9
- package/src/browser/ai-code-completion-frontend-module.ts +7 -3
- package/src/browser/ai-code-completion-preference.ts +22 -3
- package/src/browser/ai-code-frontend-application-contribution.ts +19 -9
- package/src/browser/ai-code-inline-completion-provider.ts +1 -1
- package/src/browser/code-completion-agent.ts +233 -0
- package/src/browser/code-completion-postprocessor.spec.ts +84 -0
- package/src/browser/code-completion-postprocessor.ts +48 -0
- package/lib/common/code-completion-agent.d.ts.map +0 -1
- package/lib/common/code-completion-agent.js +0 -150
- package/lib/common/code-completion-agent.js.map +0 -1
- package/src/common/code-completion-agent.ts +0 -164
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CodeCompletionAgentImpl = exports.CodeCompletionAgent = void 0;
|
|
19
|
-
const tslib_1 = require("tslib");
|
|
20
|
-
const common_1 = require("@theia/ai-core/lib/common");
|
|
21
|
-
const core_1 = require("@theia/core");
|
|
22
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
23
|
-
exports.CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
24
|
-
let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
|
|
25
|
-
constructor() {
|
|
26
|
-
this.id = 'Code Completion';
|
|
27
|
-
this.name = 'Code Completion';
|
|
28
|
-
this.description = 'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
29
|
-
this.promptTemplates = [
|
|
30
|
-
{
|
|
31
|
-
id: 'code-completion-prompt',
|
|
32
|
-
template: `You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
33
|
-
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
34
|
-
Finish the following code snippet.
|
|
35
|
-
|
|
36
|
-
{{textUntilCurrentPosition}}[[MARKER]]{{textAfterCurrentPosition}}
|
|
37
|
-
|
|
38
|
-
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
this.languageModelRequirements = [
|
|
42
|
-
{
|
|
43
|
-
purpose: 'code-completion',
|
|
44
|
-
identifier: 'openai/gpt-4o',
|
|
45
|
-
},
|
|
46
|
-
];
|
|
47
|
-
this.variables = [];
|
|
48
|
-
this.functions = [];
|
|
49
|
-
this.agentSpecificVariables = [
|
|
50
|
-
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
51
|
-
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
52
|
-
{ name: 'textUntilCurrentPosition', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
53
|
-
{ name: 'textAfterCurrentPosition', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
54
|
-
];
|
|
55
|
-
}
|
|
56
|
-
async provideInlineCompletions(model, position, context, token) {
|
|
57
|
-
const languageModel = await this.languageModelRegistry.selectLanguageModel({
|
|
58
|
-
agent: this.id,
|
|
59
|
-
...this.languageModelRequirements[0],
|
|
60
|
-
});
|
|
61
|
-
if (!languageModel) {
|
|
62
|
-
this.logger.error('No language model found for code-completion-agent');
|
|
63
|
-
return undefined;
|
|
64
|
-
}
|
|
65
|
-
// Get text until the given position
|
|
66
|
-
const textUntilCurrentPosition = model.getValueInRange({
|
|
67
|
-
startLineNumber: 1,
|
|
68
|
-
startColumn: 1,
|
|
69
|
-
endLineNumber: position.lineNumber,
|
|
70
|
-
endColumn: position.column,
|
|
71
|
-
});
|
|
72
|
-
// Get text after the given position
|
|
73
|
-
const textAfterCurrentPosition = model.getValueInRange({
|
|
74
|
-
startLineNumber: position.lineNumber,
|
|
75
|
-
startColumn: position.column,
|
|
76
|
-
endLineNumber: model.getLineCount(),
|
|
77
|
-
endColumn: model.getLineMaxColumn(model.getLineCount()),
|
|
78
|
-
});
|
|
79
|
-
const file = model.uri.toString(false);
|
|
80
|
-
const language = model.getLanguageId();
|
|
81
|
-
if (token.isCancellationRequested) {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
const prompt = await this.promptService
|
|
85
|
-
.getPrompt('code-completion-prompt', { textUntilCurrentPosition, textAfterCurrentPosition, file, language })
|
|
86
|
-
.then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
87
|
-
if (!prompt) {
|
|
88
|
-
this.logger.error('No prompt found for code-completion-agent');
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
92
|
-
const sessionId = (0, core_1.generateUuid)();
|
|
93
|
-
const requestId = (0, core_1.generateUuid)();
|
|
94
|
-
const request = {
|
|
95
|
-
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
96
|
-
};
|
|
97
|
-
const requestEntry = {
|
|
98
|
-
agentId: this.id,
|
|
99
|
-
sessionId,
|
|
100
|
-
timestamp: Date.now(),
|
|
101
|
-
requestId,
|
|
102
|
-
request: prompt,
|
|
103
|
-
};
|
|
104
|
-
if (token.isCancellationRequested) {
|
|
105
|
-
return undefined;
|
|
106
|
-
}
|
|
107
|
-
this.recordingService.recordRequest(requestEntry);
|
|
108
|
-
const response = await languageModel.request(request, token);
|
|
109
|
-
if (token.isCancellationRequested) {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
const completionText = await (0, common_1.getTextOfResponse)(response);
|
|
113
|
-
if (token.isCancellationRequested) {
|
|
114
|
-
return undefined;
|
|
115
|
-
}
|
|
116
|
-
this.recordingService.recordResponse({
|
|
117
|
-
agentId: this.id,
|
|
118
|
-
sessionId,
|
|
119
|
-
timestamp: Date.now(),
|
|
120
|
-
requestId,
|
|
121
|
-
response: completionText,
|
|
122
|
-
});
|
|
123
|
-
return {
|
|
124
|
-
items: [{ insertText: completionText }],
|
|
125
|
-
enableForwardStability: true,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl;
|
|
130
|
-
tslib_1.__decorate([
|
|
131
|
-
(0, inversify_1.inject)(core_1.ILogger),
|
|
132
|
-
(0, inversify_1.named)('code-completion-agent'),
|
|
133
|
-
tslib_1.__metadata("design:type", Object)
|
|
134
|
-
], CodeCompletionAgentImpl.prototype, "logger", void 0);
|
|
135
|
-
tslib_1.__decorate([
|
|
136
|
-
(0, inversify_1.inject)(common_1.LanguageModelRegistry),
|
|
137
|
-
tslib_1.__metadata("design:type", Object)
|
|
138
|
-
], CodeCompletionAgentImpl.prototype, "languageModelRegistry", void 0);
|
|
139
|
-
tslib_1.__decorate([
|
|
140
|
-
(0, inversify_1.inject)(common_1.PromptService),
|
|
141
|
-
tslib_1.__metadata("design:type", Object)
|
|
142
|
-
], CodeCompletionAgentImpl.prototype, "promptService", void 0);
|
|
143
|
-
tslib_1.__decorate([
|
|
144
|
-
(0, inversify_1.inject)(common_1.CommunicationRecordingService),
|
|
145
|
-
tslib_1.__metadata("design:type", Object)
|
|
146
|
-
], CodeCompletionAgentImpl.prototype, "recordingService", void 0);
|
|
147
|
-
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl = tslib_1.__decorate([
|
|
148
|
-
(0, inversify_1.injectable)()
|
|
149
|
-
], CodeCompletionAgentImpl);
|
|
150
|
-
//# sourceMappingURL=code-completion-agent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":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EAAE,cAAc;SAC3B,CAAC,CAAC;QAEH,OAAO;YACH,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC;YACvC,sBAAsB,EAAE,IAAI;SAC/B,CAAC;IACN,CAAC;CA8CJ,CAAA;AApIY,0DAAuB;AA0FtB;IAFT,IAAA,kBAAM,EAAC,cAAO,CAAC;IACf,IAAA,iBAAK,EAAC,uBAAuB,CAAC;;uDACL;AAGhB;IADT,IAAA,kBAAM,EAAC,8BAAqB,CAAC;;sEACyB;AAG7C;IADT,IAAA,kBAAM,EAAC,sBAAa,CAAC;;8DACiB;AAG7B;IADT,IAAA,kBAAM,EAAC,sCAA6B,CAAC;;iEACoB;kCAnGjD,uBAAuB;IADnC,IAAA,sBAAU,GAAE;GACA,uBAAuB,CAoInC"}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2024 EclipseSource GmbH.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
Agent, AgentSpecificVariables, CommunicationHistoryEntry, CommunicationRecordingService, getTextOfResponse,
|
|
19
|
-
LanguageModelRegistry, LanguageModelRequest, LanguageModelRequirement, PromptService, PromptTemplate
|
|
20
|
-
} from '@theia/ai-core/lib/common';
|
|
21
|
-
import { generateUuid, ILogger } from '@theia/core';
|
|
22
|
-
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
23
|
-
import * as monaco from '@theia/monaco-editor-core';
|
|
24
|
-
|
|
25
|
-
export const CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
26
|
-
export interface CodeCompletionAgent extends Agent {
|
|
27
|
-
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position,
|
|
28
|
-
context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
@injectable()
|
|
32
|
-
export class CodeCompletionAgentImpl implements CodeCompletionAgent {
|
|
33
|
-
async provideInlineCompletions(
|
|
34
|
-
model: monaco.editor.ITextModel,
|
|
35
|
-
position: monaco.Position,
|
|
36
|
-
context: monaco.languages.InlineCompletionContext,
|
|
37
|
-
token: monaco.CancellationToken
|
|
38
|
-
): Promise<monaco.languages.InlineCompletions | undefined> {
|
|
39
|
-
const languageModel =
|
|
40
|
-
await this.languageModelRegistry.selectLanguageModel({
|
|
41
|
-
agent: this.id,
|
|
42
|
-
...this.languageModelRequirements[0],
|
|
43
|
-
});
|
|
44
|
-
if (!languageModel) {
|
|
45
|
-
this.logger.error(
|
|
46
|
-
'No language model found for code-completion-agent'
|
|
47
|
-
);
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Get text until the given position
|
|
52
|
-
const textUntilCurrentPosition = model.getValueInRange({
|
|
53
|
-
startLineNumber: 1,
|
|
54
|
-
startColumn: 1,
|
|
55
|
-
endLineNumber: position.lineNumber,
|
|
56
|
-
endColumn: position.column,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Get text after the given position
|
|
60
|
-
const textAfterCurrentPosition = model.getValueInRange({
|
|
61
|
-
startLineNumber: position.lineNumber,
|
|
62
|
-
startColumn: position.column,
|
|
63
|
-
endLineNumber: model.getLineCount(),
|
|
64
|
-
endColumn: model.getLineMaxColumn(model.getLineCount()),
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const file = model.uri.toString(false);
|
|
68
|
-
const language = model.getLanguageId();
|
|
69
|
-
|
|
70
|
-
if (token.isCancellationRequested) {
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
const prompt = await this.promptService
|
|
74
|
-
.getPrompt('code-completion-prompt', { textUntilCurrentPosition, textAfterCurrentPosition, file, language })
|
|
75
|
-
.then(p => p?.text);
|
|
76
|
-
if (!prompt) {
|
|
77
|
-
this.logger.error('No prompt found for code-completion-agent');
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
82
|
-
const sessionId = generateUuid();
|
|
83
|
-
const requestId = generateUuid();
|
|
84
|
-
const request: LanguageModelRequest = {
|
|
85
|
-
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
86
|
-
};
|
|
87
|
-
const requestEntry: CommunicationHistoryEntry = {
|
|
88
|
-
agentId: this.id,
|
|
89
|
-
sessionId,
|
|
90
|
-
timestamp: Date.now(),
|
|
91
|
-
requestId,
|
|
92
|
-
request: prompt,
|
|
93
|
-
};
|
|
94
|
-
if (token.isCancellationRequested) {
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
this.recordingService.recordRequest(requestEntry);
|
|
98
|
-
const response = await languageModel.request(request, token);
|
|
99
|
-
if (token.isCancellationRequested) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
const completionText = await getTextOfResponse(response);
|
|
103
|
-
if (token.isCancellationRequested) {
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
106
|
-
this.recordingService.recordResponse({
|
|
107
|
-
agentId: this.id,
|
|
108
|
-
sessionId,
|
|
109
|
-
timestamp: Date.now(),
|
|
110
|
-
requestId,
|
|
111
|
-
response: completionText,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
items: [{ insertText: completionText }],
|
|
116
|
-
enableForwardStability: true,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
@inject(ILogger)
|
|
121
|
-
@named('code-completion-agent')
|
|
122
|
-
protected logger: ILogger;
|
|
123
|
-
|
|
124
|
-
@inject(LanguageModelRegistry)
|
|
125
|
-
protected languageModelRegistry: LanguageModelRegistry;
|
|
126
|
-
|
|
127
|
-
@inject(PromptService)
|
|
128
|
-
protected promptService: PromptService;
|
|
129
|
-
|
|
130
|
-
@inject(CommunicationRecordingService)
|
|
131
|
-
protected recordingService: CommunicationRecordingService;
|
|
132
|
-
|
|
133
|
-
id = 'Code Completion';
|
|
134
|
-
name = 'Code Completion';
|
|
135
|
-
description =
|
|
136
|
-
'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
137
|
-
promptTemplates: PromptTemplate[] = [
|
|
138
|
-
{
|
|
139
|
-
id: 'code-completion-prompt',
|
|
140
|
-
template: `You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
141
|
-
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
142
|
-
Finish the following code snippet.
|
|
143
|
-
|
|
144
|
-
{{textUntilCurrentPosition}}[[MARKER]]{{textAfterCurrentPosition}}
|
|
145
|
-
|
|
146
|
-
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
147
|
-
},
|
|
148
|
-
];
|
|
149
|
-
languageModelRequirements: LanguageModelRequirement[] = [
|
|
150
|
-
{
|
|
151
|
-
purpose: 'code-completion',
|
|
152
|
-
identifier: 'openai/gpt-4o',
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
readonly variables: string[] = [];
|
|
156
|
-
readonly functions: string[] = [];
|
|
157
|
-
readonly agentSpecificVariables: AgentSpecificVariables[] = [
|
|
158
|
-
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
159
|
-
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
160
|
-
{ name: 'textUntilCurrentPosition', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
161
|
-
{ name: 'textAfterCurrentPosition', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
162
|
-
];
|
|
163
|
-
readonly tags?: String[] | undefined;
|
|
164
|
-
}
|