@blocklet/pages-kit 0.2.317 → 0.2.319

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 (52) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +26 -0
  2. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.js +2 -2
  3. package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +1 -1
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +13 -9
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +66 -36
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +190 -57
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +101 -0
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +60 -0
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +152 -0
  11. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +80 -0
  12. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +32 -0
  13. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +54 -0
  14. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/utils.js +13 -0
  15. package/lib/cjs/builtin/async/ai-runtime/state/session.js +52 -23
  16. package/lib/cjs/components/CustomComponentRenderer/state.js +23 -4
  17. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  18. package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
  19. package/lib/esm/builtin/async/ai-runtime/locales/index.js +26 -0
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.js +2 -2
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +1 -1
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +16 -12
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +60 -30
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +191 -58
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +92 -0
  27. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +55 -0
  28. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +144 -0
  29. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +75 -0
  30. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +26 -0
  31. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +49 -0
  32. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/utils.js +9 -0
  33. package/lib/esm/builtin/async/ai-runtime/state/session.js +52 -23
  34. package/lib/esm/components/CustomComponentRenderer/state.js +22 -4
  35. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  36. package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
  37. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +1 -0
  38. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +26 -0
  39. package/lib/types/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.d.ts +2 -1
  40. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +1 -1
  41. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.d.ts +20 -0
  42. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.d.ts +6 -0
  43. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/Loading.d.ts +3 -0
  44. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.d.ts +6 -0
  45. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.d.ts +3 -0
  46. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.d.ts +16 -0
  47. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/utils.d.ts +7 -0
  48. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +11 -3
  49. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -0
  50. package/lib/types/tsconfig.tsbuildinfo +1 -1
  51. package/lib/types/types/core.d.ts +2 -1
  52. package/package.json +7 -7
@@ -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)
@@ -10,28 +19,28 @@ var __rest = (this && this.__rest) || function (s, e) {
10
19
  return t;
11
20
  };
12
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { Box, Card, CardContent, Container, Grid, Stack, ThemeProvider, Typography, createTheme, useTheme, } from '@mui/material';
14
- import dayjs from 'dayjs';
22
+ import Empty from '@arcblock/ux/lib/Empty';
23
+ import RelativeTime from '@arcblock/ux/lib/RelativeTime';
15
24
  // import { useRuntimeState } from '@blocklet/pages-kit/builtin/async/ai-runtime';
16
- // import { Icon } from 'iconify/react';
17
- import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
25
+ import { Icon } from '@iconify/react';
26
+ import { Masonry } from '@mui/lab';
27
+ import { Box, Button, Chip, Container, IconButton, Stack, ThemeProvider, Tooltip, Typography, createTheme, useTheme, } from '@mui/material';
28
+ import { Suspense, useEffect, useMemo, useRef } from 'react';
18
29
  import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
30
+ import { useLocaleContext } from '../../../../locale';
19
31
  import { useActiveAgent } from '../../contexts/ActiveAgent';
20
32
  import CurrentAgentProvider from '../../contexts/CurrentAgent';
21
33
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
22
34
  import useAppearances from '../../hooks/use-appearances';
