@difizen/libro-ai-native 0.2.41-next.0

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/es/ai-native-code-block.d.ts +4 -0
  4. package/es/ai-native-code-block.d.ts.map +1 -0
  5. package/es/ai-native-code-block.js +176 -0
  6. package/es/ai-native-command-contribution.d.ts +16 -0
  7. package/es/ai-native-command-contribution.d.ts.map +1 -0
  8. package/es/ai-native-command-contribution.js +297 -0
  9. package/es/ai-native-command.d.ts +5 -0
  10. package/es/ai-native-command.d.ts.map +1 -0
  11. package/es/ai-native-command.js +17 -0
  12. package/es/ai-native-for-cell-view.d.ts +20 -0
  13. package/es/ai-native-for-cell-view.d.ts.map +1 -0
  14. package/es/ai-native-for-cell-view.js +190 -0
  15. package/es/ai-native-output-top.d.ts +6 -0
  16. package/es/ai-native-output-top.d.ts.map +1 -0
  17. package/es/ai-native-output-top.js +37 -0
  18. package/es/ai-native-service.d.ts +13 -0
  19. package/es/ai-native-service.d.ts.map +1 -0
  20. package/es/ai-native-service.js +75 -0
  21. package/es/ai-side-toolbar-selector.d.ts +3 -0
  22. package/es/ai-side-toolbar-selector.d.ts.map +1 -0
  23. package/es/ai-side-toolbar-selector.js +47 -0
  24. package/es/chat-slot-contribution.d.ts +15 -0
  25. package/es/chat-slot-contribution.d.ts.map +1 -0
  26. package/es/chat-slot-contribution.js +71 -0
  27. package/es/chat-view.d.ts +15 -0
  28. package/es/chat-view.d.ts.map +1 -0
  29. package/es/chat-view.js +114 -0
  30. package/es/error-output-model.d.ts +8 -0
  31. package/es/error-output-model.d.ts.map +1 -0
  32. package/es/error-output-model.js +140 -0
  33. package/es/icon.d.ts +4 -0
  34. package/es/icon.d.ts.map +1 -0
  35. package/es/icon.js +92 -0
  36. package/es/index.d.ts +6 -0
  37. package/es/index.d.ts.map +1 -0
  38. package/es/index.js +5 -0
  39. package/es/index.less +297 -0
  40. package/es/libro-ai-msg-item-model.d.ts +18 -0
  41. package/es/libro-ai-msg-item-model.d.ts.map +1 -0
  42. package/es/libro-ai-msg-item-model.js +85 -0
  43. package/es/libro-ai-native-chat-service.d.ts +8 -0
  44. package/es/libro-ai-native-chat-service.d.ts.map +1 -0
  45. package/es/libro-ai-native-chat-service.js +157 -0
  46. package/es/libro-ai-native-chat-view.d.ts +42 -0
  47. package/es/libro-ai-native-chat-view.d.ts.map +1 -0
  48. package/es/libro-ai-native-chat-view.js +88 -0
  49. package/es/libro-ai-native-color-registry.d.ts +6 -0
  50. package/es/libro-ai-native-color-registry.d.ts.map +1 -0
  51. package/es/libro-ai-native-color-registry.js +46 -0
  52. package/es/module.d.ts +3 -0
  53. package/es/module.d.ts.map +1 -0
  54. package/es/module.js +28 -0
  55. package/es/protocol.d.ts +10 -0
  56. package/es/protocol.d.ts.map +1 -0
  57. package/es/protocol.js +1 -0
  58. package/es/utils.js +114 -0
  59. package/package.json +74 -0
  60. package/src/ai-native-code-block.tsx +138 -0
  61. package/src/ai-native-command-contribution.tsx +248 -0
  62. package/src/ai-native-command.ts +23 -0
  63. package/src/ai-native-for-cell-view.tsx +156 -0
  64. package/src/ai-native-output-top.tsx +43 -0
  65. package/src/ai-native-service.ts +39 -0
  66. package/src/ai-side-toolbar-selector.tsx +51 -0
  67. package/src/chat-slot-contribution.ts +36 -0
  68. package/src/chat-view.tsx +141 -0
  69. package/src/error-output-model.tsx +103 -0
  70. package/src/icon.tsx +80 -0
  71. package/src/index.less +330 -0
  72. package/src/index.spec.ts +8 -0
  73. package/src/index.ts +5 -0
  74. package/src/libro-ai-msg-item-model.ts +69 -0
  75. package/src/libro-ai-native-chat-service.ts +95 -0
  76. package/src/libro-ai-native-chat-view.tsx +54 -0
  77. package/src/libro-ai-native-color-registry.ts +33 -0
  78. package/src/module.ts +44 -0
  79. package/src/protocol.ts +18 -0
  80. package/src/utils.tsx +115 -0
