@blocklet/pages-kit 0.2.312 → 0.2.313

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 (41) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/session.js +10 -1
  2. package/lib/cjs/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +49 -0
  3. package/lib/cjs/builtin/async/ai-runtime/components/PopperMenuButton/index.js +68 -0
  4. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +1 -1
  5. package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +21 -4
  6. package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +22 -33
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +2 -2
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +6 -5
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +6 -5
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +39 -14
  11. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +2 -2
  12. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +2 -2
  13. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +2 -3
  14. package/lib/cjs/builtin/async/ai-runtime/state/session.js +217 -79
  15. package/lib/cjs/builtin/page/header.js +45 -3
  16. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  17. package/lib/esm/builtin/async/ai-runtime/api/session.js +8 -0
  18. package/lib/esm/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +46 -0
  19. package/lib/esm/builtin/async/ai-runtime/components/PopperMenuButton/index.js +42 -0
  20. package/lib/esm/builtin/async/ai-runtime/locales/index.js +1 -1
  21. package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +23 -6
  22. package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +23 -34
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +3 -3
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +7 -6
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +7 -6
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +35 -10
  27. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +3 -3
  28. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +3 -3
  29. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +3 -4
  30. package/lib/esm/builtin/async/ai-runtime/state/session.js +215 -79
  31. package/lib/esm/builtin/page/header.js +42 -1
  32. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  33. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +3 -0
  34. package/lib/types/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.d.ts +5 -0
  35. package/lib/types/builtin/async/ai-runtime/components/PopperMenuButton/index.d.ts +6 -0
  36. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/index.d.ts +2 -1
  37. package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -0
  38. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +27 -6
  39. package/lib/types/builtin/page/header.d.ts +13 -0
  40. package/lib/types/tsconfig.tsbuildinfo +1 -1
  41. package/package.json +4 -3
@@ -52,6 +52,14 @@ export function createSession(_a) {
52
52
  });
53
53
  });
54
54
  }
55
+ export function clearSession(_a) {
56
+ return __awaiter(this, arguments, void 0, function* ({ sessionId }) {
57
+ return request({
58
+ method: 'POST',
59
+ url: joinURL(getComponentMountPoint(AI_STUDIO_DID), '/api/sessions', sessionId, '/clear'),
60
+ });
61
+ });
62
+ }
55
63
  export function updateSession(_a) {
56
64
  return __awaiter(this, arguments, void 0, function* ({ sessionId, name, }) {
57
65
  return request({
@@ -0,0 +1,46 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { CircularProgress, MenuItem, Stack } from '@mui/material';
23
+ import { useState } from 'react';
24
+ export default function LoadingMenuItem(_a) {
25
+ var { children, confirmation } = _a, props = __rest(_a, ["children", "confirmation"]);
26
+ const [clicked, setClicked] = useState(false);
27
+ const [loading, setLoading] = useState(false);
28
+ const handleClick = (e) => __awaiter(this, void 0, void 0, function* () {
29
+ var _b;
30
+ if (loading)
31
+ return;
32
+ if (!clicked && confirmation) {
33
+ setClicked(true);
34
+ return;
35
+ }
36
+ try {
37
+ setLoading(true);
38
+ yield ((_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props, e));
39
+ }
40
+ finally {
41
+ setClicked(false);
42
+ setLoading(false);
43
+ }
44
+ });
45
+ return (_jsxs(MenuItem, 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 }) })] })));
46
+ }
@@ -0,0 +1,42 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { Box, Button, ClickAwayListener, Grow, List, Paper, Popper, listItemIconClasses, } from '@mui/material';
23
+ import { bindPopper, bindTrigger, usePopupState } from 'material-ui-popup-state/hooks';
24
+ import React, { isValidElement } from 'react';
25
+ export default function PopperMenuButton(_a) {
26
+ var { PopperProps, menus } = _a, props = __rest(_a, ["PopperProps", "menus"]);
27
+ const state = usePopupState({ variant: 'popper' });
28
+ return (_jsxs(_Fragment, { children: [_jsx(Box, Object.assign({ component: Button }, bindTrigger(state), props)), _jsx(Popper, Object.assign({ transition: true }, PopperProps, bindPopper(state), { children: ({ TransitionProps }) => (_jsx(ClickAwayListener, { onClickAway: state.close, children: _jsx(Grow, Object.assign({}, TransitionProps, { children: _jsx(Paper, { children: _jsx(List, { dense: true, sx: {
29
+ [`.${listItemIconClasses.root}`]: {
30
+ minWidth: 24,
31
+ },
32
+ }, children: React.Children.map(menus, (menu) => !isValidElement(menu)
33
+ ? menu
34
+ : React.cloneElement(menu, {
35
+ // Close popper after the menu item click handler has been resolved
36
+ onClick: (...args) => __awaiter(this, void 0, void 0, function* () {
37
+ var _b, _c;
38
+ yield ((_c = (_b = menu.props).onClick) === null || _c === void 0 ? void 0 : _c.call(_b, ...args));
39
+ state.close();
40
+ }),
41
+ })) }) }) })) })) }))] }));
42
+ }
@@ -118,7 +118,7 @@ export const translations = {
118
118
  parameters: '参数',
119
119
  parametersTitle: '告诉我你想要什么?',
120
120
  parametersSetting: '设置',
121
- clearSession: '清空对话',
121
+ clearSession: '清空会话',
122
122
  generate: '生成',
123
123
  startChat: '开始对话',
124
124
  collections: '知识库',
@@ -1,24 +1,36 @@
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
+ };
1
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
11
  import { Icon } from '@iconify/react';