23
- import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
24
- const getLineClamp = (count) => {
25
- return {
26
- display: '-webkit-box',
27
- WebkitLineClamp: count,
28
- WebkitBoxOrient: 'vertical',
29
- overflow: 'hidden',
30
- textOverflow: 'ellipsis',
31
- };
32
- };
35
+ import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
36
+ import { CodeRenderByMessageMemo as CodeRenderByMessage } from './components/CodePreview';
37
+ import ConfirmDialog from './components/ConfirmDialog';
38
+ import Loading from './components/Loading';
39
+ import UserQuestion from './components/UserQuestion';
40
+ import { V0RuntimeProvider, useV0RuntimeContext } from './contexts/V0Runtime';
41
+ import { getLineClamp } from './utils';
42
+ const sliderWidth = 200;
33
43
  function V0Page({ textColor = '#333', primaryColor }) {
34
- var _a;
35
44
  const inheritedTheme = useTheme();
36
45
  const theme = useMemo(() => {
37
46
  let { primary } = inheritedTheme.palette;
@@ -44,98 +53,242 @@ function V0Page({ textColor = '#333', primaryColor }) {
44
53
  console.error('augment primary color error', { error });
45
54
  }
46
55
  return createTheme(inheritedTheme, {
47
- palette: { primary, textColor },
56
+ palette: { primary, textColor, background: { block: '#f9f9f9' } },
48
57
  shape: {
49
58
  borderRadius: 8,
50
59
  },
51
60
  });
52
61
  }, [inheritedTheme, primaryColor, textColor]);
53
- const [sessionId] = useState('1');
54
- const [message, setMessage] = useState();
62
+ useAutoLoadSessionState({
63
+ autoSetCurrentSessionId: false,
64
+ });
65
+ const { currentSessionId } = useSessionState((s) => s) || {};
55
66
  const { activeAgentId } = useActiveAgent();
56
- useAutoLoadSessionState();
57
- const messagesList = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
58
- useEffect(() => {
59
- if (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length) {
60
- const lastMessage = messagesList[messagesList.length - 1];
61
- // @ts-ignore
62
- setMessage(lastMessage);
63
- }
64
- }, [messagesList]);
65
- const SliderRender = useCallback(({ message }) => {
66
- // if is detail, return output
67
- if (sessionId && (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length)) {
68
- return (_jsx(Box, { sx: {
69
- width: 200,
70
- p: 2,
71
- position: 'sticky',
72
- top: 64,
73
- height: 'calc(100vh - 65px)',
74
- overflowY: 'auto',
75
- }, children: _jsx(Stack, { spacing: 2, justifyContent: "center", children: messagesList === null || messagesList === void 0 ? void 0 : messagesList.map((_, i) => {
76
- var _a;
77
- const isCurrent = _.taskId === (message === null || message === void 0 ? void 0 : message.taskId);
78
- return (_jsxs(Box, { onClick: () => {
79
- // @ts-ignore
80
- setMessage(_);
81
- }, sx: {
82
- cursor: 'pointer',
83
- backgroundColor: isCurrent ? 'primary.main' : 'rgba(0, 0, 0, 0.5)',
84
- color: '#fff',
85
- borderRadius: 1,
86
- p: 1,
87
- }, children: [_jsx(Typography, { variant: "caption", display: "block", sx: Object.assign({ color: 'rgba(255, 255, 255, 0.9)' }, getLineClamp(2)), children: (_a = _.parameters) === null || _a === void 0 ? void 0 : _a.question }), _jsx(Box, { children: _jsxs(Typography, { sx: {
88
- textAlign: 'right',
89
- fontWeight: 600,
90
- fontSize: 12,
91
- mt: 0.5,
92
- display: 'flex',
93
- justifyContent: 'space-between',
94
- }, children: [_jsx("span", { style: {
95
- color: 'rgba(255, 255, 255, 0.7)',
96
- fontWeight: 400,
97
- }, children: dayjs(_.updatedAt).format('MM-DD HH:mm') }), _jsx("span", { children: `V${i}` })] }) })] }, _.assistantId));
98
- }) }) }, "slider"));
99
- }
100
- return null;
101
- }, [JSON.stringify(messagesList)]);
102
- const ContentRender = useCallback(() => {
103
- // if is detail, return output
104
- if (sessionId) {
105
- return (_jsx(Box, { flex: 1, children: _jsx(AgentOutputRender, { message: message }) }));
106
- }
107
- return (_jsx(Box, { flex: 1, children: _jsx(Grid, { container: true, spacing: 2, justifyContent: "center", children: [...Array(3)].map((_, i) => (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 4, children: _jsx(Card, { sx: { backgroundColor: 'rgba(0, 0, 0, 0.5)', color: '#fff' }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "body2", sx: { mb: 1 }, children: `Code Snippet ${i + 1}` }), _jsx(Typography, { variant: "caption", display: "block", sx: { color: 'rgba(255, 255, 255, 0.7)' }, children: `This is history requirement ${i + 1}` })] }) }) }, i))) }) }));
108
- }, [JSON.stringify(message)]);
109
- return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsxs(Box, { sx: {
110
- display: 'flex',
111
- // background: 'linear-gradient(135deg, #1a237e 0%, #3c3f41 100%)',
112
- }, children: [_jsx(SliderRender, { message: message }), _jsxs(Container, { sx: {
113
- minHeight: 'calc(100vh - 64px - 1px)',
67
+ return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(V0RuntimeProvider, { children: _jsx(Box, { flex: 1, children: _jsxs(Container, { sx: {
68
+ height: 'calc(100vh - 64px - 1px)',
114
69
  textAlign: 'center',
115
- py: 2,
116
- pt: 10,
70
+ pt: 3,
117
71
  gap: 2,
118
72
  display: 'flex',
119
73
  flexDirection: 'column',
120
- }, children: [_jsx(Typography, { variant: "h2", color: "textColor", sx: { fontWeight: 'bold' }, children: "AIGNE V0" }), _jsx(Typography, { variant: "h5", color: "textColor", sx: Object.assign({}, getLineClamp(5)), children: ((_a = message === null || message === void 0 ? void 0 : message.parameters) === null || _a === void 0 ? void 0 : _a.question) || 'A v0 release to help you build code quickly' }), _jsx(ContentRender, {}), _jsx(Box, { sx: {
74
+ position: 'relative',
75
+ '.code-preview-wrapper': {},
76
+ }, children: [_jsx(Box, { sx: {
77
+ flex: 1,
78
+ height: currentSessionId ? 'calc(100% - 48px - 16px - 16px)' : 'unset',
79
+ }, children: currentSessionId ? _jsx(V0DetailRender, {}) : _jsx(V0ListRender, {}) }), _jsx(Box, { sx: {
121
80
  position: 'sticky',
122
81
  bottom: 0,
123
82
  backgroundColor: 'white',
124
- pt: 4,
125
- }, children: _jsx(AgentInputRender, {}) })] })] }) }) }));
83
+ py: 2,
84
+ pt: currentSessionId ? 0 : 2,
85
+ }, children: _jsx(AgentInputRender, {}) })] }) }) }) }) }));
126
86
  }
