@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
@@ -1,41 +1,68 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
13
  import ImagePreview from '@blocklet/ai-kit/components/image-preview';
3
- import { Box, Skeleton, Stack, Tooltip, Typography, useMediaQuery, useTheme } from '@mui/material';
14
+ import { cx } from '@emotion/css';
15
+ import { Box, Skeleton, Stack, Tooltip, Typography, styled, useMediaQuery, useTheme } from '@mui/material';
4
16
  import dayjs from 'dayjs';
5
- import React, { useMemo } from 'react';
17
+ import React, { useMemo, useState } from 'react';
6
18
  import { Avatar } from '../../../../arcblock/ux';
7
19
  import { useSessionContext } from '../../../../session';
20
+ import { useAssistantState } from '../../state/assistant';
8
21
  import { MessageMetadataRenderer } from '../common';
9
22
  import MarkdownRenderer from '../MarkdownRenderer';
10
23
  import MessageActions from './MessageActions';
11
24
  import MessageErrorView from './MessageErrorView';
12
- export default function MessageItemView({ assistantId, assistant, message, hideAvatar, }) {
13
- var _a, _b;
14
- const showUserMessage = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) !== 'form' && !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
15
- const commonMessageSx = {
16
- position: 'relative',
17
- borderRadius: 1,
18
- py: 1,
19
- px: 2,
20
- mt: 0.5,
21
- // without logo width
22
- maxWidth: 'calc(100% - 40px)',
23
- };
24
- return (_jsxs(Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden",
25
- // @ts-ignore
26
- sx: {
27
- '.message-question': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
28
- ? {
29
- borderTopRightRadius: '2px',
30
- }
31
- : {})), { borderTopRightRadius: !hideAvatar && '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
32
- '.message-response': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
33
- ? {
34
- borderTopLeftRadius: '2px',
35
- }
36
- : {})), { backgroundColor: 'rgba(229, 231, 235, 1)' }),
37
- }, children: [showUserMessage && _jsx(UserMessage, { message: message }), _jsx(AgentMessage, { assistantId: assistantId, assistant: assistant, message: message, hideAvatar: hideAvatar })] }));
25
+ export default function MessageItemView(_a) {
26
+ var _b, _c;
27
+ var { page, message, hideAvatar } = _a, props = __rest(_a, ["page", "message", "hideAvatar"]);
28
+ const [assistant] = useAssistantState(page);
29
+ const showUserMessage = ((_b = assistant.release) === null || _b === void 0 ? void 0 : _b.template) !== 'form' && !!((_c = message.parameters) === null || _c === void 0 ? void 0 : _c.question);
30
+ return (_jsxs(MessageItemContainer, Object.assign({}, props, { className: cx('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: [showUserMessage && _jsx(UserMessage, { message: message }), _jsx(AgentMessage, { page: page, message: message, hideAvatar: hideAvatar })] })));
38
31
  }
32
+ const MessageItemContainer = styled(Stack) `
33
+ gap: 2.5;
34
+ overflow: hidden;
35
+
36
+ .message-question {
37
+ position: relative;
38
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
39
+ border-top-right-radius: 2px;
40
+ padding: ${({ theme }) => theme.spacing(1, 2)};
41
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
42
+ // without logo width
43
+ max-width: calc(100% - 40px);
44
+ background-color: rgba(239, 246, 255, 1);
45
+
46
+ &.hide-avatar {
47
+ border-top-right-radius: ${({ theme }) => theme.shape.borderRadius}px;
48
+ }
49
+ }
50
+
51
+ .message-response {
52
+ position: relative;
53
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
54
+ border-top-left-radius: 2px;
55
+ padding: ${({ theme }) => theme.spacing(1, 2)};
56
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
57
+ // without logo width
58
+ max-width: calc(100% - 40px);
59
+ background-color: rgba(229, 231, 235, 1);
60
+
61
+ &.hide-avatar {
62
+ border-top-left-radius: ${({ theme }) => theme.shape.borderRadius}px;
63
+ }
64
+ }
65
+ `;
39
66
  function UserMessage({ message }) {
40
67
  var _a, _b, _c, _d;
41
68
  const { session: authSession } = useSessionContext();
@@ -50,14 +77,15 @@ function UserMessage({ message }) {
50
77
  alignItems: 'flex-end',
51
78
  }, children: [_jsxs(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, _jsx(MessageTime, { time: message.createdAt })] }), _jsx(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 })] })] }));
