@theia/ai-code-completion 1.55.0-next.97 → 1.56.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-code-completion-frontend-module.js +1 -1
- package/lib/browser/ai-code-completion-frontend-module.js.map +1 -1
- package/lib/browser/ai-code-completion-preference.d.ts +1 -0
- package/lib/browser/ai-code-completion-preference.d.ts.map +1 -1
- package/lib/browser/ai-code-completion-preference.js +11 -2
- package/lib/browser/ai-code-completion-preference.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 +4 -1
- package/lib/browser/code-completion-agent.d.ts.map +1 -0
- package/lib/browser/code-completion-agent.js +181 -0
- package/lib/browser/code-completion-agent.js.map +1 -0
- package/package.json +8 -8
- package/src/browser/ai-code-completion-frontend-module.ts +1 -1
- package/src/browser/ai-code-completion-preference.ts +10 -1
- package/src/browser/ai-code-inline-completion-provider.ts +1 -1
- package/src/browser/code-completion-agent.ts +204 -0
- package/lib/common/code-completion-agent.d.ts.map +0 -1
- package/lib/common/code-completion-agent.js +0 -149
- package/lib/common/code-completion-agent.js.map +0 -1
- package/src/common/code-completion-agent.ts +0 -163
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
const core_1 = require("@theia/core");
|
|
19
19
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
20
|
-
const code_completion_agent_1 = require("
|
|
20
|
+
const code_completion_agent_1 = require("./code-completion-agent");
|
|
21
21
|
const ai_code_frontend_application_contribution_1 = require("./ai-code-frontend-application-contribution");
|
|
22
22
|
const browser_1 = require("@theia/core/lib/browser");
|
|
23
23
|
const ai_core_1 = require("@theia/ai-core");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-completion-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,sCAAsC;AACtC,4DAA+D;AAC/D,
|
|
1
|
+
{"version":3,"file":"ai-code-completion-frontend-module.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,sCAAsC;AACtC,4DAA+D;AAC/D,mEAAuF;AACvF,2GAAgG;AAChG,qDAA0H;AAC1H,4CAAuC;AACvC,mFAAoF;AACpF,6FAAuF;AAEvF,kBAAe,IAAI,2BAAe,CAAC,IAAI,CAAC,EAAE;IACtC,IAAI,CAAC,cAAO,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;QAC/B,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAU,cAAO,CAAC,CAAC;QACzD,OAAO,YAAY,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,eAAe,CAAC,uBAAuB,CAAC,CAAC;IAC/D,IAAI,CAAC,+CAAuB,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAC1D,IAAI,CAAC,2CAAmB,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC7D,IAAI,CAAC,eAAK,CAAC,CAAC,SAAS,CAAC,+CAAuB,CAAC,CAAC;IAC/C,IAAI,CAAC,oEAA+B,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IAClE,IAAI,CAAC,6EAAiC,CAAC,CAAC,MAAM,EAAE,CAAC,gBAAgB,EAAE,CAAC;IACpE,IAAI,CAAC,yCAA+B,CAAC,CAAC,EAAE,CAAC,6EAAiC,CAAC,CAAC;IAC5E,IAAI,CAAC,gCAAsB,CAAC,CAAC,SAAS,CAAC,6EAAiC,CAAC,CAAC;IAC1E,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,iEAAiC,EAAE,CAAC,CAAC;AAChG,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
|
|
2
2
|
export declare const PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = "ai-features.codeCompletion.automaticCodeCompletion";
|
|
3
3
|
export declare const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = "ai-features.codeCompletion.excludedFileExtensions";
|
|
4
|
+
export declare const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = "ai-features.codeCompletion.maxContextLines";
|
|
4
5
|
export declare const AICodeCompletionPreferencesSchema: PreferenceSchema;
|
|
5
6
|
//# sourceMappingURL=ai-code-completion-preference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-completion-preference.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,0CAA0C,uDAAuD,CAAC;AAC/G,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAG/F,eAAO,MAAM,0CAA0C,uDAAuD,CAAC;AAC/G,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;AACjH,eAAO,MAAM,2CAA2C,+CAA+C,CAAC;AAExG,eAAO,MAAM,iCAAiC,EAAE,gBA6B/C,CAAC"}
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AICodeCompletionPreferencesSchema = exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = void 0;
|
|
18
|
+
exports.AICodeCompletionPreferencesSchema = exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = void 0;
|
|
19
19
|
const ai_core_preferences_1 = require("@theia/ai-core/lib/browser/ai-core-preferences");
|
|
20
20
|
exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = 'ai-features.codeCompletion.automaticCodeCompletion';
|
|
21
21
|
exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
22
|
+
exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
22
23
|
exports.AICodeCompletionPreferencesSchema = {
|
|
23
24
|
type: 'object',
|
|
24
25
|
properties: {
|
|
@@ -28,7 +29,7 @@ exports.AICodeCompletionPreferencesSchema = {
|
|
|
28
29
|
description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
|
|
29
30
|
\n\
|
|
30
31
|
Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
|
|
31
|
-
default:
|
|
32
|
+
default: false
|
|
32
33
|
},
|
|
33
34
|
[exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
|
|
34
35
|
title: 'Excluded File Extensions',
|
|
@@ -38,6 +39,14 @@ exports.AICodeCompletionPreferencesSchema = {
|
|
|
38
39
|
type: 'string'
|
|
39
40
|
},
|
|
40
41
|
default: []
|
|
42
|
+
},
|
|
43
|
+
[exports.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES]: {
|
|
44
|
+
title: 'Maximum Context Lines',
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'The maximum number of lines used as context, distributed among the lines before and after the cursor position (prefix and suffix).\
|
|
47
|
+
Set this to -1 to use the full file as context without any line limit and 0 to only use the current line.',
|
|
48
|
+
default: -1,
|
|
49
|
+
minimum: -1
|
|
41
50
|
}
|
|
42
51
|
}
|
|
43
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-completion-preference.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAGhF,wFAA2F;AAE9E,QAAA,0CAA0C,GAAG,oDAAoD,CAAC;AAClG,QAAA,6CAA6C,GAAG,mDAAmD,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-code-completion-preference.js","sourceRoot":"","sources":["../../src/browser/ai-code-completion-preference.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAGhF,wFAA2F;AAE9E,QAAA,0CAA0C,GAAG,oDAAoD,CAAC;AAClG,QAAA,6CAA6C,GAAG,mDAAmD,CAAC;AACpG,QAAA,2CAA2C,GAAG,4CAA4C,CAAC;AAE3F,QAAA,iCAAiC,GAAqB;IAC/D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,kDAA0C,CAAC,EAAE;YAC1C,KAAK,EAAE,+CAAyB;YAChC,IAAI,EAAE,SAAS;YACf,WAAW,EAAE;;gJAEuH;YACpI,OAAO,EAAE,KAAK;SACjB;QACD,CAAC,qDAA6C,CAAC,EAAE;YAC7C,KAAK,EAAE,0BAA0B;YACjC,IAAI,EAAE,OAAO;YACb,WAAW,EAAE,oFAAoF;YACjG,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;aACjB;YACD,OAAO,EAAE,EAAE;SACd;QACD,CAAC,mDAA2C,CAAC,EAAE;YAC3C,KAAK,EAAE,uBAAuB;YAC9B,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE;sHAC6F;YAC1G,OAAO,EAAE,CAAC,CAAC;YACX,OAAO,EAAE,CAAC,CAAC;SACd;KACJ;CACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as monaco from '@theia/monaco-editor-core';
|
|
2
|
-
import { CodeCompletionAgent } from '
|
|
2
|
+
import { CodeCompletionAgent } from './code-completion-agent';
|
|
3
3
|
export declare class AICodeInlineCompletionsProvider implements monaco.languages.InlineCompletionsProvider {
|
|
4
4
|
protected readonly agent: CodeCompletionAgent;
|
|
5
5
|
private readonly agentService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-inline-completion-provider.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ai-code-inline-completion-provider.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAGpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAG9D,qBACa,+BACT,YAAW,MAAM,CAAC,SAAS,CAAC,yBAAyB;IAErD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;IAEtC,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAY1D,qBAAqB,CACjB,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,GACnF,IAAI;CAGV"}
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.AICodeInlineCompletionsProvider = void 0;
|
|
19
19
|
const tslib_1 = require("tslib");
|
|
20
20
|
const inversify_1 = require("@theia/core/shared/inversify");
|
|
21
|
-
const code_completion_agent_1 = require("
|
|
21
|
+
const code_completion_agent_1 = require("./code-completion-agent");
|
|
22
22
|
const ai_core_1 = require("@theia/ai-core");
|
|
23
23
|
let AICodeInlineCompletionsProvider = class AICodeInlineCompletionsProvider {
|
|
24
24
|
async provideInlineCompletions(model, position, context, token) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-code-inline-completion-provider.js","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAIhF,4DAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"ai-code-inline-completion-provider.js","sourceRoot":"","sources":["../../src/browser/ai-code-inline-completion-provider.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAIhF,4DAAkE;AAClE,mEAA8D;AAC9D,4CAA8C;AAGvC,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IAOxC,KAAK,CAAC,wBAAwB,CAC1B,KAA+B,EAC/B,QAAyB,EACzB,OAAiD,EACjD,KAA+B;QAE/B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YAC9C,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CACtC,KAAK,EACL,QAAQ,EACR,OAAO,EACP,KAAK,CACR,CAAC;IACN,CAAC;IAED,qBAAqB,CACjB,WAAkF;QAElF,gBAAgB;IACpB,CAAC;CACJ,CAAA;AA7BY,0EAA+B;AAGrB;IADlB,IAAA,kBAAM,EAAC,2CAAmB,CAAC;;8DACkB;AAE7B;IADhB,IAAA,kBAAM,EAAC,sBAAY,CAAC;;qEACuB;0CALnC,+BAA+B;IAD3C,IAAA,sBAAU,GAAE;GACA,+BAA+B,CA6B3C"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Agent, AgentSpecificVariables, CommunicationRecordingService, LanguageModelRegistry, LanguageModelRequirement, PromptService, PromptTemplate } from '@theia/ai-core/lib/common';
|
|
2
|
-
import { ILogger } from '@theia/core';
|
|
2
|
+
import { ILogger, ProgressService } from '@theia/core';
|
|
3
3
|
import * as monaco from '@theia/monaco-editor-core';
|
|
4
|
+
import { PreferenceService } from '@theia/core/lib/browser';
|
|
4
5
|
export declare const CodeCompletionAgent: unique symbol;
|
|
5
6
|
export interface CodeCompletionAgent extends Agent {
|
|
6
7
|
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position, context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>;
|
|
@@ -11,6 +12,8 @@ export declare class CodeCompletionAgentImpl implements CodeCompletionAgent {
|
|
|
11
12
|
protected languageModelRegistry: LanguageModelRegistry;
|
|
12
13
|
protected promptService: PromptService;
|
|
13
14
|
protected recordingService: CommunicationRecordingService;
|
|
15
|
+
protected progressService: ProgressService;
|
|
16
|
+
protected preferences: PreferenceService;
|
|
14
17
|
id: string;
|
|
15
18
|
name: string;
|
|
16
19
|
description: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-completion-agent.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,EAAE,sBAAsB,EAAE,6BAA6B,EAC5D,qBAAqB,EAAwB,wBAAwB,EAAE,aAAa,EAAE,cAAc,EACvG,MAAM,2B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IACF,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAKvD;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACxC"}
|
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
|
|
24
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
25
|
+
exports.CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
26
|
+
let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.id = 'Code Completion';
|
|
29
|
+
this.name = 'Code Completion';
|
|
30
|
+
this.description = 'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
31
|
+
this.promptTemplates = [
|
|
32
|
+
{
|
|
33
|
+
id: 'code-completion-prompt',
|
|
34
|
+
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
35
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
36
|
+
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
37
|
+
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
38
|
+
Finish the following code snippet.
|
|
39
|
+
|
|
40
|
+
{{prefix}}[[MARKER]]{{suffix}}
|
|
41
|
+
|
|
42
|
+
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
this.languageModelRequirements = [
|
|
46
|
+
{
|
|
47
|
+
purpose: 'code-completion',
|
|
48
|
+
identifier: 'openai/gpt-4o',
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
this.variables = [];
|
|
52
|
+
this.functions = [];
|
|
53
|
+
this.agentSpecificVariables = [
|
|
54
|
+
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
55
|
+
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
56
|
+
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
57
|
+
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
async provideInlineCompletions(model, position, context, token) {
|
|
61
|
+
const progress = await this.progressService.showProgress({ text: 'Calculating AI code completion...', options: { location: 'window' } });
|
|
62
|
+
try {
|
|
63
|
+
const languageModel = await this.languageModelRegistry.selectLanguageModel({
|
|
64
|
+
agent: this.id,
|
|
65
|
+
...this.languageModelRequirements[0],
|
|
66
|
+
});
|
|
67
|
+
if (!languageModel) {
|
|
68
|
+
this.logger.error('No language model found for code-completion-agent');
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const maxContextLines = this.preferences.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES, -1);
|
|
72
|
+
let prefixStartLine = 1;
|
|
73
|
+
let suffixEndLine = model.getLineCount();
|
|
74
|
+
// if maxContextLines is -1, use the full file as context without any line limit
|
|
75
|
+
if (maxContextLines === 0) {
|
|
76
|
+
// Only the cursor line
|
|
77
|
+
prefixStartLine = position.lineNumber;
|
|
78
|
+
suffixEndLine = position.lineNumber;
|
|
79
|
+
}
|
|
80
|
+
else if (maxContextLines > 0) {
|
|
81
|
+
const linesBeforeCursor = position.lineNumber - 1;
|
|
82
|
+
const linesAfterCursor = model.getLineCount() - position.lineNumber;
|
|
83
|
+
// Allocate one more line to the prefix in case of an odd maxContextLines
|
|
84
|
+
const prefixLines = Math.min(Math.ceil(maxContextLines / 2), linesBeforeCursor);
|
|
85
|
+
const suffixLines = Math.min(Math.floor(maxContextLines / 2), linesAfterCursor);
|
|
86
|
+
prefixStartLine = Math.max(1, position.lineNumber - prefixLines);
|
|
87
|
+
suffixEndLine = Math.min(model.getLineCount(), position.lineNumber + suffixLines);
|
|
88
|
+
}
|
|
89
|
+
const prefix = model.getValueInRange({
|
|
90
|
+
startLineNumber: prefixStartLine,
|
|
91
|
+
startColumn: 1,
|
|
92
|
+
endLineNumber: position.lineNumber,
|
|
93
|
+
endColumn: position.column,
|
|
94
|
+
});
|
|
95
|
+
const suffix = model.getValueInRange({
|
|
96
|
+
startLineNumber: position.lineNumber,
|
|
97
|
+
startColumn: position.column,
|
|
98
|
+
endLineNumber: suffixEndLine,
|
|
99
|
+
endColumn: model.getLineMaxColumn(suffixEndLine),
|
|
100
|
+
});
|
|
101
|
+
const file = model.uri.toString(false);
|
|
102
|
+
const language = model.getLanguageId();
|
|
103
|
+
if (token.isCancellationRequested) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
const prompt = await this.promptService
|
|
107
|
+
.getPrompt('code-completion-prompt', { prefix, suffix, file, language })
|
|
108
|
+
.then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
109
|
+
if (!prompt) {
|
|
110
|
+
this.logger.error('No prompt found for code-completion-agent');
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
114
|
+
const sessionId = (0, core_1.generateUuid)();
|
|
115
|
+
const requestId = (0, core_1.generateUuid)();
|
|
116
|
+
const request = {
|
|
117
|
+
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
118
|
+
};
|
|
119
|
+
if (token.isCancellationRequested) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
this.recordingService.recordRequest({
|
|
123
|
+
agentId: this.id,
|
|
124
|
+
sessionId,
|
|
125
|
+
requestId,
|
|
126
|
+
request: prompt,
|
|
127
|
+
});
|
|
128
|
+
const response = await languageModel.request(request, token);
|
|
129
|
+
if (token.isCancellationRequested) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const completionText = await (0, common_1.getTextOfResponse)(response);
|
|
133
|
+
if (token.isCancellationRequested) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
this.recordingService.recordResponse({
|
|
137
|
+
agentId: this.id,
|
|
138
|
+
sessionId,
|
|
139
|
+
requestId,
|
|
140
|
+
response: completionText,
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
items: [{ insertText: completionText }],
|
|
144
|
+
enableForwardStability: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
progress.cancel();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl;
|
|
153
|
+
tslib_1.__decorate([
|
|
154
|
+
(0, inversify_1.inject)(core_1.ILogger),
|
|
155
|
+
(0, inversify_1.named)('code-completion-agent'),
|
|
156
|
+
tslib_1.__metadata("design:type", Object)
|
|
157
|
+
], CodeCompletionAgentImpl.prototype, "logger", void 0);
|
|
158
|
+
tslib_1.__decorate([
|
|
159
|
+
(0, inversify_1.inject)(common_1.LanguageModelRegistry),
|
|
160
|
+
tslib_1.__metadata("design:type", Object)
|
|
161
|
+
], CodeCompletionAgentImpl.prototype, "languageModelRegistry", void 0);
|
|
162
|
+
tslib_1.__decorate([
|
|
163
|
+
(0, inversify_1.inject)(common_1.PromptService),
|
|
164
|
+
tslib_1.__metadata("design:type", Object)
|
|
165
|
+
], CodeCompletionAgentImpl.prototype, "promptService", void 0);
|
|
166
|
+
tslib_1.__decorate([
|
|
167
|
+
(0, inversify_1.inject)(common_1.CommunicationRecordingService),
|
|
168
|
+
tslib_1.__metadata("design:type", Object)
|
|
169
|
+
], CodeCompletionAgentImpl.prototype, "recordingService", void 0);
|
|
170
|
+
tslib_1.__decorate([
|
|
171
|
+
(0, inversify_1.inject)(core_1.ProgressService),
|
|
172
|
+
tslib_1.__metadata("design:type", core_1.ProgressService)
|
|
173
|
+
], CodeCompletionAgentImpl.prototype, "progressService", void 0);
|
|
174
|
+
tslib_1.__decorate([
|
|
175
|
+
(0, inversify_1.inject)(browser_1.PreferenceService),
|
|
176
|
+
tslib_1.__metadata("design:type", Object)
|
|
177
|
+
], CodeCompletionAgentImpl.prototype, "preferences", void 0);
|
|
178
|
+
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl = tslib_1.__decorate([
|
|
179
|
+
(0, inversify_1.injectable)()
|
|
180
|
+
], CodeCompletionAgentImpl);
|
|
181
|
+
//# sourceMappingURL=code-completion-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-completion-agent.js","sourceRoot":"","sources":["../../src/browser/code-completion-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC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,CAAA;AA1KY,0DAAuB;AAwHtB;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;AAGhD;IADT,IAAA,kBAAM,EAAC,sBAAe,CAAC;sCACG,sBAAe;gEAAC;AAGjC;IADT,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;4DACe;kCAvIhC,uBAAuB;IADnC,IAAA,sBAAU,GAAE;GACA,uBAAuB,CA0KnC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/ai-code-completion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.56.0",
|
|
4
4
|
"description": "Theia - AI Core",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@theia/ai-core": "1.
|
|
7
|
-
"@theia/core": "1.
|
|
8
|
-
"@theia/filesystem": "1.
|
|
6
|
+
"@theia/ai-core": "1.56.0",
|
|
7
|
+
"@theia/core": "1.56.0",
|
|
8
|
+
"@theia/filesystem": "1.56.0",
|
|
9
9
|
"@theia/monaco-editor-core": "1.83.101",
|
|
10
|
-
"@theia/output": "1.
|
|
11
|
-
"@theia/workspace": "1.
|
|
10
|
+
"@theia/output": "1.56.0",
|
|
11
|
+
"@theia/workspace": "1.56.0",
|
|
12
12
|
"minimatch": "^5.1.0",
|
|
13
13
|
"tslib": "^2.6.2"
|
|
14
14
|
},
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"watch": "theiaext watch"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@theia/ext-scripts": "1.
|
|
49
|
+
"@theia/ext-scripts": "1.56.0"
|
|
50
50
|
},
|
|
51
51
|
"nyc": {
|
|
52
52
|
"extends": "../../configs/nyc.json"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "3b4498f8f1c66be688847418fcc35595282671dc"
|
|
55
55
|
}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import { ILogger } from '@theia/core';
|
|
18
18
|
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
19
|
-
import { CodeCompletionAgent, CodeCompletionAgentImpl } from '
|
|
19
|
+
import { CodeCompletionAgent, CodeCompletionAgentImpl } from './code-completion-agent';
|
|
20
20
|
import { AIFrontendApplicationContribution } from './ai-code-frontend-application-contribution';
|
|
21
21
|
import { FrontendApplicationContribution, KeybindingContribution, PreferenceContribution } from '@theia/core/lib/browser';
|
|
22
22
|
import { Agent } from '@theia/ai-core';
|
|
@@ -19,6 +19,7 @@ import { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-pr
|
|
|
19
19
|
|
|
20
20
|
export const PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE = 'ai-features.codeCompletion.automaticCodeCompletion';
|
|
21
21
|
export const PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS = 'ai-features.codeCompletion.excludedFileExtensions';
|
|
22
|
+
export const PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES = 'ai-features.codeCompletion.maxContextLines';
|
|
22
23
|
|
|
23
24
|
export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
24
25
|
type: 'object',
|
|
@@ -29,7 +30,7 @@ export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
|
29
30
|
description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
|
|
30
31
|
\n\
|
|
31
32
|
Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
|
|
32
|
-
default:
|
|
33
|
+
default: false
|
|
33
34
|
},
|
|
34
35
|
[PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
|
|
35
36
|
title: 'Excluded File Extensions',
|
|
@@ -39,6 +40,14 @@ export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
|
|
|
39
40
|
type: 'string'
|
|
40
41
|
},
|
|
41
42
|
default: []
|
|
43
|
+
},
|
|
44
|
+
[PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES]: {
|
|
45
|
+
title: 'Maximum Context Lines',
|
|
46
|
+
type: 'number',
|
|
47
|
+
description: 'The maximum number of lines used as context, distributed among the lines before and after the cursor position (prefix and suffix).\
|
|
48
|
+
Set this to -1 to use the full file as context without any line limit and 0 to only use the current line.',
|
|
49
|
+
default: -1,
|
|
50
|
+
minimum: -1
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
};
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import * as monaco from '@theia/monaco-editor-core';
|
|
18
18
|
|
|
19
19
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
|
20
|
-
import { CodeCompletionAgent } from '
|
|
20
|
+
import { CodeCompletionAgent } from './code-completion-agent';
|
|
21
21
|
import { AgentService } from '@theia/ai-core';
|
|
22
22
|
|
|
23
23
|
@injectable()
|
|
@@ -0,0 +1,204 @@
|
|
|
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, CommunicationRecordingService, getTextOfResponse,
|
|
19
|
+
LanguageModelRegistry, LanguageModelRequest, LanguageModelRequirement, PromptService, PromptTemplate
|
|
20
|
+
} from '@theia/ai-core/lib/common';
|
|
21
|
+
import { generateUuid, ILogger, ProgressService } from '@theia/core';
|
|
22
|
+
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
|
23
|
+
import * as monaco from '@theia/monaco-editor-core';
|
|
24
|
+
import { PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES } from './ai-code-completion-preference';
|
|
25
|
+
import { PreferenceService } from '@theia/core/lib/browser';
|
|
26
|
+
|
|
27
|
+
export const CodeCompletionAgent = Symbol('CodeCompletionAgent');
|
|
28
|
+
export interface CodeCompletionAgent extends Agent {
|
|
29
|
+
provideInlineCompletions(model: monaco.editor.ITextModel, position: monaco.Position,
|
|
30
|
+
context: monaco.languages.InlineCompletionContext, token: monaco.CancellationToken): Promise<monaco.languages.InlineCompletions | undefined>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@injectable()
|
|
34
|
+
export class CodeCompletionAgentImpl implements CodeCompletionAgent {
|
|
35
|
+
async provideInlineCompletions(
|
|
36
|
+
model: monaco.editor.ITextModel,
|
|
37
|
+
position: monaco.Position,
|
|
38
|
+
context: monaco.languages.InlineCompletionContext,
|
|
39
|
+
token: monaco.CancellationToken
|
|
40
|
+
): Promise<monaco.languages.InlineCompletions | undefined> {
|
|
41
|
+
const progress = await this.progressService.showProgress(
|
|
42
|
+
{ text: 'Calculating AI code completion...', options: { location: 'window' } }
|
|
43
|
+
);
|
|
44
|
+
try {
|
|
45
|
+
const languageModel =
|
|
46
|
+
await this.languageModelRegistry.selectLanguageModel({
|
|
47
|
+
agent: this.id,
|
|
48
|
+
...this.languageModelRequirements[0],
|
|
49
|
+
});
|
|
50
|
+
if (!languageModel) {
|
|
51
|
+
this.logger.error(
|
|
52
|
+
'No language model found for code-completion-agent'
|
|
53
|
+
);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const maxContextLines = this.preferences.get<number>(PREF_AI_INLINE_COMPLETION_MAX_CONTEXT_LINES, -1);
|
|
58
|
+
|
|
59
|
+
let prefixStartLine = 1;
|
|
60
|
+
let suffixEndLine = model.getLineCount();
|
|
61
|
+
// if maxContextLines is -1, use the full file as context without any line limit
|
|
62
|
+
|
|
63
|
+
if (maxContextLines === 0) {
|
|
64
|
+
// Only the cursor line
|
|
65
|
+
prefixStartLine = position.lineNumber;
|
|
66
|
+
suffixEndLine = position.lineNumber;
|
|
67
|
+
} else if (maxContextLines > 0) {
|
|
68
|
+
const linesBeforeCursor = position.lineNumber - 1;
|
|
69
|
+
const linesAfterCursor = model.getLineCount() - position.lineNumber;
|
|
70
|
+
|
|
71
|
+
// Allocate one more line to the prefix in case of an odd maxContextLines
|
|
72
|
+
const prefixLines = Math.min(
|
|
73
|
+
Math.ceil(maxContextLines / 2),
|
|
74
|
+
linesBeforeCursor
|
|
75
|
+
);
|
|
76
|
+
const suffixLines = Math.min(
|
|
77
|
+
Math.floor(maxContextLines / 2),
|
|
78
|
+
linesAfterCursor
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
prefixStartLine = Math.max(1, position.lineNumber - prefixLines);
|
|
82
|
+
suffixEndLine = Math.min(model.getLineCount(), position.lineNumber + suffixLines);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const prefix = model.getValueInRange({
|
|
86
|
+
startLineNumber: prefixStartLine,
|
|
87
|
+
startColumn: 1,
|
|
88
|
+
endLineNumber: position.lineNumber,
|
|
89
|
+
endColumn: position.column,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const suffix = model.getValueInRange({
|
|
93
|
+
startLineNumber: position.lineNumber,
|
|
94
|
+
startColumn: position.column,
|
|
95
|
+
endLineNumber: suffixEndLine,
|
|
96
|
+
endColumn: model.getLineMaxColumn(suffixEndLine),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const file = model.uri.toString(false);
|
|
100
|
+
const language = model.getLanguageId();
|
|
101
|
+
|
|
102
|
+
if (token.isCancellationRequested) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
const prompt = await this.promptService
|
|
106
|
+
.getPrompt('code-completion-prompt', { prefix, suffix, file, language })
|
|
107
|
+
.then(p => p?.text);
|
|
108
|
+
if (!prompt) {
|
|
109
|
+
this.logger.error('No prompt found for code-completion-agent');
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
114
|
+
const sessionId = generateUuid();
|
|
115
|
+
const requestId = generateUuid();
|
|
116
|
+
const request: LanguageModelRequest = {
|
|
117
|
+
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
118
|
+
};
|
|
119
|
+
if (token.isCancellationRequested) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
this.recordingService.recordRequest({
|
|
123
|
+
agentId: this.id,
|
|
124
|
+
sessionId,
|
|
125
|
+
requestId,
|
|
126
|
+
request: prompt,
|
|
127
|
+
});
|
|
128
|
+
const response = await languageModel.request(request, token);
|
|
129
|
+
if (token.isCancellationRequested) {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const completionText = await getTextOfResponse(response);
|
|
133
|
+
if (token.isCancellationRequested) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
this.recordingService.recordResponse({
|
|
137
|
+
agentId: this.id,
|
|
138
|
+
sessionId,
|
|
139
|
+
requestId,
|
|
140
|
+
response: completionText,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
items: [{ insertText: completionText }],
|
|
145
|
+
enableForwardStability: true,
|
|
146
|
+
};
|
|
147
|
+
} finally {
|
|
148
|
+
progress.cancel();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@inject(ILogger)
|
|
153
|
+
@named('code-completion-agent')
|
|
154
|
+
protected logger: ILogger;
|
|
155
|
+
|
|
156
|
+
@inject(LanguageModelRegistry)
|
|
157
|
+
protected languageModelRegistry: LanguageModelRegistry;
|
|
158
|
+
|
|
159
|
+
@inject(PromptService)
|
|
160
|
+
protected promptService: PromptService;
|
|
161
|
+
|
|
162
|
+
@inject(CommunicationRecordingService)
|
|
163
|
+
protected recordingService: CommunicationRecordingService;
|
|
164
|
+
|
|
165
|
+
@inject(ProgressService)
|
|
166
|
+
protected progressService: ProgressService;
|
|
167
|
+
|
|
168
|
+
@inject(PreferenceService)
|
|
169
|
+
protected preferences: PreferenceService;
|
|
170
|
+
|
|
171
|
+
id = 'Code Completion';
|
|
172
|
+
name = 'Code Completion';
|
|
173
|
+
description =
|
|
174
|
+
'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
175
|
+
promptTemplates: PromptTemplate[] = [
|
|
176
|
+
{
|
|
177
|
+
id: 'code-completion-prompt',
|
|
178
|
+
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
179
|
+
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
180
|
+
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
181
|
+
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
182
|
+
Finish the following code snippet.
|
|
183
|
+
|
|
184
|
+
{{prefix}}[[MARKER]]{{suffix}}
|
|
185
|
+
|
|
186
|
+
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
187
|
+
},
|
|
188
|
+
];
|
|
189
|
+
languageModelRequirements: LanguageModelRequirement[] = [
|
|
190
|
+
{
|
|
191
|
+
purpose: 'code-completion',
|
|
192
|
+
identifier: 'openai/gpt-4o',
|
|
193
|
+
},
|
|
194
|
+
];
|
|
195
|
+
readonly variables: string[] = [];
|
|
196
|
+
readonly functions: string[] = [];
|
|
197
|
+
readonly agentSpecificVariables: AgentSpecificVariables[] = [
|
|
198
|
+
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
199
|
+
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
200
|
+
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
201
|
+
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
202
|
+
];
|
|
203
|
+
readonly tags?: string[] | undefined;
|
|
204
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-completion-agent.d.ts","sourceRoot":"","sources":["../../src/common/code-completion-agent.ts"],"names":[],"mappings":"AAgBA,OAAO,EACH,KAAK,EAAE,sBAAsB,EAAE,6BAA6B,EAC5D,qBAAqB,EAAwB,wBAAwB,EAAE,aAAa,EAAE,cAAc,EACvG,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAgB,OAAO,EAAE,MAAM,aAAa,CAAC;AAEpD,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AACjE,MAAM,WAAW,mBAAoB,SAAQ,KAAK;IAC9C,wBAAwB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAC/E,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EAAE,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAA;CACnJ;AAED,qBACa,uBAAwB,YAAW,mBAAmB;IACzD,wBAAwB,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EAC/B,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,uBAAuB,EACjD,KAAK,EAAE,MAAM,CAAC,iBAAiB,GAChC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,GAAG,SAAS,CAAC;IAiF1D,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;IAG1B,SAAS,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;IAGvD,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IAGvC,SAAS,CAAC,gBAAgB,EAAE,6BAA6B,CAAC;IAE1D,EAAE,SAAqB;IACvB,IAAI,SAAqB;IACzB,WAAW,SAC2E;IACtF,eAAe,EAAE,cAAc,EAAE,CAa/B;IACF,yBAAyB,EAAE,wBAAwB,EAAE,CAKnD;IACF,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAM;IAClC,QAAQ,CAAC,sBAAsB,EAAE,sBAAsB,EAAE,CAKvD;IACF,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CACxC"}
|
|
@@ -1,149 +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: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
33
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
34
|
-
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
35
|
-
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
36
|
-
Finish the following code snippet.
|
|
37
|
-
|
|
38
|
-
{{prefix}}[[MARKER]]{{suffix}}
|
|
39
|
-
|
|
40
|
-
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
this.languageModelRequirements = [
|
|
44
|
-
{
|
|
45
|
-
purpose: 'code-completion',
|
|
46
|
-
identifier: 'openai/gpt-4o',
|
|
47
|
-
},
|
|
48
|
-
];
|
|
49
|
-
this.variables = [];
|
|
50
|
-
this.functions = [];
|
|
51
|
-
this.agentSpecificVariables = [
|
|
52
|
-
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
53
|
-
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
54
|
-
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
55
|
-
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
async provideInlineCompletions(model, position, context, token) {
|
|
59
|
-
const languageModel = await this.languageModelRegistry.selectLanguageModel({
|
|
60
|
-
agent: this.id,
|
|
61
|
-
...this.languageModelRequirements[0],
|
|
62
|
-
});
|
|
63
|
-
if (!languageModel) {
|
|
64
|
-
this.logger.error('No language model found for code-completion-agent');
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
// Get text until the given position
|
|
68
|
-
const prefix = model.getValueInRange({
|
|
69
|
-
startLineNumber: 1,
|
|
70
|
-
startColumn: 1,
|
|
71
|
-
endLineNumber: position.lineNumber,
|
|
72
|
-
endColumn: position.column,
|
|
73
|
-
});
|
|
74
|
-
// Get text after the given position
|
|
75
|
-
const suffix = model.getValueInRange({
|
|
76
|
-
startLineNumber: position.lineNumber,
|
|
77
|
-
startColumn: position.column,
|
|
78
|
-
endLineNumber: model.getLineCount(),
|
|
79
|
-
endColumn: model.getLineMaxColumn(model.getLineCount()),
|
|
80
|
-
});
|
|
81
|
-
const file = model.uri.toString(false);
|
|
82
|
-
const language = model.getLanguageId();
|
|
83
|
-
if (token.isCancellationRequested) {
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
const prompt = await this.promptService
|
|
87
|
-
.getPrompt('code-completion-prompt', { prefix, suffix, file, language })
|
|
88
|
-
.then(p => p === null || p === void 0 ? void 0 : p.text);
|
|
89
|
-
if (!prompt) {
|
|
90
|
-
this.logger.error('No prompt found for code-completion-agent');
|
|
91
|
-
return undefined;
|
|
92
|
-
}
|
|
93
|
-
// since we do not actually hold complete conversions, the request/response pair is considered a session
|
|
94
|
-
const sessionId = (0, core_1.generateUuid)();
|
|
95
|
-
const requestId = (0, core_1.generateUuid)();
|
|
96
|
-
const request = {
|
|
97
|
-
messages: [{ type: 'text', actor: 'user', query: prompt }],
|
|
98
|
-
};
|
|
99
|
-
if (token.isCancellationRequested) {
|
|
100
|
-
return undefined;
|
|
101
|
-
}
|
|
102
|
-
this.recordingService.recordRequest({
|
|
103
|
-
agentId: this.id,
|
|
104
|
-
sessionId,
|
|
105
|
-
requestId,
|
|
106
|
-
request: prompt,
|
|
107
|
-
});
|
|
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
|
-
requestId,
|
|
120
|
-
response: completionText,
|
|
121
|
-
});
|
|
122
|
-
return {
|
|
123
|
-
items: [{ insertText: completionText }],
|
|
124
|
-
enableForwardStability: true,
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl;
|
|
129
|
-
tslib_1.__decorate([
|
|
130
|
-
(0, inversify_1.inject)(core_1.ILogger),
|
|
131
|
-
(0, inversify_1.named)('code-completion-agent'),
|
|
132
|
-
tslib_1.__metadata("design:type", Object)
|
|
133
|
-
], CodeCompletionAgentImpl.prototype, "logger", void 0);
|
|
134
|
-
tslib_1.__decorate([
|
|
135
|
-
(0, inversify_1.inject)(common_1.LanguageModelRegistry),
|
|
136
|
-
tslib_1.__metadata("design:type", Object)
|
|
137
|
-
], CodeCompletionAgentImpl.prototype, "languageModelRegistry", void 0);
|
|
138
|
-
tslib_1.__decorate([
|
|
139
|
-
(0, inversify_1.inject)(common_1.PromptService),
|
|
140
|
-
tslib_1.__metadata("design:type", Object)
|
|
141
|
-
], CodeCompletionAgentImpl.prototype, "promptService", void 0);
|
|
142
|
-
tslib_1.__decorate([
|
|
143
|
-
(0, inversify_1.inject)(common_1.CommunicationRecordingService),
|
|
144
|
-
tslib_1.__metadata("design:type", Object)
|
|
145
|
-
], CodeCompletionAgentImpl.prototype, "recordingService", void 0);
|
|
146
|
-
exports.CodeCompletionAgentImpl = CodeCompletionAgentImpl = tslib_1.__decorate([
|
|
147
|
-
(0, inversify_1.injectable)()
|
|
148
|
-
], CodeCompletionAgentImpl);
|
|
149
|
-
//# sourceMappingURL=code-completion-agent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"code-completion-agent.js","sourceRoot":"","sources":["../../src/common/code-completion-agent.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAEhF,sDAGmC;AACnC,sCAAoD;AACpD,4DAAyE;AAG5D,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAO1D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAA7B;QAkGH,OAAE,GAAG,iBAAiB,CAAC;QACvB,SAAI,GAAG,iBAAiB,CAAC;QACzB,gBAAW,GACP,iFAAiF,CAAC;QACtF,oBAAe,GAAqB;YAChC;gBACI,EAAE,EAAE,wBAAwB;gBAC5B,QAAQ,EAAE;;;;;;;;0EAQoD;aACjE;SACJ,CAAC;QACF,8BAAyB,GAA+B;YACpD;gBACI,OAAO,EAAE,iBAAiB;gBAC1B,UAAU,EAAE,eAAe;aAC9B;SACJ,CAAC;QACO,cAAS,GAAa,EAAE,CAAC;QACzB,cAAS,GAAa,EAAE,CAAC;QACzB,2BAAsB,GAA6B;YACxD,EAAE,IAAI,EAAE,MAAM,EAAE,YA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AAM,IAAA,0BAAiB,EAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,KAAK,CAAC,uBAAuB,EAAE,CAAC;YAChC,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC;YACjC,OAAO,EAAE,IAAI,CAAC,EAAE;YAChB,SAAS;YACT,SAAS;YACT,QAAQ,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;CAgDJ,CAAA;AAnIY,0DAAuB;AAuFtB;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;kCAhGjD,uBAAuB;IADnC,IAAA,sBAAU,GAAE;GACA,uBAAuB,CAmInC"}
|
|
@@ -1,163 +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, 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 prefix = 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 suffix = 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', { prefix, suffix, 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
|
-
if (token.isCancellationRequested) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
this.recordingService.recordRequest({
|
|
91
|
-
agentId: this.id,
|
|
92
|
-
sessionId,
|
|
93
|
-
requestId,
|
|
94
|
-
request: prompt,
|
|
95
|
-
});
|
|
96
|
-
const response = await languageModel.request(request, token);
|
|
97
|
-
if (token.isCancellationRequested) {
|
|
98
|
-
return undefined;
|
|
99
|
-
}
|
|
100
|
-
const completionText = await getTextOfResponse(response);
|
|
101
|
-
if (token.isCancellationRequested) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
this.recordingService.recordResponse({
|
|
105
|
-
agentId: this.id,
|
|
106
|
-
sessionId,
|
|
107
|
-
requestId,
|
|
108
|
-
response: completionText,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
items: [{ insertText: completionText }],
|
|
113
|
-
enableForwardStability: true,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
@inject(ILogger)
|
|
118
|
-
@named('code-completion-agent')
|
|
119
|
-
protected logger: ILogger;
|
|
120
|
-
|
|
121
|
-
@inject(LanguageModelRegistry)
|
|
122
|
-
protected languageModelRegistry: LanguageModelRegistry;
|
|
123
|
-
|
|
124
|
-
@inject(PromptService)
|
|
125
|
-
protected promptService: PromptService;
|
|
126
|
-
|
|
127
|
-
@inject(CommunicationRecordingService)
|
|
128
|
-
protected recordingService: CommunicationRecordingService;
|
|
129
|
-
|
|
130
|
-
id = 'Code Completion';
|
|
131
|
-
name = 'Code Completion';
|
|
132
|
-
description =
|
|
133
|
-
'This agent provides inline code completion in the code editor in the Theia IDE.';
|
|
134
|
-
promptTemplates: PromptTemplate[] = [
|
|
135
|
-
{
|
|
136
|
-
id: 'code-completion-prompt',
|
|
137
|
-
template: `{{!-- Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
|
|
138
|
-
https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
|
|
139
|
-
You are a code completion agent. The current file you have to complete is named {{file}}.
|
|
140
|
-
The language of the file is {{language}}. Return your result as plain text without markdown formatting.
|
|
141
|
-
Finish the following code snippet.
|
|
142
|
-
|
|
143
|
-
{{prefix}}[[MARKER]]{{suffix}}
|
|
144
|
-
|
|
145
|
-
Only return the exact replacement for [[MARKER]] to complete the snippet.`,
|
|
146
|
-
},
|
|
147
|
-
];
|
|
148
|
-
languageModelRequirements: LanguageModelRequirement[] = [
|
|
149
|
-
{
|
|
150
|
-
purpose: 'code-completion',
|
|
151
|
-
identifier: 'openai/gpt-4o',
|
|
152
|
-
},
|
|
153
|
-
];
|
|
154
|
-
readonly variables: string[] = [];
|
|
155
|
-
readonly functions: string[] = [];
|
|
156
|
-
readonly agentSpecificVariables: AgentSpecificVariables[] = [
|
|
157
|
-
{ name: 'file', usedInPrompt: true, description: 'The uri of the file being edited.' },
|
|
158
|
-
{ name: 'language', usedInPrompt: true, description: 'The languageId of the file being edited.' },
|
|
159
|
-
{ name: 'prefix', usedInPrompt: true, description: 'The code before the current position of the cursor.' },
|
|
160
|
-
{ name: 'suffix', usedInPrompt: true, description: 'The code after the current position of the cursor.' }
|
|
161
|
-
];
|
|
162
|
-
readonly tags?: string[] | undefined;
|
|
163
|
-
}
|