@blocklet/pages-kit 0.2.308 → 0.2.310
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/components/Header/SimpleHeader.js +3 -3
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +94 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +3 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +33 -7
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +12 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +192 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +18 -24
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/cjs/builtin/async/ai-runtime/utils/runtime-output-schema.js +8 -0
- package/lib/esm/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +87 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +10 -7
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +163 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +19 -25
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/esm/builtin/async/ai-runtime/utils/runtime-output-schema.js +4 -0
- package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +8 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +45 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -3
- package/lib/types/builtin/async/ai-runtime/utils/runtime-output-schema.d.ts +3 -0
- package/package.json +6 -6
|
@@ -0,0 +1,163 @@
|
|
|
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 { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
14
|
+
import { Avatar, Box, IconButton, Stack, ThemeProvider, alpha, createTheme, useTheme, } from '@mui/material';
|
|
15
|
+
import { memo, useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { useScrollToBottom } from 'react-scroll-to-bottom';
|
|
17
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
18
|
+
import { useSessionContext } from '../../../../session';
|
|
19
|
+
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
20
|
+
import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
21
|
+
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
22
|
+
import ScrollView from '../../components/ScrollView';
|
|
23
|
+
import UserInfo from '../../components/UserInfo';
|
|
24
|
+
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
25
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
26
|
+
import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
|
|
27
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
28
|
+
import { useSessionState } from '../../state/session';
|
|
29
|
+
import { getOutputVariableInitialValue } from '../../utils/runtime-output-schema';
|
|
30
|
+
import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
|
|
31
|
+
export default function MultiAgentsChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, backgroundImage, }) {
|
|
32
|
+
useSessionState({ autoLoad: true });
|
|
33
|
+
const inheritedTheme = useTheme();
|
|
34
|
+
const theme = useMemo(() => {
|
|
35
|
+
let { primary } = inheritedTheme.palette;
|
|
36
|
+
try {
|
|
37
|
+
if (primaryColor) {
|
|
38
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('augment primary color error', { error });
|
|
43
|
+
}
|
|
44
|
+
return createTheme(inheritedTheme, {
|
|
45
|
+
palette: { primary },
|
|
46
|
+
shape: {
|
|
47
|
+
borderRadius: 8,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}, [inheritedTheme, primaryColor]);
|
|
51
|
+
return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsxs(ThemeProvider, { theme: theme, children: [_jsx(Box, { sx: {
|
|
52
|
+
position: 'fixed',
|
|
53
|
+
left: 0,
|
|
54
|
+
top: 0,
|
|
55
|
+
right: 0,
|
|
56
|
+
bottom: 0,
|
|
57
|
+
backgroundImage: `url(${backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url}) !important`,
|
|
58
|
+
backgroundRepeat: 'no-repeat',
|
|
59
|
+
backgroundSize: 'cover',
|
|
60
|
+
backgroundPosition: 'center',
|
|
61
|
+
pointerEvents: 'none',
|
|
62
|
+
zIndex: -1,
|
|
63
|
+
} }), _jsx(SimpleChatView, {})] }) })));
|
|
64
|
+
}
|
|
65
|
+
function SimpleChatView() {
|
|
66
|
+
// auto scroll to bottom when new message is sent
|
|
67
|
+
const running = useSessionState()((s) => s.running);
|
|
68
|
+
const scrollToBottom = useScrollToBottom();
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (running)
|
|
71
|
+
scrollToBottom({ behavior: 'smooth' });
|
|
72
|
+
}, [scrollToBottom, running]);
|
|
73
|
+
const { childAgentId } = useRuntimeState();
|
|
74
|
+
const [currentAgentId, setCurrentAgentId] = useState(childAgentId);
|
|
75
|
+
return (_jsxs(SimpleLayout, { children: [_jsx(SimpleHeader, { px: 2 }), _jsx(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10, px: 2, currentAgentId: currentAgentId }), _jsx(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", currentAgentId: currentAgentId, onCurrentAgentIdChange: setCurrentAgentId, sx: {
|
|
76
|
+
position: 'sticky',
|
|
77
|
+
bottom: 0,
|
|
78
|
+
p: 2,
|
|
79
|
+
borderRadius: 1,
|
|
80
|
+
bgcolor: (theme) => alpha(theme.palette.background.paper, 0.7),
|
|
81
|
+
backdropFilter: 'blur(10px)',
|
|
82
|
+
zIndex: 10,
|
|
83
|
+
} })] }));
|
|
84
|
+
}
|
|
85
|
+
function AgentInputRender(_a) {
|
|
86
|
+
var { currentAgentId, onCurrentAgentIdChange } = _a, props = __rest(_a, ["currentAgentId", "onCurrentAgentIdChange"]);
|
|
87
|
+
const { agent } = useRuntimeState();
|
|
88
|
+
const children = useMemo(() => { var _a, _b; return (_b = (_a = getOutputVariableInitialValue(agent, RuntimeOutputVariable.children)) === null || _a === void 0 ? void 0 : _a.agents) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.id); }, [agent]);
|
|
89
|
+
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(Stack, { direction: "row", gap: 2, children: children === null || children === void 0 ? void 0 : children.map((child) => (_jsx(CurrentAgentProvider, { agentId: child.id, children: _jsx(AgentAvatar, { selected: currentAgentId === child.id, onClick: () => onCurrentAgentIdChange(child.id) }) }))) }), _jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(AgentInput, {}) }) })] })));
|
|
90
|
+
}
|
|
91
|
+
function AgentAvatar(_a) {
|
|
92
|
+
var _b;
|
|
93
|
+
var { selected } = _a, props = __rest(_a, ["selected"]);
|
|
94
|
+
const { appearanceInput } = useAppearances();
|
|
95
|
+
const profile = useProfile();
|
|
96
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
97
|
+
return null;
|
|
98
|
+
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) }) })));
|
|
99
|
+
}
|
|
100
|
+
function AgentInput() {
|
|
101
|
+
const { aid } = useCurrentAgent();
|
|
102
|
+
const { appearanceInput } = useAppearances({ aid });
|
|
103
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
104
|
+
return null;
|
|
105
|
+
return (_jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }));
|
|
106
|
+
}
|
|
107
|
+
function OutputView(_a) {
|
|
108
|
+
var { currentAgentId } = _a, props = __rest(_a, ["currentAgentId"]);
|
|
109
|
+
const messages = useSessionState()((s) => s.messages);
|
|
110
|
+
const loading = useSessionState()((s) => s.loading);
|
|
111
|
+
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
112
|
+
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningMessageView, {}) }), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && _jsx(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningQuestionsView, {}) }))] })));
|
|
113
|
+
}
|
|
114
|
+
const OutputItemView = memo(({ message }) => {
|
|
115
|
+
var _a, _b, _c, _d;
|
|
116
|
+
const { aid } = useCurrentAgent({ agentId: message.assistantId });
|
|
117
|
+
const { appearanceOutput } = useAppearances({ aid });
|
|
118
|
+
const profile = useProfile({ aid });
|
|
119
|
+
const { session: authSession } = useSessionContext();
|
|
120
|
+
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
121
|
+
return null;
|
|
122
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [_jsx(Box, { children: _jsx(UserInfo, { name: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.fullName, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, avatar: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
123
|
+
renderType: 'parameters',
|
|
124
|
+
} }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name: profile.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
125
|
+
renderType: 'result',
|
|
126
|
+
} }) }) })] }) }) }));
|
|
127
|
+
});
|
|
128
|
+
function SuggestedQuestionsView({ message }) {
|
|
129
|
+
const { aid } = useCurrentAgent({ agentId: message.assistantId });
|
|
130
|
+
const { execute } = useRuntimeState();
|
|
131
|
+
const suggestedQuestions = useMemo(() => {
|
|
132
|
+
var _a, _b, _c;
|
|
133
|
+
return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data[RuntimeOutputVariable.suggestedQuestions];
|
|
134
|
+
}, [message]);
|
|
135
|
+
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? (_jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
136
|
+
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
137
|
+
} })) : null }));
|
|
138
|
+
}
|
|
139
|
+
const OpeningMessageView = memo(() => {
|
|
140
|
+
var _a;
|
|
141
|
+
const opening = useOpeningMessage();
|
|
142
|
+
if (!opening)
|
|
143
|
+
return null;
|
|
144
|
+
return (_jsx(Box, { children: _jsx(UserInfo, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: _jsx(Box, { sx: {
|
|
145
|
+
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
146
|
+
borderRadius: 1,
|
|
147
|
+
borderTopLeftRadius: 2,
|
|
148
|
+
px: 2,
|
|
149
|
+
py: 1,
|
|
150
|
+
mt: 0.5,
|
|
151
|
+
mr: 5,
|
|
152
|
+
}, children: _jsx(MarkdownRenderer, { children: opening.message }) }) }) }));
|
|
153
|
+
});
|
|
154
|
+
function OpeningQuestionsView() {
|
|
155
|
+
const { execute } = useRuntimeState();
|
|
156
|
+
const { aid } = useCurrentAgent();
|
|
157
|
+
const opening = useOpeningQuestions({ aid });
|
|
158
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
159
|
+
return null;
|
|
160
|
+
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
161
|
+
return (_jsx(MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
162
|
+
}) }) }));
|
|
163
|
+
}
|
|
@@ -18,8 +18,9 @@ import CustomComponentRenderer from '../../../../../components/CustomComponentRe
|
|
|
18
18
|
import { useLocaleContext } from '../../../../locale';
|
|
19
19
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
20
20
|
import LoadingButton from '../../components/LoadingButton';
|
|
21
|
-
import CurrentAgentProvider
|
|
21
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
22
22
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
23
|
+
import useAppearances from '../../hooks/use-appearances';
|
|
23
24
|
import { useRuntimeState } from '../../state/runtime';
|
|
24
25
|
import { useSessionState } from '../../state/session';
|
|
25
26
|
import mapRight from '../../utils/map-right';
|
|
@@ -48,7 +49,7 @@ export default function PhotoGallery({ resultTitle, primaryColor }) {
|
|
|
48
49
|
}
|
|
49
50
|
function AgentInputRender(_a) {
|
|
50
51
|
var props = __rest(_a, []);
|
|
51
|
-
const { appearanceInput } =
|
|
52
|
+
const { appearanceInput } = useAppearances();
|
|
52
53
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
53
54
|
return null;
|
|
54
55
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
@@ -68,7 +69,7 @@ function OutputView(_a) {
|
|
|
68
69
|
} })), mapRight(messages, (message) => (_jsx(OutputItemView, { message: message }, message.taskId)))] }), _jsx(Box, { my: 4, children: !!messages.length && !noMoreMessage && (_jsx(LoadingButton, { variant: "outlined", onClick: loadMoreMessages, children: t('loadMore') })) })] })));
|
|
69
70
|
}
|
|
70
71
|
const OutputItemView = memo(({ message }) => {
|
|
71
|
-
const { appearanceOutput } =
|
|
72
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
72
73
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
73
74
|
return null;
|
|
74
75
|
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }, message.taskId));
|
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import { RuntimeOutputVariable
|
|
13
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
14
14
|
import { Box, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
|
|
15
15
|
import { memo, useEffect, useMemo } from 'react';
|
|
16
16
|
import { useScrollToBottom } from 'react-scroll-to-bottom';
|
|
@@ -23,6 +23,7 @@ import ScrollView from '../../components/ScrollView';
|
|
|
23
23
|
import UserInfo from '../../components/UserInfo';
|
|
24
24
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
25
25
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
26
|
+
import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
|
|
26
27
|
import { useRuntimeState } from '../../state/runtime';
|
|
27
28
|
import { useSessionState } from '../../state/session';
|
|
28
29
|
import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
|
|
@@ -61,8 +62,8 @@ function SimpleChatView() {
|
|
|
61
62
|
}
|
|
62
63
|
function AgentInputRender(_a) {
|
|
63
64
|
var props = __rest(_a, []);
|
|
64
|
-
const { appearanceInput } =
|
|
65
|
-
if (!
|
|
65
|
+
const { appearanceInput } = useAppearances();
|
|
66
|
+
if (!appearanceInput.componentId)
|
|
66
67
|
return null;
|
|
67
68
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
68
69
|
}
|
|
@@ -74,15 +75,15 @@ function OutputView(_a) {
|
|
|
74
75
|
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
|
|
75
76
|
}
|
|
76
77
|
const OutputItemView = memo(({ message }) => {
|
|
77
|
-
var _a, _b, _c, _d
|
|
78
|
-
const { appearanceOutput } = useCurrentAgent({ agentId: message.assistantId });
|
|
79
|
-
const { appearancePage } = useRuntimeState();
|
|
78
|
+
var _a, _b, _c, _d;
|
|
80
79
|
const { session: authSession } = useSessionContext();
|
|
80
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
81
|
+
const profile = useProfile({ agentId: message.assistantId });
|
|
81
82
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
82
83
|
return null;
|
|
83
84
|
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [_jsx(Box, { children: _jsx(UserInfo, { name: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.fullName, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, avatar: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
84
85
|
renderType: 'parameters',
|
|
85
|
-
} }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name:
|
|
86
|
+
} }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name: profile.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
86
87
|
renderType: 'result',
|
|
87
88
|
} }) }) })] }) }) }));
|
|
88
89
|
});
|
|
@@ -98,16 +99,12 @@ function SuggestedQuestionsView({ message }) {
|
|
|
98
99
|
} })) : null }));
|
|
99
100
|
}
|
|
100
101
|
const OpeningMessageView = memo(() => {
|
|
101
|
-
var _a
|
|
102
|
-
const { childAgentId
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
var _a, _b;
|
|
106
|
-
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.openingMessage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
107
|
-
}, [agent]);
|
|
108
|
-
if (!(openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.message))
|
|
102
|
+
var _a;
|
|
103
|
+
const { childAgentId } = useRuntimeState();
|
|
104
|
+
const opening = useOpeningMessage({ agentId: childAgentId });
|
|
105
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.message))
|
|
109
106
|
return null;
|
|
110
|
-
return (_jsx(Box, { children: _jsx(UserInfo, { name:
|
|
107
|
+
return (_jsx(Box, { children: _jsx(UserInfo, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: _jsx(Box, { sx: {
|
|
111
108
|
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
112
109
|
borderRadius: 1,
|
|
113
110
|
borderTopLeftRadius: 2,
|
|
@@ -115,19 +112,16 @@ const OpeningMessageView = memo(() => {
|
|
|
115
112
|
py: 1,
|
|
116
113
|
mt: 0.5,
|
|
117
114
|
mr: 5,
|
|
118
|
-
}, children: _jsx(MarkdownRenderer, { children:
|
|
115
|
+
}, children: _jsx(MarkdownRenderer, { children: opening.message }) }) }) }));
|
|
119
116
|
});
|
|
120
117
|
function OpeningQuestionsView() {
|
|
121
|
-
const { childAgentId } = useRuntimeState();
|
|
122
118
|
const { execute } = useRuntimeState();
|
|
123
|
-
const {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, [agent]);
|
|
128
|
-
if (!(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.length))
|
|
119
|
+
const { childAgentId } = useRuntimeState();
|
|
120
|
+
const { aid } = useCurrentAgent({ agentId: childAgentId });
|
|
121
|
+
const opening = useOpeningQuestions({ aid });
|
|
122
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
129
123
|
return null;
|
|
130
|
-
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children:
|
|
124
|
+
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
131
125
|
return (_jsx(MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
132
126
|
}) }) }));
|
|
133
127
|
}
|
|
@@ -16,8 +16,9 @@ import Balancer from 'react-wrap-balancer';
|
|
|
16
16
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
17
17
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
18
18
|
import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
19
|
-
import CurrentAgentProvider
|
|
19
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
20
20
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
|
+
import useAppearances from '../../hooks/use-appearances';
|
|
21
22
|
import { useRuntimeState } from '../../state/runtime';
|
|
22
23
|
import { useSessionState } from '../../state/session';
|
|
23
24
|
export default function SimplePage({ resultTitle, primaryColor }) {
|
|
@@ -45,7 +46,7 @@ export default function SimplePage({ resultTitle, primaryColor }) {
|
|
|
45
46
|
}
|
|
46
47
|
function AgentInputRender(_a) {
|
|
47
48
|
var props = __rest(_a, []);
|
|
48
|
-
const { appearanceInput } =
|
|
49
|
+
const { appearanceInput } = useAppearances();
|
|
49
50
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
50
51
|
return null;
|
|
51
52
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
@@ -56,7 +57,7 @@ function OutputView(_a) {
|
|
|
56
57
|
return (_jsx(Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && (_jsxs(_Fragment, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(Stack, { children: _jsx(OutputItemView, { message: lastMessage }) })] })) })));
|
|
57
58
|
}
|
|
58
59
|
const OutputItemView = memo(({ message }) => {
|
|
59
|
-
const { appearanceOutput } =
|
|
60
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
60
61
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
61
62
|
return null;
|
|
62
63
|
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }));
|
|
@@ -39,13 +39,9 @@ export function useRuntimeState() {
|
|
|
39
39
|
}
|
|
40
40
|
return exec(Object.assign(Object.assign({}, args), { working }));
|
|
41
41
|
}), [authSession.user, exec, working, login]);
|
|
42
|
-
const appearancePage = useMemo(() => {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
45
|
-
}, [agent]);
|
|
46
42
|
const childAgentId = useMemo(() => {
|
|
47
43
|
var _a, _b, _c, _d, _e, _f;
|
|
48
44
|
return ((_f = (_e = (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue) === null || _c === void 0 ? void 0 : _c.agents) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : agent.id);
|
|
49
45
|
}, [agent]);
|
|
50
|
-
return { aid, working, agent,
|
|
46
|
+
return { aid, working, agent, childAgentId, execute };
|
|
51
47
|
}
|
|
@@ -14,6 +14,14 @@ export interface Agent {
|
|
|
14
14
|
}[];
|
|
15
15
|
release?: AssistantBase['release'];
|
|
16
16
|
createdBy?: string;
|
|
17
|
+
project: {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
createdBy: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
};
|
|
17
25
|
}
|
|
18
26
|
export declare function getAgent({ aid, working }: {
|
|
19
27
|
aid: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RuntimeOutputAppearance } from '@blocklet/ai-runtime/types';
|
|
2
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { Agent } from '../api/agent';
|
|
3
3
|
export interface CurrentAgentState {
|
|
4
4
|
aid: string;
|
|
5
5
|
}
|
|
@@ -7,11 +7,10 @@ export default function CurrentAgentProvider({ agentId, children }: {
|
|
|
7
7
|
agentId: string;
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
}): import("react/jsx-runtime").JSX.Element;
|
|
10
|
-
export declare function useCurrentAgent(
|
|
10
|
+
export declare function useCurrentAgent(args?: {
|
|
11
|
+
aid?: string;
|
|
11
12
|
agentId?: string;
|
|
12
13
|
}): {
|
|
13
14
|
aid: string;
|
|
14
|
-
agent:
|
|
15
|
-
appearanceInput: RuntimeOutputAppearance;
|
|
16
|
-
appearanceOutput: RuntimeOutputAppearance;
|
|
15
|
+
agent: Agent;
|
|
17
16
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export default function useAppearances(args?: {
|
|
2
|
+
aid: string;
|
|
3
|
+
} | {
|
|
4
|
+
agentId: string;
|
|
5
|
+
}): {
|
|
6
|
+
appearancePage: {
|
|
7
|
+
componentId: string;
|
|
8
|
+
componentName?: string | undefined;
|
|
9
|
+
componentProps?: {
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
} | undefined;
|
|
12
|
+
};
|
|
13
|
+
appearanceInput: import("@blocklet/ai-runtime/types").RuntimeOutputAppearance;
|
|
14
|
+
appearanceOutput: import("@blocklet/ai-runtime/types").RuntimeOutputAppearance;
|
|
15
|
+
};
|
|
16
|
+
export declare function useProfile(args?: {
|
|
17
|
+
aid: string;
|
|
18
|
+
} | {
|
|
19
|
+
agentId: string;
|
|
20
|
+
}): {
|
|
21
|
+
avatar: string;
|
|
22
|
+
name: string | undefined;
|
|
23
|
+
};
|
|
24
|
+
export declare function useOpeningMessage(args?: {
|
|
25
|
+
aid: string;
|
|
26
|
+
} | {
|
|
27
|
+
agentId: string;
|
|
28
|
+
}): {
|
|
29
|
+
message: string;
|
|
30
|
+
profile: {
|
|
31
|
+
avatar: string;
|
|
32
|
+
name: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
} | undefined;
|
|
35
|
+
export declare function useOpeningQuestions(args?: {
|
|
36
|
+
aid: string;
|
|
37
|
+
} | {
|
|
38
|
+
agentId: string;
|
|
39
|
+
}): {
|
|
40
|
+
questions: {
|
|
41
|
+
id: string;
|
|
42
|
+
title?: string | undefined;
|
|
43
|
+
parameters?: any;
|
|
44
|
+
}[];
|
|
45
|
+
} | undefined;
|
|
@@ -8,6 +8,7 @@ export { default as Runtime } from './runtime/Runtime';
|
|
|
8
8
|
export { default as ChatBotButton } from './runtime/ChatBotButton';
|
|
9
9
|
export { default as SimplePage } from './runtime-components/SimplePage';
|
|
10
10
|
export { default as SimpleChat } from './runtime-components/SimpleChat';
|
|
11
|
+
export { default as MultiAgentsChat } from './runtime-components/MultiAgentsChat';
|
|
11
12
|
export { default as PhotoGallery } from './runtime-components/PhotoGallery';
|
|
12
13
|
export { default as AutoForm } from './runtime-components/AutoForm';
|
|
13
14
|
export { default as SimpleOutput } from './runtime-components/SimpleOutput';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
import ScrollView from '../../components/ScrollView';
|
|
3
|
+
export default function MultiAgentsChat({ primaryColor, scrollViewProps, backgroundImage, }: {
|
|
4
|
+
primaryColor?: string;
|
|
5
|
+
scrollViewProps?: ComponentProps<typeof ScrollView>;
|
|
6
|
+
backgroundImage?: {
|
|
7
|
+
url?: string;
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
};
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -13,4 +13,4 @@ export declare const createAgentState: ({ aid, working, agent }: {
|
|
|
13
13
|
export declare function useAgentState({ aid, working }: {
|
|
14
14
|
aid: string;
|
|
15
15
|
working?: boolean;
|
|
16
|
-
}):
|
|
16
|
+
}): [Agent, AgentState];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { RuntimeOutputAppearancePage } from '@blocklet/ai-runtime/types';
|
|
2
1
|
export declare function useRuntimeState(): {
|
|
3
2
|
aid: string;
|
|
4
3
|
working: boolean | undefined;
|
|
5
|
-
agent: import("
|
|
6
|
-
appearancePage: RuntimeOutputAppearancePage | undefined;
|
|
4
|
+
agent: import("../api/agent").Agent;
|
|
7
5
|
childAgentId: string;
|
|
8
6
|
execute: (options: {
|
|
9
7
|
aid: string;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { RuntimeOutputVariable, RuntimeOutputVariablesSchema } from '@blocklet/ai-runtime/types';
|
|
2
|
+
import { Agent } from '../api/agent';
|
|
3
|
+
export declare function getOutputVariableInitialValue<T extends RuntimeOutputVariable>(agent: Agent, output: T): RuntimeOutputVariablesSchema[T] | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/pages-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.310",
|
|
4
4
|
"description": "Pages Kit components and utils",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -81,9 +81,9 @@
|
|
|
81
81
|
"url": "git+https://github.com/blocklet/pages-kit.git"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"@arcblock/did-connect": "^2.9.
|
|
85
|
-
"@blocklet/ai-kit": "^0.1.
|
|
86
|
-
"@blocklet/ai-runtime": "^0.1.
|
|
84
|
+
"@arcblock/did-connect": "^2.9.79",
|
|
85
|
+
"@blocklet/ai-kit": "^0.1.33",
|
|
86
|
+
"@blocklet/ai-runtime": "^0.1.388",
|
|
87
87
|
"@blocklet/js-sdk": "1.16.26",
|
|
88
88
|
"@blocklet/sdk": "^1.16.26",
|
|
89
89
|
"@iconify/react": "^4.1.1",
|
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
"react-router-dom": "^6.16.0"
|
|
128
128
|
},
|
|
129
129
|
"devDependencies": {
|
|
130
|
-
"@arcblock/ux": "^2.9.
|
|
130
|
+
"@arcblock/ux": "^2.9.79",
|
|
131
131
|
"@emotion/cache": "^11.11.0",
|
|
132
132
|
"@emotion/css": "^11.11.2",
|
|
133
133
|
"@emotion/react": "^11.11.4",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"react": "^18.3.1",
|
|
147
147
|
"react-dom": "^18.3.1",
|
|
148
148
|
"react-router-dom": "^6.23.1",
|
|
149
|
-
"rimraf": "^5.0.
|
|
149
|
+
"rimraf": "^5.0.7"
|
|
150
150
|
},
|
|
151
151
|
"scripts": {
|
|
152
152
|
"lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",
|