@blocklet/pages-kit 0.2.309 → 0.2.311
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 +5 -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/ChatOutput/MessageMetadataRenderer.js +8 -5
- 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/runtime-components/V0/Input.js +152 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +79 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +147 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/index.js +12 -0
- 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/cjs/builtin/mui/material.js +3 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/utils/inject-global-components-dump-json.js +1167 -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 +3 -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/ChatOutput/MessageMetadataRenderer.js +8 -5
- 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/runtime-components/V0/Input.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +73 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +142 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/index.js +3 -0
- 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/esm/builtin/mui/material.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/utils/inject-global-components-dump-json.js +1165 -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 +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Output.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/index.d.ts +3 -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/lib/types/builtin/mui/material.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -0
- package/lib/types/utils/inject-global-components-dump-json.d.ts +1 -0
- package/package.json +13 -9
|
@@ -16,8 +16,8 @@ import Balancer, { Provider } from 'react-wrap-balancer';
|
|
|
16
16
|
import { useRuntimeState } from '../../state/runtime';
|
|
17
17
|
export default function SimpleHeader(_a) {
|
|
18
18
|
var { TitleProps, DescriptionProps } = _a, props = __rest(_a, ["TitleProps", "DescriptionProps"]);
|
|
19
|
-
const { agent
|
|
20
|
-
const title =
|
|
21
|
-
const description =
|
|
19
|
+
const { agent } = useRuntimeState();
|
|
20
|
+
const title = agent.project.name;
|
|
21
|
+
const { description } = agent.project;
|
|
22
22
|
return (_jsx(Stack, Object.assign({ gap: 2, mt: 8, mb: 4 }, props, { className: cx('aigne-header aigne-simple-header', props.className), children: _jsxs(Provider, { children: [title && (_jsx(Typography, Object.assign({ width: "100%", component: "h5", fontSize: 30, fontWeight: 700, textAlign: "center" }, TitleProps, { children: _jsx(Balancer, { children: title }) }))), description && (_jsx(Typography, Object.assign({ width: "100%", textAlign: "center" }, DescriptionProps, { children: _jsx(Balancer, { children: description }) })))] }) })));
|
|
23
23
|
}
|
|
@@ -28,6 +28,7 @@ import { withQuery } from 'ufo';
|
|
|
28
28
|
import { useLocaleContext } from '../../../../locale';
|
|
29
29
|
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
30
30
|
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
31
|
+
import { useProfile } from '../../hooks/use-appearances';
|
|
31
32
|
import { useRuntimeState } from '../../state/runtime';
|
|
32
33
|
import { convertImageToBlob, downloadImage } from '../../utils/download-image';
|
|
33
34
|
import ActionButton from '../ActionButton';
|
|
@@ -89,7 +90,8 @@ function ShareSave() {
|
|
|
89
90
|
var _a, _b, _c, _d, _e, _f;
|
|
90
91
|
const { t } = useLocaleContext();
|
|
91
92
|
const { message } = useCurrentMessage();
|
|
92
|
-
const {
|
|
93
|
+
const { aid, agent } = useRuntimeState();
|
|
94
|
+
const profile = useProfile({ aid });
|
|
93
95
|
const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
|
|
94
96
|
const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
|
|
95
97
|
if (!content && !image)
|
|
@@ -103,7 +105,7 @@ function ShareSave() {
|
|
|
103
105
|
yield html2pdf()
|
|
104
106
|
.set({
|
|
105
107
|
margin: 1,
|
|
106
|
-
filename: `${
|
|
108
|
+
filename: `${profile.name || agent.id} - ${message.taskId}.pdf`,
|
|
107
109
|
image: { type: 'jpeg', quality: 0.98 },
|
|
108
110
|
html2canvas: { scale: 2 },
|
|
109
111
|
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
|
|
@@ -112,7 +114,7 @@ function ShareSave() {
|
|
|
112
114
|
.save();
|
|
113
115
|
}
|
|
114
116
|
else if (image) {
|
|
115
|
-
saveAs(image, `${
|
|
117
|
+
saveAs(image, `${profile.name || agent.id}.png`);
|
|
116
118
|
}
|
|
117
119
|
}) }));
|
|
118
120
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { parseIdentity, stringifyIdentity } from '@blocklet/ai-runtime/common/aid';
|
|
3
|
-
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
4
3
|
import { createContext, useContext, useMemo } from 'react';
|
|
5
|
-
import { DEFAULT_INPUT_COMPONENT_ID, DEFAULT_OUTPUT_COMPONENT_ID } from '../constants';
|
|
6
4
|
import { useAgentState } from '../state/agent';
|
|
7
5
|
import { useRuntimeState } from '../state/runtime';
|
|
8
6
|
function useCurrentAid({ agentId }) {
|
|
@@ -16,23 +14,17 @@ export default function CurrentAgentProvider({ agentId, children }) {
|
|
|
16
14
|
const state = useCurrentAid({ agentId });
|
|
17
15
|
return _jsx(context.Provider, { value: state, children: children });
|
|
18
16
|
}
|
|
19
|
-
export function useCurrentAgent(
|
|
17
|
+
export function useCurrentAgent(args = {}) {
|
|
20
18
|
const { aid: runtimeAid, working } = useRuntimeState();
|
|
21
|
-
const aidFromParam = useMemo(() =>
|
|
22
|
-
|
|
19
|
+
const aidFromParam = useMemo(() => args.aid ||
|
|
20
|
+
(args.agentId
|
|
21
|
+
? stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(runtimeAid, { rejectWhenError: true })), { assistantId: args.agentId }))
|
|
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;
|
|
25
25
|
if (!aid) {
|
|
26
26
|
throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
|
|
27
27
|
}
|
|
28
28
|
const [agent] = useAgentState({ aid, working });
|
|
29
|
-
|
|
30
|
-
var _a, _b, _c;
|
|
31
|
-
return (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: DEFAULT_INPUT_COMPONENT_ID };
|
|
32
|
-
}, [agent]);
|
|
33
|
-
const appearanceOutput = useMemo(() => {
|
|
34
|
-
var _a, _b, _c;
|
|
35
|
-
return (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: DEFAULT_OUTPUT_COMPONENT_ID };
|
|
36
|
-
}, [agent]);
|
|
37
|
-
return { aid, agent, appearanceInput, appearanceOutput };
|
|
29
|
+
return { aid, agent };
|
|
38
30
|
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { joinURL } from 'ufo';
|
|
4
|
+
import { getComponentMountPoint } from '../../../utils';
|
|
5
|
+
import { AI_STUDIO_DID, DEFAULT_INPUT_COMPONENT_ID, DEFAULT_OUTPUT_COMPONENT_ID, DEFAULT_PAGE_COMPONENT_ID, } from '../constants';
|
|
6
|
+
import { useCurrentAgent } from '../contexts/CurrentAgent';
|
|
7
|
+
import { useRuntimeState } from '../state/runtime';
|
|
8
|
+
import { getOutputVariableInitialValue } from '../utils/runtime-output-schema';
|
|
9
|
+
export default function useAppearances(args) {
|
|
10
|
+
const { agent: runtimeAgent } = useRuntimeState();
|
|
11
|
+
const { agent } = useCurrentAgent(args);
|
|
12
|
+
const appearancePage = useMemo(() => {
|
|
13
|
+
const appearance = getOutputVariableInitialValue(agent, RuntimeOutputVariable.appearancePage);
|
|
14
|
+
return Object.assign(Object.assign({}, appearance), { componentId: (appearance === null || appearance === void 0 ? void 0 : appearance.componentId) || DEFAULT_PAGE_COMPONENT_ID });
|
|
15
|
+
}, [agent]);
|
|
16
|
+
const appearanceInput = useMemo(() => {
|
|
17
|
+
const appearance = getOutputVariableInitialValue(agent, RuntimeOutputVariable.appearanceInput);
|
|
18
|
+
if (appearance)
|
|
19
|
+
return appearance;
|
|
20
|
+
const runtimeAppearance = getOutputVariableInitialValue(runtimeAgent, RuntimeOutputVariable.appearanceInput);
|
|
21
|
+
if (runtimeAppearance)
|
|
22
|
+
return runtimeAppearance;
|
|
23
|
+
return {
|
|
24
|
+
componentId: DEFAULT_INPUT_COMPONENT_ID,
|
|
25
|
+
};
|
|
26
|
+
}, [agent, runtimeAgent]);
|
|
27
|
+
const appearanceOutput = useMemo(() => {
|
|
28
|
+
const appearance = getOutputVariableInitialValue(agent, RuntimeOutputVariable.appearanceOutput);
|
|
29
|
+
if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
|
|
30
|
+
return appearance;
|
|
31
|
+
const runtimeAppearance = getOutputVariableInitialValue(runtimeAgent, RuntimeOutputVariable.appearanceOutput);
|
|
32
|
+
if (runtimeAppearance)
|
|
33
|
+
return runtimeAppearance;
|
|
34
|
+
return {
|
|
35
|
+
componentId: DEFAULT_OUTPUT_COMPONENT_ID,
|
|
36
|
+
};
|
|
37
|
+
}, [agent, runtimeAgent]);
|
|
38
|
+
return { appearancePage, appearanceInput, appearanceOutput };
|
|
39
|
+
}
|
|
40
|
+
function getProjectIconUrl(projectId) {
|
|
41
|
+
return joinURL(window.location.origin, getComponentMountPoint(AI_STUDIO_DID), '/api/projects', projectId, '/logo.png');
|
|
42
|
+
}
|
|
43
|
+
export function useProfile(args) {
|
|
44
|
+
const { agent: runtimeAgent } = useRuntimeState();
|
|
45
|
+
const { agent } = useCurrentAgent(args);
|
|
46
|
+
return useMemo(() => {
|
|
47
|
+
const profile = getOutputVariableInitialValue(agent, RuntimeOutputVariable.profile);
|
|
48
|
+
const runtimeProfile = getOutputVariableInitialValue(runtimeAgent, RuntimeOutputVariable.profile);
|
|
49
|
+
return {
|
|
50
|
+
avatar: (profile === null || profile === void 0 ? void 0 : profile.avatar) || (runtimeProfile === null || runtimeProfile === void 0 ? void 0 : runtimeProfile.avatar) || getProjectIconUrl(agent.project.id),
|
|
51
|
+
name: (profile === null || profile === void 0 ? void 0 : profile.name) || (runtimeProfile === null || runtimeProfile === void 0 ? void 0 : runtimeProfile.name) || agent.name,
|
|
52
|
+
};
|
|
53
|
+
}, [agent, runtimeAgent]);
|
|
54
|
+
}
|
|
55
|
+
export function useOpeningMessage(args) {
|
|
56
|
+
const { aid: runtimeAid, agent: runtimeAgent } = useRuntimeState();
|
|
57
|
+
const runtimeProfile = useProfile({ aid: runtimeAid });
|
|
58
|
+
const { agent } = useCurrentAgent(args);
|
|
59
|
+
const profile = useProfile(args);
|
|
60
|
+
return useMemo(() => {
|
|
61
|
+
const agentOpening = getOutputVariableInitialValue(agent, RuntimeOutputVariable.openingMessage);
|
|
62
|
+
if (agentOpening === null || agentOpening === void 0 ? void 0 : agentOpening.message) {
|
|
63
|
+
return {
|
|
64
|
+
message: agentOpening.message,
|
|
65
|
+
profile,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const runtimeOpening = getOutputVariableInitialValue(runtimeAgent, RuntimeOutputVariable.openingMessage);
|
|
69
|
+
if (runtimeOpening === null || runtimeOpening === void 0 ? void 0 : runtimeOpening.message) {
|
|
70
|
+
return {
|
|
71
|
+
message: runtimeOpening.message,
|
|
72
|
+
profile: runtimeProfile,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}, [agent, profile, runtimeAgent, runtimeProfile]);
|
|
77
|
+
}
|
|
78
|
+
export function useOpeningQuestions(args) {
|
|
79
|
+
const { agent } = useCurrentAgent(args);
|
|
80
|
+
return useMemo(() => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const questions = (_b = (_a = getOutputVariableInitialValue(agent, RuntimeOutputVariable.openingQuestions)) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.title);
|
|
83
|
+
if (!(questions === null || questions === void 0 ? void 0 : questions.length))
|
|
84
|
+
return undefined;
|
|
85
|
+
return { questions };
|
|
86
|
+
}, [agent]);
|
|
87
|
+
}
|
|
@@ -8,8 +8,11 @@ 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';
|
|
14
15
|
export { default as ChatOutput } from './runtime-components/ChatOutput';
|
|
15
16
|
export { default as PhotoGalleryItem } from './runtime-components/PhotoGalleryItem';
|
|
17
|
+
// only use to debug, should be removed when PR
|
|
18
|
+
export * from './runtime-components/V0';
|
|
@@ -9,19 +9,22 @@ import RuntimeCommonProvider from '../../components/RuntimeCommonProvider';
|
|
|
9
9
|
import ScrollView from '../../components/ScrollView';
|
|
10
10
|
import { DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
11
11
|
import RuntimeProvider from '../../contexts/Runtime';
|
|
12
|
+
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
12
13
|
import { useRuntimeState } from '../../state/runtime';
|
|
13
14
|
import { useSessionState } from '../../state/session';
|
|
14
15
|
export default function ChatBotButton({ aid, working }) {
|
|
15
16
|
return (_jsx(RuntimeProvider, { aid: aid, working: working, children: _jsx(RuntimeCommonProvider, { children: _jsx(ChatBotContent, {}) }) }));
|
|
16
17
|
}
|
|
17
18
|
function ChatBotContent() {
|
|
18
|
-
var _a, _b
|
|
19
|
+
var _a, _b;
|
|
19
20
|
const anchorEl = useRef(null);
|
|
20
21
|
useSessionState({ autoLoad: true });
|
|
21
|
-
const {
|
|
22
|
+
const { aid } = useRuntimeState();
|
|
23
|
+
const { appearancePage } = useAppearances({ aid });
|
|
24
|
+
const profile = useProfile({ aid });
|
|
22
25
|
const [open, setOpen] = useState(false);
|
|
23
26
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
24
|
-
return (_jsxs(Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: 'modal' }, children: [_jsx(Fab, { sx: { width: 44, height: 44, boxShadow: open ? 0 : undefined }, onClick: () => setOpen(true), children: _jsx(Avatar, { size: 44, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src:
|
|
27
|
+
return (_jsxs(Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: 'modal' }, children: [_jsx(Fab, { sx: { width: 44, height: 44, boxShadow: open ? 0 : undefined }, onClick: () => setOpen(true), children: _jsx(Avatar, { size: 44, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: profile.avatar }) }), _jsx(Stack, { width: "100%", ref: anchorEl }), anchorEl.current && (_jsx(ResponsiveChatBotContainer, { anchorEl: anchorEl.current, open: open, onClose: () => setOpen(false), children: _jsx(ScrollView, { initialScrollBehavior: "auto", component: Stack, sx: {
|
|
25
28
|
overscrollBehavior: 'contain',
|
|
26
29
|
height: '100%',
|
|
27
30
|
width: '100%',
|
|
@@ -34,12 +37,12 @@ function ChatBotContent() {
|
|
|
34
37
|
function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
|
|
35
38
|
const theme = useTheme();
|
|
36
39
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
37
|
-
const {
|
|
38
|
-
const
|
|
40
|
+
const { aid } = useRuntimeState();
|
|
41
|
+
const profile = useProfile({ aid });
|
|
39
42
|
if (isMobile) {
|
|
40
|
-
return (_jsx(ChatBotDialog, { title:
|
|
43
|
+
return (_jsx(ChatBotDialog, { title: profile.name, open: open, onClose: onClose, children: children }));
|
|
41
44
|
}
|
|
42
|
-
return (_jsx(ChatBotPopper, { anchorEl: anchorEl, title:
|
|
45
|
+
return (_jsx(ChatBotPopper, { anchorEl: anchorEl, title: profile.name, open: open, onClose: onClose, children: children }));
|
|
43
46
|
}
|
|
44
47
|
function ChatBotPopper({ title, anchorEl, open, children, onClose, }) {
|
|
45
48
|
return (_jsx(Popper, { anchorEl: anchorEl, open: open, disablePortal: true, placement: "top-end", sx: {
|
|
@@ -2,33 +2,36 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { Box, useMediaQuery, useTheme } from '@mui/material';
|
|
3
3
|
import { useEffect } from 'react';
|
|
4
4
|
import { Helmet } from 'react-helmet';
|
|
5
|
+
import { joinURL } from 'ufo';
|
|
5
6
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
6
7
|
import { Avatar, DID } from '../../../../arcblock/ux';
|
|
7
8
|
import { useLocaleContext } from '../../../../locale';
|
|
8
9
|
import { useHeaderState } from '../../../../page/header';
|
|
10
|
+
import { getComponentMountPoint } from '../../../../utils';
|
|
9
11
|
import RuntimeCommonProvider, { RuntimeLocaleProvider } from '../../components/RuntimeCommonProvider';
|
|
10
12
|
import SocialShare from '../../components/SocialShare';
|
|
11
|
-
import { DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
13
|
+
import { AI_STUDIO_DID, DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
12
14
|
import { RuntimeProviderFromUrl } from '../../contexts/Runtime';
|
|
15
|
+
import useAppearances from '../../hooks/use-appearances';
|
|
13
16
|
import { useRuntimeState } from '../../state/runtime';
|
|
14
17
|
const logoSize = 44;
|
|
15
|
-
function AgentCreatedBy({
|
|
18
|
+
function AgentCreatedBy({ did }) {
|
|
16
19
|
const { t } = useLocaleContext();
|
|
17
|
-
return (_jsxs(_Fragment, { children: [t('by'), " ", _jsx(Box, { component: DID, did:
|
|
20
|
+
return (_jsxs(_Fragment, { children: [t('by'), " ", _jsx(Box, { component: DID, did: did, copyable: false, responsive: true })] }));
|
|
18
21
|
}
|
|
19
22
|
export default function Runtime() {
|
|
20
23
|
return (_jsx(RuntimeProviderFromUrl, { children: _jsx(RuntimeView, {}) }));
|
|
21
24
|
}
|
|
22
25
|
function RuntimeView() {
|
|
23
26
|
var _a;
|
|
24
|
-
const {
|
|
27
|
+
const { aid, agent } = useRuntimeState();
|
|
28
|
+
const { appearancePage } = useAppearances({ aid });
|
|
25
29
|
const theme = useTheme();
|
|
26
30
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
27
31
|
const { locale } = useLocaleContext();
|
|
28
32
|
useEffect(() => {
|
|
29
33
|
useHeaderState.setState((state) => {
|
|
30
|
-
|
|
31
|
-
const logo = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _a === void 0 ? void 0 : _a.url;
|
|
34
|
+
const logo = joinURL(window.location.origin, getComponentMountPoint(AI_STUDIO_DID), '/api/projects', agent.project.id, '/logo.png');
|
|
32
35
|
state.logo = logo && (_jsx(Box, { component: Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: logoSize, sx: {
|
|
33
36
|
width: logoSize,
|
|
34
37
|
height: logoSize,
|
|
@@ -37,7 +40,7 @@ function RuntimeView() {
|
|
|
37
40
|
state.brand = (_jsx(Box, { sx: {
|
|
38
41
|
height: 18,
|
|
39
42
|
fontSize: 18,
|
|
40
|
-
}, children:
|
|
43
|
+
}, children: agent.project.name }));
|
|
41
44
|
state.description = agent.createdBy && (_jsx(RuntimeLocaleProvider, { children: _jsx(Box, { sx: {
|
|
42
45
|
display: 'inline-flex',
|
|
43
46
|
alignItems: 'center',
|
|
@@ -45,7 +48,7 @@ function RuntimeView() {
|
|
|
45
48
|
mt: 0.5,
|
|
46
49
|
height: 12,
|
|
47
50
|
fontSize: 12,
|
|
48
|
-
}, children: _jsx(AgentCreatedBy, {
|
|
51
|
+
}, children: _jsx(AgentCreatedBy, { did: agent.project.createdBy }) }) }));
|
|
49
52
|
}
|
|
50
53
|
const shareContent = `${agent.name}
|
|
51
54
|
|
|
@@ -61,7 +64,7 @@ function RuntimeView() {
|
|
|
61
64
|
state.addons = (...exists) => [...exists];
|
|
62
65
|
});
|
|
63
66
|
};
|
|
64
|
-
}, [
|
|
67
|
+
}, [locale, isMobile, agent]);
|
|
65
68
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
66
|
-
return (_jsxs(RuntimeCommonProvider, { children: [
|
|
69
|
+
return (_jsxs(RuntimeCommonProvider, { 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.componentProps })] }));
|
|
67
70
|
}
|
|
@@ -20,6 +20,7 @@ import { Avatar } from '../../../../arcblock/ux';
|
|
|
20
20
|
import { useSessionContext } from '../../../../session';
|
|
21
21
|
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
22
22
|
import ShareActions from '../../components/ShareActions';
|
|
23
|
+
import { useProfile } from '../../hooks/use-appearances';
|
|
23
24
|
import { useRuntimeState } from '../../state/runtime';
|
|
24
25
|
import MessageErrorView from './MessageErrorView';
|
|
25
26
|
import MessageMetadataRenderer from './MessageMetadataRenderer';
|
|
@@ -82,13 +83,14 @@ function UserMessage({ message, hideAvatar }) {
|
|
|
82
83
|
}, children: [!hideAvatar && (_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 })] })] }));
|
|
83
84
|
}
|
|
84
85
|
function AgentMessage({ message, hideAvatar }) {
|
|
85
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
86
|
-
const {
|
|
86
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
87
|
+
const { aid } = useRuntimeState();
|
|
88
|
+
const profile = useProfile({ aid });
|
|
87
89
|
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));
|
|
88
90
|
const isMessageLoading = (message.loading || !message.result) && !message.error;
|
|
89
91
|
const theme = useTheme();
|
|
90
92
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
91
|
-
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:
|
|
93
|
+
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: 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: {
|
|
92
94
|
popper: {
|
|
93
95
|
disablePortal: true,
|
|
94
96
|
modifiers: [
|
|
@@ -104,13 +106,13 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
104
106
|
sx: { p: 0, bgcolor: 'white' },
|
|
105
107
|
},
|
|
106
108
|
}, title: !isMessageLoading &&
|
|
107
|
-
((
|
|
109
|
+
((_e = message.result) === null || _e === void 0 ? void 0 : _e.content) && (_jsx(ShareActions, { sx: {
|
|
108
110
|
fontSize: '1rem',
|
|
109
111
|
boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
|
|
110
112
|
border: '1px solid rgba(229, 231, 235, 1)',
|
|
111
113
|
borderRadius: 1,
|
|
112
114
|
p: 0.25,
|
|
113
|
-
} })), children: _jsxs(Stack, { gap: 1, className: "message-response", children: [(
|
|
115
|
+
} })), children: _jsxs(Stack, { gap: 1, className: "message-response", children: [(_g = (_f = message.result) === null || _f === void 0 ? void 0 : _f.messages) === null || _g === void 0 ? void 0 : _g.map((childMsg, index) => {
|
|
114
116
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
115
117
|
return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
|
|
116
118
|
!((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
|
|
@@ -118,16 +120,17 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
118
120
|
message.result.messages.length - 1 === index
|
|
119
121
|
? 'writing'
|
|
120
122
|
: '', 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;
|
|
121
|
-
}), ((
|
|
123
|
+
}), ((_h = message.result) === null || _h === void 0 ? void 0 : _h.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) })) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
|
|
122
124
|
// only response with loading
|
|
123
|
-
className: "message-response" }))), (
|
|
125
|
+
className: "message-response" }))), (_k = (_j = message.result) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId))), message.error && _jsx(MessageErrorView, { error: message.error })] })] })] }));
|
|
124
126
|
}
|
|
125
127
|
export function MessageItemWrapper(_a) {
|
|
126
|
-
var _b
|
|
128
|
+
var _b;
|
|
127
129
|
var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
|
|
128
|
-
const {
|
|
130
|
+
const { aid } = useRuntimeState();
|
|
131
|
+
const profile = useProfile({ aid });
|
|
129
132
|
const [time] = useState(() => new Date().toISOString());
|
|
130
|
-
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:
|
|
133
|
+
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] })] })) })));
|
|
131
134
|
}
|
|
132
135
|
function MessageUserName({ children }) {
|
|
133
136
|
return (_jsx(Typography, { component: "div", noWrap: true, sx: {
|
package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js
CHANGED
|
@@ -6,10 +6,13 @@ import { useMemo } from 'react';
|
|
|
6
6
|
import ReferenceLinks from './ReferenceLinks';
|
|
7
7
|
export default function MessageMetadataRenderer({ object }) {
|
|
8
8
|
const referenceLinks = object[RuntimeOutputVariable.referenceLinks];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
9
|
+
// 方便后续添加 metadata
|
|
10
|
+
const formattedObject = useMemo(() => {
|
|
11
|
+
const imagesList = object[RuntimeOutputVariable.images];
|
|
12
|
+
const images = (Array.isArray(imagesList) ? imagesList.map((i) => ({ src: i.url })) : []).filter((i) => typeof i.src === 'string');
|
|
13
|
+
return {
|
|
14
|
+
images: (images === null || images === void 0 ? void 0 : images.length) ? images : undefined,
|
|
15
|
+
};
|
|
13
16
|
}, [object]);
|
|
14
|
-
return (_jsxs(_Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? _jsx(ReferenceLinks, { links: referenceLinks }) : undefined, images && (_jsx(Stack, { gap: 1, children: _jsx(ImagePreview, { dataSource: images, itemWidth: 100 }) }))] }));
|
|
17
|
+
return (_jsxs(_Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? _jsx(ReferenceLinks, { links: referenceLinks }) : undefined, (formattedObject === null || formattedObject === void 0 ? void 0 : formattedObject.images) && (_jsx(Stack, { gap: 1, children: _jsx(ImagePreview, { dataSource: formattedObject.images, itemWidth: 100 }) }))] }));
|
|
15
18
|
}
|
|
@@ -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));
|