@blocklet/pages-kit 0.2.287 → 0.2.289

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 (79) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/request.js +9 -1
  2. package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +2 -38
  3. package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +3 -5
  4. package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +7 -1
  5. package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +10 -11
  6. package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +1 -1
  7. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +53 -12
  8. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +19 -5
  9. package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  10. package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +9 -4
  11. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +70 -75
  12. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +2 -3
  13. package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +1 -1
  14. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +1 -1
  15. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +26 -9
  16. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +16 -4
  17. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +8 -23
  18. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +19 -6
  19. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +24 -7
  20. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +1 -1
  21. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +38 -35
  22. package/lib/cjs/builtin/async/ai-runtime/error.js +10 -0
  23. package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +2 -1
  24. package/lib/cjs/builtin/async/ai-runtime/hooks/useAsync.js +32 -0
  25. package/lib/cjs/builtin/async/ai-runtime/index.js +22 -16
  26. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +1 -1
  27. package/lib/cjs/builtin/async/ai-runtime/state/loading.js +39 -0
  28. package/lib/cjs/builtin/async/ai-runtime/state/session.js +1 -1
  29. package/lib/esm/builtin/async/ai-runtime/api/request.js +9 -1
  30. package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +1 -36
  31. package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +4 -6
  32. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +7 -1
  33. package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +13 -14
  34. package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +3 -3
  35. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +29 -11
  36. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +18 -5
  37. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  38. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +7 -5
  39. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +70 -75
  40. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +2 -3
  41. package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +3 -3
  42. package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +1 -1
  43. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +24 -9
  44. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +16 -4
  45. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +7 -22
  46. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +20 -7
  47. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +24 -7
  48. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +1 -1
  49. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +34 -34
  50. package/lib/esm/builtin/async/ai-runtime/error.js +6 -0
  51. package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +2 -1
  52. package/lib/esm/builtin/async/ai-runtime/hooks/useAsync.js +29 -0
  53. package/lib/esm/builtin/async/ai-runtime/index.js +23 -17
  54. package/lib/esm/builtin/async/ai-runtime/locales/index.js +1 -1
  55. package/lib/esm/builtin/async/ai-runtime/state/loading.js +36 -0
  56. package/lib/esm/builtin/async/ai-runtime/state/session.js +1 -1
  57. package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +0 -31
  58. package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +4 -1
  59. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +2 -2
  60. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +5 -2
  61. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +4 -2
  62. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +1 -3
  63. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +6 -0
  64. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +3 -2
  65. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +3 -2
  66. package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +4 -5
  67. package/lib/types/builtin/async/ai-runtime/error.d.ts +4 -0
  68. package/lib/types/builtin/async/ai-runtime/hooks/useAsync.d.ts +1 -0
  69. package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -1
  70. package/lib/types/builtin/async/ai-runtime/state/loading.d.ts +10 -0
  71. package/lib/types/builtin/page/header.d.ts +1 -6
  72. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -116
  73. package/package.json +9 -9
  74. package/lib/cjs/builtin/async/ai-runtime/components/layout/index.js +0 -15
  75. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +0 -21
  76. package/lib/esm/builtin/async/ai-runtime/components/layout/index.js +0 -12
  77. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +0 -15
  78. package/lib/types/builtin/async/ai-runtime/components/layout/index.d.ts +0 -7
  79. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.d.ts +0 -4
@@ -22,7 +22,15 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.request = exports.fetch = void 0;
24
24
  const js_sdk_1 = require("@blocklet/js-sdk");
25
- exports.fetch = (0, js_sdk_1.createFetch)();
25
+ let isDEV = false;
26
+ try {
27
+ // @ts-ignore
28
+ isDEV = import.meta.env.DEV;
29
+ }
30
+ catch (_a) {
31
+ // ignore
32
+ }
33
+ exports.fetch = (0, js_sdk_1.createFetch)({}, { lazy: isDEV, lazyTime: 1000 });
26
34
  function request(_a) {
27
35
  return __awaiter(this, void 0, void 0, function* () {
28
36
  var _b, _c, _d;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __rest = (this && this.__rest) || function (s, e) {
12
3
  var t = {};
13
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -20,41 +11,14 @@ var __rest = (this && this.__rest) || function (s, e) {
20
11
  return t;
21
12
  };
22
13
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.globalLoadingState = void 0;
24
14
  const jsx_runtime_1 = require("react/jsx-runtime");
25
15
  const material_1 = require("@mui/material");
26
- const zustand_1 = require("zustand");
27
- const immer_1 = require("zustand/middleware/immer");
16
+ const loading_1 = require("../state/loading");
28
17
  function GlobalLoading(_a) {
29
18
  var props = __rest(_a, []);
30
- const state = (0, exports.globalLoadingState)();
19
+ const state = (0, loading_1.globalLoadingState)();
31
20
  if (!state.loading)
32
21
  return null;
33
22
  return (0, jsx_runtime_1.jsx)(material_1.LinearProgress, Object.assign({}, props));
34
23
  }
35
24
  exports.default = GlobalLoading;
36
- exports.globalLoadingState = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
37
- loading: false,
38
- count: 0,
39
- run: (fn) => __awaiter(void 0, void 0, void 0, function* () {
40
- try {
41
- get().start();
42
- return (yield (typeof fn === 'function' ? fn() : fn));
43
- }
44
- finally {
45
- get().end();
46
- }
47
- }),
48
- start: () => {
49
- set((state) => {
50
- state.count += 1;
51
- state.loading = true;
52
- });
53
- },
54
- end: () => {
55
- set((state) => {
56
- state.count = Math.max(0, state.count - 1);
57
- state.loading = state.count > 0;
58
- });
59
- },
60
- })));
@@ -23,17 +23,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  const jsx_runtime_1 = require("react/jsx-runtime");
24
24
  const material_1 = require("@mui/material");
