@blocklet/pages-kit 0.2.291 → 0.2.293
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.
- package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +1 -9
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -29
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/RadioField.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +153 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +179 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +13 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +129 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +117 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +109 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +17 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +87 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/index.js +42 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/assistant.js +61 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/runtime.js +56 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/session.js +213 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/utils/map-right.js +10 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +42 -20
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +12 -5
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +16 -7
- package/lib/cjs/builtin/async/ai-runtime/hooks/auth.js +31 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +29 -19
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/cjs/builtin/async/ai-runtime/index.js +38 -30
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -18
- package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +4 -4
- package/lib/cjs/components/CustomComponentRenderer/index.js +0 -1
- package/lib/cjs/components/CustomComponentRenderer/state.js +64 -57
- package/lib/cjs/components/index.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/api/assistant.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/esm/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +2 -10
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -31
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/esm/builtin/async/ai-runtime/components/parameters/RadioField.js +37 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +13 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +149 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +100 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +114 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +80 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +11 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +58 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +14 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/index.js +36 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/assistant.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/runtime.js +52 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/session.js +209 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/utils/map-right.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +21 -22
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +13 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +9 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/auth.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +30 -20
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/esm/builtin/async/ai-runtime/index.js +15 -29
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +17 -20
- package/lib/esm/builtin/async/ai-runtime/state/subscription.js +2 -2
- package/lib/esm/components/CustomComponentRenderer/index.js +0 -1
- package/lib/esm/components/CustomComponentRenderer/state.js +63 -57
- package/lib/esm/components/index.js +1 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +9 -2
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +5 -2
- package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +11 -4
- package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -3
- package/lib/types/builtin/async/ai-runtime/components/parameters/RadioField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/assistant.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/runtime.d.ts +14 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/session.d.ts +29 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/utils/map-right.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/hooks/auth.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +15 -8
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +22 -0
- package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +0 -2
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +0 -3
- package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +1 -1
- package/lib/types/components/CustomComponentRenderer/index.d.ts +0 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +2 -3
- package/lib/types/components/index.d.ts +1 -0
- package/lib/types/types/core.d.ts +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { Masonry } from '@mui/lab';
|
|
4
|
+
import { Box, Skeleton, Stack, ThemeProvider, Typography, createTheme, styled, useTheme } from '@mui/material';
|
|
5
|
+
import { Suspense, useMemo } from 'react';
|
|
6
|
+
import Balancer, { Provider } from 'react-wrap-balancer';
|
|
7
|
+
import CustomComponentRenderer from '../../../../../../../components/CustomComponentRenderer';
|
|
8
|
+
import { useLocaleContext } from '../../../../../../locale';
|
|
9
|
+
import LoadingButton from '../../../LoadingButton';
|
|
10
|
+
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
11
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
12
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
13
|
+
import mapRight from '../../utils/map-right';
|
|
14
|
+
export default function PhotoGallery({ resultTitle, background, primaryColor, }) {
|
|
15
|
+
var _a;
|
|
16
|
+
const { appearancePage, agent } = useRuntimeState();
|
|
17
|
+
const children = useMemo(() => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
20
|
+
}, [agent]);
|
|
21
|
+
const inheritedTheme = useTheme();
|
|
22
|
+
const theme = useMemo(() => {
|
|
23
|
+
let { primary } = inheritedTheme.palette;
|
|
24
|
+
try {
|
|
25
|
+
if (primaryColor) {
|
|
26
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('augment primary color error', { error });
|
|
31
|
+
}
|
|
32
|
+
return createTheme(inheritedTheme, {
|
|
33
|
+
palette: { primary },
|
|
34
|
+
shape: {
|
|
35
|
+
borderRadius: 8,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}, [inheritedTheme, primaryColor]);
|
|
39
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Root, { className: "photo-wall-root", sx: { backgroundImage: `url(${background})` }, children: [_jsx(Stack, { className: "photo-wall-header", children: _jsxs(Provider, { children: [(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) && (_jsx(Typography, { component: "h2", fontSize: 48, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: appearancePage.name }) })), (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.description) && (_jsx(Typography, { fontSize: 20, textAlign: "center", children: _jsx(Balancer, { children: appearancePage.description }) }))] }) }), _jsx(Stack, { className: "photo-wall-input", children: (_a = children === null || children === void 0 ? void 0 : children.agents) === null || _a === void 0 ? void 0 : _a.map((i) => (_jsx(CurrentAgentProvider, { agentId: i.id, children: _jsx(AgentInputRender, {}) }, i.id))) }), _jsxs(Stack, { className: "photo-wall-output", gap: 2, children: [resultTitle && (_jsx(Typography, { component: "h2", fontSize: 48, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(OutputView, {})] })] }) }));
|
|
40
|
+
}
|
|
41
|
+
const Root = styled(Stack)(({ theme }) => theme.unstable_sx({
|
|
42
|
+
gap: { xs: 3, sm: 4, md: 5 },
|
|
43
|
+
width: '100%',
|
|
44
|
+
backgroundSize: '100% auto',
|
|
45
|
+
backgroundRepeat: 'no-repeat',
|
|
46
|
+
backgroundPosition: 'top',
|
|
47
|
+
mt: 4,
|
|
48
|
+
'.photo-wall-header': {
|
|
49
|
+
maxWidth: 'md',
|
|
50
|
+
mx: 'auto',
|
|
51
|
+
width: '100%',
|
|
52
|
+
px: { xs: 2, sm: 3 },
|
|
53
|
+
gap: { xs: 2, sm: 3 },
|
|
54
|
+
},
|
|
55
|
+
'.photo-wall-input': {
|
|
56
|
+
maxWidth: 'md',
|
|
57
|
+
mx: 'auto',
|
|
58
|
+
width: '100%',
|
|
59
|
+
px: { xs: 2, sm: 3 },
|
|
60
|
+
},
|
|
61
|
+
'.photo-wall-output': {
|
|
62
|
+
width: '100%',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
px: { xs: 2, sm: 3 },
|
|
65
|
+
'.photo-wall-item': {
|
|
66
|
+
borderRadius: 1,
|
|
67
|
+
img: {
|
|
68
|
+
borderRadius: 1,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
function AgentInputRender() {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
const { agent } = useCurrentAgent();
|
|
76
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
77
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
78
|
+
return null;
|
|
79
|
+
return (_jsx(Stack, { children: _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps }) }));
|
|
80
|
+
}
|
|
81
|
+
function NoOutputs() {
|
|
82
|
+
return (_jsx(Stack, { mt: 10, children: _jsx(Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
|
|
83
|
+
}
|
|
84
|
+
function OutputView() {
|
|
85
|
+
var _a, _b, _c, _d, _e;
|
|
86
|
+
const { t } = useLocaleContext();
|
|
87
|
+
const { sessionState } = useRuntimeState();
|
|
88
|
+
return (_jsxs(_Fragment, { children: [sessionState.loaded && !((_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.length) && _jsx(NoOutputs, {}), _jsxs(Masonry, { columns: { xs: 2, sm: 3, md: 4, lg: 5 }, spacing: 1, sequential: true, sx: { width: '100%', overflow: 'hidden' }, children: [sessionState.running && (_jsx(Skeleton, { className: "photo-wall-item", variant: "rectangular", sx: {
|
|
89
|
+
// FIXME: default using history height
|
|
90
|
+
height: (_c = (_b = document.getElementsByClassName('photo-wall-item')[0]) === null || _b === void 0 ? void 0 : _b.clientHeight) !== null && _c !== void 0 ? _c : 200,
|
|
91
|
+
} })), mapRight((_d = sessionState.messages) !== null && _d !== void 0 ? _d : [], (message) => (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(OutputItemView, {}) }) }) }, message.taskId)))] }), _jsx(Box, { my: 4, children: !!((_e = sessionState.messages) === null || _e === void 0 ? void 0 : _e.length) && !sessionState.noMoreMessage && (_jsx(LoadingButton, { variant: "outlined", onClick: sessionState.loadMoreMessages, children: t('loadMore') })) })] }));
|
|
92
|
+
}
|
|
93
|
+
function OutputItemView() {
|
|
94
|
+
var _a, _b;
|
|
95
|
+
const { agent } = useCurrentAgent();
|
|
96
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
97
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
98
|
+
return null;
|
|
99
|
+
return _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps });
|
|
100
|
+
}
|
package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
14
|
+
import { Icon } from '@iconify/react';
|
|
15
|
+
import { Box, Button, Dialog, DialogContent, Stack, Typography, alpha, useTheme } from '@mui/material';
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
import { useLocaleContext } from '../../../../../../locale';
|
|
18
|
+
import { ActionButton } from '../../../ActionButton';
|
|
19
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
20
|
+
const getLineClamp = (line) => ({
|
|
21
|
+
display: '-webkit-box',
|
|
22
|
+
WebkitLineClamp: line,
|
|
23
|
+
WebkitBoxOrient: 'vertical',
|
|
24
|
+
overflow: 'hidden',
|
|
25
|
+
overflowWrap: 'break-word',
|
|
26
|
+
textOverflow: 'ellipsis',
|
|
27
|
+
whiteSpace: 'wrap',
|
|
28
|
+
});
|
|
29
|
+
export default function PhotoGalleryItem() {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
const { message } = useCurrentMessage();
|
|
32
|
+
const [openDialog, setOpenDialog] = useState(false);
|
|
33
|
+
const objects = (_b = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : [];
|
|
34
|
+
const images = objects.flatMap((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) !== null && _a !== void 0 ? _a : []; });
|
|
35
|
+
return images.map(({ url }, index) => {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_jsxs(Box, { className: "photo-wall-item", sx: {
|
|
38
|
+
position: 'relative',
|
|
39
|
+
overflow: 'hidden',
|
|
40
|
+
cursor: 'pointer',
|
|
41
|
+
'&:hover': {
|
|
42
|
+
'.photo-wall-item-alt': {
|
|
43
|
+
opacity: 1,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}, onClick: () => setOpenDialog(true), children: [_jsx(Box, { component: "img", src: url, alt: "", width: "100%", height: "100%",
|
|
47
|
+
// 首屏 image 不能用 lazy,会闪烁乱序
|
|
48
|
+
loading: index < 12 ? 'eager' : 'lazy' }), _jsx(Box, { className: "photo-wall-item-alt", sx: {
|
|
49
|
+
position: 'absolute',
|
|
50
|
+
top: 0,
|
|
51
|
+
bottom: 0,
|
|
52
|
+
left: 0,
|
|
53
|
+
right: 0,
|
|
54
|
+
width: '100%',
|
|
55
|
+
height: '100%',
|
|
56
|
+
px: 1.5,
|
|
57
|
+
py: 1,
|
|
58
|
+
display: 'flex',
|
|
59
|
+
alignItems: 'flex-end',
|
|
60
|
+
fontWeight: 500,
|
|
61
|
+
fontSize: 13,
|
|
62
|
+
color: 'white',
|
|
63
|
+
background: 'linear-gradient(to bottom, rgba(2, 7, 19, 0) 0%, rgba(2, 7, 19, 0.8) 100%)',
|
|
64
|
+
opacity: 0,
|
|
65
|
+
transition: 'opacity 0.3s',
|
|
66
|
+
}, children: _jsx(Box, { sx: Object.assign({ lineHeight: 1.5 }, getLineClamp(3)), children: (_a = message.parameters) === null || _a === void 0 ? void 0 : _a.question }) }), openDialog && (_jsx(PromptDialog, { open: true, url: url, onClose: (e) => {
|
|
67
|
+
e.stopPropagation();
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
setOpenDialog(false);
|
|
70
|
+
} }))] }, url));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function PromptDialog(_a) {
|
|
74
|
+
var { url } = _a, props = __rest(_a, ["url"]);
|
|
75
|
+
const { message } = useCurrentMessage();
|
|
76
|
+
const { parameters } = message;
|
|
77
|
+
const theme = useTheme();
|
|
78
|
+
const { t } = useLocaleContext();
|
|
79
|
+
return (_jsxs(Dialog, Object.assign({ fullWidth: true, maxWidth: false, scroll: "paper", slotProps: {
|
|
80
|
+
backdrop: {
|
|
81
|
+
sx: {
|
|
82
|
+
bgcolor: 'rgba(255, 255, 255, 0.4)',
|
|
83
|
+
backdropFilter: 'blur(12px)',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
} }, props, { children: [_jsx(Box, { sx: { position: 'absolute', right: 0, top: 0, p: 0.5 }, children: _jsx(Button, { onClick: (e) => { var _a; return (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props, e, 'backdropClick'); }, variant: "contained", disableElevation: true, sx: {
|
|
87
|
+
bgcolor: (theme) => alpha(theme.palette.primary.light, 0.2),
|
|
88
|
+
minWidth: 32,
|
|
89
|
+
minHeight: 32,
|
|
90
|
+
p: 0,
|
|
91
|
+
fontSize: 22,
|
|
92
|
+
color: 'primary.main',
|
|
93
|
+
':hover': {
|
|
94
|
+
bgcolor: (theme) => alpha(theme.palette.primary.light, 0.3),
|
|
95
|
+
},
|
|
96
|
+
}, children: _jsx(Icon, { icon: "tabler:x" }) }) }), _jsx(DialogContent, { children: _jsxs(Stack, { gap: 4, sx: { flexDirection: { md: 'row' } }, children: [_jsxs(Stack, { sx: { flex: 3, width: { xs: '100%', md: 0 }, gap: 1 }, children: [_jsx(Typography, { component: "h5", sx: { fontSize: 24, fontWeight: 700, color: 'primary.main' }, children: t('photoWall.dialog.title') }), _jsx(Box, { component: "img", src: url, alt: "", loading: "lazy", sx: {
|
|
97
|
+
display: 'block',
|
|
98
|
+
width: '100%',
|
|
99
|
+
borderRadius: 1,
|
|
100
|
+
} })] }), _jsxs(Stack, { sx: { flex: 2, width: { xs: '100%', md: 0 }, gap: 1 }, children: [_jsx(Typography, { component: "h5", sx: { fontSize: 24, fontWeight: 700, color: 'primary.main' }, children: t('photoWall.dialog.prompt') }), _jsx(Box, { sx: {
|
|
101
|
+
p: 2,
|
|
102
|
+
borderRadius: 1,
|
|
103
|
+
background: (theme) => `linear-gradient(to top, ${alpha(theme.palette.primary.light, 0.5)}, ${alpha(theme.palette.primary.light, 0.1)})`,
|
|
104
|
+
}, children: _jsx(Box, { sx: {
|
|
105
|
+
backgroundColor: 'rgba(255,255,255,0.2)',
|
|
106
|
+
borderRadius: 1,
|
|
107
|
+
p: 1,
|
|
108
|
+
fontSize: 16,
|
|
109
|
+
}, children: parameters === null || parameters === void 0 ? void 0 : parameters.question }) }), _jsx(Box, { children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "contained", placement: "right", tip: t('copyToClipboard'), title: t('copy'), titleSucceed: t('copied'), icon: "tabler:copy", iconSucceed: "tabler:copy-check-filled", onClick: () => {
|
|
110
|
+
window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
|
|
111
|
+
}, sx: {
|
|
112
|
+
borderRadius: theme.shape.borderRadius,
|
|
113
|
+
} }) })] })] }) })] })));
|
|
114
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { Box, Stack, ThemeProvider, Typography, createTheme, useTheme } from '@mui/material';
|
|
4
|
+
import { Suspense, useEffect, useMemo } from 'react';
|
|
5
|
+
import Balancer, { Provider } from 'react-wrap-balancer';
|
|
6
|
+
import CustomComponentRenderer from '../../../../../../../components/CustomComponentRenderer';
|
|
7
|
+
import { MessageSuggestedQuestions } from '../../../common';
|
|
8
|
+
import ScrollView, { useScrollToBottomModule } from '../../../ScrollView';
|
|
9
|
+
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
10
|
+
import CurrentMessageProvider, { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
11
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
12
|
+
export default function SimpleChat({ primaryColor }) {
|
|
13
|
+
const inheritedTheme = useTheme();
|
|
14
|
+
const theme = useMemo(() => {
|
|
15
|
+
let { primary } = inheritedTheme.palette;
|
|
16
|
+
try {
|
|
17
|
+
if (primaryColor) {
|
|
18
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error('augment primary color error', { error });
|
|
23
|
+
}
|
|
24
|
+
return createTheme(inheritedTheme, {
|
|
25
|
+
palette: { primary },
|
|
26
|
+
shape: {
|
|
27
|
+
borderRadius: 8,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}, [inheritedTheme, primaryColor]);
|
|
31
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(ScrollView, { scroller: "window", initialScrollBehavior: "auto", children: _jsx(SimpleChatView, {}) }) }));
|
|
32
|
+
}
|
|
33
|
+
function SimpleChatView() {
|
|
34
|
+
var _a;
|
|
35
|
+
const { agent, appearancePage, sessionState } = useRuntimeState();
|
|
36
|
+
const scrollToBottom = useScrollToBottomModule().useScrollToBottom();
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (sessionState.running)
|
|
39
|
+
scrollToBottom();
|
|
40
|
+
}, [scrollToBottom, sessionState.running]);
|
|
41
|
+
const children = useMemo(() => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
44
|
+
}, [agent]);
|
|
45
|
+
return (_jsxs(Stack, { flexGrow: 1, maxWidth: "md", width: "100%", mx: "auto", px: { xs: 2, sm: 3 }, children: [_jsx(Stack, { gap: 2, mt: 8, mb: 4, children: _jsxs(Provider, { children: [(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) && (_jsx(Typography, { component: "h5", fontSize: 30, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: appearancePage.name }) })), (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.description) && (_jsx(Typography, { textAlign: "center", children: _jsx(Balancer, { children: appearancePage.description }) }))] }) }), _jsx(Stack, { children: _jsx(OutputView, {}) }), _jsx(Box, { flexGrow: 1, minHeight: 200 }), _jsx(Stack, { sx: { position: 'sticky', bottom: 0, py: 1, bgcolor: 'background.paper', zIndex: 10 }, children: (_a = children === null || children === void 0 ? void 0 : children.agents) === null || _a === void 0 ? void 0 : _a.map((i) => (_jsx(CurrentAgentProvider, { agentId: i.id, children: _jsx(AgentInputRender, {}) }, i.id))) })] }));
|
|
46
|
+
}
|
|
47
|
+
function AgentInputRender() {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
const { agent } = useCurrentAgent();
|
|
50
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
51
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
52
|
+
return null;
|
|
53
|
+
return (_jsx(Stack, { children: _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps }) }));
|
|
54
|
+
}
|
|
55
|
+
function OutputView() {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const { sessionState } = useRuntimeState();
|
|
58
|
+
const lastMessage = (_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
|
|
59
|
+
return (_jsxs(Stack, { gap: 2, children: [(_b = sessionState.messages) === null || _b === void 0 ? void 0 : _b.map((message) => (_jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(OutputItemView, {}) }) }) }) }))), lastMessage && (_jsx(CurrentAgentProvider, { agentId: lastMessage.assistantId, children: _jsx(CurrentMessageProvider, { message: lastMessage, children: _jsx(SuggestedQuestionsView, {}) }) }))] }));
|
|
60
|
+
}
|
|
61
|
+
function OutputItemView() {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
const { agent } = useCurrentAgent();
|
|
64
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
65
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
66
|
+
return null;
|
|
67
|
+
return _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps });
|
|
68
|
+
}
|
|
69
|
+
function SuggestedQuestionsView() {
|
|
70
|
+
const { execute } = useRuntimeState();
|
|
71
|
+
const { aid } = useCurrentAgent();
|
|
72
|
+
const { message } = useCurrentMessage();
|
|
73
|
+
const suggestedQuestions = useMemo(() => {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data[RuntimeOutputVariable.suggestedQuestions];
|
|
76
|
+
}, [message]);
|
|
77
|
+
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? (_jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
78
|
+
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
79
|
+
} })) : null }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Stack } from '@mui/material';
|
|
3
|
+
import { MessageMetadataRenderer } from '../../../common';
|
|
4
|
+
import MarkdownRenderer from '../../../MarkdownRenderer';
|
|
5
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
6
|
+
export default function BaseOutputs() {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const { message } = useCurrentMessage();
|
|
9
|
+
const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
|
|
10
|
+
return (_jsxs(Stack, { gap: 2, boxShadow: 1, borderRadius: 1, p: 2, children: [_jsx(MarkdownRenderer, { children: (_b = message.result) === null || _b === void 0 ? void 0 : _b.content }), objects === null || objects === void 0 ? void 0 : objects.map((item) => _jsx(MessageMetadataRenderer, { object: item.data }))] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { Stack, ThemeProvider, Typography, createTheme, useTheme } from '@mui/material';
|
|
4
|
+
import { Suspense, useMemo } from 'react';
|
|
5
|
+
import Balancer, { Provider } from 'react-wrap-balancer';
|
|
6
|
+
import CustomComponentRenderer from '../../../../../../../components/CustomComponentRenderer';
|
|
7
|
+
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
8
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
9
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
10
|
+
export default function SimplePage({ resultTitle, primaryColor }) {
|
|
11
|
+
var _a;
|
|
12
|
+
const { agent, appearancePage } = useRuntimeState();
|
|
13
|
+
const children = useMemo(() => {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
16
|
+
}, [agent]);
|
|
17
|
+
const inheritedTheme = useTheme();
|
|
18
|
+
const theme = useMemo(() => {
|
|
19
|
+
let { primary } = inheritedTheme.palette;
|
|
20
|
+
try {
|
|
21
|
+
if (primaryColor) {
|
|
22
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('augment primary color error', { error });
|
|
27
|
+
}
|
|
28
|
+
return createTheme(inheritedTheme, {
|
|
29
|
+
palette: { primary },
|
|
30
|
+
shape: {
|
|
31
|
+
borderRadius: 8,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}, [inheritedTheme, primaryColor]);
|
|
35
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Stack, { gap: 2, maxWidth: "md", width: "100%", mx: "auto", px: { xs: 2, sm: 3 }, children: [_jsx(Stack, { gap: 2, mt: 8, mb: 4, children: _jsxs(Provider, { children: [(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) && (_jsx(Typography, { component: "h5", fontSize: 30, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: appearancePage.name }) })), (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.description) && (_jsx(Typography, { textAlign: "center", children: _jsx(Balancer, { children: appearancePage.description }) }))] }) }), _jsx(Stack, { children: (_a = children === null || children === void 0 ? void 0 : children.agents) === null || _a === void 0 ? void 0 : _a.map((i) => (_jsx(CurrentAgentProvider, { agentId: i.id, children: _jsx(AgentInputRender, {}) }, i.id))) }), _jsx(Stack, { children: _jsx(OutputView, { resultTitle: resultTitle }) })] }) }));
|
|
36
|
+
}
|
|
37
|
+
function AgentInputRender() {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const { agent } = useCurrentAgent();
|
|
40
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
41
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
42
|
+
return null;
|
|
43
|
+
return (_jsx(Stack, { children: _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps }) }));
|
|
44
|
+
}
|
|
45
|
+
function OutputView({ resultTitle }) {
|
|
46
|
+
var _a;
|
|
47
|
+
const { sessionState } = useRuntimeState();
|
|
48
|
+
const lastMessage = (_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
|
|
49
|
+
return (_jsx(Stack, { gap: 2, children: lastMessage && (_jsxs(_Fragment, { children: [_jsx(Stack, { children: resultTitle && (_jsx(Typography, { component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })) }), _jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: lastMessage.assistantId, children: _jsx(CurrentMessageProvider, { message: lastMessage, children: _jsx(Suspense, { children: _jsx(OutputItemView, {}) }) }) }) })] })) }));
|
|
50
|
+
}
|
|
51
|
+
function OutputItemView() {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const { agent } = useCurrentAgent();
|
|
54
|
+
const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
55
|
+
if (!(input === null || input === void 0 ? void 0 : input.componentId))
|
|
56
|
+
return null;
|
|
57
|
+
return _jsx(CustomComponentRenderer, { componentId: input.componentId, properties: input.componentProps });
|
|
58
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
import { parseIdentity, stringifyIdentity } from '../../../utils';
|
|
4
|
+
import { useAssistantState } from '../state/assistant';
|
|
5
|
+
import { useRuntimeState } from '../state/runtime';
|
|
6
|
+
const context = createContext(undefined);
|
|
7
|
+
export default function CurrentAgentProvider({ agentId, children }) {
|
|
8
|
+
const { aid } = useRuntimeState();
|
|
9
|
+
const state = useMemo(() => ({
|
|
10
|
+
aid: stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(aid, { rejectWhenError: true })), { assistantId: agentId })),
|
|
11
|
+
}), [aid, agentId]);
|
|
12
|
+
return _jsx(context.Provider, { value: state, children: children });
|
|
13
|
+
}
|
|
14
|
+
export function useCurrentAgent() {
|
|
15
|
+
const { working } = useRuntimeState();
|
|
16
|
+
const current = useContext(context);
|
|
17
|
+
if (!current) {
|
|
18
|
+
throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
|
|
19
|
+
}
|
|
20
|
+
const [agent] = useAssistantState({ aid: current.aid, working });
|
|
21
|
+
return Object.assign(Object.assign({}, current), { agent });
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
3
|
+
const context = createContext(undefined);
|
|
4
|
+
export default function CurrentMessageProvider({ message, children }) {
|
|
5
|
+
const state = useMemo(() => ({ message }), [message]);
|
|
6
|
+
return _jsx(context.Provider, { value: state, children: children });
|
|
7
|
+
}
|
|
8
|
+
export function useCurrentMessage() {
|
|
9
|
+
const current = useContext(context);
|
|
10
|
+
if (!current) {
|
|
11
|
+
throw new Error('No such message state. You should use `useCurrentMessage` within the `CurrentMessageProvider`');
|
|
12
|
+
}
|
|
13
|
+
return current;
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { Box } from '@mui/material';
|
|
4
|
+
import { useEffect } from 'react';
|
|
5
|
+
import { Helmet } from 'react-helmet';
|
|
6
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
7
|
+
import { Avatar } from '../../../../arcblock/ux';
|
|
8
|
+
import { useHeaderState } from '../../../../page/header';
|
|
9
|
+
import RuntimeProvider from '../RuntimeProvider';
|
|
10
|
+
import { useRuntimeState } from './state/runtime';
|
|
11
|
+
export default function Runtime() {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const { agent, appearancePage, sessionState } = useRuntimeState();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
useHeaderState.setState((state) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const logo = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _a === void 0 ? void 0 : _a.url;
|
|
18
|
+
state.logo = logo && _jsx(Box, { component: Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: 44 });
|
|
19
|
+
state.brand = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name;
|
|
20
|
+
});
|
|
21
|
+
return () => {
|
|
22
|
+
useHeaderState.setState((state) => {
|
|
23
|
+
state.logo = undefined;
|
|
24
|
+
state.brand = undefined;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
}, [appearancePage]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
sessionState.load();
|
|
30
|
+
}, []);
|
|
31
|
+
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
32
|
+
const componentId = appearance === null || appearance === void 0 ? void 0 : appearance.componentId;
|
|
33
|
+
if (!componentId)
|
|
34
|
+
throw new Error('Missing output `appearance`');
|
|
35
|
+
return (_jsxs(RuntimeProvider, { children: [appearancePage && (_jsxs(Helmet, { children: [appearancePage.name && _jsx("title", { children: appearancePage.name }), appearancePage.description && _jsx("meta", { name: "description", content: appearancePage.description })] })), _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearance.componentProps })] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
import { create } from 'zustand';
|
|
11
|
+
import { immer } from 'zustand/middleware/immer';
|
|
12
|
+
import { getAssistant } from '../../../api/assistant';
|
|
13
|
+
const STATES = {};
|
|
14
|
+
export const createAssistantState = ({ aid, working, assistant, }) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const key = working ? `${aid}-working` : aid;
|
|
17
|
+
(_a = STATES[key]) !== null && _a !== void 0 ? _a : (STATES[key] = create()(immer((set) => ({
|
|
18
|
+
assistant,
|
|
19
|
+
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
set((state) => {
|
|
21
|
+
state.loading = true;
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
const assistant = yield getAssistant({ assistantId: aid, working });
|
|
25
|
+
set((state) => {
|
|
26
|
+
state.assistant = assistant;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(error);
|
|
31
|
+
set((state) => {
|
|
32
|
+
state.error = error;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
set((state) => {
|
|
37
|
+
state.loading = false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
}))));
|
|
42
|
+
return STATES[key];
|
|
43
|
+
};
|
|
44
|
+
const LOADING_TASKS = {};
|
|
45
|
+
export function useAssistantState({ aid, working }) {
|
|
46
|
+
var _a;
|
|
47
|
+
const state = createAssistantState({ aid, working })();
|
|
48
|
+
if (!state.assistant) {
|
|
49
|
+
if (state.error)
|
|
50
|
+
throw state.error;
|
|
51
|
+
const key = working ? `${aid}-working` : aid;
|
|
52
|
+
(_a = LOADING_TASKS[key]) !== null && _a !== void 0 ? _a : (LOADING_TASKS[key] = state.load());
|
|
53
|
+
throw LOADING_TASKS[key];
|
|
54
|
+
}
|
|
55
|
+
return [state.assistant, state];
|
|
56
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
11
|
+
import { useCallback, useEffect, useMemo } from 'react';
|
|
12
|
+
import { useSearchParams } from 'react-router-dom';
|
|
13
|
+
import { useSessionContext } from '../../../../../session';
|
|
14
|
+
import { CustomError } from '../../../error';
|
|
15
|
+
import { useAssistantState } from './assistant';
|
|
16
|
+
import { createSessionState } from './session';
|
|
17
|
+
export function useRuntimeState() {
|
|
18
|
+
var _a;
|
|
19
|
+
const [query] = useSearchParams();
|
|
20
|
+
const aid = query.get('aid');
|
|
21
|
+
if (!aid)
|
|
22
|
+
throw new CustomError(404, 'Missing required query parameters `aid`');
|
|
23
|
+
const working = query.get('working') === 'true';
|
|
24
|
+
const [agent] = useAssistantState({ aid, working });
|
|
25
|
+
const sessionState = createSessionState({ aid })();
|
|
26
|
+
const { session: authSession } = useSessionContext();
|
|
27
|
+
// reset state after logged out
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
var _a;
|
|
30
|
+
if (!((_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did)) {
|
|
31
|
+
sessionState.reset();
|
|
32
|
+
}
|
|
33
|
+
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did]);
|
|
34
|
+
const login = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield new Promise((resolve) => {
|
|
36
|
+
authSession.login(() => resolve());
|
|
37
|
+
});
|
|
38
|
+
yield Promise.all([sessionState.load()]);
|
|
39
|
+
}), [aid, authSession, sessionState]);
|
|
40
|
+
const execute = useCallback((args) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
if (!authSession.user) {
|
|
42
|
+
yield login();
|
|
43
|
+
}
|
|
44
|
+
return sessionState.execute(Object.assign(Object.assign({}, args), { working }));
|
|
45
|
+
}), [authSession.user, login, sessionState]);
|
|
46
|
+
const appearancePage = useMemo(() => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const initialValue = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
49
|
+
return initialValue;
|
|
50
|
+
}, [agent]);
|
|
51
|
+
return { aid, working, agent, appearancePage, sessionState, execute };
|
|
52
|
+
}
|