monacopilot 0.10.7 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -10
- package/build/index.d.mts +29 -5
- package/build/index.d.ts +29 -5
- package/build/index.js +14 -14
- package/build/index.mjs +14 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
- [Manually Trigger Completions](#manually-trigger-completions)
|
|
22
22
|
- [Trigger Completions with a Keyboard Shortcut](#trigger-completions-with-a-keyboard-shortcut)
|
|
23
23
|
- [Trigger Completions with an Editor Action](#trigger-completions-with-an-editor-action)
|
|
24
|
-
- [
|
|
24
|
+
- [Multi-File Context](#multi-file-context)
|
|
25
25
|
- [Filename](#filename)
|
|
26
26
|
- [Completions for Specific Technologies](#completions-for-specific-technologies)
|
|
27
27
|
- [Max Context Lines](#max-context-lines)
|
|
28
28
|
- [Copilot Options](#copilot-options)
|
|
29
29
|
- [Changing the Provider and Model](#changing-the-provider-and-model)
|
|
30
|
+
- [Updating Provider and Model at Runtime](#updating-provider-and-model-at-runtime)
|
|
30
31
|
- [Custom Model](#custom-model)
|
|
31
32
|
- [Completion Request Options](#completion-request-options)
|
|
32
33
|
- [Custom Headers](#custom-headers)
|
|
@@ -113,6 +114,8 @@ registerCompletion(monaco, editor, {
|
|
|
113
114
|
});
|
|
114
115
|
```
|
|
115
116
|
|
|
117
|
+
The `registerCompletion` function returns a `completion` object with useful methods such as `trigger` and `dispose`. The `trigger` method is explained later in this document. The `dispose` method should be used to clean up resources when the completion object is no longer needed. For instance, in a React component, you can call `completion.dispose()` within the `useEffect` cleanup function to ensure proper disposal when the component unmounts.
|
|
118
|
+
|
|
116
119
|
🎉 Congratulations! The AI auto-completion is now connected to the Monaco Editor. Start typing and see completions in the editor.
|
|
117
120
|
|
|
118
121
|
## Register Completion Options
|
|
@@ -127,10 +130,11 @@ registerCompletion(monaco, editor, {
|
|
|
127
130
|
});
|
|
128
131
|
```
|
|
129
132
|
|
|
130
|
-
| Trigger | Description
|
|
131
|
-
| -------------------- |
|
|
132
|
-
| `'onIdle'` (default) |
|
|
133
|
-
| `'onTyping'` |
|
|
133
|
+
| Trigger | Description | Notes |
|
|
134
|
+
| -------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
135
|
+
| `'onIdle'` (default) | Provides completions after a brief pause in typing. | This approach is less resource-intensive, as it only initiates a request when the editor is idle. |
|
|
136
|
+
| `'onTyping'` | Provides completions in real-time as you type. | Best suited for models with low response latency, such as Groq models. This trigger mode initiates additional background requests to deliver real-time suggestions, a method known as predictive caching. |
|
|
137
|
+
| `'onDemand'` | Does not provide completions automatically. | Completions are triggered manually using the `trigger` function from the `registerCompletion` return. This allows for precise control over when completions are provided. |
|
|
134
138
|
|
|
135
139
|
[OnTyping Demo](https://github.com/user-attachments/assets/22c2ce44-334c-4963-b853-01b890b8e39f)
|
|
136
140
|
|
|
@@ -193,13 +197,13 @@ monaco.editor.addEditorAction({
|
|
|
193
197
|
});
|
|
194
198
|
```
|
|
195
199
|
|
|
196
|
-
###
|
|
200
|
+
### Multi-File Context
|
|
197
201
|
|
|
198
|
-
|
|
202
|
+
Improve the quality and relevance of Copilot's suggestions by providing additional code context from other files in your project. This feature allows Copilot to understand the broader scope of your codebase, resulting in more accurate and contextually appropriate completions.
|
|
199
203
|
|
|
200
204
|
```javascript
|
|
201
205
|
registerCompletion(monaco, editor, {
|
|
202
|
-
|
|
206
|
+
relatedFiles: [
|
|
203
207
|
{
|
|
204
208
|
path: './utils.js',
|
|
205
209
|
content:
|
|
@@ -209,7 +213,7 @@ registerCompletion(monaco, editor, {
|
|
|
209
213
|
});
|
|
210
214
|
```
|
|
211
215
|
|
|
212
|
-
|
|
216
|
+
For instance, if you begin typing `const isPalindrome = ` in your current file, Copilot will recognize the `reverse` function from the `utils.js` file you provided earlier. It will then suggest a completion that utilizes this function.
|
|
213
217
|
|
|
214
218
|
### Filename
|
|
215
219
|
|
|
@@ -272,6 +276,17 @@ There are other providers and models available. Here is a list:
|
|
|
272
276
|
| OpenAI | `gpt-4o`, `gpt-4o-mini`, `o1-preview`, `o1-mini` |
|
|
273
277
|
| Anthropic | `claude-3.5-Sonnet`, `claude-3-opus`, `claude-3-sonnet`, `claude-3-haiku` |
|
|
274
278
|
|
|
279
|
+
#### Updating Provider and Model at Runtime
|
|
280
|
+
|
|
281
|
+
You can change the provider and model at runtime using the `setModel` method.
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
copilot.setModel({
|
|
285
|
+
provider: 'anthropic',
|
|
286
|
+
model: 'claude-3-haiku',
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
275
290
|
### Custom Model
|
|
276
291
|
|
|
277
292
|
You can use a custom AI model that isn't built into Monacopilot by setting up a `model` when you create a new Copilot. This feature lets you connect to AI models from other services or your own custom-built models.
|
|
@@ -381,7 +396,7 @@ The `customPrompt` function receives a `completionMetadata` object, which contai
|
|
|
381
396
|
| `cursorPosition` | `{ lineNumber: number; column: number }` | The current cursor position in the editor. |
|
|
382
397
|
| `filename` | `string` or `undefined` | The name of the file being edited. Only available if you have provided the `filename` option in the `registerCompletion` function. |
|
|
383
398
|
| `technologies` | `string[]` or `undefined` | An array of technologies used in the project. Only available if you have provided the `technologies` option in the `registerCompletion` function. |
|
|
384
|
-
| `
|
|
399
|
+
| `context` | `object` or `undefined` | Additional context from related files. Only available if you have provided the `context` option in the `registerCompletion` function. |
|
|
385
400
|
| `textAfterCursor` | `string` | The text that appears after the cursor. |
|
|
386
401
|
| `textBeforeCursor` | `string` | The text that appears before the cursor. |
|
|
387
402
|
| `editorState` | `object` | An object containing the `completionMode` property. |
|
package/build/index.d.mts
CHANGED
|
@@ -54,6 +54,20 @@ type CustomCopilotModel = {
|
|
|
54
54
|
*/
|
|
55
55
|
transformResponse: CustomCopilotModelTransformResponse;
|
|
56
56
|
};
|
|
57
|
+
type SetModelOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* The provider to set (e.g., 'openai', 'anthropic', 'groq').
|
|
60
|
+
*/
|
|
61
|
+
provider: CopilotProvider;
|
|
62
|
+
/**
|
|
63
|
+
* The model to use for copilot AI requests.
|
|
64
|
+
* This can be either:
|
|
65
|
+
* 1. A predefined model name (e.g. 'claude-3-opus'): Use this option if you want to use a model that is built into Monacopilot.
|
|
66
|
+
* If you choose this option, also set the `provider` property to the corresponding provider of the model.
|
|
67
|
+
* 2. A custom model configuration object: Use this option if you want to use a AI model from a third-party service or your own custom model.
|
|
68
|
+
*/
|
|
69
|
+
model: CopilotModel | CustomCopilotModel;
|
|
70
|
+
};
|
|
57
71
|
type CustomCopilotModelConfig = (apiKey: string, prompt: {
|
|
58
72
|
system: string;
|
|
59
73
|
user: string;
|
|
@@ -91,7 +105,7 @@ type CursorPosition = monaco.IPosition;
|
|
|
91
105
|
type Endpoint = string;
|
|
92
106
|
type Filename = string;
|
|
93
107
|
type Technologies = string[];
|
|
94
|
-
type
|
|
108
|
+
type RelatedFile = {
|
|
95
109
|
/**
|
|
96
110
|
* The relative path from the current editing code in the editor to an external file.
|
|
97
111
|
*
|
|
@@ -144,11 +158,16 @@ interface RegisterCompletionOptions {
|
|
|
144
158
|
* etc.
|
|
145
159
|
*/
|
|
146
160
|
technologies?: Technologies;
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated
|
|
163
|
+
* Use `relatedFiles` instead.
|
|
164
|
+
*/
|
|
165
|
+
externalContext?: RelatedFile[];
|
|
147
166
|
/**
|
|
148
167
|
* Helps to give more relevant completions based on the full context.
|
|
149
168
|
* You can include things like the contents/codes of other files in the same workspace.
|
|
150
169
|
*/
|
|
151
|
-
|
|
170
|
+
relatedFiles?: RelatedFile[];
|
|
152
171
|
/**
|
|
153
172
|
* The maximum number of lines of code to include in the completion request.
|
|
154
173
|
* This limits the request size to the model to prevent `429 Too Many Requests` errors
|
|
@@ -223,7 +242,7 @@ interface CompletionMetadata {
|
|
|
223
242
|
/**
|
|
224
243
|
* Additional context from related files.
|
|
225
244
|
*/
|
|
226
|
-
|
|
245
|
+
relatedFiles: RelatedFile[] | undefined;
|
|
227
246
|
/**
|
|
228
247
|
* The text that appears after the cursor.
|
|
229
248
|
*/
|
|
@@ -251,8 +270,8 @@ interface CompletionMetadata {
|
|
|
251
270
|
|
|
252
271
|
declare class Copilot {
|
|
253
272
|
private readonly apiKey;
|
|
254
|
-
private
|
|
255
|
-
private
|
|
273
|
+
private provider;
|
|
274
|
+
private model;
|
|
256
275
|
/**
|
|
257
276
|
* Initializes the Copilot instance with an API key and optional configuration.
|
|
258
277
|
* @param apiKey - The API key for the chosen provider.
|
|
@@ -270,6 +289,11 @@ declare class Copilot {
|
|
|
270
289
|
* @returns A promise resolving to the completion response or an error.
|
|
271
290
|
*/
|
|
272
291
|
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
292
|
+
/**
|
|
293
|
+
* Sets the model and provider for the Copilot.
|
|
294
|
+
* @param options - The options for setting the model and provider.
|
|
295
|
+
*/
|
|
296
|
+
setModel({ model, provider }: SetModelOptions): void;
|
|
273
297
|
}
|
|
274
298
|
|
|
275
299
|
/**
|
package/build/index.d.ts
CHANGED
|
@@ -54,6 +54,20 @@ type CustomCopilotModel = {
|
|
|
54
54
|
*/
|
|
55
55
|
transformResponse: CustomCopilotModelTransformResponse;
|
|
56
56
|
};
|
|
57
|
+
type SetModelOptions = {
|
|
58
|
+
/**
|
|
59
|
+
* The provider to set (e.g., 'openai', 'anthropic', 'groq').
|
|
60
|
+
*/
|
|
61
|
+
provider: CopilotProvider;
|
|
62
|
+
/**
|
|
63
|
+
* The model to use for copilot AI requests.
|
|
64
|
+
* This can be either:
|
|
65
|
+
* 1. A predefined model name (e.g. 'claude-3-opus'): Use this option if you want to use a model that is built into Monacopilot.
|
|
66
|
+
* If you choose this option, also set the `provider` property to the corresponding provider of the model.
|
|
67
|
+
* 2. A custom model configuration object: Use this option if you want to use a AI model from a third-party service or your own custom model.
|
|
68
|
+
*/
|
|
69
|
+
model: CopilotModel | CustomCopilotModel;
|
|
70
|
+
};
|
|
57
71
|
type CustomCopilotModelConfig = (apiKey: string, prompt: {
|
|
58
72
|
system: string;
|
|
59
73
|
user: string;
|
|
@@ -91,7 +105,7 @@ type CursorPosition = monaco.IPosition;
|
|
|
91
105
|
type Endpoint = string;
|
|
92
106
|
type Filename = string;
|
|
93
107
|
type Technologies = string[];
|
|
94
|
-
type
|
|
108
|
+
type RelatedFile = {
|
|
95
109
|
/**
|
|
96
110
|
* The relative path from the current editing code in the editor to an external file.
|
|
97
111
|
*
|
|
@@ -144,11 +158,16 @@ interface RegisterCompletionOptions {
|
|
|
144
158
|
* etc.
|
|
145
159
|
*/
|
|
146
160
|
technologies?: Technologies;
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated
|
|
163
|
+
* Use `relatedFiles` instead.
|
|
164
|
+
*/
|
|
165
|
+
externalContext?: RelatedFile[];
|
|
147
166
|
/**
|
|
148
167
|
* Helps to give more relevant completions based on the full context.
|
|
149
168
|
* You can include things like the contents/codes of other files in the same workspace.
|
|
150
169
|
*/
|
|
151
|
-
|
|
170
|
+
relatedFiles?: RelatedFile[];
|
|
152
171
|
/**
|
|
153
172
|
* The maximum number of lines of code to include in the completion request.
|
|
154
173
|
* This limits the request size to the model to prevent `429 Too Many Requests` errors
|
|
@@ -223,7 +242,7 @@ interface CompletionMetadata {
|
|
|
223
242
|
/**
|
|
224
243
|
* Additional context from related files.
|
|
225
244
|
*/
|
|
226
|
-
|
|
245
|
+
relatedFiles: RelatedFile[] | undefined;
|
|
227
246
|
/**
|
|
228
247
|
* The text that appears after the cursor.
|
|
229
248
|
*/
|
|
@@ -251,8 +270,8 @@ interface CompletionMetadata {
|
|
|
251
270
|
|
|
252
271
|
declare class Copilot {
|
|
253
272
|
private readonly apiKey;
|
|
254
|
-
private
|
|
255
|
-
private
|
|
273
|
+
private provider;
|
|
274
|
+
private model;
|
|
256
275
|
/**
|
|
257
276
|
* Initializes the Copilot instance with an API key and optional configuration.
|
|
258
277
|
* @param apiKey - The API key for the chosen provider.
|
|
@@ -270,6 +289,11 @@ declare class Copilot {
|
|
|
270
289
|
* @returns A promise resolving to the completion response or an error.
|
|
271
290
|
*/
|
|
272
291
|
complete(request: CompletionRequest): Promise<CompletionResponse>;
|
|
292
|
+
/**
|
|
293
|
+
* Sets the model and provider for the Copilot.
|
|
294
|
+
* @param options - The options for setting the model and provider.
|
|
295
|
+
*/
|
|
296
|
+
setModel({ model, provider }: SetModelOptions): void;
|
|
273
297
|
}
|
|
274
298
|
|
|
275
299
|
/**
|
package/build/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`),r
|
|
1
|
+
"use strict";var k=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var o in t)k(e,o,{get:t[o],enumerable:!0})},he=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ue(t))!Ce.call(e,n)&&n!==o&&k(e,n,{get:()=>t[n],enumerable:!(r=me(t,n))||r.enumerable});return e};var fe=e=>he(k({},"__esModule",{value:!0}),e);var He={};ge(He,{Copilot:()=>L,registerCompletion:()=>Y,registerCopilot:()=>de});module.exports=fe(He);var H=["groq","openai","anthropic"],X={"llama-3-70b":"llama3-70b-8192","gpt-4o":"gpt-4o-2024-08-06","gpt-4o-mini":"gpt-4o-mini","claude-3.5-sonnet":"claude-3.5-sonnet-20240620","claude-3-opus":"claude-3-opus-20240229","claude-3-sonnet":"claude-3-sonnet-20240229","claude-3-haiku":"claude-3-haiku-20240307","o1-preview":"o1-preview","o1-mini":"o1-mini"},q={groq:["llama-3-70b"],openai:["gpt-4o","gpt-4o-mini","o1-preview","o1-mini"],anthropic:["claude-3.5-sonnet","claude-3-opus","claude-3-haiku","claude-3-sonnet"]},J="llama-3-70b",z="groq",Z={groq:"https://api.groq.com/openai/v1/chat/completions",openai:"https://api.openai.com/v1/chat/completions",anthropic:"https://api.anthropic.com/v1/messages"},M=.1;var x=class x{constructor(){}static getInstance(){return x.instance}handleError(t,o){let r=this.getErrorDetails(t),n=`\x1B[31m[${o}]\x1B[0m \x1B[1m${r.message}\x1B[0m`;return console.error(n),r}getErrorDetails(t){return t instanceof Error?{message:t.message,name:t.name,stack:t.stack,context:t.context}:{message:String(t),name:"UnknownError"}}};x.instance=new x;var $=x;var g=(e,t)=>$.getInstance().handleError(e,t);var I=(e,t)=>{let o=null,r=null,n=(...i)=>new Promise((l,a)=>{o&&(clearTimeout(o),r&&r("Cancelled")),r=a,o=setTimeout(()=>{l(e(...i)),r=null},t)});return n.cancel=()=>{o&&(clearTimeout(o),r&&r("Cancelled"),o=null,r=null)},n},R=e=>!e||e.length===0?"":e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e.slice(-1)}`;var U=(e,t)=>t.getLineContent(e.lineNumber)[e.column-1];var b=(e,t)=>t.getLineContent(e.lineNumber).slice(e.column-1),f=(e,t)=>t.getLineContent(e.lineNumber).slice(0,e.column-1),Q=(e,t)=>t.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:e.lineNumber,endColumn:e.column}),ee=(e,t)=>t.getValueInRange({startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:t.getLineCount(),endColumn:t.getLineMaxColumn(t.getLineCount())}),V=(e,t,o={})=>{if(t<=0)return"";let r=e.split(`
|
|
2
|
+
`),n=r.length;if(t>=n)return e;if(o.from==="end"){let l=r.slice(-t);return l.every(a=>a==="")?`
|
|
3
3
|
`.repeat(t):l.join(`
|
|
4
|
-
`)}let i=
|
|
4
|
+
`)}let i=r.slice(0,t);return i.every(l=>l==="")?`
|
|
5
5
|
`.repeat(t):i.join(`
|
|
6
|
-
`)};var te=async(e,t,o={})=>{let
|
|
6
|
+
`)};var te=async(e,t,o={})=>{let r={"Content-Type":"application/json",...o.headers},n=t==="POST"&&o.body?JSON.stringify(o.body):void 0,i=await fetch(e,{method:t,headers:r,body:n,signal:o.signal});if(!i.ok)throw new Error(`${o.error||"Network error"}: ${i.statusText}`);return i.json()},Ee=(e,t)=>te(e,"GET",t),Pe=(e,t,o)=>te(e,"POST",{...o,body:t}),v={GET:Ee,POST:Pe};var oe=(e,t)=>{let o=b(e,t).trim(),r=f(e,t).trim();return e.column<=3&&(o!==""||r!=="")};var Te="<user-current-cursor-position-is-here>",xe=e=>e==="javascript"?"JavaScript (ESNext)":e,Re=e=>`You are an expert ${xe(e.language)||R(e.technologies)} developer assistant with extensive experience in code completion and adhering to best coding practices. Your role is to provide precise and contextually relevant code completions without any errors, including syntax, punctuation, spaces, tabs, and line breaks. Focus on integrating seamlessly with the existing code and follow the user's instructions carefully.`,ye=e=>{let{filename:t="/",textBeforeCursor:o="",textAfterCursor:r="",relatedFiles:n,editorState:i}=e,p=`
|
|
7
7
|
<guidelines>
|
|
8
8
|
<instruction>${{continue:"Continue writing the code from where the cursor is positioned.",insert:"Insert the appropriate code snippet at the cursor position.",complete:"Provide the necessary code to complete the current statement or block."}[i.completionMode]}</instruction>
|
|
9
9
|
<steps>
|
|
10
|
-
<step>Analyze the provided code and any
|
|
10
|
+
<step>Analyze the provided code and any related files thoroughly.</step>
|
|
11
11
|
<step>Ensure the generated code integrates seamlessly with the existing code.</step>
|
|
12
12
|
<step>Adhere to best practices and maintain consistent coding style.</step>
|
|
13
13
|
<step>Do <strong>not</strong> include the code before the cursor in your response.</step>
|
|
@@ -21,25 +21,25 @@
|
|
|
21
21
|
<context>
|
|
22
22
|
<current_file path="${t}">
|
|
23
23
|
<code>
|
|
24
|
-
${o}${
|
|
24
|
+
${o}${Te}${r}
|
|
25
25
|
</code>
|
|
26
26
|
</current_file>
|
|
27
27
|
</context>
|
|
28
|
-
`,m=
|
|
29
|
-
<
|
|
28
|
+
`,m=n?.map(({path:u,content:c})=>`
|
|
29
|
+
<related_file path="${u}">
|
|
30
30
|
<code>
|
|
31
|
-
${
|
|
31
|
+
${c}
|
|
32
32
|
</code>
|
|
33
|
-
</
|
|
33
|
+
</related_file>
|
|
34
34
|
`).join(`
|
|
35
35
|
`)||"";return`
|
|
36
36
|
<task>
|
|
37
|
-
${
|
|
37
|
+
${p}
|
|
38
38
|
${s}
|
|
39
39
|
${m}
|
|
40
40
|
</task>
|
|
41
|
-
`};function j(e){return{system:
|
|
41
|
+
`};function j(e){return{system:Re(e),user:ye(e)}}var re={"claude-3.5-sonnet":8192,"claude-3-opus":4096,"claude-3-haiku":4096,"claude-3-sonnet":4096};var Oe={createRequestBody:(e,t)=>{let r=e==="o1-preview"||e==="o1-mini"?[{role:"user",content:t.user}]:[{role:"system",content:t.system},{role:"user",content:t.user}];return{model:K(e),temperature:M,messages:r}},createHeaders:e=>({"Content-Type":"application/json",Authorization:`Bearer ${e}`}),parseCompletion:e=>e.choices?.length?e.choices[0].message.content:null},Me={createRequestBody:(e,t)=>({model:K(e),temperature:M,messages:[{role:"system",content:t.system},{role:"user",content:t.user}]}),createHeaders:e=>({"Content-Type":"application/json",Authorization:`Bearer ${e}`}),parseCompletion:e=>e.choices?.length?e.choices[0].message.content:null},Ie={createRequestBody:(e,t)=>({model:K(e),temperature:M,system:t.system,messages:[{role:"user",content:t.user}],max_tokens:be(e)}),createHeaders:e=>({"Content-Type":"application/json","x-api-key":e,"anthropic-version":"2023-06-01"}),parseCompletion:e=>!e.content||typeof e.content!="string"?null:e.content},G={openai:Oe,groq:Me,anthropic:Ie},ne=(e,t,o)=>G[t].createRequestBody(e,o),ie=(e,t)=>G[t].createHeaders(e),se=(e,t)=>G[t].parseCompletion(e),K=e=>X[e],le=e=>Z[e],be=e=>re[e]||4096;var L=class{constructor(t,o={}){if(!t)throw new Error("Please provide an API key.");this.apiKey=t,this.provider=o.provider??z,this.model=o.model??J,this.validateInputs()}validateInputs(){if(!H.includes(this.provider))throw new Error(`The provider "${this.provider}" is not supported. Please choose a supported provider: ${R(H)}. If you're using a custom model, you don't need to specify a provider.`);if(typeof this.model=="string"&&!q[this.provider].includes(this.model)){let t=R(q[this.provider]);throw new Error(`Model "${this.model}" is not supported by the "${this.provider}" provider. Supported models: ${t}`)}}async complete(t){let{body:o,options:r}=t,{completionMetadata:n}=o,{headers:i={},customPrompt:l}=r??{},a=j(n),p=l?{...a,...l(n)}:a,s=le(this.provider),m,u=ie(this.apiKey,this.provider);if(typeof this.model=="object"&&"config"in this.model){let c=this.model.config(this.apiKey,p);s=c.endpoint??s,m=c.body??{},u={...u,...c.headers}}else m=ne(this.model,this.provider,p);u={...u,...i};try{let c=await v.POST(s,m,{headers:u}),d;if(typeof this.model=="object"&&"transformResponse"in this.model){let C=this.model.transformResponse(c);d={completion:C.text??C.completion}}else d={completion:se(c,this.provider)};return d}catch(c){return{error:g(c,"COPILOT_COMPLETION_FETCH_ERROR").message,completion:null}}}setModel({model:t,provider:o}){this.model=t,this.provider=o,this.validateInputs()}};var _=class e{constructor(t){this.formattedCompletion="";this.formattedCompletion=t}static create(t){return new e(t)}setCompletion(t){return this.formattedCompletion=t,this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}removeMarkdownCodeSyntax(){return this.formattedCompletion=this.removeMarkdownCodeBlocks(this.formattedCompletion),this}removeMarkdownCodeBlocks(t){let o=/```[\s\S]*?```/g,r=t,n;for(;(n=o.exec(t))!==null;){let i=n[0],l=i.split(`
|
|
42
42
|
`).slice(1,-1).join(`
|
|
43
|
-
`);
|
|
43
|
+
`);r=r.replace(i,l)}return r.trim()}removeExcessiveNewlines(){return this.formattedCompletion=this.formattedCompletion.replace(/\n{3,}/g,`
|
|
44
44
|
|
|
45
|
-
`),this}build(){return this.formattedCompletion}};var A=class{constructor(t,o){this.cursorPos=t,this.mdl=o}shouldProvideCompletions(){return!oe(this.cursorPos,this.mdl)}};var D=class D{constructor(){this.cache=[]}get(t,o){return this.cache.filter(
|
|
45
|
+
`),this}build(){return this.formattedCompletion}};var A=class{constructor(t,o){this.cursorPos=t,this.mdl=o}shouldProvideCompletions(){return!oe(this.cursorPos,this.mdl)}};var D=class D{constructor(){this.cache=[]}get(t,o){return this.cache.filter(r=>this.isValidCacheItem(r,t,o))}add(t){let o=[...this.cache.slice(-(D.MAX_CACHE_SIZE-1)),t];this.cache=o}clear(){this.cache=[]}isValidCacheItem(t,o,r){let n=r.getValueInRange(t.range);return f(o,r).startsWith(t.textBeforeCursorInLine)&&this.isPositionValid(t,o,n)}isPositionValid(t,o,r){let{range:n,completion:i}=t,{startLineNumber:l,startColumn:a,endColumn:p}=n,{lineNumber:s,column:m}=o,u=s===l&&m===a,c=i.startsWith(r)&&s===l&&m>=a-r.length&&m<=p+r.length;return u||c}};D.MAX_CACHE_SIZE=10;var N=D;var ve="application/json",S=async({filename:e,endpoint:t,language:o,technologies:r,relatedFiles:n,mdl:i,pos:l,maxContextLines:a})=>{try{let{completion:p}=await v.POST(t,{completionMetadata:Le({filename:e,pos:l,mdl:i,language:o,technologies:r,relatedFiles:n,maxContextLines:a})},{headers:{"Content-Type":ve},error:"Error while fetching completion item"});return p}catch(p){return g(p,"FETCH_COMPLETION_ITEM_ERROR"),null}},Le=({filename:e,pos:t,mdl:o,language:r,technologies:n,relatedFiles:i,maxContextLines:l})=>{let a=_e(t,o),s=!!i?.length?3:2,m=l?Math.floor(l/s):void 0,u=(P,T,B)=>{let O=P(t,o);return T?V(O,T,B):O},c=(P,T)=>!P||!T?P:P.map(({content:B,...O})=>({...O,content:V(B,T)})),d=u(Q,m,{from:"end"}),C=u(ee,m),F=c(i,m);return{filename:e,language:r,technologies:n,relatedFiles:F,textBeforeCursor:d,textAfterCursor:C,cursorPosition:t,editorState:{completionMode:a}}},_e=(e,t)=>{let o=U(e,t),r=b(e,t);return o?"insert":r.trim()?"complete":"continue"};var ae=(e,t,o)=>{if(!o)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};let r=t.getOffsetAt(e),n=t.getValue().substring(r),i=0,l=0,a=0,p=o.length,s=n.length;if(r>=t.getValue().length)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};if(s===0)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};let m=Math.min(p,s);for(let d=0;d<m&&o[d]===n[d];d++)i++;for(let d=1;d<=m;d++){let C=o.slice(-d),F=n.slice(0,d);C===F&&(l=d)}if(a=Math.max(i,l),a===0)for(let d=1;d<p;d++){let C=o.substring(d);if(n.startsWith(C)){a=p-d;break}}let u=r+a,c=t.getPositionAt(u);return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:c.lineNumber,endColumn:c.column}},pe=e=>_.create(e).removeMarkdownCodeSyntax().removeExcessiveNewlines().removeInvalidLineBreaks().build(),h=e=>({items:e,enableForwardStability:!0});var Ne=300,De=600,Se=0,we={onTyping:I(S,Ne),onIdle:I(S,De),onDemand:I(S,Se)},w=new N,Fe=async({mdl:e,pos:t,token:o,isCompletionAccepted:r,onShowCompletion:n,options:i})=>{let{trigger:l="onIdle",...a}=i;if(a.externalContext&&(a.relatedFiles=a.externalContext),!new A(t,e).shouldProvideCompletions())return h([]);let p=w.get(t,e).map(s=>({insertText:s.completion,range:{...s.range,endColumn:t.column}}));if(p.length>0)return n(),h(p);if(o.isCancellationRequested||r)return h([]);try{let s=we[l];o.onCancellationRequested(()=>{s.cancel()});let m=await s({...a,text:e.getValue(),mdl:e,pos:t});if(m){let u=pe(m),c=ae(t,e,u);return w.add({completion:u,range:c,textBeforeCursorInLine:f(t,e)}),n(),h([{insertText:u,range:c}])}}catch(s){if(Be(s))return h([]);g(s,"FETCH_COMPLETION_ITEM_ERROR")}return h([])},Be=e=>typeof e=="string"&&(e==="Cancelled"||e==="AbortError")||e instanceof Error&&(e.message==="Cancelled"||e.name==="AbortError"),ce=Fe;var E=new WeakMap,y=null,Y=(e,t,o)=>{y&&y.deregister();let r=[],n={isCompletionAccepted:!1,isCompletionVisible:!1,isManualTrigger:!1};E.set(t,n),t.updateOptions({inlineSuggest:{enabled:!0,mode:"subwordSmart"}});try{let i=e.languages.registerInlineCompletionsProvider(o.language,{provideInlineCompletions:(p,s,m,u)=>{let c=E.get(t);if(!(!c||o.trigger==="onDemand"&&!c.isManualTrigger))return ce({mdl:p,pos:s,token:u,isCompletionAccepted:c.isCompletionAccepted,onShowCompletion:()=>{c.isCompletionVisible=!0,c.isManualTrigger=!1},options:o})},freeInlineCompletions:()=>{}});r.push(i);let l=t.onKeyDown(p=>{let s=E.get(t);if(!s)return;let m=p.keyCode===e.KeyCode.Tab||p.keyCode===e.KeyCode.RightArrow&&p.metaKey;s.isCompletionVisible&&m?(s.isCompletionAccepted=!0,s.isCompletionVisible=!1):s.isCompletionAccepted=!1});r.push(l);let a={deregister:()=>{r.forEach(p=>p.dispose()),w.clear(),E.delete(t),y=null},trigger:()=>ke(t)};return y=a,a}catch(i){return g(i,"REGISTER_COMPLETION_ERROR"),{deregister:()=>{r.forEach(l=>l.dispose()),E.delete(t),y=null},trigger:()=>{}}}},ke=e=>{let t=E.get(e);if(!t){g(new Error("Completion is not registered. Use `registerCompletion` to register completion first."),"TRIGGER_COMPLETION_ERROR");return}t.isManualTrigger=!0,e.trigger("keyboard","editor.action.inlineSuggest.trigger",{})},de=Y;0&&(module.exports={Copilot,registerCompletion,registerCopilot});
|
package/build/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),r
|
|
1
|
+
var B=["groq","openai","anthropic"],W={"llama-3-70b":"llama3-70b-8192","gpt-4o":"gpt-4o-2024-08-06","gpt-4o-mini":"gpt-4o-mini","claude-3.5-sonnet":"claude-3.5-sonnet-20240620","claude-3-opus":"claude-3-opus-20240229","claude-3-sonnet":"claude-3-sonnet-20240229","claude-3-haiku":"claude-3-haiku-20240307","o1-preview":"o1-preview","o1-mini":"o1-mini"},k={groq:["llama-3-70b"],openai:["gpt-4o","gpt-4o-mini","o1-preview","o1-mini"],anthropic:["claude-3.5-sonnet","claude-3-opus","claude-3-haiku","claude-3-sonnet"]},Y="llama-3-70b",X="groq",J={groq:"https://api.groq.com/openai/v1/chat/completions",openai:"https://api.openai.com/v1/chat/completions",anthropic:"https://api.anthropic.com/v1/messages"},M=.1;var x=class x{constructor(){}static getInstance(){return x.instance}handleError(t,o){let r=this.getErrorDetails(t),n=`\x1B[31m[${o}]\x1B[0m \x1B[1m${r.message}\x1B[0m`;return console.error(n),r}getErrorDetails(t){return t instanceof Error?{message:t.message,name:t.name,stack:t.stack,context:t.context}:{message:String(t),name:"UnknownError"}}};x.instance=new x;var H=x;var g=(e,t)=>H.getInstance().handleError(e,t);var I=(e,t)=>{let o=null,r=null,n=(...i)=>new Promise((l,a)=>{o&&(clearTimeout(o),r&&r("Cancelled")),r=a,o=setTimeout(()=>{l(e(...i)),r=null},t)});return n.cancel=()=>{o&&(clearTimeout(o),r&&r("Cancelled"),o=null,r=null)},n},R=e=>!e||e.length===0?"":e.length===1?e[0]:`${e.slice(0,-1).join(", ")} and ${e.slice(-1)}`;var q=(e,t)=>t.getLineContent(e.lineNumber)[e.column-1];var b=(e,t)=>t.getLineContent(e.lineNumber).slice(e.column-1),f=(e,t)=>t.getLineContent(e.lineNumber).slice(0,e.column-1),z=(e,t)=>t.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:e.lineNumber,endColumn:e.column}),Z=(e,t)=>t.getValueInRange({startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:t.getLineCount(),endColumn:t.getLineMaxColumn(t.getLineCount())}),$=(e,t,o={})=>{if(t<=0)return"";let r=e.split(`
|
|
2
|
+
`),n=r.length;if(t>=n)return e;if(o.from==="end"){let l=r.slice(-t);return l.every(a=>a==="")?`
|
|
3
3
|
`.repeat(t):l.join(`
|
|
4
|
-
`)}let i=
|
|
4
|
+
`)}let i=r.slice(0,t);return i.every(l=>l==="")?`
|
|
5
5
|
`.repeat(t):i.join(`
|
|
6
|
-
`)};var Q=async(e,t,o={})=>{let
|
|
6
|
+
`)};var Q=async(e,t,o={})=>{let r={"Content-Type":"application/json",...o.headers},n=t==="POST"&&o.body?JSON.stringify(o.body):void 0,i=await fetch(e,{method:t,headers:r,body:n,signal:o.signal});if(!i.ok)throw new Error(`${o.error||"Network error"}: ${i.statusText}`);return i.json()},ce=(e,t)=>Q(e,"GET",t),de=(e,t,o)=>Q(e,"POST",{...o,body:t}),v={GET:ce,POST:de};var ee=(e,t)=>{let o=b(e,t).trim(),r=f(e,t).trim();return e.column<=3&&(o!==""||r!=="")};var me="<user-current-cursor-position-is-here>",ue=e=>e==="javascript"?"JavaScript (ESNext)":e,Ce=e=>`You are an expert ${ue(e.language)||R(e.technologies)} developer assistant with extensive experience in code completion and adhering to best coding practices. Your role is to provide precise and contextually relevant code completions without any errors, including syntax, punctuation, spaces, tabs, and line breaks. Focus on integrating seamlessly with the existing code and follow the user's instructions carefully.`,ge=e=>{let{filename:t="/",textBeforeCursor:o="",textAfterCursor:r="",relatedFiles:n,editorState:i}=e,p=`
|
|
7
7
|
<guidelines>
|
|
8
8
|
<instruction>${{continue:"Continue writing the code from where the cursor is positioned.",insert:"Insert the appropriate code snippet at the cursor position.",complete:"Provide the necessary code to complete the current statement or block."}[i.completionMode]}</instruction>
|
|
9
9
|
<steps>
|
|
10
|
-
<step>Analyze the provided code and any
|
|
10
|
+
<step>Analyze the provided code and any related files thoroughly.</step>
|
|
11
11
|
<step>Ensure the generated code integrates seamlessly with the existing code.</step>
|
|
12
12
|
<step>Adhere to best practices and maintain consistent coding style.</step>
|
|
13
13
|
<step>Do <strong>not</strong> include the code before the cursor in your response.</step>
|
|
@@ -21,25 +21,25 @@ var k=["groq","openai","anthropic"],W={"llama-3-70b":"llama3-70b-8192","gpt-4o":
|
|
|
21
21
|
<context>
|
|
22
22
|
<current_file path="${t}">
|
|
23
23
|
<code>
|
|
24
|
-
${o}${me}${
|
|
24
|
+
${o}${me}${r}
|
|
25
25
|
</code>
|
|
26
26
|
</current_file>
|
|
27
27
|
</context>
|
|
28
|
-
`,m=
|
|
29
|
-
<
|
|
28
|
+
`,m=n?.map(({path:u,content:c})=>`
|
|
29
|
+
<related_file path="${u}">
|
|
30
30
|
<code>
|
|
31
|
-
${
|
|
31
|
+
${c}
|
|
32
32
|
</code>
|
|
33
|
-
</
|
|
33
|
+
</related_file>
|
|
34
34
|
`).join(`
|
|
35
35
|
`)||"";return`
|
|
36
36
|
<task>
|
|
37
|
-
${
|
|
37
|
+
${p}
|
|
38
38
|
${s}
|
|
39
39
|
${m}
|
|
40
40
|
</task>
|
|
41
|
-
`};function U(e){return{system:Ce(e),user:ge(e)}}var te={"claude-3.5-sonnet":8192,"claude-3-opus":4096,"claude-3-haiku":4096,"claude-3-sonnet":4096};var he={createRequestBody:(e,t)=>{let
|
|
41
|
+
`};function U(e){return{system:Ce(e),user:ge(e)}}var te={"claude-3.5-sonnet":8192,"claude-3-opus":4096,"claude-3-haiku":4096,"claude-3-sonnet":4096};var he={createRequestBody:(e,t)=>{let r=e==="o1-preview"||e==="o1-mini"?[{role:"user",content:t.user}]:[{role:"system",content:t.system},{role:"user",content:t.user}];return{model:j(e),temperature:M,messages:r}},createHeaders:e=>({"Content-Type":"application/json",Authorization:`Bearer ${e}`}),parseCompletion:e=>e.choices?.length?e.choices[0].message.content:null},fe={createRequestBody:(e,t)=>({model:j(e),temperature:M,messages:[{role:"system",content:t.system},{role:"user",content:t.user}]}),createHeaders:e=>({"Content-Type":"application/json",Authorization:`Bearer ${e}`}),parseCompletion:e=>e.choices?.length?e.choices[0].message.content:null},Ee={createRequestBody:(e,t)=>({model:j(e),temperature:M,system:t.system,messages:[{role:"user",content:t.user}],max_tokens:Pe(e)}),createHeaders:e=>({"Content-Type":"application/json","x-api-key":e,"anthropic-version":"2023-06-01"}),parseCompletion:e=>!e.content||typeof e.content!="string"?null:e.content},V={openai:he,groq:fe,anthropic:Ee},oe=(e,t,o)=>V[t].createRequestBody(e,o),re=(e,t)=>V[t].createHeaders(e),ne=(e,t)=>V[t].parseCompletion(e),j=e=>W[e],ie=e=>J[e],Pe=e=>te[e]||4096;var G=class{constructor(t,o={}){if(!t)throw new Error("Please provide an API key.");this.apiKey=t,this.provider=o.provider??X,this.model=o.model??Y,this.validateInputs()}validateInputs(){if(!B.includes(this.provider))throw new Error(`The provider "${this.provider}" is not supported. Please choose a supported provider: ${R(B)}. If you're using a custom model, you don't need to specify a provider.`);if(typeof this.model=="string"&&!k[this.provider].includes(this.model)){let t=R(k[this.provider]);throw new Error(`Model "${this.model}" is not supported by the "${this.provider}" provider. Supported models: ${t}`)}}async complete(t){let{body:o,options:r}=t,{completionMetadata:n}=o,{headers:i={},customPrompt:l}=r??{},a=U(n),p=l?{...a,...l(n)}:a,s=ie(this.provider),m,u=re(this.apiKey,this.provider);if(typeof this.model=="object"&&"config"in this.model){let c=this.model.config(this.apiKey,p);s=c.endpoint??s,m=c.body??{},u={...u,...c.headers}}else m=oe(this.model,this.provider,p);u={...u,...i};try{let c=await v.POST(s,m,{headers:u}),d;if(typeof this.model=="object"&&"transformResponse"in this.model){let C=this.model.transformResponse(c);d={completion:C.text??C.completion}}else d={completion:ne(c,this.provider)};return d}catch(c){return{error:g(c,"COPILOT_COMPLETION_FETCH_ERROR").message,completion:null}}}setModel({model:t,provider:o}){this.model=t,this.provider=o,this.validateInputs()}};var L=class e{constructor(t){this.formattedCompletion="";this.formattedCompletion=t}static create(t){return new e(t)}setCompletion(t){return this.formattedCompletion=t,this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}removeMarkdownCodeSyntax(){return this.formattedCompletion=this.removeMarkdownCodeBlocks(this.formattedCompletion),this}removeMarkdownCodeBlocks(t){let o=/```[\s\S]*?```/g,r=t,n;for(;(n=o.exec(t))!==null;){let i=n[0],l=i.split(`
|
|
42
42
|
`).slice(1,-1).join(`
|
|
43
|
-
`);
|
|
43
|
+
`);r=r.replace(i,l)}return r.trim()}removeExcessiveNewlines(){return this.formattedCompletion=this.formattedCompletion.replace(/\n{3,}/g,`
|
|
44
44
|
|
|
45
|
-
`),this}build(){return this.formattedCompletion}};var _=class{constructor(t,o){this.cursorPos=t,this.mdl=o}shouldProvideCompletions(){return!ee(this.cursorPos,this.mdl)}};var N=class N{constructor(){this.cache=[]}get(t,o){return this.cache.filter(
|
|
45
|
+
`),this}build(){return this.formattedCompletion}};var _=class{constructor(t,o){this.cursorPos=t,this.mdl=o}shouldProvideCompletions(){return!ee(this.cursorPos,this.mdl)}};var N=class N{constructor(){this.cache=[]}get(t,o){return this.cache.filter(r=>this.isValidCacheItem(r,t,o))}add(t){let o=[...this.cache.slice(-(N.MAX_CACHE_SIZE-1)),t];this.cache=o}clear(){this.cache=[]}isValidCacheItem(t,o,r){let n=r.getValueInRange(t.range);return f(o,r).startsWith(t.textBeforeCursorInLine)&&this.isPositionValid(t,o,n)}isPositionValid(t,o,r){let{range:n,completion:i}=t,{startLineNumber:l,startColumn:a,endColumn:p}=n,{lineNumber:s,column:m}=o,u=s===l&&m===a,c=i.startsWith(r)&&s===l&&m>=a-r.length&&m<=p+r.length;return u||c}};N.MAX_CACHE_SIZE=10;var A=N;var Te="application/json",D=async({filename:e,endpoint:t,language:o,technologies:r,relatedFiles:n,mdl:i,pos:l,maxContextLines:a})=>{try{let{completion:p}=await v.POST(t,{completionMetadata:xe({filename:e,pos:l,mdl:i,language:o,technologies:r,relatedFiles:n,maxContextLines:a})},{headers:{"Content-Type":Te},error:"Error while fetching completion item"});return p}catch(p){return g(p,"FETCH_COMPLETION_ITEM_ERROR"),null}},xe=({filename:e,pos:t,mdl:o,language:r,technologies:n,relatedFiles:i,maxContextLines:l})=>{let a=Re(t,o),s=!!i?.length?3:2,m=l?Math.floor(l/s):void 0,u=(P,T,F)=>{let O=P(t,o);return T?$(O,T,F):O},c=(P,T)=>!P||!T?P:P.map(({content:F,...O})=>({...O,content:$(F,T)})),d=u(z,m,{from:"end"}),C=u(Z,m),w=c(i,m);return{filename:e,language:r,technologies:n,relatedFiles:w,textBeforeCursor:d,textAfterCursor:C,cursorPosition:t,editorState:{completionMode:a}}},Re=(e,t)=>{let o=q(e,t),r=b(e,t);return o?"insert":r.trim()?"complete":"continue"};var se=(e,t,o)=>{if(!o)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};let r=t.getOffsetAt(e),n=t.getValue().substring(r),i=0,l=0,a=0,p=o.length,s=n.length;if(r>=t.getValue().length)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};if(s===0)return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:e.lineNumber,endColumn:e.column};let m=Math.min(p,s);for(let d=0;d<m&&o[d]===n[d];d++)i++;for(let d=1;d<=m;d++){let C=o.slice(-d),w=n.slice(0,d);C===w&&(l=d)}if(a=Math.max(i,l),a===0)for(let d=1;d<p;d++){let C=o.substring(d);if(n.startsWith(C)){a=p-d;break}}let u=r+a,c=t.getPositionAt(u);return{startLineNumber:e.lineNumber,startColumn:e.column,endLineNumber:c.lineNumber,endColumn:c.column}},le=e=>L.create(e).removeMarkdownCodeSyntax().removeExcessiveNewlines().removeInvalidLineBreaks().build(),h=e=>({items:e,enableForwardStability:!0});var Oe=300,Me=600,Ie=0,be={onTyping:I(D,Oe),onIdle:I(D,Me),onDemand:I(D,Ie)},S=new A,ve=async({mdl:e,pos:t,token:o,isCompletionAccepted:r,onShowCompletion:n,options:i})=>{let{trigger:l="onIdle",...a}=i;if(a.externalContext&&(a.relatedFiles=a.externalContext),!new _(t,e).shouldProvideCompletions())return h([]);let p=S.get(t,e).map(s=>({insertText:s.completion,range:{...s.range,endColumn:t.column}}));if(p.length>0)return n(),h(p);if(o.isCancellationRequested||r)return h([]);try{let s=be[l];o.onCancellationRequested(()=>{s.cancel()});let m=await s({...a,text:e.getValue(),mdl:e,pos:t});if(m){let u=le(m),c=se(t,e,u);return S.add({completion:u,range:c,textBeforeCursorInLine:f(t,e)}),n(),h([{insertText:u,range:c}])}}catch(s){if(Le(s))return h([]);g(s,"FETCH_COMPLETION_ITEM_ERROR")}return h([])},Le=e=>typeof e=="string"&&(e==="Cancelled"||e==="AbortError")||e instanceof Error&&(e.message==="Cancelled"||e.name==="AbortError"),ae=ve;var E=new WeakMap,y=null,pe=(e,t,o)=>{y&&y.deregister();let r=[],n={isCompletionAccepted:!1,isCompletionVisible:!1,isManualTrigger:!1};E.set(t,n),t.updateOptions({inlineSuggest:{enabled:!0,mode:"subwordSmart"}});try{let i=e.languages.registerInlineCompletionsProvider(o.language,{provideInlineCompletions:(p,s,m,u)=>{let c=E.get(t);if(!(!c||o.trigger==="onDemand"&&!c.isManualTrigger))return ae({mdl:p,pos:s,token:u,isCompletionAccepted:c.isCompletionAccepted,onShowCompletion:()=>{c.isCompletionVisible=!0,c.isManualTrigger=!1},options:o})},freeInlineCompletions:()=>{}});r.push(i);let l=t.onKeyDown(p=>{let s=E.get(t);if(!s)return;let m=p.keyCode===e.KeyCode.Tab||p.keyCode===e.KeyCode.RightArrow&&p.metaKey;s.isCompletionVisible&&m?(s.isCompletionAccepted=!0,s.isCompletionVisible=!1):s.isCompletionAccepted=!1});r.push(l);let a={deregister:()=>{r.forEach(p=>p.dispose()),S.clear(),E.delete(t),y=null},trigger:()=>_e(t)};return y=a,a}catch(i){return g(i,"REGISTER_COMPLETION_ERROR"),{deregister:()=>{r.forEach(l=>l.dispose()),E.delete(t),y=null},trigger:()=>{}}}},_e=e=>{let t=E.get(e);if(!t){g(new Error("Completion is not registered. Use `registerCompletion` to register completion first."),"TRIGGER_COMPLETION_ERROR");return}t.isManualTrigger=!0,e.trigger("keyboard","editor.action.inlineSuggest.trigger",{})},Ae=pe;export{G as Copilot,pe as registerCompletion,Ae as registerCopilot};
|