@blocklet/pages-kit 0.2.291 → 0.2.293

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +2 -1
  2. package/lib/cjs/builtin/async/ai-runtime/api/message.js +14 -1
  3. package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -3
  4. package/lib/cjs/builtin/async/ai-runtime/api/session.js +2 -2
  5. package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +1 -9
  6. package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
  7. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +1 -1
  8. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
  9. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
  10. package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  11. package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
  12. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
  13. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -29
  14. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
  15. package/lib/cjs/builtin/async/ai-runtime/components/parameters/RadioField.js +39 -0
  16. package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
  17. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +5 -1
  18. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +153 -0
  19. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +19 -0
  20. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +179 -0
  21. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +13 -0
  22. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +129 -0
  23. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +117 -0
  24. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +109 -0
  25. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +17 -0
  26. package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +87 -0
  27. package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +27 -0
  28. package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +19 -0
  29. package/lib/cjs/builtin/async/ai-runtime/components/runtime/index.js +42 -0
  30. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/assistant.js +61 -0
  31. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/runtime.js +56 -0
  32. package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/session.js +213 -0
  33. package/lib/cjs/builtin/async/ai-runtime/components/runtime/utils/map-right.js +10 -0
  34. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +42 -20
  35. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +12 -5
  36. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
  37. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
  38. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
  39. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +16 -7
  40. package/lib/cjs/builtin/async/ai-runtime/hooks/auth.js +31 -0
  41. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +29 -19
  42. package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
  43. package/lib/cjs/builtin/async/ai-runtime/index.js +38 -30
  44. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +28 -0
  45. package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -18
  46. package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +4 -4
  47. package/lib/cjs/components/CustomComponentRenderer/index.js +0 -1
  48. package/lib/cjs/components/CustomComponentRenderer/state.js +64 -57
  49. package/lib/cjs/components/index.js +1 -0
  50. package/lib/esm/builtin/async/ai-runtime/api/assistant.js +2 -1
  51. package/lib/esm/builtin/async/ai-runtime/api/message.js +14 -1
  52. package/lib/esm/builtin/async/ai-runtime/api/request.js +5 -3
  53. package/lib/esm/builtin/async/ai-runtime/api/session.js +2 -2
  54. package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +2 -10
  55. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
  56. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +2 -2
  57. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
  58. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
  59. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
  60. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
  61. package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
  62. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -31
  63. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
  64. package/lib/esm/builtin/async/ai-runtime/components/parameters/RadioField.js +37 -0
  65. package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
  66. package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +5 -1
  67. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +146 -0
  68. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +13 -0
  69. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +149 -0
  70. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +7 -0
  71. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +100 -0
  72. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +114 -0
  73. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +80 -0
  74. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +11 -0
  75. package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +58 -0
  76. package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +22 -0
  77. package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +14 -0
  78. package/lib/esm/builtin/async/ai-runtime/components/runtime/index.js +36 -0
  79. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/assistant.js +56 -0
  80. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/runtime.js +52 -0
  81. package/lib/esm/builtin/async/ai-runtime/components/runtime/state/session.js +209 -0
  82. package/lib/esm/builtin/async/ai-runtime/components/runtime/utils/map-right.js +7 -0
  83. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +21 -22
  84. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +13 -6
  85. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
  86. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
  87. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
  88. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +9 -0
  89. package/lib/esm/builtin/async/ai-runtime/hooks/auth.js +27 -0
  90. package/lib/esm/builtin/async/ai-runtime/hooks/header.js +30 -20
  91. package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
  92. package/lib/esm/builtin/async/ai-runtime/index.js +15 -29
  93. package/lib/esm/builtin/async/ai-runtime/locales/index.js +28 -0
  94. package/lib/esm/builtin/async/ai-runtime/state/session.js +17 -20
  95. package/lib/esm/builtin/async/ai-runtime/state/subscription.js +2 -2
  96. package/lib/esm/components/CustomComponentRenderer/index.js +0 -1
  97. package/lib/esm/components/CustomComponentRenderer/state.js +63 -57
  98. package/lib/esm/components/index.js +1 -0
  99. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +4 -2
  100. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +9 -2
  101. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +4 -1
  102. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -1
  103. package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +3 -2
  104. package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +3 -2
  105. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +5 -2
  106. package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +4 -5
  107. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +11 -4
  108. package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -3
  109. package/lib/types/builtin/async/ai-runtime/components/parameters/RadioField.d.ts +9 -0
  110. package/lib/types/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.d.ts +9 -0
  111. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.d.ts +3 -0
  112. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.d.ts +12 -0
  113. package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.d.ts +1 -0
  114. package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.d.ts +5 -0
  115. package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.d.ts +1 -0
  116. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.d.ts +3 -0
  117. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.d.ts +1 -0
  118. package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.d.ts +4 -0
  119. package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.d.ts +12 -0
  120. package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.d.ts +10 -0
  121. package/lib/types/builtin/async/ai-runtime/components/runtime/index.d.ts +1 -0
  122. package/lib/types/builtin/async/ai-runtime/components/runtime/state/assistant.d.ts +17 -0
  123. package/lib/types/builtin/async/ai-runtime/components/runtime/state/runtime.d.ts +14 -0
  124. package/lib/types/builtin/async/ai-runtime/components/runtime/state/session.d.ts +29 -0
  125. package/lib/types/builtin/async/ai-runtime/components/runtime/utils/map-right.d.ts +1 -0
  126. package/lib/types/builtin/async/ai-runtime/hooks/auth.d.ts +4 -0
  127. package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +1 -0
  128. package/lib/types/builtin/async/ai-runtime/index.d.ts +15 -8
  129. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +22 -0
  130. package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +0 -2
  131. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +0 -3
  132. package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +1 -1
  133. package/lib/types/components/CustomComponentRenderer/index.d.ts +0 -1
  134. package/lib/types/components/CustomComponentRenderer/state.d.ts +2 -3
  135. package/lib/types/components/index.d.ts +1 -0
  136. package/lib/types/types/core.d.ts +1 -0
  137. package/package.json +9 -7
