@blocklet/pages-kit 0.2.308 → 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.
Files changed (37) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
  2. package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
  3. package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
  4. package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +94 -0
  5. package/lib/cjs/builtin/async/ai-runtime/index.js +3 -1
  6. package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +33 -7
  7. package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +12 -9
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +192 -0
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -26
  11. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +18 -24
  12. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -26
  13. package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -5
  14. package/lib/cjs/builtin/async/ai-runtime/utils/runtime-output-schema.js +8 -0
  15. package/lib/esm/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
  16. package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
  17. package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
  18. package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +87 -0
  19. package/lib/esm/builtin/async/ai-runtime/index.js +1 -0
  20. package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +10 -7
  21. package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +13 -10
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +163 -0
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -3
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +19 -25
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -3
  27. package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -5
  28. package/lib/esm/builtin/async/ai-runtime/utils/runtime-output-schema.js +4 -0
  29. package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +8 -0
  30. package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +4 -5
  31. package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +45 -0
  32. package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -0
  33. package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +11 -0
  34. package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +1 -1
  35. package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -3
  36. package/lib/types/builtin/async/ai-runtime/utils/runtime-output-schema.d.ts +3 -0
  37. package/package.json +6 -6
@@ -41,9 +41,9 @@ const react_wrap_balancer_1 = __importStar(require("react-wrap-balancer"));
41
41
  const runtime_1 = require("../../state/runtime");
42
42
  function SimpleHeader(_a) {
43
43
  var { TitleProps, DescriptionProps } = _a, props = __rest(_a, ["TitleProps", "DescriptionProps"]);
44
- const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
45
- const title = (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name;
46
- const description = (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.description) || agent.description;
44
+ const { agent } = (0, runtime_1.useRuntimeState)();
45
+ const title = agent.project.name;
46
+ const { description } = agent.project;
47
47
  return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 2, mt: 8, mb: 4 }, props, { className: (0, css_1.cx)('aigne-header aigne-simple-header', props.className), children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.Provider, { children: [title && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ width: "100%", component: "h5", fontSize: 30, fontWeight: 700, textAlign: "center" }, TitleProps, { children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: title }) }))), description && ((0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ width: "100%", textAlign: "center" }, DescriptionProps, { children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: description }) })))] }) })));
48
48
  }
49
49
  exports.default = SimpleHeader;
@@ -56,6 +56,7 @@ const ufo_1 = require("ufo");
56
56
  const locale_1 = require("../../../../locale");
57
57
  const CurrentAgent_1 = require("../../contexts/CurrentAgent");
58
58
  const CurrentMessage_1 = require("../../contexts/CurrentMessage");
59
+ const use_appearances_1 = require("../../hooks/use-appearances");
59
60
  const runtime_1 = require("../../state/runtime");
60
61
  const download_image_1 = require("../../utils/download-image");
61
62
  const ActionButton_1 = __importDefault(require("../ActionButton"));
@@ -118,7 +119,8 @@ function ShareSave() {
118
119
  var _a, _b, _c, _d, _e, _f;
119
120
  const { t } = (0, locale_1.useLocaleContext)();
120
121
  const { message } = (0, CurrentMessage_1.useCurrentMessage)();
121
- const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
122
+ const { aid, agent } = (0, runtime_1.useRuntimeState)();
123
+ const profile = (0, use_appearances_1.useProfile)({ aid });
122
124
  const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
123
125
  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[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[types_1.RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
124
126
  if (!content && !image)
@@ -132,7 +134,7 @@ function ShareSave() {
132
134
  yield html2pdf()
133
135
  .set({
134
136
  margin: 1,
135
- filename: `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id} - ${message.taskId}.pdf`,
137
+ filename: `${profile.name || agent.id} - ${message.taskId}.pdf`,
136
138
  image: { type: 'jpeg', quality: 0.98 },
137
139
  html2canvas: { scale: 2 },
138
140
  jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
@@ -141,7 +143,7 @@ function ShareSave() {
141
143
  .save();
142
144
  }
143
145
  else if (image) {
144
- (0, file_saver_1.saveAs)(image, `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id}.png`);
146
+ (0, file_saver_1.saveAs)(image, `${profile.name || agent.id}.png`);
145
147
  }
146
148
  }) }));
147
149
  }
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useCurrentAgent = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const aid_1 = require("@blocklet/ai-runtime/common/aid");
6
- const types_1 = require("@blocklet/ai-runtime/types");
7
6
  const react_1 = require("react");
