monacopilot 0.9.8 → 0.9.10

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/build/index.d.mts CHANGED
@@ -58,10 +58,10 @@ interface RegisterCopilotOptions {
58
58
  }
59
59
  interface CopilotRegistration {
60
60
  /**
61
- * Unregisters the Copilot from the Monaco editor.
61
+ * Deregisters the Copilot from the Monaco editor.
62
62
  * This should be called when the Copilot is no longer needed.
63
63
  */
64
- unregister: () => void;
64
+ deregister: () => void;
65
65
  }
66
66
 
67
67
  type CompletionModel = 'llama';
@@ -90,6 +90,7 @@ interface CompletionMetadata {
90
90
  */
91
91
  declare class Copilot {
92
92
  private readonly apiKey;
93
+ private readonly model;
93
94
  /**
94
95
  * Initializes the Copilot with an API key and optional configuration.
95
96
  * @param {string} apiKey - The Groq API key.
@@ -112,7 +113,7 @@ declare class Copilot {
112
113
  * @param monaco The Monaco instance.
113
114
  * @param editor The editor instance.
114
115
  * @param options The options for the Copilot.
115
- * @returns CopilotRegistration object with an unregister method.
116
+ * @returns CopilotRegistration object with a deregister method.
116
117
  */
117
118
  declare const registerCopilot: (monaco: Monaco, editor: StandaloneCodeEditor, options: RegisterCopilotOptions) => CopilotRegistration;
118
119
 
package/build/index.d.ts CHANGED
@@ -58,10 +58,10 @@ interface RegisterCopilotOptions {
58
58
  }
59
59
  interface CopilotRegistration {
60
60
  /**
61
- * Unregisters the Copilot from the Monaco editor.
61
+ * Deregisters the Copilot from the Monaco editor.
62
62
  * This should be called when the Copilot is no longer needed.
63
63
  */
64
- unregister: () => void;
64
+ deregister: () => void;
65
65
  }
66
66
 
67
67
  type CompletionModel = 'llama';
@@ -90,6 +90,7 @@ interface CompletionMetadata {
90
90
  */
91
91
  declare class Copilot {
92
92
  private readonly apiKey;
93
+ private readonly model;
93
94
  /**
94
95
  * Initializes the Copilot with an API key and optional configuration.
95
96
  * @param {string} apiKey - The Groq API key.
@@ -112,7 +113,7 @@ declare class Copilot {
112
113
  * @param monaco The Monaco instance.
113
114
  * @param editor The editor instance.
114
115
  * @param options The options for the Copilot.
115
- * @returns CopilotRegistration object with an unregister method.
116
+ * @returns CopilotRegistration object with a deregister method.
116
117
  */
117
118
  declare const registerCopilot: (monaco: Monaco, editor: StandaloneCodeEditor, options: RegisterCopilotOptions) => CopilotRegistration;
118
119
 
package/build/index.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";var b=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var ie=(t,e)=>{for(var o in e)b(t,o,{get:e[o],enumerable:!0})},se=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of re(e))!ne.call(t,i)&&i!==o&&b(t,i,{get:()=>e[i],enumerable:!(r=oe(e,i))||r.enumerable});return t};var le=t=>se(b({},"__esModule",{value:!0}),t);var Ee={};ie(Ee,{Copilot:()=>M,registerCopilot:()=>te});module.exports=le(Ee);var O=()=>{},S=(t,e=1e3)=>{let o=null;return(...i)=>(o&&clearTimeout(o),new Promise((n,s)=>{o=setTimeout(()=>{t(...i).then(n).catch(s)},e)}))},_=t=>!t||t.length===0?"":t.length===1?t[0]:`${t.slice(0,-1).join(", ")} and ${t.slice(-1)}`;var E=(t,e)=>e.getLineContent(t.lineNumber)[t.column-1],B=(t,e)=>e.getLineContent(t.lineNumber).slice(t.column-1),u=(t,e)=>e.getLineContent(t.lineNumber).slice(0,t.column-1),D=t=>{let e=t.split(`
2
- `);return e[e.length-1].length};var C=(t,e)=>e.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:t.lineNumber,endColumn:t.column}),I=(t,e)=>e.getValueInRange({startLineNumber:t.lineNumber,startColumn:t.column,endLineNumber:e.getLineCount(),endColumn:e.getLineMaxColumn(e.getLineCount())});var $=async(t,e,o={})=>{let r={"Content-Type":"application/json",...o.headers},i=e==="POST"&&o.body?JSON.stringify(o.body):void 0,n=await fetch(t,{method:e,headers:r,body:i,signal:o.signal});if(!n.ok)throw new Error(`${o.error||"Network error"}: ${n.statusText}`);return n.json()},ae=(t,e)=>$(t,"GET",e),me=(t,e,o)=>$(t,"POST",{...o,body:e}),x={GET:ae,POST:me};var T=class{constructor(e,o){this.formattedCompletion="";this.originalCompletion="";this.model=e,this.cursorPosition=o,this.lineCount=e.getLineCount()}ignoreBlankLines(){return this.formattedCompletion.trimStart()===""&&this.originalCompletion!==`
3
- `&&(this.formattedCompletion=this.formattedCompletion.trim()),this}normalise(e){return e?.trim()??""}removeDuplicatesFromStartOfCompletion(){let e=C(this.cursorPosition,this.model).trim(),o=this.normalise(this.formattedCompletion),r=0,i=Math.min(o.length,e.length);for(let n=1;n<=i;n++){let s=e.slice(-n),l=o.slice(0,n);if(s===l)r=n;else break}return r>0&&(this.formattedCompletion=this.formattedCompletion.slice(r)),this}preventDuplicateLines(){for(let e=this.cursorPosition.lineNumber+1;e<this.cursorPosition.lineNumber+3&&e<this.lineCount;e++){let o=this.model.getLineContent(e);if(this.normalise(o)===this.normalise(this.originalCompletion))return this.formattedCompletion="",this}return this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}trimStart(){let e=this.formattedCompletion.search(/\S/);return e>this.cursorPosition.column-1&&(this.formattedCompletion=this.formattedCompletion.slice(e)),this}format(e){return this.originalCompletion=e,this.formattedCompletion=e,this.ignoreBlankLines().removeDuplicatesFromStartOfCompletion().preventDuplicateLines().removeInvalidLineBreaks().trimStart(),this.formattedCompletion}};var pe=10,g=[],k=(t,e)=>g.filter(o=>{let r=e.getValueInRange(o.range);return u(t,e).startsWith(o.textBeforeCursorInLine)&&(o.range.startLineNumber===t.lineNumber&&t.column===o.range.startColumn||o.completion.startsWith(r)&&o.range.startLineNumber===t.lineNumber&&t.column>=o.range.startColumn-r.length&&t.column<=o.range.endColumn)}),q=t=>{g.length>=pe&&g.shift(),g.push(t)},F=()=>{g.length=0};var U={llama:"llama3-70b-8192"},y="llama",G="https://api.groq.com/openai/v1/chat/completions",j={temperature:.3};var H=new Set(['"',"'","`","{","}","[","]","(",")",","," ",":","."]);var W=(t,e)=>{let o=E(t,e);return!!o&&!H.has(o)},K=(t,e)=>{let o=B(t,e).trim(),r=u(t,e).trim();return t.column<=3&&(o!==""||r!=="")};var Y=(t,e,o,r)=>{let i=(t.match(/\n/g)||[]).length,n=D(t),s=E(o,r);return{startLineNumber:o.lineNumber,startColumn:o.column,endLineNumber:o.lineNumber+i,endColumn:t.includes(s)?o.lineNumber===e.startLineNumber&&i===0?o.column+n:n:o.column}},z=(t,e,o)=>new T(t,e).format(o),c=t=>({items:t,enableForwardStability:!0});var P=class{constructor(e,o){this.cursorPosition=e,this.model=o}shouldProvideCompletions(){return!W(this.cursorPosition,this.model)&&!K(this.cursorPosition,this.model)}};var R=class{static getModel(){return this.model}static setModel(e){this.model=e}};R.model=y;var L=R;var v=class{constructor(e){this.error=e}logError(e,o,r){console.error(`${e}: ${o}`,r)}monacopilotError(e){this.logError("MONACO_PILOT_ERROR",e,this.error)}apiError(e){this.logError("API_ERROR",e,this.error)}completionError(e){this.logError("COMPLETION_ERROR",e,this.error)}predictionError(e){this.logError("PREDICTION_ERROR",e,this.error)}editorError(e){this.logError("EDITOR_ERROR",e,this.error)}unexpectedError(){this.error instanceof Error?this.logError("UNEXPECTED_ERROR",this.error.message,this.error.stack):this.logError("UNKNOWN_ERROR",String(this.error))}},m=t=>new v(t);var h="<<CURSOR>>",V=t=>t==="javascript"?"latest JavaScript":t,J=t=>{switch(t){case"fill-in-the-middle":return"filling in the middle of the code";case"completion":return"completing the code"}},Q=t=>{let e=V(t.language),o=J(t.editorState.completionMode),r=e?` ${e}`:"";return`You are an advanced AI coding assistant with expertise in ${o} for${r} programming. Your goal is to provide accurate, efficient, and context-aware code completions.
1
+ "use strict";var L=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ae=(o,e)=>{for(var t in e)L(o,t,{get:e[t],enumerable:!0})},le=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ie(e))!se.call(o,n)&&n!==t&&L(o,n,{get:()=>e[n],enumerable:!(r=ne(e,n))||r.enumerable});return o};var me=o=>le(L({},"__esModule",{value:!0}),o);var xe={};ae(xe,{Copilot:()=>O,registerCopilot:()=>re});module.exports=me(xe);var w=()=>{},S=(o,e=1e3)=>{let t=null;return(...n)=>(t&&clearTimeout(t),new Promise((i,s)=>{t=setTimeout(()=>{o(...n).then(i).catch(s)},e)}))},_=o=>!o||o.length===0?"":o.length===1?o[0]:`${o.slice(0,-1).join(", ")} and ${o.slice(-1)}`;var x=(o,e)=>e.getLineContent(o.lineNumber)[o.column-1],B=(o,e)=>e.getLineContent(o.lineNumber).slice(o.column-1),d=(o,e)=>e.getLineContent(o.lineNumber).slice(0,o.column-1),$=o=>{let e=o.split(`
2
+ `);return e[e.length-1].length};var g=(o,e)=>e.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:o.lineNumber,endColumn:o.column}),b=(o,e)=>e.getValueInRange({startLineNumber:o.lineNumber,startColumn:o.column,endLineNumber:e.getLineCount(),endColumn:e.getLineMaxColumn(e.getLineCount())});var D=async(o,e,t={})=>{let r={"Content-Type":"application/json",...t.headers},n=e==="POST"&&t.body?JSON.stringify(t.body):void 0,i=await fetch(o,{method:e,headers:r,body:n,signal:t.signal});if(!i.ok)throw new Error(`${t.error||"Network error"}: ${i.statusText}`);return i.json()},pe=(o,e)=>D(o,"GET",e),ce=(o,e,t)=>D(o,"POST",{...t,body:e}),y={GET:pe,POST:ce};var P=class{constructor(e,t){this.formattedCompletion="";this.originalCompletion="";this.model=e,this.cursorPosition=t,this.lineCount=e.getLineCount()}ignoreBlankLines(){return this.formattedCompletion.trimStart()===""&&this.originalCompletion!==`
3
+ `&&(this.formattedCompletion=this.formattedCompletion.trim()),this}normalise(e){return e?.trim()??""}removeDuplicatesFromStartOfCompletion(){let e=g(this.cursorPosition,this.model).trim(),t=this.normalise(this.formattedCompletion),r=0,n=Math.min(t.length,e.length);for(let i=1;i<=n;i++){let s=e.slice(-i),a=t.slice(0,i);if(s===a)r=i;else break}return r>0&&(this.formattedCompletion=this.formattedCompletion.slice(r)),this}preventDuplicateLines(){for(let e=this.cursorPosition.lineNumber+1;e<this.cursorPosition.lineNumber+3&&e<this.lineCount;e++){let t=this.model.getLineContent(e);if(this.normalise(t)===this.normalise(this.originalCompletion))return this.formattedCompletion="",this}return this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}trimStart(){let e=this.formattedCompletion.search(/\S/);return e>this.cursorPosition.column-1&&(this.formattedCompletion=this.formattedCompletion.slice(e)),this}format(e){return this.originalCompletion=e,this.formattedCompletion=e,this.ignoreBlankLines().removeDuplicatesFromStartOfCompletion().preventDuplicateLines().removeInvalidLineBreaks().trimStart(),this.formattedCompletion}};var de=10,f=[],q=(o,e)=>f.filter(t=>{let r=e.getValueInRange(t.range);return d(o,e).startsWith(t.textBeforeCursorInLine)&&(t.range.startLineNumber===o.lineNumber&&o.column===t.range.startColumn||t.completion.startsWith(r)&&t.range.startLineNumber===o.lineNumber&&o.column>=t.range.startColumn-r.length&&o.column<=t.range.endColumn)}),k=o=>{f.length>=de&&f.shift(),f.push(o)},F=()=>{f.length=0};var G={llama:"llama3-70b-8192"},H="llama",U="https://api.groq.com/openai/v1/chat/completions",j={temperature:.3};var W=new Set(['"',"'","`","{","}","[","]","(",")",","," ",":","."]);var Y=(o,e)=>{let t=x(o,e);return!!t&&!W.has(t)},z=(o,e)=>{let t=B(o,e).trim(),r=d(o,e).trim();return o.column<=3&&(t!==""||r!=="")};var K=(o,e,t,r)=>{let n=(o.match(/\n/g)||[]).length,i=$(o),s=x(t,r);return{startLineNumber:t.lineNumber,startColumn:t.column,endLineNumber:t.lineNumber+n,endColumn:o.includes(s)?t.lineNumber===e.startLineNumber&&n===0?t.column+i:i:t.column}},V=(o,e,t)=>new P(o,e).format(t),u=o=>({items:o,enableForwardStability:!0});var I=class{constructor(e,t){this.cursorPosition=e,this.model=t}shouldProvideCompletions(){return!Y(this.cursorPosition,this.model)&&!z(this.cursorPosition,this.model)}};var h=class h{constructor(){}static getInstance(){return h.instance}log(e,...t){console.log(`[LOG] ${e}`,...t)}info(e,...t){console.info(`[INFO] ${e}`,...t)}warn(e,...t){console.warn(`[WARN] ${e}`,...t)}error(e,...t){console.error(`[ERROR] ${e}`,...t)}debug(e,...t){console.debug(`[DEBUG] ${e}`,...t)}};h.instance=new h;var v=h,J=()=>v.getInstance();var E=class E{constructor(){this.logger=J()}static getInstance(){return E.instance}handleError(e,t){let r=this.getErrorDetails(e);this.logger.error(`${t}: ${r.message}`,r)}getErrorDetails(e){return e instanceof Error?{message:e.message,name:e.name,stack:e.stack}:{message:String(e),name:"UnknownError"}}};E.instance=new E;var N=E;var m=(o,e)=>{N.getInstance().handleError(o,e)};var T="<<CURSOR>>",X=o=>o==="javascript"?"latest JavaScript":o,Q=o=>{switch(o){case"fill-in-the-middle":return"filling in the middle of the code";case"completion":return"completing the code"}},Z=o=>{let e=X(o.language),t=Q(o.editorState.completionMode),r=e?` ${e}`:"";return`You are an advanced AI coding assistant with expertise in ${t} for${r} programming. Your goal is to provide accurate, efficient, and context-aware code completions.
4
4
 
5
5
  ### Instructions:
6
6
  - Provide only the requested code completion without any additional explanations or markdown.
7
7
  - Ensure your suggestions seamlessly integrate with the existing code structure and style.
8
8
  - Maintain consistent indentation and formatting with the surrounding code.
9
- - Start your completion exactly at the cursor position (${h}).
9
+ - Start your completion exactly at the cursor position (${T}).
10
10
  - Do not repeat any existing code before or after the cursor.
11
11
  - Respect the project's coding conventions, naming styles, and design patterns.
12
12
  - Consider the broader context of the file and project when making suggestions.
@@ -16,14 +16,7 @@
16
16
  - If multiple valid completions exist, choose the most likely and idiomatic one.
17
17
  - If you cannot provide a meaningful completion, return an empty string.
18
18
 
19
- ### Formatting Rules:
20
- - Do not include any markdown or code block syntax.
21
- - Insert newlines after opening brackets ({, [, () and before closing brackets (}, ], )).
22
- - Add newlines after commas in multi-line structures.
23
- - Do not suggest newlines after spaces or existing newlines.
24
- - Match the indentation level of the current line for new lines.
25
-
26
- Remember, your role is to act as an extension of the developer's thought process, providing intelligent and contextually appropriate code completions.`},ce=(t,e)=>{if(!t?.length&&!e)return"";let o=t?` using ${_(t)}`:"",r=V(e);return`The code is written${r?` in ${r}`:""}${o}.`},X=t=>{let{filename:e,language:o,technologies:r,editorState:i,textBeforeCursor:n,textAfterCursor:s,externalContext:l}=t,p=J(i.completionMode),f=e?`the file named "${e}"`:"a larger project",a=`You are tasked with ${p} for a code snippet. The code is part of ${f}.
19
+ Remember, your role is to act as an extension of the developer's thought process, providing intelligent and contextually appropriate code completions.`},ue=(o,e)=>{if(!o?.length&&!e)return"";let t=o?` using ${_(o)}`:"",r=X(e);return`The code is written${r?` in ${r}`:""}${t}.`},ee=o=>{let{filename:e,language:t,technologies:r,editorState:n,textBeforeCursor:i,textAfterCursor:s,externalContext:a}=o,l=Q(n.completionMode),p=e?`the file named "${e}"`:"a larger project",c=`You are tasked with ${l} for a code snippet. The code is part of ${p}.
27
20
 
28
21
  Your objective is to:
29
22
  1. Analyze the provided code snippet and its context.
@@ -32,15 +25,15 @@
32
25
  4. Adhere to the project's coding style and conventions.
33
26
  5. Consider the broader context of the file and any provided external context.
34
27
 
35
- ${ce(r,o)}
28
+ ${ue(r,t)}
36
29
 
37
30
  Specific instructions:
38
- - The cursor position is marked with '${h}'.
31
+ - The cursor position is marked with '${T}'.
39
32
  - Your completion must start exactly at the cursor position.
40
33
  - Do not repeat any code that appears before or after the cursor.
41
34
  - Ensure your completion does not introduce any syntactical or logical errors.
42
- - If filling in the middle, replace '${h}' entirely with your completion.
43
- - If completing the code, start from '${h}' and provide a logical continuation.
35
+ - If filling in the middle, replace '${T}' entirely with your completion.
36
+ - If completing the code, start from '${T}' and provide a logical continuation.
44
37
  - Consider any imports, function definitions, or class structures in the surrounding code.
45
38
  - If applicable, use appropriate error handling and follow language-specific best practices.
46
39
  - Optimize for readability and performance where possible.
@@ -50,12 +43,12 @@
50
43
  Here's the code snippet for completion:
51
44
 
52
45
  <code>
53
- ${n}${h}${s}
54
- </code>`;return l&&l.length>0&&(a+=`
46
+ ${i}${T}${s}
47
+ </code>`;return a&&a.length>0&&(c+=`
55
48
 
56
49
  Additional context from related files:
57
50
 
58
- `,a+=l.map(d=>`// Path: ${d.path}
59
- ${d.content}
51
+ `,c+=a.map(C=>`// Path: ${C.path}
52
+ ${C.content}
60
53
  `).join(`
61
- `)),a.endsWith(".")?a:`${a}.`};var de="application/json",Z=async({filename:t,endpoint:e,language:o,technologies:r,externalContext:i,model:n,position:s})=>{try{let{completion:l}=await x.POST(e,{completionMetadata:ue({filename:t,position:s,model:n,language:o,technologies:r,externalContext:i})},{headers:{"Content-Type":de},error:"Error while fetching completion item"});return l||null}catch(l){return m(l).completionError("Error while fetching completion item"),null}},ue=({filename:t,position:e,model:o,language:r,technologies:i,externalContext:n})=>{let s=Ce(e,o),l=C(e,o),p=I(e,o);return{filename:t,language:r,technologies:i,externalContext:n,textBeforeCursor:l,textAfterCursor:p,editorState:{completionMode:s}}},Ce=(t,e)=>{let o=C(t,e),r=I(t,e);return o&&r?"fill-in-the-middle":"completion"};var M=class{constructor(e,o){if(!e)throw new Error("Groq API key is required to initialize Copilot.");this.apiKey=e,L.setModel(o?.model||y)}async complete({completionMetadata:e}){try{let o=L.getModel(),r=this.createRequestBody(e,o),i=this.createHeaders(),n=await x.POST(G,r,{headers:i});if(!n.choices||n.choices.length===0)throw new Error("No completion choices received from API");return{completion:n.choices[0].message.content}}catch(o){return o instanceof Error?m(o).apiError("Failed to fetch completion"):m(o).apiError("Unknown error while fetching completion"),{error:"Failed to generate completion"}}}createRequestBody(e,o){return{...j,model:U[o],messages:[{role:"system",content:Q(e)},{role:"user",content:X(e)}]}}createHeaders(){return{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}};var ge=300,he=S(Z,ge),fe=async({monaco:t,model:e,position:o,token:r,isCompletionAccepted:i,onShowCompletion:n,options:s})=>{let l=e.getValue(),p=new t.Range(o.lineNumber,o.column,o.lineNumber,o.column);if(!new P(o,e).shouldProvideCompletions())return c([]);let f=k(o,e).map(a=>({insertText:a.completion,range:a.range}));if(f.length)return n(),c(f);if(r.isCancellationRequested)return c([]);if(i)return c([]);try{let a=await he({...s,text:l,model:e,position:o});if(a){let d=z(e,o,a),w=Y(d,p,o,e);return q({completion:d,range:w,textBeforeCursorInLine:u(o,e)}),n(),c([{insertText:d,range:w}])}}catch(a){m(a).completionError("Failed to fetch completion item")}return c([])},ee=fe;var A=!1,N=!1,te=(t,e,o)=>{try{let r=t.languages.registerInlineCompletionsProvider(o.language,{provideInlineCompletions:async(n,s,l,p)=>ee({monaco:t,model:n,position:s,token:p,isCompletionAccepted:A,onShowCompletion:()=>N=!0,options:o}),freeInlineCompletions:O});return e.onKeyDown(n=>{N&&(n.keyCode===t.KeyCode.Tab||n.keyCode===t.KeyCode.RightArrow&&n.metaKey)?(A=!0,N=!1):A=!1}),{unregister:()=>{r.dispose(),F()}}}catch(r){return m(r).editorError("Error while registering Copilot"),{unregister:O}}};0&&(module.exports={Copilot,registerCopilot});
54
+ `)),c.endsWith(".")?c:`${c}.`};var Ce="application/json",te=async({filename:o,endpoint:e,language:t,technologies:r,externalContext:n,model:i,position:s})=>{try{let{completion:a}=await y.POST(e,{completionMetadata:ge({filename:o,position:s,model:i,language:t,technologies:r,externalContext:n})},{headers:{"Content-Type":Ce},error:"Error while fetching completion item"});return a||null}catch(a){return m(a,"FETCH_COMPLETION_ITEM_ERROR"),null}},ge=({filename:o,position:e,model:t,language:r,technologies:n,externalContext:i})=>{let s=fe(e,t),a=g(e,t),l=b(e,t);return{filename:o,language:r,technologies:n,externalContext:i,textBeforeCursor:a,textAfterCursor:l,editorState:{completionMode:s}}},fe=(o,e)=>{let t=g(o,e),r=b(o,e);return t&&r?"fill-in-the-middle":"completion"};var O=class{constructor(e,t){if(!e)throw new Error("Groq API key is required to initialize Copilot.");this.apiKey=e,this.model=t?.model||H}async complete({completionMetadata:e}){try{let t=this.createRequestBody(e),r=this.createHeaders(),n=await y.POST(U,t,{headers:r});if(!n.choices?.length)throw new Error("No completion choices received from API");return{completion:n.choices[0].message.content}}catch(t){return m(t,"COPILOT_COMPLETION_FETCH_ERROR"),{error:"Failed to generate completion"}}}createRequestBody(e){return{...j,model:G[this.model],messages:[{role:"system",content:Z(e)},{role:"user",content:ee(e)}]}}createHeaders(){return{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}};var he=300,Ee=S(te,he),Te=async({monaco:o,model:e,position:t,token:r,isCompletionAccepted:n,onShowCompletion:i,options:s})=>{if(!new I(t,e).shouldProvideCompletions())return u([]);let a=q(t,e).map(l=>({insertText:l.completion,range:l.range}));if(a.length)return i(),u(a);if(r.isCancellationRequested||n)return u([]);try{let l=await Ee({...s,text:e.getValue(),model:e,position:t});if(l){let p=V(e,t,l),c=new o.Range(t.lineNumber,t.column,t.lineNumber,t.column),C=K(p,c,t,e);return k({completion:p,range:C,textBeforeCursorInLine:d(t,e)}),i(),u([{insertText:p,range:C}])}}catch(l){m(l,"FETCH_COMPLETION_ITEM_ERROR")}return u([])},oe=Te;var R=!1,M=!1,re=(o,e,t)=>{let r=[];try{let n=o.languages.registerInlineCompletionsProvider(t.language,{provideInlineCompletions:async(s,a,l,p)=>oe({monaco:o,model:s,position:a,token:p,isCompletionAccepted:R,onShowCompletion:()=>M=!0,options:t}),freeInlineCompletions:w});r.push(n);let i=e.onKeyDown(s=>{let a=s.keyCode===o.KeyCode.Tab||s.keyCode===o.KeyCode.RightArrow&&s.metaKey;M&&a?(R=!0,M=!1):R=!1});return r.push(i),{deregister:()=>{r.forEach(s=>s.dispose()),F(),R=!1,M=!1}}}catch(n){return m(n,"REGISTER_COPILOT_ERROR"),{deregister:()=>r.forEach(i=>i.dispose())}}};0&&(module.exports={Copilot,registerCopilot});
package/build/index.mjs CHANGED
@@ -1,12 +1,12 @@
1
- var M=()=>{},w=(t,e=1e3)=>{let o=null;return(...i)=>(o&&clearTimeout(o),new Promise((n,s)=>{o=setTimeout(()=>{t(...i).then(n).catch(s)},e)}))},S=t=>!t||t.length===0?"":t.length===1?t[0]:`${t.slice(0,-1).join(", ")} and ${t.slice(-1)}`;var E=(t,e)=>e.getLineContent(t.lineNumber)[t.column-1],_=(t,e)=>e.getLineContent(t.lineNumber).slice(t.column-1),u=(t,e)=>e.getLineContent(t.lineNumber).slice(0,t.column-1),B=t=>{let e=t.split(`
2
- `);return e[e.length-1].length};var C=(t,e)=>e.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:t.lineNumber,endColumn:t.column}),b=(t,e)=>e.getValueInRange({startLineNumber:t.lineNumber,startColumn:t.column,endLineNumber:e.getLineCount(),endColumn:e.getLineMaxColumn(e.getLineCount())});var D=async(t,e,o={})=>{let r={"Content-Type":"application/json",...o.headers},i=e==="POST"&&o.body?JSON.stringify(o.body):void 0,n=await fetch(t,{method:e,headers:r,body:i,signal:o.signal});if(!n.ok)throw new Error(`${o.error||"Network error"}: ${n.statusText}`);return n.json()},ee=(t,e)=>D(t,"GET",e),te=(t,e,o)=>D(t,"POST",{...o,body:e}),x={GET:ee,POST:te};var T=class{constructor(e,o){this.formattedCompletion="";this.originalCompletion="";this.model=e,this.cursorPosition=o,this.lineCount=e.getLineCount()}ignoreBlankLines(){return this.formattedCompletion.trimStart()===""&&this.originalCompletion!==`
3
- `&&(this.formattedCompletion=this.formattedCompletion.trim()),this}normalise(e){return e?.trim()??""}removeDuplicatesFromStartOfCompletion(){let e=C(this.cursorPosition,this.model).trim(),o=this.normalise(this.formattedCompletion),r=0,i=Math.min(o.length,e.length);for(let n=1;n<=i;n++){let s=e.slice(-n),l=o.slice(0,n);if(s===l)r=n;else break}return r>0&&(this.formattedCompletion=this.formattedCompletion.slice(r)),this}preventDuplicateLines(){for(let e=this.cursorPosition.lineNumber+1;e<this.cursorPosition.lineNumber+3&&e<this.lineCount;e++){let o=this.model.getLineContent(e);if(this.normalise(o)===this.normalise(this.originalCompletion))return this.formattedCompletion="",this}return this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}trimStart(){let e=this.formattedCompletion.search(/\S/);return e>this.cursorPosition.column-1&&(this.formattedCompletion=this.formattedCompletion.slice(e)),this}format(e){return this.originalCompletion=e,this.formattedCompletion=e,this.ignoreBlankLines().removeDuplicatesFromStartOfCompletion().preventDuplicateLines().removeInvalidLineBreaks().trimStart(),this.formattedCompletion}};var oe=10,g=[],$=(t,e)=>g.filter(o=>{let r=e.getValueInRange(o.range);return u(t,e).startsWith(o.textBeforeCursorInLine)&&(o.range.startLineNumber===t.lineNumber&&t.column===o.range.startColumn||o.completion.startsWith(r)&&o.range.startLineNumber===t.lineNumber&&t.column>=o.range.startColumn-r.length&&t.column<=o.range.endColumn)}),k=t=>{g.length>=oe&&g.shift(),g.push(t)},q=()=>{g.length=0};var F={llama:"llama3-70b-8192"},y="llama",U="https://api.groq.com/openai/v1/chat/completions",G={temperature:.3};var j=new Set(['"',"'","`","{","}","[","]","(",")",","," ",":","."]);var H=(t,e)=>{let o=E(t,e);return!!o&&!j.has(o)},W=(t,e)=>{let o=_(t,e).trim(),r=u(t,e).trim();return t.column<=3&&(o!==""||r!=="")};var K=(t,e,o,r)=>{let i=(t.match(/\n/g)||[]).length,n=B(t),s=E(o,r);return{startLineNumber:o.lineNumber,startColumn:o.column,endLineNumber:o.lineNumber+i,endColumn:t.includes(s)?o.lineNumber===e.startLineNumber&&i===0?o.column+n:n:o.column}},Y=(t,e,o)=>new T(t,e).format(o),c=t=>({items:t,enableForwardStability:!0});var P=class{constructor(e,o){this.cursorPosition=e,this.model=o}shouldProvideCompletions(){return!H(this.cursorPosition,this.model)&&!W(this.cursorPosition,this.model)}};var R=class{static getModel(){return this.model}static setModel(e){this.model=e}};R.model=y;var O=R;var I=class{constructor(e){this.error=e}logError(e,o,r){console.error(`${e}: ${o}`,r)}monacopilotError(e){this.logError("MONACO_PILOT_ERROR",e,this.error)}apiError(e){this.logError("API_ERROR",e,this.error)}completionError(e){this.logError("COMPLETION_ERROR",e,this.error)}predictionError(e){this.logError("PREDICTION_ERROR",e,this.error)}editorError(e){this.logError("EDITOR_ERROR",e,this.error)}unexpectedError(){this.error instanceof Error?this.logError("UNEXPECTED_ERROR",this.error.message,this.error.stack):this.logError("UNKNOWN_ERROR",String(this.error))}},m=t=>new I(t);var h="<<CURSOR>>",z=t=>t==="javascript"?"latest JavaScript":t,V=t=>{switch(t){case"fill-in-the-middle":return"filling in the middle of the code";case"completion":return"completing the code"}},J=t=>{let e=z(t.language),o=V(t.editorState.completionMode),r=e?` ${e}`:"";return`You are an advanced AI coding assistant with expertise in ${o} for${r} programming. Your goal is to provide accurate, efficient, and context-aware code completions.
1
+ var A=()=>{},w=(o,e=1e3)=>{let t=null;return(...i)=>(t&&clearTimeout(t),new Promise((n,s)=>{t=setTimeout(()=>{o(...i).then(n).catch(s)},e)}))},S=o=>!o||o.length===0?"":o.length===1?o[0]:`${o.slice(0,-1).join(", ")} and ${o.slice(-1)}`;var x=(o,e)=>e.getLineContent(o.lineNumber)[o.column-1],_=(o,e)=>e.getLineContent(o.lineNumber).slice(o.column-1),d=(o,e)=>e.getLineContent(o.lineNumber).slice(0,o.column-1),B=o=>{let e=o.split(`
2
+ `);return e[e.length-1].length};var g=(o,e)=>e.getValueInRange({startLineNumber:1,startColumn:1,endLineNumber:o.lineNumber,endColumn:o.column}),M=(o,e)=>e.getValueInRange({startLineNumber:o.lineNumber,startColumn:o.column,endLineNumber:e.getLineCount(),endColumn:e.getLineMaxColumn(e.getLineCount())});var $=async(o,e,t={})=>{let r={"Content-Type":"application/json",...t.headers},i=e==="POST"&&t.body?JSON.stringify(t.body):void 0,n=await fetch(o,{method:e,headers:r,body:i,signal:t.signal});if(!n.ok)throw new Error(`${t.error||"Network error"}: ${n.statusText}`);return n.json()},oe=(o,e)=>$(o,"GET",e),re=(o,e,t)=>$(o,"POST",{...t,body:e}),y={GET:oe,POST:re};var P=class{constructor(e,t){this.formattedCompletion="";this.originalCompletion="";this.model=e,this.cursorPosition=t,this.lineCount=e.getLineCount()}ignoreBlankLines(){return this.formattedCompletion.trimStart()===""&&this.originalCompletion!==`
3
+ `&&(this.formattedCompletion=this.formattedCompletion.trim()),this}normalise(e){return e?.trim()??""}removeDuplicatesFromStartOfCompletion(){let e=g(this.cursorPosition,this.model).trim(),t=this.normalise(this.formattedCompletion),r=0,i=Math.min(t.length,e.length);for(let n=1;n<=i;n++){let s=e.slice(-n),a=t.slice(0,n);if(s===a)r=n;else break}return r>0&&(this.formattedCompletion=this.formattedCompletion.slice(r)),this}preventDuplicateLines(){for(let e=this.cursorPosition.lineNumber+1;e<this.cursorPosition.lineNumber+3&&e<this.lineCount;e++){let t=this.model.getLineContent(e);if(this.normalise(t)===this.normalise(this.originalCompletion))return this.formattedCompletion="",this}return this}removeInvalidLineBreaks(){return this.formattedCompletion=this.formattedCompletion.trimEnd(),this}trimStart(){let e=this.formattedCompletion.search(/\S/);return e>this.cursorPosition.column-1&&(this.formattedCompletion=this.formattedCompletion.slice(e)),this}format(e){return this.originalCompletion=e,this.formattedCompletion=e,this.ignoreBlankLines().removeDuplicatesFromStartOfCompletion().preventDuplicateLines().removeInvalidLineBreaks().trimStart(),this.formattedCompletion}};var ne=10,f=[],D=(o,e)=>f.filter(t=>{let r=e.getValueInRange(t.range);return d(o,e).startsWith(t.textBeforeCursorInLine)&&(t.range.startLineNumber===o.lineNumber&&o.column===t.range.startColumn||t.completion.startsWith(r)&&t.range.startLineNumber===o.lineNumber&&o.column>=t.range.startColumn-r.length&&o.column<=t.range.endColumn)}),q=o=>{f.length>=ne&&f.shift(),f.push(o)},k=()=>{f.length=0};var F={llama:"llama3-70b-8192"},G="llama",H="https://api.groq.com/openai/v1/chat/completions",U={temperature:.3};var j=new Set(['"',"'","`","{","}","[","]","(",")",","," ",":","."]);var W=(o,e)=>{let t=x(o,e);return!!t&&!j.has(t)},Y=(o,e)=>{let t=_(o,e).trim(),r=d(o,e).trim();return o.column<=3&&(t!==""||r!=="")};var z=(o,e,t,r)=>{let i=(o.match(/\n/g)||[]).length,n=B(o),s=x(t,r);return{startLineNumber:t.lineNumber,startColumn:t.column,endLineNumber:t.lineNumber+i,endColumn:o.includes(s)?t.lineNumber===e.startLineNumber&&i===0?t.column+n:n:t.column}},K=(o,e,t)=>new P(o,e).format(t),u=o=>({items:o,enableForwardStability:!0});var I=class{constructor(e,t){this.cursorPosition=e,this.model=t}shouldProvideCompletions(){return!W(this.cursorPosition,this.model)&&!Y(this.cursorPosition,this.model)}};var h=class h{constructor(){}static getInstance(){return h.instance}log(e,...t){console.log(`[LOG] ${e}`,...t)}info(e,...t){console.info(`[INFO] ${e}`,...t)}warn(e,...t){console.warn(`[WARN] ${e}`,...t)}error(e,...t){console.error(`[ERROR] ${e}`,...t)}debug(e,...t){console.debug(`[DEBUG] ${e}`,...t)}};h.instance=new h;var L=h,V=()=>L.getInstance();var E=class E{constructor(){this.logger=V()}static getInstance(){return E.instance}handleError(e,t){let r=this.getErrorDetails(e);this.logger.error(`${t}: ${r.message}`,r)}getErrorDetails(e){return e instanceof Error?{message:e.message,name:e.name,stack:e.stack}:{message:String(e),name:"UnknownError"}}};E.instance=new E;var b=E;var m=(o,e)=>{b.getInstance().handleError(o,e)};var T="<<CURSOR>>",J=o=>o==="javascript"?"latest JavaScript":o,X=o=>{switch(o){case"fill-in-the-middle":return"filling in the middle of the code";case"completion":return"completing the code"}},Q=o=>{let e=J(o.language),t=X(o.editorState.completionMode),r=e?` ${e}`:"";return`You are an advanced AI coding assistant with expertise in ${t} for${r} programming. Your goal is to provide accurate, efficient, and context-aware code completions.
4
4
 
5
5
  ### Instructions:
6
6
  - Provide only the requested code completion without any additional explanations or markdown.
7
7
  - Ensure your suggestions seamlessly integrate with the existing code structure and style.
8
8
  - Maintain consistent indentation and formatting with the surrounding code.
9
- - Start your completion exactly at the cursor position (${h}).
9
+ - Start your completion exactly at the cursor position (${T}).
10
10
  - Do not repeat any existing code before or after the cursor.
11
11
  - Respect the project's coding conventions, naming styles, and design patterns.
12
12
  - Consider the broader context of the file and project when making suggestions.
@@ -16,14 +16,7 @@ var M=()=>{},w=(t,e=1e3)=>{let o=null;return(...i)=>(o&&clearTimeout(o),new Prom
16
16
  - If multiple valid completions exist, choose the most likely and idiomatic one.
17
17
  - If you cannot provide a meaningful completion, return an empty string.
18
18
 
19
- ### Formatting Rules:
20
- - Do not include any markdown or code block syntax.
21
- - Insert newlines after opening brackets ({, [, () and before closing brackets (}, ], )).
22
- - Add newlines after commas in multi-line structures.
23
- - Do not suggest newlines after spaces or existing newlines.
24
- - Match the indentation level of the current line for new lines.
25
-
26
- Remember, your role is to act as an extension of the developer's thought process, providing intelligent and contextually appropriate code completions.`},re=(t,e)=>{if(!t?.length&&!e)return"";let o=t?` using ${S(t)}`:"",r=z(e);return`The code is written${r?` in ${r}`:""}${o}.`},Q=t=>{let{filename:e,language:o,technologies:r,editorState:i,textBeforeCursor:n,textAfterCursor:s,externalContext:l}=t,p=V(i.completionMode),f=e?`the file named "${e}"`:"a larger project",a=`You are tasked with ${p} for a code snippet. The code is part of ${f}.
19
+ Remember, your role is to act as an extension of the developer's thought process, providing intelligent and contextually appropriate code completions.`},ie=(o,e)=>{if(!o?.length&&!e)return"";let t=o?` using ${S(o)}`:"",r=J(e);return`The code is written${r?` in ${r}`:""}${t}.`},Z=o=>{let{filename:e,language:t,technologies:r,editorState:i,textBeforeCursor:n,textAfterCursor:s,externalContext:a}=o,l=X(i.completionMode),p=e?`the file named "${e}"`:"a larger project",c=`You are tasked with ${l} for a code snippet. The code is part of ${p}.
27
20
 
28
21
  Your objective is to:
29
22
  1. Analyze the provided code snippet and its context.
@@ -32,15 +25,15 @@ var M=()=>{},w=(t,e=1e3)=>{let o=null;return(...i)=>(o&&clearTimeout(o),new Prom
32
25
  4. Adhere to the project's coding style and conventions.
33
26
  5. Consider the broader context of the file and any provided external context.
34
27
 
35
- ${re(r,o)}
28
+ ${ie(r,t)}
36
29
 
37
30
  Specific instructions:
38
- - The cursor position is marked with '${h}'.
31
+ - The cursor position is marked with '${T}'.
39
32
  - Your completion must start exactly at the cursor position.
40
33
  - Do not repeat any code that appears before or after the cursor.
41
34
  - Ensure your completion does not introduce any syntactical or logical errors.
42
- - If filling in the middle, replace '${h}' entirely with your completion.
43
- - If completing the code, start from '${h}' and provide a logical continuation.
35
+ - If filling in the middle, replace '${T}' entirely with your completion.
36
+ - If completing the code, start from '${T}' and provide a logical continuation.
44
37
  - Consider any imports, function definitions, or class structures in the surrounding code.
45
38
  - If applicable, use appropriate error handling and follow language-specific best practices.
46
39
  - Optimize for readability and performance where possible.
@@ -50,12 +43,12 @@ var M=()=>{},w=(t,e=1e3)=>{let o=null;return(...i)=>(o&&clearTimeout(o),new Prom
50
43
  Here's the code snippet for completion:
51
44
 
52
45
  <code>
53
- ${n}${h}${s}
54
- </code>`;return l&&l.length>0&&(a+=`
46
+ ${n}${T}${s}
47
+ </code>`;return a&&a.length>0&&(c+=`
55
48
 
56
49
  Additional context from related files:
57
50
 
58
- `,a+=l.map(d=>`// Path: ${d.path}
59
- ${d.content}
51
+ `,c+=a.map(C=>`// Path: ${C.path}
52
+ ${C.content}
60
53
  `).join(`
61
- `)),a.endsWith(".")?a:`${a}.`};var ne="application/json",X=async({filename:t,endpoint:e,language:o,technologies:r,externalContext:i,model:n,position:s})=>{try{let{completion:l}=await x.POST(e,{completionMetadata:ie({filename:t,position:s,model:n,language:o,technologies:r,externalContext:i})},{headers:{"Content-Type":ne},error:"Error while fetching completion item"});return l||null}catch(l){return m(l).completionError("Error while fetching completion item"),null}},ie=({filename:t,position:e,model:o,language:r,technologies:i,externalContext:n})=>{let s=se(e,o),l=C(e,o),p=b(e,o);return{filename:t,language:r,technologies:i,externalContext:n,textBeforeCursor:l,textAfterCursor:p,editorState:{completionMode:s}}},se=(t,e)=>{let o=C(t,e),r=b(t,e);return o&&r?"fill-in-the-middle":"completion"};var L=class{constructor(e,o){if(!e)throw new Error("Groq API key is required to initialize Copilot.");this.apiKey=e,O.setModel(o?.model||y)}async complete({completionMetadata:e}){try{let o=O.getModel(),r=this.createRequestBody(e,o),i=this.createHeaders(),n=await x.POST(U,r,{headers:i});if(!n.choices||n.choices.length===0)throw new Error("No completion choices received from API");return{completion:n.choices[0].message.content}}catch(o){return o instanceof Error?m(o).apiError("Failed to fetch completion"):m(o).apiError("Unknown error while fetching completion"),{error:"Failed to generate completion"}}}createRequestBody(e,o){return{...G,model:F[o],messages:[{role:"system",content:J(e)},{role:"user",content:Q(e)}]}}createHeaders(){return{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}};var le=300,ae=w(X,le),me=async({monaco:t,model:e,position:o,token:r,isCompletionAccepted:i,onShowCompletion:n,options:s})=>{let l=e.getValue(),p=new t.Range(o.lineNumber,o.column,o.lineNumber,o.column);if(!new P(o,e).shouldProvideCompletions())return c([]);let f=$(o,e).map(a=>({insertText:a.completion,range:a.range}));if(f.length)return n(),c(f);if(r.isCancellationRequested)return c([]);if(i)return c([]);try{let a=await ae({...s,text:l,model:e,position:o});if(a){let d=Y(e,o,a),N=K(d,p,o,e);return k({completion:d,range:N,textBeforeCursorInLine:u(o,e)}),n(),c([{insertText:d,range:N}])}}catch(a){m(a).completionError("Failed to fetch completion item")}return c([])},Z=me;var v=!1,A=!1,pe=(t,e,o)=>{try{let r=t.languages.registerInlineCompletionsProvider(o.language,{provideInlineCompletions:async(n,s,l,p)=>Z({monaco:t,model:n,position:s,token:p,isCompletionAccepted:v,onShowCompletion:()=>A=!0,options:o}),freeInlineCompletions:M});return e.onKeyDown(n=>{A&&(n.keyCode===t.KeyCode.Tab||n.keyCode===t.KeyCode.RightArrow&&n.metaKey)?(v=!0,A=!1):v=!1}),{unregister:()=>{r.dispose(),q()}}}catch(r){return m(r).editorError("Error while registering Copilot"),{unregister:M}}};export{L as Copilot,pe as registerCopilot};
54
+ `)),c.endsWith(".")?c:`${c}.`};var se="application/json",ee=async({filename:o,endpoint:e,language:t,technologies:r,externalContext:i,model:n,position:s})=>{try{let{completion:a}=await y.POST(e,{completionMetadata:ae({filename:o,position:s,model:n,language:t,technologies:r,externalContext:i})},{headers:{"Content-Type":se},error:"Error while fetching completion item"});return a||null}catch(a){return m(a,"FETCH_COMPLETION_ITEM_ERROR"),null}},ae=({filename:o,position:e,model:t,language:r,technologies:i,externalContext:n})=>{let s=le(e,t),a=g(e,t),l=M(e,t);return{filename:o,language:r,technologies:i,externalContext:n,textBeforeCursor:a,textAfterCursor:l,editorState:{completionMode:s}}},le=(o,e)=>{let t=g(o,e),r=M(o,e);return t&&r?"fill-in-the-middle":"completion"};var N=class{constructor(e,t){if(!e)throw new Error("Groq API key is required to initialize Copilot.");this.apiKey=e,this.model=t?.model||G}async complete({completionMetadata:e}){try{let t=this.createRequestBody(e),r=this.createHeaders(),i=await y.POST(H,t,{headers:r});if(!i.choices?.length)throw new Error("No completion choices received from API");return{completion:i.choices[0].message.content}}catch(t){return m(t,"COPILOT_COMPLETION_FETCH_ERROR"),{error:"Failed to generate completion"}}}createRequestBody(e){return{...U,model:F[this.model],messages:[{role:"system",content:Q(e)},{role:"user",content:Z(e)}]}}createHeaders(){return{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}};var me=300,pe=w(ee,me),ce=async({monaco:o,model:e,position:t,token:r,isCompletionAccepted:i,onShowCompletion:n,options:s})=>{if(!new I(t,e).shouldProvideCompletions())return u([]);let a=D(t,e).map(l=>({insertText:l.completion,range:l.range}));if(a.length)return n(),u(a);if(r.isCancellationRequested||i)return u([]);try{let l=await pe({...s,text:e.getValue(),model:e,position:t});if(l){let p=K(e,t,l),c=new o.Range(t.lineNumber,t.column,t.lineNumber,t.column),C=z(p,c,t,e);return q({completion:p,range:C,textBeforeCursorInLine:d(t,e)}),n(),u([{insertText:p,range:C}])}}catch(l){m(l,"FETCH_COMPLETION_ITEM_ERROR")}return u([])},te=ce;var O=!1,R=!1,de=(o,e,t)=>{let r=[];try{let i=o.languages.registerInlineCompletionsProvider(t.language,{provideInlineCompletions:async(s,a,l,p)=>te({monaco:o,model:s,position:a,token:p,isCompletionAccepted:O,onShowCompletion:()=>R=!0,options:t}),freeInlineCompletions:A});r.push(i);let n=e.onKeyDown(s=>{let a=s.keyCode===o.KeyCode.Tab||s.keyCode===o.KeyCode.RightArrow&&s.metaKey;R&&a?(O=!0,R=!1):O=!1});return r.push(n),{deregister:()=>{r.forEach(s=>s.dispose()),k(),O=!1,R=!1}}}catch(i){return m(i,"REGISTER_COPILOT_ERROR"),{deregister:()=>r.forEach(n=>n.dispose())}}};export{N as Copilot,de as registerCopilot};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monacopilot",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "description": "AI auto-completion for Monaco Editor",
5
5
  "main": "./build/index.js",
6
6
  "module": "./build/index.mjs",
@@ -49,6 +49,13 @@
49
49
  "type": "git",
50
50
  "url": "https://github.com/arshad-yaseen/monacopilot"
51
51
  },
52
+ "maintainers": [
53
+ {
54
+ "name": "Arshad Yaseen",
55
+ "email": "m@arshadyaseen.com",
56
+ "url": "https://arshadyaseen.com"
57
+ }
58
+ ],
52
59
  "license": "MIT",
53
60
  "author": "Arshad Yaseen <m@arshadyaseen.com>"
54
61
  }