@difizen/libro-ai-native 0.0.0-snapshot-20250205064331

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/ai-inline-completions/Prompt/instruction.d.ts +2 -0
  4. package/es/ai-inline-completions/Prompt/instruction.d.ts.map +1 -0
  5. package/es/ai-inline-completions/Prompt/instruction.js +3 -0
  6. package/es/ai-inline-completions/contant.d.ts +5 -0
  7. package/es/ai-inline-completions/contant.d.ts.map +1 -0
  8. package/es/ai-inline-completions/contant.js +5 -0
  9. package/es/ai-inline-completions/index.d.ts +4 -0
  10. package/es/ai-inline-completions/index.d.ts.map +1 -0
  11. package/es/ai-inline-completions/index.js +3 -0
  12. package/es/ai-inline-completions/inline-completion-contribution.d.ts +11 -0
  13. package/es/ai-inline-completions/inline-completion-contribution.d.ts.map +1 -0
  14. package/es/ai-inline-completions/inline-completion-contribution.js +66 -0
  15. package/es/ai-inline-completions/inline-completion-provider.d.ts +19 -0
  16. package/es/ai-inline-completions/inline-completion-provider.d.ts.map +1 -0
  17. package/es/ai-inline-completions/inline-completion-provider.js +128 -0
  18. package/es/ai-inline-completions/inline-completion-request.d.ts +13 -0
  19. package/es/ai-inline-completions/inline-completion-request.d.ts.map +1 -0
  20. package/es/ai-inline-completions/inline-completion-request.js +149 -0
  21. package/es/ai-inline-completions/module.d.ts +3 -0
  22. package/es/ai-inline-completions/module.d.ts.map +1 -0
  23. package/es/ai-inline-completions/module.js +6 -0
  24. package/es/ai-inline-completions/utils.d.ts +12 -0
  25. package/es/ai-inline-completions/utils.d.ts.map +1 -0
  26. package/es/ai-inline-completions/utils.js +39 -0
  27. package/es/ai-native-code-block.d.ts +4 -0
  28. package/es/ai-native-code-block.d.ts.map +1 -0
  29. package/es/ai-native-code-block.js +177 -0
  30. package/es/ai-native-command-contribution.d.ts +16 -0
  31. package/es/ai-native-command-contribution.d.ts.map +1 -0
  32. package/es/ai-native-command-contribution.js +344 -0
  33. package/es/ai-native-command.d.ts +5 -0
  34. package/es/ai-native-command.d.ts.map +1 -0
  35. package/es/ai-native-command.js +21 -0
  36. package/es/ai-native-for-cell-view.d.ts +21 -0
  37. package/es/ai-native-for-cell-view.d.ts.map +1 -0
  38. package/es/ai-native-for-cell-view.js +222 -0
  39. package/es/ai-native-output-top.d.ts +6 -0
  40. package/es/ai-native-output-top.d.ts.map +1 -0
  41. package/es/ai-native-output-top.js +37 -0
  42. package/es/ai-native-service.d.ts +16 -0
  43. package/es/ai-native-service.d.ts.map +1 -0
  44. package/es/ai-native-service.js +78 -0
  45. package/es/ai-side-toolbar-selector.d.ts +3 -0
  46. package/es/ai-side-toolbar-selector.d.ts.map +1 -0
  47. package/es/ai-side-toolbar-selector.js +47 -0
  48. package/es/chat-slot-contribution.d.ts +15 -0
  49. package/es/chat-slot-contribution.d.ts.map +1 -0
  50. package/es/chat-slot-contribution.js +70 -0
  51. package/es/chat-view.d.ts +19 -0
  52. package/es/chat-view.d.ts.map +1 -0
  53. package/es/chat-view.js +195 -0
  54. package/es/error-output-model.d.ts +8 -0
  55. package/es/error-output-model.d.ts.map +1 -0
  56. package/es/error-output-model.js +144 -0
  57. package/es/icon.d.ts +4 -0
  58. package/es/icon.d.ts.map +1 -0
  59. package/es/icon.js +92 -0
  60. package/es/index.d.ts +7 -0
  61. package/es/index.d.ts.map +1 -0
  62. package/es/index.js +6 -0
  63. package/es/index.less +332 -0
  64. package/es/libro-ai-msg-item-model.d.ts +18 -0
  65. package/es/libro-ai-msg-item-model.d.ts.map +1 -0
  66. package/es/libro-ai-msg-item-model.js +86 -0
  67. package/es/libro-ai-native-chat-service.d.ts +8 -0
  68. package/es/libro-ai-native-chat-service.d.ts.map +1 -0
  69. package/es/libro-ai-native-chat-service.js +174 -0
  70. package/es/libro-ai-native-chat-view.d.ts +46 -0
  71. package/es/libro-ai-native-chat-view.d.ts.map +1 -0
  72. package/es/libro-ai-native-chat-view.js +89 -0
  73. package/es/libro-ai-native-color-registry.d.ts +6 -0
  74. package/es/libro-ai-native-color-registry.d.ts.map +1 -0
  75. package/es/libro-ai-native-color-registry.js +46 -0
  76. package/es/module.d.ts +6 -0
  77. package/es/module.d.ts.map +1 -0
  78. package/es/module.js +35 -0
  79. package/es/protocol.d.ts +16 -0
  80. package/es/protocol.d.ts.map +1 -0
  81. package/es/protocol.js +1 -0
  82. package/es/utils.d.ts +5 -0
  83. package/es/utils.d.ts.map +1 -0
  84. package/es/utils.js +31 -0
  85. package/package.json +77 -0
  86. package/src/ai-inline-completions/Prompt/instruction.ts +36 -0
  87. package/src/ai-inline-completions/contant.ts +5 -0
  88. package/src/ai-inline-completions/index.ts +3 -0
  89. package/src/ai-inline-completions/inline-completion-contribution.ts +36 -0
  90. package/src/ai-inline-completions/inline-completion-provider.ts +102 -0
  91. package/src/ai-inline-completions/inline-completion-request.ts +101 -0
  92. package/src/ai-inline-completions/module.ts +10 -0
  93. package/src/ai-inline-completions/utils.ts +60 -0
  94. package/src/ai-native-code-block.tsx +138 -0
  95. package/src/ai-native-command-contribution.tsx +252 -0
  96. package/src/ai-native-command.ts +23 -0
  97. package/src/ai-native-for-cell-view.tsx +168 -0
  98. package/src/ai-native-output-top.tsx +43 -0
  99. package/src/ai-native-service.ts +39 -0
  100. package/src/ai-side-toolbar-selector.tsx +51 -0
  101. package/src/chat-slot-contribution.ts +36 -0
  102. package/src/chat-view.tsx +142 -0
  103. package/src/error-output-model.tsx +106 -0
  104. package/src/icon.tsx +80 -0
  105. package/src/index.less +332 -0
  106. package/src/index.spec.ts +8 -0
  107. package/src/index.ts +6 -0
  108. package/src/libro-ai-msg-item-model.ts +69 -0
  109. package/src/libro-ai-native-chat-service.ts +102 -0
  110. package/src/libro-ai-native-chat-view.tsx +58 -0
  111. package/src/libro-ai-native-color-registry.ts +33 -0
  112. package/src/module.ts +51 -0
  113. package/src/protocol.ts +18 -0
  114. package/src/utils.tsx +33 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # libro-ai-native