8
- const constants_1 = require("../constants");
9
7
  const agent_1 = require("../state/agent");
10
8
  const runtime_1 = require("../state/runtime");
11
9
  function useCurrentAid({ agentId }) {
@@ -20,24 +18,18 @@ function CurrentAgentProvider({ agentId, children }) {
20
18
  return (0, jsx_runtime_1.jsx)(context.Provider, { value: state, children: children });
21
19
  }
22
20
  exports.default = CurrentAgentProvider;
23
- function useCurrentAgent({ agentId } = {}) {
21
+ function useCurrentAgent(args = {}) {
24
22
  const { aid: runtimeAid, working } = (0, runtime_1.useRuntimeState)();
25
- const aidFromParam = (0, react_1.useMemo)(() => agentId &&
26
- (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(runtimeAid, { rejectWhenError: true })), { assistantId: agentId })), [agentId]);
23
+ const aidFromParam = (0, react_1.useMemo)(() => args.aid ||
24
+ (args.agentId
25
+ ? (0, aid_1.stringifyIdentity)(Object.assign(Object.assign({}, (0, aid_1.parseIdentity)(runtimeAid, { rejectWhenError: true })), { assistantId: args.agentId }))
26
+ : undefined), [args.agentId, args.aid, runtimeAid]);
27
27
  const current = (0, react_1.useContext)(context);
28
28
  const aid = aidFromParam !== null && aidFromParam !== void 0 ? aidFromParam : current === null || current === void 0 ? void 0 : current.aid;
29
29
  if (!aid) {
30
30
  throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
31
31
  }
32
32
  const [agent] = (0, agent_1.useAgentState)({ aid, working });
33
- const appearanceInput = (0, react_1.useMemo)(() => {
34
- var _a, _b, _c;
35
- return (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: constants_1.DEFAULT_INPUT_COMPONENT_ID };
36
- }, [agent]);
37
- const appearanceOutput = (0, react_1.useMemo)(() => {
38
- var _a, _b, _c;
39
- return (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.initialValue) !== null && _c !== void 0 ? _c : { componentId: constants_1.DEFAULT_OUTPUT_COMPONENT_ID };
40
- }, [agent]);
41
- return { aid, agent, appearanceInput, appearanceOutput };
33
+ return { aid, agent };
42
34
  }
43
35
  exports.useCurrentAgent = useCurrentAgent;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useOpeningQuestions = exports.useOpeningMessage = exports.useProfile = void 0;
