@blocklet/pages-kit 0.2.316 → 0.2.317
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/MarkdownRenderer.js +26 -2
- package/lib/cjs/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/constants.js +34 -4
- package/lib/cjs/builtin/async/ai-runtime/contexts/ActiveAgent.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/contexts/ComponentPreferences.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +17 -3
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +60 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +50 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +13 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +46 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +2 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ShareView/index.js +16 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +25 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +73 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +58 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +33 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +23 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +20 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +28 -134
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +35 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +54 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -6
- package/lib/cjs/builtin/mui/material.js +4 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/inject-global-components.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +3 -2
- package/lib/esm/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/constants.js +32 -3
- package/lib/esm/builtin/async/ai-runtime/contexts/ActiveAgent.js +23 -0
- package/lib/esm/builtin/async/ai-runtime/contexts/ComponentPreferences.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
- package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +32 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +8 -1
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
- package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +54 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +44 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +24 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +40 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +20 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ShareView/index.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +44 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +30 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +18 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +14 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +20 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +25 -108
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +36 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +48 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -6
- package/lib/esm/builtin/mui/material.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/types/builtin/async/ai-runtime/components/OutputFieldContainer/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +14 -0
- package/lib/types/builtin/async/ai-runtime/contexts/ActiveAgent.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/contexts/ComponentPreferences.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentMessage.d.ts +6 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-header-menu.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +8 -1
- package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ImagesView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MarkdownView/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ShareView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/index.d.ts +13 -3
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +0 -1
- package/lib/types/builtin/mui/material.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -193
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -164
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +0 -11
|
@@ -0,0 +1,44 @@
|
|
|
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, IconButton, Stack } from '@mui/material';
|
|
15
|
+
import { useMemo } from 'react';
|
|
16
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
17
|
+
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
18
|
+
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
19
|
+
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
20
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
21
|
+
import { getOutputVariableInitialValue } from '../../utils/runtime-output-schema';
|
|
22
|
+
export default function InputsView(_a) {
|
|
23
|
+
var props = __rest(_a, []);
|
|
24
|
+
const { activeAgentId, setActiveAgentId } = useActiveAgent();
|
|
25
|
+
const { agent } = useRuntimeState();
|
|
26
|
+
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]);
|
|
27
|
+
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [children && children.length > 1 && (_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: activeAgentId === child.id, onClick: () => setActiveAgentId(child.id) }) }))) })), _jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(AgentInput, {}) }) })] })));
|
|
28
|
+
}
|
|
29
|
+
function AgentAvatar(_a) {
|
|
30
|
+
var _b;
|
|
31
|
+
var { selected } = _a, props = __rest(_a, ["selected"]);
|
|
32
|
+
const { appearanceInput } = useAppearances();
|
|
33
|
+
const profile = useProfile();
|
|
34
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
35
|
+
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) }) })));
|
|
37
|
+
}
|
|
38
|
+
function AgentInput() {
|
|
39
|
+
const { aid } = useCurrentAgent();
|
|
40
|
+
const { appearanceInput } = useAppearances({ aid });
|
|
41
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
42
|
+
return null;
|
|
43
|
+
return (_jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Stack } from '@mui/material';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
5
|
+
import { useSessionContext } from '../../../../session';
|
|
6
|
+
import UserInfo from '../../components/UserInfo';
|
|
7
|
+
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
8
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
9
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
10
|
+
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
11
|
+
import UserMessageView from './UserMessageView';
|
|
12
|
+
const MessageView = memo(({ message }) => {
|
|
13
|
+
var _a, _b, _c, _d, _e;
|
|
14
|
+
const { session: authSession } = useSessionContext();
|
|
15
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
16
|
+
const profile = useProfile({ agentId: message.assistantId });
|
|
17
|
+
const { hideAgentAvatar, hideUserInputs } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
18
|
+
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
19
|
+
return null;
|
|
20
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [!hideUserInputs && (_jsx(Box, { children: _jsx(UserInfo, { name: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.fullName, did: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.did, avatar: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: _jsx(Stack, { sx: { alignItems: 'flex-end' }, children: _jsx(Box, { sx: {
|
|
21
|
+
borderRadius: 1,
|
|
22
|
+
borderTopRightRadius: '2px',
|
|
23
|
+
px: 2,
|
|
24
|
+
py: 1,
|
|
25
|
+
marginTop: 0.5,
|
|
26
|
+
maxWidth: 'calc(100% - 40px)',
|
|
27
|
+
bgcolor: 'rgba(239, 246, 255, 1)',
|
|
28
|
+
}, children: _jsx(UserMessageView, {}) }) }) }) })), _jsx(Box, { children: !hideAgentAvatar ? (_jsx(UserInfo, { name: profile.name, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) })) : (_jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties })) })] }) }) }));
|
|
29
|
+
});
|
|
30
|
+
export default MessageView;
|
|
@@ -0,0 +1,27 @@
|
|
|
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Divider, Stack } from '@mui/material';
|
|
14
|
+
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
15
|
+
import { useCurrentSessionState, useSessionState } from '../../state/session';
|
|
16
|
+
import MessageView from './MessageView';
|
|
17
|
+
import OpeningMessageView from './OpeningMessageView';
|
|
18
|
+
import OpeningQuestionsView from './OpeningQuestionsView';
|
|
19
|
+
export default function MessagesView(_a) {
|
|
20
|
+
var _b;
|
|
21
|
+
var props = __rest(_a, []);
|
|
22
|
+
const messages = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
|
|
23
|
+
const loaded = useSessionState((s) => s.loaded);
|
|
24
|
+
const showOpening = useCurrentSessionState((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
|
|
25
|
+
const divider = (_b = useComponentPreferences()) === null || _b === void 0 ? void 0 : _b.divider;
|
|
26
|
+
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && _jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message, index) => (_jsxs(_Fragment, { children: [_jsx(MessageView, { message: message }, message.taskId), divider && index !== messages.length - 1 ? _jsx(Divider, { sx: { my: 2 } }) : undefined] }))), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
|
|
27
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { memo, useMemo } from 'react';
|
|
4
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
5
|
+
import UserInfo from '../../components/UserInfo';
|
|
6
|
+
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
7
|
+
import { useOpeningMessage } from '../../hooks/use-appearances';
|
|
8
|
+
const OpeningMessageView = memo(() => {
|
|
9
|
+
var _a, _b, _c, _d, _e;
|
|
10
|
+
const { hideAgentAvatar } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
11
|
+
const opening = useOpeningMessage();
|
|
12
|
+
const output = useMemo(() => { var _a; return (_a = opening === null || opening === void 0 ? void 0 : opening.agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.openingMessage); }, [opening === null || opening === void 0 ? void 0 : opening.agent]);
|
|
13
|
+
const componentId = (_b = output === null || output === void 0 ? void 0 : output.appearance) === null || _b === void 0 ? void 0 : _b.componentId;
|
|
14
|
+
if (!output || !(opening === null || opening === void 0 ? void 0 : opening.message) || !componentId)
|
|
15
|
+
return null;
|
|
16
|
+
return hideAgentAvatar ? (_jsx(CustomComponentRenderer, { instanceId: output.id, componentId: componentId, properties: (_c = output.appearance) === null || _c === void 0 ? void 0 : _c.componentProperties, props: { output, outputValue: opening.message } })) : (_jsx(UserInfo, { name: opening.profile.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { instanceId: output.id, componentId: componentId, properties: (_e = output.appearance) === null || _e === void 0 ? void 0 : _e.componentProperties, props: { output, outputValue: opening.message } }) }));
|
|
17
|
+
});
|
|
18
|
+
export default OpeningMessageView;
|
package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
5
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
6
|
+
export default function OpeningQuestionsView() {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const { agent } = useCurrentAgent();
|
|
9
|
+
const output = useMemo(() => { var _a; return (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.openingQuestions); }, [agent.outputVariables]);
|
|
10
|
+
const componentId = (_a = output === null || output === void 0 ? void 0 : output.appearance) === null || _a === void 0 ? void 0 : _a.componentId;
|
|
11
|
+
if (!componentId)
|
|
12
|
+
return null;
|
|
13
|
+
return (_jsx(CustomComponentRenderer, { instanceId: output.id, componentId: componentId, properties: (_b = output.appearance) === null || _b === void 0 ? void 0 : _b.componentProperties, props: { output } }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
5
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
6
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
7
|
+
import { isValidInput } from '../../utils/agent-inputs';
|
|
8
|
+
export default function UserMessageView() {
|
|
9
|
+
var _a;
|
|
10
|
+
const { message } = useCurrentMessage();
|
|
11
|
+
const { agent } = useCurrentAgent();
|
|
12
|
+
const params = useMemo(() => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => { var _a, _b; return [((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || i.key, (_b = message.parameters) === null || _b === void 0 ? void 0 : _b[i.key]]; }).filter((i) => i[1]);
|
|
15
|
+
}, [agent.parameters, message.parameters]);
|
|
16
|
+
if ((params === null || params === void 0 ? void 0 : params.length) === 1) {
|
|
17
|
+
return _jsx(MarkdownRenderer, { children: (_a = params[0]) === null || _a === void 0 ? void 0 : _a[1] });
|
|
18
|
+
}
|
|
19
|
+
return params === null || params === void 0 ? void 0 : params.map(([key, value]) => (_jsxs(Typography, { sx: { wordWrap: 'break-word' }, children: [_jsx(Box, { component: "span", sx: { color: 'text.secondary' }, children: key }), "\u00A0\u00A0", _jsx("span", { children: value })] }, key)));
|
|
20
|
+
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
2
|
var t = {};
|
|
12
3
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -19,29 +10,22 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
10
|
return t;
|
|
20
11
|
};
|
|
21
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import { Box, IconButton, ListItemIcon, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
|
|
25
|
-
import { memo, useEffect, useMemo } from 'react';
|
|
13
|
+
import { ThemeProvider, alpha, createTheme, useTheme } from '@mui/material';
|
|
14
|
+
import { useEffect, useMemo } from 'react';
|
|
26
15
|
import { useScrollToBottom } from 'react-scroll-to-bottom';
|
|
27
|
-
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
28
|
-
import { useLocaleContext } from '../../../../locale';
|
|
29
|
-
import { useHeader } from '../../../../page/header';
|
|
30
|
-
import { useSessionContext } from '../../../../session';
|
|
31
16
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
32
17
|
import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
33
|
-
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
34
|
-
import PopperMenuButton from '../../components/PopperMenuButton';
|
|
35
|
-
import LoadingMenuItem from '../../components/PopperMenuButton/LoadingMenuItem';
|
|
36
18
|
import ScrollView from '../../components/ScrollView';
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
41
|
-
import {
|
|
42
|
-
import
|
|
43
|
-
import
|
|
44
|
-
|
|
19
|
+
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
20
|
+
import { ComponentPreferencesProvider } from '../../contexts/ComponentPreferences';
|
|
21
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
22
|
+
import { useHeaderMenu } from '../../hooks/use-header-menu';
|
|
23
|
+
import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
|
|
24
|
+
import BackgroundImage from './BackgroundImage';
|
|
25
|
+
import InputsView from './InputsView';
|
|
26
|
+
import MessagesView from './MessagesView';
|
|
27
|
+
export default function SimpleChat(_a) {
|
|
28
|
+
var { primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' } } = _a, preferences = __rest(_a, ["primaryColor", "scrollViewProps"]);
|
|
45
29
|
useAutoLoadSessionState();
|
|
46
30
|
const inheritedTheme = useTheme();
|
|
47
31
|
const theme = useMemo(() => {
|
|
@@ -61,11 +45,10 @@ export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: '
|
|
|
61
45
|
},
|
|
62
46
|
});
|
|
63
47
|
}, [inheritedTheme, primaryColor]);
|
|
64
|
-
return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children:
|
|
48
|
+
return (_jsx(ComponentPreferencesProvider, Object.assign({}, preferences, { children: _jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsxs(ThemeProvider, { theme: theme, children: [_jsx(BackgroundImage, {}), _jsx(SimpleChatView, {})] }) })) })));
|
|
65
49
|
}
|
|
66
|
-
function SimpleChatView(
|
|
67
|
-
const {
|
|
68
|
-
const { childAgentId } = useRuntimeState();
|
|
50
|
+
function SimpleChatView() {
|
|
51
|
+
const { activeAgentId } = useActiveAgent();
|
|
69
52
|
// auto scroll to bottom when new message is sent
|
|
70
53
|
const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
|
|
71
54
|
const scrollToBottom = useScrollToBottom();
|
|
@@ -73,80 +56,14 @@ function SimpleChatView({ hideHeaderMenuButton }) {
|
|
|
73
56
|
if (running)
|
|
74
57
|
scrollToBottom({ behavior: 'smooth' });
|
|
75
58
|
}, [scrollToBottom, running]);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
function AgentInputRender(_a) {
|
|
88
|
-
var props = __rest(_a, []);
|
|
89
|
-
const { appearanceInput } = useAppearances();
|
|
90
|
-
if (!appearanceInput.componentId)
|
|
91
|
-
return null;
|
|
92
|
-
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
93
|
-
}
|
|
94
|
-
function OutputView(_a) {
|
|
95
|
-
var props = __rest(_a, []);
|
|
96
|
-
const messages = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
|
|
97
|
-
const loaded = useSessionState((s) => s.loaded);
|
|
98
|
-
const showOpening = useCurrentSessionState((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
|
|
99
|
-
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
100
|
-
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && _jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage }), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
|
|
101
|
-
}
|
|
102
|
-
const OutputItemView = memo(({ message }) => {
|
|
103
|
-
var _a, _b, _c, _d;
|
|
104
|
-
const { session: authSession } = useSessionContext();
|
|
105
|
-
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
106
|
-
const profile = useProfile({ agentId: message.assistantId });
|
|
107
|
-
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
108
|
-
return null;
|
|
109
|
-
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: {
|
|
110
|
-
renderType: 'parameters',
|
|
111
|
-
} }) }) }), _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: {
|
|
112
|
-
renderType: 'result',
|
|
113
|
-
} }) }) })] }) }) }));
|
|
114
|
-
});
|
|
115
|
-
function SuggestedQuestionsView({ message }) {
|
|
116
|
-
const { aid } = useCurrentAgent({ agentId: message.assistantId });
|
|
117
|
-
const { execute } = useRuntimeState();
|
|
118
|
-
const suggestedQuestions = useMemo(() => {
|
|
119
|
-
var _a, _b, _c;
|
|
120
|
-
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];
|
|
121
|
-
}, [message]);
|
|
122
|
-
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) => {
|
|
123
|
-
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
124
|
-
} })) : null }));
|
|
125
|
-
}
|
|
126
|
-
const OpeningMessageView = memo(() => {
|
|
127
|
-
var _a;
|
|
128
|
-
const { childAgentId } = useRuntimeState();
|
|
129
|
-
const opening = useOpeningMessage({ agentId: childAgentId });
|
|
130
|
-
if (!(opening === null || opening === void 0 ? void 0 : opening.message))
|
|
131
|
-
return null;
|
|
132
|
-
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: {
|
|
133
|
-
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
134
|
-
borderRadius: 1,
|
|
135
|
-
borderTopLeftRadius: 2,
|
|
136
|
-
px: 2,
|
|
137
|
-
py: 1,
|
|
138
|
-
mt: 0.5,
|
|
139
|
-
mr: 5,
|
|
140
|
-
}, children: _jsx(MarkdownRenderer, { children: opening.message }) }) }) }));
|
|
141
|
-
});
|
|
142
|
-
function OpeningQuestionsView() {
|
|
143
|
-
const { execute } = useRuntimeState();
|
|
144
|
-
const { childAgentId } = useRuntimeState();
|
|
145
|
-
const { aid } = useCurrentAgent({ agentId: childAgentId });
|
|
146
|
-
const opening = useOpeningQuestions({ aid });
|
|
147
|
-
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
148
|
-
return null;
|
|
149
|
-
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
150
|
-
return (_jsx(MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
151
|
-
}) }) }));
|
|
59
|
+
useHeaderMenu();
|
|
60
|
+
return (_jsxs(SimpleLayout, { children: [_jsx(SimpleHeader, { px: 2 }), _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(MessagesView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10 }) }), _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(InputsView, { className: "aigne-inputs aigne-simple-chat-inputs", sx: {
|
|
61
|
+
position: 'sticky',
|
|
62
|
+
bottom: 0,
|
|
63
|
+
p: 2,
|
|
64
|
+
zIndex: 10,
|
|
65
|
+
borderRadius: 1,
|
|
66
|
+
bgcolor: (theme) => alpha(theme.palette.background.paper, 0.7),
|
|
67
|
+
backdropFilter: 'blur(10px)',
|
|
68
|
+
} }) })] }));
|
|
152
69
|
}
|
|
@@ -1,15 +1,41 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
2
3
|
import { Stack } from '@mui/material';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
6
|
+
import { getDefaultOutputComponent } from '../../constants';
|
|
7
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
5
8
|
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
const ignoredOutputs = new Set([
|
|
10
|
+
RuntimeOutputVariable.appearancePage,
|
|
11
|
+
RuntimeOutputVariable.appearanceInput,
|
|
12
|
+
RuntimeOutputVariable.appearanceOutput,
|
|
13
|
+
RuntimeOutputVariable.openingQuestions,
|
|
14
|
+
RuntimeOutputVariable.openingMessage,
|
|
15
|
+
]);
|
|
8
16
|
export default function SimpleOutput() {
|
|
9
|
-
var _a, _b, _c;
|
|
10
17
|
const { message } = useCurrentMessage();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
18
|
+
if (message.error)
|
|
19
|
+
throw message.error;
|
|
20
|
+
const { agent } = useCurrentAgent();
|
|
21
|
+
const outputs = useMemo(() => {
|
|
22
|
+
var _a;
|
|
23
|
+
return (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.map((i) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return (Object.assign(Object.assign({}, i), { appearance: Object.assign(Object.assign({}, i.appearance), { componentId: ((_a = i.appearance) === null || _a === void 0 ? void 0 : _a.componentId) || ((_b = getDefaultOutputComponent(i)) === null || _b === void 0 ? void 0 : _b.componentId) }) }));
|
|
26
|
+
}).filter((i) => { var _a; return !!((_a = i.appearance) === null || _a === void 0 ? void 0 : _a.componentId) && !ignoredOutputs.has(i.name); });
|
|
27
|
+
}, [agent.outputVariables]);
|
|
28
|
+
if (!(outputs === null || outputs === void 0 ? void 0 : outputs.length))
|
|
29
|
+
return null;
|
|
30
|
+
return (_jsx(Stack, { gap: 2, children: outputs.map((output) => {
|
|
31
|
+
var _a, _b, _c, _d, _e;
|
|
32
|
+
const value = output.name === RuntimeOutputVariable.text
|
|
33
|
+
? (_a = message.result) === null || _a === void 0 ? void 0 : _a.content
|
|
34
|
+
: (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e[output.name];
|
|
35
|
+
return (_jsx(CustomComponentRenderer, { instanceId: output.id, componentId: output.appearance.componentId, properties: output.appearance.componentProperties, props: {
|
|
36
|
+
output,
|
|
37
|
+
outputValue: value,
|
|
38
|
+
writing: output.name === RuntimeOutputVariable.text && message.loading,
|
|
39
|
+
} }, output.id));
|
|
40
|
+
}) }));
|
|
15
41
|
}
|
|
@@ -16,13 +16,13 @@ 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 { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
19
20
|
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
20
21
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
22
|
import useAppearances from '../../hooks/use-appearances';
|
|
22
|
-
import { useRuntimeState } from '../../state/runtime';
|
|
23
23
|
import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
|
|
24
24
|
export default function SimplePage({ resultTitle, primaryColor }) {
|
|
25
|
-
const {
|
|
25
|
+
const { activeAgentId } = useActiveAgent();
|
|
26
26
|
useAutoLoadSessionState();
|
|
27
27
|
const inheritedTheme = useTheme();
|
|
28
28
|
const theme = useMemo(() => {
|
|
@@ -42,14 +42,14 @@ export default function SimplePage({ resultTitle, primaryColor }) {
|
|
|
42
42
|
},
|
|
43
43
|
});
|
|
44
44
|
}, [inheritedTheme, primaryColor]);
|
|
45
|
-
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(SimpleLayout, { pb: 4, children: [_jsx(SimpleHeader, {}), _jsx(CurrentAgentProvider, { agentId:
|
|
45
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(SimpleLayout, { pb: 4, children: [_jsx(SimpleHeader, {}), _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(AgentInputRender, { className: "aigne-inputs aigne-simple-page-inputs" }) }), _jsx(OutputView, { className: "aigne-outputs aigne-simple-page-outputs", resultTitle: resultTitle })] }) }));
|
|
46
46
|
}
|
|
47
47
|
function AgentInputRender(_a) {
|
|
48
48
|
var props = __rest(_a, []);
|
|
49
49
|
const { appearanceInput } = useAppearances();
|
|
50
50
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
51
51
|
return null;
|
|
52
|
-
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.
|
|
52
|
+
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }) })));
|
|
53
53
|
}
|
|
54
54
|
function OutputView(_a) {
|
|
55
55
|
var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
|
|
@@ -60,5 +60,5 @@ const OutputItemView = memo(({ message }) => {
|
|
|
60
60
|
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
61
61
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
62
62
|
return null;
|
|
63
|
-
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.
|
|
63
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }) }) }));
|
|
64
64
|
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Stack, Typography } from '@mui/material';
|
|
14
|
+
import Joi from 'joi';
|
|
15
|
+
import { useMemo } from 'react';
|
|
16
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
17
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
18
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
19
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
20
|
+
import { useCurrentSessionState } from '../../state/session';
|
|
21
|
+
const suggestedQuestionsSchema = Joi.array().items(Joi.object({
|
|
22
|
+
question: Joi.string().required(),
|
|
23
|
+
}));
|
|
24
|
+
export default function SuggestedQuestionsView({ output, outputValue, onlyLastMessage, }) {
|
|
25
|
+
var _a;
|
|
26
|
+
const { message } = (_a = useCurrentMessage({ optional: true })) !== null && _a !== void 0 ? _a : {};
|
|
27
|
+
const lastMessage = useCurrentSessionState((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
28
|
+
const isLastMessage = !!message && message.taskId === (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.taskId);
|
|
29
|
+
const questions = useMemo(() => {
|
|
30
|
+
const result = suggestedQuestionsSchema.validate(outputValue, { allowUnknown: true });
|
|
31
|
+
if (result.error)
|
|
32
|
+
return undefined;
|
|
33
|
+
return result.value;
|
|
34
|
+
}, [outputValue]);
|
|
35
|
+
const { aid } = useCurrentAgent();
|
|
36
|
+
const { execute } = useRuntimeState();
|
|
37
|
+
if (!message || (!isLastMessage && onlyLastMessage) || !(questions === null || questions === void 0 ? void 0 : questions.length))
|
|
38
|
+
return null;
|
|
39
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(Stack, { gap: 1, children: questions.map((item) => (_jsx(MessageSuggestedQuestion, { onClick: () => {
|
|
40
|
+
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
41
|
+
}, children: item.question }, item.question))) }) }));
|
|
42
|
+
}
|
|
43
|
+
function MessageSuggestedQuestion(_a) {
|
|
44
|
+
var props = __rest(_a, []);
|
|
45
|
+
return (_jsx(Typography, Object.assign({ variant: "subtitle2" }, props, { sx: Object.assign({ display: 'inline-block', border: 1, borderColor: 'rgba(229, 231, 235, 1)', borderRadius: 1, py: 1, px: 2, cursor: 'pointer', '&:hover': {
|
|
46
|
+
backgroundColor: 'rgba(239, 246, 255, 1)',
|
|
47
|
+
} }, props.sx) })));
|
|
48
|
+
}
|
|
@@ -16,10 +16,10 @@ import dayjs from 'dayjs';
|
|
|
16
16
|
// import { Icon } from 'iconify/react';
|
|
17
17
|
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
|
|
18
18
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
19
|
+
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
19
20
|
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
20
21
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
22
|
import useAppearances from '../../hooks/use-appearances';
|
|
22
|
-
import { useRuntimeState } from '../../state/runtime';
|
|
23
23
|
import { useAutoLoadSessionState, useCurrentSessionState } from '../../state/session';
|
|
24
24
|
const getLineClamp = (count) => {
|
|
25
25
|
return {
|
|
@@ -52,7 +52,7 @@ function V0Page({ textColor = '#333', primaryColor }) {
|
|
|
52
52
|
}, [inheritedTheme, primaryColor, textColor]);
|
|
53
53
|
const [sessionId] = useState('1');
|
|
54
54
|
const [message, setMessage] = useState();
|
|
55
|
-
const {
|
|
55
|
+
const { activeAgentId } = useActiveAgent();
|
|
56
56
|
useAutoLoadSessionState();
|
|
57
57
|
const messagesList = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
|
|
58
58
|
useEffect(() => {
|
|
@@ -106,7 +106,7 @@ function V0Page({ textColor = '#333', primaryColor }) {
|
|
|
106
106
|
}
|
|
107
107
|
return (_jsx(Box, { flex: 1, children: _jsx(Grid, { container: true, spacing: 2, justifyContent: "center", children: [...Array(3)].map((_, i) => (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 4, children: _jsx(Card, { sx: { backgroundColor: 'rgba(0, 0, 0, 0.5)', color: '#fff' }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "body2", sx: { mb: 1 }, children: `Code Snippet ${i + 1}` }), _jsx(Typography, { variant: "caption", display: "block", sx: { color: 'rgba(255, 255, 255, 0.7)' }, children: `This is history requirement ${i + 1}` })] }) }) }, i))) }) }));
|
|
108
108
|
}, [JSON.stringify(message)]);
|
|
109
|
-
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId:
|
|
109
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsxs(Box, { sx: {
|
|
110
110
|
display: 'flex',
|
|
111
111
|
// background: 'linear-gradient(135deg, #1a237e 0%, #3c3f41 100%)',
|
|
112
112
|
}, children: [_jsx(SliderRender, { message: message }), _jsxs(Container, { sx: {
|
|
@@ -130,12 +130,12 @@ function AgentInputRender(_a) {
|
|
|
130
130
|
const { appearanceInput } = useAppearances();
|
|
131
131
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
132
132
|
return null;
|
|
133
|
-
return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceInput.componentId, properties: appearanceInput.
|
|
133
|
+
return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }, props)) }));
|
|
134
134
|
}
|
|
135
135
|
function AgentOutputRender(_a) {
|
|
136
136
|
var { message } = _a, props = __rest(_a, ["message"]);
|
|
137
137
|
const { appearanceOutput } = useAppearances();
|
|
138
138
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId) || !message)
|
|
139
139
|
return null;
|
|
140
|
-
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceOutput.componentId, properties: appearanceOutput.
|
|
140
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }, props)) }) }) }));
|
|
141
141
|
}
|
|
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
11
10
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
12
11
|
import { useSessionContext } from '../../../session';
|
|
13
12
|
import { useRuntimeContext } from '../contexts/Runtime';
|
|
@@ -39,9 +38,5 @@ export function useRuntimeState() {
|
|
|
39
38
|
}
|
|
40
39
|
return exec(Object.assign(Object.assign({}, args), { working }));
|
|
41
40
|
}), [authSession.user, exec, working, login]);
|
|
42
|
-
|
|
43
|
-
var _a, _b, _c, _d, _e, _f;
|
|
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);
|
|
45
|
-
}, [agent]);
|
|
46
|
-
return { aid, working, agent, childAgentId, execute };
|
|
41
|
+
return { aid, working, agent, execute };
|
|
47
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Alert, AlertTitle, Autocomplete, Avatar, Box, Button, IconButton, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';
|
|
1
|
+
export { Checkbox, ListItemText, Alert, AlertTitle, Autocomplete, Avatar, Box, Button, IconButton, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';
|