@difizen/libro-prompt-cell 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/index.d.ts +6 -0
  4. package/es/index.d.ts.map +1 -0
  5. package/es/index.js +5 -0
  6. package/es/index.less +54 -0
  7. package/es/libro-llm-render.d.ts +10 -0
  8. package/es/libro-llm-render.d.ts.map +1 -0
  9. package/es/libro-llm-render.js +71 -0
  10. package/es/module.d.ts +3 -0
  11. package/es/module.d.ts.map +1 -0
  12. package/es/module.js +23 -0
  13. package/es/prompt-cell-command-contribution.d.ts +18 -0
  14. package/es/prompt-cell-command-contribution.d.ts.map +1 -0
  15. package/es/prompt-cell-command-contribution.js +62 -0
  16. package/es/prompt-cell-contribution.d.ts +13 -0
  17. package/es/prompt-cell-contribution.d.ts.map +1 -0
  18. package/es/prompt-cell-contribution.js +66 -0
  19. package/es/prompt-cell-model.d.ts +33 -0
  20. package/es/prompt-cell-model.d.ts.map +1 -0
  21. package/es/prompt-cell-model.js +163 -0
  22. package/es/prompt-cell-output-area.d.ts +14 -0
  23. package/es/prompt-cell-output-area.d.ts.map +1 -0
  24. package/es/prompt-cell-output-area.js +74 -0
  25. package/es/prompt-cell-protocol.d.ts +5 -0
  26. package/es/prompt-cell-protocol.d.ts.map +1 -0
  27. package/es/prompt-cell-protocol.js +1 -0
  28. package/es/prompt-cell-script.d.ts +4 -0
  29. package/es/prompt-cell-script.d.ts.map +1 -0
  30. package/es/prompt-cell-script.js +4 -0
  31. package/es/prompt-cell-utils.d.ts +2 -0
  32. package/es/prompt-cell-utils.d.ts.map +1 -0
  33. package/es/prompt-cell-utils.js +7 -0
  34. package/es/prompt-cell-view.d.ts +50 -0
  35. package/es/prompt-cell-view.d.ts.map +1 -0
  36. package/es/prompt-cell-view.js +543 -0
  37. package/es/prompt-output-render.d.ts +6 -0
  38. package/es/prompt-output-render.d.ts.map +1 -0
  39. package/es/prompt-output-render.js +120 -0
  40. package/es/prompt-output-rendermime-contribution.d.ts +13 -0
  41. package/es/prompt-output-rendermime-contribution.d.ts.map +1 -0
  42. package/es/prompt-output-rendermime-contribution.js +22 -0
  43. package/package.json +72 -0
  44. package/src/index.less +54 -0
  45. package/src/index.spec.ts +9 -0
  46. package/src/index.ts +5 -0
  47. package/src/libro-llm-render.tsx +63 -0
  48. package/src/module.ts +35 -0
  49. package/src/prompt-cell-command-contribution.ts +61 -0
  50. package/src/prompt-cell-contribution.ts +34 -0
  51. package/src/prompt-cell-model.ts +117 -0
  52. package/src/prompt-cell-output-area.tsx +59 -0
  53. package/src/prompt-cell-protocol.ts +8 -0
  54. package/src/prompt-cell-script.ts +4 -0
  55. package/src/prompt-cell-utils.ts +6 -0
  56. package/src/prompt-cell-view.tsx +446 -0
  57. package/src/prompt-output-render.tsx +83 -0
  58. package/src/prompt-output-rendermime-contribution.ts +16 -0
