@difizen/libro-ai-native 0.2.41-next.1 → 0.2.41-next.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/ai-native-code-block.d.ts.map +1 -1
- package/es/ai-native-code-block.js +6 -5
- package/es/ai-native-command-contribution.d.ts.map +1 -1
- package/es/ai-native-command-contribution.js +60 -15
- package/es/ai-native-command.d.ts.map +1 -1
- package/es/ai-native-command.js +4 -0
- package/es/ai-native-for-cell-view.d.ts.map +1 -1
- package/es/ai-native-for-cell-view.js +41 -22
- package/es/ai-native-service.d.ts +3 -0
- package/es/ai-native-service.d.ts.map +1 -1
- package/es/ai-native-service.js +3 -0
- package/es/ai-side-toolbar-selector.js +4 -4
- package/es/chat-slot-contribution.d.ts.map +1 -1
- package/es/chat-slot-contribution.js +1 -2
- package/es/chat-view.d.ts +4 -1
- package/es/chat-view.d.ts.map +1 -1
- package/es/chat-view.js +109 -30
- package/es/error-output-model.d.ts.map +1 -1
- package/es/error-output-model.js +8 -5
- package/es/index.less +60 -27
- package/es/libro-ai-msg-item-model.d.ts.map +1 -1
- package/es/libro-ai-msg-item-model.js +1 -0
- package/es/libro-ai-native-chat-service.d.ts.map +1 -1
- package/es/libro-ai-native-chat-service.js +28 -20
- package/es/libro-ai-native-chat-view.d.ts +4 -1
- package/es/libro-ai-native-chat-view.d.ts.map +1 -1
- package/es/libro-ai-native-chat-view.js +8 -10
- package/es/protocol.d.ts +8 -2
- package/es/protocol.d.ts.map +1 -1
- package/es/utils.d.ts +6 -0
- package/es/utils.d.ts.map +1 -0
- package/es/utils.js +15 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-code-block.d.ts","sourceRoot":"","sources":["../src/ai-native-code-block.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-native-code-block.d.ts","sourceRoot":"","sources":["../src/ai-native-code-block.tsx"],"names":[],"mappings":"AASA,OAAO,cAAc,CAAC;AAItB,eAAO,MAAM,eAAe,UAAW,GAAG,4CAiDzC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,GAAG,4CAyEzC,CAAC"}
|
|
@@ -11,6 +11,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
11
11
|
import { CopyOutlined } from '@ant-design/icons';
|
|
12
12
|
import { LibroCodeCellView } from '@difizen/libro-jupyter';
|
|
13
13
|
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
14
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
14
15
|
import { Button, message } from 'antd';
|
|
15
16
|
import copy from 'copy-to-clipboard';
|
|
16
17
|
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
|
|
@@ -48,7 +49,7 @@ export var CodeBlockInCell = function CodeBlockInCell(props) {
|
|
|
48
49
|
}), /*#__PURE__*/_jsx(CopyOutlined, {
|
|
49
50
|
onClick: function onClick() {
|
|
50
51
|
copy(children);
|
|
51
|
-
message.success('代码已复制');
|
|
52
|
+
message.success(l10n.t('代码已复制'));
|
|
52
53
|
},
|
|
53
54
|
className: "chat-msg-md-code-copy"
|
|
54
55
|
}), /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
@@ -64,7 +65,7 @@ export var CodeBlockInCell = function CodeBlockInCell(props) {
|
|
|
64
65
|
onClick: function onClick() {
|
|
65
66
|
return replace(children);
|
|
66
67
|
},
|
|
67
|
-
children:
|
|
68
|
+
children: l10n.t('替换代码')
|
|
68
69
|
})
|
|
69
70
|
})]
|
|
70
71
|
});
|
|
@@ -141,7 +142,7 @@ export var CodeBlockInChat = function CodeBlockInChat(props) {
|
|
|
141
142
|
}), /*#__PURE__*/_jsx(CopyOutlined, {
|
|
142
143
|
onClick: function onClick() {
|
|
143
144
|
copy(children);
|
|
144
|
-
message.success('代码已复制');
|
|
145
|
+
message.success(l10n.t('代码已复制'));
|
|
145
146
|
},
|
|
146
147
|
className: "chat-msg-md-code-copy"
|
|
147
148
|
}), /*#__PURE__*/_jsx(SyntaxHighlighter, {
|
|
@@ -157,14 +158,14 @@ export var CodeBlockInChat = function CodeBlockInChat(props) {
|
|
|
157
158
|
onClick: function onClick() {
|
|
158
159
|
return insertCell(children);
|
|
159
160
|
},
|
|
160
|
-
children:
|
|
161
|
+
children: l10n.t('插入 Cell')
|
|
161
162
|
}), /*#__PURE__*/_jsx(Button, {
|
|
162
163
|
color: "primary",
|
|
163
164
|
variant: "outlined",
|
|
164
165
|
onClick: function onClick() {
|
|
165
166
|
return replace(children);
|
|
166
167
|
},
|
|
167
|
-
children:
|
|
168
|
+
children: l10n.t('替换 Cell')
|
|
168
169
|
})]
|
|
169
170
|
})]
|
|
170
171
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-command-contribution.d.ts","sourceRoot":"","sources":["../src/ai-native-command-contribution.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ai-native-command-contribution.d.ts","sourceRoot":"","sources":["../src/ai-native-command-contribution.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAa,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAI1E,qBACa,gCACX,YAAW,mBAAmB,EAAE,mBAAmB;IAErB,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAEpF,2BAA2B,EAAE,2BAA2B,CAAC;IAC/B,gBAAgB,EAAE,gBAAgB,CAAC;IAC/B,oBAAoB,EAAE,oBAAoB,CAAC;IACpD,WAAW,EAAE,WAAW,CAAC;IAE9C,oBAAoB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAuBrD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;CA+LjD"}
|
|
@@ -11,15 +11,19 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
11
11
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
12
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
13
13
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
14
|
+
import { CommentOutlined } from '@ant-design/icons';
|
|
14
15
|
import { LibroCommandRegister, LibroSlotManager, LibroSlotView, LibroToolbarArea, LibroCellView, LibroView } from '@difizen/libro-jupyter';
|
|
15
16
|
import { inject } from '@difizen/mana-app';
|
|
16
17
|
import { CommandContribution } from '@difizen/mana-app';
|
|
17
18
|
import { singleton, ToolbarContribution, ViewManager } from '@difizen/mana-app';
|
|
19
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
18
20
|
import { AINativeCommands } from "./ai-native-command.js";
|
|
19
21
|
import { LibroAINativeService } from "./ai-native-service.js";
|
|
20
22
|
import { AIToolbarSelector } from "./ai-side-toolbar-selector.js";
|
|
21
23
|
import { LibroAIChatSlotContribution } from "./chat-slot-contribution.js";
|
|
22
24
|
import { AIIcon } from "./icon.js";
|
|
25
|
+
import { addCellAIClassname } from "./utils.js";
|
|
26
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
27
|
export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
24
28
|
contrib: [CommandContribution, ToolbarContribution]
|
|
25
29
|
}), _dec2 = inject(LibroCommandRegister), _dec3 = inject(LibroAIChatSlotContribution), _dec4 = inject(LibroSlotManager), _dec5 = inject(LibroAINativeService), _dec6 = inject(ViewManager), _dec(_class = (_class2 = /*#__PURE__*/function () {
|
|
@@ -39,8 +43,7 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
39
43
|
command: AINativeCommands['AISideToolbarSelect'].id,
|
|
40
44
|
icon: AIToolbarSelector,
|
|
41
45
|
showLabelInline: true,
|
|
42
|
-
|
|
43
|
-
order: 'a'
|
|
46
|
+
order: 'b'
|
|
44
47
|
});
|
|
45
48
|
registry.registerItem({
|
|
46
49
|
id: AINativeCommands['Chat'].id,
|
|
@@ -48,6 +51,14 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
48
51
|
icon: AIIcon,
|
|
49
52
|
order: 'a'
|
|
50
53
|
});
|
|
54
|
+
registry.registerItem({
|
|
55
|
+
id: AINativeCommands['CellChat'].id,
|
|
56
|
+
command: AINativeCommands['CellChat'].id,
|
|
57
|
+
icon: /*#__PURE__*/_jsx(CommentOutlined, {
|
|
58
|
+
className: "libro-ai-native-cell-chat-icon"
|
|
59
|
+
}),
|
|
60
|
+
order: 'a'
|
|
61
|
+
});
|
|
51
62
|
}
|
|
52
63
|
}, {
|
|
53
64
|
key: "registerCommands",
|
|
@@ -95,14 +106,18 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
95
106
|
}
|
|
96
107
|
return _context2.abrupt("return");
|
|
97
108
|
case 2:
|
|
98
|
-
|
|
109
|
+
addCellAIClassname(cell);
|
|
99
110
|
chatView = _this.libroAINativeService.chatViewMap.get(libro.id);
|
|
100
111
|
showChat = _this.libroAINativeService.showChatMap.get(libro.id);
|
|
101
112
|
if (!chatView) {
|
|
102
|
-
_context2.next =
|
|
113
|
+
_context2.next = 12;
|
|
103
114
|
break;
|
|
104
115
|
}
|
|
105
|
-
chatView.
|
|
116
|
+
chatView.setAINativeChatView({
|
|
117
|
+
id: cell.id,
|
|
118
|
+
isCellChat: true,
|
|
119
|
+
cell: cell
|
|
120
|
+
});
|
|
106
121
|
if (!showChat) {
|
|
107
122
|
_context2.next = 9;
|
|
108
123
|
break;
|
|
@@ -110,14 +125,15 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
110
125
|
return _context2.abrupt("return");
|
|
111
126
|
case 9:
|
|
112
127
|
_this.libroAINativeService.showChatMap.set(libro.id, !showChat);
|
|
128
|
+
_this.libroAINativeService.cellAIChatMap.set(cell.id, !showChat);
|
|
113
129
|
_this.libroSlotManager.slotViewManager.addView(chatView, _this.libroSlotManager.getSlotName(libro, _this.libroAIChatSlotContribution.slot), {
|
|
114
130
|
reveal: true,
|
|
115
131
|
order: 'a'
|
|
116
132
|
});
|
|
117
|
-
case
|
|
133
|
+
case 12:
|
|
118
134
|
//优化交互,用于控制点击按钮后菜单消失
|
|
119
135
|
_this.libroAINativeService.showSideToolbar = false;
|
|
120
|
-
case
|
|
136
|
+
case 13:
|
|
121
137
|
case "end":
|
|
122
138
|
return _context2.stop();
|
|
123
139
|
}
|
|
@@ -133,6 +149,12 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
133
149
|
return false;
|
|
134
150
|
}
|
|
135
151
|
return true;
|
|
152
|
+
},
|
|
153
|
+
isVisible: function isVisible(cell, libro, path) {
|
|
154
|
+
if (!cell || !libro || !(libro instanceof LibroView)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
return path === LibroToolbarArea.CellRight;
|
|
136
158
|
}
|
|
137
159
|
});
|
|
138
160
|
this.libroCommand.registerLibroCommand(command, AINativeCommands['Chat'], {
|
|
@@ -159,10 +181,16 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
159
181
|
_context3.next = 9;
|
|
160
182
|
break;
|
|
161
183
|
}
|
|
162
|
-
chatView.
|
|
184
|
+
chatView.setAINativeChatView({
|
|
185
|
+
id: libro.id,
|
|
186
|
+
isCellChat: false
|
|
187
|
+
});
|
|
163
188
|
return _context3.abrupt("return");
|
|
164
189
|
case 9:
|
|
165
|
-
chatView.
|
|
190
|
+
chatView.setAINativeChatView({
|
|
191
|
+
id: libro.id,
|
|
192
|
+
isCellChat: false
|
|
193
|
+
});
|
|
166
194
|
_this.libroAINativeService.showChatMap.set(libro.id, !showChat);
|
|
167
195
|
if (showChat) {
|
|
168
196
|
slotview = _this.libroSlotManager.slotViewManager.getSlotView(_this.libroSlotManager.getSlotName(libro, 'right'));
|
|
@@ -219,10 +247,9 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
219
247
|
case 4:
|
|
220
248
|
libroAINativeForCellView = _context4.sent;
|
|
221
249
|
libroAINativeForCellView.showAI = true;
|
|
222
|
-
|
|
250
|
+
addCellAIClassname(cell);
|
|
223
251
|
libroAINativeForCellView.chatStream({
|
|
224
|
-
|
|
225
|
-
content: "\u5E2E\u5FD9\u89E3\u91CA\u4E00\u4E0B\u8FD9\u6BB5\u4EE3\u7801\uFF1A".concat(cell.model.value)
|
|
252
|
+
content: l10n.getLang() ? "Could you please explain this piece of code?\uFF1A".concat(cell.model.value, "\uFF0CProvide the reasons and the results of the optimization.") : "\u5E2E\u5FD9\u4F18\u5316\u4E00\u4E0B\u8FD9\u6BB5\u4EE3\u7801\uFF1A".concat(cell.model.value, "\uFF0C\u7ED9\u51FA\u539F\u56E0\u4EE5\u53CA\u4F18\u5316\u7ED3\u679C")
|
|
226
253
|
});
|
|
227
254
|
// this.libroService.active?.enterEditMode();
|
|
228
255
|
case 8:
|
|
@@ -243,18 +270,36 @@ export var LibroAINativeCommandContribution = (_dec = singleton({
|
|
|
243
270
|
return true;
|
|
244
271
|
}
|
|
245
272
|
});
|
|
246
|
-
this.libroCommand.registerLibroCommand(command, AINativeCommands['
|
|
273
|
+
this.libroCommand.registerLibroCommand(command, AINativeCommands['Optimize'], {
|
|
247
274
|
execute: function () {
|
|
248
|
-
var _execute5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
275
|
+
var _execute5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(cell, libro) {
|
|
276
|
+
var libroAINativeForCellView;
|
|
249
277
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
250
278
|
while (1) switch (_context5.prev = _context5.next) {
|
|
251
279
|
case 0:
|
|
280
|
+
if (!(!cell || !(cell instanceof LibroCellView) || !libro || !(libro instanceof LibroView))) {
|
|
281
|
+
_context5.next = 2;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
return _context5.abrupt("return");
|
|
285
|
+
case 2:
|
|
286
|
+
_context5.next = 4;
|
|
287
|
+
return _this.libroAINativeService.getOrCreateLibroAINativeForCellView(cell.id, cell);
|
|
288
|
+
case 4:
|
|
289
|
+
libroAINativeForCellView = _context5.sent;
|
|
290
|
+
libroAINativeForCellView.showAI = true;
|
|
291
|
+
addCellAIClassname(cell);
|
|
292
|
+
libroAINativeForCellView.chatStream({
|
|
293
|
+
content: l10n.getLang() ? "Please help optimize this piece of code: ".concat(cell.model.value, ",provide reasons and the optimized result.") : "\u5E2E\u5FD9\u4F18\u5316\u4E00\u4E0B\u8FD9\u6BB5\u4EE3\u7801\uFF1A".concat(cell.model.value, "\uFF0C\u7ED9\u51FA\u539F\u56E0\u4EE5\u53CA\u4F18\u5316\u7ED3\u679C")
|
|
294
|
+
});
|
|
295
|
+
// this.libroService.active?.enterEditMode();
|
|
296
|
+
case 8:
|
|
252
297
|
case "end":
|
|
253
298
|
return _context5.stop();
|
|
254
299
|
}
|
|
255
300
|
}, _callee5);
|
|
256
301
|
}));
|
|
257
|
-
function execute() {
|
|
302
|
+
function execute(_x7, _x8) {
|
|
258
303
|
return _execute5.apply(this, arguments);
|
|
259
304
|
}
|
|
260
305
|
return execute;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-command.d.ts","sourceRoot":"","sources":["../src/ai-native-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"ai-native-command.d.ts","sourceRoot":"","sources":["../src/ai-native-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAoB3E,CAAC"}
|
package/es/ai-native-command.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-for-cell-view.d.ts","sourceRoot":"","sources":["../src/ai-native-for-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-native-for-cell-view.d.ts","sourceRoot":"","sources":["../src/ai-native-for-cell-view.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAMvD,OAAO,EAAE,QAAQ,EAAmB,MAAM,mBAAmB,CAAC;AAU9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGhE,wBAAgB,0BAA0B,mDA+CzC;AAED,qBAEa,wBAAyB,SAAQ,QAAQ;IAC3C,IAAI,EAAE,aAAa,CAA8B;IACzC,OAAO,EAAE,OAAO,CAAC;IAClC,IAAI,EAAE,QAAQ,CAAC;IAEf,6BAA6B,EAAE,aAAa,CAAC,OAAO,2BAA2B,CAAC,CAAC;IAEjF,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAG1D,MAAM,UAAS;gBACiB,OAAO,EAAE,0BAA0B;IAKnE,UAAU,WAAkB,YAAY,mBA0DtC;CACH"}
|
|
@@ -30,26 +30,32 @@ import { useObserve } from '@difizen/mana-app';
|
|
|
30
30
|
import { useInject, ViewInstance } from '@difizen/mana-app';
|
|
31
31
|
import { inject } from '@difizen/mana-app';
|
|
32
32
|
import { BaseView, transient, view } from '@difizen/mana-app';
|
|
33
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
33
34
|
import { Button } from 'antd';
|
|
34
35
|
import { EventSourceParserStream } from 'eventsource-parser/stream';
|
|
35
36
|
import breaks from 'remark-breaks';
|
|
36
37
|
import remarkGfm from 'remark-gfm';
|
|
37
38
|
import { CodeBlockInCell } from "./ai-native-code-block.js";
|
|
39
|
+
import { LibroAINativeService } from "./ai-native-service.js";
|
|
38
40
|
import { AILoadding } from "./icon.js";
|
|
39
41
|
import { LibroAIChatMessageItemModel } from "./libro-ai-msg-item-model.js";
|
|
40
|
-
import { stringToReadableStream } from "./utils.js";
|
|
42
|
+
import { cancelCellAIClassname, stringToReadableStream } from "./utils.js";
|
|
41
43
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
42
44
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
43
45
|
export function LibroAINativeForCellRender() {
|
|
44
46
|
var LLMRender = ChatComponents.Markdown;
|
|
45
47
|
var instance = useInject(ViewInstance);
|
|
48
|
+
var libroAINativeService = useInject(LibroAINativeService);
|
|
46
49
|
var msgItem = useObserve(instance.libroAIChatMessageItemModel);
|
|
47
50
|
if (!instance.showAI) {
|
|
48
51
|
return null;
|
|
49
52
|
}
|
|
50
53
|
return /*#__PURE__*/_jsxs("div", {
|
|
51
54
|
className: "libro-ai-native-for-cell-container",
|
|
52
|
-
children: [/*#__PURE__*/_jsx(
|
|
55
|
+
children: [(msgItem === null || msgItem === void 0 ? void 0 : msgItem.state) === AnswerState.FAIL ? /*#__PURE__*/_jsx("div", {
|
|
56
|
+
className: "libro-ai-native-for-cell-error",
|
|
57
|
+
children: l10n.t('请求报错~')
|
|
58
|
+
}) : /*#__PURE__*/_jsx(LLMRender, {
|
|
53
59
|
type: "message",
|
|
54
60
|
components: {
|
|
55
61
|
code: CodeBlockInCell
|
|
@@ -59,13 +65,15 @@ export function LibroAINativeForCellRender() {
|
|
|
59
65
|
}), /*#__PURE__*/_jsx(Button, {
|
|
60
66
|
color: "default",
|
|
61
67
|
variant: "outlined",
|
|
62
|
-
className: "libro-ai-native-for-cell-cancel-btn",
|
|
68
|
+
className: "libro-ai-native-for-cell-cancel-btn ".concat((msgItem === null || msgItem === void 0 ? void 0 : msgItem.state) === AnswerState.FAIL ? 'error' : ''),
|
|
63
69
|
onClick: function onClick() {
|
|
64
70
|
instance.showAI = false;
|
|
65
|
-
|
|
71
|
+
if (!libroAINativeService.cellAIChatMap.get(instance.cell.id)) {
|
|
72
|
+
cancelCellAIClassname(instance.cell);
|
|
73
|
+
}
|
|
66
74
|
},
|
|
67
|
-
icon: (msgItem === null || msgItem === void 0 ? void 0 : msgItem.state) === AnswerState.SUCCESS ? /*#__PURE__*/_jsx(CloseOutlined, {}) : /*#__PURE__*/_jsx(AILoadding, {}),
|
|
68
|
-
children:
|
|
75
|
+
icon: (msgItem === null || msgItem === void 0 ? void 0 : msgItem.state) === AnswerState.SUCCESS || (msgItem === null || msgItem === void 0 ? void 0 : msgItem.state) === AnswerState.FAIL ? /*#__PURE__*/_jsx(CloseOutlined, {}) : /*#__PURE__*/_jsx(AILoadding, {}),
|
|
76
|
+
children: l10n.t('取消')
|
|
69
77
|
})]
|
|
70
78
|
});
|
|
71
79
|
}
|
|
@@ -83,15 +91,16 @@ export var LibroAINativeForCellView = (_dec = transient(), _dec2 = view('libro-a
|
|
|
83
91
|
_initializerDefineProperty(_this, "showAI", _descriptor4, _assertThisInitialized(_this));
|
|
84
92
|
_this.chatStream = /*#__PURE__*/function () {
|
|
85
93
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(option) {
|
|
86
|
-
var chat_key, content, url, msg, res, reader, stream, msgItem, alreayDone, _yield$reader$read, value, done, data, event;
|
|
94
|
+
var chat_key, content, language, url, msg, res, reader, stream, msgItem, alreayDone, _yield$reader$read, value, done, data, event;
|
|
87
95
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
88
96
|
while (1) switch (_context.prev = _context.next) {
|
|
89
97
|
case 0:
|
|
90
|
-
chat_key = option.chat_key, content = option.content;
|
|
98
|
+
chat_key = option.chat_key, content = option.content, language = option.language;
|
|
91
99
|
url = "/libro/api/chatstream";
|
|
92
100
|
msg = {
|
|
93
101
|
chat_key: chat_key,
|
|
94
|
-
prompt: content
|
|
102
|
+
prompt: content,
|
|
103
|
+
language: language
|
|
95
104
|
};
|
|
96
105
|
_context.next = 5;
|
|
97
106
|
return _this.fetcher.post(url, msg, {
|
|
@@ -104,7 +113,7 @@ export var LibroAINativeForCellView = (_dec = transient(), _dec2 = view('libro-a
|
|
|
104
113
|
case 5:
|
|
105
114
|
res = _context.sent;
|
|
106
115
|
if (!(res.status === 200)) {
|
|
107
|
-
_context.next =
|
|
116
|
+
_context.next = 33;
|
|
108
117
|
break;
|
|
109
118
|
}
|
|
110
119
|
if (typeof res.data === 'string') {
|
|
@@ -116,45 +125,55 @@ export var LibroAINativeForCellView = (_dec = transient(), _dec2 = view('libro-a
|
|
|
116
125
|
msgItem = _this.libroAiChatMessageItemFactory({
|
|
117
126
|
sender: {
|
|
118
127
|
type: 'AI',
|
|
119
|
-
id:
|
|
128
|
+
id: 'libro'
|
|
120
129
|
},
|
|
121
130
|
content: ''
|
|
122
131
|
});
|
|
123
132
|
_this.libroAIChatMessageItemModel = msgItem;
|
|
124
133
|
alreayDone = false;
|
|
125
|
-
|
|
134
|
+
_context.prev = 11;
|
|
135
|
+
case 12:
|
|
126
136
|
if (alreayDone) {
|
|
127
|
-
_context.next =
|
|
137
|
+
_context.next = 27;
|
|
128
138
|
break;
|
|
129
139
|
}
|
|
130
|
-
_context.next =
|
|
140
|
+
_context.next = 15;
|
|
131
141
|
return reader.read();
|
|
132
|
-
case
|
|
142
|
+
case 15:
|
|
133
143
|
_yield$reader$read = _context.sent;
|
|
134
144
|
value = _yield$reader$read.value;
|
|
135
145
|
done = _yield$reader$read.done;
|
|
136
146
|
if (!done) {
|
|
137
|
-
_context.next =
|
|
147
|
+
_context.next = 22;
|
|
138
148
|
break;
|
|
139
149
|
}
|
|
140
150
|
alreayDone = true;
|
|
141
151
|
msgItem.handleEventData({
|
|
142
152
|
type: 'done'
|
|
143
153
|
});
|
|
144
|
-
return _context.abrupt("break",
|
|
145
|
-
case
|
|
154
|
+
return _context.abrupt("break", 27);
|
|
155
|
+
case 22:
|
|
146
156
|
data = JSON.parse(value.data);
|
|
147
157
|
event = ChatEvent.format(value.event || 'chunk', data);
|
|
148
158
|
msgItem.handleEventData(event);
|
|
149
|
-
_context.next =
|
|
159
|
+
_context.next = 12;
|
|
150
160
|
break;
|
|
151
|
-
case 26:
|
|
152
|
-
return _context.abrupt("return");
|
|
153
161
|
case 27:
|
|
162
|
+
_context.next = 32;
|
|
163
|
+
break;
|
|
164
|
+
case 29:
|
|
165
|
+
_context.prev = 29;
|
|
166
|
+
_context.t0 = _context["catch"](11);
|
|
167
|
+
msgItem.handleEventData({
|
|
168
|
+
type: 'error'
|
|
169
|
+
});
|
|
170
|
+
case 32:
|
|
171
|
+
return _context.abrupt("return");
|
|
172
|
+
case 33:
|
|
154
173
|
case "end":
|
|
155
174
|
return _context.stop();
|
|
156
175
|
}
|
|
157
|
-
}, _callee);
|
|
176
|
+
}, _callee, null, [[11, 29]]);
|
|
158
177
|
}));
|
|
159
178
|
return function (_x) {
|
|
160
179
|
return _ref.apply(this, arguments);
|
|
@@ -2,12 +2,15 @@ import type { CellView } from '@difizen/libro-jupyter';
|
|
|
2
2
|
import { ViewManager } from '@difizen/mana-app';
|
|
3
3
|
import { LibroAINativeForCellView } from './ai-native-for-cell-view.js';
|
|
4
4
|
import type { LibroChatView } from './chat-view.js';
|
|
5
|
+
import type { LibroAiNativeChatView } from './libro-ai-native-chat-view.js';
|
|
5
6
|
export declare class LibroAINativeService {
|
|
6
7
|
showSideToolbar: boolean;
|
|
7
8
|
chatViewMap: Map<string, LibroChatView>;
|
|
8
9
|
showChatMap: Map<string, boolean>;
|
|
10
|
+
cellAIChatMap: Map<string, boolean>;
|
|
9
11
|
viewManager: ViewManager;
|
|
10
12
|
libroAINativeForCellViewMap: Map<string, LibroAINativeForCellView>;
|
|
13
|
+
libroAINativeChatViewMap: Map<string, LibroAiNativeChatView>;
|
|
11
14
|
getOrCreateLibroAINativeForCellView(id: string, cell: CellView): Promise<LibroAINativeForCellView>;
|
|
12
15
|
}
|
|
13
16
|
//# sourceMappingURL=ai-native-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-native-service.d.ts","sourceRoot":"","sources":["../src/ai-native-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAsC,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ai-native-service.d.ts","sourceRoot":"","sources":["../src/ai-native-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAsC,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAE5E,qBACa,oBAAoB;IAE/B,eAAe,UAAS;IAExB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAa;IAGpD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAE9C,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAEhD,WAAW,EAAE,WAAW,CAAC;IAEzB,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAa;IAE/E,wBAAwB,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAa;IAEnE,mCAAmC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;CAarE"}
|
package/es/ai-native-service.js
CHANGED
|
@@ -18,9 +18,12 @@ export var LibroAINativeService = (_dec = singleton(), _dec2 = prop(), _dec3 = i
|
|
|
18
18
|
_classCallCheck(this, LibroAINativeService);
|
|
19
19
|
_initializerDefineProperty(this, "showSideToolbar", _descriptor, this);
|
|
20
20
|
this.chatViewMap = new Map();
|
|
21
|
+
//用于控制是否显示当前 libro 层级的 chat 面板
|
|
21
22
|
this.showChatMap = new Map();
|
|
23
|
+
this.cellAIChatMap = new Map();
|
|
22
24
|
_initializerDefineProperty(this, "viewManager", _descriptor2, this);
|
|
23
25
|
this.libroAINativeForCellViewMap = new Map();
|
|
26
|
+
this.libroAINativeChatViewMap = new Map();
|
|
24
27
|
}
|
|
25
28
|
_createClass(LibroAINativeService, [{
|
|
26
29
|
key: "getOrCreateLibroAINativeForCellView",
|
|
@@ -9,20 +9,20 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
9
9
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
10
|
export var AIToolbarSelector = function AIToolbarSelector() {
|
|
11
11
|
var items = [{
|
|
12
|
-
id: AINativeCommands['
|
|
12
|
+
id: AINativeCommands['Explain'].id,
|
|
13
13
|
label: /*#__PURE__*/_jsx(_Fragment, {
|
|
14
14
|
children: /*#__PURE__*/_jsx("span", {
|
|
15
15
|
className: "libro-menu-item-label",
|
|
16
|
-
children: l10n.t('
|
|
16
|
+
children: l10n.t('代码解释')
|
|
17
17
|
})
|
|
18
18
|
}),
|
|
19
19
|
group: 'ai'
|
|
20
20
|
}, {
|
|
21
|
-
id: AINativeCommands['
|
|
21
|
+
id: AINativeCommands['Optimize'].id,
|
|
22
22
|
label: /*#__PURE__*/_jsx(_Fragment, {
|
|
23
23
|
children: /*#__PURE__*/_jsx("span", {
|
|
24
24
|
className: "libro-menu-item-label",
|
|
25
|
-
children: l10n.t('
|
|
25
|
+
children: l10n.t('代码优化')
|
|
26
26
|
})
|
|
27
27
|
}),
|
|
28
28
|
group: 'ai'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-slot-contribution.d.ts","sourceRoot":"","sources":["../src/chat-slot-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,yBAAyB,EACzB,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBACa,2BAA4B,YAAW,8BAA8B;IAC3D,WAAW,EAAE,WAAW,CAAC;IAChB,oBAAoB,EAAE,oBAAoB,CAAC;IAEzE,SAAgB,IAAI,EAAE,SAAS,CAAW;IAE1C,OAAO,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"chat-slot-contribution.d.ts","sourceRoot":"","sources":["../src/chat-slot-contribution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,yBAAyB,EACzB,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,qBACa,2BAA4B,YAAW,8BAA8B;IAC3D,WAAW,EAAE,WAAW,CAAC;IAChB,oBAAoB,EAAE,oBAAoB,CAAC;IAEzE,SAAgB,IAAI,EAAE,SAAS,CAAW;IAE1C,OAAO,EAAE,yBAAyB,CAWhC;IACF,cAAc;;;MAGZ;CACH"}
|
|
@@ -37,14 +37,13 @@ export var LibroAIChatSlotContribution = (_dec = singleton({
|
|
|
37
37
|
case 2:
|
|
38
38
|
view = _context.sent;
|
|
39
39
|
view.parent = libro;
|
|
40
|
-
view.chatView.libro = libro;
|
|
41
40
|
_this.libroAINativeService.chatViewMap.set(libro.id, view);
|
|
42
41
|
_this.libroAINativeService.showChatMap.set(libro.id, false);
|
|
43
42
|
view.onDisposed(function () {
|
|
44
43
|
_this.libroAINativeService.chatViewMap.delete(libro.id);
|
|
45
44
|
});
|
|
46
45
|
return _context.abrupt("return", view);
|
|
47
|
-
case
|
|
46
|
+
case 8:
|
|
48
47
|
case "end":
|
|
49
48
|
return _context.stop();
|
|
50
49
|
}
|
package/es/chat-view.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import type { DisplayView, LibroView } from '@difizen/libro-jupyter';
|
|
2
2
|
import type { ConfigurationService } from '@difizen/mana-app';
|
|
3
3
|
import { BaseView, ViewManager } from '@difizen/mana-app';
|
|
4
|
+
import { LibroAINativeService } from './ai-native-service.js';
|
|
4
5
|
import { LibroAiNativeChatView } from './libro-ai-native-chat-view.js';
|
|
6
|
+
import type { AiNativeChatViewOption } from './protocol.js';
|
|
5
7
|
export declare const ChatRender: () => import("react/jsx-runtime").JSX.Element;
|
|
6
8
|
export declare class LibroChatView extends BaseView implements DisplayView {
|
|
7
9
|
parent: LibroView | undefined;
|
|
8
10
|
protected configurationService: ConfigurationService;
|
|
9
11
|
viewManager: ViewManager;
|
|
12
|
+
libroAINativeService: LibroAINativeService;
|
|
10
13
|
view: () => import("react/jsx-runtime").JSX.Element;
|
|
11
14
|
chatView: LibroAiNativeChatView;
|
|
12
15
|
isDisplay: boolean;
|
|
13
|
-
|
|
16
|
+
setAINativeChatView(option: AiNativeChatViewOption): Promise<void>;
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=chat-view.d.ts.map
|
package/es/chat-view.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-view.d.ts","sourceRoot":"","sources":["../src/chat-view.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EACL,QAAQ,EAKR,WAAW,EAIZ,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat-view.d.ts","sourceRoot":"","sources":["../src/chat-view.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EACL,QAAQ,EAKR,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG5D,eAAO,MAAM,UAAU,+CA6DtB,CAAC;AAEF,qBAEa,aAAc,SAAQ,QAAS,YAAW,WAAW;IAChE,MAAM,EAAE,SAAS,GAAG,SAAS,CAAa;IAC1C,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;IAChC,WAAW,EAAE,WAAW,CAAC;IAChB,oBAAoB,EAAE,oBAAoB,CAAC;IAEhE,IAAI,gDAAc;IAG3B,QAAQ,EAAE,qBAAqB,CAAC;IAGhC,SAAS,UAAQ;IAEX,mBAAmB,CAAC,MAAM,EAAE,sBAAsB;CAmCzD"}
|
package/es/chat-view.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
-
var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3;
|
|
2
|
+
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
|
|
3
3
|
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
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); } }
|
|
5
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; }
|
|
6
7
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
8
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
9
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
10
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
11
11
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
@@ -15,15 +15,20 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
15
15
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
16
16
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
|
|
17
17
|
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
|
|
18
|
+
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; }
|
|
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); } }
|
|
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); }); }; }
|
|
18
21
|
import { CloseOutlined } from '@ant-design/icons';
|
|
19
22
|
import { LibroContextKey, LibroSlotManager, LibroSlotView } from '@difizen/libro-jupyter';
|
|
20
23
|
import { BaseView, prop, transient, view, inject, ViewManager, useInject, ViewInstance, ViewRender } from '@difizen/mana-app';
|
|
21
24
|
import { useRef } from 'react';
|
|
22
25
|
import { LibroAINativeService } from "./ai-native-service.js";
|
|
23
26
|
import { LibroAiNativeChatView } from "./libro-ai-native-chat-view.js";
|
|
27
|
+
import { cancelCellAIClassname } from "./utils.js";
|
|
24
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
30
|
export var ChatRender = function ChatRender() {
|
|
31
|
+
var _libroChatView$chatVi;
|
|
27
32
|
var containRef = useRef(null);
|
|
28
33
|
var libroChatView = useInject(ViewInstance);
|
|
29
34
|
var libroSlotManager = useInject(LibroSlotManager);
|
|
@@ -47,20 +52,43 @@ export var ChatRender = function ChatRender() {
|
|
|
47
52
|
className: "chat-right-toolbar",
|
|
48
53
|
children: [/*#__PURE__*/_jsx("div", {
|
|
49
54
|
className: "chat-type",
|
|
50
|
-
children: libroChatView.chatView.isCellChat ? 'Focused Cell' : 'General Chat'
|
|
55
|
+
children: (_libroChatView$chatVi = libroChatView.chatView) !== null && _libroChatView$chatVi !== void 0 && _libroChatView$chatVi.isCellChat ? 'Focused Cell' : 'General Chat'
|
|
51
56
|
}), /*#__PURE__*/_jsx("div", {
|
|
52
57
|
children: /*#__PURE__*/_jsx(CloseOutlined, {
|
|
53
58
|
className: "chat-close-icon",
|
|
54
|
-
onClick: function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
60
|
+
var _libroChatView$chatVi2, libroAINativeForCellView, slotview;
|
|
61
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
62
|
+
while (1) switch (_context.prev = _context.next) {
|
|
63
|
+
case 0:
|
|
64
|
+
if (!libroChatView.parent) {
|
|
65
|
+
_context.next = 9;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
if (!((_libroChatView$chatVi2 = libroChatView.chatView) !== null && _libroChatView$chatVi2 !== void 0 && _libroChatView$chatVi2.cell)) {
|
|
69
|
+
_context.next = 6;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
_context.next = 4;
|
|
73
|
+
return libroAINativeService.getOrCreateLibroAINativeForCellView(libroChatView.chatView.cell.id, libroChatView.chatView.cell);
|
|
74
|
+
case 4:
|
|
75
|
+
libroAINativeForCellView = _context.sent;
|
|
76
|
+
if (!libroAINativeForCellView.showAI) {
|
|
77
|
+
cancelCellAIClassname(libroChatView.chatView.cell);
|
|
78
|
+
libroAINativeService.cellAIChatMap.set(libroChatView.chatView.cell.id, false);
|
|
79
|
+
}
|
|
80
|
+
case 6:
|
|
81
|
+
libroAINativeService.showChatMap.set(libroChatView.parent.id, false);
|
|
82
|
+
slotview = libroSlotManager.slotViewManager.getSlotView(libroSlotManager.getSlotName(libroChatView.parent, 'right'));
|
|
83
|
+
if (slotview instanceof LibroSlotView) {
|
|
84
|
+
slotview.revertActive();
|
|
85
|
+
}
|
|
86
|
+
case 9:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context.stop();
|
|
61
89
|
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
90
|
+
}, _callee);
|
|
91
|
+
}))
|
|
64
92
|
})
|
|
65
93
|
})]
|
|
66
94
|
})]
|
|
@@ -69,42 +97,93 @@ export var ChatRender = function ChatRender() {
|
|
|
69
97
|
})]
|
|
70
98
|
});
|
|
71
99
|
};
|
|
72
|
-
export var LibroChatView = (_dec = transient(), _dec2 = view('libro-chat-view'), _dec3 = inject(ViewManager), _dec4 =
|
|
100
|
+
export var LibroChatView = (_dec = transient(), _dec2 = view('libro-chat-view'), _dec3 = inject(ViewManager), _dec4 = inject(LibroAINativeService), _dec5 = prop(), _dec6 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
|
|
73
101
|
_inherits(LibroChatView, _BaseView);
|
|
74
102
|
var _super = _createSuper(LibroChatView);
|
|
75
|
-
function LibroChatView(
|
|
103
|
+
function LibroChatView() {
|
|
76
104
|
var _this;
|
|
77
105
|
_classCallCheck(this, LibroChatView);
|
|
78
|
-
|
|
106
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
107
|
+
args[_key] = arguments[_key];
|
|
108
|
+
}
|
|
109
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
79
110
|
_this.parent = undefined;
|
|
80
111
|
_initializerDefineProperty(_this, "viewManager", _descriptor, _assertThisInitialized(_this));
|
|
112
|
+
_initializerDefineProperty(_this, "libroAINativeService", _descriptor2, _assertThisInitialized(_this));
|
|
81
113
|
_this.view = ChatRender;
|
|
82
|
-
_initializerDefineProperty(_this, "chatView",
|
|
83
|
-
_initializerDefineProperty(_this, "isDisplay",
|
|
84
|
-
viewManager.getOrCreateView(LibroAiNativeChatView, {
|
|
85
|
-
id: _this.id,
|
|
86
|
-
chat_key: 'LLM:chatgpt'
|
|
87
|
-
}).then(function (chatView) {
|
|
88
|
-
_this.chatView = chatView;
|
|
89
|
-
return;
|
|
90
|
-
}).catch(function () {
|
|
91
|
-
//
|
|
92
|
-
});
|
|
114
|
+
_initializerDefineProperty(_this, "chatView", _descriptor3, _assertThisInitialized(_this));
|
|
115
|
+
_initializerDefineProperty(_this, "isDisplay", _descriptor4, _assertThisInitialized(_this));
|
|
93
116
|
return _this;
|
|
94
117
|
}
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
_createClass(LibroChatView, [{
|
|
119
|
+
key: "setAINativeChatView",
|
|
120
|
+
value: function () {
|
|
121
|
+
var _setAINativeChatView = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(option) {
|
|
122
|
+
var _this$chatView,
|
|
123
|
+
_this2 = this;
|
|
124
|
+
var _this$chatView2, _option$cell, libroAINativeForCellView;
|
|
125
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
126
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
127
|
+
case 0:
|
|
128
|
+
if (!((_this$chatView = this.chatView) !== null && _this$chatView !== void 0 && _this$chatView.cell)) {
|
|
129
|
+
_context2.next = 7;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (!(((_this$chatView2 = this.chatView) === null || _this$chatView2 === void 0 ? void 0 : _this$chatView2.cell.id) === ((_option$cell = option.cell) === null || _option$cell === void 0 ? void 0 : _option$cell.id))) {
|
|
133
|
+
_context2.next = 3;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
return _context2.abrupt("return");
|
|
137
|
+
case 3:
|
|
138
|
+
_context2.next = 5;
|
|
139
|
+
return this.libroAINativeService.getOrCreateLibroAINativeForCellView(this.chatView.cell.id, this.chatView.cell);
|
|
140
|
+
case 5:
|
|
141
|
+
libroAINativeForCellView = _context2.sent;
|
|
142
|
+
if (this.libroAINativeService.cellAIChatMap.get(this.chatView.cell.id) && !libroAINativeForCellView.showAI) {
|
|
143
|
+
cancelCellAIClassname(this.chatView.cell);
|
|
144
|
+
this.libroAINativeService.cellAIChatMap.set(this.chatView.cell.id, false);
|
|
145
|
+
}
|
|
146
|
+
case 7:
|
|
147
|
+
this.viewManager.getOrCreateView(LibroAiNativeChatView, option).then(function (chatView) {
|
|
148
|
+
chatView.libro = _this2.parent;
|
|
149
|
+
if (option.isCellChat && option.cell) {
|
|
150
|
+
chatView.cell = option.cell;
|
|
151
|
+
_this2.libroAINativeService.cellAIChatMap.set(option.cell.id, true);
|
|
152
|
+
}
|
|
153
|
+
_this2.chatView = chatView;
|
|
154
|
+
return;
|
|
155
|
+
}).catch(function () {
|
|
156
|
+
//
|
|
157
|
+
});
|
|
158
|
+
case 8:
|
|
159
|
+
case "end":
|
|
160
|
+
return _context2.stop();
|
|
161
|
+
}
|
|
162
|
+
}, _callee2, this);
|
|
163
|
+
}));
|
|
164
|
+
function setAINativeChatView(_x) {
|
|
165
|
+
return _setAINativeChatView.apply(this, arguments);
|
|
166
|
+
}
|
|
167
|
+
return setAINativeChatView;
|
|
168
|
+
}()
|
|
169
|
+
}]);
|
|
170
|
+
return LibroChatView;
|
|
97
171
|
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "viewManager", [_dec3], {
|
|
98
172
|
configurable: true,
|
|
99
173
|
enumerable: true,
|
|
100
174
|
writable: true,
|
|
101
175
|
initializer: null
|
|
102
|
-
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "
|
|
176
|
+
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "libroAINativeService", [_dec4], {
|
|
177
|
+
configurable: true,
|
|
178
|
+
enumerable: true,
|
|
179
|
+
writable: true,
|
|
180
|
+
initializer: null
|
|
181
|
+
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "chatView", [_dec5], {
|
|
103
182
|
configurable: true,
|
|
104
183
|
enumerable: true,
|
|
105
184
|
writable: true,
|
|
106
185
|
initializer: null
|
|
107
|
-
}),
|
|
186
|
+
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "isDisplay", [_dec6], {
|
|
108
187
|
configurable: true,
|
|
109
188
|
enumerable: true,
|
|
110
189
|
writable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-output-model.d.ts","sourceRoot":"","sources":["../src/error-output-model.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,gBAAgB,EAIjB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"error-output-model.d.ts","sourceRoot":"","sources":["../src/error-output-model.tsx"],"names":[],"mappings":";AAEA,OAAO,EACL,gBAAgB,EAIjB,MAAM,wBAAwB,CAAC;AAOhC,OAAO,cAAc,CAAC;AAmFtB,qBAEa,kBAAmB,SAAQ,gBAAgB;IAC7C,IAAI,2FAA4B;IACjC,QAAQ,UAAS;CAC1B"}
|
package/es/error-output-model.js
CHANGED
|
@@ -22,11 +22,13 @@ import { concatMultilineString } from '@difizen/libro-jupyter';
|
|
|
22
22
|
import { ErrorOutputModel, defaultSanitizer, RenderMimeRegistry, renderText } from '@difizen/libro-jupyter';
|
|
23
23
|
import { prop, transient } from '@difizen/mana-app';
|
|
24
24
|
import { getOrigin, useInject, view, ViewInstance } from '@difizen/mana-app';
|
|
25
|
+
import { l10n } from '@difizen/mana-l10n';
|
|
25
26
|
import { Button } from 'antd';
|
|
26
27
|
import { forwardRef, createRef, useEffect } from 'react';
|
|
27
28
|
import "./index.less";
|
|
28
29
|
import { LibroAINativeService } from "./ai-native-service.js";
|
|
29
30
|
import { AIIcon } from "./icon.js";
|
|
31
|
+
import { addCellAIClassname } from "./utils.js";
|
|
30
32
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
33
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
34
|
var AIErrorOutputModelRender = /*#__PURE__*/forwardRef(function ErrorOutputModelRender(_props, ref) {
|
|
@@ -56,15 +58,16 @@ var AIErrorOutputModelRender = /*#__PURE__*/forwardRef(function ErrorOutputModel
|
|
|
56
58
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
57
59
|
while (1) switch (_context.prev = _context.next) {
|
|
58
60
|
case 0:
|
|
59
|
-
|
|
60
|
-
_context.next = 3;
|
|
61
|
+
_context.next = 2;
|
|
61
62
|
return libroAINativeService.getOrCreateLibroAINativeForCellView(output.cell.id, getOrigin(output.cell));
|
|
62
|
-
case
|
|
63
|
+
case 2:
|
|
63
64
|
libroAINativeForCellView = _context.sent;
|
|
65
|
+
addCellAIClassname(output.cell);
|
|
64
66
|
libroAINativeForCellView.showAI = true;
|
|
65
67
|
libroAINativeForCellView.chatStream({
|
|
66
|
-
chat_key: 'LLM:debug
|
|
67
|
-
content: "\u4EE3\u7801\u4E3A:\n".concat(output.cell.model.value, "\n\u62A5\u9519\u4E3A:\n").concat(concatMultilineString(source.traceback))
|
|
68
|
+
chat_key: 'LLM:debug',
|
|
69
|
+
content: "\u4EE3\u7801\u4E3A:\n".concat(output.cell.model.value, "\n\u62A5\u9519\u4E3A:\n").concat(concatMultilineString(source.traceback)),
|
|
70
|
+
language: l10n.getLang()
|
|
68
71
|
});
|
|
69
72
|
case 6:
|
|
70
73
|
case "end":
|
package/es/index.less
CHANGED
|
@@ -46,9 +46,13 @@
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
.libro-
|
|
50
|
-
|
|
49
|
+
.libro-ai-native-cell-chat-icon {
|
|
50
|
+
svg {
|
|
51
|
+
color: var(--mana-libro-ai-native-color);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
51
54
|
|
|
55
|
+
.libro-view-content-right {
|
|
52
56
|
.libro-slot-container {
|
|
53
57
|
height: 100%;
|
|
54
58
|
}
|
|
@@ -70,7 +74,8 @@
|
|
|
70
74
|
border: 1px solid var(--mana-libro-ai-native-color);
|
|
71
75
|
box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
|
|
72
76
|
border-radius: 6px;
|
|
73
|
-
|
|
77
|
+
margin: 16px 0;
|
|
78
|
+
height: calc(100% - 32px);
|
|
74
79
|
width: 460px;
|
|
75
80
|
|
|
76
81
|
.chat {
|
|
@@ -86,11 +91,21 @@
|
|
|
86
91
|
cursor: pointer;
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
.chat-input-upload {
|
|
95
|
+
display: none;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.chat-input-iconBottom {
|
|
99
|
+
align-items: center;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
}
|
|
102
|
+
|
|
89
103
|
.chat-input-searchInput:focus-within {
|
|
90
104
|
border-color: var(--mana-libro-ai-native-color);
|
|
91
105
|
}
|
|
92
106
|
|
|
93
107
|
.chat-input-sendButton {
|
|
108
|
+
margin: unset;
|
|
94
109
|
background-color: var(--mana-libro-ai-native-color);
|
|
95
110
|
}
|
|
96
111
|
|
|
@@ -107,36 +122,39 @@
|
|
|
107
122
|
}
|
|
108
123
|
}
|
|
109
124
|
|
|
110
|
-
.ai-cell-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
.libro-dnd-cell:has(.ai-cell-focus) {
|
|
126
|
+
&.active {
|
|
127
|
+
border: 1px solid var(--mana-libro-ai-native-color);
|
|
128
|
+
box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
|
|
129
|
+
|
|
130
|
+
.libro-cell-input-collapser,
|
|
131
|
+
.libro-cell-output-collapser,
|
|
132
|
+
.libro-cell-collapser {
|
|
133
|
+
background: var(--mana-libro-ai-native-color);
|
|
134
|
+
opacity: 1;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
&.error {
|
|
113
138
|
border: 1px solid var(--mana-libro-ai-native-color);
|
|
114
139
|
box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
115
142
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
background: var(--mana-libro-ai-native-color);
|
|
120
|
-
opacity: 1;
|
|
121
|
-
}
|
|
143
|
+
&.error {
|
|
144
|
+
border: 1px solid var(--mana-libro-ai-native-color);
|
|
145
|
+
box-shadow: var(--mana-libro-ai-native-box-shadow) 0 0 0 2px;
|
|
122
146
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
.libro-cell-output-collapser,
|
|
129
|
-
.libro-cell-collapser {
|
|
130
|
-
background: var(--mana-libro-ai-native-color);
|
|
131
|
-
opacity: 1;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
147
|
+
.libro-cell-input-collapser,
|
|
148
|
+
.libro-cell-output-collapser,
|
|
149
|
+
.libro-cell-collapser {
|
|
150
|
+
background: var(--mana-libro-ai-native-color);
|
|
151
|
+
opacity: 1;
|
|
134
152
|
}
|
|
153
|
+
}
|
|
135
154
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
155
|
+
&.active.command-mode {
|
|
156
|
+
border: 1px solid var(--mana-libro-ai-native-color);
|
|
157
|
+
box-shadow: unset;
|
|
140
158
|
}
|
|
141
159
|
}
|
|
142
160
|
|
|
@@ -170,6 +188,16 @@
|
|
|
170
188
|
&:hover {
|
|
171
189
|
border-color: var(--mana-libro-ai-native-color) !important;
|
|
172
190
|
color: var(--mana-libro-ai-native-color) !important;
|
|
191
|
+
|
|
192
|
+
&.error {
|
|
193
|
+
border-color: var(--mana-libro-error-color) !important;
|
|
194
|
+
color: var(--mana-libro-error-color) !important;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
&.error {
|
|
199
|
+
border-color: var(--mana-libro-error-color);
|
|
200
|
+
color: var(--mana-libro-error-color);
|
|
173
201
|
}
|
|
174
202
|
}
|
|
175
203
|
}
|
|
@@ -237,6 +265,7 @@
|
|
|
237
265
|
|
|
238
266
|
.libro-ai-native-for-cell-container {
|
|
239
267
|
display: flex;
|
|
268
|
+
padding-top: 18px;
|
|
240
269
|
justify-content: space-between;
|
|
241
270
|
}
|
|
242
271
|
|
|
@@ -295,3 +324,7 @@
|
|
|
295
324
|
color: var(--mana-libro-editor-class-color);
|
|
296
325
|
}
|
|
297
326
|
}
|
|
327
|
+
|
|
328
|
+
.libro-ai-native-for-cell-error {
|
|
329
|
+
color: var(--mana-libro-error-color);
|
|
330
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-ai-msg-item-model.d.ts","sourceRoot":"","sources":["../src/libro-ai-msg-item-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAI9B,qBACa,2BAA2B;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,kBAAkB,CAAC;IAG3B,KAAK,EAAE,WAAW,CAAC;IAGnB,SAAS,CAAC,QAAQ,SAAM;IACxB,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,CAAC,EAHE,MAGF,EAEZ;IAED,MAAM,EAAE,gBAAgB,CAAC;IAGzB,KAAK,CAAC,EAAE,YAAY,CAAC;gBAEkB,MAAM,EAAE,gBAAgB;IAQ/D,eAAe,CAAC,CAAC,EAAE,UAAU;IAY7B,WAAW,CAAC,CAAC,EAAE,cAAc;IAI7B,YAAY,CAAC,CAAC,EAAE,eAAe;IAK/B,WAAW,CAAC,CAAC,EAAE,cAAc;
|
|
1
|
+
{"version":3,"file":"libro-ai-msg-item-model.d.ts","sourceRoot":"","sources":["../src/libro-ai-msg-item-model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAa,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAI9B,qBACa,2BAA2B;IACtC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,kBAAkB,CAAC;IAG3B,KAAK,EAAE,WAAW,CAAC;IAGnB,SAAS,CAAC,QAAQ,SAAM;IACxB,IAAI,OAAO,IAAI,MAAM,CAEpB;IACD,IAAI,OAAO,CAAC,CAAC,EAHE,MAGF,EAEZ;IAED,MAAM,EAAE,gBAAgB,CAAC;IAGzB,KAAK,CAAC,EAAE,YAAY,CAAC;gBAEkB,MAAM,EAAE,gBAAgB;IAQ/D,eAAe,CAAC,CAAC,EAAE,UAAU;IAY7B,WAAW,CAAC,CAAC,EAAE,cAAc;IAI7B,YAAY,CAAC,CAAC,EAAE,eAAe;IAK/B,WAAW,CAAC,CAAC,EAAE,cAAc;CAI9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-ai-native-chat-service.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AAGxE,qBACa,wBAAyB,SAAQ,gBAAgB;IACnD,IAAI,WACH,kCAAkC,KACzC,QAAQ,gBAAgB,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"libro-ai-native-chat-service.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAIzD,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,eAAe,CAAC;AAGxE,qBACa,wBAAyB,SAAQ,gBAAgB;IACnD,IAAI,WACH,kCAAkC,KACzC,QAAQ,gBAAgB,EAAE,CAAC,CAkB5B;IACO,UAAU,WACT,kCAAkC,0BAClB,gBAAgB,KAAK,IAAI,yBAC1B,UAAU,KAAK,IAAI,mBA0D1C;CACH"}
|
|
@@ -32,14 +32,13 @@ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PU
|
|
|
32
32
|
_this = _super.call.apply(_super, [this].concat(args));
|
|
33
33
|
_this.chat = /*#__PURE__*/function () {
|
|
34
34
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(option) {
|
|
35
|
-
var
|
|
35
|
+
var content, system_prompt, res;
|
|
36
36
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
37
37
|
while (1) switch (_context.prev = _context.next) {
|
|
38
38
|
case 0:
|
|
39
|
-
|
|
39
|
+
content = option.content, system_prompt = option.system_prompt;
|
|
40
40
|
_context.next = 3;
|
|
41
41
|
return _this.fetcher.post("/libro/api/chat", {
|
|
42
|
-
chat_key: chat_key,
|
|
43
42
|
prompt: content,
|
|
44
43
|
system_prompt: system_prompt
|
|
45
44
|
});
|
|
@@ -56,7 +55,7 @@ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PU
|
|
|
56
55
|
return _context.abrupt("return", [{
|
|
57
56
|
sender: {
|
|
58
57
|
type: 'AI',
|
|
59
|
-
id:
|
|
58
|
+
id: 'libro'
|
|
60
59
|
},
|
|
61
60
|
content: res.data.output
|
|
62
61
|
}]);
|
|
@@ -74,14 +73,13 @@ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PU
|
|
|
74
73
|
}();
|
|
75
74
|
_this.chatStream = /*#__PURE__*/function () {
|
|
76
75
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(option, messgeCallback, eventCallback) {
|
|
77
|
-
var
|
|
76
|
+
var content, system_prompt, url, msg, res, reader, stream, alreayDone, _yield$reader$read, value, done, data, _event;
|
|
78
77
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
79
78
|
while (1) switch (_context2.prev = _context2.next) {
|
|
80
79
|
case 0:
|
|
81
|
-
|
|
80
|
+
content = option.content, system_prompt = option.system_prompt;
|
|
82
81
|
url = "/libro/api/chatstream";
|
|
83
82
|
msg = {
|
|
84
|
-
chat_key: chat_key,
|
|
85
83
|
prompt: content,
|
|
86
84
|
system_prompt: system_prompt
|
|
87
85
|
};
|
|
@@ -96,7 +94,7 @@ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PU
|
|
|
96
94
|
case 5:
|
|
97
95
|
res = _context2.sent;
|
|
98
96
|
if (!(res.status === 200)) {
|
|
99
|
-
_context2.next =
|
|
97
|
+
_context2.next = 32;
|
|
100
98
|
break;
|
|
101
99
|
}
|
|
102
100
|
if (typeof res.data === 'string') {
|
|
@@ -108,44 +106,54 @@ export var LibroAINativeChatService = (_dec = singleton(), _dec(_class = /*#__PU
|
|
|
108
106
|
messgeCallback({
|
|
109
107
|
sender: {
|
|
110
108
|
type: 'AI',
|
|
111
|
-
id:
|
|
109
|
+
id: 'libro'
|
|
112
110
|
},
|
|
113
111
|
content: ''
|
|
114
112
|
});
|
|
115
113
|
alreayDone = false;
|
|
116
|
-
|
|
114
|
+
_context2.prev = 10;
|
|
115
|
+
case 11:
|
|
117
116
|
if (alreayDone) {
|
|
118
|
-
_context2.next =
|
|
117
|
+
_context2.next = 26;
|
|
119
118
|
break;
|
|
120
119
|
}
|
|
121
|
-
_context2.next =
|
|
120
|
+
_context2.next = 14;
|
|
122
121
|
return reader.read();
|
|
123
|
-
case
|
|
122
|
+
case 14:
|
|
124
123
|
_yield$reader$read = _context2.sent;
|
|
125
124
|
value = _yield$reader$read.value;
|
|
126
125
|
done = _yield$reader$read.done;
|
|
127
126
|
if (!done) {
|
|
128
|
-
_context2.next =
|
|
127
|
+
_context2.next = 21;
|
|
129
128
|
break;
|
|
130
129
|
}
|
|
131
130
|
alreayDone = true;
|
|
132
131
|
eventCallback({
|
|
133
132
|
type: 'done'
|
|
134
133
|
});
|
|
135
|
-
return _context2.abrupt("break",
|
|
136
|
-
case
|
|
134
|
+
return _context2.abrupt("break", 26);
|
|
135
|
+
case 21:
|
|
137
136
|
data = JSON.parse(value.data);
|
|
138
137
|
_event = ChatEvent.format(value.event || 'chunk', data);
|
|
139
138
|
eventCallback(_event);
|
|
140
|
-
_context2.next =
|
|
139
|
+
_context2.next = 11;
|
|
141
140
|
break;
|
|
142
|
-
case 25:
|
|
143
|
-
return _context2.abrupt("return");
|
|
144
141
|
case 26:
|
|
142
|
+
_context2.next = 31;
|
|
143
|
+
break;
|
|
144
|
+
case 28:
|
|
145
|
+
_context2.prev = 28;
|
|
146
|
+
_context2.t0 = _context2["catch"](10);
|
|
147
|
+
eventCallback({
|
|
148
|
+
type: 'error'
|
|
149
|
+
});
|
|
150
|
+
case 31:
|
|
151
|
+
return _context2.abrupt("return");
|
|
152
|
+
case 32:
|
|
145
153
|
case "end":
|
|
146
154
|
return _context2.stop();
|
|
147
155
|
}
|
|
148
|
-
}, _callee2);
|
|
156
|
+
}, _callee2, null, [[10, 28]]);
|
|
149
157
|
}));
|
|
150
158
|
return function (_x2, _x3, _x4) {
|
|
151
159
|
return _ref2.apply(this, arguments);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import type { LibroView } from '@difizen/libro-jupyter';
|
|
1
|
+
import type { CellView, LibroView } from '@difizen/libro-jupyter';
|
|
2
2
|
import { ChatView } from '@difizen/magent-chat';
|
|
3
3
|
import breaks from 'remark-breaks';
|
|
4
4
|
import remarkGfm from 'remark-gfm';
|
|
5
5
|
import './index.less';
|
|
6
|
+
import type { AiNativeChatViewOption } from './protocol.js';
|
|
6
7
|
import { ImageModal } from './utils.js';
|
|
7
8
|
export declare class LibroAiNativeChatView extends ChatView {
|
|
8
9
|
isCellChat: boolean;
|
|
9
10
|
libro?: LibroView;
|
|
11
|
+
cell?: CellView;
|
|
12
|
+
constructor(option: AiNativeChatViewOption);
|
|
10
13
|
getMarkdownProps(): {
|
|
11
14
|
components: {
|
|
12
15
|
code: (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libro-ai-native-chat-view.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"libro-ai-native-chat-view.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-chat-view.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,OAAO,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAIxC,qBAEa,qBAAsB,SAAQ,QAAQ;IAEjD,UAAU,UAAS;IAEnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,IAAI,CAAC,EAAE,QAAQ,CAAC;gBAEgB,MAAM,EAAE,sBAAsB;IAMrD,gBAAgB;;;;;;;cAON,eAAe,CAAC,UAAU,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;CAiBtD"}
|
|
@@ -19,28 +19,26 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
19
19
|
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; }
|
|
20
20
|
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.'); }
|
|
21
21
|
import { ChatView } from '@difizen/magent-chat';
|
|
22
|
-
import { prop, transient, view } from '@difizen/mana-app';
|
|
22
|
+
import { inject, prop, transient, view, ViewOption } from '@difizen/mana-app';
|
|
23
23
|
import breaks from 'remark-breaks';
|
|
24
24
|
import remarkGfm from 'remark-gfm';
|
|
25
25
|
import { CodeBlockInChat } from "./ai-native-code-block.js";
|
|
26
26
|
import "./index.less";
|
|
27
27
|
import { ImageModal } from "./utils.js";
|
|
28
|
-
// import { ImageModal } from './utils.js';
|
|
29
|
-
|
|
30
28
|
var viewId = 'magent-chat';
|
|
31
29
|
export var LibroAiNativeChatView = (_dec = transient(), _dec2 = view(viewId), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_ChatView) {
|
|
32
30
|
_inherits(LibroAiNativeChatView, _ChatView);
|
|
33
31
|
var _super = _createSuper(LibroAiNativeChatView);
|
|
34
|
-
function LibroAiNativeChatView() {
|
|
32
|
+
function LibroAiNativeChatView(option) {
|
|
35
33
|
var _this;
|
|
36
34
|
_classCallCheck(this, LibroAiNativeChatView);
|
|
37
|
-
|
|
38
|
-
args[_key] = arguments[_key];
|
|
39
|
-
}
|
|
40
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
35
|
+
_this = _super.call(this, option);
|
|
41
36
|
_initializerDefineProperty(_this, "isCellChat", _descriptor, _assertThisInitialized(_this));
|
|
37
|
+
_this.option = option;
|
|
38
|
+
_this.isCellChat = option.isCellChat;
|
|
42
39
|
return _this;
|
|
43
40
|
}
|
|
41
|
+
LibroAiNativeChatView = inject(ViewOption)(LibroAiNativeChatView, undefined, 0) || LibroAiNativeChatView;
|
|
44
42
|
_createClass(LibroAiNativeChatView, [{
|
|
45
43
|
key: "getMarkdownProps",
|
|
46
44
|
value: function getMarkdownProps() {
|
|
@@ -56,7 +54,7 @@ export var LibroAiNativeChatView = (_dec = transient(), _dec2 = view(viewId), _d
|
|
|
56
54
|
key: "toMessageOption",
|
|
57
55
|
value: function toMessageOption(msgContent) {
|
|
58
56
|
if (this.isCellChat) {
|
|
59
|
-
var _this$
|
|
57
|
+
var _this$cell;
|
|
60
58
|
return _objectSpread(_objectSpread({
|
|
61
59
|
stream: true
|
|
62
60
|
}, this.option), {}, {
|
|
@@ -64,7 +62,7 @@ export var LibroAiNativeChatView = (_dec = transient(), _dec2 = view(viewId), _d
|
|
|
64
62
|
type: 'HUMAN'
|
|
65
63
|
},
|
|
66
64
|
input: msgContent,
|
|
67
|
-
system_prompt: "\u6709\u5982\u4E0B\u7684\u4EE3\u7801\u4F5C\u4E3A\u5BF9\u8BDD\u7684\u4E0A\u4E0B\u6587\uFF1A".concat((_this$
|
|
65
|
+
system_prompt: "\u6709\u5982\u4E0B\u7684\u4EE3\u7801\u4F5C\u4E3A\u5BF9\u8BDD\u7684\u4E0A\u4E0B\u6587\uFF1A".concat((_this$cell = this.cell) === null || _this$cell === void 0 ? void 0 : _this$cell.model.value)
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
68
|
return _objectSpread(_objectSpread({
|
package/es/protocol.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { CellView } from '@difizen/libro-jupyter';
|
|
2
|
-
import type { IChatMessageItem } from '@difizen/magent-chat';
|
|
2
|
+
import type { ChatViewOption, IChatMessageItem } from '@difizen/magent-chat';
|
|
3
3
|
export interface IAINativeForCellViewOption {
|
|
4
4
|
cell: CellView;
|
|
5
5
|
[key: string]: any;
|
|
6
6
|
}
|
|
7
7
|
export interface LibroAINativeChatMessageItemOption extends IChatMessageItem {
|
|
8
|
-
chat_key
|
|
8
|
+
chat_key?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AiNativeChatViewOption extends ChatViewOption {
|
|
11
|
+
id: string;
|
|
12
|
+
chat_key?: string;
|
|
13
|
+
isCellChat: boolean;
|
|
14
|
+
cell?: CellView;
|
|
9
15
|
}
|
|
10
16
|
//# sourceMappingURL=protocol.d.ts.map
|
package/es/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,kCAAmC,SAAQ,gBAAgB;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAuB,SAAQ,cAAc;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB"}
|
package/es/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CellView } from '@difizen/libro-jupyter';
|
|
2
|
+
export declare function stringToReadableStream(inputString: string): ReadableStream<any>;
|
|
3
|
+
export declare function addCellAIClassname(cell: CellView): void;
|
|
4
|
+
export declare function cancelCellAIClassname(cell: CellView): void;
|
|
5
|
+
export declare function ImageModal({ src, alt }: any): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAKvD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,uBAgBzD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,QAMhD;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,QAInD;AAED,wBAAgB,UAAU,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,2CA6E3C"}
|
package/es/utils.js
CHANGED
|
@@ -25,6 +25,21 @@ export function stringToReadableStream(inputString) {
|
|
|
25
25
|
});
|
|
26
26
|
return readableStream;
|
|
27
27
|
}
|
|
28
|
+
export function addCellAIClassname(cell) {
|
|
29
|
+
var _cell$className;
|
|
30
|
+
if ((_cell$className = cell.className) !== null && _cell$className !== void 0 && _cell$className.includes('ai-cell-focus')) {
|
|
31
|
+
return;
|
|
32
|
+
} else {
|
|
33
|
+
cell.className = cell.className + ' ai-cell-focus';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function cancelCellAIClassname(cell) {
|
|
37
|
+
var _cell$className2;
|
|
38
|
+
if ((_cell$className2 = cell.className) !== null && _cell$className2 !== void 0 && _cell$className2.includes(' ai-cell-focus')) {
|
|
39
|
+
var _cell$className3;
|
|
40
|
+
cell.className = (_cell$className3 = cell.className) === null || _cell$className3 === void 0 ? void 0 : _cell$className3.replace(' ai-cell-focus', '');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
28
43
|
export function ImageModal(_ref) {
|
|
29
44
|
var src = _ref.src,
|
|
30
45
|
alt = _ref.alt;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@difizen/libro-ai-native",
|
|
3
|
-
"version": "0.2.41-next.
|
|
3
|
+
"version": "0.2.41-next.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"libro",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"src"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@difizen/libro-jupyter": "
|
|
35
|
+
"@difizen/libro-jupyter": "0.2.41-next.3",
|
|
36
36
|
"@ant-design/icons": "^5.4.0",
|
|
37
37
|
"react-zoom-pan-pinch": "^3.6.1",
|
|
38
38
|
"@difizen/mana-app": "latest",
|