25
25
  const react_1 = require("react");
26
- const locale_1 = require("../../../locale");
27
26
  function LoadingListItemButton(_a) {
28
- var props = __rest(_a, []);
29
- const { t } = (0, locale_1.useLocaleContext)();
27
+ var { children, confirmation } = _a, props = __rest(_a, ["children", "confirmation"]);
30
28
  const [clicked, setClicked] = (0, react_1.useState)(false);
31
29
  const [loading, setLoading] = (0, react_1.useState)(false);
32
30
  const handleClick = (e) => __awaiter(this, void 0, void 0, function* () {
33
31
  var _b;
34
32
  if (loading)
35
33
  return;
36
- if (!clicked) {
34
+ if (!clicked && confirmation) {
37
35
  setClicked(true);
38
36
  return;
39
37
  }
@@ -46,6 +44,6 @@ function LoadingListItemButton(_a) {
46
44
  setLoading(false);
47
45
  }
48
46
  });
49
- return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, Object.assign({}, props, { onClick: handleClick, sx: Object.assign(Object.assign({}, props.sx), { minWidth: 120, display: 'flex', justifyContent: 'space-between', gap: 1 }), children: [clicked ? t('confirmDelete') : t('delete'), loading && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 14 })] })));
47
+ return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, Object.assign({}, props, { onClick: handleClick, sx: Object.assign(Object.assign({}, props.sx), { display: 'flex', alignItems: 'center', gap: 1 }), children: [(clicked && confirmation) || children, (0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", sx: { width: 18 }, children: loading && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 14 }) })] })));
50
48
  }
51
49
  exports.default = LoadingListItemButton;
@@ -4,13 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const material_1 = require("@mui/material");
7
8
  const react_1 = __importDefault(require("react"));
9
+ const react_error_boundary_1 = require("react-error-boundary");
10
+ const ux_1 = require("../../../arcblock/ux");
8
11
  const locale_1 = require("../../../locale");
9
12
  const locales_1 = require("../locales");
10
13
  const GlobalLoading_1 = __importDefault(require("./GlobalLoading"));
11
14
  const ThemeProvider_1 = __importDefault(require("./ThemeProvider"));
12
15
  function RuntimeProvider({ children }) {
13
16
  const { locale } = (0, locale_1.useLocaleContext)();
14
- return ((0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { translations: locales_1.translations, locale: locale, fallbackLocale: "en", children: (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { children: (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [(0, jsx_runtime_1.jsx)(GlobalLoading_1.default, { sx: { position: 'fixed', left: 0, top: 0, width: '100%', zIndex: 'snackbar' } }), children] }) }) }));
17
+ return ((0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { translations: locales_1.translations, locale: locale, fallbackLocale: "en", children: (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { children: (0, jsx_runtime_1.jsxs)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: ErrorRender, children: [(0, jsx_runtime_1.jsx)(GlobalLoading_1.default, { sx: { position: 'fixed', left: 0, top: 0, width: '100%', zIndex: 'snackbar' } }), (0, jsx_runtime_1.jsx)(react_1.default.Suspense, { fallback: (0, jsx_runtime_1.jsx)(material_1.Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 24 }) }), children: children })] }) }) }));
15
18
  }
16
19
  exports.default = RuntimeProvider;
20
+ function ErrorRender({ error }) {
21
+ return ((0, jsx_runtime_1.jsx)(ux_1.Result, Object.assign({ status: error.status || 'error' }, (Number(error.status) === 404 ? { message: error.message } : {}), { sx: { bgcolor: 'transparent', mt: '20%' } })));
22
+ }
@@ -21,7 +21,7 @@ function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popp
21
21
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
22
22
  const chatViewSizeSx = isMobile
23
23
  ? { width: '100vw', height: 'calc(100vh - 72px)' }
24
- : { width: '40vw', height: '70vh' };
24
+ : { width: '40vw', height: '80vh' };
25
25
  if (popperWidth) {
26
26
  chatViewSizeSx.width = popperWidth;
27
27
  }
