@difizen/libro-prompt-cell 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/es/index.less +6 -0
- package/es/input-handler/chat-record-input.d.ts +12 -0
- package/es/input-handler/chat-record-input.d.ts.map +1 -0
- package/es/input-handler/chat-record-input.js +92 -0
- package/es/input-handler/index.d.ts +3 -0
- package/es/input-handler/index.d.ts.map +1 -0
- package/es/input-handler/index.js +2 -0
- package/es/input-handler/index.less +91 -0
- package/es/input-handler/variable-name-input.d.ts +18 -0
- package/es/input-handler/variable-name-input.d.ts.map +1 -0
- package/es/input-handler/variable-name-input.js +120 -0
- package/es/libro-formatter-prompt-magic-contribution.d.ts +9 -0
- package/es/libro-formatter-prompt-magic-contribution.d.ts.map +1 -1
- package/es/libro-formatter-prompt-magic-contribution.js +12 -3
- package/es/module.js +2 -2
- package/es/prompt-cell-model.d.ts +16 -0
- package/es/prompt-cell-model.d.ts.map +1 -1
- package/es/prompt-cell-model.js +49 -13
- package/es/prompt-cell-script.d.ts +3 -2
- package/es/prompt-cell-script.d.ts.map +1 -1
- package/es/prompt-cell-script.js +13 -4
- package/es/prompt-cell-view.d.ts +33 -13
- package/es/prompt-cell-view.d.ts.map +1 -1
- package/es/prompt-cell-view.js +326 -181
- package/es/prompt-output-render.js +15 -16
- package/package.json +11 -7
- package/src/index.less +6 -0
- package/src/input-handler/chat-record-input.tsx +93 -0
- package/src/input-handler/index.less +91 -0
- package/src/input-handler/index.ts +2 -0
- package/src/input-handler/variable-name-input.tsx +121 -0
- package/src/libro-formatter-prompt-magic-contribution.ts +13 -2
- package/src/module.ts +2 -2
- package/src/prompt-cell-model.ts +26 -0
- package/src/prompt-cell-script.ts +8 -3
- package/src/prompt-cell-view.tsx +233 -92
- package/src/prompt-output-render.tsx +1 -1
- package/es/prompt-cell-output-area.d.ts +0 -14
- package/es/prompt-cell-output-area.d.ts.map +0 -1
- package/es/prompt-cell-output-area.js +0 -74
- package/src/prompt-cell-output-area.tsx +0 -59
package/es/prompt-cell-view.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
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, _class, _class2, _descriptor, _descriptor2;
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6;
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
7
|
+
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."); }
|
|
8
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
3
10
|
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 }); }
|
|
4
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
12
|
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); } }
|
|
6
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
|
+
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); }
|
|
7
16
|
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
8
17
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
9
18
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
@@ -18,11 +27,6 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
18
27
|
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; }
|
|
19
28
|
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); } }
|
|
20
29
|
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); }); }; }
|
|
21
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
25
|
-
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); }
|
|
26
30
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
27
31
|
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."); }
|
|
28
32
|
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); }
|
|
@@ -31,17 +35,69 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
31
35
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
32
36
|
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
33
37
|
import { isOutput } from '@difizen/libro-common';
|
|
34
|
-
import {
|
|
38
|
+
import { LibroOutputArea } from '@difizen/libro-core';
|
|
39
|
+
import { CellService, LibroExecutableCellView, LibroViewTracker, EditorStatus, LirboContextKey } from '@difizen/libro-core';
|
|
35
40
|
import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
|
|
36
41
|
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
|
|
37
42
|
import { Deferred } from '@difizen/mana-app';
|
|
38
|
-
import { Select } from 'antd';
|
|
43
|
+
import { Select, Tag } from 'antd';
|
|
39
44
|
import React, { useEffect, useState } from 'react';
|
|
45
|
+
import { ChatRecordInput, VariableNameInput } from "./input-handler/index.js";
|
|
46
|
+
import { LibroPromptCellModel } from "./prompt-cell-model.js";
|
|
40
47
|
import { PromptScript } from "./prompt-cell-script.js";
|
|
48
|
+
import "./index.less";
|
|
41
49
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
42
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
43
50
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
44
|
-
|
|
51
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
52
|
+
var ChatObjectOptions = function ChatObjectOptions(type) {
|
|
53
|
+
switch (type) {
|
|
54
|
+
case 'LLM':
|
|
55
|
+
return {
|
|
56
|
+
order: 1,
|
|
57
|
+
color: 'blue'
|
|
58
|
+
};
|
|
59
|
+
case 'LMM':
|
|
60
|
+
return {
|
|
61
|
+
order: 2,
|
|
62
|
+
color: 'cyan'
|
|
63
|
+
};
|
|
64
|
+
case 'VARIABLE':
|
|
65
|
+
return {
|
|
66
|
+
order: 3,
|
|
67
|
+
color: 'red'
|
|
68
|
+
};
|
|
69
|
+
case 'API':
|
|
70
|
+
return {
|
|
71
|
+
order: 4,
|
|
72
|
+
color: 'green'
|
|
73
|
+
};
|
|
74
|
+
case 'CUSTOM':
|
|
75
|
+
return {
|
|
76
|
+
order: 5,
|
|
77
|
+
color: undefined
|
|
78
|
+
};
|
|
79
|
+
default:
|
|
80
|
+
return {
|
|
81
|
+
order: undefined,
|
|
82
|
+
color: undefined
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var SelectionItemLabel = function SelectionItemLabel(props) {
|
|
87
|
+
var item = props.item;
|
|
88
|
+
return /*#__PURE__*/_jsxs("span", {
|
|
89
|
+
className: "libro-prompt-cell-selection-label",
|
|
90
|
+
children: [/*#__PURE__*/_jsx(Tag, {
|
|
91
|
+
color: ChatObjectOptions(item.type).color,
|
|
92
|
+
className: "libro-prompt-cell-header-selection-type",
|
|
93
|
+
children: item.type
|
|
94
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
95
|
+
className: "libro-prompt-cell-header-selection-name",
|
|
96
|
+
children: item.name
|
|
97
|
+
})]
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
var CellEditorRaw = function CellEditorRaw() {
|
|
45
101
|
var _instance$editorView3;
|
|
46
102
|
var instance = useInject(ViewInstance);
|
|
47
103
|
useEffect(function () {
|
|
@@ -57,7 +113,7 @@ var CellEditor = function CellEditor() {
|
|
|
57
113
|
})
|
|
58
114
|
});
|
|
59
115
|
};
|
|
60
|
-
export var
|
|
116
|
+
export var CellEditor = /*#__PURE__*/React.memo(CellEditorRaw);
|
|
61
117
|
var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmtEditorViewComponent(props, ref) {
|
|
62
118
|
var instance = useInject(ViewInstance);
|
|
63
119
|
var _useState = useState('暂无内置模型'),
|
|
@@ -65,30 +121,28 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
65
121
|
selectedModel = _useState2[0],
|
|
66
122
|
setSelectedModel = _useState2[1];
|
|
67
123
|
useEffect(function () {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var len = instance.modelSelection.length;
|
|
124
|
+
// TODO: Data initialization should not depend on view initialization, which causes limitations in usage scenarios and multiple renderings.
|
|
125
|
+
instance.model.variableName = instance.model.decodeObject.variableName;
|
|
126
|
+
instance.updateChatObjects().then(function () {
|
|
127
|
+
var len = instance.chatObjects.length;
|
|
73
128
|
if (len > 0) {
|
|
74
|
-
instance.model.decodeObject
|
|
75
|
-
modelType
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
129
|
+
if (!instance.model.decodeObject.modelType) {
|
|
130
|
+
instance.model.modelType = instance.chatObjects[len - 1].key;
|
|
131
|
+
} else {
|
|
132
|
+
instance.model.modelType = instance.model.decodeObject.modelType;
|
|
133
|
+
}
|
|
134
|
+
setSelectedModel(instance.model.modelType);
|
|
79
135
|
return;
|
|
80
136
|
}
|
|
81
137
|
return;
|
|
82
138
|
}).catch(function () {
|
|
83
139
|
//
|
|
84
140
|
});
|
|
141
|
+
instance.updateChatRecords();
|
|
85
142
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
86
143
|
}, []);
|
|
87
144
|
var handleChange = function handleChange(value) {
|
|
88
|
-
instance.
|
|
89
|
-
instance.model.decodeObject = _objectSpread(_objectSpread({}, instance.model.decodeObject), {}, {
|
|
90
|
-
modelType: value
|
|
91
|
-
});
|
|
145
|
+
instance.handleModelNameChange(value);
|
|
92
146
|
setSelectedModel(value);
|
|
93
147
|
};
|
|
94
148
|
return /*#__PURE__*/_jsxs("div", {
|
|
@@ -96,55 +150,67 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
96
150
|
ref: ref,
|
|
97
151
|
tabIndex: 10,
|
|
98
152
|
onBlur: instance.blur,
|
|
99
|
-
children: [/*#__PURE__*/
|
|
153
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
100
154
|
className: "libro-prompt-cell-header",
|
|
101
|
-
children: /*#__PURE__*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
155
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
156
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
157
|
+
children: /*#__PURE__*/_jsx(Select, {
|
|
158
|
+
value: selectedModel,
|
|
159
|
+
style: {
|
|
160
|
+
width: 160
|
|
161
|
+
},
|
|
162
|
+
onChange: handleChange,
|
|
163
|
+
options: instance.sortedChatItems.map(instance.toSelectionOption),
|
|
164
|
+
bordered: false,
|
|
165
|
+
onFocus: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
166
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
167
|
+
while (1) switch (_context.prev = _context.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
_context.next = 2;
|
|
170
|
+
return instance.updateChatObjects();
|
|
171
|
+
case 2:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context.stop();
|
|
174
|
+
}
|
|
175
|
+
}, _callee);
|
|
176
|
+
}))
|
|
177
|
+
})
|
|
178
|
+
}), /*#__PURE__*/_jsx(VariableNameInput, {
|
|
179
|
+
value: instance.model.variableName,
|
|
180
|
+
checkVariableNameAvailable: instance.checkVariableNameAvailable,
|
|
181
|
+
handleVariableNameChange: instance.handleVariableNameChange
|
|
182
|
+
})]
|
|
183
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
184
|
+
children: /*#__PURE__*/_jsx(ChatRecordInput, {
|
|
185
|
+
value: instance.model.record,
|
|
186
|
+
handleChange: instance.handleRecordChange,
|
|
187
|
+
records: instance.chatRecords,
|
|
188
|
+
onFocus: instance.updateChatRecords
|
|
126
189
|
})
|
|
127
|
-
})
|
|
128
|
-
}), /*#__PURE__*/_jsx(
|
|
190
|
+
})]
|
|
191
|
+
}), /*#__PURE__*/_jsx(CellEditor, {})]
|
|
129
192
|
});
|
|
130
193
|
});
|
|
131
|
-
export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 =
|
|
194
|
+
export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = inject(LirboContextKey), _dec4 = prop(), _dec5 = prop(), _dec6 = inject(CodeEditorManager), _dec7 = inject(PromptScript), _dec8 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
|
|
132
195
|
_inherits(LibroPromptCellView, _LibroExecutableCellV);
|
|
133
196
|
var _super = _createSuper(LibroPromptCellView);
|
|
134
|
-
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker
|
|
197
|
+
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker) {
|
|
135
198
|
var _options$cell;
|
|
136
199
|
var _this;
|
|
137
200
|
_classCallCheck(this, LibroPromptCellView);
|
|
138
201
|
_this = _super.call(this, options, cellService);
|
|
202
|
+
_initializerDefineProperty(_this, "lirboContextKey", _descriptor, _assertThisInitialized(_this));
|
|
139
203
|
_this.view = PropmtEditorViewComponent;
|
|
140
|
-
|
|
204
|
+
// TODO: Chat objects and chat message records should belong to libro rather than cell
|
|
205
|
+
_initializerDefineProperty(_this, "chatObjects", _descriptor2, _assertThisInitialized(_this));
|
|
206
|
+
_initializerDefineProperty(_this, "contextChatRecords", _descriptor3, _assertThisInitialized(_this));
|
|
141
207
|
_this.viewManager = void 0;
|
|
142
|
-
_this
|
|
208
|
+
_initializerDefineProperty(_this, "codeEditorManager", _descriptor4, _assertThisInitialized(_this));
|
|
209
|
+
_initializerDefineProperty(_this, "promptScript", _descriptor5, _assertThisInitialized(_this));
|
|
143
210
|
_this.outputs = void 0;
|
|
144
211
|
_this.libroViewTracker = void 0;
|
|
145
|
-
_initializerDefineProperty(_this, "editorView",
|
|
212
|
+
_initializerDefineProperty(_this, "editorView", _descriptor6, _assertThisInitialized(_this));
|
|
146
213
|
_this.outputAreaDeferred = new Deferred();
|
|
147
|
-
_this.editorViewReadyDeferred = new Deferred();
|
|
148
214
|
_this.blur = function () {
|
|
149
215
|
var _this$editorView, _this$editorView2;
|
|
150
216
|
(_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
|
|
@@ -152,48 +218,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
152
218
|
};
|
|
153
219
|
_this.focus = function (toEdit) {
|
|
154
220
|
if (toEdit) {
|
|
155
|
-
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (!_this.editorView) {
|
|
159
|
-
_this.editorReady.then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
160
|
-
var _this$editorView3, _this$editorView4, _this$editorView5, _this$editorView6, _this$editorView7;
|
|
161
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
162
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
163
|
-
case 0:
|
|
164
|
-
_context2.next = 2;
|
|
165
|
-
return (_this$editorView3 = _this.editorView) === null || _this$editorView3 === void 0 ? void 0 : _this$editorView3.editorReady;
|
|
166
|
-
case 2:
|
|
167
|
-
(_this$editorView4 = _this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4 = _this$editorView4.editor) === null || _this$editorView4 === void 0 || _this$editorView4.setOption('styleActiveLine', true);
|
|
168
|
-
(_this$editorView5 = _this.editorView) === null || _this$editorView5 === void 0 || (_this$editorView5 = _this$editorView5.editor) === null || _this$editorView5 === void 0 || _this$editorView5.setOption('highlightActiveLineGutter', true);
|
|
169
|
-
if (!((_this$editorView6 = _this.editorView) !== null && _this$editorView6 !== void 0 && (_this$editorView6 = _this$editorView6.editor) !== null && _this$editorView6 !== void 0 && _this$editorView6.hasFocus())) {
|
|
170
|
-
_context2.next = 6;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
return _context2.abrupt("return");
|
|
174
|
-
case 6:
|
|
175
|
-
(_this$editorView7 = _this.editorView) === null || _this$editorView7 === void 0 || (_this$editorView7 = _this$editorView7.editor) === null || _this$editorView7 === void 0 || _this$editorView7.focus();
|
|
176
|
-
return _context2.abrupt("return");
|
|
177
|
-
case 8:
|
|
178
|
-
case "end":
|
|
179
|
-
return _context2.stop();
|
|
180
|
-
}
|
|
181
|
-
}, _callee2);
|
|
182
|
-
}))).catch(function () {
|
|
183
|
-
//
|
|
184
|
-
});
|
|
185
|
-
} else {
|
|
186
|
-
var _this$editorView8;
|
|
187
|
-
if (!((_this$editorView8 = _this.editorView) !== null && _this$editorView8 !== void 0 && _this$editorView8.editor)) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
_this.editorView.editor.setOption('styleActiveLine', true);
|
|
191
|
-
_this.editorView.editor.setOption('highlightActiveLineGutter', true);
|
|
192
|
-
if (_this.editorView.editor.hasFocus()) {
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
_this.editorView.editor.focus();
|
|
196
|
-
}
|
|
221
|
+
_this.focusEditor();
|
|
197
222
|
} else {
|
|
198
223
|
var _this$container, _this$container2;
|
|
199
224
|
if ((_this$container = _this.container) !== null && _this$container !== void 0 && (_this$container = _this$container.current) !== null && _this$container !== void 0 && (_this$container = _this$container.parentElement) !== null && _this$container !== void 0 && _this$container.contains(document.activeElement)) {
|
|
@@ -221,14 +246,14 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
221
246
|
};
|
|
222
247
|
};
|
|
223
248
|
_this.fetch = /*#__PURE__*/function () {
|
|
224
|
-
var
|
|
249
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(content, ioCallback) {
|
|
225
250
|
var _this$parent;
|
|
226
251
|
var model, connection, future;
|
|
227
|
-
return _regeneratorRuntime().wrap(function
|
|
228
|
-
while (1) switch (
|
|
252
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
253
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
229
254
|
case 0:
|
|
230
255
|
model = (_this$parent = _this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.model;
|
|
231
|
-
|
|
256
|
+
_context2.next = 3;
|
|
232
257
|
return model.kcReady;
|
|
233
258
|
case 3:
|
|
234
259
|
connection = model.kernelConnection;
|
|
@@ -236,21 +261,74 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
236
261
|
future.onIOPub = function (msg) {
|
|
237
262
|
ioCallback(msg);
|
|
238
263
|
};
|
|
239
|
-
return
|
|
264
|
+
return _context2.abrupt("return", future.done);
|
|
240
265
|
case 7:
|
|
241
266
|
case "end":
|
|
242
|
-
return
|
|
267
|
+
return _context2.stop();
|
|
243
268
|
}
|
|
244
|
-
},
|
|
269
|
+
}, _callee2);
|
|
245
270
|
}));
|
|
246
271
|
return function (_x, _x2) {
|
|
247
|
-
return
|
|
272
|
+
return _ref2.apply(this, arguments);
|
|
248
273
|
};
|
|
249
274
|
}();
|
|
250
|
-
_this.
|
|
275
|
+
_this.updateChatObjects = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
276
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
277
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
278
|
+
case 0:
|
|
279
|
+
return _context3.abrupt("return", _this.fetch({
|
|
280
|
+
code: _this.promptScript.getChatObjects,
|
|
281
|
+
store_history: false
|
|
282
|
+
}, function (msg) {
|
|
283
|
+
return _this.handleQueryResponse(msg, function (result) {
|
|
284
|
+
try {
|
|
285
|
+
_this.chatObjects = JSON.parse(result);
|
|
286
|
+
} catch (e) {
|
|
287
|
+
//
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}));
|
|
291
|
+
case 1:
|
|
292
|
+
case "end":
|
|
293
|
+
return _context3.stop();
|
|
294
|
+
}
|
|
295
|
+
}, _callee3);
|
|
296
|
+
}));
|
|
297
|
+
_this.updateChatRecords = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
298
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
299
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
300
|
+
case 0:
|
|
301
|
+
return _context4.abrupt("return", _this.fetch({
|
|
302
|
+
code: _this.promptScript.getChatRecoreds,
|
|
303
|
+
store_history: false
|
|
304
|
+
}, function (msg) {
|
|
305
|
+
return _this.handleQueryResponse(msg, function (result) {
|
|
306
|
+
try {
|
|
307
|
+
_this.contextChatRecords = JSON.parse(result);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
//
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}));
|
|
313
|
+
case 1:
|
|
314
|
+
case "end":
|
|
315
|
+
return _context4.stop();
|
|
316
|
+
}
|
|
317
|
+
}, _callee4);
|
|
318
|
+
}));
|
|
319
|
+
_this.toSelectionOption = function (item) {
|
|
320
|
+
return {
|
|
321
|
+
value: item.key,
|
|
322
|
+
label: /*#__PURE__*/_jsx(SelectionItemLabel, {
|
|
323
|
+
item: item
|
|
324
|
+
})
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
_this.handleQueryResponse = function (response, cb) {
|
|
251
328
|
var msgType = response.header.msg_type;
|
|
252
329
|
switch (msgType) {
|
|
253
330
|
case 'execute_result':
|
|
331
|
+
case 'display_data':
|
|
254
332
|
{
|
|
255
333
|
var payload = response;
|
|
256
334
|
var content = payload.content.data['text/plain'];
|
|
@@ -258,13 +336,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
258
336
|
content = content.slice(1, -1);
|
|
259
337
|
content = content.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
260
338
|
}
|
|
261
|
-
|
|
262
|
-
_this.modelSelection = update.map(function (item) {
|
|
263
|
-
return {
|
|
264
|
-
value: item,
|
|
265
|
-
label: item
|
|
266
|
-
};
|
|
267
|
-
});
|
|
339
|
+
cb(content);
|
|
268
340
|
break;
|
|
269
341
|
}
|
|
270
342
|
case 'stream':
|
|
@@ -275,23 +347,30 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
275
347
|
contentStream = contentStream.slice(1, -1);
|
|
276
348
|
contentStream = contentStream.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
277
349
|
}
|
|
278
|
-
|
|
279
|
-
_this.modelSelection = updateStream.map(function (item) {
|
|
280
|
-
return {
|
|
281
|
-
value: item,
|
|
282
|
-
label: item
|
|
283
|
-
};
|
|
284
|
-
});
|
|
350
|
+
cb(contentStream);
|
|
285
351
|
break;
|
|
286
352
|
}
|
|
287
353
|
default:
|
|
288
354
|
break;
|
|
289
355
|
}
|
|
290
356
|
};
|
|
357
|
+
_this.checkVariableNameAvailable = function (variableName) {
|
|
358
|
+
return _this.parent.model.cells.findIndex(function (cell) {
|
|
359
|
+
return cell.model instanceof LibroPromptCellModel && cell.model.variableName === variableName;
|
|
360
|
+
}) > -1;
|
|
361
|
+
};
|
|
362
|
+
_this.handleModelNameChange = function (value) {
|
|
363
|
+
_this.model.modelType = value;
|
|
364
|
+
};
|
|
365
|
+
_this.handleVariableNameChange = function (value) {
|
|
366
|
+
_this.model.variableName = value;
|
|
367
|
+
};
|
|
368
|
+
_this.handleRecordChange = function (value) {
|
|
369
|
+
_this.model.record = value;
|
|
370
|
+
};
|
|
291
371
|
_this.options = options;
|
|
292
372
|
_this.viewManager = viewManager;
|
|
293
373
|
_this.className = _this.className + ' prompt';
|
|
294
|
-
_this.codeEditorManager = codeEditorManager;
|
|
295
374
|
_this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
|
|
296
375
|
_this.libroViewTracker = libroViewTracker;
|
|
297
376
|
|
|
@@ -300,51 +379,81 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
300
379
|
cellId: _this.id,
|
|
301
380
|
cell: _assertThisInitialized(_this)
|
|
302
381
|
}).then( /*#__PURE__*/function () {
|
|
303
|
-
var
|
|
382
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(outputArea) {
|
|
304
383
|
var output;
|
|
305
|
-
return _regeneratorRuntime().wrap(function
|
|
306
|
-
while (1) switch (
|
|
384
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
385
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
307
386
|
case 0:
|
|
308
387
|
_this.outputArea = outputArea;
|
|
309
388
|
output = _this.outputs;
|
|
310
389
|
if (!isOutput(output)) {
|
|
311
|
-
|
|
390
|
+
_context5.next = 5;
|
|
312
391
|
break;
|
|
313
392
|
}
|
|
314
|
-
|
|
393
|
+
_context5.next = 5;
|
|
315
394
|
return _this.outputArea.fromJSON(output);
|
|
316
395
|
case 5:
|
|
317
396
|
_this.outputAreaDeferred.resolve(outputArea);
|
|
318
397
|
_this.outputWatch();
|
|
319
|
-
return
|
|
398
|
+
return _context5.abrupt("return");
|
|
320
399
|
case 8:
|
|
321
400
|
case "end":
|
|
322
|
-
return
|
|
401
|
+
return _context5.stop();
|
|
323
402
|
}
|
|
324
|
-
},
|
|
403
|
+
}, _callee5);
|
|
325
404
|
}));
|
|
326
405
|
return function (_x3) {
|
|
327
|
-
return
|
|
406
|
+
return _ref5.apply(this, arguments);
|
|
328
407
|
};
|
|
329
408
|
}()).catch(function () {
|
|
330
409
|
//
|
|
331
410
|
});
|
|
332
411
|
return _this;
|
|
333
412
|
}
|
|
334
|
-
LibroPromptCellView = inject(CodeEditorManager)(LibroPromptCellView, undefined, 4) || LibroPromptCellView;
|
|
335
413
|
LibroPromptCellView = inject(LibroViewTracker)(LibroPromptCellView, undefined, 3) || LibroPromptCellView;
|
|
336
414
|
LibroPromptCellView = inject(ViewManager)(LibroPromptCellView, undefined, 2) || LibroPromptCellView;
|
|
337
415
|
LibroPromptCellView = inject(CellService)(LibroPromptCellView, undefined, 1) || LibroPromptCellView;
|
|
338
416
|
LibroPromptCellView = inject(ViewOption)(LibroPromptCellView, undefined, 0) || LibroPromptCellView;
|
|
339
417
|
_createClass(LibroPromptCellView, [{
|
|
340
|
-
key: "
|
|
418
|
+
key: "sortedChatItems",
|
|
341
419
|
get: function get() {
|
|
342
|
-
return this.
|
|
420
|
+
return _toConsumableArray(this.chatObjects).sort(function (a, b) {
|
|
421
|
+
if (a.type !== b.type) {
|
|
422
|
+
var aOrder = ChatObjectOptions(a.type).order || 0;
|
|
423
|
+
var bOrder = ChatObjectOptions(b.type).order || 0;
|
|
424
|
+
if (aOrder === bOrder && aOrder === 0) {
|
|
425
|
+
return a.type.localeCompare(b.type);
|
|
426
|
+
}
|
|
427
|
+
return aOrder - bOrder;
|
|
428
|
+
}
|
|
429
|
+
return a.order - b.order;
|
|
430
|
+
});
|
|
343
431
|
}
|
|
344
432
|
}, {
|
|
345
|
-
key: "
|
|
433
|
+
key: "chatRecords",
|
|
346
434
|
get: function get() {
|
|
347
|
-
|
|
435
|
+
var records = [];
|
|
436
|
+
var recordMap = {};
|
|
437
|
+
this.parent.model.cells.forEach(function (cell) {
|
|
438
|
+
if (cell.model instanceof LibroPromptCellModel && cell.model.record) {
|
|
439
|
+
records = records.concat(cell.model.record);
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
return [].concat(_toConsumableArray(records), _toConsumableArray(this.contextChatRecords)).filter(function (r) {
|
|
443
|
+
if (recordMap[r]) {
|
|
444
|
+
return false;
|
|
445
|
+
} else {
|
|
446
|
+
recordMap[r] = true;
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}).sort(function (a, b) {
|
|
450
|
+
return a.localeCompare(b);
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}, {
|
|
454
|
+
key: "outputAreaReady",
|
|
455
|
+
get: function get() {
|
|
456
|
+
return this.outputAreaDeferred.promise;
|
|
348
457
|
}
|
|
349
458
|
}, {
|
|
350
459
|
key: "outputWatch",
|
|
@@ -379,6 +488,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
379
488
|
key: "getEditorOption",
|
|
380
489
|
value: function getEditorOption() {
|
|
381
490
|
var option = {
|
|
491
|
+
uuid: "".concat(this.parent.model.id, "-").concat(this.model.id),
|
|
382
492
|
editorHostId: this.parent.id + this.id,
|
|
383
493
|
model: this.model,
|
|
384
494
|
config: {
|
|
@@ -391,36 +501,35 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
391
501
|
}, {
|
|
392
502
|
key: "createEditor",
|
|
393
503
|
value: function () {
|
|
394
|
-
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
504
|
+
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
395
505
|
var option, editorView;
|
|
396
|
-
return _regeneratorRuntime().wrap(function
|
|
397
|
-
while (1) switch (
|
|
506
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
507
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
398
508
|
case 0:
|
|
399
509
|
option = this.getEditorOption();
|
|
400
510
|
this.editorStatus = EditorStatus.LOADING;
|
|
401
511
|
|
|
402
512
|
// 防止虚拟滚动中编辑器被频繁创建
|
|
403
513
|
if (!this.editorView) {
|
|
404
|
-
|
|
514
|
+
_context6.next = 5;
|
|
405
515
|
break;
|
|
406
516
|
}
|
|
407
517
|
this.editorStatus = EditorStatus.LOADED;
|
|
408
|
-
return
|
|
518
|
+
return _context6.abrupt("return");
|
|
409
519
|
case 5:
|
|
410
|
-
|
|
520
|
+
_context6.next = 7;
|
|
411
521
|
return this.codeEditorManager.getOrCreateEditorView(option);
|
|
412
522
|
case 7:
|
|
413
|
-
editorView =
|
|
523
|
+
editorView = _context6.sent;
|
|
414
524
|
this.editorView = editorView;
|
|
415
|
-
this.editorViewReadyDeferred.resolve();
|
|
416
525
|
this.editorStatus = EditorStatus.LOADED;
|
|
417
|
-
|
|
526
|
+
_context6.next = 12;
|
|
418
527
|
return this.afterEditorReady();
|
|
419
|
-
case
|
|
528
|
+
case 12:
|
|
420
529
|
case "end":
|
|
421
|
-
return
|
|
530
|
+
return _context6.stop();
|
|
422
531
|
}
|
|
423
|
-
},
|
|
532
|
+
}, _callee6, this);
|
|
424
533
|
}));
|
|
425
534
|
function createEditor() {
|
|
426
535
|
return _createEditor.apply(this, arguments);
|
|
@@ -430,24 +539,24 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
430
539
|
}, {
|
|
431
540
|
key: "afterEditorReady",
|
|
432
541
|
value: function () {
|
|
433
|
-
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
542
|
+
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
434
543
|
var _this3 = this,
|
|
435
|
-
_this$
|
|
436
|
-
return _regeneratorRuntime().wrap(function
|
|
437
|
-
while (1) switch (
|
|
544
|
+
_this$editorView3;
|
|
545
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
546
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
438
547
|
case 0:
|
|
439
548
|
watch(this.parent.model, 'readOnly', function () {
|
|
440
549
|
var _this3$editorView;
|
|
441
550
|
(_this3$editorView = _this3.editorView) === null || _this3$editorView === void 0 || (_this3$editorView = _this3$editorView.editor) === null || _this3$editorView === void 0 || _this3$editorView.setOption('readOnly', getOrigin(_this3.parent.model.readOnly));
|
|
442
551
|
});
|
|
443
|
-
(_this$
|
|
552
|
+
(_this$editorView3 = this.editorView) === null || _this$editorView3 === void 0 || _this$editorView3.onModalChange(function (val) {
|
|
444
553
|
return _this3.hasModal = val;
|
|
445
554
|
});
|
|
446
555
|
case 2:
|
|
447
556
|
case "end":
|
|
448
|
-
return
|
|
557
|
+
return _context7.stop();
|
|
449
558
|
}
|
|
450
|
-
},
|
|
559
|
+
}, _callee7, this);
|
|
451
560
|
}));
|
|
452
561
|
function afterEditorReady() {
|
|
453
562
|
return _afterEditorReady.apply(this, arguments);
|
|
@@ -460,25 +569,39 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
460
569
|
var _getOrigin;
|
|
461
570
|
return (_getOrigin = getOrigin(this.editorView)) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.editor) !== null && _getOrigin !== void 0 && (_getOrigin = _getOrigin.host) !== null && _getOrigin !== void 0 && _getOrigin.contains(e.target) && this.parent.model.commandMode ? true : false;
|
|
462
571
|
}
|
|
572
|
+
}, {
|
|
573
|
+
key: "focusEditor",
|
|
574
|
+
value: function focusEditor() {
|
|
575
|
+
var _this$editorView4, _this$parent$model$ac2;
|
|
576
|
+
//选中cell、编辑模式、非只读时才focus
|
|
577
|
+
if ((_this$editorView4 = this.editorView) !== null && _this$editorView4 !== void 0 && _this$editorView4.editor && this.editorView.editorStatus === 'ready' && ((_this$parent$model$ac2 = this.parent.model.active) === null || _this$parent$model$ac2 === void 0 ? void 0 : _this$parent$model$ac2.id) === this.id && !this.parent.model.commandMode && this.lirboContextKey.commandModeEnabled === true &&
|
|
578
|
+
// 排除弹窗等情况
|
|
579
|
+
this.parent.model.readOnly === false) {
|
|
580
|
+
var _this$editorView5, _this$editorView6, _this$editorView7;
|
|
581
|
+
(_this$editorView5 = this.editorView) === null || _this$editorView5 === void 0 || _this$editorView5.editor.setOption('styleActiveLine', true);
|
|
582
|
+
(_this$editorView6 = this.editorView) === null || _this$editorView6 === void 0 || _this$editorView6.editor.setOption('highlightActiveLineGutter', true);
|
|
583
|
+
(_this$editorView7 = this.editorView) === null || _this$editorView7 === void 0 || _this$editorView7.editor.focus();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
463
586
|
}, {
|
|
464
587
|
key: "run",
|
|
465
588
|
value: function () {
|
|
466
|
-
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
589
|
+
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
467
590
|
var _this4 = this;
|
|
468
591
|
var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
|
|
469
|
-
return _regeneratorRuntime().wrap(function
|
|
470
|
-
while (1) switch (
|
|
592
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
593
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
471
594
|
case 0:
|
|
472
595
|
libroModel = this.parent.model;
|
|
473
596
|
if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
|
|
474
|
-
|
|
597
|
+
_context8.next = 3;
|
|
475
598
|
break;
|
|
476
599
|
}
|
|
477
|
-
return
|
|
600
|
+
return _context8.abrupt("return", false);
|
|
478
601
|
case 3:
|
|
479
602
|
kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
480
603
|
cellContent = this.model.source;
|
|
481
|
-
|
|
604
|
+
_context8.prev = 5;
|
|
482
605
|
// Promise.resolve().then(() => {
|
|
483
606
|
this.clearExecution();
|
|
484
607
|
// });
|
|
@@ -508,10 +631,10 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
508
631
|
_this4.model.hasExecutedError = true;
|
|
509
632
|
}
|
|
510
633
|
};
|
|
511
|
-
|
|
634
|
+
_context8.next = 14;
|
|
512
635
|
return future.done;
|
|
513
636
|
case 14:
|
|
514
|
-
msgPromise =
|
|
637
|
+
msgPromise = _context8.sent;
|
|
515
638
|
this.model.executing = false;
|
|
516
639
|
this.model.kernelExecuting = false;
|
|
517
640
|
this.model.hasExecutedSuccess = !this.model.hasExecutedError;
|
|
@@ -520,36 +643,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
520
643
|
this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
|
|
521
644
|
this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
|
|
522
645
|
if (msgPromise) {
|
|
523
|
-
|
|
646
|
+
_context8.next = 24;
|
|
524
647
|
break;
|
|
525
648
|
}
|
|
526
|
-
return
|
|
649
|
+
return _context8.abrupt("return", true);
|
|
527
650
|
case 24:
|
|
528
651
|
if (!(msgPromise.content.status === 'ok')) {
|
|
529
|
-
|
|
652
|
+
_context8.next = 28;
|
|
530
653
|
break;
|
|
531
654
|
}
|
|
532
|
-
return
|
|
655
|
+
return _context8.abrupt("return", true);
|
|
533
656
|
case 28:
|
|
534
657
|
throw new KernelError(msgPromise.content);
|
|
535
658
|
case 29:
|
|
536
|
-
|
|
659
|
+
_context8.next = 36;
|
|
537
660
|
break;
|
|
538
661
|
case 31:
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (!
|
|
542
|
-
|
|
662
|
+
_context8.prev = 31;
|
|
663
|
+
_context8.t0 = _context8["catch"](5);
|
|
664
|
+
if (!_context8.t0.message.startsWith('Canceled')) {
|
|
665
|
+
_context8.next = 35;
|
|
543
666
|
break;
|
|
544
667
|
}
|
|
545
|
-
return
|
|
668
|
+
return _context8.abrupt("return", false);
|
|
546
669
|
case 35:
|
|
547
|
-
throw
|
|
670
|
+
throw _context8.t0;
|
|
548
671
|
case 36:
|
|
549
672
|
case "end":
|
|
550
|
-
return
|
|
673
|
+
return _context8.stop();
|
|
551
674
|
}
|
|
552
|
-
},
|
|
675
|
+
}, _callee8, this, [[5, 31]]);
|
|
553
676
|
}));
|
|
554
677
|
function run() {
|
|
555
678
|
return _run.apply(this, arguments);
|
|
@@ -558,14 +681,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
558
681
|
}()
|
|
559
682
|
}]);
|
|
560
683
|
return LibroPromptCellView;
|
|
561
|
-
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "
|
|
684
|
+
}(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "lirboContextKey", [_dec3], {
|
|
685
|
+
configurable: true,
|
|
686
|
+
enumerable: true,
|
|
687
|
+
writable: true,
|
|
688
|
+
initializer: null
|
|
689
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "chatObjects", [_dec4], {
|
|
562
690
|
configurable: true,
|
|
563
691
|
enumerable: true,
|
|
564
692
|
writable: true,
|
|
565
693
|
initializer: function initializer() {
|
|
566
694
|
return [];
|
|
567
695
|
}
|
|
568
|
-
}),
|
|
696
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "contextChatRecords", [_dec5], {
|
|
697
|
+
configurable: true,
|
|
698
|
+
enumerable: true,
|
|
699
|
+
writable: true,
|
|
700
|
+
initializer: function initializer() {
|
|
701
|
+
return [];
|
|
702
|
+
}
|
|
703
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "codeEditorManager", [_dec6], {
|
|
704
|
+
configurable: true,
|
|
705
|
+
enumerable: true,
|
|
706
|
+
writable: true,
|
|
707
|
+
initializer: null
|
|
708
|
+
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "promptScript", [_dec7], {
|
|
709
|
+
configurable: true,
|
|
710
|
+
enumerable: true,
|
|
711
|
+
writable: true,
|
|
712
|
+
initializer: null
|
|
713
|
+
}), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec8], {
|
|
569
714
|
configurable: true,
|
|
570
715
|
enumerable: true,
|
|
571
716
|
writable: true,
|