@difizen/libro-ai-native 0.2.45 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/ai-inline-completions/Prompt/instruction.d.ts +2 -0
- package/es/ai-inline-completions/Prompt/instruction.d.ts.map +1 -0
- package/es/ai-inline-completions/Prompt/instruction.js +3 -0
- package/es/ai-inline-completions/contant.d.ts +5 -0
- package/es/ai-inline-completions/contant.d.ts.map +1 -0
- package/es/ai-inline-completions/contant.js +5 -0
- package/es/ai-inline-completions/index.d.ts +4 -0
- package/es/ai-inline-completions/index.d.ts.map +1 -0
- package/es/ai-inline-completions/index.js +3 -0
- package/es/ai-inline-completions/inline-completion-contribution.d.ts +11 -0
- package/es/ai-inline-completions/inline-completion-contribution.d.ts.map +1 -0
- package/es/ai-inline-completions/inline-completion-contribution.js +66 -0
- package/es/ai-inline-completions/inline-completion-provider.d.ts +19 -0
- package/es/ai-inline-completions/inline-completion-provider.d.ts.map +1 -0
- package/es/ai-inline-completions/inline-completion-provider.js +128 -0
- package/es/ai-inline-completions/inline-completion-request.d.ts +13 -0
- package/es/ai-inline-completions/inline-completion-request.d.ts.map +1 -0
- package/es/ai-inline-completions/inline-completion-request.js +149 -0
- package/es/ai-inline-completions/module.d.ts +3 -0
- package/es/ai-inline-completions/module.d.ts.map +1 -0
- package/es/ai-inline-completions/module.js +6 -0
- package/es/ai-inline-completions/utils.d.ts +12 -0
- package/es/ai-inline-completions/utils.d.ts.map +1 -0
- package/es/ai-inline-completions/utils.js +39 -0
- package/es/ai-native-for-cell-view.d.ts.map +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +2 -1
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -1
- package/es/module.js +8 -1
- package/package.json +4 -3
- package/src/ai-inline-completions/Prompt/instruction.ts +36 -0
- package/src/ai-inline-completions/contant.ts +5 -0
- package/src/ai-inline-completions/index.ts +3 -0
- package/src/ai-inline-completions/inline-completion-contribution.ts +36 -0
- package/src/ai-inline-completions/inline-completion-provider.ts +102 -0
- package/src/ai-inline-completions/inline-completion-request.ts +101 -0
- package/src/ai-inline-completions/module.ts +10 -0
- package/src/ai-inline-completions/utils.ts +60 -0
- package/src/ai-native-for-cell-view.tsx +2 -0
- package/src/index.ts +1 -0
- package/src/module.ts +8 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instruction.d.ts","sourceRoot":"","sources":["../../../src/ai-inline-completions/Prompt/instruction.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,aAC3B,MAAM,UACR,MAAM,UACN,MAAM,WAgCX,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export var generateInstructionsPrompt = function generateInstructionsPrompt(language, prompt, suffix) {
|
|
2
|
+
return "\n You are an expert ".concat(language, " developer assistant.\n Your task is to provide precise and contextually relevant code completions, modifications, or generations .\n Ensure that your responses integrate seamlessly with the existing code and maintain consistency with the project's style and conventions.\n Pay special attention to ").concat(language, "-specific syntax and best practices.\n Before providing the completion or modification, think through the problem step-by-step, considering best practices and any potential edge cases.\n <task>\n <instructions>\n You are an expert coding assistant. Your task is to provide code completions based on the current cursor position in the code.\n Below is the code file with a special token '<cursor>' indicating the current cursor position.\n\n <code_file>\n ").concat(prompt, "<cursor>").concat(suffix, "\n </code_file>\n\n Please provide the code that should be inserted at the cursor position, following these guidelines:\n - Carefully analyze the code context before and after the cursor to understand what code is needed.\n - Follow best practices and maintain a consistent coding style with the existing code.\n - Ensure the generated code integrates smoothly with the existing codebase.\n - Do **not** include any code that is before the cursor in your response.\n - Do **not** include any explanations, comments, or placeholders.\n - Avoid wrapping your completion with markdown code blocks (``` or `).\n - Provide **only** the necessary code to be inserted at the cursor location.\n\n Depending on the completion mode, adjust your completion accordingly:\n - **Completion Mode**: continue\n -- Continue writing the code from the current cursor location.\n\n Remember to output **only** the code that should be inserted at the cursor, without any additional formatting or explanations.\n </instructions>\n </task>\n ");
|
|
3
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contant.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/contant.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,+BAA+B;;;CAG3C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InlineCompletionRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { InlineCompletionContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import { AICompletionProvider } from './inline-completion-provider.js';
|
|
4
|
+
export declare class AICompletionContribution implements InlineCompletionContribution {
|
|
5
|
+
private sequencer;
|
|
6
|
+
completionProvider: AICompletionProvider;
|
|
7
|
+
constructor(completionProvider: AICompletionProvider);
|
|
8
|
+
canHandle(): number;
|
|
9
|
+
registerCompletion(register: InlineCompletionRegistry): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=inline-completion-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-completion-contribution.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/inline-completion-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAI1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,qBACa,wBAAyB,YAAW,4BAA4B;IAC3E,OAAO,CAAC,SAAS,CAAmB;IACpC,kBAAkB,EAAE,oBAAoB,CAAC;gBAEC,kBAAkB,EAAE,oBAAoB;IAIlF,SAAS;IAIT,kBAAkB,CAAC,QAAQ,EAAE,wBAAwB;CAetD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
5
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
import { InlineCompletionContribution } from '@difizen/libro-code-editor';
|
|
12
|
+
import { Sequencer } from '@difizen/libro-code-editor';
|
|
13
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
14
|
+
import { AICompletionProvider } from "./inline-completion-provider.js";
|
|
15
|
+
export var AICompletionContribution = (_dec = singleton({
|
|
16
|
+
contrib: [InlineCompletionContribution]
|
|
17
|
+
}), _dec(_class = /*#__PURE__*/function () {
|
|
18
|
+
function AICompletionContribution(completionProvider) {
|
|
19
|
+
_classCallCheck(this, AICompletionContribution);
|
|
20
|
+
this.sequencer = new Sequencer();
|
|
21
|
+
this.completionProvider = completionProvider;
|
|
22
|
+
}
|
|
23
|
+
AICompletionContribution = inject(AICompletionProvider)(AICompletionContribution, undefined, 0) || AICompletionContribution;
|
|
24
|
+
_createClass(AICompletionContribution, [{
|
|
25
|
+
key: "canHandle",
|
|
26
|
+
value: function canHandle() {
|
|
27
|
+
return 100;
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "registerCompletion",
|
|
31
|
+
value: function registerCompletion(register) {
|
|
32
|
+
var _this = this;
|
|
33
|
+
register.addCompletion({
|
|
34
|
+
selector: '*',
|
|
35
|
+
getInlineCompletions: function () {
|
|
36
|
+
var _getInlineCompletions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(context, token) {
|
|
37
|
+
var completionsResult;
|
|
38
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
39
|
+
while (1) switch (_context.prev = _context.next) {
|
|
40
|
+
case 0:
|
|
41
|
+
_context.next = 2;
|
|
42
|
+
return _this.sequencer.queue(function () {
|
|
43
|
+
return _this.completionProvider.provideInlineCompletionItems(context, token);
|
|
44
|
+
});
|
|
45
|
+
case 2:
|
|
46
|
+
completionsResult = _context.sent;
|
|
47
|
+
return _context.abrupt("return", completionsResult);
|
|
48
|
+
case 4:
|
|
49
|
+
case "end":
|
|
50
|
+
return _context.stop();
|
|
51
|
+
}
|
|
52
|
+
}, _callee);
|
|
53
|
+
}));
|
|
54
|
+
function getInlineCompletions(_x, _x2) {
|
|
55
|
+
return _getInlineCompletions.apply(this, arguments);
|
|
56
|
+
}
|
|
57
|
+
return getInlineCompletions;
|
|
58
|
+
}(),
|
|
59
|
+
freeInlineCompletions: function freeInlineCompletions() {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}]);
|
|
65
|
+
return AICompletionContribution;
|
|
66
|
+
}()) || _class);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InlineCompletionProvider, CancellationToken, IIntelligentCompletionsResult, ICompletionContext } from '@difizen/libro-code-editor';
|
|
2
|
+
import { CompletionRequest } from './inline-completion-request.js';
|
|
3
|
+
declare class ReqStack {
|
|
4
|
+
queue: CompletionRequest[];
|
|
5
|
+
constructor();
|
|
6
|
+
addReq(reqRequest: CompletionRequest): void;
|
|
7
|
+
runReq(): Promise<import("@difizen/libro-code-editor").InlineCompletion[]> | undefined;
|
|
8
|
+
cancelReq(): void;
|
|
9
|
+
}
|
|
10
|
+
export declare class AICompletionProvider implements InlineCompletionProvider {
|
|
11
|
+
reqStack: ReqStack;
|
|
12
|
+
inlineComletionsDebounceTime: number;
|
|
13
|
+
constructor();
|
|
14
|
+
mount(): void;
|
|
15
|
+
provideInlineCompletionItems(context: ICompletionContext, token: CancellationToken): Promise<IIntelligentCompletionsResult<any> | undefined>;
|
|
16
|
+
cancelRequest(): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=inline-completion-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-completion-provider.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/inline-completion-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAcnE,cAAM,QAAQ;IACZ,KAAK,EAAE,iBAAiB,EAAE,CAAC;;IAI3B,MAAM,CAAC,UAAU,EAAE,iBAAiB;IAGpC,MAAM;IAWN,SAAS;CASV;AAED,qBACa,oBAAqB,YAAW,wBAAwB;IACnE,QAAQ,EAAE,QAAQ,CAAC;IACnB,4BAA4B,EAAE,MAAM,CAAC;;IAM9B,KAAK,IAAI,IAAI;IAKd,4BAA4B,CAChC,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,iBAAiB;IA4B1B,aAAa;CAKd"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var _dec, _class;
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
8
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
9
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
11
|
+
import { singleton } from '@difizen/mana-app';
|
|
12
|
+
import { CompletionRequest } from "./inline-completion-request.js";
|
|
13
|
+
import { raceCancellation, sleep } from "./utils.js";
|
|
14
|
+
|
|
15
|
+
// 缓存最近一次的补全结果
|
|
16
|
+
var inlineCompletionCache = {
|
|
17
|
+
line: -1,
|
|
18
|
+
column: -1,
|
|
19
|
+
last: null
|
|
20
|
+
};
|
|
21
|
+
var ReqStack = /*#__PURE__*/function () {
|
|
22
|
+
function ReqStack() {
|
|
23
|
+
_classCallCheck(this, ReqStack);
|
|
24
|
+
this.queue = [];
|
|
25
|
+
}
|
|
26
|
+
_createClass(ReqStack, [{
|
|
27
|
+
key: "addReq",
|
|
28
|
+
value: function addReq(reqRequest) {
|
|
29
|
+
this.queue.push(reqRequest);
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "runReq",
|
|
33
|
+
value: function runReq() {
|
|
34
|
+
if (this.queue.length === 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var fn = this.queue.pop();
|
|
38
|
+
if (!fn) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return fn.run();
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "cancelReq",
|
|
45
|
+
value: function cancelReq() {
|
|
46
|
+
if (this.queue.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.queue.forEach(function (item) {
|
|
50
|
+
item.cancelRequest();
|
|
51
|
+
});
|
|
52
|
+
this.queue = [];
|
|
53
|
+
}
|
|
54
|
+
}]);
|
|
55
|
+
return ReqStack;
|
|
56
|
+
}();
|
|
57
|
+
export var AICompletionProvider = (_dec = singleton(), _dec(_class = /*#__PURE__*/function () {
|
|
58
|
+
function AICompletionProvider() {
|
|
59
|
+
_classCallCheck(this, AICompletionProvider);
|
|
60
|
+
this.mount();
|
|
61
|
+
}
|
|
62
|
+
_createClass(AICompletionProvider, [{
|
|
63
|
+
key: "mount",
|
|
64
|
+
value: function mount() {
|
|
65
|
+
this.reqStack = new ReqStack();
|
|
66
|
+
this.inlineComletionsDebounceTime = 500;
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "provideInlineCompletionItems",
|
|
70
|
+
value: function () {
|
|
71
|
+
var _provideInlineCompletionItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(context, token) {
|
|
72
|
+
var requestImp, list;
|
|
73
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
74
|
+
while (1) switch (_context.prev = _context.next) {
|
|
75
|
+
case 0:
|
|
76
|
+
this.cancelRequest();
|
|
77
|
+
|
|
78
|
+
// 放入队列
|
|
79
|
+
requestImp = new CompletionRequest(context, token);
|
|
80
|
+
this.reqStack.addReq(requestImp);
|
|
81
|
+
_context.next = 5;
|
|
82
|
+
return raceCancellation(sleep(this.inlineComletionsDebounceTime), token);
|
|
83
|
+
case 5:
|
|
84
|
+
if (!(token !== null && token !== void 0 && token.isCancellationRequested)) {
|
|
85
|
+
_context.next = 7;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return _context.abrupt("return", undefined);
|
|
89
|
+
case 7:
|
|
90
|
+
_context.next = 9;
|
|
91
|
+
return this.reqStack.runReq();
|
|
92
|
+
case 9:
|
|
93
|
+
list = _context.sent;
|
|
94
|
+
if (list) {
|
|
95
|
+
_context.next = 12;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
return _context.abrupt("return", undefined);
|
|
99
|
+
case 12:
|
|
100
|
+
if (context.position) {
|
|
101
|
+
inlineCompletionCache.column = context.position.column;
|
|
102
|
+
inlineCompletionCache.line = context.position.line;
|
|
103
|
+
}
|
|
104
|
+
inlineCompletionCache.last = {
|
|
105
|
+
items: list
|
|
106
|
+
};
|
|
107
|
+
return _context.abrupt("return", inlineCompletionCache.last);
|
|
108
|
+
case 15:
|
|
109
|
+
case "end":
|
|
110
|
+
return _context.stop();
|
|
111
|
+
}
|
|
112
|
+
}, _callee, this);
|
|
113
|
+
}));
|
|
114
|
+
function provideInlineCompletionItems(_x, _x2) {
|
|
115
|
+
return _provideInlineCompletionItems.apply(this, arguments);
|
|
116
|
+
}
|
|
117
|
+
return provideInlineCompletionItems;
|
|
118
|
+
}()
|
|
119
|
+
}, {
|
|
120
|
+
key: "cancelRequest",
|
|
121
|
+
value: function cancelRequest() {
|
|
122
|
+
if (this.reqStack) {
|
|
123
|
+
this.reqStack.cancelReq();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}]);
|
|
127
|
+
return AICompletionProvider;
|
|
128
|
+
}()) || _class);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IAICompletionOption, ICompletionContext, IIntelligentCompletionsResult, CancellationToken } from '@difizen/libro-code-editor';
|
|
2
|
+
export declare class CompletionRequest {
|
|
3
|
+
context: ICompletionContext;
|
|
4
|
+
token: CancellationToken;
|
|
5
|
+
isCancelFlag: boolean;
|
|
6
|
+
id: string;
|
|
7
|
+
constructor(context: ICompletionContext, token: CancellationToken);
|
|
8
|
+
protected constructRequestContext(context: ICompletionContext, token: CancellationToken): IAICompletionOption;
|
|
9
|
+
cancelRequest(): void;
|
|
10
|
+
run(): Promise<import("@difizen/libro-code-editor").InlineCompletion[]>;
|
|
11
|
+
protected complete(data: IAICompletionOption): Promise<IIntelligentCompletionsResult | undefined>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=inline-completion-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-completion-request.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/inline-completion-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,6BAA6B,EAC7B,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAMpC,qBACa,iBAAiB;IAKnB,OAAO,EAAE,kBAAkB;IAC3B,KAAK,EAAE,iBAAiB;IALjC,YAAY,EAAE,OAAO,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;gBAGF,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,iBAAiB;IAOjC,SAAS,CAAC,uBAAuB,CAC/B,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,iBAAiB,GACvB,mBAAmB;IAgBtB,aAAa;IAKP,GAAG;cAoBO,QAAQ,CACtB,IAAI,EAAE,mBAAmB,GACxB,OAAO,CAAC,6BAA6B,GAAG,SAAS,CAAC;CA6BtD"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
var _dec, _class;
|
|
3
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
10
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
11
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
14
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
import { transient } from '@difizen/mana-app';
|
|
18
|
+
import { v4 } from 'uuid';
|
|
19
|
+
import { generateInstructionsPrompt } from "./Prompt/instruction.js";
|
|
20
|
+
export var CompletionRequest = (_dec = transient(), _dec(_class = /*#__PURE__*/function () {
|
|
21
|
+
function CompletionRequest(context, token) {
|
|
22
|
+
_classCallCheck(this, CompletionRequest);
|
|
23
|
+
this.context = context;
|
|
24
|
+
this.token = token;
|
|
25
|
+
this.isCancelFlag = false;
|
|
26
|
+
this.id = v4();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 拼接上下文信息
|
|
30
|
+
_createClass(CompletionRequest, [{
|
|
31
|
+
key: "constructRequestContext",
|
|
32
|
+
value: function constructRequestContext(context, token) {
|
|
33
|
+
// const prompt = lineBasedPromptProcessor.processPrefix(context.prefix);
|
|
34
|
+
// const suffix = lineBasedPromptProcessor.processSuffix(context.suffix);
|
|
35
|
+
var prompt = context.prefix;
|
|
36
|
+
var suffix = context.suffix;
|
|
37
|
+
return {
|
|
38
|
+
prompt: prompt,
|
|
39
|
+
suffix: suffix,
|
|
40
|
+
sessionId: v4(),
|
|
41
|
+
language: context.language,
|
|
42
|
+
fileUrl: context.fileUrl
|
|
43
|
+
// workspaceDir: context.workspaceDir,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "cancelRequest",
|
|
48
|
+
value: function cancelRequest() {
|
|
49
|
+
this.isCancelFlag = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 向大模型发送请求
|
|
53
|
+
}, {
|
|
54
|
+
key: "run",
|
|
55
|
+
value: function () {
|
|
56
|
+
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
57
|
+
var _completeResult;
|
|
58
|
+
var context, token, completeResult, requestBean;
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
context = this.context, token = this.token;
|
|
63
|
+
if (!(this.isCancelFlag || token.isCancellationRequested)) {
|
|
64
|
+
_context.next = 3;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
return _context.abrupt("return", []);
|
|
68
|
+
case 3:
|
|
69
|
+
_context.next = 5;
|
|
70
|
+
return this.constructRequestContext(context, token);
|
|
71
|
+
case 5:
|
|
72
|
+
requestBean = _context.sent;
|
|
73
|
+
_context.prev = 6;
|
|
74
|
+
_context.next = 9;
|
|
75
|
+
return this.complete(requestBean);
|
|
76
|
+
case 9:
|
|
77
|
+
completeResult = _context.sent;
|
|
78
|
+
_context.next = 16;
|
|
79
|
+
break;
|
|
80
|
+
case 12:
|
|
81
|
+
_context.prev = 12;
|
|
82
|
+
_context.t0 = _context["catch"](6);
|
|
83
|
+
console.error('Inline Completion Request Error:', _context.t0);
|
|
84
|
+
return _context.abrupt("return", []);
|
|
85
|
+
case 16:
|
|
86
|
+
return _context.abrupt("return", _toConsumableArray(((_completeResult = completeResult) === null || _completeResult === void 0 ? void 0 : _completeResult.items) || []));
|
|
87
|
+
case 17:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}, _callee, this, [[6, 12]]);
|
|
92
|
+
}));
|
|
93
|
+
function run() {
|
|
94
|
+
return _run.apply(this, arguments);
|
|
95
|
+
}
|
|
96
|
+
return run;
|
|
97
|
+
}()
|
|
98
|
+
}, {
|
|
99
|
+
key: "complete",
|
|
100
|
+
value: function () {
|
|
101
|
+
var _complete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
|
|
102
|
+
var url, instruction, res, responseData;
|
|
103
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
104
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
105
|
+
case 0:
|
|
106
|
+
// 调用大模型非流式接口
|
|
107
|
+
url = "/libro/api/chat";
|
|
108
|
+
instruction = generateInstructionsPrompt(data.language, data.prompt, data.suffix || '');
|
|
109
|
+
_context2.next = 4;
|
|
110
|
+
return fetch(url, {
|
|
111
|
+
method: 'POST',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json'
|
|
114
|
+
},
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
prompt: instruction
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
case 4:
|
|
120
|
+
res = _context2.sent;
|
|
121
|
+
_context2.prev = 5;
|
|
122
|
+
_context2.next = 8;
|
|
123
|
+
return res.json();
|
|
124
|
+
case 8:
|
|
125
|
+
responseData = _context2.sent;
|
|
126
|
+
return _context2.abrupt("return", {
|
|
127
|
+
items: [{
|
|
128
|
+
insertText: responseData.res
|
|
129
|
+
}] // Expecting the result to be in this structure
|
|
130
|
+
});
|
|
131
|
+
case 12:
|
|
132
|
+
_context2.prev = 12;
|
|
133
|
+
_context2.t0 = _context2["catch"](5);
|
|
134
|
+
console.error('Error parsing JSON response:', _context2.t0);
|
|
135
|
+
return _context2.abrupt("return", undefined);
|
|
136
|
+
case 16:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context2.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee2, null, [[5, 12]]);
|
|
141
|
+
}));
|
|
142
|
+
function complete(_x) {
|
|
143
|
+
return _complete.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
return complete;
|
|
146
|
+
}()
|
|
147
|
+
}]);
|
|
148
|
+
return CompletionRequest;
|
|
149
|
+
}()) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAM/C,eAAO,MAAM,uBAAuB,YAEP,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
import { AICompletionContribution } from "./inline-completion-contribution.js";
|
|
4
|
+
import { AICompletionProvider } from "./inline-completion-provider.js";
|
|
5
|
+
import { CompletionRequest } from "./inline-completion-request.js";
|
|
6
|
+
export var LibroAICompletionModule = ManaModule.create().register(CompletionRequest, AICompletionProvider, AICompletionContribution).dependOn(CodeEditorModule);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CancellationToken } from '@difizen/libro-code-editor';
|
|
2
|
+
declare function processPrefix(prompt: string): string;
|
|
3
|
+
declare function processSuffix(suffix: string): string;
|
|
4
|
+
export declare const lineBasedPromptProcessor: {
|
|
5
|
+
processPrefix: typeof processPrefix;
|
|
6
|
+
processSuffix: typeof processSuffix;
|
|
7
|
+
};
|
|
8
|
+
export declare function sleep(time: number): Promise<void>;
|
|
9
|
+
export declare function raceCancellation<T>(promise: Promise<T>, token: CancellationToken): Promise<T | undefined>;
|
|
10
|
+
export declare function raceCancellation<T>(promise: Promise<T>, token: CancellationToken, defaultValue: T): Promise<T>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/ai-inline-completions/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAKpE,iBAAS,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAW7C;AAGD,iBAAS,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAS7C;AAED,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC;AAEF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,iBAEjC;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAC1B,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,iBAAiB,EACxB,YAAY,EAAE,CAAC,GACd,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { lineBasedCompletionModelConfigs } from "./contant.js";
|
|
2
|
+
|
|
3
|
+
// 去除多余的空行,并且限制前文的长度
|
|
4
|
+
function processPrefix(prompt) {
|
|
5
|
+
// remove all empty lines
|
|
6
|
+
prompt = prompt.replace(/^s*[\n]/gm, '');
|
|
7
|
+
var arr = prompt.split('\n');
|
|
8
|
+
// if the number of lines is greater than n, take the last n lines
|
|
9
|
+
if (arr.length > lineBasedCompletionModelConfigs.completionPromptMaxLineSize) {
|
|
10
|
+
prompt = arr.slice(-lineBasedCompletionModelConfigs.completionPromptMaxLineSize).join('\n');
|
|
11
|
+
}
|
|
12
|
+
return prompt;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 去除多余的空行,并且限制后文的长度
|
|
16
|
+
function processSuffix(suffix) {
|
|
17
|
+
suffix = suffix.replace(/^s*[\n]/gm, '');
|
|
18
|
+
var arr = suffix.split('\n');
|
|
19
|
+
if (arr.length > lineBasedCompletionModelConfigs.completionSuffixMaxLineSize) {
|
|
20
|
+
suffix = arr.slice(-lineBasedCompletionModelConfigs.completionSuffixMaxLineSize).join('\n');
|
|
21
|
+
}
|
|
22
|
+
return suffix;
|
|
23
|
+
}
|
|
24
|
+
export var lineBasedPromptProcessor = {
|
|
25
|
+
processPrefix: processPrefix,
|
|
26
|
+
processSuffix: processSuffix
|
|
27
|
+
};
|
|
28
|
+
export function sleep(time) {
|
|
29
|
+
return new Promise(function (resolve) {
|
|
30
|
+
return setTimeout(resolve, time);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export function raceCancellation(promise, token, defaultValue) {
|
|
34
|
+
return Promise.race([promise, new Promise(function (resolve) {
|
|
35
|
+
return token.onCancellationRequested(function () {
|
|
36
|
+
return resolve(defaultValue);
|
|
37
|
+
});
|
|
38
|
+
})]);
|
|
39
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-for-cell-view.d.ts","sourceRoot":"","sources":["../src/ai-native-for-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAW9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGhE,wBAAgB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"ai-native-for-cell-view.d.ts","sourceRoot":"","sources":["../src/ai-native-for-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAW9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGhE,wBAAgB,0BAA0B,mDAgDzC;AAED,qBAEa,wBAAyB,SAAQ,QAAQ;IAC3C,IAAI,EAAE,aAAa,CAA8B;IACzC,OAAO,EAAE,OAAO,CAAC;IAClC,IAAI,EAAE,QAAQ,CAAC;IAEf,6BAA6B,EAAE,aAAa,CAAC,OAAO,2BAA2B,CAAC,CAAC;IAEjF,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAG1D,MAAM,UAAS;gBACiB,OAAO,EAAE,0BAA0B;IAMnE,UAAU,WAAkB,YAAY,mBA+DtC;CACH"}
|
package/es/index.d.ts
CHANGED
package/es/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,yBAAyB,CAAC;AACxC,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC"}
|
package/es/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export * from "./module.js";
|
|
|
2
2
|
export * from "./chat-slot-contribution.js";
|
|
3
3
|
export * from "./chat-view.js";
|
|
4
4
|
export * from "./error-output-model.js";
|
|
5
|
-
export * from "./libro-ai-native-color-registry.js";
|
|
5
|
+
export * from "./libro-ai-native-color-registry.js";
|
|
6
|
+
export * from "./ai-inline-completions/index.js";
|
package/es/module.d.ts
CHANGED
package/es/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAe/C,eAAO,MAAM,0BAA0B;;CAEtC,CAAC;AAEF,eAAO,MAAM,mBAAmB,YA2BuC,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
1
2
|
import { CellOutputTopProvider, ErrorOutputModel } from '@difizen/libro-jupyter';
|
|
2
3
|
import { ChatView } from '@difizen/magent-chat';
|
|
3
4
|
import { LibroChatModule, LibroChatService } from '@difizen/magent-libro';
|
|
4
5
|
import { ManaModule } from '@difizen/mana-app';
|
|
6
|
+
import { LibroAICompletionModule } from "./ai-inline-completions/module.js";
|
|
5
7
|
import { LibroAINativeCommandContribution } from "./ai-native-command-contribution.js";
|
|
6
8
|
import { LibroAINativeForCellView } from "./ai-native-for-cell-view.js";
|
|
7
9
|
import { LibroAINativeCellTopBlank } from "./ai-native-output-top.js";
|
|
@@ -13,6 +15,9 @@ import { LibroAIChatMessageItemModel } from "./libro-ai-msg-item-model.js";
|
|
|
13
15
|
import { LibroAINativeChatService } from "./libro-ai-native-chat-service.js";
|
|
14
16
|
import { LibroAiNativeChatView } from "./libro-ai-native-chat-view.js";
|
|
15
17
|
import { LibroAINativeColorRegistry } from "./libro-ai-native-color-registry.js";
|
|
18
|
+
export var LibroAINativeModuleSetting = {
|
|
19
|
+
loadable: true
|
|
20
|
+
};
|
|
16
21
|
export var LibroAINativeModule = ManaModule.create().register(LibroAINativeColorRegistry, LibroChatView, LibroAIChatSlotContribution, LibroAINativeCommandContribution, LibroAINativeService, LibroAIChatMessageItemModel, LibroAINativeForCellView, {
|
|
17
22
|
token: ErrorOutputModel,
|
|
18
23
|
useClass: AIErrorOutputModel
|
|
@@ -25,4 +30,6 @@ export var LibroAINativeModule = ManaModule.create().register(LibroAINativeColor
|
|
|
25
30
|
}, {
|
|
26
31
|
token: CellOutputTopProvider,
|
|
27
32
|
useValue: LibroAINativeCellTopBlank
|
|
28
|
-
}).
|
|
33
|
+
}).canload(function () {
|
|
34
|
+
return Promise.resolve(LibroAINativeModuleSetting.loadable);
|
|
35
|
+
}).dependOn(LibroChatModule, CodeEditorModule, LibroAICompletionModule);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-ai-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-jupyter": "^0.
|
|
35
|
+
"@difizen/libro-jupyter": "^0.3.0",
|
|
36
|
+
"@difizen/libro-code-editor": "^0.3.0",
|
|
36
37
|
"@ant-design/icons": "^5.4.0",
|
|
37
38
|
"@difizen/mana-app": "latest",
|
|
38
39
|
"@difizen/mana-l10n": "latest",
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
"react": ">=16"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@types/react": "^18.
|
|
56
|
+
"@types/react": "^18.3.12",
|
|
56
57
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
57
58
|
"@types/sanitize-html": "^2.6.2",
|
|
58
59
|
"@types/uuid": "^9.0.2"
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const generateInstructionsPrompt = (
|
|
2
|
+
language: string,
|
|
3
|
+
prompt: string,
|
|
4
|
+
suffix: string,
|
|
5
|
+
) => `
|
|
6
|
+
You are an expert ${language} developer assistant.
|
|
7
|
+
Your task is to provide precise and contextually relevant code completions, modifications, or generations .
|
|
8
|
+
Ensure that your responses integrate seamlessly with the existing code and maintain consistency with the project's style and conventions.
|
|
9
|
+
Pay special attention to ${language}-specific syntax and best practices.
|
|
10
|
+
Before providing the completion or modification, think through the problem step-by-step, considering best practices and any potential edge cases.
|
|
11
|
+
<task>
|
|
12
|
+
<instructions>
|
|
13
|
+
You are an expert coding assistant. Your task is to provide code completions based on the current cursor position in the code.
|
|
14
|
+
Below is the code file with a special token '<cursor>' indicating the current cursor position.
|
|
15
|
+
|
|
16
|
+
<code_file>
|
|
17
|
+
${prompt}<cursor>${suffix}
|
|
18
|
+
</code_file>
|
|
19
|
+
|
|
20
|
+
Please provide the code that should be inserted at the cursor position, following these guidelines:
|
|
21
|
+
- Carefully analyze the code context before and after the cursor to understand what code is needed.
|
|
22
|
+
- Follow best practices and maintain a consistent coding style with the existing code.
|
|
23
|
+
- Ensure the generated code integrates smoothly with the existing codebase.
|
|
24
|
+
- Do **not** include any code that is before the cursor in your response.
|
|
25
|
+
- Do **not** include any explanations, comments, or placeholders.
|
|
26
|
+
- Avoid wrapping your completion with markdown code blocks (\`\`\` or \`).
|
|
27
|
+
- Provide **only** the necessary code to be inserted at the cursor location.
|
|
28
|
+
|
|
29
|
+
Depending on the completion mode, adjust your completion accordingly:
|
|
30
|
+
- **Completion Mode**: continue
|
|
31
|
+
-- Continue writing the code from the current cursor location.
|
|
32
|
+
|
|
33
|
+
Remember to output **only** the code that should be inserted at the cursor, without any additional formatting or explanations.
|
|
34
|
+
</instructions>
|
|
35
|
+
</task>
|
|
36
|
+
`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { InlineCompletionRegistry } from '@difizen/libro-code-editor';
|
|
2
|
+
import { InlineCompletionContribution } from '@difizen/libro-code-editor';
|
|
3
|
+
import { Sequencer } from '@difizen/libro-code-editor';
|
|
4
|
+
import { inject, singleton } from '@difizen/mana-app';
|
|
5
|
+
|
|
6
|
+
import { AICompletionProvider } from './inline-completion-provider.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: [InlineCompletionContribution] })
|
|
9
|
+
export class AICompletionContribution implements InlineCompletionContribution {
|
|
10
|
+
private sequencer = new Sequencer();
|
|
11
|
+
completionProvider: AICompletionProvider;
|
|
12
|
+
|
|
13
|
+
constructor(@inject(AICompletionProvider) completionProvider: AICompletionProvider) {
|
|
14
|
+
this.completionProvider = completionProvider;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
canHandle() {
|
|
18
|
+
return 100;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
registerCompletion(register: InlineCompletionRegistry) {
|
|
22
|
+
register.addCompletion({
|
|
23
|
+
selector: '*',
|
|
24
|
+
getInlineCompletions: async (context, token) => {
|
|
25
|
+
const completionsResult = await this.sequencer.queue(() =>
|
|
26
|
+
this.completionProvider.provideInlineCompletionItems(context, token),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return completionsResult;
|
|
30
|
+
},
|
|
31
|
+
freeInlineCompletions: () => {
|
|
32
|
+
return;
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
InlineCompletionProvider,
|
|
3
|
+
CancellationToken,
|
|
4
|
+
IIntelligentCompletionsResult,
|
|
5
|
+
ICompletionContext,
|
|
6
|
+
} from '@difizen/libro-code-editor';
|
|
7
|
+
import { singleton } from '@difizen/mana-app';
|
|
8
|
+
|
|
9
|
+
import { CompletionRequest } from './inline-completion-request.js';
|
|
10
|
+
import { raceCancellation, sleep } from './utils.js';
|
|
11
|
+
|
|
12
|
+
// 缓存最近一次的补全结果
|
|
13
|
+
const inlineCompletionCache: {
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
last: IIntelligentCompletionsResult | null;
|
|
17
|
+
} = {
|
|
18
|
+
line: -1,
|
|
19
|
+
column: -1,
|
|
20
|
+
last: null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class ReqStack {
|
|
24
|
+
queue: CompletionRequest[];
|
|
25
|
+
constructor() {
|
|
26
|
+
this.queue = [];
|
|
27
|
+
}
|
|
28
|
+
addReq(reqRequest: CompletionRequest) {
|
|
29
|
+
this.queue.push(reqRequest);
|
|
30
|
+
}
|
|
31
|
+
runReq() {
|
|
32
|
+
if (this.queue.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const fn = this.queue.pop();
|
|
36
|
+
if (!fn) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return fn.run();
|
|
41
|
+
}
|
|
42
|
+
cancelReq() {
|
|
43
|
+
if (this.queue.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
this.queue.forEach((item) => {
|
|
47
|
+
item.cancelRequest();
|
|
48
|
+
});
|
|
49
|
+
this.queue = [];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@singleton()
|
|
54
|
+
export class AICompletionProvider implements InlineCompletionProvider {
|
|
55
|
+
reqStack: ReqStack;
|
|
56
|
+
inlineComletionsDebounceTime: number;
|
|
57
|
+
|
|
58
|
+
constructor() {
|
|
59
|
+
this.mount();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public mount(): void {
|
|
63
|
+
this.reqStack = new ReqStack();
|
|
64
|
+
this.inlineComletionsDebounceTime = 500;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async provideInlineCompletionItems(
|
|
68
|
+
context: ICompletionContext,
|
|
69
|
+
token: CancellationToken,
|
|
70
|
+
) {
|
|
71
|
+
this.cancelRequest();
|
|
72
|
+
|
|
73
|
+
// 放入队列
|
|
74
|
+
const requestImp = new CompletionRequest(context, token);
|
|
75
|
+
this.reqStack.addReq(requestImp);
|
|
76
|
+
|
|
77
|
+
await raceCancellation(sleep(this.inlineComletionsDebounceTime), token);
|
|
78
|
+
|
|
79
|
+
if (token?.isCancellationRequested) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const list = await this.reqStack.runReq();
|
|
84
|
+
if (!list) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
if (context.position) {
|
|
88
|
+
inlineCompletionCache.column = context.position.column;
|
|
89
|
+
inlineCompletionCache.line = context.position.line;
|
|
90
|
+
}
|
|
91
|
+
inlineCompletionCache.last = {
|
|
92
|
+
items: list,
|
|
93
|
+
};
|
|
94
|
+
return inlineCompletionCache.last;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
cancelRequest() {
|
|
98
|
+
if (this.reqStack) {
|
|
99
|
+
this.reqStack.cancelReq();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IAICompletionOption,
|
|
3
|
+
ICompletionContext,
|
|
4
|
+
IIntelligentCompletionsResult,
|
|
5
|
+
CancellationToken,
|
|
6
|
+
} from '@difizen/libro-code-editor';
|
|
7
|
+
import { transient } from '@difizen/mana-app';
|
|
8
|
+
import { v4 } from 'uuid';
|
|
9
|
+
|
|
10
|
+
import { generateInstructionsPrompt } from './Prompt/instruction.js';
|
|
11
|
+
|
|
12
|
+
@transient()
|
|
13
|
+
export class CompletionRequest {
|
|
14
|
+
isCancelFlag: boolean;
|
|
15
|
+
id: string;
|
|
16
|
+
|
|
17
|
+
constructor(
|
|
18
|
+
public context: ICompletionContext,
|
|
19
|
+
public token: CancellationToken,
|
|
20
|
+
) {
|
|
21
|
+
this.isCancelFlag = false;
|
|
22
|
+
this.id = v4();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 拼接上下文信息
|
|
26
|
+
protected constructRequestContext(
|
|
27
|
+
context: ICompletionContext,
|
|
28
|
+
token: CancellationToken,
|
|
29
|
+
): IAICompletionOption {
|
|
30
|
+
// const prompt = lineBasedPromptProcessor.processPrefix(context.prefix);
|
|
31
|
+
// const suffix = lineBasedPromptProcessor.processSuffix(context.suffix);
|
|
32
|
+
const prompt = context.prefix;
|
|
33
|
+
const suffix = context.suffix;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
prompt,
|
|
37
|
+
suffix,
|
|
38
|
+
sessionId: v4(),
|
|
39
|
+
language: context.language,
|
|
40
|
+
fileUrl: context.fileUrl,
|
|
41
|
+
// workspaceDir: context.workspaceDir,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cancelRequest() {
|
|
46
|
+
this.isCancelFlag = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 向大模型发送请求
|
|
50
|
+
async run() {
|
|
51
|
+
const { context, token } = this;
|
|
52
|
+
|
|
53
|
+
if (this.isCancelFlag || token.isCancellationRequested) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let completeResult: IIntelligentCompletionsResult | undefined;
|
|
58
|
+
const requestBean = await this.constructRequestContext(context, token);
|
|
59
|
+
try {
|
|
60
|
+
completeResult = await this.complete(requestBean);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error('Inline Completion Request Error:', e);
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
// 结果format 及推送,先直接返回
|
|
66
|
+
|
|
67
|
+
return [...(completeResult?.items || [])];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
protected async complete(
|
|
71
|
+
data: IAICompletionOption,
|
|
72
|
+
): Promise<IIntelligentCompletionsResult | undefined> {
|
|
73
|
+
// 调用大模型非流式接口
|
|
74
|
+
const url = `/libro/api/chat`;
|
|
75
|
+
|
|
76
|
+
const instruction = generateInstructionsPrompt(
|
|
77
|
+
data.language,
|
|
78
|
+
data.prompt,
|
|
79
|
+
data.suffix || '',
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const res = await fetch(url, {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: {
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
},
|
|
87
|
+
body: JSON.stringify({ prompt: instruction }),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const responseData = await res.json();
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
items: [{ insertText: responseData.res }], // Expecting the result to be in this structure
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('Error parsing JSON response:', error);
|
|
98
|
+
return undefined; // Or handle the error appropriately
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { AICompletionContribution } from './inline-completion-contribution.js';
|
|
5
|
+
import { AICompletionProvider } from './inline-completion-provider.js';
|
|
6
|
+
import { CompletionRequest } from './inline-completion-request.js';
|
|
7
|
+
|
|
8
|
+
export const LibroAICompletionModule = ManaModule.create()
|
|
9
|
+
.register(CompletionRequest, AICompletionProvider, AICompletionContribution)
|
|
10
|
+
.dependOn(CodeEditorModule);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { CancellationToken } from '@difizen/libro-code-editor';
|
|
2
|
+
|
|
3
|
+
import { lineBasedCompletionModelConfigs } from './contant.js';
|
|
4
|
+
|
|
5
|
+
// 去除多余的空行,并且限制前文的长度
|
|
6
|
+
function processPrefix(prompt: string): string {
|
|
7
|
+
// remove all empty lines
|
|
8
|
+
prompt = prompt.replace(/^s*[\n]/gm, '');
|
|
9
|
+
const arr = prompt.split('\n');
|
|
10
|
+
// if the number of lines is greater than n, take the last n lines
|
|
11
|
+
if (arr.length > lineBasedCompletionModelConfigs.completionPromptMaxLineSize) {
|
|
12
|
+
prompt = arr
|
|
13
|
+
.slice(-lineBasedCompletionModelConfigs.completionPromptMaxLineSize)
|
|
14
|
+
.join('\n');
|
|
15
|
+
}
|
|
16
|
+
return prompt;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 去除多余的空行,并且限制后文的长度
|
|
20
|
+
function processSuffix(suffix: string): string {
|
|
21
|
+
suffix = suffix.replace(/^s*[\n]/gm, '');
|
|
22
|
+
const arr = suffix.split('\n');
|
|
23
|
+
if (arr.length > lineBasedCompletionModelConfigs.completionSuffixMaxLineSize) {
|
|
24
|
+
suffix = arr
|
|
25
|
+
.slice(-lineBasedCompletionModelConfigs.completionSuffixMaxLineSize)
|
|
26
|
+
.join('\n');
|
|
27
|
+
}
|
|
28
|
+
return suffix;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const lineBasedPromptProcessor = {
|
|
32
|
+
processPrefix,
|
|
33
|
+
processSuffix,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function sleep(time: number) {
|
|
37
|
+
return new Promise<void>((resolve) => setTimeout(resolve, time));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function raceCancellation<T>(
|
|
41
|
+
promise: Promise<T>,
|
|
42
|
+
token: CancellationToken,
|
|
43
|
+
): Promise<T | undefined>;
|
|
44
|
+
export function raceCancellation<T>(
|
|
45
|
+
promise: Promise<T>,
|
|
46
|
+
token: CancellationToken,
|
|
47
|
+
defaultValue: T,
|
|
48
|
+
): Promise<T>;
|
|
49
|
+
export function raceCancellation<T>(
|
|
50
|
+
promise: Promise<T>,
|
|
51
|
+
token: CancellationToken,
|
|
52
|
+
defaultValue?: T,
|
|
53
|
+
): Promise<T | undefined> {
|
|
54
|
+
return Promise.race([
|
|
55
|
+
promise,
|
|
56
|
+
new Promise<T | undefined>((resolve) =>
|
|
57
|
+
token.onCancellationRequested(() => resolve(defaultValue)),
|
|
58
|
+
),
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
@@ -35,6 +35,7 @@ export function LibroAINativeForCellRender() {
|
|
|
35
35
|
const libroAINativeService = useInject<LibroAINativeService>(LibroAINativeService);
|
|
36
36
|
|
|
37
37
|
const msgItem = useObserve(instance.libroAIChatMessageItemModel);
|
|
38
|
+
|
|
38
39
|
if (!instance.showAI) {
|
|
39
40
|
return null;
|
|
40
41
|
}
|
|
@@ -92,6 +93,7 @@ export class LibroAINativeForCellView extends BaseView {
|
|
|
92
93
|
showAI = false;
|
|
93
94
|
constructor(@inject(ViewOption) options: IAINativeForCellViewOption) {
|
|
94
95
|
super();
|
|
96
|
+
|
|
95
97
|
this.cell = options.cell;
|
|
96
98
|
}
|
|
97
99
|
|
package/src/index.ts
CHANGED
package/src/module.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { CodeEditorModule } from '@difizen/libro-code-editor';
|
|
1
2
|
import { CellOutputTopProvider, ErrorOutputModel } from '@difizen/libro-jupyter';
|
|
2
3
|
import { ChatView } from '@difizen/magent-chat';
|
|
3
4
|
import { LibroChatModule, LibroChatService } from '@difizen/magent-libro';
|
|
4
5
|
import { ManaModule } from '@difizen/mana-app';
|
|
5
6
|
|
|
7
|
+
import { LibroAICompletionModule } from './ai-inline-completions/module.js';
|
|
6
8
|
import { LibroAINativeCommandContribution } from './ai-native-command-contribution.js';
|
|
7
9
|
import { LibroAINativeForCellView } from './ai-native-for-cell-view.js';
|
|
8
10
|
import { LibroAINativeCellTopBlank } from './ai-native-output-top.js';
|
|
@@ -15,6 +17,10 @@ import { LibroAINativeChatService } from './libro-ai-native-chat-service.js';
|
|
|
15
17
|
import { LibroAiNativeChatView } from './libro-ai-native-chat-view.js';
|
|
16
18
|
import { LibroAINativeColorRegistry } from './libro-ai-native-color-registry.js';
|
|
17
19
|
|
|
20
|
+
export const LibroAINativeModuleSetting = {
|
|
21
|
+
loadable: true,
|
|
22
|
+
};
|
|
23
|
+
|
|
18
24
|
export const LibroAINativeModule = ManaModule.create()
|
|
19
25
|
.register(
|
|
20
26
|
LibroAINativeColorRegistry,
|
|
@@ -41,4 +47,5 @@ export const LibroAINativeModule = ManaModule.create()
|
|
|
41
47
|
useValue: LibroAINativeCellTopBlank,
|
|
42
48
|
},
|
|
43
49
|
)
|
|
44
|
-
.
|
|
50
|
+
.canload(() => Promise.resolve(LibroAINativeModuleSetting.loadable))
|
|
51
|
+
.dependOn(LibroChatModule, CodeEditorModule, LibroAICompletionModule);
|