@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,14 @@
1
+ import type { IOutputAreaOption } from '@difizen/libro-core';
2
+ import { LibroOutputArea } from '@difizen/libro-core';
3
+ import type { ViewComponent } from '@difizen/mana-app';
4
+ import React from 'react';
5
+ import './index.less';
6
+ export declare const LibroPromptOutputAreaRender: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
7
+ export declare class LibroPromptOutputArea extends LibroOutputArea {
8
+ view: ViewComponent;
9
+ promptExecutionTipVisiable: boolean;
10
+ promptExecutionTipShown: boolean;
11
+ constructor(option: IOutputAreaOption);
12
+ setSqlExecutionTipVisiable: (value: boolean) => void;
13
+ }
14
+ //# sourceMappingURL=prompt-cell-output-area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-output-area.d.ts","sourceRoot":"","sources":["../src/prompt-cell-output-area.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAWvD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,2BAA2B,sEAoBvC,CAAC;AAEF,qBAEa,qBAAsB,SAAQ,eAAe;IAC/C,IAAI,EAAE,aAAa,CAA+B;IAE3D,0BAA0B,UAAS;IAEnC,uBAAuB,UAAQ;gBAEC,MAAM,EAAE,iBAAiB;IAIzD,0BAA0B,UAAW,OAAO,UAE1C;CACH"}
@@ -0,0 +1,74 @@
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 _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 _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); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ 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); }
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+ 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); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ 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); }; }
12
+ 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); }
13
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
+ 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; } }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
+ 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; }
17
+ 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.'); }
18
+ // import { l10n } from '@difizen/mana-l10n';
19
+
20
+ import { LibroOutputArea } from '@difizen/libro-core';
21
+ import { RenderMimeRegistry } from '@difizen/libro-jupyter';
22
+ import { useInject, ViewInstance, ViewRender, prop, view, inject, transient, ViewOption } from '@difizen/mana-app';
23
+ import React from 'react';
24
+ import "./index.less";
25
+ import { jsx as _jsx } from "react/jsx-runtime";
26
+ export var LibroPromptOutputAreaRender = /*#__PURE__*/React.forwardRef(function LibroPromptOutputAreaRender(_props, ref) {
27
+ var outputArea = useInject(ViewInstance);
28
+ var defaultRenderMime = useInject(RenderMimeRegistry);
29
+ return /*#__PURE__*/_jsx("div", {
30
+ className: "libro-output-area prompt-cell",
31
+ ref: ref,
32
+ children: outputArea.outputs.map(function (output) {
33
+ if (defaultRenderMime.preferredMimeType(output) !== 'application/vnd.libro.prompt+json') {
34
+ return /*#__PURE__*/_jsx(ViewRender, {
35
+ view: output
36
+ }, output.id);
37
+ } else {
38
+ return null;
39
+ }
40
+ })
41
+ });
42
+ });
43
+ export var LibroPromptOutputArea = (_dec = transient(), _dec2 = view('libro-prompt-output-area'), _dec3 = prop(), _dec4 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroOutputArea) {
44
+ _inherits(LibroPromptOutputArea, _LibroOutputArea);
45
+ var _super = _createSuper(LibroPromptOutputArea);
46
+ function LibroPromptOutputArea(option) {
47
+ var _this;
48
+ _classCallCheck(this, LibroPromptOutputArea);
49
+ _this = _super.call(this, option);
50
+ _this.view = LibroPromptOutputAreaRender;
51
+ _initializerDefineProperty(_this, "promptExecutionTipVisiable", _descriptor, _assertThisInitialized(_this));
52
+ _initializerDefineProperty(_this, "promptExecutionTipShown", _descriptor2, _assertThisInitialized(_this));
53
+ _this.setSqlExecutionTipVisiable = function (value) {
54
+ _this.promptExecutionTipVisiable = value;
55
+ };
56
+ return _this;
57
+ }
58
+ LibroPromptOutputArea = inject(ViewOption)(LibroPromptOutputArea, undefined, 0) || LibroPromptOutputArea;
59
+ return _createClass(LibroPromptOutputArea);
60
+ }(LibroOutputArea), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "promptExecutionTipVisiable", [_dec3], {
61
+ configurable: true,
62
+ enumerable: true,
63
+ writable: true,
64
+ initializer: function initializer() {
65
+ return false;
66
+ }
67
+ }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "promptExecutionTipShown", [_dec4], {
68
+ configurable: true,
69
+ enumerable: true,
70
+ writable: true,
71
+ initializer: function initializer() {
72
+ return true;
73
+ }
74
+ })), _class2)) || _class) || _class);
@@ -0,0 +1,5 @@
1
+ import type { CellOptions } from '@difizen/libro-core';
2
+ import type { LibroPromptCellModel } from './prompt-cell-model.js';
3
+ export type LibroPromptCellModelFactory = (options: CellOptions) => LibroPromptCellModel;
4
+ export declare const LibroPromptCellModelFactory: unique symbol;
5
+ //# sourceMappingURL=prompt-cell-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-protocol.d.ts","sourceRoot":"","sources":["../src/prompt-cell-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,MAAM,MAAM,2BAA2B,GAAG,CACxC,OAAO,EAAE,WAAW,KACjB,oBAAoB,CAAC;AAC1B,eAAO,MAAM,2BAA2B,eAAwC,CAAC"}
@@ -0,0 +1 @@
1
+ export var LibroPromptCellModelFactory = Symbol('LibroPromptCellModelFactory');
@@ -0,0 +1,4 @@
1
+ export declare namespace PromptScript {
2
+ const get_models = "import json\nfrom aistudio_notebook.prompt_flow import prompt_model_registry\nmodel_list = list(prompt_model_registry.promptModelRegistry.get_models().keys())\nmodel_data = json.dumps(model_list)\nprint(model_data)\n";
3
+ }
4
+ //# sourceMappingURL=prompt-cell-script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-script.d.ts","sourceRoot":"","sources":["../src/prompt-cell-script.ts"],"names":[],"mappings":"AAAA,yBAAiB,YAAY,CAAC;IACrB,MAAM,UAAU,6NACqM,CAAC;CAC9N"}
@@ -0,0 +1,4 @@
1
+ export var PromptScript;
2
+ (function (_PromptScript) {
3
+ var get_models = _PromptScript.get_models = 'import json\nfrom aistudio_notebook.prompt_flow import prompt_model_registry\nmodel_list = list(prompt_model_registry.promptModelRegistry.get_models().keys())\nmodel_data = json.dumps(model_list)\nprint(model_data)\n';
4
+ })(PromptScript || (PromptScript = {}));
@@ -0,0 +1,2 @@
1
+ export declare const getPythonCode: (str: string) => string[];
2
+ //# sourceMappingURL=prompt-cell-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-utils.d.ts","sourceRoot":"","sources":["../src/prompt-cell-utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,QAAS,MAAM,aAKxC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export var getPythonCode = function getPythonCode(str) {
2
+ var pattern = /```python([\s\S]*?)```/g;
3
+ var matches = str.match(pattern) || [];
4
+ return matches.map(function (match) {
5
+ return match.replace(/```python([\s\S]*?)```/g, '$1');
6
+ });
7
+ };
@@ -0,0 +1,50 @@
1
+ import type { CodeEditorViewOptions, IRange } from '@difizen/libro-code-editor';
2
+ import { CodeEditorView } from '@difizen/libro-code-editor';
3
+ import type { IOutput } from '@difizen/libro-common';
4
+ import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
5
+ import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker } from '@difizen/libro-core';
6
+ import type { KernelMessage } from '@difizen/libro-jupyter';
7
+ import { ViewManager } from '@difizen/mana-app';
8
+ import { Deferred } from '@difizen/mana-app';
9
+ import React from 'react';
10
+ import type { LibroPromptCellModel } from './prompt-cell-model.js';
11
+ export interface IModelSelectionItem {
12
+ value: string;
13
+ label: string;
14
+ }
15
+ export interface IModelItem {
16
+ value: string;
17
+ }
18
+ export declare const CellEditorMemo: React.NamedExoticComponent<{}>;
19
+ export declare class LibroPromptCellView extends LibroExecutableCellView {
20
+ view: React.ForwardRefExoticComponent<React.RefAttributes<HTMLDivElement>>;
21
+ model: LibroPromptCellModel;
22
+ modelSelection: IModelSelectionItem[];
23
+ viewManager: ViewManager;
24
+ outputs: IOutput[];
25
+ libroViewTracker: LibroViewTracker;
26
+ editorView?: CodeEditorView;
27
+ protected outputAreaDeferred: Deferred<LibroOutputArea>;
28
+ get outputAreaReady(): Promise<LibroOutputArea>;
29
+ protected editorViewReadyDeferred: Deferred<void>;
30
+ get editorReady(): Promise<void>;
31
+ constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker);
32
+ outputWatch(): void;
33
+ toJSON(): LibroCell;
34
+ onViewMount(): void;
35
+ protected getEditorOption(): CodeEditorViewOptions;
36
+ createEditor(): Promise<void>;
37
+ shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
38
+ blur: () => void;
39
+ focus: (toEdit: boolean) => void;
40
+ clearExecution: () => void;
41
+ getSelections: () => [];
42
+ getSelectionsOffsetAt: (selection: IRange) => {
43
+ start: number;
44
+ end: number;
45
+ };
46
+ run(): Promise<boolean>;
47
+ fetch: (content: KernelMessage.IExecuteRequestMsg['content'], ioCallback: (msg: KernelMessage.IIOPubMessage) => any) => Promise<KernelMessage.IExecuteReplyMsg>;
48
+ handleQueryResponse: (response: KernelMessage.IIOPubMessage) => void;
49
+ }
50
+ //# sourceMappingURL=prompt-cell-view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,EAAa,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,eAAe,EACf,gBAAgB,EACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAQL,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAGnE,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AACD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAYD,eAAO,MAAM,cAAc,gCAAyB,CAAC;AA4DrD,qBAEa,mBAAoB,SAAQ,uBAAuB;IACrD,IAAI,uEAA6B;IAElC,KAAK,EAAE,oBAAoB,CAAC;IAGpC,cAAc,EAAE,mBAAmB,EAAE,CAAM;IAE3C,WAAW,EAAE,WAAW,CAAC;IAEzB,OAAO,EAAE,OAAO,EAAE,CAAC;IAEnB,gBAAgB,EAAE,gBAAgB,CAAC;IAGnC,UAAU,CAAC,EAAE,cAAc,CAAC;IAE5B,SAAS,CAAC,kBAAkB,4BAAmC;IAC/D,IAAI,eAAe,6BAElB;IAED,SAAS,CAAC,uBAAuB,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAwB;IAEzE,IAAI,WAAW,kBAEd;gBAGqB,OAAO,EAAE,eAAe,EACvB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACnB,gBAAgB,EAAE,gBAAgB;IA+BrD,WAAW;IAQX,MAAM,IAAI,SAAS;IASnB,WAAW;IAQpB,SAAS,CAAC,eAAe,IAAI,qBAAqB;IAmB5C,YAAY;IAoBT,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAQtD,IAAI,aAGX;IAEO,KAAK,WAAY,OAAO,UAqC/B;IAEO,cAAc,aAGrB;IAEO,aAAa,QAAO,EAAE,CAE7B;IAEO,qBAAqB,cAAe,MAAM;;;MAKjD;IAEa,GAAG;IAkFlB,KAAK,YACM,cAAc,kBAAkB,CAAC,SAAS,CAAC,oBAClC,cAAc,aAAa,KAAK,GAAG,6CAUrD;IAEF,mBAAmB,aAAc,cAAc,aAAa,UAmC1D;CACH"}