@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
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
3
|
var t = {};
|
|
27
4
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
@@ -41,18 +18,13 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
41
18
|
const react_1 = require("@iconify/react");
|
|
42
19
|
const material_1 = require("@mui/material");
|
|
43
20
|
const react_2 = __importDefault(require("react"));
|
|
21
|
+
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
22
|
+
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
44
23
|
const locale_1 = require("../../../locale");
|
|
45
|
-
const react_markdown_1 = __importDefault(require("../../react-markdown"));
|
|
46
24
|
const react_syntax_highlighter_1 = __importDefault(require("../../react-syntax-highlighter"));
|
|
47
25
|
const ActionButton_1 = __importDefault(require("./ActionButton"));
|
|
48
26
|
const ReactSyntaxHighlighter = react_2.default.lazy(() => (0, react_syntax_highlighter_1.default)().then((m) => ({ default: m.Prism })));
|
|
49
|
-
const
|
|
50
|
-
(0, react_markdown_1.default)(),
|
|
51
|
-
Promise.resolve().then(() => __importStar(require('https://esm.sh/remark-gfm@4?bundle'))),
|
|
52
|
-
]).then(([{ default: Markdown }, remark]) => ({
|
|
53
|
-
default: (props) => (0, jsx_runtime_1.jsx)(Markdown, Object.assign({}, props, { remarkPlugins: [remark.default] })),
|
|
54
|
-
})));
|
|
55
|
-
const MarkdownRenderer = (0, material_1.styled)((props) => ((0, jsx_runtime_1.jsx)(Markdown, Object.assign({}, props, { components: {
|
|
27
|
+
const MarkdownRenderer = (0, material_1.styled)((props) => ((0, jsx_runtime_1.jsx)(react_markdown_1.default, Object.assign({}, props, { remarkPlugins: [remark_gfm_1.default], components: {
|
|
56
28
|
pre: MarkdownPre,
|
|
57
29
|
code: (_a) => {
|
|
58
30
|
var { node, inline, className, children } = _a, props = __rest(_a, ["node", "inline", "className", "children"]);
|
|
@@ -8,22 +8,28 @@ const react_1 = require("react");
|
|
|
8
8
|
const constants_1 = require("../constants");
|
|
9
9
|
const agent_1 = require("../state/agent");
|
|
10
10
|
const runtime_1 = require("../state/runtime");
|
|
11
|
-
|
|
12
|
-
function CurrentAgentProvider({ agentId, children }) {
|
|
11
|
+
function useCurrentAid({ agentId }) {
|
|
13
12
|
const { aid } = (0, runtime_1.useRuntimeState)();
|
|
14
|
-
|
|
13
|
+
return (0, react_1.useMemo)(() => ({
|
|
15
14
|
aid: (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(aid, { rejectWhenError: true })), { assistantId: agentId })),
|
|
16
15
|
}), [aid, agentId]);
|
|
16
|
+
}
|
|
17
|
+
const context = (0, react_1.createContext)(undefined);
|
|
18
|
+
function CurrentAgentProvider({ agentId, children }) {
|
|
19
|
+
const state = useCurrentAid({ agentId });
|
|
17
20
|
return (0, jsx_runtime_1.jsx)(context.Provider, { value: state, children: children });
|
|
18
21
|
}
|
|
19
22
|
exports.default = CurrentAgentProvider;
|
|
20
|
-
function useCurrentAgent() {
|
|
21
|
-
const { working } = (0, runtime_1.useRuntimeState)();
|
|
23
|
+
function useCurrentAgent({ agentId } = {}) {
|
|
24
|
+
const { aid: runtimeAid, working } = (0, runtime_1.useRuntimeState)();
|
|
25
|
+
const aidFromParam = (0, react_1.useMemo)(() => agentId &&
|
|
26
|
+
(0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(runtimeAid, { rejectWhenError: true })), { assistantId: agentId })), [agentId]);
|
|
22
27
|
const current = (0, react_1.useContext)(context);
|
|
23
|
-
|
|
28
|
+
const aid = aidFromParam !== null && aidFromParam !== void 0 ? aidFromParam : current === null || current === void 0 ? void 0 : current.aid;
|
|
29
|
+
if (!aid) {
|
|
24
30
|
throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
|
|
25
31
|
}
|
|
26
|
-
const [agent] = (0, agent_1.useAgentState)({ aid
|
|
32
|
+
const [agent] = (0, agent_1.useAgentState)({ aid, working });
|
|
27
33
|
const appearanceInput = (0, react_1.useMemo)(() => {
|
|
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 === types_1.RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: constants_1.DEFAULT_INPUT_COMPONENT_ID };
|
|
@@ -32,6 +38,6 @@ function useCurrentAgent() {
|
|
|
32
38
|
var _a, _b, _c;
|
|
33
39
|
return (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: constants_1.DEFAULT_OUTPUT_COMPONENT_ID };
|
|
34
40
|
}, [agent]);
|
|
35
|
-
return
|
|
41
|
+
return { aid, agent, appearanceInput, appearanceOutput };
|
|
36
42
|
}
|
|
37
43
|
exports.useCurrentAgent = useCurrentAgent;
|
|
@@ -15,6 +15,7 @@ const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
|
|
|
15
15
|
const constants_1 = require("../../constants");
|
|
16
16
|
const Runtime_1 = __importDefault(require("../../contexts/Runtime"));
|
|
17
17
|
const runtime_1 = require("../../state/runtime");
|
|
18
|
+
const session_1 = require("../../state/session");
|
|
18
19
|
function ChatBotButton({ aid, working }) {
|
|
19
20
|
return ((0, jsx_runtime_1.jsx)(Runtime_1.default, { aid: aid, working: working, children: (0, jsx_runtime_1.jsx)(RuntimeCommonProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ChatBotContent, {}) }) }));
|
|
20
21
|
}
|
|
@@ -22,13 +23,11 @@ exports.default = ChatBotButton;
|
|
|
22
23
|
function ChatBotContent() {
|
|
23
24
|
var _a, _b, _c;
|
|
24
25
|
const anchorEl = (0, react_2.useRef)(null);
|
|
25
|
-
|
|
26
|
+
(0, session_1.useSessionState)({ autoLoad: true });
|
|
27
|
+
const { appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
26
28
|
const [open, setOpen] = (0, react_2.useState)(false);
|
|
27
|
-
(0, react_2.useEffect)(() => {
|
|
28
|
-
sessionState.load();
|
|
29
|
-
}, []);
|
|
30
29
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PAGE_COMPONENT_ID;
|
|
31
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: '
|
|
30
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: 'modal' }, children: [(0, jsx_runtime_1.jsx)(material_1.Fab, { sx: { width: 44, height: 44, boxShadow: open ? 0 : undefined }, onClick: () => setOpen(true), children: (0, jsx_runtime_1.jsx)(ux_1.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 }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { width: "100%", ref: anchorEl }), anchorEl.current && ((0, jsx_runtime_1.jsx)(ResponsiveChatBotContainer, { anchorEl: anchorEl.current, open: open, onClose: () => setOpen(false), children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { initialScrollBehavior: "auto", component: material_1.Stack, sx: {
|
|
32
31
|
overscrollBehavior: 'contain',
|
|
33
32
|
height: '100%',
|
|
34
33
|
width: '100%',
|
|
@@ -49,12 +48,12 @@ function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
|
|
|
49
48
|
return ((0, jsx_runtime_1.jsx)(ChatBotPopper, { anchorEl: anchorEl, title: title, open: open, onClose: onClose, children: children }));
|
|
50
49
|
}
|
|
51
50
|
function ChatBotPopper({ title, anchorEl, open, children, onClose, }) {
|
|
52
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl, open: open, placement: "top-end", sx: {
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl, open: open, disablePortal: true, placement: "top-end", sx: {
|
|
53
52
|
zIndex: 'modal',
|
|
54
53
|
maxWidth: 500,
|
|
55
|
-
maxHeight: '
|
|
56
|
-
width:
|
|
57
|
-
height: '
|
|
54
|
+
maxHeight: 'min(calc(100vh - 128px), 1000px)',
|
|
55
|
+
width: 500,
|
|
56
|
+
height: '90vh',
|
|
58
57
|
}, children: (0, jsx_runtime_1.jsx)(material_1.ClickAwayListener, { onClickAway: (e) => {
|
|
59
58
|
e.preventDefault();
|
|
60
59
|
e.stopPropagation();
|
|
@@ -50,7 +50,7 @@ function Runtime() {
|
|
|
50
50
|
exports.default = Runtime;
|
|
51
51
|
function RuntimeView() {
|
|
52
52
|
var _a;
|
|
53
|
-
const { agent, appearancePage
|
|
53
|
+
const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
54
54
|
const theme = (0, material_1.useTheme)();
|
|
55
55
|
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
|
|
56
56
|
const { locale } = (0, locale_1.useLocaleContext)();
|
|
@@ -90,10 +90,7 @@ function RuntimeView() {
|
|
|
90
90
|
state.addons = (...exists) => [...exists];
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
|
-
}, [appearancePage, locale, isMobile]);
|
|
94
|
-
(0, react_1.useEffect)(() => {
|
|
95
|
-
sessionState.load();
|
|
96
|
-
}, []);
|
|
93
|
+
}, [appearancePage, locale, isMobile, agent]);
|
|
97
94
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PAGE_COMPONENT_ID;
|
|
98
95
|
return ((0, jsx_runtime_1.jsxs)(RuntimeCommonProvider_1.default, { children: [appearancePage && ((0, jsx_runtime_1.jsxs)(react_helmet_1.Helmet, { children: [appearancePage.name && (0, jsx_runtime_1.jsx)("title", { children: appearancePage.name }), appearancePage.description && (0, jsx_runtime_1.jsx)("meta", { name: "description", content: appearancePage.description })] })), (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps })] }));
|
|
99
96
|
}
|
|
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SUPPORTED_PARAMETER_TYPES = void 0;
|
|
16
15
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
17
16
|
const css_1 = require("@emotion/css");
|
|
18
17
|
const material_1 = require("@mui/material");
|
|
@@ -25,14 +24,16 @@ const AgentInputField_1 = __importDefault(require("../../components/AgentInputFi
|
|
|
25
24
|
const LoadingButton_1 = __importDefault(require("../../components/LoadingButton"));
|
|
26
25
|
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
27
26
|
const runtime_1 = require("../../state/runtime");
|
|
28
|
-
|
|
27
|
+
const session_1 = require("../../state/session");
|
|
28
|
+
const agent_inputs_1 = require("../../utils/agent-inputs");
|
|
29
29
|
function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
|
|
30
30
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
31
31
|
const { aid, agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
32
|
-
const {
|
|
32
|
+
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
33
|
+
const running = (0, session_1.useSessionState)()((s) => s.running);
|
|
33
34
|
const parameters = (0, react_1.useMemo)(() => {
|
|
34
35
|
var _a;
|
|
35
|
-
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(
|
|
36
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.isValidInput).map((i) => {
|
|
36
37
|
var _a;
|
|
37
38
|
return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
|
|
38
39
|
});
|
|
@@ -44,7 +45,7 @@ function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQu
|
|
|
44
45
|
if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
|
|
45
46
|
form.reset(chatMode ? (0, omit_1.default)(defaultForm, 'question') : defaultForm);
|
|
46
47
|
}
|
|
47
|
-
}, [defaultForm, autoFillLastForm, form]);
|
|
48
|
+
}, [defaultForm, autoFillLastForm, form, chatMode]);
|
|
48
49
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
49
50
|
yield execute({
|
|
50
51
|
aid,
|
|
@@ -75,33 +76,31 @@ function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQu
|
|
|
75
76
|
var _a;
|
|
76
77
|
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "form-item", children: [parameter.label && (0, jsx_runtime_1.jsx)(material_1.FormLabel, { children: parameter.label }), (0, jsx_runtime_1.jsx)(AgentInputField_1.default, { 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
|
|
77
78
|
? {
|
|
78
|
-
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading:
|
|
79
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75 }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText }) })),
|
|
79
80
|
}
|
|
80
81
|
: undefined })] }));
|
|
81
82
|
} }) }, parameter.id));
|
|
82
|
-
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading:
|
|
83
|
+
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
|
|
83
84
|
}
|
|
84
85
|
exports.default = AutoForm;
|
|
85
86
|
function useInitialFormValues() {
|
|
86
|
-
var _a;
|
|
87
|
-
const [lastMessage, setLastMessage] = (0, react_1.useState)();
|
|
88
87
|
const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
89
|
-
const
|
|
88
|
+
const lastMessage = (0, session_1.useSessionState)()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
89
|
+
const [lastInputs, setLastInputs] = (0, react_1.useState)();
|
|
90
90
|
(0, react_1.useEffect)(() => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if (!lastInputs) {
|
|
92
|
+
const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
|
|
93
|
+
if (!(0, isEmpty_1.default)(lastParameters))
|
|
94
|
+
setLastInputs(lastParameters);
|
|
94
95
|
}
|
|
95
|
-
}, [
|
|
96
|
+
}, [lastMessage]);
|
|
96
97
|
return (0, react_1.useMemo)(() => {
|
|
97
98
|
var _a, _b;
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
if (!(0, isEmpty_1.default)(lastParameters))
|
|
101
|
-
return lastParameters;
|
|
99
|
+
if (lastInputs) {
|
|
100
|
+
return lastInputs;
|
|
102
101
|
}
|
|
103
102
|
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 : []);
|
|
104
|
-
}, [
|
|
103
|
+
}, [lastInputs, agent]);
|
|
105
104
|
}
|
|
106
105
|
function useFormTheme() {
|
|
107
106
|
const theme = (0, material_1.useTheme)();
|
|
@@ -49,9 +49,11 @@ const LoadingButton_1 = __importDefault(require("../../components/LoadingButton"
|
|
|
49
49
|
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
50
50
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
51
51
|
const runtime_1 = require("../../state/runtime");
|
|
52
|
+
const session_1 = require("../../state/session");
|
|
52
53
|
const map_right_1 = __importDefault(require("../../utils/map-right"));
|
|
53
54
|
function PhotoGallery({ resultTitle, primaryColor }) {
|
|
54
55
|
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
56
|
+
(0, session_1.useSessionState)({ autoLoad: true });
|
|
55
57
|
const inheritedTheme = (0, material_1.useTheme)();
|
|
56
58
|
const theme = (0, react_1.useMemo)(() => {
|
|
57
59
|
let { primary } = inheritedTheme.palette;
|
|
@@ -84,19 +86,19 @@ function NoOutputs() {
|
|
|
84
86
|
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { mt: 10, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
|
|
85
87
|
}
|
|
86
88
|
function OutputView(_a) {
|
|
87
|
-
var _b, _c, _d
|
|
89
|
+
var _b, _c, _d;
|
|
88
90
|
var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
|
|
89
91
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
90
|
-
const { sessionState } = (0, runtime_1.useRuntimeState)();
|
|
91
92
|
const ref = (0, react_1.useRef)(null);
|
|
92
|
-
|
|
93
|
+
const { messages = [], running, loaded, noMoreMessage, loadMoreMessages } = (0, session_1.useSessionState)()();
|
|
94
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ width: "100%", alignItems: "center", px: { xs: 2, sm: 3 }, mt: { xs: 2, sm: 3 } }, props, { children: [resultTitle && ((0, jsx_runtime_1.jsx)(material_1.Typography, { width: "100%", component: "h2", fontSize: 36, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: resultTitle }) })), loaded && !messages.length && (0, jsx_runtime_1.jsx)(NoOutputs, {}), (0, jsx_runtime_1.jsxs)(lab_1.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 && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", sx: {
|
|
93
95
|
// FIXME: default using history height
|
|
94
|
-
height: (
|
|
95
|
-
} })), (0, map_right_1.default)(
|
|
96
|
+
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,
|
|
97
|
+
} })), (0, map_right_1.default)(messages, (message) => ((0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)))] }), (0, jsx_runtime_1.jsx)(material_1.Box, { my: 4, children: !!messages.length && !noMoreMessage && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { variant: "outlined", onClick: loadMoreMessages, children: t('loadMore') })) })] })));
|
|
96
98
|
}
|
|
97
|
-
|
|
98
|
-
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
99
|
+
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
100
|
+
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
99
101
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
100
102
|
return null;
|
|
101
|
-
return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }));
|
|
102
|
-
}
|
|
103
|
+
return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }, message.taskId));
|
|
104
|
+
});
|
|
@@ -24,7 +24,9 @@ const locale_1 = require("../../../../locale");
|
|
|
24
24
|
const session_1 = require("../../../../session");
|
|
25
25
|
const ActionButton_1 = __importDefault(require("../../components/ActionButton"));
|
|
26
26
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
27
|
+
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
27
28
|
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
29
|
+
const agent_inputs_1 = require("../../utils/agent-inputs");
|
|
28
30
|
const getLineClamp = (line) => ({
|
|
29
31
|
display: '-webkit-box',
|
|
30
32
|
WebkitLineClamp: line,
|
|
@@ -91,6 +93,19 @@ exports.default = PhotoGalleryItem;
|
|
|
91
93
|
function RenderSubTitle({ children }) {
|
|
92
94
|
return ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", sx: { fontSize: 14 }, children: children }));
|
|
93
95
|
}
|
|
96
|
+
function PromptView() {
|
|
97
|
+
var _a;
|
|
98
|
+
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
99
|
+
const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
100
|
+
const params = (0, react_2.useMemo)(() => {
|
|
101
|
+
var _a;
|
|
102
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.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]);
|
|
103
|
+
}, [agent.parameters, message.parameters]);
|
|
104
|
+
if ((params === null || params === void 0 ? void 0 : params.length) === 1) {
|
|
105
|
+
return (_a = params[0]) === null || _a === void 0 ? void 0 : _a[1];
|
|
106
|
+
}
|
|
107
|
+
return params === null || params === void 0 ? void 0 : params.map(([key, value]) => ((0, jsx_runtime_1.jsxs)(material_1.Typography, { sx: { wordWrap: 'break-word' }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", sx: { color: 'text.secondary' }, children: [key, ":"] }), "\u00A0\u00A0", (0, jsx_runtime_1.jsx)("span", { children: value })] }, key)));
|
|
108
|
+
}
|
|
94
109
|
function PromptDialog(_a) {
|
|
95
110
|
var _b, _c, _d;
|
|
96
111
|
var { url } = _a, props = __rest(_a, ["url"]);
|
|
@@ -132,7 +147,7 @@ function PromptDialog(_a) {
|
|
|
132
147
|
borderColor: 'divider',
|
|
133
148
|
overflow: 'auto',
|
|
134
149
|
maxHeight: { xs: 'unset', md: '40vh' },
|
|
135
|
-
}, children:
|
|
150
|
+
}, children: (0, jsx_runtime_1.jsx)(PromptView, {}) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ActionButton_1.default, { 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: () => {
|
|
136
151
|
window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
|
|
137
152
|
}, sx: {
|
|
138
153
|
borderRadius,
|
|
@@ -49,10 +49,12 @@ const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLa
|
|
|
49
49
|
const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
|
|
50
50
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
51
51
|
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
52
|
-
const CurrentMessage_1 =
|
|
52
|
+
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
53
53
|
const runtime_1 = require("../../state/runtime");
|
|
54
|
+
const session_2 = require("../../state/session");
|
|
54
55
|
const MessageSuggestedQuestions_1 = __importDefault(require("../ChatOutput/MessageSuggestedQuestions"));
|
|
55
56
|
function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, }) {
|
|
57
|
+
(0, session_2.useSessionState)({ autoLoad: true });
|
|
56
58
|
const inheritedTheme = (0, material_1.useTheme)();
|
|
57
59
|
const theme = (0, react_1.useMemo)(() => {
|
|
58
60
|
let { primary } = inheritedTheme.palette;
|
|
@@ -75,12 +77,14 @@ function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initia
|
|
|
75
77
|
}
|
|
76
78
|
exports.default = SimpleChat;
|
|
77
79
|
function SimpleChatView() {
|
|
78
|
-
const { childAgentId
|
|
80
|
+
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
81
|
+
// auto scroll to bottom when new message is sent
|
|
82
|
+
const running = (0, session_2.useSessionState)()((s) => s.running);
|
|
79
83
|
const scrollToBottom = (0, react_scroll_to_bottom_1.useScrollToBottom)();
|
|
80
84
|
(0, react_1.useEffect)(() => {
|
|
81
|
-
if (
|
|
85
|
+
if (running)
|
|
82
86
|
scrollToBottom({ behavior: 'smooth' });
|
|
83
|
-
}, [scrollToBottom,
|
|
87
|
+
}, [scrollToBottom, running]);
|
|
84
88
|
return ((0, jsx_runtime_1.jsxs)(SimpleLayout_1.default, { children: [(0, jsx_runtime_1.jsx)(SimpleHeader_1.default, {}), (0, jsx_runtime_1.jsx)(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10 }), (0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: childAgentId, children: (0, jsx_runtime_1.jsx)(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", sx: { position: 'sticky', bottom: 0, pt: 1, pb: 2, bgcolor: 'background.paper', zIndex: 10 } }) })] }));
|
|
85
89
|
}
|
|
86
90
|
function AgentInputRender(_a) {
|
|
@@ -91,30 +95,27 @@ function AgentInputRender(_a) {
|
|
|
91
95
|
return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
92
96
|
}
|
|
93
97
|
function OutputView(_a) {
|
|
94
|
-
var _b, _c;
|
|
95
98
|
var props = __rest(_a, []);
|
|
96
|
-
const
|
|
97
|
-
const lastMessage =
|
|
98
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [
|
|
99
|
+
const messages = (0, session_2.useSessionState)()((s) => s.messages);
|
|
100
|
+
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
101
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [messages === null || messages === void 0 ? void 0 : messages.map((message) => (0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)), lastMessage && (0, jsx_runtime_1.jsx)(SuggestedQuestionsView, { message: lastMessage })] })));
|
|
99
102
|
}
|
|
100
|
-
|
|
103
|
+
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
101
104
|
var _a, _b, _c, _d, _e;
|
|
105
|
+
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
102
106
|
const { appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
103
|
-
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
104
|
-
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
105
107
|
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
106
108
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
107
109
|
return null;
|
|
108
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { 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: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
function SuggestedQuestionsView() {
|
|
110
|
+
return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { 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: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
111
|
+
renderType: 'parameters',
|
|
112
|
+
} }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { 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: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
113
|
+
renderType: 'result',
|
|
114
|
+
} }) }) })] }) }) }));
|
|
115
|
+
});
|
|
116
|
+
function SuggestedQuestionsView({ message }) {
|
|
117
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
115
118
|
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
116
|
-
const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
117
|
-
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
118
119
|
const suggestedQuestions = (0, react_1.useMemo)(() => {
|
|
119
120
|
var _a, _b, _c;
|
|
120
121
|
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[types_1.RuntimeOutputVariable.suggestedQuestions];
|
|
@@ -47,8 +47,10 @@ const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLa
|
|
|
47
47
|
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
48
48
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
49
49
|
const runtime_1 = require("../../state/runtime");
|
|
50
|
+
const session_1 = require("../../state/session");
|
|
50
51
|
function SimplePage({ resultTitle, primaryColor }) {
|
|
51
52
|
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
53
|
+
(0, session_1.useSessionState)({ autoLoad: true });
|
|
52
54
|
const inheritedTheme = (0, material_1.useTheme)();
|
|
53
55
|
const theme = (0, react_1.useMemo)(() => {
|
|
54
56
|
let { primary } = inheritedTheme.palette;
|
|
@@ -78,15 +80,13 @@ function AgentInputRender(_a) {
|
|
|
78
80
|
return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
79
81
|
}
|
|
80
82
|
function OutputView(_a) {
|
|
81
|
-
var _b;
|
|
82
83
|
var { resultTitle } = _a, props = __rest(_a, ["resultTitle"]);
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [resultTitle && ((0, jsx_runtime_1.jsx)(material_1.Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: resultTitle }) })), (0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: lastMessage.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: lastMessage, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsx)(OutputItemView, {}) }) }) }) })] })) })));
|
|
84
|
+
const lastMessage = (0, session_1.useSessionState)()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
85
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [resultTitle && ((0, jsx_runtime_1.jsx)(material_1.Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: resultTitle }) })), (0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(OutputItemView, { message: lastMessage }) })] })) })));
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
87
|
+
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
88
|
+
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
89
89
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
90
90
|
return null;
|
|
91
|
-
return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }));
|
|
92
|
-
}
|
|
91
|
+
return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }));
|
|
92
|
+
});
|
|
@@ -13,11 +13,10 @@ exports.useAgentState = exports.createAgentState = void 0;
|
|
|
13
13
|
const zustand_1 = require("zustand");
|
|
14
14
|
const immer_1 = require("zustand/middleware/immer");
|
|
15
15
|
const agent_1 = require("../api/agent");
|
|
16
|
-
const
|
|
16
|
+
const zustand_2 = require("../utils/zustand");
|
|
17
17
|
const createAgentState = ({ aid, working, agent }) => {
|
|
18
|
-
var _a;
|
|
19
18
|
const key = working ? `${aid}-working` : aid;
|
|
20
|
-
(
|
|
19
|
+
return (0, zustand_2.createCachedStore)(key, () => (0, zustand_1.create)()((0, immer_1.immer)((set) => ({
|
|
21
20
|
agent,
|
|
22
21
|
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
22
|
set((state) => {
|
|
@@ -42,7 +41,6 @@ const createAgentState = ({ aid, working, agent }) => {
|
|
|
42
41
|
}
|
|
43
42
|
}),
|
|
44
43
|
}))));
|
|
45
|
-
return STATES[key];
|
|
46
44
|
};
|
|
47
45
|
exports.createAgentState = createAgentState;
|
|
48
46
|
const LOADING_TASKS = {};
|
|
@@ -20,27 +20,28 @@ function useRuntimeState() {
|
|
|
20
20
|
var _a;
|
|
21
21
|
const { aid, working } = (0, Runtime_1.useRuntimeContext)();
|
|
22
22
|
const [agent] = (0, agent_1.useAgentState)({ aid, working });
|
|
23
|
-
const sessionState = (0, session_2.createSessionState)({ aid })();
|
|
24
23
|
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
24
|
+
const sessionState = (0, react_1.useMemo)(() => (0, session_2.createSessionState)({ aid }), [aid]);
|
|
25
|
+
const exec = sessionState((s) => s.execute);
|
|
25
26
|
// reset state after logged out
|
|
26
27
|
(0, react_1.useEffect)(() => {
|
|
27
28
|
var _a;
|
|
28
29
|
if (!((_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did)) {
|
|
29
|
-
sessionState.reset();
|
|
30
|
+
sessionState.getState().reset();
|
|
30
31
|
}
|
|
31
|
-
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did]);
|
|
32
|
+
}, [(_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did, sessionState]);
|
|
32
33
|
const login = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
33
34
|
yield new Promise((resolve) => {
|
|
34
35
|
authSession.login(() => resolve());
|
|
35
36
|
});
|
|
36
|
-
yield
|
|
37
|
-
}), [
|
|
37
|
+
yield sessionState.getState().load();
|
|
38
|
+
}), [authSession, sessionState]);
|
|
38
39
|
const execute = (0, react_1.useCallback)((args) => __awaiter(this, void 0, void 0, function* () {
|
|
39
40
|
if (!authSession.user) {
|
|
40
41
|
yield login();
|
|
41
42
|
}
|
|
42
|
-
return
|
|
43
|
-
}), [authSession.user,
|
|
43
|
+
return exec(Object.assign(Object.assign({}, args), { working }));
|
|
44
|
+
}), [authSession.user, exec, working, login]);
|
|
44
45
|
const appearancePage = (0, react_1.useMemo)(() => {
|
|
45
46
|
var _a, _b;
|
|
46
47
|
const initialValue = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
@@ -50,6 +51,6 @@ function useRuntimeState() {
|
|
|
50
51
|
var _a, _b, _c, _d, _e, _f;
|
|
51
52
|
return ((_f = (_e = (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.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);
|
|
52
53
|
}, [agent]);
|
|
53
|
-
return { aid, working, agent, appearancePage,
|
|
54
|
+
return { aid, working, agent, appearancePage, childAgentId, execute };
|
|
54
55
|
}
|
|
55
56
|
exports.useRuntimeState = useRuntimeState;
|