@theia/ai-code-completion 1.55.0 → 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.
Files changed (29) hide show
  1. package/lib/browser/ai-code-completion-frontend-module.d.ts.map +1 -1
  2. package/lib/browser/ai-code-completion-frontend-module.js +4 -2
  3. package/lib/browser/ai-code-completion-frontend-module.js.map +1 -1
  4. package/lib/browser/ai-code-completion-preference.d.ts +2 -1
  5. package/lib/browser/ai-code-completion-preference.d.ts.map +1 -1
  6. package/lib/browser/ai-code-completion-preference.js +15 -4
  7. package/lib/browser/ai-code-completion-preference.js.map +1 -1
  8. package/lib/browser/ai-code-frontend-application-contribution.d.ts +3 -2
  9. package/lib/browser/ai-code-frontend-application-contribution.d.ts.map +1 -1
  10. package/lib/browser/ai-code-frontend-application-contribution.js +15 -3
  11. package/lib/browser/ai-code-frontend-application-contribution.js.map +1 -1
  12. package/lib/browser/ai-code-inline-completion-provider.d.ts +1 -1
  13. package/lib/browser/ai-code-inline-completion-provider.d.ts.map +1 -1
  14. package/lib/browser/ai-code-inline-completion-provider.js +1 -1
  15. package/lib/browser/ai-code-inline-completion-provider.js.map +1 -1
  16. package/lib/{common → browser}/code-completion-agent.d.ts +5 -2
  17. package/lib/browser/code-completion-agent.d.ts.map +1 -0
  18. package/lib/browser/code-completion-agent.js +181 -0
  19. package/lib/browser/code-completion-agent.js.map +1 -0
  20. package/package.json +8 -8
  21. package/src/browser/ai-code-completion-frontend-module.ts +5 -3
  22. package/src/browser/ai-code-completion-preference.ts +14 -3
  23. package/src/browser/ai-code-frontend-application-contribution.ts +19 -9
  24. package/src/browser/ai-code-inline-completion-provider.ts +1 -1
  25. package/src/browser/code-completion-agent.ts +204 -0
  26. package/lib/common/code-completion-agent.d.ts.map +0 -1
  27. package/lib/common/code-completion-agent.js +0 -150
  28. package/lib/common/code-completion-agent.js.map +0 -1
  29. package/src/common/code-completion-agent.ts +0 -164
