@myun/gimi-chat 0.1.7 → 0.1.9

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 (32) hide show
  1. package/dist/apis/useApi.d.ts +1 -1
  2. package/dist/apis/useApi.js +3 -3
  3. package/dist/assets/image/addChat.png +0 -0
  4. package/dist/client/components/common-chat/index.d.ts +5 -0
  5. package/dist/client/components/common-chat/index.js +207 -0
  6. package/dist/client/components/common-chat/index.module.css +109 -0
  7. package/dist/client/components/history-list/index.d.ts +5 -0
  8. package/dist/client/components/history-list/index.js +281 -0
  9. package/dist/client/components/history-list/index.module.css +127 -0
  10. package/dist/client/components/new-main/index.css +34 -0
  11. package/dist/client/components/new-main/index.d.ts +4 -0
  12. package/dist/client/components/new-main/index.js +140 -0
  13. package/dist/client/components/slider/index.css +249 -0
  14. package/dist/client/components/slider/index.d.ts +4 -0
  15. package/dist/client/components/slider/index.js +70 -0
  16. package/dist/client/core/chat.d.ts +5 -0
  17. package/dist/client/core/chat.js +109 -0
  18. package/dist/client/core/index.css +17 -0
  19. package/dist/client/core/index.d.ts +3 -0
  20. package/dist/client/core/index.js +10 -0
  21. package/dist/client/index.d.ts +18 -0
  22. package/dist/client/index.js +26 -0
  23. package/dist/components/answer-item/index.js +1 -1
  24. package/dist/components/chat-input/index.js +10 -21
  25. package/dist/components/preset-agent-content/index.module.css +1 -1
  26. package/dist/components/templates/CommonChat.js +19 -4
  27. package/dist/hooks/useChatHistory.js +1 -1
  28. package/dist/hooks/useCommonChatAPI.js +2 -2
  29. package/dist/store/slices/gimiMenuSlice.d.ts +1 -0
  30. package/dist/store/slices/gimiMenuSlice.js +25 -15
  31. package/dist/umd/index.min.js +1 -0
  32. package/package.json +1 -1