@@ -48,7 +48,7 @@ function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popp
48
48
  setOpenPopper(false);
49
49
  }, children: children }));
50
50
  }
51
- return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl.current, open: openPopper, placement: "top-end", sx: Object.assign({ zIndex: 1200, minWidth: { sm: 400 } }, chatViewSizeSx), children: (0, jsx_runtime_1.jsx)(material_1.ClickAwayListener, { onClickAway: (e) => {
51
+ return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl.current, open: openPopper, placement: "top-end", sx: Object.assign({ zIndex: 1200, minWidth: { sm: 500 }, maxWidth: 600 }, chatViewSizeSx), children: (0, jsx_runtime_1.jsx)(material_1.ClickAwayListener, { onClickAway: (e) => {
52
52
  e.preventDefault();
53
53
  e.stopPropagation();
54
54
  setOpenPopper(false);
@@ -74,24 +74,19 @@ function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popp
74
74
  }, [isMobile, openPopper]);
75
75
  if (!assistant)
76
76
  return null;
77
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
77
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'fixed', bottom: bottom || 24, right: right || 24 }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
78
78
  display: 'inline-flex',
79
79
  flexDirection: 'column',
80
80
  justifyContent: 'center',
81
81
  alignItems: 'center',
82
- position: 'fixed',
83
- bottom: bottom || 24,
84
- right: right || 24,
85
82
  boxShadow: '0px 2px 4px 0px rgba(3, 7, 18, 0.04)',
86
- cursor: 'pointer !important',
83
+ cursor: 'pointer',
87
84
  zIndex: 1000,
88
85
  transition: 'transform 0.3s',
89
86
  ':hover': {
90
87
  transform: 'scale(1.05)',
91
88
  },
92
- }, onClick: () => {
93
- setOpenPopper(!openPopper);
94
- }, children: [(0, jsx_runtime_1.jsx)(ux_1.Avatar, { className: "logo", size: size || 48, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo }), (0, jsx_runtime_1.jsx)(material_1.Box, { width: "100%", ref: anchorEl })] }), anchorEl.current && ((0, jsx_runtime_1.jsx)(WrapperComponent, { children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { className: "ai-bot-scroll-container", initialScrollBehavior: "auto", component: material_1.Box, sx: {
89
+ }, onClick: () => setOpenPopper(!openPopper), children: [(0, jsx_runtime_1.jsx)(ux_1.Avatar, { className: "logo", size: size || 48, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo }), (0, jsx_runtime_1.jsx)(material_1.Box, { width: "100%", ref: anchorEl })] }), anchorEl.current && ((0, jsx_runtime_1.jsx)(WrapperComponent, { children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { className: "ai-bot-scroll-container", initialScrollBehavior: "auto", component: material_1.Box, sx: {
95
90
  overscrollBehavior: 'contain',
96
91
  height: isMobile ? '100%' : `calc(${chatViewSizeSx.height} - 70px)`,
97
92
  width: '100%',
@@ -100,6 +95,10 @@ function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popp
100
95
  '.ai-chat-header': {
101
96
  pt: 4,
102
97
  },
103
- }, children: children }) }))] }));
98
+ '.ai-runtime-form-container': {
99
+ borderBottomLeftRadius: 8,
100
+ borderBottomRightRadius: 8,
101
+ },
102
+ }, children: (0, jsx_runtime_1.jsx)(react_2.Suspense, { fallback: (0, jsx_runtime_1.jsx)(material_1.Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 24 }) }), children: children }) }) }))] }));
104
103
  }
105
104
  exports.default = ChatBot;
@@ -16,6 +16,6 @@ function MessageMetadataRenderer({ object }) {
16
16
  const images = (Array.isArray(list) ? list.map((i) => ({ src: i.url })) : []).filter((i) => typeof i.src === 'string');
17
17
  return images.length ? images : undefined;
18
18
  }, [object]);
19
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? (0, jsx_runtime_1.jsx)(ReferenceLinks_1.default, { links: referenceLinks }) : undefined, images && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", children: "Images:" }), (0, jsx_runtime_1.jsx)(image_preview_1.default, { dataSource: images, itemWidth: 100 })] }))] }));
19
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? (0, jsx_runtime_1.jsx)(ReferenceLinks_1.default, { links: referenceLinks }) : undefined, images && ((0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: (0, jsx_runtime_1.jsx)(image_preview_1.default, { dataSource: images, itemWidth: 100 }) }))] }));
20
20
  }
21
21
  exports.default = MessageMetadataRenderer;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -13,36 +36,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
36
  };
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
38
  const jsx_runtime_1 = require("react/jsx-runtime");
39
+ const react_1 = require("@iconify/react");
16
40
  const material_1 = require("@mui/material");
41
+ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
17
42
  const omit_1 = __importDefault(require("lodash/omit"));