@@ -1 +1 @@
1
- {"version":3,"file":"ai-code-completion-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAQ/D,wBAWG"}
1
+ {"version":3,"file":"ai-code-completion-frontend-module.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-completion-frontend-module.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;;AAQ/D,wBAaG"}
@@ -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("../common/code-completion-agent");
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");
@@ -32,7 +32,9 @@ exports.default = new inversify_1.ContainerModule(bind => {
32
32
  bind(code_completion_agent_1.CodeCompletionAgent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
33
33
  bind(ai_core_1.Agent).toService(code_completion_agent_1.CodeCompletionAgentImpl);
34
34
  bind(ai_code_inline_completion_provider_1.AICodeInlineCompletionsProvider).toSelf().inSingletonScope();
35
- bind(browser_1.FrontendApplicationContribution).to(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution).inSingletonScope();
35
+ bind(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution).toSelf().inSingletonScope();
36
+ bind(browser_1.FrontendApplicationContribution).to(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
37
+ bind(browser_1.KeybindingContribution).toService(ai_code_frontend_application_contribution_1.AIFrontendApplicationContribution);
36
38
  bind(browser_1.PreferenceContribution).toConstantValue({ schema: ai_code_completion_preference_1.AICodeCompletionPreferencesSchema });
37
39
  });
38
40
  //# sourceMappingURL=ai-code-completion-frontend-module.js.map
@@ -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,2EAA+F;AAC/F,2GAAgG;AAChG,qDAAkG;AAClG,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,yCAA+B,CAAC,CAAC,EAAE,CAAC,6EAAiC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IAC/F,IAAI,CAAC,gCAAsB,CAAC,CAAC,eAAe,CAAC,EAAE,MAAM,EAAE,iEAAiC,EAAE,CAAC,CAAC;AAChG,CAAC,CAAC,CAAC"}
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
- export declare const PREF_AI_INLINE_COMPLETION_ENABLE = "ai-features.codeCompletion.enableCodeCompletion";
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,gCAAgC,oDAAoD,CAAC;AAClG,eAAO,MAAM,6CAA6C,sDAAsD,CAAC;AAEjH,eAAO,MAAM,iCAAiC,EAAE,gBAmB/C,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,17 +15,20 @@
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_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
- exports.PREF_AI_INLINE_COMPLETION_ENABLE = 'ai-features.codeCompletion.enableCodeCompletion';
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: {
25
- [exports.PREF_AI_INLINE_COMPLETION_ENABLE]: {
26
+ [exports.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE]: {
26
27
  title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
27
28
  type: 'boolean',
28
- description: 'Enable AI completions inline within any (Monaco) editor.',
29
+ description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
30
+ \n\
31
+ Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
29
32
  default: false
30
33
  },
31
34
  [exports.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
@@ -36,6 +39,14 @@ exports.AICodeCompletionPreferencesSchema = {
36
39
  type: 'string'
37
40
  },
38
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
39
50
  }
40
51
  }
41
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,gCAAgC,GAAG,iDAAiD,CAAC;AACrF,QAAA,6CAA6C,GAAG,mDAAmD,CAAC;AAEpG,QAAA,iCAAiC,GAAqB;IAC/D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACR,CAAC,wCAAgC,CAAC,EAAE;YAChC,KAAK,EAAE,+CAAyB;YAChC,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,0DAA0D;YACvE,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;KACJ;CACJ,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,13 +1,14 @@
1
- import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
1
+ import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, PreferenceService } from '@theia/core/lib/browser';
2
2
  import { AIActivationService } from '@theia/ai-core/lib/browser';
3
3
  import { Disposable } from '@theia/core';
4
- export declare class AIFrontendApplicationContribution implements FrontendApplicationContribution {
4
+ export declare class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
5
5
  private inlineCodeCompletionProvider;
6
6
  protected readonly preferenceService: PreferenceService;
7
7
  protected readonly activationService: AIActivationService;
8
8
  private toDispose;
9
9
  onDidInitializeLayout(): void;
10
10
  protected handlePreferences(): void;
11
+ registerKeybindings(keybindings: KeybindingRegistry): void;
11
12
  protected handleInlineCompletions(): Disposable;
12
13
  }
13
14
  //# sourceMappingURL=ai-code-frontend-application-contribution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-code-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,+BAA+B,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,qBACa,iCAAkC,YAAW,+BAA+B;IAErF,OAAO,CAAC,4BAA4B,CAAkC;IAGtE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IAE1D,OAAO,CAAC,SAAS,CAAiC;IAElD,qBAAqB,IAAI,IAAI;IAM7B,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAkBnC,SAAS,CAAC,uBAAuB,IAAI,UAAU;CA0BlD"}
1
+ {"version":3,"file":"ai-code-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,+BAA+B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEzI,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,qBACa,iCAAkC,YAAW,+BAA+B,EAAE,sBAAsB;IAE7G,OAAO,CAAC,4BAA4B,CAAkC;IAGtE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAGxD,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IAE1D,OAAO,CAAC,SAAS,CAAiC;IAElD,qBAAqB,IAAI,IAAI;IAM7B,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAmBnC,mBAAmB,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAQ1D,SAAS,CAAC,uBAAuB,IAAI,UAAU;CA0BlD"}
@@ -24,6 +24,7 @@ const browser_2 = require("@theia/ai-core/lib/browser");
24
24
  const core_1 = require("@theia/core");
25
25
  const ai_code_inline_completion_provider_1 = require("./ai-code-inline-completion-provider");
26
26
  const ai_code_completion_preference_1 = require("./ai-code-completion-preference");
27
+ const languages_1 = require("@theia/monaco-editor-core/esm/vs/editor/common/languages");
27
28
  let AIFrontendApplicationContribution = class AIFrontendApplicationContribution {
28
29
  constructor() {
29
30
  this.toDispose = new Map();
@@ -38,7 +39,8 @@ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution
38
39
  this.toDispose.set('inlineCompletions', handler());
39
40
  this.preferenceService.onPreferenceChanged(event => {
40
41
  var _a;
41
- if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_ENABLE || event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
42
+ if (event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
43
+ || event.preferenceName === ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
42
44
  (_a = this.toDispose.get('inlineCompletions')) === null || _a === void 0 ? void 0 : _a.dispose();
43
45
  this.toDispose.set('inlineCompletions', handler());
44
46
  }
@@ -49,14 +51,24 @@ let AIFrontendApplicationContribution = class AIFrontendApplicationContribution
49
51
  this.toDispose.set('inlineCompletions', handler());
50
52
  });
51
53
  }
54
+ registerKeybindings(keybindings) {
55
+ keybindings.registerKeybinding({
56
+ command: 'editor.action.inlineSuggest.trigger',
57
+ keybinding: 'Shift+Space',
58
+ when: '!editorReadonly && editorTextFocus'
59
+ });
60
+ }
52
61
  handleInlineCompletions() {
53
- const enable = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_ENABLE, false) && this.activationService.isActive;
54
- if (!enable) {
62
+ if (!this.activationService.isActive) {
55
63
  return core_1.Disposable.NULL;
56
64
  }
65
+ const automatic = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, true);
57
66
  const excludedExtensions = this.preferenceService.get(ai_code_completion_preference_1.PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS, []);
58
67
  return monaco.languages.registerInlineCompletionsProvider({ scheme: 'file' }, {
59
68
  provideInlineCompletions: (model, position, context, token) => {
69
+ if (!automatic && context.triggerKind === languages_1.InlineCompletionTriggerKind.Automatic) {
70
+ return { items: [] };
71
+ }
60
72
  const fileName = model.uri.toString();
61
73
  if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
62
74
  return { items: [] };
@@ -1 +1 @@
1
- {"version":3,"file":"ai-code-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.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,oDAAo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D7C"}
1
+ {"version":3,"file":"ai-code-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/ai-code-frontend-application-contribution.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,oDAAoD;AAEpD,qDAAyI;AACzI,4DAAkE;AAClE,wDAAiE;AACjE,sCAAyC;AACzC,6FAAuF;AACvF,mFAA4I;AAC5I,wFAAuG;AAGhG,IAAM,iCAAiC,GAAvC,MAAM,iCAAiC;IAAvC;QAUK,cAAS,GAAG,IAAI,GAAG,EAAsB,CAAC;IA6DtD,CAAC;IA3DG,qBAAqB;QACjB,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;IACP,CAAC;IAES,iBAAiB;QACvB,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAErD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,EAAE,CAAC,CAAC;QAEnD,IAAI,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;;YAC/C,IAAI,KAAK,CAAC,cAAc,KAAK,0EAA0C;mBAChE,KAAK,CAAC,cAAc,KAAK,6EAA6C,EAAE,CAAC;gBAC5E,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,0CAAE,OAAO,EAAE,CAAC;gBACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,mBAAmB,EAAE,OAAO,EAAE,CAAC,CAAC;YACvD,CAAC;QACL,CAAC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,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBACzD,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;gBACzB,CAAC;gBACD,OAAO,IAAI,CAAC,4BAA4B,CAAC,wBAAwB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACvG,CAAC;YACD,qBAAqB,EAAE,WAAW,CAAC,EAAE;gBACjC,IAAI,CAAC,4BAA4B,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;YACzE,CAAC;SACJ,CACJ,CAAC;IACN,CAAC;CACJ,CAAA;AAvEY,8EAAiC;AAElC;IADP,IAAA,kBAAM,EAAC,oEAA+B,CAAC;sCACF,oEAA+B;uFAAC;AAGnD;IADlB,IAAA,kBAAM,EAAC,2BAAiB,CAAC;;4EAC8B;AAGrC;IADlB,IAAA,kBAAM,EAAC,6BAAmB,CAAC;sCACU,6BAAmB;4EAAC;4CARjD,iCAAiC;IAD7C,IAAA,sBAAU,GAAE;GACA,iCAAiC,CAuE7C"}
@@ -1,5 +1,5 @@
1
1
  import * as monaco from '@theia/monaco-editor-core';
2
- import { CodeCompletionAgent } from '../common/code-completion-agent';
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,iCAAiC,CAAC;AAGtE,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"}
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("../common/code-completion-agent");
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,2EAAsE;AACtE,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
+ {"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;
@@ -19,6 +22,6 @@ export declare class CodeCompletionAgentImpl implements CodeCompletionAgent {
19
22
  readonly variables: string[];
20
23
  readonly functions: string[];
21
24
  readonly agentSpecificVariables: AgentSpecificVariables[];
22
- readonly tags?: String[] | undefined;
25
+ readonly tags?: string[] | undefined;
23
26
  }
24
27
  //# sourceMappingURL=code-completion-agent.d.ts.map
@@ -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,2BAA2B,CAAC;AACnC,OAAO,EAAgB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,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;IAkH1D,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;IAG1D,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC;IAG3C,SAAS,CAAC,WAAW,EAAE,iBAAiB,CAAC;IAEzC,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"}
@@ -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,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,sCAAqE;AACrE,4DAAyE;AAEzE,mFAA8F;AAC9F,qDAA4D;AAE/C,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAO1D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAA7B;QAyIH,OAAE,GAAG,iBAAiB,CAAC;QACvB,SAAI,GAAG,iBAAiB,CAAC;QACzB,gBAAW,GACP,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A0KnC"}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@theia/ai-code-completion",
3
- "version": "1.55.0",
3
+ "version": "1.56.0",
4
4
  "description": "Theia - AI Core",
5
5
  "dependencies": {
6
- "@theia/ai-core": "1.55.0",
7
- "@theia/core": "1.55.0",
8
- "@theia/filesystem": "1.55.0",
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.55.0",
11
- "@theia/workspace": "1.55.0",
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.55.0"
49
+ "@theia/ext-scripts": "1.56.0"
50
50
  },
51
51
  "nyc": {
52
52
  "extends": "../../configs/nyc.json"
53
53
  },
54
- "gitHead": "0e7a523b8e798679d2e098709c63bd7060e54c8a"
54
+ "gitHead": "3b4498f8f1c66be688847418fcc35595282671dc"
55
55
  }
@@ -16,9 +16,9 @@
16
16
 
17
17
  import { ILogger } from '@theia/core';
18
18
  import { ContainerModule } from '@theia/core/shared/inversify';
19
- import { CodeCompletionAgent, CodeCompletionAgentImpl } from '../common/code-completion-agent';
19
+ import { CodeCompletionAgent, CodeCompletionAgentImpl } from './code-completion-agent';
20
20
  import { AIFrontendApplicationContribution } from './ai-code-frontend-application-contribution';
21
- import { FrontendApplicationContribution, PreferenceContribution } from '@theia/core/lib/browser';
21
+ import { FrontendApplicationContribution, KeybindingContribution, PreferenceContribution } from '@theia/core/lib/browser';
22
22
  import { Agent } from '@theia/ai-core';
23
23
  import { AICodeCompletionPreferencesSchema } from './ai-code-completion-preference';
24
24
  import { AICodeInlineCompletionsProvider } from './ai-code-inline-completion-provider';
@@ -32,6 +32,8 @@ export default new ContainerModule(bind => {
32
32
  bind(CodeCompletionAgent).toService(CodeCompletionAgentImpl);
33
33
  bind(Agent).toService(CodeCompletionAgentImpl);
34
34
  bind(AICodeInlineCompletionsProvider).toSelf().inSingletonScope();
35
- bind(FrontendApplicationContribution).to(AIFrontendApplicationContribution).inSingletonScope();
35
+ bind(AIFrontendApplicationContribution).toSelf().inSingletonScope();
36
+ bind(FrontendApplicationContribution).to(AIFrontendApplicationContribution);
37
+ bind(KeybindingContribution).toService(AIFrontendApplicationContribution);
36
38
  bind(PreferenceContribution).toConstantValue({ schema: AICodeCompletionPreferencesSchema });
37
39
  });
@@ -17,16 +17,19 @@
17
17
  import { PreferenceSchema } from '@theia/core/lib/browser/preferences/preference-contribution';
18
18
  import { AI_CORE_PREFERENCES_TITLE } from '@theia/ai-core/lib/browser/ai-core-preferences';
19
19
 
20
- export const PREF_AI_INLINE_COMPLETION_ENABLE = 'ai-features.codeCompletion.enableCodeCompletion';
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',
25
26
  properties: {
26
- [PREF_AI_INLINE_COMPLETION_ENABLE]: {
27
+ [PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE]: {
27
28
  title: AI_CORE_PREFERENCES_TITLE,
28
29
  type: 'boolean',
29
- description: 'Enable AI completions inline within any (Monaco) editor.',
30
+ description: 'Automatically trigger AI completions inline within any (Monaco) editor while editing.\
31
+ \n\
32
+ Alternatively, you can manually trigger the code via the command "Trigger Inline Suggestion" or the default shortcut "SHIFT+Space".',
30
33
  default: false
31
34
  },
32
35
  [PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS]: {
@@ -37,6 +40,14 @@ export const AICodeCompletionPreferencesSchema: PreferenceSchema = {
37
40
  type: 'string'
38
41
  },
39
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
40
51
  }
41
52
  }
42
53
  };
@@ -16,15 +16,16 @@
16
16
 
17
17
  import * as monaco from '@theia/monaco-editor-core';
18
18
 
19
- import { FrontendApplicationContribution, PreferenceService } from '@theia/core/lib/browser';
19
+ import { FrontendApplicationContribution, KeybindingContribution, KeybindingRegistry, PreferenceService } from '@theia/core/lib/browser';
20
20
  import { inject, injectable } from '@theia/core/shared/inversify';
21
21
  import { AIActivationService } from '@theia/ai-core/lib/browser';
22
22
  import { Disposable } from '@theia/core';
23
23
  import { AICodeInlineCompletionsProvider } from './ai-code-inline-completion-provider';
24
- import { PREF_AI_INLINE_COMPLETION_ENABLE, PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS } from './ai-code-completion-preference';
24
+ import { PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS } from './ai-code-completion-preference';
25
+ import { InlineCompletionTriggerKind } from '@theia/monaco-editor-core/esm/vs/editor/common/languages';
25
26
 
26
27
  @injectable()
27
- export class AIFrontendApplicationContribution implements FrontendApplicationContribution {
28
+ export class AIFrontendApplicationContribution implements FrontendApplicationContribution, KeybindingContribution {
28
29
  @inject(AICodeInlineCompletionsProvider)
29
30
  private inlineCodeCompletionProvider: AICodeInlineCompletionsProvider;
30
31
 
@@ -48,7 +49,8 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
48
49
  this.toDispose.set('inlineCompletions', handler());
49
50
 
50
51
  this.preferenceService.onPreferenceChanged(event => {
51
- if (event.preferenceName === PREF_AI_INLINE_COMPLETION_ENABLE || event.preferenceName === PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
52
+ if (event.preferenceName === PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE
53
+ || event.preferenceName === PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS) {
52
54
  this.toDispose.get('inlineCompletions')?.dispose();
53
55
  this.toDispose.set('inlineCompletions', handler());
54
56
  }
@@ -60,21 +62,29 @@ export class AIFrontendApplicationContribution implements FrontendApplicationCon
60
62
  });
61
63
  }
62
64
 
63
- protected handleInlineCompletions(): Disposable {
64
- const enable = this.preferenceService.get<boolean>(PREF_AI_INLINE_COMPLETION_ENABLE, false) && this.activationService.isActive;
65
+ registerKeybindings(keybindings: KeybindingRegistry): void {
66
+ keybindings.registerKeybinding({
67
+ command: 'editor.action.inlineSuggest.trigger',
68
+ keybinding: 'Shift+Space',
69
+ when: '!editorReadonly && editorTextFocus'
70
+ });
71
+ }
65
72
 
66
- if (!enable) {
73
+ protected handleInlineCompletions(): Disposable {
74
+ if (!this.activationService.isActive) {
67
75
  return Disposable.NULL;
68
76
  }
69
-
77
+ const automatic = this.preferenceService.get<boolean>(PREF_AI_INLINE_COMPLETION_AUTOMATIC_ENABLE, true);
70
78
  const excludedExtensions = this.preferenceService.get<string[]>(PREF_AI_INLINE_COMPLETION_EXCLUDED_EXTENSIONS, []);
71
79
 
72
80
  return monaco.languages.registerInlineCompletionsProvider(
73
81
  { scheme: 'file' },
74
82
  {
75
83
  provideInlineCompletions: (model, position, context, token) => {
84
+ if (!automatic && context.triggerKind === InlineCompletionTriggerKind.Automatic) {
85
+ return { items: [] };
86
+ }
76
87
  const fileName = model.uri.toString();
77
-
78
88
  if (excludedExtensions.some(ext => fileName.endsWith(ext))) {
79
89
  return { items: [] };
80
90
  }
@@ -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 '../common/code-completion-agent';
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,EAA6B,6BAA6B,EACvF,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;IAoF1D,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,CAW/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,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":"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;QAqGH,OA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,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
- }