@@ -0,0 +1,153 @@
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
+ exports.SUPPORTED_PARAMETER_TYPES = void 0;
16
+ const jsx_runtime_1 = require("react/jsx-runtime");
17
+ const css_1 = require("@emotion/css");
18
+ const material_1 = require("@mui/material");
19
+ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
20
+ const omit_1 = __importDefault(require("lodash/omit"));
21
+ const react_1 = require("react");
22
+ const react_hook_form_1 = require("react-hook-form");
23
+ const locale_1 = require("../../../../../../locale");
24
+ const LoadingButton_1 = __importDefault(require("../../../LoadingButton"));
25
+ const parameters_1 = __importDefault(require("../../../parameters"));
26
+ const CurrentAgent_1 = require("../../contexts/CurrentAgent");
27
+ const runtime_1 = require("../../state/runtime");
28
+ exports.SUPPORTED_PARAMETER_TYPES = ['string', 'number', 'select', 'language'];
29
+ function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
30
+ const { t } = (0, locale_1.useLocaleContext)();
31
+ const { aid, agent } = (0, CurrentAgent_1.useCurrentAgent)();
32
+ const { sessionState, execute } = (0, runtime_1.useRuntimeState)();
33
+ const parameters = (0, react_1.useMemo)(() => {
34
+ var _a;
35
+ return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => !!i.key && exports.SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string')).map((i) => {
36
+ var _a;
37
+ return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
38
+ });
39
+ }, [agent.parameters]);
40
+ const defaultForm = useInitialFormValues();
41
+ const theme = useFormTheme();
42
+ const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
43
+ (0, react_1.useEffect)(() => {
44
+ if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
45
+ form.reset(chatMode ? (0, omit_1.default)(defaultForm, 'question') : defaultForm);
46
+ }
47
+ }, [defaultForm, autoFillLastForm, form]);
48
+ const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
49
+ yield execute({
50
+ aid,
51
+ parameters,
52
+ onResponseStart: () => {
53
+ if (chatMode)
54
+ form.resetField('question', { defaultValue: '' });
55
+ },
56
+ });
57
+ });
58
+ 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) => {
59
+ const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
60
+ 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: {
61
+ required,
62
+ min: parameter.type === 'number' && typeof parameter.min === 'number'
63
+ ? { value: parameter.min, message: '' }
64
+ : undefined,
65
+ max: parameter.type === 'number' && typeof parameter.max === 'number'
66
+ ? { value: parameter.max, message: '' }
67
+ : undefined,
68
+ minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
69
+ ? { value: parameter.minLength, message: '' }
70
+ : undefined,
71
+ maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
72
+ ? { value: parameter.maxLength, message: '' }
73
+ : undefined,
74
+ }, render: ({ field, fieldState }) => {
75
+ var _a;
76
+ 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)(parameters_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
77
+ ? {
78
+ endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: sessionState.running, sx: { borderRadius: 100 }, children: submitText }) })),
79
+ }
80
+ : undefined })] }));
81
+ } }) }, parameter.id));
82
+ }), !(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: sessionState.running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
83
+ }
84
+ exports.default = AutoForm;
85
+ function useInitialFormValues() {
86
+ var _a;
87
+ const [lastMessage, setLastMessage] = (0, react_1.useState)();
88
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
89
+ const { sessionState } = (0, runtime_1.useRuntimeState)();
90
+ (0, react_1.useEffect)(() => {
91
+ var _a;
92
+ if (!lastMessage) {
93
+ setLastMessage((_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]);
94
+ }
95
+ }, [(_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.length]);
96
+ return (0, react_1.useMemo)(() => {
97
+ var _a, _b;
98
+ if (lastMessage) {
99
+ const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
100
+ if (!(0, isEmpty_1.default)(lastParameters))
101
+ return lastParameters;
102
+ }
103
+ return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _b !== void 0 ? _b : []);
104
+ }, [lastMessage, agent]);
105
+ }
106
+ function useFormTheme() {
107
+ const theme = (0, material_1.useTheme)();
108
+ return (0, react_1.useMemo)(() => {
109
+ const themeOptions = {
110
+ shape: {
111
+ borderRadius: 8,
112
+ },
113
+ components: {
114
+ MuiTextField: {
115
+ styleOverrides: {
116
+ root: ({ theme }) => theme.unstable_sx({
117
+ [`.${material_1.outlinedInputClasses.root}`]: {
118
+ [`.${material_1.outlinedInputClasses.notchedOutline}`]: {
119
+ borderWidth: 2,
120
+ borderColor: 'primary.light',
121
+ },
122
+ ':hover': {
123
+ [`.${material_1.outlinedInputClasses.notchedOutline}`]: {
124
+ borderColor: 'primary.main',
125
+ },
126
+ },
127
+ },
128
+ }),
129
+ },
130
+ },
131
+ },
132
+ };
133
+ return (0, material_1.createTheme)(theme, themeOptions);
134
+ }, [theme]);
135
+ }
136
+ const Form = (0, material_1.styled)(material_1.Stack)(({ theme }) => theme.unstable_sx({
137
+ gap: 2,
138
+ '.form-item': {
139
+ gap: 0.5,
140
+ [`.${material_1.formLabelClasses.root}`]: {
141
+ fontWeight: 500,
142
+ color: 'text.primary',
143
+ },
144
+ },
145
+ '&.label-position-start': {
146
+ '.form-item': {
147
+ display: 'flex',
148
+ flexDirection: 'row',
149
+ alignItems: 'center',
150
+ gap: 1,
151
+ },
152
+ },
153
+ }));
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const material_1 = require("@mui/material");
8
+ const locale_1 = require("../../../../../../locale");
9
+ const MarkdownRenderer_1 = __importDefault(require("../../../MarkdownRenderer"));
10
+ function MessageErrorView({ error }) {
11
+ const { t } = (0, locale_1.useLocaleContext)();
12
+ if (!error)
13
+ return null;
14
+ if (error.status === 401) {
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
+ }
17
+ return ((0, jsx_runtime_1.jsx)(material_1.Alert, { className: "ai-chat-message-error", severity: "error", sx: { mr: 5 }, children: error.message }));
18
+ }
19
+ exports.default = MessageErrorView;
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.MessageItemWrapper = void 0;
41
+ const jsx_runtime_1 = require("react/jsx-runtime");
42
+ const image_preview_1 = __importDefault(require("@blocklet/ai-kit/components/image-preview"));
43
+ const css_1 = require("@emotion/css");
44
+ const material_1 = require("@mui/material");
45
+ const dayjs_1 = __importDefault(require("dayjs"));
46
+ const react_1 = __importStar(require("react"));
47
+ const ux_1 = require("../../../../../../arcblock/ux");
48
+ const session_1 = require("../../../../../../session");
49
+ const common_1 = require("../../../common");
50
+ const MarkdownRenderer_1 = __importDefault(require("../../../MarkdownRenderer"));
51
+ const MessageActions_1 = __importDefault(require("../../../message/MessageActions"));
52
+ const runtime_1 = require("../../state/runtime");
53
+ const MessageErrorView_1 = __importDefault(require("./MessageErrorView"));
54
+ const MessageItemView = (0, react_1.memo)((_a) => {
55
+ var _b;
56
+ var { message, hideAvatar } = _a, props = __rest(_a, ["message", "hideAvatar"]);
57
+ const showUserMessage = !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
58
+ return ((0, jsx_runtime_1.jsxs)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: [showUserMessage && (0, jsx_runtime_1.jsx)(UserMessage, { message: message }), (0, jsx_runtime_1.jsx)(AgentMessage, { message: message, hideAvatar: hideAvatar })] })));
59
+ });
60
+ exports.default = MessageItemView;
61
+ const MessageItemContainer = (0, material_1.styled)(material_1.Stack) `
62
+ gap: ${({ theme }) => theme.spacing(2.5)};
63
+ overflow: hidden;
64
+
65
+ .message-question {
66
+ position: relative;
67
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
68
+ border-top-right-radius: 2px;
69
+ padding: ${({ theme }) => theme.spacing(1, 2)};
70
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
71
+ // without logo width
72
+ max-width: calc(100% - 40px);
73
+ background-color: rgba(239, 246, 255, 1);
74
+
75
+ &.hide-avatar {
76
+ border-top-right-radius: ${({ theme }) => theme.shape.borderRadius}px;
77
+ }
78
+ }
79
+
80
+ .message-response {
81
+ position: relative;
82
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
83
+ border-top-left-radius: 2px;
84
+ padding: ${({ theme }) => theme.spacing(1, 2)};
85
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
86
+ // without logo width
87
+ max-width: calc(100% - 40px);
88
+ background-color: rgba(229, 231, 235, 1);
89
+
90
+ &.hide-avatar {
91
+ border-top-left-radius: ${({ theme }) => theme.shape.borderRadius}px;
92
+ }
93
+ }
94
+ `;
95
+ function UserMessage({ message }) {
96
+ var _a, _b, _c, _d;
97
+ const { session: authSession } = (0, session_1.useSessionContext)();
98
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-user", direction: "row", gap: 1.5, sx: {
99
+ display: 'flex',
100
+ flexDirection: 'row-reverse',
101
+ textAlign: 'right',
102
+ justifyContent: 'flex-end',
103
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, src: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.avatar, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, variant: "circle", shape: "circle" }) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { flex: 1, overflow: "hidden", sx: {
104
+ display: 'flex',
105
+ flexDirection: 'column',
106
+ alignItems: 'flex-end',
107
+ }, children: [(0, jsx_runtime_1.jsxs)(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_d = message.parameters) === null || _d === void 0 ? void 0 : _d.question })] })] }));
108
+ }
109
+ function AgentMessage({ message, hideAvatar }) {
110
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
111
+ const { appearancePage } = (0, runtime_1.useRuntimeState)();
112
+ const showMainMessage = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) || ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.length));
113
+ const isMessageLoading = (message.loading || !message.result) && !message.error;
114
+ const theme = (0, material_1.useTheme)();
115
+ const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
116
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _e === void 0 ? void 0 : _e.url }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { placement: "right-start", slotProps: {
117
+ popper: {
118
+ modifiers: [
119
+ {
120
+ name: 'offset',
121
+ options: {
122
+ offset: [-3, isMobile ? (!hideAvatar ? -18 : -8) : -6],
123
+ },
124
+ },
125
+ ],
126
+ },
127
+ tooltip: {
128
+ sx: {
129
+ bgcolor: 'white',
130
+ boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
131
+ border: '1px solid rgba(229, 231, 235, 1)',
132
+ p: 0.5,
133
+ },
134
+ },
135
+ }, title: !isMessageLoading && ((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && (0, jsx_runtime_1.jsx)(MessageActions_1.default, { content: message.result.content }), children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
136
+ var _a, _b, _c, _d, _e, _f, _g;
137
+ return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading &&
138
+ !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
139
+ !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
140
+ message.result.messages.length - 1 === index
141
+ ? 'writing'
142
+ : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? ((0, jsx_runtime_1.jsx)(image_preview_1.default, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
143
+ }), ((_j = message.result) === null || _j === void 0 ? void 0 : _j.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) })) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
144
+ // only response with loading
145
+ className: "message-response" }))), (_l = (_k = message.result) === null || _k === void 0 ? void 0 : _k.objects) === null || _l === void 0 ? void 0 : _l.map((object) => ((0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: message.error })] })] })] }));
146
+ }
147
+ function MessageItemWrapper(_a) {
148
+ var _b, _c;
149
+ var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
150
+ const { appearancePage } = (0, runtime_1.useRuntimeState)();
151
+ const [time] = (0, react_1.useState)(() => new Date().toISOString());
152
+ return ((0, jsx_runtime_1.jsx)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _c === void 0 ? void 0 : _c.url }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: time })] })), agentMessage] })] })) })));
153
+ }
154
+ exports.MessageItemWrapper = MessageItemWrapper;
155
+ function MessageUserName({ children }) {
156
+ return ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", noWrap: true, sx: {
157
+ fontSize: 14,
158
+ lineHeight: '24px',
159
+ fontWeight: 500,
160
+ display: 'flex',
161
+ alignItems: 'center',
162
+ gap: 1,
163
+ }, children: children }));
164
+ }
165
+ function MessageTime({ time }) {
166
+ const t = (0, react_1.useMemo)(() => {
167
+ const date = (0, dayjs_1.default)(time);
168
+ if (!date.isValid())
169
+ return undefined;
170
+ return date.isSame((0, dayjs_1.default)(), 'date') ? date.format('HH:mm') : date.format('YYYY-MM-DD HH:mm');
171
+ }, [time]);
172
+ if (!t)
173
+ return null;
174
+ return ((0, jsx_runtime_1.jsx)(material_1.Typography, { sx: {
175
+ fontSize: 12,
176
+ lineHeight: '24px',
177
+ color: 'text.secondary',
178
+ }, children: t }, "user-time"));
179
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const CurrentMessage_1 = require("../../contexts/CurrentMessage");
8
+ const MessageItemView_1 = __importDefault(require("./MessageItemView"));
9
+ function ChatOutput() {
10
+ const { message } = (0, CurrentMessage_1.useCurrentMessage)();
11
+ return (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { message: message });
12
+ }
13
+ exports.default = ChatOutput;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const jsx_runtime_1 = require("react/jsx-runtime");
30
+ const types_1 = require("@blocklet/ai-runtime/types");
31
+ const lab_1 = require("@mui/lab");
32
+ const material_1 = require("@mui/material");
33
+ const react_1 = require("react");
34
+ const react_wrap_balancer_1 = __importStar(require("react-wrap-balancer"));
35
+ const CustomComponentRenderer_1 = __importDefault(require("../../../../../../../components/CustomComponentRenderer"));
36
+ const locale_1 = require("../../../../../../locale");
37
+ const LoadingButton_1 = __importDefault(require("../../../LoadingButton"));
38
+ const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
39
+ const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
40
+ const runtime_1 = require("../../state/runtime");
41
+ const map_right_1 = __importDefault(require("../../utils/map-right"));
42
+ function PhotoGallery({ resultTitle, background, primaryColor, }) {
43
+ var _a;
44
+ const { appearancePage, agent } = (0, runtime_1.useRuntimeState)();
45
+ const children = (0, react_1.useMemo)(() => {
46
+ var _a, _b;
47
+ return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue;
48
+ }, [agent]);
49
+ const inheritedTheme = (0, material_1.useTheme)();
50
+ const theme = (0, react_1.useMemo)(() => {
51
+ let { primary } = inheritedTheme.palette;
52
+ try {
53
+ if (primaryColor) {
54
+ primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
55
+ }
56
+ }
57
+ catch (error) {
58
+ console.error('augment primary color error', { error });
59
+ }
60
+ return (0, material_1.createTheme)(inheritedTheme, {
61
+ palette: { primary },
62
+ shape: {
63
+ borderRadius: 8,
64
+ },
65
+ });
66
+ }, [inheritedTheme, primaryColor]);
67
+ return ((0, jsx_runtime_1.jsx)(material_1.ThemeProvider, { theme: theme, children: (0, jsx_runtime_1.jsxs)(Root, { className: "photo-wall-root", sx: { backgroundImage: `url(${background})` }, children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { className: "photo-wall-header", children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.Provider, { children: [(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) && ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", fontSize: 48, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: appearancePage.name }) })), (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.description) && ((0, jsx_runtime_1.jsx)(material_1.Typography, { fontSize: 20, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: appearancePage.description }) }))] }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { className: "photo-wall-input", children: (_a = children === null || children === void 0 ? void 0 : children.agents) === null || _a === void 0 ? void 0 : _a.map((i) => ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: i.id, children: (0, jsx_runtime_1.jsx)(AgentInputRender, {}) }, i.id))) }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "photo-wall-output", gap: 2, children: [resultTitle && ((0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", fontSize: 48, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: resultTitle }) })), (0, jsx_runtime_1.jsx)(OutputView, {})] })] }) }));
68
+ }
69
+ exports.default = PhotoGallery;
70
+ const Root = (0, material_1.styled)(material_1.Stack)(({ theme }) => theme.unstable_sx({
71
+ gap: { xs: 3, sm: 4, md: 5 },
72
+ width: '100%',
73
+ backgroundSize: '100% auto',
74
+ backgroundRepeat: 'no-repeat',
75
+ backgroundPosition: 'top',
76
+ mt: 4,
77
+ '.photo-wall-header': {
78
+ maxWidth: 'md',
79
+ mx: 'auto',
80
+ width: '100%',
81
+ px: { xs: 2, sm: 3 },
82
+ gap: { xs: 2, sm: 3 },
83
+ },
84
+ '.photo-wall-input': {
85
+ maxWidth: 'md',
86
+ mx: 'auto',
87
+ width: '100%',
88
+ px: { xs: 2, sm: 3 },
89
+ },
90
+ '.photo-wall-output': {
91
+ width: '100%',
92
+ alignItems: 'center',
93
+ px: { xs: 2, sm: 3 },
94
+ '.photo-wall-item': {
95
+ borderRadius: 1,
96
+ img: {
97
+ borderRadius: 1,
98
+ },
99
+ },
100
+ },
101
+ }));
102
+ function AgentInputRender() {
103
+ var _a, _b;
104
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
105
+ const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue;
106
+ if (!(input === null || input === void 0 ? void 0 : input.componentId))
107
+ return null;
108
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: input.componentId, properties: input.componentProps }) }));
109
+ }
110
+ function NoOutputs() {
111
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, { mt: 10, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
112
+ }
113
+ function OutputView() {
114
+ var _a, _b, _c, _d, _e;
115
+ const { t } = (0, locale_1.useLocaleContext)();
116
+ const { sessionState } = (0, runtime_1.useRuntimeState)();
117
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [sessionState.loaded && !((_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.length) && (0, jsx_runtime_1.jsx)(NoOutputs, {}), (0, jsx_runtime_1.jsxs)(lab_1.Masonry, { columns: { xs: 2, sm: 3, md: 4, lg: 5 }, spacing: 1, sequential: true, sx: { width: '100%', overflow: 'hidden' }, children: [sessionState.running && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { className: "photo-wall-item", variant: "rectangular", sx: {
118
+ // FIXME: default using history height
119
+ height: (_c = (_b = document.getElementsByClassName('photo-wall-item')[0]) === null || _b === void 0 ? void 0 : _b.clientHeight) !== null && _c !== void 0 ? _c : 200,
120
+ } })), (0, map_right_1.default)((_d = sessionState.messages) !== null && _d !== void 0 ? _d : [], (message) => ((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_1.Suspense, { children: (0, jsx_runtime_1.jsx)(OutputItemView, {}) }) }) }, message.taskId)))] }), (0, jsx_runtime_1.jsx)(material_1.Box, { my: 4, children: !!((_e = sessionState.messages) === null || _e === void 0 ? void 0 : _e.length) && !sessionState.noMoreMessage && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { variant: "outlined", onClick: sessionState.loadMoreMessages, children: t('loadMore') })) })] }));
121
+ }
122
+ function OutputItemView() {
123
+ var _a, _b;
124
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
125
+ const input = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue;
126
+ if (!(input === null || input === void 0 ? void 0 : input.componentId))
127
+ return null;
128
+ return (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: input.componentId, properties: input.componentProps });
129
+ }
@@ -0,0 +1,117 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const jsx_runtime_1 = require("react/jsx-runtime");
15
+ const types_1 = require("@blocklet/ai-runtime/types");
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 ActionButton_1 = require("../../../ActionButton");
21
+ const CurrentMessage_1 = require("../../contexts/CurrentMessage");
22
+ const getLineClamp = (line) => ({
23
+ display: '-webkit-box',
24
+ WebkitLineClamp: line,
25
+ WebkitBoxOrient: 'vertical',
26
+ overflow: 'hidden',
27
+ overflowWrap: 'break-word',
28
+ textOverflow: 'ellipsis',
29
+ whiteSpace: 'wrap',
30
+ });
31
+ function PhotoGalleryItem() {
32
+ var _a, _b;
33
+ const { message } = (0, CurrentMessage_1.useCurrentMessage)();
34
+ const [openDialog, setOpenDialog] = (0, react_2.useState)(false);
35
+ const objects = (_b = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : [];
36
+ const images = objects.flatMap((i) => { var _a; return (_a = i.data[types_1.RuntimeOutputVariable.images]) !== null && _a !== void 0 ? _a : []; });
37
+ return images.map(({ url }, index) => {
38
+ var _a;
39
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { className: "photo-wall-item", sx: {
40
+ position: 'relative',
41
+ overflow: 'hidden',
42
+ cursor: 'pointer',
43
+ '&:hover': {
44
+ '.photo-wall-item-alt': {
45
+ opacity: 1,
46
+ },
47
+ },
48
+ }, onClick: () => setOpenDialog(true), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: url, alt: "", width: "100%", height: "100%",
49
+ // 首屏 image 不能用 lazy,会闪烁乱序
50
+ loading: index < 12 ? 'eager' : 'lazy' }), (0, jsx_runtime_1.jsx)(material_1.Box, { className: "photo-wall-item-alt", sx: {
51
+ position: 'absolute',
52
+ top: 0,
53
+ bottom: 0,
54
+ left: 0,
55
+ right: 0,
56
+ width: '100%',
57
+ height: '100%',
58
+ px: 1.5,
59
+ py: 1,
60
+ display: 'flex',
61
+ alignItems: 'flex-end',
62
+ fontWeight: 500,
63
+ fontSize: 13,
64
+ color: 'white',
65
+ background: 'linear-gradient(to bottom, rgba(2, 7, 19, 0) 0%, rgba(2, 7, 19, 0.8) 100%)',
66
+ opacity: 0,
67
+ transition: 'opacity 0.3s',
68
+ }, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: Object.assign({ lineHeight: 1.5 }, getLineClamp(3)), children: (_a = message.parameters) === null || _a === void 0 ? void 0 : _a.question }) }), openDialog && ((0, jsx_runtime_1.jsx)(PromptDialog, { open: true, url: url, onClose: (e) => {
69
+ e.stopPropagation();
70
+ e.preventDefault();
71
+ setOpenDialog(false);
72
+ } }))] }, url));
73
+ });
74
+ }
75
+ exports.default = PhotoGalleryItem;
76
+ function PromptDialog(_a) {
77
+ var { url } = _a, props = __rest(_a, ["url"]);
78
+ const { message } = (0, CurrentMessage_1.useCurrentMessage)();
79
+ const { parameters } = message;
80
+ const theme = (0, material_1.useTheme)();
81
+ const { t } = (0, locale_1.useLocaleContext)();
82
+ return ((0, jsx_runtime_1.jsxs)(material_1.Dialog, Object.assign({ fullWidth: true, maxWidth: false, scroll: "paper", slotProps: {
83
+ backdrop: {
84
+ sx: {
85
+ bgcolor: 'rgba(255, 255, 255, 0.4)',
86
+ backdropFilter: 'blur(12px)',
87
+ },
88
+ },
89
+ } }, props, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { position: 'absolute', right: 0, top: 0, p: 0.5 }, children: (0, jsx_runtime_1.jsx)(material_1.Button, { onClick: (e) => { var _a; return (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props, e, 'backdropClick'); }, variant: "contained", disableElevation: true, sx: {
90
+ bgcolor: (theme) => (0, material_1.alpha)(theme.palette.primary.light, 0.2),
91
+ minWidth: 32,
92
+ minHeight: 32,
93
+ p: 0,
94
+ fontSize: 22,
95
+ color: 'primary.main',
96
+ ':hover': {
97
+ bgcolor: (theme) => (0, material_1.alpha)(theme.palette.primary.light, 0.3),
98
+ },
99
+ }, children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:x" }) }) }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 4, sx: { flexDirection: { md: 'row' } }, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flex: 3, width: { xs: '100%', md: 0 }, gap: 1 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h5", sx: { fontSize: 24, fontWeight: 700, color: 'primary.main' }, children: t('photoWall.dialog.title') }), (0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: url, alt: "", loading: "lazy", sx: {
100
+ display: 'block',
101
+ width: '100%',
102
+ borderRadius: 1,
103
+ } })] }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flex: 2, width: { xs: '100%', md: 0 }, gap: 1 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h5", sx: { fontSize: 24, fontWeight: 700, color: 'primary.main' }, children: t('photoWall.dialog.prompt') }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
104
+ p: 2,
105
+ borderRadius: 1,
106
+ background: (theme) => `linear-gradient(to top, ${(0, material_1.alpha)(theme.palette.primary.light, 0.5)}, ${(0, material_1.alpha)(theme.palette.primary.light, 0.1)})`,
107
+ }, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
108
+ backgroundColor: 'rgba(255,255,255,0.2)',
109
+ borderRadius: 1,
110
+ p: 1,
111
+ fontSize: 16,
112
+ }, children: parameters === null || parameters === void 0 ? void 0 : parameters.question }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { autoReset: true, size: "small", variant: "contained", placement: "right", tip: t('copyToClipboard'), title: t('copy'), titleSucceed: t('copied'), icon: "tabler:copy", iconSucceed: "tabler:copy-check-filled", onClick: () => {
113
+ window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
114
+ }, sx: {
115
+ borderRadius: theme.shape.borderRadius,
116
+ } }) })] })] }) })] })));
117
+ }