@blocklet/pages-kit 0.2.317 → 0.2.318

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 (48) 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/V0/Input.js +66 -36
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +190 -57
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +101 -0
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +60 -0
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +152 -0
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +80 -0
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +32 -0
  11. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +54 -0
  12. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/utils.js +13 -0
  13. package/lib/cjs/builtin/async/ai-runtime/state/session.js +52 -23
  14. package/lib/cjs/components/CustomComponentRenderer/state.js +23 -4
  15. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  16. package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
  17. package/lib/esm/builtin/async/ai-runtime/locales/index.js +26 -0
  18. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.js +2 -2
  19. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +60 -30
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +191 -58
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +92 -0
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +55 -0
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +144 -0
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +75 -0
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +26 -0
  27. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +49 -0
  28. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/utils.js +9 -0
  29. package/lib/esm/builtin/async/ai-runtime/state/session.js +52 -23
  30. package/lib/esm/components/CustomComponentRenderer/state.js +22 -4
  31. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  32. package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
  33. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +1 -0
  34. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +26 -0
  35. package/lib/types/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.d.ts +2 -1
  36. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +1 -1
  37. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.d.ts +20 -0
  38. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.d.ts +6 -0
  39. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/Loading.d.ts +3 -0
  40. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.d.ts +6 -0
  41. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.d.ts +3 -0
  42. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.d.ts +16 -0
  43. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/utils.d.ts +7 -0
  44. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +11 -3
  45. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -0
  46. package/lib/types/tsconfig.tsbuildinfo +1 -1
  47. package/lib/types/types/core.d.ts +2 -1
  48. package/package.json +1 -1