4
+ const types_1 = require("@blocklet/ai-runtime/types");
5
+ const react_1 = require("react");
6
+ const ufo_1 = require("ufo");
7
+ const utils_1 = require("../../../utils");
8
+ const constants_1 = require("../constants");
9
+ const CurrentAgent_1 = require("../contexts/CurrentAgent");
10
+ const runtime_1 = require("../state/runtime");
11
+ const runtime_output_schema_1 = require("../utils/runtime-output-schema");
12
+ function useAppearances(args) {
13
+ const { agent: runtimeAgent } = (0, runtime_1.useRuntimeState)();
14
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)(args);
15
+ const appearancePage = (0, react_1.useMemo)(() => {
16
+ const appearance = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.appearancePage);
17
+ return Object.assign(Object.assign({}, appearance), { componentId: (appearance === null || appearance === void 0 ? void 0 : appearance.componentId) || constants_1.DEFAULT_PAGE_COMPONENT_ID });
18
+ }, [agent]);
19
+ const appearanceInput = (0, react_1.useMemo)(() => {
20
+ const appearance = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.appearanceInput);
21
+ if (appearance)
22
+ return appearance;
23
+ const runtimeAppearance = (0, runtime_output_schema_1.getOutputVariableInitialValue)(runtimeAgent, types_1.RuntimeOutputVariable.appearanceInput);
24
+ if (runtimeAppearance)
25
+ return runtimeAppearance;
26
+ return {
27
+ componentId: constants_1.DEFAULT_INPUT_COMPONENT_ID,
28
+ };
29
+ }, [agent, runtimeAgent]);
30
+ const appearanceOutput = (0, react_1.useMemo)(() => {
31
+ const appearance = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.appearanceOutput);
32
+ if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
33
+ return appearance;
34
+ const runtimeAppearance = (0, runtime_output_schema_1.getOutputVariableInitialValue)(runtimeAgent, types_1.RuntimeOutputVariable.appearanceOutput);
35
+ if (runtimeAppearance)
36
+ return runtimeAppearance;
37
+ return {
38
+ componentId: constants_1.DEFAULT_OUTPUT_COMPONENT_ID,
39
+ };
40
+ }, [agent, runtimeAgent]);
41
+ return { appearancePage, appearanceInput, appearanceOutput };
42
+ }
43
+ exports.default = useAppearances;
44
+ function getProjectIconUrl(projectId) {
45
+ return (0, ufo_1.joinURL)(window.location.origin, (0, utils_1.getComponentMountPoint)(constants_1.AI_STUDIO_DID), '/api/projects', projectId, '/logo.png');
46
+ }
47
+ function useProfile(args) {
48
+ const { agent: runtimeAgent } = (0, runtime_1.useRuntimeState)();
49
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)(args);
50
+ return (0, react_1.useMemo)(() => {
51
+ const profile = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.profile);
52
+ const runtimeProfile = (0, runtime_output_schema_1.getOutputVariableInitialValue)(runtimeAgent, types_1.RuntimeOutputVariable.profile);
53
+ return {
54
+ avatar: (profile === null || profile === void 0 ? void 0 : profile.avatar) || (runtimeProfile === null || runtimeProfile === void 0 ? void 0 : runtimeProfile.avatar) || getProjectIconUrl(agent.project.id),
55
+ name: (profile === null || profile === void 0 ? void 0 : profile.name) || (runtimeProfile === null || runtimeProfile === void 0 ? void 0 : runtimeProfile.name) || agent.name,
56
+ };
57
+ }, [agent, runtimeAgent]);
58
+ }
59
+ exports.useProfile = useProfile;
60
+ function useOpeningMessage(args) {
61
+ const { aid: runtimeAid, agent: runtimeAgent } = (0, runtime_1.useRuntimeState)();
62
+ const runtimeProfile = useProfile({ aid: runtimeAid });
63
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)(args);
64
+ const profile = useProfile(args);
65
+ return (0, react_1.useMemo)(() => {
66
+ const agentOpening = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.openingMessage);
67
+ if (agentOpening === null || agentOpening === void 0 ? void 0 : agentOpening.message) {
68
+ return {
69
+ message: agentOpening.message,
70
+ profile,
71
+ };
72
+ }
73
+ const runtimeOpening = (0, runtime_output_schema_1.getOutputVariableInitialValue)(runtimeAgent, types_1.RuntimeOutputVariable.openingMessage);
74
+ if (runtimeOpening === null || runtimeOpening === void 0 ? void 0 : runtimeOpening.message) {
75
+ return {
76
+ message: runtimeOpening.message,
77
+ profile: runtimeProfile,
78
+ };
79
+ }
80
+ return undefined;
81
+ }, [agent, profile, runtimeAgent, runtimeProfile]);
82
+ }
83
+ exports.useOpeningMessage = useOpeningMessage;
84
+ function useOpeningQuestions(args) {
85
+ const { agent } = (0, CurrentAgent_1.useCurrentAgent)(args);
86
+ return (0, react_1.useMemo)(() => {
87
+ var _a, _b;
88
+ const questions = (_b = (_a = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.openingQuestions)) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.title);
89
+ if (!(questions === null || questions === void 0 ? void 0 : questions.length))
90
+ return undefined;
91
+ return { questions };
92
+ }, [agent]);
93
+ }
94
+ exports.useOpeningQuestions = useOpeningQuestions;
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = exports.CurrentMessageProvider = exports.CurrentAgentProvider = void 0;
20
+ exports.PhotoGalleryItem = exports.ChatOutput = exports.SimpleOutput = exports.AutoForm = exports.PhotoGallery = exports.MultiAgentsChat = exports.SimpleChat = exports.SimplePage = exports.ChatBotButton = exports.Runtime = exports.CurrentMessageProvider = exports.CurrentAgentProvider = void 0;
21
21
  __exportStar(require("./contexts/CurrentAgent"), exports);
