@blocklet/pages-kit 0.2.358 → 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/contexts/CurrentAgent.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +16 -9
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +4 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -46
- 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/builtin/async/ai-runtime/state/session.js +5 -3
- 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/contexts/CurrentAgent.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +16 -9
- package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +4 -1
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +3 -47
- 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/builtin/async/ai-runtime/state/session.js +5 -3
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/api/asset.d.ts +13 -0
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +26 -2
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -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
|
+
}
|
|
@@ -6,7 +6,7 @@ import { useRuntimeState } from '../state/runtime';
|
|
|
6
6
|
function useCurrentAid({ agentId }) {
|
|
7
7
|
const { aid } = useRuntimeState();
|
|
8
8
|
return useMemo(() => ({
|
|
9
|
-
aid: stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(aid, { rejectWhenError: true })), {
|
|
9
|
+
aid: stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(aid, { rejectWhenError: true })), { agentId })),
|
|
10
10
|
}), [aid, agentId]);
|
|
11
11
|
}
|
|
12
12
|
const context = createContext(undefined);
|
|
@@ -18,7 +18,7 @@ export function useCurrentAgent(args = {}) {
|
|
|
18
18
|
const { blockletDid, aid: runtimeAid, working } = useRuntimeState();
|
|
19
19
|
const aidFromParam = useMemo(() => args.aid ||
|
|
20
20
|
(args.agentId
|
|
21
|
-
? stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(runtimeAid, { rejectWhenError: true })), {
|
|
21
|
+
? stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(runtimeAid, { rejectWhenError: true })), { agentId: args.agentId }))
|
|
22
22
|
: undefined), [args.agentId, args.aid, runtimeAid]);
|
|
23
23
|
const current = useContext(context);
|
|
24
24
|
const aid = aidFromParam !== null && aidFromParam !== void 0 ? aidFromParam : current === null || current === void 0 ? void 0 : current.aid;
|
|
@@ -10,18 +10,25 @@ export default function useAppearances(args) {
|
|
|
10
10
|
const { agent: runtimeAgent } = useRuntimeState();
|
|
11
11
|
const { agent } = useCurrentAgent(args);
|
|
12
12
|
const appearancePage = useMemo(() => {
|
|
13
|
-
var _a, _b;
|
|
13
|
+
var _a, _b, _c, _d;
|
|
14
14
|
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
15
|
-
|
|
15
|
+
if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
|
|
16
|
+
return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
|
|
17
|
+
const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _d === void 0 ? void 0 : _d.appearance;
|
|
18
|
+
if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
|
|
19
|
+
return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
|
|
20
|
+
return {
|
|
21
|
+
componentId: DEFAULT_PAGE_COMPONENT_ID,
|
|
22
|
+
};
|
|
16
23
|
}, [agent]);
|
|
17
24
|
const appearanceInput = useMemo(() => {
|
|
18
25
|
var _a, _b, _c, _d;
|
|
19
26
|
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
20
|
-
if (appearance)
|
|
21
|
-
return appearance;
|
|
27
|
+
if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
|
|
28
|
+
return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
|
|
22
29
|
const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _d === void 0 ? void 0 : _d.appearance;
|
|
23
|
-
if (runtimeAppearance)
|
|
24
|
-
return runtimeAppearance;
|
|
30
|
+
if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
|
|
31
|
+
return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
|
|
25
32
|
return {
|
|
26
33
|
componentId: DEFAULT_INPUT_COMPONENT_ID,
|
|
27
34
|
};
|
|
@@ -30,10 +37,10 @@ export default function useAppearances(args) {
|
|
|
30
37
|
var _a, _b, _c, _d;
|
|
31
38
|
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
32
39
|
if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
|
|
33
|
-
return appearance;
|
|
40
|
+
return Object.assign(Object.assign({}, appearance), { componentId: appearance.componentId });
|
|
34
41
|
const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _d === void 0 ? void 0 : _d.appearance;
|
|
35
|
-
if (runtimeAppearance)
|
|
36
|
-
return runtimeAppearance;
|
|
42
|
+
if (runtimeAppearance === null || runtimeAppearance === void 0 ? void 0 : runtimeAppearance.componentId)
|
|
43
|
+
return Object.assign(Object.assign({}, runtimeAppearance), { componentId: runtimeAppearance.componentId });
|
|
37
44
|
return {
|
|
38
45
|
componentId: DEFAULT_OUTPUT_COMPONENT_ID,
|
|
39
46
|
};
|
|
@@ -15,18 +15,20 @@ import { useHeader } from '../../../page/header';
|
|
|
15
15
|
import { settingsDialogState } from '../components/AgentSettings/AgentSettingsDialog';
|
|
16
16
|
import PopperMenuButton from '../components/PopperMenuButton';
|
|
17
17
|
import LoadingMenuItem from '../components/PopperMenuButton/LoadingMenuItem';
|
|
18
|
+
import SocialShare from '../components/SocialShare';
|
|
18
19
|
import { useComponentPreferences } from '../contexts/ComponentPreferences';
|
|
19
20
|
import { useRuntimeState } from '../state/runtime';
|
|
20
21
|
import { useSessionState } from '../state/session';
|
|
21
22
|
import { useIsAgentAdmin } from './use-agent-admin';
|
|
22
23
|
export function useHeaderMenu() {
|
|
23
|
-
var _a;
|
|
24
|
+
var _a, _b, _c;
|
|
24
25
|
const { t, locale } = useLocaleContext();
|
|
25
26
|
const { hideHeaderMenuButton } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
26
27
|
const clearSession = useSessionState((s) => s.clearSession);
|
|
27
28
|
const { agent } = useRuntimeState();
|
|
28
29
|
const isAdmin = useIsAgentAdmin(agent);
|
|
29
30
|
const hasSettings = agent.config.secrets.length > 0;
|
|
31
|
+
const shareContent = ((_b = agent.project) === null || _b === void 0 ? void 0 : _b.name) ? `${agent.project.name}\n\n${(_c = agent.project) === null || _c === void 0 ? void 0 : _c.description}` : '';
|
|
30
32
|
useHeader(() => hideHeaderMenuButton
|
|
31
33
|
? {}
|
|
32
34
|
: {
|
|
@@ -35,6 +37,7 @@ export function useHeaderMenu() {
|
|
|
35
37
|
hasSettings && isAdmin && (_jsxs(MenuItem, { onClick: () => settingsDialogState.getState().open(), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "tabler:settings" }) }), t('settings')] }, "settings")),
|
|
36
38
|
_jsxs(LoadingMenuItem, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }, "clearSession"),
|
|
37
39
|
], children: _jsx(Icon, { icon: "tabler:dots" }) }),
|
|
40
|
+
_jsx(SocialShare, { content: shareContent }),
|
|
38
41
|
...exists,
|
|
39
42
|
],
|
|
40
43
|
}, [locale, hideHeaderMenuButton]);
|
|
@@ -1,65 +1,21 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
2
|
import { Helmet } from 'react-helmet';
|
|
4
|
-
import { joinURL } from 'ufo';
|
|
5
3
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
6
|
-
import { Avatar, DID } from '../../../../arcblock/ux';
|
|
7
|
-
import { useLocaleContext } from '../../../../locale';
|
|
8
|
-
import { useHeader } from '../../../../page/header';
|
|
9
|
-
import { getComponentMountPoint } from '../../../../utils';
|
|
10
4
|
import AgentSettingsDialog from '../../components/AgentSettings/AgentSettingsDialog';
|
|
11
|
-
import RuntimeCommonProvider
|
|
12
|
-
import SocialShare from '../../components/SocialShare';
|
|
5
|
+
import RuntimeCommonProvider from '../../components/RuntimeCommonProvider';
|
|
13
6
|
import ThemeProvider from '../../components/ThemeProvider';
|
|
14
|
-
import { AI_STUDIO_DID, DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
15
7
|
import ActiveAgentProvider from '../../contexts/ActiveAgent';
|
|
16
8
|
import RuntimeProvider, { RuntimeProviderFromUrl } from '../../contexts/Runtime';
|
|
17
9
|
import useAppearances from '../../hooks/use-appearances';
|
|
18
10
|
import { useHeaderMenu } from '../../hooks/use-header-menu';
|
|
19
11
|
import { useRuntimeState } from '../../state/runtime';
|
|
20
|
-
const logoSize = 44;
|
|
21
|
-
function AgentCreatedBy({ did }) {
|
|
22
|
-
const { t } = useLocaleContext();
|
|
23
|
-
return (_jsxs(_Fragment, { children: [t('by'), " ", _jsx(Box, { component: DID, did: did, copyable: false, responsive: true })] }));
|
|
24
|
-
}
|
|
25
12
|
export default function Runtime({ blockletDid, aid, working, }) {
|
|
26
13
|
const children = (_jsx(ThemeProvider, { children: _jsx(ActiveAgentProvider, { children: _jsx(RuntimeView, {}) }) }));
|
|
27
14
|
return (_jsx(RuntimeCommonProvider, { children: aid ? (_jsx(RuntimeProvider, { blockletDid: blockletDid, aid: aid, working: working, children: children })) : (_jsx(RuntimeProviderFromUrl, { children: children })) }));
|
|
28
15
|
}
|
|
29
16
|
function RuntimeView() {
|
|
30
|
-
var _a;
|
|
31
17
|
const { aid, agent } = useRuntimeState();
|
|
32
18
|
const { appearancePage } = useAppearances({ aid });
|
|
33
|
-
const theme = useTheme();
|
|
34
|
-
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
35
|
-
const { locale } = useLocaleContext();
|
|
36
|
-
useHeader(() => {
|
|
37
|
-
const logo = joinURL(window.location.origin, getComponentMountPoint(AI_STUDIO_DID), '/api/projects', agent.project.id, '/logo.png');
|
|
38
|
-
const shareContent = `${agent.name}
|
|
39
|
-
|
|
40
|
-
${agent === null || agent === void 0 ? void 0 : agent.description}
|
|
41
|
-
`;
|
|
42
|
-
return {
|
|
43
|
-
logo: logo && (_jsx(Box, { component: Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: logoSize, sx: {
|
|
44
|
-
width: logoSize,
|
|
45
|
-
height: logoSize,
|
|
46
|
-
} })),
|
|
47
|
-
brand: !isMobile ? (_jsx(Box, { sx: {
|
|
48
|
-
height: 18,
|
|
49
|
-
fontSize: 18,
|
|
50
|
-
}, children: agent.project.name })) : undefined,
|
|
51
|
-
description: !isMobile && agent.createdBy ? (_jsx(RuntimeLocaleProvider, { children: _jsx(Box, { sx: {
|
|
52
|
-
display: 'inline-flex',
|
|
53
|
-
alignItems: 'center',
|
|
54
|
-
gap: 0.5,
|
|
55
|
-
mt: 0.5,
|
|
56
|
-
height: 12,
|
|
57
|
-
fontSize: 12,
|
|
58
|
-
}, children: _jsx(AgentCreatedBy, { did: agent.project.createdBy }) }) })) : undefined,
|
|
59
|
-
addons: (exists) => [_jsx(SocialShare, { content: shareContent }), ...exists].filter(Boolean),
|
|
60
|
-
};
|
|
61
|
-
}, [locale, isMobile, agent]);
|
|
62
19
|
useHeaderMenu();
|
|
63
|
-
|
|
64
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Helmet, { children: [agent.project.name && _jsx("title", { children: agent.project.name }), agent.project.description && _jsx("meta", { name: "description", content: agent.project.description })] }), _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProperties }), _jsx(AgentSettingsDialog, {})] }));
|
|
20
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Helmet, { children: [agent.project.name && _jsx("title", { children: agent.project.name }), agent.project.description && _jsx("meta", { name: "description", content: agent.project.description })] }), _jsx(CustomComponentRenderer, { componentId: appearancePage.componentId, properties: appearancePage.componentProperties }), _jsx(AgentSettingsDialog, {})] }));
|
|
65
21
|
}
|
|
@@ -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;
|
|
@@ -268,6 +268,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
268
268
|
parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
|
|
269
269
|
});
|
|
270
270
|
let responseStarted = false;
|
|
271
|
+
let mainTaskId;
|
|
271
272
|
try {
|
|
272
273
|
for (var _e = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _b = stream_1_1.done, !_b; _e = true) {
|
|
273
274
|
_d = stream_1_1.value;
|
|
@@ -279,9 +280,10 @@ export const createSessionState = ({ aid }) => {
|
|
|
279
280
|
}
|
|
280
281
|
if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
|
|
281
282
|
if (!message) {
|
|
283
|
+
mainTaskId = value.taskId;
|
|
282
284
|
message = {
|
|
283
|
-
id: value.
|
|
284
|
-
agentId: identity.
|
|
285
|
+
id: value.messageId,
|
|
286
|
+
agentId: identity.agentId,
|
|
285
287
|
sessionId,
|
|
286
288
|
inputs: parameters,
|
|
287
289
|
createdAt: new Date().toISOString(),
|
|
@@ -297,7 +299,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
297
299
|
s.messages.push(message);
|
|
298
300
|
});
|
|
299
301
|
}
|
|
300
|
-
if (
|
|
302
|
+
if (mainTaskId === value.taskId) {
|
|
301
303
|
requestAnimationFrame(() => {
|
|
302
304
|
set((state) => {
|
|
303
305
|
var _a, _b, _c, _d;
|