@blocklet/pages-kit 0.2.302 → 0.2.304
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 +3 -31
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +14 -8
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +8 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +18 -19
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +11 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +16 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +21 -20
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +8 -8
- package/lib/cjs/builtin/async/ai-runtime/state/agent.js +2 -4
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +9 -8
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +29 -16
- package/lib/cjs/builtin/async/ai-runtime/utils/agent-inputs.js +8 -0
- package/lib/cjs/builtin/async/ai-runtime/utils/zustand.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +3 -9
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +14 -8
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +9 -10
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +2 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +18 -18
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +12 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +17 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +22 -21
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +9 -9
- package/lib/esm/builtin/async/ai-runtime/state/agent.js +2 -4
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +9 -8
- package/lib/esm/builtin/async/ai-runtime/state/session.js +27 -15
- package/lib/esm/builtin/async/ai-runtime/utils/agent-inputs.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/utils/zustand.js +6 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +5 -3
- package/lib/types/builtin/async/ai-runtime/runtime-components/AutoForm/index.d.ts +0 -2
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +2 -3
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -2
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/utils/agent-inputs.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/utils/zustand.d.ts +2 -0
- package/package.json +5 -4
|
@@ -16,18 +16,19 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
16
16
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.createSessionState = void 0;
|
|
19
|
+
exports.useSessionState = exports.createSessionState = void 0;
|
|
20
20
|
const aid_1 = require("@blocklet/ai-runtime/common/aid");
|
|
21
|
+
const react_1 = require("react");
|
|
21
22
|
const zustand_1 = require("zustand");
|
|
22
23
|
const immer_1 = require("zustand/middleware/immer");
|
|
23
24
|
const message_1 = require("../api/message");
|
|
24
25
|
const session_1 = require("../api/session");
|
|
25
|
-
const
|
|
26
|
+
const Runtime_1 = require("../contexts/Runtime");
|
|
27
|
+
const zustand_2 = require("../utils/zustand");
|
|
26
28
|
const GET_MESSAGES_LIMIT = 100;
|
|
27
29
|
const GET_MESSAGES_ORDER_DIRECTION = 'desc';
|
|
28
30
|
const createSessionState = ({ aid }) => {
|
|
29
|
-
|
|
30
|
-
(_a = STATES[aid]) !== null && _a !== void 0 ? _a : (STATES[aid] = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
31
|
+
return (0, zustand_2.createCachedStore)(aid, () => (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
31
32
|
reset: () => {
|
|
32
33
|
set((state) => {
|
|
33
34
|
state.loading = undefined;
|
|
@@ -41,13 +42,13 @@ const createSessionState = ({ aid }) => {
|
|
|
41
42
|
});
|
|
42
43
|
},
|
|
43
44
|
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
var
|
|
45
|
+
var _a;
|
|
45
46
|
set((state) => {
|
|
46
47
|
state.loading = true;
|
|
47
48
|
});
|
|
48
49
|
try {
|
|
49
50
|
const { sessions } = yield (0, session_1.getSessions)({ aid });
|
|
50
|
-
const session = (
|
|
51
|
+
const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (yield (0, session_1.createSession)({ aid })).created;
|
|
51
52
|
const { messages } = yield (0, message_1.getMessages)({
|
|
52
53
|
sessionId: session.id,
|
|
53
54
|
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
@@ -73,7 +74,7 @@ const createSessionState = ({ aid }) => {
|
|
|
73
74
|
}
|
|
74
75
|
}),
|
|
75
76
|
loadMoreMessages: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
var
|
|
77
|
+
var _b;
|
|
77
78
|
set((state) => {
|
|
78
79
|
state.messageLoading = true;
|
|
79
80
|
});
|
|
@@ -83,7 +84,7 @@ const createSessionState = ({ aid }) => {
|
|
|
83
84
|
try {
|
|
84
85
|
const result = yield (0, message_1.getMessages)({
|
|
85
86
|
sessionId: session.id,
|
|
86
|
-
before: (
|
|
87
|
+
before: (_b = messages === null || messages === void 0 ? void 0 : messages.slice(-1)[0]) === null || _b === void 0 ? void 0 : _b.id,
|
|
87
88
|
orderDirection: GET_MESSAGES_ORDER_DIRECTION,
|
|
88
89
|
limit: GET_MESSAGES_LIMIT,
|
|
89
90
|
});
|
|
@@ -99,8 +100,8 @@ const createSessionState = ({ aid }) => {
|
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
}),
|
|
102
|
-
execute: (
|
|
103
|
-
var
|
|
103
|
+
execute: (_c) => __awaiter(void 0, [_c], void 0, function* ({ aid, working, parameters, onResponseStart, }) {
|
|
104
|
+
var _d, e_1, _e, _f;
|
|
104
105
|
let { session } = get();
|
|
105
106
|
if (!session) {
|
|
106
107
|
yield get().load();
|
|
@@ -124,10 +125,10 @@ const createSessionState = ({ aid }) => {
|
|
|
124
125
|
});
|
|
125
126
|
let responseStarted = false;
|
|
126
127
|
try {
|
|
127
|
-
for (var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const value =
|
|
128
|
+
for (var _g = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _d = stream_1_1.done, !_d; _g = true) {
|
|
129
|
+
_f = stream_1_1.value;
|
|
130
|
+
_g = false;
|
|
131
|
+
const value = _f;
|
|
131
132
|
if (!responseStarted) {
|
|
132
133
|
responseStarted = true;
|
|
133
134
|
onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
|
|
@@ -185,7 +186,7 @@ const createSessionState = ({ aid }) => {
|
|
|
185
186
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
186
187
|
finally {
|
|
187
188
|
try {
|
|
188
|
-
if (!
|
|
189
|
+
if (!_g && !_d && (_e = stream_1.return)) yield _e.call(stream_1);
|
|
189
190
|
}
|
|
190
191
|
finally { if (e_1) throw e_1.error; }
|
|
191
192
|
}
|
|
@@ -208,6 +209,18 @@ const createSessionState = ({ aid }) => {
|
|
|
208
209
|
}
|
|
209
210
|
}),
|
|
210
211
|
}))));
|
|
211
|
-
return STATES[aid];
|
|
212
212
|
};
|
|
213
213
|
exports.createSessionState = createSessionState;
|
|
214
|
+
function useSessionState({ autoLoad } = {}) {
|
|
215
|
+
const { aid } = (0, Runtime_1.useRuntimeContext)();
|
|
216
|
+
const state = (0, react_1.useMemo)(() => (0, exports.createSessionState)({ aid }), [aid]);
|
|
217
|
+
(0, react_1.useEffect)(() => {
|
|
218
|
+
if (!autoLoad)
|
|
219
|
+
return;
|
|
220
|
+
const { loading, loaded, load } = state.getState();
|
|
221
|
+
if (!loading && !loaded)
|
|
222
|
+
load();
|
|
223
|
+
}, [state, autoLoad]);
|
|
224
|
+
return state;
|
|
225
|
+
}
|
|
226
|
+
exports.useSessionState = useSessionState;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidInput = exports.USER_INPUT_PARAMETER_TYPES = void 0;
|
|
4
|
+
exports.USER_INPUT_PARAMETER_TYPES = ['string', 'number', 'select', 'language'];
|
|
5
|
+
function isValidInput(input) {
|
|
6
|
+
return !!input.key && exports.USER_INPUT_PARAMETER_TYPES.includes(input.type || 'string');
|
|
7
|
+
}
|
|
8
|
+
exports.isValidInput = isValidInput;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCachedStore = void 0;
|
|
4
|
+
const STATES = {};
|
|
5
|
+
function createCachedStore(key, creator) {
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = STATES[key]) !== null && _a !== void 0 ? _a : (STATES[key] = creator());
|
|
8
|
+
return STATES[key];
|
|
9
|
+
}
|
|
10
|
+
exports.createCachedStore = createCachedStore;
|
|
@@ -13,19 +13,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import { Icon } from '@iconify/react';
|
|
14
14
|
import { Box, Stack, styled } from '@mui/material';
|
|
15
15
|
import React from 'react';
|
|
16
|
+
import Markdown from 'react-markdown';
|
|
17
|
+
import remarkGfm from 'remark-gfm';
|
|
16
18
|
import { useLocaleContext } from '../../../locale';
|
|
17
|
-
import MarkdownAsync from '../../react-markdown';
|
|
18
19
|
import ReactSyntaxHighlighterAsync from '../../react-syntax-highlighter';
|
|
19
20
|
import ActionButton from './ActionButton';
|
|
20
21
|
const ReactSyntaxHighlighter = React.lazy(() => ReactSyntaxHighlighterAsync().then((m) => ({ default: m.Prism })));
|
|
21
|
-
const
|
|
22
|
-
MarkdownAsync(),
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
import('https://esm.sh/remark-gfm@4?bundle'),
|
|
25
|
-
]).then(([{ default: Markdown }, remark]) => ({
|
|
26
|
-
default: (props) => _jsx(Markdown, Object.assign({}, props, { remarkPlugins: [remark.default] })),
|
|
27
|
-
})));
|
|
28
|
-
const MarkdownRenderer = styled((props) => (_jsx(Markdown, Object.assign({}, props, { components: {
|
|
22
|
+
const MarkdownRenderer = styled((props) => (_jsx(Markdown, Object.assign({}, props, { remarkPlugins: [remarkGfm], components: {
|
|
29
23
|
pre: MarkdownPre,
|
|
30
24
|
code: (_a) => {
|
|
31
25
|
var { node, inline, className, children } = _a, props = __rest(_a, ["node", "inline", "className", "children"]);
|
|
@@ -5,21 +5,27 @@ import { createContext, useContext, useMemo } from 'react';
|
|
|
5
5
|
import { DEFAULT_INPUT_COMPONENT_ID, DEFAULT_OUTPUT_COMPONENT_ID } from '../constants';
|
|
6
6
|
import { useAgentState } from '../state/agent';
|
|
7
7
|
import { useRuntimeState } from '../state/runtime';
|
|
8
|
-
|
|
9
|
-
export default function CurrentAgentProvider({ agentId, children }) {
|
|
8
|
+
function useCurrentAid({ agentId }) {
|
|
10
9
|
const { aid } = useRuntimeState();
|
|
11
|
-
|
|
10
|
+
return useMemo(() => ({
|
|
12
11
|
aid: stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(aid, { rejectWhenError: true })), { assistantId: agentId })),
|
|
13
12
|
}), [aid, agentId]);
|
|
13
|
+
}
|
|
14
|
+
const context = createContext(undefined);
|
|
15
|
+
export default function CurrentAgentProvider({ agentId, children }) {
|
|
16
|
+
const state = useCurrentAid({ agentId });
|
|
14
17
|
return _jsx(context.Provider, { value: state, children: children });
|
|
15
18
|
}
|
|
16
|
-
export function useCurrentAgent() {
|
|
17
|
-
const { working } = useRuntimeState();
|
|
19
|
+
export function useCurrentAgent({ agentId } = {}) {
|
|
20
|
+
const { aid: runtimeAid, working } = useRuntimeState();
|
|
21
|
+
const aidFromParam = useMemo(() => agentId &&
|
|
22
|
+
stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(runtimeAid, { rejectWhenError: true })), { assistantId: agentId })), [agentId]);
|
|
18
23
|
const current = useContext(context);
|
|
19
|
-
|
|
24
|
+
const aid = aidFromParam !== null && aidFromParam !== void 0 ? aidFromParam : current === null || current === void 0 ? void 0 : current.aid;
|
|
25
|
+
if (!aid) {
|
|
20
26
|
throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
|
|
21
27
|
}
|
|
22
|
-
const [agent] = useAgentState({ aid
|
|
28
|
+
const [agent] = useAgentState({ aid, working });
|
|
23
29
|
const appearanceInput = useMemo(() => {
|
|
24
30
|
var _a, _b, _c;
|
|
25
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 };
|
|
@@ -28,5 +34,5 @@ export function useCurrentAgent() {
|
|
|
28
34
|
var _a, _b, _c;
|
|
29
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 };
|
|
30
36
|
}, [agent]);
|
|
31
|
-
return
|
|
37
|
+
return { aid, agent, appearanceInput, appearanceOutput };
|
|
32
38
|
}
|
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { Icon } from '@iconify/react';
|
|
3
3
|
import { ArrowBackIosNewRounded } from '@mui/icons-material';
|
|
4
4
|
import { Box, Button, CircularProgress, ClickAwayListener, Dialog, DialogContent, DialogTitle, Fab, IconButton, Popper, Stack, Typography, useMediaQuery, useTheme, } from '@mui/material';
|
|
5
|
-
import { Suspense,
|
|
5
|
+
import { Suspense, useRef, useState } from 'react';
|
|
6
6
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
7
7
|
import { Avatar } from '../../../../arcblock/ux';
|
|
8
8
|
import RuntimeCommonProvider from '../../components/RuntimeCommonProvider';
|
|
@@ -10,19 +10,18 @@ import ScrollView from '../../components/ScrollView';
|
|
|
10
10
|
import { DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
11
11
|
import RuntimeProvider from '../../contexts/Runtime';
|
|
12
12
|
import { useRuntimeState } from '../../state/runtime';
|
|
13
|
+
import { useSessionState } from '../../state/session';
|
|
13
14
|
export default function ChatBotButton({ aid, working }) {
|
|
14
15
|
return (_jsx(RuntimeProvider, { aid: aid, working: working, children: _jsx(RuntimeCommonProvider, { children: _jsx(ChatBotContent, {}) }) }));
|
|
15
16
|
}
|
|
16
17
|
function ChatBotContent() {
|
|
17
18
|
var _a, _b, _c;
|
|
18
19
|
const anchorEl = useRef(null);
|
|
19
|
-
|
|
20
|
+
useSessionState({ autoLoad: true });
|
|
21
|
+
const { appearancePage } = useRuntimeState();
|
|
20
22
|
const [open, setOpen] = useState(false);
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
sessionState.load();
|
|
23
|
-
}, []);
|
|
24
23
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
25
|
-
return (_jsxs(Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: '
|
|
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: (_c = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _c === void 0 ? void 0 : _c.url }) }), _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: {
|
|
26
25
|
overscrollBehavior: 'contain',
|
|
27
26
|
height: '100%',
|
|
28
27
|
width: '100%',
|
|
@@ -43,12 +42,12 @@ function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
|
|
|
43
42
|
return (_jsx(ChatBotPopper, { anchorEl: anchorEl, title: title, open: open, onClose: onClose, children: children }));
|
|
44
43
|
}
|
|
45
44
|
function ChatBotPopper({ title, anchorEl, open, children, onClose, }) {
|
|
46
|
-
return (_jsx(Popper, { anchorEl: anchorEl, open: open, placement: "top-end", sx: {
|
|
45
|
+
return (_jsx(Popper, { anchorEl: anchorEl, open: open, disablePortal: true, placement: "top-end", sx: {
|
|
47
46
|
zIndex: 'modal',
|
|
48
47
|
maxWidth: 500,
|
|
49
|
-
maxHeight: '
|
|
50
|
-
width:
|
|
51
|
-
height: '
|
|
48
|
+
maxHeight: 'min(calc(100vh - 128px), 1000px)',
|
|
49
|
+
width: 500,
|
|
50
|
+
height: '90vh',
|
|
52
51
|
}, children: _jsx(ClickAwayListener, { onClickAway: (e) => {
|
|
53
52
|
e.preventDefault();
|
|
54
53
|
e.stopPropagation();
|
|
@@ -21,7 +21,7 @@ export default function Runtime() {
|
|
|
21
21
|
}
|
|
22
22
|
function RuntimeView() {
|
|
23
23
|
var _a;
|
|
24
|
-
const { agent, appearancePage
|
|
24
|
+
const { agent, appearancePage } = useRuntimeState();
|
|
25
25
|
const theme = useTheme();
|
|
26
26
|
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
27
27
|
const { locale } = useLocaleContext();
|
|
@@ -61,10 +61,7 @@ function RuntimeView() {
|
|
|
61
61
|
state.addons = (...exists) => [...exists];
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
-
}, [appearancePage, locale, isMobile]);
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
sessionState.load();
|
|
67
|
-
}, []);
|
|
64
|
+
}, [appearancePage, locale, isMobile, agent]);
|
|
68
65
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
69
66
|
return (_jsxs(RuntimeCommonProvider, { children: [appearancePage && (_jsxs(Helmet, { children: [appearancePage.name && _jsx("title", { children: appearancePage.name }), appearancePage.description && _jsx("meta", { name: "description", content: appearancePage.description })] })), _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps })] }));
|
|
70
67
|
}
|
|
@@ -19,14 +19,16 @@ import AgentInputField from '../../components/AgentInputField';
|
|
|
19
19
|
import LoadingButton from '../../components/LoadingButton';
|
|
20
20
|
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
21
21
|
import { useRuntimeState } from '../../state/runtime';
|
|
22
|
-
|
|
22
|
+
import { useSessionState } from '../../state/session';
|
|
23
|
+
import { isValidInput } from '../../utils/agent-inputs';
|
|
23
24
|
export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
|
|
24
25
|
const { t } = useLocaleContext();
|
|
25
26
|
const { aid, agent } = useCurrentAgent();
|
|
26
|
-
const {
|
|
27
|
+
const { execute } = useRuntimeState();
|
|
28
|
+
const running = useSessionState()((s) => s.running);
|
|
27
29
|
const parameters = useMemo(() => {
|
|
28
30
|
var _a;
|
|
29
|
-
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(
|
|
31
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => {
|
|
30
32
|
var _a;
|
|
31
33
|
return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
|
|
32
34
|
});
|
|
@@ -38,7 +40,7 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
|
|
|
38
40
|
if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
|
|
39
41
|
form.reset(chatMode ? omit(defaultForm, 'question') : defaultForm);
|
|
40
42
|
}
|
|
41
|
-
}, [defaultForm, autoFillLastForm, form]);
|
|
43
|
+
}, [defaultForm, autoFillLastForm, form, chatMode]);
|
|
42
44
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
43
45
|
yield execute({
|
|
44
46
|
aid,
|
|
@@ -69,32 +71,30 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
|
|
|
69
71
|
var _a;
|
|
70
72
|
return (_jsxs(Stack, { className: "form-item", children: [parameter.label && _jsx(FormLabel, { children: parameter.label }), _jsx(AgentInputField, { inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: parameter.key === 'question' && submitInQuestionField
|
|
71
73
|
? {
|
|
72
|
-
endAdornment: (_jsx(InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: _jsx(LoadingButton, { type: "submit", variant: "contained", loading:
|
|
74
|
+
endAdornment: (_jsx(InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: _jsx(LoadingButton, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText }) })),
|
|
73
75
|
}
|
|
74
76
|
: undefined })] }));
|
|
75
77
|
} }) }, parameter.id));
|
|
76
|
-
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading:
|
|
78
|
+
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
|
|
77
79
|
}
|
|
78
80
|
function useInitialFormValues() {
|
|
79
|
-
var _a;
|
|
80
|
-
const [lastMessage, setLastMessage] = useState();
|
|
81
81
|
const { agent } = useCurrentAgent();
|
|
82
|
-
const {
|
|
82
|
+
const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
83
|
+
const [lastInputs, setLastInputs] = useState();
|
|
83
84
|
useEffect(() => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
if (!lastInputs) {
|
|
86
|
+
const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
|
|
87
|
+
if (!isEmpty(lastParameters))
|
|
88
|
+
setLastInputs(lastParameters);
|
|
87
89
|
}
|
|
88
|
-
}, [
|
|
90
|
+
}, [lastMessage]);
|
|
89
91
|
return useMemo(() => {
|
|
90
92
|
var _a, _b;
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
if (!isEmpty(lastParameters))
|
|
94
|
-
return lastParameters;
|
|
93
|
+
if (lastInputs) {
|
|
94
|
+
return lastInputs;
|
|
95
95
|
}
|
|
96
96
|
return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _b !== void 0 ? _b : []);
|
|
97
|
-
}, [
|
|
97
|
+
}, [lastInputs, agent]);
|
|
98
98
|
}
|
|
99
99
|
function useFormTheme() {
|
|
100
100
|
const theme = useTheme();
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Masonry } from '@mui/lab';
|
|
14
14
|
import { Box, Skeleton, Stack, ThemeProvider, Typography, createTheme, useTheme } from '@mui/material';
|
|
15
|
-
import { Suspense, useMemo, useRef } from 'react';
|
|
15
|
+
import { Suspense, memo, useMemo, useRef } from 'react';
|
|
16
16
|
import Balancer from 'react-wrap-balancer';
|
|
17
17
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
18
18
|
import { useLocaleContext } from '../../../../locale';
|
|
@@ -21,9 +21,11 @@ import LoadingButton from '../../components/LoadingButton';
|
|
|
21
21
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
22
22
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
23
23
|
import { useRuntimeState } from '../../state/runtime';
|
|
24
|
+
import { useSessionState } from '../../state/session';
|
|
24
25
|
import mapRight from '../../utils/map-right';
|
|
25
26
|
export default function PhotoGallery({ resultTitle, primaryColor }) {
|
|
26
27
|
const { childAgentId } = useRuntimeState();
|
|
28
|
+
useSessionState({ autoLoad: true });
|
|
27
29
|
const inheritedTheme = useTheme();
|
|
28
30
|
const theme = useMemo(() => {
|
|
29
31
|
let { primary } = inheritedTheme.palette;
|
|
@@ -55,19 +57,19 @@ function NoOutputs() {
|
|
|
55
57
|
return (_jsx(Stack, { mt: 10, children: _jsx(Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
|
|
56
58
|
}
|
|
57
59
|
function OutputView(_a) {
|
|
58
|
-
var _b, _c, _d
|
|
60
|
+
var _b, _c, _d;
|
|
59
61
|
var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
|
|
60
62
|
const { t } = useLocaleContext();
|
|
61
|
-
const { sessionState } = useRuntimeState();
|
|
62
63
|
const ref = useRef(null);
|
|
63
|
-
|
|
64
|
+
const { messages = [], running, loaded, noMoreMessage, loadMoreMessages } = useSessionState()();
|
|
65
|
+
return (_jsxs(Stack, Object.assign({ width: "100%", alignItems: "center", px: { xs: 2, sm: 3 }, mt: { xs: 2, sm: 3 } }, props, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h2", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), loaded && !messages.length && _jsx(NoOutputs, {}), _jsxs(Masonry, { ref: ref, columns: { xs: 2, sm: 3, md: 4, lg: 5 }, spacing: 1, sequential: true, sx: { width: '100%', overflow: 'hidden', '> *': { borderRadius: 1 } }, children: [running && (_jsx(Skeleton, { variant: "rectangular", sx: {
|
|
64
66
|
// FIXME: default using history height
|
|
65
|
-
height: (
|
|
66
|
-
} })), mapRight(
|
|
67
|
+
height: (_d = (_c = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.querySelector('*')) === null || _c === void 0 ? void 0 : _c.clientHeight) !== null && _d !== void 0 ? _d : 200,
|
|
68
|
+
} })), 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') })) })] })));
|
|
67
69
|
}
|
|
68
|
-
|
|
69
|
-
const { appearanceOutput } = useCurrentAgent();
|
|
70
|
+
const OutputItemView = memo(({ message }) => {
|
|
71
|
+
const { appearanceOutput } = useCurrentAgent({ agentId: message.assistantId });
|
|
70
72
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
71
73
|
return null;
|
|
72
|
-
return (_jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }));
|
|
73
|
-
}
|
|
74
|
+
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));
|
|
75
|
+
});
|
|
@@ -13,13 +13,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
14
14
|
import { Icon } from '@iconify/react';
|
|
15
15
|
import { Alert, Box, Button, Dialog, DialogContent, DialogTitle, Stack, Typography, alpha, } from '@mui/material';
|
|
16
|
-
import { useState } from 'react';
|
|
16
|
+
import { useMemo, useState } from 'react';
|
|
17
17
|
import { RelativeTime } from '../../../../arcblock/ux';
|
|
18
18
|
import { useLocaleContext } from '../../../../locale';
|
|
19
19
|
import { useSessionContext } from '../../../../session';
|
|
20
20
|
import ActionButton from '../../components/ActionButton';
|
|
21
21
|
import UserInfo from '../../components/UserInfo';
|
|
22
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
22
23
|
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
24
|
+
import { isValidInput } from '../../utils/agent-inputs';
|
|
23
25
|
const getLineClamp = (line) => ({
|
|
24
26
|
display: '-webkit-box',
|
|
25
27
|
WebkitLineClamp: line,
|
|
@@ -85,6 +87,19 @@ export default function PhotoGalleryItem() {
|
|
|
85
87
|
function RenderSubTitle({ children }) {
|
|
86
88
|
return (_jsx(Typography, { variant: "caption", sx: { fontSize: 14 }, children: children }));
|
|
87
89
|
}
|
|
90
|
+
function PromptView() {
|
|
91
|
+
var _a;
|
|
92
|
+
const { message } = useCurrentMessage();
|
|
93
|
+
const { agent } = useCurrentAgent();
|
|
94
|
+
const params = useMemo(() => {
|
|
95
|
+
var _a;
|
|
96
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => { var _a; return [i.label || i.key, (_a = message.parameters) === null || _a === void 0 ? void 0 : _a[i.key]]; }).filter((i) => i[1]);
|
|
97
|
+
}, [agent.parameters, message.parameters]);
|
|
98
|
+
if ((params === null || params === void 0 ? void 0 : params.length) === 1) {
|
|
99
|
+
return (_a = params[0]) === null || _a === void 0 ? void 0 : _a[1];
|
|
100
|
+
}
|
|
101
|
+
return params === null || params === void 0 ? void 0 : params.map(([key, value]) => (_jsxs(Typography, { sx: { wordWrap: 'break-word' }, children: [_jsxs(Box, { component: "span", sx: { color: 'text.secondary' }, children: [key, ":"] }), "\u00A0\u00A0", _jsx("span", { children: value })] }, key)));
|
|
102
|
+
}
|
|
88
103
|
function PromptDialog(_a) {
|
|
89
104
|
var _b, _c, _d;
|
|
90
105
|
var { url } = _a, props = __rest(_a, ["url"]);
|
|
@@ -126,7 +141,7 @@ function PromptDialog(_a) {
|
|
|
126
141
|
borderColor: 'divider',
|
|
127
142
|
overflow: 'auto',
|
|
128
143
|
maxHeight: { xs: 'unset', md: '40vh' },
|
|
129
|
-
}, children:
|
|
144
|
+
}, children: _jsx(PromptView, {}) }), _jsx(Box, { children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "contained", placement: "right", tip: t('copyToClipboard'), title: t('copy'), titleSucceed: t('copied'), icon: "tabler:copy", iconSucceed: "tabler:copy-check-filled", onClick: () => {
|
|
130
145
|
window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
|
|
131
146
|
}, sx: {
|
|
132
147
|
borderRadius,
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
14
14
|
import { Box, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
|
|
15
|
-
import {
|
|
15
|
+
import { memo, useEffect, useMemo } from 'react';
|
|
16
16
|
import { useScrollToBottom } from 'react-scroll-to-bottom';
|
|
17
17
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
18
18
|
import { useSessionContext } from '../../../../session';
|
|
@@ -21,10 +21,12 @@ import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
|
21
21
|
import ScrollView from '../../components/ScrollView';
|
|
22
22
|
import UserInfo from '../../components/UserInfo';
|
|
23
23
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
24
|
-
import CurrentMessageProvider
|
|
24
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
25
25
|
import { useRuntimeState } from '../../state/runtime';
|
|
26
|
+
import { useSessionState } from '../../state/session';
|
|
26
27
|
import MessageSuggestedQuestions from '../ChatOutput/MessageSuggestedQuestions';
|
|
27
28
|
export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, }) {
|
|
29
|
+
useSessionState({ autoLoad: true });
|
|
28
30
|
const inheritedTheme = useTheme();
|
|
29
31
|
const theme = useMemo(() => {
|
|
30
32
|
let { primary } = inheritedTheme.palette;
|
|
@@ -46,12 +48,14 @@ export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: '
|
|
|
46
48
|
return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsx(ThemeProvider, { theme: theme, children: _jsx(SimpleChatView, {}) }) })));
|
|
47
49
|
}
|
|
48
50
|
function SimpleChatView() {
|
|
49
|
-
const { childAgentId
|
|
51
|
+
const { childAgentId } = useRuntimeState();
|
|
52
|
+
// auto scroll to bottom when new message is sent
|
|
53
|
+
const running = useSessionState()((s) => s.running);
|
|
50
54
|
const scrollToBottom = useScrollToBottom();
|
|
51
55
|
useEffect(() => {
|
|
52
|
-
if (
|
|
56
|
+
if (running)
|
|
53
57
|
scrollToBottom({ behavior: 'smooth' });
|
|
54
|
-
}, [scrollToBottom,
|
|
58
|
+
}, [scrollToBottom, running]);
|
|
55
59
|
return (_jsxs(SimpleLayout, { children: [_jsx(SimpleHeader, {}), _jsx(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10 }), _jsx(CurrentAgentProvider, { agentId: childAgentId, children: _jsx(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", sx: { position: 'sticky', bottom: 0, pt: 1, pb: 2, bgcolor: 'background.paper', zIndex: 10 } }) })] }));
|
|
56
60
|
}
|
|
57
61
|
function AgentInputRender(_a) {
|
|
@@ -62,30 +66,27 @@ function AgentInputRender(_a) {
|
|
|
62
66
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
63
67
|
}
|
|
64
68
|
function OutputView(_a) {
|
|
65
|
-
var _b, _c;
|
|
66
69
|
var props = __rest(_a, []);
|
|
67
|
-
const
|
|
68
|
-
const lastMessage =
|
|
69
|
-
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [
|
|
70
|
+
const messages = useSessionState()((s) => s.messages);
|
|
71
|
+
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
72
|
+
return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage })] })));
|
|
70
73
|
}
|
|
71
|
-
|
|
74
|
+
const OutputItemView = memo(({ message }) => {
|
|
72
75
|
var _a, _b, _c, _d, _e;
|
|
76
|
+
const { appearanceOutput } = useCurrentAgent({ agentId: message.assistantId });
|
|
73
77
|
const { appearancePage } = useRuntimeState();
|
|
74
|
-
const { appearanceOutput } = useCurrentAgent();
|
|
75
|
-
const { message } = useCurrentMessage();
|
|
76
78
|
const { session: authSession } = useSessionContext();
|
|
77
79
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
78
80
|
return null;
|
|
79
|
-
return (_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: {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
function SuggestedQuestionsView() {
|
|
81
|
+
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: {
|
|
82
|
+
renderType: 'parameters',
|
|
83
|
+
} }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: (_e = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _e === void 0 ? void 0 : _e.url, time: message.createdAt, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
84
|
+
renderType: 'result',
|
|
85
|
+
} }) }) })] }) }) }));
|
|
86
|
+
});
|
|
87
|
+
function SuggestedQuestionsView({ message }) {
|
|
88
|
+
const { aid } = useCurrentAgent({ agentId: message.assistantId });
|
|
86
89
|
const { execute } = useRuntimeState();
|
|
87
|
-
const { aid } = useCurrentAgent();
|
|
88
|
-
const { message } = useCurrentMessage();
|
|
89
90
|
const suggestedQuestions = useMemo(() => {
|
|
90
91
|
var _a, _b, _c;
|
|
91
92
|
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];
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
13
|
import { Stack, ThemeProvider, Typography, createTheme, useTheme } from '@mui/material';
|
|
14
|
-
import { Suspense, useMemo } from 'react';
|
|
14
|
+
import { Suspense, memo, useMemo } from 'react';
|
|
15
15
|
import Balancer from 'react-wrap-balancer';
|
|
16
16
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
17
17
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
@@ -19,8 +19,10 @@ import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
|
19
19
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
20
20
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
21
|
import { useRuntimeState } from '../../state/runtime';
|
|
22
|
+
import { useSessionState } from '../../state/session';
|
|
22
23
|
export default function SimplePage({ resultTitle, primaryColor }) {
|
|
23
24
|
const { childAgentId } = useRuntimeState();
|
|
25
|
+
useSessionState({ autoLoad: true });
|
|
24
26
|
const inheritedTheme = useTheme();
|
|
25
27
|
const theme = useMemo(() => {
|
|
26
28
|
let { primary } = inheritedTheme.palette;
|
|
@@ -49,15 +51,13 @@ function AgentInputRender(_a) {
|
|
|
49
51
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
50
52
|
}
|
|
51
53
|
function OutputView(_a) {
|
|
52
|
-
var _b;
|
|
53
54
|
var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
|
|
54
|
-
const {
|
|
55
|
-
|
|
56
|
-
return (_jsx(Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && (_jsxs(_Fragment, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: lastMessage.assistantId, children: _jsx(CurrentMessageProvider, { message: lastMessage, children: _jsx(Suspense, { children: _jsx(OutputItemView, {}) }) }) }) })] })) })));
|
|
55
|
+
const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
56
|
+
return (_jsx(Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && (_jsxs(_Fragment, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(Stack, { children: _jsx(OutputItemView, { message: lastMessage }) })] })) })));
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
const { appearanceOutput } = useCurrentAgent();
|
|
58
|
+
const OutputItemView = memo(({ message }) => {
|
|
59
|
+
const { appearanceOutput } = useCurrentAgent({ agentId: message.assistantId });
|
|
60
60
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
61
61
|
return null;
|
|
62
|
-
return (_jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }));
|
|
63
|
-
}
|
|
62
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }));
|
|
63
|
+
});
|
|
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { create } from 'zustand';
|
|
11
11
|
import { immer } from 'zustand/middleware/immer';
|
|
12
12
|
import { getAgent } from '../api/agent';
|
|
13
|
-
|
|
13
|
+
import { createCachedStore } from '../utils/zustand';
|
|
14
14
|
export const createAgentState = ({ aid, working, agent }) => {
|
|
15
|
-
var _a;
|
|
16
15
|
const key = working ? `${aid}-working` : aid;
|
|
17
|
-
(
|
|
16
|
+
return createCachedStore(key, () => create()(immer((set) => ({
|
|
18
17
|
agent,
|
|
19
18
|
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
19
|
set((state) => {
|
|
@@ -39,7 +38,6 @@ export const createAgentState = ({ aid, working, agent }) => {
|
|
|
39
38
|
}
|
|
40
39
|
}),
|
|
41
40
|
}))));
|
|
42
|
-
return STATES[key];
|
|
43
41
|
};
|
|
44
42
|
const LOADING_TASKS = {};
|
|
45
43
|
export function useAgentState({ aid, working }) {
|