@@ -0,0 +1,109 @@
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
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ 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; }
4
+ 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); } }
5
+ 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); }); }; }
6
+ import React, { useEffect } from 'react';
7
+ import Slider from "../components/slider";
8
+ import NewMain from "../components/new-main";
9
+ import "./index.css";
10
+ import useApi from "../../apis/useApi";
11
+ import { Toast } from '@douyinfe/semi-ui';
12
+ import { useAppDispatch, useAppSelector } from "../../store/hooks";
13
+ import { setAgentDetail, setBaseUrl, setToken, setPlatform, setConversationId, getChatHistoryList } from "../../store/slices/gimiMenuSlice";
14
+ import CommonChat from "../../components/templates/CommonChat";
15
+ var Chat = function Chat(props) {
16
+ var _props$ui;
17
+ var _ref = props.chat,
18
+ agentId = _ref.agentId,
19
+ baseUrl = _ref.baseUrl,
20
+ token = _ref.token,
21
+ platform = _ref.platform;
22
+ var conversationId = useAppSelector(function (state) {
23
+ return state.gimiMenu.conversationId;
24
+ });
25
+ var initMsg = useAppSelector(function (state) {
26
+ return state.gimiMenu.initMsg;
27
+ });
28
+ var dispatch = useAppDispatch();
29
+ var _useApi = useApi(baseUrl, token),
30
+ getAgentDetail = _useApi.getAgentDetail;
31
+ var fetchAgentDetail = /*#__PURE__*/function () {
32
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
33
+ var res;
34
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
35
+ while (1) switch (_context.prev = _context.next) {
36
+ case 0:
37
+ _context.prev = 0;
38
+ _context.next = 3;
39
+ return getAgentDetail(agentId);
40
+ case 3:
41
+ res = _context.sent;
42
+ if (res.status === 0) {
43
+ dispatch(setAgentDetail({
44
+ agentDetail: res.result
45
+ }));
46
+ } else {
47
+ Toast.error(res.message);
48
+ }
49
+ _context.next = 10;
50
+ break;
51
+ case 7:
52
+ _context.prev = 7;
53
+ _context.t0 = _context["catch"](0);
54
+ console.log('error', _context.t0);
55
+ case 10:
56
+ case "end":
57
+ return _context.stop();
58
+ }
59
+ }, _callee, null, [[0, 7]]);
60
+ }));
61
+ return function fetchAgentDetail() {
62
+ return _ref2.apply(this, arguments);
63
+ };
64
+ }();
65
+ useEffect(function () {
66
+ dispatch(setBaseUrl({
67
+ baseUrl: baseUrl || ''
68
+ }));
69
+ dispatch(setToken({
70
+ token: token || ''
71
+ }));
72
+ dispatch(setPlatform({
73
+ platform: platform
74
+ }));
75
+ }, [baseUrl, token, platform]);
76
+ useEffect(function () {
77
+ if (agentId) {
78
+ var historyConversationId = localStorage.getItem('historyConversationId');
79
+ console.log('historyConversationId', historyConversationId);
80
+ if (historyConversationId) dispatch(setConversationId({
81
+ conversationId: parseInt(historyConversationId, 10)
82
+ }));
83
+ fetchAgentDetail();
84
+ }
85
+ }, [agentId]);
86
+ return /*#__PURE__*/React.createElement("div", {
87
+ className: "chat-sdk-container"
88
+ }, !!((_props$ui = props.ui) !== null && _props$ui !== void 0 && _props$ui.slider) && /*#__PURE__*/React.createElement(Slider, null), /*#__PURE__*/React.createElement("div", {
89
+ className: "chat-sdk-container-main"
90
+ }, /*#__PURE__*/React.createElement("div", {
91
+ className: "chat-sdk-container-main-content"
92
+ }, conversationId || initMsg ? /*#__PURE__*/React.createElement(CommonChat, _extends({}, props.chat, {
93
+ chatInputConfig: {
94
+ onConversationCreated: function onConversationCreated() {
95
+ dispatch({
96
+ type: 'gimiMenu/setInitMsg',
97
+ payload: {
98
+ initMsg: ''
99
+ }
100
+ });
101
+ dispatch(getChatHistoryList({
102
+ pageIndex: 1,
103
+ pageSize: 50
104
+ }));
105
+ }
106
+ }
107
+ })) : /*#__PURE__*/React.createElement(NewMain, null))));
108
+ };
109
+ export default Chat;
@@ -0,0 +1,17 @@
1
+ .chat-sdk-container {
2
+ display: flex;
3
+ height: 100%;
4
+ overflow-y: hidden;
5
+ }
6
+ .chat-sdk-container .chat-sdk-container-main {
7
+ flex: 1;
8
+ display: flex;
9
+ flex-direction: column;
10
+ }
11
+ .chat-sdk-container .chat-sdk-container-main .chat-sdk-container-main-content {
12
+ flex: 1;
13
+ width: 800px;
14
+ margin: 0 auto;
15
+ padding: 20px;
16
+ height: calc(100% - 40px);
17
+ }
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Index: (props: any) => React.JSX.Element;
3
+ export default Index;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { store } from "../../store";
3
+ import { Provider } from 'react-redux';
4
+ import Chat from "../core/chat";
5
+ var Index = function Index(props) {
6
+ return /*#__PURE__*/React.createElement(Provider, {
7
+ store: store
8
+ }, /*#__PURE__*/React.createElement(Chat, props));
9
+ };
10
+ export default Index;
@@ -0,0 +1,18 @@
1
+ import { CommonChatProps } from '../types/chat';
2
+ export interface Ui {
3
+ slider?: {
4
+ showHistory?: boolean;
5
+ showAddNew?: boolean;
6
+ };
7
+ }
8
+ export interface ChatClientOptions {
9
+ container?: HTMLElement;
10
+ ui?: Ui;
11
+ chat?: CommonChatProps;
12
+ }
13
+ declare class ChatClient {
14
+ private options;
15
+ constructor(options: ChatClientOptions);
16
+ init(): void;
17
+ }
18
+ export default ChatClient;
@@ -0,0 +1,26 @@
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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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 _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 React from 'react';
9
+ import { render } from 'react-dom';
10
+ import Core from "./core";
11
+ var ChatClient = /*#__PURE__*/function () {
12
+ function ChatClient(options) {
13
+ _classCallCheck(this, ChatClient);
14
+ _defineProperty(this, "options", {});
15
+ this.options = options;
16
+ this.init();
17
+ }
18
+ _createClass(ChatClient, [{
19
+ key: "init",
20
+ value: function init() {
21
+ render( /*#__PURE__*/React.createElement(Core, this.options), this.options.container || document.body);
22
+ }
23
+ }]);
24
+ return ChatClient;
25
+ }();
26
+ export default ChatClient;
@@ -138,7 +138,7 @@ var AnswerItem = function AnswerItem(_ref) {
138
138
  onFailure: onFailure
139
139
  }), item.stop === 1 && /*#__PURE__*/React.createElement("div", {
140
140
  className: styles.stop
141
- }, item.vipLevel === 1 && item.reasoningStatus === 3 ? '已停止推理' : '已停止内容输出'), showOperation && /*#__PURE__*/React.createElement("div", {
141
+ }, "\u5DF2\u505C\u6B62"), showOperation && /*#__PURE__*/React.createElement("div", {
142
142
  className: styles.opera
143
143
  }, (showOpera === null || showOpera === void 0 ? void 0 : showOpera(item.id)) && !item.loading && /*#__PURE__*/React.createElement("div", {
144
144
  className: styles.opera_item
@@ -235,7 +235,9 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
235
235
  case 16:
236
236
  res = _context.sent;
237
237
  if (res && res.status === 0) {
238
- dispatch(setConversationId(res.result));
238
+ dispatch(setConversationId({
239
+ conversationId: res.result
240
+ }));
239
241
  (_props$onConversation = props.onConversationCreated) === null || _props$onConversation === void 0 || _props$onConversation.call(props, res.result);
240
242
  setShowChatCommunication(true);
241
243
  } else {
@@ -390,24 +392,8 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
390
392
  }
391
393
  (_props$onHistoryReloa = props.onHistoryReload) === null || _props$onHistoryReloa === void 0 || _props$onHistoryReloa.call(props);
392
394
  };
393
- React.useEffect(function () {
394
- if (messageList.length === 0 && !conversationIdRef.current) {
395
- var defaultContent = transformToInputSlots(props.defaultPrompt || '', props.titleSlot || '');
396
- // 解决 Semi UI AIChatInput setContent 在 useEffect 中触发 flushSync 警告的问题
397
- Promise.resolve().then(function () {
398
- var _inputRef$current7;
399
- (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 || _inputRef$current7.setContent(defaultContent);
400
- });
401
- setHasContent(!!props.defaultPrompt);
402
- preInputValueRef.current = props.defaultPrompt || '';
403
- } else {
404
- Promise.resolve().then(function () {
405
- var _inputRef$current8;
406
- (_inputRef$current8 = inputRef.current) === null || _inputRef$current8 === void 0 || _inputRef$current8.setContent('');
407
- });
408
- setHasContent(false);
409
- }
410
- }, [props.defaultPrompt, messageList.length, props.titleSlot]);
395
+ var defaultContent = transformToInputSlots(props.defaultPrompt || '', props.titleSlot || '');
396
+ var uniqueKey = "".concat(props.placeholder, "-").concat(defaultContent);
411
397
  return /*#__PURE__*/React.createElement("div", {
412
398
  className: styles.inputWrap,
413
399
  ref: inputWrapRef
@@ -416,14 +402,17 @@ var ChatInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
416
402
  stopRecording: stopRecording,
417
403
  containerWidth: inputWidth
418
404
  }) : /*#__PURE__*/React.createElement(AIChatInput, _extends({
419
- ref: inputRef,
405
+ ref: inputRef
406
+ // 为了当 props 变化时,重新渲染 AIChatInput
407
+ ,
408
+ key: uniqueKey,
420
409
  className: styles.chatInput,
421
410
  placeholder: props.placeholder || '',
422
411
  references: [{
423
412
  type: 'text',
424
413
  id: '123'
425
414
  }],
426
- defaultContent: props.showDefaultPrompt || props.titleSlot ? transformToInputSlots(props.defaultPrompt || '', props.titleSlot || '') : '',
415
+ defaultContent: defaultContent,
427
416
  onContentChange: onContentChange
428
417
  // 输入框底部右侧操作区域
429
418
  ,
@@ -3,7 +3,7 @@
3
3
  display: flex;
4
4
  flex-direction: column;
5
5
  align-items: start;
6
- padding: 14px 0px 20px 16px;
6
+ padding: 14px 0px 20px 10px;
7
7
  width: 100%;
8
8
  }
9
9
  .container .prologue {
@@ -61,6 +61,9 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
61
61
  var storedToken = useAppSelector(function (state) {
62
62
  return state.gimiMenu.token;
63
63
  });
64
+ var initMsg = useAppSelector(function (state) {
65
+ return state.gimiMenu.initMsg;
66
+ });
64
67
  var chatUI = useChatUI();
65
68
  var _useChatVoice = useChatVoice(),
66
69
  isRecording = _useChatVoice.isRecording,
@@ -111,9 +114,11 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
111
114
  }));
112
115
  }, [baseUrl, token, platform]);
113
116
  React.useEffect(function () {
114
- dispatch(setConversationId({
115
- conversationId: conversationId || null
116
- }));
117
+ if (conversationId) {
118
+ dispatch(setConversationId({
119
+ conversationId: conversationId
120
+ }));
121
+ }
117
122
  }, [conversationId]);
118
123
  React.useEffect(function () {
119
124
  dispatch(setAgentDetail({
@@ -155,6 +160,16 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
155
160
  }
156
161
  handleSend(val, agent, isSystemAuto);
157
162
  }, [handleSend, startConversationAndChat]);
163
+ React.useEffect(function () {
164
+ if (initMsg) {
165
+ handleInputSend(initMsg);
166
+ }
167
+ }, [initMsg]);
168
+
169
+ // 输入框开头Agent名称
170
+ var showTitleSlot = React.useMemo(function () {
171
+ return messageList.length > 0 || (agentObj === null || agentObj === void 0 ? void 0 : agentObj.showNameStatus) !== 1 ? '' : (agentObj === null || agentObj === void 0 ? void 0 : agentObj.showName) || '';
172
+ }, [messageList, agentObj]);
158
173
  return /*#__PURE__*/React.createElement("div", {
159
174
  className: styles.main,
160
175
  id: "myun_gimi_design_chat"
@@ -203,7 +218,7 @@ var CommonChat = /*#__PURE__*/React.forwardRef(function (props, ref) {
203
218
  disabled: disableSend || isMoreLoading,
204
219
  placeholder: (agentObj === null || agentObj === void 0 ? void 0 : agentObj.inputPrompt) || '',
205
220
  defaultPrompt: messageList.length > 0 ? '' : (agentObj === null || agentObj === void 0 ? void 0 : agentObj.defaultPrompt) || '',
206
- titleSlot: messageList.length > 0 ? '' : (agentObj === null || agentObj === void 0 ? void 0 : agentObj.agentName) || '',
221
+ titleSlot: showTitleSlot,
207
222
  showDefaultPrompt: messageList.length === 0
208
223
  // onContentChange={onInputValueChange}
209
224
  ,
@@ -235,7 +235,7 @@ var useChatHistory = function useChatHistory(checkUnfinishedMessage, scrollBotto
235
235
  return _context.stop();
236
236
  }
237
237
  }, _callee, null, [[5, 40]]);
238
- })), [conversationId]);
238
+ })), []);
239
239
  return {
240
240
  getContentMessageList: getContentMessageList,
241
241
  isMoreLoading: isMoreLoading,
@@ -1026,7 +1026,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1026
1026
  }