3
12
  import { ArrowBackIosNewRounded } from '@mui/icons-material';
4
- import { Box, Button, CircularProgress, ClickAwayListener, Dialog, DialogContent, DialogTitle, Fab, Grow, IconButton, Popper, Stack, Typography, useMediaQuery, useTheme, } from '@mui/material';
13
+ import { Box, Button, CircularProgress, ClickAwayListener, Dialog, DialogContent, DialogTitle, Fab, Grow, IconButton, ListItemIcon, Popper, Stack, Typography, useMediaQuery, useTheme, } from '@mui/material';
5
14
  import { Suspense, useRef, useState } from 'react';
6
15
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
7
16
  import { Avatar } from '../../../../arcblock/ux';
17
+ import { useLocaleContext } from '../../../../locale';
18
+ import PopperMenuButton from '../../components/PopperMenuButton';
19
+ import LoadingMenuItem from '../../components/PopperMenuButton/LoadingMenuItem';
8
20
  import RuntimeCommonProvider from '../../components/RuntimeCommonProvider';
9
21
  import ScrollView from '../../components/ScrollView';
10
22
  import { DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
11
23
  import RuntimeProvider from '../../contexts/Runtime';
12
24
  import useAppearances, { useProfile } from '../../hooks/use-appearances';
13
25
  import { useRuntimeState } from '../../state/runtime';
14
- import { useSessionState } from '../../state/session';
26
+ import { useAutoLoadSessionState, useSessionState } from '../../state/session';
15
27
  export default function ChatBotButton({ aid, working }) {
16
28
  return (_jsx(RuntimeProvider, { aid: aid, working: working, children: _jsx(RuntimeCommonProvider, { children: _jsx(ChatBotContent, {}) }) }));
17
29
  }
18
30
  function ChatBotContent() {
19
31
  var _a, _b;
20
32
  const anchorEl = useRef(null);
21
- useSessionState({ autoLoad: true });
33
+ useAutoLoadSessionState();
22
34
  const { aid } = useRuntimeState();
23
35
  const { appearancePage } = useAppearances({ aid });
24
36
  const profile = useProfile({ aid });
@@ -32,7 +44,7 @@ function ChatBotContent() {
32
44
  '.aigne-layout': {
33
45
  px: 2,
34
46
  },
35
- }, children: _jsx(Suspense, { fallback: _jsx(Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(CircularProgress, { size: 24 }) }), children: _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps, props: { scrollViewProps: { disabled: true } } }) }) }) }))] }));
47
+ }, children: _jsx(Suspense, { fallback: _jsx(Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(CircularProgress, { size: 24 }) }), children: _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps, props: { scrollViewProps: { disabled: true }, hideHeaderMenuButton: true } }) }) }) }))] }));
36
48
  }
37
49
  function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
38
50
  const theme = useTheme();