52
79
  }
53
- function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
80
+ function AgentMessage({ page, message, hideAvatar }) {
54
81
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
82
+ const [assistant] = useAssistantState(page);
55
83
  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));
56
84
  const isMessageLoading = (message.loading || !message.result) && !message.error;
57
85
  const theme = useTheme();
58
86
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
59
87
  const isFormTemplate = ((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.template) === 'form';
60
- return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, variant: "circle", shape: "circle", src: (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.logo }) })), _jsxs(Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_g = assistant.release) === null || _g === void 0 ? void 0 : _g.title) || assistant.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, Object.assign({}, (isFormTemplate && {
88
+ return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, variant: "circle", shape: "circle", src: (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.logo }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_g = assistant.release) === null || _g === void 0 ? void 0 : _g.title) || assistant.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, Object.assign({}, (isFormTemplate && {
61
89
  open: true,
62
90
  }), { placement: "right-start", PopperProps: {
63
91
  className: 'white-tooltip',
@@ -83,7 +111,13 @@ function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
83
111
  }), ((_l = message.result) === null || _l === void 0 ? void 0 : _l.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) }))) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
84
112
  // only response with loading
85
113
  className: "message-response" }))), !!((_o = (_m = message.result) === null || _m === void 0 ? void 0 : _m.objects) === null || _o === void 0 ? void 0 : _o.length) &&