@@ -37,6 +37,7 @@ exports.translations = {
37
37
  rename: 'Rename',
38
38
  delete: 'Delete',
39
39
  confirmDelete: 'Confirm Delete?',
40
+ confirm: 'Confirm',
40
41
  noData: 'No {data} yet',
41
42
  createObject: 'Create {object}',
42
43
  title: 'Title',
@@ -95,6 +96,18 @@ exports.translations = {
95
96
  send: 'Send',
96
97
  session: 'Session',
97
98
  loadMore: 'Load More',
99
+ v0: {
100
+ title: 'AIGNE v0',
101
+ description: 'AIGNE v0 is an AI-based code tool that can help you generate code quickly.',
102
+ noData: 'No conversation information yet, click the button below to start generating!',
103
+ deleteSessionTitle: 'Delete Conversation Information',
104
+ deleteSessionTip: 'Are you sure you want to delete this Conversation Information?',
105
+ propertiesSetting: 'Properties Setting',
106
+ propertiesSettingTip: 'This function is used for debugging components and does not affect the final code',
107
+ cannotSetPropertiesTip: 'Failed to parse PROPERTIES_SCHEMA, this code cannot be set properties',
108
+ codePreview: 'Code Preview',
109
+ codePreviewTip: 'Here is the code preview, you can view the generated code, and editing is not supported yet.',
110
+ },
98
111
  },
99
112
  zh: {
100
113
  by: '作者',
@@ -131,6 +144,7 @@ exports.translations = {
131
144
  rename: '重命名',
132
145
  delete: '删除',
133
146
  confirmDelete: '确定删除?',
147
+ confirm: '确定',
134
148
  noData: '暂无{data}',
135
149
  createObject: '创建{object}',
136
150
  title: '标题',
@@ -189,5 +203,17 @@ exports.translations = {
189
203
  send: '发送',
190
204
  session: '会话',
191
205
  loadMore: '加载更多',
206
+ v0: {
207
+ title: 'AIGNE v0',
208
+ description: 'AIGNE v0 是一个基于人工智能的代码工具,可以帮助您快速生成代码。',
209
+ noData: '暂无生成记录,点击下方按钮开始生成吧!',
210
+ deleteSessionTitle: '删除生成记录',
211
+ deleteSessionTip: '确定要删除此生成记录吗?',
212
+ propertiesSetting: '属性设置',
213
+ propertiesSettingTip: '此功能用于调试组件,不影响最终代码',
214
+ cannotSetPropertiesTip: '解析 PROPERTIES_SCHEMA 失败,此代码无法进行属性设置',
215
+ codePreview: '代码预览',
216
+ codePreviewTip: '以下是代码预览,您可以查看生成的代码,目前还不支持编辑。',
217
+ },
192
218
  },
193
219
  };
@@ -7,13 +7,13 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const material_1 = require("@mui/material");
8
8
  const locale_1 = require("../../../../locale");
9
9
  const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
10
- function MessageErrorView({ error }) {
10
+ function MessageErrorView({ error, sx }) {
11
11
  const { t } = (0, locale_1.useLocaleContext)();
12
12
  if (!error)
13
13
  return null;
14
14
  if (error.status === 401) {
15
15
  return ((0, jsx_runtime_1.jsx)(material_1.Box, { className: "ai-chat-message-error", children: (0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-response", children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: t('requireLogin') }) }) }));
16
16
  }
17
- return ((0, jsx_runtime_1.jsx)(material_1.Alert, { className: "ai-chat-message-error", severity: "error", sx: { mr: 5 }, children: error.message }));
17
+ return ((0, jsx_runtime_1.jsx)(material_1.Alert, { className: "ai-chat-message-error", severity: "error", sx: Object.assign({ mr: 5 }, sx), children: error.message }));
18
18
  }
19
19
  exports.default = MessageErrorView;
@@ -14,24 +14,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
16
  const css_1 = require("@emotion/css");
17
+ const react_1 = require("@iconify/react");
17
18
  const material_1 = require("@mui/material");
18
19
  const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
19
20
  const omit_1 = __importDefault(require("lodash/omit"));
20
- const react_1 = require("react");
21
+ const react_2 = require("react");
21
22
  const react_hook_form_1 = require("react-hook-form");
22
23
  const locale_1 = require("../../../../locale");
23
24
  const AgentInputField_1 = __importDefault(require("../../components/AgentInputField"));
24
25
  const LoadingButton_1 = __importDefault(require("../../components/LoadingButton"));
25
26
  const CurrentAgent_1 = require("../../contexts/CurrentAgent");
27
+ const use_appearances_1 = require("../../hooks/use-appearances");
26
28
  const runtime_1 = require("../../state/runtime");
27
29
  const session_1 = require("../../state/session");
28
30
  const agent_inputs_1 = require("../../utils/agent-inputs");
29
- function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
31
+ const V0Runtime_1 = require("./contexts/V0Runtime");
32
+ function V0Input({ submitText, inlineLabel, autoFillLastForm = false, submitInQuestionField = true, chatMode = true, }) {
33
+ var _a, _b;
30
34
  const { t } = (0, locale_1.useLocaleContext)();
31
35
  const { aid, agent } = (0, CurrentAgent_1.useCurrentAgent)();
36
+ const opening = (0, use_appearances_1.useOpeningQuestions)();
32
37
  const { execute } = (0, runtime_1.useRuntimeState)();
33
- const running = (0, session_1.useCurrentSessionState)((s) => s === null || s === void 0 ? void 0 : s.running);
34
- const parameters = (0, react_1.useMemo)(() => {
38
+ const { running } = (0, session_1.useCurrentSessionState)((s) => s) || {};
39
+ const { createSession, currentSessionId } = (0, session_1.useSessionState)((s) => s) || {};
40
+ const { setCurrentMessageTaskId } = (0, V0Runtime_1.useV0RuntimeContext)();
41
+ const parameters = (0, react_2.useMemo)(() => {
35
42
  var _a;
36
43
  return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.isValidInput).map((i) => {
37
44
  var _a;
@@ -41,60 +48,83 @@ function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQu
41
48
  const defaultForm = useInitialFormValues();
42
49
  const theme = useFormTheme();
43
50
  const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
44
- (0, react_1.useEffect)(() => {
51
+ (0, react_2.useEffect)(() => {
45
52
  if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
46
53
  form.reset(chatMode ? (0, omit_1.default)(defaultForm, 'question') : defaultForm);
47
54
  }
48
55
  }, [defaultForm, autoFillLastForm, form, chatMode]);
49
56
  const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
57
+ if (!(parameters === null || parameters === void 0 ? void 0 : parameters.question))
58
+ return;
59
+ if (!currentSessionId) {
60
+ yield createSession({
61
+ name: parameters === null || parameters === void 0 ? void 0 : parameters.question,
62
+ });
63
+ }
64
+ // in session page, send message
50
65
  yield execute({
51
66
  aid,
52
67
  parameters,
53
68
  onResponseStart: () => {
69
+ setCurrentMessageTaskId(undefined);
54
70
  if (chatMode)
55
71
  form.resetField('question', { defaultValue: '' });
56
72
  },
57
73
  });
58
74
  });
59
- return ((0, jsx_runtime_1.jsx)(material_1.ThemeProvider, { theme: theme, children: (0, jsx_runtime_1.jsxs)(Form, { component: "form", className: (0, css_1.cx)('form', `label-position-${inlineLabel ? 'start' : 'top'}`), onSubmit: form.handleSubmit(onSubmit), children: [parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter, index) => {
60
- const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
61
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: key, rules: {
62
- required,
63
- min: parameter.type === 'number' && typeof parameter.min === 'number'
64
- ? { value: parameter.min, message: '' }
65
- : undefined,
66
- max: parameter.type === 'number' && typeof parameter.max === 'number'
67
- ? { value: parameter.max, message: '' }
68
- : undefined,
69
- minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
70
- ? { value: parameter.minLength, message: '' }
71
- : undefined,
72
- maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
73
- ? { value: parameter.maxLength, message: '' }
74
- : undefined,
75
- }, render: ({ field, fieldState }) => {
76
- var _a;
77
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "form-item", children: [parameter.label && (0, jsx_runtime_1.jsx)(material_1.FormLabel, { children: parameter.label }), (0, jsx_runtime_1.jsx)(AgentInputField_1.default, { inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: parameter.key === 'question' && submitInQuestionField
78
- ? {
79
- endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75, alignSelf: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText }) })),
80
- }
81
- : undefined })] }));
82
- } }) }, parameter.id));
83
- }), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
75
+ return ((0, jsx_runtime_1.jsxs)(material_1.ThemeProvider, { theme: theme, children: [!currentSessionId && ((_a = opening === null || opening === void 0 ? void 0 : opening.questions) === null || _a === void 0 ? void 0 : _a.length) && ((0, jsx_runtime_1.jsx)(material_1.Stack, { sx: {
76
+ flexDirection: 'row',
77
+ gap: 1,
78
+ mb: 1,
79
+ }, children: (_b = opening === null || opening === void 0 ? void 0 : opening.questions) === null || _b === void 0 ? void 0 : _b.map((item) => {
80
+ const { title, parameters, id } = item;
81
+ const question = (parameters === null || parameters === void 0 ? void 0 : parameters.questions) || title;
82
+ return ((0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", size: "small", endIcon: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:arrow-down-right", style: {
83
+ marginLeft: -4,
84
+ } }), onClick: () => {
85
+ form.reset(Object.assign({}, parameters));
86
+ onSubmit(Object.assign({}, parameters));
87
+ }, children: question }, id));
88
+ }) })), (0, jsx_runtime_1.jsxs)(Form, { id: "v0-input", component: "form", className: (0, css_1.cx)('form', `label-position-${inlineLabel ? 'start' : 'top'}`), onSubmit: form.handleSubmit(onSubmit), children: [parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter, index) => {
89
+ const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
90
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: key, rules: {
91
+ required,
92
+ min: parameter.type === 'number' && typeof parameter.min === 'number'
93
+ ? { value: parameter.min, message: '' }
94
+ : undefined,
95
+ max: parameter.type === 'number' && typeof parameter.max === 'number'
96
+ ? { value: parameter.max, message: '' }
97
+ : undefined,
98
+ minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
99
+ ? { value: parameter.minLength, message: '' }
100
+ : undefined,
101
+ maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
102
+ ? { value: parameter.maxLength, message: '' }
103
+ : undefined,
104
+ }, render: ({ field, fieldState }) => {
105
+ var _a;
106
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "form-item", children: [parameter.label && (0, jsx_runtime_1.jsx)(material_1.FormLabel, { children: parameter.label }), (0, jsx_runtime_1.jsx)(AgentInputField_1.default, { inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: parameter.key === 'question' && submitInQuestionField
107
+ ? {
108
+ endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75, alignSelf: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText || t('generate') }) })),
109
+ }
110
+ : undefined })] }));
111
+ } }) }, parameter.id));
112
+ }), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] })] }));
84
113
  }