22
22
  var CurrentAgent_1 = require("./contexts/CurrentAgent");
23
23
  Object.defineProperty(exports, "CurrentAgentProvider", { enumerable: true, get: function () { return __importDefault(CurrentAgent_1).default; } });
@@ -34,6 +34,8 @@ var SimplePage_1 = require("./runtime-components/SimplePage");
34
34
  Object.defineProperty(exports, "SimplePage", { enumerable: true, get: function () { return __importDefault(SimplePage_1).default; } });
35
35
  var SimpleChat_1 = require("./runtime-components/SimpleChat");
36
36
  Object.defineProperty(exports, "SimpleChat", { enumerable: true, get: function () { return __importDefault(SimpleChat_1).default; } });
37
+ var MultiAgentsChat_1 = require("./runtime-components/MultiAgentsChat");
38
+ Object.defineProperty(exports, "MultiAgentsChat", { enumerable: true, get: function () { return __importDefault(MultiAgentsChat_1).default; } });
37
39
  var PhotoGallery_1 = require("./runtime-components/PhotoGallery");
38
40
  Object.defineProperty(exports, "PhotoGallery", { enumerable: true, get: function () { return __importDefault(PhotoGallery_1).default; } });
39
41
  var AutoForm_1 = require("./runtime-components/AutoForm");
