@blocklet/pages-kit 0.2.309 → 0.2.311
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +94 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +33 -7
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +12 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +192 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +18 -24
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +152 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +79 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +147 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/index.js +12 -0
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/cjs/builtin/async/ai-runtime/utils/runtime-output-schema.js +8 -0
- package/lib/cjs/builtin/mui/material.js +3 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/utils/inject-global-components-dump-json.js +1167 -0
- package/lib/esm/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +87 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +10 -7
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +163 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +19 -25
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +73 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +142 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/esm/builtin/async/ai-runtime/utils/runtime-output-schema.js +4 -0
- package/lib/esm/builtin/mui/material.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/utils/inject-global-components-dump-json.js +1165 -0
- package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +8 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +45 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Output.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -3
- package/lib/types/builtin/async/ai-runtime/utils/runtime-output-schema.d.ts +3 -0
- package/lib/types/builtin/mui/material.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -0
- package/lib/types/utils/inject-global-components-dump-json.d.ts +1 -0
- package/package.json +13 -9
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
41
|
+
const types_1 = require("@blocklet/ai-runtime/types");
|
|
42
|
+
const material_1 = require("@mui/material");
|
|
43
|
+
const react_1 = require("react");
|
|
44
|
+
const react_scroll_to_bottom_1 = require("react-scroll-to-bottom");
|
|
45
|
+
const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
|
|
46
|
+
const session_1 = require("../../../../session");
|
|
47
|
+
const SimpleHeader_1 = __importDefault(require("../../components/Header/SimpleHeader"));
|
|
48
|
+
const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLayout"));
|
|
49
|
+
const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
|
|
50
|
+
const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
|
|
51
|
+
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
52
|
+
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
53
|
+
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
54
|
+
const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
|
|
55
|
+
const runtime_1 = require("../../state/runtime");
|
|
56
|
+
const session_2 = require("../../state/session");
|
|
57
|
+
const runtime_output_schema_1 = require("../../utils/runtime-output-schema");
|
|
58
|
+
const MessageSuggestedQuestions_1 = __importStar(require("../ChatOutput/MessageSuggestedQuestions"));
|
|
59
|
+
function MultiAgentsChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, backgroundImage, }) {
|
|
60
|
+
(0, session_2.useSessionState)({ autoLoad: true });
|
|
61
|
+
const inheritedTheme = (0, material_1.useTheme)();
|
|
62
|
+
const theme = (0, react_1.useMemo)(() => {
|
|
63
|
+
let { primary } = inheritedTheme.palette;
|
|
64
|
+
try {
|
|
65
|
+
if (primaryColor) {
|
|
66
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('augment primary color error', { error });
|
|
71
|
+
}
|
|
72
|
+
return (0, material_1.createTheme)(inheritedTheme, {
|
|
73
|
+
palette: { primary },
|
|
74
|
+
shape: {
|
|
75
|
+
borderRadius: 8,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}, [inheritedTheme, primaryColor]);
|
|
79
|
+
return ((0, jsx_runtime_1.jsx)(ScrollView_1.default, Object.assign({}, scrollViewProps, { children: (0, jsx_runtime_1.jsxs)(material_1.ThemeProvider, { theme: theme, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
80
|
+
position: 'fixed',
|
|
81
|
+
left: 0,
|
|
82
|
+
top: 0,
|
|
83
|
+
right: 0,
|
|
84
|
+
bottom: 0,
|
|
85
|
+
backgroundImage: `url(${backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url}) !important`,
|
|
86
|
+
backgroundRepeat: 'no-repeat',
|
|
87
|
+
backgroundSize: 'cover',
|
|
88
|
+
backgroundPosition: 'center',
|
|
89
|
+
pointerEvents: 'none',
|
|
90
|
+
zIndex: -1,
|
|
91
|
+
} }), (0, jsx_runtime_1.jsx)(SimpleChatView, {})] }) })));
|
|
92
|
+
}
|
|
93
|
+
exports.default = MultiAgentsChat;
|
|
94
|
+
function SimpleChatView() {
|
|
95
|
+
// auto scroll to bottom when new message is sent
|
|
96
|
+
const running = (0, session_2.useSessionState)()((s) => s.running);
|
|
97
|
+
const scrollToBottom = (0, react_scroll_to_bottom_1.useScrollToBottom)();
|
|
98
|
+
(0, react_1.useEffect)(() => {
|
|
99
|
+
if (running)
|
|
100
|
+
scrollToBottom({ behavior: 'smooth' });
|
|
101
|
+
}, [scrollToBottom, running]);
|
|
102
|
+
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
103
|
+
const [currentAgentId, setCurrentAgentId] = (0, react_1.useState)(childAgentId);
|
|
104
|
+
return ((0, jsx_runtime_1.jsxs)(SimpleLayout_1.default, { children: [(0, jsx_runtime_1.jsx)(SimpleHeader_1.default, { px: 2 }), (0, jsx_runtime_1.jsx)(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10, px: 2, currentAgentId: currentAgentId }), (0, jsx_runtime_1.jsx)(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", currentAgentId: currentAgentId, onCurrentAgentIdChange: setCurrentAgentId, sx: {
|
|
105
|
+
position: 'sticky',
|
|
106
|
+
bottom: 0,
|
|
107
|
+
p: 2,
|
|
108
|
+
borderRadius: 1,
|
|
109
|
+
bgcolor: (theme) => (0, material_1.alpha)(theme.palette.background.paper, 0.7),
|
|
110
|
+
backdropFilter: 'blur(10px)',
|
|
111
|
+
zIndex: 10,
|
|
112
|
+
} })] }));
|
|
113
|
+
}
|
|
114
|
+
function AgentInputRender(_a) {
|
|
115
|
+
var { currentAgentId, onCurrentAgentIdChange } = _a, props = __rest(_a, ["currentAgentId", "onCurrentAgentIdChange"]);
|
|
116
|
+
const { agent } = (0, runtime_1.useRuntimeState)();
|
|
117
|
+
const children = (0, react_1.useMemo)(() => { var _a, _b; return (_b = (_a = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.children)) === null || _a === void 0 ? void 0 : _a.agents) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.id); }, [agent]);
|
|
118
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", gap: 2, children: children === null || children === void 0 ? void 0 : children.map((child) => ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: child.id, children: (0, jsx_runtime_1.jsx)(AgentAvatar, { selected: currentAgentId === child.id, onClick: () => onCurrentAgentIdChange(child.id) }) }))) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(AgentInput, {}) }) })] })));
|
|
119
|
+
}
|
|
120
|
+
function AgentAvatar(_a) {
|
|
121
|
+
var _b;
|
|
122
|
+
var { selected } = _a, props = __rest(_a, ["selected"]);
|
|
123
|
+
const { appearanceInput } = (0, use_appearances_1.default)();
|
|
124
|
+
const profile = (0, use_appearances_1.useProfile)();
|
|
125
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
126
|
+
return null;
|
|
127
|
+
return ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({}, props, { sx: Object.assign({ p: 0, outline: selected ? 3 : 0, outlineColor: 'primary.light' }, props.sx), children: (0, jsx_runtime_1.jsx)(material_1.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) }) })));
|
|
128
|
+
}
|
|
129
|
+
function AgentInput() {
|
|
130
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
131
|
+
const { appearanceInput } = (0, use_appearances_1.default)({ aid });
|
|
132
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
133
|
+
return null;
|
|
134
|
+
return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }));
|
|
135
|
+
}
|
|
136
|
+
function OutputView(_a) {
|
|
137
|
+
var { currentAgentId } = _a, props = __rest(_a, ["currentAgentId"]);
|
|
138
|
+
const messages = (0, session_2.useSessionState)()((s) => s.messages);
|
|
139
|
+
const loading = (0, session_2.useSessionState)()((s) => s.loading);
|
|
140
|
+
const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
|
|
141
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [(0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(OpeningMessageView, {}) }), messages === null || messages === void 0 ? void 0 : messages.map((message) => (0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && (0, jsx_runtime_1.jsx)(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(OpeningQuestionsView, {}) }))] })));
|
|
142
|
+
}
|
|
143
|
+
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
144
|
+
var _a, _b, _c, _d;
|
|
145
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
146
|
+
const { appearanceOutput } = (0, use_appearances_1.default)({ aid });
|
|
147
|
+
const profile = (0, use_appearances_1.useProfile)({ aid });
|
|
148
|
+
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
149
|
+
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
150
|
+
return null;
|
|
151
|
+
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: {
|
|
152
|
+
renderType: 'parameters',
|
|
153
|
+
} }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { 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: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
154
|
+
renderType: 'result',
|
|
155
|
+
} }) }) })] }) }) }));
|
|
156
|
+
});
|
|
157
|
+
function SuggestedQuestionsView({ message }) {
|
|
158
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
159
|
+
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
160
|
+
const suggestedQuestions = (0, react_1.useMemo)(() => {
|
|
161
|
+
var _a, _b, _c;
|
|
162
|
+
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];
|
|
163
|
+
}, [message]);
|
|
164
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.default, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
165
|
+
execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
|
|
166
|
+
} })) : null }));
|
|
167
|
+
}
|
|
168
|
+
const OpeningMessageView = (0, react_1.memo)(() => {
|
|
169
|
+
var _a;
|
|
170
|
+
const opening = (0, use_appearances_1.useOpeningMessage)();
|
|
171
|
+
if (!opening)
|
|
172
|
+
return null;
|
|
173
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
174
|
+
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
175
|
+
borderRadius: 1,
|
|
176
|
+
borderTopLeftRadius: 2,
|
|
177
|
+
px: 2,
|
|
178
|
+
py: 1,
|
|
179
|
+
mt: 0.5,
|
|
180
|
+
mr: 5,
|
|
181
|
+
}, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: opening.message }) }) }) }));
|
|
182
|
+
});
|
|
183
|
+
function OpeningQuestionsView() {
|
|
184
|
+
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
185
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
186
|
+
const opening = (0, use_appearances_1.useOpeningQuestions)({ aid });
|
|
187
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
188
|
+
return null;
|
|
189
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
190
|
+
return ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
191
|
+
}) }) }));
|
|
192
|
+
}
|
|
@@ -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)
|
|
@@ -46,8 +23,9 @@ const CustomComponentRenderer_1 = __importDefault(require("../../../../../compon
|
|
|
46
23
|
const locale_1 = require("../../../../locale");
|
|
47
24
|
const SimpleHeader_1 = __importDefault(require("../../components/Header/SimpleHeader"));
|
|
48
25
|
const LoadingButton_1 = __importDefault(require("../../components/LoadingButton"));
|
|
49
|
-
const CurrentAgent_1 =
|
|
26
|
+
const CurrentAgent_1 = __importDefault(require("../../contexts/CurrentAgent"));
|
|
50
27
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
28
|
+
const use_appearances_1 = __importDefault(require("../../hooks/use-appearances"));
|
|
51
29
|
const runtime_1 = require("../../state/runtime");
|
|
52
30
|
const session_1 = require("../../state/session");
|
|
53
31
|
const map_right_1 = __importDefault(require("../../utils/map-right"));
|
|
@@ -77,7 +55,7 @@ function PhotoGallery({ resultTitle, primaryColor }) {
|
|
|
77
55
|
exports.default = PhotoGallery;
|
|
78
56
|
function AgentInputRender(_a) {
|
|
79
57
|
var props = __rest(_a, []);
|
|
80
|
-
const { appearanceInput } = (0,
|
|
58
|
+
const { appearanceInput } = (0, use_appearances_1.default)();
|
|
81
59
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
82
60
|
return null;
|
|
83
61
|
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 }) })));
|
|
@@ -97,7 +75,7 @@ function OutputView(_a) {
|
|
|
97
75
|
} })), (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') })) })] })));
|
|
98
76
|
}
|
|
99
77
|
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
100
|
-
const { appearanceOutput } = (0,
|
|
78
|
+
const { appearanceOutput } = (0, use_appearances_1.default)({ agentId: message.assistantId });
|
|
101
79
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
102
80
|
return null;
|
|
103
81
|
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));
|
|
@@ -51,6 +51,7 @@ const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
|
|
|
51
51
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
52
52
|
const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
|
|
53
53
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
54
|
+
const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
|
|
54
55
|
const runtime_1 = require("../../state/runtime");
|
|
55
56
|
const session_2 = require("../../state/session");
|
|
56
57
|
const MessageSuggestedQuestions_1 = __importStar(require("../ChatOutput/MessageSuggestedQuestions"));
|
|
@@ -90,8 +91,8 @@ function SimpleChatView() {
|
|
|
90
91
|
}
|
|
91
92
|
function AgentInputRender(_a) {
|
|
92
93
|
var props = __rest(_a, []);
|
|
93
|
-
const { appearanceInput } = (0,
|
|
94
|
-
if (!
|
|
94
|
+
const { appearanceInput } = (0, use_appearances_1.default)();
|
|
95
|
+
if (!appearanceInput.componentId)
|
|
95
96
|
return null;
|
|
96
97
|
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 }) })));
|
|
97
98
|
}
|
|
@@ -103,15 +104,15 @@ function OutputView(_a) {
|
|
|
103
104
|
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [(0, jsx_runtime_1.jsx)(OpeningMessageView, {}), 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 }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && (0, jsx_runtime_1.jsx)(OpeningQuestionsView, {})] })));
|
|
104
105
|
}
|
|
105
106
|
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
106
|
-
var _a, _b, _c, _d
|
|
107
|
-
const { appearanceOutput } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
|
|
108
|
-
const { appearancePage } = (0, runtime_1.useRuntimeState)();
|
|
107
|
+
var _a, _b, _c, _d;
|
|
109
108
|
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
109
|
+
const { appearanceOutput } = (0, use_appearances_1.default)({ agentId: message.assistantId });
|
|
110
|
+
const profile = (0, use_appearances_1.useProfile)({ agentId: message.assistantId });
|
|
110
111
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
111
112
|
return null;
|
|
112
113
|
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: {
|
|
113
114
|
renderType: 'parameters',
|
|
114
|
-
} }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name:
|
|
115
|
+
} }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { 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: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
|
|
115
116
|
renderType: 'result',
|
|
116
117
|
} }) }) })] }) }) }));
|
|
117
118
|
});
|
|
@@ -127,16 +128,12 @@ function SuggestedQuestionsView({ message }) {
|
|
|
127
128
|
} })) : null }));
|
|
128
129
|
}
|
|
129
130
|
const OpeningMessageView = (0, react_1.memo)(() => {
|
|
130
|
-
var _a
|
|
131
|
-
const { childAgentId
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
var _a, _b;
|
|
135
|
-
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.openingMessage)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
136
|
-
}, [agent]);
|
|
137
|
-
if (!(openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.message))
|
|
131
|
+
var _a;
|
|
132
|
+
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
133
|
+
const opening = (0, use_appearances_1.useOpeningMessage)({ agentId: childAgentId });
|
|
134
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.message))
|
|
138
135
|
return null;
|
|
139
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name:
|
|
136
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
140
137
|
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
141
138
|
borderRadius: 1,
|
|
142
139
|
borderTopLeftRadius: 2,
|
|
@@ -144,19 +141,16 @@ const OpeningMessageView = (0, react_1.memo)(() => {
|
|
|
144
141
|
py: 1,
|
|
145
142
|
mt: 0.5,
|
|
146
143
|
mr: 5,
|
|
147
|
-
}, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children:
|
|
144
|
+
}, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: opening.message }) }) }) }));
|
|
148
145
|
});
|
|
149
146
|
function OpeningQuestionsView() {
|
|
150
|
-
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
151
147
|
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
152
|
-
const {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}, [agent]);
|
|
157
|
-
if (!(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.length))
|
|
148
|
+
const { childAgentId } = (0, runtime_1.useRuntimeState)();
|
|
149
|
+
const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: childAgentId });
|
|
150
|
+
const opening = (0, use_appearances_1.useOpeningQuestions)({ aid });
|
|
151
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
158
152
|
return null;
|
|
159
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children:
|
|
153
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
160
154
|
return ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
|
|
161
155
|
}) }) }));
|
|
162
156
|
}
|
|
@@ -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)
|
|
@@ -44,8 +21,9 @@ const react_wrap_balancer_1 = __importDefault(require("react-wrap-balancer"));
|
|
|
44
21
|
const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
|
|
45
22
|
const SimpleHeader_1 = __importDefault(require("../../components/Header/SimpleHeader"));
|
|
46
23
|
const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLayout"));
|
|
47
|
-
const CurrentAgent_1 =
|
|
24
|
+
const CurrentAgent_1 = __importDefault(require("../../contexts/CurrentAgent"));
|
|
48
25
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
26
|
+
const use_appearances_1 = __importDefault(require("../../hooks/use-appearances"));
|
|
49
27
|
const runtime_1 = require("../../state/runtime");
|
|
50
28
|
const session_1 = require("../../state/session");
|
|
51
29
|
function SimplePage({ resultTitle, primaryColor }) {
|
|
@@ -74,7 +52,7 @@ function SimplePage({ resultTitle, primaryColor }) {
|
|
|
74
52
|
exports.default = SimplePage;
|
|
75
53
|
function AgentInputRender(_a) {
|
|
76
54
|
var props = __rest(_a, []);
|
|
77
|
-
const { appearanceInput } = (0,
|
|
55
|
+
const { appearanceInput } = (0, use_appearances_1.default)();
|
|
78
56
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
79
57
|
return null;
|
|
80
58
|
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 }) })));
|
|
@@ -85,7 +63,7 @@ function OutputView(_a) {
|
|
|
85
63
|
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
64
|
}
|
|
87
65
|
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
88
|
-
const { appearanceOutput } = (0,
|
|
66
|
+
const { appearanceOutput } = (0, use_appearances_1.default)({ agentId: message.assistantId });
|
|
89
67
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
90
68
|
return null;
|
|
91
69
|
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 }) }) }) }));
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const css_1 = require("@emotion/css");
|
|
17
|
+
const material_1 = require("@mui/material");
|
|
18
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
19
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
20
|
+
const react_1 = require("react");
|
|
21
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
22
|
+
const locale_1 = require("../../../../locale");
|
|
23
|
+
const AgentInputField_1 = __importDefault(require("../../components/AgentInputField"));
|
|
24
|
+
const LoadingButton_1 = __importDefault(require("../../components/LoadingButton"));
|
|
25
|
+
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
26
|
+
const runtime_1 = require("../../state/runtime");
|
|
27
|
+
const session_1 = require("../../state/session");
|
|
28
|
+
const agent_inputs_1 = require("../../utils/agent-inputs");
|
|
29
|
+
function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
|
|
30
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
31
|
+
const { aid, agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
32
|
+
const { execute } = (0, runtime_1.useRuntimeState)();
|
|
33
|
+
const running = (0, session_1.useSessionState)()((s) => s.running);
|
|
34
|
+
const parameters = (0, react_1.useMemo)(() => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(agent_inputs_1.isValidInput).map((i) => {
|
|
37
|
+
var _a;
|
|
38
|
+
return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
|
|
39
|
+
});
|
|
40
|
+
}, [agent.parameters]);
|
|
41
|
+
const defaultForm = useInitialFormValues();
|
|
42
|
+
const theme = useFormTheme();
|
|
43
|
+
const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
|
|
44
|
+
(0, react_1.useEffect)(() => {
|
|
45
|
+
if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
|
|
46
|
+
form.reset(chatMode ? (0, omit_1.default)(defaultForm, 'question') : defaultForm);
|
|
47
|
+
}
|
|
48
|
+
}, [defaultForm, autoFillLastForm, form, chatMode]);
|
|
49
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
yield execute({
|
|
51
|
+
aid,
|
|
52
|
+
parameters,
|
|
53
|
+
onResponseStart: () => {
|
|
54
|
+
if (chatMode)
|
|
55
|
+
form.resetField('question', { defaultValue: '' });
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(material_1.ThemeProvider, { theme: theme, children: (0, jsx_runtime_1.jsxs)(Form, { component: "form", className: (0, css_1.cx)('form', `label-position-${inlineLabel ? 'start' : 'top'}`), onSubmit: form.handleSubmit(onSubmit), children: [parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter, index) => {
|
|
60
|
+
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: key, rules: {
|
|
62
|
+
required,
|
|
63
|
+
min: parameter.type === 'number' && typeof parameter.min === 'number'
|
|
64
|
+
? { value: parameter.min, message: '' }
|
|
65
|
+
: undefined,
|
|
66
|
+
max: parameter.type === 'number' && typeof parameter.max === 'number'
|
|
67
|
+
? { value: parameter.max, message: '' }
|
|
68
|
+
: undefined,
|
|
69
|
+
minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
|
|
70
|
+
? { value: parameter.minLength, message: '' }
|
|
71
|
+
: undefined,
|
|
72
|
+
maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
|
|
73
|
+
? { value: parameter.maxLength, message: '' }
|
|
74
|
+
: undefined,
|
|
75
|
+
}, render: ({ field, fieldState }) => {
|
|
76
|
+
var _a;
|
|
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
|
|
78
|
+
? {
|
|
79
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.InputAdornment, { position: "end", sx: { py: 3, mr: -0.75, alignSelf: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText }) })),
|
|
80
|
+
}
|
|
81
|
+
: undefined })] }));
|
|
82
|
+
} }) }, parameter.id));
|
|
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') }))] }) }));
|
|
84
|
+
}
|
|
85
|
+
exports.default = AutoForm;
|
|
86
|
+
function useInitialFormValues() {
|
|
87
|
+
const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
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
|
+
(0, react_1.useEffect)(() => {
|
|
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);
|
|
95
|
+
}
|
|
96
|
+
}, [lastMessage]);
|
|
97
|
+
return (0, react_1.useMemo)(() => {
|
|
98
|
+
var _a, _b;
|
|
99
|
+
if (lastInputs) {
|
|
100
|
+
return lastInputs;
|
|
101
|
+
}
|
|
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 : []);
|
|
103
|
+
}, [lastInputs, agent]);
|
|
104
|
+
}
|
|
105
|
+
function useFormTheme() {
|
|
106
|
+
const theme = (0, material_1.useTheme)();
|
|
107
|
+
return (0, react_1.useMemo)(() => {
|
|
108
|
+
const themeOptions = {
|
|
109
|
+
shape: {
|
|
110
|
+
borderRadius: 8,
|
|
111
|
+
},
|
|
112
|
+
components: {
|
|
113
|
+
MuiTextField: {
|
|
114
|
+
styleOverrides: {
|
|
115
|
+
root: ({ theme }) => theme.unstable_sx({
|
|
116
|
+
[`.${material_1.outlinedInputClasses.root}`]: {
|
|
117
|
+
[`.${material_1.outlinedInputClasses.notchedOutline}`]: {
|
|
118
|
+
borderWidth: 2,
|
|
119
|
+
borderColor: 'primary.light',
|
|
120
|
+
},
|
|
121
|
+
':hover': {
|
|
122
|
+
[`.${material_1.outlinedInputClasses.notchedOutline}`]: {
|
|
123
|
+
borderColor: 'primary.main',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
return (0, material_1.createTheme)(theme, themeOptions);
|
|
133
|
+
}, [theme]);
|
|
134
|
+
}
|
|
135
|
+
const Form = (0, material_1.styled)(material_1.Stack)(({ theme }) => theme.unstable_sx({
|
|
136
|
+
gap: 2,
|
|
137
|
+
'.form-item': {
|
|
138
|
+
gap: 0.5,
|
|
139
|
+
[`.${material_1.formLabelClasses.root}`]: {
|
|
140
|
+
fontWeight: 500,
|
|
141
|
+
color: 'text.primary',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
'&.label-position-start': {
|
|
145
|
+
'.form-item': {
|
|
146
|
+
display: 'flex',
|
|
147
|
+
flexDirection: 'row',
|
|
148
|
+
alignItems: 'center',
|
|
149
|
+
gap: 1,
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
}));
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("@iconify/react");
|
|
8
|
+
const material_1 = require("@mui/material");
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
|
|
11
|
+
const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
|
|
12
|
+
const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
|
|
13
|
+
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
14
|
+
const MessageErrorView_1 = __importDefault(require("../ChatOutput/MessageErrorView"));
|
|
15
|
+
const MessageMetadataRenderer_1 = __importDefault(require("../ChatOutput/MessageMetadataRenderer"));
|
|
16
|
+
const codeField = 'code';
|
|
17
|
+
function V0Output() {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
20
|
+
const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
|
|
21
|
+
const { error } = message;
|
|
22
|
+
const isMessageLoading = (message.loading || !message.result) && !message.error;
|
|
23
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, sx: {
|
|
24
|
+
py: 2,
|
|
25
|
+
}, children: [error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: error }), isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Stack, { sx: {
|
|
26
|
+
flex: 1,
|
|
27
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", sx: {
|
|
28
|
+
height: 400,
|
|
29
|
+
borderRadius: 1,
|
|
30
|
+
} }) })), objects === null || objects === void 0 ? void 0 : objects.map((item) => {
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
const code = item.data[codeField];
|
|
33
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1, sx: {
|
|
34
|
+
display: 'flex',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
}, children: (0, jsx_runtime_1.jsx)(CodePreview, { code: code }) }));
|
|
38
|
+
}), objects === null || objects === void 0 ? void 0 : objects.map((item) => (0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: item.data })), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } }))] }));
|
|
39
|
+
}
|
|
40
|
+
exports.default = V0Output;
|
|
41
|
+
function CodePreview({ code }) {
|
|
42
|
+
const [showCode, setShowCode] = (0, react_2.useState)(false);
|
|
43
|
+
if (!code)
|
|
44
|
+
return null;
|
|
45
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: {
|
|
46
|
+
flex: 1,
|
|
47
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
48
|
+
display: 'flex',
|
|
49
|
+
justifyContent: 'flex-end',
|
|
50
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: () => setShowCode((prev) => !prev), sx: {
|
|
51
|
+
color: 'textColor',
|
|
52
|
+
}, children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: showCode ? 'tabler:layout-sidebar' : 'tabler:code' }) }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 2, sx: {
|
|
53
|
+
display: 'flex',
|
|
54
|
+
flexDirection: 'row',
|
|
55
|
+
alignItems: 'center',
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
58
|
+
display: 'flex',
|
|
59
|
+
justifyContent: 'center',
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
}, children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: "mock-dev-component", dev: {
|
|
62
|
+
components: {
|
|
63
|
+
'mock-dev-component': {
|
|
64
|
+
data: {
|
|
65
|
+
id: 'mock-dev-component',
|
|
66
|
+
createdAt: '',
|
|
67
|
+
updatedAt: '',
|
|
68
|
+
renderer: {
|
|
69
|
+
type: 'react-component',
|
|
70
|
+
script: code,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
} }) }) }), (0, jsx_runtime_1.jsx)(material_1.Drawer, { anchor: "right", open: showCode, onClose: () => setShowCode(false), children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
76
|
+
p: 2,
|
|
77
|
+
maxWidth: '40vw',
|
|
78
|
+
}, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: `\`\`\`typescript\n${code}\n\`\`\`` }) }) })] }));
|
|
79
|
+
}
|