18
- const react_1 = require("react");
43
+ const react_2 = require("react");
19
44
  const react_hook_form_1 = require("react-hook-form");
20
45
  const locale_1 = require("../../../../locale");
21
46
  const LoadingButton_1 = __importDefault(require("../LoadingButton"));
22
- const ParameterFormFields_1 = __importDefault(require("./ParameterFormFields"));
47
+ const ParameterFormFields_1 = __importStar(require("./ParameterFormFields"));
23
48
  const QuestionField_1 = __importDefault(require("./QuestionField"));
24
49
  const SettingButton_1 = __importDefault(require("./SettingButton"));
25
50
  function ParameterForm(_a) {
26
- var _b, _c, _d, _e;
51
+ var _b, _c, _d;
27
52
  var { sessionId, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle = (_c = (_b = assistant.release) === null || _b === void 0 ? void 0 : _b.submitButton) === null || _c === void 0 ? void 0 : _c.title, } = _a;
28
53
  const { t } = (0, locale_1.useLocaleContext)();
29
- const parameters = (_d = assistant.parameters) === null || _d === void 0 ? void 0 : _d.filter((i) => i.key && !['question', 'datasetId'].includes(i.key));
30
- const isChat = (_e = assistant.parameters) === null || _e === void 0 ? void 0 : _e.some((i) => i.key === 'question');
31
- const defaultForm = (0, react_1.useMemo)(() => {
54
+ const parameters = (0, react_2.useMemo)(() => {
55
+ var _a;
56
+ return (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => i.key && !['question', 'datasetId'].includes(i.key) && ParameterFormFields_1.SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string'));
57
+ }, [assistant.parameters]);
58
+ const isChat = (_d = assistant.parameters) === null || _d === void 0 ? void 0 : _d.some((i) => i.key === 'question');
59
+ const defaultForm = (0, react_2.useMemo)(() => {
32
60
  var _a;
33
- return defaultValues !== null && defaultValues !== void 0 ? defaultValues : Object.fromEntries((_a = parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _a !== void 0 ? _a : []);
61
+ const values = (0, omit_1.default)(defaultValues, 'question');
62
+ if (!(0, isEmpty_1.default)(values))
63
+ return values;
64
+ return Object.fromEntries((_a = parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _a !== void 0 ? _a : []);
34
65
  }, [defaultValues]);
35
- const form = (0, react_hook_form_1.useForm)({ defaultValues: (0, omit_1.default)(defaultForm, isChat ? ['question'] : []) });
36
- (0, react_1.useEffect)(() => {
37
- form.reset((0, omit_1.default)(defaultForm, 'question'));
66
+ const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm, shouldFocusError: true });
67
+ (0, react_2.useEffect)(() => {
68
+ form.reset(defaultForm);
38
69
  }, [defaultForm]);
39
70
  const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
40
71
  if (onSubmit) {
72
+ form.setFocus('question');
41
73
  yield onSubmit(parameters);
42
74
  form.reset((0, omit_1.default)(parameters, 'question'));
43
75
  }
44
76
  });
45
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-form", component: "form", onSubmit: form.handleSubmit(handleSubmit), gap: 2, children: [!!(parameters === null || parameters === void 0 ? void 0 : parameters.length) && ((0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { disabled: disabled, readOnly: readOnly, parameters: parameters, form: form })), !hideSubmit &&
46
- (isChat ? ((0, jsx_runtime_1.jsx)(QuestionField_1.default, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle, readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !(parameters === null || parameters === void 0 ? void 0 : parameters.length) })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && (0, jsx_runtime_1.jsx)(SettingButton_1.default, { sessionId: sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('submit') }) }) })] })))] }));
77
+ const [expand, setExpand] = (0, react_2.useState)(false);
78
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-form", component: "form", onSubmit: form.handleSubmit(handleSubmit, (e) => {
79
+ if (Object.keys(e).some((i) => i !== 'question')) {
80
+ setExpand(true);
81
+ }
82
+ }), children: [!!(parameters === null || parameters === void 0 ? void 0 : parameters.length) && ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(material_1.Button, { sx: { minWidth: 0, px: 4, py: 0, opacity: 0.7, color: 'text.secondary' }, onClick: () => setExpand(!expand), children: (0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: "tabler:chevron-compact-up", sx: {
83
+ fontSize: 24,
84
+ transform: `rotateX(${expand ? '180deg' : '0deg'})`,
85
+ transition: 'transform .3s ease-in-out',
86
+ } }) }) }), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: expand, orientation: "vertical", sx: { maxHeight: '40vh', overflowY: 'auto' }, children: (0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { autoFocus: !sessionId, disabled: disabled, readOnly: readOnly, parameters: parameters, form: form, sx: { pb: 2, px: 2 } }) })] })), (0, jsx_runtime_1.jsx)(material_1.Box, { px: 2, children: !hideSubmit &&
87
+ (isChat ? ((0, jsx_runtime_1.jsx)(QuestionField_1.default, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle, readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && (0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, sessionId: sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('submit') }) }) })] }))) })] }));
47
88
  }
