UNPKG

@difizen/libro-ai-native

Version:
86 lines 5.35 kB
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); } var _dec, _dec2, _dec3, _dec4, _class, _class2, _descriptor, _descriptor2, _descriptor3; 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 }); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } 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); } 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; } 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.'); } import { AnswerState, ChatEvent } from '@difizen/magent-chat'; import { autoFactory, AutoFactoryOption } from '@difizen/magent-core'; import { inject, prop } from '@difizen/mana-app'; export var LibroAIChatMessageItemModel = (_dec = autoFactory(), _dec2 = prop(), _dec3 = prop(), _dec4 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () { function LibroAIChatMessageItemModel(option) { _classCallCheck(this, LibroAIChatMessageItemModel); _initializerDefineProperty(this, "state", _descriptor, this); _initializerDefineProperty(this, "_content", _descriptor2, this); _initializerDefineProperty(this, "error", _descriptor3, this); if (option.content) { this.state = AnswerState.SUCCESS; } else { this.state = AnswerState.WAITING; } } LibroAIChatMessageItemModel = inject(AutoFactoryOption)(LibroAIChatMessageItemModel, undefined, 0) || LibroAIChatMessageItemModel; _createClass(LibroAIChatMessageItemModel, [{ key: "content", get: function get() { return this._content; }, set: function set(v) { this._content = v; } }, { key: "handleEventData", value: function handleEventData(e) { if (ChatEvent.isChunk(e)) { this.appendChunk(e); } if (ChatEvent.isError(e)) { this.handleError(e); } if (ChatEvent.isResult(e)) { this.handleResult(e); } } }, { key: "appendChunk", value: function appendChunk(e) { this.content = "".concat(this.content).concat(e.output); } }, { key: "handleResult", value: function handleResult(e) { this.content = e.output; this.state = AnswerState.SUCCESS; } }, { key: "handleError", value: function handleError(e) { this.error = { message: e.message }; this.state = AnswerState.FAIL; } }]); return LibroAIChatMessageItemModel; }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "state", [_dec2], { configurable: true, enumerable: true, writable: true, initializer: null }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "_content", [_dec3], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return ''; } }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "error", [_dec4], { configurable: true, enumerable: true, writable: true, initializer: null })), _class2)) || _class);