@difizen/libro-prompt-cell 0.1.13 → 0.1.15
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/README.md +7 -0
- package/es/index.less +6 -0
- package/es/input-handler/chat-record-input.d.ts +12 -0
- package/es/input-handler/chat-record-input.d.ts.map +1 -0
- package/es/input-handler/chat-record-input.js +92 -0
- package/es/input-handler/index.d.ts +3 -0
- package/es/input-handler/index.d.ts.map +1 -0
- package/es/input-handler/index.js +2 -0
- package/es/input-handler/index.less +91 -0
- package/es/input-handler/variable-name-input.d.ts +18 -0
- package/es/input-handler/variable-name-input.d.ts.map +1 -0
- package/es/input-handler/variable-name-input.js +120 -0
- package/es/libro-formatter-prompt-magic-contribution.d.ts +9 -0
- package/es/libro-formatter-prompt-magic-contribution.d.ts.map +1 -1
- package/es/libro-formatter-prompt-magic-contribution.js +12 -3
- package/es/module.js +2 -2
- package/es/prompt-cell-model.d.ts +16 -0
- package/es/prompt-cell-model.d.ts.map +1 -1
- package/es/prompt-cell-model.js +49 -13
- package/es/prompt-cell-script.d.ts +3 -2
- package/es/prompt-cell-script.d.ts.map +1 -1
- package/es/prompt-cell-script.js +13 -4
- package/es/prompt-cell-view.d.ts +33 -13
- package/es/prompt-cell-view.d.ts.map +1 -1
- package/es/prompt-cell-view.js +326 -181
- package/es/prompt-output-render.js +15 -16
- package/package.json +11 -7
- package/src/index.less +6 -0
- package/src/input-handler/chat-record-input.tsx +93 -0
- package/src/input-handler/index.less +91 -0
- package/src/input-handler/index.ts +2 -0
- package/src/input-handler/variable-name-input.tsx +121 -0
- package/src/libro-formatter-prompt-magic-contribution.ts +13 -2
- package/src/module.ts +2 -2
- package/src/prompt-cell-model.ts +26 -0
- package/src/prompt-cell-script.ts +8 -3
- package/src/prompt-cell-view.tsx +233 -92
- package/src/prompt-output-render.tsx +1 -1
- package/es/prompt-cell-output-area.d.ts +0 -14
- package/es/prompt-cell-output-area.d.ts.map +0 -1
- package/es/prompt-cell-output-area.js +0 -74
- package/src/prompt-cell-output-area.tsx +0 -59
|
@@ -37,15 +37,14 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
37
37
|
if (!model.data['application/vnd.libro.prompt+json']) {
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
|
-
var
|
|
41
|
-
data = _ref.data;
|
|
40
|
+
var data = model.data['application/vnd.libro.prompt+json'];
|
|
42
41
|
if (!data) {
|
|
43
42
|
return null;
|
|
44
43
|
}
|
|
45
44
|
var modelData = getModelOutput(data);
|
|
46
45
|
var sourceArr = getPythonCode(modelData !== null && modelData !== void 0 ? modelData : '');
|
|
47
46
|
var insertAndRun = /*#__PURE__*/function () {
|
|
48
|
-
var
|
|
47
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
49
48
|
var libro, insertIndex;
|
|
50
49
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
51
50
|
while (1) switch (_context3.prev = _context3.next) {
|
|
@@ -56,7 +55,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
56
55
|
});
|
|
57
56
|
_context3.next = 4;
|
|
58
57
|
return Promise.all(sourceArr.map( /*#__PURE__*/function () {
|
|
59
|
-
var
|
|
58
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(value, index) {
|
|
60
59
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
61
60
|
while (1) switch (_context.prev = _context.next) {
|
|
62
61
|
case 0:
|
|
@@ -76,13 +75,13 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
76
75
|
}, _callee);
|
|
77
76
|
}));
|
|
78
77
|
return function (_x, _x2) {
|
|
79
|
-
return
|
|
78
|
+
return _ref2.apply(this, arguments);
|
|
80
79
|
};
|
|
81
80
|
}()));
|
|
82
81
|
case 4:
|
|
83
82
|
_context3.next = 6;
|
|
84
83
|
return Promise.all(sourceArr.map( /*#__PURE__*/function () {
|
|
85
|
-
var
|
|
84
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_, index) {
|
|
86
85
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
87
86
|
while (1) switch (_context2.prev = _context2.next) {
|
|
88
87
|
case 0:
|
|
@@ -95,7 +94,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
95
94
|
}, _callee2);
|
|
96
95
|
}));
|
|
97
96
|
return function (_x3, _x4) {
|
|
98
|
-
return
|
|
97
|
+
return _ref3.apply(this, arguments);
|
|
99
98
|
};
|
|
100
99
|
}()));
|
|
101
100
|
case 6:
|
|
@@ -105,11 +104,11 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
105
104
|
}, _callee3);
|
|
106
105
|
}));
|
|
107
106
|
return function insertAndRun() {
|
|
108
|
-
return
|
|
107
|
+
return _ref.apply(this, arguments);
|
|
109
108
|
};
|
|
110
109
|
}();
|
|
111
110
|
var insert = /*#__PURE__*/function () {
|
|
112
|
-
var
|
|
111
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
113
112
|
var libro, insertIndex;
|
|
114
113
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
115
114
|
while (1) switch (_context5.prev = _context5.next) {
|
|
@@ -120,7 +119,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
120
119
|
});
|
|
121
120
|
_context5.next = 4;
|
|
122
121
|
return Promise.all(sourceArr.map( /*#__PURE__*/function () {
|
|
123
|
-
var
|
|
122
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(value, index) {
|
|
124
123
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
125
124
|
while (1) switch (_context4.prev = _context4.next) {
|
|
126
125
|
case 0:
|
|
@@ -140,7 +139,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
140
139
|
}, _callee4);
|
|
141
140
|
}));
|
|
142
141
|
return function (_x5, _x6) {
|
|
143
|
-
return
|
|
142
|
+
return _ref5.apply(this, arguments);
|
|
144
143
|
};
|
|
145
144
|
}()));
|
|
146
145
|
case 4:
|
|
@@ -150,11 +149,11 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
150
149
|
}, _callee5);
|
|
151
150
|
}));
|
|
152
151
|
return function insert() {
|
|
153
|
-
return
|
|
152
|
+
return _ref4.apply(this, arguments);
|
|
154
153
|
};
|
|
155
154
|
}();
|
|
156
155
|
var copy = /*#__PURE__*/function () {
|
|
157
|
-
var
|
|
156
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
158
157
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
159
158
|
while (1) switch (_context6.prev = _context6.next) {
|
|
160
159
|
case 0:
|
|
@@ -166,11 +165,11 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
166
165
|
}, _callee6);
|
|
167
166
|
}));
|
|
168
167
|
return function copy() {
|
|
169
|
-
return
|
|
168
|
+
return _ref6.apply(this, arguments);
|
|
170
169
|
};
|
|
171
170
|
}();
|
|
172
171
|
var copySelection = /*#__PURE__*/function () {
|
|
173
|
-
var
|
|
172
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
174
173
|
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
175
174
|
while (1) switch (_context7.prev = _context7.next) {
|
|
176
175
|
case 0:
|
|
@@ -182,7 +181,7 @@ export var PromptOutputRender = function PromptOutputRender(props) {
|
|
|
182
181
|
}, _callee7);
|
|
183
182
|
}));
|
|
184
183
|
return function copySelection() {
|
|
185
|
-
return
|
|
184
|
+
return _ref7.apply(this, arguments);
|
|
186
185
|
};
|
|
187
186
|
}();
|
|
188
187
|
var updateSelection = function updateSelection() {
|
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.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,18 +32,22 @@
|
|
|
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.15",
|
|
36
|
+
"@difizen/libro-jupyter": "^0.1.15",
|
|
37
|
+
"@difizen/libro-rendermime": "^0.1.15",
|
|
38
|
+
"@difizen/libro-codemirror": "^0.1.15",
|
|
39
|
+
"@difizen/libro-common": "^0.1.15",
|
|
40
|
+
"@difizen/libro-core": "^0.1.15",
|
|
41
|
+
"@ant-design/icons": "^5.1.0",
|
|
42
|
+
"@difizen/mana-l10n": "latest",
|
|
41
43
|
"@difizen/mana-app": "latest",
|
|
44
|
+
"classnames": "^2.3.2",
|
|
42
45
|
"highlight.js": "^11.8.0",
|
|
43
46
|
"marked": "^5.1.1",
|
|
44
47
|
"marked-highlight": "^2.0.1",
|
|
45
48
|
"marked-katex-extension": "^3.0.0",
|
|
46
49
|
"uuid": "^9.0.0",
|
|
50
|
+
"rc-select": "^14.9.2",
|
|
47
51
|
"react-dom": "^18.2.0"
|
|
48
52
|
},
|
|
49
53
|
"peerDependencies": {
|
package/src/index.less
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { EditFilled } from '@ant-design/icons';
|
|
2
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
3
|
+
import { useInject } from '@difizen/mana-app';
|
|
4
|
+
import { Select, Tag } from 'antd';
|
|
5
|
+
import classNames from 'classnames';
|
|
6
|
+
import type { BaseSelectRef } from 'rc-select';
|
|
7
|
+
import type { FC } from 'react';
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
import { useRef } from 'react';
|
|
10
|
+
import { useState } from 'react';
|
|
11
|
+
import './index.less';
|
|
12
|
+
|
|
13
|
+
interface ChatRecordInputProps {
|
|
14
|
+
value: string;
|
|
15
|
+
handleChange: (value: string) => void;
|
|
16
|
+
onFocus?: () => void;
|
|
17
|
+
classname?: string;
|
|
18
|
+
records: string[];
|
|
19
|
+
}
|
|
20
|
+
const ChatRecordInputCls = 'libro-chat-record-input';
|
|
21
|
+
export const ChatRecordInput: FC<ChatRecordInputProps> = (
|
|
22
|
+
props: ChatRecordInputProps,
|
|
23
|
+
) => {
|
|
24
|
+
const { value, records, handleChange, onFocus } = props;
|
|
25
|
+
const selectRef = useRef<BaseSelectRef>(null);
|
|
26
|
+
const [selecting, setSelecting] = useState(false);
|
|
27
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
28
|
+
const contextKey = useInject(LirboContextKey);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (selecting) {
|
|
32
|
+
selectRef.current?.focus();
|
|
33
|
+
}
|
|
34
|
+
}, [selecting]);
|
|
35
|
+
|
|
36
|
+
const handleSelecting = (value: boolean) => {
|
|
37
|
+
if (value) {
|
|
38
|
+
contextKey.disableCommandMode();
|
|
39
|
+
} else {
|
|
40
|
+
contextKey.enableCommandMode();
|
|
41
|
+
}
|
|
42
|
+
setSelecting(value);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div
|
|
47
|
+
className={classNames(ChatRecordInputCls, props.classname)}
|
|
48
|
+
ref={ref}
|
|
49
|
+
tabIndex={0}
|
|
50
|
+
>
|
|
51
|
+
<span className="libro-chat-record-input-label">Chat: </span>
|
|
52
|
+
{selecting ? (
|
|
53
|
+
<Select
|
|
54
|
+
ref={selectRef}
|
|
55
|
+
className="libro-chat-record-input-select"
|
|
56
|
+
size="small"
|
|
57
|
+
mode="tags"
|
|
58
|
+
style={{ width: '100%' }}
|
|
59
|
+
placeholder="选择或输入聊天标识"
|
|
60
|
+
onSelect={handleChange}
|
|
61
|
+
showSearch={false}
|
|
62
|
+
onBlur={() => {
|
|
63
|
+
handleSelecting(false);
|
|
64
|
+
}}
|
|
65
|
+
onFocus={() => {
|
|
66
|
+
if (onFocus) {
|
|
67
|
+
onFocus();
|
|
68
|
+
}
|
|
69
|
+
}}
|
|
70
|
+
options={
|
|
71
|
+
records.map((record) => ({
|
|
72
|
+
label: record,
|
|
73
|
+
value: record,
|
|
74
|
+
})) || []
|
|
75
|
+
}
|
|
76
|
+
/>
|
|
77
|
+
) : (
|
|
78
|
+
<>
|
|
79
|
+
<span className="libro-chat-record-input-value">
|
|
80
|
+
{value ? <Tag>{value}</Tag> : '...'}
|
|
81
|
+
</span>
|
|
82
|
+
<span
|
|
83
|
+
onClick={() => {
|
|
84
|
+
handleSelecting(true);
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
<EditFilled />
|
|
88
|
+
</span>
|
|
89
|
+
</>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.libro-chat-record-input {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
padding: 0 8px;
|
|
5
|
+
|
|
6
|
+
&-select {
|
|
7
|
+
min-width: 180px;
|
|
8
|
+
padding: 0 8px;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
&-value {
|
|
12
|
+
padding-left: 2px;
|
|
13
|
+
|
|
14
|
+
span {
|
|
15
|
+
margin-inline-end: 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&-label {
|
|
20
|
+
padding-left: 16px;
|
|
21
|
+
color: var(--mana-libro-cell-header-title);
|
|
22
|
+
font-size: 14px;
|
|
23
|
+
letter-spacing: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
svg {
|
|
27
|
+
margin-left: 4px;
|
|
28
|
+
color: #bdc0c4 !important;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
|
|
31
|
+
&:hover {
|
|
32
|
+
color: #1590ff !important;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.libro-variable-name-input {
|
|
38
|
+
border-left: 1px solid var(--mana-color-border);
|
|
39
|
+
display: inline-flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
|
|
42
|
+
svg {
|
|
43
|
+
margin-left: 4px;
|
|
44
|
+
color: #bdc0c4 !important;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
|
|
47
|
+
&:hover {
|
|
48
|
+
color: #1590ff !important;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&-value {
|
|
53
|
+
padding-left: 2px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
&-label {
|
|
57
|
+
padding-left: 16px;
|
|
58
|
+
color: var(--mana-libro-cell-header-title);
|
|
59
|
+
font-size: 14px;
|
|
60
|
+
letter-spacing: 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&-input {
|
|
64
|
+
width: 120px;
|
|
65
|
+
height: 32px;
|
|
66
|
+
border: 1px solid #d6d8da;
|
|
67
|
+
border-radius: 6px;
|
|
68
|
+
box-shadow: unset;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&-popover {
|
|
72
|
+
vertical-align: middle;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&-warning-text {
|
|
76
|
+
margin-top: 4px;
|
|
77
|
+
color: #faad14;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
&-actions {
|
|
81
|
+
padding: 2px 0;
|
|
82
|
+
|
|
83
|
+
span + span {
|
|
84
|
+
margin-left: 8px;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
span {
|
|
88
|
+
color: #1890ff;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { EditFilled } from '@ant-design/icons';
|
|
2
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
3
|
+
import { useInject } from '@difizen/mana-app';
|
|
4
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
5
|
+
import { Input, Popover } from 'antd';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import type { FC } from 'react';
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
import { useRef } from 'react';
|
|
10
|
+
import { useCallback, useState } from 'react';
|
|
11
|
+
import './index.less';
|
|
12
|
+
|
|
13
|
+
interface VariableNameInputPopoverContentProps {
|
|
14
|
+
value: string;
|
|
15
|
+
handleVariableNameChange: (variableName: string) => void;
|
|
16
|
+
checkVariableNameAvailable: (variableName: string) => boolean;
|
|
17
|
+
cancel: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const VariableNameInputPopoverContent: FC<
|
|
21
|
+
VariableNameInputPopoverContentProps
|
|
22
|
+
> = (props: VariableNameInputPopoverContentProps) => {
|
|
23
|
+
const { value, handleVariableNameChange, checkVariableNameAvailable, cancel } = props;
|
|
24
|
+
const [variableNameAvailable, setVariableNameAvailable] = useState(true);
|
|
25
|
+
const [variableName, setVariableName] = useState(value);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setVariableName(value);
|
|
29
|
+
}, [value]);
|
|
30
|
+
|
|
31
|
+
const handleValueChange = useCallback(
|
|
32
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
33
|
+
if (checkVariableNameAvailable(e.target.value)) {
|
|
34
|
+
setVariableNameAvailable(false);
|
|
35
|
+
} else {
|
|
36
|
+
setVariableNameAvailable(true);
|
|
37
|
+
}
|
|
38
|
+
setVariableName(e.target.value);
|
|
39
|
+
},
|
|
40
|
+
[checkVariableNameAvailable],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const handValueSave = useCallback(() => {
|
|
44
|
+
handleVariableNameChange(variableName);
|
|
45
|
+
cancel();
|
|
46
|
+
}, [variableName, handleVariableNameChange, cancel]);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<Input
|
|
51
|
+
status={`${variableNameAvailable ? '' : 'warning'}`}
|
|
52
|
+
className="libro-variable-name-input-component"
|
|
53
|
+
onChange={handleValueChange}
|
|
54
|
+
value={variableName}
|
|
55
|
+
/>
|
|
56
|
+
|
|
57
|
+
{!variableNameAvailable && (
|
|
58
|
+
<span className="libro-variable-name-input-warning-text">
|
|
59
|
+
{l10n.t('当前变量名已存在')}
|
|
60
|
+
</span>
|
|
61
|
+
)}
|
|
62
|
+
|
|
63
|
+
<div className="libro-variable-name-input-actions">
|
|
64
|
+
<span onClick={cancel}>{l10n.t('取消')}</span>
|
|
65
|
+
<span onClick={handValueSave}>{l10n.t('保存')}</span>
|
|
66
|
+
</div>
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
interface VariableNameInputProps {
|
|
72
|
+
value: string;
|
|
73
|
+
handleVariableNameChange: (variableName: string) => void;
|
|
74
|
+
checkVariableNameAvailable: (variableName: string) => boolean;
|
|
75
|
+
classname?: string;
|
|
76
|
+
}
|
|
77
|
+
const variableNameInputCls = 'libro-variable-name-input';
|
|
78
|
+
export const VariableNameInput: FC<VariableNameInputProps> = (
|
|
79
|
+
props: VariableNameInputProps,
|
|
80
|
+
) => {
|
|
81
|
+
const { value } = props;
|
|
82
|
+
const [popoverVisible, setPopoverVisible] = useState(false);
|
|
83
|
+
const contextKey = useInject(LirboContextKey);
|
|
84
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
85
|
+
return (
|
|
86
|
+
<div className={classNames(variableNameInputCls, props.classname)} ref={ref}>
|
|
87
|
+
<span className="libro-variable-name-input-label">Save: </span>
|
|
88
|
+
<span className="libro-variable-name-input-value">{value || '...'}</span>
|
|
89
|
+
<span className="libro-variable-name-input-popover">
|
|
90
|
+
<Popover
|
|
91
|
+
content={
|
|
92
|
+
<VariableNameInputPopoverContent
|
|
93
|
+
{...props}
|
|
94
|
+
cancel={() => {
|
|
95
|
+
setPopoverVisible(false);
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
}
|
|
99
|
+
placement="bottomLeft"
|
|
100
|
+
open={popoverVisible}
|
|
101
|
+
onOpenChange={(visible) => {
|
|
102
|
+
if (visible) {
|
|
103
|
+
contextKey.disableCommandMode();
|
|
104
|
+
} else {
|
|
105
|
+
contextKey.enableCommandMode();
|
|
106
|
+
}
|
|
107
|
+
setPopoverVisible(visible);
|
|
108
|
+
}}
|
|
109
|
+
getPopupContainer={() => {
|
|
110
|
+
return ref.current?.getElementsByClassName(
|
|
111
|
+
variableNameInputCls,
|
|
112
|
+
)[0] as HTMLElement;
|
|
113
|
+
}}
|
|
114
|
+
trigger="click"
|
|
115
|
+
>
|
|
116
|
+
<EditFilled />
|
|
117
|
+
</Popover>
|
|
118
|
+
</span>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
@@ -10,6 +10,9 @@ import { singleton } from '@difizen/mana-app';
|
|
|
10
10
|
|
|
11
11
|
export interface PromptDecodedFormatter extends DefaultDecodedFormatter {
|
|
12
12
|
modelType?: string;
|
|
13
|
+
variableName?: string;
|
|
14
|
+
cellId?: string;
|
|
15
|
+
record?: string;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
@singleton({ contrib: FormatterContribution })
|
|
@@ -27,8 +30,11 @@ export class FormatterPromptMagicContribution
|
|
|
27
30
|
|
|
28
31
|
encode = (source: PromptDecodedFormatter) => {
|
|
29
32
|
const promptObj = {
|
|
30
|
-
model_name: source.modelType || '
|
|
33
|
+
model_name: source.modelType || 'chatgpt',
|
|
31
34
|
prompt: source.value,
|
|
35
|
+
variable_name: source.variableName,
|
|
36
|
+
cell_id: source.cellId,
|
|
37
|
+
record: source.record,
|
|
32
38
|
};
|
|
33
39
|
const encodeValue = `%%prompt \n${JSON.stringify(promptObj)}`;
|
|
34
40
|
return {
|
|
@@ -41,15 +47,20 @@ export class FormatterPromptMagicContribution
|
|
|
41
47
|
|
|
42
48
|
decode = (formatterValue: DefaultEncodedFormatter) => {
|
|
43
49
|
const value = concatMultilineString(formatterValue.source);
|
|
44
|
-
|
|
45
50
|
if (value.startsWith('%%prompt \n')) {
|
|
46
51
|
const run = value.split('%%prompt \n')[1];
|
|
47
52
|
const runValue = JSON.parse(run);
|
|
48
53
|
const codeValue = runValue.prompt;
|
|
49
54
|
const modelType = runValue.model_name;
|
|
55
|
+
const variableName = runValue.variable_name;
|
|
56
|
+
const cellId = runValue.cell_id;
|
|
57
|
+
const record = runValue.record;
|
|
50
58
|
return {
|
|
51
59
|
value: codeValue,
|
|
60
|
+
variableName,
|
|
52
61
|
modelType,
|
|
62
|
+
cellId,
|
|
63
|
+
record,
|
|
53
64
|
};
|
|
54
65
|
}
|
|
55
66
|
return {
|
package/src/module.ts
CHANGED
|
@@ -6,17 +6,17 @@ import { FormatterPromptMagicContribution } from './libro-formatter-prompt-magic
|
|
|
6
6
|
import { LibroPromptCellCommandContribution } from './prompt-cell-command-contribution.js';
|
|
7
7
|
import { PromptCellContribution } from './prompt-cell-contribution.js';
|
|
8
8
|
import { LibroPromptCellModel } from './prompt-cell-model.js';
|
|
9
|
-
import { LibroPromptOutputArea } from './prompt-cell-output-area.js';
|
|
10
9
|
import { LibroPromptCellModelFactory } from './prompt-cell-protocol.js';
|
|
10
|
+
import { PromptScript } from './prompt-cell-script.js';
|
|
11
11
|
import { LibroPromptCellView } from './prompt-cell-view.js';
|
|
12
12
|
import { LibroPromptOutputMimeTypeContribution } from './prompt-output-rendermime-contribution.js';
|
|
13
13
|
|
|
14
14
|
export const LibroPromptCellModule = ManaModule.create()
|
|
15
15
|
.register(
|
|
16
16
|
PromptCellContribution,
|
|
17
|
+
PromptScript,
|
|
17
18
|
LibroPromptCellView,
|
|
18
19
|
LibroPromptCellModel,
|
|
19
|
-
LibroPromptOutputArea,
|
|
20
20
|
LibroPromptOutputMimeTypeContribution,
|
|
21
21
|
LibroPromptCellCommandContribution,
|
|
22
22
|
FormatterPromptMagicContribution,
|
package/src/prompt-cell-model.ts
CHANGED
|
@@ -36,7 +36,15 @@ export class LibroPromptCellModel
|
|
|
36
36
|
@prop()
|
|
37
37
|
kernelExecuting = false;
|
|
38
38
|
|
|
39
|
+
@prop()
|
|
40
|
+
record: string;
|
|
41
|
+
|
|
42
|
+
@prop()
|
|
39
43
|
modelType: string;
|
|
44
|
+
|
|
45
|
+
@prop()
|
|
46
|
+
variableName: string;
|
|
47
|
+
|
|
40
48
|
@prop()
|
|
41
49
|
executing: boolean;
|
|
42
50
|
@prop()
|
|
@@ -51,6 +59,24 @@ export class LibroPromptCellModel
|
|
|
51
59
|
return this.msgChangeEmitter.event;
|
|
52
60
|
}
|
|
53
61
|
|
|
62
|
+
override get decodeObject() {
|
|
63
|
+
return {
|
|
64
|
+
...this._decodeObject,
|
|
65
|
+
variableName: this.variableName,
|
|
66
|
+
modelType: this.modelType,
|
|
67
|
+
record: this.record,
|
|
68
|
+
value: this.value,
|
|
69
|
+
cellId: this.id,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
override set decodeObject(value) {
|
|
74
|
+
super.decodeObject = value;
|
|
75
|
+
this.variableName = value.variableName;
|
|
76
|
+
this.modelType = value.modelType;
|
|
77
|
+
this.record = value.record;
|
|
78
|
+
}
|
|
79
|
+
|
|
54
80
|
viewManager: ViewManager;
|
|
55
81
|
|
|
56
82
|
constructor(
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
@singleton()
|
|
4
|
+
export class PromptScript {
|
|
5
|
+
public readonly getChatObjects = `from libro_server import chat_object_manager
|
|
6
|
+
chat_object_manager.dump_list_json()`;
|
|
7
|
+
public readonly getChatRecoreds = `from libro_server import chat_record_provider
|
|
8
|
+
chat_record_provider.get_records()`;
|
|
4
9
|
}
|