127
87
  export default V0Page;
88
+ function V0ListRender() {
89
+ const ConfirmDialogRef = useRef();
90
+ const { sessions: sessionsList, setCurrentSessionId, loadLatestMessagesForAllSessions, sessionMap, deleteSession, loading, } = useSessionState((s) => s) || {};
91
+ const { t } = useLocaleContext();
92
+ useEffect(() => {
93
+ const loadData = () => __awaiter(this, void 0, void 0, function* () {
94
+ if (sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.length) {
95
+ yield loadLatestMessagesForAllSessions();
96
+ }
97
+ });
98
+ loadData();
99
+ }, [sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.length]);
100
+ return (_jsxs(Box, { flex: 1, children: [_jsx(Typography, { variant: "h2", color: "textColor", sx: { fontWeight: 'bold', mt: 6 }, children: t('v0.title') }), _jsx(Typography, { variant: "h5", color: "textColor", sx: Object.assign(Object.assign({}, getLineClamp(5)), { mt: 2 }), children: t('v0.description') }), loading ? (_jsx(Loading, { sx: {
101
+ position: 'relative',
102
+ height: '40vh',
103
+ width: '100%',
104
+ } })) : (_jsxs(Box, { sx: {
105
+ mt: 8,
106
+ }, children: [(sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.length) ? (_jsx(Masonry, { columns: { xs: 2, sm: 3, md: 4, lg: 4 }, sequential: true, spacing: 2, children: sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.map((item) => {
107
+ var _a, _b;
108
+ const { name, id } = item;
109
+ const latestMessage = (_b = (_a = sessionMap === null || sessionMap === void 0 ? void 0 : sessionMap[id]) === null || _a === void 0 ? void 0 : _a.messages) === null || _b === void 0 ? void 0 : _b.at(-1);
110
+ return (_jsxs(Box, { sx: {
111
+ display: 'flex',
112
+ justifyContent: 'center',
113
+ flexDirection: 'column',
114
+ gap: 1,
115
+ }, children: [_jsx(Box, { sx: {
116
+ border: 2,
117
+ borderRadius: 1,
118
+ borderColor: 'background.block',
119
+ backgroundColor: 'background.block',
120
+ display: 'flex',
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ cursor: 'pointer',
124
+ transition: 'all 0.3s',
125
+ overflow: 'hidden',
126
+ minHeight: sliderWidth,
127
+ maxHeight: '50vh',
128
+ '&:hover': {
129
+ borderColor: 'primary.main',
130
+ },
131
+ }, onClick: () => {
132
+ setCurrentSessionId(id);
133
+ }, children: _jsx(CodeRenderByMessage, { zoom: 0.5, message: latestMessage, sx: {
134
+ pointerEvents: 'none',
135
+ } }) }), _jsxs(Box, { sx: {
136
+ display: 'flex',
137
+ alignItems: 'center',
138
+ justifyContent: 'space-between',
139
+ }, children: [_jsx(UserQuestion, { question: name }), _jsx(Box, { children: _jsx(IconButton, { color: "error", size: "small", onClick: () => {
140
+ var _a, _b;
141
+ (_b = (_a = ConfirmDialogRef === null || ConfirmDialogRef === void 0 ? void 0 : ConfirmDialogRef.current) === null || _a === void 0 ? void 0 : _a.open) === null || _b === void 0 ? void 0 : _b.call(_a, {
142
+ title: t('v0.deleteSessionTitle', { name }),
143
+ children: _jsx(Box, { children: t('v0.deleteSessionTip') }),
144
+ onConfirm: () => __awaiter(this, void 0, void 0, function* () {
145
+ yield deleteSession({
146
+ sessionId: id,
147
+ autoSetCurrentSessionId: false,
148
+ });
149
+ }),
150
+ onConfirmProps: {
151
+ color: 'error',
152
+ children: t('delete'),
153
+ },
154
+ onCancelProps: {
155
+ color: 'inherit',
156
+ },
157
+ });
158
+ }, children: _jsx(Icon, { icon: "tabler:trash" }) }) })] })] }, id));
159
+ }) }, "masonry-list")) : (_jsx(Box, { sx: {
160
+ mt: 12,
161
+ }, children: _jsx(Empty, { children: t('v0.noData') }) })), _jsx(ConfirmDialog, { ref: ConfirmDialogRef })] }))] }, "list-render"));
162
+ }
163
+ function V0DetailRender() {
164
+ const { setCurrentSessionId } = useSessionState((s) => s) || {};
165
+ const { messages: messagesList, loading } = useCurrentSessionState((s) => s) || {};
166
+ const { currentMessageTaskId, setCurrentMessageTaskId, propertiesValueMap } = useV0RuntimeContext();
167
+ const { t } = useLocaleContext();
168
+ const currentMessage = messagesList === null || messagesList === void 0 ? void 0 : messagesList.find((item) => item.taskId === currentMessageTaskId);
169
+ useEffect(() => {
170
+ if (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length) {
171
+ const latestMessage = messagesList === null || messagesList === void 0 ? void 0 : messagesList.at(-1);
172
+ // no currentMessageTaskId or has new message
173
+ if (!currentMessageTaskId || (currentMessageTaskId === (latestMessage === null || latestMessage === void 0 ? void 0 : latestMessage.taskId) && (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length) > 1)) {
174
+ // @ts-ignore
175
+ setCurrentMessageTaskId(latestMessage.taskId);
176
+ }
177
+ }
178
+ }, [messagesList, currentMessageTaskId]);
179
+ return (_jsxs(Box, { flex: 1, sx: {
180
+ display: 'flex',
181
+ gap: 2,
182
+ height: '100%',
183
+ }, children: [_jsxs(Box, { sx: {
184
+ width: sliderWidth,
185
+ gap: 2,
186
+ display: 'flex',
187
+ flexDirection: 'column',
188
+ height: '100%',
189
+ backgroundColor: 'background.block',
190
+ borderRadius: 1,
191
+ p: 2,
192
+ position: 'relative',
193
+ }, children: [_jsx(Button, { variant: "outlined", size: "small", startIcon: _jsx(Icon, { icon: "tabler:chevron-left" }), onClick: () => {
194
+ setCurrentMessageTaskId(undefined);
195
+ setCurrentSessionId('');
196
+ }, sx: {
197
+ backgroundColor: 'white',
198
+ }, children: t('back') }), loading && (_jsx(Loading, { sx: {
199
+ position: 'absolute',
200
+ width: '80px',
201
+ height: '80px',
202
+ zIndex: 99999,
203
+ top: 0,
204
+ left: 0,
205
+ right: 0,
206
+ bottom: 0,
207
+ margin: 'auto',
208
+ background: 'rgba(255, 255, 255, 0.8)',
209
+ opacity: 0.8,
210
+ borderRadius: 1,
211
+ boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)',
212
+ } })), _jsx(Stack, { spacing: 2, sx: {
213
+ overflowY: 'auto',
214
+ overflowX: 'hidden',
215
+ // scrollbarWidth: 'thin',
216
+ // scrollbarColor: 'grey transparent',
217
+ '&::-webkit-scrollbar': {
218
+ display: 'none',
219
+ },
220
+ }, children: messagesList === null || messagesList === void 0 ? void 0 : messagesList.map((item, i) => {
221
+ const { parameters, taskId, updatedAt } = item;
222
+ const isCurrent = taskId === (currentMessageTaskId || undefined);
223
+ return (_jsx(Box, { sx: {
224
+ display: 'flex',
225
+ justifyContent: 'center',
226
+ flexDirection: 'column',
227
+ gap: 1,
228
+ }, children: _jsxs(Box, { onClick: () => {
229
+ // @ts-ignore
230
+ setCurrentMessageTaskId(item.taskId);
231
+ }, sx: {
232
+ cursor: 'pointer',
233
+ color: 'textColor',
234
+ borderRadius: 1,
235
+ border: 1,
236
+ borderColor: isCurrent ? 'primary.main' : 'background.block',
237
+ backgroundColor: 'white',
238
+ position: 'relative',
239
+ transition: 'all 0.3s',
240
+ '&:hover': {
241
+ borderColor: isCurrent ? 'primary.main' : 'textColor',
242
+ },
243
+ minHeight: sliderWidth / 2,
244
+ maxHeight: '50vh',
245
+ }, children: [_jsx(CodeRenderByMessage, { zoom: 0.25, message: item, sx: {
246
+ pointerEvents: 'none',
247
+ }, propertiesValueMap: propertiesValueMap }), _jsx(Tooltip, { placement: "right", arrow: true, PopperProps: {
248
+ // disablePortal: true,
249
+ }, TransitionProps: {
250
+ timeout: {
251
+ appear: 500,
252
+ enter: 500,
253
+ exit: 0,
254
+ },
255
+ }, title: _jsxs(Box, { children: [_jsx(Typography, { sx: {
256
+ fontSize: 13,
257
+ fontWeight: 500,
258
+ color: 'white',
259
+ }, children: parameters === null || parameters === void 0 ? void 0 : parameters.question }), _jsx(Box, { sx: {
260
+ fontSize: 12,
261
+ opacity: 0.75,
262
+ }, children: _jsx(RelativeTime, { value: updatedAt }) })] }), children: _jsx(Chip, { label: `V${i}`, size: "small", variant: "outlined", sx: {
263
+ fontWeight: 500,
264
+ fontSize: 10,
265
+ height: 20,
266
+ position: 'absolute',
267
+ bottom: 4,
268
+ right: 4,
269
+ backgroundColor: 'background.block',
270
+ borderColor: isCurrent ? 'primary.main' : 'textColor',
271
+ color: isCurrent ? 'primary.main' : 'textColor',
272
+ borderRadius: 1,
273
+ } }) }, taskId)] }, taskId) }, taskId));
274
+ }) })] }, "slider"), _jsx(Box, { sx: {
275
+ borderRadius: 1,
276
+ backgroundColor: 'background.block',
277
+ flex: 1,
278
+ maxWidth: `calc(100% - ${sliderWidth}px - 16px)`,
279
+ }, children: _jsx(AgentOutputRender, { message: currentMessage }) })] }));
280
+ }
128
281
  function AgentInputRender(_a) {
129
282
  var props = __rest(_a, []);
130
283
  const { appearanceInput } = useAppearances();
131
284
  if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
132
285
  return null;
133
- return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }, props)) }));
286
+ return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties, props: props }) }));
134
287
  }