@@ -61,8 +73,13 @@ function ChatBotPopper({ title, anchorEl, open, children, onClose, }) {
61
73
  position: 'relative',
62
74
  background: 'white',
63
75
  borderRadius: 1,
64
- }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "space-between", borderBottom: 1, borderColor: "divider", p: 2, gap: 2, children: [_jsx(Typography, { variant: "h6", noWrap: true, children: title }), _jsx(Button, { sx: { minWidth: 28, minHeight: 28, p: 0 }, onClick: onClose, children: _jsx(Icon, { icon: "tabler:x", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), children] }) })) })) }));
76
+ }, children: [_jsxs(Stack, { direction: "row", alignItems: "center", borderBottom: 1, borderColor: "divider", p: 2, gap: 2, children: [_jsx(Typography, { variant: "h6", noWrap: true, sx: { flex: 1, width: 1 }, children: title }), _jsx(ChatMenuButton, {}), _jsx(Button, { sx: { minWidth: 28, minHeight: 28, p: 0 }, onClick: onClose, children: _jsx(Icon, { icon: "tabler:x", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), children] }) })) })) }));
65
77
  }
66
78
  function ChatBotDialog({ title, open, children, onClose, }) {
67
- return (_jsxs(Dialog, { open: open, onClose: onClose, fullScreen: true, children: [_jsx(DialogTitle, { sx: { pl: 0 }, children: _jsxs(Stack, { direction: "row", alignItems: "center", gap: 2, children: [_jsx(IconButton, { size: "small", onClick: onClose, children: _jsx(ArrowBackIosNewRounded, { fontSize: "inherit" }) }), _jsx(Typography, { variant: "h6", noWrap: true, children: title })] }) }), _jsx(DialogContent, { sx: { p: 0 }, dividers: true, children: children })] }));
79
+ return (_jsxs(Dialog, { open: open, onClose: onClose, fullScreen: true, children: [_jsx(DialogTitle, { sx: { px: 1 }, children: _jsxs(Stack, { direction: "row", alignItems: "center", gap: 2, children: [_jsx(IconButton, { size: "small", onClick: onClose, children: _jsx(ArrowBackIosNewRounded, { fontSize: "inherit" }) }), _jsx(Typography, { variant: "h6", noWrap: true, sx: { flex: 1, width: 1 }, children: title }), _jsx(ChatMenuButton, {})] }) }), _jsx(DialogContent, { sx: { p: 0 }, dividers: true, children: children })] }));
80
+ }
81
+ function ChatMenuButton() {
82
+ const { t } = useLocaleContext();
83
+ const clearSession = useSessionState((s) => s.clearSession);
84
+ return (_jsx(PopperMenuButton, { component: IconButton, PopperProps: { placement: 'bottom-end', sx: { zIndex: 'snackbar' } }, menus: _jsxs(LoadingMenuItem, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }), children: _jsx(Icon, { icon: "tabler:dots" }) }));
68
85
  }
@@ -1,12 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, useMediaQuery, useTheme } from '@mui/material';
3
- import { useEffect } from 'react';
4
3
  import { Helmet } from 'react-helmet';
5
4
  import { joinURL } from 'ufo';
6
5
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
7
6
  import { Avatar, DID } from '../../../../arcblock/ux';
8
7
  import { useLocaleContext } from '../../../../locale';
9
- import { useHeaderState } from '../../../../page/header';
8
+ import { useHeader } from '../../../../page/header';
10
9
  import { getComponentMountPoint } from '../../../../utils';
11
10
  import RuntimeCommonProvider, { RuntimeLocaleProvider } from '../../components/RuntimeCommonProvider';
12
11
  import SocialShare from '../../components/SocialShare';
