@difizen/libro-ai-native 0.2.41-next.2 → 0.2.41-next.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/es/ai-native-code-block.d.ts.map +1 -1
  2. package/es/ai-native-code-block.js +6 -5
  3. package/es/ai-native-command-contribution.d.ts.map +1 -1
  4. package/es/ai-native-command-contribution.js +60 -15
  5. package/es/ai-native-command.d.ts.map +1 -1
  6. package/es/ai-native-command.js +4 -0
  7. package/es/ai-native-for-cell-view.d.ts.map +1 -1
  8. package/es/ai-native-for-cell-view.js +41 -22
  9. package/es/ai-native-service.d.ts +3 -0
  10. package/es/ai-native-service.d.ts.map +1 -1
  11. package/es/ai-native-service.js +3 -0
  12. package/es/ai-side-toolbar-selector.js +4 -4
  13. package/es/chat-slot-contribution.d.ts.map +1 -1
  14. package/es/chat-slot-contribution.js +1 -2
  15. package/es/chat-view.d.ts +4 -1
  16. package/es/chat-view.d.ts.map +1 -1
  17. package/es/chat-view.js +109 -30
  18. package/es/error-output-model.d.ts.map +1 -1
  19. package/es/error-output-model.js +8 -5
  20. package/es/index.less +60 -27
  21. package/es/libro-ai-msg-item-model.d.ts.map +1 -1
  22. package/es/libro-ai-msg-item-model.js +1 -0
  23. package/es/libro-ai-native-chat-service.d.ts.map +1 -1
  24. package/es/libro-ai-native-chat-service.js +28 -20
  25. package/es/libro-ai-native-chat-view.d.ts +4 -1
  26. package/es/libro-ai-native-chat-view.d.ts.map +1 -1
  27. package/es/libro-ai-native-chat-view.js +8 -10
  28. package/es/protocol.d.ts +8 -2
  29. package/es/protocol.d.ts.map +1 -1
  30. package/es/utils.d.ts +6 -0
  31. package/es/utils.d.ts.map +1 -0
  32. package/es/utils.js +15 -0
  33. package/package.json +2 -2
  34. package/src/ai-native-command-contribution.tsx +10 -6
  35. package/src/ai-native-for-cell-view.tsx +7 -1
  36. package/src/index.less +1 -1
  37. package/src/libro-ai-native-chat-service.ts +9 -2
@@ -1 +1 @@
1
- {"version":3,"file":"ai-native-code-block.d.ts","sourceRoot":"","sources":["../src/ai-native-code-block.tsx"],"names":[],"mappings":"AAQA,OAAO,cAAc,CAAC;AAItB,eAAO,MAAM,eAAe,UAAW,GAAG,4CAiDzC,CAAC;AAEF,eAAO,MAAM,eAAe,UAAW,GAAG,4CAyEzC,CAAC"}
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: "\u66FF\u6362\u4EE3\u7801"
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: "\u63D2\u5165 Cell"
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: "\u66FF\u6362 Cell"
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":"AAAA,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;AAGhF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAG1E,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;IAgBrD,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;CAyJjD"}
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
- group: ['group2'],
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
- libro.model.libroViewClass = 'ai-cell-chat';
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 = 11;
113
+ _context2.next = 12;
103
114
  break;
104
115
  }
105
- chatView.chatView.isCellChat = true;
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 11:
133
+ case 12:
118
134
  //优化交互,用于控制点击按钮后菜单消失
119
135
  _this.libroAINativeService.showSideToolbar = false;
120
- case 12:
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.chatView.isCellChat = false;
184
+ chatView.setAINativeChatView({
185
+ id: libro.id,
186
+ isCellChat: false
187
+ });
163
188
  return _context3.abrupt("return");
164
189
  case 9:
165
- chatView.chatView.isCellChat = false;
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
- libro.model.libroViewClass = 'ai-cell-chat';
250
+ addCellAIClassname(cell);
223
251
  libroAINativeForCellView.chatStream({
224
- chat_key: 'LLM:gpt4',
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['CellChat'], {
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,CAgB3E,CAAC"}
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"}
@@ -13,5 +13,9 @@ export var AINativeCommands = {
13
13
  },
14
14
  AISideToolbarSelect: {
15
15
  id: 'ai-native:side-toolbat-select'
16
+ },
17
+ Optimize: {
18
+ id: 'ai-native:optimize',
19
+ label: 'Optimize'
16
20
  }
17
21
  };
@@ -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;AAQ9D,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAGhE,wBAAgB,0BAA0B,mDAkCzC;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,mBAmDtC;CACH"}
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(LLMRender, {
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
- instance.cell.parent.model.libroViewClass = instance.cell.parent.model.libroViewClass.replace('ai-cell-chat', '');
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: "\u53D6\u6D88"
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 = 27;
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: chat_key
128
+ id: 'libro'
120
129
  },
121
130
  content: ''
122
131
  });
123
132
  _this.libroAIChatMessageItemModel = msgItem;
124
133
  alreayDone = false;
125
- case 11:
134
+ _context.prev = 11;
135
+ case 12:
126
136
  if (alreayDone) {
127
- _context.next = 26;
137
+ _context.next = 27;
128
138
  break;
129
139
  }
130
- _context.next = 14;
140
+ _context.next = 15;
131
141
  return reader.read();
132
- case 14:
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 = 21;
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", 26);
145
- case 21:
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 = 11;
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;AAEpD,qBACa,oBAAoB;IAE/B,eAAe,UAAS;IAExB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAa;IAEpD,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;IAE9C,WAAW,EAAE,WAAW,CAAC;IAEzB,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAa;IAEzE,mCAAmC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ;CAarE"}
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"}
@@ -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['CellChat'].id,
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('AI 对话')
16
+ children: l10n.t('代码解释')
17
17
  })
18
18
  }),
19
19
  group: 'ai'
20
20
  }, {
21
- id: AINativeCommands['Explain'].id,
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,CAYhC;IACF,cAAc;;;MAGZ;CACH"}
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 9:
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
- constructor(viewManager: ViewManager);
16
+ setAINativeChatView(option: AiNativeChatViewOption): Promise<void>;
14
17
  }
15
18
  //# sourceMappingURL=chat-view.d.ts.map
@@ -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;AAI3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAEvE,eAAO,MAAM,UAAU,+CAoDtB,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;IAErC,IAAI,gDAAc;IAG3B,QAAQ,EAAE,qBAAqB,CAAC;IAGhC,SAAS,UAAQ;gBAEgB,WAAW,EAAE,WAAW;CAe1D"}
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"}