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