UNPKG

@difizen/magent-au

Version:
88 lines (86 loc) 4.14 kB
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; } 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; } 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; } 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 _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); } /* eslint-disable no-unused-vars */ export var AUChatMessageType = { isCreate: function isCreate(data) { return _typeof(data) === 'object' && 'input' in data && !('id' in data); }, isMessageOption: function isMessageOption(data) { return _typeof(data) === 'object' && 'id' in data && 'messages' in data; } }; export var toMessageItem = function toMessageItem(item) { return { sender: { type: item.type === 'ai' ? 'AI' : 'HUMAN' }, content: item.content }; }; export var toMessageOption = function toMessageOption(msg, agentId) { var _msg$message_id, _msg$id; var items = []; if (msg.content) { items = JSON.parse(msg.content); } return { id: ((_msg$message_id = msg.message_id) === null || _msg$message_id === void 0 ? void 0 : _msg$message_id.toString()) || ((_msg$id = msg.id) === null || _msg$id === void 0 ? void 0 : _msg$id.toString()), sessionId: msg.session_id, agentId: agentId, messages: items.map(toMessageItem), created: msg.gmt_created, modified: msg.gmt_modified }; }; export var QuestionState = /*#__PURE__*/function (QuestionState) { QuestionState["SENDING"] = "sending"; QuestionState["VALIDATING"] = "validating"; QuestionState["FAIL"] = "fail"; QuestionState["SUCCESS"] = "success"; return QuestionState; }({}); // 发送完成 // 接收消息状态 export var AnswerState = /*#__PURE__*/function (AnswerState) { AnswerState["WAITING"] = "waiting"; AnswerState["RECEIVING"] = "receiving"; AnswerState["FAIL"] = "fail"; AnswerState["SUCCESS"] = "success"; return AnswerState; }({}); // 发送完成 export var AUChatEvent = { isResult: function isResult(e) { return !!e && e.type === 'result'; }, isStep: function isStep(e) { return !!e && e.type === 'steps'; }, format: function format(e, data) { switch (e) { case 'chunk': return _objectSpread(_objectSpread({}, data), {}, { type: 'chunk' }); case 'result': return _objectSpread(_objectSpread({}, data), {}, { type: 'result' }); case 'steps': return _objectSpread(_objectSpread({}, data), {}, { type: 'steps' }); case 'error': return _objectSpread(_objectSpread({}, data), {}, { type: 'error' }); case 'done': return _objectSpread(_objectSpread({}, data), {}, { type: 'done' }); } return data; } };