@@ -0,0 +1,2 @@
1
+ export declare const generateInstructionsPrompt: (language: string, prompt: string, suffix: string) => string;
2
+ //# sourceMappingURL=instruction.d.ts.map
@@ -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,5 @@
1
+ export declare const lineBasedCompletionModelConfigs: {
2
+ completionPromptMaxLineSize: number;
3
+ completionSuffixMaxLineSize: number;
4
+ };
5
+ //# sourceMappingURL=contant.d.ts.map
@@ -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,5 @@
1
+ // 光标所在位置的上下文窗口大小
2
+ export var lineBasedCompletionModelConfigs = {
3
+ completionPromptMaxLineSize: 1024,
4
+ completionSuffixMaxLineSize: 500
5
+ };
@@ -0,0 +1,4 @@
1
+ export * from './inline-completion-request.js';
2
+ export * from './inline-completion-provider.js';
3
+ export * from './module.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export * from "./inline-completion-request.js";
2
+ export * from "./inline-completion-provider.js";
3
+ export * from "./module.js";
@@ -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, EditorCancellationToken, IIntelligentCompletionsResult, ICompletionContext } from '@difizen/libro-code-editor';
2
+ import { AiCompletionRequest } from './inline-completion-request.js';
3
+ declare class ReqStack {
4
+ queue: AiCompletionRequest[];
5
+ constructor();
6
+ addReq(reqRequest: AiCompletionRequest): 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: EditorCancellationToken): 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,uBAAuB,EACvB,6BAA6B,EAC7B,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAcrE,cAAM,QAAQ;IACZ,KAAK,EAAE,mBAAmB,EAAE,CAAC;;IAI7B,MAAM,CAAC,UAAU,EAAE,mBAAmB;IAGtC,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,uBAAuB;IA4BhC,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 { AiCompletionRequest } 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 AiCompletionRequest(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, EditorCancellationToken } from '@difizen/libro-code-editor';
2
+ export declare class AiCompletionRequest {
3
+ context: ICompletionContext;
4
+ token: EditorCancellationToken;
5
+ isCancelFlag: boolean;
6
+ id: string;
7
+ constructor(context: ICompletionContext, token: EditorCancellationToken);
8
+ protected constructRequestContext(context: ICompletionContext, token: EditorCancellationToken): 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,uBAAuB,EACxB,MAAM,4BAA4B,CAAC;AAMpC,qBACa,mBAAmB;IAKrB,OAAO,EAAE,kBAAkB;IAC3B,KAAK,EAAE,uBAAuB;IALvC,YAAY,EAAE,OAAO,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;gBAGF,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,uBAAuB;IAOvC,SAAS,CAAC,uBAAuB,CAC/B,OAAO,EAAE,kBAAkB,EAC3B,KAAK,EAAE,uBAAuB,GAC7B,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 AiCompletionRequest = (_dec = transient(), _dec(_class = /*#__PURE__*/function () {
21
+ function AiCompletionRequest(context, token) {
22
+ _classCallCheck(this, AiCompletionRequest);
23
+ this.context = context;
24
+ this.token = token;
25
+ this.isCancelFlag = false;
26
+ this.id = v4();
27
+ }
28
+
29
+ // 拼接上下文信息
30
+ _createClass(AiCompletionRequest, [{
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 AiCompletionRequest;
149
+ }()) || _class);
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const LibroAICompletionModule: ManaModule;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -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 { AiCompletionRequest } from "./inline-completion-request.js";
6
+ export var LibroAICompletionModule = ManaModule.create().register(AiCompletionRequest, AICompletionProvider, AICompletionContribution).dependOn(CodeEditorModule);
@@ -0,0 +1,12 @@
1
+ import type { EditorCancellationToken } 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: EditorCancellationToken): Promise<T | undefined>;
10
+ export declare function raceCancellation<T>(promise: Promise<T>, token: EditorCancellationToken, 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,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAK1E,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,uBAAuB,GAC7B,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAC1B,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,uBAAuB,EAC9B,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
+ }
@@ -0,0 +1,4 @@
1
+ import './index.less';
2
+ export declare const CodeBlockInCell: (props: any) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const CodeBlockInChat: (props: any) => import("react/jsx-runtime").JSX.Element;
4
+ //# sourceMappingURL=ai-native-code-block.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-native-code-block.d.ts","sourceRoot":"","sources":["../src/ai-native-code-block.tsx"],"names":[],"mappings":"AASA,OAAO,cAAc,CAAC;AAItB,eAAO,MAAM,eAAe,UAAW,GAAG,4CAiDzC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,GAAG,4CAyEzC,CAAC"}