@blocklet/pages-kit 0.2.287 → 0.2.288

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