@@ -29,40 +28,30 @@ function RuntimeView() {
29
28
  const theme = useTheme();
30
29
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
31
30
  const { locale } = useLocaleContext();
32
- useEffect(() => {
33
- useHeaderState.setState((state) => {
34
- const logo = joinURL(window.location.origin, getComponentMountPoint(AI_STUDIO_DID), '/api/projects', agent.project.id, '/logo.png');
35
- state.logo = logo && (_jsx(Box, { component: Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: logoSize, sx: {
31
+ useHeader(() => {
32
+ const logo = joinURL(window.location.origin, getComponentMountPoint(AI_STUDIO_DID), '/api/projects', agent.project.id, '/logo.png');
33
+ const shareContent = `${agent.name}
34
+
35
+ ${agent === null || agent === void 0 ? void 0 : agent.description}
36
+ `;
37
+ return {
38
+ logo: logo && (_jsx(Box, { component: Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: logoSize, sx: {
36
39
  width: logoSize,
37
40
  height: logoSize,
38
- } }));
39
- if (!isMobile) {
40
- state.brand = (_jsx(Box, { sx: {
41
- height: 18,
42
- fontSize: 18,
43
- }, children: agent.project.name }));
44
- state.description = agent.createdBy && (_jsx(RuntimeLocaleProvider, { children: _jsx(Box, { sx: {
45
- display: 'inline-flex',
46
- alignItems: 'center',
47
- gap: 0.5,
48
- mt: 0.5,
49
- height: 12,
50
- fontSize: 12,
51
- }, children: _jsx(AgentCreatedBy, { did: agent.project.createdBy }) }) }));
52
- }
53
- const shareContent = `${agent.name}
54
-
55
- ${agent === null || agent === void 0 ? void 0 : agent.description}
56
- `;
57
- state.addons = (...exists) => [_jsx(SocialShare, { content: shareContent }), ...exists].filter(Boolean);
58
- });
59
- return () => {
60
- useHeaderState.setState((state) => {
61
- state.logo = undefined;
62
- state.brand = undefined;
63
- state.description = undefined;
64
- state.addons = (...exists) => [...exists];
65
- });
41
+ } })),
42
+ brand: !isMobile ? (_jsx(Box, { sx: {
43
+ height: 18,
44
+ fontSize: 18,
45
+ }, children: agent.project.name })) : undefined,
46
+ description: !isMobile && agent.createdBy ? (_jsx(RuntimeLocaleProvider, { children: _jsx(Box, { sx: {
47
+ display: 'inline-flex',
48
+ alignItems: 'center',
49
+ gap: 0.5,
50
+ mt: 0.5,
51
+ height: 12,
52
+ fontSize: 12,
53
+ }, children: _jsx(AgentCreatedBy, { did: agent.project.createdBy }) }) })) : undefined,
54
+ addons: (...exists) => [_jsx(SocialShare, { content: shareContent }), ...exists].filter(Boolean),
66
55
  };
67
56
  }, [locale, isMobile, agent]);
68
57
  const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
@@ -19,13 +19,13 @@ import AgentInputField from '../../components/AgentInputField';
19
19
  import LoadingButton from '../../components/LoadingButton';
20
20
  import { useCurrentAgent } from '../../contexts/CurrentAgent';
21
21
  import { useRuntimeState } from '../../state/runtime';
22
- import { useSessionState } from '../../state/session';
22
+ import { useCurrentSessionState } from '../../state/session';
23
23
  import { isValidInput } from '../../utils/agent-inputs';
24
24
  export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
25
25
  const { t } = useLocaleContext();
26
26
  const { aid, agent } = useCurrentAgent();
27
27
  const { execute } = useRuntimeState();
28
- const running = useSessionState()((s) => s.running);
28
+ const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
29
29
  const parameters = useMemo(() => {
30
30
  var _a;
31
31
  return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => {
@@ -79,7 +79,7 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
79
79
  }
80
80
  function useInitialFormValues() {
81
81
  const { agent } = useCurrentAgent();
82
- const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
82
+ const lastMessage = useCurrentSessionState((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
83
83
  const [lastInputs, setLastInputs] = useState();
84
84
  useEffect(() => {
85
85
  if (!lastInputs) {
@@ -25,11 +25,11 @@ import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAge
25
25
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
26
26
  import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
27
27
  import { useRuntimeState } from '../../state/runtime';
28
- import { useSessionState } from '../../state/session';
28
+ import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
29
29
  import { getOutputVariableInitialValue } from '../../utils/runtime-output-schema';
30
30
  import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
31
31
  export default function MultiAgentsChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, backgroundImage, }) {
32
- useSessionState({ autoLoad: true });
32
+ useAutoLoadSessionState();
33
33
  const inheritedTheme = useTheme();
34
34
  const theme = useMemo(() => {
35
35
  let { primary } = inheritedTheme.palette;
@@ -64,7 +64,7 @@ export default function MultiAgentsChat({ primaryColor, scrollViewProps = { scro
64
64
  }
65
65
  function SimpleChatView() {
66
66
  // auto scroll to bottom when new message is sent
67
- const running = useSessionState()((s) => s.running);
67
+ const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
68
68
  const scrollToBottom = useScrollToBottom();
69
69
  useEffect(() => {
70
70
  if (running)
@@ -106,10 +106,11 @@ function AgentInput() {
106
106
  }
107
107
  function OutputView(_a) {
108
108
  var { currentAgentId } = _a, props = __rest(_a, ["currentAgentId"]);
109
- const messages = useSessionState()((s) => s.messages);
110
- const loading = useSessionState()((s) => s.loading);
109
+ const messages = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
110
+ const loaded = useSessionState((s) => s.loaded);
111
+ const showOpening = useCurrentSessionState((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
111
112
  const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
112
- return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningMessageView, {}) }), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && _jsx(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningQuestionsView, {}) }))] })));
113
+ return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningMessageView, {}) })), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && _jsx(SuggestedQuestionsView, { message: lastMessage }), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningQuestionsView, {}) }))] })));
113
114
  }
