@difizen/libro-prompt-cell 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/libro-formatter-prompt-magic-contribution.d.ts +25 -0
- package/es/libro-formatter-prompt-magic-contribution.d.ts.map +1 -0
- package/es/libro-formatter-prompt-magic-contribution.js +57 -0
- package/es/module.d.ts.map +1 -1
- package/es/module.js +2 -1
- package/es/prompt-cell-model.d.ts +0 -1
- package/es/prompt-cell-model.d.ts.map +1 -1
- package/es/prompt-cell-model.js +10 -26
- package/es/prompt-cell-view.d.ts.map +1 -1
- package/es/prompt-cell-view.js +34 -31
- package/package.json +7 -7
- package/src/libro-formatter-prompt-magic-contribution.ts +63 -0
- package/src/module.ts +2 -0
- package/src/prompt-cell-model.ts +7 -25
- package/src/prompt-cell-view.tsx +12 -11
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DefaultEncodedFormatter } from '@difizen/libro-jupyter';
|
|
2
|
+
import { DefaultDecodedFormatter, FormatterContribution } from '@difizen/libro-jupyter';
|
|
3
|
+
export interface PromptDecodedFormatter extends DefaultDecodedFormatter {
|
|
4
|
+
modelType?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class FormatterPromptMagicContribution implements FormatterContribution<PromptDecodedFormatter> {
|
|
7
|
+
formatter: string;
|
|
8
|
+
formatterOptions?: object;
|
|
9
|
+
canHandle: (libroFormatter: string) => 1 | 100;
|
|
10
|
+
encode: (source: PromptDecodedFormatter) => {
|
|
11
|
+
source: string;
|
|
12
|
+
metadata: {
|
|
13
|
+
libroFormatter: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
decode: (formatterValue: DefaultEncodedFormatter) => {
|
|
17
|
+
value: any;
|
|
18
|
+
modelType: any;
|
|
19
|
+
} | {
|
|
20
|
+
value: string;
|
|
21
|
+
modelType?: undefined;
|
|
22
|
+
};
|
|
23
|
+
validate: (source: PromptDecodedFormatter) => source is PromptDecodedFormatter;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=libro-formatter-prompt-magic-contribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libro-formatter-prompt-magic-contribution.d.ts","sourceRoot":"","sources":["../src/libro-formatter-prompt-magic-contribution.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,wBAAwB,CAAC;AAGhC,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBACa,gCACX,YAAW,qBAAqB,CAAC,sBAAsB,CAAC;IAExD,SAAS,SAA4B;IACrC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,SAAS,mBAAoB,MAAM,aAKjC;IAEF,MAAM,WAAY,sBAAsB;;;;;MAYtC;IAEF,MAAM,mBAAoB,uBAAuB;;;;;;MAgB/C;IAEF,QAAQ,WAAY,sBAAsB,sCAExC;CACH"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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, _class;
|
|
3
|
+
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); } }
|
|
4
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
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); }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
9
|
+
|
|
10
|
+
import { concatMultilineString, DefaultDecodedFormatter, FormatterContribution } from '@difizen/libro-jupyter';
|
|
11
|
+
import { singleton } from '@difizen/mana-app';
|
|
12
|
+
export var FormatterPromptMagicContribution = (_dec = singleton({
|
|
13
|
+
contrib: FormatterContribution
|
|
14
|
+
}), _dec(_class = /*#__PURE__*/_createClass(function FormatterPromptMagicContribution() {
|
|
15
|
+
var _this = this;
|
|
16
|
+
_classCallCheck(this, FormatterPromptMagicContribution);
|
|
17
|
+
this.formatter = 'formatter-prompt-magic';
|
|
18
|
+
this.formatterOptions = void 0;
|
|
19
|
+
this.canHandle = function (libroFormatter) {
|
|
20
|
+
if (libroFormatter === _this.formatter) {
|
|
21
|
+
return 100;
|
|
22
|
+
}
|
|
23
|
+
return 1;
|
|
24
|
+
};
|
|
25
|
+
this.encode = function (source) {
|
|
26
|
+
var promptObj = {
|
|
27
|
+
model_name: source.modelType || 'CodeGPT',
|
|
28
|
+
prompt: source.value
|
|
29
|
+
};
|
|
30
|
+
var encodeValue = "%%prompt \n".concat(JSON.stringify(promptObj));
|
|
31
|
+
return {
|
|
32
|
+
source: encodeValue,
|
|
33
|
+
metadata: {
|
|
34
|
+
libroFormatter: _this.formatter
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
this.decode = function (formatterValue) {
|
|
39
|
+
var value = concatMultilineString(formatterValue.source);
|
|
40
|
+
if (value.startsWith('%%prompt \n')) {
|
|
41
|
+
var run = value.split('%%prompt \n')[1];
|
|
42
|
+
var runValue = JSON.parse(run);
|
|
43
|
+
var codeValue = runValue.prompt;
|
|
44
|
+
var modelType = runValue.model_name;
|
|
45
|
+
return {
|
|
46
|
+
value: codeValue,
|
|
47
|
+
modelType: modelType
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
value: ''
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
this.validate = function (source) {
|
|
55
|
+
return DefaultDecodedFormatter.is(source) && 'modelType' in source;
|
|
56
|
+
};
|
|
57
|
+
})) || _class);
|
package/es/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAW/C,eAAO,MAAM,qBAAqB,YAwB2B,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CellOptions, LibroModule, OutputModule } from '@difizen/libro-core';
|
|
2
2
|
import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
|
|
3
3
|
import { ManaModule } from '@difizen/mana-app';
|
|
4
|
+
import { FormatterPromptMagicContribution } from "./libro-formatter-prompt-magic-contribution.js";
|
|
4
5
|
import { LibroPromptCellCommandContribution } from "./prompt-cell-command-contribution.js";
|
|
5
6
|
import { PromptCellContribution } from "./prompt-cell-contribution.js";
|
|
6
7
|
import { LibroPromptCellModel } from "./prompt-cell-model.js";
|
|
@@ -8,7 +9,7 @@ import { LibroPromptOutputArea } from "./prompt-cell-output-area.js";
|
|
|
8
9
|
import { LibroPromptCellModelFactory } from "./prompt-cell-protocol.js";
|
|
9
10
|
import { LibroPromptCellView } from "./prompt-cell-view.js";
|
|
10
11
|
import { LibroPromptOutputMimeTypeContribution } from "./prompt-output-rendermime-contribution.js";
|
|
11
|
-
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, LibroPromptCellCommandContribution, {
|
|
12
|
+
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, LibroPromptCellCommandContribution, FormatterPromptMagicContribution, {
|
|
12
13
|
token: LibroPromptCellModelFactory,
|
|
13
14
|
useFactory: function useFactory(ctx) {
|
|
14
15
|
return function (options) {
|
|
@@ -24,7 +24,6 @@ export declare class LibroPromptCellModel extends LibroCellModel implements Exec
|
|
|
24
24
|
get msgChange(): ManaEvent<any>;
|
|
25
25
|
viewManager: ViewManager;
|
|
26
26
|
constructor(options: CellOptions, viewManager: ViewManager);
|
|
27
|
-
fromSource(source: string): void;
|
|
28
27
|
toJSON(): Omit<ICodeCell, 'outputs'>;
|
|
29
28
|
clearExecution(): void;
|
|
30
29
|
dispose(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cell-model.d.ts","sourceRoot":"","sources":["../src/prompt-cell-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt-cell-model.d.ts","sourceRoot":"","sources":["../src/prompt-cell-model.ts"],"names":[],"mappings":"AAAA,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;IAiBtC,MAAM,IAAI,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC;IAW7C,cAAc,IAAI,IAAI;IAKb,OAAO;IAKhB,SAAS;CAGV"}
|
package/es/prompt-cell-model.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8;
|
|
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; }
|
|
3
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 }); }
|
|
4
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
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); } }
|
|
@@ -17,7 +20,6 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
17
20
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
18
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; }
|
|
19
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.'); }
|
|
20
|
-
import { concatMultilineString } from '@difizen/libro-common';
|
|
21
23
|
import { LibroCellModel } from '@difizen/libro-core';
|
|
22
24
|
import { CellOptions } from '@difizen/libro-core';
|
|
23
25
|
import { Emitter } from '@difizen/mana-app';
|
|
@@ -29,7 +31,7 @@ export var LibroPromptCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = p
|
|
|
29
31
|
_inherits(LibroPromptCellModel, _LibroCellModel);
|
|
30
32
|
var _super = _createSuper(LibroPromptCellModel);
|
|
31
33
|
function LibroPromptCellModel(options, viewManager) {
|
|
32
|
-
var _options$cell
|
|
34
|
+
var _options$cell;
|
|
33
35
|
var _this;
|
|
34
36
|
_classCallCheck(this, LibroPromptCellModel);
|
|
35
37
|
_this = _super.call(this, options);
|
|
@@ -51,9 +53,11 @@ export var LibroPromptCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = p
|
|
|
51
53
|
_this.executeCount = options.cell.execution_count || null;
|
|
52
54
|
_this.hasOutputHidden = false;
|
|
53
55
|
_this.hasOutputsScrolled = false;
|
|
54
|
-
_this.
|
|
55
|
-
_this.
|
|
56
|
-
_this.
|
|
56
|
+
_this.libroFormatType = 'formatter-prompt-magic';
|
|
57
|
+
_this.mimeType = 'application/vnd.libro.prompt+json';
|
|
58
|
+
_this.metadata = _objectSpread(_objectSpread({}, options === null || options === void 0 || (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.metadata), {}, {
|
|
59
|
+
libroFormatter: _this.libroFormatType
|
|
60
|
+
});
|
|
57
61
|
return _this;
|
|
58
62
|
}
|
|
59
63
|
LibroPromptCellModel = inject(ViewManager)(LibroPromptCellModel, undefined, 1) || LibroPromptCellModel;
|
|
@@ -63,33 +67,13 @@ export var LibroPromptCellModel = (_dec = transient(), _dec2 = prop(), _dec3 = p
|
|
|
63
67
|
get: function get() {
|
|
64
68
|
return this.msgChangeEmitter.event;
|
|
65
69
|
}
|
|
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
70
|
}, {
|
|
81
71
|
key: "toJSON",
|
|
82
72
|
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
73
|
return {
|
|
90
74
|
id: this.id,
|
|
91
75
|
cell_type: this.type,
|
|
92
|
-
source:
|
|
76
|
+
source: this.source,
|
|
93
77
|
metadata: this.metadata,
|
|
94
78
|
execution_count: this.executeCount
|
|
95
79
|
// outputs: this.outputs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EACV,qBAAqB,EACrB,MAAM,EACN,cAAc,EACf,MAAM,4BAA4B,CAAC;AACpC,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,EAEjB,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;AAsErD,qBAEa,mBAAoB,SAAQ,uBAAuB;IACrD,IAAI,uEAA6B;IAElC,KAAK,EAAE,oBAAoB,CAAC;IAGpC,cAAc,EAAE,mBAAmB,EAAE,CAAM;IAE3C,WAAW,EAAE,WAAW,CAAC;IAEzB,iBAAiB,EAAE,iBAAiB,CAAC;IAErC,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,EACjC,iBAAiB,EAAE,iBAAiB;IAgCxD,WAAW;IAQX,MAAM,IAAI,SAAS;IASnB,WAAW;IAQpB,SAAS,CAAC,eAAe,IAAI,qBAAqB;IAY5C,YAAY;cAmBF,gBAAgB;IAUvB,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC;IAQtD,IAAI,aAGX;IAEO,KAAK,WAAY,OAAO,UAqC/B;IAEO,cAAc,aAGrB;IAEF,aAAa,QAAO,EAAE,CAEpB;IAEF,qBAAqB,cAAe,MAAM;;;MAKxC;IAEa,GAAG;IA4ElB,KAAK,YACM,cAAc,kBAAkB,CAAC,SAAS,CAAC,oBAClC,cAAc,aAAa,KAAK,GAAG,6CAUrD;IAEF,mBAAmB,aAAc,cAAc,aAAa,UAmC1D;CACH"}
|
package/es/prompt-cell-view.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
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
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 }); }
|
|
7
4
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
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); } }
|
|
9
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; }
|
|
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
7
|
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
8
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
14
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); }
|
|
@@ -23,6 +18,11 @@ function _initializerWarningHelper(descriptor, context) { throw new Error('Decor
|
|
|
23
18
|
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
19
|
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
20
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
25
|
+
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); }
|
|
26
26
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
27
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
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); }
|
|
@@ -71,8 +71,11 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
71
71
|
}, instance.handleQueryResponse).then(function () {
|
|
72
72
|
var len = instance.modelSelection.length;
|
|
73
73
|
if (len > 0) {
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
instance.model.decodeObject = _objectSpread({
|
|
75
|
+
modelType: instance.modelSelection[len - 1].label
|
|
76
|
+
}, instance.model.decodeObject);
|
|
77
|
+
setSelectedModel(instance.model.decodeObject['modelType']);
|
|
78
|
+
instance.model.modelType = instance.model.decodeObject['modelType'];
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
78
81
|
return;
|
|
@@ -83,6 +86,9 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
83
86
|
}, []);
|
|
84
87
|
var handleChange = function handleChange(value) {
|
|
85
88
|
instance.model.modelType = value;
|
|
89
|
+
instance.model.decodeObject = _objectSpread(_objectSpread({}, instance.model.decodeObject), {}, {
|
|
90
|
+
modelType: value
|
|
91
|
+
});
|
|
86
92
|
setSelectedModel(value);
|
|
87
93
|
};
|
|
88
94
|
return /*#__PURE__*/_jsxs("div", {
|
|
@@ -216,11 +222,12 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
216
222
|
};
|
|
217
223
|
_this.fetch = /*#__PURE__*/function () {
|
|
218
224
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(content, ioCallback) {
|
|
225
|
+
var _this$parent;
|
|
219
226
|
var model, connection, future;
|
|
220
227
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
221
228
|
while (1) switch (_context3.prev = _context3.next) {
|
|
222
229
|
case 0:
|
|
223
|
-
model = _this.parent.model;
|
|
230
|
+
model = (_this$parent = _this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.model;
|
|
224
231
|
_context3.next = 3;
|
|
225
232
|
return model.kcReady;
|
|
226
233
|
case 3:
|
|
@@ -458,7 +465,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
458
465
|
value: function () {
|
|
459
466
|
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
460
467
|
var _this4 = this;
|
|
461
|
-
var libroModel, kernelConnection,
|
|
468
|
+
var libroModel, kernelConnection, cellContent, future, startTimeStr, msgPromise, endTimeStr;
|
|
462
469
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
463
470
|
while (1) switch (_context7.prev = _context7.next) {
|
|
464
471
|
case 0:
|
|
@@ -469,13 +476,9 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
469
476
|
}
|
|
470
477
|
return _context7.abrupt("return", false);
|
|
471
478
|
case 3:
|
|
472
|
-
kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
prompt: this.model.value
|
|
476
|
-
};
|
|
477
|
-
cellContent = "%%prompt \n".concat(JSON.stringify(promptObj));
|
|
478
|
-
_context7.prev = 6;
|
|
479
|
+
kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
480
|
+
cellContent = this.model.source;
|
|
481
|
+
_context7.prev = 5;
|
|
479
482
|
// Promise.resolve().then(() => {
|
|
480
483
|
this.clearExecution();
|
|
481
484
|
// });
|
|
@@ -505,9 +508,9 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
505
508
|
_this4.model.hasExecutedError = true;
|
|
506
509
|
}
|
|
507
510
|
};
|
|
508
|
-
_context7.next =
|
|
511
|
+
_context7.next = 14;
|
|
509
512
|
return future.done;
|
|
510
|
-
case
|
|
513
|
+
case 14:
|
|
511
514
|
msgPromise = _context7.sent;
|
|
512
515
|
this.model.executing = false;
|
|
513
516
|
this.model.kernelExecuting = false;
|
|
@@ -517,36 +520,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
517
520
|
this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
|
|
518
521
|
this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
|
|
519
522
|
if (msgPromise) {
|
|
520
|
-
_context7.next =
|
|
523
|
+
_context7.next = 24;
|
|
521
524
|
break;
|
|
522
525
|
}
|
|
523
526
|
return _context7.abrupt("return", true);
|
|
524
|
-
case
|
|
527
|
+
case 24:
|
|
525
528
|
if (!(msgPromise.content.status === 'ok')) {
|
|
526
|
-
_context7.next =
|
|
529
|
+
_context7.next = 28;
|
|
527
530
|
break;
|
|
528
531
|
}
|
|
529
532
|
return _context7.abrupt("return", true);
|
|
530
|
-
case
|
|
533
|
+
case 28:
|
|
531
534
|
throw new KernelError(msgPromise.content);
|
|
532
|
-
case
|
|
533
|
-
_context7.next =
|
|
535
|
+
case 29:
|
|
536
|
+
_context7.next = 36;
|
|
534
537
|
break;
|
|
535
|
-
case
|
|
536
|
-
_context7.prev =
|
|
537
|
-
_context7.t0 = _context7["catch"](
|
|
538
|
+
case 31:
|
|
539
|
+
_context7.prev = 31;
|
|
540
|
+
_context7.t0 = _context7["catch"](5);
|
|
538
541
|
if (!_context7.t0.message.startsWith('Canceled')) {
|
|
539
|
-
_context7.next =
|
|
542
|
+
_context7.next = 35;
|
|
540
543
|
break;
|
|
541
544
|
}
|
|
542
545
|
return _context7.abrupt("return", false);
|
|
543
|
-
case
|
|
546
|
+
case 35:
|
|
544
547
|
throw _context7.t0;
|
|
545
|
-
case
|
|
548
|
+
case 36:
|
|
546
549
|
case "end":
|
|
547
550
|
return _context7.stop();
|
|
548
551
|
}
|
|
549
|
-
}, _callee7, this, [[
|
|
552
|
+
}, _callee7, this, [[5, 31]]);
|
|
550
553
|
}));
|
|
551
554
|
function run() {
|
|
552
555
|
return _run.apply(this, arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-prompt-cell",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-code-editor": "^0.1.
|
|
36
|
-
"@difizen/libro-jupyter": "^0.1.
|
|
37
|
-
"@difizen/libro-rendermime": "^0.1.
|
|
38
|
-
"@difizen/libro-codemirror": "^0.1.
|
|
39
|
-
"@difizen/libro-common": "^0.1.
|
|
40
|
-
"@difizen/libro-core": "^0.1.
|
|
35
|
+
"@difizen/libro-code-editor": "^0.1.3",
|
|
36
|
+
"@difizen/libro-jupyter": "^0.1.3",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.1.3",
|
|
38
|
+
"@difizen/libro-codemirror": "^0.1.3",
|
|
39
|
+
"@difizen/libro-common": "^0.1.3",
|
|
40
|
+
"@difizen/libro-core": "^0.1.3",
|
|
41
41
|
"@difizen/mana-app": "latest",
|
|
42
42
|
"highlight.js": "^11.8.0",
|
|
43
43
|
"marked": "^5.1.1",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
|
|
3
|
+
import type { DefaultEncodedFormatter } from '@difizen/libro-jupyter';
|
|
4
|
+
import {
|
|
5
|
+
concatMultilineString,
|
|
6
|
+
DefaultDecodedFormatter,
|
|
7
|
+
FormatterContribution,
|
|
8
|
+
} from '@difizen/libro-jupyter';
|
|
9
|
+
import { singleton } from '@difizen/mana-app';
|
|
10
|
+
|
|
11
|
+
export interface PromptDecodedFormatter extends DefaultDecodedFormatter {
|
|
12
|
+
modelType?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@singleton({ contrib: FormatterContribution })
|
|
16
|
+
export class FormatterPromptMagicContribution
|
|
17
|
+
implements FormatterContribution<PromptDecodedFormatter>
|
|
18
|
+
{
|
|
19
|
+
formatter = 'formatter-prompt-magic';
|
|
20
|
+
formatterOptions?: object;
|
|
21
|
+
canHandle = (libroFormatter: string) => {
|
|
22
|
+
if (libroFormatter === this.formatter) {
|
|
23
|
+
return 100;
|
|
24
|
+
}
|
|
25
|
+
return 1;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
encode = (source: PromptDecodedFormatter) => {
|
|
29
|
+
const promptObj = {
|
|
30
|
+
model_name: source.modelType || 'CodeGPT',
|
|
31
|
+
prompt: source.value,
|
|
32
|
+
};
|
|
33
|
+
const encodeValue = `%%prompt \n${JSON.stringify(promptObj)}`;
|
|
34
|
+
return {
|
|
35
|
+
source: encodeValue,
|
|
36
|
+
metadata: {
|
|
37
|
+
libroFormatter: this.formatter,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
43
|
+
const value = concatMultilineString(formatterValue.source);
|
|
44
|
+
|
|
45
|
+
if (value.startsWith('%%prompt \n')) {
|
|
46
|
+
const run = value.split('%%prompt \n')[1];
|
|
47
|
+
const runValue = JSON.parse(run);
|
|
48
|
+
const codeValue = runValue.prompt;
|
|
49
|
+
const modelType = runValue.model_name;
|
|
50
|
+
return {
|
|
51
|
+
value: codeValue,
|
|
52
|
+
modelType,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
value: '',
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
validate = (source: PromptDecodedFormatter): source is PromptDecodedFormatter => {
|
|
61
|
+
return DefaultDecodedFormatter.is(source) && 'modelType' in source;
|
|
62
|
+
};
|
|
63
|
+
}
|
package/src/module.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CellOptions, LibroModule, OutputModule } from '@difizen/libro-core';
|
|
|
2
2
|
import { LibroRenderMimeModule } from '@difizen/libro-rendermime';
|
|
3
3
|
import { ManaModule } from '@difizen/mana-app';
|
|
4
4
|
|
|
5
|
+
import { FormatterPromptMagicContribution } from './libro-formatter-prompt-magic-contribution.js';
|
|
5
6
|
import { LibroPromptCellCommandContribution } from './prompt-cell-command-contribution.js';
|
|
6
7
|
import { PromptCellContribution } from './prompt-cell-contribution.js';
|
|
7
8
|
import { LibroPromptCellModel } from './prompt-cell-model.js';
|
|
@@ -18,6 +19,7 @@ export const LibroPromptCellModule = ManaModule.create()
|
|
|
18
19
|
LibroPromptOutputArea,
|
|
19
20
|
LibroPromptOutputMimeTypeContribution,
|
|
20
21
|
LibroPromptCellCommandContribution,
|
|
22
|
+
FormatterPromptMagicContribution,
|
|
21
23
|
{
|
|
22
24
|
token: LibroPromptCellModelFactory,
|
|
23
25
|
useFactory: (ctx) => {
|
package/src/prompt-cell-model.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { concatMultilineString } from '@difizen/libro-common';
|
|
2
1
|
import type {
|
|
3
2
|
ICellMetadata,
|
|
4
3
|
ExecutionCount,
|
|
@@ -65,36 +64,19 @@ export class LibroPromptCellModel
|
|
|
65
64
|
this.executeCount = (options.cell as ICodeCell).execution_count || null;
|
|
66
65
|
this.hasOutputHidden = false;
|
|
67
66
|
this.hasOutputsScrolled = false;
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const run = source.split('%%prompt \n')[1];
|
|
76
|
-
const runValue = JSON.parse(run);
|
|
77
|
-
this.value = runValue.prompt;
|
|
78
|
-
this.modelType = runValue.model_name;
|
|
79
|
-
} catch {
|
|
80
|
-
() => {
|
|
81
|
-
//
|
|
82
|
-
};
|
|
83
|
-
}
|
|
67
|
+
this.libroFormatType = 'formatter-prompt-magic';
|
|
68
|
+
this.mimeType = 'application/vnd.libro.prompt+json';
|
|
69
|
+
this.metadata = {
|
|
70
|
+
...options?.cell?.metadata,
|
|
71
|
+
libroFormatter: this.libroFormatType,
|
|
72
|
+
};
|
|
84
73
|
}
|
|
85
74
|
|
|
86
75
|
override toJSON(): Omit<ICodeCell, 'outputs'> {
|
|
87
|
-
// const outputs = this.outputArea?.toJSON() ?? this.outputs;
|
|
88
|
-
const promptObj = {
|
|
89
|
-
model_name: this.modelType || 'CodeGPT',
|
|
90
|
-
prompt: this.value,
|
|
91
|
-
};
|
|
92
|
-
const encodeValue = `%%prompt \n${JSON.stringify(promptObj)}`;
|
|
93
|
-
|
|
94
76
|
return {
|
|
95
77
|
id: this.id,
|
|
96
78
|
cell_type: this.type,
|
|
97
|
-
source:
|
|
79
|
+
source: this.source,
|
|
98
80
|
metadata: this.metadata,
|
|
99
81
|
execution_count: this.executeCount,
|
|
100
82
|
// outputs: this.outputs,
|
package/src/prompt-cell-view.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
IRange,
|
|
5
5
|
CodeEditorView,
|
|
6
6
|
} from '@difizen/libro-code-editor';
|
|
7
|
-
|
|
8
7
|
import type { ICodeCell, IOutput } from '@difizen/libro-common';
|
|
9
8
|
import { isOutput } from '@difizen/libro-common';
|
|
10
9
|
import type {
|
|
@@ -74,8 +73,12 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
74
73
|
.then(() => {
|
|
75
74
|
const len = instance.modelSelection.length;
|
|
76
75
|
if (len > 0) {
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
instance.model.decodeObject = {
|
|
77
|
+
modelType: instance.modelSelection[len - 1].label,
|
|
78
|
+
...instance.model.decodeObject,
|
|
79
|
+
};
|
|
80
|
+
setSelectedModel(instance.model.decodeObject['modelType']);
|
|
81
|
+
instance.model.modelType = instance.model.decodeObject['modelType'];
|
|
79
82
|
return;
|
|
80
83
|
}
|
|
81
84
|
return;
|
|
@@ -88,6 +91,10 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
88
91
|
|
|
89
92
|
const handleChange = (value: string) => {
|
|
90
93
|
instance.model.modelType = value;
|
|
94
|
+
instance.model.decodeObject = {
|
|
95
|
+
...instance.model.decodeObject,
|
|
96
|
+
modelType: value,
|
|
97
|
+
};
|
|
91
98
|
setSelectedModel(value);
|
|
92
99
|
};
|
|
93
100
|
|
|
@@ -338,13 +345,7 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
338
345
|
|
|
339
346
|
const kernelConnection = getOrigin(libroModel.kernelConnection);
|
|
340
347
|
|
|
341
|
-
|
|
342
|
-
const promptObj = {
|
|
343
|
-
model_name: this.model.modelType || 'CodeGPT',
|
|
344
|
-
prompt: this.model.value,
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const cellContent = `%%prompt \n${JSON.stringify(promptObj)}`;
|
|
348
|
+
const cellContent = this.model.source;
|
|
348
349
|
|
|
349
350
|
try {
|
|
350
351
|
// Promise.resolve().then(() => {
|
|
@@ -410,7 +411,7 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
410
411
|
content: KernelMessage.IExecuteRequestMsg['content'],
|
|
411
412
|
ioCallback: (msg: KernelMessage.IIOPubMessage) => any,
|
|
412
413
|
) => {
|
|
413
|
-
const model = this.parent
|
|
414
|
+
const model = this.parent?.model as LibroJupyterModel;
|
|
414
415
|
await model.kcReady;
|
|
415
416
|
const connection = model.kernelConnection!;
|
|
416
417
|
const future = connection.requestExecute(content);
|