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