@@ -1,4 +1,27 @@
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -14,6 +37,7 @@ const RuntimeCommonProvider_1 = __importDefault(require("../../components/Runtim
14
37
  const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
15
38
  const constants_1 = require("../../constants");
16
39
  const Runtime_1 = __importDefault(require("../../contexts/Runtime"));
40
+ const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
17
41
  const runtime_1 = require("../../state/runtime");
18
42
  const session_1 = require("../../state/session");
19
43
  function ChatBotButton({ aid, working }) {
@@ -21,13 +45,15 @@ function ChatBotButton({ aid, working }) {
21
45
  }
22
46
  exports.default = ChatBotButton;
23
47
  function ChatBotContent() {
24
- var _a, _b, _c;
48
+ var _a, _b;
25
49
  const anchorEl = (0, react_2.useRef)(null);
26
50
  (0, session_1.useSessionState)({ autoLoad: true });
27
- const { appearancePage } = (0, runtime_1.useRuntimeState)();
51
+ const { aid } = (0, runtime_1.useRuntimeState)();
52
+ const { appearancePage } = (0, use_appearances_1.default)({ aid });
53
+ const profile = (0, use_appearances_1.useProfile)({ aid });
28
54
  const [open, setOpen] = (0, react_2.useState)(false);
29
55
  const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PAGE_COMPONENT_ID;
30
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: 'modal' }, children: [(0, jsx_runtime_1.jsx)(material_1.Fab, { sx: { width: 44, height: 44, boxShadow: open ? 0 : undefined }, onClick: () => setOpen(true), children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 44, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _c === void 0 ? void 0 : _c.url }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { width: "100%", ref: anchorEl }), anchorEl.current && ((0, jsx_runtime_1.jsx)(ResponsiveChatBotContainer, { anchorEl: anchorEl.current, open: open, onClose: () => setOpen(false), children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { initialScrollBehavior: "auto", component: material_1.Stack, sx: {
56
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: 'fixed', bottom: 32, right: 16, zIndex: 'modal' }, children: [(0, jsx_runtime_1.jsx)(material_1.Fab, { sx: { width: 44, height: 44, boxShadow: open ? 0 : undefined }, onClick: () => setOpen(true), children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 44, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: profile.avatar }) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { width: "100%", ref: anchorEl }), anchorEl.current && ((0, jsx_runtime_1.jsx)(ResponsiveChatBotContainer, { anchorEl: anchorEl.current, open: open, onClose: () => setOpen(false), children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { initialScrollBehavior: "auto", component: material_1.Stack, sx: {
31
57
  overscrollBehavior: 'contain',
32
58
  height: '100%',
33
59
  width: '100%',
@@ -40,12 +66,12 @@ function ChatBotContent() {
40
66
  function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
41
67
  const theme = (0, material_1.useTheme)();
42
68
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
43
- const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
44
- const title = (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name;
69
+ const { aid } = (0, runtime_1.useRuntimeState)();
70
+ const profile = (0, use_appearances_1.useProfile)({ aid });
45
71
  if (isMobile) {
46
- return ((0, jsx_runtime_1.jsx)(ChatBotDialog, { title: title, open: open, onClose: onClose, children: children }));
72
+ return ((0, jsx_runtime_1.jsx)(ChatBotDialog, { title: profile.name, open: open, onClose: onClose, children: children }));
47
73
  }
48
- return ((0, jsx_runtime_1.jsx)(ChatBotPopper, { anchorEl: anchorEl, title: title, open: open, onClose: onClose, children: children }));
74
+ return ((0, jsx_runtime_1.jsx)(ChatBotPopper, { anchorEl: anchorEl, title: profile.name, open: open, onClose: onClose, children: children }));
49
75
  }
50
76
  function ChatBotPopper({ title, anchorEl, open, children, onClose, }) {
51
77
  return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl, open: open, disablePortal: true, placement: "top-end", sx: {
@@ -30,19 +30,22 @@ const jsx_runtime_1 = require("react/jsx-runtime");
30
30
  const material_1 = require("@mui/material");
31
31
  const react_1 = require("react");
32
32
  const react_helmet_1 = require("react-helmet");
33
+ const ufo_1 = require("ufo");
33
34
  const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
34
35
  const ux_1 = require("../../../../arcblock/ux");
35
36
  const locale_1 = require("../../../../locale");
36
37
  const header_1 = require("../../../../page/header");
38
+ const utils_1 = require("../../../../utils");
37
39
  const RuntimeCommonProvider_1 = __importStar(require("../../components/RuntimeCommonProvider"));
38
40
  const SocialShare_1 = __importDefault(require("../../components/SocialShare"));
39
41
  const constants_1 = require("../../constants");
40
42
  const Runtime_1 = require("../../contexts/Runtime");
43
+ const use_appearances_1 = __importDefault(require("../../hooks/use-appearances"));
41
44
  const runtime_1 = require("../../state/runtime");
42
45
  const logoSize = 44;
43
- function AgentCreatedBy({ agent }) {
46
+ function AgentCreatedBy({ did }) {
44
47
  const { t } = (0, locale_1.useLocaleContext)();
45
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [t('by'), " ", (0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.DID, did: agent.createdBy, copyable: false, responsive: true })] }));
48
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [t('by'), " ", (0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.DID, did: did, copyable: false, responsive: true })] }));
46
49
  }
47
50
  function Runtime() {
48
51
  return ((0, jsx_runtime_1.jsx)(Runtime_1.RuntimeProviderFromUrl, { children: (0, jsx_runtime_1.jsx)(RuntimeView, {}) }));
@@ -50,14 +53,14 @@ function Runtime() {
50
53
  exports.default = Runtime;
51
54
  function RuntimeView() {
52
55
  var _a;
53
- const { agent, appearancePage } = (0, runtime_1.useRuntimeState)();
56
+ const { aid, agent } = (0, runtime_1.useRuntimeState)();
57
+ const { appearancePage } = (0, use_appearances_1.default)({ aid });
54
58
  const theme = (0, material_1.useTheme)();
55
59
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
56
60
  const { locale } = (0, locale_1.useLocaleContext)();
57
61
  (0, react_1.useEffect)(() => {
58
62
  header_1.useHeaderState.setState((state) => {
59
- var _a;
60
- const logo = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _a === void 0 ? void 0 : _a.url;
63
+ const logo = (0, ufo_1.joinURL)(window.location.origin, (0, utils_1.getComponentMountPoint)(constants_1.AI_STUDIO_DID), '/api/projects', agent.project.id, '/logo.png');
61
64
  state.logo = logo && ((0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.Avatar, src: logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, size: logoSize, sx: {
62
65
  width: logoSize,
63
66
  height: logoSize,
@@ -66,7 +69,7 @@ function RuntimeView() {
66
69
  state.brand = ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
67
70
  height: 18,
68
71
  fontSize: 18,
69
- }, children: (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name }));
72
+ }, children: agent.project.name }));
70
73
  state.description = agent.createdBy && ((0, jsx_runtime_1.jsx)(RuntimeCommonProvider_1.RuntimeLocaleProvider, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
71
74
  display: 'inline-flex',
72
75
  alignItems: 'center',
@@ -74,7 +77,7 @@ function RuntimeView() {
74
77
  mt: 0.5,
75
78
  height: 12,
76
79
  fontSize: 12,
77
- }, children: (0, jsx_runtime_1.jsx)(AgentCreatedBy, { agent: agent }) }) }));
80
+ }, children: (0, jsx_runtime_1.jsx)(AgentCreatedBy, { did: agent.project.createdBy }) }) }));
78
81
  }
79
82
  const shareContent = `${agent.name}
80
83
 
@@ -90,7 +93,7 @@ function RuntimeView() {
90
93
  state.addons = (...exists) => [...exists];
91
94
  });
92
95
  };
93
- }, [appearancePage, locale, isMobile, agent]);
96
+ }, [locale, isMobile, agent]);
94
97
  const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : constants_1.DEFAULT_PAGE_COMPONENT_ID;
95
- return ((0, jsx_runtime_1.jsxs)(RuntimeCommonProvider_1.default, { children: [appearancePage && ((0, jsx_runtime_1.jsxs)(react_helmet_1.Helmet, { children: [appearancePage.name && (0, jsx_runtime_1.jsx)("title", { children: appearancePage.name }), appearancePage.description && (0, jsx_runtime_1.jsx)("meta", { name: "description", content: appearancePage.description })] })), (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps })] }));
98
+ return ((0, jsx_runtime_1.jsxs)(RuntimeCommonProvider_1.default, { children: [(0, jsx_runtime_1.jsxs)(react_helmet_1.Helmet, { children: [agent.project.name && (0, jsx_runtime_1.jsx)("title", { children: agent.project.name }), agent.project.description && (0, jsx_runtime_1.jsx)("meta", { name: "description", content: agent.project.description })] }), (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProps })] }));
96
99
  }
@@ -49,6 +49,7 @@ const ux_1 = require("../../../../arcblock/ux");
49
49
  const session_1 = require("../../../../session");
50
50
  const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
51
51
  const ShareActions_1 = __importDefault(require("../../components/ShareActions"));
52
+ const use_appearances_1 = require("../../hooks/use-appearances");
52
53
  const runtime_1 = require("../../state/runtime");
53
54
  const MessageErrorView_1 = __importDefault(require("./MessageErrorView"));
54
55
  const MessageMetadataRenderer_1 = __importDefault(require("./MessageMetadataRenderer"));
@@ -111,13 +112,14 @@ function UserMessage({ message, hideAvatar }) {
111
112
  }, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsx)(material_1.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 })] })] }));
112
113
  }
113
114
  function AgentMessage({ message, hideAvatar }) {
114
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
115
- const { appearancePage } = (0, runtime_1.useRuntimeState)();
115
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
116
+ const { aid } = (0, runtime_1.useRuntimeState)();
117
+ const profile = (0, use_appearances_1.useProfile)({ aid });
116
118
  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));
117
119
  const isMessageLoading = (message.loading || !message.result) && !message.error;
118
120
  const theme = (0, material_1.useTheme)();
119
121
  const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
120
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _e === void 0 ? void 0 : _e.url }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { placement: "right-start", slotProps: {
122
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: profile.avatar }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [profile.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: message.createdAt })] })), (0, jsx_runtime_1.jsxs)(react_1.default.Suspense, { children: [showMainMessage ? ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { placement: "right-start", slotProps: {
121
123
  popper: {
122
124
  disablePortal: true,
123
125
  modifiers: [
@@ -133,13 +135,13 @@ function AgentMessage({ message, hideAvatar }) {
133
135
  sx: { p: 0, bgcolor: 'white' },
134
136
  },
135
137
  }, title: !isMessageLoading &&
136
- ((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { sx: {
138
+ ((_e = message.result) === null || _e === void 0 ? void 0 : _e.content) && ((0, jsx_runtime_1.jsx)(ShareActions_1.default, { sx: {
137
139
  fontSize: '1rem',
138
140
  boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
139
141
  border: '1px solid rgba(229, 231, 235, 1)',
140
142
  borderRadius: 1,
141
143
  p: 0.25,
142
- } })), children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
144
+ } })), children: (0, jsx_runtime_1.jsxs)(material_1.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) => {
143
145
  var _a, _b, _c, _d, _e, _f, _g;
144
146
  return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading &&
145
147
  !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
@@ -147,16 +149,17 @@ function AgentMessage({ message, hideAvatar }) {
147
149
  message.result.messages.length - 1 === index
148
150
  ? 'writing'
149
151
  : '', 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) ? ((0, jsx_runtime_1.jsx)(image_preview_1.default, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
150
- }), ((_j = message.result) === null || _j === void 0 ? void 0 : _j.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) })) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
152
+ }), ((_h = message.result) === null || _h === void 0 ? void 0 : _h.content) && ((0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) })) : (isMessageLoading && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
151
153
  // only response with loading
152
- className: "message-response" }))), (_l = (_k = message.result) === null || _k === void 0 ? void 0 : _k.objects) === null || _l === void 0 ? void 0 : _l.map((object) => ((0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: object.data }, object.taskId))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: message.error })] })] })] }));
154
+ className: "message-response" }))), (_k = (_j = message.result) === null || _j === void 0 ? void 0 : _j.objects) === null || _k === void 0 ? void 0 : _k.map((object) => ((0, jsx_runtime_1.jsx)(MessageMetadataRenderer_1.default, { object: object.data }, object.taskId))), message.error && (0, jsx_runtime_1.jsx)(MessageErrorView_1.default, { error: message.error })] })] })] }));
153
155
  }
154
156
  function MessageItemWrapper(_a) {
155
- var _b, _c;
157
+ var _b;
156
158
  var { hideAvatar, agentMessage } = _a, props = __rest(_a, ["hideAvatar", "agentMessage"]);
157
- const { appearancePage } = (0, runtime_1.useRuntimeState)();
159
+ const { aid } = (0, runtime_1.useRuntimeState)();
160
+ const profile = (0, use_appearances_1.useProfile)({ aid });
158
161
  const [time] = (0, react_1.useState)(() => new Date().toISOString());
159
- return ((0, jsx_runtime_1.jsx)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _c === void 0 ? void 0 : _c.url }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: time })] })), agentMessage] })] })) })));
162
+ return ((0, jsx_runtime_1.jsx)(MessageItemContainer, Object.assign({}, props, { className: (0, css_1.cx)('ai-chat-message-item', hideAvatar && 'hide-avatar', props.className), children: agentMessage && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ux_1.Avatar, { size: 40, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: profile.avatar }) })), (0, jsx_runtime_1.jsxs)(material_1.Box, { flex: 1, width: 0, children: [!hideAvatar && ((0, jsx_runtime_1.jsxs)(MessageUserName, { children: [profile.name, (0, jsx_runtime_1.jsx)(MessageTime, { time: time })] })), agentMessage] })] })) })));
160
163
  }
161
164
  exports.MessageItemWrapper = MessageItemWrapper;
162
165
  function MessageUserName({ children }) {
@@ -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
+ }