@blocklet/pages-kit 0.2.359 → 0.2.360
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/builtin/async/ai-runtime/api/asset.js +23 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +5 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +4 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +3 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +4 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +9 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/api/asset.js +20 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +5 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +4 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +3 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +4 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +9 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/api/asset.d.ts +13 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { joinURL, withQuery } from 'ufo';
|
|
2
|
+
import { getAIRuntimeApiPrefix } from './request';
|
|
3
|
+
const presets = {
|
|
4
|
+
avatar: { w: 80 },
|
|
5
|
+
};
|
|
6
|
+
export function getAssetUrl({ blockletDid, aid, filename, w, preset, }) {
|
|
7
|
+
var _a;
|
|
8
|
+
const url = filename && aid && !(filename === null || filename === void 0 ? void 0 : filename.startsWith('http'))
|
|
9
|
+
? withQuery(joinURL(getAIRuntimeApiPrefix(), '/api/agents', aid, 'assets', filename), {
|
|
10
|
+
blockletDid,
|
|
11
|
+
})
|
|
12
|
+
: filename;
|
|
13
|
+
if (!url)
|
|
14
|
+
return url;
|
|
15
|
+
const width = w !== null && w !== void 0 ? w : (_a = presets[preset]) === null || _a === void 0 ? void 0 : _a.w;
|
|
16
|
+
return withQuery(url, {
|
|
17
|
+
imageFilter: width ? 'resize' : undefined,
|
|
18
|
+
w: width,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -17,6 +17,7 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
17
17
|
import React, { memo, useMemo, useState } from 'react';
|
|
18
18
|
import { Avatar } from '../../../../arcblock/ux';
|
|
19
19
|
import { useSessionContext } from '../../../../session';
|
|
20
|
+
import { getAssetUrl } from '../../api/asset';
|
|
20
21
|
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
21
22
|
import ShareActions from '../../components/ShareActions';
|
|
22
23
|
import { useProfile } from '../../hooks/use-appearances';
|
|
@@ -83,13 +84,13 @@ function UserMessage({ message, hideAvatar }) {
|
|
|
83
84
|
}
|
|
84
85
|
function AgentMessage({ message, hideAvatar }) {
|
|
85
86
|
var _a, _b, _c, _d, _e, _f;
|
|
86
|
-
const { aid } = useRuntimeState();
|
|
87
|
+
const { blockletDid, aid } = useRuntimeState();
|
|
87
88
|
const profile = useProfile({ aid });
|
|
88
89
|
const showMainMessage = !!((_a = message.outputs) === null || _a === void 0 ? void 0 : _a.content);
|
|
89
90
|
const isMessageLoading = (message.loading || !message.outputs) && !message.error;
|
|
90
91
|
const theme = useTheme();
|
|
91
92
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
92
|
-
return (_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: profile.avatar }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [profile.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, { placement: "right-start", slotProps: {
|
|
93
|
+
return (_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: getAssetUrl({ blockletDid, aid, filename: profile.avatar, preset: 'avatar' }) }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [profile.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, { placement: "right-start", slotProps: {
|
|
93
94
|
popper: {
|
|
94
95
|
disablePortal: true,
|
|
95
96
|
modifiers: [
|
|
@@ -118,10 +119,10 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
118
119
|
export function MessageItemWrapper(_a) {
|
|
119
120
|
var _b;
|
|
120
121
|
var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
|
|
121
|
-
const { aid } = useRuntimeState();
|
|
122
|
+
const { blockletDid, aid } = useRuntimeState();
|
|
122
123
|
const profile = useProfile({ aid });
|
|
123
124
|
const [time] = useState(() => new Date().toISOString());
|
|
124
|
-
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: profile.avatar }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [profile.name, _jsx(MessageTime, { time: time })] })), agentMessage] })] })) })));
|
|
125
|
+
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: getAssetUrl({ blockletDid, aid, filename: profile.avatar, preset: 'avatar' }) }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [profile.name, _jsx(MessageTime, { time: time })] })), agentMessage] })] })) })));
|
|
125
126
|
}
|
|
126
127
|
function MessageUserName({ children }) {
|
|
127
128
|
return (_jsx(Typography, { component: "div", noWrap: true, sx: {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from '@mui/material';
|
|
3
|
+
import { getAssetUrl } from '../../api/asset';
|
|
3
4
|
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
5
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
4
6
|
export default function BackgroundImage() {
|
|
5
7
|
var _a, _b;
|
|
8
|
+
const { blockletDid, aid } = useRuntimeState();
|
|
6
9
|
const preferences = useComponentPreferences();
|
|
7
10
|
if (!((_a = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _a === void 0 ? void 0 : _a.url))
|
|
8
11
|
return null;
|
|
@@ -12,7 +15,7 @@ export default function BackgroundImage() {
|
|
|
12
15
|
top: 0,
|
|
13
16
|
right: 0,
|
|
14
17
|
bottom: 0,
|
|
15
|
-
backgroundImage: `url(${(_b = preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url}) !important`,
|
|
18
|
+
backgroundImage: `url(${getAssetUrl({ blockletDid, aid, filename: (_b = preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url })}) !important`,
|
|
16
19
|
backgroundRepeat: 'no-repeat',
|
|
17
20
|
backgroundSize: 'cover',
|
|
18
21
|
backgroundPosition: 'center',
|
|
@@ -14,6 +14,7 @@ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
|
14
14
|
import { Avatar, IconButton, Stack } from '@mui/material';
|
|
15
15
|
import { useMemo } from 'react';
|
|
16
16
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
17
|
+
import { getAssetUrl } from '../../api/asset';
|
|
17
18
|
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
18
19
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
19
20
|
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
@@ -29,11 +30,12 @@ export default function InputsView(_a) {
|
|
|
29
30
|
function AgentAvatar(_a) {
|
|
30
31
|
var _b;
|
|
31
32
|
var { selected } = _a, props = __rest(_a, ["selected"]);
|
|
33
|
+
const { blockletDid, aid } = useRuntimeState();
|
|
32
34
|
const { appearanceInput } = useAppearances();
|
|
33
35
|
const profile = useProfile();
|
|
34
36
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
35
37
|
return null;
|
|
36
|
-
return (_jsx(IconButton, Object.assign({}, props, { sx: Object.assign({ p: 0, outline: selected ? 3 : 0, outlineColor: 'primary.light' }, props.sx), children: _jsx(Avatar, { src: profile === null || profile === void 0 ? void 0 : profile.avatar, children: (_b = profile.name) === null || _b === void 0 ? void 0 : _b.slice(0, 1) }) })));
|
|
38
|
+
return (_jsx(IconButton, Object.assign({}, props, { sx: Object.assign({ p: 0, outline: selected ? 3 : 0, outlineColor: 'primary.light' }, props.sx), children: _jsx(Avatar, { src: getAssetUrl({ blockletDid, aid, filename: profile === null || profile === void 0 ? void 0 : profile.avatar, preset: 'avatar' }), children: (_b = profile.name) === null || _b === void 0 ? void 0 : _b.slice(0, 1) }) })));
|
|
37
39
|
}
|
|
38
40
|
function AgentInput() {
|
|
39
41
|
const { aid } = useCurrentAgent();
|
|
@@ -14,15 +14,18 @@ import { Box, Stack } from '@mui/material';
|
|
|
14
14
|
import { memo } from 'react';
|
|
15
15
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
16
16
|
import { useSessionContext } from '../../../../session';
|
|
17
|
+
import { getAssetUrl } from '../../api/asset';
|
|
17
18
|
import { AgentErrorView } from '../../components/AgentErrorBoundary';
|
|
18
19
|
import UserInfo from '../../components/UserInfo';
|
|
19
20
|
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
20
21
|
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
21
22
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
22
23
|
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
24
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
23
25
|
import UserMessageView from './UserMessageView';
|
|
24
26
|
const MessageView = memo(({ message }) => {
|
|
25
27
|
var _a, _b, _c, _d, _e, _f;
|
|
28
|
+
const { aid, blockletDid } = useRuntimeState();
|
|
26
29
|
const preferences = useComponentPreferences();
|
|
27
30
|
const hasBg = !!((_a = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _a === void 0 ? void 0 : _a.url);
|
|
28
31
|
const { session: authSession } = useSessionContext();
|
|
@@ -32,7 +35,7 @@ const MessageView = memo(({ message }) => {
|
|
|
32
35
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
33
36
|
return null;
|
|
34
37
|
const agentMessage = (_jsx(MessageBodyContainer, { messageRole: "assistant", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties, fallbackRender: AgentErrorView }, message.id) }));
|
|
35
|
-
return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [!hideUserInputs && (_jsx(Box, { children: _jsx(UserInfo, { name: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, did: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.did, avatar: (_e = authSession.user) === null || _e === void 0 ? void 0 : _e.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: _jsx(Stack, { sx: { alignItems: 'flex-end' }, children: _jsx(MessageBodyContainer, { messageRole: "user", children: _jsx(UserMessageView, {}) }) }) }) })), _jsx(Box, { children: !hideAgentAvatar ? (_jsx(UserInfo, { name: profile.name, did: (_f = globalThis.blocklet) === null || _f === void 0 ? void 0 : _f.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: agentMessage })) : (agentMessage) })] }) }) }));
|
|
38
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [!hideUserInputs && (_jsx(Box, { children: _jsx(UserInfo, { name: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, did: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.did, avatar: getAssetUrl({ filename: (_e = authSession.user) === null || _e === void 0 ? void 0 : _e.avatar, preset: 'avatar' }), time: message.createdAt, reverse: true, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: _jsx(Stack, { sx: { alignItems: 'flex-end' }, children: _jsx(MessageBodyContainer, { messageRole: "user", children: _jsx(UserMessageView, {}) }) }) }) })), _jsx(Box, { children: !hideAgentAvatar ? (_jsx(UserInfo, { name: profile.name, did: (_f = globalThis.blocklet) === null || _f === void 0 ? void 0 : _f.appId, avatar: getAssetUrl({ blockletDid, aid, filename: profile.avatar, preset: 'avatar' }), time: message.createdAt, alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: agentMessage })) : (agentMessage) })] }) }) }));
|
|
36
39
|
});
|
|
37
40
|
export default MessageView;
|
|
38
41
|
export function MessageBodyContainer(_a) {
|
package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js
CHANGED
|
@@ -2,14 +2,17 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
4
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
5
|
+
import { getAssetUrl } from '../../api/asset';
|
|
5
6
|
import UserInfo from '../../components/UserInfo';
|
|
6
7
|
import { DEFAULT_OUTPUT_COMPONENTS } from '../../constants';
|
|
7
8
|
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
8
9
|
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
9
10
|
import { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
|
|
11
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
10
12
|
import { MessageBodyContainer } from './MessageView';
|
|
11
13
|
const OpeningMessageView = memo(({ isMessagesEmpty }) => {
|
|
12
14
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
15
|
+
const { blockletDid, aid } = useRuntimeState();
|
|
13
16
|
const { hideAgentAvatar, backgroundImage } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
14
17
|
const hasBg = !!(backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url);
|
|
15
18
|
const openingMessage = useOpeningMessage();
|
|
@@ -27,6 +30,11 @@ const OpeningMessageView = memo(({ isMessagesEmpty }) => {
|
|
|
27
30
|
return null;
|
|
28
31
|
}
|
|
29
32
|
const children = (_jsxs(MessageBodyContainer, { children: [openingMessage && openingMessageOutput && openingMessageComponentId && (_jsx(CustomComponentRenderer, { instanceId: openingMessageOutput.id, componentId: openingMessageComponentId, properties: (_f = openingMessageOutput.appearance) === null || _f === void 0 ? void 0 : _f.componentProperties, props: { output: openingMessageOutput, outputValue: openingMessage.message } })), isMessagesEmpty && openingQuestionsComponentId && (_jsx(CustomComponentRenderer, { instanceId: agent.id, componentId: openingQuestionsComponentId, properties: (_g = openingQuestionsOutput === null || openingQuestionsOutput === void 0 ? void 0 : openingQuestionsOutput.appearance) === null || _g === void 0 ? void 0 : _g.componentProperties, props: { output: openingQuestionsOutput } }))] }));
|
|
30
|
-
return hideAgentAvatar ? (children) : (_jsx(UserInfo, { name: ((_h = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _h !== void 0 ? _h : profile).name, did: (_j = globalThis.blocklet) === null || _j === void 0 ? void 0 : _j.appId, avatar: (
|
|
33
|
+
return hideAgentAvatar ? (children) : (_jsx(UserInfo, { name: ((_h = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _h !== void 0 ? _h : profile).name, did: (_j = globalThis.blocklet) === null || _j === void 0 ? void 0 : _j.appId, avatar: getAssetUrl({
|
|
34
|
+
blockletDid,
|
|
35
|
+
aid,
|
|
36
|
+
filename: ((_k = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _k !== void 0 ? _k : profile).avatar,
|
|
37
|
+
preset: 'avatar',
|
|
38
|
+
}), alignItems: "flex-start", UserNameProps: { sx: { color: hasBg ? 'white' : undefined } }, children: children }));
|
|
31
39
|
});
|
|
32
40
|
export default OpeningMessageView;
|