135
288
  function AgentOutputRender(_a) {
136
289
  var { message } = _a, props = __rest(_a, ["message"]);
137
290
  const { appearanceOutput } = useAppearances();
138
291
  if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId) || !message)
139
292
  return null;
140
- return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }, props)) }) }) }));
293
+ return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, props: props }) }) }) }));
141
294
  }
@@ -0,0 +1,92 @@
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 } from "react/jsx-runtime";
13
+ import { Box } from '@mui/material';
14
+ import { memo, useCallback } from 'react';
15
+ import CustomComponentRenderer from '../../../../../../components/CustomComponentRenderer';
16
+ import { useLocaleContext } from '../../../../../locale';
17
+ import MessageErrorView from '../../ChatOutput/MessageErrorView';
18
+ import { AIRunningLoading } from './Loading';
19
+ const codeField = 'code';
20
+ export default function CodePreview(_a) {
21
+ var { componentId = 'mock-dev-component', code, propertiesValue } = _a, restProps = __rest(_a, ["componentId", "code", "propertiesValue"]);
22
+ const { locale } = useLocaleContext();
23
+ if (!code)
24
+ return null;
25
+ return (_jsx(Box, Object.assign({ id: componentId, className: "code-preview-wrapper" }, restProps, { children: _jsx(CustomComponentRenderer, { componentId: componentId, locale: locale, props: propertiesValue || {}, dev: {
26
+ components: {
27
+ [componentId]: {
28
+ data: {
29
+ id: componentId,
30
+ createdAt: '',
31
+ updatedAt: '',
32
+ renderer: {
33
+ type: 'react-component',
34
+ script: code,
35
+ },
36
+ },
37
+ },
38
+ },
39
+ } }) }), componentId));
40
+ }
41
+ export const CodePreviewMemo = memo(CodePreview);
42
+ export function CodeRenderByMessage({ zoom, message, minHeight = 200, sx, propertiesValueMap, }) {
43
+ var _a;
44
+ const { locale } = useLocaleContext();
45
+ const zoomSx = {
46
+ '& > *': {
47
+ zoom,
48
+ minHeight,
49
+ },
50
+ };
51
+ const isMessageLoading = ((message === null || message === void 0 ? void 0 : message.loading) || !(message === null || message === void 0 ? void 0 : message.result)) && !(message === null || message === void 0 ? void 0 : message.error);
52
+ const ContentRender = useCallback(() => {
53
+ var _a, _b, _c, _d;
54
+ if (isMessageLoading) {
55
+ return (_jsx(Box, { className: "code-message-loading", sx: {
56
+ py: 8,
57
+ display: 'flex',
58
+ justifyContent: 'center',
59
+ alignItems: 'center',
60
+ }, children: _jsx(AIRunningLoading, {}) }));
61
+ }
62
+ if (message === null || message === void 0 ? void 0 : message.error) {
63
+ return (_jsx(Box, { sx: {
64
+ width: '100%',
65
+ }, children: _jsx(MessageErrorView, { error: message.error, sx: {
66
+ mr: 0,
67
+ } }) }));
68
+ }
69
+ if (!((_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.length)) {
70
+ return (_jsx(Box, { children: _jsx(MessageErrorView, { error: new Error('Something error'), sx: {
71
+ mr: 0,
72
+ } }) }));
73
+ }
74
+ return (_d = (_c = message === null || message === void 0 ? void 0 : message.result) === null || _c === void 0 ? void 0 : _c.objects) === null || _d === void 0 ? void 0 : _d.map((item) => {
75
+ var _a, _b;
76
+ const { taskId } = item;
77
+ // @ts-ignore
78
+ const code = (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a[codeField];
79
+ return (_jsx(CodePreviewMemo, { componentId: `code-preview-${taskId}`, code: code, propertiesValue: (_b = propertiesValueMap === null || propertiesValueMap === void 0 ? void 0 : propertiesValueMap[taskId]) === null || _b === void 0 ? void 0 : _b[locale] }, item.taskId));
80
+ });
81
+ // eslint-disable-next-line react-hooks/exhaustive-deps
82
+ }, [isMessageLoading, (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects, propertiesValueMap, locale]);
83
+ return (_jsx(Box, { sx: Object.assign(Object.assign(Object.assign({ transition: 'all 0.3s', overflow: 'hidden', borderRadius: 1, width: '100%', height: '100%', backgroundColor: 'white' }, zoomSx), sx), { '.code-preview-wrapper': {
84
+ // p: 2,
85
+ } }), children: _jsx(ContentRender, {}) }, message === null || message === void 0 ? void 0 : message.taskId));
86
+ }
87
+ export const CodeRenderByMessageMemo = memo(CodeRenderByMessage);
88
+ export function getCurrentCodeByTaskId(message, taskId) {
89
+ var _a, _b, _c, _d;
90
+ // @ts-ignore
91
+ return (_d = (_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.find((item) => item.taskId === taskId)) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d[codeField];
92
+ }
@@ -0,0 +1,55 @@
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { Icon } from '@iconify/react';
12
+ import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Typography } from '@mui/material';
13
+ import { forwardRef, useImperativeHandle, useState } from 'react';
14
+ import { useLocaleContext } from '../../../../../locale';
15
+ import LoadingButton from '../../../components/LoadingButton';
16
+ const ConfirmDialog = forwardRef((props, ref) => {
17
+ const [openDialog, setOpenDialog] = useState(false);
18
+ const [openParams, setOpenParams] = useState({});
19
+ const { t } = useLocaleContext();
20
+ const open = (params) => {
21
+ setOpenParams(params);
22
+ setOpenDialog(true);
23
+ };
24
+ const close = () => {
25
+ setOpenDialog(false);
26
+ };
27
+ useImperativeHandle(ref, () => ({
28
+ open,
29
+ close,
30
+ }));
31
+ const { title, children, onConfirm, onCancel, onConfirmProps, onCancelProps } = openParams;
32
+ return (_jsxs(Dialog, Object.assign({ disableScrollLock: true, onClose: close, fullWidth: true, maxWidth: "sm" }, props, { open: openDialog, children: [_jsxs(DialogTitle, { sx: {
33
+ display: 'flex',
34
+ alignItems: 'center',
35
+ justifyContent: 'space-between',
36
+ }, children: [_jsx(Typography, { component: "h5", sx: { fontSize: 24, fontWeight: 700 }, children: title }), _jsx(Button, { onClick: close,
37
+ // variant="text"
38
+ color: "inherit", disableElevation: true, sx: {
39
+ minWidth: 32,
40
+ minHeight: 32,
41
+ p: 0,
42
+ fontSize: 22,
43
+ }, children: _jsx(Icon, { icon: "tabler:x" }) })] }), _jsx(DialogContent, { children: children }), _jsxs(DialogActions, { sx: {
44
+ px: 3,
45
+ pt: 0,
46
+ pb: 2,
47
+ }, children: [_jsx(Button, Object.assign({ variant: "contained", color: "inherit" }, onCancelProps, { onClick: () => {
48
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
49
+ setOpenDialog(false);
50
+ }, children: (onCancelProps === null || onCancelProps === void 0 ? void 0 : onCancelProps.children) || t('cancel') })), _jsx(LoadingButton, Object.assign({ variant: "contained" }, onConfirmProps, { onClick: () => __awaiter(void 0, void 0, void 0, function* () {
51
+ yield (onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm());
52
+ setOpenDialog(false);
53
+ }), children: (onConfirmProps === null || onConfirmProps === void 0 ? void 0 : onConfirmProps.children) || t('submit') }))] })] })));
54
+ });
55
+ export default ConfirmDialog;