@@ -0,0 +1,88 @@
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, _class, _class2, _descriptor;
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ 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); }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ 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
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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
+ 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
+ import { ChatView } from '@difizen/magent-chat';
22
+ import { prop, transient, view } from '@difizen/mana-app';
23
+ import breaks from 'remark-breaks';
24
+ import remarkGfm from 'remark-gfm';
25
+ import { CodeBlockInChat } from "./ai-native-code-block.js";
26
+ import "./index.less";
27
+ import { ImageModal } from "./utils.js";
28
+ // import { ImageModal } from './utils.js';
29
+
30
+ var viewId = 'magent-chat';
31
+ export var LibroAiNativeChatView = (_dec = transient(), _dec2 = view(viewId), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_ChatView) {
32
+ _inherits(LibroAiNativeChatView, _ChatView);
33
+ var _super = _createSuper(LibroAiNativeChatView);
34
+ function LibroAiNativeChatView() {
35
+ var _this;
36
+ _classCallCheck(this, LibroAiNativeChatView);
37
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
38
+ args[_key] = arguments[_key];
39
+ }
40
+ _this = _super.call.apply(_super, [this].concat(args));
41
+ _initializerDefineProperty(_this, "isCellChat", _descriptor, _assertThisInitialized(_this));
42
+ return _this;
43
+ }
44
+ _createClass(LibroAiNativeChatView, [{
45
+ key: "getMarkdownProps",
46
+ value: function getMarkdownProps() {
47
+ return {
48
+ components: {
49
+ code: CodeBlockInChat,
50
+ img: ImageModal
51
+ },
52
+ remarkPlugins: [remarkGfm, breaks]
53
+ };
54
+ }
55
+ }, {
56
+ key: "toMessageOption",
57
+ value: function toMessageOption(msgContent) {
58
+ if (this.isCellChat) {
59
+ var _this$libro;
60
+ return _objectSpread(_objectSpread({
61
+ stream: true
62
+ }, this.option), {}, {
63
+ sender: {
64
+ type: 'HUMAN'
65
+ },
66
+ input: msgContent,
67
+ system_prompt: "\u6709\u5982\u4E0B\u7684\u4EE3\u7801\u4F5C\u4E3A\u5BF9\u8BDD\u7684\u4E0A\u4E0B\u6587\uFF1A".concat((_this$libro = this.libro) === null || _this$libro === void 0 || (_this$libro = _this$libro.activeCell) === null || _this$libro === void 0 ? void 0 : _this$libro.model.value)
68
+ });
69
+ }
70
+ return _objectSpread(_objectSpread({
71
+ stream: true
72
+ }, this.option), {}, {
73
+ sender: {
74
+ type: 'HUMAN'
75
+ },
76
+ input: msgContent
77
+ });
78
+ }
79
+ }]);
80
+ return LibroAiNativeChatView;
81
+ }(ChatView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "isCellChat", [_dec3], {
82
+ configurable: true,
83
+ enumerable: true,
84
+ writable: true,
85
+ initializer: function initializer() {
86
+ return false;
87
+ }
88
+ })), _class2)) || _class) || _class);
@@ -0,0 +1,6 @@
1
+ import type { ColorRegistry } from '@difizen/mana-app';
2
+ import { ColorContribution } from '@difizen/mana-app';
3
+ export declare class LibroAINativeColorRegistry implements ColorContribution {
4
+ registerColors(colors: ColorRegistry): void;
5
+ }
6
+ //# sourceMappingURL=libro-ai-native-color-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libro-ai-native-color-registry.d.ts","sourceRoot":"","sources":["../src/libro-ai-native-color-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAa,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEjE,qBACa,0BAA2B,YAAW,iBAAiB;IAClE,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;CA0B5C"}
@@ -0,0 +1,46 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _dec, _class;
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ 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
+ 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
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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
+ import { Color } from '@difizen/mana-app';
9
+ import { singleton, ColorContribution } from '@difizen/mana-app';
10
+ export var LibroAINativeColorRegistry = (_dec = singleton({
11
+ contrib: ColorContribution
12
+ }), _dec(_class = /*#__PURE__*/function () {
13
+ function LibroAINativeColorRegistry() {
14
+ _classCallCheck(this, LibroAINativeColorRegistry);
15
+ }
16
+ _createClass(LibroAINativeColorRegistry, [{
17
+ key: "registerColors",
18
+ value: function registerColors(colors) {
19
+ colors.register(
20
+ // #region antd variable
21
+ {
22
+ id: 'libro.ai.native.color',
23
+ defaults: {
24
+ dark: '#bd74e8',
25
+ light: '#bd74e8'
26
+ },
27
+ description: ''
28
+ }, {
29
+ id: 'libro.ai.native.box.shadow',
30
+ defaults: {
31
+ dark: Color.rgba(203, 146, 197, 0.37),
32
+ light: Color.rgba(203, 146, 197, 0.37)
33
+ },
34
+ description: ''
35
+ }, {
36
+ id: 'libro.ai.native.btn.hover.color',
37
+ defaults: {
38
+ dark: Color.rgba(255, 255, 255, 0.2),
39
+ light: Color.rgba(0, 10, 26, 0.16)
40
+ },
41
+ description: ''
42
+ });
43
+ }
44
+ }]);
45
+ return LibroAINativeColorRegistry;
46
+ }()) || _class);
package/es/module.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ManaModule } from '@difizen/mana-app';
2
+ export declare const LibroAINativeModule: ManaModule;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAc/C,eAAO,MAAM,mBAAmB,YA0BJ,CAAC"}
package/es/module.js ADDED
@@ -0,0 +1,28 @@
1
+ import { CellOutputTopProvider, ErrorOutputModel } from '@difizen/libro-jupyter';
2
+ import { ChatView } from '@difizen/magent-chat';
3
+ import { LibroChatModule, LibroChatService } from '@difizen/magent-libro';
4
+ import { ManaModule } from '@difizen/mana-app';
5
+ import { LibroAINativeCommandContribution } from "./ai-native-command-contribution.js";
6
+ import { LibroAINativeForCellView } from "./ai-native-for-cell-view.js";
7
+ import { LibroAINativeCellTopBlank } from "./ai-native-output-top.js";
8
+ import { LibroAINativeService } from "./ai-native-service.js";
9
+ import { LibroAIChatSlotContribution } from "./chat-slot-contribution.js";
10
+ import { LibroChatView } from "./chat-view.js";
11
+ import { AIErrorOutputModel } from "./error-output-model.js";
12
+ import { LibroAIChatMessageItemModel } from "./libro-ai-msg-item-model.js";
13
+ import { LibroAINativeChatService } from "./libro-ai-native-chat-service.js";
14
+ import { LibroAiNativeChatView } from "./libro-ai-native-chat-view.js";
15
+ import { LibroAINativeColorRegistry } from "./libro-ai-native-color-registry.js";
16
+ export var LibroAINativeModule = ManaModule.create().register(LibroAINativeColorRegistry, LibroChatView, LibroAIChatSlotContribution, LibroAINativeCommandContribution, LibroAINativeService, LibroAIChatMessageItemModel, LibroAINativeForCellView, {
17
+ token: ErrorOutputModel,
18
+ useClass: AIErrorOutputModel
19
+ }, {
20
+ token: ChatView,
21
+ useClass: LibroAiNativeChatView
22
+ }, {
23
+ token: LibroChatService,
24
+ useClass: LibroAINativeChatService
25
+ }, {
26
+ token: CellOutputTopProvider,
27
+ useValue: LibroAINativeCellTopBlank
28
+ }).dependOn(LibroChatModule);
@@ -0,0 +1,10 @@
1
+ import type { CellView } from '@difizen/libro-jupyter';
2
+ import type { IChatMessageItem } from '@difizen/magent-chat';
3
+ export interface IAINativeForCellViewOption {
4
+ cell: CellView;
5
+ [key: string]: any;
6
+ }
7
+ export interface LibroAINativeChatMessageItemOption extends IChatMessageItem {
8
+ chat_key: string;
9
+ }
10
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +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;AAE7D,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,EAAE,MAAM,CAAC;CAClB"}
package/es/protocol.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/es/utils.js ADDED
@@ -0,0 +1,114 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { Modal } from 'antd';
8
+ import { useEffect, useState } from 'react';
9
+ import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ export function stringToReadableStream(inputString) {
13
+ // Convert the string into a Uint8Array
14
+ var encoder = new TextEncoder();
15
+ var uint8Array = encoder.encode(inputString);
16
+
17
+ // Create a new ReadableStream
18
+ var readableStream = new ReadableStream({
19
+ start: function start(controller) {
20
+ // Enqueue the Uint8Array into the stream
21
+ controller.enqueue(uint8Array);
22
+ // Close the stream
23
+ controller.close();
24
+ }
25
+ });
26
+ return readableStream;
27
+ }
28
+ export function ImageModal(_ref) {
29
+ var src = _ref.src,
30
+ alt = _ref.alt;
31
+ var _useState = useState(false),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ visible = _useState2[0],
34
+ setVisible = _useState2[1];
35
+ var _useState3 = useState({
36
+ width: 0,
37
+ height: 0
38
+ }),
39
+ _useState4 = _slicedToArray(_useState3, 2),
40
+ imageDimensions = _useState4[0],
41
+ setImageDimensions = _useState4[1];
42
+ useEffect(function () {
43
+ var img = new Image();
44
+ img.src = src;
45
+ img.onload = function () {
46
+ setImageDimensions({
47
+ width: img.width,
48
+ height: img.height
49
+ });
50
+ };
51
+ }, [src]);
52
+ var maxModalWidth = window.innerWidth * 0.8; // 80% of the viewport width
53
+ var maxModalHeight = window.innerHeight * 0.8; // 80% of the viewport height
54
+
55
+ var adjustedWidth, adjustedHeight;
56
+ var aspectRatio = imageDimensions.width / imageDimensions.height;
57
+ if (imageDimensions.width > maxModalWidth) {
58
+ adjustedWidth = maxModalWidth;
59
+ adjustedHeight = adjustedWidth / aspectRatio;
60
+ } else if (imageDimensions.height > maxModalHeight) {
61
+ adjustedHeight = maxModalHeight;
62
+ adjustedWidth = adjustedHeight * aspectRatio;
63
+ } else {
64
+ adjustedWidth = imageDimensions.width;
65
+ adjustedHeight = imageDimensions.height;
66
+ }
67
+ return /*#__PURE__*/_jsxs("div", {
68
+ children: [/*#__PURE__*/_jsx("img", {
69
+ src: src,
70
+ alt: alt,
71
+ style: {
72
+ cursor: 'pointer'
73
+ },
74
+ onClick: function onClick() {
75
+ return setVisible(true);
76
+ },
77
+ onLoad: function onLoad() {
78
+ var _document$getElementB;
79
+ // 解决生成图片没有滚动到最下方的问题。
80
+ (_document$getElementB = document.getElementById('chat-main-scroll')) === null || _document$getElementB === void 0 || _document$getElementB.scrollIntoView(false);
81
+ }
82
+ }), /*#__PURE__*/_jsx(Modal, {
83
+ open: visible,
84
+ closeIcon: false,
85
+ footer: null,
86
+ width: adjustedWidth + 30,
87
+ onCancel: function onCancel() {
88
+ return setVisible(false);
89
+ },
90
+ bodyStyle: {
91
+ padding: 0,
92
+ display: 'flex',
93
+ justifyContent: 'center',
94
+ alignItems: 'center',
95
+ height: adjustedHeight
96
+ },
97
+ children: /*#__PURE__*/_jsx(TransformWrapper, {
98
+ initialScale: 1,
99
+ initialPositionX: 0,
100
+ initialPositionY: 0,
101
+ children: /*#__PURE__*/_jsx(TransformComponent, {
102
+ children: /*#__PURE__*/_jsx("img", {
103
+ src: src,
104
+ alt: alt,
105
+ style: {
106
+ width: '100%',
107
+ height: '100%'
108
+ }
109
+ })
110
+ })
111
+ })
112
+ })]
113
+ });
114
+ }
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@difizen/libro-ai-native",
3
+ "version": "0.2.41-next.0",
4
+ "description": "",
5
+ "keywords": [
6
+ "libro",
7
+ "ai-native"
8
+ ],
9
+ "repository": "git@github.com:difizen/libro.git",
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "typings": "./es/index.d.ts",
15
+ "default": "./es/index.js"
16
+ },
17
+ "./mock": {
18
+ "typings": "./es/mock/index.d.ts",
19
+ "default": "./es/mock/index.js"
20
+ },
21
+ "./es/mock": {
22
+ "typings": "./es/mock/index.d.ts",
23
+ "default": "./es/mock/index.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "main": "es/index.js",
28
+ "module": "es/index.js",
29
+ "typings": "es/index.d.ts",
30
+ "files": [
31
+ "es",
32
+ "src"
33
+ ],
34
+ "dependencies": {
35
+ "@difizen/libro-jupyter": "^0.2.41-next.0",
36
+ "@ant-design/icons": "^5.4.0",
37
+ "react-zoom-pan-pinch": "^3.6.1",
38
+ "@difizen/mana-app": "latest",
39
+ "@difizen/mana-l10n": "latest",
40
+ "@difizen/magent-libro": "^0.1.27",
41
+ "@difizen/magent-chat": "^0.1.27",
42
+ "@difizen/magent-core": "^0.1.27",
43
+ "copy-to-clipboard": "^3.3.3",
44
+ "eventsource-parser": "^1.1.2",
45
+ "react-syntax-highlighter": "^15.5.0",
46
+ "markdown-it": "^13.0.1",
47
+ "remark-breaks": "^4.0.0",
48
+ "remark-gfm": "^4.0.0",
49
+ "uuid": "^9.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "antd": "^5.8.6",
53
+ "react": ">=16"
54
+ },
55
+ "devDependencies": {
56
+ "@types/react": "^18.2.25",
57
+ "@types/react-syntax-highlighter": "^15.5.13",
58
+ "@types/sanitize-html": "^2.6.2",
59
+ "@types/uuid": "^9.0.2"
60
+ },
61
+ "scripts": {
62
+ "setup": "father build",
63
+ "build": "father build",
64
+ "test": ": Note: lint task is delegated to test:* scripts",
65
+ "test:vitest": "vitest run",
66
+ "test:jest": "jest",
67
+ "coverage": ": Note: lint task is delegated to coverage:* scripts",
68
+ "coverage:vitest": "vitest run --coverage",
69
+ "coverage:jest": "jest --coverage",
70
+ "lint": ": Note: lint task is delegated to lint:* scripts",
71
+ "lint:eslint": "eslint src",
72
+ "typecheck:tsc": "tsc --noEmit"
73
+ }
74
+ }
@@ -0,0 +1,138 @@
1
+ import { CopyOutlined } from '@ant-design/icons';
2
+ import { LibroCodeCellView } from '@difizen/libro-jupyter';
3
+ import { useInject, ViewInstance } from '@difizen/mana-app';
4
+ import { l10n } from '@difizen/mana-l10n';
5
+ import { Button, message } from 'antd';
6
+ import copy from 'copy-to-clipboard';
7
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
8
+ import { v4 } from 'uuid';
9
+
10
+ import './index.less';
11
+ import type { LibroAINativeForCellView } from './ai-native-for-cell-view.js';
12
+ import type { LibroAiNativeChatView } from './libro-ai-native-chat-view.js';
13
+
14
+ export const CodeBlockInCell = (props: any) => {
15
+ const { className, children } = props;
16
+ const instance = useInject<LibroAINativeForCellView>(ViewInstance);
17
+ const cell = instance.cell;
18
+
19
+ const replace = (data: any) => {
20
+ if (cell instanceof LibroCodeCellView && cell.editor) {
21
+ const length = cell.editor.model.value.length;
22
+ const start = cell.editor.getPositionAt(0);
23
+ const end = cell.editor.getPositionAt(length);
24
+ if (start && end) {
25
+ cell.editor.replaceSelection(data, {
26
+ start,
27
+ end,
28
+ });
29
+ }
30
+ }
31
+ };
32
+
33
+ if (!props.inline && className) {
34
+ const [, lang] = /language-(\w+)/.exec(className || '') || [];
35
+
36
+ return (
37
+ <pre className={`chat-msg-md-code-wrap`}>
38
+ {lang && <div className={`chat-msg-md-code-lang`}>{lang}</div>}
39
+ <CopyOutlined
40
+ onClick={() => {
41
+ copy(children);
42
+ message.success(l10n.t('代码已复制'));
43
+ }}
44
+ className={`chat-msg-md-code-copy`}
45
+ />
46
+ <SyntaxHighlighter
47
+ className={`libro-llm-syntax-highlighter`}
48
+ language={lang}
49
+ style={{}}
50
+ >
51
+ {typeof children === 'string' ? children.trim() : children}
52
+ </SyntaxHighlighter>
53
+ <div className="libro-ai-native-debug-code-btn-container">
54
+ <Button color="primary" variant="outlined" onClick={() => replace(children)}>
55
+ {l10n.t('替换代码')}
56
+ </Button>
57
+ </div>
58
+ </pre>
59
+ );
60
+ }
61
+
62
+ return <code className={`chat-msg-md-code-code`}>{children}</code>;
63
+ };
64
+
65
+ export const CodeBlockInChat = (props: any) => {
66
+ const { className, children } = props;
67
+ const instance = useInject<LibroAiNativeChatView>(ViewInstance);
68
+ const cell = instance.libro?.activeCell;
69
+
70
+ const insertCell = async (data: any) => {
71
+ const libro = instance.libro;
72
+ if (!libro) {
73
+ return;
74
+ }
75
+ const insertIndex = libro.model.cells.findIndex(
76
+ (c) => c.id === libro.activeCell?.id,
77
+ );
78
+ await libro.addCell(
79
+ {
80
+ id: v4(),
81
+ cell: { cell_type: 'code', source: data, metadata: {} },
82
+ },
83
+ insertIndex + 1,
84
+ );
85
+ };
86
+
87
+ const replace = (data: any) => {
88
+ if (cell instanceof LibroCodeCellView && cell.editor) {
89
+ const length = cell.editor.model.value.length;
90
+ const start = cell.editor.getPositionAt(0);
91
+ const end = cell.editor.getPositionAt(length);
92
+ if (start && end) {
93
+ cell.editor.replaceSelection(data, {
94
+ start,
95
+ end,
96
+ });
97
+ }
98
+ }
99
+ };
100
+
101
+ if (!props.inline && className) {
102
+ const [, lang] = /language-(\w+)/.exec(className || '') || [];
103
+
104
+ return (
105
+ <pre className={`chat-msg-md-code-wrap`}>
106
+ {lang && <div className={`chat-msg-md-code-lang`}>{lang}</div>}
107
+ <CopyOutlined
108
+ onClick={() => {
109
+ copy(children);
110
+ message.success(l10n.t('代码已复制'));
111
+ }}
112
+ className={`chat-msg-md-code-copy`}
113
+ />
114
+ <SyntaxHighlighter
115
+ className={`libro-llm-syntax-highlighter`}
116
+ language={lang}
117
+ style={{}}
118
+ >
119
+ {typeof children === 'string' ? children.trim() : children}
120
+ </SyntaxHighlighter>
121
+ <div className="libro-ai-native-debug-code-btn-container">
122
+ <Button
123
+ color="primary"
124
+ variant="outlined"
125
+ onClick={() => insertCell(children)}
126
+ >
127
+ {l10n.t('插入 Cell')}
128
+ </Button>
129
+ <Button color="primary" variant="outlined" onClick={() => replace(children)}>
130
+ {l10n.t('替换 Cell')}
131
+ </Button>
132
+ </div>
133
+ </pre>
134
+ );
135
+ }
136
+
137
+ return <code className={`chat-msg-md-code-code`}>{children}</code>;
138
+ };