@difizen/libro-prompt-cell 0.1.1 → 0.1.2
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/index.less +1 -1
- package/es/libro-llm-render.d.ts.map +1 -1
- package/es/libro-llm-render.js +6 -2
- package/es/module.d.ts.map +1 -1
- package/es/module.js +2 -1
- package/es/prompt-cell-view.d.ts +5 -3
- package/es/prompt-cell-view.d.ts.map +1 -1
- package/es/prompt-cell-view.js +87 -60
- package/es/prompt-output-render.d.ts.map +1 -1
- package/es/prompt-output-render.js +117 -10
- package/package.json +7 -7
- package/src/index.less +1 -1
- package/src/libro-llm-render.tsx +2 -1
- package/src/module.ts +2 -1
- package/src/prompt-cell-view.tsx +46 -33
- package/src/prompt-output-render.tsx +51 -8
package/es/index.less
CHANGED
|
@@ -1 +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;
|
|
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;AAiBtB,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAqCrD,CAAC;AACF,eAAO,MAAM,kBAAkB;UAtCe,MAAM;EAsCE,CAAC"}
|
package/es/libro-llm-render.js
CHANGED
|
@@ -29,7 +29,10 @@ marked.use(markedKatex({
|
|
|
29
29
|
language: language
|
|
30
30
|
}).value;
|
|
31
31
|
}
|
|
32
|
-
})
|
|
32
|
+
}), {
|
|
33
|
+
headerIds: false,
|
|
34
|
+
mangle: false
|
|
35
|
+
});
|
|
33
36
|
export var LibroLLMRender = function LibroLLMRender(props) {
|
|
34
37
|
var data = props.data;
|
|
35
38
|
var renderMarkdownRef = useRef(null);
|
|
@@ -57,7 +60,8 @@ export var LibroLLMRender = function LibroLLMRender(props) {
|
|
|
57
60
|
(_hljsElement$parentNo = hljsElement.parentNode) === null || _hljsElement$parentNo === void 0 || _hljsElement$parentNo.insertBefore(newElement, hljsElement.nextSibling);
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
|
-
}, [data
|
|
63
|
+
}, [data]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
64
|
+
|
|
61
65
|
return /*#__PURE__*/_jsx("div", {
|
|
62
66
|
className: "libro-llm-output-render",
|
|
63
67
|
ref: renderMarkdownRef,
|
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;AAU/C,eAAO,MAAM,qBAAqB,YAuB2B,CAAC"}
|
package/es/module.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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 { LibroPromptCellCommandContribution } from "./prompt-cell-command-contribution.js";
|
|
4
5
|
import { PromptCellContribution } from "./prompt-cell-contribution.js";
|
|
5
6
|
import { LibroPromptCellModel } from "./prompt-cell-model.js";
|
|
6
7
|
import { LibroPromptOutputArea } from "./prompt-cell-output-area.js";
|
|
7
8
|
import { LibroPromptCellModelFactory } from "./prompt-cell-protocol.js";
|
|
8
9
|
import { LibroPromptCellView } from "./prompt-cell-view.js";
|
|
9
10
|
import { LibroPromptOutputMimeTypeContribution } from "./prompt-output-rendermime-contribution.js";
|
|
10
|
-
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, {
|
|
11
|
+
export var LibroPromptCellModule = ManaModule.create().register(PromptCellContribution, LibroPromptCellView, LibroPromptCellModel, LibroPromptOutputArea, LibroPromptOutputMimeTypeContribution, LibroPromptCellCommandContribution, {
|
|
11
12
|
token: LibroPromptCellModelFactory,
|
|
12
13
|
useFactory: function useFactory(ctx) {
|
|
13
14
|
return function (options) {
|
package/es/prompt-cell-view.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CodeEditorView } from '@difizen/libro-code-editor';
|
|
1
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
2
|
+
import type { CodeEditorViewOptions, IRange, CodeEditorView } from '@difizen/libro-code-editor';
|
|
3
3
|
import type { IOutput } from '@difizen/libro-common';
|
|
4
4
|
import type { LibroCell, CellViewOptions } from '@difizen/libro-core';
|
|
5
5
|
import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker } from '@difizen/libro-core';
|
|
@@ -21,6 +21,7 @@ export declare class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
21
21
|
model: LibroPromptCellModel;
|
|
22
22
|
modelSelection: IModelSelectionItem[];
|
|
23
23
|
viewManager: ViewManager;
|
|
24
|
+
codeEditorManager: CodeEditorManager;
|
|
24
25
|
outputs: IOutput[];
|
|
25
26
|
libroViewTracker: LibroViewTracker;
|
|
26
27
|
editorView?: CodeEditorView;
|
|
@@ -28,12 +29,13 @@ export declare class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
28
29
|
get outputAreaReady(): Promise<LibroOutputArea>;
|
|
29
30
|
protected editorViewReadyDeferred: Deferred<void>;
|
|
30
31
|
get editorReady(): Promise<void>;
|
|
31
|
-
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker);
|
|
32
|
+
constructor(options: CellViewOptions, cellService: CellService, viewManager: ViewManager, libroViewTracker: LibroViewTracker, codeEditorManager: CodeEditorManager);
|
|
32
33
|
outputWatch(): void;
|
|
33
34
|
toJSON(): LibroCell;
|
|
34
35
|
onViewMount(): void;
|
|
35
36
|
protected getEditorOption(): CodeEditorViewOptions;
|
|
36
37
|
createEditor(): Promise<void>;
|
|
38
|
+
protected afterEditorReady(): Promise<void>;
|
|
37
39
|
shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>): boolean;
|
|
38
40
|
blur: () => void;
|
|
39
41
|
focus: (toEdit: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cell-view.d.ts","sourceRoot":"","sources":["../src/prompt-cell-view.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAEpC,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;AA8DrD,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;IAkFlB,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
|
@@ -29,10 +29,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
29
29
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
30
30
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
31
31
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
32
|
-
import {
|
|
33
|
-
import { CodeMirrorEditor, codeMirrorEditorFactory } from '@difizen/libro-codemirror';
|
|
32
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
34
33
|
import { isOutput } from '@difizen/libro-common';
|
|
35
|
-
import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker } from '@difizen/libro-core';
|
|
34
|
+
import { CellService, LibroExecutableCellView, LibroOutputArea, LibroViewTracker, EditorStatus } from '@difizen/libro-core';
|
|
36
35
|
import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
|
|
37
36
|
import { getOrigin, inject, prop, transient, useInject, view, ViewInstance, ViewManager, ViewOption, ViewRender, watch } from '@difizen/mana-app';
|
|
38
37
|
import { Deferred } from '@difizen/mana-app';
|
|
@@ -70,16 +69,18 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
70
69
|
code: PromptScript.get_models,
|
|
71
70
|
store_history: false
|
|
72
71
|
}, instance.handleQueryResponse).then(function () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
instance.
|
|
72
|
+
var len = instance.modelSelection.length;
|
|
73
|
+
if (len > 0) {
|
|
74
|
+
setSelectedModel(instance.modelSelection[len - 1].label);
|
|
75
|
+
instance.model.modelType = instance.modelSelection[len - 1].label;
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
return;
|
|
79
79
|
}).catch(function () {
|
|
80
80
|
//
|
|
81
81
|
});
|
|
82
|
-
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, []);
|
|
83
84
|
var handleChange = function handleChange(value) {
|
|
84
85
|
instance.model.modelType = value;
|
|
85
86
|
setSelectedModel(value);
|
|
@@ -124,7 +125,7 @@ var PropmtEditorViewComponent = /*#__PURE__*/React.forwardRef(function MaxPropmt
|
|
|
124
125
|
export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-editor-cell-view'), _dec3 = prop(), _dec4 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_LibroExecutableCellV) {
|
|
125
126
|
_inherits(LibroPromptCellView, _LibroExecutableCellV);
|
|
126
127
|
var _super = _createSuper(LibroPromptCellView);
|
|
127
|
-
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker) {
|
|
128
|
+
function LibroPromptCellView(options, cellService, viewManager, libroViewTracker, codeEditorManager) {
|
|
128
129
|
var _options$cell;
|
|
129
130
|
var _this;
|
|
130
131
|
_classCallCheck(this, LibroPromptCellView);
|
|
@@ -132,6 +133,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
132
133
|
_this.view = PropmtEditorViewComponent;
|
|
133
134
|
_initializerDefineProperty(_this, "modelSelection", _descriptor, _assertThisInitialized(_this));
|
|
134
135
|
_this.viewManager = void 0;
|
|
136
|
+
_this.codeEditorManager = void 0;
|
|
135
137
|
_this.outputs = void 0;
|
|
136
138
|
_this.libroViewTracker = void 0;
|
|
137
139
|
_initializerDefineProperty(_this, "editorView", _descriptor2, _assertThisInitialized(_this));
|
|
@@ -282,6 +284,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
282
284
|
_this.options = options;
|
|
283
285
|
_this.viewManager = viewManager;
|
|
284
286
|
_this.className = _this.className + ' prompt';
|
|
287
|
+
_this.codeEditorManager = codeEditorManager;
|
|
285
288
|
_this.outputs = (_options$cell = options.cell) === null || _options$cell === void 0 ? void 0 : _options$cell.outputs;
|
|
286
289
|
_this.libroViewTracker = libroViewTracker;
|
|
287
290
|
|
|
@@ -321,6 +324,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
321
324
|
});
|
|
322
325
|
return _this;
|
|
323
326
|
}
|
|
327
|
+
LibroPromptCellView = inject(CodeEditorManager)(LibroPromptCellView, undefined, 4) || LibroPromptCellView;
|
|
324
328
|
LibroPromptCellView = inject(LibroViewTracker)(LibroPromptCellView, undefined, 3) || LibroPromptCellView;
|
|
325
329
|
LibroPromptCellView = inject(ViewManager)(LibroPromptCellView, undefined, 2) || LibroPromptCellView;
|
|
326
330
|
LibroPromptCellView = inject(CellService)(LibroPromptCellView, undefined, 1) || LibroPromptCellView;
|
|
@@ -367,15 +371,8 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
367
371
|
}, {
|
|
368
372
|
key: "getEditorOption",
|
|
369
373
|
value: function getEditorOption() {
|
|
370
|
-
var _this3 = this;
|
|
371
374
|
var option = {
|
|
372
|
-
|
|
373
|
-
return codeMirrorEditorFactory(_objectSpread(_objectSpread({}, editorOption), {}, {
|
|
374
|
-
config: _objectSpread(_objectSpread({}, editorOption.config), {
|
|
375
|
-
readOnly: _this3.parent.model.readOnly
|
|
376
|
-
})
|
|
377
|
-
}));
|
|
378
|
-
},
|
|
375
|
+
editorHostId: this.parent.id + this.id,
|
|
379
376
|
model: this.model,
|
|
380
377
|
config: {
|
|
381
378
|
readOnly: this.parent.model.readOnly,
|
|
@@ -388,28 +385,31 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
388
385
|
key: "createEditor",
|
|
389
386
|
value: function () {
|
|
390
387
|
var _createEditor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
391
|
-
var
|
|
392
|
-
var option;
|
|
388
|
+
var option, editorView;
|
|
393
389
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
394
390
|
while (1) switch (_context5.prev = _context5.next) {
|
|
395
391
|
case 0:
|
|
396
392
|
option = this.getEditorOption();
|
|
397
|
-
this.
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
393
|
+
this.editorStatus = EditorStatus.LOADING;
|
|
394
|
+
|
|
395
|
+
// 防止虚拟滚动中编辑器被频繁创建
|
|
396
|
+
if (!this.editorView) {
|
|
397
|
+
_context5.next = 5;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
this.editorStatus = EditorStatus.LOADED;
|
|
401
|
+
return _context5.abrupt("return");
|
|
402
|
+
case 5:
|
|
403
|
+
_context5.next = 7;
|
|
404
|
+
return this.codeEditorManager.getOrCreateEditorView(option);
|
|
405
|
+
case 7:
|
|
406
|
+
editorView = _context5.sent;
|
|
407
|
+
this.editorView = editorView;
|
|
408
|
+
this.editorViewReadyDeferred.resolve();
|
|
409
|
+
this.editorStatus = EditorStatus.LOADED;
|
|
410
|
+
_context5.next = 13;
|
|
411
|
+
return this.afterEditorReady();
|
|
412
|
+
case 13:
|
|
413
413
|
case "end":
|
|
414
414
|
return _context5.stop();
|
|
415
415
|
}
|
|
@@ -420,6 +420,33 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
420
420
|
}
|
|
421
421
|
return createEditor;
|
|
422
422
|
}()
|
|
423
|
+
}, {
|
|
424
|
+
key: "afterEditorReady",
|
|
425
|
+
value: function () {
|
|
426
|
+
var _afterEditorReady = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
427
|
+
var _this3 = this,
|
|
428
|
+
_this$editorView9;
|
|
429
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
430
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
431
|
+
case 0:
|
|
432
|
+
watch(this.parent.model, 'readOnly', function () {
|
|
433
|
+
var _this3$editorView;
|
|
434
|
+
(_this3$editorView = _this3.editorView) === null || _this3$editorView === void 0 || (_this3$editorView = _this3$editorView.editor) === null || _this3$editorView === void 0 || _this3$editorView.setOption('readOnly', getOrigin(_this3.parent.model.readOnly));
|
|
435
|
+
});
|
|
436
|
+
(_this$editorView9 = this.editorView) === null || _this$editorView9 === void 0 || _this$editorView9.onModalChange(function (val) {
|
|
437
|
+
return _this3.hasModal = val;
|
|
438
|
+
});
|
|
439
|
+
case 2:
|
|
440
|
+
case "end":
|
|
441
|
+
return _context6.stop();
|
|
442
|
+
}
|
|
443
|
+
}, _callee6, this);
|
|
444
|
+
}));
|
|
445
|
+
function afterEditorReady() {
|
|
446
|
+
return _afterEditorReady.apply(this, arguments);
|
|
447
|
+
}
|
|
448
|
+
return afterEditorReady;
|
|
449
|
+
}()
|
|
423
450
|
}, {
|
|
424
451
|
key: "shouldEnterEditorMode",
|
|
425
452
|
value: function shouldEnterEditorMode(e) {
|
|
@@ -429,18 +456,18 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
429
456
|
}, {
|
|
430
457
|
key: "run",
|
|
431
458
|
value: function () {
|
|
432
|
-
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
433
|
-
var
|
|
459
|
+
var _run = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
460
|
+
var _this4 = this;
|
|
434
461
|
var libroModel, kernelConnection, promptObj, cellContent, future, startTimeStr, msgPromise, endTimeStr;
|
|
435
|
-
return _regeneratorRuntime().wrap(function
|
|
436
|
-
while (1) switch (
|
|
462
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
463
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
437
464
|
case 0:
|
|
438
465
|
libroModel = this.parent.model;
|
|
439
466
|
if (!(!libroModel || !(libroModel instanceof LibroJupyterModel) || !libroModel.kernelConnection || libroModel.kernelConnection.isDisposed)) {
|
|
440
|
-
|
|
467
|
+
_context7.next = 3;
|
|
441
468
|
break;
|
|
442
469
|
}
|
|
443
|
-
return
|
|
470
|
+
return _context7.abrupt("return", false);
|
|
444
471
|
case 3:
|
|
445
472
|
kernelConnection = getOrigin(libroModel.kernelConnection); // const cellContent = '%prompt ' + toBase64(this.model.value) + ',model:';
|
|
446
473
|
promptObj = {
|
|
@@ -448,7 +475,7 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
448
475
|
prompt: this.model.value
|
|
449
476
|
};
|
|
450
477
|
cellContent = "%%prompt \n".concat(JSON.stringify(promptObj));
|
|
451
|
-
|
|
478
|
+
_context7.prev = 6;
|
|
452
479
|
// Promise.resolve().then(() => {
|
|
453
480
|
this.clearExecution();
|
|
454
481
|
// });
|
|
@@ -465,23 +492,23 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
465
492
|
|
|
466
493
|
// Handle iopub messages
|
|
467
494
|
future.onIOPub = function (msg) {
|
|
468
|
-
|
|
495
|
+
_this4.model.msgChangeEmitter.fire(msg);
|
|
469
496
|
if (msg.header.msg_type === 'execute_input') {
|
|
470
|
-
|
|
497
|
+
_this4.model.kernelExecuting = true;
|
|
471
498
|
startTimeStr = msg.header.date;
|
|
472
|
-
var meta =
|
|
499
|
+
var meta = _this4.model.metadata.execution;
|
|
473
500
|
if (meta) {
|
|
474
501
|
meta['shell.execute_reply.started'] = startTimeStr;
|
|
475
502
|
}
|
|
476
503
|
}
|
|
477
504
|
if (msg.header.msg_type === 'error') {
|
|
478
|
-
|
|
505
|
+
_this4.model.hasExecutedError = true;
|
|
479
506
|
}
|
|
480
507
|
};
|
|
481
|
-
|
|
508
|
+
_context7.next = 15;
|
|
482
509
|
return future.done;
|
|
483
510
|
case 15:
|
|
484
|
-
msgPromise =
|
|
511
|
+
msgPromise = _context7.sent;
|
|
485
512
|
this.model.executing = false;
|
|
486
513
|
this.model.kernelExecuting = false;
|
|
487
514
|
this.model.hasExecutedSuccess = !this.model.hasExecutedError;
|
|
@@ -490,36 +517,36 @@ export var LibroPromptCellView = (_dec = transient(), _dec2 = view('prompt-edito
|
|
|
490
517
|
this.model.metadata['execution']['shell.execute_reply.started'] = startTimeStr;
|
|
491
518
|
this.model.metadata['execution']['shell.execute_reply.end'] = endTimeStr;
|
|
492
519
|
if (msgPromise) {
|
|
493
|
-
|
|
520
|
+
_context7.next = 25;
|
|
494
521
|
break;
|
|
495
522
|
}
|
|
496
|
-
return
|
|
523
|
+
return _context7.abrupt("return", true);
|
|
497
524
|
case 25:
|
|
498
525
|
if (!(msgPromise.content.status === 'ok')) {
|
|
499
|
-
|
|
526
|
+
_context7.next = 29;
|
|
500
527
|
break;
|
|
501
528
|
}
|
|
502
|
-
return
|
|
529
|
+
return _context7.abrupt("return", true);
|
|
503
530
|
case 29:
|
|
504
531
|
throw new KernelError(msgPromise.content);
|
|
505
532
|
case 30:
|
|
506
|
-
|
|
533
|
+
_context7.next = 37;
|
|
507
534
|
break;
|
|
508
535
|
case 32:
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (!
|
|
512
|
-
|
|
536
|
+
_context7.prev = 32;
|
|
537
|
+
_context7.t0 = _context7["catch"](6);
|
|
538
|
+
if (!_context7.t0.message.startsWith('Canceled')) {
|
|
539
|
+
_context7.next = 36;
|
|
513
540
|
break;
|
|
514
541
|
}
|
|
515
|
-
return
|
|
542
|
+
return _context7.abrupt("return", false);
|
|
516
543
|
case 36:
|
|
517
|
-
throw
|
|
544
|
+
throw _context7.t0;
|
|
518
545
|
case 37:
|
|
519
546
|
case "end":
|
|
520
|
-
return
|
|
547
|
+
return _context7.stop();
|
|
521
548
|
}
|
|
522
|
-
},
|
|
549
|
+
}, _callee7, this, [[6, 32]]);
|
|
523
550
|
}));
|
|
524
551
|
function run() {
|
|
525
552
|
return _run.apply(this, arguments);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-output-render.d.ts","sourceRoot":"","sources":["../src/prompt-output-render.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt-output-render.d.ts","sourceRoot":"","sources":["../src/prompt-output-render.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,OAAO,KAAmB,MAAM,OAAO,CAAC;AAcxC,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,KAAK,EAAE,cAAc,CAAC;CACvB,CAmGA,CAAC"}
|
|
@@ -2,14 +2,22 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
2
2
|
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; }
|
|
3
3
|
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); } }
|
|
4
4
|
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); }); }; }
|
|
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 { copy2clipboard } from '@difizen/libro-common';
|
|
5
12
|
import { concatMultilineString } from '@difizen/libro-common';
|
|
6
13
|
import { NotebookCommands } from '@difizen/libro-jupyter';
|
|
7
14
|
import { CommandRegistry, useInject } from '@difizen/mana-app';
|
|
8
|
-
import React from 'react';
|
|
15
|
+
import React, { useState } from 'react';
|
|
9
16
|
import { v4 } from 'uuid';
|
|
10
17
|
import { LibroLLMRenderMemo } from "./libro-llm-render.js";
|
|
11
18
|
import { getPythonCode } from "./prompt-cell-utils.js";
|
|
12
19
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
21
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
22
|
var getModelOutput = function getModelOutput(data) {
|
|
15
23
|
if (typeof data === 'string' || Array.isArray(data)) {
|
|
@@ -22,6 +30,10 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
22
30
|
var model = props.model;
|
|
23
31
|
var renderHTMLRef = /*#__PURE__*/React.createRef();
|
|
24
32
|
var commandRegistry = useInject(CommandRegistry);
|
|
33
|
+
var _useState = useState(''),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
selection = _useState2[0],
|
|
36
|
+
setSelection = _useState2[1];
|
|
25
37
|
if (!model.data['application/vnd.libro.prompt+json']) {
|
|
26
38
|
return null;
|
|
27
39
|
}
|
|
@@ -32,7 +44,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
32
44
|
}
|
|
33
45
|
var modelData = getModelOutput(data);
|
|
34
46
|
var sourceArr = getPythonCode(modelData !== null && modelData !== void 0 ? modelData : '');
|
|
35
|
-
var
|
|
47
|
+
var insertAndRun = /*#__PURE__*/function () {
|
|
36
48
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
37
49
|
var libro, insertIndex;
|
|
38
50
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
@@ -45,7 +57,6 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
45
57
|
_context3.next = 4;
|
|
46
58
|
return Promise.all(sourceArr.map( /*#__PURE__*/function () {
|
|
47
59
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value, index) {
|
|
48
|
-
var newView;
|
|
49
60
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
50
61
|
while (1) switch (_context.prev = _context.next) {
|
|
51
62
|
case 0:
|
|
@@ -59,9 +70,6 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
59
70
|
}
|
|
60
71
|
}, insertIndex + index + 1);
|
|
61
72
|
case 2:
|
|
62
|
-
newView = _context.sent;
|
|
63
|
-
return _context.abrupt("return", newView);
|
|
64
|
-
case 4:
|
|
65
73
|
case "end":
|
|
66
74
|
return _context.stop();
|
|
67
75
|
}
|
|
@@ -96,12 +104,97 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
96
104
|
}
|
|
97
105
|
}, _callee3);
|
|
98
106
|
}));
|
|
99
|
-
return function
|
|
107
|
+
return function insertAndRun() {
|
|
100
108
|
return _ref2.apply(this, arguments);
|
|
101
109
|
};
|
|
102
110
|
}();
|
|
111
|
+
var insert = /*#__PURE__*/function () {
|
|
112
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
113
|
+
var libro, insertIndex;
|
|
114
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
115
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
libro = model.cell.parent;
|
|
118
|
+
insertIndex = libro.model.cells.findIndex(function (c) {
|
|
119
|
+
return c.id === model.cell.id;
|
|
120
|
+
});
|
|
121
|
+
_context5.next = 4;
|
|
122
|
+
return Promise.all(sourceArr.map( /*#__PURE__*/function () {
|
|
123
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(value, index) {
|
|
124
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
125
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
_context4.next = 2;
|
|
128
|
+
return libro.addCell({
|
|
129
|
+
id: v4(),
|
|
130
|
+
cell: {
|
|
131
|
+
cell_type: 'code',
|
|
132
|
+
source: value,
|
|
133
|
+
metadata: {}
|
|
134
|
+
}
|
|
135
|
+
}, insertIndex + index + 1);
|
|
136
|
+
case 2:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context4.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee4);
|
|
141
|
+
}));
|
|
142
|
+
return function (_x5, _x6) {
|
|
143
|
+
return _ref6.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
}()));
|
|
146
|
+
case 4:
|
|
147
|
+
case "end":
|
|
148
|
+
return _context5.stop();
|
|
149
|
+
}
|
|
150
|
+
}, _callee5);
|
|
151
|
+
}));
|
|
152
|
+
return function insert() {
|
|
153
|
+
return _ref5.apply(this, arguments);
|
|
154
|
+
};
|
|
155
|
+
}();
|
|
156
|
+
var copy = /*#__PURE__*/function () {
|
|
157
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
158
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
159
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
160
|
+
case 0:
|
|
161
|
+
copy2clipboard(concatMultilineString(sourceArr));
|
|
162
|
+
case 1:
|
|
163
|
+
case "end":
|
|
164
|
+
return _context6.stop();
|
|
165
|
+
}
|
|
166
|
+
}, _callee6);
|
|
167
|
+
}));
|
|
168
|
+
return function copy() {
|
|
169
|
+
return _ref7.apply(this, arguments);
|
|
170
|
+
};
|
|
171
|
+
}();
|
|
172
|
+
var copySelection = /*#__PURE__*/function () {
|
|
173
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
174
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
175
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
176
|
+
case 0:
|
|
177
|
+
copy2clipboard(selection);
|
|
178
|
+
case 1:
|
|
179
|
+
case "end":
|
|
180
|
+
return _context7.stop();
|
|
181
|
+
}
|
|
182
|
+
}, _callee7);
|
|
183
|
+
}));
|
|
184
|
+
return function copySelection() {
|
|
185
|
+
return _ref8.apply(this, arguments);
|
|
186
|
+
};
|
|
187
|
+
}();
|
|
188
|
+
var updateSelection = function updateSelection() {
|
|
189
|
+
var _document$getSelectio;
|
|
190
|
+
var tmpSelection = (_document$getSelectio = document.getSelection()) === null || _document$getSelectio === void 0 ? void 0 : _document$getSelectio.toString();
|
|
191
|
+
if (tmpSelection) {
|
|
192
|
+
setSelection(tmpSelection);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
103
195
|
return /*#__PURE__*/_jsxs("div", {
|
|
104
196
|
className: "libro-prompt-output-render-container",
|
|
197
|
+
onMouseUp: updateSelection,
|
|
105
198
|
children: [/*#__PURE__*/_jsx("div", {
|
|
106
199
|
className: "prompt-output-render",
|
|
107
200
|
ref: renderHTMLRef,
|
|
@@ -111,10 +204,24 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
111
204
|
data: modelData
|
|
112
205
|
})
|
|
113
206
|
})
|
|
114
|
-
}), sourceArr.length > 0 && /*#__PURE__*/
|
|
115
|
-
|
|
207
|
+
}), sourceArr.length > 0 && /*#__PURE__*/_jsxs(_Fragment, {
|
|
208
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
209
|
+
onClick: insertAndRun,
|
|
210
|
+
className: "libro-prompt-output-btn",
|
|
211
|
+
children: "\u63D2\u5165\u5E76\u8FD0\u884C"
|
|
212
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
213
|
+
onClick: insert,
|
|
214
|
+
className: "libro-prompt-output-btn",
|
|
215
|
+
children: "\u63D2\u5165\u4EE3\u7801"
|
|
216
|
+
})]
|
|
217
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
218
|
+
onClick: copy,
|
|
219
|
+
className: "libro-prompt-output-btn",
|
|
220
|
+
children: "\u590D\u5236\u4EE3\u7801"
|
|
221
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
222
|
+
onClick: copySelection,
|
|
116
223
|
className: "libro-prompt-output-btn",
|
|
117
|
-
children: "\
|
|
224
|
+
children: "\u590D\u5236\u9009\u4E2D\u5185\u5BB9"
|
|
118
225
|
})]
|
|
119
226
|
});
|
|
120
227
|
};
|
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.2",
|
|
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.2",
|
|
36
|
+
"@difizen/libro-jupyter": "^0.1.2",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.1.2",
|
|
38
|
+
"@difizen/libro-codemirror": "^0.1.2",
|
|
39
|
+
"@difizen/libro-common": "^0.1.2",
|
|
40
|
+
"@difizen/libro-core": "^0.1.2",
|
|
41
41
|
"@difizen/mana-app": "latest",
|
|
42
42
|
"highlight.js": "^11.8.0",
|
|
43
43
|
"marked": "^5.1.1",
|
package/src/index.less
CHANGED
package/src/libro-llm-render.tsx
CHANGED
|
@@ -20,6 +20,7 @@ marked.use(
|
|
|
20
20
|
return hljs.highlight(code, { language }).value;
|
|
21
21
|
},
|
|
22
22
|
}),
|
|
23
|
+
{ headerIds: false, mangle: false },
|
|
23
24
|
);
|
|
24
25
|
|
|
25
26
|
export const LibroLLMRender: React.FC<{ data: string }> = (props: { data: string }) => {
|
|
@@ -50,7 +51,7 @@ export const LibroLLMRender: React.FC<{ data: string }> = (props: { data: string
|
|
|
50
51
|
hljsElement.parentNode?.insertBefore(newElement, hljsElement.nextSibling);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
}, [data
|
|
54
|
+
}, [data]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
54
55
|
|
|
55
56
|
return (
|
|
56
57
|
<div className="libro-llm-output-render" ref={renderMarkdownRef}>
|
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 { 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';
|
|
7
8
|
import { LibroPromptOutputArea } from './prompt-cell-output-area.js';
|
|
@@ -16,7 +17,7 @@ export const LibroPromptCellModule = ManaModule.create()
|
|
|
16
17
|
LibroPromptCellModel,
|
|
17
18
|
LibroPromptOutputArea,
|
|
18
19
|
LibroPromptOutputMimeTypeContribution,
|
|
19
|
-
|
|
20
|
+
LibroPromptCellCommandContribution,
|
|
20
21
|
{
|
|
21
22
|
token: LibroPromptCellModelFactory,
|
|
22
23
|
useFactory: (ctx) => {
|
package/src/prompt-cell-view.tsx
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { CodeEditorManager } from '@difizen/libro-code-editor';
|
|
2
|
+
import type {
|
|
3
|
+
CodeEditorViewOptions,
|
|
4
|
+
IRange,
|
|
5
|
+
CodeEditorView,
|
|
6
|
+
} from '@difizen/libro-code-editor';
|
|
7
|
+
|
|
4
8
|
import type { ICodeCell, IOutput } from '@difizen/libro-common';
|
|
5
9
|
import { isOutput } from '@difizen/libro-common';
|
|
6
10
|
import type {
|
|
@@ -13,6 +17,7 @@ import {
|
|
|
13
17
|
LibroExecutableCellView,
|
|
14
18
|
LibroOutputArea,
|
|
15
19
|
LibroViewTracker,
|
|
20
|
+
EditorStatus,
|
|
16
21
|
} from '@difizen/libro-core';
|
|
17
22
|
import type { ExecutionMeta, KernelMessage } from '@difizen/libro-jupyter';
|
|
18
23
|
import { KernelError, LibroJupyterModel } from '@difizen/libro-jupyter';
|
|
@@ -67,9 +72,10 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
67
72
|
instance.handleQueryResponse,
|
|
68
73
|
)
|
|
69
74
|
.then(() => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
instance.
|
|
75
|
+
const len = instance.modelSelection.length;
|
|
76
|
+
if (len > 0) {
|
|
77
|
+
setSelectedModel(instance.modelSelection[len - 1].label);
|
|
78
|
+
instance.model.modelType = instance.modelSelection[len - 1].label;
|
|
73
79
|
return;
|
|
74
80
|
}
|
|
75
81
|
return;
|
|
@@ -77,7 +83,8 @@ const PropmtEditorViewComponent = React.forwardRef<HTMLDivElement>(
|
|
|
77
83
|
.catch(() => {
|
|
78
84
|
//
|
|
79
85
|
});
|
|
80
|
-
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
87
|
+
}, []);
|
|
81
88
|
|
|
82
89
|
const handleChange = (value: string) => {
|
|
83
90
|
instance.model.modelType = value;
|
|
@@ -126,6 +133,8 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
126
133
|
|
|
127
134
|
viewManager: ViewManager;
|
|
128
135
|
|
|
136
|
+
codeEditorManager: CodeEditorManager;
|
|
137
|
+
|
|
129
138
|
outputs: IOutput[];
|
|
130
139
|
|
|
131
140
|
libroViewTracker: LibroViewTracker;
|
|
@@ -149,11 +158,13 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
149
158
|
@inject(CellService) cellService: CellService,
|
|
150
159
|
@inject(ViewManager) viewManager: ViewManager,
|
|
151
160
|
@inject(LibroViewTracker) libroViewTracker: LibroViewTracker,
|
|
161
|
+
@inject(CodeEditorManager) codeEditorManager: CodeEditorManager,
|
|
152
162
|
) {
|
|
153
163
|
super(options, cellService);
|
|
154
164
|
this.options = options;
|
|
155
165
|
this.viewManager = viewManager;
|
|
156
166
|
this.className = this.className + ' prompt';
|
|
167
|
+
this.codeEditorManager = codeEditorManager;
|
|
157
168
|
|
|
158
169
|
this.outputs = options.cell?.outputs as IOutput[];
|
|
159
170
|
this.libroViewTracker = libroViewTracker;
|
|
@@ -206,14 +217,7 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
206
217
|
|
|
207
218
|
protected getEditorOption(): CodeEditorViewOptions {
|
|
208
219
|
const option: CodeEditorViewOptions = {
|
|
209
|
-
|
|
210
|
-
codeMirrorEditorFactory({
|
|
211
|
-
...editorOption,
|
|
212
|
-
config: {
|
|
213
|
-
...editorOption.config,
|
|
214
|
-
...{ readOnly: this.parent.model.readOnly },
|
|
215
|
-
},
|
|
216
|
-
}),
|
|
220
|
+
editorHostId: this.parent.id + this.id,
|
|
217
221
|
model: this.model,
|
|
218
222
|
config: {
|
|
219
223
|
readOnly: this.parent.model.readOnly,
|
|
@@ -225,22 +229,31 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
225
229
|
|
|
226
230
|
async createEditor() {
|
|
227
231
|
const option = this.getEditorOption();
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
232
|
+
|
|
233
|
+
this.editorStatus = EditorStatus.LOADING;
|
|
234
|
+
|
|
235
|
+
// 防止虚拟滚动中编辑器被频繁创建
|
|
236
|
+
if (this.editorView) {
|
|
237
|
+
this.editorStatus = EditorStatus.LOADED;
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const editorView = await this.codeEditorManager.getOrCreateEditorView(option);
|
|
241
|
+
|
|
242
|
+
this.editorView = editorView;
|
|
243
|
+
this.editorViewReadyDeferred.resolve();
|
|
244
|
+
this.editorStatus = EditorStatus.LOADED;
|
|
245
|
+
|
|
246
|
+
await this.afterEditorReady();
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
protected async afterEditorReady() {
|
|
250
|
+
watch(this.parent.model, 'readOnly', () => {
|
|
251
|
+
this.editorView?.editor?.setOption(
|
|
252
|
+
'readOnly',
|
|
253
|
+
getOrigin(this.parent.model.readOnly),
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
this.editorView?.onModalChange((val) => (this.hasModal = val));
|
|
244
257
|
}
|
|
245
258
|
|
|
246
259
|
override shouldEnterEditorMode(e: React.FocusEvent<HTMLElement>) {
|
|
@@ -300,11 +313,11 @@ export class LibroPromptCellView extends LibroExecutableCellView {
|
|
|
300
313
|
this.outputArea.clear();
|
|
301
314
|
};
|
|
302
315
|
|
|
303
|
-
|
|
316
|
+
getSelections = (): [] => {
|
|
304
317
|
return this.editor?.getSelections() as [];
|
|
305
318
|
};
|
|
306
319
|
|
|
307
|
-
|
|
320
|
+
getSelectionsOffsetAt = (selection: IRange) => {
|
|
308
321
|
const isSelect = selection;
|
|
309
322
|
const start = this.editor?.getOffsetAt(isSelect.start) ?? 0;
|
|
310
323
|
const end = this.editor?.getOffsetAt(isSelect.end) ?? 0;
|
|
@@ -3,11 +3,12 @@ import type {
|
|
|
3
3
|
MultilineString,
|
|
4
4
|
PartialJSONObject,
|
|
5
5
|
} from '@difizen/libro-common';
|
|
6
|
+
import { copy2clipboard } from '@difizen/libro-common';
|
|
6
7
|
import { concatMultilineString } from '@difizen/libro-common';
|
|
7
8
|
import type { BaseOutputView } from '@difizen/libro-jupyter';
|
|
8
9
|
import { NotebookCommands } from '@difizen/libro-jupyter';
|
|
9
10
|
import { CommandRegistry, useInject } from '@difizen/mana-app';
|
|
10
|
-
import React from 'react';
|
|
11
|
+
import React, { useState } from 'react';
|
|
11
12
|
import { v4 } from 'uuid';
|
|
12
13
|
|
|
13
14
|
import { LibroLLMRenderMemo } from './libro-llm-render.js';
|
|
@@ -27,6 +28,7 @@ export const PromptOutputRender: React.FC<{
|
|
|
27
28
|
const { model } = props;
|
|
28
29
|
const renderHTMLRef = React.createRef<HTMLDivElement>();
|
|
29
30
|
const commandRegistry = useInject(CommandRegistry);
|
|
31
|
+
const [selection, setSelection] = useState('');
|
|
30
32
|
|
|
31
33
|
if (!model.data['application/vnd.libro.prompt+json']) {
|
|
32
34
|
return null;
|
|
@@ -39,20 +41,19 @@ export const PromptOutputRender: React.FC<{
|
|
|
39
41
|
}
|
|
40
42
|
const modelData = getModelOutput(data);
|
|
41
43
|
const sourceArr = getPythonCode(modelData ?? '');
|
|
42
|
-
const
|
|
44
|
+
const insertAndRun = async () => {
|
|
43
45
|
const libro = model.cell.parent;
|
|
44
46
|
const insertIndex = libro.model.cells.findIndex((c) => c.id === model.cell.id);
|
|
45
47
|
|
|
46
48
|
await Promise.all(
|
|
47
49
|
sourceArr.map(async (value, index) => {
|
|
48
|
-
|
|
50
|
+
await libro.addCell(
|
|
49
51
|
{
|
|
50
52
|
id: v4(),
|
|
51
53
|
cell: { cell_type: 'code', source: value, metadata: {} },
|
|
52
54
|
},
|
|
53
55
|
insertIndex + index + 1,
|
|
54
56
|
);
|
|
55
|
-
return newView;
|
|
56
57
|
}),
|
|
57
58
|
);
|
|
58
59
|
|
|
@@ -66,18 +67,60 @@ export const PromptOutputRender: React.FC<{
|
|
|
66
67
|
}),
|
|
67
68
|
);
|
|
68
69
|
};
|
|
70
|
+
const insert = async () => {
|
|
71
|
+
const libro = model.cell.parent;
|
|
72
|
+
const insertIndex = libro.model.cells.findIndex((c) => c.id === model.cell.id);
|
|
73
|
+
await Promise.all(
|
|
74
|
+
sourceArr.map(async (value, index) => {
|
|
75
|
+
await libro.addCell(
|
|
76
|
+
{
|
|
77
|
+
id: v4(),
|
|
78
|
+
cell: { cell_type: 'code', source: value, metadata: {} },
|
|
79
|
+
},
|
|
80
|
+
insertIndex + index + 1,
|
|
81
|
+
);
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const copy = async () => {
|
|
87
|
+
copy2clipboard(concatMultilineString(sourceArr));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const copySelection = async () => {
|
|
91
|
+
copy2clipboard(selection);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const updateSelection = () => {
|
|
95
|
+
const tmpSelection = document.getSelection()?.toString();
|
|
96
|
+
if (tmpSelection) {
|
|
97
|
+
setSelection(tmpSelection);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
69
101
|
return (
|
|
70
|
-
<div className="libro-prompt-output-render-container">
|
|
102
|
+
<div className="libro-prompt-output-render-container" onMouseUp={updateSelection}>
|
|
71
103
|
<div className="prompt-output-render" ref={renderHTMLRef}>
|
|
72
104
|
<div className="libro-prompt-output-llm-render">
|
|
73
105
|
<LibroLLMRenderMemo data={modelData} />
|
|
74
106
|
</div>
|
|
75
107
|
</div>
|
|
76
108
|
{sourceArr.length > 0 && (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
109
|
+
<>
|
|
110
|
+
<span onClick={insertAndRun} className="libro-prompt-output-btn">
|
|
111
|
+
插入并运行
|
|
112
|
+
</span>
|
|
113
|
+
<span onClick={insert} className="libro-prompt-output-btn">
|
|
114
|
+
插入代码
|
|
115
|
+
</span>
|
|
116
|
+
</>
|
|
80
117
|
)}
|
|
118
|
+
<span onClick={copy} className="libro-prompt-output-btn">
|
|
119
|
+
复制代码
|
|
120
|
+
</span>
|
|
121
|
+
<span onClick={copySelection} className="libro-prompt-output-btn">
|
|
122
|
+
复制选中内容
|
|
123
|
+
</span>
|
|
81
124
|
</div>
|
|
82
125
|
);
|
|
83
126
|
};
|