48
89
  exports.default = ParameterForm;
@@ -1,17 +1,31 @@
1
1
  "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SUPPORTED_PARAMETER_TYPES = void 0;
6
18
  const jsx_runtime_1 = require("react/jsx-runtime");
7
19
  const material_1 = require("@mui/material");
8
20
  const react_hook_form_1 = require("react-hook-form");
9
21
  const parameters_1 = __importDefault(require("../parameters"));
10
- function ParameterFormFields({ disabled, readOnly, parameters, form, }) {
22
+ exports.SUPPORTED_PARAMETER_TYPES = ['string', 'number', 'select', 'language'];
23
+ function ParameterFormFields(_a) {
24
+ var { autoFocus, disabled, readOnly, parameters, form } = _a, props = __rest(_a, ["autoFocus", "disabled", "readOnly", "parameters", "form"]);
11
25
  let isFirstParameterRendered = false;
12
- return ((0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 2, children: parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => {
26
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 1 }, props, { children: parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => {
13
27
  const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
14
- if (!key)
28
+ if (!key || !exports.SUPPORTED_PARAMETER_TYPES.includes(parameter.type || 'string'))
15
29
  return null;
16
30
  const isFirstParameter = !isFirstParameterRendered;
17
31
  isFirstParameterRendered = true;
@@ -36,8 +50,8 @@ function ParameterFormFields({ disabled, readOnly, parameters, form, }) {
36
50
  mb: 0.5,
37
51
  fontWeight: 500,
38
52
  color: 'rgba(18, 22, 24, 1)',
39
- }, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { autoFocus: isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: { bgcolor: 'background.paper' } })] }));
53
+ }, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { inputRef: field.ref, autoFocus: autoFocus && isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: { bgcolor: 'background.paper' } })] }));
40
54
  } }) }, parameter.id));
41
- }) }));
55
+ }) })));
42
56
  }
43
57
  exports.default = ParameterFormFields;
@@ -16,7 +16,7 @@ function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmit
16
16
  const defaultPlaceholder = t('questionPlaceholder');
