@blocklet/pages-kit 0.2.320 → 0.2.321
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/components/ThemeProvider.js +11 -4
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +4 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +29 -17
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +36 -17
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +84 -77
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +7 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +4 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +4 -1
- package/lib/cjs/builtin/iconify/react.js +8 -2
- package/lib/cjs/components/CustomComponentRenderer/state.js +14 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/inject-global-components-dump-json.js +8 -3
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +11 -4
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +29 -17
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +36 -17
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +84 -78
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +7 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +4 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +4 -1
- package/lib/esm/builtin/iconify/react.js +7 -1
- package/lib/esm/components/CustomComponentRenderer/state.js +11 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/inject-global-components-dump-json.js +8 -3
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +1 -5
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.d.ts +1 -0
- package/lib/types/builtin/iconify/react.d.ts +2 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -414,7 +414,7 @@ export default function FormDemo() {
|
|
|
414
414
|
// '@blocklet/pages-kit/builtin/iconify/react'
|
|
415
415
|
{
|
|
416
416
|
name: '@blocklet/pages-kit/builtin/iconify/react',
|
|
417
|
-
description: 'A iconify/react component for pages-kit builtin package, all icons
|
|
417
|
+
description: 'A iconify/react component for pages-kit builtin package, all used icons are imported from this package (based on iconify)',
|
|
418
418
|
docs: {
|
|
419
419
|
components: ['Icon'],
|
|
420
420
|
import: 'import { Icon } from "@blocklet/pages-kit/builtin/iconify/react"',
|
|
@@ -425,8 +425,13 @@ export default function FormDemo() {
|
|
|
425
425
|
code: `
|
|
426
426
|
import { Icon } from '@blocklet/pages-kit/builtin/iconify/react';
|
|
427
427
|
|
|
428
|
+
|
|
428
429
|
export default function TablerSuccessIcon() {
|
|
429
|
-
return <Icon icon="tabler:check"
|
|
430
|
+
return <Icon icon="tabler:check" sx={{
|
|
431
|
+
mr: 1,
|
|
432
|
+
fontSize: 24,
|
|
433
|
+
color: 'success.main'
|
|
434
|
+
}}/>
|
|
430
435
|
}
|
|
431
436
|
`,
|
|
432
437
|
},
|
|
@@ -1112,7 +1117,7 @@ export default function LocalCustomComponentRendererDemo({ code }) {
|
|
|
1112
1117
|
];
|
|
1113
1118
|
// set dumpJSON to AI Studio knowledge
|
|
1114
1119
|
const shouldUpdateKnowledge = true;
|
|
1115
|
-
const cookie = 'CookieConsent=true; _ga=GA1.2.1343579140.1705048750; _ga_B1V5Y6VTCW=GS1.2.1705048750.1.1.1705049433.0.0.0; __stripe_mid=b799e3a9-894f-4069-aa7b-731906316d4b34cd93; nf_lang=
|
|
1120
|
+
const cookie = 'CookieConsent=true; _ga=GA1.2.1343579140.1705048750; _ga_B1V5Y6VTCW=GS1.2.1705048750.1.1.1705049433.0.0.0; __stripe_mid=b799e3a9-894f-4069-aa7b-731906316d4b34cd93; nf_lang=en; login_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoidXNlciIsImRpZCI6InoxVENDb21nQ0pOSGJIV2V0VFdHZGhQQjZOWVoyUmVEakx1Iiwicm9sZSI6Im93bmVyIiwicHJvdmlkZXIiOiJ3YWxsZXQiLCJ3YWxsZXRPUyI6IndlYiIsInBhc3Nwb3J0Ijp7ImlkIjoiejJpVHkyWkRUdENIamJLNEh6ZXQ5U25aR2pjRnRYODFHTjk4ViJ9LCJmdWxsTmFtZSI6Illvbmd6aHVvIExpYW5nIiwiaWF0IjoxNzE2NjkyMTQyLCJleHAiOjE3MTY2OTU3NDJ9.DuUCAOo7j-5w7eMQgd4FWWpPwD9OTebSAHavbSkuRx4';
|
|
1116
1121
|
const aiStudioUrl = 'https://bbqa2t5pfyfroyobmzknmktshckzto4btkfagxyjqwy.did.abtnet.io/ai-studio';
|
|
1117
1122
|
const datasetId = '443696818363039744';
|
|
1118
1123
|
if (cookie && shouldUpdateKnowledge && aiStudioUrl && datasetId) {
|
|
@@ -52,15 +52,22 @@ export default function ThemeProvider({ children, template, transparentHeaderBg,
|
|
|
52
52
|
style: ({ theme }) => theme.unstable_sx({
|
|
53
53
|
'.MuiInputBase-root': {
|
|
54
54
|
fieldset: { borderColor: 'rgba(229, 231, 235, 1)' },
|
|
55
|
-
[
|
|
55
|
+
[`&.Mui-focused, :not(.${inputBaseClasses.disabled}):hover`]: {
|
|
56
56
|
fieldset: {
|
|
57
57
|
border: 'none',
|
|
58
58
|
boxShadow: `0px 0px 0px 4px ${alpha(theme.palette.primary.main, 0.2)}, 0px 0px 0px 1px ${theme.palette.primary.main}`,
|
|
59
59
|
},
|
|
60
60
|
},
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
},
|
|
62
|
+
'.MuiInputLabel-root': {
|
|
63
|
+
[`&.Mui-focused, :not(.${inputBaseClasses.disabled}):hover, &.MuiFormLabel-filled`]: {
|
|
64
|
+
backgroundColor: `${theme.palette.primary.main}`,
|
|
65
|
+
color: 'white',
|
|
66
|
+
px: 1,
|
|
67
|
+
ml: -0.8,
|
|
68
|
+
py: 0.2,
|
|
69
|
+
mt: -0.1,
|
|
70
|
+
borderRadius: 4,
|
|
64
71
|
},
|
|
65
72
|
},
|
|
66
73
|
}),
|
|
@@ -104,6 +104,8 @@ export const translations = {
|
|
|
104
104
|
cannotSetPropertiesTip: 'Failed to parse PROPERTIES_SCHEMA, this code cannot be set properties',
|
|
105
105
|
codePreview: 'Code Preview',
|
|
106
106
|
codePreviewTip: 'Here is the code preview, you can view the generated code, and editing is not supported yet.',
|
|
107
|
+
hideSlider: 'Hide Versions',
|
|
108
|
+
showSlider: 'Show Versions',
|
|
107
109
|
},
|
|
108
110
|
},
|
|
109
111
|
zh: {
|
|
@@ -211,6 +213,8 @@ export const translations = {
|
|
|
211
213
|
cannotSetPropertiesTip: '解析 PROPERTIES_SCHEMA 失败,此代码无法进行属性设置',
|
|
212
214
|
codePreview: '代码预览',
|
|
213
215
|
codePreviewTip: '以下是代码预览,您可以查看生成的代码,目前还不支持编辑。',
|
|
216
|
+
hideSlider: '隐藏版本历史',
|
|
217
|
+
showSlider: '显示版本历史',
|
|
214
218
|
},
|
|
215
219
|
},
|
|
216
220
|
};
|
|
@@ -28,6 +28,7 @@ export default function V0Input({ submitText, inlineLabel, autoFillLastForm = fa
|
|
|
28
28
|
var _a, _b;
|
|
29
29
|
const { t } = useLocaleContext();
|
|
30
30
|
const { aid, agent } = useCurrentAgent();
|
|
31
|
+
const [executeLoading, setExecuteLoading] = useState(false);
|
|
31
32
|
const opening = useOpeningQuestions();
|
|
32
33
|
const { execute } = useRuntimeState();
|
|
33
34
|
const { running } = useCurrentSessionState((s) => s) || {};
|
|
@@ -49,28 +50,38 @@ export default function V0Input({ submitText, inlineLabel, autoFillLastForm = fa
|
|
|
49
50
|
}
|
|
50
51
|
}, [defaultForm, autoFillLastForm, form, chatMode]);
|
|
51
52
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
try {
|
|
54
|
+
if (!(parameters === null || parameters === void 0 ? void 0 : parameters.question))
|
|
55
|
+
return;
|
|
56
|
+
setExecuteLoading(true);
|
|
57
|
+
if (!currentSessionId) {
|
|
58
|
+
yield createSession({
|
|
59
|
+
name: parameters === null || parameters === void 0 ? void 0 : parameters.question,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// in session page, send message
|
|
63
|
+
yield execute({
|
|
64
|
+
aid,
|
|
65
|
+
parameters,
|
|
66
|
+
onResponseStart: () => {
|
|
67
|
+
setCurrentMessageTaskId(undefined);
|
|
68
|
+
if (chatMode)
|
|
69
|
+
form.resetField('question', { defaultValue: '' });
|
|
70
|
+
},
|
|
57
71
|
});
|
|
58
72
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (chatMode)
|
|
66
|
-
form.resetField('question', { defaultValue: '' });
|
|
67
|
-
},
|
|
68
|
-
});
|
|
73
|
+
catch (error) {
|
|
74
|
+
console.error(error);
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
setExecuteLoading(false);
|
|
78
|
+
}
|
|
69
79
|
});
|
|
70
80
|
return (_jsxs(ThemeProvider, { theme: theme, children: [!currentSessionId && ((_a = opening === null || opening === void 0 ? void 0 : opening.questions) === null || _a === void 0 ? void 0 : _a.length) && (_jsx(Stack, { sx: {
|
|
71
81
|
flexDirection: 'row',
|
|
72
82
|
gap: 1,
|
|
73
83
|
mb: 1,
|
|
84
|
+
flexWrap: 'wrap',
|
|
74
85
|
}, children: (_b = opening === null || opening === void 0 ? void 0 : opening.questions) === null || _b === void 0 ? void 0 : _b.map((item) => {
|
|
75
86
|
const { title, parameters, id } = item;
|
|
76
87
|
const question = (parameters === null || parameters === void 0 ? void 0 : parameters.questions) || title;
|
|
@@ -78,7 +89,8 @@ export default function V0Input({ submitText, inlineLabel, autoFillLastForm = fa
|
|
|
78
89
|
marginLeft: -4,
|
|
79
90
|
} }), onClick: () => {
|
|
80
91
|
form.reset(Object.assign({}, parameters));
|
|
81
|
-
|
|
92
|
+
// auto execute message
|
|
93
|
+
// onSubmit({ ...parameters });
|
|
82
94
|
}, children: question }, id));
|
|
83
95
|
}) })), _jsxs(Form, { id: "v0-input", component: "form", className: cx('form', `label-position-${inlineLabel ? 'start' : 'top'}`), onSubmit: form.handleSubmit(onSubmit), children: [parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter, index) => {
|
|
84
96
|
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
@@ -104,7 +116,7 @@ export default function V0Input({ submitText, inlineLabel, autoFillLastForm = fa
|
|
|
104
116
|
}
|
|
105
117
|
: undefined })] }));
|
|
106
118
|
} }) }, parameter.id));
|
|
107
|
-
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] })] }));
|
|
119
|
+
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading: executeLoading || running, sx: { height: 40 }, children: submitText || t('generate') }))] })] }));
|
|
108
120
|
}
|
|
109
121
|
const autoSetLastParameters = false;
|
|
110
122
|
function useInitialFormValues() {
|
|
@@ -32,7 +32,7 @@ export default function V0Output() {
|
|
|
32
32
|
var _a, _b;
|
|
33
33
|
const { message } = useCurrentMessage();
|
|
34
34
|
const propertiesSettingRef = useRef(null);
|
|
35
|
-
const { propertiesValueMap, setPropertiesValueMap } = useV0RuntimeContext();
|
|
35
|
+
const { propertiesValueMap, setPropertiesValueMap, isMobile } = useV0RuntimeContext();
|
|
36
36
|
const [code, setCode] = useState('');
|
|
37
37
|
const { t, locale } = useLocaleContext();
|
|
38
38
|
const [codePreviewExtraSx, setCodePreviewExtraSx] = useState(DEFAULT_DESKTOP_SX);
|
|
@@ -45,7 +45,7 @@ export default function V0Output() {
|
|
|
45
45
|
borderColor: 'rgba(0, 0, 0, 0.1) !important',
|
|
46
46
|
};
|
|
47
47
|
const tooltipOptions = [
|
|
48
|
-
{
|
|
48
|
+
!isMobile && {
|
|
49
49
|
key: 'Desktop',
|
|
50
50
|
icon: 'tabler:device-desktop',
|
|
51
51
|
props: {
|
|
@@ -54,7 +54,7 @@ export default function V0Output() {
|
|
|
54
54
|
},
|
|
55
55
|
group: 'responsive',
|
|
56
56
|
},
|
|
57
|
-
{
|
|
57
|
+
!isMobile && {
|
|
58
58
|
key: 'Tablet',
|
|
59
59
|
icon: 'tabler:device-tablet',
|
|
60
60
|
props: {
|
|
@@ -66,7 +66,7 @@ export default function V0Output() {
|
|
|
66
66
|
},
|
|
67
67
|
group: 'responsive',
|
|
68
68
|
},
|
|
69
|
-
{
|
|
69
|
+
!isMobile && {
|
|
70
70
|
key: 'Mobile',
|
|
71
71
|
icon: 'tabler:device-mobile',
|
|
72
72
|
props: {
|
|
@@ -91,14 +91,14 @@ export default function V0Output() {
|
|
|
91
91
|
const currentCode = getCurrentCodeByTaskId(message, taskId);
|
|
92
92
|
try {
|
|
93
93
|
yield transpileAndLoadScript(currentCode).then((m) => {
|
|
94
|
-
var _a, _b;
|
|
94
|
+
var _a, _b, _c;
|
|
95
95
|
if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
|
|
96
96
|
const schemaDefaultValues = Object.fromEntries(m.PROPERTIES_SCHEMA.map((item) => {
|
|
97
97
|
const { key, locales } = item;
|
|
98
98
|
const currentLocale = (locales === null || locales === void 0 ? void 0 : locales[locale]) || (locales === null || locales === void 0 ? void 0 : locales.en);
|
|
99
99
|
return [key, currentLocale === null || currentLocale === void 0 ? void 0 : currentLocale.defaultValue];
|
|
100
100
|
}));
|
|
101
|
-
const defaultValues = Object.assign(Object.assign({}, schemaDefaultValues), (_a = propertiesValueMap[taskId]) === null || _a === void 0 ? void 0 : _a[locale]);
|
|
101
|
+
const defaultValues = Object.assign(Object.assign({}, schemaDefaultValues), (((_a = propertiesValueMap[taskId]) === null || _a === void 0 ? void 0 : _a[locale]) || ((_b = propertiesValueMap[taskId]) === null || _b === void 0 ? void 0 : _b.en) || {}));
|
|
102
102
|
// format default values
|
|
103
103
|
m.PROPERTIES_SCHEMA.forEach((item) => {
|
|
104
104
|
const { key, type } = item;
|
|
@@ -112,7 +112,7 @@ export default function V0Output() {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
// @ts-ignore
|
|
115
|
-
(
|
|
115
|
+
(_c = propertiesSettingRef.current) === null || _c === void 0 ? void 0 : _c.open({
|
|
116
116
|
schema: m.PROPERTIES_SCHEMA,
|
|
117
117
|
onSubmit: (values) => {
|
|
118
118
|
const realValues = {};
|
|
@@ -150,7 +150,7 @@ export default function V0Output() {
|
|
|
150
150
|
{
|
|
151
151
|
key: 'CodePreview',
|
|
152
152
|
icon: code ? 'tabler:layout-board' : 'tabler:code',
|
|
153
|
-
buttonText: code ? 'Canvas' : 'Code',
|
|
153
|
+
buttonText: !isMobile && (code ? 'Canvas' : 'Code'),
|
|
154
154
|
props: {
|
|
155
155
|
disabled,
|
|
156
156
|
variant: 'contained',
|
|
@@ -163,7 +163,8 @@ export default function V0Output() {
|
|
|
163
163
|
},
|
|
164
164
|
group: 'codePreview',
|
|
165
165
|
},
|
|
166
|
-
];
|
|
166
|
+
].filter(Boolean);
|
|
167
|
+
const onCloseCode = () => setCode('');
|
|
167
168
|
return (_jsxs(Stack, { sx: {
|
|
168
169
|
p: 2,
|
|
169
170
|
gap: 2,
|
|
@@ -179,10 +180,15 @@ export default function V0Output() {
|
|
|
179
180
|
width: '100%',
|
|
180
181
|
gap: 1.5,
|
|
181
182
|
flexDirection: 'row',
|
|
183
|
+
'.question': {
|
|
184
|
+
backgroundColor: 'white',
|
|
185
|
+
border: 1,
|
|
186
|
+
borderColor: 'rgba(0, 0, 0, 0.1) !important',
|
|
187
|
+
},
|
|
182
188
|
}, children: [_jsx(UserQuestion, { question: parameters === null || parameters === void 0 ? void 0 : parameters.question }), _jsx(Box, { sx: {
|
|
183
189
|
display: 'flex',
|
|
184
190
|
alignItems: 'center',
|
|
185
|
-
gap: 1
|
|
191
|
+
gap: 1,
|
|
186
192
|
}, children: Object.entries(groupBy(tooltipOptions, 'group')).map(([group, options]) => {
|
|
187
193
|
return (_jsx(ButtonGroup, { variant: "text", color: "inherit", size: "small", sx: {
|
|
188
194
|
borderColor: 'rgba(0, 0, 0, 0.1) !important',
|
|
@@ -196,11 +202,24 @@ export default function V0Output() {
|
|
|
196
202
|
overflowY: 'auto',
|
|
197
203
|
scrollbarWidth: 'thin',
|
|
198
204
|
scrollbarColor: 'grey transparent',
|
|
199
|
-
}, propertiesValueMap: propertiesValueMap }) }), objects === null || objects === void 0 ? void 0 : objects.map((item, index) => _jsx(MessageMetadataRenderer, { object: item.data }, index)), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && (_jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })), _jsxs(Suspense, { fallback: _jsx(Loading, {}), children: [_jsx(Drawer, { anchor:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
}, propertiesValueMap: propertiesValueMap }) }), objects === null || objects === void 0 ? void 0 : objects.map((item, index) => _jsx(MessageMetadataRenderer, { object: item.data }, index)), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && (_jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })), _jsxs(Suspense, { fallback: _jsx(Loading, {}), children: [_jsx(Drawer, { anchor: isMobile ? 'bottom' : 'right', open: !!code, onClose: onCloseCode, children: _jsxs(Box, { sx: Object.assign({ p: 2, pt: 0 }, (isMobile ? { maxHeight: '70vh' } : { maxWidth: '70vw' })), children: [_jsxs(Box, { sx: {
|
|
206
|
+
py: 2,
|
|
207
|
+
position: 'sticky',
|
|
208
|
+
top: 0,
|
|
209
|
+
left: 0,
|
|
210
|
+
backgroundColor: 'white',
|
|
211
|
+
zIndex: 9999,
|
|
212
|
+
display: 'flex',
|
|
213
|
+
justifyContent: 'space-between',
|
|
214
|
+
alignItems: 'center',
|
|
215
|
+
}, children: [_jsx(Typography, { variant: "h6", sx: {
|
|
216
|
+
lineHeight: 1,
|
|
217
|
+
}, children: t('v0.codePreview') }), _jsx(Button, { onClick: onCloseCode,
|
|
218
|
+
// variant="text"
|
|
219
|
+
color: "inherit", disableElevation: true, sx: {
|
|
220
|
+
minWidth: 32,
|
|
221
|
+
minHeight: 32,
|
|
222
|
+
p: 0,
|
|
223
|
+
fontSize: 22,
|
|
224
|
+
}, children: _jsx(Icon, { icon: "tabler:x" }) })] }), _jsx(Alert, { severity: "info", sx: { mb: 2 }, children: t('v0.codePreviewTip') }), _jsx(MarkdownRenderer, { children: `\`\`\`typescript\n${code}\n\`\`\`` })] }) }), _jsx(PropertiesSetting, { ref: propertiesSettingRef })] })] }));
|
|
206
225
|
}
|
|
@@ -25,7 +25,7 @@ import RelativeTime from '@arcblock/ux/lib/RelativeTime';
|
|
|
25
25
|
import { Icon } from '@iconify/react';
|
|
26
26
|
import { Masonry } from '@mui/lab';
|
|
27
27
|
import { Box, Button, Chip, Container, IconButton, Stack, ThemeProvider, Tooltip, Typography, createTheme, useTheme, } from '@mui/material';
|
|
28
|
-
import { Suspense, useEffect, useMemo, useRef } from 'react';
|
|
28
|
+
import { Suspense, useEffect, useMemo, useRef, useState } from 'react';
|
|
29
29
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
30
30
|
import { useLocaleContext } from '../../../../locale';
|
|
31
31
|
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
@@ -40,7 +40,7 @@ import UserQuestion from './components/UserQuestion';
|
|
|
40
40
|
import { V0RuntimeProvider, useV0RuntimeContext } from './contexts/V0Runtime';
|
|
41
41
|
import { getLineClamp } from './utils';
|
|
42
42
|
const sliderWidth = 200;
|
|
43
|
-
function V0Page({ textColor = '#333', primaryColor }) {
|
|
43
|
+
function V0Page({ textColor = '#333', primaryColor = '#333' }) {
|
|
44
44
|
const inheritedTheme = useTheme();
|
|
45
45
|
const theme = useMemo(() => {
|
|
46
46
|
let { primary } = inheritedTheme.palette;
|
|
@@ -53,7 +53,7 @@ function V0Page({ textColor = '#333', primaryColor }) {
|
|
|
53
53
|
console.error('augment primary color error', { error });
|
|
54
54
|
}
|
|
55
55
|
return createTheme(inheritedTheme, {
|
|
56
|
-
palette: { primary, textColor, background: { block: '#
|
|
56
|
+
palette: { primary, textColor, background: { block: '#f6f6f6' } },
|
|
57
57
|
shape: {
|
|
58
58
|
borderRadius: 8,
|
|
59
59
|
},
|
|
@@ -64,30 +64,35 @@ function V0Page({ textColor = '#333', primaryColor }) {
|
|
|
64
64
|
});
|
|
65
65
|
const { currentSessionId } = useSessionState((s) => s) || {};
|
|
66
66
|
const { activeAgentId } = useActiveAgent();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
const { isMobile } = useV0RuntimeContext();
|
|
68
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(Box, { flex: 1, children: _jsxs(Container, { sx: {
|
|
69
|
+
height: 'calc(100vh - 64px - 1px)',
|
|
70
|
+
textAlign: 'center',
|
|
71
|
+
pt: 3,
|
|
72
|
+
gap: 2,
|
|
73
|
+
display: 'flex',
|
|
74
|
+
flexDirection: 'column',
|
|
75
|
+
position: 'relative',
|
|
76
|
+
'.code-preview-wrapper': {},
|
|
77
|
+
}, children: [_jsx(Box, { sx: {
|
|
78
|
+
flex: 1,
|
|
79
|
+
height: !isMobile && currentSessionId ? 'calc(100% - 48px - 16px - 16px)' : 'unset',
|
|
80
|
+
}, children: currentSessionId ? _jsx(V0DetailRender, {}) : _jsx(V0ListRender, {}) }), _jsx(Box, { sx: {
|
|
81
|
+
position: 'sticky',
|
|
82
|
+
bottom: 0,
|
|
83
|
+
backgroundColor: 'white',
|
|
84
|
+
py: 2,
|
|
85
|
+
pt: currentSessionId ? 0 : 2,
|
|
86
|
+
zIndex: 1100,
|
|
87
|
+
}, children: _jsx(AgentInputRender, {}) })] }) }) }) }));
|
|
88
|
+
}
|
|
89
|
+
export default function Page() {
|
|
90
|
+
return (_jsx(V0RuntimeProvider, { children: _jsx(V0Page, {}) }));
|
|
86
91
|
}
|
|
87
|
-
export default V0Page;
|
|
88
92
|
function V0ListRender() {
|
|
89
93
|
const ConfirmDialogRef = useRef();
|
|
90
94
|
const { sessions: sessionsList, setCurrentSessionId, loadLatestMessagesForAllSessions, sessionMap, deleteSession, loading, } = useSessionState((s) => s) || {};
|
|
95
|
+
const { isMobile } = useV0RuntimeContext();
|
|
91
96
|
const { t } = useLocaleContext();
|
|
92
97
|
useEffect(() => {
|
|
93
98
|
const loadData = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -97,13 +102,16 @@ function V0ListRender() {
|
|
|
97
102
|
});
|
|
98
103
|
loadData();
|
|
99
104
|
}, [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: {
|
|
105
|
+
return (_jsxs(Box, { flex: 1, children: [_jsx(Typography, { variant: "h2", color: "textColor", sx: { fontWeight: 'bold', mt: isMobile ? 3 : 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
106
|
position: 'relative',
|
|
102
107
|
height: '40vh',
|
|
103
108
|
width: '100%',
|
|
104
109
|
} })) : (_jsxs(Box, { sx: {
|
|
105
|
-
mt: 8,
|
|
106
|
-
|
|
110
|
+
mt: isMobile ? 4 : 8,
|
|
111
|
+
display: 'flex',
|
|
112
|
+
alignContent: 'center',
|
|
113
|
+
justifyContent: 'center',
|
|
114
|
+
}, children: [(sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.length) ? (_jsx(Masonry, { columns: { xs: 1, sm: 2, md: 4, lg: 4 }, sequential: true, spacing: 2, children: sessionsList === null || sessionsList === void 0 ? void 0 : sessionsList.map((item) => {
|
|
107
115
|
var _a, _b;
|
|
108
116
|
const { name, id } = item;
|
|
109
117
|
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);
|
|
@@ -123,8 +131,9 @@ function V0ListRender() {
|
|
|
123
131
|
cursor: 'pointer',
|
|
124
132
|
transition: 'all 0.3s',
|
|
125
133
|
overflow: 'hidden',
|
|
126
|
-
minHeight: sliderWidth,
|
|
127
|
-
maxHeight: '50vh',
|
|
134
|
+
// minHeight: sliderWidth,
|
|
135
|
+
// maxHeight: '50vh',
|
|
136
|
+
height: 300,
|
|
128
137
|
'&:hover': {
|
|
129
138
|
borderColor: 'primary.main',
|
|
130
139
|
},
|
|
@@ -163,7 +172,8 @@ function V0ListRender() {
|
|
|
163
172
|
function V0DetailRender() {
|
|
164
173
|
const { setCurrentSessionId } = useSessionState((s) => s) || {};
|
|
165
174
|
const { messages: messagesList, loading } = useCurrentSessionState((s) => s) || {};
|
|
166
|
-
const { currentMessageTaskId, setCurrentMessageTaskId, propertiesValueMap } = useV0RuntimeContext();
|
|
175
|
+
const { currentMessageTaskId, setCurrentMessageTaskId, propertiesValueMap, isMobile } = useV0RuntimeContext();
|
|
176
|
+
const [sliderOpenInMobile, setSliderOpenInMobile] = useState(!isMobile);
|
|
167
177
|
const { t } = useLocaleContext();
|
|
168
178
|
const currentMessage = messagesList === null || messagesList === void 0 ? void 0 : messagesList.find((item) => item.taskId === currentMessageTaskId);
|
|
169
179
|
useEffect(() => {
|
|
@@ -176,48 +186,48 @@ function V0DetailRender() {
|
|
|
176
186
|
}
|
|
177
187
|
}
|
|
178
188
|
}, [messagesList, currentMessageTaskId]);
|
|
189
|
+
const sliderOpen = isMobile ? sliderOpenInMobile : true;
|
|
190
|
+
const sliderWrapperSx = {
|
|
191
|
+
height: isMobile ? 'unset' : '100%',
|
|
192
|
+
backgroundColor: 'background.block',
|
|
193
|
+
borderRadius: 1,
|
|
194
|
+
p: 2,
|
|
195
|
+
position: 'relative',
|
|
196
|
+
};
|
|
179
197
|
return (_jsxs(Box, { flex: 1, sx: {
|
|
180
198
|
display: 'flex',
|
|
181
199
|
gap: 2,
|
|
182
200
|
height: '100%',
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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: {
|
|
201
|
+
flexDirection: isMobile ? 'column' : 'row',
|
|
202
|
+
}, children: [_jsxs(Box, { sx: Object.assign({ width: isMobile ? '100%' : sliderWidth, gap: 2, display: 'flex', flexDirection: 'column' }, (isMobile ? {} : Object.assign({}, sliderWrapperSx))), children: [_jsxs(Box, { sx: {
|
|
203
|
+
display: 'flex',
|
|
204
|
+
justifyContent: 'space-between',
|
|
205
|
+
alignItems: 'center',
|
|
206
|
+
gap: 2,
|
|
207
|
+
}, children: [_jsx(Button, { variant: "outlined", size: "small", startIcon: _jsx(Icon, { icon: "tabler:chevron-left" }), onClick: () => {
|
|
208
|
+
setCurrentMessageTaskId(undefined);
|
|
209
|
+
setCurrentSessionId('');
|
|
210
|
+
}, sx: {
|
|
211
|
+
backgroundColor: 'white',
|
|
212
|
+
width: isMobile ? 'auto' : '100%',
|
|
213
|
+
}, children: t('back') }), isMobile ? (_jsx(Button, { startIcon: _jsx(Icon, { icon: sliderOpenInMobile ? 'tabler:chevron-up' : 'tabler:chevron-down' }), size: "small", onClick: () => setSliderOpenInMobile(!sliderOpenInMobile), children: sliderOpenInMobile ? t('v0.hideSlider') : t('v0.showSlider') })) : null, loading && (_jsx(Loading, { sx: Object.assign({ position: 'absolute', zIndex: 99999, top: 0, left: 0, right: 0, bottom: 0, margin: 'auto', background: 'rgba(255, 255, 255, 0.8)', opacity: 0.8, borderRadius: 1, boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)' }, (isMobile
|
|
214
|
+
? {
|
|
215
|
+
width: '40px',
|
|
216
|
+
height: '40px',
|
|
217
|
+
}
|
|
218
|
+
: {
|
|
219
|
+
width: '80px',
|
|
220
|
+
height: '80px',
|
|
221
|
+
})) }))] }), sliderOpen && (_jsx(Stack, { spacing: 2, direction: isMobile ? 'row' : 'column', sx: Object.assign(Object.assign({}, (isMobile
|
|
222
|
+
? Object.assign({ overflowY: 'hidden', overflowX: 'auto' }, sliderWrapperSx) : {
|
|
213
223
|
overflowY: 'auto',
|
|
214
224
|
overflowX: 'hidden',
|
|
225
|
+
})), {
|
|
215
226
|
// scrollbarWidth: 'thin',
|
|
216
227
|
// scrollbarColor: 'grey transparent',
|
|
217
228
|
'&::-webkit-scrollbar': {
|
|
218
229
|
display: 'none',
|
|
219
|
-
},
|
|
220
|
-
}, children: messagesList === null || messagesList === void 0 ? void 0 : messagesList.map((item, i) => {
|
|
230
|
+
} }), children: messagesList === null || messagesList === void 0 ? void 0 : messagesList.map((item, i) => {
|
|
221
231
|
const { parameters, taskId, updatedAt } = item;
|
|
222
232
|
const isCurrent = taskId === (currentMessageTaskId || undefined);
|
|
223
233
|
return (_jsx(Box, { sx: {
|
|
@@ -228,21 +238,17 @@ function V0DetailRender() {
|
|
|
228
238
|
}, children: _jsxs(Box, { onClick: () => {
|
|
229
239
|
// @ts-ignore
|
|
230
240
|
setCurrentMessageTaskId(item.taskId);
|
|
231
|
-
}, sx: {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
},
|
|
243
|
-
minHeight: sliderWidth / 2,
|
|
244
|
-
maxHeight: '50vh',
|
|
245
|
-
}, children: [_jsx(CodeRenderByMessage, { zoom: 0.25, message: item, sx: {
|
|
241
|
+
}, sx: Object.assign({ cursor: 'pointer', color: 'textColor', borderRadius: 1, border: 1, borderColor: isCurrent ? 'primary.main' : 'background.block', backgroundColor: 'white', position: 'relative', transition: 'all 0.3s', '&:hover': {
|
|
242
|
+
borderColor: 'primary.main',
|
|
243
|
+
} }, (isMobile
|
|
244
|
+
? {
|
|
245
|
+
width: sliderWidth / 2,
|
|
246
|
+
height: sliderWidth / 2,
|
|
247
|
+
}
|
|
248
|
+
: {
|
|
249
|
+
minHeight: sliderWidth / 2,
|
|
250
|
+
maxHeight: '50vh',
|
|
251
|
+
})), children: [_jsx(CodeRenderByMessage, { zoom: 0.25, message: item, sx: {
|
|
246
252
|
pointerEvents: 'none',
|
|
247
253
|
}, propertiesValueMap: propertiesValueMap }), _jsx(Tooltip, { placement: "right", arrow: true, PopperProps: {
|
|
248
254
|
// disablePortal: true,
|
|
@@ -271,11 +277,11 @@ function V0DetailRender() {
|
|
|
271
277
|
color: isCurrent ? 'primary.main' : 'textColor',
|
|
272
278
|
borderRadius: 1,
|
|
273
279
|
} }) }, taskId)] }, taskId) }, taskId));
|
|
274
|
-
}) })] }, "slider"), _jsx(Box, { sx: {
|
|
280
|
+
}) }))] }, "slider"), _jsx(Box, { sx: {
|
|
275
281
|
borderRadius: 1,
|
|
276
282
|
backgroundColor: 'background.block',
|
|
277
283
|
flex: 1,
|
|
278
|
-
maxWidth: `calc(100% - ${sliderWidth}px - 16px)`,
|
|
284
|
+
maxWidth: isMobile ? '100%' : `calc(100% - ${sliderWidth}px - 16px)`,
|
|
279
285
|
}, children: _jsx(AgentOutputRender, { message: currentMessage }) })] }));
|
|
280
286
|
}
|
|
281
287
|
function AgentInputRender(_a) {
|
|
@@ -72,11 +72,11 @@ export function CodeRenderByMessage({ zoom, message, minHeight = 200, sx, proper
|
|
|
72
72
|
} }) }));
|
|
73
73
|
}
|
|
74
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;
|
|
75
|
+
var _a, _b, _c;
|
|
76
76
|
const { taskId } = item;
|
|
77
77
|
// @ts-ignore
|
|
78
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));
|
|
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]) || ((_c = propertiesValueMap === null || propertiesValueMap === void 0 ? void 0 : propertiesValueMap[taskId]) === null || _c === void 0 ? void 0 : _c.en) || {} }, item.taskId));
|
|
80
80
|
});
|
|
81
81
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
82
|
}, [isMessageLoading, (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects, propertiesValueMap, locale]);
|
|
@@ -74,29 +74,31 @@ export function AIRunningLoading(props) {
|
|
|
74
74
|
backgroundColor: 'grey.200',
|
|
75
75
|
} }),
|
|
76
76
|
_jsx(Skeleton, { variant: "rectangular", sx: {
|
|
77
|
-
width:
|
|
77
|
+
width: 90,
|
|
78
78
|
height: 50,
|
|
79
79
|
borderRadius: 1,
|
|
80
80
|
backgroundColor: 'grey.200',
|
|
81
81
|
} }),
|
|
82
82
|
_jsx(Skeleton, { variant: "rectangular", sx: {
|
|
83
|
-
width:
|
|
83
|
+
width: 120,
|
|
84
84
|
height: 50,
|
|
85
85
|
borderRadius: 1,
|
|
86
86
|
backgroundColor: 'grey.200',
|
|
87
87
|
} }),
|
|
88
88
|
],
|
|
89
89
|
sx: {
|
|
90
|
-
|
|
90
|
+
px: 2,
|
|
91
|
+
py: 1,
|
|
91
92
|
display: 'flex',
|
|
92
93
|
gap: 1.5,
|
|
93
94
|
justifyContent: 'space-between',
|
|
95
|
+
overflow: 'hidden',
|
|
94
96
|
},
|
|
95
97
|
},
|
|
96
98
|
},
|
|
97
99
|
{
|
|
98
100
|
time: 60,
|
|
99
|
-
width:
|
|
101
|
+
width: 290,
|
|
100
102
|
height: 150,
|
|
101
103
|
extraProps: {
|
|
102
104
|
sx: {
|
|
@@ -105,7 +107,7 @@ export function AIRunningLoading(props) {
|
|
|
105
107
|
},
|
|
106
108
|
},
|
|
107
109
|
];
|
|
108
|
-
return (_jsx(Box, Object.assign({ sx: Object.assign({ flex: 1, display: 'inline-flex', justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', flexDirection: 'column', gap: 1.5, '@keyframes loading': {
|
|
110
|
+
return (_jsx(Box, Object.assign({ sx: Object.assign({ flex: 1, display: 'inline-flex', justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', flexDirection: 'column', gap: 1.5, width: '100%', overflow: 'hidden', '@keyframes loading': {
|
|
109
111
|
'0%': {
|
|
110
112
|
transform: 'translateY(-8px) scaleX(1.3)',
|
|
111
113
|
opacity: 0,
|