86
- ((_q = (_p = message.result) === null || _p === void 0 ? void 0 : _p.objects) === null || _q === void 0 ? void 0 : _q.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && _jsx(MessageErrorView, { assistantId: assistantId, assistant: assistant, error: message.error })] })] })] }));
114
+ ((_q = (_p = message.result) === null || _p === void 0 ? void 0 : _p.objects) === null || _q === void 0 ? void 0 : _q.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && _jsx(MessageErrorView, { page: page, error: message.error })] })] })] }));
115
+ }
116
+ export function MessageItemWrapper(_a) {
117
+ var _b, _c, _d;
118
+ var { hideAvatar, assistant, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "assistant", "agentMessage"]);
119
+ const [time] = useState(() => new Date().toISOString());
120
+ return (_jsx(MessageItemContainer, Object.assign({}, props, { className: cx('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.title) || assistant.name, _jsx(MessageTime, { time: time })] })), agentMessage] })] })) })));
87
121
  }
88
122
  function MessageUserName({ children }) {
89
123
  return (_jsx(Typography, { component: "div", noWrap: true, sx: {
@@ -16,15 +16,16 @@ import { useAssistantState } from '../../state/assistant';
16
16
  import { useSessionState } from '../../state/session';
17
17
  import MessageItemView from './MessageItemView';
18
18
  export default function MessageListView(_a) {
19
- var { assistantId, sessionId } = _a, props = __rest(_a, ["assistantId", "sessionId"]);
20
- const [assistant] = useAssistantState({ assistantId });
21
- const [session, { messages = [] }] = useSessionState({ sessionId, required: true });
19
+ var { page } = _a, props = __rest(_a, ["page"]);
20
+ const [assistant] = useAssistantState(page);
21
+ const [session, { messages = [] }] = useSessionState({ sessionId: page.sessionId, required: true });
22
22
  const opener = useMemo(() => {
23
23
  var _a;
24
24
  const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
25
25
  if (openerMessage) {
26
26
  return {
27
27
  taskId: '',
28
+ assistantId: assistant.id,
28
29
  sessionId: session.id,
29
30
  createdAt: session.createdAt,
30
31
  updatedAt: session.createdAt,
@@ -35,7 +36,7 @@ export default function MessageListView(_a) {
35
36
  }, [assistant.release]);
36
37
  if (!session)
37
38
  return null;
38
- return (_jsxs(Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && _jsx(MessageItemView, { assistantId: assistantId, assistant: assistant, message: opener }), messages.map((message) => {
39
- return (_jsx(MessageItemView, { assistantId: assistantId, assistant: assistant, message: message }, message.taskId));
39
+ return (_jsxs(Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && _jsx(MessageItemView, { page: page, message: opener }), messages.map((message) => {
40
+ return _jsx(MessageItemView, { page: page, message: message }, message.taskId);
40
41
  })] })));
41
42
  }
@@ -0,0 +1,37 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { FormControlLabel, Radio, RadioGroup, alpha } from '@mui/material';
14
+ import { forwardRef } from 'react';
15
+ const RadioField = forwardRef((_a, ref) => {
16
+ var _b;
17
+ var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
18
+ return (_jsx(RadioGroup, Object.assign({ ref: ref, row: true, onChange: (e) => onChange(e.target.value) }, props, { children: (_b = parameter === null || parameter === void 0 ? void 0 : parameter.options) === null || _b === void 0 ? void 0 : _b.map((option) => {
19
+ const checked = option.value === props.value;
20
+ return (_jsx(FormControlLabel, { label: option.label, disabled: readOnly, value: option.value, checked: checked, control: _jsx(Radio, {}), sx: {
21
+ transition: 'all 0.3s linear',
22
+ ml: 0,
23
+ mr: 1,
24
+ my: 0.5,
25
+ py: 0.5,
26
+ px: 2.5,
27
+ border: 2,
28
+ borderColor: (theme) => (checked ? theme.palette.primary.main : alpha(theme.palette.primary.main, 0.3)),
29
+ borderRadius: 8,
30
+ '.MuiRadio-root': {
31
+ // hidden radio button
32
+ display: 'none',
33
+ },
34
+ } }, option.id));
35
+ }) })));
36
+ });
37
+ export default RadioField;
@@ -15,7 +15,7 @@ import { forwardRef } from 'react';
15
15
  const SelectField = forwardRef((_a, ref) => {
16
16
  var _b, _c, _d, _e;
17
17
  var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
18
- return (_jsx(TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), SelectProps: Object.assign(Object.assign({}, props.SelectProps), { MenuProps: Object.assign(Object.assign({}, (_b = props.SelectProps) === null || _b === void 0 ? void 0 : _b.MenuProps), { sx: Object.assign(Object.assign({}, (_d = (_c = props.SelectProps) === null || _c === void 0 ? void 0 : _c.MenuProps) === null || _d === void 0 ? void 0 : _d.sx), { '.MuiMenuItem-root': {
18
+ return (_jsx(TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), SelectProps: Object.assign(Object.assign({}, props.SelectProps), { MenuProps: Object.assign(Object.assign({ disableScrollLock: true }, (_b = props.SelectProps) === null || _b === void 0 ? void 0 : _b.MenuProps), { sx: Object.assign(Object.assign({}, (_d = (_c = props.SelectProps) === null || _c === void 0 ? void 0 : _c.MenuProps) === null || _d === void 0 ? void 0 : _d.sx), { '.MuiMenuItem-root': {
19
19
  whiteSpace: 'pre-wrap',
20
20
  } }) }) }), children: (_e = parameter === null || parameter === void 0 ? void 0 : parameter.options) === null || _e === void 0 ? void 0 : _e.map((option) => (_jsx(MenuItem, { value: option.value, children: option.label }, option.id))) })));
21
21
  });
@@ -12,9 +12,11 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import LanguageField from './LanguageField';
14
14
  import NumberField from './NumberField';
15
+ import RadioField from './RadioField';
15
16
  import SelectField from './SelectField';
16
17
  import StringField from './StringField';
17
18
  export default function ParameterField(_a) {
19
+ var _b;
18
20
  var { parameter } = _a, props = __rest(_a, ["parameter"]);
19
21
  if (parameter.type === 'source')
20
22
  return null;
@@ -24,7 +26,9 @@ export default function ParameterField(_a) {
24
26
  const Field = {
25
27
  number: NumberField,
26
28
  string: StringField,
27
- select: SelectField,
29
+ select: parameter.type === 'select' && ((_b = parameter.options) === null || _b === void 0 ? void 0 : _b.length) && parameter.options.length <= 8
30
+ ? RadioField
31
+ : SelectField,
28
32
  language: LanguageField,
29
33
  }[parameter.type || 'string'] || StringField;
30
34
  return (_jsx(Field, Object.assign({ label: parameter === null || parameter === void 0 ? void 0 : parameter.label, helperText: parameter === null || parameter === void 0 ? void 0 : parameter.helper, placeholder: parameter === null || parameter === void 0 ? void 0 : parameter.placeholder }, { parameter }, { size: "small" }, props)));
@@ -0,0 +1,146 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { cx } from '@emotion/css';
12
+ import { Box, FormLabel, InputAdornment, Stack, ThemeProvider, createTheme, formLabelClasses, outlinedInputClasses, styled, useTheme, } from '@mui/material';
13
+ import isEmpty from 'lodash/isEmpty';
14
+ import omit from 'lodash/omit';
15
+ import { useEffect, useMemo, useState } from 'react';
16
+ import { Controller, useForm } from 'react-hook-form';
17
+ import { useLocaleContext } from '../../../../../../locale';
18
+ import LoadingButton from '../../../LoadingButton';
19
+ import ParameterField from '../../../parameters';
20
+ import { useCurrentAgent } from '../../contexts/CurrentAgent';
21
+ import { useRuntimeState } from '../../state/runtime';
22
+ export const SUPPORTED_PARAMETER_TYPES = ['string', 'number', 'select', 'language'];
23
+ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
24
+ const { t } = useLocaleContext();
25
+ const { aid, agent } = useCurrentAgent();
26
+ const { sessionState, execute } = useRuntimeState();
27
+ const parameters = useMemo(() => {
28
+ var _a;
29
+ return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => !!i.key && SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string')).map((i) => {
30
+ var _a;
31
+ return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
32
+ });
33
+ }, [agent.parameters]);
34
+ const defaultForm = useInitialFormValues();
35
+ const theme = useFormTheme();
36
+ const form = useForm({ defaultValues: defaultForm });
37
+ useEffect(() => {
38
+ if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
39
+ form.reset(chatMode ? omit(defaultForm, 'question') : defaultForm);
40
+ }
41
+ }, [defaultForm, autoFillLastForm, form]);
42
+ const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
43
+ yield execute({
44
+ aid,
45
+ parameters,
46
+ onResponseStart: () => {
47
+ if (chatMode)
48
+ form.resetField('question', { defaultValue: '' });
49
+ },
50
+ });
51
+ });
52
+ return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Form, { 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) => {
53
+ const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
54
+ return (_jsx(Box, { children: _jsx(Controller, { control: form.control, name: key, rules: {
55
+ required,
56
+ min: parameter.type === 'number' && typeof parameter.min === 'number'
57
+ ? { value: parameter.min, message: '' }
58
+ : undefined,
59
+ max: parameter.type === 'number' && typeof parameter.max === 'number'
60
+ ? { value: parameter.max, message: '' }
61
+ : undefined,
62
+ minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
63
+ ? { value: parameter.minLength, message: '' }
64
+ : undefined,
65
+ maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
66
+ ? { value: parameter.maxLength, message: '' }
67
+ : undefined,
68
+ }, render: ({ field, fieldState }) => {
69
+ var _a;
70
+ return (_jsxs(Stack, { className: "form-item", children: [parameter.label && _jsx(FormLabel, { children: parameter.label }), _jsx(ParameterField, { 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
71
+ ? {
72
+ endAdornment: (_jsx(InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: _jsx(LoadingButton, { type: "submit", variant: "contained", loading: sessionState.running, sx: { borderRadius: 100 }, children: submitText }) })),
73
+ }
74
+ : undefined })] }));
75
+ } }) }, parameter.id));
76
+ }), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading: sessionState.running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
77
+ }
78
+ function useInitialFormValues() {
79
+ var _a;
80
+ const [lastMessage, setLastMessage] = useState();
81
+ const { agent } = useCurrentAgent();
82
+ const { sessionState } = useRuntimeState();
83
+ useEffect(() => {
84
+ var _a;
85
+ if (!lastMessage) {
86
+ setLastMessage((_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]);
87
+ }
88
+ }, [(_a = sessionState.messages) === null || _a === void 0 ? void 0 : _a.length]);
89
+ return useMemo(() => {
90
+ var _a, _b;
91
+ if (lastMessage) {
92
+ const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
93
+ if (!isEmpty(lastParameters))
94
+ return lastParameters;
95
+ }
96
+ 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 : []);
97
+ }, [lastMessage, agent]);
98
+ }
99
+ function useFormTheme() {
100
+ const theme = useTheme();
101
+ return useMemo(() => {
102
+ const themeOptions = {
103
+ shape: {
104
+ borderRadius: 8,
105
+ },
106
+ components: {
107
+ MuiTextField: {
108
+ styleOverrides: {
109
+ root: ({ theme }) => theme.unstable_sx({
110
+ [`.${outlinedInputClasses.root}`]: {
111
+ [`.${outlinedInputClasses.notchedOutline}`]: {
112
+ borderWidth: 2,
113
+ borderColor: 'primary.light',
114
+ },
115
+ ':hover': {
116
+ [`.${outlinedInputClasses.notchedOutline}`]: {
117
+ borderColor: 'primary.main',
118
+ },
119
+ },
120
+ },
121
+ }),
122
+ },
123
+ },
124
+ },
125
+ };
126
+ return createTheme(theme, themeOptions);
127
+ }, [theme]);
128
+ }
129
+ const Form = styled(Stack)(({ theme }) => theme.unstable_sx({
130
+ gap: 2,
131
+ '.form-item': {
132
+ gap: 0.5,
133
+ [`.${formLabelClasses.root}`]: {
134
+ fontWeight: 500,
135
+ color: 'text.primary',
136
+ },
137
+ },
138
+ '&.label-position-start': {
139
+ '.form-item': {
140
+ display: 'flex',
141
+ flexDirection: 'row',
142
+ alignItems: 'center',
143
+ gap: 1,
144
+ },
145
+ },
146
+ }));
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Alert, Box } from '@mui/material';
3
+ import { useLocaleContext } from '../../../../../../locale';
4
+ import MarkdownRenderer from '../../../MarkdownRenderer';
5
+ export default function MessageErrorView({ error }) {
6
+ const { t } = useLocaleContext();
7
+ if (!error)
8
+ return null;
9
+ if (error.status === 401) {
10
+ return (_jsx(Box, { className: "ai-chat-message-error", children: _jsx(Box, { className: "message-response", children: _jsx(MarkdownRenderer, { children: t('requireLogin') }) }) }));
11
+ }
12
+ return (_jsx(Alert, { className: "ai-chat-message-error", severity: "error", sx: { mr: 5 }, children: error.message }));
13
+ }
@@ -0,0 +1,149 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import ImagePreview from '@blocklet/ai-kit/components/image-preview';
14
+ import { cx } from '@emotion/css';
15
+ import { Box, Skeleton, Stack, Tooltip, Typography, styled, useMediaQuery, useTheme } from '@mui/material';
16
+ import dayjs from 'dayjs';
17
+ import React, { memo, useMemo, useState } from 'react';
18
+ import { Avatar } from '../../../../../../arcblock/ux';
19
+ import { useSessionContext } from '../../../../../../session';
20
+ import { MessageMetadataRenderer } from '../../../common';
21
+ import MarkdownRenderer from '../../../MarkdownRenderer';
22
+ import MessageActions from '../../../message/MessageActions';
23
+ import { useRuntimeState } from '../../state/runtime';
24
+ import MessageErrorView from './MessageErrorView';
25
+ const MessageItemView = memo((_a) => {
26
+ var _b;
27
+ var { message, hideAvatar } = _a, props = __rest(_a, ["message", "hideAvatar"]);
28
+ const showUserMessage = !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
29
+ return (_jsxs(MessageItemContainer, Object.assign({}, props, { className: cx('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: [showUserMessage && _jsx(UserMessage, { message: message }), _jsx(AgentMessage, { message: message, hideAvatar: hideAvatar })] })));
30
+ });
31
+ export default MessageItemView;
32
+ const MessageItemContainer = styled(Stack) `
33
+ gap: ${({ theme }) => theme.spacing(2.5)};
34
+ overflow: hidden;
35
+
36
+ .message-question {
37
+ position: relative;
38
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
39
+ border-top-right-radius: 2px;
40
+ padding: ${({ theme }) => theme.spacing(1, 2)};
41
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
42
+ // without logo width
43
+ max-width: calc(100% - 40px);
44
+ background-color: rgba(239, 246, 255, 1);
45
+
46
+ &.hide-avatar {
47
+ border-top-right-radius: ${({ theme }) => theme.shape.borderRadius}px;
48
+ }
49
+ }
50
+
51
+ .message-response {
52
+ position: relative;
53
+ border-radius: ${({ theme }) => theme.shape.borderRadius}px;
54
+ border-top-left-radius: 2px;
55
+ padding: ${({ theme }) => theme.spacing(1, 2)};
56
+ margin-top: ${({ theme }) => theme.spacing(0.5)};
57
+ // without logo width
58
+ max-width: calc(100% - 40px);
59
+ background-color: rgba(229, 231, 235, 1);
60
+
61
+ &.hide-avatar {
62
+ border-top-left-radius: ${({ theme }) => theme.shape.borderRadius}px;
63
+ }
64
+ }
65
+ `;
66
+ function UserMessage({ message }) {
67
+ var _a, _b, _c, _d;
68
+ const { session: authSession } = useSessionContext();
69
+ return (_jsxs(Stack, { className: "ai-chat-message-user", direction: "row", gap: 1.5, sx: {
70
+ display: 'flex',
71
+ flexDirection: 'row-reverse',
72
+ textAlign: 'right',
73
+ justifyContent: 'flex-end',
74
+ }, children: [_jsx(Box, { children: _jsx(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" }) }), _jsxs(Stack, { flex: 1, overflow: "hidden", sx: {
75
+ display: 'flex',
76
+ flexDirection: 'column',
77
+ alignItems: 'flex-end',
78
+ }, children: [_jsxs(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, _jsx(MessageTime, { time: message.createdAt })] }), _jsx(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 })] })] }));
79
+ }
80
+ function AgentMessage({ message, hideAvatar }) {
81
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
82
+ const { appearancePage } = useRuntimeState();
83
+ 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));
84
+ const isMessageLoading = (message.loading || !message.result) && !message.error;
85
+ const theme = useTheme();
86
+ const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
87
+ return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(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 }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, { placement: "right-start", slotProps: {
88
+ popper: {
89
+ modifiers: [
90
+ {
91
+ name: 'offset',
92
+ options: {
93
+ offset: [-3, isMobile ? (!hideAvatar ? -18 : -8) : -6],
94
+ },
95
+ },
96
+ ],
97
+ },
98
+ tooltip: {
99
+ sx: {
100
+ bgcolor: 'white',
101
+ boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
102
+ border: '1px solid rgba(229, 231, 235, 1)',
103
+ p: 0.5,
104
+ },
105
+ },
106
+ }, title: !isMessageLoading && ((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && _jsx(MessageActions, { content: message.result.content }), children: _jsxs(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) => {
107
+ var _a, _b, _c, _d, _e, _f, _g;
108
+ return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
109
+ !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
110
+ !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
111
+ message.result.messages.length - 1 === index
112
+ ? 'writing'
113
+ : '', 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) ? (_jsx(ImagePreview, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
114
+ }), ((_j = message.result) === null || _j === void 0 ? void 0 : _j.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) })) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
115
+ // only response with loading
116
+ className: "message-response" }))), (_l = (_k = message.result) === null || _k === void 0 ? void 0 : _k.objects) === null || _l === void 0 ? void 0 : _l.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId))), message.error && _jsx(MessageErrorView, { error: message.error })] })] })] }));
117
+ }
118
+ export function MessageItemWrapper(_a) {
119
+ var _b, _c;
120
+ var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
121
+ const { appearancePage } = useRuntimeState();
122
+ const [time] = useState(() => new Date().toISOString());
123
+ return (_jsx(MessageItemContainer, Object.assign({}, props, { className: cx('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(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 }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, _jsx(MessageTime, { time: time })] })), agentMessage] })] })) })));
124
+ }
125
+ function MessageUserName({ children }) {
126
+ return (_jsx(Typography, { component: "div", noWrap: true, sx: {
127
+ fontSize: 14,
128
+ lineHeight: '24px',
129
+ fontWeight: 500,
130
+ display: 'flex',
131
+ alignItems: 'center',
132
+ gap: 1,
133
+ }, children: children }));
134
+ }
135
+ function MessageTime({ time }) {
136
+ const t = useMemo(() => {
137
+ const date = dayjs(time);
138
+ if (!date.isValid())
139
+ return undefined;
140
+ return date.isSame(dayjs(), 'date') ? date.format('HH:mm') : date.format('YYYY-MM-DD HH:mm');
141
+ }, [time]);
142
+ if (!t)
143
+ return null;
144
+ return (_jsx(Typography, { sx: {
145
+ fontSize: 12,
146
+ lineHeight: '24px',
147
+ color: 'text.secondary',
148
+ }, children: t }, "user-time"));
149
+ }
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCurrentMessage } from '../../contexts/CurrentMessage';
3
+ import MessageItemView from './MessageItemView';
4
+ export default function ChatOutput() {
5
+ const { message } = useCurrentMessage();
6
+ return _jsx(MessageItemView, { message: message });
7
+ }