17
17
  const placeholder = (0, react_2.useMemo)(() => { var _a, _b; return ((_b = (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.find((i) => i.key === 'question')) === null || _b === void 0 ? void 0 : _b.placeholder) || defaultPlaceholder; }, [submitButtonTitle, assistant, defaultPlaceholder]);
18
18
  const submitRef = (0, react_2.useRef)(null);
19
- return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: "question", rules: { required: true }, render: ({ field }) => ((0, jsx_runtime_1.jsx)(material_1.TextField, { disabled: disabled, inputRef: field.ref, id: "question-input", required: true, size: "small", multiline: true, fullWidth: true, variant: "outlined", autoFocus: autoFocus, placeholder: placeholder, value: field.value || '', onChange: (e) => field.onChange(e), onKeyDownCapture: (e) => {
19
+ return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: "question", rules: { required: true }, render: ({ field }) => ((0, jsx_runtime_1.jsx)(material_1.TextField, { disabled: disabled, inputRef: field.ref, id: "question-input", size: "small", multiline: true, fullWidth: true, variant: "outlined", autoFocus: autoFocus, placeholder: placeholder, value: field.value || '', onChange: (e) => field.onChange(e), onKeyDownCapture: (e) => {
20
20
  var _a;
21
21
  // NOTE: Pressing Enter in the IME will trigger the 229 event
22
22
  if (e.keyCode === 229)
@@ -28,7 +28,7 @@ function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmit
28
28
  }, InputProps: {
29
29
  readOnly,
30
30
  sx: { p: 1, bgcolor: 'white', borderRadius: 1 },
31
- startAdornment: showSettingButton && sessionId && ((0, jsx_runtime_1.jsx)(SettingButton_1.default, { sessionId: sessionId, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
31
+ startAdornment: showSettingButton && sessionId && ((0, jsx_runtime_1.jsx)(SettingButton_1.default, { form: form, sessionId: sessionId, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
32
32
  className: 'ai-chat-question-field',
33
33
  endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, id: "question-submit", ref: submitRef, type: "submit", variant: "contained",
34
34
  // @ts-ignore
@@ -19,6 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  const jsx_runtime_1 = require("react/jsx-runtime");
24
27
  const react_1 = require("@iconify/react");
@@ -26,8 +29,9 @@ const material_1 = require("@mui/material");
26
29
  const react_2 = require("react");
27
30
  const locale_1 = require("../../../../locale");
28
31
  const session_1 = require("../../state/session");
32
+ const LoadingListItemButton_1 = __importDefault(require("../LoadingListItemButton"));
29
33
  function SettingButton(_a) {
30
- var { sessionId } = _a, props = __rest(_a, ["sessionId"]);
34
+ var { sessionId, form } = _a, props = __rest(_a, ["sessionId", "form"]);
31
35
  const { t } = (0, locale_1.useLocaleContext)();
32
36
  const [, state] = (0, session_1.useSessionState)({ sessionId, required: true });
33
37
  const [openSetting, setOpenSetting] = (0, react_2.useState)(false);
@@ -45,6 +49,7 @@ function SettingButton(_a) {
45
49
  key: 'clearSession',
46
50
  label: t('clearSession'),
47
51
  onClick: () => __awaiter(this, void 0, void 0, function* () {
52
+ form.setFocus('question');
48
53
  yield state.clearSession({
49
54
  sessionId,
50
55
  });
@@ -66,10 +71,10 @@ function SettingButton(_a) {
66
71
  boxShadow: '0px 8px 16px 0px rgba(2, 7, 19, 0.08), 0px 0px 0px 1px rgba(2, 7, 19, 0.08)',
67
72
  }, children: settingOptions.map((option) => {
68
73
  const { key, label, onClick, icon, sx } = option;
69
- return ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => {
74
+ return ((0, jsx_runtime_1.jsxs)(LoadingListItemButton_1.default, { onClick: () => __awaiter(this, void 0, void 0, function* () {
75
+ yield onClick();
70
76
  setOpenSetting(false);
71
- onClick();
72
- }, sx: Object.assign({ fontSize: 13, lineHeight: '22px', py: 0.75, px: 1.5, fontWeight: 400 }, sx), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: icon, sx: { fontSize: 16, mr: 1 } }), label] }, key));
77
+ }), sx: Object.assign({ fontSize: 13, lineHeight: '22px', py: 0.75, px: 1.5, fontWeight: 400 }, sx), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: icon, sx: { fontSize: 16, mr: 1 } }), label] }, key));
73
78
  }) }) }) }, "setting-popper"),
74
79
  ];
75
80
  }
@@ -28,69 +28,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  const jsx_runtime_1 = require("react/jsx-runtime");
30
30
  const image_preview_1 = __importDefault(require("@blocklet/ai-kit/components/image-preview"));
31
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
31
  const material_1 = require("@mui/material");
33
32
  const dayjs_1 = __importDefault(require("dayjs"));
34
33
  const react_1 = __importStar(require("react"));
35
34
  const ux_1 = require("../../../../arcblock/ux");
36
- const locale_1 = require("../../../../locale");
37
35
  const session_1 = require("../../../../session");
38
36
  const common_1 = require("../common");
39
37
  const MarkdownRenderer_1 = __importDefault(require("../MarkdownRenderer"));
40
38
  const MessageActions_1 = __importDefault(require("./MessageActions"));
41
39
  const MessageErrorView_1 = __importDefault(require("./MessageErrorView"));
42
- // if today, show time only, else show date and time
43
- const formatTodayTime = (time) => {
44
- const today = (0, dayjs_1.default)().format('YYYY-MM-DD');
45
- const date = (0, dayjs_1.default)(time).format('YYYY-MM-DD');
46
- return today === date ? (0, dayjs_1.default)(time).format('HH:mm') : (0, dayjs_1.default)(time).format('YYYY-MM-DD HH:mm');
47
- };
48
- function MessageItemView({ assistantId, assistant, message, previousMessageTime, messageTimeType = 'user', hideAvatar, }) {
49
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
50
- const { session: authSession } = (0, session_1.useSessionContext)();
51
- const { locale } = (0, locale_1.useLocaleContext)();
52
- const hasResult = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) ||
53
- ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.images) === null || _c === void 0 ? void 0 : _c.length) ||
54
- ((_e = (_d = message.result) === null || _d === void 0 ? void 0 : _d.messages) === null || _e === void 0 ? void 0 : _e.length) ||
55
- ((_g = (_f = message.result) === null || _f === void 0 ? void 0 : _f.objects) === null || _g === void 0 ? void 0 : _g.length));
56
- const showPreviousTime = (0, react_1.useMemo)(() => {
57
- if (messageTimeType !== 'previous')
58
- return false;
59
- if (!previousMessageTime)
60
- return true;
61
- const p = (0, dayjs_1.default)(previousMessageTime);
62
- const c = (0, dayjs_1.default)(message.createdAt);
63
- return c.valueOf() - p.valueOf() >= 300e3; // 和上一条消息时间间隔不超过 5 分钟,则不显示时间
64
- }, [previousMessageTime, messageTimeType]);
65
- const extraUserInfo = [
66
- messageTimeType === 'user' && (message === null || message === void 0 ? void 0 : message.createdAt) && ((0, jsx_runtime_1.jsx)(material_1.Typography, { sx: {
67
- fontSize: 12,
68
- lineHeight: '24px',
69
- color: 'text.secondary',
70
- }, children: formatTodayTime(message.createdAt) }, "user-time")),
71
- ].filter(Boolean);
72
- const commonMessageSx = {
73
- position: 'relative',
74
- borderRadius: 1,
75
- py: 1,
76
- px: 2,
77
- mt: 0.5,
78
- // without logo width
79
- maxWidth: 'calc(100% - 40px)',
80
- '.message-actions': {
81
- position: 'absolute',
82
- top: 0,
83
- right: -40,
84
- background: 'white',
85
- border: 1,
86
- borderRadius: 1,
87
- borderColor: 'grey.300',
88
- opacity: 0,
89
- transition: 'opacity 0.2s',
90
- },
91
- };
92
- const isMessageLoading = (message.loading || !message.result) && !message.error;
93
- const showUserMessage = ((_h = assistant.release) === null || _h === void 0 ? void 0 : _h.template) !== 'form' && !!((_j = message.parameters) === null || _j === void 0 ? void 0 : _j.question);
40
+ function MessageItemView({ assistantId, assistant, message, hideAvatar, }) {
41
+ var _a, _b;
42
+ const showUserMessage = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) !== 'form' && !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
94
43
  return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden", sx: {