114
115
  const OutputItemView = memo(({ message }) => {
115
116
  var _a, _b, _c, _d;
@@ -22,11 +22,11 @@ import CurrentAgentProvider from '../../contexts/CurrentAgent';
22
22
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
23
23
  import useAppearances from '../../hooks/use-appearances';
24
24
  import { useRuntimeState } from '../../state/runtime';
25
- import { useSessionState } from '../../state/session';
25
+ import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
26
26
  import mapRight from '../../utils/map-right';
27
27
  export default function PhotoGallery({ resultTitle, primaryColor }) {
28
28
  const { childAgentId } = useRuntimeState();
29
- useSessionState({ autoLoad: true });
29
+ useAutoLoadSessionState();
30
30
  const inheritedTheme = useTheme();
31
31
  const theme = useMemo(() => {
32
32
  let { primary } = inheritedTheme.palette;
@@ -58,15 +58,16 @@ function NoOutputs() {
58
58
  return (_jsx(Stack, { mt: 10, children: _jsx(Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
59
59
  }
60
60
  function OutputView(_a) {
61
- var _b, _c, _d;
61
+ var _b, _c, _d, _e;
62
62
  var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
63
63
  const { t } = useLocaleContext();
64
64
  const ref = useRef(null);
65
- const { messages = [], running, loaded, noMoreMessage, loadMoreMessages } = useSessionState()();
65
+ const { messages = [], running, loaded, noMoreMessage } = (_b = useCurrentSessionState((s) => s)) !== null && _b !== void 0 ? _b : {};
66
+ const loadMoreMessages = useSessionState((s) => s.loadMoreMessages);
66
67
  return (_jsxs(Stack, Object.assign({ width: "100%", alignItems: "center", px: { xs: 2, sm: 3 }, mt: { xs: 2, sm: 3 } }, props, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h2", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), loaded && !messages.length && _jsx(NoOutputs, {}), _jsxs(Masonry, { ref: ref, columns: { xs: 2, sm: 3, md: 4, lg: 5 }, spacing: 1, sequential: true, sx: { width: '100%', overflow: 'hidden', '> *': { borderRadius: 1 } }, children: [running && (_jsx(Skeleton, { variant: "rectangular", sx: {
67
68
  // FIXME: default using history height
68
- height: (_d = (_c = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.querySelector('*')) === null || _c === void 0 ? void 0 : _c.clientHeight) !== null && _d !== void 0 ? _d : 200,
69
- } })), mapRight(messages, (message) => (_jsx(OutputItemView, { message: message }, message.taskId)))] }), _jsx(Box, { my: 4, children: !!messages.length && !noMoreMessage && (_jsx(LoadingButton, { variant: "outlined", onClick: loadMoreMessages, children: t('loadMore') })) })] })));
69
+ height: (_e = (_d = (_c = ref.current) === null || _c === void 0 ? void 0 : _c.querySelector('*')) === null || _d === void 0 ? void 0 : _d.clientHeight) !== null && _e !== void 0 ? _e : 200,
70
+ } })), mapRight(messages, (message) => (_jsx(OutputItemView, { message: message }, message.taskId)))] }), _jsx(Box, { my: 4, children: !!messages.length && !noMoreMessage && (_jsx(LoadingButton, { variant: "outlined", onClick: () => loadMoreMessages(), children: t('loadMore') })) })] })));
70
71
  }