1027
1027
  }, [agentId, reloadAgentKey, baseUrl]);
1028
1028
  React.useEffect(function () {
1029
- if (resetKey !== resetKeyRef.current) {
1029
+ if (resetKey && resetKey !== resetKeyRef.current) {
1030
1030
  var _controllerRef$curren, _streamEsAbortRef$cur;
1031
1031
  resetKeyRef.current = resetKey || '';
1032
1032
  (_controllerRef$curren = controllerRef.current) === null || _controllerRef$curren === void 0 || _controllerRef$curren.abort();
@@ -1275,7 +1275,7 @@ var useCommonChatAPI = function useCommonChatAPI(containerRef, platform, stopTTS
1275
1275
  handleSend('重试');
1276
1276
  }, []);
1277
1277
  React.useEffect(function () {
1278
- if (interruptKey !== interruptKeyRef.current) {
1278
+ if (interruptKey && interruptKey !== interruptKeyRef.current) {
1279
1279
  interruptKeyRef.current = interruptKey || '';
1280
1280
  if (streamEsAbortRef.current && step.current === 2) {
1281
1281
  handleInterrupt();
@@ -47,6 +47,7 @@ export interface GimiMenuState {
47
47
  displayImage: number;
48
48
  imageUrl: string;
49
49
  showMicWarning: boolean;
50
+ initMsg?: string;
50
51
  }
51
52
  export declare const getChatHistoryList: import("@reduxjs/toolkit").AsyncThunk<{
52
53
  data: any;
@@ -55,7 +55,8 @@ var initialState = {
55
55
  quoteTeachModelList: [],
56
56
  displayImage: 1,
57
57
  imageUrl: '',
58
- showMicWarning: false
58
+ showMicWarning: false,
59
+ initMsg: ''
59
60
  };
60
61
  export var getChatHistoryList = createAsyncThunk('gimiMenu/getChatHistoryList', /*#__PURE__*/function () {
61
62
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload, _ref) {
@@ -65,6 +66,7 @@ export var getChatHistoryList = createAsyncThunk('gimiMenu/getChatHistoryList',
65
66
  case 0:
66
67
  rejectWithValue = _ref.rejectWithValue, getState = _ref.getState;
67
68
  pageIndex = payload.pageIndex, pageSize = payload.pageSize;
69
+ console.log('getChatHistoryList', payload);
68
70
  params = {
69
71
  pageIndex: pageIndex,
70
72
  pageSize: pageSize,
@@ -72,20 +74,23 @@ export var getChatHistoryList = createAsyncThunk('gimiMenu/getChatHistoryList',
72
74
  conversationTypes: [2, 3]
73
75
  }
74
76
  };
75
- _context.prev = 3;
77
+ _context.prev = 4;
76
78
  state = getState();
77
79
  api = createFetch({
78
80
  baseURL: state.gimiMenu.baseUrl,
79
- timeout: 10000
80
- });
81
- _context.next = 8;
82
- return api.get('/chat/history', {
83
- params: params
81
+ timeout: 10000,
82
+ headers: {
83
+ 'Authorization': 'Bearer ' + state.gimiMenu.token,
84
+ 'X-Mc-Domain': location.hostname,
85
+ 'Content-Type': 'application/json'
86
+ }
84
87
  });
85
- case 8:
88
+ _context.next = 9;
89
+ return api.post('/mbot/web/conversation/page', params);
90
+ case 9:
86
91
  res = _context.sent;
87
92
  if (!((res === null || res === void 0 ? void 0 : res.status) === 0)) {
88
- _context.next = 11;
93
+ _context.next = 12;
89
94
  break;
90
95
  }
91
96
  return _context.abrupt("return", {
@@ -93,17 +98,17 @@ export var getChatHistoryList = createAsyncThunk('gimiMenu/getChatHistoryList',
93
98
  last: res.result.last,
94
99
  loadMore: payload.loadMore || false
95
100
  });
96
- case 11:
101
+ case 12:
97
102
  return _context.abrupt("return", rejectWithValue('获取历史记录失败'));
98
- case 14:
99
- _context.prev = 14;
100
- _context.t0 = _context["catch"](3);
103
+ case 15:
104
+ _context.prev = 15;
105
+ _context.t0 = _context["catch"](4);
101
106
  return _context.abrupt("return", rejectWithValue(_context.t0));
102
- case 17:
107
+ case 18:
103
108
  case "end":
104
109
  return _context.stop();
105
110
  }
106
- }, _callee, null, [[3, 14]]);
111
+ }, _callee, null, [[4, 15]]);
107
112
  }));
108
113
  return function (_x, _x2) {
109
114
  return _ref2.apply(this, arguments);
@@ -119,6 +124,8 @@ var gimiMenuSlice = createSlice({
119
124
  },
120
125
  setConversationId: function setConversationId(state, action) {
121
126
  var conversationId = action.payload.conversationId;
127
+ console.log('setConversationId', conversationId);
128
+ localStorage.setItem('historyConversationId', conversationId ? conversationId + '' : '');
122
129
  state.conversationId = conversationId;
123
130
  },
124
131
  setIsMsgRecieving: function setIsMsgRecieving(state, action) {
@@ -196,6 +203,9 @@ var gimiMenuSlice = createSlice({
196
203
  },
197
204
  setShowMicWarning: function setShowMicWarning(state, action) {
198
205
  state.showMicWarning = action.payload.showMicWarning;
206
+ },
207
+ setInitMsg: function setInitMsg(state, action) {
208
+ state.initMsg = action.payload.initMsg;
199
209
  }
200
210
  },
201
211
  extraReducers: function extraReducers(builder) {