95
44
  '.message-question': Object.assign(Object.assign({}, commonMessageSx), { borderTopRightRadius: '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
96
45
  '.message-response': Object.assign(Object.assign({}, commonMessageSx), { borderTopLeftRadius: '2px', backgroundColor: 'rgba(229, 231, 235, 1)' }),
@@ -99,29 +48,60 @@ function MessageItemView({ assistantId, assistant, message, previousMessageTime,
99
48
  opacity: 1,
100
49
  },
101
50
  },
102
- }, children: [showPreviousTime && message.createdAt && ((0, jsx_runtime_1.jsx)(material_1.Box, { className: "ai-chat-message-time", sx: { textAlign: 'center', fontSize: 13, color: 'text.secondary', mb: -1.5 }, children: (0, jsx_runtime_1.jsx)(ux_1.RelativeTime, { locale: locale, value: message.createdAt, relativeRange: 600e3 }) })), showUserMessage && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-user", direction: "row", gap: 1.5, sx: {
103
- display: 'flex',
104
- flexDirection: 'row-reverse',
105
- textAlign: 'right',
106
- justifyContent: 'flex-end',
107
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, src: (_k = authSession.user) === null || _k === void 0 ? void 0 : _k.avatar, did: (_l = authSession.user) === null || _l === void 0 ? void 0 : _l.did, variant: "circle", shape: "circle" }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { flex: 1, overflow: "hidden", sx: {
108
- display: 'flex',
109
- flexDirection: 'column',
110
- alignItems: 'flex-end',
111
- }, children: [(0, jsx_runtime_1.jsxs)(MessageUserName, { children: [(_m = authSession.user) === null || _m === void 0 ? void 0 : _m.fullName, extraUserInfo] }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_o = message.parameters) === null || _o === void 0 ? void 0 : _o.question })] })] })), (0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_p = globalThis.blocklet) === null || _p === void 0 ? void 0 : _p.appId, variant: "circle", shape: "circle", src: (_q = assistant.release) === null || _q === void 0 ? void 0 : _q.logo }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [((_r = assistant.release) === null || _r === void 0 ? void 0 : _r.title) || assistant.name, extraUserInfo] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [hasResult ? ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, className: "message-response", children: [(_t = (_s = message.result) === null || _s === void 0 ? void 0 : _s.messages) === null || _t === void 0 ? void 0 : _t.map((childMsg, index) => {
112
- var _a, _b, _c, _d, _e, _f, _g;
113
- return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading &&
114
- !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
115
- !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
116
- message.result.messages.length - 1 === index
117
- ? 'writing'
118
- : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? ((0, jsx_runtime_1.jsx)(image_preview_1.default, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
119
- }), ((_u = message.result) === null || _u === void 0 ? void 0 : _u.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content })), !!((_w = (_v = message.result) === null || _v === void 0 ? void 0 : _v.images) === null || _w === void 0 ? void 0 : _w.length) && ((0, jsx_runtime_1.jsx)(image_preview_1.default, { itemWidth: 100, spacing: 1, dataSource: message.result.images.map((i) => ({ src: i.url })) })), !isMessageLoading && ((_x = message.result) === null || _x === void 0 ? void 0 : _x.content) && ((0, jsx_runtime_1.jsx)(MessageActions_1.default, { className: "message-actions", content: message.result.content }))] })) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
120
- // only response with loading
121
- className: "message-response" }))), !!((_z = (_y = message.result) === null || _y === void 0 ? void 0 : _y.objects) === null || _z === void 0 ? void 0 : _z.length) &&
122
- ((_1 = (_0 = message.result) === null || _0 === void 0 ? void 0 : _0.objects) === null || _1 === void 0 ? void 0 : _1.map((object) => ((0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && ((0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { assistantId: assistantId, assistant: assistant, error: message.error }))] })] })] })] }));
51
+ }, children: [showUserMessage && (0, jsx_runtime_1.jsx)(UserMessage, { message: message }), (0, jsx_runtime_1.jsx)(AgentMessage, { assistantId: assistantId, assistant: assistant, message: message, hideAvatar: hideAvatar })] }));
123
52
  }