71
72
  const OutputItemView = memo(({ message }) => {
72
73
  const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
@@ -1,3 +1,12 @@
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
+ };
1
10
  var __rest = (this && this.__rest) || function (s, e) {
2
11
  var t = {};
3
12
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -11,24 +20,29 @@ var __rest = (this && this.__rest) || function (s, e) {
11
20
  };
12
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
22
  import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
14
- import { Box, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
23
+ import { Icon } from '@iconify/react';
24
+ import { Box, IconButton, ListItemIcon, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
15
25
  import { memo, useEffect, useMemo } from 'react';
16
26
  import { useScrollToBottom } from 'react-scroll-to-bottom';
17
27
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
28
+ import { useLocaleContext } from '../../../../locale';
29
+ import { useHeader } from '../../../../page/header';
18
30
  import { useSessionContext } from '../../../../session';
19
31
  import SimpleHeader from '../../components/Header/SimpleHeader';
20
32
  import SimpleLayout from '../../components/Layout/SimpleLayout';
21
33
  import MarkdownRenderer from '../../components/MarkdownRenderer';
34
+ import PopperMenuButton from '../../components/PopperMenuButton';
35
+ import LoadingMenuItem from '../../components/PopperMenuButton/LoadingMenuItem';
22
36
  import ScrollView from '../../components/ScrollView';
23
37
  import UserInfo from '../../components/UserInfo';
24
38
  import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
25
39
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
26
40
  import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
27
41
  import { useRuntimeState } from '../../state/runtime';
28
- import { useSessionState } from '../../state/session';
42
+ import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
29
43
  import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
30
- export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, }) {
31
- useSessionState({ autoLoad: true });
44
+ export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, hideHeaderMenuButton, }) {
45
+ useAutoLoadSessionState();
32
46
  const inheritedTheme = useTheme();
33
47
  const theme = useMemo(() => {
34
48
  let { primary } = inheritedTheme.palette;
@@ -47,17 +61,27 @@ export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: '
47
61
  },
48
62
  });
49
63
  }, [inheritedTheme, primaryColor]);
50
- return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsx(ThemeProvider, { theme: theme, children: _jsx(SimpleChatView, {}) }) })));
64
+ return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsx(ThemeProvider, { theme: theme, children: _jsx(SimpleChatView, { hideHeaderMenuButton: hideHeaderMenuButton }) }) })));
51
65
  }