@@ -0,0 +1,543 @@
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;
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 _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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ 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); }
13
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
14
+ 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); }
15
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
16
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
17
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
18
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ 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; }
22
+ 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.'); }
23
+ 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; }
24
+ 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); } }
25
+ 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); }); }; }
26
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+ 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
+ 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); }
29
+ 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; }
30
+ 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; } }
31
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
+ import { CodeEditorView } from '@difizen/libro-code-editor';
33
+ import { CodeMirrorEditor, codeMirrorEditorFactory } from '@difizen/libro-codemirror';
34
+ import { isOutput } from '@difizen/libro-common';
35
+ import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker } from '@difizen/libro-core';
36
+ import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
37
+ import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
38
+ import { Deferred } from '@difizen/mana-app';
39
+ import { Select } from 'antd';
40
+ import React, { useEffect, useState } from 'react';
41
+ import { PromptScript } from "./prompt-cell-script.js";
42
+ import { jsx as _jsx } from "react/jsx-runtime";
43
+ import { Fragment as _Fragment } from "react/jsx-runtime";
44
+ import { jsxs as _jsxs } from "react/jsx-runtime";
45
+ var CellEditor = function CellEditor() {
46
+ var _instance$editorView3;
47
+ var instance = useInject(ViewInstance);
48
+ useEffect(function () {
49
+ var _instance$editorView;
50
+ if ((_instance$editorView = instance.editorView) !== null && _instance$editorView !== void 0 && _instance$editorView.editor) {
51
+ var _instance$editorView2;
52
+ instance.editor = getOrigin((_instance$editorView2 = instance.editorView) === null || _instance$editorView2 === void 0 ? void 0 : _instance$editorView2.editor);
53
+ }
54
+ }, [instance, (_instance$editorView3 = instance.editorView) === null || _instance$editorView3 === void 0 ? void 0 : _instance$editorView3.editor]);
55
+ return /*#__PURE__*/_jsx(_Fragment, {
56
+ children: instance.editorView && /*#__PURE__*/_jsx(ViewRender, {
57
+ view: instance.editorView
58
+ })
59
+ });
60
+ };
61
+ export var CellEditorMemo = /*#__PURE__*/React.memo(CellEditor);
62
+ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmtEditorViewComponent(props, ref) {
63
+ var instance = useInject(ViewInstance);
64
+ var _useState = useState('暂无内置模型'),
65
+ _useState2 = _slicedToArray(_useState, 2),
66
+ selectedModel = _useState2[0],
67
+ setSelectedModel = _useState2[1];
68
+ useEffect(function () {
69
+ instance.fetch({
70
+ code: PromptScript.get_models,
71
+ store_history: false
72
+ }, instance.handleQueryResponse).then(function () {
73
+ if (instance.modelSelection.length > 0) {
74
+ setSelectedModel(instance.modelSelection[0].label);
75
+ instance.model.modelType = instance.modelSelection[0].label;
76
+ return;
77
+ }
78
+ return;
79
+ }).catch(function () {
80
+ //
81
+ });
82
+ }, [instance]);
83
+ var handleChange = function handleChange(value) {
84
+ instance.model.modelType = value;
85
+ setSelectedModel(value);
86
+ };
87
+ return /*#__PURE__*/_jsxs("div", {
88
+ className: instance.className,
89
+ ref: ref,
90
+ tabIndex: 10,
91
+ onBlur: instance.blur,
92
+ children: [/*#__PURE__*/_jsx("div", {
93
+ className: "libro-prompt-cell-header",
94
+ children: /*#__PURE__*/_jsx("div", {
95
+ className: "libro-prompt-cell-header-model-config",
96
+ children: /*#__PURE__*/_jsx(Select, {
97
+ value: selectedModel,
98
+ style: {
99
+ width: 160
100
+ },
101
+ onChange: handleChange,
102
+ options: instance.modelSelection,
103
+ bordered: false,
104
+ onFocus: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
105
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
106
+ while (1) switch (_context.prev = _context.next) {
107
+ case 0:
108
+ _context.next = 2;
109
+ return instance.fetch({
110
+ code: PromptScript.get_models,
111
+ store_history: false
112
+ }, instance.handleQueryResponse);
113
+ case 2:
114
+ case "end":
115
+ return _context.stop();
116
+ }
117
+ }, _callee);
118
+ }))
119
+ })
120
+ })
121
+ }), /*#__PURE__*/_jsx(CellEditorMemo, {})]
122
+ });
123
+ });
124
+ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
125
+ _inherits(LibroPromptCellView, _LibroExecutableCellV);
126
+ var _super = _createSuper(LibroPromptCellView);
127
+ function LibroPromptCellView(options, cellService, viewManager, libroViewTracker) {
128
+ var _options$cell;
129
+ var _this;
130
+ _classCallCheck(this, LibroPromptCellView);
131
+ _this = _super.call(this, options, cellService);
132
+ _this.view = PropmtEditorViewComponent;
133
+ _initializerDefineProperty(_this, "modelSelection", _descriptor, _assertThisInitialized(_this));
134
+ _this.viewManager = void 0;
135
+ _this.outputs = void 0;
136
+ _this.libroViewTracker = void 0;
137
+ _initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
138
+ _this.outputAreaDeferred = new Deferred();
139
+ _this.editorViewReadyDeferred = new Deferred();
140
+ _this.blur = function () {
141
+ var _this$editorView, _this$editorView2;
142
+ (_this$editorView = _this.editorView) === null || _this$editorView === void 0 || (_this$editorView = _this$editorView.editor) === null || _this$editorView === void 0 || _this$editorView.setOption('styleActiveLine', false);
143
+ (_this$editorView2 = _this.editorView) === null || _this$editorView2 === void 0 || (_this$editorView2 = _this$editorView2.editor) === null || _this$editorView2 === void 0 || _this$editorView2.setOption('highlightActiveLineGutter', false);
144
+ };
145
+ _this.focus = function (toEdit) {
146
+ if (toEdit) {
147
+ if (_this.parent.model.readOnly === true) {
148
+ return;
149
+ }
150
+ if (!_this.editorView) {
151
+ _this.editorReady.then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
152
+ var _this$editorView3, _this$editorView4, _this$editorView5, _this$editorView6, _this$editorView7;
153
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
154
+ while (1) switch (_context2.prev = _context2.next) {
155
+ case 0:
156
+ _context2.next = 2;
157
+ return (_this$editorView3 = _this.editorView) === null || _this$editorView3 === void 0 ? void 0 : _this$editorView3.editorReady;
158
+ case 2:
159
+ (_this$editorView4 = _this.editorView) === null || _this$editorView4 === void 0 || (_this$editorView4 = _this$editorView4.editor) === null || _this$editorView4 === void 0 || _this$editorView4.setOption('styleActiveLine', true);
160
+ (_this$editorView5 = _this.editorView) === null || _this$editorView5 === void 0 || (_this$editorView5 = _this$editorView5.editor) === null || _this$editorView5 === void 0 || _this$editorView5.setOption('highlightActiveLineGutter', true);
161
+ if (!((_this$editorView6 = _this.editorView) !== null && _this$editorView6 !== void 0 && (_this$editorView6 = _this$editorView6.editor) !== null && _this$editorView6 !== void 0 && _this$editorView6.hasFocus())) {
162
+ _context2.next = 6;
163
+ break;
164
+ }
165
+ return _context2.abrupt("return");
166
+ case 6:
167
+ (_this$editorView7 = _this.editorView) === null || _this$editorView7 === void 0 || (_this$editorView7 = _this$editorView7.editor) === null || _this$editorView7 === void 0 || _this$editorView7.focus();
168
+ return _context2.abrupt("return");
169
+ case 8:
170
+ case "end":
171
+ return _context2.stop();
172
+ }
173
+ }, _callee2);
174
+ }))).catch(function () {
175
+ //
176
+ });
177
+ } else {
178
+ var _this$editorView8;
179
+ if (!((_this$editorView8 = _this.editorView) !== null && _this$editorView8 !== void 0 && _this$editorView8.editor)) {
180
+ return;
181
+ }
182
+ _this.editorView.editor.setOption('styleActiveLine', true);
183
+ _this.editorView.editor.setOption('highlightActiveLineGutter', true);
184
+ if (_this.editorView.editor.hasFocus()) {
185
+ return;
186
+ }
187
+ _this.editorView.editor.focus();
188
+ }
189
+ } else {
190
+ var _this$container, _this$container2;
191
+ 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)) {
192
+ return;
193
+ }
194
+ (_this$container2 = _this.container) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.current) === null || _this$container2 === void 0 || (_this$container2 = _this$container2.parentElement) === null || _this$container2 === void 0 || _this$container2.focus();
195
+ }
196
+ };
197
+ _this.clearExecution = function () {
198
+ _this.model.clearExecution();
199
+ _this.outputArea.clear();
200
+ };
201
+ _this.getSelections = function () {
202
+ var _this$editor;
203
+ return (_this$editor = _this.editor) === null || _this$editor === void 0 ? void 0 : _this$editor.getSelections();
204
+ };
205
+ _this.getSelectionsOffsetAt = function (selection) {
206
+ var _this$editor$getOffse, _this$editor2, _this$editor$getOffse2, _this$editor3;
207
+ var isSelect = selection;
208
+ var start = (_this$editor$getOffse = (_this$editor2 = _this.editor) === null || _this$editor2 === void 0 ? void 0 : _this$editor2.getOffsetAt(isSelect.start)) !== null && _this$editor$getOffse !== void 0 ? _this$editor$getOffse : 0;
209
+ var end = (_this$editor$getOffse2 = (_this$editor3 = _this.editor) === null || _this$editor3 === void 0 ? void 0 : _this$editor3.getOffsetAt(isSelect.end)) !== null && _this$editor$getOffse2 !== void 0 ? _this$editor$getOffse2 : 0;
210
+ return {
211
+ start: start,
212
+ end: end
213
+ };
214
+ };
215
+ _this.fetch = /*#__PURE__*/function () {
216
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(content, ioCallback) {
217
+ var model, connection, future;
218
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
219
+ while (1) switch (_context3.prev = _context3.next) {
220
+ case 0:
221
+ model = _this.parent.model;
222
+ _context3.next = 3;
223
+ return model.kcReady;
224
+ case 3:
225
+ connection = model.kernelConnection;
226
+ future = connection.requestExecute(content);
227
+ future.onIOPub = function (msg) {
228
+ ioCallback(msg);
229
+ };
230
+ return _context3.abrupt("return", future.done);
231
+ case 7:
232
+ case "end":
233
+ return _context3.stop();
234
+ }
235
+ }, _callee3);
236
+ }));
237
+ return function (_x, _x2) {
238
+ return _ref3.apply(this, arguments);
239
+ };
240
+ }();
241
+ _this.handleQueryResponse = function (response) {
242
+ var msgType = response.header.msg_type;
243
+ switch (msgType) {
244
+ case 'execute_result':
245
+ {
246
+ var payload = response;
247
+ var content = payload.content.data['text/plain'];
248
+ if (content.slice(0, 1) === "'" || content.slice(0, 1) === '"') {
249
+ content = content.slice(1, -1);
250
+ content = content.replace(/\\"/g, '"').replace(/\\'/g, "'");
251
+ }
252
+ var update = JSON.parse(content);
253
+ _this.modelSelection = update.map(function (item) {
254
+ return {
255
+ value: item,
256
+ label: item
257
+ };
258
+ });
259
+ break;
260
+ }
261
+ case 'stream':
262
+ {
263
+ var payloadDisplay = response;
264
+ var contentStream = payloadDisplay.content.text;
265
+ if (contentStream.slice(0, 1) === "'" || contentStream.slice(0, 1) === '"') {
266
+ contentStream = contentStream.slice(1, -1);
267
+ contentStream = contentStream.replace(/\\"/g, '"').replace(/\\'/g, "'");
268
+ }
269
+ var updateStream = JSON.parse(contentStream);
270
+ _this.modelSelection = updateStream.map(function (item) {
271
+ return {
272
+ value: item,
273
+ label: item
274
+ };
275
+ });
276
+ break;
277
+ }
278
+ default:
279
+ break;
280
+ }
281
+ };
282
+ _this.options = options;
283
+ _this.viewManager = viewManager;
284
+ _this.className = _this.className + ' prompt';
285
+ _this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
286
+ _this.libroViewTracker = libroViewTracker;
287
+
288
+ // 创建outputArea
289
+ _this.viewManager.getOrCreateView(LibroOutputArea, {
290
+ cellId: _this.id,
291
+ cell: _assertThisInitialized(_this)
292
+ }).then( /*#__PURE__*/function () {
293
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(outputArea) {
294
+ var output;
295
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
296
+ while (1) switch (_context4.prev = _context4.next) {
297
+ case 0:
298
+ _this.outputArea = outputArea;
299
+ output = _this.outputs;
300
+ if (!isOutput(output)) {
301
+ _context4.next = 5;
302
+ break;
303
+ }
304
+ _context4.next = 5;
305
+ return _this.outputArea.fromJSON(output);
306
+ case 5:
307
+ _this.outputAreaDeferred.resolve(outputArea);
308
+ _this.outputWatch();
309
+ return _context4.abrupt("return");
310
+ case 8:
311
+ case "end":
312
+ return _context4.stop();
313
+ }
314
+ }, _callee4);
315
+ }));
316
+ return function (_x3) {
317
+ return _ref4.apply(this, arguments);
318
+ };
319
+ }()).catch(function () {
320
+ //
321
+ });
322
+ return _this;
323
+ }
324
+ LibroPromptCellView = inject(LibroViewTracker)(LibroPromptCellView, undefined, 3) || LibroPromptCellView;
325
+ LibroPromptCellView = inject(ViewManager)(LibroPromptCellView, undefined, 2) || LibroPromptCellView;
326
+ LibroPromptCellView = inject(CellService)(LibroPromptCellView, undefined, 1) || LibroPromptCellView;
327
+ LibroPromptCellView = inject(ViewOption)(LibroPromptCellView, undefined, 0) || LibroPromptCellView;
328
+ _createClass(LibroPromptCellView, [{
329
+ key: "outputAreaReady",
330
+ get: function get() {
331
+ return this.outputAreaDeferred.promise;
332
+ }
333
+ }, {
334
+ key: "editorReady",
335
+ get: function get() {
336
+ return this.editorViewReadyDeferred.promise;
337
+ }
338
+ }, {
339
+ key: "outputWatch",
340
+ value: function outputWatch() {
341
+ var _this2 = this;
342
+ this.toDispose.push(watch(this.outputArea, 'outputs', function () {
343
+ var _this2$parent$model$o, _this2$parent$model;
344
+ (_this2$parent$model$o = (_this2$parent$model = _this2.parent.model).onChange) === null || _this2$parent$model$o === void 0 || _this2$parent$model$o.call(_this2$parent$model);
345
+ }));
346
+ }
347
+ }, {
348
+ key: "toJSON",
349
+ value: function toJSON() {
350
+ var _meta$source, _this$outputArea$toJS, _this$outputArea;
351
+ var meta = _get(_getPrototypeOf(LibroPromptCellView.prototype), "toJSON", this).call(this);
352
+ return _objectSpread(_objectSpread({}, meta), {}, {
353
+ source: (_meta$source = meta.source) !== null && _meta$source !== void 0 ? _meta$source : this.options.cell.source,
354
+ outputs: (_this$outputArea$toJS = (_this$outputArea = this.outputArea) === null || _this$outputArea === void 0 ? void 0 : _this$outputArea.toJSON()) !== null && _this$outputArea$toJS !== void 0 ? _this$outputArea$toJS : this.outputs
355
+ });
356
+ }
357
+ }, {
358
+ key: "onViewMount",
359
+ value: function onViewMount() {
360
+ var _this$parent$model$ac;
361
+ this.createEditor();
362
+ //选中cell时才focus
363
+ if (((_this$parent$model$ac = this.parent.model.active) === null || _this$parent$model$ac === void 0 ? void 0 : _this$parent$model$ac.id) === this.id) {
364
+ this.focus(!this.parent.model.commandMode);
365
+ }
366
+ }
367
+ }, {
368
+ key: "getEditorOption",
369
+ value: function getEditorOption() {
370
+ var _this3 = this;
371
+ var option = {
372
+ factory: function factory(editorOption) {
373
+ return codeMirrorEditorFactory(_objectSpread(_objectSpread({}, editorOption), {}, {
374
+ config: _objectSpread(_objectSpread({}, editorOption.config), {
375
+ readOnly: _this3.parent.model.readOnly
376
+ })
377
+ }));
378
+ },
379
+ model: this.model,
380
+ config: {
381
+ readOnly: this.parent.model.readOnly,
382
+ editable: !this.parent.model.readOnly
383
+ }
384
+ };
385
+ return option;
386
+ }
387
+ }, {
388
+ key: "createEditor",
389
+ value: function () {
390
+ var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
391
+ var _this4 = this;
392
+ var option;
393
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
394
+ while (1) switch (_context5.prev = _context5.next) {
395
+ case 0:
396
+ option = this.getEditorOption();
397
+ this.viewManager.getOrCreateView(CodeEditorView, option).then(function (editorView) {
398
+ _this4.editorView = editorView;
399
+ _this4.editorViewReadyDeferred.resolve();
400
+ watch(_this4.parent.model, 'readOnly', function () {
401
+ var _this4$editorView, _this4$editorView2;
402
+ (_this4$editorView = _this4.editorView) === null || _this4$editorView === void 0 || (_this4$editorView = _this4$editorView.editor) === null || _this4$editorView === void 0 || _this4$editorView.setOption('readOnly', _this4.parent.model.readOnly);
403
+ if (((_this4$editorView2 = _this4.editorView) === null || _this4$editorView2 === void 0 ? void 0 : _this4$editorView2.editor) instanceof CodeMirrorEditor) {
404
+ var _this4$editorView3;
405
+ (_this4$editorView3 = _this4.editorView) === null || _this4$editorView3 === void 0 || _this4$editorView3.editor.setOption('placeholder', '请输入代码');
406
+ }
407
+ });
408
+ return;
409
+ }).catch(function () {
410
+ //
411
+ });
412
+ case 2:
413
+ case "end":
414
+ return _context5.stop();
415
+ }
416
+ }, _callee5, this);
417
+ }));
418
+ function createEditor() {
419
+ return _createEditor.apply(this, arguments);
420
+ }
421
+ return createEditor;
422
+ }()
423
+ }, {
424
+ key: "shouldEnterEditorMode",
425
+ value: function shouldEnterEditorMode(e) {
426
+ var _getOrigin;
427
+ 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;
428
+ }
429
+ }, {
430
+ key: "run",
431
+ value: function () {
432
+ var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
433
+ var _this5 = this;
434
+ var libroModel, kernelConnection, promptObj, cellContent, future, startTimeStr, msgPromise, endTimeStr;
435
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
436
+ while (1) switch (_context6.prev = _context6.next) {
437
+ case 0:
438
+ libroModel = this.parent.model;
439
+ if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
440
+ _context6.next = 3;
441
+ break;
442
+ }
443
+ return _context6.abrupt("return", false);
444
+ case 3:
445
+ kernelConnection = getOrigin(libroModel.kernelConnection); // const cellContent = '%prompt ' + toBase64(this.model.value) + ',model:';
446
+ promptObj = {
447
+ model_name: this.model.modelType || 'CodeGPT',
448
+ prompt: this.model.value
449
+ };
450
+ cellContent = "%%prompt \n".concat(JSON.stringify(promptObj));
451
+ _context6.prev = 6;
452
+ // Promise.resolve().then(() => {
453
+ this.clearExecution();
454
+ // });
455
+ future = kernelConnection.requestExecute({
456
+ code: cellContent
457
+ });
458
+ startTimeStr = null;
459
+ this.model.executing = true;
460
+ this.model.metadata['execution'] = {
461
+ 'shell.execute_reply.started': '',
462
+ 'shell.execute_reply.end': '',
463
+ to_execute: new Date().toISOString()
464
+ };
465
+
466
+ // Handle iopub messages
467
+ future.onIOPub = function (msg) {
468
+ _this5.model.msgChangeEmitter.fire(msg);
469
+ if (msg.header.msg_type === 'execute_input') {
470
+ _this5.model.kernelExecuting = true;
471
+ startTimeStr = msg.header.date;
472
+ var meta = _this5.model.metadata.execution;
473
+ if (meta) {
474
+ meta['shell.execute_reply.started'] = startTimeStr;
475
+ }
476
+ }
477
+ if (msg.header.msg_type === 'error') {
478
+ _this5.model.hasExecutedError = true;
479
+ }
480
+ };
481
+ _context6.next = 15;
482
+ return future.done;
483
+ case 15:
484
+ msgPromise = _context6.sent;
485
+ this.model.executing = false;
486
+ this.model.kernelExecuting = false;
487
+ this.model.hasExecutedSuccess = !this.model.hasExecutedError;
488
+ startTimeStr = msgPromise.metadata['started']; // 更新startTimeStr
489
+ endTimeStr = msgPromise.header.date;
490
+ this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
491
+ this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
492
+ if (msgPromise) {
493
+ _context6.next = 25;
494
+ break;
495
+ }
496
+ return _context6.abrupt("return", true);
497
+ case 25:
498
+ if (!(msgPromise.content.status === 'ok')) {
499
+ _context6.next = 29;
500
+ break;
501
+ }
502
+ return _context6.abrupt("return", true);
503
+ case 29:
504
+ throw new KernelError(msgPromise.content);
505
+ case 30:
506
+ _context6.next = 37;
507
+ break;
508
+ case 32:
509
+ _context6.prev = 32;
510
+ _context6.t0 = _context6["catch"](6);
511
+ if (!_context6.t0.message.startsWith('Canceled')) {
512
+ _context6.next = 36;
513
+ break;
514
+ }
515
+ return _context6.abrupt("return", false);
516
+ case 36:
517
+ throw _context6.t0;
518
+ case 37:
519
+ case "end":
520
+ return _context6.stop();
521
+ }
522
+ }, _callee6, this, [[6, 32]]);
523
+ }));
524
+ function run() {
525
+ return _run.apply(this, arguments);
526
+ }
527
+ return run;
528
+ }()
529
+ }]);
530
+ return LibroPromptCellView;
531
+ }(LibroExecutableCellView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "modelSelection", [_dec3], {
532
+ configurable: true,
533
+ enumerable: true,
534
+ writable: true,
535
+ initializer: function initializer() {
536
+ return [];
537
+ }
538
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "editorView", [_dec4], {
539
+ configurable: true,
540
+ enumerable: true,
541
+ writable: true,
542
+ initializer: null
543
+ })), _class2)) || _class) || _class);
@@ -0,0 +1,6 @@
1
+ import type { BaseOutputView } from '@difizen/libro-jupyter';
2
+ import React from 'react';
3
+ export declare const PromptOutputRender: React.FC<{
4
+ model: BaseOutputView;
5
+ }>;
6
+ //# sourceMappingURL=prompt-output-render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-output-render.d.ts","sourceRoot":"","sources":["../src/prompt-output-render.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,KAAK,MAAM,OAAO,CAAC;AAc1B,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,KAAK,EAAE,cAAc,CAAC;CACvB,CAyDA,CAAC"}