@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Difizen Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # libro-prompt-cell
package/es/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './prompt-cell-contribution.js';
2
+ export * from './prompt-cell-model.js';
3
+ export * from './prompt-cell-protocol.js';
4
+ export * from './prompt-cell-view.js';
5
+ export * from './module.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
package/es/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from "./prompt-cell-contribution.js";
2
+ export * from "./prompt-cell-model.js";
3
+ export * from "./prompt-cell-protocol.js";
4
+ export * from "./prompt-cell-view.js";
5
+ export * from "./module.js";
package/es/index.less ADDED
@@ -0,0 +1,54 @@
1
+ .libro-llm-hljs {
2
+ overflow-x: auto;
3
+ white-space: pre-wrap !important;
4
+ word-wrap: break-word !important;
5
+ text-shadow: unset !important;
6
+ color: var(--mana-libro-editor-variable-color) !important;
7
+
8
+ .hljs-title.function_ {
9
+ color: var(--mana-libro-editor-def-color);
10
+ }
11
+
12
+ .hljs-keyword {
13
+ color: var(--mana-libro-editor-keyword-color);
14
+ }
15
+
16
+ .hljs-number {
17
+ color: var(--mana-libro-editor-number-color);
18
+ }
19
+
20
+ .hljs-comment {
21
+ color: var(--mana-libro-editor-comment-color);
22
+ }
23
+
24
+ .hljs-string {
25
+ color: var(--mana-libro-editor-string-color);
26
+ }
27
+
28
+ .hljs-built_in {
29
+ color: var(--mana-libro-editor-builtin-color);
30
+ }
31
+ }
32
+
33
+ .libro-llm-output-render {
34
+ p {
35
+ color: var(--mana-libro-llm-response-output-text-color);
36
+ }
37
+ }
38
+
39
+ .libro-prompt-output-render-container {
40
+ padding: 10px 24px;
41
+ }
42
+
43
+ .libro-prompt-output-llm-render {
44
+ .libro-llm-output-render pre {
45
+ background: #f4f6fb;
46
+ padding: 16px;
47
+ }
48
+ }
49
+
50
+ .libro-prompt-output-btn {
51
+ cursor: pointer;
52
+ color: #1677ff;
53
+ margin-left: 24px;
54
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import 'highlight.js/styles/default.css';
3
+ import './index.less';
4
+ export declare const LibroLLMRender: React.FC<{
5
+ data: string;
6
+ }>;
7
+ export declare const LibroLLMRenderMemo: React.NamedExoticComponent<{
8
+ data: string;
9
+ }>;
10
+ //# sourceMappingURL=libro-llm-render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-llm-render.d.ts","sourceRoot":"","sources":["../src/libro-llm-render.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAqD,MAAM,OAAO,CAAC;AAC1E,OAAO,iCAAiC,CAAC;AAEzC,OAAO,cAAc,CAAC;AAgBtB,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAqCrD,CAAC;AACF,eAAO,MAAM,kBAAkB;UAtCe,MAAM;EAsCE,CAAC"}
@@ -0,0 +1,71 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ 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."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ import { ToolbarRender } from '@difizen/mana-app';
12
+ import hljs from 'highlight.js';
13
+ import { marked } from 'marked';
14
+ import { markedHighlight } from 'marked-highlight';
15
+ import markedKatex from 'marked-katex-extension';
16
+ import React, { useEffect, useRef, memo, useState, useMemo } from 'react';
17
+ import 'highlight.js/styles/default.css';
18
+ import { createPortal } from 'react-dom';
19
+ import "./index.less";
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ marked.use(markedKatex({
22
+ throwOnError: false,
23
+ output: 'mathml'
24
+ }), markedHighlight({
25
+ langPrefix: 'libro-llm-hljs code-block language-',
26
+ highlight: function highlight(code, lang) {
27
+ var language = hljs.getLanguage(lang) ? lang : 'python';
28
+ return hljs.highlight(code, {
29
+ language: language
30
+ }).value;
31
+ }
32
+ }));
33
+ export var LibroLLMRender = function LibroLLMRender(props) {
34
+ var data = props.data;
35
+ var renderMarkdownRef = useRef(null);
36
+ // const LLMExtraRender = useInject<LLMExtraRenderProvider>(LLMExtraRenderProvider);
37
+ var _useState = useState([]),
38
+ _useState2 = _slicedToArray(_useState, 2),
39
+ renderExtraList = _useState2[0],
40
+ setRenderExtraList = _useState2[1];
41
+ var codeToolbarArgs = useMemo(function () {
42
+ return [data, 'CodeToolbar'];
43
+ }, [data]);
44
+ useEffect(function () {
45
+ if (!renderMarkdownRef.current) {
46
+ return;
47
+ }
48
+ renderMarkdownRef.current.innerHTML = marked.parse(data);
49
+ var hljsElements = renderMarkdownRef.current.getElementsByClassName('libro-llm-hljs');
50
+ for (var i = 0; i < hljsElements.length; i++) {
51
+ var newElement = document.createElement('div');
52
+ var newRenderExtraList = [].concat(_toConsumableArray(renderExtraList), [newElement]);
53
+ setRenderExtraList(newRenderExtraList);
54
+ var hljsElement = hljsElements.item(i);
55
+ if (hljsElement) {
56
+ var _hljsElement$parentNo;
57
+ (_hljsElement$parentNo = hljsElement.parentNode) === null || _hljsElement$parentNo === void 0 || _hljsElement$parentNo.insertBefore(newElement, hljsElement.nextSibling);
58
+ }
59
+ }
60
+ }, [data, renderExtraList]);
61
+ return /*#__PURE__*/_jsx("div", {
62
+ className: "libro-llm-output-render",
63
+ ref: renderMarkdownRef,
64
+ children: renderExtraList.map(function (element) {
65
+ return /*#__PURE__*/createPortal( /*#__PURE__*/_jsx(ToolbarRender, {
66
+ data: codeToolbarArgs
67
+ }), element);
68
+ })
69
+ });
70
+ };
71
+ export var LibroLLMRenderMemo = /*#__PURE__*/memo(LibroLLMRender);
package/es/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const LibroPromptCellModule: ManaModule;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAS/C,eAAO,MAAM,qBAAqB,YAuB2B,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,23 @@
1
+ import { CellOptions, LibroModule, OutputModule } from '@difizen/libro-core';
2
+ import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
3
+ import { ManaModule } from '@difizen/mana-app';
4
+ import { PromptCellContribution } from "./prompt-cell-contribution.js";
5
+ import { LibroPromptCellModel } from "./prompt-cell-model.js";
6
+ import { LibroPromptOutputArea } from "./prompt-cell-output-area.js";
7
+ import { LibroPromptCellModelFactory } from "./prompt-cell-protocol.js";
8
+ import { LibroPromptCellView } from "./prompt-cell-view.js";
9
+ import { LibroPromptOutputMimeTypeContribution } from "./prompt-output-rendermime-contribution.js";
10
+ export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, {
11
+ token: LibroPromptCellModelFactory,
12
+ useFactory: function useFactory(ctx) {
13
+ return function (options) {
14
+ var child = ctx.container.createChild();
15
+ child.register({
16
+ token: CellOptions,
17
+ useValue: options
18
+ });
19
+ var model = child.get(LibroPromptCellModel);
20
+ return model;
21
+ };
22
+ }
23
+ }).dependOn(LibroModule, OutputModule, LibroRenderMimeModule);
@@ -0,0 +1,18 @@
1
+ import { LibroCommandRegister } from '@difizen/libro-core';
2
+ import type { CommandRegistry } from '@difizen/mana-app';
3
+ import { CommandContribution, KeybindingContribution, KeybindingRegistry } from '@difizen/mana-app';
4
+ export declare const LibroPromptCellCommands: {
5
+ ChangeCellToPrompt: {
6
+ id: string;
7
+ label: string;
8
+ keybind: string;
9
+ when: string;
10
+ };
11
+ };
12
+ export declare class LibroPromptCellCommandContribution implements CommandContribution, KeybindingContribution {
13
+ protected readonly libroCommand: LibroCommandRegister;
14
+ constructor(keybindRegistry: KeybindingRegistry);
15
+ registerCommands(command: CommandRegistry): void;
16
+ registerKeybindings(keybindings: KeybindingRegistry): void;
17
+ }
18
+ //# sourceMappingURL=prompt-cell-command-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-command-contribution.d.ts","sourceRoot":"","sources":["../src/prompt-cell-command-contribution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAA4B,MAAM,qBAAqB,CAAC;AACrF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACL,mBAAmB,EAEnB,sBAAsB,EACtB,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAE3B,eAAO,MAAM,uBAAuB;;;;;;;CAOnC,CAAC;AAEF,qBACa,kCACX,YAAW,mBAAmB,EAAE,sBAAsB;IAGtD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;gBACd,eAAe,EAAE,kBAAkB;IAM3E,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAyBhD,mBAAmB,CAAC,WAAW,EAAE,kBAAkB;CAGpD"}
@@ -0,0 +1,62 @@
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, _class, _class2, _descriptor;
3
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ 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); }
9
+ 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; }
10
+ 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.'); }
11
+ import { LibroCommandRegister, LibroCellView, LibroView } from '@difizen/libro-core';
12
+ import { CommandContribution, inject, KeybindingContribution, KeybindingRegistry, singleton } from '@difizen/mana-app';
13
+ export var LibroPromptCellCommands = {
14
+ ChangeCellToPrompt: {
15
+ id: 'notebook:change-cell-to-prompt',
16
+ label: "Change to Prompt",
17
+ keybind: 'p',
18
+ when: 'commandMode'
19
+ }
20
+ };
21
+ export var LibroPromptCellCommandContribution = (_dec = singleton({
22
+ contrib: [CommandContribution, KeybindingContribution]
23
+ }), _dec2 = inject(LibroCommandRegister), _dec(_class = (_class2 = /*#__PURE__*/function () {
24
+ function LibroPromptCellCommandContribution(keybindRegistry) {
25
+ _classCallCheck(this, LibroPromptCellCommandContribution);
26
+ _initializerDefineProperty(this, "libroCommand", _descriptor, this);
27
+ // 快捷键命中时默认阻止事件冒泡
28
+ keybindRegistry.preventDefault = true;
29
+ keybindRegistry.stopPropagation = true;
30
+ }
31
+ LibroPromptCellCommandContribution = inject(KeybindingRegistry)(LibroPromptCellCommandContribution, undefined, 0) || LibroPromptCellCommandContribution;
32
+ _createClass(LibroPromptCellCommandContribution, [{
33
+ key: "registerCommands",
34
+ value: function registerCommands(command) {
35
+ this.libroCommand.registerLibroCommand(command, LibroPromptCellCommands.ChangeCellToPrompt, {
36
+ execute: function execute(cell, libro) {
37
+ if (!cell || !libro || !(cell instanceof LibroCellView) || !(libro instanceof LibroView)) {
38
+ return;
39
+ }
40
+ libro.invertCell(cell, 'prompt');
41
+ },
42
+ isEnabled: function isEnabled(cell, libro) {
43
+ if (!libro || !(libro instanceof LibroView) || libro.model.readOnly) {
44
+ return false;
45
+ }
46
+ return true;
47
+ }
48
+ });
49
+ }
50
+ }, {
51
+ key: "registerKeybindings",
52
+ value: function registerKeybindings(keybindings) {
53
+ this.libroCommand.registerKeybinds(keybindings, LibroPromptCellCommands);
54
+ }
55
+ }]);
56
+ return LibroPromptCellCommandContribution;
57
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroCommand", [_dec2], {
58
+ configurable: true,
59
+ enumerable: true,
60
+ writable: true,
61
+ initializer: null
62
+ })), _class2)) || _class);
@@ -0,0 +1,13 @@
1
+ import type { CellModel } from '@difizen/libro-core';
2
+ import type { CellMeta, CellOptions } from '@difizen/libro-core';
3
+ import { CellViewContribution, CellModelContribution } from '@difizen/libro-core';
4
+ import { LibroPromptCellModelFactory } from './prompt-cell-protocol.js';
5
+ import { LibroPromptCellView } from './prompt-cell-view.js';
6
+ export declare class PromptCellContribution implements CellModelContribution, CellViewContribution {
7
+ libroCellModelFactory: LibroPromptCellModelFactory;
8
+ cellMeta: CellMeta;
9
+ canHandle(options: CellOptions, libroType?: string): number;
10
+ createModel(options: CellOptions): Promise<CellModel>;
11
+ view: typeof LibroPromptCellView;
12
+ }
13
+ //# sourceMappingURL=prompt-cell-contribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-contribution.d.ts","sourceRoot":"","sources":["../src/prompt-cell-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAIlF,OAAO,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,qBACa,sBACX,YAAW,qBAAqB,EAAE,oBAAoB;IAGtD,qBAAqB,EAAE,2BAA2B,CAAC;IAEnD,QAAQ,EAAE,QAAQ,CAKhB;IAEF,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAIrD,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;IAK3D,IAAI,6BAAuB;CAC5B"}
@@ -0,0 +1,66 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _class, _class2, _descriptor;
3
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
4
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _toPropertyKey(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 _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
13
+ function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
14
+ import { CellViewContribution, CellModelContribution } from '@difizen/libro-core';
15
+ import { inject } from '@difizen/mana-app';
16
+ import { singleton } from '@difizen/mana-app';
17
+ import { LibroPromptCellModelFactory } from "./prompt-cell-protocol.js";
18
+ import { LibroPromptCellView } from "./prompt-cell-view.js";
19
+ export var PromptCellContribution = (_dec = singleton({
20
+ contrib: [CellModelContribution, CellViewContribution]
21
+ }), _dec2 = inject(LibroPromptCellModelFactory), _dec(_class = (_class2 = /*#__PURE__*/function () {
22
+ function PromptCellContribution() {
23
+ _classCallCheck(this, PromptCellContribution);
24
+ _initializerDefineProperty(this, "libroCellModelFactory", _descriptor, this);
25
+ this.cellMeta = {
26
+ type: 'prompt',
27
+ name: 'Propmt',
28
+ order: 'f',
29
+ nbformatType: 'code'
30
+ };
31
+ this.view = LibroPromptCellView;
32
+ }
33
+ _createClass(PromptCellContribution, [{
34
+ key: "canHandle",
35
+ value: function canHandle(options, libroType) {
36
+ return libroType === this.cellMeta.type ? 2000 : -1;
37
+ }
38
+ }, {
39
+ key: "createModel",
40
+ value: function () {
41
+ var _createModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
42
+ var model;
43
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
44
+ while (1) switch (_context.prev = _context.next) {
45
+ case 0:
46
+ model = this.libroCellModelFactory(options);
47
+ return _context.abrupt("return", model);
48
+ case 2:
49
+ case "end":
50
+ return _context.stop();
51
+ }
52
+ }, _callee, this);
53
+ }));
54
+ function createModel(_x) {
55
+ return _createModel.apply(this, arguments);
56
+ }
57
+ return createModel;
58
+ }()
59
+ }]);
60
+ return PromptCellContribution;
61
+ }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "libroCellModelFactory", [_dec2], {
62
+ configurable: true,
63
+ enumerable: true,
64
+ writable: true,
65
+ initializer: null
66
+ })), _class2)) || _class);
@@ -0,0 +1,33 @@
1
+ import type { ICellMetadata, ExecutionCount, ICodeCellMetadata } from '@difizen/libro-common';
2
+ import type { ICodeCell } from '@difizen/libro-common';
3
+ import type { ExecutableCellModel } from '@difizen/libro-core';
4
+ import { LibroCellModel } from '@difizen/libro-core';
5
+ import { CellOptions } from '@difizen/libro-core';
6
+ import type { ExecutionMeta } from '@difizen/libro-jupyter';
7
+ import { Emitter } from '@difizen/mana-app';
8
+ import { ViewManager } from '@difizen/mana-app';
9
+ import type { Event as ManaEvent } from '@difizen/mana-app';
10
+ export interface PromptCellMetadata extends ICodeCellMetadata {
11
+ execution: ExecutionMeta;
12
+ }
13
+ export declare class LibroPromptCellModel extends LibroCellModel implements ExecutableCellModel {
14
+ executeCount: ExecutionCount;
15
+ hasExecutedSuccess: boolean;
16
+ hasExecutedError: boolean;
17
+ metadata: Partial<PromptCellMetadata | ICellMetadata>;
18
+ kernelExecuting: boolean;
19
+ modelType: string;
20
+ executing: boolean;
21
+ hasOutputHidden: boolean;
22
+ hasOutputsScrolled: boolean;
23
+ msgChangeEmitter: Emitter<any>;
24
+ get msgChange(): ManaEvent<any>;
25
+ viewManager: ViewManager;
26
+ constructor(options: CellOptions, viewManager: ViewManager);
27
+ fromSource(source: string): void;
28
+ toJSON(): Omit<ICodeCell, 'outputs'>;
29
+ clearExecution(): void;
30
+ dispose(): void;
31
+ getSource(): string;
32
+ }
33
+ //# sourceMappingURL=prompt-cell-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-model.d.ts","sourceRoot":"","sources":["../src/prompt-cell-model.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE5D,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,qBACa,oBACX,SAAQ,cACR,YAAW,mBAAmB;IAG9B,YAAY,EAAE,cAAc,CAAC;IAG7B,kBAAkB,UAAS;IAE3B,gBAAgB,UAAS;IAEhB,QAAQ,EAAE,OAAO,CAAC,kBAAkB,GAAG,aAAa,CAAC,CAAC;IAE/D,eAAe,UAAS;IAExB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,OAAO,CAAC;IAEnB,eAAe,EAAE,OAAO,CAAC;IAEzB,kBAAkB,EAAE,OAAO,CAAC;IAG5B,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,CAAC,CAE9B;IAED,WAAW,EAAE,WAAW,CAAC;gBAGF,OAAO,EAAE,WAAW,EACpB,WAAW,EAAE,WAAW;IAc/C,UAAU,CAAC,MAAM,EAAE,MAAM;IAahB,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;IAkB7C,cAAc,IAAI,IAAI;IAKb,OAAO;IAKhB,SAAS;CAGV"}
@@ -0,0 +1,163 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
3
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ 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); }
9
+ 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); }
10
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
11
+ 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); }
12
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
13
+ 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); }; }
14
+ 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); }
15
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
16
+ 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; } }
17
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
18
+ 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; }
19
+ 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.'); }
20
+ import { concatMultilineString } from '@difizen/libro-common';
21
+ import { LibroCellModel } from '@difizen/libro-core';
22
+ import { CellOptions } from '@difizen/libro-core';
23
+ import { Emitter } from '@difizen/mana-app';
24
+ import { transient } from '@difizen/mana-app';
25
+ import { prop } from '@difizen/mana-app';
26
+ import { ViewManager } from '@difizen/mana-app';
27
+ import { inject } from '@difizen/mana-app';
28
+ export var LibroPromptCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec5 = prop(), _dec6 = prop(), _dec7 = prop(), _dec8 = prop(), _dec9 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function (_LibroCellModel) {
29
+ _inherits(LibroPromptCellModel, _LibroCellModel);
30
+ var _super = _createSuper(LibroPromptCellModel);
31
+ function LibroPromptCellModel(options, viewManager) {
32
+ var _options$cell, _options$cell2;
33
+ var _this;
34
+ _classCallCheck(this, LibroPromptCellModel);
35
+ _this = _super.call(this, options);
36
+ _initializerDefineProperty(_this, "executeCount", _descriptor, _assertThisInitialized(_this));
37
+ _initializerDefineProperty(_this, "hasExecutedSuccess", _descriptor2, _assertThisInitialized(_this));
38
+ _initializerDefineProperty(_this, "hasExecutedError", _descriptor3, _assertThisInitialized(_this));
39
+ _initializerDefineProperty(_this, "metadata", _descriptor4, _assertThisInitialized(_this));
40
+ _initializerDefineProperty(_this, "kernelExecuting", _descriptor5, _assertThisInitialized(_this));
41
+ _this.modelType = void 0;
42
+ _initializerDefineProperty(_this, "executing", _descriptor6, _assertThisInitialized(_this));
43
+ _initializerDefineProperty(_this, "hasOutputHidden", _descriptor7, _assertThisInitialized(_this));
44
+ _initializerDefineProperty(_this, "hasOutputsScrolled", _descriptor8, _assertThisInitialized(_this));
45
+ // Emitter Msg
46
+ _this.msgChangeEmitter = void 0;
47
+ _this.viewManager = void 0;
48
+ _this.viewManager = viewManager;
49
+ _this.executing = false;
50
+ _this.msgChangeEmitter = new Emitter();
51
+ _this.executeCount = options.cell.execution_count || null;
52
+ _this.hasOutputHidden = false;
53
+ _this.hasOutputsScrolled = false;
54
+ _this.mimeType = 'text/x-python';
55
+ _this.metadata = (options === null || options === void 0 || (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.metadata) || {};
56
+ _this.fromSource(concatMultilineString(options === null || options === void 0 || (_options$cell2 = options.cell) === null || _options$cell2 === void 0 ? void 0 : _options$cell2.source));
57
+ return _this;
58
+ }
59
+ LibroPromptCellModel = inject(ViewManager)(LibroPromptCellModel, undefined, 1) || LibroPromptCellModel;
60
+ LibroPromptCellModel = inject(CellOptions)(LibroPromptCellModel, undefined, 0) || LibroPromptCellModel;
61
+ _createClass(LibroPromptCellModel, [{
62
+ key: "msgChange",
63
+ get: function get() {
64
+ return this.msgChangeEmitter.event;
65
+ }
66
+ }, {
67
+ key: "fromSource",
68
+ value: function fromSource(source) {
69
+ try {
70
+ var run = source.split('%%prompt \n')[1];
71
+ var runValue = JSON.parse(run);
72
+ this.value = runValue.prompt;
73
+ this.modelType = runValue.model_name;
74
+ } catch (_unused) {
75
+ (function () {
76
+ //
77
+ });
78
+ }
79
+ }
80
+ }, {
81
+ key: "toJSON",
82
+ value: function toJSON() {
83
+ // const outputs = this.outputArea?.toJSON() ?? this.outputs;
84
+ var promptObj = {
85
+ model_name: this.modelType || 'CodeGPT',
86
+ prompt: this.value
87
+ };
88
+ var encodeValue = "%%prompt \n".concat(JSON.stringify(promptObj));
89
+ return {
90
+ id: this.id,
91
+ cell_type: this.type,
92
+ source: encodeValue,
93
+ metadata: this.metadata,
94
+ execution_count: this.executeCount
95
+ // outputs: this.outputs,
96
+ };
97
+ }
98
+ }, {
99
+ key: "clearExecution",
100
+ value: function clearExecution() {
101
+ this.executeCount = null;
102
+ this.metadata = {};
103
+ }
104
+ }, {
105
+ key: "dispose",
106
+ value: function dispose() {
107
+ _get(_getPrototypeOf(LibroPromptCellModel.prototype), "dispose", this).call(this);
108
+ this.msgChangeEmitter.dispose();
109
+ }
110
+ }, {
111
+ key: "getSource",
112
+ value: function getSource() {
113
+ return this.value;
114
+ }
115
+ }]);
116
+ return LibroPromptCellModel;
117
+ }(LibroCellModel), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "executeCount", [_dec2], {
118
+ configurable: true,
119
+ enumerable: true,
120
+ writable: true,
121
+ initializer: null
122
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "hasExecutedSuccess", [_dec3], {
123
+ configurable: true,
124
+ enumerable: true,
125
+ writable: true,
126
+ initializer: function initializer() {
127
+ return false;
128
+ }
129
+ }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "hasExecutedError", [_dec4], {
130
+ configurable: true,
131
+ enumerable: true,
132
+ writable: true,
133
+ initializer: function initializer() {
134
+ return false;
135
+ }
136
+ }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "metadata", [_dec5], {
137
+ configurable: true,
138
+ enumerable: true,
139
+ writable: true,
140
+ initializer: null
141
+ }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "kernelExecuting", [_dec6], {
142
+ configurable: true,
143
+ enumerable: true,
144
+ writable: true,
145
+ initializer: function initializer() {
146
+ return false;
147
+ }
148
+ }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "executing", [_dec7], {
149
+ configurable: true,
150
+ enumerable: true,
151
+ writable: true,
152
+ initializer: null
153
+ }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "hasOutputHidden", [_dec8], {
154
+ configurable: true,
155
+ enumerable: true,
156
+ writable: true,
157
+ initializer: null
158
+ }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "hasOutputsScrolled", [_dec9], {
159
+ configurable: true,
160
+ enumerable: true,
161
+ writable: true,
162
+ initializer: null
163
+ })), _class2)) || _class);