52
- function SimpleChatView() {
66
+ function SimpleChatView({ hideHeaderMenuButton }) {
67
+ const { t, locale } = useLocaleContext();
53
68
  const { childAgentId } = useRuntimeState();
54
69
  // auto scroll to bottom when new message is sent
55
- const running = useSessionState()((s) => s.running);
70
+ const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
56
71
  const scrollToBottom = useScrollToBottom();
57
72
  useEffect(() => {
58
73
  if (running)
59
74
  scrollToBottom({ behavior: 'smooth' });
60
75
  }, [scrollToBottom, running]);
76
+ const clearSession = useSessionState((s) => s.clearSession);
77
+ useHeader(() => hideHeaderMenuButton
78
+ ? {}
79
+ : {
80
+ addons: (...exists) => [
81
+ _jsx(PopperMenuButton, { component: IconButton, PopperProps: { placement: 'bottom-end', sx: { zIndex: 'appBar' } }, menus: _jsxs(LoadingMenuItem, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }), children: _jsx(Icon, { icon: "tabler:dots" }) }),
82
+ ...exists,
83
+ ],
84
+ }, [locale, hideHeaderMenuButton]);
61
85
  return (_jsxs(SimpleLayout, { children: [_jsx(SimpleHeader, {}), _jsx(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10 }), _jsx(CurrentAgentProvider, { agentId: childAgentId, children: _jsx(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", sx: { position: 'sticky', bottom: 0, pt: 1, pb: 2, bgcolor: 'background.paper', zIndex: 10 } }) })] }));
62
86
  }
63
87
  function AgentInputRender(_a) {
@@ -69,10 +93,11 @@ function AgentInputRender(_a) {
69
93
  }
70
94
  function OutputView(_a) {
71
95
  var props = __rest(_a, []);
72
- const messages = useSessionState()((s) => s.messages);
73
- const loading = useSessionState()((s) => s.loading);
96
+ const messages = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
97
+ const loaded = useSessionState((s) => s.loaded);
98
+ const showOpening = useCurrentSessionState((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
74
99
  const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
75
- return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
100
+ return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && _jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage }), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
76
101
  }
77
102
  const OutputItemView = memo(({ message }) => {
78
103
  var _a, _b, _c, _d;
@@ -20,10 +20,10 @@ import CurrentAgentProvider from '../../contexts/CurrentAgent';
20
20
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
21
21
  import useAppearances from '../../hooks/use-appearances';
22
22
  import { useRuntimeState } from '../../state/runtime';
23
- import { useSessionState } from '../../state/session';
23
+ import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
24
24
  export default function SimplePage({ resultTitle, primaryColor }) {
25
25
  const { childAgentId } = useRuntimeState();
26
- useSessionState({ autoLoad: true });
26
+ useAutoLoadSessionState();
27
27
  const inheritedTheme = useTheme();
28
28
  const theme = useMemo(() => {
29
29
  let { primary } = inheritedTheme.palette;
@@ -53,7 +53,7 @@ function AgentInputRender(_a) {
53
53
  }
54
54
  function OutputView(_a) {
55
55
  var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
56
- const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
56
+ const lastMessage = useCurrentSessionState((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
57
57
  return (_jsx(Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && (_jsxs(_Fragment, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(Stack, { children: _jsx(OutputItemView, { message: lastMessage }) })] })) })));
58
58
  }
59
59
  const OutputItemView = memo(({ message }) => {
@@ -19,13 +19,13 @@ import AgentInputField from '../../components/AgentInputField';
19
19
  import LoadingButton from '../../components/LoadingButton';
20
20
  import { useCurrentAgent } from '../../contexts/CurrentAgent';
21
21
  import { useRuntimeState } from '../../state/runtime';
22
- import { useSessionState } from '../../state/session';
22
+ import { useCurrentSessionState } from '../../state/session';
23
23
  import { isValidInput } from '../../utils/agent-inputs';
24
24
  export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
25
25
  const { t } = useLocaleContext();
26
26
  const { aid, agent } = useCurrentAgent();
27
27
  const { execute } = useRuntimeState();
28
- const running = useSessionState()((s) => s.running);
28
+ const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
29
29
  const parameters = useMemo(() => {
30
30
  var _a;
31
31
  return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => {
@@ -79,7 +79,7 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
79
79
  }
80
80
  function useInitialFormValues() {
81
81
  const { agent } = useCurrentAgent();
82
- const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
82
+ const lastMessage = useCurrentSessionState((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
83
83
  const [lastInputs, setLastInputs] = useState();
84
84
  useEffect(() => {
85
85
  if (!lastInputs) {
@@ -20,7 +20,7 @@ import CurrentAgentProvider from '../../contexts/CurrentAgent';
20
20
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
21
21
  import useAppearances from '../../hooks/use-appearances';
22
22
  import { useRuntimeState } from '../../state/runtime';
23
- import { useSessionState } from '../../state/session';
23
+ import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
24
24
  const getLineClamp = (count) => {
25
25
  return {
26
26
  display: '-webkit-box',
@@ -53,9 +53,8 @@ function V0Page({ textColor = '#333', primaryColor }) {
53
53
  const [sessionId] = useState('1');
54
54
  const [message, setMessage] = useState();
55
55
  const { childAgentId } = useRuntimeState();
56
- const messagesList = useSessionState({
57
- autoLoad: true,
58
- })((s) => s.messages);
56
+ useAutoLoadSessionState();
57
+ const messagesList = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
59
58
  useEffect(() => {
60
59
  if (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length) {
61
60
  const lastMessage = messagesList[messagesList.length - 1];