85
- exports.default = AutoForm;
114
+ exports.default = V0Input;
115
+ const autoSetLastParameters = false;
86
116
  function useInitialFormValues() {
87
117
  const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
88
118
  const lastMessage = (0, session_1.useCurrentSessionState)((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
89
- const [lastInputs, setLastInputs] = (0, react_1.useState)();
90
- (0, react_1.useEffect)(() => {
91
- if (!lastInputs) {
119
+ const [lastInputs, setLastInputs] = (0, react_2.useState)();
120
+ (0, react_2.useEffect)(() => {
121
+ if (autoSetLastParameters && !lastInputs) {
92
122
  const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
93
123
  if (!(0, isEmpty_1.default)(lastParameters))
94
124
  setLastInputs(lastParameters);
95
125
  }
96
126
  }, [lastMessage]);
97
- return (0, react_1.useMemo)(() => {
127
+ return (0, react_2.useMemo)(() => {
98
128
  var _a, _b;
99
129
  if (lastInputs) {
100
130
  return lastInputs;
@@ -104,7 +134,7 @@ function useInitialFormValues() {
104
134
  }
105
135
  function useFormTheme() {
106
136
  const theme = (0, material_1.useTheme)();
107
- return (0, react_1.useMemo)(() => {
137
+ return (0, react_2.useMemo)(() => {
108
138
  const themeOptions = {
109
139
  shape: {
110
140
  borderRadius: 8,
@@ -1,79 +1,212 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  const jsx_runtime_1 = require("react/jsx-runtime");
16
+ const Toast_1 = __importDefault(require("@arcblock/ux/lib/Toast"));
7
17
  const react_1 = require("@iconify/react");
8
18
  const material_1 = require("@mui/material");
19
+ const groupBy_1 = __importDefault(require("lodash/groupBy"));
9
20
  const react_2 = require("react");
10
- const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
21
+ const CustomComponentRenderer_1 = require("../../../../../components/CustomComponentRenderer");
22
+ const locale_1 = require("../../../../locale");
11
23
  const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
12
24
  const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
13
25
  const CurrentMessage_1 = require("../../contexts/CurrentMessage");
14
- const MessageErrorView_1 = __importDefault(require("../ChatOutput/MessageErrorView"));
15
26
  const MessageMetadataRenderer_1 = __importDefault(require("../ChatOutput/MessageMetadataRenderer"));
16
- const codeField = 'code';
27
+ const CodePreview_1 = require("./components/CodePreview");
28
+ const Loading_1 = __importDefault(require("./components/Loading"));
29
+ const PropertiesSetting_1 = __importDefault(require("./components/PropertiesSetting"));
30
+ const UserQuestion_1 = __importDefault(require("./components/UserQuestion"));
31
+ const V0Runtime_1 = require("./contexts/V0Runtime");
32
+ const DEFAULT_DESKTOP_SX = {
33
+ width: '100%',
34
+ height: '100%',
35
+ };
17
36
  function V0Output() {
18
37
  var _a, _b;
19
38
  const { message } = (0, CurrentMessage_1.useCurrentMessage)();
39
+ const propertiesSettingRef = (0, react_2.useRef)(null);
40
+ const { propertiesValueMap, setPropertiesValueMap } = (0, V0Runtime_1.useV0RuntimeContext)();
41
+ const [code, setCode] = (0, react_2.useState)('');
42
+ const { t, locale } = (0, locale_1.useLocaleContext)();
43
+ const [codePreviewExtraSx, setCodePreviewExtraSx] = (0, react_2.useState)(DEFAULT_DESKTOP_SX);
20
44
  const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
21
- const { error } = message;
45
+ const { taskId, parameters } = message;
22
46
  const isMessageLoading = (message.loading || !message.result) && !message.error;
23
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, sx: {
24
- py: 2,
25
- }, children: [error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: error }), isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Stack, { sx: {
26
- flex: 1,
27
- }, children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", sx: {
28
- height: 400,
29
- borderRadius: 1,
30
- } }) })), objects === null || objects === void 0 ? void 0 : objects.map((item) => {
31
- // @ts-ignore
32
- const code = item.data[codeField];
33
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1, sx: {
34
- display: 'flex',
35
- justifyContent: 'center',
36
- alignItems: 'center',
37
- }, children: (0, jsx_runtime_1.jsx)(CodePreview, { code: code }) }));
38
- }), objects === null || objects === void 0 ? void 0 : objects.map((item) => (0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: item.data })), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } }))] }));
39
- }
40
- exports.default = V0Output;
41
- function CodePreview({ code }) {
42
- const [showCode, setShowCode] = (0, react_2.useState)(false);
43
- if (!code)
44
- return null;
47
+ const disabled = isMessageLoading || !(objects === null || objects === void 0 ? void 0 : objects.length) || message.error;
48
+ const responsiveSx = {
49
+ backgroundColor: 'white',
50
+ borderColor: 'rgba(0, 0, 0, 0.1) !important',
51
+ };
52
+ const tooltipOptions = [
53
+ {
54
+ key: 'Desktop',
55
+ icon: 'tabler:device-desktop',
56
+ props: {
57
+ sx: Object.assign({}, responsiveSx),
58
+ onClick: () => setCodePreviewExtraSx(DEFAULT_DESKTOP_SX),
59
+ },
60
+ group: 'responsive',
61
+ },
62
+ {
63
+ key: 'Tablet',
64
+ icon: 'tabler:device-tablet',
65
+ props: {
66
+ sx: Object.assign({}, responsiveSx),
67
+ onClick: () => setCodePreviewExtraSx({
68
+ width: '768px',
69
+ height: '1024px',
70
+ }),
71
+ },
72
+ group: 'responsive',
73
+ },
74
+ {
75
+ key: 'Mobile',
76
+ icon: 'tabler:device-mobile',
77
+ props: {
78
+ sx: Object.assign({}, responsiveSx),
79
+ onClick: () => setCodePreviewExtraSx({
80
+ width: '375px',
81
+ height: '667px',
82
+ }),
83
+ },
84
+ group: 'responsive',
85
+ },
86
+ // setting
87
+ {
88
+ key: 'Setting',
89
+ icon: 'tabler:settings-2',
90
+ props: {
91
+ disabled,
92
+ sx: Object.assign({}, responsiveSx),
93
+ onClick: (e) => __awaiter(this, void 0, void 0, function* () {
94
+ var _c;
95
+ const { taskid: taskId } = ((_c = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _c === void 0 ? void 0 : _c.dataset) || {};
96
+ const currentCode = (0, CodePreview_1.getCurrentCodeByTaskId)(message, taskId);
97
+ try {
98
+ yield (0, CustomComponentRenderer_1.transpileAndLoadScript)(currentCode).then((m) => {
99
+ var _a, _b;
100
+ if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
101
+ const schemaDefaultValues = Object.fromEntries(m.PROPERTIES_SCHEMA.map((item) => {
102
+ const { key, locales } = item;
103
+ const currentLocale = (locales === null || locales === void 0 ? void 0 : locales[locale]) || (locales === null || locales === void 0 ? void 0 : locales.en);
104
+ return [key, currentLocale === null || currentLocale === void 0 ? void 0 : currentLocale.defaultValue];
105
+ }));
106
+ const defaultValues = Object.assign(Object.assign({}, schemaDefaultValues), (_a = propertiesValueMap[taskId]) === null || _a === void 0 ? void 0 : _a[locale]);
107
+ // format default values
108
+ m.PROPERTIES_SCHEMA.forEach((item) => {
109
+ const { key, type } = item;
110
+ if (type === 'json' && typeof defaultValues[key] === 'object') {
111
+ try {
112
+ defaultValues[key] = JSON.stringify(defaultValues[key], null, 2);
113
+ }
114
+ catch (error) {
115
+ // ignore error
116
+ }
117
+ }
118
+ });
119
+ // @ts-ignore
120
+ (_b = propertiesSettingRef.current) === null || _b === void 0 ? void 0 : _b.open({
121
+ schema: m.PROPERTIES_SCHEMA,
122
+ onSubmit: (values) => {
123
+ const realValues = {};
124
+ m.PROPERTIES_SCHEMA.forEach((item) => {
125
+ const { key, type } = item;
126
+ if (type === 'json' && typeof values[key] === 'string') {
127
+ try {
128
+ realValues[key] = JSON.parse(values[key]);
129
+ return;
130
+ }
131
+ catch (error) {
132
+ // ignore error
133
+ }
134
+ }
135
+ realValues[key] = values[key];
136
+ });
137
+ setPropertiesValueMap(Object.assign(Object.assign({}, propertiesValueMap), { [taskId]: Object.assign(Object.assign({}, propertiesValueMap[taskId]), { [locale]: realValues }) }));
138
+ },
139
+ defaultValues,
140
+ });
141
+ return;
142
+ }
143
+ throw new Error('No properties schema found');
144
+ });
145
+ }
146
+ catch (error) {
147
+ // ignore error
148
+ // send cannot set properties message
149
+ Toast_1.default.info(t('v0.cannotSetPropertiesTip'));
150
+ }
151
+ }),
152
+ },
153
+ group: 'setting',
154
+ },
155
+ {
156
+ key: 'CodePreview',
157
+ icon: code ? 'tabler:layout-board' : 'tabler:code',
158
+ buttonText: code ? 'Canvas' : 'Code',
159
+ props: {
160
+ disabled,
161
+ variant: 'contained',
162
+ color: 'primary',
163
+ onClick: (e) => {
164
+ var _a;
165
+ const { taskid: taskId } = ((_a = e === null || e === void 0 ? void 0 : e.currentTarget) === null || _a === void 0 ? void 0 : _a.dataset) || {};
166
+ setCode((0, CodePreview_1.getCurrentCodeByTaskId)(message, taskId));
167
+ },
168
+ },
169
+ group: 'codePreview',
170
+ },
171
+ ];
45
172
  return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: {
46
- flex: 1,
47
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
173
+ p: 2,
174
+ gap: 2,
175
+ height: '100%',
176
+ display: 'flex',
177
+ justifyContent: 'flex-start',
178
+ alignItems: 'center',
179
+ flexDirection: 'column',
180
+ }, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: {
48
181
  display: 'flex',
49
- justifyContent: 'flex-end',
50
- }, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: () => setShowCode((prev) => !prev), sx: {
51
- color: 'textColor',
52
- }, children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: showCode ? 'tabler:layout-sidebar' : 'tabler:code' }) }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 2, sx: {
53
- display: 'flex',
54
- flexDirection: 'row',
182
+ justifyContent: 'space-between',
55
183
  alignItems: 'center',
56
- justifyContent: 'center',
57
- }, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
58
- display: 'flex',
59
- justifyContent: 'center',
60
- alignItems: 'center',
61
- }, children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: "mock-dev-component", dev: {
62
- components: {
63
- 'mock-dev-component': {
64
- data: {
65
- id: 'mock-dev-component',
66
- createdAt: '',
67
- updatedAt: '',
68
- renderer: {
69
- type: 'react-component',
70
- script: code,
71
- },
72
- },
73
- },
74
- },
75
- } }) }) }), (0, jsx_runtime_1.jsx)(material_1.Drawer, { anchor: "right", open: showCode, onClose: () => setShowCode(false), children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
76
- p: 2,
77
- maxWidth: '40vw',
78
- }, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: `\`\`\`typescript\n${code}\n\`\`\`` }) }) })] }));
184
+ width: '100%',
185
+ gap: 1.5,
186
+ flexDirection: 'row',
187
+ }, children: [(0, jsx_runtime_1.jsx)(UserQuestion_1.default, { question: parameters === null || parameters === void 0 ? void 0 : parameters.question }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
188
+ display: 'flex',
189
+ alignItems: 'center',
190
+ gap: 1.5,
191
+ }, children: Object.entries((0, groupBy_1.default)(tooltipOptions, 'group')).map(([group, options]) => {
192
+ return ((0, jsx_runtime_1.jsx)(material_1.ButtonGroup, { variant: "text", color: "inherit", size: "small", sx: {
193
+ borderColor: 'rgba(0, 0, 0, 0.1) !important',
194
+ border: 1,
195
+ }, children: options.map((option) => {
196
+ const { icon, key, props, buttonText } = option;
197
+ return ((0, jsx_runtime_1.jsxs)(material_1.Button, Object.assign({ "data-taskId": taskId }, props, { children: [(0, jsx_runtime_1.jsx)(react_1.Icon, { icon: icon, fontSize: 22 }), buttonText && (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { ml: 1 }, children: buttonText })] }), key));
198
+ }) }, group));
199
+ }) })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: Object.assign({ display: 'flex', justifyContent: 'center', overflow: 'hidden', backgroundColor: 'white', borderRadius: 1 }, codePreviewExtraSx), children: (0, jsx_runtime_1.jsx)(CodePreview_1.CodeRenderByMessageMemo, { message: message, zoom: 1, sx: {
200
+ overflowX: 'auto',
201
+ overflowY: 'auto',
202
+ scrollbarWidth: 'thin',
203
+ scrollbarColor: 'grey transparent',
204
+ }, propertiesValueMap: propertiesValueMap }) }), objects === null || objects === void 0 ? void 0 : objects.map((item, index) => (0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: item.data }, index)), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })), (0, jsx_runtime_1.jsxs)(react_2.Suspense, { fallback: (0, jsx_runtime_1.jsx)(Loading_1.default, {}), children: [(0, jsx_runtime_1.jsx)(material_1.Drawer, { anchor: "right", open: !!code, onClose: () => setCode(''), children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
205
+ p: 2,
206
+ maxWidth: '60vw',
207
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h6", sx: {
208
+ lineHeight: 2,
209
+ mb: 1,
210
+ }, children: t('v0.codePreview') }), (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "info", sx: { mb: 2 }, children: t('v0.codePreviewTip') }), (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: `\`\`\`typescript\n${code}\n\`\`\`` })] }) }), (0, jsx_runtime_1.jsx)(PropertiesSetting_1.default, { ref: propertiesSettingRef })] })] }));
79
211
  }
212
+ exports.default = V0Output;