@difizen/libro-ai-native 0.2.41-next.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/LICENSE +21 -0
- package/README.md +1 -0
- package/es/ai-native-code-block.d.ts +4 -0
- package/es/ai-native-code-block.d.ts.map +1 -0
- package/es/ai-native-code-block.js +176 -0
- package/es/ai-native-command-contribution.d.ts +16 -0
- package/es/ai-native-command-contribution.d.ts.map +1 -0
- package/es/ai-native-command-contribution.js +297 -0
- package/es/ai-native-command.d.ts +5 -0
- package/es/ai-native-command.d.ts.map +1 -0
- package/es/ai-native-command.js +17 -0
- package/es/ai-native-for-cell-view.d.ts +20 -0
- package/es/ai-native-for-cell-view.d.ts.map +1 -0
- package/es/ai-native-for-cell-view.js +190 -0
- package/es/ai-native-output-top.d.ts +6 -0
- package/es/ai-native-output-top.d.ts.map +1 -0
- package/es/ai-native-output-top.js +37 -0
- package/es/ai-native-service.d.ts +13 -0
- package/es/ai-native-service.d.ts.map +1 -0
- package/es/ai-native-service.js +75 -0
- package/es/ai-side-toolbar-selector.d.ts +3 -0
- package/es/ai-side-toolbar-selector.d.ts.map +1 -0
- package/es/ai-side-toolbar-selector.js +47 -0
- package/es/chat-slot-contribution.d.ts +15 -0
- package/es/chat-slot-contribution.d.ts.map +1 -0
- package/es/chat-slot-contribution.js +71 -0
- package/es/chat-view.d.ts +15 -0
- package/es/chat-view.d.ts.map +1 -0
- package/es/chat-view.js +114 -0
- package/es/error-output-model.d.ts +8 -0
- package/es/error-output-model.d.ts.map +1 -0
- package/es/error-output-model.js +140 -0
- package/es/icon.d.ts +4 -0
- package/es/icon.d.ts.map +1 -0
- package/es/icon.js +92 -0
- package/es/index.d.ts +6 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5 -0
- package/es/index.less +297 -0
- package/es/libro-ai-msg-item-model.d.ts +18 -0
- package/es/libro-ai-msg-item-model.d.ts.map +1 -0
- package/es/libro-ai-msg-item-model.js +85 -0
- package/es/libro-ai-native-chat-service.d.ts +8 -0
- package/es/libro-ai-native-chat-service.d.ts.map +1 -0
- package/es/libro-ai-native-chat-service.js +157 -0
- package/es/libro-ai-native-chat-view.d.ts +42 -0
- package/es/libro-ai-native-chat-view.d.ts.map +1 -0
- package/es/libro-ai-native-chat-view.js +88 -0
- package/es/libro-ai-native-color-registry.d.ts +6 -0
- package/es/libro-ai-native-color-registry.d.ts.map +1 -0
- package/es/libro-ai-native-color-registry.js +46 -0
- package/es/module.d.ts +3 -0
- package/es/module.d.ts.map +1 -0
- package/es/module.js +28 -0
- package/es/protocol.d.ts +10 -0
- package/es/protocol.d.ts.map +1 -0
- package/es/protocol.js +1 -0
- package/es/utils.js +114 -0
- package/package.json +74 -0
- package/src/ai-native-code-block.tsx +138 -0
- package/src/ai-native-command-contribution.tsx +248 -0
- package/src/ai-native-command.ts +23 -0
- package/src/ai-native-for-cell-view.tsx +156 -0
- package/src/ai-native-output-top.tsx +43 -0
- package/src/ai-native-service.ts +39 -0
- package/src/ai-side-toolbar-selector.tsx +51 -0
- package/src/chat-slot-contribution.ts +36 -0
- package/src/chat-view.tsx +141 -0
- package/src/error-output-model.tsx +103 -0
- package/src/icon.tsx +80 -0
- package/src/index.less +330 -0
- package/src/index.spec.ts +8 -0
- package/src/index.ts +5 -0
- package/src/libro-ai-msg-item-model.ts +69 -0
- package/src/libro-ai-native-chat-service.ts +95 -0
- package/src/libro-ai-native-chat-view.tsx +54 -0
- package/src/libro-ai-native-color-registry.ts +33 -0
- package/src/module.ts +44 -0
- package/src/protocol.ts +18 -0
- package/src/utils.tsx +115 -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 @@
|
|
|
1
|
+
{"version":3,"file":"ai-native-code-block.d.ts","sourceRoot":"","sources":["../src/ai-native-code-block.tsx"],"names":[],"mappings":"AAQA,OAAO,cAAc,CAAC;AAItB,eAAO,MAAM,eAAe,UAAW,GAAG,4CAiDzC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,GAAG,4CAyEzC,CAAC"}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { CopyOutlined } from '@ant-design/icons';
|
|
12
|
+
import { LibroCodeCellView } from '@difizen/libro-jupyter';
|
|
13
|
+
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
14
|
+
import { Button, message } from 'antd';
|
|
15
|
+
import copy from 'copy-to-clipboard';
|
|
16
|
+
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
17
|
+
import { v4 } from 'uuid';
|
|
18
|
+
import "./index.less";
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
21
|
+
export var CodeBlockInCell = function CodeBlockInCell(props) {
|
|
22
|
+
var className = props.className,
|
|
23
|
+
children = props.children;
|
|
24
|
+
var instance = useInject(ViewInstance);
|
|
25
|
+
var cell = instance.cell;
|
|
26
|
+
var replace = function replace(data) {
|
|
27
|
+
if (cell instanceof LibroCodeCellView && cell.editor) {
|
|
28
|
+
var length = cell.editor.model.value.length;
|
|
29
|
+
var start = cell.editor.getPositionAt(0);
|
|
30
|
+
var end = cell.editor.getPositionAt(length);
|
|
31
|
+
if (start && end) {
|
|
32
|
+
cell.editor.replaceSelection(data, {
|
|
33
|
+
start: start,
|
|
34
|
+
end: end
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
if (!props.inline && className) {
|
|
40
|
+
var _ref = /language-(\w+)/.exec(className || '') || [],
|
|
41
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
42
|
+
lang = _ref2[1];
|
|
43
|
+
return /*#__PURE__*/_jsxs("pre", {
|
|
44
|
+
className: "chat-msg-md-code-wrap",
|
|
45
|
+
children: [lang && /*#__PURE__*/_jsx("div", {
|
|
46
|
+
className: "chat-msg-md-code-lang",
|
|
47
|
+
children: lang
|
|
48
|
+
}), /*#__PURE__*/_jsx(CopyOutlined, {
|
|
49
|
+
onClick: function onClick() {
|
|
50
|
+
copy(children);
|
|
51
|
+
message.success('代码已复制');
|
|
52
|
+
},
|
|
53
|
+
className: "chat-msg-md-code-copy"
|
|
54
|
+
}), /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
55
|
+
className: "libro-llm-syntax-highlighter",
|
|
56
|
+
language: lang,
|
|
57
|
+
style: {},
|
|
58
|
+
children: typeof children === 'string' ? children.trim() : children
|
|
59
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
60
|
+
className: "libro-ai-native-debug-code-btn-container",
|
|
61
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
62
|
+
color: "primary",
|
|
63
|
+
variant: "outlined",
|
|
64
|
+
onClick: function onClick() {
|
|
65
|
+
return replace(children);
|
|
66
|
+
},
|
|
67
|
+
children: "\u66FF\u6362\u4EE3\u7801"
|
|
68
|
+
})
|
|
69
|
+
})]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return /*#__PURE__*/_jsx("code", {
|
|
73
|
+
className: "chat-msg-md-code-code",
|
|
74
|
+
children: children
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export var CodeBlockInChat = function CodeBlockInChat(props) {
|
|
78
|
+
var _instance$libro;
|
|
79
|
+
var className = props.className,
|
|
80
|
+
children = props.children;
|
|
81
|
+
var instance = useInject(ViewInstance);
|
|
82
|
+
var cell = (_instance$libro = instance.libro) === null || _instance$libro === void 0 ? void 0 : _instance$libro.activeCell;
|
|
83
|
+
var insertCell = /*#__PURE__*/function () {
|
|
84
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
|
|
85
|
+
var libro, insertIndex;
|
|
86
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
87
|
+
while (1) switch (_context.prev = _context.next) {
|
|
88
|
+
case 0:
|
|
89
|
+
libro = instance.libro;
|
|
90
|
+
if (libro) {
|
|
91
|
+
_context.next = 3;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return _context.abrupt("return");
|
|
95
|
+
case 3:
|
|
96
|
+
insertIndex = libro.model.cells.findIndex(function (c) {
|
|
97
|
+
var _libro$activeCell;
|
|
98
|
+
return c.id === ((_libro$activeCell = libro.activeCell) === null || _libro$activeCell === void 0 ? void 0 : _libro$activeCell.id);
|
|
99
|
+
});
|
|
100
|
+
_context.next = 6;
|
|
101
|
+
return libro.addCell({
|
|
102
|
+
id: v4(),
|
|
103
|
+
cell: {
|
|
104
|
+
cell_type: 'code',
|
|
105
|
+
source: data,
|
|
106
|
+
metadata: {}
|
|
107
|
+
}
|
|
108
|
+
}, insertIndex + 1);
|
|
109
|
+
case 6:
|
|
110
|
+
case "end":
|
|
111
|
+
return _context.stop();
|
|
112
|
+
}
|
|
113
|
+
}, _callee);
|
|
114
|
+
}));
|
|
115
|
+
return function insertCell(_x) {
|
|
116
|
+
return _ref3.apply(this, arguments);
|
|
117
|
+
};
|
|
118
|
+
}();
|
|
119
|
+
var replace = function replace(data) {
|
|
120
|
+
if (cell instanceof LibroCodeCellView && cell.editor) {
|
|
121
|
+
var length = cell.editor.model.value.length;
|
|
122
|
+
var start = cell.editor.getPositionAt(0);
|
|
123
|
+
var end = cell.editor.getPositionAt(length);
|
|
124
|
+
if (start && end) {
|
|
125
|
+
cell.editor.replaceSelection(data, {
|
|
126
|
+
start: start,
|
|
127
|
+
end: end
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
if (!props.inline && className) {
|
|
133
|
+
var _ref4 = /language-(\w+)/.exec(className || '') || [],
|
|
134
|
+
_ref5 = _slicedToArray(_ref4, 2),
|
|
135
|
+
lang = _ref5[1];
|
|
136
|
+
return /*#__PURE__*/_jsxs("pre", {
|
|
137
|
+
className: "chat-msg-md-code-wrap",
|
|
138
|
+
children: [lang && /*#__PURE__*/_jsx("div", {
|
|
139
|
+
className: "chat-msg-md-code-lang",
|
|
140
|
+
children: lang
|
|
141
|
+
}), /*#__PURE__*/_jsx(CopyOutlined, {
|
|
142
|
+
onClick: function onClick() {
|
|
143
|
+
copy(children);
|
|
144
|
+
message.success('代码已复制');
|
|
145
|
+
},
|
|
146
|
+
className: "chat-msg-md-code-copy"
|
|
147
|
+
}), /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
148
|
+
className: "libro-llm-syntax-highlighter",
|
|
149
|
+
language: lang,
|
|
150
|
+
style: {},
|
|
151
|
+
children: typeof children === 'string' ? children.trim() : children
|
|
152
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
153
|
+
className: "libro-ai-native-debug-code-btn-container",
|
|
154
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
155
|
+
color: "primary",
|
|
156
|
+
variant: "outlined",
|
|
157
|
+
onClick: function onClick() {
|
|
158
|
+
return insertCell(children);
|
|
159
|
+
},
|
|
160
|
+
children: "\u63D2\u5165 Cell"
|
|
161
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
162
|
+
color: "primary",
|
|
163
|
+
variant: "outlined",
|
|
164
|
+
onClick: function onClick() {
|
|
165
|
+
return replace(children);
|
|
166
|
+
},
|
|
167
|
+
children: "\u66FF\u6362 Cell"
|
|
168
|
+
})]
|
|
169
|
+
})]
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return /*#__PURE__*/_jsx("code", {
|
|
173
|
+
className: "chat-msg-md-code-code",
|
|
174
|
+
children: children
|
|
175
|
+
});
|
|
176
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LibroCommandRegister, LibroSlotManager } from '@difizen/libro-jupyter';
|
|
2
|
+
import type { CommandRegistry, ToolbarRegistry } from '@difizen/mana-app';
|
|
3
|
+
import { CommandContribution } from '@difizen/mana-app';
|
|
4
|
+
import { ToolbarContribution, ViewManager } from '@difizen/mana-app';
|
|
5
|
+
import { LibroAINativeService } from './ai-native-service.js';
|
|
6
|
+
import { LibroAIChatSlotContribution } from './chat-slot-contribution.js';
|
|
7
|
+
export declare class LibroAINativeCommandContribution implements ToolbarContribution, CommandContribution {
|
|
8
|
+
protected readonly libroCommand: LibroCommandRegister;
|
|
9
|
+
libroAIChatSlotContribution: LibroAIChatSlotContribution;
|
|
10
|
+
libroSlotManager: LibroSlotManager;
|
|
11
|
+
libroAINativeService: LibroAINativeService;
|
|
12
|
+
viewManager: ViewManager;
|
|
13
|
+
registerToolbarItems(registry: ToolbarRegistry): void;
|
|
14
|
+
registerCommands(command: CommandRegistry): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ai-native-command-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-native-command-contribution.d.ts","sourceRoot":"","sources":["../src/ai-native-command-contribution.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAa,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAG1E,qBACa,gCACX,YAAW,mBAAmB,EAAE,mBAAmB;IAErB,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAEpF,2BAA2B,EAAE,2BAA2B,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;IAC/B,oBAAoB,EAAE,oBAAoB,CAAC;IACpD,WAAW,EAAE,WAAW,CAAC;IAE9C,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAgBrD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;CAyJjD"}
|
|
@@ -0,0 +1,297 @@
|
|
|
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, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5;
|
|
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 _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
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); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
|
+
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); }
|
|
12
|
+
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
|
+
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { LibroCommandRegister, LibroSlotManager, LibroSlotView, LibroToolbarArea, LibroCellView, LibroView } from '@difizen/libro-jupyter';
|
|
15
|
+
import { inject } from '@difizen/mana-app';
|
|
16
|
+
import { CommandContribution } from '@difizen/mana-app';
|
|
17
|
+
import { singleton, ToolbarContribution, ViewManager } from '@difizen/mana-app';
|
|
18
|
+
import { AINativeCommands } from "./ai-native-command.js";
|
|
19
|
+
import { LibroAINativeService } from "./ai-native-service.js";
|
|
20
|
+
import { AIToolbarSelector } from "./ai-side-toolbar-selector.js";
|
|
21
|
+
import { LibroAIChatSlotContribution } from "./chat-slot-contribution.js";
|
|
22
|
+
import { AIIcon } from "./icon.js";
|
|
23
|
+
export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
24
|
+
contrib: [CommandContribution, ToolbarContribution]
|
|
25
|
+
}), _dec2 = inject(LibroCommandRegister), _dec3 = inject(LibroAIChatSlotContribution), _dec4 = inject(LibroSlotManager), _dec5 = inject(LibroAINativeService), _dec6 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
26
|
+
function LibroAINativeCommandContribution() {
|
|
27
|
+
_classCallCheck(this, LibroAINativeCommandContribution);
|
|
28
|
+
_initializerDefineProperty(this, "libroCommand", _descriptor, this);
|
|
29
|
+
_initializerDefineProperty(this, "libroAIChatSlotContribution", _descriptor2, this);
|
|
30
|
+
_initializerDefineProperty(this, "libroSlotManager", _descriptor3, this);
|
|
31
|
+
_initializerDefineProperty(this, "libroAINativeService", _descriptor4, this);
|
|
32
|
+
_initializerDefineProperty(this, "viewManager", _descriptor5, this);
|
|
33
|
+
}
|
|
34
|
+
_createClass(LibroAINativeCommandContribution, [{
|
|
35
|
+
key: "registerToolbarItems",
|
|
36
|
+
value: function registerToolbarItems(registry) {
|
|
37
|
+
registry.registerItem({
|
|
38
|
+
id: AINativeCommands['AISideToolbarSelect'].id,
|
|
39
|
+
command: AINativeCommands['AISideToolbarSelect'].id,
|
|
40
|
+
icon: AIToolbarSelector,
|
|
41
|
+
showLabelInline: true,
|
|
42
|
+
group: ['group2'],
|
|
43
|
+
order: 'a'
|
|
44
|
+
});
|
|
45
|
+
registry.registerItem({
|
|
46
|
+
id: AINativeCommands['Chat'].id,
|
|
47
|
+
command: AINativeCommands['Chat'].id,
|
|
48
|
+
icon: AIIcon,
|
|
49
|
+
order: 'a'
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "registerCommands",
|
|
54
|
+
value: function registerCommands(command) {
|
|
55
|
+
var _this = this;
|
|
56
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['AISideToolbarSelect'], {
|
|
57
|
+
execute: function () {
|
|
58
|
+
var _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
59
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context.stop();
|
|
64
|
+
}
|
|
65
|
+
}, _callee);
|
|
66
|
+
}));
|
|
67
|
+
function execute() {
|
|
68
|
+
return _execute.apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
return execute;
|
|
71
|
+
}(),
|
|
72
|
+
isVisible: function isVisible(cell, libro, path) {
|
|
73
|
+
if (!cell || !libro || !(libro instanceof LibroView)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return path === LibroToolbarArea.CellRight;
|
|
77
|
+
},
|
|
78
|
+
isEnabled: function isEnabled(cell, libro) {
|
|
79
|
+
if (!libro || !(libro instanceof LibroView)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['CellChat'], {
|
|
86
|
+
execute: function () {
|
|
87
|
+
var _execute2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(cell, libro) {
|
|
88
|
+
var chatView, showChat;
|
|
89
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
90
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
91
|
+
case 0:
|
|
92
|
+
if (!(!libro || !cell)) {
|
|
93
|
+
_context2.next = 2;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
return _context2.abrupt("return");
|
|
97
|
+
case 2:
|
|
98
|
+
libro.model.libroViewClass = 'ai-cell-chat';
|
|
99
|
+
chatView = _this.libroAINativeService.chatViewMap.get(libro.id);
|
|
100
|
+
showChat = _this.libroAINativeService.showChatMap.get(libro.id);
|
|
101
|
+
if (!chatView) {
|
|
102
|
+
_context2.next = 11;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
chatView.chatView.isCellChat = true;
|
|
106
|
+
if (!showChat) {
|
|
107
|
+
_context2.next = 9;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return _context2.abrupt("return");
|
|
111
|
+
case 9:
|
|
112
|
+
_this.libroAINativeService.showChatMap.set(libro.id, !showChat);
|
|
113
|
+
_this.libroSlotManager.slotViewManager.addView(chatView, _this.libroSlotManager.getSlotName(libro, _this.libroAIChatSlotContribution.slot), {
|
|
114
|
+
reveal: true,
|
|
115
|
+
order: 'a'
|
|
116
|
+
});
|
|
117
|
+
case 11:
|
|
118
|
+
//优化交互,用于控制点击按钮后菜单消失
|
|
119
|
+
_this.libroAINativeService.showSideToolbar = false;
|
|
120
|
+
case 12:
|
|
121
|
+
case "end":
|
|
122
|
+
return _context2.stop();
|
|
123
|
+
}
|
|
124
|
+
}, _callee2);
|
|
125
|
+
}));
|
|
126
|
+
function execute(_x, _x2) {
|
|
127
|
+
return _execute2.apply(this, arguments);
|
|
128
|
+
}
|
|
129
|
+
return execute;
|
|
130
|
+
}(),
|
|
131
|
+
isEnabled: function isEnabled(cell, libro) {
|
|
132
|
+
if (!libro || !(libro instanceof LibroView)) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['Chat'], {
|
|
139
|
+
execute: function () {
|
|
140
|
+
var _execute3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(cell, libro) {
|
|
141
|
+
var chatView, showChat, slotview;
|
|
142
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
143
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
144
|
+
case 0:
|
|
145
|
+
if (!(!libro || !(libro instanceof LibroView))) {
|
|
146
|
+
_context3.next = 2;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
return _context3.abrupt("return");
|
|
150
|
+
case 2:
|
|
151
|
+
chatView = _this.libroAINativeService.chatViewMap.get(libro.id);
|
|
152
|
+
showChat = _this.libroAINativeService.showChatMap.get(libro.id);
|
|
153
|
+
_this.libroAINativeService.showChatMap;
|
|
154
|
+
if (!chatView) {
|
|
155
|
+
_context3.next = 12;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
if (!(showChat && chatView.chatView.isCellChat)) {
|
|
159
|
+
_context3.next = 9;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
chatView.chatView.isCellChat = false;
|
|
163
|
+
return _context3.abrupt("return");
|
|
164
|
+
case 9:
|
|
165
|
+
chatView.chatView.isCellChat = false;
|
|
166
|
+
_this.libroAINativeService.showChatMap.set(libro.id, !showChat);
|
|
167
|
+
if (showChat) {
|
|
168
|
+
slotview = _this.libroSlotManager.slotViewManager.getSlotView(_this.libroSlotManager.getSlotName(libro, 'right'));
|
|
169
|
+
if (slotview instanceof LibroSlotView) {
|
|
170
|
+
slotview.revertActive();
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
_this.libroSlotManager.slotViewManager.addView(chatView, _this.libroSlotManager.getSlotName(libro, _this.libroAIChatSlotContribution.slot), {
|
|
174
|
+
reveal: true,
|
|
175
|
+
order: 'a'
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
case 12:
|
|
179
|
+
_this.libroAINativeService.showSideToolbar = false;
|
|
180
|
+
case 13:
|
|
181
|
+
case "end":
|
|
182
|
+
return _context3.stop();
|
|
183
|
+
}
|
|
184
|
+
}, _callee3);
|
|
185
|
+
}));
|
|
186
|
+
function execute(_x3, _x4) {
|
|
187
|
+
return _execute3.apply(this, arguments);
|
|
188
|
+
}
|
|
189
|
+
return execute;
|
|
190
|
+
}(),
|
|
191
|
+
isVisible: function isVisible(cell, libro, path) {
|
|
192
|
+
if (!cell || !libro || !(libro instanceof LibroView)) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
return path === LibroToolbarArea.HeaderRight;
|
|
196
|
+
},
|
|
197
|
+
isEnabled: function isEnabled(cell, libro) {
|
|
198
|
+
if (!libro || !(libro instanceof LibroView)) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['Explain'], {
|
|
205
|
+
execute: function () {
|
|
206
|
+
var _execute4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(cell, libro) {
|
|
207
|
+
var libroAINativeForCellView;
|
|
208
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
209
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
if (!(!cell || !(cell instanceof LibroCellView) || !libro || !(libro instanceof LibroView))) {
|
|
212
|
+
_context4.next = 2;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
return _context4.abrupt("return");
|
|
216
|
+
case 2:
|
|
217
|
+
_context4.next = 4;
|
|
218
|
+
return _this.libroAINativeService.getOrCreateLibroAINativeForCellView(cell.id, cell);
|
|
219
|
+
case 4:
|
|
220
|
+
libroAINativeForCellView = _context4.sent;
|
|
221
|
+
libroAINativeForCellView.showAI = true;
|
|
222
|
+
libro.model.libroViewClass = 'ai-cell-chat';
|
|
223
|
+
libroAINativeForCellView.chatStream({
|
|
224
|
+
chat_key: 'LLM:gpt4',
|
|
225
|
+
content: "\u5E2E\u5FD9\u89E3\u91CA\u4E00\u4E0B\u8FD9\u6BB5\u4EE3\u7801\uFF1A".concat(cell.model.value)
|
|
226
|
+
});
|
|
227
|
+
// this.libroService.active?.enterEditMode();
|
|
228
|
+
case 8:
|
|
229
|
+
case "end":
|
|
230
|
+
return _context4.stop();
|
|
231
|
+
}
|
|
232
|
+
}, _callee4);
|
|
233
|
+
}));
|
|
234
|
+
function execute(_x5, _x6) {
|
|
235
|
+
return _execute4.apply(this, arguments);
|
|
236
|
+
}
|
|
237
|
+
return execute;
|
|
238
|
+
}(),
|
|
239
|
+
isEnabled: function isEnabled(cell, libro) {
|
|
240
|
+
if (!libro || !(libro instanceof LibroView)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['CellChat'], {
|
|
247
|
+
execute: function () {
|
|
248
|
+
var _execute5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
249
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
250
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
251
|
+
case 0:
|
|
252
|
+
case "end":
|
|
253
|
+
return _context5.stop();
|
|
254
|
+
}
|
|
255
|
+
}, _callee5);
|
|
256
|
+
}));
|
|
257
|
+
function execute() {
|
|
258
|
+
return _execute5.apply(this, arguments);
|
|
259
|
+
}
|
|
260
|
+
return execute;
|
|
261
|
+
}(),
|
|
262
|
+
isEnabled: function isEnabled(cell, libro) {
|
|
263
|
+
if (!libro || !(libro instanceof LibroView)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}]);
|
|
271
|
+
return LibroAINativeCommandContribution;
|
|
272
|
+
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroCommand", [_dec2], {
|
|
273
|
+
configurable: true,
|
|
274
|
+
enumerable: true,
|
|
275
|
+
writable: true,
|
|
276
|
+
initializer: null
|
|
277
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "libroAIChatSlotContribution", [_dec3], {
|
|
278
|
+
configurable: true,
|
|
279
|
+
enumerable: true,
|
|
280
|
+
writable: true,
|
|
281
|
+
initializer: null
|
|
282
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "libroSlotManager", [_dec4], {
|
|
283
|
+
configurable: true,
|
|
284
|
+
enumerable: true,
|
|
285
|
+
writable: true,
|
|
286
|
+
initializer: null
|
|
287
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "libroAINativeService", [_dec5], {
|
|
288
|
+
configurable: true,
|
|
289
|
+
enumerable: true,
|
|
290
|
+
writable: true,
|
|
291
|
+
initializer: null
|
|
292
|
+
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec6], {
|
|
293
|
+
configurable: true,
|
|
294
|
+
enumerable: true,
|
|
295
|
+
writable: true,
|
|
296
|
+
initializer: null
|
|
297
|
+
})), _class2)) || _class);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-native-command.d.ts","sourceRoot":"","sources":["../src/ai-native-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAgB3E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export var AINativeCommands = {
|
|
2
|
+
Explain: {
|
|
3
|
+
id: 'ai-native:explain',
|
|
4
|
+
label: 'EXPLAIN'
|
|
5
|
+
},
|
|
6
|
+
Chat: {
|
|
7
|
+
id: 'ai-native:chat',
|
|
8
|
+
label: 'Chat'
|
|
9
|
+
},
|
|
10
|
+
CellChat: {
|
|
11
|
+
id: 'ai-native:cell-chat',
|
|
12
|
+
label: 'Cell Chat'
|
|
13
|
+
},
|
|
14
|
+
AISideToolbarSelect: {
|
|
15
|
+
id: 'ai-native:side-toolbat-select'
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-jupyter';
|
|
2
|
+
import type { IChatMessage } from '@difizen/magent-chat';
|
|
3
|
+
import type { ToAutoFactory } from '@difizen/magent-core';
|
|
4
|
+
import { Fetcher } from '@difizen/magent-core';
|
|
5
|
+
import type { ViewComponent } from '@difizen/mana-app';
|
|
6
|
+
import { BaseView } from '@difizen/mana-app';
|
|
7
|
+
import { LibroAIChatMessageItemModel } from './libro-ai-msg-item-model.js';
|
|
8
|
+
import type { IAINativeForCellViewOption } from './protocol.js';
|
|
9
|
+
export declare function LibroAINativeForCellRender(): import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export declare class LibroAINativeForCellView extends BaseView {
|
|
11
|
+
view: ViewComponent;
|
|
12
|
+
fetcher: Fetcher;
|
|
13
|
+
cell: CellView;
|
|
14
|
+
libroAiChatMessageItemFactory: ToAutoFactory<typeof LibroAIChatMessageItemModel>;
|
|
15
|
+
libroAIChatMessageItemModel?: LibroAIChatMessageItemModel;
|
|
16
|
+
showAI: boolean;
|
|
17
|
+
constructor(options: IAINativeForCellViewOption);
|
|
18
|
+
chatStream: (option: IChatMessage) => Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=ai-native-for-cell-view.d.ts.map
|
|
@@ -0,0 +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;AAQ9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGhE,wBAAgB,0BAA0B,mDAkCzC;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;IAKnE,UAAU,WAAkB,YAAY,mBAmDtC;CACH"}
|