@theia/ai-code-completion 1.63.0-next.52 → 1.63.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.
@@ -61,7 +61,7 @@ let CodeCompletionAgentImpl = class CodeCompletionAgentImpl {
61
61
  return undefined;
62
62
  }
63
63
  const prompt = await this.promptService
64
- .getResolvedPromptFragment('code-completion-prompt', undefined, variableContext)
64
+ .getResolvedPromptFragment('code-completion-system', undefined, variableContext)
65
65
  .then(p => p === null || p === void 0 ? void 0 : p.text);
66
66
  if (!prompt) {
67
67
  this.logger.error('No prompt found for code-completion-agent');
@@ -4,13 +4,22 @@ export declare class CodeCompletionCache {
4
4
  private maxSize;
5
5
  constructor();
6
6
  /**
7
- * Generate a unique cache key based on input parameters
7
+ * Generate a unique cache key for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
8
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
9
+ *
8
10
  * @param filePath Path of the current file
9
- * @param lineNumber Current line number
10
- * @param lineText Context prefix for completion
11
- * @returns Unique cache key
11
+ * @param model Monaco text model of the file
12
+ * @param position Current cursor position in the editor
13
+ * @returns Unique cache key as a string
12
14
  */
13
15
  generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string;
16
+ /**
17
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
18
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
19
+ * @param str The string to hash
20
+ * @returns The hash as a hex string
21
+ */
22
+ private static hashString;
14
23
  /**
15
24
  * Get a cached completion if available
16
25
  * @param key Cache key
@@ -1 +1 @@
1
- {"version":3,"file":"code-completion-cache.d.ts","sourceRoot":"","sources":["../../src/browser/code-completion-cache.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,MAAM,MAAM,2BAA2B,CAAC;AAEpD,qBACa,mBAAmB;IAC5B,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,OAAO,CAAO;;IAMtB;;;;;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AO,CAAC,uBAAuB;IAgB/B;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAOjC"}
@@ -14,37 +14,56 @@
14
14
  //
15
15
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16
16
  // *****************************************************************************
17
+ var CodeCompletionCache_1;
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.CodeCompletionCache = void 0;
19
20
  const tslib_1 = require("tslib");
20
21
  const inversify_1 = require("@theia/core/shared/inversify");
21
22
  const monaco = require("@theia/monaco-editor-core");
22
- let CodeCompletionCache = class CodeCompletionCache {
23
+ let CodeCompletionCache = CodeCompletionCache_1 = class CodeCompletionCache {
23
24
  constructor() {
24
25
  this.maxSize = 100;
25
26
  this.cache = new Map();
26
27
  }
27
28
  /**
28
- * Generate a unique cache key based on input parameters
29
+ * Generate a unique cache key for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
30
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
31
+ *
29
32
  * @param filePath Path of the current file
30
- * @param lineNumber Current line number
31
- * @param lineText Context prefix for completion
32
- * @returns Unique cache key
33
+ * @param model Monaco text model of the file
34
+ * @param position Current cursor position in the editor
35
+ * @returns Unique cache key as a string
33
36
  */
34
37
  generateKey(filePath, model, position) {
35
38
  const lineNumber = position.lineNumber;
36
- const beforeCursorLineRange = new monaco.Range(position.lineNumber, 1, position.lineNumber, position.column);
37
- const prefix = model.getValueInRange(beforeCursorLineRange);
38
- const afterCursorLineRange = new monaco.Range(position.lineNumber, position.column, position.lineNumber, model.getLineMaxColumn(position.lineNumber));
39
- const suffix = model.getValueInRange(afterCursorLineRange);
39
+ const prefixRange = new monaco.Range(1, 1, position.lineNumber, position.column);
40
+ const prefix = model.getValueInRange(prefixRange);
41
+ const lastLine = model.getLineCount();
42
+ const lastColumn = model.getLineMaxColumn(lastLine);
43
+ const suffixRange = new monaco.Range(position.lineNumber, position.column, lastLine, lastColumn);
44
+ const suffix = model.getValueInRange(suffixRange);
40
45
  const key = JSON.stringify({
41
46
  filePath,
42
47
  lineNumber,
43
- prefix,
44
- suffix
48
+ prefixHash: CodeCompletionCache_1.hashString(prefix),
49
+ suffixHash: CodeCompletionCache_1.hashString(suffix)
45
50
  });
46
51
  return key;
47
52
  }
53
+ /**
54
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
55
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
56
+ * @param str The string to hash
57
+ * @returns The hash as a hex string
58
+ */
59
+ static hashString(str) {
60
+ let hash = 0x811c9dc5;
61
+ for (let i = 0; i < str.length; i++) {
62
+ hash ^= str.charCodeAt(i);
63
+ hash = (hash * 0x01000193) >>> 0;
64
+ }
65
+ return hash.toString(16);
66
+ }
48
67
  /**
49
68
  * Get a cached completion if available
50
69
  * @param key Cache key
@@ -109,7 +128,7 @@ let CodeCompletionCache = class CodeCompletionCache {
109
128
  }
110
129
  };
111
130
  exports.CodeCompletionCache = CodeCompletionCache;
112
- exports.CodeCompletionCache = CodeCompletionCache = tslib_1.__decorate([
131
+ exports.CodeCompletionCache = CodeCompletionCache = CodeCompletionCache_1 = tslib_1.__decorate([
113
132
  (0, inversify_1.injectable)(),
114
133
  tslib_1.__metadata("design:paramtypes", [])
115
134
  ], CodeCompletionCache);
@@ -1 +1 @@
1
- {"version":3,"file":"code-completion-cache.js","sourceRoot":"","sources":["../../src/browser/code-completion-cache.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,4DAA0D;AAC1D,oDAAoD;AAG7C,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAI5B;QAFQ,YAAO,GAA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IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE;YAChB,KAAK;YACL,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;SAC3B,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,KAAK;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACK,uBAAuB;QAC3B,IAAI,SAA6B,CAAC;QAClC,IAAI,UAAU,GAAG,QAAQ,CAAC;QAE1B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,YAAY,GAAG,UAAU,EAAE,CAAC;gBAClC,SAAS,GAAG,GAAG,CAAC;gBAChB,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC;YACpC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,IAAY;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,oCAAoC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;CACJ,CAAA;AAzGY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;;GACA,mBAAmB,CAyG/B"}
1
+ {"version":3,"file":"code-completion-cache.js","sourceRoot":"","sources":["../../src/browser/code-completion-cache.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;A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AK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAC9C,IAAI,KAAK,CAAC,YAAY,GAAG,UAAU,EAAE,CAAC;gBAClC,SAAS,GAAG,GAAG,CAAC;gBAChB,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC;YACpC,CAAC;QACL,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACjC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,UAAU,CAAC,IAAY;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,oCAAoC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YACpC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QACnC,CAAC;IACL,CAAC;CACJ,CAAA;AAtHY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,GAAE;;GACA,mBAAmB,CAsH/B"}
@@ -13,9 +13,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.codeCompletionPrompts = void 0;
14
14
  const code_completion_variables_1 = require("./code-completion-variables");
15
15
  exports.codeCompletionPrompts = [{
16
- id: 'code-completion-prompt',
16
+ id: 'code-completion-system',
17
17
  variants: [{
18
- id: 'code-completion-prompt-previous',
18
+ id: 'code-completion-system-previous',
19
19
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
20
20
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
21
21
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -28,7 +28,7 @@ Finish the following code snippet.
28
28
  Only return the exact replacement for [[MARKER]] to complete the snippet.`
29
29
  },
30
30
  {
31
- id: 'code-completion-prompt-next',
31
+ id: 'code-completion-system-next',
32
32
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
33
33
  Made improvements or adaptations to this prompt template? We'd love for you to share it with the community! Contribute back here:
34
34
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -62,7 +62,7 @@ You are an expert AI code completion assistant focused on generating precise, co
62
62
  - Consider language-specific idioms and patterns`
63
63
  }],
64
64
  defaultVariant: {
65
- id: 'code-completion-prompt-default',
65
+ id: 'code-completion-system-default',
66
66
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
67
67
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
68
68
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@theia/ai-code-completion",
3
- "version": "1.63.0-next.52+176018e53",
3
+ "version": "1.63.0",
4
4
  "description": "Theia - AI Core",
5
5
  "dependencies": {
6
- "@theia/ai-core": "1.63.0-next.52+176018e53",
7
- "@theia/core": "1.63.0-next.52+176018e53",
8
- "@theia/filesystem": "1.63.0-next.52+176018e53",
6
+ "@theia/ai-core": "1.63.0",
7
+ "@theia/core": "1.63.0",
8
+ "@theia/filesystem": "1.63.0",
9
9
  "@theia/monaco-editor-core": "1.96.302",
10
- "@theia/output": "1.63.0-next.52+176018e53",
11
- "@theia/workspace": "1.63.0-next.52+176018e53",
10
+ "@theia/output": "1.63.0",
11
+ "@theia/workspace": "1.63.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.62.0"
49
+ "@theia/ext-scripts": "1.63.0"
50
50
  },
51
51
  "nyc": {
52
52
  "extends": "../../configs/nyc.json"
53
53
  },
54
- "gitHead": "176018e53e62cafec9b25b23ac9f0b4826b6d0f7"
54
+ "gitHead": "facf442522991134333495a0b90cf56a56990280"
55
55
  }
@@ -71,7 +71,7 @@ export class CodeCompletionAgentImpl implements CodeCompletionAgent {
71
71
  return undefined;
72
72
  }
73
73
  const prompt = await this.promptService
74
- .getResolvedPromptFragment('code-completion-prompt', undefined, variableContext)
74
+ .getResolvedPromptFragment('code-completion-system', undefined, variableContext)
75
75
  .then(p => p?.text);
76
76
  if (!prompt) {
77
77
  this.logger.error('No prompt found for code-completion-agent');
@@ -27,33 +27,46 @@ export class CodeCompletionCache {
27
27
  }
28
28
 
29
29
  /**
30
- * Generate a unique cache key based on input parameters
30
+ * Generate a unique cache key for code completion based on the file path, cursor position, and the hashed context (prefix and suffix).
31
+ * The prefix and suffix are hashed to avoid storing large or sensitive content directly in the cache key.
32
+ *
31
33
  * @param filePath Path of the current file
32
- * @param lineNumber Current line number
33
- * @param lineText Context prefix for completion
34
- * @returns Unique cache key
34
+ * @param model Monaco text model of the file
35
+ * @param position Current cursor position in the editor
36
+ * @returns Unique cache key as a string
35
37
  */
36
38
  generateKey(filePath: string, model: monaco.editor.ITextModel, position: monaco.Position): string {
37
39
  const lineNumber = position.lineNumber;
38
- const beforeCursorLineRange = new monaco.Range(
39
- position.lineNumber, 1,
40
- position.lineNumber, position.column
41
- );
42
- const prefix = model.getValueInRange(beforeCursorLineRange);
43
- const afterCursorLineRange = new monaco.Range(
44
- position.lineNumber, position.column,
45
- position.lineNumber, model.getLineMaxColumn(position.lineNumber)
46
- );
47
- const suffix = model.getValueInRange(afterCursorLineRange);
40
+ const prefixRange = new monaco.Range(1, 1, position.lineNumber, position.column);
41
+ const prefix = model.getValueInRange(prefixRange);
42
+ const lastLine = model.getLineCount();
43
+ const lastColumn = model.getLineMaxColumn(lastLine);
44
+ const suffixRange = new monaco.Range(position.lineNumber, position.column, lastLine, lastColumn);
45
+ const suffix = model.getValueInRange(suffixRange);
48
46
  const key = JSON.stringify({
49
47
  filePath,
50
48
  lineNumber,
51
- prefix,
52
- suffix
49
+ prefixHash: CodeCompletionCache.hashString(prefix),
50
+ suffixHash: CodeCompletionCache.hashString(suffix)
53
51
  });
54
52
  return key;
55
53
  }
56
54
 
55
+ /**
56
+ * Hash a string using a simple hash algorithm (FNV-1a 32-bit).
57
+ * This is not cryptographically secure but is sufficient for cache key uniqueness.
58
+ * @param str The string to hash
59
+ * @returns The hash as a hex string
60
+ */
61
+ private static hashString(str: string): string {
62
+ let hash = 0x811c9dc5;
63
+ for (let i = 0; i < str.length; i++) {
64
+ hash ^= str.charCodeAt(i);
65
+ hash = (hash * 0x01000193) >>> 0;
66
+ }
67
+ return hash.toString(16);
68
+ }
69
+
57
70
  /**
58
71
  * Get a cached completion if available
59
72
  * @param key Cache key
@@ -13,9 +13,9 @@ import { PromptVariantSet } from '@theia/ai-core/lib/common';
13
13
  import { FILE, LANGUAGE, PREFIX, SUFFIX } from './code-completion-variables';
14
14
 
15
15
  export const codeCompletionPrompts: PromptVariantSet[] = [{
16
- id: 'code-completion-prompt',
16
+ id: 'code-completion-system',
17
17
  variants: [{
18
- id: 'code-completion-prompt-previous',
18
+ id: 'code-completion-system-previous',
19
19
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
20
20
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
21
21
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -28,7 +28,7 @@ Finish the following code snippet.
28
28
  Only return the exact replacement for [[MARKER]] to complete the snippet.`
29
29
  },
30
30
  {
31
- id: 'code-completion-prompt-next',
31
+ id: 'code-completion-system-next',
32
32
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
33
33
  Made improvements or adaptations to this prompt template? We'd love for you to share it with the community! Contribute back here:
34
34
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}
@@ -62,7 +62,7 @@ You are an expert AI code completion assistant focused on generating precise, co
62
62
  - Consider language-specific idioms and patterns`
63
63
  }],
64
64
  defaultVariant: {
65
- id: 'code-completion-prompt-default',
65
+ id: 'code-completion-system-default',
66
66
  template: `{{!-- This prompt is licensed under the MIT License (https://opensource.org/license/mit).
67
67
  Made improvements or adaptations to this prompt template? We’d love for you to share it with the community! Contribute back here:
68
68
  https://github.com/eclipse-theia/theia/discussions/new?category=prompt-template-contribution --}}