124
53
  exports.default = MessageItemView;
54
+ const commonMessageSx = {
55
+ position: 'relative',
56
+ borderRadius: 1,
57
+ py: 1,
58
+ px: 2,
59
+ mt: 0.5,
60
+ // without logo width
61
+ maxWidth: 'calc(100% - 40px)',
62
+ '.message-actions': {
63
+ position: 'absolute',
64
+ top: 0,
65
+ right: -40,
66
+ background: 'white',
67
+ border: 1,
68
+ borderRadius: 1,
69
+ borderColor: 'grey.300',
70
+ opacity: 0,
71
+ transition: 'opacity 0.2s',
72
+ },
73
+ };
74
+ function UserMessage({ message }) {
75
+ var _a, _b, _c, _d;
76
+ const { session: authSession } = (0, session_1.useSessionContext)();
77
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-user", direction: "row", gap: 1.5, sx: {
78
+ display: 'flex',
79
+ flexDirection: 'row-reverse',
80
+ textAlign: 'right',
81
+ justifyContent: 'flex-end',
82
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, src: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.avatar, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, variant: "circle", shape: "circle" }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { flex: 1, overflow: "hidden", sx: {
83
+ display: 'flex',
84
+ flexDirection: 'column',
85
+ alignItems: 'flex-end',
86
+ }, children: [(0, jsx_runtime_1.jsxs)(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_d = message.parameters) === null || _d === void 0 ? void 0 : _d.question })] })] }));
87
+ }
88
+ function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
89
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
90
+ const showMainMessage = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) || ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.length));
91
+ const isMessageLoading = (message.loading || !message.result) && !message.error;
92
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = assistant.release) === null || _e === void 0 ? void 0 : _e.logo }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [((_f = assistant.release) === null || _f === void 0 ? void 0 : _f.title) || assistant.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
93
+ var _a, _b, _c, _d, _e, _f, _g;
94
+ return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading &&
95
+ !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
96
+ !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
97
+ message.result.messages.length - 1 === index
98
+ ? 'writing'
99
+ : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? ((0, jsx_runtime_1.jsx)(image_preview_1.default, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
100
+ }), ((_j = message.result) === null || _j === void 0 ? void 0 : _j.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content })), !isMessageLoading && ((_k = message.result) === null || _k === void 0 ? void 0 : _k.content) && ((0, jsx_runtime_1.jsx)(MessageActions_1.default, { className: "message-actions", content: message.result.content }))] })) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
101
+ // only response with loading
102
+ className: "message-response" }))), !!((_m = (_l = message.result) === null || _l === void 0 ? void 0 : _l.objects) === null || _m === void 0 ? void 0 : _m.length) &&
103
+ ((_p = (_o = message.result) === null || _o === void 0 ? void 0 : _o.objects) === null || _p === void 0 ? void 0 : _p.map((object) => ((0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { assistantId: assistantId, assistant: assistant, error: message.error })] })] })] }));
104
+ }
125
105
  function MessageUserName({ children }) {
126
106
  return ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", noWrap: true, sx: {
127
107
  fontSize: 14,
@@ -132,3 +112,18 @@ function MessageUserName({ children }) {
132
112
  gap: 1,
133
113
  }, children: children }));
134
114
  }
115
+ function MessageTime({ time }) {
116
+ const t = (0, react_1.useMemo)(() => {
117
+ const date = (0, dayjs_1.default)(time);
118
+ if (!date.isValid())
119
+ return undefined;
120
+ return date.isSame((0, dayjs_1.default)(), 'date') ? date.format('HH:mm') : date.format('YYYY-MM-DD HH:mm');
121
+ }, [time]);
122
+ if (!t)
123
+ return null;
124
+ return ((0, jsx_runtime_1.jsx)(material_1.Typography, { sx: {
125
+ fontSize: 12,
126
+ lineHeight: '24px',
127
+ color: 'text.secondary',
128
+ }, children: t }, "user-time"));
129
+ }
@@ -40,9 +40,8 @@ function MessageListView(_a) {
40
40
  }, [assistant.release]);
41
41
  if (!session)
42
42
  return null;
43
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: opener }), messages.map((message, index) => {
44
- var _a, _b;
45
- return ((0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: message, previousMessageTime: (_b = (_a = messages[index - 1]) === null || _a === void 0 ? void 0 : _a.createdAt) !== null && _b !== void 0 ? _b : session.createdAt }, message.taskId));
43
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: opener }), messages.map((message) => {
44
+ return ((0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, assistant: assistant, message: message }, message.taskId));
46
45
  })] })));
47
46
  }
48
47
  exports.default = MessageListView;